openMSX
MSXtar.hh
Go to the documentation of this file.
1 // This code implements the functionality of my older msxtar program
2 // that could manipulate files and directories on dsk and ide-hd images
3 // Integrating it is seen as temporary bypassing of the need for a
4 // DirAsDisk2 that supports subdirs, partitions etc. since this class will
5 // of those functionalities although not on a dynamic base
6 
7 #ifndef MSXTAR_HH
8 #define MSXTAR_HH
9 
10 #include "MemBuffer.hh"
11 #include "DiskImageUtils.hh"
12 #include <string_view>
13 
14 namespace openmsx {
15 
16 class SectorAccessibleDisk;
17 
18 class MSXtar
19 {
20 public:
21  explicit MSXtar(SectorAccessibleDisk& disk);
22  ~MSXtar();
23 
24  void chdir(std::string_view newRootDir);
25  void mkdir(std::string_view newRootDir);
26  std::string dir();
27  std::string addFile(const std::string& filename);
28  std::string addDir(std::string_view rootDirName);
29  std::string getItemFromDir(std::string_view rootDirName, std::string_view itemName);
30  void getDir(std::string_view rootDirName);
31 
32 private:
33  struct DirEntry {
34  unsigned sector;
35  unsigned index;
36  };
37 
38  void writeLogicalSector(unsigned sector, const SectorBuffer& buf);
39  void readLogicalSector (unsigned sector, SectorBuffer& buf);
40 
41  [[nodiscard]] unsigned clusterToSector(unsigned cluster) const;
42  [[nodiscard]] unsigned sectorToCluster(unsigned sector) const;
43  void parseBootSector(const MSXBootSector& boot);
44  [[nodiscard]] unsigned readFAT(unsigned clnr) const;
45  void writeFAT(unsigned clnr, unsigned val);
46  unsigned findFirstFreeCluster();
47  unsigned findUsableIndexInSector(unsigned sector);
48  unsigned getNextSector(unsigned sector);
49  unsigned appendClusterToSubdir(unsigned sector);
50  DirEntry addEntryToDir(unsigned sector);
51  unsigned addSubdir(std::string_view msxName,
52  unsigned t, unsigned d, unsigned sector);
53  void alterFileInDSK(MSXDirEntry& msxDirEntry, const std::string& hostName);
54  unsigned addSubdirToDSK(const std::string& hostName,
55  std::string_view msxName, unsigned sector);
56  DirEntry findEntryInDir(const std::string& name, unsigned sector,
57  SectorBuffer& sectorBuf);
58  std::string addFileToDSK(const std::string& fullHostName, unsigned sector);
59  std::string recurseDirFill(std::string_view dirName, unsigned sector);
60  void fileExtract(const std::string& resultFile, const MSXDirEntry& dirEntry);
61  void recurseDirExtract(std::string_view dirName, unsigned sector);
62  std::string singleItemExtract(std::string_view dirName, std::string_view itemName,
63  unsigned sector);
64  void chroot(std::string_view newRootDir, bool createDir);
65 
66 private:
68  MemBuffer<SectorBuffer> fatBuffer;
69 
70  unsigned maxCluster;
71  unsigned sectorsPerCluster;
72  unsigned sectorsPerFat;
73  unsigned rootDirStart; // first sector from the root directory
74  unsigned rootDirLast; // last sector from the root directory
75  unsigned chrootSector;
76 
77  bool fatCacheDirty;
78 };
79 
80 } // namespace openmsx
81 
82 #endif
openmsx::SectorAccessibleDisk
Definition: SectorAccessibleDisk.hh:16
openmsx::SectorBuffer
Definition: DiskImageUtils.hh:90
openmsx::MSXtar::mkdir
void mkdir(std::string_view newRootDir)
Definition: MSXtar.cc:710
openmsx::MSXtar::MSXtar
MSXtar(SectorAccessibleDisk &disk)
Definition: MSXtar.cc:134
t
TclObject t
Definition: TclObject_test.cc:264
openmsx::MSXtar::chdir
void chdir(std::string_view newRootDir)
Definition: MSXtar.cc:705
DiskImageUtils.hh
openmsx::MemBuffer
This class manages the lifetime of a block of memory.
Definition: MemBuffer.hh:29
openmsx::MSXtar::addFile
std::string addFile(const std::string &filename)
Definition: MSXtar.cc:838
openmsx::filename
constexpr const char *const filename
Definition: FirmwareSwitch.cc:10
openmsx::MSXtar
Definition: MSXtar.hh:19
MemBuffer.hh
openmsx::MSXtar::dir
std::string dir()
Definition: MSXtar.cc:676
openmsx::MSXtar::addDir
std::string addDir(std::string_view rootDirName)
Definition: MSXtar.cc:833
openmsx::MSXtar::getDir
void getDir(std::string_view rootDirName)
Definition: MSXtar.cc:848
openmsx::MSXtar::~MSXtar
~MSXtar()
Definition: MSXtar.cc:156
openmsx::MSXtar::getItemFromDir
std::string getItemFromDir(std::string_view rootDirName, std::string_view itemName)
Definition: MSXtar.cc:843
openmsx::MSXBootSector
Definition: DiskImageUtils.hh:13
openmsx::MSXDirEntry
Definition: DiskImageUtils.hh:33
openmsx
This file implemented 3 utility functions:
Definition: Autofire.cc:5