stat

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



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

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

       int stat(const char *file_name, struct stat *buf);
       int fstat(int filedes, struct stat *buf);
       int lstat(const char *file_name, struct stat *buf);

説æ
       ãããã®é¢æ°ã¯æå®ããããã¡ã¤ã«ã«ã¤ãã¦ã®æå ±ãè¿ãããããã®æå ±ã
       å¾ãããã«ã¯ãã®ãã¡ã¤ã«ã«å¯¾ãã¦ã®ã¢ã¯ã»ã¹æ¨©ã¯å¿è¦ãªããããããã®
       ãã¡ã¤ã«ã¸å°ããã¹ã«ãããã£ã¬ã¯ããªå¨ã¦ã®æ¤ç´¢æ¨©ãå¿è¦ã§ããã

       stat 㯠file_name ã§æå®ããããã¡ã¤ã«ã®ç¶æãåå¾ã buf ã¸æ ¼ç´ããã

       lstat 㯠stat
       ã¨åãã§ãããããªã³ã¯ã追跡ãã¦å¾ããããã¡ã¤ã«ã§ã¯ãªããªã³ã¯èªèº«ã®
       ç¶æãåå¾ããç¹ãç°ã£ã¦ããã

       fstat 㯠stat ã¨åãã§ãããã file_name ã®ãããã«( open(2) ã®è¿ã) filedes
       ã«ãã£ã¦æå®ããããªã¼ãã³ããããã¡ã¤ã«ã«ã¤ãã¦ç¶æãåå¾ããã


       ãããã¯å¨ã¦ä»¥ä¸ã®ããã«å®£è¨ããã stat æ§é ä½ãè¿ãã

              struct stat
              {
                  dev_t         st_dev;      /* device */
                  ino_t         st_ino;      /* inode */
                  umode_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 type (if inode device) */
                  off_t         st_size;     /* total size, in bytes */
                  unsigned long st_blksize;  /* blocksize for filesystem I/O */
                  unsigned long st_blocks;   /* number of 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 change */
              };

       st_blocks 㯠st_blksize ã®ãããã¯ã®ãµã¤ãºã®é 㨠常ã«ä¸è´ããããã§ã¯ãªãã
       st_blksize ã¯ãããã«å¹ççãªãã¡ã¤ã«ã»ã·ã¹ãã  I/O ã®ããã«ã好ã¾ãããå¤ã
       æä¾ãããããããªããã¨ã«æ³¨æãããã¨ã

       å¨ã¦ã® Linux ã®ãã¡ã¤ã«ã»ã·ã¹ãã ãå¨ã¦ã®æéãã£ã¼ã«ãã
       å®è£(implement)ãã¦ããããã§ã¯ãªããä¼çµ±çã« st_atime 㯠mknod(2), utime(2),
       read(2), write(2), truncate(2) ã«ãã£ã¦å¤æ´ãããã

       ä¼çµ±çã« st_mtime 㯠mknod(2), utime(2), write(2) ã«ãã£ã¦å¤æ´ãããã
       st_mtime 㯠ææè(owner)ãã°ã«ã¼ã(group)ããã¼ãã»ãªã³ã¯æ°(hard link count)ã
       ã¢ã¼ã(mode)ã®å¤æ´ã§ã¯å¤æ´ãã ãªãã

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

       以ä¸ã®ãã¯ãã¯ãã¡ã¤ã«ã®ç¨®é¡ã®ãã§ãã¯ã®ããã«å®ç¾©ããã :

              S_ISLNK(m)  ã·ã³ããªãã¯ã»ãªã³ã¯(symbolic link)ãï¼

              S_ISREG(m)  é常ã®ãã¡ã¤ã«ãï¼

              S_ISDIR(m)  ãã£ã¬ã¯ããªãï¼

              S_ISCHR(m)  ãã£ã©ã¯ã¿ã¼ã»ããã¤ã¹(character device)ãï¼

              S_ISBLK(m)  ãããã¯ã»ããã¤ã¹(block device)ãï¼

              S_ISFIFO(m) fifo ãï¼

              S_ISSOCK(m) ã½ã±ãã(socket)ãï¼

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

              S_IFMT   00170000
                       ãã¡ã¤ã«ç¨®å¥ããããã£ã¼ã«ã(bitfield)ã®ããããããã¹ã¯(bitmask)

              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 UID bit

              S_ISGID  0002000 set GID bit

              S_ISVTX  0001000 ã¹ãã£ããã¼ã»ããã(sticky bit)

              S_IRWXU  00700 ã¦ã¼ã¶ã¼(ãã¡ã¤ã«ã®ææè)ã®èª‐
                       ã¿è¾¼ã¿ãæ¸ãè¾¼ã¿ãå®è¡è¨±å¯

              S_IRUSR (S_IREAD)
                       00400 ã¦ã¼ã¶ã¼ã®èªã¿è¾¼ã¿è¨±å¯

              S_IWUSR (S_IWRITE)
                       00200 ã¦ã¼ã¶ã¼ã®æ¸ãè¾¼ã¿è¨±å¯

              S_IXUSR (S_IEXEC)
                       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 ä»äººã®å®è¡è¨±å¯

è¿ãå¤
       æåããå ´åã¯ã¼ããè¿ããã¨ã©ã¼ã®å ´å㯠-1 ãè¿ãã errno ãé©åã«è¨å®ãããã

ã¨ã©ã¼
       EBADF  filedes ãä¸æ£

       ENOENT ãã¡ã¤ã«ãåå¨ããªãã

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

       EACCES 許å¯ããªãã

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

       ENAMETOOLONG
              ãã¡ã¤ã«åãé·éããã

æºæ
       stat 㨠fstat ã³ã¼ã«ã¯ SVr4, SVID, POSIX, X/OPEN, 4.3BSD ã«æºæ ãã¦ããã
       lstat ã³ã¼ã«ã¯ 4.3BSD 㨠SVr4 ã«æºæ ãã¦ããã call conforms to 4.3BSD and
       SVr4.  SVr4 ã«ã¯ä»ã« fstat ã®ã¨ã©ã¼ã¨ã㦠EFAULT, EINTR, ENOLINK,
       EOVERFLOW ã«ã¤ãã¦ã®è¨è¿°ãããã SVr4 ã«ã¯ä»ã« stat 㨠lstat ã®ã¨ã©ã¼ã¨ãã¦
       EACCES, EFAULT, EINTR, ELOOP, EMULTIHOP, ENAMETOOLONG, ENOTDIR,
       ENOLINK, EOVERFLOW ã«ã¤ãã¦ã®è¨è¿°ãããã

é¢é£é ç®
       chmod(2), chown(2), readlink(2), utime(2)



Linux 1.1.75                    1 January 1995                         STAT(2)