stat

Language/C 2011. 11. 8. 14:23

#include<stdio.h>

#include<sys/types.h>

#include<sys/stat.h>

 

/**********************************

struct stat{

dev_t   st_dev;

ino_t   st_ino;

mode_t  st_mode;

nlink_t st_nlink;

uid_t   st_uid;

gid_t   st_gid;

dev_t   st_rdev;

off_t   st_size;

blksize_t st_blksize;

blkcnt_t st_blocks;

time_t  st_atime;

time_t  st_mtime;

time_t  st_ctime;

};

***********************************/

int main(int ac, char *av[])

{

    struct stat info;

 

    if( stat(av[1], &info) != -1 ){

        /*적재된파일시스템을위한장치.

        적재된각파일시스템은서로다른st_dev 값을가진다*/

        printf("device : %d\n", info.st_dev);

 

        /*해당파일시스템내에서그파일의아이노드번호.

        (st_dev, st_ino)쌍으로서로다른파일을구별한다*/

        printf("inode  : %d\n", info.st_ino);

 

        /*파일타입과접근허가가함께코드화되어있는필드*/

        printf("type and protection : %d\n", info.st_mode);

 

        /*이파일에대한하드링크의개수(링크개수).

        파일이열린후에링크가끊어졌다면(unlink) 이필드값은0이될수있다*/

        printf("number of hard links : %d\n", info.st_nlink);

 

        /*파일의UID(소유자번호)*/

        printf("user ID of owner : %d\n", info.st_uid);

 

        /*파일의GID(그룹번호)*/

        printf("group ID of owner : %d\n", info.st_gid);

 

        /*파일이블록또는문자장치일경우의장치타입.

        st_rdev는장치에관한정보를코드화한것이다.*/

        printf("device type (block or character device) : %d\n", info.st_rdev);

 

        /*파일의논리적인크기파일내에는여러개의구멍이있을수있으며,

        이경우에이크기는그파일이차지하고있는실제저장공간의크기를

        제대로반영하지못할수도있다*/

        printf("total size, in bytes : %d\n", info.st_size);

 

        /*파일의'블록크기'. 이필드는해당파일에대한I/O를위한

        적합한데이터블록의크기를나타낸다이값은거의모든경우에

        물리적인디스크섹터(sector)보다크다.

        linux ext2ext3 파일시스템에서이값은4096이다*/

        printf("blocksize for filesystem I/O : %d\n", info.st_blksize);

 

        /*이파일이사용하고있는'블록'의개수.

        linux에서이값은512 바이트블록단위이다*/

        printf("number of blocks allocated : %d\n", info.st_blocks);

 

        /*파일의데이터를마지막으로읽은시간*/

        printf("time of last access : %d\n", info.st_atime);

 

        /*파일의데이터를마지막으로쓰거나그크기를조정한시간*/

        printf("time of last modification : %d\n", info.st_mtime);

 

        /*파일의아이노드를마지막으로접근허가나

        소유자와같은파일의메타데이터가변경된시간*/

        printf("time of last inode change : %d\n", info.st_ctime);

    }

    else

        fprintf(stderr,"errror\n");

 

    return 0;

}

'Language > C' 카테고리의 다른 글

파일 퍼미션  (0) 2011.11.14
bsearch / 이진탐색  (0) 2011.11.09
배열 크기 구하기  (0) 2011.11.08
exec 함수군  (0) 2011.11.07
현재 날짜와 시간 출력  (0) 2011.11.04
: