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 "zstring_view.hh"
13 #include <string_view>
14 
15 namespace openmsx {
16 
17 class SectorAccessibleDisk;
18 
19 class MSXtar
20 {
21 public:
22  explicit MSXtar(SectorAccessibleDisk& disk);
23  MSXtar(MSXtar&& other);
24  ~MSXtar();
25 
26  void chdir(std::string_view newRootDir);
27  void mkdir(std::string_view newRootDir);
28  std::string dir();
29  std::string addFile(const std::string& filename);
30  std::string addDir(std::string_view rootDirName);
31  std::string getItemFromDir(std::string_view rootDirName, std::string_view itemName);
32  void getDir(std::string_view rootDirName);
33 
34 private:
35  struct DirEntry {
36  unsigned sector;
37  unsigned index;
38  };
39 
40  void writeLogicalSector(unsigned sector, const SectorBuffer& buf);
41  void readLogicalSector (unsigned sector, SectorBuffer& buf);
42 
43  [[nodiscard]] unsigned clusterToSector(unsigned cluster) const;
44  [[nodiscard]] unsigned sectorToCluster(unsigned sector) const;
45  void parseBootSector(const MSXBootSector& boot);
46  [[nodiscard]] unsigned readFAT(unsigned clNr) const;
47  void writeFAT(unsigned clNr, unsigned val);
48  unsigned findFirstFreeCluster();
49  unsigned findUsableIndexInSector(unsigned sector);
50  unsigned getNextSector(unsigned sector);
51  unsigned appendClusterToSubdir(unsigned sector);
52  DirEntry addEntryToDir(unsigned sector);
53  unsigned addSubdir(std::string_view msxName,
54  unsigned t, unsigned d, unsigned sector);
55  void alterFileInDSK(MSXDirEntry& msxDirEntry, const std::string& hostName);
56  unsigned addSubdirToDSK(zstring_view hostName,
57  std::string_view msxName, unsigned sector);
58  DirEntry findEntryInDir(const std::string& name, unsigned sector,
59  SectorBuffer& sectorBuf);
60  std::string addFileToDSK(const std::string& fullHostName, unsigned sector);
61  std::string recurseDirFill(std::string_view dirName, unsigned sector);
62  void fileExtract(const std::string& resultFile, const MSXDirEntry& dirEntry);
63  void recurseDirExtract(std::string_view dirName, unsigned sector);
64  std::string singleItemExtract(std::string_view dirName, std::string_view itemName,
65  unsigned sector);
66  void chroot(std::string_view newRootDir, bool createDir);
67 
68 private:
70  MemBuffer<SectorBuffer> fatBuffer;
71 
72  unsigned maxCluster;
73  unsigned sectorsPerCluster;
74  unsigned sectorsPerFat;
75  unsigned rootDirStart; // first sector from the root directory
76  unsigned rootDirLast; // last sector from the root directory
77  unsigned chrootSector;
78 
79  bool fatCacheDirty;
80 };
81 
82 } // namespace openmsx
83 
84 #endif
TclObject t
std::string getItemFromDir(std::string_view rootDirName, std::string_view itemName)
Definition: MSXtar.cc:857
MSXtar(SectorAccessibleDisk &disk)
Definition: MSXtar.cc:135
void getDir(std::string_view rootDirName)
Definition: MSXtar.cc:862
std::string addFile(const std::string &filename)
Definition: MSXtar.cc:852
void chdir(std::string_view newRootDir)
Definition: MSXtar.cc:719
void mkdir(std::string_view newRootDir)
Definition: MSXtar.cc:724
std::string addDir(std::string_view rootDirName)
Definition: MSXtar.cc:847
std::string dir()
Definition: MSXtar.cc:690
This class manages the lifetime of a block of memory.
Definition: MemBuffer.hh:29
Like std::string_view, but with the extra guarantee that it refers to a zero-terminated string.
Definition: zstring_view.hh:22
This file implemented 3 utility functions:
Definition: Autofire.cc:9
constexpr const char *const filename