| 190 | } |
| 191 | |
| 192 | Bytes getFile(const Path& path) override |
| 193 | { |
| 194 | mount(); |
| 195 | |
| 196 | auto dir = chdir(path.parent()); |
| 197 | auto dirent = dir->find(path.back()); |
| 198 | |
| 199 | Bytes bytes; |
| 200 | switch (dirent->storageType) |
| 201 | { |
| 202 | case STORAGETYPE_SUBDIR: |
| 203 | throw BadPathException("tried to use a directory like a file"); |
| 204 | |
| 205 | case STORAGETYPE_SEEDLING: |
| 206 | bytes = getLogicalBlock(dirent->keyBlock); |
| 207 | break; |
| 208 | |
| 209 | case STORAGETYPE_SAPLING: |
| 210 | { |
| 211 | auto keyBytes = getLogicalBlock(dirent->keyBlock); |
| 212 | ByteWriter bw(bytes); |
| 213 | readIndexBlock(keyBytes, bw); |
| 214 | break; |
| 215 | } |
| 216 | |
| 217 | case STORAGETYPE_TREE: |
| 218 | { |
| 219 | auto masterKeyBytes = getLogicalBlock(dirent->keyBlock); |
| 220 | ByteWriter bw(bytes); |
| 221 | ByteReader br(masterKeyBytes); |
| 222 | |
| 223 | /* This always appends 16MB of data, the maximum amount |
| 224 | * for a tree file, which is wasteful but simple. |
| 225 | */ |
| 226 | |
| 227 | while (!br.eof()) |
| 228 | { |
| 229 | uint16_t indexBlock = br.read_le16(); |
| 230 | if (indexBlock) |
| 231 | readIndexBlock(getLogicalBlock(indexBlock), bw); |
| 232 | else |
| 233 | bw += Bytes(128 * 1024); |
| 234 | } |
| 235 | break; |
| 236 | } |
| 237 | |
| 238 | default: |
| 239 | throw UnimplementedFilesystemException( |
| 240 | fmt::format("storage type 0x{:x} isn't supported yet", |
| 241 | dirent->storageType)); |
| 242 | } |
| 243 | |
| 244 | return bytes.slice(0, dirent->length); |
| 245 | } |
| 246 | |
| 247 | private: |
| 248 | void mount() |
nothing calls this directly
no test coverage detected