0

I have found the following image on the web:

enter image description here

What I understand from this image is that if for example Process 1 wants to read some file, it will do the following:

  • Call read() and pass the file descriptor for the file as argument to read().
  • The Virtual File System will check to see on what filesystem type the file resides on, let's say that it resides on an ext2 filesystem.
  • The ext2 driver (don't know if it's called "driver") will ask the appropriate device driver to retrieve the file from the HDD.

Now what I want to know is: what does the "Device driver" box in the image represent, does it represent device files such as /dev/sda1, /dev/sda2, /dev/sdb1, etc.?

So basically does Linux actually uses these device files to access the HDD (i.e. when Linux wants to read some file, does it call open() on the /dev/sda1 device file and then read from the returned file descriptor), or are these device files only available for the users and programs to use them, and Linux uses some other means to access the HDD partitions?

3

So basically does Linux actually uses these device files to access the HDD (i.e. when Linux wants to read some file, does it call open() on the /dev/sda1 device file and then read from the returned file descriptor), or are these device files only available for the users and programs to use them, and Linux uses some other means to access the HDD partitions?

No.

The Linux kernel is implementing syscalls(2); it is not directly using them.

System calls make sense only in user-mode application code. Kernel code is running in kernel mode. Read about CPU modes.

Of course, open(2)-ing then read(2)-ing some disk partition like /dev/sda1 indirectly involves some kernel code which is shared and used by other kernel code (eg notably by the page cache and file system code).

are these device files only available for the users and programs to use them, and Linux uses some other means to access the HDD partitions?

Yes, kernel code don't use device files such as sd(4) (but some code layer is shared somewhere). Kernel don't use (but just provides to user processes when they use system calls) file descriptors and deal with kernel inodes and other data (dentries, vfsmounts, ...). Some other kind of inodes are written on the disk by the file system layer.

what does the "Device driver" box in the image represent,

It represent kernel code (read device driver wikipage) related to SATA disks and to your chipset.

Read Operating Systems : Three Easy Pieces (freely downloadable) since an entire book is required to explain all that. Then see kernelnewbies for Linux kernel specific things and study the kernel source code (it is free software) from kernel.org

(this is a gross simplification; kernel code is modular and organized in software layers, such as VFS, SATA bus, etc....)

  • This might be getting into too much detail, but instead of saying the kernel deals with inodes, it would be more accurate (for Linux) to say that the kernel deals with directory entries (dentries), inodes, and vfsmounts. (You need all three to represent all the data involved in using a file descriptor.) – Stephen Kitt Sep 28 '17 at 22:41

Your Answer

By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Not the answer you're looking for? Browse other questions tagged or ask your own question.