VFS(Virtual File system)
- Disk-based filesystems
- Network filesystems
- NFS, SMB 등
- Special filesystems (also called virtual filesystems)
- /proc나 /dev 같은 것
- The first Virtual Filesystem was included in Sun Microsystems's SunOS in 1986. Since then,
크게 세 가지로 구분됨
most Unix filesystems include a VFS.
- linux는 모든 종류의 file system을 지원하지만 빌드 시 config 세팅을 해줘야 함.
VFS 객체와 자료구조
- file system
- data를 특정 구조체에 담는 계층적인 저장소로, tree 구조임.
- 통상적으로 생성, 삭제, 마운트를 함.
- 유닉스의 file system은 namespace라는 전역 계층 구조에 mount함.
- 윈도우는 드라이브(ex. C:\)로 나뉜 namespce에 파일을 저장함. --> 이 방법은 HW의 세부 사항이 드러나 추상화를 할 수 없음!
- struct file
- byte가 정렬된 문자열
- 첫 번째 byte는 파일의 시작, 마지막 byte는 파일의 끝을 나타냄.
- 파일 동작은 읽기/쓰기, 생성/삭제가 있음.
- open() 호출시 생성, close() 호출시 소멸
- 메모리에 생성
- 다수 생성 가능.
- directory
- linux에서는 일종의 file로 취급함.
- super block/ inode 등의 data 정보를 disk에 따로 보관함.
VFS 객체와 자료구조
- 추상적인 개념 네 가지: file system은 객체지향적임
- super block struct:
- 마운트된 파일시스템을 표현, file system 전체에 대한 정보를 담고 있는 자료 구조.
- mount란, kernel이 디스크에 연결 고리를 만들어 주는 것을 말함.
- 하드디스크를 물리적으로 연결하면 /dev/sdb라고 디바이스가 연결된다. 하지만 이 것은 디바이스에 물리적으로 접근한다는 것이지 파일 시스템을 본다는 것이 아니다. 그래서 mount를 하면 file system으로 인식을 하게 되는 것이다.
- sysfs와 같은 디스크가 아닌 파일 시스템의 경우에는 가상으로 실시간으로 슈퍼블록을 생성해서 메모리에 저장함.
- 수퍼 블록 구조체의 연결 관계는 다음과 같다.
- <linux/fs.h> struct super_block
- 의 멤버인 struct super_operations s_op
- inode struct:
- file 관련 정보
- <linux/fs.h> struct inode
- 의 멤버인 struct inode_operations
- inode는 파일 시스템의 각 파일을 나타낸다.
- inode 객체를 생성하면 memory에서만 생성됨.
- 디스크에 저장된 file system의 정보를 갖는다.
- dev_t i_rdev: [12bit(주번호), 20bit(부번호)]
- dentry struct:
- 파일을 포함한 경로를 구성하는 요소. 디렉토리는 아니고 파일의 특별한 형태임
- <linux/dcache.h> struct dentry와 멤버인 struct dentry_operations d_op
- 디스크 상에 저장하지 않는다. 대신 inode에 해당하는 dentry가 메모리에 생성됨.
- 사용자가 접근하면 캐시에 넣어두고 나중에 접근할 것을 대비해 폐기하지 않는다.
- open() syscall이 존재하지 않는 dir을 지속적으로 호출하면 메모리 확보를 위하여 폐기함.
- dentry는 다음과 같이 엮여있다
- task_struct의 fs는 file system을 말하는 것이고 files는 task가 open한 file descriptor임.
- 예를 들면 다음 /dev/SK를 호출하는 과정이다.
- inode도 kmem_cache를 이용하여 할당함.
- file struct:
- 프로세스가 사용하는 열린 파일 표현, open을 해야 생김.
- struct inode의 멤버 struct file_operations i_fop
- 유닉스 시스템은..
- 접근 권한, 크기, 생성시간 등의 파일 관련 정보(메타데이터)를 inode(index node)라는 자료구조에 따로 보관함.
- 주요 struct
- file_system_type: 등록된 파일 시스템
- vfsmount: 마운트 지점
- fs_struct
- file
수퍼블록 객체 / operations
참고사항
- passwd라는 명령은 사용자는 user인데 700인 /etc/shadow 파일을 변경한다. 이는 effective UID를 root로 변경하기 때문이다. passwd는 effective UID를 변경하는 특수 파일이다.
- t: 누구나 다 쓸 수는 있는데 다른 사람이 할 수 없는 것
- 등등… 찾아볼 것
- effective라는 말에 대해 더 찾아볼 것
- struct file
- struct file_operations1526struct file_operations { 1527 struct module *owner; 1528 loff_t (*llseek) (struct file *, loff_t, int); 1529 ssize_t (*read) (struct file *, char __user *, size_t, loff_t *); 1530 ssize_t (*write) (struct file *, const char __user *, size_t, loff_t *); 1531 ssize_t (*aio_read) (struct kiocb *, const struct iovec *, unsigned long, loff_t); 1532 ssize_t (*aio_write) (struct kiocb *, const struct iovec *, unsigned long, loff_t); 1533 int (*iterate) (struct file *, struct dir_context *); 1534 unsigned int (*poll) (struct file *, struct poll_table_struct *); 1535 long (*unlocked_ioctl) (struct file *, unsigned int, unsigned long); 1536 long (*compat_ioctl) (struct file *, unsigned int, unsigned long); 1537 int (*mmap) (struct file *, struct vm_area_struct *); //user와 kernel 영역 mapping을 위함. 1538 int (*open) (struct inode *, struct file *); 1539 int (*flush) (struct file *, fl_owner_t id); 1540 int (*release) (struct inode *, struct file *); 1541 int (*fsync) (struct file *, loff_t, loff_t, int datasync); 1542 int (*aio_fsync) (struct kiocb *, int datasync); 1543 int (*fasync) (int, struct file *, int); 1544 int (*lock) (struct file *, int, struct file_lock *); 1545 ssize_t (*sendpage) (struct file *, struct page *, int, size_t, loff_t *, int); 1546 unsigned long (*get_unmapped_area)(struct file *, unsigned long, unsigned long, unsigned long, unsigned long); 1547 int (*check_flags)(int); 1548 int (*flock) (struct file *, int, struct file_lock *); 1549 ssize_t (*splice_write)(struct pipe_inode_info *, struct file *, loff_t *, size_t, unsigned int); 1550 ssize_t (*splice_read)(struct file *, loff_t *, struct pipe_inode_info *, size_t, unsigned int); 1551 int (*setlease)(struct file *, long, struct file_lock **); 1552 long (*fallocate)(struct file *file, int mode, loff_t offset, 1553 loff_t len); 1554 int (*show_fdinfo)(struct seq_file *m, struct file *f); 1555};
- open/release()는 필수임
- aio_read/write: async io에 대한 것이며, io가 여러 개 한꺼번에 왔을 때 처리하기 위함.
- ioctl:
- 기존에는 lock/unlock ioctl 두 가지였음. 하지만 ioctl은 read/write가 아닌 command이므로 굳이 lock을 할 필요가 없었음.
- 2.6버전 이후에는 locked_ioctl은 없어지고 compact_ioctl로 변경됨.
- driver 교재에 나옴. 자세히 알아볼 것.
- mmap
- copy_from_user()는 작은 단위… buddy로 조금 할당하는 것은 잘 동작하지만, 미디어.. 즉 동영상 같은 G 단위의 큰 복사는 어렵다.
- 이를 해결하기 위한 것이 mmap임. 복사할 필요 없이 kernel/user 영역이 동시에 접근하도록 해준다. 이 것이 해주는 역할은 특정 주소를 kernel 영역일 때는 kernel 주소로, user 영역일 때는 user 주소로 변경해 주는 역할을 하는 것이다.
댓글 없음:
댓글 쓰기