엔지니어가 되고 싶은 공돌이
06. File System 본문

6. 1. File System
- Unix에서 File은 크게 3종류가 있습니다.
1) General File: Text File, Executive File 처럼 우리가 일반적으로 알고있는 파일.
2) Directory: 리눅스에서는 Directory도 파일로 처리합니다.
3) Special File: Hardward.
- ls -l 명령을 사용해서 파일의 종류를 확인할 수 있습니다.
General File은 -로 시작, Directory는 d로 시작, Special File은 b or c 로 시작합니다.
- Composition of Files
1) File Name: 사용자가 접근할 때 사용, 최대 255자까지 가능, 대소문자 구분함.
2) inode: 번호로 표시, 파일정보(Meta Data)를 저장, Data Block의 Address를 저장.
ls -i 명령으로 inode를 확인할 수 있습니다.
3) Data Block: 실제로 데이터가 저장되는 부분.
File Name이 Pointer처럼 inode를 가리키고 있고, inode에서 Pointer처럼 Data Block을 가리키고 있습니다.
6. 2. File Function
- 파일정보를 검색하기 위해서 파일명으로 접근하는 stat() , File Descriptor로 접근하는 fstat()가 있습니다.
int stat(const char *restrict path, struct stat *buf);
path에 filename을 입력하면 해당 파일의 Meta Data가 buf에 저장이 됩니다.
int fstat(int fd, struct stat *buf);
- chmod로 File 뿐만 아니라 Directory의 접근권한도 변경할 수 있습니다.
- Macro로를 이용해서 파일의 종류(General File, Directory, Special)를 확인할 수 도 있습니다.
- access()로 파일이 어떤 권한을 가지고 있는지 확인할 수 있습니다.
int access(const char *path, int amode);
path로 지정된 file이 amode의 권한을 가지고 있는지 확인해서, 있으면 0, 없으면 -1을 리턴합니다.
- Link: 이미 있는 File이나 Directory에 접근할 수 있는 새로운 이름.
1) Hard Link: 기존 파일과 같은 inode를 사용.
link(exist filename, new filename);
2) Symbolic Link: 기존 파일에 접근하는 또 다른 파일을 생성, 다른 inode를 사용.
symlink(exist filename, new filename);
mkdir(*path, mode) | Path에 mode권한으로 디렉토리 생성 |
rmdir(*path) | 디렉토리 삭제 |
rename(*old name, *new name) | 디렉토리명 변경 |
getcwd(*buf, size) | 현재 작업 디렉토리 위치 |
chdir(*path) | 디렉토리 이동 |
DIR *opendir(*dirname) | 디렉토리 열기 |
closedir(DIR *dirp) | 디렉토리 닫기 |
readdir(DIR *dirp) | 디렉토리 정보 읽기 |
'Computer Science > Unix' 카테고리의 다른 글
08. Fork and Exec (0) | 2025.03.15 |
---|---|
07. Process (0) | 2025.03.14 |
05. High-Level File I/O (0) | 2025.03.10 |
04. Low-Level File I/O (0) | 2025.02.28 |
03. Linux Coding (0) | 2025.02.28 |