File src/fs/fat.cpp changed (mode: 100644) (index 6b993de..9b2ff57) |
5 |
5 |
|
|
6 |
6 |
using namespace fs; |
using namespace fs; |
7 |
7 |
|
|
8 |
|
static void printFileContents(const DirectoryEntryFat32 &ent, |
|
9 |
|
drv::ATA &hd, const BiosParameterBlock32 &bpb, |
|
10 |
|
std::uint32_t fatStart, std::uint32_t dataStart); |
|
11 |
|
|
|
12 |
|
void |
|
13 |
|
fs::readBiosBlock(drv::ATA &hd, std::uint32_t partitionOffset) |
|
|
8 |
|
FAT::FAT(drv::ATA &hd, std::uint32_t partitionOffset) : hd(hd) |
14 |
9 |
{ |
{ |
15 |
|
BiosParameterBlock32 bpb; |
|
16 |
10 |
hd.read28(partitionOffset, reinterpret_cast<std::uint8_t *>(&bpb), |
hd.read28(partitionOffset, reinterpret_cast<std::uint8_t *>(&bpb), |
17 |
11 |
sizeof(BiosParameterBlock32)); |
sizeof(BiosParameterBlock32)); |
18 |
12 |
|
|
19 |
13 |
kprint("sectors per cluster: ", bpb.sectorsPerCluster, "\n"); |
kprint("sectors per cluster: ", bpb.sectorsPerCluster, "\n"); |
20 |
14 |
|
|
21 |
|
std::uint32_t fatStart = partitionOffset + bpb.reservedSectors; |
|
22 |
|
std::uint32_t fatSize = bpb.tableSize; |
|
23 |
|
|
|
24 |
|
std::uint32_t dataStart = fatStart + fatSize*bpb.fatCopies; |
|
25 |
|
|
|
26 |
|
std::uint32_t rootStart = dataStart |
|
27 |
|
+ bpb.sectorsPerCluster*(bpb.rootCluster - 2); |
|
|
15 |
|
fatStart = partitionOffset + bpb.reservedSectors; |
|
16 |
|
dataStart = fatStart + bpb.tableSize*bpb.fatCopies; |
|
17 |
|
rootStart = dataStart + bpb.sectorsPerCluster*(bpb.rootCluster - 2); |
|
18 |
|
} |
28 |
19 |
|
|
|
20 |
|
void |
|
21 |
|
FAT::printFiles() |
|
22 |
|
{ |
29 |
23 |
DirectoryEntryFat32 dirent[16]; |
DirectoryEntryFat32 dirent[16]; |
30 |
24 |
hd.read28(rootStart, reinterpret_cast<std::uint8_t *>(&dirent[0]), |
hd.read28(rootStart, reinterpret_cast<std::uint8_t *>(&dirent[0]), |
31 |
25 |
16*sizeof(DirectoryEntryFat32)); |
16*sizeof(DirectoryEntryFat32)); |
|
... |
... |
fs::readBiosBlock(drv::ATA &hd, std::uint32_t partitionOffset) |
47 |
41 |
|
|
48 |
42 |
// Skip directories. |
// Skip directories. |
49 |
43 |
if (!(dirent[i].attributes & 0x10)) { |
if (!(dirent[i].attributes & 0x10)) { |
50 |
|
printFileContents(dirent[i], hd, bpb, fatStart, dataStart); |
|
|
44 |
|
printFileContents(dirent[i]); |
51 |
45 |
} |
} |
52 |
46 |
} |
} |
53 |
47 |
} |
} |
54 |
48 |
|
|
55 |
|
static void |
|
56 |
|
printFileContents(const DirectoryEntryFat32 &ent, drv::ATA &hd, |
|
57 |
|
const BiosParameterBlock32 &bpb, std::uint32_t fatStart, |
|
58 |
|
std::uint32_t dataStart) |
|
|
49 |
|
void |
|
50 |
|
FAT::printFileContents(const DirectoryEntryFat32 &ent) const |
59 |
51 |
{ |
{ |
60 |
52 |
std::uint32_t firstCluster = ent.firstClusterHi; |
std::uint32_t firstCluster = ent.firstClusterHi; |
61 |
53 |
firstCluster = (firstCluster << 16) | ent.firstClusterLow; |
firstCluster = (firstCluster << 16) | ent.firstClusterLow; |
File src/fs/mbr.cpp changed (mode: 100644) (index dd4f59c..4b977ad) |
... |
... |
MBR::readPartitions(drv::ATA &hd) |
31 |
31 |
kprint(" Partition ", i, is, " bootable. Type 0x", |
kprint(" Partition ", i, is, " bootable. Type 0x", |
32 |
32 |
mbr.primaryPartition[i].partition_id, ".\n"); |
mbr.primaryPartition[i].partition_id, ".\n"); |
33 |
33 |
|
|
34 |
|
readBiosBlock(hd, mbr.primaryPartition[i].start_lba); |
|
|
34 |
|
FAT fat(hd, mbr.primaryPartition[i].start_lba); |
|
35 |
|
fat.printFiles(); |
35 |
36 |
} |
} |
36 |
37 |
} |
} |