---------------------------------------------------------------------
这是通用的inode结构,它主要是将索引节点的通用部分组织起来,这个结构会被嵌入到特定的文件系统的索引节点结构中,而后者则会包含一些具体文件系统数据组织的信息,比如文件的块指针等。
每个索引节点对象都会复制磁盘索引节点中包含的一些数据,比如分配给文件的磁盘块数,访问时间、修改时间,文件拥有者的UID、GID等。如果i_state字段的值等于I_DIRTY_SYNC、I_DIRTY_DATASYNC或I_DIRTY_PAGES,则该索引节点是“脏”的,也就是说,索引节点被修改,对应的磁盘索引节点必须被更新。I_DIRTY宏可以用来检查这三个标志的值。i_state字段的其他值有I_NEW(索引节点对象已经分配但还没有用从磁盘索引节点读取来的数据进行填充)、I_WILL_FREE、I_FREEING(索引节点对象正在被释放)、I_CLEAR(索引节点对象的内容不再有意义)、I_SYNC
每个索引节点对象总是出现在两个不同的索引节点表中。首先,是inode的哈希表,这主要是为了快速查询,前提是系统内核要知道索引节点号及文件系统对应的超级块对象的地址。inode.c文件中的hlist_head类型指针静态变量inode_hashtable为哈希表的表头,哈希表的元素也同样为hlist_head类型,inode结构的hlist_node类型的i_hash字段用来将inode和哈希表链接起来。
它还会出现在另外两个“类型”双向循环链表中的某个链表里(使用i_list与相应的链表链接起来):
有效但未使用的索引节点链表,该链表中的索引节点未被任何进程使用。它们的i_count字段值为0。链表中的首元素和尾元素是由全局变量inode_unused(fs/inode.c中, LIST_HEAD(inode_unused);)的next字段和prev字段分别指向的。这个链表用作磁盘高速缓存。
正在使用的索引节点链表,该链表里的索引节点当前被某些进程使用。它们的i_count字段大于零,i_nlink字段大于零。链表中的首元素和尾元素是由全局变量inode_in_use(fs/inode.c, LIST_HEAD(inode_in_use);)引用的。
最后,它还会出现在特定文件系统,也就是特定super_block的双向循环索引节点表中,由super_block的s_inodes字段和inode结构的i_sb_list字段连接。
索引节点结构与超级块之间的关系如下图:
2.4索引节点操作
与索引节点对象相关联的方法也叫索引节点操作。由inode_operations来描述,该结构的地址存放在索引节点的i_op字段中。定义如下:
---------------------------------------------------------------------
include/linux/fs.h
struct inode_operations {
int (*create) (struct inode *,struct dentry *,int, struct nameidata *);
struct dentry * (*lookup) (struct inode *,struct dentry *, struct nameidata *);
int (*link) (struct dentry *,struct inode *,struct dentry *);
int (*unlink) (struct inode *,struct dentry *);
int (*symlink) (struct inode *,struct dentry *,const char *);
int (*mkdir) (struct inode *,struct dentry *,int);
int (*rmdir) (struct inode *,struct dentry *);
int (*mknod) (struct inode *,struct dentry *,int,dev_t);
int (*rename) (struct inode *, struct dentry *,
struct inode *, struct dentry *);
int (*readlink) (struct dentry *, char __user *,int);
void * (*follow_link) (struct dentry *, struct nameidata *);
void (*put_link) (struct dentry *, struct nameidata *, void *);
void (*truncate) (struct inode *);
int (*permission) (struct inode *, int);
int (*check_acl)(struct inode *, int);
int (*setattr) (struct dentry *, struct iattr *);
int (*getattr) (struct vfsmount *mnt, struct dentry *, struct kstat *);
int (*setxattr) (struct dentry *, const char *,const void *,size_t,int);
ssize_t (*getxattr) (struct dentry *, const char *, void *, size_t);
ssize_t (*listxattr) (struct dentry *, char *, size_t);
int (*removexattr) (struct dentry *, const char *);
void (*truncate_range)(struct inode *, loff_t, loff_t);
long (*fallocate)(struct inode *inode, int mode, loff_t offset,
loff_t len);
int (*fiemap)(struct inode *, struct fiemap_extent_info *, u64 start,
u64 len);
};
本文来自电脑杂谈,转载请注明本文网址:
http://www.pc-fly.com/a/jisuanjixue/article-76619-4.html
茶馆
赚中国人的钱拿去给美国人花