📄 00000046.htm
字号:
16. writev - implements writev(2) system call <BR>3.5 Superblock and Mountpoint Management <BR>Under Linux, information about mounted filesystems is kept in two separate s <BR>tructures - super_block and vfsmount. The reason for this is that Linux allo <BR>ws to mount the same filesystem (block device) under multiple mount points, <BR>which means that the same super_block can correspond to multiple vfsmount st <BR>ructures. <BR>Let us look at struct super_block first, declared in include/linux/fs.h: <BR>struct super_block { <BR> struct list_head s_list; /* Keep this first */ <BR> kdev_t s_dev; <BR> unsigned long s_blocksize; <BR> unsigned char s_blocksize_bits; <BR> unsigned char s_lock; <BR> unsigned char s_dirt; <BR> struct file_system_type *s_type; <BR> struct super_operations *s_op; <BR> struct dquot_operations *dq_op; <BR> unsigned long s_flags; <BR> unsigned long s_magic; <BR> struct dentry *s_root; <BR> wait_queue_head_t s_wait; <BR> struct list_head s_dirty; /* dirty inodes */ <BR> struct list_head s_files; <BR> struct block_device *s_bdev; <BR> struct list_head s_mounts; /* vfsmount(s) of this one * <BR>/ <BR> struct quota_mount_options s_dquot; /* Diskquota specific option <BR>s */ <BR> union { <BR> struct minix_sb_info minix_sb; <BR> struct ext2_sb_info ext2_sb; <BR> ..... all filesystems that need sb-private info ... <BR> void *generic_sbp; <BR> } u; <BR> /* <BR> * The next field is for VFS *only*. No filesystems have any busines <BR>s <BR> * even looking at it. You had been warned. <BR> */ <BR> struct semaphore s_vfs_rename_sem; /* Kludge */ <BR> /* The next field is used by knfsd when converting a (inode number b <BR>ased) <BR> * file handle into a dentry. As it builds a path in the dcache tree <BR> from <BR> * the bottom up, there may for a time be a subpath of dentrys which <BR> is not <BR> * connected to the main tree. This semaphore ensure that there is <BR>only ever <BR> * one such free path per filesystem. Note that unconnected files ( <BR>or other <BR> * non-directories) are allowed, but not unconnected diretories. <BR> */ <BR> struct semaphore s_nfsd_free_path_sem; <BR>}; <BR>The various fields in the super_block structure are: <BR>1. s_list - a doubly-linked list of all active superblocks, note I don't say <BR> "of all mounted filesystems" because under Linux one can have multiple inst <BR>ances of a mounted filesystem corresponding to a single superblock <BR>2. s_dev - for filesystems which require a block to be mounted on, i.e. for <BR>FS_REQUIRES_DEV filesystems, this is the i_dev of the block device. For othe <BR>rs (called anonymous filesystems) this is an integer MKDEV(UNNAMED_MAJOR, i) <BR> where i is the first unset bit in unnamed_dev_in_use array, between 1 and 2 <BR>55 inclusive. See fs/super.c:get_unnamed_dev()/put_unnamed_dev(). It has bee <BR>n suggested many times that anonymous filesystems should not use s_dev field <BR> <BR>3. s_blocksize, s_blocksize_bits - blocksize and log2(blocksize) <BR>4. s_lock - indicates whether superblock is currently locked by lock_super() <BR>/unlock_super() <BR>5. s_dirt - set when superblock is changed and cleared whenever it is writte <BR>n back to disk <BR>6. s_type - pointer to 'struct file_system_type' of the corresponding filesy <BR>stem. Filesystem's read_super() method doesn't need to set it as VFS fs/supe <BR>r.c:read_super() sets it for you if fs-specific read_super() succeeds and re <BR>sets to NULL if it fails <BR>7. s_op - pointer to super_operations structure which contains fs-specific m <BR>ethods to read/write inodes etc. It is the job of filesystem's read_super() <BR>method to initialise s_op correctly <BR>8. dq_op - disk quota operations <BR>9. s_flags - superblock flags <BR>10. s_magic - filesystem's magic number. Used by minix filesystem to differe <BR>ntiate between multiple flavours of itself <BR>11. s_root - dentry of the filesystem's root. It is the job of read_super() <BR>to read the root inode from the disk and pass it to d_alloc_root() to alloca <BR>te the dentry and instantiate it. Some filesystems spell "root" other than " <BR>/" and so use more generic d_alloc() function to bind the dentry to a name, <BR>e.g. pipefs mounts itself on "pipe:" as its own root instead of "/" <BR>12. s_wait - waitqueue of processes waiting for superblock to be unlocked <BR>13. s_dirty - a list of all dirty inodes. Recall that if inode is dirty (ino <BR>de-i_state & I_DIRTY) then it is on superblock-specific dirty list linked vi <BR>a inode-i_list <BR>14. s_files - a list of all open files on this superblock. Useful for decidi <BR>ng whether filesystem can be remounted read-only, see fs/file_table.c:fs_may <BR>_remount_ro() which goes through sb-s_files list and denies remounting if th <BR>ere are files opened for write (file-f_mode & FMODE_WRITE) or files with pen <BR>ding unlink (inode-i_nlink == 0) <BR>15. s_bdev - for FS_REQUIRES_DEV this points to the block_device structure d <BR>escribing the device the filesystem is mounted on <BR>16. s_mounts - a list of all vfsmount structures, one for each mounted insta <BR>nce of this superblock <BR>17. s_dquot - more diskquota stuff <BR>The superblock operations are described in the super_operations structure de <BR>clared in include/linux/fs.h: <BR>struct super_operations { <BR> void (*read_inode) (struct inode *); <BR> void (*write_inode) (struct inode *, int); <BR> void (*put_inode) (struct inode *); <BR> void (*delete_inode) (struct inode *); <BR> void (*put_super) (struct super_block *); <BR> void (*write_super) (struct super_block *); <BR> &
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -