|
在内核中可以用filp_open()来打开一个文件,
其原形如下:
strcut file* filp_open(const char* filename, int open_mode, int mode);
例如在内核中调用:filp_open("/bin/ls",O_RDONLY,0);
该函数返回strcut file*结构指针,这个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 dentry *f_dentry;
struct vfsmount *f_vfsmnt;
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;
void *f_security;
/* 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;
}; |
|