This commit is contained in:
Andy McFadden 2021-04-18 17:16:58 -07:00
commit 17689a7b23
8 changed files with 74 additions and 7 deletions

4
.gitignore vendored
View File

@ -26,3 +26,7 @@ tags
# VIM # VIM
*~ *~
*.swp *.swp
# Doxygen
diskimg/doc/

View File

@ -835,6 +835,9 @@ DIError DiskFSDOS33::ProcessCatalogSector(int catTrack, int catSect,
break; break;
} }
memcpy(pFile->fRawFileName, &pEntry[0x03], A2FileDOS::kMaxFileName);
pFile->fRawFileName[A2FileDOS::kMaxFileName] = '\0';
memcpy(pFile->fFileName, &pEntry[0x03], A2FileDOS::kMaxFileName); memcpy(pFile->fFileName, &pEntry[0x03], A2FileDOS::kMaxFileName);
pFile->fFileName[A2FileDOS::kMaxFileName] = '\0'; pFile->fFileName[A2FileDOS::kMaxFileName] = '\0';
pFile->FixFilename(); pFile->FixFilename();
@ -860,7 +863,6 @@ DIError DiskFSDOS33::ProcessCatalogSector(int catTrack, int catSect,
return kDIErrNone; return kDIErrNone;
} }
/* /*
* Perform consistency checks on the filesystem. * Perform consistency checks on the filesystem.
* *
@ -2869,6 +2871,19 @@ bail:
return dierr; return dierr;
} }
/*
* Returns the raw filename.
*
* If a pointer to a size_t is passed in, it will be filled with the
* raw filename length.
*/
const char* A2FileDOS::GetRawFileName(size_t* size) const {
if (size) {
*size = strlen(fRawFileName);
}
return fRawFileName;
}
/* /*
* =========================================================================== * ===========================================================================

View File

@ -292,6 +292,12 @@ void DiskImg::SetCustomNibbleDescr(const NibbleDescr* pDescr)
} }
} }
const char* A2File::GetRawFileName(size_t* size) const { // get unmodified file name
if (size) {
*size = strlen(GetFileName());
}
return GetFileName();
}
/* /*
* Open a volume or a file on disk. * Open a volume or a file on disk.

View File

@ -1474,6 +1474,11 @@ public:
* means that embedded nulls in HFS filenames (which are discouraged but * means that embedded nulls in HFS filenames (which are discouraged but
* allowed) will be lost. * allowed) will be lost.
* *
* The original unmodified filename is availale through GetRawFileName,
* which can be optionally passed a size_t pointer to get the size
* of the raw file name, which is helpful for getting a HFS filename with
* embedded nulls.
*
* We do guarantee that the contents of subdirectories are grouped * We do guarantee that the contents of subdirectories are grouped
* together. This makes it much easier to construct a hierarchy out of * together. This makes it much easier to construct a hierarchy out of
* the linear list. This becomes important when dynamically adding * the linear list. This becomes important when dynamically adding
@ -1481,6 +1486,7 @@ public:
*/ */
virtual const char* GetFileName(void) const = 0; // name of this file virtual const char* GetFileName(void) const = 0; // name of this file
virtual const char* GetPathName(void) const = 0; // full path virtual const char* GetPathName(void) const = 0; // full path
virtual const char* GetRawFileName(size_t* size = NULL) const; // get unmodified file name
virtual char GetFssep(void) const = 0; // '\0' if none virtual char GetFssep(void) const = 0; // '\0' if none
virtual uint32_t GetFileType(void) const = 0; virtual uint32_t GetFileType(void) const = 0;
virtual uint32_t GetAuxType(void) const = 0; virtual uint32_t GetAuxType(void) const = 0;

View File

@ -1444,6 +1444,7 @@ public:
*/ */
virtual const char* GetFileName(void) const override { return fFileName; } virtual const char* GetFileName(void) const override { return fFileName; }
virtual const char* GetPathName(void) const override { return fFileName; } virtual const char* GetPathName(void) const override { return fFileName; }
virtual const char* GetRawFileName(size_t* size = NULL) const override;
virtual char GetFssep(void) const override { return '\0'; } virtual char GetFssep(void) const override { return '\0'; }
virtual uint32_t GetFileType(void) const override; virtual uint32_t GetFileType(void) const override;
virtual uint32_t GetAuxType(void) const override { return fAuxType; } virtual uint32_t GetAuxType(void) const override { return fAuxType; }
@ -1482,6 +1483,7 @@ private:
short fTSListSector; short fTSListSector;
uint16_t fLengthInSectors; uint16_t fLengthInSectors;
bool fLocked; bool fLocked;
char fRawFileName[kMaxFileName + 1]; // "raw" version
char fFileName[kMaxFileName+1]; // "fixed" version char fFileName[kMaxFileName+1]; // "fixed" version
FileType fFileType; FileType fFileType;
@ -2493,6 +2495,7 @@ public:
*/ */
virtual const char* GetFileName(void) const override { return fFileName; } virtual const char* GetFileName(void) const override { return fFileName; }
virtual const char* GetPathName(void) const override { return fFileName; } virtual const char* GetPathName(void) const override { return fFileName; }
virtual const char* GetRawFileName(size_t* size = NULL) const override;
virtual char GetFssep(void) const override { return '\0'; } virtual char GetFssep(void) const override { return '\0'; }
virtual uint32_t GetFileType(void) const override; virtual uint32_t GetFileType(void) const override;
virtual uint32_t GetAuxType(void) const override { return fLoadAddr; } virtual uint32_t GetAuxType(void) const override { return fLoadAddr; }
@ -2518,6 +2521,7 @@ public:
/* fields pulled out of directory block */ /* fields pulled out of directory block */
char fFileName[kMaxFileName+1]; char fFileName[kMaxFileName+1];
char fRawFileName[kMaxFileName + 1];
FileType fFileType; FileType fFileType;
uint16_t fNumSectors; uint16_t fNumSectors;
uint16_t fLoadAddr; uint16_t fLoadAddr;

