【问题标题】:Linux Kernel inode timestampLinux 内核 inode 时间戳
【发布时间】:2014-04-08 12:15:06
【问题描述】:

我想知道以下哪个inode条目包含文件创建时间和文件最后修改时间?

谢谢

【问题讨论】:

  • 以下哪些条目?您似乎遗漏了一些问题。
  • i_atime、i_mtime 和 i_ctime。以下哪个告诉创建和修改时间...

标签: linux linux-kernel kernel kernel-module inode


【解决方案1】:

阅读 stat(2) 的手册页。这是直接从那里:

       struct stat {
           dev_t     st_dev;     /* ID of device containing file */
           ino_t     st_ino;     /* inode number */
           mode_t    st_mode;    /* protection */
           nlink_t   st_nlink;   /* number of hard links */
           uid_t     st_uid;     /* user ID of owner */
           gid_t     st_gid;     /* group ID of owner */
           dev_t     st_rdev;    /* device ID (if special file) */
           off_t     st_size;    /* total size, in bytes */
           blksize_t st_blksize; /* blocksize for file system I/O */
           blkcnt_t  st_blocks;  /* number of 512B blocks allocated */
           time_t    st_atime;   /* time of last access */
           time_t    st_mtime;   /* time of last modification */
           time_t    st_ctime;   /* time of last status change */
       };

【讨论】:

    【解决方案2】:

    struct inode 包含i_ctime(创建)和i_mtime(修改)。

    如果您在内核空间中并且需要为给定路径获取这些值,则过程如下:

    声明一个struct path,然后使用路径名调用kern_path 来填充结构,这允许您访问struct dentry,这里是struct inode。所以path->dentry->d_inode

    一旦您有了struct inode,就可以像inode->ctime.tv_sec / inode->ctime.tv_nsec 一样简单地访问它。

    如果您需要修改这些值,则需要根据此概念证明进行一些额外的工作:

    https://github.com/linuxthor/inode-ctime/blob/master/inode-ctime.c

    【讨论】:

      猜你喜欢
      • 2017-06-07
      • 1970-01-01
      • 2014-05-24
      • 1970-01-01
      • 1970-01-01
      • 2010-10-10
      • 2015-05-04
      • 2016-03-08
      • 2015-12-08
      相关资源
      最近更新 更多