cs assignment
CSc 360: Operating Systems (Fall 2020)
Assignment 3: A Simple File System (SFS)
Due Date: Dec.4, 2020
1 Introduction1
In this assignment, you will implement utilities that perform operations on a simple file system, FAT12, used by2 MS-DOS.3
1.1 Sample File Systems4
You will be given a file system image: disk.IMA for self-testing, but your submission may be tested against other5 disk images following the same specification.6
You should get comfortable examining the raw, binary data in the file system images using the program xxd.7
2 Requirements8
2.1 Part I9
In part I, you will write a program that displays information about the file system. In order to complete part I,10 you will need to understand the file system structure of MS-DOS, including FAT Partition Boot Sector, FAT File11 Allocation Table, FAT Root Folder, FAT Folder Structure, and so on.12
For example, your program for part I will be invoked as follows:13
./diskinfo disk.IMA
Your output should include the following information:14
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):
=============
Number of FAT copies:
Sectors per FAT:
Note 1: when you list the total number of files in the disk, a subdirectory name is not considered15 as a normal file name and thus should not be counted.16
Note 2: For a directory entry, if the field of “First Logical Cluster” is 0 or 1, then this directory17 entry should not be counted.18
Note 3: Total size of the disk = total sector count * bytes per sector19 Note 4: Free size of the disk = total number of sectors that are unused (i.e., 0x000 in an FAT20
entry means unused) * bytes per sector. Remember that the first two entries in FAT are reserved.21
1
2.2 Part II22
In part II, you will write a program, with the routines already implemented for part I, that displays the contents of23 the root directory and all sub-directories (possibly multi-layers) in the file system.24
Your program for part II will be invoked as follows:25
./disklist disk.IMA
Starting from the root directory, the directory listing should be formatted as follows:26
• Directory Name, followed by a line break, followed by “==================”, followed by a line27 break.28
• List of files or subdirectories:29
– The first column will contain:30
∗ F for regular files, or31 ∗ D for directories;32
followed by a single space33
– then 10 characters to show the file size in bytes, followed by a single space34
– then 20 characters for the file name, followed by a single space35
– then the file creation date and creation time.36
– then a line break.37
Note: For a directory entry, if the field of “First Logical Cluster” is 0 or 1, then this directory38 entry should be skipped and not listed.39
2.3 Part III40
In part III, you will write a program that copies a file from the root directory of the file system to the current41 directory in Linux. If the specified file cannot be found in the root directory of the file system, you should output42 the message File not found. and exit.43
Your program for part III will be invoked as follows:44
./diskget disk.IMA ANS1.PDF
If your code runs correctly, ANS1.PDF should be copied to your current Linux directory, and you should be able45 to read the content of ANS1.PDF.46
2.4 Part IV47
You will write a program that copies a file from the current Linux directory into specified directory (i.e., the root48 directory or a subdirectory) of the file system. If the specified file is not found, you should output the message File49 not found. and exit. If the specified directory is not found in the file system, you should output the message The50 directory not found. and exit. If the file system does not have enough free space to store the file, you should51 output the message No enough free space in the disk image. and exit.52
Your program will be invoked as follows:53
./diskput disk.IMA /subdir1/subdir2/foo.txt
where subdir1 is a sub-directory of the root directory and subdir2 is a sub-directory of subdir1, and foo.txt is54 the file name. If no specified directory is given, then the file is copied to the root directory of the file system, e.g.,55
./diskput disk.IMA foo.txt
will copy foo.txt to the root directory of the file system.56 Note that since most linux file systems do not record the file creation date & time (it is called birth time, and57
it is mostly empty), let’s set the creation time and the last write time the same in the disk image, which is the last58 write time in the original file in linux.59
Note that a correct execution should update FAT and related allocation information in disk.IMA accordingly.60 To validate, you can use diskget implemented in Part III to check if you can correctly read foo.txt from the file61 system.62
2
3 File System Specification63
The specification of FAT12 and related information could be found in Connex -¿ Resources.64
4 Byte Ordering65
Different hardware architectures store multi-byte data (like integers) in different orders. Consider the large integer:66 0xDEADBEEF67
On the Intel architecture (Little Endian), it would be stored in memory as:68
EF BE AD DE69
On the PowerPC (Big Endian), it would be stored in memory as:70
DE AD BE EF71
Since the FAT was developed for IBM PC machines, the data storage is in Little Endian format, i.e. the least72 significant byte is placed in the lowest address. This will mean that you have to convert all your integer values to73 Little Endian format before writing them to disk.74
5 Submission Requirements75
What to hand in: You need to hand in a .tar.gz file containing all your source code, readme.txt, and a Makefile76 that produces the executables (i.e., diskinfo, disklist, diskget, and diskput).77
The file is submitted through connex.csc.uvic.ca site.78
6 Marking Scheme79
We will mark your code submission based on correct functionality and code quality.80
6.1 Functionality81
1. Your programs must correctly output the required information in Part I, II, and III. One sample disk image is82 provided to you for self-learning and self-testing. Nevertheless, your code may be tested with other disk images83 of the same file system. We will not test your code with a damaged disk image. We will not disclose all test84 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 result86 in the logic error or malfunctioning of your program.87
6.2 Code Quality88
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 100090 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. To92 further elaborate:93
(a) Your favorite quote from Star Wars or Douglas Adams’ Hitch-hiker’s Guide to the Galaxy does not count94 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 all system calls and function calls listed in the assignment specification100 should be checked and all values should be dealt with appropriately.101
3
6.3 Detailed Test Plan102
The detailed test plan for the code submission is as follows.103
Components Weight Make file 5 diskinfo 15 disklist 20 diskget 25 diskput 30 Readme 5
Total Weight 100
104
7 Warning105
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 will107 result in the deduction of scores.108
3. You should use the server linux.csc.uvic.ca to test your work.109
8 Plagiarism110
This assignment is to be done individually. You are encouraged to discuss the design of the solution and the FAT 12111 specification with your classmates, but each student must implement their own assignment.112
4
- Introduction
- Sample File Systems
- Requirements
- Part I
- Part II
- Part III
- Part IV
- File System Specification
- Byte Ordering
- Submission Requirements
- Marking Scheme
- Functionality
- Code Quality
- Detailed Test Plan
- Warning
- Plagiarism