Rechercher une page de manuel

Chercher une autre page de manuel:

stat

Autres langues

Langue: ja

Version: 2007-06-08 (openSuse - 09/10/07)

Autres sections - même nom

Section: 2 (Appels système)

̾Á°

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 filedes, struct stat *buf);
int lstat(const char *path, struct stat *buf);

ÀâÌÀ

¤³¤ì¤é¤Î´Ø¿ô¤Ï¥Õ¥¡¥¤¥ë¤Ë¤Ä¤¤¤Æ¤Î¾ðÊó¤òÊÖ¤¹¡£ ¥Õ¥¡¥¤¥ë¤½¤Î¤â¤Î¤ËÂФ¹¤ë¥¢¥¯¥»¥¹µö²Ä¤ÏɬÍפȤ·¤Ê¤¤¤¬¡¢ --- stat() ¤È lstat() ¤Î¾ì¹ç¤Ë¤Ï --- ¤½¤Î¥Õ¥¡¥¤¥ë¤Ø»ê¤ë path ¤ò¹½À®¤¹¤ëÁ´¤Æ¤Î¥Ç¥£¥ì¥¯¥È¥ê¤ËÂФ¹¤ë¼Â¹Ô (¸¡º÷) µö²Ä¤¬É¬ÍפǤ¢¤ë¡£

stat() ¤Ï path ¤Ç»ØÄꤵ¤ì¤¿¥Õ¥¡¥¤¥ë¤Î¾õÂÖ¤ò¼èÆÀ¤·¤Æ buf ¤Ø³ÊǼ¤¹¤ë¡£

lstat() ¤Ï stat() ¤ÈƱ¤¸¤Ç¤¢¤ë¤¬¡¢ path ¤¬¥·¥ó¥Ü¥ê¥Ã¥¯¥ê¥ó¥¯¤Î¾ì¹ç¡¢¥ê¥ó¥¯¤¬»²¾È¤·¤Æ¤¤¤ë¥Õ¥¡¥¤¥ë¤Ç¤Ï¤Ê¤¯¡¢ ¥ê¥ó¥¯¼«¿È¤Î¾õÂÖ¤ò¼èÆÀ¤¹¤ëÅÀ¤¬°Û¤Ê¤ë¡£

fstat() ¤Ï stat() ¤ÈƱ¤¸¤À¤¬¡¢ ¾õÂÖ¤ò¼èÆÀ¤¹¤ë¥Õ¥¡¥¤¥ë¤ò¥Õ¥¡¥¤¥ë¡¦¥Ç¥£¥¹¥¯¥ê¥×¥¿ filedes ¤Ç»ØÄꤹ¤ë¡£

¤³¤ì¤é¤Î¥·¥¹¥Æ¥à¥³¡¼¥ë¤Ï¤¤¤º¤ì¤â¡¢·ë²Ì¤ò 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;  /* ³ä¤êÅö¤Æ¤é¤ì¤¿¥Ö¥í¥Ã¥¯¿ô */

    time_t    st_atime;   /* ºÇ½ª¥¢¥¯¥»¥¹»þ¹ï */

    time_t    st_mtime;   /* ºÇ½ª½¤Àµ»þ¹ï */

    time_t    st_ctime;   /* ºÇ½ª¾õÂÖÊѹ¹»þ¹ï */

};

st_dev ¥Õ¥£¡¼¥ë¥É¤Ï¡¢¤³¤Î¥Õ¥¡¥¤¥ë¤¬Â¸ºß¤¹¤ë¥Ç¥Ð¥¤¥¹¤ò¼¨¤¹¡£

st_rdev ¥Õ¥£¡¼¥ë¥É¤Ï¡¢¤³¤Î¥Õ¥¡¥¤¥ë (inode) ¤¬É½¤¹¥Ç¥Ð¥¤¥¹¤ò¼¨¤¹¡£

st_size ¥Õ¥£¡¼¥ë¥É¤Ï¡¢(Ä̾ï¤Î¥Õ¥¡¥¤¥ë¤«¥·¥ó¥Ü¥ê¥Ã¥¯¥ê¥ó¥¯¤Î¾ì¹ç¤Ë) ¥Õ¥¡¥¤¥ë¤ÎÂ礭¤µ¤ò¥Ð¥¤¥Èñ°Ì¤Ç¼¨¤¹¡£ ¥·¥ó¥Ü¥ê¥Ã¥¯¥ê¥ó¥¯¤ÎÂ礭¤µ¤Ï¡¢¥·¥ó¥Ü¥ê¥Ã¥¯¥ê¥ó¥¯¤Ë´Þ¤Þ¤ì¤Æ¤¤¤ë ¥Ñ¥¹Ì¾¤ÎŤµ (ºÇ¸å¤Î NULL ¥Ð¥¤¥È¤Ï´Þ¤Þ¤Ê¤¤) ¤Ç¤¢¤ë¡£

