K 개발자

파일 정보 검색 본문

유닉스(Unix)/시스템 프로그래밍

파일 정보 검색

ddingz 2021. 8. 16. 13:54

파일 정보 검색

파일명으로 파일 정보 검색 : stat(2)

#include <fcntl.h>
#include <sys/types.h>
#include <sys/stat.h>

int stat(const char *restrict path, struct stat *buf);
// path : 정보를 알고자 하는 파일명, buf : 검색한 파일 정보를 저장할 구조체 주소

stat 구조체

stat 함수로 검색한 inode 정보는 stat 구조체에 저장된다.

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;
	time_t st_atime;
	time_t st_mtime;
	time_t st_ctime;
	blksize_t st_blksize;
	blkcnt_t st_blocks;
	char st_fstype[_ST_FSTYPSZ];
};

파일 기술자로 파일 정보 검색 : fstat(2)

#include <sys/types.h>
#include <sys/stat.h>

int fstat(int fd, struct stat *buf);
// fd : 열려 있는 파일의 파일 기술자, buf : 검색한 파일 정보를 저장할 구조체 주소

'유닉스(Unix) > 시스템 프로그래밍' 카테고리의 다른 글

링크 파일 생성  (0) 2021.08.16
파일 접근 권한 제어  (0) 2021.08.16
유닉스 파일의 특징  (0) 2021.08.16
임시 파일 사용  (0) 2021.08.15
파일 기술자와 파일 포인터 간 변환  (0) 2021.08.15
Comments