Document directory
Ø root file system: Root filesytem should be used in English, but sometimes it is simply called a file system. In fact, it refers to some files required for Linux system running as described in the previous section, and the entire file directory structure composed of commands.
Ø File System: The English format should be file system or filesytem. It refers to a method used to facilitate the management of file storage and data organization. For example, fat, FAT32, NTFS in windows, ext2, ext3, and NFS in Linux all belong to this concept.
Therefore, the root file system and the file system are two concepts. Do not misunderstand them. For ease of understanding, you can understand the file system as the format in which the root file system is stored on the disk.
RFs and FS
"File System" and "root file system ".
Otherwise, we will refer to them as FS and RFS:
File System: File System => FS;
Root file system: root file system => RFS.
First, consider a description statement: the root file system is also a "File System", which can be considered as a "special" File System ", why is it "special? This is because such "root" and "File System" carry some "special functions" (In fact, if the "File System" is the same, all functions are the same ), that is, the "Operating System" may need to manage related devices through some "layout", such as floppy disk devices, hard disk devices, and virtual disk devices, here, we may use a "layout" that has been defined as "Data Structure", that is, "File System ", the "root file system" may be used to assume a major or important role.
(In terms of image, the C drive partition in Windows has a certain file system, such as FAT32 and NTFS, which are also file systems. When installing the Windows operating system, you will be asked to "format" drive C [of course, we currently consider that the operating system is installed in drive C], A "File System" such as NTFs and FAT32 is used. This step is similar to installing the "root file system ", that is to say, the NTFS file system in drive C is called the "root file system ", the NTFS file system in disk D is called a "File System" or you want to add a prefix name, such as "Common File System ", in terms of name, there is a word "root" here, so we have two names: FS and RFS, therefore, such names will make people feel like they are "in the fog", and then "zhuyun"], in this "formatting" process, the storage space on the C disk is initialized according to the pre-defined FS "Data Structure". [Here we assume that minix
FS can also be used by windows to "format" A drive C] such as creating a boot block, creating a super block, creating two types of Bitmap blocks, creating an I-node bitmap block, and creating a data block) that is to say, this disk partition must have organized the disk space according to a certain data structure, so as to "A system" (OS or FS, it seems that FS is more accurate) the partition can be accessed, so there are two differences in the 0.11 kernel: mount_root () and sys_mount (), they refer to "mount the root file system" and "mount the file system". [here I don't think we should use the word "Install! What I understand is that "installation" means to "put" something on another thing. For example, if you want to install some software on the C drive, the installation program of this software may be on disk D. Then you will start the installation program of the software on disk D, and then the installation program will install the software on disk C by default, therefore, this process is called "installation". The C disk does not have any information about the software before installation. After installation, the C disk will have information about the software, to use the sys_mount () function, a certain device (specifically a partition) must have been "installed" by a certain FS format, then the device will be mounted to "one place.
Let's analyze it with minix FS and fat FS.
In the 0.11 kernel code, we can see from the comments in mount_root (void) that this function will be called by the "System Call function" sys_setup (), and the function sys_setup () is used when the system is set to initialize upon startup () will be called. Why not call sys_mount? So when will we use the sys_mount () function? In fact, the sys_mount () function is also a "system call function ". In Linux, when you enter mount in a shell command line and press enter, you will see the following prompt:
Mount: Usage: Mount Dev dir
You should probably be clear, and this is the "Correct prompt information", because we use the wrong Mount usage (In addition, in the/bin directory, we can see a file such as Mount, mount should be a separate program. In many cases, Mount is an internal shell command, and I may think that CD is one of the internal shell commands ).
We can see from the comments of the sys_mount () function that this function is a "Install file system call function" (I personally think this sentence is not very easy to understand ), I know the functions of a function, so I will understand it as follows: this function is a "system-called function ", the function is to mount a 'file system' (FS) to a "directory" (the existing 'root File System' (RFS), that is, the I node of the directory file. Therefore, this corresponds to the prompt information such as "Mount Dev dir". In addition, Dev indicates a partition on a device, dir indicates a "directory file" in an "existing" File System. Note that it must be "existing". Here is what we call "root file system ", therefore, to use the Mount function, you must have the following conditions:
1. Under an existing "File System" (root file system RFS)
2. Some device files already exist in the RFS, such as hd0 and hd1 in/dev.
In 3 and 2,/Dev is actually managed by RFS.
4. A directory also needs to exist, which is also managed by RFS in The RFS.
5. Of course, you need to have the actual disk device (/dev/hd0 only indicates a "virtual" device file name) and the device has been formatted by "FS"
6. Finally, you will use the Mount Dev dir method to mount the actual disk partition to the Dir.
Assume that you have a hard disk (assuming the size is 512 MB), it is just a partition, And the FS in this partition is fat FS (assuming UNIX can be accessed directly, the big deal is that it is the same as minix FS, but the name is different. Here we think of it as a minix Fs for analysis ).
So after you start "0.11 system" (which is simplified, that is, you enter the sh command line, in fact, RFS has been "automatically" mounted "(that is, mount_root (). In this case, you need to access the hard disk in the" 0.11 system, assume that you have installed the hard disk on the hardware, and then you will perform the "installation" process in the sh command line, for example:
Mount/dev/hd0/mnt/fatc
Attach the first partition (currently only one partition) of the first hard disk to the fatc directory in the MNT directory under the root directory of RFs. Therefore, you can directly access the files on the hard disk in the fatc directory.
Successful! Mounting successful. Success!
Because you understand the kernel code, you should be aware of the Mount process. You need to know the following points:
1./dev/hd0,/mnt/fatc are all "Files" in RFS. The former is a device file, and the latter is a directory file.
[It is reflected in the I node structure, that is, the inode-> I _mode will distinguish between "Device Files" and "directory Files ", and the former inode-> zone [0] contains the device Number of the device (and inode-> I _dev is also the device number, but the actual meaning is different ), the inode-> I _mount of the latter is set. Note that this I node is an I node that has been "installed"/"mounted"]
2./This is the directory, but this is the RFS directory and the root directory.
3./mnt/fatc "equivalent" is the root directory of the FS in the hard disk partition. But the root directory of the hard disk is /.
[Assume that when you access the "root" directory of the partition (in fact, it is also/, but can you directly go in ?) File hello. c. In the existing sh command line, press "CD/mnt/fatc" and then "ls hello *-L". Then, you will find "hello. in this file C, you should know how RFS "locates" to find the hello. in file C, an important process is to take the inode information of each file, that is, the iget () function. In this function, when inode-> I _mount of a file is set to a bit, it's just "very careful". Why? Because the inode indicates that a file system is "mounted", RFS will "Switch" to the root directory of that FS (using root_ino, super_block [I]. s_dev), and then continue searching for the required files in the FS according to the normal process, so you can find]
"Normal process" means to either search for files from the root directory of a FS, or to find files from the current working directory of the current user process of a file system.
So there is an important saying (I understand this): Cross-file system access to files. This process involves a wide range of data structures, including I nodes and Super blocks.
4. When you do not need to use this partition or want to take the hard disk away, you will use the umount function, which corresponds to the "System Call function" of sys_umount ", then you need to know what the function has done.
Finally, in general:
Mount_root () mounts a minix FS, also known as RFS.
Then you can mount another FS in The RFS. RFs and the system are "active" and are automatically "mounted" and "uninstalled ".
Therefore, fat and so on can also be the root file system, of course, also the file system.
Therefore, if you have installed multiple operating systems on your computer, if you have installed Win98 on drive C (FAT32 FS) and WINXP on drive D (NTFs FS, when you enter Win98, FAT32 seems to be RFS, and NTFS is FS; when you enter WINXP, NTFS seems to be RFS, and FAT32 is FS.
(Why is the C drive FAT32? Because Win98 does not support ntfs fs, And you have installed Win98)