Filesystem driver

Question about which tools to use, bugs, the best way to implement a function, etc should go here. Don't forget to see if your question is answered in the wiki first! When in doubt post here.
Post Reply
MadZarx
Member
Member
Posts: 85
Joined: Mon Apr 01, 2013 5:06 am
Location: CMOS :D

Filesystem driver

Post 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?
Nable
Member
Member
Posts: 453
Joined: Tue Nov 08, 2011 11:35 am

Re: Filesystem driver

Post 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)
User avatar
sortie
Member
Member
Posts: 931
Joined: Wed Mar 21, 2012 3:01 pm
Libera.chat IRC: sortie

Re: Filesystem driver

Post 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).
User avatar
bluemoon
Member
Member
Posts: 1761
Joined: Wed Dec 01, 2010 3:41 am
Location: Hong Kong

Re: Filesystem driver

Post 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.
MadZarx
Member
Member
Posts: 85
Joined: Mon Apr 01, 2013 5:06 am
Location: CMOS :D

Re: Filesystem driver

Post 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?
egos
Member
Member
Posts: 612
Joined: Fri Nov 16, 2007 1:59 pm

Re: Filesystem driver

Post 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.
If you have seen bad English in my words, tell me what's wrong, please.
MadZarx
Member
Member
Posts: 85
Joined: Mon Apr 01, 2013 5:06 am
Location: CMOS :D

Re: Filesystem driver

Post by MadZarx »

Thanks egos. Thank you all :oops:
Post Reply