Page 1 of 1

Filesystem driver

Posted: Sun Aug 11, 2013 1:48 pm
by MadZarx
Hello.
I just want to implement a FS driver to at least be able to read or write in a file in an ISO or floppy image FS. How and where should I start?
My question may be kind of dumb but I'm willing to build a hybrid kernel and I need to load drivers from a location in disk or image. Someone tell me how can I have a FS driver for ISO or IMG?

Re: Filesystem driver

Posted: Sun Aug 11, 2013 2:22 pm
by Nable
ISO (if one mean iso9660 FS) is read-only FS (ok, there are some special cases but I don't think it's time to discuss them).
IMG is not a format at all, it's just a filename extension. *.IMG disk images can contain ~any FS, although FAT12 and EXT2 are most common for floppies.
So, you need some routines (functions) to read (and possible write) blocks (device-specific stuff it you want to work with real devices or just fread/fwrite functions if you're building an image) and routines to work with FS structures (http://wiki.osdev.org/FAT , http://wiki.osdev.org/Ext2)

Re: Filesystem driver

Posted: Sun Aug 11, 2013 4:35 pm
by sortie
Don't confuse filesystems (or filesystem drivers) with block devices (or block device drivers). The filesystem driver doesn't care how the data is stored physically (except for some performance hints).

Re: Filesystem driver

Posted: Sun Aug 11, 2013 5:46 pm
by bluemoon
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.

Re: Filesystem driver

Posted: Sun Aug 11, 2013 8:29 pm
by MadZarx
Alright guys. I didn't know that first I should write the device driver. Okay there is some tutorials on the wiki about disks, bu which one should I read to be able to read from an ISO9660?

Re: Filesystem driver

Posted: Sun Aug 11, 2013 11:19 pm
by egos
MadZarx wrote:I didn't know that first I should write the device driver.
As bluemoon said, you can write RAM/image-based disk driver. Or you can impement storage device (driver) interface in image manipulation tool first (and then implement FS driver interface and VFS interface).
which one should I read to be able to read from an ISO9660?
To be able to read from CD/DVD with ISO9660 read the following:
- ATA Spec. and description of ATAPI packets;
- PCI IDE/AHCI Spec.;
- ISO 9660 Spec. and description of some its extensions.

Re: Filesystem driver

Posted: Mon Aug 12, 2013 12:26 am
by MadZarx
Thanks egos. Thank you all :oops: