如何获取内核struct file中的当前文件节点名

如何获取内核struct file中的当前文件节点名

struct file结构如下
struct file {
/*
* fu_list becomes invalid after file_free is called and queued via
* fu_rcuhead for RCU freeing
*/
union {
struct list_head fu_list;
struct rcu_head fu_rcuhead;
} f_u;
struct path f_path;
#define f_dentry f_path.dentry
#define f_vfsmnt f_path.mnt
const struct file_operations *f_op;
atomic_t f_count;
unsigned int f_flags;
mode_t f_mode;
loff_t f_pos;
struct fown_struct f_owner;
unsigned int f_uid, f_gid;
struct file_ra_state f_ra;
unsigned long f_version;
#ifdef CONFIG_SECURITY
void f_security;
#endif
/
needed for tty driver, and maybe others */
void private_data;
#ifdef CONFIG_EPOLL
/
Used by fs/eventpoll.c to link all the hooks to this file /
struct list_head f_ep_links;
spinlock_t f_ep_lock;
#endif /
#ifdef CONFIG_EPOLL */
struct address_space *f_mapping;
};

其中
struct path {
struct vfsmount *mnt;
struct dentry *dentry;
};

struct dentry {
atomic_t d_count; 目录项对象使用计数器,可以有未使用态,使用态和负状态
unsigned int d_flags; 目录项标志
struct inode * d_inode; 与文件名关联的索引节点
struct dentry * d_parent; 父目录的目录项对象
struct list_head d_hash; 散列表表项的指针
struct list_head d_lru; 未使用链表的指针
struct list_head d_child; 父目录中目录项对象的链表的指针
struct list_head d_subdirs;对目录而言,表示子目录目录项对象的链表
struct list_head d_alias; 相关索引节点(别名)的链表
int d_mounted; 对于安装点而言,表示被安装文件系统根项
struct qstr d_name; 文件名
unsigned long d_time; /* used by d_revalidate */
struct dentry_operations *d_op; 目录项方法
struct super_block * d_sb; 文件的超级块对象
vunsigned long d_vfs_flags;
void * d_fsdata;与文件系统相关的数据
unsigned char d_iname [DNAME_INLINE_LEN]; 存放短文件名
};

根据以上结构,驱动中可由该路径获取相应的文件名以及文件父目录
文件名:file->f_path.dentry->d_name
父目录名:file->f_path.dentry->d_parent->d_name

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值