View File

@ -1145,7 +1145,7 @@ DIError WrapperDiskCopy42::WriteHeader(GenericFD* pGFD, const DC42Header* pHeade
* magic string. To be safe, we only increment it if it starts with '-'. * magic string. To be safe, we only increment it if it starts with '-'.
* (Need access to a Macintosh to test this.) * (Need access to a Macintosh to test this.)
*/ */
hdrBuf[0] = strlen(pHeader->diskName); hdrBuf[0] = (uint8_t) (strlen(pHeader->diskName) & 0xff);
if (pHeader->diskName[0] == '-' && hdrBuf[0] < (kDC42NameLen-1)) if (pHeader->diskName[0] == '-' && hdrBuf[0] < (kDC42NameLen-1))
hdrBuf[0]++; hdrBuf[0]++;
memcpy(&hdrBuf[1], pHeader->diskName, hdrBuf[0]); memcpy(&hdrBuf[1], pHeader->diskName, hdrBuf[0]);

View File

@ -344,6 +344,9 @@ DIError DiskFSRDOS::ReadCatalog(void)
pFile = new A2FileRDOS(this); pFile = new A2FileRDOS(this);
memcpy(pFile->fRawFileName, dirPtr, A2FileRDOS::kMaxFileName);
pFile->fRawFileName[A2FileRDOS::kMaxFileName] = '\0';
memcpy(pFile->fFileName, dirPtr, A2FileRDOS::kMaxFileName); memcpy(pFile->fFileName, dirPtr, A2FileRDOS::kMaxFileName);
pFile->fFileName[A2FileRDOS::kMaxFileName] = '\0'; pFile->fFileName[A2FileRDOS::kMaxFileName] = '\0';
pFile->FixFilename(); pFile->FixFilename();
@ -521,6 +524,19 @@ DIError A2FileRDOS::Open(A2FileDescr** ppOpenFile, bool readOnly,
return kDIErrNone; return kDIErrNone;
} }
/*
* Returns the raw filename.
*
* If a pointer to a size_t is passed in, it will be filled with the
* raw filename length.
*/
const char* A2FileRDOS::GetRawFileName(size_t* size) const {
if (size) {
*size = strlen(fRawFileName);
}
return fRawFileName;
}
/* /*
* =========================================================================== * ===========================================================================

View File

@ -13,6 +13,8 @@
#include <time.h> #include <time.h>
#include <errno.h> #include <errno.h>
#include <assert.h> #include <assert.h>
#include <sys/types.h>
#include <sys/stat.h>
#include "../diskimg/DiskImg.h" #include "../diskimg/DiskImg.h"
using namespace DiskImgLib; using namespace DiskImgLib;
@ -97,7 +99,21 @@ CopyFiles(DiskFS* pDiskFS, int argc, char** argv)
}; };
argv--;
while (argc--) { while (argc--) {
argv++;
// Confirm this is a regular file, and not a directory.
struct stat sb;
if (stat(*argv, &sb) != 0) {
fprintf(stderr, "Warning: unable to stat '%s'\n", *argv);
continue;
}
if ((sb.st_mode & S_IFREG) == 0) {
printf("--- Skipping '%s'\n", *argv);
continue;
}
printf("+++ Adding '%s'\n", *argv); printf("+++ Adding '%s'\n", *argv);
/* /*
@ -148,6 +164,11 @@ CopyFiles(DiskFS* pDiskFS, int argc, char** argv)
} }
len = ftell(fp); len = ftell(fp);
if (len >= 1L<<31) { // 2GB
fprintf(stderr, "Warning: file '%s' too large, skipping\n", *argv);
fclose(fp);
continue;
}
rewind(fp); rewind(fp);
buf = new char[len]; buf = new char[len];
@ -199,11 +220,6 @@ CopyFiles(DiskFS* pDiskFS, int argc, char** argv)
pNewFile->GetPathName(), DIStrError(dierr)); pNewFile->GetPathName(), DIStrError(dierr));
return -1; return -1;
} }
/*
* On to the next file.
*/
argv++;
} }
return 0; return 0;