Page 2 of 6

Re: FUSE filesystem?

Posted: Thu Nov 11, 2021 6:37 pm
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.

Re: FUSE filesystem?

Posted: Fri Nov 12, 2021 9:00 am
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.

Re: FUSE filesystem?

Posted: Fri Nov 12, 2021 10:17 am
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.

Re: FUSE filesystem?

Posted: Fri Nov 12, 2021 10:24 am
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.

Re: FUSE filesystem?

Posted: Fri Nov 12, 2021 11:36 am
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.

Re: FUSE filesystem?

Posted: Fri Nov 12, 2021 12:14 pm
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?

Re: FUSE filesystem?

Posted: Fri Nov 12, 2021 12:39 pm
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.)

Re: FUSE filesystem?

Posted: Fri Nov 12, 2021 2:08 pm
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.

Re: FUSE filesystem?

Posted: Fri Nov 12, 2021 2:42 pm
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!

Re: FUSE filesystem?

Posted: Fri Nov 12, 2021 6:08 pm
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?

Re: FUSE filesystem?

Posted: Fri Nov 12, 2021 6:20 pm
by Octocontrabass
I don't understand the question. What structure are you talking about?

Re: FUSE filesystem?

Posted: Fri Nov 12, 2021 10:47 pm
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.

Re: FUSE filesystem?

Posted: Fri Nov 12, 2021 11:53 pm
by Octocontrabass
I still don't understand. Where is this structure used?

Re: FUSE filesystem?

Posted: Mon Nov 15, 2021 9:15 am
by zap8600
Hi. I believe it is in the fuse_common.h file.

Re: FUSE filesystem?

Posted: Mon Nov 15, 2021 10:45 am
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.