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
User avatar
crazygray1
Member
Member
Posts: 168
Joined: Thu Nov 22, 2007 7:18 pm
Location: USA,Hawaii,Honolulu(Seriously)

Filesystem Driver

Post by crazygray1 »

How would you go about writing a driver for a custom filesystem under Linux?
Codname: Cipher
Working On: Design Doc(CFFS file system)
User avatar
XCHG
Member
Member
Posts: 416
Joined: Sat Nov 25, 2006 3:55 am
Location: Wisconsin
Contact:

Post by XCHG »

I'm on Windows but I hope this will help. First I laid out the basic structure of the file system. You have to have a sound understanding of your goals and what you want to pull off with your file system in the future since changing it will change many things in your operating system. I suggest you start with minimal support for files and directories and not worry about too many complicated things at first. Remember to leave room for changes later. For example, right now, each entry in my file system has the below descriptor:

Code: Select all

; ——————————————————————————————————————————————————
  ;  typedef STRUCT FDDTEntry{
  ;    QWORD       EntryParentIndexInFDDT;
  ;    QWORD       EntryLinkIndexInFDDT;
  ;    QWORD       EntryRelativeClusterIndexOnDisk;
  ;    QWORD       EntrySizeInBytes;
  ;    QWORD       EntrySizeOnDiskInClusters;
  ;    DWORD       EntryType;
  ;    DWORD       Attributes;
  ;    DWORD       CreationTime;
  ;    DWORD       CreationDate;
  ;    DWORD       ModificationTime;
  ;    DWORD       ModificationDate;
  ;    DWORD       LastAccessTime;
  ;    DWORD       LastAccessDate;
  ;    DWORD       CreatorID;
  ;    DWORD       CreatorGroupID;
  ;    DWORD[44]   Reserved;
  ;    BYTE[256]   EntryNameInUTF8;
  ;  }
; ——————————————————————————————————————————————————
Note the second to last member which is 44 DWORDs that are reserved. I am not using them but I know I will do it in the future.

Then I suggest you start with a simple disk image instead of worrying about real hardware. Then once in a while, ask others (who do have the equipments) to test your images on a real hardware. I hope you will be able to find wonderful people like Dex who are willing to do things like this :)

Last but not least, don't get hung up on technicality and complicated matters. Write drafts of the structure of your file system and understand its abilities and lack of abilities in various cases.
On the field with sword and shield amidst the din of dying of men's wails. War is waged and the battle will rage until only the righteous prevails.
jal
Member
Member
Posts: 1385
Joined: Wed Oct 31, 2007 9:09 am

Post by jal »

XCHG wrote:I'm on Windows but I hope this will help. First I laid out the basic structure of the file system. You have to have a sound understanding of your goals and what you want to pull off with your file system in the future since changing it will change many things in your operating system.
I think the OP's question is not how to write a file system driver for his OS, but how to write a file system driver for Linux, so he can access the file system from his OS, in Linux. Unfortunately, I have very little experience with that. That said, check out FUSE. Google is your friend in this case, as no doubt many implementations of a FUSE driver can be found.

EDIT: The FUSE page mentions many projects using FUSE.


JAL
User avatar
crazygray1
Member
Member
Posts: 168
Joined: Thu Nov 22, 2007 7:18 pm
Location: USA,Hawaii,Honolulu(Seriously)

Post by crazygray1 »

Instead I may write a prog to work with disk images formatted to my file system.
Codname: Cipher
Working On: Design Doc(CFFS file system)
User avatar
Telgin
Member
Member
Posts: 72
Joined: Thu Dec 20, 2007 1:45 pm

Post by Telgin »

