File system API

The API that applications can use. It's exported by FS.RDV driver, and it's declared in USER.INC:

GetDriveInfo
SetCurDrive
GetCurDrive
SetCurDir
GetCurDir
MakeDir
RemoveDir
RenameFile
DeleteFile
GetFileAttribute
SetFileAttribute
OpenDir
CloseDir
ReadDir
OpenFile
CreateFile
CloseFile
DuplFile
GetIoctlData
GetFileSize
SetFileSize
GetFilePos
SetFilePos
GetFileTime
SetFileTime
ReadFile
WriteFile

The virtual file system also exports the following function that physical file systems use to register themselves:

RegisterFileSystem (OS.INC)

And the following that physical drivers use to install a file system:

InstallFileSystem (OS.INC)

Physical file system interface

The API all file systems must implement is the following. The interface hooks are implemented in FS.ASM and declared in FS.INC:

mount_proc
dismount_proc
info_proc
set_cur_dir_proc
get_cur_dir_proc
make_dir_proc
remove_dir_proc
delete_file_proc
rename_file_proc
get_file_attrib_proc
set_file_attrib_proc
open_dir_proc
close_dir_proc
read_dir_proc
open_file_proc
create_file_proc
close_file_proc
dupl_file_proc
get_ioctl_data_proc
get_file_size_proc
set_file_size_proc
get_file_time_proc
set_file_time_proc
read_file_proc
write_file_proc

File system synchronization

To ensure multitasking in the file system, I'd use the following method:

Open file / directory:
request read lock on file system
parse pathname
request read lock on directory
release read lock on file system
open file / directory
release read lock on directory

Create file / directory, delete file:
request read lock on file system
parse pathname
request write lock on directory
release read lock on file system
create file / directory, delete
release write lock on directory

Delete directory:
request write lock on file system
parse pathname
request write lock on directory
delete directory
release write lock on directory
release write lock on file system

More than one reader can take the read-lock, but only one writer is allowed to take a write-lock. A writer will have to wait until the lock is free and a reader can only enter if no writers have the lock.

File system initialization

File system initialization / operation procedure

- Physical driver registers itself as a physical disk driver (HookInitDisc).

- The logical disk driver (DRIVE.ASM) creates a initialization thread (threadname: Disc)

- The initialization thread calls back all registered physical disk drivers.

- Physical driver installs it's physical disks and hands over the access functions as a parameter (InstallDisc).

- Logical disk driver creates a server thread per installed disk (example threadname: IDE 0)

- The server thread creates an initialization thread (threadname: Disc Init), and waits for requests from file system

- The initialization thread calls the physical driver's open procedure.

- Physical driver's open procedure determines type of file system. If it finds a valid file system, it creates a drive # (AllocateStaticDrive, AllocateDynamicDrive or AllocateFixedDrive) and installs the file system with InstallFileSystem

- The virtual file system (FS.ASM) searches for registered file systems, and if it finds the requested file system, calls it's mount procedure.

- Physical file system accesses data through the logical disk driver.

- Logical disk driver buffers data. If data is buffered, it just returns it. Otherwise it wakes up the server thread & suspends current thread.

- Server thread reads / writes to physical disk and wakes up the requesting thread(s) when data is available.