STAT

Section: System calls (2)
Updated: May 13, 1998
Index
Return to Main Contents
 

À̸§

stat, fstat, lstat - ÆÄÀÏ »óŸ¦ ¾ò´Â´Ù  

»ç¿ë¹ý

#include <sys/types.h>
#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. ´ë½Å¿¡ filedes ¿¡ ÀÇÇØ ÁöÁ¤µÈ ¿­¸° ÆÄÀϸ¸ ( open(2) ¿¡ ÀÇÇØ ¹ÝȯµÇµíÀÌ) ¼³¸íµÈ´Ù.

±×°ÍµéÀº ¸ðµÎ ¾Æ·¡ ¿µ¿ªÀ» Æ÷ÇÔÇÏ´Â stat ±¸Á¶À» ¹ÝȯÇÑ´Ù:

struct stat
{
    dev_t         st_dev;      /* device */
    ino_t         st_ino;      /* inode */
    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 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 */
};

The value st_blocks °ªÀº 512-bytes ºí·Ï¿¡ ÀÖ´Â ÆÄÀÏÀÇ Å©±â¸¦ ÁØ´Ù. st_blksize °ªÀº È¿À²ÀûÀÎ ÆÄÀÏ ½Ã½ºÅÛ I/O¸¦ À§ÇØ "¼±ÅõÈ" ºí·Ï Å©±â¸¦ ÁØ´Ù. (´õ ÀÛÀº °ø°£¿¡ ÆÄÀÏÀ» ¾²´Â °ÍÀº ¾²°í-¼öÁ¤ÇÏ°í-´Ù½Ã ¾²´Âµ¥ ºñÈ¿À²ÀûÀÌ´Ù.)4

¸ðµç ¸®´ª½º ÆÄÀϽýºÅÛÀÌ ¸ðµç ½Ã°£ ¿µ¿ª¿¡¼­ ½ÇÇàÇÏ´Â °ÍÀº ¾Æ´Ï´Ù. ÀüÅëÀûÀ¸·Î, st_atime ´Â mknod(2), utime(2), read(2), write(2),¿Í truncate(2). ·Î ¹Ù²î¾ú´Ù. ÀüÅëÀûÀ¸·Î, st_mtime ´Â mknod(2), utime(2),¿Í write(2). ·Î ¹Ù²î¾ú´Ù. st_mtime ´Â ¼ÒÀ¯ÀÚ, ±×·ì, Çϵ帵ũ Ä«¿îÆ®, ȤÀº ¸ðµåÀÇ º¯È­¿¡ µû¶ó ¹Ù²îÁö ¾Ê¾Ò´Ù. ÀüÅëÀûÀ¸·Î, st_ctime ´Â inode Á¤º¸¸¦ ¾²°Å³ª ¼³Á¤ÇÔÀ¸·Î½á ¹Ù²î¾ú´Ù.(i.e., owner, group,link count, mode,µîµî).

¾Æ·¡ POSIX ¸ÅÅ©·Î´Â ÆÄÀÏ Å¸ÀÔÀ» È®ÀÎÇÏ´Â °ÍÀÌ´Ù:

S_ISLNK(m)
is it a symbolic link?
S_ISREG(m)
regular file?
S_ISDIR(m)
directory?
S_ISCHR(m)
character device?
S_ISBLK(m)
block device?
S_ISFIFO(m)
fifo?
S_ISSOCK(m)
socket?

