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.hh"
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(string_view newRootDir);
25  void mkdir(string_view newRootDir);
26  std::string dir();
27  std::string addFile(const std::string& filename);
28  std::string addDir(string_view rootDirName);
29  std::string getItemFromDir(string_view rootDirName, string_view itemName);
30  void getDir(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  unsigned clusterToSector(unsigned cluster);
42  unsigned sectorToCluster(unsigned sector);
43  void parseBootSector(const MSXBootSector& boot);
44  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 getStartCluster(const MSXDirEntry& entry);
50  unsigned appendClusterToSubdir(unsigned sector);
51  DirEntry addEntryToDir(unsigned sector);
52  unsigned addSubdir(const std::string& msxName,
53  unsigned t, unsigned d, unsigned sector);
54  void alterFileInDSK(MSXDirEntry& msxDirEntry, const std::string& hostName);
55  unsigned addSubdirToDSK(const std::string& hostName,
56  const std::string& 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(string_view dirName, unsigned sector);
61  std::string condensName(const MSXDirEntry& dirEntry);
62  void changeTime (const std::string& resultFile, const MSXDirEntry& dirEntry);
63  void fileExtract(const std::string& resultFile, const MSXDirEntry& dirEntry);
64  void recurseDirExtract(string_view dirName, unsigned sector);
65  std::string singleItemExtract(string_view dirName, string_view itemName,
66  unsigned sector);
67  void chroot(string_view newRootDir, bool createDir);
68 
69 
71  MemBuffer<SectorBuffer> fatBuffer;
72 
73  unsigned maxCluster;
74  unsigned sectorsPerCluster;
75  unsigned sectorsPerFat;
76  unsigned rootDirStart; // first sector from the root directory
77  unsigned rootDirLast; // last sector from the root directory
78  unsigned chrootSector;
79 
80  bool fatCacheDirty;
81 };
82 
83 } // namespace openmsx
84 
85 #endif
void getDir(string_view rootDirName)
Definition: MSXtar.cc:866
void mkdir(string_view newRootDir)
Definition: MSXtar.cc:725
void chdir(string_view newRootDir)
Definition: MSXtar.cc:720
std::string dir()
Definition: MSXtar.cc:690
Thanks to enen for testing this on a real cartridge:
Definition: Autofire.cc:5
This class implements a (close approximation) of the std::string_view class.
Definition: string_view.hh:15
This class manages the lifetime of a block of memory.
Definition: MemBuffer.hh:37
std::string addDir(string_view rootDirName)
Definition: MSXtar.cc:851
MSXtar(SectorAccessibleDisk &disk)
Definition: MSXtar.cc:132
std::string getItemFromDir(string_view rootDirName, string_view itemName)
Definition: MSXtar.cc:861
std::string addFile(const std::string &filename)
Definition: MSXtar.cc:856