Homework 4: Address Conversion Utility¶
Multiple addressing techniques are used on IBM PC-compatible hard drives and in FAT file systems to both simplify addressing mechanisms and to reduce the number of bits necessary to locate all areas within a logical space, like a partition.
For this assignment, you are to write a Unix-like command line utility that will convert between three different address types when an address of a different type is given. This will require you to have a sound understanding of the following principles:
- Hard drive geometry and layout.
- Partition creation.
- FAT tables and clusters.
- Addition, subtraction, multiplication, and division.
The code you write for this project should be in a Linux-compatible language (e.g. C/C++, Java, Python, Perl, etc.). Use the following usage specifications for your utility:
addrconv logical [-b offset] [-B [-s bytes]] [-p address] [-c address -k sectors -r sectors -t tables -f sectors] addrconv physical [-b offset] [-B [-s bytes]] [-l address] [-c address -k sectors -r sectors -t tables -f sectors] addrconv cluster [-b offset] [-B [-s bytes]] [-l address] [-p address]
Where the parameters must conform to the following specifications:
logical Calculate the logical address from either the cluster address or the physical address. Either
-pmust be given.
physical Calculate the physical address from either the cluster address or the logical address. Either
-lmust be given.
cluster Calculate the cluster address from either the logical address or the physical address. Either
-pmust be given.
-b offset, --partition-start=offset This specifies the physical address (sector number) of the start of the partition, and defaults to 0 for ease in working with images of a single partition. The
offsetvalue will always translate into logical address 0.
-B, --byte-address Instead of returning sector values for the conversion, this returns the byte address of the calculated value, which is the number of sectors multiplied by the number of
-s bytes, --sector-size=bytes When the
-Boption is used, this allows for a specification of
bytesper sector other than the default 512. Has no affect on output without
-l address, --logical-known=address This specifies the known logical
addressfor calculating either a cluster address or a physical address. When used with the
-Loption, this simply returns the value given for
-p address, --physical-known=address This specifies the known physical
addressfor calculating either a cluster address or a logical address. When used with the
-Poption, this simply returns the value given for
-c address, --cluster-known=address This specifies the known cluster
addressfor calculating either a logical address or a physical address. When used with the
-Coption, this simply returns the value given for
address. Note that options
-fmust be provided with this option.
-k sectors, --cluster-size=sectors This specifies the number of sectors per cluster. -r sectors, --reserved=sectors This specifies the number of reserved sectors in the partition. -t tables, --fat-tables=tables This specifies the number of FAT tables, which is usually 2. -f sectors, --fat-length=sectors This specifies the length of each FAT table in sectors.
One of the objectives of this assignment is to help you familiarize yourself with how to read and understand command line specifications, such as the above. Take your time to understand each option, what it does, and the other options it interacts with, and you’ll do fine.
An example of this in use would be the following, where the desired number is the logical address of physical sector 12345678 in a partition that begins at physical sector 128:
$ addrconv -L -b 128 --physical-known=12345678 12345550
Another example shows the utility getting the physical address of cluster 58, in a partition that begins at physical sector 128, has 2 FAT tables that are each 16 sectors long, 6 reserved sectors, and 4 sectors per cluster:
$ addrconv -P --partition-start=128 -c 58 -k 4 -r 6 -t 2 -f 16 390
Your program must work on Ubuntu 18.04 64-bit with the default packages installed. You may find it helpful to set up a virtual machine to do your development. VirtualBox is a free and open-source VM system.
If you wish to use packages that are not installed on Ubuntu 18.04 64-bit by default, please submit a file with your
packages, with a list of packages that you would like installed before calling
make. Each line of
packages must be a valid package name, one package per line. The submission
system will automatically install all the dependencies that the package lists.
We’ve created a test script called
test.sh to help you test your program before compiling.
- Download test.sh to the directory where your code lives (including
- Ensure that
chmod +x test.sh
You will need to submit your source code, along with a Makefile and README. The Makefile must create your executable,
addrconv, when the command
make is run. Your README file must be plain text and should contain your name,
ASU ID, and a description of how your program works.
A prior TA compiled some resources on how to write a Makefile which might be helpful: