3

In Tanenbaum's Modern OS book, for Linux file systems, there are two sketches:

enter image description here

enter image description here

In both sketches, specific file systems (e.g. ext4 type) ( "File systems" in the first sketch, and "File system 1" in the second sketch) is listed under "Virtual file system".

The difference is that

  • in the first sketch, "File systems" is listed at the same level as "Terminals" and "Sockets", and doesn't include the latter two,
  • in the second sketch, "File system 1" includes "Regular file", "Block special file", "Char special file", and "Network socket".

My understanding is that the two sketches are showing the same thing, so they should be consistent.

My question is

  • Do specific file systems (e.g. ext4) implement device files and make them treat the same as regular files, or is it the job of the "virtual file system"?

  • How shall I understand the difference between the two sketches, mentioned above for relation between "File systems" and "Network sockets", "Block/Char special file"?

Tim
  • 1
  • 141
  • 372
  • 590

1 Answers1

3

File systems have inodes, which know about char devices and block devices (and return them, e.g. thru stat(2) syscall).

When your program (and process) opens a char device (in some file system), the kernel will use some device driver, often related to the device major number.

The Ext2 wikipage has a nice picture (showing inodes & data) which is grossly applicable to Ext4 (but of course, many details have changed).

The VFS is an abstraction layer in the kernel. See a tour of VFS and look inside the kernel source code.

An ordinary file system (e.g. an Ext3 one) may contain char device inodes (visible as e.g. char device file in some directory), but many new Linux systems are conventionally using the devfs pseudo-file system (mounted on /dev/) for them (related to udev & systemd).

Basile Starynkevitch
  • 223,805
  • 18
  • 296
  • 547
  • Thanks. could you also answer my questions directly? – Tim Dec 13 '15 at 16:57
  • I am not sure your questions have some precise meaning and answer. You might be slightly confused. The important notion is that a file system contains inodes and data. – Basile Starynkevitch Dec 13 '15 at 16:57
  • Does "a file system" in your " a file system contains inodes and data" mean a specific file system (e.g. ext4) or can it also be a "virtual file system"? – Tim Dec 13 '15 at 16:59
  • VFS is an interface abstraction to implement real file systems. – Basile Starynkevitch Dec 13 '15 at 17:00
  • are device files (block or character files) and sockets in the same file system as regular file systems, or do device files (block or character files) and sockets have their own file systems, different from the file systems for regular files? It seems the latter on my Ubuntu, but the second sketch shows a single file systems for regular files and device files. – Tim Dec 13 '15 at 17:02
  • You can have a char device inode in some Ext4 system. But modern Linux have a *devfs* for them – Basile Starynkevitch Dec 13 '15 at 17:11