Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
70 changes: 35 additions & 35 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ Virtual FAT32 disk
~~~
git clone git@github.com:Travelinglight/VHD.git
~~~
2. Use Windows to generate a .vhd file.
2. use Windows to generate a .vhd file.
* the format should be FunAT32
* the filesize should not be too large, 20MB is recommended
* the number of bytes per block is recommended to be 512
Expand All @@ -29,10 +29,10 @@ Virtual FAT32 disk
~~~
./VHD
~~~
type "help" for instructions list
use "-help" for the instruction list

## Things you can do
1. list out the file list, with detailed infomation
1. list out the file list, with detailed information
2. remove a file from the VHD
3. copy a file from the VHD to the outside
4. move a file from outside into the VHD
Expand All @@ -54,53 +54,53 @@ Virtual FAT32 disk
## Functions Specification
### Important functions
1. <b>init</b>
1. read parameters from boot block
2. read the whole FAT
3. read root directory and initialize the fIndex array
* read parameters from boot block
* read the whole FAT
* read root directory and initialize the fIndex array
2. <b>ls: list file infomation</b>
1. list the file id, file name, attribute, timestamp, and file size for each file in the fIndex
* list the file id, file name, attribute, timestamp, and file size for each file in the fIndex
3. <b>cp: copy a file from vhd to outside</b>
1. generate the filename of the outside file, and open it
2. read data area according to the FAT, write the destination file block by block
* generate the filename of the outside file, and open it
* read data area according to the FAT, write the destination file block by block
4. <b>rm: remove a file from VHD</b>
1. clear the FAT chain (reset those half_word in FAT describing the clusters of the file to 0)
2. put 0xE5 to the first byte of the filename in root directory
3. free and clear the file struct in the fIndex array
* clear the FAT chain (reset those half_word in FAT describing the clusters of the file to 0)
* put 0xE5 to the first byte of the filename in root directory
* free and clear the file struct in the fIndex array
5. <b>mv: move a file from outside into the VHD</b>
1. parse the filename and file_extention
2. get the file size
3. find and clear enough clusters that are not used, and record them in an array
4. obtain other necessary attributes describing a file
5. modify root directory with the attributes obtained before
6. modify FAT according to the clusters array found out before
7. read binary data from source file, and write them into the clusters found before, byte by byte
* parse the filename and file_extension
* get the file size
* find and clear enough clusters that are not used, and record them in an array
* obtain other necessary attributes describing a file
* modify root directory with the attributes obtained before
* modify FAT according to the clusters array found out before
* read binary data from source file, and write them into the clusters found before, byte by byte

### Complementary functions
1. readBlock: to read a block from .vhd file into buff_block
2. readByte: to read and return a byte from .vhd file
3. readHWord: to read and return a half_word from .vhd file. This function calls:
1. readByte;
* readByte;
4. readWord: to read and return a word from .vhd file. This function calls:
1. readHWord;
* readHWord;
5. readFAT: to read the while FAT from .vhd file into FAT
6. raedFileName: to read the filename from .vhd file, format it and handle special cases. This function calls:
1. readByte;
7. readFileExt: to read the file extention from .vhd file and format it. This function calls:
1. readByte;
* readByte;
7. readFileExt: to read the file extension from .vhd file and format it. This function calls:
* readByte;
8. readAttr: to read the attribute of a file from .vhd file. This function calls:
* readByte;
* readByte;
9. readFileTimeStamp: to read the time and date of the file from root directory in .vhd file. This function calls:
* readHWord;
* readHWord;
10. readFileStart: to read the id of start cluster of the file from .vhd file. This function calls:
* readHWord;
* readHWord;
11. readFileSize: to read the file size from the root directory in .vhd file. This function calls:
* readHWord;
* readHWord;
12. readRD: to read the info of all files. This function calls:
1. readFileExt;
2. readFileAttr;
3. readFileTimeStamp;
4. readFileStart;
5. readFileSize;
* readFileExt;
* readFileAttr;
* readFileTimeStamp;
* readFileStart;
* readFileSize;
13. printFileName: to print the filename in normal way
14. printFileAttr: to print the file attribute in binary format
15. printFileTime: to print the time of the file vividly
Expand All @@ -111,6 +111,6 @@ Virtual FAT32 disk
20. writeTime: to write the time and date into the root directory in .vhd file

## Bugs exist
1. After a .txt file is written into .vhd file, there would be an extra half_word (0x0AFF) appended to the original file.
2. The file of 2 bytes would become 512 bytes after being written into and extracted out from VHD.
1. After a .txt file is written into .vhd file, an extra half_word (0x0AFF) should be appended to the original file.
2. A 2-byte file would become 512-byte after being written into and extracted out from VHD.
3. Some constants are used in the program, so the program may not be universal to all FAT32 VHDs.