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();
24 
25  void chdir(std::string_view newRootDir);
26  void mkdir(std::string_view newRootDir);
27  std::string dir();
28  std::string addFile(const std::string& filename);
29  std::string addDir(std::string_view rootDirName);
30  std::string getItemFromDir(std::string_view rootDirName, std::string_view itemName);
31  void getDir(std::string_view rootDirName);
32 
33 private:
34  struct DirEntry {
35  unsigned sector;
36  unsigned index;
37  };
38 
39  void writeLogicalSector(unsigned sector, const SectorBuffer& buf);
40  void readLogicalSector (unsigned sector, SectorBuffer& buf);
41 
42  [[nodiscard]] unsigned clusterToSector(unsigned cluster) const;
43  [[nodiscard]] unsigned sectorToCluster(unsigned sector) const;
44  void parseBootSector(const MSXBootSector& boot);
45  [[nodiscard]] unsigned readFAT(unsigned clNr) const;
46  void writeFAT(unsigned clNr, unsigned val);
47  unsigned findFirstFreeCluster();
48  unsigned findUsableIndexInSector(unsigned sector);
49  unsigned getNextSector(unsigned sector);
50  unsigned appendClusterToSubdir(unsigned sector);
51  DirEntry addEntryToDir(unsigned sector);
52  unsigned addSubdir(std::string_view msxName,
53  unsigned t, unsigned d, unsigned sector);
54  void alterFileInDSK(MSXDirEntry& msxDirEntry, const std::string& hostName);
55  unsigned addSubdirToDSK(zstring_view hostName,
56  std::string_view msxName, unsigned sector);
57  DirEntry findEntryInDir(const std::string& name, unsigned sector,
58  SectorBuffer& sectorBuf);
59  std::string addFileToDSK(const std::string& fullHostName, unsigned sector);
60  std::string recurseDirFill(std::string_view dirName, unsigned sector);
61  void fileExtract(const std::string& resultFile, const MSXDirEntry& dirEntry);
62  void recurseDirExtract(std::string_view dirName, unsigned sector);
63  std::string singleItemExtract(std::string_view dirName, std::string_view itemName,
64  unsigned sector);
65  void chroot(std::string_view newRootDir, bool createDir);
66 
67 private:
69  MemBuffer<SectorBuffer> fatBuffer;
70 
71  unsigned maxCluster;
72  unsigned sectorsPerCluster;
73  unsigned sectorsPerFat;
74  unsigned rootDirStart; // first sector from the root directory
75  unsigned rootDirLast; // last sector from the root directory
76  unsigned chrootSector;
77 
78  bool fatCacheDirty;
79 };
80 
81 } // namespace openmsx
82 
83 #endif
TclObject t
std::string getItemFromDir(std::string_view rootDirName, std::string_view itemName)
Definition: MSXtar.cc:842
MSXtar(SectorAccessibleDisk &disk)
Definition: MSXtar.cc:135
void getDir(std::string_view rootDirName)
Definition: MSXtar.cc:847
std::string addFile(const std::string &filename)
Definition: MSXtar.cc:837
void chdir(std::string_view newRootDir)
Definition: MSXtar.cc:704
void mkdir(std::string_view newRootDir)
Definition: MSXtar.cc:709
std::string addDir(std::string_view rootDirName)
Definition: MSXtar.cc:832
std::string dir()
Definition: MSXtar.cc:675
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