stat

STAT(2)                    Linux Programmer's Manual                   STAT(2)



åå
       stat, fstat, lstat - ãã¡ã¤ã«ã®ç¶æãåå¾ãã

æ¸å¼
       #include <sys/types.h>
       #include <sys/stat.h>
       #include <unistd.h>

       int stat(const char *path, struct stat *buf);
       int fstat(int fd, struct stat *buf);
       int lstat(const char *path, struct stat *buf);

   glibc åãã®æ©è½æ¤æ»ãã¯ãã®è¦ä»¶ (feature_test_macros(7)  åç§):

       lstat():
           _BSD_SOURCE || _XOPEN_SOURCE >= 500 ||
           _XOPEN_SOURCE && _XOPEN_SOURCE_EXTENDED
           || /* glibc 2.10 以é: */ _POSIX_C_SOURCE >= 200112L

説æ
       ãããã®é¢æ°ã¯ãã¡ã¤ã«ã«ã¤ãã¦ã®æå ±ãè¿ãã
       ãã¡ã¤ã«ãã®ãã®ã«å¯¾ããã¢ã¯ã»ã¹è¨±å¯ã¯å¿è¦ã¨ããªããã —stat() 㨠lstat()
       ã®å ´åã«ã¯ — ãã®ãã¡ã¤ã«ã¸è³ã path ãæ§æããå¨ã¦ã®ãã£ã¬ã¯ããªã«å¯¾ãã å®è¡
       (æ¤ç´¢) 許å¯ãå¿è¦ã§ããã

       stat()  㯠path ã§æå®ããããã¡ã¤ã«ã®ç¶æãåå¾ã㦠buf ã¸æ ¼ç´ããã

       lstat()  㯠stat()  ã¨åãã§ãããã path
       ãã·ã³ããªãã¯ãªã³ã¯ã®å ´åããªã³ã¯ãåç§ãã¦ãããã¡ã¤ã«ã§ã¯ãªãã
       ãªã³ã¯èªèº«ã®ç¶æãåå¾ããç¹ãç°ãªãã

       fstat()  㯠stat()  ã¨åãã ãã ç¶æãåå¾ãããã¡ã¤ã«ããã¡ã¤ã«ã»ãã£ã¹ã¯ãªãã¿ fd
       ã§æå®ããã

       ãããã®ã·ã¹ãã ã³ã¼ã«ã¯ãããããçµæã stat æ§é ä½ã«å¥ãã¦è¿ãã stat
       æ§é ä½ã«ã¯ä»¥ä¸ã®ãã£ã¼ã«ããå«ã¾ãã¦ãã:

           struct stat {
               dev_t     st_dev;     /* ãã¡ã¤ã«ãããããã¤ã¹ã® ID */
               ino_t     st_ino;     /* inode çªå· */
               mode_t    st_mode;    /* ã¢ã¯ã»ã¹ä¿è· */
               nlink_t   st_nlink;   /* ãã¼ããªã³ã¯ã®æ° */
               uid_t     st_uid;     /* ææèã®ã¦ã¼ã¶ ID */
               gid_t     st_gid;     /* ææèã®ã°ã«ã¼ã ID */
               dev_t     st_rdev;    /* ããã¤ã¹ ID (ç¹æ®ãã¡ã¤ã«ã®å ´å) */
               off_t     st_size;    /* å¨ä½ã®ãµã¤ãº (ãã¤ãåä½) */
               blksize_t st_blksize; /* ãã¡ã¤ã«ã·ã¹ãã  I/O ã§ã®
                                        ãããã¯ãµã¤ãº */
               blkcnt_t  st_blocks;  /* å²ãå½ã¦ããã 512B ã®ãããã¯æ° */
               time_t    st_atime;   /* æçµã¢ã¯ã»ã¹æå» */
               time_t    st_mtime;   /* æçµä¿®æ£æå» */
               time_t    st_ctime;   /* æçµç¶æå¤æ´æå» */
           };

       st_dev ãã£ã¼ã«ãã¯ããã®ãã¡ã¤ã«ãåå¨ããããã¤ã¹ã示ã (ãã¯ã major(3), minor(3)
       ã¯ããã®ãã£ã¼ã«ãã®ããã¤ã¹ ID ãå解ããã®ã«å½¹ç«ã¤ã ãã)ã

       st_rdev ãã£ã¼ã«ãã¯ããã®ãã¡ã¤ã« (inode) ã表ãããã¤ã¹ã示ãã

       st_size ãã£ã¼ã«ãã¯ã(é常ã®ãã¡ã¤ã«ãã·ã³ããªãã¯ãªã³ã¯ã®å ´åã«)
       ãã¡ã¤ã«ã®å¤§ããããã¤ãåä½ã§ç¤ºãã ã·ã³ããªãã¯ãªã³ã¯ã®å¤§ããã¯ã
       ã·ã³ããªãã¯ãªã³ã¯ã«å«ã¾ãã¦ãã ãã¹åã®é·ã (çµç«¯ã® NULL ãã¤ãã¯å«ã¾ãªã)
       ã§ããã

       st_blocks ãã£ã¼ã«ãã¯ããã¡ã¤ã«ã®å¤§ããã 512 ãã¤ãã®ãããã¯ãµã¤ãºåä½ã§ç¤ºã
       ãã£ã¼ã«ãã¯ããã¡ã¤ã«ã«å²ãå½ã¦ããããããã¯æ°ã 512 ãã¤ãåä½ã§ç¤ºãã
       (ãã¡ã¤ã«ã«ç©´ããããããªå ´åããã®å¤ã¯ st_size/512 ããå°ãããªããã¨ããã)ã

       st_blksize ãã£ã¼ã«ãã¯ãå¹ççã«ãã¡ã¤ã«ã·ã¹ãã  I/O ãã§ããã好ã¾ããã ãã‐
       ãã¯ãµã¤ãºã示ã (ãã£ã¨å°ããåä½ã§ãã¡ã¤ã«ã«æ¸ãè¾¼ã¿ãè¡ãã¨ã èªã¿åºã--ä¿®æ‐
       £--åæ¸ãè¾¼ã¿ã¨ãã£ãéå¹çãªåä½ã«ãªã£ã¦ãã¾ããããããªã)ã

       å¨ã¦ã® Linux ã®ãã¡ã¤ã«ã·ã¹ãã ãå¨ã¦ã®æéãã£ã¼ã«ãã å®è£ãã¦ããããã§ã¯ãªãã
       ãã¡ã¤ã«ããã£ã¬ã¯ããªã®ã¢ã¯ã»ã¹ã st_atime
       ãã£ã¼ã«ããæ´æ°ããªããããªããã¡ã§ãã¦ã³ãã§ãããã¡ã¤ã«ã·ã¹ãã ãããã (mount(8)  ã®
       noatime, nodiratime, relatime ã mount(2)  ã®é¢é£ããæå ±ãåç§)ã
       ã¾ãããã¡ã¤ã«ã O_NOATIME ä»ãã§ãªã¼ãã³ããã¦ããå ´åã«ã¯ st_atime ã¯æ´æ°ãããªãã
       open(2)  åç§ã

       st_atime ãã£ã¼ã«ãã¯ãã¡ã¤ã«ã¢ã¯ã»ã¹ããã£ãå ´åã«å¤æ´ããã (ä¾ãã°ã execve(2),
       mknod(2), pipe(2), utime(2)  ã使ç¨ããå ´åã read(2)  㧠1 ãã¤ã以ä¸èª‐
       ã¿è¾¼ãã å ´åãªã©)ã mmap(2)  ãªã©ã®ä»ã®ã«ã¼ãã³ã§ã¯ã st_atime
       ã¯æ´æ°ããããã¨ãããã°ãããã§ãªãå ´åãããã

       st_mtime ãã£ã¼ã«ãã¯ããã¡ã¤ã«ãä¿®æ£ãããå ´åã«å¤æ´ããã (ä¾ãã°ã mknod(2),
       truncate(2), utime(2)  ã使ç¨ããå ´åã write(2)  㧠1
       ãã¤ã以ä¸æ¸ãè¾¼ã¿ãããå ´åãªã©)ã ããã«ããã£ã¬ã¯ããªã® st_mtime
       ã¯ããã®ãã£ã¬ã¯ããªã§ ãã¡ã¤ã«ãä½æããããåé¤ããããããã¨å¤æ´ãããã st_mtime
       ãã£ã¼ã«ã㯠ææèãã°ã«ã¼ãããã¼ãã»ãªã³ã¯æ°ãã¢ã¼ãã®å¤æ´ã§ã¯å¤æ´ ãããªãã

       st_ctime ãã£ã¼ã«ãã¯æ¸ãè¾¼ã¿ã inode æå ±
       (ææèãã°ã«ã¼ãããªã³ã¯æ°ãã¢ã¼ããªã©) ã® è¨å®ã«ãã£ã¦å¤æ´ãããã

       以ä¸ã® POSIX ãã¯ãã¯ã st_mode ãã£ã¼ã«ã
       ã§ä½¿ç¨ããããã¡ã¤ã«ç¨®å¥ã®ãã§ãã¯ã®ããã«å®ç¾©ããã¦ãã :

           S_ISREG(m)  é常ã®ãã¡ã¤ã«ã?

           S_ISDIR(m)  ãã£ã¬ã¯ããªã?

           S_ISCHR(m)  ãã£ã©ã¯ã¿ã¼ã»ããã¤ã¹ã?

           S_ISBLK(m)  ãããã¯ã»ããã¤ã¹ã?

           S_ISFIFO(m) FIFO (ååä»ããã¤ã) ã?

           S_ISLNK(m)  ã·ã³ããªãã¯ãªã³ã¯ã? (POSIX.1-1996 ã«ã¯ãªã)

           S_ISSOCK(m) ã½ã±ããã? (POSIX.1-1996 ã«ã¯ãªã)

       以ä¸ã®ãã©ã°ã st_mode ãã£ã¼ã«ãç¨ã«å®ç¾©ããã¦ãã:

           S_IFMT     0170000   ãã¡ã¤ã«ç¨®å¥ã示ããããé åã表ãããããã¹ã¯
           S_IFSOCK   0140000   ã½ã±ãã
           S_IFLNK    0120000   ã·ã³ããªãã¯ãªã³ã¯
           S_IFREG    0100000   é常ã®ãã¡ã¤ã«
           S_IFBLK    0060000   ãããã¯ã»ããã¤ã¹
           S_IFDIR    0040000   ãã£ã¬ã¯ããª
           S_IFCHR    0020000   ãã£ã©ã¯ã¿ã¼ã»ããã¤ã¹
           S_IFIFO    0010000   FIFO
           S_ISUID    0004000   set-user-ID bit
           S_ISGID    0002000   set-group-ID bit (ä¸è¨åç§)
           S_ISVTX    0001000   ã¹ãã£ããã¼ã»ããã (ä¸è¨åç§)
           S_IRWXU    00700     ãã¡ã¤ã«ææèã®ã¢ã¯ã»ã¹è¨±å¯ç¨ã®ããããã¹ã¯
           S_IRUSR    00400     ææèã®èªã¿è¾¼ã¿è¨±å¯
           S_IWUSR    00200     ææèã®æ¸ãè¾¼ã¿è¨±å¯
           S_IXUSR    00100     ææèã®å®è¡è¨±å¯

           S_IRWXG    00070     ã°ã«ã¼ãã®ã¢ã¯ã»ã¹è¨±å¯ç¨ã®ããããã¹ã¯
           S_IRGRP    00040     ã°ã«ã¼ãã®èªã¿è¾¼ã¿è¨±å¯
           S_IWGRP    00020     ã°ã«ã¼ãã®æ¸ãè¾¼ã¿è¨±å¯
           S_IXGRP    00010     ã°ã«ã¼ãã®å®è¡è¨±å¯
           S_IRWXO    00007     ä»äºº (others) ã®ã¢ã¯ã»ã¹è¨±å¯ç¨ã®ããããã¹ã¯
           S_IROTH    00004     ä»äººã®èªã¿è¾¼ã¿è¨±å¯
           S_IWOTH    00002     ä»äººã®æ¸ãè¾¼ã¿è¨±å¯
           S_IXOTH    00001     ä»äººã®å®è¡è¨±å¯

       set-group-ID bit (S_ISGID)  ã«ã¯ããã¤ãã®ç¹æ®ãªä½¿ç¨æ³ããã:
       ãã£ã¬ã¯ããªã«è¨å®ããå ´åã«ã¯ããã®ãã£ã¬ã¯ããªã BSD æ¹å¼ã§ä½¿ç¨ããã
       ãã¨ã示ããã¤ã¾ãããã®ãã£ã¬ã¯ããªã«ä½æããããã¡ã¤ã«ã®ã°ã«ã¼ãID 㯠ä½æãããã‐
       ã»ã¹ã®å®å¹ (effective) ã°ã«ã¼ãID ã§ã¯ãªãããã£ã¬ã¯ããªã® ã°ã«ã¼ãID
       ãç¶æ¿ãããã¾ãããã®ãã£ã¬ã¯ããªã«ä½æããããã£ã¬ã¯ããªã«ã S_ISGID ããããè¨‐
       å®ããããã°ã«ã¼ãå®è¡ããã (S_IXGRP)  ãè¨å®ããã¦ããªããã¡ã¤ã«ã«è¨å®ãããå ´åã¯ã
       set-group-ID ãããã¯ãã¡ã¤ã«/ã¬ã³ã¼ãã® å¼·å¶ç㪠(mandatory) ããã¯ã表ãã

       ãã£ã¬ã¯ããªã«ã¹ãã£ããã¼ããã (S_ISVTX) ãè¨å®ãããå ´åã¯ã
       ãã®ãã£ã¬ã¯ããªã®ãã¡ã¤ã«ã®ååãå¤æ´ããããåé¤ãããã§ããã®ã¯ã
       ãã®ãã¡ã¤ã«ã®ææèãããã®ãã£ã¬ã¯ããªã®ææèããç¹æ¨©ããã»ã¹ ã ãã¨ãªãã