¾Æ·¡ flag´Â st_mode ¿µ¿ªÀ» À§ÇØ Á¤ÀÇµÈ °ÍÀÌ´Ù:
S_IFMT0170000bitmask for the file type bitfields
S_IFSOCK0140000socket
S_IFLNK0120000symbolic link
S_IFREG0100000regular file
S_IFBLK0060000block device
S_IFDIR0040000directory
S_IFCHR0020000character device
S_IFIFO0010000fifo
S_ISUID0004000set UID bit
S_ISGID0002000set GID bit (see below)
S_ISVTX0001000sticky bit (see below)
S_IRWXU00700mask for file owner permissions
S_IRUSR00400owner has read permission
S_IWUSR00200owner has write permission
S_IXUSR00100owner has execute permission
S_IRWXG00070mask for group permissions
S_IRGRP00040group has read permission
S_IWGRP00020group has write permission
S_IXGRP00010group has execute permission
S_IRWXO00007mask for permissions for others (not in group)
S_IROTH00004others have read permission
S_IWOTH00002others have write permisson
S_IXOTH00001others have execute permission
GID ºñÆ® (S_ISGID)¼³Á¤Àº ¸î°¡Áö Ưº°ÇÑ ÀÌ¿ë¹ýÀÌ ÀÖ´Ù: µð·ºÅ丮ÀÇ °æ¿ì BSD semanticÀÌ ¾²ÀÌ°í ÀÖÀ½ÀÌ ³ªÅ¸³­´Ù: »ý¼ºµÈ ÆÄÀÏÀº »ý¼º ÇÁ·Î¼¼½º¿Í »ý¼ºµÈ µð·ºÅ丮ÀÇ À¯È¿ÇÑ gid·ÎºÎÅÍ°¡ ¾Æ´Ï¶ó µð·ºÅ丮·ÎºÎÅÍ ±×µéÀÇ ±×·ì ID¸¦ »ó¼Ó¹Þ´Â´Ù. ±×¸®°í S_ISGID ºñÆ®±ºÀ» °¡Áø´Ù. ½ÇÇà ºñÆ®(S_IXGRP)±ºÀ» °®Áö ¾ÊÀº ÆÄÀÏÀÇ °æ¿ì, mandatory file/record lockingÀ» ³ªÅ¸³½´Ù. µð·ºÅ丮 »óÀÇ `sticky' bit (S_ISVTX)´Â µð·ºÅ丮¾ÈÀÇ ÆÄÀÏÀÌ ÆÄÀÏÀÇ ¼ÒÀ¯ÀÚ, µð·ºÅ丮ÀÇ ¼ÒÀ¯ÀÚ, ±×¸®°í ·çÆ®¿¡ ÀÇÇØ À̸§À» ¹Ù²î°Å³ª Áö¿öÁú ¼ö ÀÖ´Ù´Â °ÍÀ» ¶æÇÑ´Ù.  

¹Ýȯ°ª

¼º°ø½Ã, 0ÀÌ ¹ÝȯµÇ°í, ½ÇÆнÃ, -1ÀÌ ¹ÝȯµÈ´Ù. ±×¸®°í errno ´Â ÀûÀýÇÑ °ªÀ¸·Î ¼³Á¤µÈ´Ù.  

¿¡·¯

EBADF
filedes ´Â À߸øµÆ´Ù.
ENOENT
A component of the path file_name °æ·ÎÀÇ ±¸¼º¿ä¼Ò°¡ Á¸ÀçÇÏÁö ¾Ê°Å³ª °æ·Î°¡ ºó ¹®ÀÚ¿­ÀÌ´Ù.
ENOTDIR
°æ·ÎÀÇ ±¸¼º¿ä¼Ò°¡ µð·ºÅ丮°¡ ¾Æ´Ï´Ù.
ELOOP
½Éº¼¸¯¸µÅ©°¡ ³Ê¹« ¸¹´Ù.
EFAULT
À߸øµÈ ÁÖ¼ÒÀÌ´Ù.
EACCES
±ÇÇÑÀÌ °ÅºÎµÆ´Ù.
ENOMEM
¸Þ¸ð¸® ºÎÁ·.
ENAMETOOLONG
ÆÄÀϸíÀÌ ³Ê¹« ±æ´Ù.
 

ȣȯ

stat ¿Í fstat È£ÃâÀº SVr4, SVID, POSIX, X/OPEN, BSD 4.3¿¡ µû¸¥´Ù. lstat È£ÃâÀº 4.3BSD and SVr4¿¡ µû¸¥´Ù. SVr4´Â Ãß°¡ÀûÀ¸·Î documents additional fstat ¿¡·¯ »óÅÂÀÎ EINTR, ENOLINK, EOVERFLOW¸¦ ¹®¼­È­Çß´Ù. SVr4 ´Â Ãß°¡ÀûÀ¸·Î stat ¿Í lstat ÀÇ ¿¡·¯ÀÎ EACCES, EINTR, EMULTIHOP, ENOLINK, EOVERFLOW¸¦ ¹®¼­È­Çß´Ù. st_blocks ¿Í st_blksize ÇʵåÀÇ »ç¿ëÀº ÀÌ½ÄµÉ ¼ö ¾ø´Ù. (±×°ÍµéÀº POSIX¿¡ÀÇÇØ ÁöÁ¤µÈ°ÍÀÌ ¾Æ´Ï°í BSD¿¡¼­ ¼Ò°³µÇ¾ú´Ù. Çؼ®Àº ½Ã½ºÅÛ¸¶´Ù ´Ù¸£°í, ½Ì±Û ½Ã½ºÅÛ¿¡¼­ NFS°¡ ¸¶¿îÆ®µÇ¸é º¹ÀâÇØÁø´Ù.)

POSIXÀº S_IFMT, S_IFSOCK, S_IFLNK, S_IFREG, S_IFBLK, S_IFDIR, S_IFCHR, S_IFIFO, S_ISVTX ºñÆ®¿¡ ´ëÇØ ¼³¸íÇÏÁö ¾ÊÁö¸¸, ´ë½Å S_ISDIR()µîÀÇ ¸ÅÅ©·Î »ç¿ëÀº ¿ä±¸ÇÑ´Ù. À¯´Ð½º V7 (À̳ª ÈÄÀÇ ½Ã½ºÅÛ)Àº POSIX¿¡¼­ ±ÔÁ¤ÇÑ À¯»ç¾îÀÎ S_IRUSR, S_IWUSR, S_IXUSR ÀÇ S_IREAD, S_IWRITE, S_IEXEC¸¦ °®´Â´Ù.  

Ÿ ½Ã½ºÅÛ

´Ù¾çÇÑ ½Ã½ºÅÛ¿¡¼­ »ç¿ëµÇ´Â °ªµé:
hexÀ̸§lsoctal¼³¸í
f000S_IFMT170000ÆÄÀÏŸÀÔÀ» À§ÇÑ mask
0000000000SCO out-of-service inode, BSD unknown type
SVID-v2 and XPG2 have both 0 and 0100000 for ordinary file
1000S_IFIFOp|010000fifo (named pipe)
2000S_IFCHRc020000character special (V7)
3000S_IFMPC030000multiplexed character special (V7)
4000S_IFDIRd/040000directory (V7)
5000S_IFNAM050000XENIX named special file
with two subtypes, distinguished by st_rdev values 1, 2:
0001S_INSEMs000001XENIX semaphore subtype of IFNAM
0002S_INSHDm000002XENIX shared data subtype of IFNAM
6000S_IFBLKb060000block special (V7)
7000S_IFMPB070000multiplexed block special (V7)
8000S_IFREG-100000regular (V7)
9000S_IFCMP110000VxFS compressed
9000S_IFNWKn110000network special (HP-UX)
a000S_IFLNKl@120000symbolic link (BSD)
b000S_IFSHAD130000Solaris shadow inode for ACL (not seen by userspace)
c000S_IFSOCKs=140000socket (BSD; also "S_IFSOC" on VxFS)
d000S_IFDOORD150000Solaris door
e000S_IFWHTw%160000BSD whiteout (not used for inode)

0200S_ISVTX001000`sticky bit': save swapped text even after use (V7)
reserved (SVID-v2)
On non-directories: don't cache this file (SunOS)
On directories: restricted deletion flag (SVID-v4.2)
0400S_ISGID002000set group ID on execution (V7)
for directories: use BSD semantics for propagation of gid
0400S_ENFMT002000SysV file locking enforcement (shared w/ S_ISGID)
0800S_ISUID004000set user ID on execution (V7)
0800S_CDF004000directory is a context dependent file (HP-UX)
sticky ¸í·ÉÀº AT&T UNIX V32¿¡¼­ ¼±º¸¿´´Ù.  

°ü·Ã Ç׸ñ

chmod(2), chown(2), readlink(2), utime(2)


 

Index

À̸§
»ç¿ë¹ý
¼³¸í
¹Ýȯ°ª
¿¡·¯
ȣȯ
Ÿ ½Ã½ºÅÛ
°ü·Ã Ç׸ñ

This document was created by man2html, using the manual pages.
Time: 08:07:01 GMT, March 25, 2004