Search code examples
iodirectoryoperating-systemfilesystems

what does the author mean by directory structure in operating system?


I'm reading Operating System Concepts by Avi Silberschatz(9thE), in section 11.4 File-System Mounting, the author explains the steps of filesystem mounting as follows:

  1. The operating system is given the name of the device and the mount point—the location within the file structure where the file system is to be attached.
  2. Next, the operating system verifies that the device contains a valid file system.
  3. Finally, the operating system notes in its directory structure that a file system is mounted at the specified mount point.

I'm confused with the final step, since to the best of my knowledge, the directory structure is stored somewhere on the disk, which records the files' information -- such as name, location, size, and type. Then what does the author mean by directory structure in operating system? Is it the same directory on disk?

Additionally, which part finishes the conversion from file name to physical address on disk? Is it the disk driver or the disk controller or done by processor with memory?


Solution

  • What you are reading is largely nonsense. To begin with, it is eunuchs specific. Eunuchs variants tend to have a single directory structure containing all disks and even things that are not really files.

    Let us assume that you are on Windoze. If you mount a disk the drive gets a name, typically a single letter but larger names are possible in some cases. Let's say you mount a disk drive, and the system assigns it to "Q:".

    So now Q: is available and you can access files, by specifying something like "Q:\dir1\dir2\file.type"

    You are just accessing the directory structure that exists on Q:.

    Each drive has a separate, independent directory structure.

    Many operating system operate this way and your sequence above is irrelevant to them.

    Eunchs variants do not work this way. The system maintains a single directory starting at "/" which is the root directory for the system. This is a directory maintained by the operating system and does not exist at all on a disk drive.

    On a Mac, for instance, there is a "/Volumes" directory that contains all the drives mounted. These too are directories maintained by the operating system and do not exist at all on a disk drive.

    "/Volumes/Macintosh HD" "/Volumes/Backup Drive"

    These system directories then link to the directories that are stored on those disks. Thus, in Eunuchs, there are directories maintained by the operating system and directories maintained on the disk that are merged together.

    So if you want to find "/Volumes/Backup Drive/dir/something.txt" the system goes to the root "/" finds "Volumes" and determines this is a system directory. Finds "Backup Drives" and determines this is a disk drive that has been mounted. Goes to the root directory of the drive and find that "dir" is a directory on the drive, and finds the file something.txt.

    To add to the confusion, there are disk formats that have no directory structure at all. But this illustrates that your book is taking you on a confusing path.

    Each disk drive has a format of some kind. E.g., NTFS, ODS-11, FAT, ....

    What I am telling you from here on is generalization of what typically happens but there are large variations in how it works among systems.

    Typically, each drive will have a header that includes a description of block clusters in use (often a bitmaps) and files on the disk. The file description will usually have a file name, date created, owner, etc. The file description will also have information about where the data is stored on the disk.

    The drive often will have a directory structure in which there is some file it defines as the root directory. The directory structure exists by creating directory files within other directory files. A directory is normally just a file that has a list of file names and the address of their description in the the disk header. Other file attributes, such as the file size and date of creation, are not stored in the directory.You get that from the file description in the disk header.

    The file structure in the disk header is separate from the directory structure. In fact, it is often possible to create a file that is not even in a directory at all. Or you can put a single file in multiple directories.

    If your disk gets trashed and has to be recovered, this is usually done by looking at the disk header. You get back your files but lose your directory structure.

    Additionally, which part finishes the conversion from file name to physical address on disk? Is it the disk driver or the disk controller or done by processor with memory?

    The logical location on the disk is specified in the file description in the disk header. The format of that information is specific to the underlying disk format. Generally you have two paths to reach the file description:

    1. You can go through the list of file headers maintained by the disk; or

    2. You can navigate a directory structure until you find the file name you want with a link to the file description.