è¿ãå¤
       æåããå ´åã0 ãè¿ãããã 失æããå ´åã -1 ãè¿ããã errno ã«é©åãªå¤ãã»ãããããã

ã¨ã©ã¼
       EACCES path ãæå±ãããã£ã¬ã¯ããªã¨ãã®ä¸ä½ã®ãã£ã¬ã¯ããªã®ããããã«
              対ããæ¤ç´¢è¨±å¯ããªãã£ã (path_resolution(7) ãåç§ã®ãã¨)ã

       EBADF  fd ãä¸æ£ã§ããã

       EFAULT ã¢ãã¬ã¹ãééã£ã¦ããã

       ELOOP  ãã¹ã辿ãéã«è§£æ±ºãã¹ãã·ã³ããªãã¯ãªã³ã¯ãå¤éããã

       ENAMETOOLONG
              path ãé·éããã

       ENOENT path ã®æ§æè¦ç´ ãåå¨ããªããã path ã空æååã§ããã

       ENOMEM ã«ã¼ãã«ã®ã¡ã¢ãªã足ããªãã

       ENOTDIR
              path ã®ååé¨å (prefix) ã®æ§æè¦ç´ ããã£ã¬ã¯ããªã§ã¯ãªãã

       EOVERFLOW
              path ã¾ã㯠fd ãããã¡ã¤ã«ãµã¤ãºãinode çªå·ããããã¯æ°ã ãããã off_t åã
              ino_t åã blkcnt_t åã§è¡¨ç¾ã§ããªããã¡ã¤ã«ã
              åç§ãã¦ããããã®ã¨ã©ã¼ãèµ·ããã®ã¯ãä¾ãã°ã32 ããããã©ãããã©ã¼ã ä¸ã§
              -D_FILE_OFFSET_BITS=64 ãæå®ããã«ã³ã³ãã¤ã«ãããã¢ããªã±ã¼ã·ã§ã³ãã
              ãã¡ã¤ã«ãµã¤ãºã (1<<31)-1 ãã¤ããè¶ãããã¡ã¤ã«ã«å¯¾ã㦠stat()
              ãå¼ã³åºããå ´åã§ããã

