일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
1 | ||||||
2 | 3 | 4 | 5 | 6 | 7 | 8 |
9 | 10 | 11 | 12 | 13 | 14 | 15 |
16 | 17 | 18 | 19 | 20 | 21 | 22 |
23 | 24 | 25 | 26 | 27 | 28 |
Tags
- 어셈블리어
- 워게임
- 알고리즘
- pwncollege
- Pwnable.kr
- write up
- 컴퓨터구조
- 시스템 프로그래밍
- 취약점
- wargame
- 프로그래밍
- C언어
- 리눅스커널
- kernel
- 시스템프로그래밍
- 시스템해킹
- Leviathan
- radare2
- 시스템
- css
- C++
- 시그널
- pwn.college
- 리버싱
- 커널
- Bandit
- px4
- 리눅스 커널
- 드론
- 리눅스
Archives
- Today
- Total
Computer Security
#12 파일 속성 본문
반응형
파일 속성 조회
int stat(const char *pathname, struct stat *statbuf);
int fstat(int fd, struct stat *statbuf);
int lstat(const char *pathname, struct stat *statbuf);
파라미터
- pathname : 파일 경로
- fd : 열린 파일 디스크립터
- statbuf : 파일 속성 버퍼
반환 값
- 성공 시 0
- 실패 시 -1
stat 명령같은 경우, 소프트 링크같은경우에 소프트링크가 가르키는 원본파일의 정보를 가져온다.
하지만, lstat 의 경우 pathname이 가르키는 파일이 심볼릭링크 파일인 경우, 원본파일의 정보를 가져오는 것이 아니라, 심볼릭 링크파일의 정보를 가져온다.
어떤 정보를 가져오는지 알아보자.
struct stat {
dev_t st_dev; /* ID of device containing file */
ino_t st_ino; /* inode number */
mode_t st_mode; /* 파일의 종류 및 접근권한 */
nlink_t st_nlink; /* hardlink 된 횟수 */
uid_t st_uid; /* 파일의 owner */
gid_t st_gid; /* group ID of owner */
dev_t st_rdev; /* device ID (if special file) */
off_t st_size; /* 파일의 크기(bytes) */
blksize_t st_blksize; /* blocksize for file system I/O */
blkcnt_t st_blocks; /* number of 512B 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 status change */
};
파일의 type을 조사 할 수 있는 매크로를 알아보자.
예시
stat(pathname, &sb);
if (S_ISREG(sb.st_mode)) {
/* Handle regular file */
}
반응형
'리눅스 시스템 프로그래밍' 카테고리의 다른 글
#14 디렉토리 다루기 (2) | 2022.09.19 |
---|---|
#13 파일 속성(실습) (0) | 2022.09.18 |
#11 하드링크, 소프트 링크(실습) (0) | 2022.09.16 |
#10 파일 구조,하드링크, 소프트링크 (1) | 2022.09.15 |
#9 저수준 파일 문자/문자열 읽고 쓰기 (실습) (0) | 2022.09.14 |
Comments