For an assignment we have to build a FUSE file system using C. I am trying to create an empty file in the mountpoint directory that I have mounted when I start fuse but it’s not working.
I tried placing the following inside my own implementation of the fuse init function:
FILE * fp = fopen("data.0", "w"); fclose(fp);
After I had done that, what happened when I tried to navigate to the mountpoint was that I got an error: Transport endpoint is not connected
.
When I tried to run FUSE in debug mode using -d
flag, the terminal and FUSE froze and then I wasn’t even able to navigate to the directory containing the mount point.
Then instead I placed the following inside my implementation of read:
mknod("data.0", 33206, 20); // a mode of 33206 means that it's a regular file with permissions 666
And then when I looked at the result of having called mknod()
I got a return value of -1
(error) and an errno
of 1
(operation not permitted).
If I call my read function again (by opening a file), now I still get a return value of -1
(error) but an 1 errno
of 13
(Permission denied). Note that there is only one file in the directory and it’s only there because my readdir
function fills the buffer with that file’s name. There isn’t a physical file in the directory.
I’m probably approaching this all wrong. How do I create an empty file?
Is FUSE only an in memory thing?
OK maybe it might be better to ask this: If I wanted to create a FUSE file system and all that it did was create a physical empty file in the mountpoint and let you access that file, how would I do that?
Advertisement
Answer
It turns out that when FUSE is started, it starts of at the root directory, “/” not the mountpoint that you specified. So by running something such as inside init
:
FILE* fp = fopen("data.0", "w+"); fclose(fp);
FUSE was crashing because the command is being run as the logged user who has no permissions to write in the root directory (“/”).
This was resolved by attempting to create a folder in “/”, granting everyone full permissions, and then writing to that folder:
sudo -s cd / mkdir data chmod 777 data
And then in fuse init
:
FILE* fp = fopen("/data/data.0", "w+"); fclose(fp);