1

so I’m making this software that encrypts the files on a computer. A friend of mine (we're both students so don't be too hard on us) suggested I use a Virtual File System. I asked why, and what even is that, and they gave me some half assed answer that didn't help

[I don't know if this is important but I'm on a linux environment]

so no worries I went on Google and searched. But I still don't get it. The explanations, especially the one on Wikipedia doesn't make sense to me. What is a VFS? What is the actual need, or advantage to using a Virtual File System? As opposed to just, not?

I'm asking because I'm actually curious, and if it is that useful, I'd like to implement it into what I'm making.

Thank you

(also any links or books or something I could read on that would expand on my knowledge would help too)

kmkmkmkmkm
  • 69
  • 1
  • 7
  • 3
    A virtual filesystem is usually a kernel layer that abstract real filesystems for your OS. You access every file the same way even if the underlying FS is NTFS, HFS, Ext4, etc. VFS masks you different technical details about differences among real FSes. Probably nothing to do with your initial problem or you may want to implement a crypto-FS? – Jean-Baptiste Yunès Feb 11 '17 at 13:45
  • 1
    Stack Overflow is a site for programming and development questions. This question appears to be off-topic because it is not about programming or development. See [What topics can I ask about here](http://stackoverflow.com/help/on-topic) in the Help Center. Perhaps [Super User](http://superuser.com/) or [Unix & Linux Stack Exchange](http://unix.stackexchange.com/) would be a better place to ask. Also see [Where do I post questions about Dev Ops?](http://meta.stackexchange.com/q/134306) – jww Feb 11 '17 at 16:13

2 Answers2

3

Very generally speaking, the VFS is a layer of abstraction. Think of the VFS like an abstract base class that has to be used when you want to implement your concrete class of file system like NTFS, Ext3, NFS or others. It offers basic functionality that the concrete file systems can use, but also is an interface that the concrete classes have to implement against.

No idea if that was what you were looking for. Let me know if it wasn't and I can add more detail.

cfromme
  • 470
  • 4
  • 11
2

The VFS is part of a kernel and is a unified abstraction layer used by file systems and user applications that presents multiple local or network file systems in a common accessible format, regardless of the file system of the volume the files are on, the location of the volume the files are on (local or network), the bus / controller / storage standard or network protocol, or whether the file system is mounted on a volume or file system + volume is mounted at a mount point, allowing it to be accessible anywhere.

The VFS includes:

  • File IO / file mapping / file metadata / directory traversal APIs which call the underlying file system that is mounted to the volume no matter what the file system is.
  • API for file system drivers to be notified of volume arrival such that they can identify whether their file system is on the volume
  • API for file systems to perform read / write operations on the volume with their file system without knowing the underlying bus / controller / storage transfer standards, or the network storage (block, file) / transport / network / data link / physical protocols, or the physical partition or sector of the volume on the storage medium (only the logical cluster within it), or the operation of the storage medium (other than knowing whether or not external fragmentation matters).
  • Reparse point functionality such as mount points, directory junctions and symbolic links -- it reparses the filepath (unlike a hard link) to produce a file path for the underlying file system to access
  • Caching pages of files so they can be fetched from RAM without having to call the file system, and only having to call the file system on a file cache page miss (see comments).
  • Prefetching parts of a file around a page miss (demand paging) or prefetching associated files or dynamic libraries i.e. prefetch on Windows or even Superfetch.

A file explorer GUI application can then use the API to interact with the virtual file system representation of the volumes, and the VFS calls the underlying file system, which then read/write to their volumes through the VFS. The file explorer can then visually represent the virtual file system representations of the volumes on a common interface

Lewis Kelsey
  • 4,129
  • 1
  • 32
  • 42
  • Another important part is caching of file data, and of metadata, in a unified way. If a path lookup hits in the VFS cache, it doesn't even have to call into the driver for whatever filesystem that path component is handled by. So VFS-cache access doesn't have to go through any layers of abstraction and can thus be faster. – Peter Cordes Mar 11 '21 at 08:41
  • @PeterCordes yes, I was debating whether the file cache would be considered part of it. I don't know how it is on linux so the nomenclature might be more explicit there – Lewis Kelsey Mar 11 '21 at 09:57
  • Yeah, Linux documentation and /proc stats files definitely talk about "VFS cache", e.g. this old documentation https://www.usenix.org/legacy/publications/library/proceedings/usenix01/full_papers/kroeger/kroeger_html/node8.html showing inode cache and directory cache. (And pagecache for file data, and buffer cache for block-device data.) Ah, current kernel docs still talk about caching as an important part of the VFS: https://www.kernel.org/doc/html/latest/filesystems/vfs.html – Peter Cordes Mar 11 '21 at 10:08
  • 1
    @PeterCordes I think you can include prefetching then as well – Lewis Kelsey Mar 11 '21 at 10:53