
Operating SystemsCh10, part 1Details of FAT32T
Operating Systems Ch10, part 1 Details of FAT32 1

TopicsinCh10: Case studyDetailsofFAT32File attributes and directory entries, file operationsDetailsofExt2/3/4Detailed layout, detailed inode structure (file attributes), FS operations...2
Topics in Ch10 • Case study 2 File attributes and directory entries, file operations Details of FAT32 Detailed layout, detailed inode structure (file attributes), FS operations. Details of Ext2/3/4

DetailsofFAT32IntroductionDirectory and File Attributes File Operations-Readfiles-Writefiles-Deletefiles-RecoverdeletedfilesMicrosoftExtensibleFirmwareInitiativeFAT32FileSystemSpecification (FAT:GeneralOverviewofOn-DiskFormat),Version1.03,December6,2000,hardwarewhitepapers@MicrosoftCorporation.3
Details of FAT32 • Introduction • Directory and File Attributes • File Operations – Read files – Write files – Delete files – Recover deleted files 3 Microsoft Extensible Firmware Initiative FAT32 File System Specification (FAT: General Overview of On-Disk Format), Version 1.03, December 6, 2000, hardware white papers @ Microsoft Corporation

Recall on FATallocation· The layoutAblockisnamedaclusterFAT12FAT16FAT32FileSystemClusteraddr length12bits16bits32bits(28?)NumberofFilenameFirst4K64K256MBlock#clustersrock.mp3119game.exe7ubuntu.iso252627282930671819Block#802900262002730NextBlock#2EREEFileRootAllocationDirectoryTable(FAT)个←1+11121304
Recall on FAT allocation • The layout 4 A block is named a cluster. File System FAT12 FAT16 FAT32 Cluster addr length 12 bits 16 bits 32 bits (28?) Number of clusters 4K 64K 256M

TriviaWhenasectoris>512B.? Cluster Size:512B1KB2KB4KB8KB16KB32KB64KB128KB256KB- Try typing “help format" in the command prompt inWindows. Calculating the maximum partition size-withtheclustersize=32KB...(32 × 210) × 228 = 243 (8TB)5
Trivia • Cluster Size: – Try typing “help format” in the command prompt in Windows. • Calculating the maximum partition size – with the cluster size = 32KB. 5 512B 1KB 2KB 4KB 8KB 16KB 32KB 64KB 128KB 256KB When a sector is > 512B . 32 × 2 10 × 2 28 = 2 43 (8𝑇𝐵)

Typical layoutof a FAT32partitionSizeProposeBoot sectorStore FS-specific parameters1 sector,512bytesFSINFOFree-spacemanagement1sector,512bytesReservedDon'taskme,askMicrosoft!Variable,can bechanged during format.sectorsArobustdesign:if"FAT1"isVariable.dependsondisksizeancFAT (2pieces)corrupted or containing bad sectors,clustersize.then"FAT2"canactasa backupAtleastonecluster,dependontheRoot directoryStart of the directory tree.numberof director entries.RootBootFAT1FAT2FSINFODirectorySector6
Typical layout of a FAT32 partition 6 Root Directory FAT1 FAT2 Boot Sector FSINFO Propose Size Boot sector Store FS-specific parameters 1 sector, 512 bytes FSINFO Free-space management 1 sector, 512 bytes Reserved sectors Don’t ask me, ask Micro$oft! Variable, can be changed during format. FAT (2 pieces) A robust design: if “FAT 1” is corrupted or containing bad sectors, then “FAT 2” can act as a backup. Variable, depends on disk size and cluster size. Root directory Start of the directory tree. At least one cluster, depend on the number of director entries

Typical layout of a FAT32partition$sudo mkfs.vfat-F32/dev/ramoFormatthedisk,"-F32"meansFAT32mkfs.fat3.0.28(2015-05-16)$sudodosfsck-v/dev/rameRead the informationstored inthe boot sectorRunning"dosfsck",DOsfilesystemcheck,onaFAT32FS.ThisprogramreadsdetailsfromtheBootSector.BootRootFAT1FAT2FSINFODirectorySector
Typical layout of a FAT32 partition 7 $ sudo mkfs.vfat -F32 /dev/ram0 mkfs.fat 3.0.28 (2015-05-16) . $ sudo dosfsck -v /dev/ram0 Root Directory FAT1 FAT2 Boot Sector FSINFO Format the disk, “-F32” means FAT32. Read the information stored in the boot sector. Running “dosfsck”, DOS file system check, on a FAT32 FS. This program reads details from the Boot Sector

