15#include "FSDescriptors.h"
17#include "FSDirEntry.h"
19#include "AnyCollection.h"
25class FileSystem : CoreObject {
30 std::vector<BlockPtr> blocks;
35 FSDeviceDescriptor layout;
38 std::vector<FSDirEntry *> dir;
47 FileSystem(isize capacity) { init(capacity); }
48 FileSystem(FSDeviceDescriptor &layout) { init(layout); }
49 FileSystem(DiskType type, DOSType vType) { init(type, vType); }
50 FileSystem(
const class D64File &d64)
throws { init(d64); }
51 FileSystem(
class Disk &disk)
throws { init(disk); }
52 FileSystem(AnyCollection &collection)
throws { init(collection); }
53 FileSystem(MediaFile &file)
throws;
54 FileSystem(
const fs::path &path)
throws { init(path); }
59 void init(isize capacity);
60 void init(FSDeviceDescriptor &layout);
61 void init(DiskType type, DOSType vType);
62 void init(
const class D64File &d64)
throws;
63 void init(
class Disk &disk)
throws;
64 void init(AnyCollection &collection)
throws;
65 void init(MediaFile &file)
throws;
66 void init(
const fs::path &path)
throws;
71 const char *objectName()
const override {
return "FSVolume"; }
87 void printDirectory();
97 DOSType dos()
const {
return layout.dos; }
100 PETName<16> getName()
const;
101 void setName(PETName<16> name);
104 PETName<2> getID()
const;
105 void setID(PETName<2> name);
108 u8 diskId1()
const {
return bamPtr()->data[0xA2]; }
109 u8 diskId2()
const {
return bamPtr()->data[0xA3]; }
112 isize getNumCyls()
const {
return layout.numCyls; }
113 isize getNumHeads()
const {
return layout.numHeads; }
114 isize getNumTracks()
const {
return layout.numTracks(); }
115 isize getNumSectors(Track track)
const {
return layout.numSectors(track); }
116 isize getNumBlocks()
const {
return layout.numBlocks(); }
117 isize getNumBytes()
const {
return getNumBlocks() * 256; }
120 isize freeBlocks()
const;
121 isize usedBlocks()
const;
122 isize freeBytes()
const {
return freeBlocks() * 256; }
123 isize usedBytes()
const {
return usedBlocks() * 256; }
124 double fillLevel()
const {
return double(100) * usedBlocks() / getNumBlocks(); }
127 isize numFiles()
const {
return isize(dir.size()); }
137 FSBlockType blockType(Block b)
const;
138 FSBlockType blockType(TSLink ts)
const {
return blockType(layout.blockNr(ts)); }
141 FSUsage usage(Block b, u32 pos)
const;
142 FSUsage usage(TSLink ts, u32 pos)
const {
return usage(layout.blockNr(ts), pos); }
145 u8 getErrorCode(Block b)
const;
146 u8 getErrorCode(TSLink ts)
const {
return getErrorCode(layout.blockNr(ts)); }
147 void setErrorCode(Block b, u8 code);
148 void setErrorCode(TSLink ts, u8 code) { setErrorCode(layout.blockNr(ts), code); }
151 FSBlock *blockPtr(Block b)
const;
152 FSBlock *blockPtr(TSLink ts)
const {
return blockPtr(layout.blockNr(ts)); }
153 FSBlock *bamPtr()
const {
return blocks[357]; }
156 FSBlock *nextBlockPtr(Block b)
const;
157 FSBlock *nextBlockPtr(TSLink ts)
const {
return nextBlockPtr(layout.blockNr(ts)); }
158 FSBlock *nextBlockPtr(FSBlock *ptr)
const;
166 bool isFree(Block b)
const {
return isFree(layout.tsLink(b)); }
167 bool isFree(TSLink ts)
const;
170 TSLink nextFreeBlock(TSLink start)
const;
171 TSLink firstFreeBlock()
const {
return nextFreeBlock({1,0}); }
174 void markAsAllocated(Block b) { setAllocBit(b, 0); }
175 void markAsAllocated(TSLink ts) { setAllocBit(ts, 0); }
177 void markAsFree(Block b) { setAllocBit(b, 1); }
178 void markAsFree(TSLink ts) { setAllocBit(ts, 1); }
180 void setAllocBit(Block b,
bool value) { setAllocBit(layout.tsLink(b), value); }
181 void setAllocBit(TSLink ts,
bool value);
184 std::vector<TSLink> allocate(TSLink ref, u32 n);
185 std::vector<TSLink> allocate(u32 n) {
return allocate( TSLink{1,0}, n); }
190 FSBlock *locateAllocBit(Block b, isize *
byte, isize *bit)
const;
191 FSBlock *locateAllocBit(TSLink ref, isize *
byte, isize *bit)
const;
201 PETName<16> fileName(isize nr)
const;
202 PETName<16> fileName(FSDirEntry *entry)
const;
205 FSFileType fileType(isize nr)
const;
206 FSFileType fileType(FSDirEntry *entry)
const;
209 isize fileSize(isize nr)
const;
210 isize fileSize(FSDirEntry *entry)
const;
213 isize fileBlocks(isize nr)
const;
214 isize fileBlocks(FSDirEntry *entry)
const;
217 u16 loadAddr(isize nr)
const;
218 u16 loadAddr(FSDirEntry *entry)
const;
221 void copyFile(isize nr, u8 *buf, u64 len, u64 offset = 0)
const;
222 void copyFile(FSDirEntry *entry, u8 *buf, u64 len, u64 offset = 0)
const;
225 void scanDirectory(
bool skipInvisible =
true);
233 bool makeFile(PETName<16> name,
const u8 *buf, isize cnt);
237 bool makeFile(PETName<16> name, FSDirEntry *entry,
const u8 *buf, isize cnt);
240 FSDirEntry *getOrCreateNextFreeDirEntry();
250 FSErrorReport check(
bool strict);
253 ErrorCode check(isize blockNr, u32 pos, u8 *expected,
bool strict);
256 bool isBlockNumber(isize nr)
const {
return nr >= 0 && nr < getNumBlocks(); }
259 isize getCorrupted(isize blockNr)
const;
262 bool isCorrupted(isize blockNr)
const {
return getCorrupted(blockNr) != 0; }
265 isize nextCorrupted(isize blockNr)
const;
266 isize prevCorrupted(isize blockNr)
const;
269 bool isCorrupted(isize blockNr, isize n)
const;
272 isize seekCorruptedBlock(isize n)
const;
282 u8 readByte(Block block, isize offset)
const;
283 u8 readByte(TSLink ts, isize offset)
const {
return readByte(layout.blockNr(ts), offset); }
286 string ascii(Block nr, isize offset, isize len)
const;
289 void importVolume(
const u8 *src, isize size)
throws;
290 bool importVolume(
const u8 *src, isize size, ErrorCode *err);
293 void importDirectory(
const fs::path &path)
throws;
294 void importDirectory(
const fs::directory_entry &dir)
throws;
297 bool exportVolume(u8 *dst, isize size, ErrorCode *err =
nullptr);
300 bool exportBlock(isize nr, u8 *dst, isize size, ErrorCode *err =
nullptr);
301 bool exportBlocks(isize first, isize last, u8 *dst, isize size, ErrorCode *err =
nullptr);
304 void exportDirectory(
const fs::path &path,
bool createDir =
true) throws;
305 void exportFile(FSDirEntry *item, const fs::path &path) throws;
306 void exportFile(FSDirEntry *entry, std::ofstream &stream) throws;
314 FSBlockType getDisplayType(isize column);
317 isize diagnoseImageSlice(isize column);
320 isize nextBlockOfType(FSBlockType type, isize after);
323 isize nextCorruptedBlock(isize after);
VirtualC64 project namespace.
Definition CmdQueue.cpp:16