microsoft file system - access ic lab (prof. an-yeu (andy
TRANSCRIPT
ACCESS IC LAB
Graduate Institute of Electronics Engineering, NTU
Microsoft File SystemMicrosoft File System
Instructor: Chia-Tsun Wu.11/25/2004
ACCESS IC LAB Graduate Institute of Electronics Engineering, NTU
P2
OutlineOutline
Types of File SystemPrinciples of File SystemMicrosoft File System
General CommentsBoot Sector and BPBBoot Sector and BPB StructureFAT Data Structure
LAB
ACCESS IC LAB Graduate Institute of Electronics Engineering, NTU
P3
Types of Types of FileSystemFileSystem
DOS FAT 12/16/32, VFATHigh Performance FileSystem (HPFS)New Technology FileSystem (NTFS)Extended filesystems (Ext, Ext2, Ext3)Macintosh Hierarchical Filesystem - HFSISO 9660 - CD-ROM filesystem
ACCESS IC LAB Graduate Institute of Electronics Engineering, NTU
P4
Other Other filesystemsfilesystemsADFS - Acorn Disc File System AFFS - Amiga fast filesystemBeFS - BeOS filesystemBFS - UnixWare Boot FilesystemCrosStor filesystemDTFS - Desktop filesystemEFS - Enhanced filesystem (Linux) EFS - Extent filesystem (IRIX) FFS - BSD Fast filesystemGPFS - General Parallel FilesystemHFS - HP-UX Hi performance filesystemHTFS - High throughput filesystemLFS - Linux log structured filesystemJFS - Journaled filesystem (HP-UX, AIX, OS/2 5, Linux) MFS - Macintosh filesystemMinix filesystemNWFS - Novell NetWare filesystem
NSS - Novell Storage Services ODS - On Disk Structure filesystemQNX filesystemReiser filesystemRFS (CD-ROM Filesystem) RomFS - Rom filesystemSFS - Secure filesystemSpiralog filesystem (OpenVMS) System V and derived filesystemsText - (Philips' CD-ROM Filesystem) UDF - Universal Disk Format (DVD-ROM filesystem) UFS V7 FilesystemVxFS - Veritas filesystem (HP-UX, SCO UnixWare, Solaris) XFS - Extended filesystem (IRIX) Xia FS
ACCESS IC LAB
Graduate Institute of Electronics Engineering, NTU
FileFile--System StructureSystem Structure
ACCESS IC LAB Graduate Institute of Electronics Engineering, NTU
P6
IntroductionIntroduction
File structureLogical storage unitCollection of related information
File system resides on secondary storage (disks)File system organized into layersFile control block storage structure consisting of information about a file
Ownership, permissions, and location of the file content
I/O transfers between memory and disk are performed in units of blocks (one more more sectors)
ACCESS IC LAB Graduate Institute of Electronics Engineering, NTU
P7
Layered File SystemLayered File System
ACCESS IC LAB Graduate Institute of Electronics Engineering, NTU
P8
Layered File System (Cont.)Layered File System (Cont.)
I/O control device drivers and interrupt handlers
Transfer information between main memory and disk systemRetrieve block 123 HW-specific instructions
Basic file systemIssue generic commands to device driver to read and write physical blocks on the diskPhysical block: drive 1, cylinder 73, track 2, sector 10
ACCESS IC LAB Graduate Institute of Electronics Engineering, NTU
P9
Layered File System (Cont.)Layered File System (Cont.)
File-organization moduleKnow about files, their logical blocks, and physical blocksTranslate logical blocks to physical blocks (similar to VM)
Logical blocks: 0 N
Free-space managerBlocks allocation
Logical file system manage metadata informationMetadata: file-system structure, excluding the actual file contentsManage the directory structure via file control blocks (FCB)
ACCESS IC LAB Graduate Institute of Electronics Engineering, NTU
P10
Layered File System (Cont.)Layered File System (Cont.)
Why Layered file system?All the advantages of the layered approachFile system standard: UFS, FAT FAT32, NTFSDuplication of code is minimized for different file system standardUsually I/O control and the basic file system code can be used by multiple file system formats.
ACCESS IC LAB
Graduate Institute of Electronics Engineering, NTU
File System ImplementationFile System Implementation
ACCESS IC LAB Graduate Institute of Electronics Engineering, NTU
P13
OnOn--Disk StructuresDisk Structures
Boot control block: information needed by the system to boot an OS from that partition
UFS: boot block; NTFS: partition boot sector
Partition control block: partition detailsNo. of blocks, size of the blocks, free-block count and free-block pointers, free FCB count and FCB pointersUFS: superblock; NTFS: Master File Table
A directory structure is used to organize the filesFile control block: many of the file s details
File permissions, ownership, size, location of the data blocksUFS: inode; NTFS: within the Master File Table
ACCESS IC LAB Graduate Institute of Electronics Engineering, NTU
P14
InIn--Memory StructuresMemory Structures
An in-memory partition table containing information about each mounted partitionAn in-memory directory structure that holds the directory information of recently accessed directoriesThe system-wide open-file table (Chapter 11)The per-process open-file table (Chapter 11)
Caching information so that no need to retrieve the information every time from the disk
ACCESS IC LAB Graduate Institute of Electronics Engineering, NTU
P15
InIn--Memory FileMemory File--System StructuresSystem Structures
File Open
File Read
ACCESS IC LAB Graduate Institute of Electronics Engineering, NTU
P16
Virtual File SystemsVirtual File Systems
Virtual File Systems (VFS) provide an object-oriented way of implementing file systemsVFS separates file-system-generic operations from their implementation by defining a clean VFS interfaceVFS allows the same system call interface (the API) to be used for different types of file systemsVFS is based on a file-representation structure, called a vnode, that contains a numerical designator for a network-wide unique fileThe API is to the VFS interface, rather than any specific type of file system
ACCESS IC LAB Graduate Institute of Electronics Engineering, NTU
P17
Schematic View of Virtual File SystemSchematic View of Virtual File SystemOpen, read, write
ACCESS IC LAB Graduate Institute of Electronics Engineering, NTU
P18
Directory ImplementationDirectory Implementation
Linear list of file names with pointer to the data blocksSimple to programTime-consuming to execute linear search to find a particular entry
Cache and sorted list may help
Hash Table linear list with hash data structureDecreases directory search timeCollisions situations where two file names hash to the same locationFixed size and the dependence of the hash function on that size
ACCESS IC LAB
Graduate Institute of Electronics Engineering, NTU
Allocation MethodsAllocation Methods
How to allocate space to files so that disk space is utilized effectively and files can be accessed quickly
ACCESS IC LAB Graduate Institute of Electronics Engineering, NTU
P20
Contiguous AllocationContiguous Allocation
A file occupies a set of contiguous blocks on diskOnly starting block (block #) and length (number of blocks) are required in the directory entry (FCB)Fast -- Minimal seek time and head movementRandom access any block within the fileSimilar to dynamic storage-allocation problem
External fragmentation may need compaction
Files are difficult to growFind a larger hole and copy the file to the new space
ACCESS IC LAB Graduate Institute of Electronics Engineering, NTU
P21
Contiguous Allocation (Cont.)Contiguous Allocation (Cont.)
ACCESS IC LAB Graduate Institute of Electronics Engineering, NTU
P22
ExtentExtent--Based SystemsBased Systems
Many newer file systems (I.e. Veritas File System) use a modified contiguous allocation schemeExtent-based file systems allocate disk blocks in extentsAn extent is a contiguous block of disks. Extents are allocated for file allocation. A file consists of one or more extents. Integrate contiguous allocation and linked allocation (see later)
ACCESS IC LAB Graduate Institute of Electronics Engineering, NTU
P23
Linked AllocationLinked Allocation
Each file is a linked list of disk blocksBlocks may be scattered anywhere on the diskDirectory contains a pointer to the first and last blocksEach block contains a pointer to the next block
AdvantagesNo external fragmentationEasy to grow Any free block is OK
DisadvantagesEffectively for only sequential-access fileSpace required for the pointersReliability What if the pointers are lost
ACCESS IC LAB Graduate Institute of Electronics Engineering, NTU
P24
Linked Allocation (Cont.)Linked Allocation (Cont.)
pointer
data
block =
ACCESS IC LAB Graduate Institute of Electronics Engineering, NTU
P25
Linked Allocation (Cont.)Linked Allocation (Cont.)
Solution for spaces for pointersCollect blocks into clusters, and allocate the clusters than blocks ( Allocate Cluster, Block)Fewer disk head seeks and decreases the space needed for block allocation and free-list managementInternal fragmentation
Solution for reliabilityDouble linked list or store the filename and relative block number in each block
More overhead for each file
ACCESS IC LAB Graduate Institute of Electronics Engineering, NTU
P26
Linked Allocation (Cont.)Linked Allocation (Cont.)FAT (File Allocation Table)
OS/2, MS-DOSThe table has one entry for each disk block and is indexed by block number
Similar to the linked list
Contain the block number of the next block in the file
Significant number of disk head seeks
One for FAT, one for dataImproved by caching FATRandom access time is improved
PointerFAT
Data Block
ACCESS IC LAB Graduate Institute of Electronics Engineering, NTU
P27
Indexed AllocationIndexed Allocation
Bring all pointers together into the index blockAn array of disk-block addressesThe ith entry points to the ith block of the fileThe directory contains the address of the index blockSimilar to the paging scheme for memory management
ACCESS IC LAB Graduate Institute of Electronics Engineering, NTU
P28
Example of Indexed AllocationExample of Indexed Allocation
ACCESS IC LAB Graduate Institute of Electronics Engineering, NTU
P29
Indexed Allocation (Cont.)Indexed Allocation (Cont.)
AdvantageSupport random accessDynamic access without external fragmentationNo size-declaration problemBut have overhead of index block. Need index table
DisadvantageWasted space: Worse than the linked allocation for small files
How large the index block should beLarge index block: waste space for small filesSmall index block: how to handle large files
ACCESS IC LAB Graduate Institute of Electronics Engineering, NTU
P30
Indexed Allocation (Cont.)Indexed Allocation (Cont.)
Mechanism for handling the index blockLinked scheme: Link together several index blocksMultilevel index: like multi-level paging
With 4096-byte blocks, we could store 1024 4-byte pointers in an index block. Two levels of indexes allows 1,048,576 data blocks, which allow a file of up to 4 gigabytes
Combined scheme: For example BSD UNIX System
ACCESS IC LAB Graduate Institute of Electronics Engineering, NTU
P31
Indexed Allocation Indexed Allocation Multilevel Multilevel Index (Cont.)Index (Cont.)
ACCESS IC LAB Graduate Institute of Electronics Engineering, NTU
P32
Combined Scheme: UNIX (4K Combined Scheme: UNIX (4K bytes per block)bytes per block)
The UNIX inode
How large can a file be, if each pointer in the index blocks is 4-bytes?
ACCESS IC LAB
Graduate Institute of Electronics Engineering, NTU
Free Space ManagementFree Space Management
ACCESS IC LAB Graduate Institute of Electronics Engineering, NTU
P34
Bit VectorBit VectorSimple and efficient to find the first free block, or consecutive free blocks
By bit-manipulation
Requires extra spaceblock size = 212 bytes
disk size = 230 bytesn = 230/212 = 218 bits (or 32K bytes)
Efficient only when the entire vector is kept in main memory
Write back to the disk occasionally for recovery needs
001111001111100011000011100
0 1 2 n-1
bit[i] =0 block[i] free
1 block[i] occupied
Question: What s the block # of the fist free block?
ACCESS IC LAB Graduate Institute of Electronics Engineering, NTU
P35
Linked ListLinked List
Link together all free blocksKeep a pointer to the first free block in a special location on the disk and caching it in memoryCannot get contiguous space easilyNo waste of spaceNot efficient: have to traverse the disk for free spaces
Usually, OS needs one free block at a time
FAT incorporate the linked list mechanism
ACCESS IC LAB Graduate Institute of Electronics Engineering, NTU
P36
Grouping And CountingGrouping And Counting
Grouping: store the address of n free blocks in the first free block. The first n-1 are actually free. The final block contains the addresses of another n free blocksCounting: Each entry has a disk address and a count
Several contiguous blocks may be allocated or freed simultaneously
ACCESS IC LAB Graduate Institute of Electronics Engineering, NTU
P37
Example Of FreeExample Of Free--Space ManagementSpace ManagementBit Vector
11000011000000111001111110001111
Counting 2 48 617 225 3
GroupingBlock 2 3, 4, 5Block 5 8, 9, 10Block 10 11, 12, 13Block 13 17, 28, 25Block 25 26, 27
ACCESS IC LAB
Graduate Institute of Electronics Engineering, NTU
Efficiency and PerformanceEfficiency and Performance
ACCESS IC LAB Graduate Institute of Electronics Engineering, NTU
P39
Efficiency and PerformanceEfficiency and Performance
Efficiency dependent onDisk allocation and directory algorithmsTypes of data kept in file s directory entry
PerformanceOn-board cache local memory in disk controller to store entire tracks at a timeDisk cache separate section of main memory for frequently used blocks (LRU is a reasonable algorithm for block replacement)Free-behind and read-ahead techniques to optimize sequential access (optimize the disk cache s block replacement algorithm)Improve PC performance by dedicating section of memory as virtual disk, or RAM disk.
ACCESS IC LAB Graduate Institute of Electronics Engineering, NTU
P40
Various DiskVarious Disk--Caching LocationsCaching Locations
ACCESS IC LAB Graduate Institute of Electronics Engineering, NTU
P41
Page CachePage Cache
Non-unified buffer cacheA page cache caches pages rather than disk blocks using virtual memory techniquesMemory-mapped I/O uses a page cacheRoutine I/O through the file system uses the buffer (disk) cache
Unified Buffer CacheA unified buffer cache uses the same buffer cache to cache both memory-mapped pages and ordinary file system I/O
ACCESS IC LAB Graduate Institute of Electronics Engineering, NTU
P42
I/O Without/With A Unified Buffer CacheI/O Without/With A Unified Buffer Cache
ACCESS IC LAB Graduate Institute of Electronics Engineering, NTU
P43
RecoveryRecovery
Consistency checker compares data in directory structure with data blocks on disk, and tries to fix inconsistenciesUse system programs to back up data from disk to another storage device (floppy disk, magnetic tape)Recover lost file or disk by restoring data from backup
ACCESS IC LAB Graduate Institute of Electronics Engineering, NTU
P44
Log Structured File SystemsLog Structured File Systems
Log structured (or journaling) file systems record each update to the file system as a transactionAll transactions are written to a log. A transaction is considered committed once it is written to the logHowever, the file system may not yet be updatedThe transactions in the log are asynchronously written to the file system. When the file system is modified, the transaction is removed from the logIf the file system crashes, all remaining transactions in the log must still be performed
ACCESS IC LAB
Graduate Institute of Electronics Engineering, NTU
Microsoft File SystemMicrosoft File System
ACCESS IC LAB Graduate Institute of Electronics Engineering, NTU
P46
General CommentsGeneral Comments
FAT file system on disk data structure is all little endianyou will have to translate if your machine is a big endian machineA FAT file system volume is composed of four basic regions, which are laid out in this order on the volume:
0 Reserved Region1 FAT Region2 Root Directory Region (doesn t exist on FAT32 volumes)3 File and Directory Data Region
ACCESS IC LAB Graduate Institute of Electronics Engineering, NTU
P47
BPB (BIOS Parameter Block), which is located in the first sector of the volume in the Reserved Region. AKA boot sector or the reserved sector or the 0th sector,There is no BPB in MS-DOS 1.XThe BPB in the boot sector defined for MS-DOS 2.x (FAT 16) FAT16 volume with strictly less than 65,536 sectors (32 MB worth of 512-byte sectors).FAT32 was defined by MS-DOS 3.x, where the BPB was modified to include a new 32-bit field for the total sectors value.Win95 OSR2
ACCESS IC LAB Graduate Institute of Electronics Engineering, NTU
P48
struct BootSector{
u8 BS_jmpBoot[3]; //long jump instructionu8 BS_OEMName[8]; //name of OEMu16 BPB_BytsPerSec; //512,1024,2048,4096u8 BPB_SecPerClus; //1,2,4,8,16,32,64,128u16 BPB_RsvdSecCnt; //reserved sector after BPBu8 BPB_NumFATs; //2u16 BPB_RootEntCnt; //the count of 32-byte directory entries in the root directoryu16 BPB_TotSec16; //total size in this volume (FAT 16)u8 BPB_Media; //media typeu16 BPB_FATsz; //number of sectorsu16 BPB_SecPerTrk; //Sectors per track for interrupt 0x13u16 BPB_NumHeads; //Number of heads for interrupt 0x13u32 BPB_HiddSec; //Count of hidden sectorsu32 BPB_TotSec32; //total size in this volume (FAT 32)
} ;
ACCESS IC LAB Graduate Institute of Electronics Engineering, NTU
P49
Fat12 and Fat16 Structure Starting at Offset 36
struct Fat12_16{
u8 BS_DrvNum; //device numberu8 BS_Reserved1; //reservedu8 BS_BootSig; //Extended boot signatureu32 BS_VolID; //serial IDu8 BS_VolLab[11]; //Volume label.u8 BS_FilSysType[8] //FAT12/FAT16/FAT
};
ACCESS IC LAB Graduate Institute of Electronics Engineering, NTU
P50
FAT32 Structure Starting at Offset 36Struct Fat32{
u32 BPB_FATSz32; //count of sectorsu16 BPB_ExtFlags;u8 BPB_FSVer[2]; //file system versionu32 BPB_RootClus; //root cluster (directory)u16 BPB_FSInfo; //file system informationu16 BPB_BkBootSec; //back up boot sectoru8 BPB_Reserved[12]; //reservedu8 BS_DrvNum; //driver numberu8 BS_Reserved1; //reservedu8 BS_BootSig; //Extended boot signatureu32 BS_VolID; //volume serial numberu8 BS_VolLab[11]; //volume labelu8 BS_FilSysType[8]; //file system type ( FAT32 )
};
ACCESS IC LAB Graduate Institute of Electronics Engineering, NTU
P51
File Allocation Table (FAT) is a linking list to a stored fileThe FAT maps the data region of the volume by cluster numberThe first data cluster is cluster 2.RootDirSectors = ((BPB_RootEntCnt * 32) + (BPB_BytsPerSec 1)) / BPB_BytsPerSec;The start of the data region, the first sector of cluster 2:
If(BPB_FATSz16 != 0)FATSz = BPB_FATSz16;
ElseFATSz = BPB_FATSz32;
FirstDataSector = BPB_ResvdSecCnt + (BPB_NumFATs * FATSz) + RootDirSectors;
ACCESS IC LAB Graduate Institute of Electronics Engineering, NTU
P52
FAT32 FSInfo Sector Structure and Backup Boot Sector
Data structure on FAT12/16/32On a FAT32 volume, the FAT can be a large data structureOn FAT16 where it is limited to a maximum of 128K worth of sectorsOn FAT12 where it is limited to a maximum of 6K worth of sectors. A provision is made to store the last known free cluster count on the FAT32 volume.
The FSInfo sector number is the value in the BPB_FSInfo field;For Microsoft operating systems it is always set to 1. Here is the structure of the FSInfo sector:
ACCESS IC LAB Graduate Institute of Electronics Engineering, NTU
P53
struct FSInfo{
u64 FSI_LeadSig; //FSInfo header = 0x41615252u8 FSI_Reserved1[480]; //reserved (should not be used)u64 FSI_StrucSig; //structure header = 0x61417272.u64 FSI_Free_Count; //free cluster countu64 FSI_Nxt_Free; //next free cluster pointeru8 FSI_Reserved2[12]; //reserved (should not be used)u64 FSI_TrailSig; //0xAA550000 to valid FSsector
};
ACCESS IC LAB Graduate Institute of Electronics Engineering, NTU
P54
FAT32 FSInfo Sector Structure and Backup Boot Sector
The Microsoft FAT32 boot sector is actually three 512-byte sectors long. There is a copy of all three of these sectors starting at the BPB_BkBootSec sector. BPB_BkBootSec sector is a complete boot record include FSInfo sector.BPB_BkBootSec is not present on FAT16/FAT12.FAT16/FAT12 volumes can be totally lost if the contents of sector 0 of the volume are overwritten or sector 0 goes bad and cannot be read.The BPB_BkBootSec field reduces the severity of this problem for FAT32 on no value other than sector 6 When the sector 0 information has been accidentally overwritten, all a disk repair utility has to do is restore the boot sector(s) from the backup copy.When sector 0 goes bad, this allows the volume to be mounted so that the user can access data before replacing the disk.When sector 0 goes bad, check for backup boot sector(s) starting at sector 6 of the FAT32 volume.
NOTE: All 3 of these sectors have the 0xAA55 signature in sector offsets 510 and 511, just like the first boot sector does
ACCESS IC LAB Graduate Institute of Electronics Engineering, NTU
P55
A FAT directory is a file composed of a linear list of 32-byte structures.The root directory must always be present.For FAT12 and FAT16 media, the root directory is located in a fixed location on the disk immediately following the last FAT and is of a fixed size in sectors computed from the BPB_RootEntCnt value .For FAT12 and FAT16 media, the first sector of the root directory is sector number relative to the first sector of the FAT volume:
FirstRootDirSecNum = BPB_ResvdSecCnt + (BPB_NumFATs * BPB_FATSz16);For FAT32, the root directory can be of variable size and is a cluster chain, just like any other directory is.The first cluster of the root directory on a FAT32 volume is stored in BPB_RootClus.Unlike other directories, the root directory itself on any FAT type does not have any date or time stamps, does not have a file name (other than the implied file name \ ), and does not contain . and .. files as the first two directory entries in the directory.The only other special aspect of the root directory is that it is the only directory on the FAT volume for which it is valid to have a file that has only the ATTR_VOLUME_ID attribute bit set (see below).
ACCESS IC LAB Graduate Institute of Electronics Engineering, NTU
P56
FAT 32 Byte Directory Entry Structurestruct DirectoryEntryStruct{
u8 DIR_Name[11]; //directory nameu8 DIR_Attr; //file attribute
//ATTR_READ_ONLY 0x01//ATTR_HIDDEN 0x02//ATTR_SYSTEM 0x04//ATTR_VOLUME_ID 0x08//ATTR_DIRECTORY 0x10//ATTR_ARCHIVE 0x20//ATTR_LONG_NAME // ATTR_READ_ONLY |// ATTR_HIDDEN | ATTR_SYSTEM |// ATTR_VOLUME_ID
u8 DIR_NTRes; //reversed for NTu8 DIR_CrtTimeTenth; //create time tenth to DIR_CrtTimeu16 DIR_CrtTime; // create time of 2 secondsu16 DIR_CrtDate; //create dateu16 DIR_LstAccDate; //last access dateu16 DIR_FstClusHI; //High word of this entry s first cluster numberu16 DIR_WrtTime; //last write timeu16 DIR_WrtDate; //last write dateu16 DIR_FstClusLO; //Low word of this entry s first cluster numberu32 DIR_FileSize; //file size in bytes
};
ACCESS IC LAB Graduate Institute of Electronics Engineering, NTU
P57
Directory NameDirectory NameSpecial notes about the first byte (DIR_Name[0]) of a FAT directory entry:
If DIR_Name[0] == 0xE5, then the directory entry is free (there is no file or directory name in this entry).If DIR_Name[0] == 0x00, then the directory entry is free (same as for 0xE5), and there are no allocated directory entries after this one (all of the DIR_Name[0] bytes in all of the entries after this one are also set to 0).The special 0 value, rather than the 0xE5 value, indicates to FAT file system driver code that the rest of the entries in this directory do not need to be examined because they are all free.If DIR_Name[0] == 0x05, then the actual file name character for this byte is 0xE5. 0xE5 is actually a valid KANJI lead byte value for the character set used in Japan.The special 0x05 value is used so that this special file name case for Japan can be handled properly and not cause FAT file system code to think that the entry is free.
The DIR_Name field is actually broken into two parts+ the 8-character main part of the name, and the 3-character extension.These two parts are trailing space padded with bytes of 0x20.DIR_Name[0] may not equal 0x20.Lower case characters are not allowed in DIR_NameThe following characters are not legal in any bytes of DIR_Name:
Values less than 0x20 except for the special case of 0x05 in DIR_Name[0] described above.0x22, 0x2A, 0x2B, 0x2C, 0x2E, 0x2F, 0x3A, 0x3B, 0x3C, 0x3D, 0x3E, 0x3F, 0x5B, 0x5C, 0x5D, and 0x7C.
ACCESS IC LAB Graduate Institute of Electronics Engineering, NTU
P58
Directory NameDirectory NameATTR_VOLUME_ID There should only be one file on the volume that has this attribute set, and that file must be in the root directory.DIR_FstClusHI and DIR_FstClusLO must always be 0 for the volume label (no data clusters are allocated to the volume label file).When a directory is created, a file with the ATTR_DIRECTORY bit set in its DIR_Attr field, you set its DIR_FileSize to 0. DIR_FileSize is not used and is always 0 on a file with the ATTR_DIRECTORY attribute(directories are sized by simply following their cluster chains to the EOC mark). One cluster is allocated to the directory (unless it is the root directory on a FAT16/FAT12 volume), and you set DIR_FstClusLO and DIR_FstClusHI to that cluster number and place an EOC mark in that clusters entry in the FAT. Next, you initialize all bytes of that cluster to 0. If the directory is the root directory, you are done (there are no dot or dotdot entries in the root directory).
ACCESS IC LAB Graduate Institute of Electronics Engineering, NTU
P59
Directory NameDirectory NameIf the directory is not the root directory, you need to create two special entries in
the first two 32-byte FAT directory entries of the directory (the first two 32 byte entries in the data region of the cluster you just allocated).
The first directory entry has DIR_Name set to: . The second has DIR_Name set to: ..
These are called the dot and dotdot entries. The DIR_FileSize field on both entries is set to 0, and all of the date and time fields in both of these entries are set to the same values as they were in the directory entry for the directory that you just created.You now set DIR_FstClusLO and DIR_FstClusHI for the dot entry (the first entry) to the same values you put in those fields for the directories directory entry (the cluster number of the cluster that contains the dot and dotdot entries).Finally, you set DIR_FstClusLO and DIR_FstClusHI for the dotdot entry (the second entry) to the first cluster number of the directory in which you just created the directory (value is 0 if this directory is the root directory even for FAT32 volumes).Here is the summary for the dot and dotdot entries:
The dot entry is a directory that points to itself.The dotdot entry points to the starting cluster of the parent of this directory (which is 0 if this directories parent is the root directory).
ACCESS IC LAB Graduate Institute of Electronics Engineering, NTU
P60
Date and Time FormatsMany FAT file systems do not support Date/Time other than DIR_WrtTime and DIR_WrtDate.For this reason, DIR_CrtTimeMil, DIR_CrtTime, DIR_CrtDate, and DIR_LstAccDate are actually optional fields.DIR_WrtTime and DIR_WrtDate must be supported.Set to 0 If the other date and time fields are not supportedDate Format.
A FAT directory entry date stamp is a 16-bit field that is basically a date relative to the MS-DOS epoch of 01/01/1980. Here is the
Bits 0 4: Day of month, valid value range 1-31 inclusive.Bits 5 8: Month of year, 1 = January, valid value range 1 12 inclusive.Bits 9 15: Count of years from 1980, valid value range 0 127 inclusive (1980 2107).
Time Format. A FAT directory entry time stamp is a 16-bit field that has a granularity of 2 seconds.Here is the format:
Bits 0 4: 2-second count, valid value range 0 29 inclusive (0 58 seconds).Bits 5 10: Minutes, valid value range 0 59 inclusive.Bits 11 15: Hours, valid value range 0 23 inclusive.
The valid time range is from Midnight 00:00:00 to 23:59:58.
ACCESS IC LAB Graduate Institute of Electronics Engineering, NTU
P61
LabLab
Create a Virtual Disk form SDRAMCreate a Boot Sector on Virtual DiskCreate two FATs and one Directory on Virtual Disk which should be compatible to Microsoft File System FAT32Provide Delete, Create, Write, Read functions to Virtual disk for next Lab usage