st_blocks ¥Õ¥£¡¼¥ë¥É¤Ï¡¢¥Õ¥¡¥¤¥ë¤ÎÂ礭¤µ¤ò 512 ¥Ð¥¤¥È¤Î¥Ö¥í¥Ã¥¯¥µ¥¤¥ºÃ±°Ì¤Ç¼¨¤¹ ¥Õ¥£¡¼¥ë¥É¤Ï¡¢¥Õ¥¡¥¤¥ë¤Ë³ä¤êÅö¤Æ¤µ¤ì¤¿¥Ö¥í¥Ã¥¯¿ô¤ò 512 ¥Ð¥¤¥Èñ°Ì¤Ç¼¨¤¹¡£ (Î㤨¤Ð¥Õ¥¡¥¤¥ë¤Ë·ê¤¬¤¢¤ë¤è¤¦¤Ê¾ì¹ç¡¢¤³¤ÎÃÍ¤Ï st_size/512 ¤è¤ê¾®¤µ¤¯¤Ê¤ë¤³¤È¤â¤¢¤ë)¡£

st_blksize ¥Õ¥£¡¼¥ë¥É¤Ï¡¢¸úΨŪ¤Ë¥Õ¥¡¥¤¥ë¡¦¥·¥¹¥Æ¥à I/O ¤¬¤Ç¤­¤ë¡Ö¹¥¤Þ¤·¤¤¡× ¥Ö¥í¥Ã¥¯¥µ¥¤¥º¤ò¼¨¤¹ (¤â¤Ã¤È¾®¤µ¤¤Ã±°Ì¤Ç¥Õ¥¡¥¤¥ë¤Ë½ñ¤­¹þ¤ß¤ò¹Ô¤¦¤È¡¢ Æɤ߽Ф·--½¤Àµ--ºÆ½ñ¤­¹þ¤ß¤È¤¤¤Ã¤¿Èó¸úΨ¤ÊÆ°ºî¤Ë¤Ê¤Ã¤Æ¤·¤Þ¤¦¤«¤â¤·¤ì¤Ê¤¤)¡£

