Microsoft File System Microsoft File System Instructor: Chia-Tsun - - PowerPoint PPT Presentation

microsoft file system microsoft file system
SMART_READER_LITE
LIVE PREVIEW

Microsoft File System Microsoft File System Instructor: Chia-Tsun - - PowerPoint PPT Presentation

Graduate Institute of Electronics Engineering, NTU Microsoft File System Microsoft File System Instructor: Chia-Tsun Wu. 11/25/2004 ACCESS IC LAB ACCESS IC LAB Graduate Institute of Electronics Engineering, NTU Outline Outline Types of


slide-1
SLIDE 1

ACCESS IC LAB

Graduate Institute of Electronics Engineering, NTU

Microsoft File System Microsoft File System

Instructor: Chia-Tsun Wu. 11/25/2004

slide-2
SLIDE 2

ACCESS IC LAB

Graduate Institute of Electronics Engineering, NTU

P2

Outline Outline

Types of File System Principles of File System Microsoft File System

General Comments Boot Sector and BPB Boot Sector and BPB Structure FAT Data Structure

LAB

slide-3
SLIDE 3

ACCESS IC LAB

Graduate Institute of Electronics Engineering, NTU

P3

Types of Types of FileSystem FileSystem

DOS FAT 12/16/32, VFAT High Performance FileSystem (HPFS) New Technology FileSystem (NTFS) Extended filesystems (Ext, Ext2, Ext3) Macintosh Hierarchical Filesystem - HFS ISO 9660 - CD-ROM filesystem

slide-4
SLIDE 4

ACCESS IC LAB

Graduate Institute of Electronics Engineering, NTU

P4

Other Other filesystems filesystems

ADFS - Acorn Disc File System AFFS - Amiga fast filesystem BeFS - BeOS filesystem BFS - UnixWare Boot Filesystem CrosStor filesystem DTFS - Desktop filesystem EFS - Enhanced filesystem (Linux) EFS - Extent filesystem (IRIX) FFS - BSD Fast filesystem GPFS - General Parallel Filesystem HFS - HP-UX Hi performance filesystem HTFS - High throughput filesystem LFS - Linux log structured filesystem JFS - Journaled filesystem (HP-UX, AIX, OS/2 5, Linux) MFS - Macintosh filesystem Minix filesystem NWFS - Novell NetWare filesystem NSS - Novell Storage Services ODS - On Disk Structure filesystem QNX filesystem Reiser filesystem RFS (CD-ROM Filesystem) RomFS - Rom filesystem SFS - Secure filesystem Spiralog filesystem (OpenVMS) System V and derived filesystems Text - (Philips' CD-ROM Filesystem) UDF - Universal Disk Format (DVD-ROM filesystem) UFS V7 Filesystem VxFS - Veritas filesystem (HP-UX, SCO UnixWare, Solaris) XFS - Extended filesystem (IRIX) Xia FS

slide-5
SLIDE 5

ACCESS IC LAB

Graduate Institute of Electronics Engineering, NTU

File File-

  • System Structure

System Structure

slide-6
SLIDE 6

ACCESS IC LAB

Graduate Institute of Electronics Engineering, NTU

P6

Introduction Introduction

File structure

Logical storage unit Collection of related information

File system resides on secondary storage (disks) File system organized into layers File 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)

slide-7
SLIDE 7

ACCESS IC LAB

Graduate Institute of Electronics Engineering, NTU

P7

Layered File System Layered File System

slide-8
SLIDE 8

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 system Retrieve block 123 HW-specific instructions

Basic file system

Issue generic commands to device driver to read and write physical blocks on the disk Physical block: drive 1, cylinder 73, track 2, sector 10

slide-9
SLIDE 9

ACCESS IC LAB

Graduate Institute of Electronics Engineering, NTU

P9

Layered File System (Cont.) Layered File System (Cont.)

File-organization module

Know about files, their logical blocks, and physical blocks Translate logical blocks to physical blocks (similar to VM)

Logical blocks: 0 N

Free-space manager Blocks allocation

Logical file system manage metadata information

Metadata: file-system structure, excluding the actual file contents Manage the directory structure via file control blocks (FCB)

slide-10
SLIDE 10

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 approach File system standard: UFS, FAT FAT32, NTFS Duplication of code is minimized for different file system standard Usually I/O control and the basic file system code can be used by multiple file system formats.

