LinuxSir.cn,穿越时空的Linuxsir!

 找回密码
 注册
搜索
热搜: shell linux mysql
查看: 2177|回复: 1

在Linux内核中,如何获取谋文件的扇区号?

[复制链接]
发表于 2009-6-1 16:44:13 | 显示全部楼层 |阅读模式
在内核中可以用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;
};
发表于 2009-11-8 10:37:40 | 显示全部楼层
是否可以通过柱面数、盘片数、每道扇区数之间的关系计算出来呢。呵呵
回复 支持 反对

使用道具 举报

您需要登录后才可以回帖 登录 | 注册

本版积分规则

快速回复 返回顶部 返回列表