[File system] File System learning Note (ix)---ROOTFS

Source: Internet
Author: User

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
  1. 307 int __init init_rootfs (void)
  2. 308 {
  3. 309 int err;
  4. 311 err = Bdi_init (&ramfs_backing_dev_info);
  5. 312 if (err)
  6. 313 return err;
  7. 315 err = Register_filesystem (&rootfs_fs_type);
  8. if (err)
  9. 317 Bdi_destroy (&ramfs_backing_dev_info);
  10. 319 return err;
  11. 320}
  12. 288 static struct File_system_type Rootfs_fs_type = {
  13. 289. Name = "Rootfs",
  14. 290. Mount = Rootfs_mount,
  15. 291. KILL_SB = Kill_litter_super,
  16. 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
  1. 1060 struct dentry *mount_nodev (struct file_system_type *fs_type,
  2. 1061 int flags, void *data,
  3. 1062 Int (*fill_super) (struct super_block *, void *, int))
  4. 1063 {
  5. 1064 int error;
  6. 1065 struct Super_block *s = sget (Fs_type, NULL, set_anon_super, NULL);
  7. 1067 if (Is_err (s))
  8. 1068 return Err_cast (s);
  9. 1069
  10. 1070 s->s_flags = flags;
  11. 1072 error = Fill_super (s, data, Flags & ms_silent? 1:0);
  12. 1073 if (error) {
  13. 1074 Deactivate_locked_super (s);
  14. 1075 return err_ptr (Error);
  15. 1076}
  16. 1077 S->s_flags |= ms_active;
  17. 1078 return Dget (s->s_root);
  18. 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
    1. 209 int Ramfs_fill_super (struct super_block *sb, void *data, int silent)
    2. 210 {
    3. 211 struct Ramfs_fs_info *fsi;
    4. 212 struct Inode *inode;
    5. 213 int Err;
    6. 215 save_mount_options (SB, data);
    7. 217 FSI = Kzalloc (sizeof (struct ramfs_fs_info), gfp_kernel);
    8. 218 Sb->s_fs_info = FSI;
    9. 219 if (!FSI)
    10. Return-enomem;
    11. 222 Err = ramfs_parse_options (data, &fsi->mount_opts);
    12. 223 if (err)
    13. 224 return err;
    14. 226 sb->s_maxbytes = max_lfs_filesize; //maximum value of the file
    15. 227 sb->s_blocksize = page_cache_size; //The size of the block in bytes
    16. 228 sb->s_blocksize_bits = Page_cache_shift; //The size of the block in bits
    17. 229 sb->s_magic = ramfs_magic;
    18. Sb->s_op = &ramfs_ops; //Super Block method, which will be useful when dealing with the Inode
    19. 231 Sb->s_time_gran = 1;
    20. 233 inode = Ramfs_get_inode (SB, NULL, S_ifdir | fsi->mount_opts.mode, 0); //Establish root index node
    21. 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
    22. 235 if (!sb->s_root)
    23. 236 Return-enomem;
    24. 238 return 0;
    25. 239}
    26. the *ramfs_get_inode-struct inode (struct super_block *sb,
    27. const struct inode *dir, umode_t mode, dev_t Dev)
    28. 56 {
    29. The inode of the new_inode struct, inode = (SB); //Create an inode in the index node cache,
    30. if (inode) {
    31. Inode->i_ino = Get_next_ino (); //Get an inode number
    32. Inode_init_owner (Inode, dir, mode); //Set Inode, initialize UID GID mode, etc.
    33. Inode->i_mapping->a_ops = &ramfs_aops;
    34. Inode->i_mapping->backing_dev_info = &ramfs_backing_dev_info;
    35. Mapping_set_gfp_mask (inode->i_mapping, Gfp_highuser);
    36. Mapping_set_unevictable (inode->i_mapping);
    37. Inode->i_atime = Inode->i_mtime = Inode->i_ctime = Current_time;
    38. (Mode & s_ifmt) {
    39. default: //Special files such as: Character ~ block device file, fifo,socket file
    40. Init_special_inode (inode, mode, dev);
    41. a break ;
    42. S_ifreg Case: //Normal file
    43. Inode->i_op = &ramfs_file_inode_operations;
    44. INODE->I_FOP = &ramfs_file_operations;
    45. a break ;
    46. s_ifdir Case: //directory file
    47. Inode->i_op = &ramfs_dir_inode_operations;
    48. INODE->I_FOP = &simple_dir_operations;
    49. */* directory inodes start off with i_nlink = = 2 (for "." entry) */
    50. Inc_nlink (Inode);
    51. Bayi break ;
    52. S_iflnk Case: //link file
    53. Inode->i_op = &page_symlink_inode_operations;
    54. a break ;
    55. 85}
    56. 86}
    57. The return of the inode; //Returns the created Inode associated with the corresponding Catalog item object
    58. 88}

[File system] File System learning Note (ix)---ROOTFS

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.