æºæ
       ãããã®ã·ã¹ãã ã³ã¼ã«ã¯ SVr4, 4.3BSD, POSIX.1-2001 ã«æºæ ãã¦ããã stat()  ã¨
       fstat() ã³ã¼ã«ã¯ SVr4, SVID, POSIX, X/OPEN, 4.3BSD ã«æºæ ãã¦ããã lstat()
       ã³ã¼ã«ã¯ 4.3BSD 㨠SVr4 ã«æºæ ãã¦ããã

       POSIX.1-2001 ã§ã¯ãã·ã³ããªãã¯ãªã³ã¯ã«å¯¾ãã lstat() ã§
       æå¹ãªæå ±ãè¿ãããã«æ±ãããã¦ããã®ã¯ã stat æ§é ä½ã® st_size 㨠st_mode
       ã®ãã¡ã¤ã«ç¨®å¥è¦ç´ ã ãã§ãã£ãã POSIX.1-2008 ã§ã¯è¦å®ãå³ãããªãã lstat() ã¯
       st_mode ã® ã¢ã¯ã»ã¹è¨±å¯ããã以å¤ã®å¨ã¦ã®ãã£ã¼ã«ãã«æå¹ãªæå ±ãè¿ããã¨ã
       æ±ããããããã«ãªã£ã¦ããã

       st_blocks 㨠st_blksize ãã£ã¼ã«ãã®ä½¿ç¨ã¯ãã¾ã移æ¤æ§ããªã
       (ãããã®ãã£ã¼ã«ã㯠BSD ã«ãã£ã¦å°å¥ãããã ã·ã¹ãã ãã¨ã«è§£éã ç°ãªã£ã¦ããã NFS
       ãã¦ã³ãã®å ´åã«ã¯åãã·ã¹ãã ã§ãç°ãªãå¯è½æ§ããã)ã <sys/stat.h> ãã blkcnt_t
       ã® blksize_t åå®ç¾©ã èª‐
       ã¿è¾¼ã¿ããå ´åã¯ã(ã©ã®ããããã¡ã¤ã«ãã¤ã³ã¯ã«ã¼ããããããåã«) _XOPEN_SOURCE ã
       500 以ä¸ã®å¤ã§å®ç¾©ãããã¨ã

       POSIX.1-1990 ã«ã¯ S_IFMT, S_IFSOCK, S_IFLNK, S_IFREG, S_IFBLK, S_IFDIR,
       S_IFCHR, S_IFIFO, S_ISVTX å®æ°ã«é¢ãã è¨è¿°ã¯ãªãã£ããã代ããã« S_ISDIR()
       ã®ãããªãã¯ãã使ç¨ããããã« è¦æ±ãã¦ããã S_IF* å®æ°ã¯ POSIX.1-2001 以éã«ã¯å‐
       å¨ããã

       ãã¯ã S_ISLNK() 㨠S_ISSOCK() 㯠POSIX.1-1996 ã«ã¯ãªããã POSIX.1-2001
       ã«ã¯ä¸¡æ¹ã¨ãåå¨ããã åè㯠SVID 4 ã«ãå¾è㯠SUSv2 ã« ç±æ¥ãã¦ããã

       UNIX V7 (ã¨ãã®å¾ã®ã·ã¹ãã ) 㯠S_IREAD, S_IWRITE, S_IEXEC ãæã£ã¦ããã
       POSIX ã¯ãã®å義èªã¨ã㦠S_IRUSR, S_IWUSR, S_IXUSR ãè¦å®ãã¦ããã

   ä»ã®ã·ã¹ãã
       å種ã·ã¹ãã ã§ä½¿ç¨ããã¦ãã(ãã)å¤:

       16é²   åå         ls   8é²æ°    説æ
       f000   S_IFMT          170000   ãã¡ã¤ã«ç¨®å¥ãã£ã¼ã«ãã®ããããã¹ã¯
       0000                   000000   SCO ã§ã¯ 使ç¨ä¸è½ inode; BSD
                                       ã§ã¯ä¸æãªãã¡ã¤ã«ç¨®å¥; SVID-v2 ã¨
                                       XPG2 ã§ã¯ 0 㨠0100000
                                       ã®ä¸¡æ¹ãé常ã®ãã¡ã¤ã«
       1000   S_IFIFO    p|   010000   FIFO (ååä»ããã¤ã)
       2000   S_IFCHR    c    020000   ãã£ã©ã¯ã¿ç¹æ®ãã¡ã¤ã« (V7)
       3000   S_IFMPC         030000   å¤éåããããã£ã©ã¯ã¿ç¹æ®ãã¡ã¤ã« (V7)
       4000   S_IFDIR    d/   040000   ãã£ã¬ã¯ã㪠(V7)
       5000   S_IFNAM         050000   XENIX
                                       ã®äºã¤ã®å¯åãæã¤ååä»ãã®ç¹æ®ãã¡ã¤ã«
                                       å¯å㯠st_rdev ã®å¤ 1, 2 ã§åºå¥ããã
       0001   S_INSEM    s    000001   XENIX ã® IFNAM ã»ããã©å¯å
       0002   S_INSHD    m    000002   XENIX ã® IFNAM å±æãã¼ã¿å¯å
       6000   S_IFBLK    b    060000   ãããã¯ç¹æ®ãã¡ã¤ã« (V7)
       7000   S_IFMPB         070000   å¤éåããããããã¯ç¹æ®ãã¡ã¤ã« (V7)
       8000   S_IFREG    -    100000   é常ãã¡ã¤ã« (V7)
       9000   S_IFCMP         110000   VxFS å§ç¸®ãã¡ã¤ã«
       9000   S_IFNWK    n    110000   ãããã¯ã¼ã¯ç¹æ®ãã¡ã¤ã« (HP-UX)
       a000   S_IFLNK    l@   120000   ã·ã³ããªãã¯ãªã³ã¯ (BSD)
       b000   S_IFSHAD        130000   Solaris ã® ACL ç¨ã®é ã inode
                                       (ã¦ã¼ã¶ç©ºéããã¯è¦ããªã)
       c000   S_IFSOCK   s=   140000   ã½ã±ãã (BSD; VxFS ã® "S_IFSOC")
       d000   S_IFDOOR   D>   150000   Solaris ã® door ãã¡ã¤ã«
       e000   S_IFWHT    w%   160000   BSD ã®ç©ºç½ãã¡ã¤ã« (inode ã使ç¨ããªã)
       0200   S_ISVTX         001000   ã¹ãã£ããã¼ããã: 使ç¨å¾ãã¹ã¯ããã«æ®ã
                                       (V7)
                                       äºç´ (SVID-v2)
                                       ãã£ã¬ã¯ããªä»¥å¤: ãã¡ã¤ã«ããã£ãã·ã¥ããªã
                                       (SunOS)
                                       ãã£ã¬ã¯ããªã®å ´å: åé¤å¶éãã©ã°
                                       (SVID-v4.2)
       0400   S_ISGID         002000   å®è¡æã® set-group-ID (V7)
                                       ãã£ã¬ã¯ããªã®å ´å: GID ã®ä¼æ¬ã« BSD
                                       æ¹å¼ã使ç¨ãã
       0400   S_ENFMT         002000   System V ãã¡ã¤ã«ããã¯ãå¼·å¶ãã (S_ISGID
                                       ã¨å±æ)
       0800   S_ISUID         004000   å®è¡æã® set-user-ID (V7)
       0800   S_CDF           004000   ãã£ã¬ã¯ããªãã³ã³ããã¹ãä¾åãã¡ã¤ã«
                                       (HP-UX)

       ã¹ãã£ããã¼ ã³ãã³ã㯠Version 32V AT&T UNIX ã§ç»å ´ããã

