| 396 | |
| 397 | public: |
| 398 | void putFile(const Path& path, const Bytes& bytes) override |
| 399 | { |
| 400 | mount(); |
| 401 | if (path.size() != 1) |
| 402 | throw BadPathException(); |
| 403 | |
| 404 | /* Test to see if the file already exists. */ |
| 405 | |
| 406 | for (int d = 0; d < _config.dir_entries(); d++) |
| 407 | { |
| 408 | std::unique_ptr<Entry> entry = getEntry(d); |
| 409 | if (entry->deleted) |
| 410 | continue; |
| 411 | if (path[0] == entry->combinedFilename()) |
| 412 | throw CannotWriteException(); |
| 413 | } |
| 414 | |
| 415 | /* Write blocks, one at a time. */ |
| 416 | |
| 417 | std::unique_ptr<Entry> entry; |
| 418 | ByteReader br(bytes); |
| 419 | while (!br.eof()) |
| 420 | { |
| 421 | unsigned extent = br.pos / 0x4000; |
| 422 | Bytes block = br.read(_config.block_size()); |
| 423 | |
| 424 | /* Allocate a block and write it. */ |
| 425 | |
| 426 | auto bit = std::find(_bitmap.begin(), _bitmap.end(), false); |
| 427 | if (bit == _bitmap.end()) |
| 428 | throw DiskFullException(); |
| 429 | *bit = true; |
| 430 | unsigned blocknum = bit - _bitmap.begin(); |
| 431 | putCpmBlock(blocknum, block); |
| 432 | |
| 433 | /* Do we need a new directory entry? */ |
| 434 | |
| 435 | if (!entry || |
| 436 | entry->allocation_map[std::size(entry->allocation_map) - 1]) |
| 437 | { |
| 438 | if (entry) |
| 439 | { |
| 440 | entry->records = 0x80; |
| 441 | putEntry(entry); |
| 442 | } |
| 443 | |
| 444 | entry.reset(); |
| 445 | for (int d = 0; d < _config.dir_entries(); d++) |
| 446 | { |
| 447 | entry = getEntry(d); |
| 448 | if (entry->deleted) |
| 449 | break; |
| 450 | entry.reset(); |
| 451 | } |
| 452 | |
| 453 | if (!entry) |
| 454 | throw DiskFullException(); |
| 455 | entry->deleted = false; |
nothing calls this directly
no test coverage detected