COMP3430
Operating Systems
Home
ROASS
Lectures
Assignments
Labs
Resources
Assignment 4: File Systems
Due: April 4, 11:59pm
Write a program that reads a FAT 16-formatted drive. For this assignment we will use disk image -
though you are encouraged to read a USB ash
drive as a raw device (ie. /dev/disk3).
Your program requires 2 functions:
1. Print information about the drive. The command, assuming your program is named fat16,
would be ./fat16 imagename info. Print out the following:
Drive name
Free space on the drive in kB
The amount of usable storage on the drive (not free, but usable space)
The cluster size in number of sectors, and in KB.
2. Output all les
and directories on the drive. The output should look roughly like the output
from tree, where there is the same number of "-" characters as the depth of the le/folder.
The command, assuming your program is named fat16, would be ./fat16 imagename
list
Output should look something like:
file.txt
Directory: FOLDER
-Directory: FOLDER2
--Directory: FOLDER3
---File: THEFILE.TXT
file2.txt
3. Be able to fetch, and return a le
from the drive
3/18/2019 Assignments - COMP3430
http://www.cs.umanitoba.ca/~comp3430/assignments/assignment4/ 2/4
The command, assuming your compiled program name is fat16, would be ./fat16
imagename get path/to/file.txt
To work with the disk / disk image, use the low-level, unbuered
open, close, read, write, and
lseek system calls. This will save you headaches, buering,
conversions, etc., and let you work
on the byte level.
You have been provided with a Microsoft white paper on their FAT le
systems (Fat12/16/32). You
will only worry about the FAT32 short name implementation so you should use your
discretion on reading.
Also, the minimal header le
fat.h provides a struct data structure for the boot sector. In
addition to any other data structures you may need for your implementation, you will need to
create a similar struct for the FSInfo type. Note the datatypes used instead of the standard int,
etc. Note carefully the #pragma commands used and use them for any structures that you tie
directly to reading from disk (what do these do and why are they important?
http://en.wikipedia.org/wiki/Data_structure_alignment)
Finally, you've been provided with a disk image for testing.
Directories
Directories (aka folders) are simply les
on disk with a special format. There are some good
things to note before reading a directory:
The rst
byte of an entry tells you things such as whether the entry is empty or if it’s the last
entry.
You will nd
empty entries interspersed through the directory. Do not stop searching on an
empty entry! Only the last one!
A directory le
can be quite large and span multiple clusters (Check in the FAT!), so don’t just
stop at one cluster.
The most confusing part here is that you will nd
what appear to be garbage entries.
Fat12/16 only supported 8-character le
names with a 3-character extension. Fat32 added
long lename
support but did it in a way that is backward compatible - old Fat12/16
systems would only see an 8-char version. E.g., le
somelongfilename would show up as
SOMELO~1 - you may have seen such les
up until the mid 2000's. The full lename
is
hidden across several extra added directory entries. For this assignment we will use the
short names only (much simpler) and can skip the ller
entries. Note that you can lter
out
these unwanted long-name additional entries by ltering
against the ATTR_LONG_NAME
attribute.
An additional side eect
is that everything in FAT12/16 was uppercase, so you should stick
to uppercase
Directory entries inside a directory point to the cluster where another directory le
is stored
- look in that le
to see what is in the directory
Memory and Data Types
3/18/2019 Assignments - COMP3430
http://www.cs.umanitoba.ca/~comp3430/assignments/assignment4/ 3/4
Integer overows
and memory layout and alignment are serious issues in this assignment. Note
#pragma comment above. When dealing with addressing specic
bytes of a le
(or disk.) and you
seek using the lseek command, you can easily get bytes addressed well out of range of a
standard 32 bit integer, particularly if it is signed. When dealing with addresses use the explicit
uint32_t family of types to be sure you have enough memory, and use the off_t type (le
oset,
as in man lseek) to be safe. In addition, you will want to add the following line to the TOP
of your main source le
before you load the system libraries:
#define _FILE_OFFSET_BITS 64
This tells the compiler to make the off_t 64 bits wide instead of 32 bits. This is more important if
you are implementing FAT32 (the bonus). Further, it is recommended that you think of reading
and writing to disk in units of sectors and clusters. Not only for eciency
reasons, but it will help
you conceptualize the assignment a lot easier. Try to work in sectors and clusters as much as
possible and only convert to bytes when necessary (e.g., when doing a seek and read)
Disk layout
1. Reserved Area - boot sector and bios parameter block (BPB) at sector 0 (1 sector only).
Read sector 0 directly into the fatBS struct provided.
2. FAT Area - File allocation table (list of 16-bit entries). Immediately follows the reserved area.
3. Data Area - Most of the disk. All the le
data is stored in here, directory entries are stored
in here. NOTE: The rst
cluster of this area is ocially
called Cluster 2 regardless of where it
starts on the disk. The space used by the proceeding two areas is quite denitely
more than
2 clusters large (which would only be ~8k on many disks) luckily, from here the following
clusters are of the appropriate size.
Notes
The top 2 addresses of the FAT are are signatures. You must validate these signatures
before using the le
system
The FAT can be quite large so do not load the entire FAT into memory at once.
Be very careful with unit types! You will need to work in sectors, clusters, and bytes, at
dierent
times. Maybe create functions to convert the types.
How to get started (just suggestions)
1. You will most likely get overows,
null pointers, etc. Some bad math and who knows where
you'll end up on disk (or in memory!). Be extremely defensive in your programming.
2. Check parameters, ranges, and printf meaningful error messages. This will save you
debug time
3. First, load and parse the boot sector / BPB into the struct and write your info function as
much as possible. CHECK THE SIGNATURE BYTES. This tells you if you loaded it correctly.
4. Calculate the location of the FAT and check the FAT Signature
3/18/2019 Assignments - COMP3430
http://www.cs.umanitoba.ca/~comp3430/assignments/assignment4/ 4/4
5. Implement methods to read specic
fat items for disk clusters
Handin
Include a makele
to build your assignment, with proper build and clean rules. Make sure to
run make clean before handing in your assignment. A penalty of 25% of your nal
mark
will apply, if your submission contains temporary les
(including the sample disk image! Do
NOT submit it...)
Include a readme, that explains how to build and run your assignment.
Your assignment must run on the CS Aviary lab computers.
A completed copy of your the honesty declaration for this assignment.
Bonus
Implement FAT32, in addition to FAT16. Choose the driver appropriately based on the signature.
版权所有:留学生编程辅导网 2020 All Rights Reserved 联系方式:QQ:99515681 微信:codinghelp 电子信箱:99515681@qq.com
免责声明:本站部分内容从网络整理而来,只供参考!如有版权问题可联系本站删除。