| 65 | } |
| 66 | |
| 67 | void writeDirectory() |
| 68 | { |
| 69 | Bytes buffer(2048); |
| 70 | ByteWriter bw(buffer); |
| 71 | |
| 72 | int count = 0; |
| 73 | for (const auto& it : directory) |
| 74 | { |
| 75 | const auto& dirent = it.second; |
| 76 | |
| 77 | if (count == DIRECTORY_SIZE) |
| 78 | error("too many files on disk"); |
| 79 | |
| 80 | bw.append(dirent->filename); |
| 81 | for (int i = dirent->filename.size(); i < 8; i++) |
| 82 | bw.write_8(' '); |
| 83 | |
| 84 | bw.write_8(dirent->type); |
| 85 | bw.write_be16(dirent->startSector); |
| 86 | bw.write_8(dirent->sectorCount); |
| 87 | bw.write_be32(0); /* unknown */ |
| 88 | count++; |
| 89 | } |
| 90 | |
| 91 | static const Bytes padding(15); |
| 92 | while (count < DIRECTORY_SIZE) |
| 93 | { |
| 94 | bw.write_8(0xf0); |
| 95 | bw.append(padding); |
| 96 | count++; |
| 97 | } |
| 98 | |
| 99 | file.seekp(0, std::ifstream::beg); |
| 100 | buffer.writeTo(file); |
| 101 | } |
| 102 | |
| 103 | void writeBootSector(const Dirent& dirent, uint16_t checksum) |
| 104 | { |