FAT directory traversal

I’m getting slowly closer to getting this FAT driver working in a usable fashion. As can be seen below, it’s now finally able to open the root directory and look for files in it. It should be able to traverse into other directories, too – I just don’t have a suitable test image handy. I haven’t implemented reading or writing to the files yet, and we’re probably going to need a way to enumerate directory records, but they’re on their way.

It turns out I made a teeny little mistake previously when calculating the offset of the first FAT – I’d blindly followed some random web page, which I’d misread… in a nutshell I was looking at the start of data for the FAT, and some random offset in the data section for the start of data. Needless to say that didn’t work very well. A trivial thing to fix, though; I don’t understand how I got this wrong to start with.

Unable to open file "/Users/wadetregaskis/Documents/School/Fifth Year/ENP/Project/Flash Disk Image" as writable; reverting to read-only.
..i.k$.....YU.J..r.y.b..9...e...O.:N.h......&...|...Bjl.i.........u.7.[.Kv.1`...*...A`...=.61[.....b.SO5...U
+..J...uO....b.b^9...N....c&.!.3`....HP..K:...3.s..u.b.....d01...Q.h..g...^..X..**f...}...yf......ke.....mh.
..e............x*..f.~E.[6V.6.f.[....aH.g[..Tk0.."....#R.....jQ...Wq<-EEm=...#.C....s.....R..gUs.{P#V-cp....
.%_^q.0mZ...b...d.._...&..7...`?]z.."....,.~.q...[1.}..`sn&...*n.Vl.jn.{z.dLi..ES....4..*..%...:q..(.....a.
...B44O...P....e.....T.."#......j.*..<.....C<...6.}.78D.K(....I._..!..9.,..7....
/Users/wadetregaskis/Documents/School/Fifth Year/ENP/Project/FATShell/FATDriver.c:1012 (FATCreateVolume) - FATVolume:
/Users/wadetregaskis/Documents/School/Fifth Year/ENP/Project/FATShell/FATDriver.c:1013 (FATCreateVolume) - volume = 0xb364
/Users/wadetregaskis/Documents/School/Fifth Year/ENP/Project/FATShell/FATDriver.c:1014 (FATCreateVolume) - FATOffset = 19456
/Users/wadetregaskis/Documents/School/Fifth Year/ENP/Project/FATShell/FATDriver.c:1015 (FATCreateVolume) - DataOffset = 1028096
/Users/wadetregaskis/Documents/School/Fifth Year/ENP/Project/FATShell/FATDriver.c:1016 (FATCreateVolume) - bytesPerSector = 512
/Users/wadetregaskis/Documents/School/Fifth Year/ENP/Project/FATShell/FATDriver.c:1017 (FATCreateVolume) - sectorsPerCluster = 1
/Users/wadetregaskis/Documents/School/Fifth Year/ENP/Project/FATShell/FATDriver.c:1018 (FATCreateVolume) - reservedSectorCount = 38
/Users/wadetregaskis/Documents/School/Fifth Year/ENP/Project/FATShell/FATDriver.c:1019 (FATCreateVolume) - numberOfFATs = 2
/Users/wadetregaskis/Documents/School/Fifth Year/ENP/Project/FATShell/FATDriver.c:1033 (FATCreateVolume) - FAT32:
/Users/wadetregaskis/Documents/School/Fifth Year/ENP/Project/FATShell/FATDriver.c:1034 (FATCreateVolume) - FATInUse = 0
/Users/wadetregaskis/Documents/School/Fifth Year/ENP/Project/FATShell/FATDriver.c:1035 (FATCreateVolume) - mirroringDisabled = 0
/Users/wadetregaskis/Documents/School/Fifth Year/ENP/Project/FATShell/FATDriver.c:1036 (FATCreateVolume) - majorVersion = 0
/Users/wadetregaskis/Documents/School/Fifth Year/ENP/Project/FATShell/FATDriver.c:1037 (FATCreateVolume) - minorVersion = 0
/Users/wadetregaskis/Documents/School/Fifth Year/ENP/Project/FATShell/FATDriver.c:1038 (FATCreateVolume) - rootCluster = 2
/Users/wadetregaskis/Documents/School/Fifth Year/ENP/Project/FATShell/FATDriver.c:1039 (FATCreateVolume) - fileSystemInformationSector = 1
/Users/wadetregaskis/Documents/School/Fifth Year/ENP/Project/FATShell/FATDriver.c:1040 (FATCreateVolume) - backupBootSector = 6
/Users/wadetregaskis/Documents/School/Fifth Year/ENP/Project/FATShell/FATDriver.c:1041 (FATCreateVolume) - logicalDriveNumber = 0
/Users/wadetregaskis/Documents/School/Fifth Year/ENP/Project/FATShell/FATDriver.c:1042 (FATCreateVolume) - extendedSignature = 41
/Users/wadetregaskis/Documents/School/Fifth Year/ENP/Project/FATShell/FATDriver.c:1043 (FATCreateVolume) - serialNumber = 1149524418
/Users/wadetregaskis/Documents/School/Fifth Year/ENP/Project/FATShell/FATDriver.c:1049 (FATCreateVolume) - totalSectors = 128000
/Users/wadetregaskis/Documents/School/Fifth Year/ENP/Project/FATShell/FATDriver.c:1050 (FATCreateVolume) - mediaDescriptor = 248
/Users/wadetregaskis/Documents/School/Fifth Year/ENP/Project/FATShell/FATDriver.c:1051 (FATCreateVolume) - sectorsPerFAT = 985
/Users/wadetregaskis/Documents/School/Fifth Year/ENP/Project/FATShell/FATDriver.c:1052 (FATCreateVolume) - sectorsPerTrack = 63
/Users/wadetregaskis/Documents/School/Fifth Year/ENP/Project/FATShell/FATDriver.c:1053 (FATCreateVolume) - numberOfHeads = 255
/Users/wadetregaskis/Documents/School/Fifth Year/ENP/Project/FATShell/FATDriver.c:1054 (FATCreateVolume) - hiddenSectors = 0
/Users/wadetregaskis/Documents/School/Fifth Year/ENP/Project/FATShell/VolumeInterface.c:125 (createVolume) - Successfully opened volume starting at logical address 0 (0), length 4294967295 (0xffffffff), suggestedFormat 3 (actual format 3).
/Users/wadetregaskis/Documents/School/Fifth Year/ENP/Project/FATShell/VolumeInterface.c:155 (destroyVolume) - Successfully destroyed volume (handle = 0, ptr = 0xb364) starting at logical address 0 (0), length 0 (0), format 3.
/Users/wadetregaskis/Documents/School/Fifth Year/ENP/Project/FATShell/FATDriver.c:1012 (FATCreateVolume) - FATVolume:
/Users/wadetregaskis/Documents/School/Fifth Year/ENP/Project/FATShell/FATDriver.c:1013 (FATCreateVolume) - volume = 0xb364
/Users/wadetregaskis/Documents/School/Fifth Year/ENP/Project/FATShell/FATDriver.c:1014 (FATCreateVolume) - FATOffset = 19456
/Users/wadetregaskis/Documents/School/Fifth Year/ENP/Project/FATShell/FATDriver.c:1015 (FATCreateVolume) - DataOffset = 1028096
/Users/wadetregaskis/Documents/School/Fifth Year/ENP/Project/FATShell/FATDriver.c:1016 (FATCreateVolume) - bytesPerSector = 512
/Users/wadetregaskis/Documents/School/Fifth Year/ENP/Project/FATShell/FATDriver.c:1017 (FATCreateVolume) - sectorsPerCluster = 1
/Users/wadetregaskis/Documents/School/Fifth Year/ENP/Project/FATShell/FATDriver.c:1018 (FATCreateVolume) - reservedSectorCount = 38
/Users/wadetregaskis/Documents/School/Fifth Year/ENP/Project/FATShell/FATDriver.c:1019 (FATCreateVolume) - numberOfFATs = 2
/Users/wadetregaskis/Documents/School/Fifth Year/ENP/Project/FATShell/FATDriver.c:1033 (FATCreateVolume) - FAT32:
/Users/wadetregaskis/Documents/School/Fifth Year/ENP/Project/FATShell/FATDriver.c:1034 (FATCreateVolume) - FATInUse = 0
/Users/wadetregaskis/Documents/School/Fifth Year/ENP/Project/FATShell/FATDriver.c:1035 (FATCreateVolume) - mirroringDisabled = 0
/Users/wadetregaskis/Documents/School/Fifth Year/ENP/Project/FATShell/FATDriver.c:1036 (FATCreateVolume) - majorVersion = 0
/Users/wadetregaskis/Documents/School/Fifth Year/ENP/Project/FATShell/FATDriver.c:1037 (FATCreateVolume) - minorVersion = 0
/Users/wadetregaskis/Documents/School/Fifth Year/ENP/Project/FATShell/FATDriver.c:1038 (FATCreateVolume) - rootCluster = 2
/Users/wadetregaskis/Documents/School/Fifth Year/ENP/Project/FATShell/FATDriver.c:1039 (FATCreateVolume) - fileSystemInformationSector = 1
/Users/wadetregaskis/Documents/School/Fifth Year/ENP/Project/FATShell/FATDriver.c:1040 (FATCreateVolume) - backupBootSector = 6
/Users/wadetregaskis/Documents/School/Fifth Year/ENP/Project/FATShell/FATDriver.c:1041 (FATCreateVolume) - logicalDriveNumber = 0
/Users/wadetregaskis/Documents/School/Fifth Year/ENP/Project/FATShell/FATDriver.c:1042 (FATCreateVolume) - extendedSignature = 41
/Users/wadetregaskis/Documents/School/Fifth Year/ENP/Project/FATShell/FATDriver.c:1043 (FATCreateVolume) - serialNumber = 1149524418
/Users/wadetregaskis/Documents/School/Fifth Year/ENP/Project/FATShell/FATDriver.c:1049 (FATCreateVolume) - totalSectors = 128000
/Users/wadetregaskis/Documents/School/Fifth Year/ENP/Project/FATShell/FATDriver.c:1050 (FATCreateVolume) - mediaDescriptor = 248
/Users/wadetregaskis/Documents/School/Fifth Year/ENP/Project/FATShell/FATDriver.c:1051 (FATCreateVolume) - sectorsPerFAT = 985
/Users/wadetregaskis/Documents/School/Fifth Year/ENP/Project/FATShell/FATDriver.c:1052 (FATCreateVolume) - sectorsPerTrack = 63
/Users/wadetregaskis/Documents/School/Fifth Year/ENP/Project/FATShell/FATDriver.c:1053 (FATCreateVolume) - numberOfHeads = 255
/Users/wadetregaskis/Documents/School/Fifth Year/ENP/Project/FATShell/FATDriver.c:1054 (FATCreateVolume) - hiddenSectors = 0
/Users/wadetregaskis/Documents/School/Fifth Year/ENP/Project/FATShell/VolumeInterface.c:125 (createVolume) - Successfully opened volume starting at logical address 0 (0), length 65536000 (0x3e80000), suggestedFormat 0 (actual format 3).
Successfully opened root directory.
Successfully closed root directory.
/Users/wadetregaskis/Documents/School/Fifth Year/ENP/Project/FATShell/FATDriver.c:451 (FATOpenFile) - Current condensed directory entry: WOOT 
/Users/wadetregaskis/Documents/School/Fifth Year/ENP/Project/FATShell/FATDriver.c:451 (FATOpenFile) - Current condensed directory entry: D,
/Users/wadetregaskis/Documents/School/Fifth Year/ENP/Project/FATShell/FATDriver.c:451 (FATOpenFile) - Current condensed directory entry: s
/Users/wadetregaskis/Documents/School/Fifth Year/ENP/Project/FATShell/FATDriver.c:451 (FATOpenFile) - Current condensed directory entry: ]
/Users/wadetregaskis/Documents/School/Fifth Year/ENP/Project/FATShell/FATDriver.c:451 (FATOpenFile) - Current condensed directory entry: C
/Users/wadetregaskis/Documents/School/Fifth Year/ENP/Project/FATShell/FATDriver.c:451 (FATOpenFile) - Current condensed directory entry: CODE_W~1ZIP 
/Users/wadetregaskis/Documents/School/Fifth Year/ENP/Project/FATShell/FATDriver.c:451 (FATOpenFile) - Current condensed directory entry: AT
/Users/wadetregaskis/Documents/School/Fifth Year/ENP/Project/FATShell/FATDriver.c:451 (FATOpenFile) - Current condensed directory entry: THESIS PDF 
/Users/wadetregaskis/Documents/School/Fifth Year/ENP/Project/FATShell/FATDriver.c:451 (FATOpenFile) - Current condensed directory entry: Dp
/Users/wadetregaskis/Documents/School/Fifth Year/ENP/Project/FATShell/FATDriver.c:451 (FATOpenFile) - Current condensed directory entry: b
/Users/wadetregaskis/Documents/School/Fifth Year/ENP/Project/FATShell/FATDriver.c:451 (FATOpenFile) - Current condensed directory entry: 
/Users/wadetregaskis/Documents/School/Fifth Year/ENP/Project/FATShell/FATDriver.c:451 (FATOpenFile) - Current condensed directory entry: C
/Users/wadetregaskis/Documents/School/Fifth Year/ENP/Project/FATShell/FATDriver.c:451 (FATOpenFile) - Current condensed directory entry: CODE(4~1ZIP 
/Users/wadetregaskis/Documents/School/Fifth Year/ENP/Project/FATShell/FATDriver.c:451 (FATOpenFile) - Current condensed directory entry: Bp
/Users/wadetregaskis/Documents/School/Fifth Year/ENP/Project/FATShell/FATDriver.c:451 (FATOpenFile) - Current condensed directory entry: Z
/Users/wadetregaskis/Documents/School/Fifth Year/ENP/Project/FATShell/FATDriver.c:526 (FATOpenFile) - Path "/Wrong" is invalid; cannot find "WRONG ".
/Users/wadetregaskis/Documents/School/Fifth Year/ENP/Project/FATShell/StandardIO.c:336 (openFile) - Unable to open file at path "/Wrong" with mode 1, permissions 700 - error #2 (No such file or directory).
Successfully failed to open "/Wrong", which shouldn't exist.
/Users/wadetregaskis/Documents/School/Fifth Year/ENP/Project/FATShell/FATDriver.c:451 (FATOpenFile) - Current condensed directory entry: WOOT 
/Users/wadetregaskis/Documents/School/Fifth Year/ENP/Project/FATShell/FATDriver.c:451 (FATOpenFile) - Current condensed directory entry: D,
/Users/wadetregaskis/Documents/School/Fifth Year/ENP/Project/FATShell/FATDriver.c:451 (FATOpenFile) - Current condensed directory entry: s
/Users/wadetregaskis/Documents/School/Fifth Year/ENP/Project/FATShell/FATDriver.c:451 (FATOpenFile) - Current condensed directory entry: ]
/Users/wadetregaskis/Documents/School/Fifth Year/ENP/Project/FATShell/FATDriver.c:451 (FATOpenFile) - Current condensed directory entry: C
/Users/wadetregaskis/Documents/School/Fifth Year/ENP/Project/FATShell/FATDriver.c:451 (FATOpenFile) - Current condensed directory entry: CODE_W~1ZIP 
/Users/wadetregaskis/Documents/School/Fifth Year/ENP/Project/FATShell/FATDriver.c:451 (FATOpenFile) - Current condensed directory entry: AT
/Users/wadetregaskis/Documents/School/Fifth Year/ENP/Project/FATShell/FATDriver.c:451 (FATOpenFile) - Current condensed directory entry: THESIS PDF 
Successfully opened "/Thesis.pdf".
Successfully closed "/Thesis.pdf".

Leave a Comment