http://blog.naver.com/ikaruce2/100018083359
stat and fstat는 한 프로세스가 기존 파일의 특성 값을 볼 수 있게 해 줍니다.
#include <sys/types.h>
#include <sys/stat.h>
int stat(cosnt char *pathname, struct stat *buf );
//파일에 연관된 정보를 얻음.
int fstat( int filedes, struct stat *buf );
// stat과 거의 유사하지만 파일이름 대신 파일 디스크립터를 사용
pathname : 파일 이름
buf : stat 구조를 가리키는 포인터
filedes : 파일 디스크립터
사용 예시
struct stat s;
int filedes, retval;
filedes = open("tmp/dina", O_RDWR );
retval = stat("/tmp/dina", &s );
retval = fstat(filedes, &s );
stat 스트럭처의 멤버는 다음과 같은 의미를 가집니다.
st_dev : 파일이 들어있는 논리적 장치
st_ino :파일의 inode 번호
st_mode : 파일 모드를 나타냄
st_nlink : 파일에 연관된 비(非) 심볼형 링크의 개수
st_uid, st_gid : 파일의 사용자 식별번호와 그룹 식별번호
st_rdev : 파일 엔트리가 장치를 기술
st_size : 파일의 현재 크기
st_atime : 파일이 마지막으로 읽혔던 시간
st_mtime : 파일이 마지막으로 변경된 시간
st_ctime : stat구조체의 멤버가 변경된 시간을 기록
st_blksize : 파일 시스템의 고유 I/O 블록 사이즈
st_blocks : 파일에 할당된 물리적 파일 시스템 블록의 수