What Happens If You Mount to a Non-Empty Mount Point with Fuse

how does all the existing directories get mounted at the mount point when using FUSE?

Are you saying that you mounted the file system over a non-empty directory, and you can see the previous contents of the directory? (In which case, the answer is "don't mount to a non-empty mount point". Usually it throws an error to tell you not to do that.)

If what you're seeing is the directories and files in the directory that you are using as your base directory, that's the normal behavior for a loopback file system, which is what fusexmp_fh.c is. The example file system takes a mount point, and passes all commands on that mount point through to a backing directory. If you use a backing directory that has files in it, you will now see those files in two places, the original location and the mounted fuse directory.

If you want to understand how the directory filling works, start by taking a look at readdir, and see how the stat items that it returns are constructed. Each of those is a single directory entry.

Yes, you can use fusexmp_fh.c as the basis for a basic file system, it's got all the necessary pieces, although extended metadata isn't supported. (But adding it is fairly trivial for a loopback.)

How to tell fuse3 that you need a device and a mount point in command-line arguments

so for this you will have to restrict the user on the order of the cmd arguments(all fuse/mount options come before the devicepath and mountpoint). To make it simple, ensure that the path to the device and mount point are provided last:

So in your main function, this statement will check that there is a correct number of arguments and the mount point and device do not start with hyphens as with options.

    if ((argc < 3) || (argv[argc-2][0] == '-') || (argv[argc-1][0] == '-'))
{
fprintf(stderr, "usage: ./myfuse [FUSE and mount options] devicepath mountPoint\n");
abort();
}

Then extract the device path and store it in a struct:

struct my_state *my_data;
my_data = malloc(sizeof(struct mi_state));
if (mi_data == NULL) {
perror("main calloc");
abort();
}

my_data->devicepath = realpath(argv[argc - 2], NULL);
argv[argc-2] = argv[argc-1];
argv[argc-1] = NULL;
argc--;

Notice that I remove the device paths from argv and decrement argc by 1 before passing hem to the fuse_main function
Then while calling the fuse_main function make sure to pass the my_data struct:

fuse_main(argc, argv, &my_fuse_operations, mi_data);

Here is the defination of the my_state struct which you can put in a header file:

struct my_state{
char *devicepath;
};

You should also add this definition in the header file below the struct definition:

#define BB_DATA ((struct mi_state *) fuse_get_context()->private_data)

And also in your init function call fuse_get_context and return BB_DATA:

void *my_init()
{
fuse_get_context();
return BB_DATA;
}

The return value will be passed in the private_data field of fuse_context to all file operations and as a parameter to the destroy() method.
The fuse_context is set up before this function is called, and fuse_get_context()->private_data returns the user_data passed to fuse_main().

s3fs unmount: directory is not empty

Okay, I feel silly - I figured out the answer right after posting. I'm not supposed to do s3fs umount $PWD/s3, just umount $PWD/s3.

The former is presumably trying to mount another bucket called umount at the same path where the previous one is mounted.



Related Topics



Leave a reply



Submit