slide-11
SLIDE 11

ACCESS IC LAB

Graduate Institute of Electronics Engineering, NTU

P11

A Typical FCB A Typical FCB

slide-12
SLIDE 12

ACCESS IC LAB

Graduate Institute of Electronics Engineering, NTU

File System Implementation File System Implementation

slide-13
SLIDE 13

ACCESS IC LAB

Graduate Institute of Electronics Engineering, NTU

P13

On On-

  • Disk Structures

Disk 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 details

  • No. of blocks, size of the blocks, free-block count and free-

block pointers, free FCB count and FCB pointers UFS: superblock; NTFS: Master File Table

A directory structure is used to organize the files File control block: many of the file s details

File permissions, ownership, size, location of the data blocks UFS: inode; NTFS: within the Master File Table

slide-14
SLIDE 14

ACCESS IC LAB

Graduate Institute of Electronics Engineering, NTU

P14

In In-

  • Memory Structures

Memory Structures

An in-memory partition table containing information about each mounted partition An in-memory directory structure that holds the directory information of recently accessed directories The 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

slide-15
SLIDE 15

ACCESS IC LAB

Graduate Institute of Electronics Engineering, NTU

P15

In In-

  • Memory File

Memory File-

  • System Structures

System Structures

File Open File Read

slide-16
SLIDE 16

ACCESS IC LAB

Graduate Institute of Electronics Engineering, NTU

P16

Virtual File Systems Virtual File Systems

Virtual File Systems (VFS) provide an object-oriented way of implementing file systems VFS separates file-system-generic operations from their implementation by defining a clean VFS interface VFS allows the same system call interface (the API) to be used for different types of file systems VFS is based on a file-representation structure, called a vnode, that contains a numerical designator for a network-wide unique file The API is to the VFS interface, rather than any specific type of file system

slide-17
SLIDE 17

ACCESS IC LAB

Graduate Institute of Electronics Engineering, NTU

P17

Schematic View of Virtual File System Schematic View of Virtual File System

Open, read, write

slide-18
SLIDE 18

ACCESS IC LAB

Graduate Institute of Electronics Engineering, NTU

P18

Directory Implementation Directory Implementation

Linear list of file names with pointer to the data blocks

Simple to program Time-consuming to execute linear search to find a particular entry

Cache and sorted list may help

Hash Table linear list with hash data structure

Decreases directory search time Collisions situations where two file names hash to the same location Fixed size and the dependence of the hash function on that size

slide-19
SLIDE 19

ACCESS IC LAB

Graduate Institute of Electronics Engineering, NTU

Allocation Methods Allocation Methods

How to allocate space to files so that disk space is utilized effectively and files can be accessed quickly

slide-20
SLIDE 20

ACCESS IC LAB

Graduate Institute of Electronics Engineering, NTU

P20

Contiguous Allocation Contiguous Allocation

A file occupies a set of contiguous blocks on disk Only starting block (block #) and length (number of blocks) are required in the directory entry (FCB) Fast -- Minimal seek time and head movement Random access any block within the file Similar to dynamic storage-allocation problem

External fragmentation may need compaction

Files are difficult to grow

Find a larger hole and copy the file to the new space

slide-21
SLIDE 21

ACCESS IC LAB

Graduate Institute of Electronics Engineering, NTU

P21

Contiguous Allocation (Cont.) Contiguous Allocation (Cont.)

slide-22
SLIDE 22

ACCESS IC LAB

Graduate Institute of Electronics Engineering, NTU

P22

Extent Extent-

  • Based Systems

Based Systems

Many newer file systems (I.e. Veritas File System) use a modified contiguous allocation scheme Extent-based file systems allocate disk blocks in extents An 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)

slide-23
SLIDE 23

ACCESS IC LAB

Graduate Institute of Electronics Engineering, NTU

P23

Linked Allocation Linked Allocation

Each file is a linked list of disk blocks

Blocks may be scattered anywhere on the disk Directory contains a pointer to the first and last blocks Each block contains a pointer to the next block

Advantages

No external fragmentation Easy to grow Any free block is OK

Disadvantages

Effectively for only sequential-access file Space required for the pointers Reliability What if the pointers are lost

slide-24
SLIDE 24

ACCESS IC LAB

Graduate Institute of Electronics Engineering, NTU

P24

Linked Allocation (Cont.) Linked Allocation (Cont.)

pointer data block =

slide-25
SLIDE 25

ACCESS IC LAB

Graduate Institute of Electronics Engineering, NTU

P25

Linked Allocation (Cont.) Linked Allocation (Cont.)

Solution for spaces for pointers

Collect 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 management Internal fragmentation

Solution for reliability

Double linked list or store the filename and relative block number in each block

More overhead for each file

slide-26
SLIDE 26

ACCESS IC LAB

Graduate Institute of Electronics Engineering, NTU

P26

Linked Allocation (Cont.) Linked Allocation (Cont.)

FAT (File Allocation Table)

OS/2, MS-DOS The table has one entry for each disk block and is indexed by block number

Similar to the linked list Contain the block number

  • f the next block in the file

Significant number of disk head seeks

One for FAT, one for data Improved by caching FAT Random access time is improved

Pointer FAT Data Block

slide-27
SLIDE 27

ACCESS IC LAB

Graduate Institute of Electronics Engineering, NTU

P27

Indexed Allocation Indexed Allocation

Bring all pointers together into the index block

An array of disk-block addresses The ith entry points to the ith block of the file The directory contains the address of the index block Similar to the paging scheme for memory management

slide-28
SLIDE 28

ACCESS IC LAB

Graduate Institute of Electronics Engineering, NTU

P28

Example of Indexed Allocation Example of Indexed Allocation

slide-29
SLIDE 29

ACCESS IC LAB

Graduate Institute of Electronics Engineering, NTU

P29

Indexed Allocation (Cont.) Indexed Allocation (Cont.)

Advantage

Support random access Dynamic access without external fragmentation No size-declaration problem But have overhead of index block. Need index table

Disadvantage

Wasted space: Worse than the linked allocation for small files

How large the index block should be

Large index block: waste space for small files Small index block: how to handle large files

slide-30
SLIDE 30

ACCESS IC LAB

Graduate Institute of Electronics Engineering, NTU

P30

Indexed Allocation (Cont.) Indexed Allocation (Cont.)

Mechanism for handling the index block

Linked scheme: Link together several index blocks Multilevel 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

slide-31
SLIDE 31

ACCESS IC LAB

Graduate Institute of Electronics Engineering, NTU

P31

Indexed Allocation Indexed Allocation Multilevel Multilevel Index (Cont.) Index (Cont.)

slide-32
SLIDE 32

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?

slide-33
SLIDE 33

ACCESS IC LAB

Graduate Institute of Electronics Engineering, NTU

Free Space Management Free Space Management

slide-34
SLIDE 34

ACCESS IC LAB

Graduate Institute of Electronics Engineering, NTU

P34

Bit Vector Bit Vector

Simple and efficient to find the first free block, or consecutive free blocks

By bit-manipulation

Requires extra space

block size = 212 bytes disk size = 230 bytes n = 230/212 = 218 bits (or 32K bytes)

Efficient only when the entire vector is kept in main memory

Write back to the disk

  • ccasionally for recovery

needs 001111001111100011000011100 0 1 2 n-1 bit[i] = block[i] free 1 block[i] occupied

Question: What s the block # of the fist free block?

slide-35
SLIDE 35

ACCESS IC LAB

Graduate Institute of Electronics Engineering, NTU

P35

Linked List Linked List

Link together all free blocks Keep a pointer to the first free block in a special location on the disk and caching it in memory Cannot get contiguous space easily No waste of space Not efficient: have to traverse the disk for free spaces

Usually, OS needs one free block at a time

FAT incorporate the linked list mechanism

slide-36
SLIDE 36

ACCESS IC LAB

Graduate Institute of Electronics Engineering, NTU

P36

Grouping And Counting Grouping 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
  • f another n free blocks

Counting: Each entry has a disk address and a count

Several contiguous blocks may be allocated or freed simultaneously

slide-37
SLIDE 37

ACCESS IC LAB

Graduate Institute of Electronics Engineering, NTU

P37

Example Of Free Example Of Free-

  • Space Management

Space Management

Bit Vector 11000011000000111001111110001111 Counting 2 4 8 6 17 2 25 3 Grouping Block 2 3, 4, 5 Block 5 8, 9, 10 Block 10 11, 12, 13 Block 13 17, 28, 25 Block 25 26, 27

slide-38
SLIDE 38

ACCESS IC LAB

Graduate Institute of Electronics Engineering, NTU

Efficiency and Performance Efficiency and Performance

slide-39
SLIDE 39

ACCESS IC LAB

Graduate Institute of Electronics Engineering, NTU

P39

Efficiency and Performance Efficiency and Performance

Efficiency dependent on

Disk allocation and directory algorithms Types of data kept in file s directory entry

Performance

On-board cache local memory in disk controller to store entire tracks at a time Disk 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.

slide-40
SLIDE 40

ACCESS IC LAB

Graduate Institute of Electronics Engineering, NTU

P40

Various Disk Various Disk-

  • Caching Locations

Caching Locations

slide-41
SLIDE 41

ACCESS IC LAB

Graduate Institute of Electronics Engineering, NTU

P41

Page Cache Page Cache

Non-unified buffer cache

A page cache caches pages rather than disk blocks using virtual memory techniques Memory-mapped I/O uses a page cache Routine I/O through the file system uses the buffer (disk) cache

Unified Buffer Cache

A unified buffer cache uses the same buffer cache to cache both memory-mapped pages and

  • rdinary file system I/O
slide-42
SLIDE 42

ACCESS IC LAB

Graduate Institute of Electronics Engineering, NTU

P42

I/O Without/With A Unified Buffer Cache I/O Without/With A Unified Buffer Cache

slide-43
SLIDE 43

ACCESS IC LAB

Graduate Institute of Electronics Engineering, NTU

P43

Recovery Recovery

Consistency checker compares data in directory structure with data blocks on disk, and tries to fix inconsistencies Use 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

slide-44
SLIDE 44

ACCESS IC LAB

Graduate Institute of Electronics Engineering, NTU

P44

Log Structured File Systems Log Structured File Systems

Log structured (or journaling) file systems record each update to the file system as a transaction All transactions are written to a log. A transaction is considered committed once it is written to the log However, the file system may not yet be updated The transactions in the log are asynchronously written to the file system. When the file system is modified, the transaction is removed from the log If the file system crashes, all remaining transactions in the log must still be performed

slide-45
SLIDE 45

ACCESS IC LAB

Graduate Institute of Electronics Engineering, NTU

Microsoft File System Microsoft File System

slide-46
SLIDE 46

ACCESS IC LAB

Graduate Institute of Electronics Engineering, NTU

P46

General Comments General Comments

FAT file system on disk data structure is all little endian you will have to translate if your machine is a big endian machine A FAT file system volume is composed of four basic regions, which are laid out in this order on the volume:

Reserved Region 1 FAT Region 2 Root Directory Region (doesn t exist on FAT32 volumes) 3 File and Directory Data Region

slide-47
SLIDE 47

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.X The 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

slide-48
SLIDE 48

ACCESS IC LAB

Graduate Institute of Electronics Engineering, NTU

P48

struct BootSector { u8 BS_jmpBoot[3]; //long jump instruction u8 BS_OEMName[8]; //name of OEM u16 BPB_BytsPerSec; //512,1024,2048,4096 u8 BPB_SecPerClus; //1,2,4,8,16,32,64,128 u16 BPB_RsvdSecCnt; //reserved sector after BPB u8 BPB_NumFATs; //2 u16 BPB_RootEntCnt; //the count of 32-byte directory entries in the root directory u16 BPB_TotSec16; //total size in this volume (FAT 16) u8 BPB_Media; //media type u16 BPB_FATsz; //number of sectors u16 BPB_SecPerTrk; //Sectors per track for interrupt 0x13 u16 BPB_NumHeads; //Number of heads for interrupt 0x13 u32 BPB_HiddSec; //Count of hidden sectors u32 BPB_TotSec32; //total size in this volume (FAT 32) } ;

slide-49
SLIDE 49

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 number u8 BS_Reserved1; //reserved u8 BS_BootSig; //Extended boot signature u32 BS_VolID; //serial ID u8 BS_VolLab[11]; //Volume label. u8 BS_FilSysType[8] //FAT12/FAT16/FAT };

slide-50
SLIDE 50

ACCESS IC LAB

Graduate Institute of Electronics Engineering, NTU

P50

FAT32 Structure Starting at Offset 36

Struct Fat32 { u32 BPB_FATSz32; //count of sectors u16 BPB_ExtFlags; u8 BPB_FSVer[2]; //file system version u32 BPB_RootClus; //root cluster (directory) u16 BPB_FSInfo; //file system information u16 BPB_BkBootSec; //back up boot sector u8 BPB_Reserved[12]; //reserved u8 BS_DrvNum; //driver number u8 BS_Reserved1; //reserved u8 BS_BootSig; //Extended boot signature u32 BS_VolID; //volume serial number u8 BS_VolLab[11]; //volume label u8 BS_FilSysType[8]; //file system type ( FAT32 ) };

slide-51
SLIDE 51

ACCESS IC LAB

Graduate Institute of Electronics Engineering, NTU

P51

File Allocation Table (FAT) is a linking list to a stored file The FAT maps the data region of the volume by cluster number The 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; Else FATSz = BPB_FATSz32; FirstDataSector = BPB_ResvdSecCnt + (BPB_NumFATs * FATSz) + RootDirSectors;

slide-52
SLIDE 52

ACCESS IC LAB

Graduate Institute of Electronics Engineering, NTU

P52

FAT32 FSInfo Sector Structure and Backup Boot Sector

Data structure on FAT12/16/32

On a FAT32 volume, the FAT can be a large data structure On FAT16 where it is limited to a maximum of 128K worth of sectors On 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:

slide-53
SLIDE 53

ACCESS IC LAB

Graduate Institute of Electronics Engineering, NTU

P53

struct FSInfo { u64 FSI_LeadSig; //FSInfo header = 0x41615252 u8 FSI_Reserved1[480]; //reserved (should not be used) u64 FSI_StrucSig; //structure header = 0x61417272. u64 FSI_Free_Count; //free cluster count u64 FSI_Nxt_Free; //next free cluster pointer u8 FSI_Reserved2[12]; //reserved (should not be used) u64 FSI_TrailSig; //0xAA550000 to valid FSsector };

slide-54
SLIDE 54

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

slide-55
SLIDE 55

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

  • n the FAT volume for which it is valid to have a file that has only the

ATTR_VOLUME_ID attribute bit set (see below).

slide-56
SLIDE 56

ACCESS IC LAB

Graduate Institute of Electronics Engineering, NTU

P56

FAT 32 Byte Directory Entry Structure

struct DirectoryEntryStruct { u8 DIR_Name[11]; //directory name u8 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 NT u8 DIR_CrtTimeTenth; //create time tenth to DIR_CrtTime u16 DIR_CrtTime; // create time of 2 seconds u16 DIR_CrtDate; //create date u16 DIR_LstAccDate; //last access date u16 DIR_FstClusHI; //High word of this entry s first cluster number u16 DIR_WrtTime; //last write time u16 DIR_WrtDate; //last write date u16 DIR_FstClusLO; //Low word of this entry s first cluster number u32 DIR_FileSize; //file size in bytes };

slide-57
SLIDE 57

ACCESS IC LAB

Graduate Institute of Electronics Engineering, NTU

P57

Directory Name Directory Name

Special 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

  • ne are also set to 0).

The special 0 value, rather than the 0xE5 value, indicates to FAT file system driver code that the rest

  • f 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_Name The 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.

slide-58
SLIDE 58

ACCESS IC LAB

Graduate Institute of Electronics Engineering, NTU

P58

Directory Name Directory Name

ATTR_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

  • n 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).

slide-59
SLIDE 59

ACCESS IC LAB

Graduate Institute of Electronics Engineering, NTU

P59

Directory Name Directory Name

If 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).

slide-60
SLIDE 60

ACCESS IC LAB

Graduate Institute of Electronics Engineering, NTU

P60

Date and Time Formats

Many 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 supported Date 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.

slide-61
SLIDE 61

ACCESS IC LAB

Graduate Institute of Electronics Engineering, NTU

P61

Lab Lab

Create a Virtual Disk form SDRAM Create a Boot Sector on Virtual Disk Create two FATs and one Directory on Virtual Disk which should be compatible to Microsoft File System FAT32 Provide Delete, Create, Write, Read functions to Virtual disk for next Lab usage