I suggest you start with designing your first simple block device and FS and VFS interface, and implement a simple ram disk + simpleFS/FAT combo.
For example, for my design I got 5 entities: disk driver, disk, FS driver, volume, VFS
block devices got these functions:
Code: Select all
typedef struct DRIVER_DISK_{
DRIVER header;
int (*create) (struct DRIVER_DISK_* driver, struct HAL_DISK_* disk, const char* resource, int option);
int (*destroy)(struct DRIVER_DISK_* driver, struct HAL_DISK_* disk);
int (*ioctl) (struct HAL_DISK_* disk, int req, ...);
uint64_t (*read) (struct HAL_DISK_* disk, void* buf, uint64_t block, uint64_t nblock);
uint64_t (*write) (struct HAL_DISK_* disk, const void* buf, uint64_t block, uint64_t nblock);
} DRIVER_DISK;
Implement the ram disk driver is just trivial memcpy().
Then, to design the FS layer you may consider the following POSIX alike functions (taken from my OS as an example):
Code: Select all
int tablefs_init (DRIVER* driver);
int tablefs_fini (DRIVER* driver);
int tablefs_create (DRIVER_VOLUME* driver, HAL_VOLUME* volume);
int tablefs_destroy (DRIVER_VOLUME* driver, HAL_VOLUME* volume);
int tablefs_format (HAL_VOLUME* volume);
int tablefs_open (HAL_VOLUME* volume, FS_FILE* file, const char* path);
int tablefs_close (HAL_VOLUME* volume, FS_FILE* file);
uint64_t tablefs_read (HAL_VOLUME* volume, FS_FILE* file, void* buf, uint64_t block, uint64_t nblock);
uint64_t tablefs_write (HAL_VOLUME* volume, FS_FILE* file, const void* buf, uint64_t block, uint64_t nblock);
int tablefs_opendir (HAL_VOLUME* volume, FS_DIR *dir, const char* path);
int tablefs_closedir (HAL_VOLUME* volume, FS_DIR *dir);
int tablefs_readdir (HAL_VOLUME* volume, FS_DIR *dir, unsigned int index, FS_DIRENT* dirent);
Finally, design the VFS layer to group together multiple volumes/mount points - single root like unix or multiple drives...
Once you got a basic VFS-FS-DEVICE architecture implemented, you may think about implementing IDE/SATA disk driver and/or all the fancy features (and perhaps rewrite the whole stuff with better understandings).
* Note that the above design is greatly simplified and may not suitable for serious kernel.