[목차]
File concepts
File System Implementation
Allocation Methods
Examples
File Concepts
File attributes
- 식별자
- inode에 파일의 모든 정보 있음
- type(확장자)
- permission
- ....
inode를 어떻게 찾을까? 가 중요하다
inode : 파일이 어떻게, 어디에, 언제 저장되는지 알고 있음
+) 단위 : block
A : 4MB, 4KB => 1024Blocks
File operation
- create
- write
- 현재 파일 position pointer를 update하고 contents 바꿈
- default : file position pointer
- Read
- default : file position pointer
main() {
int fd
1. fd = open('~~')
2. read(fd, ..., ...)
3. write
4. seek
=> position pointer 변경
ex) 유튜브 재생바 마음대로
}
open files
why? 메모리에 inode 갖다놓기 위함
파일 여러 개 오픈 가능
파일 open 할 때 필요한 것들
- position pointer
- file-open count(몇 개 파일이 열렸는지)
- disk location of the file
- access rights
1) per process open file table
2) system wide open file table => inode
Q. 여러 process에서 한 개의 파일 오픈 가능할까?
A: Yes
ex) 메모장 파일에서도 열리고 한글에서도 열림(file position pointer, permission다를 수도)
File System Implementation
Information on disk
1. Boot control block
- 각 partition의 첫 번째 block
- 부팅할 때 필요한 정보 있음
2. Volume control block
- volume(=partition)
- C드라이브, D드라이브
- volume마다 file system 들어가야 함.
- 파일 시스템 정보 있음
- UNIX에서는 superblock이라 함
- 복제돼서 저장
- why? 복구 위해
3. Directory structure for a file system
- meta 데이터 정보
- inode number
- inode는 array 형태 => inode Table
4. Per-file FCB(File Control Block)
- 파일의 세부사항 있음
- directory structure 통해서 inode number 가져옴
- master file table에 저장(NTFS)
Information in memory
**새로운 file system이 들어오면 mount 필요하다
1) In-memory mount table
- 현재 사용하고 있는 file system
- UNIX : 임의의 디렉토리에 마운트 됨
2) In-memory directory structure
- directory structure에서, 왼 : file name, 오 : inode number
3) System-wide open-file table
- FCB 복제 포함됨
4) Per-process open-file table
- 적절한 pointer 포함(SWOT에서)
- SWOT의 pointer + file offset and protection(process마다 다름)
Why SWOT, PPOT 두 개로 구분?
=> 여러 process가 한 파일 open 가능
=> FPP랑 권한 다를 수도 있음
* SWOT : System-wide open-file table
* PPOT : Per-process open-file table
파일 open 할 때?
directory structure에서 inode number찾고, inode에서 찾는다.
파일 read or written 할 때?(open된 상태)
1) PPOT search
2) SWOT search
> inode 있음
> FCB는 파일 정보 있음
파일 closed
1) process별 file table entry를 지운다
2) SWOT에서 open count 수를 줄인
inode number은 directory structure에서 찾음
그 다음, inode table에서 inode 읽음
+) block은 FCB에서 찾음
VFS(Virtual File System)
- 이질적인 file system을 동일 시스템에서 사용할 수 있도록 => VFS가 변환 시켜줌.
- VFS를 사용하면 동일한 시스템 호출 인터페이스(API)를 다른 유형의 파일 시스템에 사용할 수 있음
- 또 다른 inode 개념인 Vnode(Virtual node) 존재
> 파일 시스템에 있음
Allocation Methods
ex) 8GB면
1 block(4KB) * 1024 => 4MB
1024 * 1024 => 4GB
2 * 1024 * 1024 => 8GB
Sequential access : 영화를 처음부터 보는 것(연속적), 계속 재생하므로 성능 좋음
directed access : 위치를 마음대로 하는 것(영화 재생바 내 마음대로)
1) Contiguous allocation
- 단점 : external fragmentation 발생, File can't grow
- sequential access일 때 no head movement
- 시작 주소만 알면 됨
- Extent-based allocation
- extent : contiguous block of disk
> 연속적이지 않을 수 있음
> 그러면 무조건 시작 block number을 알아야 한다(그래야 연속적이지 않아도 실행)
2) Linked allocation
- next block num이 같이 기록되어 있음(링크드리스트 느낌)
- overhead 크다
- 단점 : Delay 많고 만약 Bad Block되면 이후에는 못찾음, Internal Fragmentation 발생
- 중간에 Bad Block 있으면 안됨
- Reliability Problem
- Direct Access에 취약
- 변형 : FAT(File Allocation Table)
- 시작 위치만 알면 FAT 통해서 타고 타고 타고 간다.
- 첫번째 block number만 알면 FAT look up
- block number은 directory structure에 있음
- 시작 위치만 알면 FAT 통해서 타고 타고 타고 간다.
+) SSD vs HDD
SSD
- 최소 단위 : cell
- 수명 있음
- overwrite X
- So, erase before write
- P/E cycle
- P : Program(write), E : erase
- 각 cell마다 P/E cycle 있음
- HDD가 값이 싸기 때문에 나름 SSD에서 SLC, MLC, TLC, QLC 지원
- SLC(single level cell), MLC(multi level cell) ....
- SLC, MLC, TLC, QLC 오른쪽으로 갈 수록 P/E cycle 점점 작아짐
HDD
- 최소 단위 : section
- overwrite O
3) Indexed Allocation
- outer Index - index table - file 구조
- inode에 block num 12개까지(48KB) 직접 저장
- 단점 : index block을 여러 번 읽어야 함
Direct | Single | Double | Triple |
48KB | 4MB | 4GB | 4TB |
> 리눅스 파일 전체 크기 = 48KB + 4MB + 4GB + 4TB
- Sequential access 가능
- Direct access 가능
4) Examples
- log-structured file system
- log 위치에 transaction 기록
- transaction은 로그를 disk에 기록(commit)한다
but, File system은 나중에 update
- transaction은 로그를 disk에 기록(commit)한다
- log 위치에 transaction 기록
- 1) log transaction
2) transaction 마지막, 나중에 sequential하게 update - 장점 : crash 발생해도 기록되어있기 때문에 괜찮
NFS(Network file system)
영화를 제공하는 machine을 NFS server, 접근하는 Machine을 NFS client라 하자
NFS server : 특정 디렉토리만 보여줌
NFS client : 임의의 디렉토리에 Mount (why? file system 쓰려면 무조건 mount)
+) NFS client에 b.txt가 있다고 했을 때, mount가 살아있는 동안 원래 있던 b.txt는 안보인다
Reference
Operating System Concepts 10th Edition