CSc 360: Programming Assignment 3 (P3): A Simple File System (SFS)

$30.00

Category: You will Instantly receive a download link for .zip solution file upon Payment

Description

5/5 - (3 votes)

12 2 Requirements
13 2.1 Part I (5 marks)
14 In part I, you will write a program that displays information about the file system. In order to complete part I, you
15 will need to read the file system super block and use the information in the super block to read the FAT.
16 Your program for part I will be invoked as follows:
./diskinfo disk1.img
17 Sample output:
Super block information:
Block size: 512
Block count: 5120
FAT starts: 1
FAT blocks: 40
Root directory start: 41
Root directory blocks: 8
FAT information:
Free Blocks: 5071
Reserved Blocks: 41
Allocated Blocks: 8
18 Please be sure to use the exact same output format as shown above.
1
19 2.2 Part II (5 marks)
20 In part II, you will write a program, with the routines already implemented for part I, that displays the contents of
21 the root directory in the file system.
22 Your program for part II will be invoked as follows:
./disklist disk1.img
23 The directory listing should be formatted as follows:
24 1. The first column will contain:
25 (a) F for regular files, or
26 (b) D for directories;
27 followed by a single space
28 2. then 10 characters to show the file size, followed by a single space
29 3. then 30 characters for the file name, followed by a single space
30 4. then the file modification date (we won’t display the file creation date).
For example:
F 2560 foo.txt 2005/11/15 12:00:00
F 5120 foo2.txt 2005/11/15 12:00:00
F 48127 makefs 2005/11/15 12:00:00
F 8 foo3.txt 2005/11/15 12:00:00
31 2.3 Part III (5 Marks)
32 In part III, you will write a program that copies a file from the file system to the current directory in Linux. If the
33 specified file is not found in the root directory of the file system, you should output the message File not found.
34 and exit.
35 Your program for part III will be invoked as follows:
./diskget disk1.img foo.txt
36 2.4 Part IV (5 marks)
37 In part IV, you will write a program that copies a file from the current Linux directory into the file system. If the
38 specified file is not found, you should output the message File not found. on a single line and exit.
39 Your program for part IV will be invoked as follows:
./diskput disk1.img foo.txt
40 3 File System Specification
41 The FAT file system has three major components:
42 1. the super block,
43 2. the File Allocation Table (informally referred to as the FAT),
44 3. the directory structure.
45 Each of these three components is described in the subsections below.
2
Description Size Default Value
File system identifier 8 bytes CSC360FS
Block Size 2 bytes 0x200
File system size (in blocks) 4 bytes 0x00001400
Block where FAT starts 4 bytes 0x00000001
Number of blocks in FAT 4 bytes 0x00000028
Block where root directory starts 4 bytes 0x00000029
Number of blocks in root dir 4 bytes 0x00000008
Figure 1: Superblock Fields
46 3.1 File System Superblock
47 The first block (512 bytes) is reserved to contain information about the file system. The layout of the superblock is
48 as follows:
49 Note: Block number starts from 0 in the file system.
50 IMPORTANT: the superblock only specifies the starting block of FAT and root directory and how
51 many blocks they have—this does NOT mean that these blocks are consecutive in the disk image,
52 i.e., you need to use the FAT to locate the complete FAT and root directory blocks as well.
53 3.2 Directory Entries
54 Each directory entry takes up 64 bytes, which implies there are 8 directory entries per 512 byte block.
55 Each directory entry has the following structure:
Description Size
Status 1 byte
Starting Block 4 bytes
Number of Blocks 4 bytes
File Size (in bytes) 4 bytes
Create Time 7 bytes
Modify Time 7 bytes
File Name 31 bytes
unused (set to 0xFF) 6 bytes
Figure 2: Directory Entry
56 The description of each field follows:
57 Status This is bit mask that is used to describe the status of the file. Currently only 3 of the bits are used.
Bit 0 set to 0 if this directory entry is available,
set to 1 if it is in use
Bit 1 set to 1 if this entry is a normal file
Bit 2 set to 1 if this entry is a directory
Figure 3: Format of Status Field
58 It is implied that only one of bit 2 or bit 1 can be set to 1. That is, an entry is either a normal file or it is a
59 directory, not both.
60 Starting Block This is the location on disk of the first block in the file
61 Number of Blocks The total number of blocks in this file
3
File Size The size of the file, in bytes. The size of this field implies that the largest file we can support is 232
62 bytes
63 long.
64 Create Time The date and time when this file was created. The file system stores the system times as integer
65 values in the format:
66 YYYYMMDDHHMMSS
Field Size
YYYY 2 bytes
MM 1 byte
DD 1 byte
HH 1 byte
MM 1 byte
SS 1 byte
Figure 4: Format of Date-Time Field
67 Modify Time The last time this file was modified. Stored in the same format as the Create Time shown above.
68 File Name The file name, null terminated. Because of the null terminator, the maximum length of any filename is
69 30 bytes.
70 Valid characters are upper and lower case letters (a-z, A-Z), digits (0-9) and the underscore character ( ).
71 3.3 File Allocation Table (FAT)
72 Each directory entry contains the starting block number for a file, let’s say it is block number X. To find the next
73 block in the file, you should look at entry X in the FAT. If the value you find there does not indicate End-of-File
74 (see below) then that value, call it Y, is the next block number in the file.
75 That is, the first block is at block number X, you look in the FAT table at entry X and find the value Y. The
76 second data block is at block number Y. Then you look in the FAT at entry Y to find the next data block number…
77 continue this until you find the special value in the FAT entry indicating that you are at the last FAT entry of the
78 file.
79 The FAT is really just a linked list, which the head of the list being stored in the “Starting Block” field in the
80 directory entry, and the ‘next pointers’ being stored in the FAT entries.
81 Fat entries are 4 bytes long (32 bits), which implies there are 128 FAT entries per block.
Special values for FAT entries are described in Figure 5.
Value Meaning
0x00000000 This block is available
0x00000001 This block is reserved
0x00000002–
0xFFFFFF00 Allocated blocks as part of files
0xFFFFFFFF This is the last block in a file
Figure 5: Value of FAT entry
82
83 4 Byte Ordering
84 Different hardware architectures store multi-byte data (like integers) in different orders. Consider the large integer:
85 0xDEADBEEF
86 On the Intel architecture (Little Endian), it would be stored in memory as:
87 EF BE AD DE
4
88 On the PowerPC (Big Endian), it would be stored in memory as:
89 DE AD BE EF
90 Our file system will use Big Endian for storage. This will make debugging the file system by examining the raw
91 data much easier.
92 This will mean that you have to convert all your integer values to Big Endian before writing them to disk. There
93 are utility functions in netinit/in.h that do exactly that. (When sending data over the network, it is expected the
94 data is in Big Endian format.)
95 See the functions htons, htonl, ntohs and ntohl.
96 The side effect of using these functions will be that your code will work on multiple platforms. (On machines
97 that natively store integers in Big Endian format, like the Mac (not the Intel-based ones), the above functions don’t
98 actually do anything but you should still use them!)
99 5 Submission Requirements
100 What to hand in: You need to hand in a .tar.gz file containing all your source code and a Makefile that produces
101 the executables for parts 1 – 4.
102 Please include a readme.txt file that explains any bonus activities that you completed.
103 The file is submitted through connex.csc.uvic.ca site.
104 6 Possible Bonuses
105 There is lots of room for bonus marks in this assignment. As before, you must get permission from your instructor
106 before you begin the bonus activities, at least one week before the due date. Some things you may consider:
107 1. implementing directories other than the root directory
108 2. implementing fast searching for directories and/or free space
109 3. implementing the file system as a device driver for Linux
110 4. writing a shell to interact with the file system
If you have any other ideas, please email your instructor.
5
A An Exercise
Q1 Consider the superblock shown below:
0000000: 4353 4333 3630 4653 0200 0000 1400 0000 CSC360FS……..
0000010: 0001 0000 0028 0000 0029 0000 0008 0000 …..(…)……
0000020: 0000 0000 0000 0000 0000 0000 0000 0000 …………….
(a) What block does the FAT start on? How many blocks are used for the FAT?
(b) What block does the root directory start on? How many blocks are used for the root directory?
6
Q2 Consider the following block from the root directory:
0005200: 0300 0000 3100 0000 0500 000a 0007 d50b ….1………..
0005210: 0f0c 0000 07d5 0b0f 0c00 0066 6f6f 2e74 ………..foo.t
0005220: 7874 0000 0000 0000 0000 0000 0000 0000 xt…………..
0005230: 0000 0000 0000 0000 0000 00ff ffff ffff …………….
0005240: 0300 0000 3600 0000 0a00 0014 0007 d50b ….6………..
0005250: 0f0c 0000 07d5 0b0f 0c00 0066 6f6f 322e ………..foo2.
0005260: 7478 7400 0000 0000 0000 0000 0000 0000 txt………….
0005270: 0000 0000 0000 0000 0000 00ff ffff ffff …………….
0005280: 0300 0000 4000 0000 5e00 00bb ff07 d50b ….@…^…….
0005290: 0f0c 0000 07d5 0b0f 0c00 006d 616b 6566 ………..makef
00052a0: 7300 0000 0000 0000 0000 0000 0000 0000 s……………
00052b0: 0000 0000 0000 0000 0000 00ff ffff ffff …………….
00052c0: 0300 0000 9e00 0000 0100 0000 0807 d50b …………….
00052d0: 0f0c 0000 07d5 0b0f 0c00 0066 6f6f 332e ………..foo3.
00052e0: 7478 7400 0000 0000 0000 0000 0000 0000 txt………….
00052f0: 0000 0000 0000 0000 0000 00ff ffff ffff …………….
(a) How many files are allocated in this directory? What are their names?
(b) How many blocks does the file makefs occupy on the disk?
7
Q3 Given the root directory information from the previous question and the FAT table shown below:
0000200: 0000 0001 0000 0001 0000 0001 0000 0001 …………….
0000210: 0000 0001 0000 0001 0000 0001 0000 0001 …………….
0000220: 0000 0001 0000 0001 0000 0001 0000 0001 …………….
0000230: 0000 0001 0000 0001 0000 0001 0000 0001 …………….
0000240: 0000 0001 0000 0001 0000 0001 0000 0001 …………….
0000250: 0000 0001 0000 0001 0000 0001 0000 0001 …………….
0000260: 0000 0001 0000 0001 0000 0001 0000 0001 …………….
0000270: 0000 0001 0000 0001 0000 0001 0000 0001 …………….
0000280: 0000 0001 0000 0001 0000 0001 0000 0001 …………….
0000290: 0000 0001 0000 0001 0000 0001 0000 0001 …………….
00002a0: 0000 0001 0000 002a 0000 002b 0000 002c …….*…+…,
00002b0: 0000 002d 0000 002e 0000 002f 0000 0030 …-……./…0
00002c0: ffff ffff 0000 0032 0000 0033 0000 0034 …….2…3…4
00002d0: 0000 0035 ffff ffff 0000 0037 0000 0038 …5…….7…8
00002e0: 0000 0039 0000 003a 0000 003b 0000 003c …9…:…;…< 00002f0: 0000 003d 0000 003e 0000 003f ffff ffff ...=...>…?….
(a) What blocks does the file foo.txt occupy on the disk?
(b) What blocks does the file foo2.txt occupy on the disk?
8