One: Root file System (ROOTFS)
Registration of the 1,rootfs file system
In the Linux kernel initialization phase, an int __init init_rootfs (void) is called to register the Rootfs file system with the kernel.
The function of the core of Init_rootfs () is Register_filesystem (); This function registers the structure File_system_type in a single linked list of the kernel,
[CPP]View Plaincopy
- 307 int __init init_rootfs (void)
- 308 {
- 309 int err;
- 311 err = Bdi_init (&ramfs_backing_dev_info);
- 312 if (err)
- 313 return err;
- 315 err = Register_filesystem (&rootfs_fs_type);
- if (err)
- 317 Bdi_destroy (&ramfs_backing_dev_info);
- 319 return err;
- 320}
- 288 static struct File_system_type Rootfs_fs_type = {
- 289. Name = "Rootfs",
- 290. Mount = Rootfs_mount,
- 291. KILL_SB = Kill_litter_super,
- 292};
2,rootfs_mount () function parsing
static struct Dentry *rootfs_mount (struct file_system_type *fs_type, int flags, const char *dev_name, void *data)
The Rootfs_mount () function first calls the Mount_nodev () function, and the Mount_nodev () function is prototyped as follows: Mount_nodev (Fs_type, Flags, data, ramfs_fill_super);
[CPP]View Plaincopy
- 1060 struct dentry *mount_nodev (struct file_system_type *fs_type,
- 1061 int flags, void *data,
- 1062 Int (*fill_super) (struct super_block *, void *, int))
- 1063 {
- 1064 int error;
- 1065 struct Super_block *s = sget (Fs_type, NULL, set_anon_super, NULL);
- 1067 if (Is_err (s))
- 1068 return Err_cast (s);
- 1069
- 1070 s->s_flags = flags;
- 1072 error = Fill_super (s, data, Flags & ms_silent? 1:0);
- 1073 if (error) {
- 1074 Deactivate_locked_super (s);
- 1075 return err_ptr (Error);
- 1076}
- 1077 S->s_flags |= ms_active;
- 1078 return Dget (s->s_root);
- 1079}
The function of the Sget () function of the above functions is mainly to allocate a super fast (Super_block) instance, and. Join the list super_blocks by S_list and then join the list s_instances by Typer->fs_supers.
The Fill_super () function is called to the Ramfs_fill_super () function, and the Ramfs_fill_super () function is defined as follows:
[CPP]View Plaincopy
- 209 int Ramfs_fill_super (struct super_block *sb, void *data, int silent)
- 210 {
- 211 struct Ramfs_fs_info *fsi;
- 212 struct Inode *inode;
- 213 int Err;
- 215 save_mount_options (SB, data);
- 217 FSI = Kzalloc (sizeof (struct ramfs_fs_info), gfp_kernel);
- 218 Sb->s_fs_info = FSI;
- 219 if (!FSI)
- Return-enomem;
- 222 Err = ramfs_parse_options (data, &fsi->mount_opts);
- 223 if (err)
- 224 return err;
- 226 sb->s_maxbytes = max_lfs_filesize; //maximum value of the file
- 227 sb->s_blocksize = page_cache_size; //The size of the block in bytes
- 228 sb->s_blocksize_bits = Page_cache_shift; //The size of the block in bits
- 229 sb->s_magic = ramfs_magic;
- Sb->s_op = &ramfs_ops; //Super Block method, which will be useful when dealing with the Inode
- 231 Sb->s_time_gran = 1;
- 233 inode = Ramfs_get_inode (SB, NULL, S_ifdir | fsi->mount_opts.mode, 0); //Establish root index node
- 234 sb->s_root = D_make_root (inode); //Establish the root directory object; The s_root of the Super block points to the newly created root directory object
- 235 if (!sb->s_root)
- 236 Return-enomem;
- 238 return 0;
- 239}
- the *ramfs_get_inode-struct inode (struct super_block *sb,
- const struct inode *dir, umode_t mode, dev_t Dev)
- 56 {
- The inode of the new_inode struct, inode = (SB); //Create an inode in the index node cache,
- if (inode) {
- Inode->i_ino = Get_next_ino (); //Get an inode number
- Inode_init_owner (Inode, dir, mode); //Set Inode, initialize UID GID mode, etc.
- Inode->i_mapping->a_ops = &ramfs_aops;
- Inode->i_mapping->backing_dev_info = &ramfs_backing_dev_info;
- Mapping_set_gfp_mask (inode->i_mapping, Gfp_highuser);
- Mapping_set_unevictable (inode->i_mapping);
- Inode->i_atime = Inode->i_mtime = Inode->i_ctime = Current_time;
- (Mode & s_ifmt) {
- default: //Special files such as: Character ~ block device file, fifo,socket file
- Init_special_inode (inode, mode, dev);
- a break ;
- S_ifreg Case: //Normal file
- Inode->i_op = &ramfs_file_inode_operations;
- INODE->I_FOP = &ramfs_file_operations;
- a break ;
- s_ifdir Case: //directory file
- Inode->i_op = &ramfs_dir_inode_operations;
- INODE->I_FOP = &simple_dir_operations;
- */* directory inodes start off with i_nlink = = 2 (for "." entry) */
- Inc_nlink (Inode);
- Bayi break ;
- S_iflnk Case: //link file
- Inode->i_op = &page_symlink_inode_operations;
- a break ;
- 85}
- 86}
- The return of the inode; //Returns the created Inode associated with the corresponding Catalog item object
- 88}
[File system] File System learning Note (ix)---ROOTFS