FUSE filesystem?

Programming, for all ages and all languages.
Octocontrabass
Member
Member
Posts: 5512
Joined: Mon Mar 25, 2013 7:01 pm

Re: FUSE filesystem?

Post by Octocontrabass »

zap8600 wrote:What I could do is make a disk image, make a FUSE driver, open the image with the driver, make a file, close the image, and open the image in a hex editor. Then I could look at the file and, if I ever get disk access working, implement my own way to read files.
FUSE is just an API that allows userspace filesystem drivers to talk to the Linux (and BSD?) kernel VFS. If you're designing a new filesystem for your OS, you won't be able to get away from writing both a filesystem driver and a VFS.

It might be a good idea to write your filesystem for Linux using libfuse first, so you can test your filesystem code and design outside of your OS.
zap8600 wrote:If there is a way to make files with inodes without needing disk access, I would like to know. That would be much appreciated.
You probably want a RAM drive. Making one is pretty simple: allocate some memory, and pretend the contents of that memory are on a disk. When your filesystem driver asks to read or write a block, you read or write from that allocated memory instead of from a hard drive.
zap8600
Member
Member
Posts: 195
Joined: Tue Nov 02, 2021 11:26 am
Libera.chat IRC: zap8600

Re: FUSE filesystem?

Post by zap8600 »

Hi. I think I'm starting to understand. Sooo.. how do I use the RAM disk? I have my own bootloader, so I can't load it with GRUB. Also, how would I make a filesystem with libfuse? I've looked at it before. Do I use the passthrough examples? Would I be able to create my own file structures? If I could get answers, that would be much appreciated.
Octocontrabass
Member
Member
Posts: 5512
Joined: Mon Mar 25, 2013 7:01 pm

Re: FUSE filesystem?

Post by Octocontrabass »

zap8600 wrote:Sooo.. how do I use the RAM disk? I have my own bootloader, so I can't load it with GRUB.
Load the disk image somewhere in memory, then tell your kernel where it was loaded.
zap8600 wrote:Also, how would I make a filesystem with libfuse? I've looked at it before. Do I use the passthrough examples? Would I be able to create my own file structures?
I think the passthrough examples do a pretty good job of showing off the libfuse API. There's also documentation for each of the callbacks, if you look around a bit. You'll decide how to turn the libfuse callbacks into reading and writing structures on the disk, so you can design your own structures. When you design your structures, keep in mind that disks are block devices: you can only read or write whole blocks, not individual bytes. The two most common block sizes are 512 bytes and 4096 bytes.
zap8600
Member
Member
Posts: 195
Joined: Tue Nov 02, 2021 11:26 am
Libera.chat IRC: zap8600

Re: FUSE filesystem?

Post by zap8600 »

Hi. So what you're telling me is that if I use libfuse, I can r/w to the disk without disk drivers? Sorry if I'm not properly understanding.
Octocontrabass
Member
Member
Posts: 5512
Joined: Mon Mar 25, 2013 7:01 pm

Re: FUSE filesystem?

Post by Octocontrabass »

zap8600 wrote:So what you're telling me is that if I use libfuse, I can r/w to the disk without disk drivers?
No. If you use libfuse, you can use Linux to read/write the disk. Linux has disk drivers.
zap8600
Member
Member
Posts: 195
Joined: Tue Nov 02, 2021 11:26 am
Libera.chat IRC: zap8600

Re: FUSE filesystem?

Post by zap8600 »

Hi. So basically, I can go through the Linux kernel code and grab the code? If so, then what file am I looking for? Does it use inb and outb (or something similar) to r/w to the disk?
Octocontrabass
Member
Member
Posts: 5512
Joined: Mon Mar 25, 2013 7:01 pm

Re: FUSE filesystem?

Post by Octocontrabass »

No, I was suggesting that you use libfuse to test your filesystem in Linux before trying to make it work in your OS. You would still need to write your own disk drivers for your OS.

(If you really wanted to, you could copy Linux code as long as you follow the license, but that's not what I'm suggesting here.)
zap8600
Member
Member
Posts: 195
Joined: Tue Nov 02, 2021 11:26 am
Libera.chat IRC: zap8600

Re: FUSE filesystem?

Post by zap8600 »

Hi. Now I think I understand. So first, I make my filesystem. Then I test it in Linux. After that, I try to add disk access to my OS. Then I test the disk access (probably by making a .bin file, adding data to it with a hex editor, adding it to the OS image, running it in QEMU, and trying to read that data) and see if it works. But first, I have some questions. First, can I change the structure of a file? I want it to start out simple, probably as a flat filesystem, and as I continue developing my OS, I'll make it more advanced. Second, what functions does my filesystem need just to work? I think it only needs readdir and getattr.
Octocontrabass
Member
Member
Posts: 5512
Joined: Mon Mar 25, 2013 7:01 pm

Re: FUSE filesystem?

Post by Octocontrabass »

zap8600 wrote:First, can I change the structure of a file? I want it to start out simple, probably as a flat filesystem, and as I continue developing my OS, I'll make it more advanced.
It's your filesystem, you can change it however you like.
zap8600 wrote:Second, what functions does my filesystem need just to work? I think it only needs readdir and getattr.
As far as libfuse is concerned, you don't need any functions, so pick whichever ones sound useful. I think those two are enough to navigate (sub)directories, but you won't be able to read any files!
zap8600
Member
Member
Posts: 195
Joined: Tue Nov 02, 2021 11:26 am
Libera.chat IRC: zap8600

Re: FUSE filesystem?

Post by zap8600 »

Hi. What I meant in my first question, is if it possible to change the structure of a file, and if so, then how?
Octocontrabass
Member
Member
Posts: 5512
Joined: Mon Mar 25, 2013 7:01 pm

Re: FUSE filesystem?

Post by Octocontrabass »

I don't understand the question. What structure are you talking about?
zap8600
Member
Member
Posts: 195
Joined: Tue Nov 02, 2021 11:26 am
Libera.chat IRC: zap8600

Re: FUSE filesystem?

Post by zap8600 »

Hi. If I remember correctly, it is something like this:

Code: Select all

struct FILE {
    char name; 
    int uid;
    int size;
    int type;
}
It basically defines the parameters of a file. You would probably have to make some of them uint32 and some of them unsigned. This is the simplest structure I could come up with.
Octocontrabass
Member
Member
Posts: 5512
Joined: Mon Mar 25, 2013 7:01 pm

Re: FUSE filesystem?

Post by Octocontrabass »

I still don't understand. Where is this structure used?
zap8600
Member
Member
Posts: 195
Joined: Tue Nov 02, 2021 11:26 am
Libera.chat IRC: zap8600

Re: FUSE filesystem?

Post by zap8600 »

Hi. I believe it is in the fuse_common.h file.
Octocontrabass
Member
Member
Posts: 5512
Joined: Mon Mar 25, 2013 7:01 pm

Re: FUSE filesystem?

Post by Octocontrabass »

That file is part of the libfuse API. If you change any of the structures in it, your code won't be compatible with libfuse anymore.

If you're designing your own API, you can define whatever structures you like.
Post Reply