CSc 360 简单文件系统

CSc 360: Operating Systems (Fall 2021)
Assignment 3: A Simple File System (SFS)
Due Date: Dec.2, 2021
1 1 Introduction
2 In this assignment, you will implement utilities that perform operations on a simple file system, FAT12, used by
3 MS-DOS.
4 1.1 Sample File Systems
5 You will be given a file system image: disk.IMA for self-testing, but your submission may be tested against other
6 disk images following the same specification.
7 You should get comfortable examining the raw, binary data in the file system images using the program xxd.
8 2 Requirements
9 2.1 Part I
10 In part I, you will write a program that displays information about the file system. In order to complete part I,
11 you will need to understand the file system structure of MS-DOS, including FAT Partition Boot Sector, FAT File
12 Allocation Table, FAT Root Folder, FAT Folder Structure, and so on.
13 For example, your program for part I will be invoked as follows:
./diskinfo disk.IMA
14 Your output should include the following information:
OS Name:
Label of the disk:
Total size of the disk:
Free size of the disk: The number of files in the disk (including all files in the root directory and files in all subdirectories): 【CSc 360 简单文件系统】Number of FAT copies:
Sectors per FAT:
15 Note 1: when you list the total number of files in the disk, a subdirectory name is not considered
16 as a normal file name and thus should not be counted.
17 Note 2: For a directory entry, if the field of “First Logical Cluster” is 0 or 1, then this directory
18 entry should not be counted.
19 Note 3: Total size of the disk = total sector count * bytes per sector
20 Note 4: Free size of the disk = total number of sectors that are unused (i.e., 0x000 in an FAT
21 entry means unused) * bytes per sector. Remember that the first two entries in FAT are reserved.
1
22 2.2 Part II
23 In part II, you will write a program, with the routines already implemented for part I, that displays the contents of
24 the root directory and all sub-directories (possibly multi-layers) in the file system.
25 Your program for part II will be invoked as follows:
./disklist disk.IMA
26 Starting from the root directory, the directory listing should be formatted as follows:
27 ? Directory Name, followed by a line break, followed by “==================”, followed by a line
28 break.
29 ? List of files or subdirectories:
30 – The first column will contain:
31 ? F for regular files, or
32 ? D for directories;
33 followed by a single space
34 – then 10 characters to show the file size in bytes, followed by a single space
35 – then 20 characters for the file name, followed by a single space
36 – then the file creation date and creation time.
37 – then a line break.
38 Note: For a directory entry, if the field of “First Logical Cluster” is 0 or 1, then this directory
39 entry should be skipped and not listed.
40 2.3 Part III
41 In part III, you will write a program that copies a file from the root directory of the file system to the current
42 directory in Linux. If the specified file cannot be found in the root directory of the file system, you should output
43 the message File not found. and exit.
44 Your program for part III will be invoked as follows:
./diskget disk.IMA ANS1.PDF
45 If your code runs correctly, ANS1.PDF should be copied to your current Linux directory, and you should be able
46 to read the content of ANS1.PDF.
47 2.4 Part IV
48 You will write a program that copies a file from the current Linux directory into specified directory (i.e., the root
49 directory or a subdirectory) of the file system. If the specified file is not found, you should output the message File
50 not found. and exit. If the specified directory is not found in the file system, you should output the message The
51 directory not found. and exit. If the file system does not have enough free space to store the file, you should
52 output the message No enough free space in the disk image. and exit.
53 Your program will be invoked as follows:
./diskput disk.IMA /subdir1/subdir2/foo.txt
54 where subdir1 is a sub-directory of the root directory and subdir2 is a sub-directory of subdir1, and foo.txt is
55 the file name. If no specified directory is given, then the file is copied to the root directory of the file system, e.g.,
./diskput disk.IMA foo.txt
56 will copy foo.txt to the root directory of the file system.
57 Note that since most linux file systems do not record the file creation date & time (it is called birth time, and
58 it is mostly empty), let’s set the creation time and the last write time the same in the disk image, which is the last
59 write time in the original file in linux.
60 Note that a correct execution should update FAT and related allocation information in disk.IMA accordingly.
61 To validate, you can use diskget implemented in Part III to check if you can correctly read foo.txt from the file
62 system.
2
63 3 File System Specification
64 The specification of FAT12 and related information could be found in Brightspace – content – Week 10.
65 4 Byte Ordering
66 Different hardware architectures store multi-byte data (like integers) in different orders. Consider the large integer:
67 0xDEADBEEF
68 On the Intel architecture (Little Endian), it would be stored in memory as:
69 EF BE AD DE
70 On the PowerPC (Big Endian), it would be stored in memory as:
71 DE AD BE EF
72 Since the FAT was developed for IBM PC machines, the data storage is in Little Endian format, i.e. the least
73 significant byte is placed in the lowest address. This will mean that you have to convert all your integer values to
74 Little Endian format before writing them to disk.
75 5 Submission Requirements
76 What to hand in: You need to submit a .tar.gz file to Brightspace containing all your source code, readme.txt,
77 and a Makefile that produces the executables (i.e., diskinfo, disklist, diskget, and diskput).
78 6 Marking Scheme
79 We will mark your code submission based on correct functionality and code quality.
80 6.1 Functionality
81 1. Your programs must correctly output the required information in Part I, II, and III. One sample disk image is
82 provided to you for self-learning and self-testing. Nevertheless, your code may be tested with other disk images
83 of the same file system. We will not test your code with a damaged disk image. We will not disclose all test
84 files before the final submission. This is very common in software engineering.
85 2. You are required to catch return errors of important function calls, especially when a return error may result
86 in the logic error or malfunctioning of your program.
87 6.2 Code Quality
88 We cannot specify completely the coding style that we would like to see but it includes the following:
89 1. Proper decomposition of a program into subroutines (and multiple source code files when necessary)—A 1000
90 line C program as a single routine would fail this criterion.
91 2. Comment—judiciously, but not profusely. Comments also serve to help a marker, in addition to yourself. To
92 further elaborate:
93 (a) Your favorite quote from Star Wars or Douglas Adams’ Hitch-hiker’s Guide to the Galaxy does not count
94 as comments. In fact, they simply count as anti-comments, and will result in a loss of marks.
95 (b) Comment your code in English. It is the official language of this university.
96 3. Proper variable names—leia is not a good variable name, it never was and never will be.
97 4. Small number of global variables, if any. Most programs need a very small number of global variables, if any.
98 (If you have a global variable named temp, think again.)
99 5. The return values from system calls and function calls, particularly those related to the excep-
100 tions listed in Section 2, should be checked and all values should be dealt with appropriately.
3
101 6.3 Detailed Test Plan
102 The detailed test plan for the code submission is as follows.
Components Weight
Make file 5
diskinfo 15
disklist 20
diskget 25
diskput 30
Readme 5
Total Weight 100
103
104 7 Warning
105 1. You are required to use C. Any other language is not acceptable.
106 2. Your code should output the required information specified in Parts I, II, III, and IV. Failing to do so will
107 result in the deduction of scores.
108 3. You should use the server linux.csc.uvic.ca to test your work.
109 8 Plagiarism
110 This assignment is to be done individually. You are encouraged to discuss the design of the solution and the FAT 12
111 specification with your classmates, but each student must implement their own assignment.

    推荐阅读