📄 fs.h
字号:
struct inode *host; /* owner: inode, block_device */ struct vm_area_struct *i_mmap; /* list of private mappings */ struct vm_area_struct *i_mmap_shared; /* list of shared mappings */ spinlock_t i_shared_lock; /* and spinlock protecting it */ int gfp_mask; /* how to allocate the pages */};struct char_device { struct list_head hash; atomic_t count; dev_t dev; atomic_t openers; struct semaphore sem;};struct block_device { struct list_head bd_hash;/*哈希表*/ atomic_t bd_count;/*引用计数*/ struct inode * bd_inode;/*所指的inode节点*/ dev_t bd_dev; /* not a kdev_t - it's a search key 查找号*/ int bd_openers;/*打开的用户数*/ const struct block_device_operations *bd_op;/*操作集*/ struct semaphore bd_sem; /* open/close mutex 打开关闭互斥信号量*/ struct list_head bd_inodes;/*同种设备的节点链表*/};struct inode { struct list_head i_hash;/*指向散列链表的指针 */ struct list_head i_list;/*指向索引节点链表的指针*/ struct list_head i_dentry;/*指向目录项表的指针*/ struct list_head i_dirty_buffers;/*脏块链表*/ struct list_head i_dirty_data_buffers; unsigned long i_ino;/*真实文件系统中队这个inode的编号*/ atomic_t i_count;/*引用计数,表示使用这个VFS inode的用户数,0意味着空闲,可废弃或重用*/ kdev_t i_dev;/*存放这个文件的设备标识符*/ umode_t i_mode;/*描述代表的对象和它的访问权限*/ nlink_t i_nlink;/*到文件的连接数,或文件在不同目录中的出现次数*/ uid_t i_uid;/*文件属主的用户标识*/ gid_t i_gid;/*组标识*/ kdev_t i_rdev;/*对设备特殊文件,此处存储的是该文件所代表的主设备号和次设备号,其他类型的文件,该域未用*/ loff_t i_size;/*文件长度*/ time_t i_atime;/*文件的最后一次访问时间*/ time_t i_mtime;/*文件最有修改时间*/ time_t i_ctime;/*文件创建时间*/ unsigned int i_blkbits; unsigned long i_blksize;/*组成这个文件的块的大小,字节为单位*/ unsigned long i_blocks;/*文件占的块数*/ unsigned long i_version; struct semaphore i_sem; struct semaphore i_zombie; struct inode_operations *i_op;/*指向一组inode的操作集*/ struct file_operations *i_fop; /* former ->i_op->default_file_ops */ struct super_block *i_sb;/*指向inode所属文件系统的VFS超级块的指针*/ wait_queue_head_t i_wait;/*在文件上等待操作的进程*/ struct file_lock *i_flock;/*指向一串文件锁结构的指针*/ struct address_space *i_mapping;/*若文件用于映射,则指针指向在文件上建立的一组address_space结构*/ struct address_space i_data; struct dquot *i_dquot[MAXQUOTAS]; /* These three should probably be a union */ struct list_head i_devices; struct pipe_inode_info *i_pipe;/*管道指针*/ struct block_device *i_bdev;/*块设备指针 */ struct char_device *i_cdev; unsigned long i_dnotify_mask; /* Directory notify events */ struct dnotify_struct *i_dnotify; /* for directory notifications */ unsigned long i_state;/*文件状态*/ unsigned int i_flags;/*标志*/ unsigned char i_sock; atomic_t i_writecount; unsigned int i_attr_flags; __u32 i_generation; union {/*用来描述文件系统的特有文件信息*/ struct minix_inode_info minix_i; struct ext2_inode_info ext2_i; struct ext3_inode_info ext3_i; struct hpfs_inode_info hpfs_i; struct ntfs_inode_info ntfs_i; struct msdos_inode_info msdos_i; struct umsdos_inode_info umsdos_i; struct iso_inode_info isofs_i; struct nfs_inode_info nfs_i; struct sysv_inode_info sysv_i; struct affs_inode_info affs_i; struct ufs_inode_info ufs_i; struct efs_inode_info efs_i; struct romfs_inode_info romfs_i; struct shmem_inode_info shmem_i; struct coda_inode_info coda_i; struct smb_inode_info smbfs_i; struct hfs_inode_info hfs_i; struct adfs_inode_info adfs_i; struct qnx4_inode_info qnx4_i; struct reiserfs_inode_info reiserfs_i; struct bfs_inode_info bfs_i; struct udf_inode_info udf_i; struct ncp_inode_info ncpfs_i; struct proc_inode_info proc_i; struct socket socket_i; struct usbdev_inode_info usbdev_i; struct jffs2_inode_info jffs2_i; void *generic_ip; } u;};struct fown_struct { int pid; /* pid or -pgrp where SIGIO should be sent */ uid_t uid, euid; /* uid/euid of process setting the owner */ int signum; /* posix.1b rt signal to be delivered on IO */};struct file { struct list_head f_list;/*这个字段将文件一起链接到许多链表中的一个列表*/ struct dentry *f_dentry;/**/ struct vfsmount *f_vfsmnt;/*指向虚拟文件系统模块*/ struct file_operations *f_op;/*指向这个文件上使用的方法*/ atomic_t f_count;/*对这个文件的引用数量*/ unsigned int f_flags;/*文件标志,如访问类型(读/写),无诸塞,只附加等*/ mode_t f_mode;/*f_mode将读取和写入访问存储为两个单独的位*/ loff_t f_pos;/*记录了当前文件的位置*/ unsigned long f_reada, f_ramax, f_raend, f_ralen, f_rawin;/*记录了文件上的顺序访问模式,可以确定需要完成多少预读*/ struct fown_struct f_owner;/*该结构存储了进程ID和一个在文件发生了某个时向进程发送的信号*/ unsigned int f_uid, f_gid;/*打开文件的进程的所有者和组*/ int f_error;/*可返回写入错误*/ unsigned long f_version;/*基本文件系统可以使用这个字段来帮助缓存状态和检查边的无效的缓存*/ /* needed for tty driver, and maybe others */ void *private_data;/*存储每个打开文件的额外信息*/ /* preallocated helper kiobuf to speedup O_DIRECT */ struct kiobuf *f_iobuf;/*指向输入输出缓冲区*/ long f_iobuf_lock;/*io时的锁*/};extern spinlock_t files_lock;#define file_list_lock() spin_lock(&files_lock);#define file_list_unlock() spin_unlock(&files_lock);#define get_file(x) atomic_inc(&(x)->f_count)#define file_count(x) atomic_read(&(x)->f_count)extern int init_private_file(struct file *, struct dentry *, int);#define MAX_NON_LFS ((1UL<<31) - 1)#define FL_POSIX 1#define FL_FLOCK 2#define FL_BROKEN 4 /* broken flock() emulation */#define FL_ACCESS 8 /* for processes suspended by mandatory locking */#define FL_LOCKD 16 /* lock held by rpc.lockd */#define FL_LEASE 32 /* lease held on this file *//* * The POSIX file lock owner is determined by * the "struct files_struct" in the thread group * (or NULL for no owner - BSD locks). * * Lockd stuffs a "host" pointer into this. */typedef struct files_struct *fl_owner_t;struct file_lock { struct file_lock *fl_next; /* singly linked list for this inode */ struct list_head fl_link; /* doubly linked list of all locks */ struct list_head fl_block; /* circular list of blocked processes */ fl_owner_t fl_owner; unsigned int fl_pid; wait_queue_head_t fl_wait; struct file *fl_file; unsigned char fl_flags; unsigned char fl_type; loff_t fl_start; loff_t fl_end; void (*fl_notify)(struct file_lock *); /* unblock callback */ void (*fl_insert)(struct file_lock *); /* lock insertion callback */ void (*fl_remove)(struct file_lock *); /* lock removal callback */ struct fasync_struct * fl_fasync; /* for lease break notifications */ union { struct nfs_lock_info nfs_fl; } fl_u;};/* The following constant reflects the upper bound of the file/locking space */#ifndef OFFSET_MAX#define INT_LIMIT(x) (~((x)1 << (sizeof(x)*8 - 1)))#define OFFSET_MAX INT_LIMIT(loff_t)#define OFFT_OFFSET_MAX INT_LIMIT(off_t)#endifextern struct list_head file_lock_list;#include <linux/fcntl.h>extern int fcntl_getlk(unsigned int, struct flock *);extern int fcntl_setlk(unsigned int, unsigned int, struct flock *);extern int fcntl_getlk64(unsigned int, struct flock64 *);extern int fcntl_setlk64(unsigned int, unsigned int, struct flock64 *);/* fs/locks.c */extern void locks_init_lock(struct file_lock *);extern void locks_copy_lock(struct file_lock *, struct file_lock *);extern void locks_remove_posix(struct file *, fl_owner_t);extern void locks_remove_flock(struct file *);extern struct file_lock *posix_test_lock(struct file *, struct file_lock *);extern int posix_lock_file(struct file *, struct file_lock *, unsigned int);extern void posix_block_lock(struct file_lock *, struct file_lock *);extern void posix_unblock_lock(struct file_lock *);extern int posix_locks_deadlock(struct file_lock *, struct file_lock *);extern int __get_lease(struct inode *inode, unsigned int flags);extern time_t lease_get_mtime(struct inode *);extern int lock_may_read(struct inode *, loff_t start, unsigned long count);extern int lock_may_write(struct inode *, loff_t start, unsigned long count);struct fasync_struct { int magic; int fa_fd; struct fasync_struct *fa_next; /* singly linked list */ struct file *fa_file;};#define FASYNC_MAGIC 0x4601/* SMP safe fasync helpers: */extern int fasync_helper(int, struct file *, int, struct fasync_struct **);/* can be called from interrupts */extern void kill_fasync(struct fasync_struct **, int, int);/* only for net: no internal synchronization */extern void __kill_fasync(struct fasync_struct *, int, int);struct nameidata { struct dentry *dentry;/*目录结构*/ struct vfsmount *mnt;/*mnt指向文件的安装信息结构*/ struct qstr last;/*当前文件名信息*/ unsigned int flags;/*寻找方式标记标记*/ int last_type;/*路径名结尾的方式*/};#define DQUOT_USR_ENABLED 0x01 /* User diskquotas enabled */#define DQUOT_GRP_ENABLED 0x02 /* Group diskquotas enabled */struct quota_mount_options{ unsigned int flags; /* Flags for diskquotas on this device */ struct semaphore dqio_sem; /* lock device while I/O in progress */ struct semaphore dqoff_sem; /* serialize quota_off() and quota_on() on device */ struct file *files[MAXQUOTAS]; /* fp's to quotafiles */ time_t inode_expire[MAXQUOTAS]; /* expiretime for inode-quota */ time_t block_expire[MAXQUOTAS]; /* expiretime for block-quota */ char rsquash[MAXQUOTAS]; /* for quotas threat root as any other user */};/* * Umount options */#define MNT_FORCE 0x00000001 /* Attempt to forcibily umount */#define MNT_DETACH 0x00000002 /* Just detach from the tree */#include <linux/minix_fs_sb.h>#include <linux/ext2_fs_sb.h>#include <linux/ext3_fs_sb.h>#include <linux/hpfs_fs_sb.h>#include <linux/ntfs_fs_sb.h>#include <linux/msdos_fs_sb.h>#include <linux/iso_fs_sb.h>#include <linux/nfs_fs_sb.h>#include <linux/sysv_fs_sb.h>#include <linux/affs_fs_sb.h>#include <linux/ufs_fs_sb.h>#include <linux/efs_fs_sb.h>#include <linux/romfs_fs_sb.h>#include <linux/smb_fs_sb.h>#include <linux/hfs_fs_sb.h>#include <linux/adfs_fs_sb.h>#include <linux/qnx4_fs_sb.h>#include <linux/reiserfs_fs_sb.h>#include <linux/bfs_fs_sb.h>#include <linux/udf_fs_sb.h>#include <linux/ncp_fs_sb.h>#include <linux/usbdev_fs_sb.h>#include <linux/cramfs_fs_sb.h>#include <linux/jffs2_fs_sb.h>extern struct list_head super_blocks;extern spinlock_t sb_lock;#define sb_entry(list) list_entry((list), struct super_block, s_list)#define S_BIAS (1<<30)struct super_block {/*存放已安装文件系统的相关信息*/ struct list_head s_list; /* Keep this first 指向超级块链表的指针*/ kdev_t s_dev; /*文件系统的主次设备号*/ unsigned long s_blocksize; /*文件系统的基本块大小,以字节为单位*/ unsigned char s_blocksize_bits;/*表示块的尺寸占用的二进制的位数*/ unsigned char s_dirt;/*脏标志,表示超级块结构是否被修改过*/ unsigned long long s_maxbytes; /* Max file size文件大小上限*/ struct file_system_type *s_type; /*指向表示该文件系统所属类型的file_system_type结构*/ struct super_operations *s_op;/*指向一组对该文件系统进行操作的函数集合*/ struct dquot_operations *dq_op;/*对文件系统磁盘配额操作的一组函数*/ unsigned long s_flags;/*标志,描述文件系统的特殊性*/ unsigned long s_magic;/*魔数,是一个文件系统专有的标志,每个真实的文件系统的魔数都不同*/ struct dentry *s_root; /*安装目录的目录项对象*/ struct rw_semaphore s_umount;/*读写同步信号量,对超级块读写时进行同步*/ struct semaphore s_lock;/*超级块锁,若置该位,则其他进程不能对该超级块操作*/ int s_count;/*超级块引用计数*/ atomic_t s_active; struct list_head s_dirty; /* dirty inodes 脏索引节点队列,所有脏inode都在该队列上排队*/ struct list_head s_locked_inodes;/* inodes being synced要进行同步的索引节点形成的链表*/ struct list_head s_files;/*文件系统上打开文件的列表,f_list上链接*/ struct block_device *s_bdev;/*相关的块设备驱动*/ struct list_head s_instances;/*超级块的实例链表*/ struct quota_mount_options s_dquot; /* Diskquota specific options 磁盘配额特别选项*/ union {/*联合结构体,其成员是各种文件系统的fsname_sb_info数据结构,其中的每个结构表示一个真实文件系统的私有信息*/ struct minix_sb_info minix_sb; struct ext2_sb_info ext2_sb; struct ext3_sb_info ext3_sb; struct hpfs_sb_info hpfs_sb; struct ntfs_sb_info ntfs_sb; struct msdos_sb_info msdos_sb; struct isofs_sb_info isofs_sb; struct nfs_sb_info nfs_sb; struct sysv_sb_info sysv_sb; struct affs_sb_info affs_sb; struct ufs_sb_info ufs_sb; struct efs_sb_info efs_sb; struct shmem_sb_info shmem_sb; struct romfs_sb_info romfs_sb; struct smb_sb_info smbfs_sb; struct hfs_sb_info hfs_sb; struct adfs_sb_info adfs_sb; struct qnx4_sb_info qnx4_sb; struct reiserfs_sb_info reiserfs_sb; struct bfs_sb_info bfs_sb; struct udf_sb_info udf_sb; struct ncp_sb_info ncpfs_sb; struct usbdev_sb_info usbdevfs_sb; struct jffs2_sb_info jffs2_sb; struct cramfs_sb_info cramfs_sb; void *generic_sbp; } u;/*super_block.u是支持多种文件系统的关键*/ /* * The next field is for VFS *only*. No filesystems have any business * even looking at it. You had been warned. */ struct semaphore s_vfs_rename_sem; /* Kludge 目录重命名信号量*/ /* The next field is used by knfsd when converting a (inode number based) * file handle into a dentry. As it builds a path in the dcache tree from * the bottom up, there may for a time be a subpath of dentrys which is not * connected to the main tree. This semaphore ensure that there is only ever * one such free path per filesystem. Note that unconnected files (or other * non-directories) are allowed, but not unconnected diretories. */ struct semaphore s_nfsd_free_path_sem;};/* * VFS helper functions.. */extern int vfs_create(struct inode *, struct dentry *, int);extern int vfs_mkdir(struct inode *, struct dentry *, int);extern int vfs_mknod(struct inode *, struct dentry *, int, dev_t);extern int vfs_symlink(struct inode *, struct dentry *, const char *);extern int vfs_link(struct dentry *, struct inode *, struct dentry *);extern int vfs_rmdir(struct inode *, struct dentry *);extern int vfs_unlink(struct inode *, struct dentry *);extern int vfs_rename(struct inode *, struct dentry *, struct inode *, struct dentry *);/* * File types */#define DT_UNKNOWN 0#define DT_FIFO 1#define DT_CHR 2#define DT_DIR 4#define DT_BLK 6#define DT_REG 8#define DT_LNK 10#define DT_SOCK 12#define DT_WHT 14/* * This is the "filldir" function type, used by readdir() to let * the kernel specify what kind of dirent layout it wants to have. * This allows the kernel to read directories into kernel space or * to have different dirent layouts depending on the binary type. */typedef int (*filldir_t)(void *, const char *, int, loff_t, ino_t, unsigned);struct block_device_operations { int (*open) (struct inode *, struct file *); int (*release) (struct inode *, struct file *);
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -