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

I'm trying to build a new filesystem with deduplication using FUSE.
I tried running the fusexmp_fh.c provided in the example section of the FUSE. However after mounting the filesystem at a mount point, I can see all the existing directories inside the mount point. I dont need those directories. I want the mounted filesystem to be empty.
I tried searching through fusexmp_fh.c but could not find out where the existing directories get added.
Can someone explain to me how this works?
Also
can fusexmp_fh.c be taken as a base for building the filesystem?
Does it have all the basic functionalities?

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.)

Related

MiniDLNA: not recognizing additional mount points

I have a volume mounted at /media.
I have an additional volume mounted at /media/dvd.
I have mounted things this way as I understand that minidlna can only use a single directory for, say, videos.
Each volume is structured with sub directories. On the main director, /media everything works, the folder structure works, and adding new files appear automatically.
I cannot get minidlna to recognise the /media/dvd directory. I have tried to restart, force-reload, and even deleted the files.db file to force a refresh.
I don’t know whether the issue is:
The fact that I have one mount point inside another
The permissions need fixing
The fact that the second volume /media/dvd is HFS+; the volume mounts well enough and I can read & write from the shell (touch test).
Something else … ?
I am running Centos 6.

In a kernel module, how to know whether given inode belongs to a specific directory?

One possible way is that, compare given inode with list of inodes in that directory. The list of inodes could be predetermined or it can be calculated run time, both ways have their own problems:
Predetermined list: List can be changed during this operation, i.e. files could be added or removed from that directory.
Run time list: If that directory has too many files, it's too much overhead for each access of any file in the system.
Is there any efficient solution/way for this? I have tried by comparing file by it's path, which was really a bad idea.
Either if you do it in kernel mode or in user mode has no advantages. To see if an inode is indeed in some directory you have to read that directory as files are located in directories normally as a linear list. This can lead your process blocking for directory blocks to be present if not cached and, in that time, the directory contents can be modified. Only if you maintain the directory inode blocked while doing that operation can help, but this can add severe performance restrictions to your operating system. Another issue is that each filesystem is free to implement directory contents in it's own format. In userland you get an uniform directory format, but in kernel mode you have to deal with the different approaches for different filesystem types. Why do you need to know that? I can't imagine a scenario where this can be needed. Perhaps you can redesign your algorithm for the directory contents to be unnecessary.
By the way, dealing with complete paths or searching directories have obscure race conditions that can deal your system blocked someway. What can happen if, in the middle of your seach, somebody tries to unlink the inode you are searching for; or the directory contents must be modified; or some other process is using namei() to traverse through your directory upwards; or downwards. Have you think in all these possibilities?

Once you mount a file system, how do you use it?

I understand that a file system can be visualized as a "tree" of files and directories. I also understand that "mounting" a file system means to placing or rooting that tree within an existing directory. https://askubuntu.com/questions/20680/what-does-it-mean-to-mount-something
With that said, I have mounted an implementation of python fuse that is similar to this one. When I run my implementation, it runs to the end of the init method and then just shows a blinking cursor. So fuse is getting mounted. I know that fuse is mounted because of what happens when I run $mount
$mount
...
FuseHandler on /home/memsql/mount
So now that I've mounted fuse, how do I access the files.
The linked tutorial says
You will see all files in /your/dir under /mnt/point and be able to
manipulate them exactly as if they were in the original filesystem.
How exactly do you do this? Can somebody show me, syntactically, how to instantiate and query Fuse? How do you perform a read or write? What does code that performs those operations look like?
As l4mpi notes, you’ve now mounted a file system, so it will respond to the standard Unix file system API, and FUSE will handle the file system operations. You can cd to it, ls in it, read or creat files in it, etc.

Query with mv linux command

I used the following linx command :
mv RegisteredOutputs.msg registered_outputs.tcl
My intention was to achieve the following :
mv RegisteredOutputs.msg registered_outputs.msg
The directory in which I issued the command already had a file named registered_outputs.tcl .
So by far you might have figured out what my issue is. registered_outputs.tcl got overwritten. Is there any way of recovering it ?
First thing you always do: Boot a live CD/USB so that your partition is mounted read-only, to avoid those spaces on the drive being re-used. Once another file uses that platter space, the data is gone.
Because of how Linux ext3 file system works, it actually zeroes out inode data on delete, making recovery impossible. This is for delete however, and I don't know if the same could apply to overwriting existing files. Hope you're feeling lucky.
See this guide on how to recover deleted files on ext3
source:
recovery of overwritten file

Checksum of a loop device file exactly reproducible?

how can I mount and unmount a file as loop device and have exactly the same MD5 checksum afterwards? (Linux)
Here's the workflow:
I take a fresh copy of a fixed template file which contains a prepared
ext2 root file system.
The file is mounted with mount -t ext2 <file> <mountpoint> -o loop,sync,noatime,nodiratime
( Here, some files will be added in future--but ignore this for a moment and focus on mount / umount )
umount
Take the MD5 sum of the file.
I expect the same, reproducible checksum every time I perform exactly the same steps.
However, when I repeat the process (remember: taking a fresh copy of the template file), I always get a different checksum.
I assume on the one hand that still some timestamps are set internally (I tried to avoid this with the noatime option) or, on the other hand, Linux manages the file system on its own way where I have no influence. That means: the files and timestamps inside might might be the same, but the way the file system is arranged inside the file might be differnt and therefore kind of random.
In comparison, when I create a zip file of a file tree, and I touched all files with a defined timestamp, the checksum of the zip file is reproducible.
Is there a way to keep the mount or file access that controlled as I need at all?
it depends on the file system on disk format. I believe ext2 keep sat the least the mount count counter - how many time the file system was mounted. I don't remember any mount option to tell it not to write that counter (and perhaps other data items) but you can:
a. mount the file system read only. Then the checksum will not change of course.
b. Change the ext2 file system kernel driver to add an option to not change the counter and possible other data bits.
The more interesting question is why you are interested is such an option. I think there is probably a better way to achieve what you are trying to do - whatever it is.

Resources