inode 或i节点是指对文件的索引。如一个系统,所有文件是放在磁盘或flash上,就要编个目录来说明每个文件在什么地方,有什么属性,及大小等。就像书本的目录一样,便于查找和管理。这目录是操作系统需要的,用来找文件或叫管理文件。许多操作系统都用到这个概念,如linux, 某些嵌入式文件系统等。当然,对某个系统来说,有许多i节点。所以对i节点本身也是要进行管理的。
在linux中,内核通过inode来找到每个文件,但一个文件可以被许多用户同时打开或一个用户同时打开多次。这就有一个问题,如何管理文件的当前位移量,因为可能每个用户打开文件后进行的操作都不一样,这样文件位移量也不同,当然还有其他的一些问题。所以linux又搞了一个文件描述符(file descriptor)这个东西,来分别为每一个用户服务。每个用户每次打开一个文件,就产生一个文件描述符,多次打开就产生多个文件描述符,一一对应,不管是同一个用户,还是多个用户。该文件描述符就记录了当前打开的文件的偏移量等数据。所以一个i节点可以有0个或多个文件描述符。多个文件描述符可以对应一个i节点。
- struct inode {
- struct list_headi_hash;
- struct list_headi_list;
- struct list_headi_dentry;
- struct list_headi_dirty_buffers;
- unsigned longi_ino;
- atomic_t i_count;
- kdev_t i_dev;
- umode_t i_mode;
- nlink_t i_nlink;
- uid_t i_uid;
- gid_t i_gid;
- kdev_t i_rdev;
- off_t i_size;
- time_t i_atime;
- time_t i_mtime;
- time_t i_ctime;
- unsigned long i_blksize;
- unsigned long i_blocks;
- unsigned long i_version;
- unsigned short i_bytes;
- struct semaphore i_sem;
- struct rw_semaphore i_truncate_sem;
- struct semaphore i_zombie;
- struct inode_operations *i_op;
- struct file_operations *i_fop;
- struct super_block *i_sb;
- wait_queue_head_t i_wait;
- struct file_lock *i_flock;
- struct address_space *i_mapping;
- struct address_space i_data;
- struct dquot *i_dquot [MAXQUOTAS];
-
- struct pipe_inode_info *i_pipe;
- struct block_device *i_bdev;
- struct char_device *i_cdev;
- unsigned longi_dnotify_mask;
- struct dnotify_struct *i_dnotify;
- unsigned long i_state;
- unsigned int i_flags;
- unsigned char i_sock;
- atomic_t i_write count;
- 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 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 socketsocket_i;
- struct usbdev_inode_info usbdev_i;
- struct jffs2_inode_infojffs2_i;
- void *generic_ip;
- } u;
- };