首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 操作系统 > UNIXLINUX >

unix是怎么从i节点得到目录信息的

2012-02-17 
unix是如何从i节点得到目录信息的unix是如何从i节点得到目录信息的,包括目录名和目录包含的文件之类的内容

unix是如何从i节点得到目录信息的
unix是如何从i节点得到目录信息的,包括目录名和目录包含的文件之类的内容。
“由这个索引节点得到目录内容的存放位置”这样一句话就带过了……

i节点的结构体里面没有找到指向目录表的编号,难道i节点的i就指向dir[i]?

[解决办法]
Linux内核中inode结构是通过i_dentry链表成员指向目录项对象的。
dentry结构在内核中表示目录项。
可以通过inode_operations结构中的create函数建立指向dentry结构对象的连接,lookup函数可以查找inode中的目录项。等等。
[解决办法]
i节点结构中有个i_dentry这个成员,这个成员是一个链表,对应着一群目录项。
比如硬连接的情况,一个i节点可能对应多个目录项。
[解决办法]
这些数据结构linux内核源代码都有,
~/include/linux/fs.h中定义的inode结构:
struct inode {
struct hlist_nodei_hash;
struct list_headi_list;
struct list_headi_sb_list;
struct list_headi_dentry; //这是一个dentry结构的链表
unsigned longi_ino;
atomic_ti_count;
umode_ti_mode;
unsigned inti_nlink;
uid_ti_uid;
gid_ti_gid;
dev_ti_rdev;
loff_ti_size;
struct timespeci_atime;
struct timespeci_mtime;
struct timespeci_ctime;
unsigned inti_blkbits;
unsigned longi_blksize;
unsigned longi_version;
unsigned longi_blocks;
unsigned short i_bytes;
spinlock_ti_lock;/* i_blocks, i_bytes, maybe i_size */
struct semaphorei_sem;
struct rw_semaphorei_alloc_sem;
struct inode_operations*i_op;
struct file_operations*i_fop;/* former -> i_op-> default_file_ops */
struct super_block*i_sb;
struct file_lock*i_flock;
struct address_space*i_mapping;
struct address_spacei_data;
#ifdef CONFIG_QUOTA
struct dquot*i_dquot[MAXQUOTAS];
#endif
/* These three should probably be a union */
struct list_headi_devices;
struct pipe_inode_info*i_pipe;
struct block_device*i_bdev;
struct cdev*i_cdev;
inti_cindex;

__u32i_generation;

#ifdef CONFIG_DNOTIFY
unsigned longi_dnotify_mask; /* Directory notify events */
struct dnotify_struct*i_dnotify; /* for directory notifications */
#endif

#ifdef CONFIG_INOTIFY
struct list_headinotify_watches; /* watches on this inode */
struct semaphoreinotify_sem;/* protects the watches list */
#endif

unsigned longi_state;
unsigned longdirtied_when;/* jiffies of first dirtying */

unsigned inti_flags;

atomic_ti_writecount;
void*i_security;
union {
void*generic_ip;
} u;
#ifdef __NEED_I_SIZE_ORDERED
seqcount_ti_size_seqcount;
#endif
};

结构dentry定义在~/include/linux/dcache.h中,其中的d_iname成员就是文件名
比如
inode i;
.... //对i进行初始化
char *ch=(struct dentry)list_entry(&i-> i_dentry,struct inode,i_dentry)-> d_iname;
就可以访问i节点i的文件名了。

热点排行