- byte offset = (starting cluster number + 31) * bytesPerSector
- Example: Calculate the starting position of /dir1/file1
- Search from the first root directory entry @ 0x2600
(sector #19)
- The first 32-byte entry @ 0x2600 starts with 0x41, so it is not
a valid entry, but the next 32-byte entry @ 0x2620 is a valid entry
- The first 8 bytes starting @ 0x2620 is the directory name
(DIR1), while the 2 bytes starting at relative position @ 0x1A is
the starting cluster number of DIR1, which is 0x0002
- Calculate the starting position of DIR1: (2 + 31) * 512 =
0x4200, i.e., DIR1 starts @ 0x4200
- The first 32-byte entry @ 0x4200 starts with 0x2e, so it points
to the current directory, the 2 bytes starting at relative position
@ 0x1A should be the same as 0x0002
- The next 32-byte entry @ 0x4220 starts with 0x2e2e, so it
points to the parent directory, the 2 bytes starting at relative
position @ 0x1A should be the same as the starting cluster number
of its parent (in this example, parent is root, so it is 0)
- The next three 32-byte entries starts with 0xe5, so they are
invalid entries, we can simply skip them
- The next 32-byte entry @ 0x42a0 starts with 0x41, so it is not
a valid entry, but the next 32-byte entry @ 0x42c0 is a valid entry
- The first 8 bytes starting @ 0x42c0 is the file name(file1),
the next 3 bytes is the extension (txt), while the 2 bytes starting
at relative position @ 0x1A is the starting cluster number of
file1.txt, which is 0x0015
- Calculate the starting position of file1.txt: (15 + 31) * 512 =
0x6800, i.e., file1.txt starts @ 0x6800
|