crazygray1 wrote:Instead I may write a prog to work with disk images formatted to my file system.
This is the route I'm going actually. It lacks some power in that it's hard to write such a program to integrate with things like drag and drop files (I'm not even bothering, just run the program and choose what to do to the image). On the other hand, it is arguably much simpler to do it this way, and if the program dies it won't take the host OS down with it. A driver is much more difficult to debug anyway.
User avatar
Alboin
Member
Member
Posts: 1466
Joined: Thu Jan 04, 2007 3:29 pm
Location: Noricum and Pannonia

Post by Alboin »

Telgin wrote:
crazygray1 wrote:Instead I may write a prog to work with disk images formatted to my file system.
This is the route I'm going actually. It lacks some power in that it's hard to write such a program to integrate with things like drag and drop files (I'm not even bothering, just run the program and choose what to do to the image). On the other hand, it is arguably much simpler to do it this way, and if the program dies it won't take the host OS down with it. A driver is much more difficult to debug anyway.
It's also more portable and easier to install. ;)
C8H10N4O2 | #446691 | Trust the nodes.
User avatar
crazygray1
Member
Member
Posts: 168
Joined: Thu Nov 22, 2007 7:18 pm
Location: USA,Hawaii,Honolulu(Seriously)

Post by crazygray1 »

I'm making a command line prog. Like mkisofs for ISO 9660.
Codname: Cipher
Working On: Design Doc(CFFS file system)
iammisc
Member
Member
Posts: 269
Joined: Thu Nov 09, 2006 6:23 pm

Post by iammisc »

FUSE is probably better than writing a new app. It has the same benefits as a disk image app except that the filesystem will be able to do the same things that all linux file systems do. Even if the driver crashes, it won't take the kernel down with it because it is running in userspace. I wrote a simple driver for a pseudo-filesystem in FUSE for SQLite and it wasn't too hard. Writing it for a custom filesystem would only be a little harder. The FUSE API is pretty easy to work with. You also don't need to implement everything, just enough to do what you want. For example, I only implemented, readdir, read, and stat at first and then worried about writing later.
User avatar
Brynet-Inc
Member
Member
Posts: 2426
Joined: Tue Oct 17, 2006 9:29 pm
Libera.chat IRC: brynet
Location: Canada
Contact:

Post by Brynet-Inc »

iammisc wrote:FUSE is probably better than writing a new app. It has the same benefits as a disk image app except that the filesystem will be able to do the same things that all linux file systems do. Even if the driver crashes, it won't take the kernel down with it because it is running in userspace. I wrote a simple driver for a pseudo-filesystem in FUSE for SQLite and it wasn't too hard. Writing it for a custom filesystem would only be a little harder. The FUSE API is pretty easy to work with. You also don't need to implement everything, just enough to do what you want. For example, I only implemented, readdir, read, and stat at first and then worried about writing later.
FUSE only supports a handful of operating systems... It would be far easier to make a portable utility in C.
Image
Twitter: @canadianbryan. Award by smcerm, I stole it. Original was larger.
User avatar
Telgin
Member
Member
Posts: 72
Joined: Thu Dec 20, 2007 1:45 pm

Post by Telgin »

Alboin wrote:
Telgin wrote:
crazygray1 wrote:Instead I may write a prog to work with disk images formatted to my file system.
This is the route I'm going actually. It lacks some power in that it's hard to write such a program to integrate with things like drag and drop files (I'm not even bothering, just run the program and choose what to do to the image). On the other hand, it is arguably much simpler to do it this way, and if the program dies it won't take the host OS down with it. A driver is much more difficult to debug anyway.
It's also more portable and easier to install. ;)
Yup, if it follows standards and doesn't use any APIs you can just copy and compile. Command line apps are simple to port.

Speaking of command line applications, that's probably a good way to go, and what I intend to do eventually. You could add functionality to take parameters from the command line and do things automatically, such as update a file in place. Then just whip up a shell script / batch file to replace the kernel file in the image with your just compiled version and presto, you're good to go.
jal
Member
Member
Posts: 1385
Joined: Wed Oct 31, 2007 9:09 am

Post by jal »

Brynet-Inc wrote:FUSE only supports a handful of operating systems... It would be far easier to make a portable utility in C.
Then again, the OP specifically asked for a Linux solution.


JAL
Post Reply