多线程代写 | C代写 | 操作系统代写 – A Simple File System (SFS)

多线程代写|C代写|操作系统代写:这是一个利用C语言完成的操作系统方面的代写
1 1 Introduction
2 So far, you have built a shell environment and a multi-thread scheduler with process synchronization. Excellent job!
3 What is still missing for a “real” operating system? A file system! In this assignment, you will implement utilities
4 that perform operations on a file system similar to Microsoft’s FAT file system with some improvement.
5 1.1 Sample File Systems
6 You will be given a test file system image for self-testing, but you can create your own image following the specification,
7 and your submission may be tested against other disk images following the same specification.
8 You should get comfortable examining the raw, binary data in the file system images using the program xxd.
9 IMPORTANT: since you are dealing with binary data, functions intended for string manipulation
10 such as strcpy() do NOT work (since binary data may contain binary ‘0’ anywhere), and you should
11 use functions intended for binary data such as memcpy().
12 2 Tutorial Schedule
13 In order to help you finish this programming assignment on time successfully (and also the last one ;-), the schedule
14 of the lectures and the tutorials has been adjusted. There are three tutorials arranged during the course of this
15 assignment. NOTE: Please do attend the tutorials and follow the tutorial schedule closely.
Date Tutorial Milestones
Mar 6/7 no tutorial due to p2b extension and m2 preparation p3 self-practice questions
Mar 13/14 p3 spec and practice questions go-through design done
Mar 20/21 more on design and implementation coding done
Mar 27/28 testing and last-minute help final deliverable
16 3 Requirements
17 3.1 Part I (3 points)
18 In part I, you will write a program that displays information about the file system. In order to complete part I, you
19 will need to read the file system super block and use the information in the super block to read the FAT.
20 Your program for part I will be invoked as follows (output value just for illustration purposes):
./diskinfo test.img
21 Sample output:
Super block information:
Block size: 512
Block count: 5120
FAT starts: 1
1
FAT blocks: 40
Root directory start: 41
Root directory blocks: 8
FAT information:
Free Blocks: 5071
Reserved Blocks: 41
Allocated Blocks: 8
22 Please be sure to use the exact same output format as shown above.
23 3.2 Part II (4 points)
24 In part II, you will write a program, with the routines already implemented for part I, that displays the contents of
25 the root directory or a given sub-directory in the file system.
26 Your program for part II will be invoked as follows:
./disklist test.img /sub_dir
27 The directory listing should be formatted as follows:
28 1. The first column will contain:
29 (a) F for regular files, or
30 (b) D for directories;
31 followed by a single space
32 2. then 10 characters to show the file size, followed by a single space
33 3. then 30 characters for the file name, followed by a single space
34 4. then the file modification date (we will not 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
35 3.3 Part III (4 points)
36 In part III, you will write a program that copies a file from the file system to the current directory in Linux. If the
37 specified file is not found in the root directory or a given sub-directory of the file system, you should output the
38 message File not found. and exit.
39 Your program for part III will be invoked as follows:
./diskget test.img /sub_dir/foo2.txt foo.txt
40 3.4 Part IV (4 points)
41 In part IV, you will write a program that copies a file from the current Linux directory into the file system, at the
42 root directory or a given sub-directory. If the specified file is not found, you should output the message File not
43 found. on a single line and exit.
44 Your program for part IV will be invoked as follows:
./diskput test.img foo.txt /sub_dir/foo3.txt
2
45 4 File System Specification
46 The FAT file system has three major components:
47 1. the super block,
48 2. the directory structure.
49 3. the File Allocation Table (informally referred to as the FAT),
50 Each of these three components is described in the subsections below.
51 4.1 File System Superblock
52 The first block (512 bytes) is reserved to contain information about the file system. The layout of the superblock is
53 as follows:
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
54 Note: Block number starts from 0 in the file system.
55 4.2 Directory Entries
56 Each directory entry takes up 64 bytes, which implies there are 8 directory entries per 512 byte block.
57 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
58 The description of each field follows:
59 Status This is bit mask that is used to describe the status of the file. Currently only 3 of the bits are used.
60 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
61 directory, not both.
62 Starting Block This is the location on disk of the first block in the file
63 Number of Blocks The total number of blocks in this file
File Size The size of the file, in bytes. The size of this field implies that the largest file we can support is 232
64 bytes
65 long.
3
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
66 Create Time The date and time when this file was created. The file system stores the system times as integer
67 values in the format:
68 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
69 Modify Time The last time this file was modified. Stored in the same format as the Create Time shown above.
70 File Name The file name, null terminated. Because of the null terminator, the maximum length of any filename is
71 30 bytes.
72 Valid characters are upper and lower case letters (a-z, A-Z), digits (0-9) and the underscore character ( ).
73 4.3 File Allocation Table (FAT)
74 Each directory entry contains the starting block number for a file, let’s say it is block number X. To find the next
75 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
76 (see below) then that value, call it Y, is the next block number in the file.
77 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
78 second data block is at block number Y. Then you look in the FAT at entry Y to find the next data block number…
79 continue this until you find the special value in the FAT entry indicating that you are at the last FAT entry of the
80 file.
81 The FAT is really just a linked list, which the head of the list being stored in the “Starting Block” field in the
82 directory entry, and the ‘next pointers’ being stored in the FAT entries.
83 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
84
4
85 5 Byte Ordering
86 Different hardware architectures store multi-byte data (like integers) in different orders. Consider the large integer:
87 0xDEADBEEF
88 On the Intel architecture (Little Endian), it would be stored in memory as:
89 EF BE AD DE
90 On the PowerPC (Big Endian), it would be stored in memory as:
91 DE AD BE EF
92 Our file system will use Big Endian for storage. This will make debugging the file system by examining the raw
93 data much easier.
94 This will mean that you have to convert all your integer values to Big Endian before writing them to disk. There
95 are utility functions in netinit/in.h that do exactly that. (When sending data over the network, it is expected the
96 data is in Big Endian format.)
97 See the functions htons, htonl, ntohs and ntohl.
98 The side effect of using these functions will be that your code will work on multiple platforms. (On machines
99 that natively store integers in Big Endian format, like the Mac (not the Intel-based ones), the above functions don’t
100 actually do anything but you should still use them!)
101 6 Submission Requirements
102 What to hand in: You need to hand in a .tar.gz file containing all your source code and a Makefile that produces
103 the executables for parts 1 – 4.
104 Please include a readme.txt file that explains your design and implementation.
105 The file is submitted through connex.csc.uvic.ca site.
5
106 A An Exercise
107 Q1 Consider the superblock shown below:
108 0000000: 4353 4333 3630 4653 0200 0000 1400 0000 CSC360FS……..
109 0000010: 0001 0000 0028 0000 0029 0000 0008 0000 …..(…)……
110 0000020: 0000 0000 0000 0000 0000 0000 0000 0000 …………….
111 (a) What block does the FAT start on? How many blocks are used for the FAT?
112 (b) What block does the root directory start on? How many blocks are used for the root directory?
6
113 Q2 Consider the following block from the root directory:
114 0005200: 0300 0000 3100 0000 0500 000a 0007 d50b ….1………..
115 0005210: 0f0c 0000 07d5 0b0f 0c00 0066 6f6f 2e74 ………..foo.t
116 0005220: 7874 0000 0000 0000 0000 0000 0000 0000 xt…………..
117 0005230: 0000 0000 0000 0000 0000 00ff ffff ffff …………….
118 0005240: 0300 0000 3600 0000 0a00 0014 0007 d50b ….6………..
119 0005250: 0f0c 0000 07d5 0b0f 0c00 0066 6f6f 322e ………..foo2.
120 0005260: 7478 7400 0000 0000 0000 0000 0000 0000 txt………….
121 0005270: 0000 0000 0000 0000 0000 00ff ffff ffff …………….
122 0005280: 0300 0000 4000 0000 5e00 00bb ff07 d50b ….@…^…….
123 0005290: 0f0c 0000 07d5 0b0f 0c00 006d 616b 6566 ………..makef
124 00052a0: 7300 0000 0000 0000 0000 0000 0000 0000 s……………
125 00052b0: 0000 0000 0000 0000 0000 00ff ffff ffff …………….
126 00052c0: 0300 0000 9e00 0000 0100 0000 0807 d50b …………….
127 00052d0: 0f0c 0000 07d5 0b0f 0c00 0066 6f6f 332e ………..foo3.
128 00052e0: 7478 7400 0000 0000 0000 0000 0000 0000 txt………….
129 00052f0: 0000 0000 0000 0000 0000 00ff ffff ffff …………….
130 (a) How many files are allocated in this directory? What are their names?
131 (b) How many blocks does the file makefs occupy on the disk?
7
132 Q3 Given the root directory information from the previous question and the FAT table shown below:
133 0000200: 0000 0001 0000 0001 0000 0001 0000 0001 …………….
134 0000210: 0000 0001 0000 0001 0000 0001 0000 0001 …………….
135 0000220: 0000 0001 0000 0001 0000 0001 0000 0001 …………….
136 0000230: 0000 0001 0000 0001 0000 0001 0000 0001 …………….
137 0000240: 0000 0001 0000 0001 0000 0001 0000 0001 …………….
138 0000250: 0000 0001 0000 0001 0000 0001 0000 0001 …………….
139 0000260: 0000 0001 0000 0001 0000 0001 0000 0001 …………….
140 0000270: 0000 0001 0000 0001 0000 0001 0000 0001 …………….
141 0000280: 0000 0001 0000 0001 0000 0001 0000 0001 …………….
142 0000290: 0000 0001 0000 0001 0000 0001 0000 0001 …………….
143 00002a0: 0000 0001 0000 002a 0000 002b 0000 002c …….*…+…,
144 00002b0: 0000 002d 0000 002e 0000 002f 0000 0030 …-……./…0
145 00002c0: ffff ffff 0000 0032 0000 0033 0000 0034 …….2…3…4
146 00002d0: 0000 0035 ffff ffff 0000 0037 0000 0038 …5…….7…8
147 00002e0: 0000 0039 0000 003a 0000 003b 0000 003c …9…:…;…< 148 00002f0: 0000 003d 0000 003e 0000 003f ffff ffff ...=...>…?….
149 (a) What blocks does the file foo.txt occupy on the disk?
150 (b) What blocks does the file foo2.txt occupy on the disk?
8

发表评论

电子邮件地址不会被公开。 必填项已用*标注