Typical layout of a FAT32 partition$ sudo mkfs.vfat-F32/dev/ramemkfs.fat 3.0.28(2015-05-16)DetailsoftheBootSector$ sudo dosfsck-v /dev/ramefsck.fat3.0.28(2015-05-16)Checking we can access the last sector of the filesystemBoot sector contents:System ID "mkfs.fat"Media byte oxf8(hard disk)512 bytes per logical sectorThebootsectorsays:512 bytesper clusterAclusterismadeof1sector.32reserved sectorsFirst FAT starts at byte 16384 (sector 32)2 FATs, 32 bit entries516608 bytesperFAT (=1009sectors)Root directory start at cluster 2 (arbitrary size)Data area starts at byte 1049600(sector 2050)Oneclustersize:512129022data clusters(66059264bytes)bytesinthiscase卡RootBootFAT1FAT2FSINFODirectorySector32sectors8
Typical layout of a FAT32 partition 8 Root Directory FAT1 FAT2 Boot Sector FSINFO $ sudo mkfs.vfat -F32 /dev/ram0 mkfs.fat 3.0.28 (2015-05-16) . $ sudo dosfsck -v /dev/ram0 fsck.fat 3.0.28 (2015-05-16) Checking we can access the last sector of the filesystem Boot sector contents: System ID "mkfs.fat" Media byte 0xf8 (hard disk) 512 bytes per logical sector 512 bytes per cluster 32 reserved sectors First FAT starts at byte 16384 (sector 32) 2 FATs, 32 bit entries 516608 bytes per FAT (= 1009 sectors) Root directory start at cluster 2 (arbitrary size) Data area starts at byte 1049600 (sector 2050) 129022 data clusters (66059264 bytes) . The boot sector says: A cluster is made of 1 sector. One cluster size: 512 bytes in this case Details of the Boot Sector 32 sectors

Typical layoutof aFAT32partition$ sudo mkfs.vfat-F32/dev/ramemkfs.fat3.0.28(2015-05-16)$ sudo dosfsck-v /dev/ramefsck.fat3.0.28(2015-05-16)Checking we can access the last sector of the filesystemBoot sector contents:System ID "mkdosfs"Media byte xf8 (hard disk)Thebootsectorsays:512 bytes per logical sector2FATsandeachof themisof512 bytes per cluster32reserved sectorssize516,608bytes.FirstFATstarts atbyte 16384 (sector 32)2FATs, 32 bit entries516608bytesperFAT(=1009sectors)NumberofFATsandtheRoot directory start at cluster 2 (arbitrary size)lengthofeachentryinaFAT.Data area starts at byte 1049600 (sector 2050)129022dataclusters(66059264bytes)Good!Noslackspace betweenreserved sectorsofthefirstFATRootBootFAT1FAT2FSINFODirectorySector32sectors100910099
Typical layout of a FAT32 partition 9 Root Directory FAT1 FAT2 Boot Sector FSINFO $ sudo mkfs.vfat -F32 /dev/ram0 mkfs.fat 3.0.28 (2015-05-16) . $ sudo dosfsck -v /dev/ram0 fsck.fat 3.0.28 (2015-05-16) Checking we can access the last sector of the filesystem Boot sector contents: System ID "mkdosfs" Media byte 0xf8 (hard disk) 512 bytes per logical sector 512 bytes per cluster 32 reserved sectors First FAT starts at byte 16384 (sector 32) 2 FATs, 32 bit entries 516608 bytes per FAT (= 1009 sectors) Root directory start at cluster 2 (arbitrary size) Data area starts at byte 1049600 (sector 2050) 129022 data clusters (66059264 bytes) . The boot sector says: 2 FATs and each of them is of size 516,608 bytes. 32 sectors 1009 1009 Number of FATs and the length of each entry in a FAT. Good! No slack space between reserved sectors of the first FAT

Typical layoutof a FAT32partition$sudomkfs.vfat-F32/dev/ramemkfs.fat3.0.28(2015-05-16)$ sudodosfsck-v /dev/ramefsck.fat3.0.28(2015-05-16)The first data cluster isChecking we can access the last sector of the filesystemCluster#2and it isusually,Boot sector contents:notalways,therootSystem ID "mkdosfs"Media byte xf8 (hard disk)directory.512 bytes per logical sector512 bytes per clusterCluster#0 are32 reserved sectorsreserved.First FAT startsat byte 16384 (sector32)2FATs,32 bit entries516608 bytes perFAT (=1009sectors)Root directory start at cluster 2 (arbitrary size)Data area starts at byte 1049600(sector 2050)32+1009x2=2050129022 data clusters(66059264 bytes)BootRootFAT1FAT2FSINFODirectorySector1009100932sectors2050 and beyond...10
Typical layout of a FAT32 partition 10 Root Directory FAT1 FAT2 Boot Sector FSINFO $ sudo mkfs.vfat -F32 /dev/ram0 mkfs.fat 3.0.28 (2015-05-16) . $ sudo dosfsck -v /dev/ram0 fsck.fat 3.0.28 (2015-05-16) Checking we can access the last sector of the filesystem Boot sector contents: System ID "mkdosfs" Media byte 0xf8 (hard disk) 512 bytes per logical sector 512 bytes per cluster 32 reserved sectors First FAT starts at byte 16384 (sector 32) 2 FATs, 32 bit entries 516608 bytes per FAT (= 1009 sectors) Root directory start at cluster 2 (arbitrary size) Data area starts at byte 1049600 (sector 2050) 129022 data clusters (66059264 bytes) . The first data cluster is Cluster #2 and it is usually, not always, the root directory. Cluster #0 & #1 are reserved. 32 sectors 1009 1009 2050 and beyond. 32 + 1009 x 2 = 2050