Á´¤Æ¤Î Linux ¤Î¥Õ¥¡¥¤¥ë¡¦¥·¥¹¥Æ¥à¤¬Á´¤Æ¤Î»þ´Ö¥Õ¥£¡¼¥ë¥É¤ò ¼ÂÁõ¤·¤Æ¤¤¤ë¤ï¤±¤Ç¤Ï¤Ê¤¤¡£ ¥Õ¥¡¥¤¥ë¥¢¥¯¥»¥¹¤¬ st_atime ¥Õ¥£¡¼¥ë¥É¤ò¹¹¿·¤·¤Ê¤¤¤è¤¦¤Ê¤«¤¿¤Á¤Ç¥Þ¥¦¥ó¥È¤Ç¤­¤ë¥Õ¥¡¥¤¥ë¥·¥¹¥Æ¥à¤â¤¢¤ë¡£ (mount(8) ¤Î `noatime' ¥ª¥×¥·¥ç¥ó¤ò»²¾È)

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
filedes ¤¬ÉÔÀµ¤Ç¤¢¤ë¡£
EFAULT
¥¢¥É¥ì¥¹¤¬´Ö°ã¤Ã¤Æ¤¤¤ë¡£
ELOOP
¥Ñ¥¹¤òé¤ëºÝ¤Ë²ò·è¤¹¤Ù¤­¥·¥ó¥Ü¥ê¥Ã¥¯¡¦¥ê¥ó¥¯¤¬Â¿²á¤®¤¿¡£
ENAMETOOLONG
¥Õ¥¡¥¤¥ë̾¤¬Ä¹²á¤®¤ë¡£
ENOENT
¥Ñ¥¹ path ¤Î¹½À®Í×ÁǤ¬Â¸ºß¤·¤Ê¤¤¤«¡¢¥Ñ¥¹¤¬¶õʸ»úÎó¤Ç¤¢¤ë¡£
ENOMEM
¥«¡¼¥Í¥ë¤Î¥á¥â¥ê¤¬Â­¤ê¤Ê¤¤¡£
ENOTDIR
¥Ñ¥¹¤Î¹½À®Í×ÁǤ¬¥Ç¥£¥ì¥¯¥È¥ê¤Ç¤Ï¤Ê¤¤¡£

½àµò

¤³¤ì¤é¤Î¥·¥¹¥Æ¥à¥³¡¼¥ë¤Ï SVr4, 4.3BSD, POSIX.1-2001 ¤Ë½àµò¤·¤Æ¤¤¤ë¡£ stat() ¤È fstat() ¥³¡¼¥ë¤Ï SVr4, SVID, POSIX, X/OPEN, 4.3BSD ¤Ë½àµò¤·¤Æ¤¤¤ë¡£ lstat() ¥³¡¼¥ë¤Ï 4.3BSD ¤È SVr4 ¤Ë½àµò¤·¤Æ¤¤¤ë¡£

st_blocks ¤È st_blksize ¥Õ¥£¡¼¥ë¥É¤Î»ÈÍѤϤ¢¤Þ¤ê°Ü¿¢À­¤¬¤Ê¤¤¡£ (¤³¤ì¤é¤Î¥Õ¥£¡¼¥ë¥É¤Ï BSD ¤Ë¤è¤Ã¤ÆƳÆþ¤µ¤ì¤¿¡£ ¥·¥¹¥Æ¥à¤´¤È¤Ë²ò¼á¤¬°Û¤Ê¤Ã¤Æ¤ª¤ê¡¢ NFS ¥Þ¥¦¥ó¥È¤Î¾ì¹ç¤Ë¤ÏƱ¤¸¥·¥¹¥Æ¥à¤Ç¤â°Û¤Ê¤ë²ÄǽÀ­¤¬¤¢¤ë)

POSIX ¤Ë¤Ï S_IFMT, S_IFSOCK, S_IFLNK, S_IFREG, S_IFBLK, S_IFDIR, S_IFCHR, S_IFIFO, S_ISVTX ¥Ó¥Ã¥È¤Ë¤Ä¤¤¤Æ¤Îµ­½Ò¤Ï¤Ê¤¤¡£¤«¤ï¤ê¤Ë S_ISDIR() ¤Î¤è¤¦¤Ê ¥Þ¥¯¥í¤ò»ÈÍѤ¹¤ë¤è¤¦¤ËÍ׵ᤷ¤Æ¤¤¤ë¡£ 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 ¥É¥¢¡¦¥Õ¥¡¥¤¥ë
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 SysV ¥Õ¥¡¥¤¥ë¡¦¥í¥Ã¥¯¤ò¶¯À©¤¹¤ë
(S_ISGID ¤È¶¦Í­)
0800 S_ISUID 004000 ¼Â¹Ô»þ¤Î set-user-ID (V7)
0800 S_CDF 004000 ¥Ç¥£¥ì¥¯¥È¥ê¤¬¾õ¶·°Í¸¥Õ¥¡¥¤¥ë (HP-UX)

¥¹¥Æ¥£¥Ã¥­¡¼ ¥³¥Þ¥ó¥É¤Ï Version 32V AT&T UNIX ¤ÇÅо줷¤¿¡£

Ãí°Õ

Linux ¤Ç¤ÎÃí°Õ

¥«¡¼¥Í¥ë 2.5.48 °Ê¹ß¤Ç¤Ï¡¢ stat ¹½Â¤ÂÎ¤Ï 3¤Ä¤Î¥Õ¥¡¥¤¥ë¤Î¥¿¥¤¥à¥¹¥¿¥ó¥×´ØÏ¢¤Î¥Õ¥£¡¼¥ë¥É¤Ç ¥Ê¥ÎÉÃñ°Ì¤ÎÀºÅÙ¤ËÂбþ¤·¤Æ¤¤¤ë¡£ glibc ¤Ç¤Ï¡¢³Æ¥Õ¥£¡¼¥ë¥É¤Î¥Ê¥ÎÉäξðÊó¤ò st_atim.tv_nsec ¤ä st_atimensec ¤È¤¤¤Ã¤¿·Á¤Ç»²¾È¤Ç¤­¤ë¡£ µ¡Ç½¸¡ºº¥Þ¥¯¥í _BSD_SOURCE ¤« _SVID_SOURCE ¤¬ÄêµÁ¤µ¤ì¤Æ¤¤¤ë¾ì¹ç¤Ë¤Ï st_atim.tv_nsec ¤Î·Á¼°¤Ç¡¢¤½¤ì°Ê³°¤Î¾ì¹ç¤Ë¤Ï st_atimensec ¤Î·Á¼°¤È¤Ê¤ë¡£ Éäè¤êºÙ¤«¤¤¥¿¥¤¥à¥¹¥¿¥ó¥×¤ò¥µ¥Ý¡¼¥È¤·¤Æ¤¤¤Ê¤¤¥Õ¥¡¥¤¥ë¥·¥¹¥Æ¥à¤Ç¤Ï¡¢ ¤³¤ì¤é¤Î¥Ê¥ÎÉäΥե£¡¼¥ë¥É¤Ï 0 ¤ËÀßÄꤵ¤ì¤ë¡£

/proc ¥Ç¥£¥ì¥¯¥È¥ê°Ê²¼¤Ë¤¢¤ë¥Õ¥¡¥¤¥ë¤Î¤Û¤È¤ó¤É¤Ç¤Ï¡¢ stat() ¤ò¸Æ¤Ó½Ð¤·¤¿ºÝ¤Ë¡¢ st_size ¥Õ¥£¡¼¥ë¥É¤Ë¥Õ¥¡¥¤¥ë¥µ¥¤¥º¤¬ÊÖ¤µ¤ì¤Ê¤¤¡£ Âå¤ï¤ê¤Ë st_size ¥Õ¥£¡¼¥ë¥É¤Ë¤Ï 0 ¤¬ÊÖ¤µ¤ì¤ë¡£

Îã

°Ê²¼¤Î¥×¥í¥°¥é¥à¤Ï stat(2) ¤ò¸Æ¤Ó½Ð¤·¡¢Ê֤äƤ­¤¿ 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_SUCCESS);

    }



    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 i-node 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)
Nous sommes plus près d'aimer ceux qui nous haïssent
que ceux qui nous aiment plus que nous ne voulons.
-+- François de La Rochefoucauld (1613-1680), Maximes 321 -+-