diff options
author | 2025-03-02 22:32:09 -0500 | |
---|---|---|
committer | 2025-03-02 22:32:09 -0500 | |
commit | 7e62c257243f2fd1b1d29570271e51d6336ebfb9 (patch) | |
tree | 73178285154a3400168eab01d7c04c22f208fb72 /src/lib/formats/fs_coco_os9.cpp | |
parent | acf0aeaa4bb4c149faee749043d575875feb53a2 (diff) |
fsblk.cpp: Internal overhaul
- Replace custom reference counting wrapper with std::shared_ptr
- Rename fsblk_t::block_t::copy to write and use it in a few more places
- Add fsblk_t::block_t::read
- Rename fsblk_t::block_t::offset and rooffset due to name collisions and privatize these helper functions
- Rename fsblk_t::fill to fill_all for clarity's sake
Diffstat (limited to 'src/lib/formats/fs_coco_os9.cpp')
-rw-r--r-- | src/lib/formats/fs_coco_os9.cpp | 156 |
1 files changed, 78 insertions, 78 deletions
diff --git a/src/lib/formats/fs_coco_os9.cpp b/src/lib/formats/fs_coco_os9.cpp index e261968f69a..8e9d9e8c8d0 100644 --- a/src/lib/formats/fs_coco_os9.cpp +++ b/src/lib/formats/fs_coco_os9.cpp @@ -39,23 +39,23 @@ public: class volume_header { public: - volume_header(fsblk_t::block_t &&block); + volume_header(fsblk_t::block_t::ptr &&block); volume_header(const volume_header &) = delete; volume_header(volume_header &&) = default; - u32 total_sectors() const { return m_block.r24b(0); } - u8 track_size_in_sectors() const { return m_block.r8(3); } - u16 allocation_bitmap_bytes() const { return m_block.r16b(4); } - u16 cluster_size() const { return m_block.r16b(6); } - u32 root_dir_lsn() const { return m_block.r24b(8); } - u16 owner_id() const { return m_block.r16b(11); } - u16 disk_id() const { return m_block.r16b(14); } - u8 format_flags() const { return m_block.r8(16); } - u16 sectors_per_track() const { return m_block.r16b(17); } - u32 bootstrap_lsn() const { return m_block.r24b(21); } - u16 bootstrap_size() const { return m_block.r16b(24); } - util::arbitrary_datetime creation_date() const { return from_os9_date(m_block.r24b(26), m_block.r16b(29)); } - u16 sector_size() const { u16 result = m_block.r16b(104); return result != 0 ? result : 256; } + u32 total_sectors() const { return m_block->r24b(0); } + u8 track_size_in_sectors() const { return m_block->r8(3); } + u16 allocation_bitmap_bytes() const { return m_block->r16b(4); } + u16 cluster_size() const { return m_block->r16b(6); } + u32 root_dir_lsn() const { return m_block->r24b(8); } + u16 owner_id() const { return m_block->r16b(11); } + u16 disk_id() const { return m_block->r16b(14); } + u8 format_flags() const { return m_block->r8(16); } + u16 sectors_per_track() const { return m_block->r16b(17); } + u32 bootstrap_lsn() const { return m_block->r24b(21); } + u16 bootstrap_size() const { return m_block->r16b(24); } + util::arbitrary_datetime creation_date() const { return from_os9_date(m_block->r24b(26), m_block->r16b(29)); } + u16 sector_size() const { u16 result = m_block->r16b(104); return result != 0 ? result : 256; } u8 sides() const { return (format_flags() & 0x01) ? 2 : 1; } bool double_density() const { return (format_flags() & 0x02) != 0; } bool double_track() const { return (format_flags() & 0x04) != 0; } @@ -65,7 +65,7 @@ public: std::string name() const; private: - fsblk_t::block_t m_block; + fsblk_t::block_t::ptr m_block; }; @@ -74,17 +74,17 @@ public: class file_header { public: - file_header(fsblk_t::block_t &&block, std::string &&filename); + file_header(fsblk_t::block_t::ptr &&block, std::string &&filename); file_header(const file_header &) = delete; file_header(file_header &&) = default; file_header &operator=(const file_header &) = delete; file_header &operator=(file_header &&) = default; - u8 attributes() const { return m_block.r8(0); } - u16 owner_id() const { return m_block.r16b(1); } - u8 link_count() const { return m_block.r8(8); } - u32 file_size() const { return m_block.r32b(9); } + u8 attributes() const { return m_block->r8(0); } + u16 owner_id() const { return m_block->r16b(1); } + u8 link_count() const { return m_block->r8(8); } + u32 file_size() const { return m_block->r32b(9); } util::arbitrary_datetime creation_date() const; bool is_directory() const { return (attributes() & 0x80) != 0; } bool is_non_sharable() const { return (attributes() & 0x40) != 0; } @@ -100,8 +100,8 @@ public: void get_sector_map_entry(int entry_number, u32 &start_lsn, u16 &count) const; private: - fsblk_t::block_t m_block; - std::string m_filename; + fsblk_t::block_t::ptr m_block; + std::string m_filename; }; // ctor/dtor @@ -364,7 +364,7 @@ std::pair<std::error_condition, std::vector<u8>> coco_os9_impl::file_read(const std::error_condition coco_os9_impl::format(const meta_data &meta) { // for some reason, the OS-9 world favored filling with 0xE5 - m_blockdev.fill(0xe5); + m_blockdev.fill_all(0xe5); // identify geometry info u8 sectors = 18; // TODO - we need a definitive technique to get the floppy geometry @@ -390,33 +390,33 @@ std::error_condition coco_os9_impl::format(const meta_data &meta) // volume header auto volume_header = m_blockdev.get(0); - volume_header.fill(0x00); - volume_header.w24b(0, lsn_count); // DD.TOT - total secctors - volume_header.w8(3, sectors); // DD.TKS - track size in sectors - volume_header.w16b(4, (allocation_bitmap_bits + 7) / 8); // DD.MAP - allocation bitmap in bytes - volume_header.w16b(6, cluster_size); // DD.BIT - cluster size - volume_header.w24b(8, 1 + allocation_bitmap_lsns); // DD.DIR - root directory LSN - volume_header.w16b(11, owner_id); // DD.OWN - owner ID - volume_header.w8(13, attributes); // DD.ATT - Dattributes - volume_header.w16b(14, disk_id); // DD.DSK - disk ID - volume_header.w8(16, format_flags); // DD.FMT - format flags - volume_header.w16b(17, sectors); // DD.SPT - sectors per track - volume_header.w24b(26, creation_os9date); // DD.DAT - date of creation - volume_header.w16b(29, creation_os9time); // DD.DAT - time of creation - volume_header.wstr(31, to_os9_string(volume_title, 32)); // DD.NAM - title - volume_header.w16b(103, sector_bytes / 256); // sector bytes + volume_header->fill(0x00); + volume_header->w24b(0, lsn_count); // DD.TOT - total secctors + volume_header->w8(3, sectors); // DD.TKS - track size in sectors + volume_header->w16b(4, (allocation_bitmap_bits + 7) / 8); // DD.MAP - allocation bitmap in bytes + volume_header->w16b(6, cluster_size); // DD.BIT - cluster size + volume_header->w24b(8, 1 + allocation_bitmap_lsns); // DD.DIR - root directory LSN + volume_header->w16b(11, owner_id); // DD.OWN - owner ID + volume_header->w8(13, attributes); // DD.ATT - Dattributes + volume_header->w16b(14, disk_id); // DD.DSK - disk ID + volume_header->w8(16, format_flags); // DD.FMT - format flags + volume_header->w16b(17, sectors); // DD.SPT - sectors per track + volume_header->w24b(26, creation_os9date); // DD.DAT - date of creation + volume_header->w16b(29, creation_os9time); // DD.DAT - time of creation + volume_header->wstr(31, to_os9_string(volume_title, 32)); // DD.NAM - title + volume_header->w16b(103, sector_bytes / 256); // sector bytes // path descriptor options - volume_header.w8(0x3f + 0x00, 1); // device class - volume_header.w8(0x3f + 0x01, 1); // drive number - volume_header.w8(0x3f + 0x03, 0x20); // device type - volume_header.w8(0x3f + 0x04, 1); // density capability - volume_header.w16b(0x3f + 0x05, tracks); // number of tracks - volume_header.w8(0x3f + 0x07, heads); // number of sides - volume_header.w16b(0x3f + 0x09, sectors); // sectors per track - volume_header.w16b(0x3f + 0x0b, sectors); // sectors on track zero - volume_header.w8(0x3f + 0x0d, 3); // sector interleave factor - volume_header.w8(0x3f + 0x0e, 8); // default sectors per allocation + volume_header->w8(0x3f + 0x00, 1); // device class + volume_header->w8(0x3f + 0x01, 1); // drive number + volume_header->w8(0x3f + 0x03, 0x20); // device type + volume_header->w8(0x3f + 0x04, 1); // density capability + volume_header->w16b(0x3f + 0x05, tracks); // number of tracks + volume_header->w8(0x3f + 0x07, heads); // number of sides + volume_header->w16b(0x3f + 0x09, sectors); // sectors per track + volume_header->w16b(0x3f + 0x0b, sectors); // sectors on track zero + volume_header->w8(0x3f + 0x0d, 3); // sector interleave factor + volume_header->w8(0x3f + 0x0e, 8); // default sectors per allocation // allocation bitmap u32 total_allocated_sectors = 1 + allocation_bitmap_lsns + 1 + 8; @@ -436,34 +436,34 @@ std::error_condition coco_os9_impl::format(const meta_data &meta) } auto abblk = m_blockdev.get(1 + i); - abblk.copy(0, abblk_bytes.data(), sector_bytes); + abblk->write(0, abblk_bytes.data(), sector_bytes); } // root directory header auto roothdr_blk = m_blockdev.get(1 + allocation_bitmap_lsns); - roothdr_blk.fill(0x00); - roothdr_blk.w8(0x00, 0xbf); - roothdr_blk.w8(0x01, 0x00); - roothdr_blk.w8(0x02, 0x00); - roothdr_blk.w24b(0x03, creation_os9date); - roothdr_blk.w16b(0x06, creation_os9time); - roothdr_blk.w8(0x08, 0x01); - roothdr_blk.w8(0x09, 0x00); - roothdr_blk.w8(0x0a, 0x00); - roothdr_blk.w8(0x0b, 0x00); - roothdr_blk.w8(0x0c, 0x40); - roothdr_blk.w24b(0x0d, creation_os9date); - roothdr_blk.w24b(0x10, 1 + allocation_bitmap_lsns + 1); - roothdr_blk.w16b(0x13, 8); + roothdr_blk->fill(0x00); + roothdr_blk->w8(0x00, 0xbf); + roothdr_blk->w8(0x01, 0x00); + roothdr_blk->w8(0x02, 0x00); + roothdr_blk->w24b(0x03, creation_os9date); + roothdr_blk->w16b(0x06, creation_os9time); + roothdr_blk->w8(0x08, 0x01); + roothdr_blk->w8(0x09, 0x00); + roothdr_blk->w8(0x0a, 0x00); + roothdr_blk->w8(0x0b, 0x00); + roothdr_blk->w8(0x0c, 0x40); + roothdr_blk->w24b(0x0d, creation_os9date); + roothdr_blk->w24b(0x10, 1 + allocation_bitmap_lsns + 1); + roothdr_blk->w16b(0x13, 8); // root directory data auto rootdata_blk = m_blockdev.get(1 + allocation_bitmap_lsns + 1); - rootdata_blk.fill(0x00); - rootdata_blk.w8(0x00, 0x2e); - rootdata_blk.w8(0x01, 0xae); - rootdata_blk.w8(0x1f, 1 + allocation_bitmap_lsns); - rootdata_blk.w8(0x20, 0xae); - rootdata_blk.w8(0x3f, 1 + allocation_bitmap_lsns); + rootdata_blk->fill(0x00); + rootdata_blk->w8(0x00, 0x2e); + rootdata_blk->w8(0x01, 0xae); + rootdata_blk->w8(0x1f, 1 + allocation_bitmap_lsns); + rootdata_blk->w8(0x20, 0xae); + rootdata_blk->w8(0x3f, 1 + allocation_bitmap_lsns); return std::error_condition(); } @@ -554,9 +554,9 @@ std::vector<u8> coco_os9_impl::read_file_data(const file_header &header) const for (u32 lsn = start_lsn; lsn < start_lsn + count; lsn++) { auto block = m_blockdev.get(lsn); - size_t block_size = std::min(std::min(u32(m_volume_header.sector_size()), block.size()), header.file_size() - u32(data.size())); + size_t block_size = std::min(std::min(u32(m_volume_header.sector_size()), block->size()), header.file_size() - u32(data.size())); for (auto i = 0; i < block_size; i++) - data.push_back(block.rodata()[i]); + data.push_back(block->rodata()[i]); } } return data; @@ -664,7 +664,7 @@ bool coco_os9_impl::is_ignored_filename(std::string_view name) // volume_header ctor //------------------------------------------------- -coco_os9_impl::volume_header::volume_header(fsblk_t::block_t &&block) +coco_os9_impl::volume_header::volume_header(fsblk_t::block_t::ptr &&block) : m_block(std::move(block)) { } @@ -676,7 +676,7 @@ coco_os9_impl::volume_header::volume_header(fsblk_t::block_t &&block) std::string coco_os9_impl::volume_header::name() const { - std::string_view raw_name((const char *)&m_block.rodata()[31], 32); + std::string_view raw_name(m_block->rstr(31, 32)); return pick_os9_string(raw_name); } @@ -685,7 +685,7 @@ std::string coco_os9_impl::volume_header::name() const // file_header ctor //------------------------------------------------- -coco_os9_impl::file_header::file_header(fsblk_t::block_t &&block, std::string &&filename) +coco_os9_impl::file_header::file_header(fsblk_t::block_t::ptr &&block, std::string &&filename) : m_block(std::move(block)) , m_filename(std::move(filename)) { @@ -698,7 +698,7 @@ coco_os9_impl::file_header::file_header(fsblk_t::block_t &&block, std::string && util::arbitrary_datetime coco_os9_impl::file_header::creation_date() const { - return from_os9_date(m_block.r24b(13)); + return from_os9_date(m_block->r24b(13)); } @@ -735,7 +735,7 @@ meta_data coco_os9_impl::file_header::metadata() const int coco_os9_impl::file_header::get_sector_map_entry_count() const { - return (m_block.size() - 16) / 5; + return (m_block->size() - 16) / 5; } @@ -745,6 +745,6 @@ int coco_os9_impl::file_header::get_sector_map_entry_count() const void coco_os9_impl::file_header::get_sector_map_entry(int entry_number, u32 &start_lsn, u16 &count) const { - start_lsn = m_block.r24b(16 + (entry_number * 5) + 0); - count = m_block.r16b(16 + (entry_number * 5) + 3); + start_lsn = m_block->r24b(16 + (entry_number * 5) + 0); + count = m_block->r16b(16 + (entry_number * 5) + 3); } |