COMP 3430 Lab 4
COMP 3430 Lab 4
Copyright By PowCoder代写 加微信 powcoder
File systems
Winter 2022
Lab introduction
General requirements
fsck-ing exFAT
Checking the MBR
Checking the Allocation
Boot sector
Sample volumes
Assessment
Handing in
Lab introduction
Hi! Welcome to lab 4!
In this lab we’re going to spend some time checking file systems.
Lab 4 is due on Friday, April 15th 2022 at 11:59pm
CDT (Winnipeg time). See Handing in
below for more details about how to hand in your lab work.
General requirements
Your submission must have a working
Makefile. There are no firm requirements on flags as in the
assignments, but your TA must be able to build your submission with
make. You may specify alternative targets in your
README, but if you have alternative targets you must
explicitly document them.
If you do not include a Makefile, your TA will not
assess your submission.
fsck-ing exFAT
What the fsck is this?! (Public
In this part of the lab you’re going to fsck an exFAT
volume. Really specifically, you’re going to be fsck-ing
some properties of the Main Boot Sector, and confirming that the Allocation Bitmap and the Main Boot Sector agree with one another (i.e., they
are consistent).
Checking the MBR
Table 4 describes each of the fields that are
present in the Main Boot Sector. Each of these fields links to
descriptions in the comments column, and each of these descriptions
explains what the valid values are for each field.
Your program should read an exFAT-formatted volume and check the
following values in the Main Boot Sector:
FileSystemName
MustBeZero
VolumeLength
FirstClusterOfRootDirectory
BootSignature
If your program finds an invalid value for any of these properties,
it should immediately stop processing and print out an appropriate error
Inconsistent file system: FileSystemName must be ‘EXFAT ‘, value is ‘NOTEXFAT’.
Inconsistent file system: FatOffset should be >=24, value is 21.
Inconsistent file system: FatOffset should be <=128, value is 132.
If your program does not find any invalid values for these
properties, it should print out a success message for the MBR:
MBR appears to be consistent.
Checking the Allocation
Your next task is to check the Allocation Bitmap. The Allocation Bitmap is stored in an exFAT volume as a
Directory Entry in the cluster of the root
directory.
Find the cluster for the root directory using the
FirstClusterOfRootDirectory cluster.
Scan through the DirectoryEntrys in the root directory
until you find the entry with entry type 0x81 (indicating
the Allocation Bitmap directory entry).
Each DirectoryEntry is 32 bytes in size, and the
EntryType is always the first byte.
Find the first cluster of the Allocation Bitmap using the
FirstCluster field from the Allocation Bitmap
DirectoryEntry.
Read all bytes from the cluster. The number of bytes you should read
from the cluster are DataLength bytes.
Count the number of set bits in each byte using the __builtin_popcount function (population
count counts the number of set bits).
Check that the fraction of set bits out of all bits in the
allocation bitmap matches PercentInUse in the MBR.
NOTE: For the purposes of this lab, you
can safely assume that the things we’re interested in are entirely
contained within one cluster. In other words, you don’t need to build
cluster chains to get this data, you can go directly to the cluster heap
from the first cluster fields that you’re reading.
If your program finds an inconsistency between the allocation bitmap
and the PercentInUse field, you should print out an error
Inconsistent file system: PercentInUse is 30%, allocation bitmap is 1536/2048 bits => 75%.
If your program finds that the allocation bitmap and
PercentInUse are consistent, you should print out a success
File system appears to be consistent.
Be careful to note the units of different fields (e.g.,
FatOffset and ClusterHeapOffset are measured
in sectors, but you lseek with bytes).
Fields that are named XShift are named that way
because they are always used as powers of 2, and powers of 2 can be
expressed as 1 << X.
In other words: 220 →
Be careful about operator precedence: << has a
lower precedence than other arithmetic operations.
The cluster heap is a 2-based array of clusters. Read the start
of section 5.1 Cluster Heap Sub-region carefully:
Importantly, the first cluster of the Cluster Heap has index two,
which directly corresponds to the index of FatEntry[2].
This means that any arithmetic you do to get to the start of the
cluster heap must be off by two. For example: if the
FirstClusterOfRootDirectory is 5, then the cluster for the
root directory is actually at 3 (5 - 2 = 3).
You can print a % symbol with printf by
using the format code %% (i.e., printf("%%")
prints out one % symbol).
Boot sector struct
Typing in a struct for the boot sector is tedious, and
doesn’t help you demonstrate your ability to work with a file system
(believe us, we know, we typed in the struct for the boot
Have a struct (you are permitted to use this code in
your lab submission):
#pragma pack(1)
#pragma pack(push)
typedef struct MAIN_BOOT_SECTOR
uint8_t jump_boot[3];
char fs_name[8];
uint8_t must_be_zero[53];
uint64_t partition_offset;
uint64_t volume_length;
uint32_t fat_offset;
uint32_t fat_length;
uint32_t cluster_heap_offset;
uint32_t cluster_count;
uint32_t first_cluster_of_root_directory;
uint32_t volume_serial_number;
uint16_t fs_revision;
uint16_t fs_flags;
uint8_t bytes_per_sector_shift;
uint8_t sectors_per_cluster_shift;
uint8_t number_of_fats;
uint8_t drive_select;
uint8_t percent_in_use;
uint8_t reserved[7];
uint8_t bootcode[390];
uint16_t boot_signature;
} main_boot_sector;
#pragma pack(pop)
Sample volumes
You can download some sample volumes to test
your fsck. The zip file contains a README
describing what each volume is, and what you would expect to see as
output for the fsck.
Assessment
The code for this part is worth 4 points:
Level Description
0 No attempt or minimal attempt to complete the question.
1 Implementation is substantially incomplete (MBR started).
2 Implementation is partially complete (MBR finished, no attempt at
bitmap, or bitmap does not work at all).
3 Implementation is substantially complete (MBR finished, bitmap
started but incomplete).
4 Implementation is complete (MBR and bitmap are complete).
Handing in
A complete folder for lab 4 might look something like:
~]> tree my_lab4/
├── Makefile
├── fsck-exfat.c
└── README.md
0 directories, 3 files
When completed, use the handin command. Assuming that
you’ve put all of your lab 4 stuff into a folder called
my_lab4, then you can run:
handin 3430 lab4 my_lab4
handin will then make some happy noises to say that
you’ve handed in your folder successfully:
~]> handin 3430 lab4 my_lab4
handin: Time Stamp: Fri Apr 15 10:16:39 2022
Submitter:
Total bytes copied to handin file was: 2840
Handin was successful.
Note: the number of bytes handin reports
will always be smaller than the size of your folder
because handin compresses the folder before turning it
程序代写 CS代考 加微信: powcoder QQ: 1823890830 Email: powcoder@163.com