Introduction
这个作业要求实现一个 FAT32 的文件系统,能实现基本的文件系统命令即可。作业给了参考的微软白皮书,以及image镜像文件。
Preface
For this assignment, you must use a single makefile that is able to build your
project. It must have a default all target that builds the shell executable,
and a clean target that removes all the build products. You can start with the
makefile from the previous assignment and/or modify, or use makefiles found
online (please cite!) as you like.
Also, please note:
All work submitted for the assignment must be your own.
- Include your name and user id in a comment at the top of each source code file.
- The code you submit must be easily readable by the marker. Remember that well-written code (including good structure and naming) is better than lots of comments.
- The code you submit must be easily buildable and runnable by the marker. Follow all instructions. The markers may use scripts to ease their work, and if they break because you did not follow instructions, you may receive substantial mark penalties.
- Your makefile and the executable it builds should be in the top-level directory that you hand in. Entering make and then simulator (with parameters) should be enough to run it.
- The code you submit must build and run correctly on the CS Linux systems with gcc. Watch out with filename case! The UNIX standard is all-lower-case source file names, and Makefile.
Question 1: Simulated FAT
Write an interactive shell that lets you browse a FAT12/16 formatted disk
image. These images may be created from a DOS floppy or (small) hard drive.
They contain only a single partition.
Your shell will implement (at least) the following commands:
- info prints summary information about the FAT partition.
- dir lists all the files (including metadata) in the current directory.
- cd changes the current directory.
- get downloads a file from the current directory in the FAT partition to your local disk.
Sending EOF (Ctrl-D) ends the program.
Download the Microsoft white paper on their FAT file systems posted on the
site. You will be implementing FAT12/16, and there are many additional parts
of the document that may not be relevant to your work on the assignment. Read
the relevant sections thoroughly. Like man pages, this document is dense with
content and important details.
You have also been provided with three C files: - fat.h contains some of the important constants and structures defined in the MS whitepaper.
- fat_fs.h is an interface to functions that manipulate the FAT image. You can extend but not modify this file.
- shell.c is code for managing the interactive shell.
You will probably want to use all three, but you must implement the functions
in fat_fs.h without modification. You may extend it with additional functions
but do not change the names, behaviours, or signatures of the existing
functions. You may modify the other files as you like.
Your implementation must not read the entire contents of the image into
memory. You must work with the image on disk, reading only individual sectors
or clusters at a time. There are two possibilities. The mmap function lets you
map a file into memory pages (more soon!) and access the bytes of the file
relative to a pointer. Or you can more directly access the file using the
lseek function and reading bytes from there.
Bonus marks!
You can get bonus marks (allowing your assignment to total more than 100%) if
you successfully and completely implement some or all of the following
additional features:
- Implement long filename support in the directory listing. Show the long filename underneath the short name.
- Implement (read-only) FAT32 support. This will include extra data in the info command, chained directories, and support for . and .. directories.
- Implement directory creation with md.
- Implement file deletion with del.
- Implement file writing with put.
Each feature is worth up to an additional 5% of your assignment mark, if
implemented completely and correctly. In order to receive bonus marks, you
must include a README.TXT file at the top level of your handin detailing the
extra features you included.
Sample output and volumes
For now, there are a lot of FAT32 floppy images online. E.g.
http://schierlm.users.sourceforge.net/bootdisk/
(first link: Download the floppy image).
Here is an example using allinone.img:
% ./shell allinone.img
> info
Volume information for: allinone.img
Disk information:
—————–
OEM Name: mkdosfs
Volume Label:
File System Type (text): FAT12
Media Type: 0xF0 (removable)
Size: 1474560 bytes (1.47MB)
Disk geometry:
————–
Bytes Per Sector: 512
Sectors Per Cluster: 1
Total Sectors: 2880
Physical - Sectors per Track: 18
Physical - Heads: 2
File system info:
—————-
Volume ID: ALLINONE
File System Type (calculated): FAT12
FAT Size (sectors): 9
Free space: 62464 bytes
> dir
AUTOEXEC.BAT 830 A 2016/02/24 00:00:00
COMMAND.COM 68459 A 2016/02/24 00:00:00
FDCONFIG.SYS 385 A 2016/02/24 00:00:00
KERNEL.SYS 44018 A 2016/02/24 00:00:00
SHCDX33A.COM 6900 A 2016/02/24 00:00:00
VIDE-CDD.SYS 11188 A 2016/02/24 00:00:00
6 file(s) 2 dir(s)
> cd boot
> dir
<.> 2016/02/24 18:28:04
<..> 2016/02/24 18:28:04
INVADERS.MB 3020 A 2016/02/24 00:00:00
GPXE.LKR 177815 A 2016/02/24 00:00:00
MEMTEST.BIN 103328 A 2016/02/24 00:00:00
SBOOTMGR.LKR 20342 A 2016/02/24 00:00:00
MT86PLUS.BIN 111864 A 2016/02/24 00:00:00
BOOTSECT.OR 512 A 2016/02/24 00:00:00
6 file(s) 4 dir(s)
> cd grub2
> dir
<.> 2016/02/24 18:28:04
<..> 2016/02/24 18:28:04
CORE.IMG 25572 A 2016/02/24 00:00:00
ACORN.MOD 2168 A 2016/02/24 00:00:00
AFFS.MOD 4788 A 2016/02/24 00:00:00
AMIGA.MOD 2512 A 2016/02/24 00:00:00
APPLE.MOD 2596 A 2016/02/24 00:00:00
ATA.MOD 4608 A 2016/02/24 00:00:00
BIOSDISK.MOD 4048 A 2016/02/24 00:00:00
BITMAP.MOD 2512 A 2016/02/24 00:00:00
BLOCKL1.MOD 2060 A 2016/02/24 00:00:001.MOD 1816 A 2016/02/24 00:00:00
BOOT.IMG 512 A 2016/02/24 00:00:00
BOOT.MOD 1276 A 2016/02/24 00:00:00
CAT.MOD 1800 A 2016/02/24 00:00:00
CDBOOT.IMG 512 A 2016/02/24 00:00:00
_CHAIN.MOD 2332 A 2016/02/24 00:00:00
CHAIN.MOD 1640 A 2016/02/24 00:00:00
CMP.MOD 2132 A 2016/02/24 00:00:00
COMMAND.LST 621 A 2016/02/24 00:00:00
CONFIG
CPIO.MOD 2972 A 2016/02/24 00:00:00
CPUID.MOD 1504 A 2016/02/24 00:00:00
DISKBOOT.IMG 512 A 2016/02/24 00:00:00
ECHO.MOD 1916 A 2016/02/24 00:00:00
ELF.MOD 4396 A 2016/02/24 00:00:00
EXT2.MOD 4172 A 2016/02/24 00:00:00
FAT.MOD 4808 A 2016/02/24 00:00:00
FONT.MOD 2484 A 2016/02/24 00:00:00
FSHELP.MOD 2492 A 2016/02/24 00:00:00
FS.LST 75 A 2016/02/24 00:00:00
GFXTERM.MOD 8580 A 2016/02/24 00:00:00
GPT.MOD 2680 A 2016/02/24 00:00:00
GZIO.MOD 8148 A 2016/02/24 00:00:00
HALT.MOD 1452 A 2016/02/24 00:00:00
HELLO.MOD 1200 A 2016/02/24 00:00:00
HELP.MOD 1904 A 2016/02/24 00:00:00
HEXDUMP.MOD 2556 A 2016/02/24 00:00:00
HFS.MOD 6556 A 2016/02/24 00:00:00
HFSPLUS.MOD 6596 A 2016/02/24 00:00:00
ISO9660.MOD 5100 A 2016/02/24 00:00:00
JFS.MOD 5052 A 2016/02/24 00:00:00
JPEG.MOD 6032 A 2016/02/24 00:00:00
KERNEL.IMG 30200 A 2016/02/24 00:00:00
_LINUX.MOD 4768 A 2016/02/24 00:00:00
LINUX.MOD 1492 A 2016/02/24 00:00:00
LNXBOOT.IMG 1024 A 2016/02/24 00:00:00
LOOPBACK.MOD 3156 A 2016/02/24 00:00:00
LS.MOD 3748 A 2016/02/24 00:00:00
LSPCI.MOD 4068 A 2016/02/24 00:00:00
LVM.MOD 5044 A 2016/02/24 00:00:00
MEMDISK.MOD 2104 A 2016/02/24 00:00:00
MINIX.MOD 4244 A 2016/02/24 00:00:00
MODDEP.LST 904 A 2016/02/24 00:00:00
_MULTI1.MOD 11068 A 2016/02/24 00:00:001.MOD 1572 A 2016/02/24 00:00:00
MULTIB
NORMAL.MOD 41320 A 2016/02/24 00:00:00
NTFSCOMP.MOD 3424 A 2016/02/24 00:00:00
NTFS.MOD 8352 A 2016/02/24 00:00:00
PCI.MOD 856 A 2016/02/24 00:00:00
PC.MOD 3220 A 2016/02/24 00:00:00
PLAY.MOD 2080 A 2016/02/24 00:00:00
PNG.MOD 6148 A 2016/02/24 00:00:00
PXEBOOT.IMG 1024 A 2016/02/24 00:00:00
RAID.MOD 4212 A 2016/02/24 00:00:00
READ.MOD 1600 A 2016/02/24 00:00:00
REBOOT.MOD 1184 A 2016/02/24 00:00:00
REISERFS.MOD 9432 A 2016/02/24 00:00:00
SEARCH.MOD 3080 A 2016/02/24 00:00:00
SERIAL.MOD 5648 A 2016/02/24 00:00:00
SFS.MOD 4340 A 2016/02/24 00:00:00
SUN.MOD 2492 A 2016/02/24 00:00:00
TERMINAL.MOD 1792 A 2016/02/24 00:00:00
TERMINFO.MOD 6952 A 2016/02/24 00:00:00
TEST.MOD 1580 A 2016/02/24 00:00:00
TGA.MOD 2868 A 2016/02/24 00:00:00
UFS.MOD 4988 A 2016/02/24 00:00:00
VBEINFO.MOD 2112 A 2016/02/24 00:00:00
VBE.MOD 14044 A 2016/02/24 00:00:00
VBETEST.MOD 2988 A 2016/02/24 00:00:00
VGA.MOD 3868 A 2016/02/24 00:00:00
VIDEO.MOD 3988 A 2016/02/24 00:00:00
VIDEOT~1.MOD 2700 A 2016/02/24 00:00:00
XFS.MOD 7576 A 2016/02/24 00:00:00
81 file(s) 2 dir(s)
> cd ..
> cd grub
> dir
<.> 2016/02/24 18:28:04
<..> 2016/02/24 18:28:04
LICENSE.TCT 17104 A 2016/02/24 00:00:00
STAGE1 512 A 2016/02/24 00:00:00
TEMPLATE.TXT 700 A 2016/02/24 00:00:00
KEYBOARD.LST 2755 A 2016/02/24 00:00:00
TAIOBF.LST 1166 A 2016/02/24 00:00:00
COLOR.LST 818 A 2016/02/24 00:00:00
INTRO.TCT 2110 A 2016/02/24 00:00:00
KEYBOARD.TXT 497 A 2016/02/24 00:00:00
TEMPLATE.LST 2186 A 2016/02/24 00:00:00
STAGE2 100338 A 2016/02/24 00:00:00
TAIOBF.TXT 838 A 2016/02/24 00:00:00
MENU.LST 135 A 2016/02/24 00:00:00
12 file(s) 2 dir(s)
> get license.tct out.txt
Copied 17104 bytes to out.txt
> ^D
Exiting cleanly.