歡迎來到Linux教程網
Linux教程網
Linux教程網
Linux教程網
您现在的位置: Linux教程網 >> UnixLinux >  >> Linux基礎 >> Linux教程

Linux 文件系統模塊的注冊

用cramfs.ko做的實驗,斷點放在init_cramfs_fs(void)函數的rv = register_filesystem(&cramfs_fs_type);行,執行register_filesystem函數:

register_filesystem (fs=0xda7142e0) at fs/filesystems.c:74

顯示cramfs的file_system_type結構提如下:

{name = 0xda714268 "cramfs", fs_flags = 1,
  get_sb = 0xda713150 <cramfs_get_sb>,
  kill_sb = 0xc0205bb0 <kill_block_super>, owner = 0xda714320, next = 0x0,
  fs_supers = {next = 0x0, prev = 0x0}, s_lock_key = {<No data fields>},
  s_umount_key = {<No data fields>}, i_lock_key = {<No data fields>},
  i_mutex_key = {<No data fields>}, i_mutex_dir_key = {<No data fields>},
  i_alloc_sem_key = {<No data fields>}}

先提一下,實際注冊文件系統的時候是將file_system_type放在以file_systems為表頭的一個鏈表中。

先看下file_systems的內容:

(gdb) p *file_systems
$8 = {name = 0xc06cf3f4 "sysfs", fs_flags = 0,
  get_sb = 0xc0259190 <sysfs_get_sb>, kill_sb = 0xc0205c00 <kill_anon_super>,
  owner = 0x0, next = 0xc0751460, fs_supers = {next = 0xd78044a0,
    prev = 0xd78044a0}, s_lock_key = {<No data fields>},
  s_umount_key = {<No data fields>}, i_lock_key = {<No data fields>},
  i_mutex_key = {<No data fields>}, i_mutex_dir_key = {<No data fields>},
  i_alloc_sem_key = {<No data fields>}}

根據next = 0xc0751460   p *(struct file_system_type *)0xc0751460

{name = 0xc06c0033 "rootfs", fs_flags = 0,
  get_sb = 0xc02b7240 <rootfs_get_sb>,
  kill_sb = 0xc0205c50 <kill_litter_super>, owner = 0x0, next = 0xc074fc00,
  fs_supers = {next = 0xd78046a0, prev = 0xd78046a0},
  s_lock_key = {<No data fields>}, s_umount_key = {<No data fields>},
  i_lock_key = {<No data fields>}, i_mutex_key = {<No data fields>},
  i_mutex_dir_key = {<No data fields>}, i_alloc_sem_key = {<No data fields>}}

rootfs的注冊還在sysfs之後。

register_filesystem函數具體做了什麼?主要是兩點:

1、INIT_LIST_HEAD(&fs->fs_supers);

    初始化file_system_type結構體中的fs_supers雙向鏈表,後來會看到它會與該種文件系統類型的super_block結構體的s_instances關聯。

2、find_filesystem(fs->name, strlen(fs->name));

    在find_filesystem函數中就是根據name和名字長度遍歷鏈表進行查找的,從而將新的文件系統加到這個鏈表中。

附上一個圖:


 



文件系統模塊的注冊應該就這麼簡單,注冊完成後,就可以mount並使用該文件系統了。

Copyright © Linux教程網 All Rights Reserved