注æ
       ã«ã¼ãã« 2.5.48 以éã§ã¯ã stat æ§é ä½ã¯ 3 ã¤ã®ãã¡ã¤ã«ã®ã¿ã¤ã ã¹ã¿ã³ã
       é¢é£ã®ãã£ã¼ã«ãã§ããç§åä½ã®ç²¾åº¦ã«å¯¾å¿ãã¦ããã glibc ã§ã¯ãæ©è½æ¤æ» ãã¯ã
       _BSD_SOURCE ã _SVID_SOURCE ãå®ç¾©ãããå ´åã«ãåãã£ã¼ã«ãã® ããç§ã®æå ±ã
       st_atim.tv_nsec ã¨ããå½¢å¼ã®ååã§å¬éããã ãããã®ãã£ã¼ã«ã㯠POSIX.1-2008
       ã§è¦å®ããã¦ããã ãã¼ã¸ã§ã³ 2.12 以éã® glibc ã§ã¯ã _POSIX_C_SOURCE ã
       200809L 以ä¸ã®å¤ã§å®ç¾©ããããã _XOPEN_SOURCE ã 700
       以ä¸ã®å¤ã§å®ç¾©ãããå ´åã«ã ãããã®ãã£ã¼ã«ããå¬éãããã ä¸è¨ã®ãã¯ã‐
       ã®ããããå®ç¾©ããã¦ããªãå ´åãããç§ã®å¤ã¯ st_atimensec ã¨ããå½¢å¼ã®ååã§å¬éãããã
       ç§ããç´°ããã¿ã¤ã ã¹ã¿ã³ãããµãã¼ããã¦ããªããã¡ã¤ã«ã·ã¹ãã ã§ã¯ã
       ããç§ã®ãã£ã¼ã«ã㯠0 ã«è¨å®ãããã

       Linux ã§ã¯ã lstat() ã¯ä¸è¬ã«ã¯èªåãã¦ã³ãåä½ (automounter action) ã®
       ãã£ããã¨ãªããªããã stat() ã¯ãã£ããã¨ãªã (fstatat(2) ãåç§)ã

       /proc ãã£ã¬ã¯ããªä»¥ä¸ã«ãããã¡ã¤ã«ã®ã»ã¨ãã©ã§ã¯ã stat()  ãå¼ã³åºããéã«ã
       st_size ãã£ã¼ã«ãã«ãã¡ã¤ã«ãµã¤ãºãè¿ãããªãã 代ããã« st_size ãã£ã¼ã«ãã«ã¯ 0
       ãè¿ãããã

   èå¾ã®ã«ã¼ãã«ã»ã¤ã³ã¿ãã§ã¼ã¹
       æéã®çµéã¨ã¨ãã«ã stat æ§é ä½ã®ãµã¤ãºã大ãããªãããã®å½±é¿ã§ stat()  ã«ã¯
       3ã¤ã®ãã¼ã¸ã§ã³ãåå¨ãã: sys_stat()  (ã¹ããã㯠__NR_oldstatsys_newstat()
       (ã¹ããã㯠__NR_statsys_stat64()  (ã«ã¼ãã« 2.4 ã§å°å¥; ã¹ãããã¯
       __NR_stat64).  glibc ã® stat()
       ã©ããã¼é¢æ°ã¯ãããã®è©³ç´°ãã¢ããªã±ã¼ã·ã§ã³ããé è½ãã¦ãããã
       å·ä½çã«ã¯ãã«ã¼ãã«ãæä¾ãã¦ããã·ã¹ãã ã³ã¼ã«ã®ãã¡ææ°ã®ãã¼ã¸ã§ã³ã
       èµ·åããå¤ããã¤ããªã®å ´åã«ã¯å¿è¦ã«å¿ãã¦è¿ãããæå ±ãåæ§æ (repack) ããã fstat()
       㨠lstat()  ã«ã¤ãã¦ãåæ§ã§ããã

ä¾
       以ä¸ã®ããã°ã©ã 㯠stat()  ãå¼ã³åºããè¿ã£ã¦ãã stat
       æ§é ä½ã®ãã£ã¼ã«ãã®ããã¤ãã表示ããã

       #include <sys/types.h>
       #include <sys/stat.h>
       #include <time.h>
       #include <stdio.h>
       #include <stdlib.h>

       int
       main(int argc, char *argv[])
       {
           struct stat sb;

           if (argc != 2) {
               fprintf(stderr, "Usage: %s <pathname>\n", argv[0]);
               exit(EXIT_FAILURE);
           }

           if (stat(argv[1], &sb) == -1) {
               perror("stat");
               exit(EXIT_FAILURE);
           }

           printf("File type:                ");

           switch (sb.st_mode & S_IFMT) {
           case S_IFBLK:  printf("block device\n");            break;
           case S_IFCHR:  printf("character device\n");        break;
           case S_IFDIR:  printf("directory\n");               break;
           case S_IFIFO:  printf("FIFO/pipe\n");               break;
           case S_IFLNK:  printf("symlink\n");                 break;
           case S_IFREG:  printf("regular file\n");            break;
           case S_IFSOCK: printf("socket\n");                  break;
           default:       printf("unknown?\n");                break;
           }

           printf("I-node number:            %ld\n", (long) sb.st_ino);

           printf("Mode:                     %lo (octal)\n",
                   (unsigned long) sb.st_mode);

           printf("Link count:               %ld\n", (long) sb.st_nlink);
           printf("Ownership:                UID=%ld   GID=%ld\n",
                   (long) sb.st_uid, (long) sb.st_gid);

           printf("Preferred I/O block size: %ld bytes\n",
                   (long) sb.st_blksize);
           printf("File size:                %lld bytes\n",
                   (long long) sb.st_size);
           printf("Blocks allocated:         %lld\n",
                   (long long) sb.st_blocks);

           printf("Last status change:       %s", ctime(&sb.st_ctime));
           printf("Last file access:         %s", ctime(&sb.st_atime));
           printf("Last file modification:   %s", ctime(&sb.st_mtime));

           exit(EXIT_SUCCESS);
       }

é¢é£é ç®
       access(2), chmod(2), chown(2), fstatat(2), readlink(2), utime(2),
       capabilities(7), symlink(7)

ãã®ææ¸ã«ã¤ãã¦
       ãã® man ãã¼ã¸ã¯ Linux man-pages ããã¸ã§ã¯ãã®ãªãªã¼ã¹ 3.51 ã®ä¸é¨
       ã§ãããããã¸ã§ã¯ãã®èª¬æã¨ãã°å ±åã«é¢ããæå ±ã¯
       http://www.kernel.org/doc/man-pages/ ã«æ¸ããã¦ããã



Linux                             2012-11-11                           STAT(2)