[pintOS] 4주차 File Systems: 진행 과정 기록
CHECK POINT 1
-
상태
- 기존에 통과하던 테스트 케이스 모두 실패
- 테스트를 돌리기 위해
Make.vars
에서 VM 관련 line을 uncomment해주어야 함
-
개선 요구 사항: Indexed and Extensible Files
- fat 구현하기
-
진행 과정
-
((OSTEP page 522)) 개념 파악
- Thus, when mounting a file system, the operating system will read the superblock first, to initialize various parameters, and then attach the volume to the file-system tree. When files within the volumn are accessed, the system will thus know exactly where to look for the needed on-dist structures.
- superblock
- (교재 vsfs에서는 맨 앞 block)
- contains information about this particular filesystem, including, for example, how many inodes and data blocks are in the file system, where the inode table begins, and so forth.
- also include a magic number of some kind to identify the file system type.
-
((
fat.c
))fat_init()
확인-
struct fat_boot { unsigned int magic; unsigned int sectors_per_cluster; /* Fixed to 1 */ unsigned int total_sectors; unsigned int fat_start; unsigned int fat_sectors; /* Size of FAT in sectors. */ unsigned int root_dir_cluster; }; /* FAT FS */ struct fat_fs { struct fat_boot bs; unsigned int *fat; unsigned int fat_length; disk_sector_t data_start; cluster_t last_clst; struct lock write_lock; }; #define FAT_BOOT_SECTOR 0 /* FAT boot sector. */ void fat_init (void) { fat_fs = calloc (1, sizeof (struct fat_fs)); if (fat_fs == NULL) PANIC ("FAT init failed"); // Read boot sector from the disk unsigned int *bounce = malloc (DISK_SECTOR_SIZE); if (bounce == NULL) PANIC ("FAT init failed"); disk_read (filesys_disk, FAT_BOOT_SECTOR, bounce); memcpy (&fat_fs->bs, bounce, sizeof (fat_fs->bs)); free (bounce); // Extract FAT info if (fat_fs->bs.magic != FAT_MAGIC) fat_boot_create (); fat_fs_init (); }```
-
여기서
fat_fs->bs
에 들어가는 정보(struct fat_boot
)가 superblock에 담긴 정보filesys_disk
에서FAT_BOOT_SECTOR
에 해당하는 섹터에서 읽어온 내용을 다시fat_fs->bs
에 넣어주고 있음fat_fs->bs.magic
이 없는 경우는 처음 부팅한 상황, 있는 경우는 재부팅한 상황으로 예상됨
-
-
((
fat.c
))fat_fs_init()
구현- fat_length: stores how many clusters in the filesystem.
- fat에 담을 수 있는 cluster의 개수
- 현재 cluster는 하나의 disk sector로 구성되기 때문에, 결국 몇 개의 sector가 들어가느냐의 문제
- data_start: stores in which sector we can start to store files.
- fat_start + fat_secters 만큼 지나서 시작
- fat_length: stores how many clusters in the filesystem.
-
((
fat.c
))fat_create()
확인fat_fs->fat = calloc (fat_fs->fat_length, sizeof (cluster_t));
- fat의 한 entry에는 cluster가 하나씩 들어감
- 즉, 현재 클러스터의 다음 클러스터값이 들어감
- 그러므로 한 entry의 크기는
size of (cluster_t)
fat_put (ROOT_DIR_CLUSTER, EOChain);
ROOT_DIR_CLUSTER
는 1- 루트 디렉토리는 클러스터 1개만 차지할테니 fat의 1번째 인덱스에는 End-Of-Chain
disk_write (filesys_disk, cluster_to_sector (ROOT_DIR_CLUSTER), buf);
- 1번째 클러스터 위치에 buf(모두 0으로 된 DISK_SECTOR_SIZE의 메모리 영역)를 복사
- fat의 0번째가 루트 디렉토리가 되게 하려면 1을 빼주어야겠지?
- ROOT_DIR_CLUSTER가 0이 아닌 1인 이유가 있을까?
- If
clst
is equal to zero, then create a new chain. - cluster 0을 새로운 chain이라는 의미로 정했기 때문
- If
- ROOT_DIR_CLUSTER가 user data region에서 맨 처음이 맞나?
- ROOT_DIR_CLUSTER가 0이 아닌 1인 이유가 있을까?
-
((
fat.c
))fat_get
,fat_put
,cluster_to_sector
구현- fat의 엔트리는 (현재 cluster 번호, 다음 cluster 번호)일 것
- fat을 배열로 보면, fat의 '현재 clut 번호' 인덱스에는 '다음 clst 번호'가 값으로 들어가게 됨
-
((
fat.c
))fat_create_chain()
구현- fat에서 비어 있는 위치를 찾아 입력된 clst를 인덱스로 했을 때의 값을 next clst로 만듦
- 이 때 fat의 next_clst를 인덱스로 했을 때의 값은 EOChain이 되어야 함
-
((
fat.c
))fat_remove_chain()
구현- clst에서부터 이어지는 clst들을 모두 비움
- pclst의 값을 EOChain으로 설정
- 이 때, pclst가 0인 경우, chain이 모두 사라진 것이므로 처리해줄 필요 없음
-
CHECK POINT 2
- 상태
- priority 관련 testcase 통과
- userprog 관련 testcase 실패
- 개선 요구 사항
fat.c
에서 정의된 함수들을 filesys와 inode에서 활용하기
- 진행 과정
- ((
fat.c
))fat_allocate()
구현free_map_allocate()
대신fat_allocate()
filesys_create()
에서free_map_allocate()
에서 터짐- free_map 대신 fat를 사용하므로,
free_map_allocate()
에 대응하는 fat의 함수 생성 free_map_allocate()
의 역할은, Allocates CNT consecutive sectors from the free map and stores the first into *SECTORP.
fat_allocate()
에서는 연속될 필요 없이 chaining 방식으로 연결된 sector 들일 것- 필요한 sector의 개수(cnt)와 시작 sector의 위치를 저장할 포인터를 입력값으로 받음
- fat에서 요구된 만큼 sector(cluster)들을 할당한 뒤
- 시작 cluster를 파라미터로 들어온 포인터에 저장
- ((
filesys.c
)) 바이바이..
- ((
Author And Source
이 문제에 관하여([pintOS] 4주차 File Systems: 진행 과정 기록), 우리는 이곳에서 더 많은 자료를 발견하고 링크를 클릭하여 보았다 https://velog.io/@johnny/pintOS-proj4-FileSystems저자 귀속: 원작자 정보가 원작자 URL에 포함되어 있으며 저작권은 원작자 소유입니다.
우수한 개발자 콘텐츠 발견에 전념 (Collection and Share based on the CC Protocol.)