FAT directory traversal

Array

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".

ADD transceiver working

Array

So today I finally got the transceiver for our ADD project working. It’s a trivial little thing; it just sends and receives 32 bits of data at a time over a serial connection, using Manchester encoding. It was relatively tricky to do, though; harder than I expected. Transmission’s easy; receiving not so much, as there’s an element of guess work involved in interpreting the data, and guessing is always horrible to implement in logic.

Once that was working, I added CRC-16 CCITT support. It’s massive overkill for a four-byte packet, which I find amusing, but it is a useful thing to have implemented, and will hopefully garner a bit of appreciation come marking time. The CRC stuff gave me some grief; trying to mesh in a serial CRC generator and verifier with the existing code was a bit messy. But in the end it came out alright. There’s a few niggling potential issues still, mainly to do with end of transmission and skew, but I’m pretty sure we can bang those out pretty directly.

‘course, since ADD’s due next week, I suspect I’ll be spending a fair bit of time in the labs ’till then. I actually finished at 2pm today, and don’t have anything on until next Wednesday – woo! five day weekend! – except, of course, all this work to do. 🙁

Still, I like this ADD project, and it’s one of the last few things due this semester. Exams are only a few weeks away, and then it’s break time; four weeks, more or less, I think. I’m looking forward to it.

The importance of working late

Array

Now while I’m not particularly happy about my normal coding hours – say, 10pm till 4am – in this particular case they just did me wonders. I have some code, you see, which converts between NSCalendarDate and CSSM_DATEs – don’t worry if this is going over your head, it’s part of the boring, disgusting internal details of the CDSA. There’s at least five time formats I have to deal with. Hooray. I have to deal with it as part of the Keychain framework, one of my major projects – and probably the one I’ve worked on longest; at least three years now.

Anyway, what I apparently didn’t think of when I first wrote this code was that CSSM_DATEs have no explicit time zone information, ergo they assume GMT. NSCalendarDate of course defaults to the local timezone. So I was actually corrupting the date when converting it. And I never would have known had I not been testing some code that depends on this just as the clock struck midnight. All of a sudden, everything broke. One of those typical horrible moments – “but I swear I hardly touched it!” :).

Luckily I figured it out pretty quickly. A bit of testing (trying my tests again at 9:58am and 10:02am) proved my hypothesis. And now it’s fixed, and working all swell again, back in real time (12:40am).

It’s quite disturbing how many bugs I’m killing tonight in this framework. It’s a wonder it’s ever worked at all. :/