Академический Документы
Профессиональный Документы
Культура Документы
Purpose
File management is a central component to most applications. With the exception of perhaps real-time
applications, the input and output of an application is via a file. Files have a life outside of any individual
application and provide a medium for later access by the user or by other programs. Typically, an operating
system implements a file management system with a set of utility programs that run as privileged
applications. In this project, you will add a MS-DOS® FAT-12 file manager to your operating system that
will enable you to traverse file directories, read/write/seek file data, and execute LC-3 program files.
Project Requirements
The following are important guidelines for programming the FAT FMS assignment:
1) RAM Disk Image: A FAT-12 disk image is loaded into a RAM disk (memory array) using the shell
mount command. The RAM disk is divided into 2849 sectors, each being 512 bytes in length. The
file allocation tables (FAT1 and FAT2) are held in separate memory arrays. All memory accesses to
the RAM disk array must be made using the following read/write sector functions:
2) RAM Disk Files and Directories: A FAT-12 file system specifies how files are named, accessed,
and stored in your RAM disk image. Your program will maintain a “current directory” variable (cDir
in the task control block) which points to the start cluster of the current working directory. You must
be able to navigate hierarchal directories using the cd and dir shell commands. Short file and
directory names can be assumed to be at most 8 characters long, with an optional 1-3 character
extension (filename is separated from the extensions by a dot [.]).
4) C File Management Functions: The second part of Project Six deals with basic file I/O operations.
You will need to implement the following C functions in your File Management System: (Again, do
NOT change the API‟s.):
5) Validation: Your completed file management system must be able to pass a disk validation program
(chkdsk) and a final stress test (final). The DOS function chkdsk analyzes a FAT-12 disk and reports
any problems. (See description below.) The final program has six steps that will test various
implementations of your file manager and must be executed in order. These tests include the creation
and deletion of a large number of files and directories, opening and closing a maximum number of
files, random access within files using the read, seek, and write primitives, and testing the various
modes of opening files including read-only, write, read/write, and append.
BYU, CS 345 Project Six – FAT File Management System Page 3/10
About DOS File Names
A DOS 8.3 file name is composed of two parts: a name, which can be up to eight characters long, and an
optional extension, which can be up to three characters long. The name and extension are separated by a
period. A file name may not begin with a period. Extensions are typically not added to directory names
because it makes discerning them from filenames difficult. The extension is DOS' way of determining
which of the four basic functions a file performs: executable (.exe or .com), support (.ini, .cgf, or .dll),
data (.doc, .txt, .xls, .dbf, and .dxf), and batch (.bat).
In general, DOS filenames use only letters and numerals. Upper and lower case letters are considered
identical. In addition, the following symbols can be used in file names:
`~!@#$%^&()_-{}'
File/Directory Masks
A file name mask is used to selectively qualify directory entries. A wildcard is a special character that
can fill in for missing letter(s) in file and directory names when used to add specificity to OS commands.
Although there are various ways to define the syntax and semantics of a mask string, we will use the
following rules:
A mask has two parts, one for the file name and the other for the extension. If an extension mask is
included, it is separated from the file mask by a period.
A null file mask string qualifies all entries (regardless of extension.)
An „*‟ qualifies all characters to the right and cannot be followed by any characters (other than a
period and an extension mask.) There can be only one “*” per file name and/or extension mask.
Thus a single “*” would select all files without an extension. A “*.*” mask would be the same as a
null string and select all files with or without an extension.
A „?‟ is a wild card for any single character and requires the presence of a character in the file name
to qualify. It may be used multiple times in the file name and/or file extension mask.
BYU, CS 345 Project Six – FAT File Management System Page 4/10
Directory structure
A DOS directory entry is a 32-byte struct that contains the file name, extension, time and date of last
update, size of the file (in bytes), and the cluster number of the cluster of the file. File names follow the
8.3 naming standard. Time, date, startCluster, and fileSize are in little-endian format. The struct must be
byte aligned.
File/Directory Deletion
DOS does not immediately erase a file or directory when it is deleted. In fact, it does nothing to the
clusters that contain the information (this is why it is sometimes possible to un-delete something).
However, DOS does zero out the file/directory's cluster chain from the FAT table and places a special
character (0xe5) in the first byte of the directory entry signaling that this entry has been deleted. You will
need to do the same when a file or directory is deleted. Start with the cluster indicated in the directory
entry, traverse the cluster chain, and then set each FAT entry to zero including the EOC entry.
The special code 0xe5 in the first byte of a directory entry, indicates that this directory entry is free, and
may be overwritten with a new entry in the future. Place this value in the first byte of the directory entry
to effectively delete it (it will be the first character of the file/directory name field). When reading
directory entries, ignore all entries that begin with 0xe5.
When making any change to the FAT 1 table, copy the FAT 1 table to the FAT 2 table, EXCEPT when
deleting a file.
FMS Errors
In order to use the LC-3 file programs, we must standardize on error numbers coming from the File
Management System. As such, please use the following error definitions in your implementation:
Implementation Strategy
1. Read and comprehend the MS-DOS FAT File System help document as well as Stallings, Chapter 12.
2. Comprehend these lab specs. Discuss questions with classmates, the TA‟s and/or the professor.
Make sure you understand what the requirements are!
3. Design your file management system. Break the problem down into manageable parts.
4. A suggested implementation order might be:
a. Begin with the shell commands cd and dir. Implement the fmsChangeDir and
fmsGetNextDirEntry functions.
b. Implement fmsOpenFile, fmsReadFile, and fmsCloseFile. Verify your implement using the
type command.
c. Implement fmsWriteFile. Verify your implement using the copy command.
d. Implement fmsDefineFile, fmsDeleteFile.
BYU, CS 345 Project Six – FAT File Management System Page 6/10
e. Implement fmsSeekFile and test with LC-3 decoder programs.
f. Valid your completed FMS with the chkdsk and final programs.
1) Do the following:
Add a FAT-12 file management system to your operating system. Use an open file table, I/O
buffering, file descriptors to accommodate up to 32 open files at a time.
Change your shell prompt to display the current working directory path name.
Use the following shell commands to demonstrate your file manager: (Please ask your
instructor/TA for further clarification of arguments.)
o cd <file name/..> Change directory
o chkdsk Check disk
o copy <file1>,<file2> Copy file
o define <file> Define file
o delete <file name> Delete file
o dir {<mask>} Display files in current directory
o fat <#>,<s>,<e> Display FAT structure
o final Test file manager
o map {<mask>} Map files from current directory
o mkdir <dir name> Create directory
o mount <file name> Initialize FAT-12 RAM disk from file
o run <file name> Execute LC-3 program
o sp Display bytes used/free/bad/size
o type <file name> Display file
o unmount <file name> Write FAT-12 RAM disk to file
2) Demonstrate that your file management system is functioning correctly. Be able to traverse the
directory structure on a disk and list selected files. Be able to display file contents. Be able to copy
files, create and delete files and directories, seek, read/write, and append files, and successfully
execute LC-3 file programs from your RAM disk.
3) There are 20 points possible for Project 6. The grading criteria will be as follows:
BYU, CS 345 Project Six – FAT File Management System Page 7/10
In addition to the possible 20 points, the following bonus/penalties apply:
+2 points bonus for early pass-off (at least one day before due date.)
+2 points bonus for implementing support (cd, dir) for long file names.
+2 points bonus for implementing an undelete command.
+2 points bonus for implementing a rename command.
+2 points bonus for deleting multiple files using a file mask.
+5 points bonus for implementing your file management functions as background kernel tasks that
suspend the calling process until I/O operations complete.
-2 points penalty for each school day late.
-20 points penalty for any invalid reference to the RAM disk.
Sample Output
***NOTE: This sample may or may not reflect your results and should not be used as validation of your
FMS implementation.
CS345 F2008
0>>mount
Mount Disk "c:/lcc/projects/disk4"
System: IBM 3.3
Bytes/Sector: 512
Sectors/Cluster: 1
Reserved sectors: 1
FAT tables: 2
Max root dir entries: 224
FAT-12 sectors: 2880
FAT sectors: 9
Sectors/track: 18
Heads/volume: 2
FAT-32 sectors: 0
c:/lcc/projects/disk4:\>>final all
Running Test 1...
Define 128 directories...
Define 64 files...
Running Test 2...
Open 64 files...
Now is the time for all good men to come to the aid of their country.
Running Test 3...
Now is the time for all good men to come to the aid of their country.
Running Test 4...
Now is the time for all good men to come to the aid of their country.
Running Test 5...
fmsMakeDirectory("TESTDIR")
fmsChangeDir("TESTDIR")
Define 64 files...
fmsChangeDir("..")
fmsDeleteFile("TESTDIR") Can Not Delete... Good!
fmsChangeDir("TESTDIR")
Delete 64 files...
fmsChangeDir("..")
fmsDeleteFile("TESTDIR")
Running Test 6...
Delete 64 files...
BYU, CS 345 Project Six – FAT File Management System Page 8/10
Delete 128 directories...
Slot Name Ext Atr Size Strt Curr cDir cPID Mode Flag Indx
Name:ext time date cluster size
BIGDIR ----D- 11:31:40 03/31/2004 3 0
BYU ----D- 11:34:54 03/31/2004 171 0
JOKES ----D- 11:37:06 03/31/2004 800 0
LONGFI~1 ----D- 11:37:14 03/31/2004 875 0
PERSONAL ----D- 11:37:18 03/31/2004 937 0
TEMP ----D- 11:37:36 03/31/2004 1355 0
H2O.C -----A 19:00:02 02/12/2004 1380 3425
MAKE.TXT -----A 16:26:58 02/27/2004 1387 18584
CONGRATULATIONS! YOU PASS!
c:/lcc/projects/disk4:\>>cd byu
c:/lcc/projects/disk4:\byu>>cd cs345
c:/lcc/projects/disk4:\byu\cs345>>cd projects
c:/lcc/projects/disk4:\byu\cs345\projects>>cd p6
c:/lcc/projects/disk4:\byu\cs345\projects\p6>>run decode1.hex
c:/lcc/projects/disk4:\byu\cs345\projects\p6>>
Load "decode1.hex" from FAT
Memory loaded! PC=0x3000
Process #1 Halted at 0x313e
Exit Task 1
c:/lcc/projects/disk4:\byu\cs345\projects\p6>>dir
Name:ext time date cluster size
. ----D- 11:35:10 03/31/2004 224 0
.. ----D- 11:35:10 03/31/2004 222 0
DECODE1.HEX -----A 11:00:58 03/31/2004 225 3630
DECODE2.HEX -----A 11:02:10 03/31/2004 233 3630
DECODE3.HEX -----A 11:02:56 03/31/2004 241 3630
DECODE4.HEX -----A 11:03:44 03/31/2004 249 3630
DECODE5.HEX -----A 11:04:14 03/31/2004 257 3630
DECODE6.HEX -----A 11:04:36 03/31/2004 265 3630
DECODE7.HEX -----A 11:05:02 03/31/2004 273 3630
DECODE8.HEX -----A 11:05:26 03/31/2004 281 3630
DECODE9.HEX -----A 11:05:48 03/31/2004 289 3630
DICT.DAT -----A 13:45:30 03/22/2004 297 4600
SECRET1.DAT -----A 13:45:30 03/22/2004 306 156
SECRET2.DAT -----A 13:45:30 03/22/2004 307 966
SECRET3.DAT -----A 13:45:30 03/22/2004 309 300
SECRET4.DAT -----A 13:45:30 03/22/2004 310 1146
SECRET5.DAT -----A 13:45:30 03/22/2004 314 660
SECRET6.DAT -----A 13:45:30 03/22/2004 316 1494
SECRET7.DAT -----A 13:45:30 03/22/2004 319 492
SECRET8.DAT -----A 13:45:30 03/22/2004 320 438
SECRET9.DAT -----A 13:45:30 03/22/2004 321 282
MAP.HEX -----A 13:11:24 03/20/2004 1563 1782
CALCUL~1.HEX -----A 14:38:18 01/27/2004 1567 6174
CRAWLER.HEX -----A 17:18:00 02/02/2004 1580 1980
MEMTEST.HEX -----A 22:09:32 02/09/2004 1584 2640
MESSAGE1.TXT -----A 15:14:44 10/01/2008 2 61
c:/lcc/projects/disk4:\byu\cs345\projects\p6>>type message1.txt
Men do not fail,
but often rather,
they simply quit trying...
c:/lcc/projects/disk4:\byu\cs345\projects\p6>>final all
Running Test 1...
Define 128 directories...
Define 64 files...
Running Test 2...
Open 64 files...
Now is the time for all good men to come to the aid of their country.
BYU, CS 345 Project Six – FAT File Management System Page 9/10
Running Test 3...
Now is the time for all good men to come to the aid of their country.
Running Test 4...
Now is the time for all good men to come to the aid of their country.
Running Test 5...
fmsMakeDirectory("TESTDIR")
fmsChangeDir("TESTDIR")
Define 64 files...
fmsChangeDir("..")
fmsDeleteFile("TESTDIR") Can Not Delete... Good!
fmsChangeDir("TESTDIR")
Delete 64 files...
fmsChangeDir("..")
fmsDeleteFile("TESTDIR")
Running Test 6...
Delete 64 files...
Delete 128 directories...
Slot Name Ext Atr Size Strt Curr cDir cPID Mode Flag Indx
Name:ext time date cluster size
. ----D- 11:35:10 03/31/2004 224 0
.. ----D- 11:35:10 03/31/2004 222 0
DECODE1.HEX -----A 11:00:58 03/31/2004 225 3630
DECODE2.HEX -----A 11:02:10 03/31/2004 233 3630
DECODE3.HEX -----A 11:02:56 03/31/2004 241 3630
DECODE4.HEX -----A 11:03:44 03/31/2004 249 3630
DECODE5.HEX -----A 11:04:14 03/31/2004 257 3630
DECODE6.HEX -----A 11:04:36 03/31/2004 265 3630
DECODE7.HEX -----A 11:05:02 03/31/2004 273 3630
DECODE8.HEX -----A 11:05:26 03/31/2004 281 3630
DECODE9.HEX -----A 11:05:48 03/31/2004 289 3630
DICT.DAT -----A 13:45:30 03/22/2004 297 4600
SECRET1.DAT -----A 13:45:30 03/22/2004 306 156
SECRET2.DAT -----A 13:45:30 03/22/2004 307 966
SECRET3.DAT -----A 13:45:30 03/22/2004 309 300
SECRET4.DAT -----A 13:45:30 03/22/2004 310 1146
SECRET5.DAT -----A 13:45:30 03/22/2004 314 660
SECRET6.DAT -----A 13:45:30 03/22/2004 316 1494
SECRET7.DAT -----A 13:45:30 03/22/2004 319 492
SECRET8.DAT -----A 13:45:30 03/22/2004 320 438
SECRET9.DAT -----A 13:45:30 03/22/2004 321 282
MAP.HEX -----A 13:11:24 03/20/2004 1563 1782
CALCUL~1.HEX -----A 14:38:18 01/27/2004 1567 6174
CRAWLER.HEX -----A 17:18:00 02/02/2004 1580 1980
MEMTEST.HEX -----A 22:09:32 02/09/2004 1584 2640
MESSAGE1.TXT -----A 15:14:44 10/01/2008 2 61
CONGRATULATIONS! YOU PASS!
c:/lcc/projects/disk4:\byu\cs345\projects\p6>>
BYU, CS 345 Project Six – FAT File Management System Page 10/10