diff --git a/.gitignore b/.gitignore index ca86d52..b93b08b 100644 --- a/.gitignore +++ b/.gitignore @@ -26,3 +26,7 @@ tags # VIM *~ *.swp + +# Doxygen + +diskimg/doc/ diff --git a/diskimg/DOS33.cpp b/diskimg/DOS33.cpp index af71f9c..d41ad4c 100644 --- a/diskimg/DOS33.cpp +++ b/diskimg/DOS33.cpp @@ -835,6 +835,9 @@ DIError DiskFSDOS33::ProcessCatalogSector(int catTrack, int catSect, break; } + memcpy(pFile->fRawFileName, &pEntry[0x03], A2FileDOS::kMaxFileName); + pFile->fRawFileName[A2FileDOS::kMaxFileName] = '\0'; + memcpy(pFile->fFileName, &pEntry[0x03], A2FileDOS::kMaxFileName); pFile->fFileName[A2FileDOS::kMaxFileName] = '\0'; pFile->FixFilename(); @@ -860,7 +863,6 @@ DIError DiskFSDOS33::ProcessCatalogSector(int catTrack, int catSect, return kDIErrNone; } - /* * Perform consistency checks on the filesystem. * @@ -2869,6 +2871,19 @@ bail: 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; +} + /* * =========================================================================== diff --git a/diskimg/DiskImg.cpp b/diskimg/DiskImg.cpp index bcf4e8f..2404a8d 100644 --- a/diskimg/DiskImg.cpp +++ b/diskimg/DiskImg.cpp @@ -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. diff --git a/diskimg/DiskImg.h b/diskimg/DiskImg.h index 78d81b9..e57b28d 100644 --- a/diskimg/DiskImg.h +++ b/diskimg/DiskImg.h @@ -1474,6 +1474,11 @@ public: * means that embedded nulls in HFS filenames (which are discouraged but * 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 * together. This makes it much easier to construct a hierarchy out of * 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* 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 uint32_t GetFileType(void) const = 0; virtual uint32_t GetAuxType(void) const = 0; diff --git a/diskimg/DiskImgDetail.h b/diskimg/DiskImgDetail.h index 8b31b7e..ca33017 100644 --- a/diskimg/DiskImgDetail.h +++ b/diskimg/DiskImgDetail.h @@ -1444,6 +1444,7 @@ public: */ virtual const char* GetFileName(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 uint32_t GetFileType(void) const override; virtual uint32_t GetAuxType(void) const override { return fAuxType; } @@ -1482,6 +1483,7 @@ private: short fTSListSector; uint16_t fLengthInSectors; bool fLocked; + char fRawFileName[kMaxFileName + 1]; // "raw" version char fFileName[kMaxFileName+1]; // "fixed" version FileType fFileType; @@ -2493,6 +2495,7 @@ public: */ virtual const char* GetFileName(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 uint32_t GetFileType(void) const override; virtual uint32_t GetAuxType(void) const override { return fLoadAddr; } @@ -2518,6 +2521,7 @@ public: /* fields pulled out of directory block */ char fFileName[kMaxFileName+1]; + char fRawFileName[kMaxFileName + 1]; FileType fFileType; uint16_t fNumSectors; uint16_t fLoadAddr; diff --git a/diskimg/ImageWrapper.cpp b/diskimg/ImageWrapper.cpp index db2b203..efcdade 100644 --- a/diskimg/ImageWrapper.cpp +++ b/diskimg/ImageWrapper.cpp @@ -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 '-'. * (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)) hdrBuf[0]++; memcpy(&hdrBuf[1], pHeader->diskName, hdrBuf[0]); diff --git a/diskimg/RDOS.cpp b/diskimg/RDOS.cpp index e6ac8c7..7cc698e 100644 --- a/diskimg/RDOS.cpp +++ b/diskimg/RDOS.cpp @@ -344,6 +344,9 @@ DIError DiskFSRDOS::ReadCatalog(void) pFile = new A2FileRDOS(this); + memcpy(pFile->fRawFileName, dirPtr, A2FileRDOS::kMaxFileName); + pFile->fRawFileName[A2FileRDOS::kMaxFileName] = '\0'; + memcpy(pFile->fFileName, dirPtr, A2FileRDOS::kMaxFileName); pFile->fFileName[A2FileRDOS::kMaxFileName] = '\0'; pFile->FixFilename(); @@ -521,6 +524,19 @@ DIError A2FileRDOS::Open(A2FileDescr** ppOpenFile, bool readOnly, 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; +} + /* * =========================================================================== diff --git a/linux/MakeDisk.cpp b/linux/MakeDisk.cpp index 38cb505..d97d188 100644 --- a/linux/MakeDisk.cpp +++ b/linux/MakeDisk.cpp @@ -13,6 +13,8 @@ #include #include #include +#include +#include #include "../diskimg/DiskImg.h" using namespace DiskImgLib; @@ -97,7 +99,21 @@ CopyFiles(DiskFS* pDiskFS, int argc, char** argv) }; + argv--; 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); /* @@ -148,6 +164,11 @@ CopyFiles(DiskFS* pDiskFS, int argc, char** argv) } len = ftell(fp); + if (len >= 1L<<31) { // 2GB + fprintf(stderr, "Warning: file '%s' too large, skipping\n", *argv); + fclose(fp); + continue; + } rewind(fp); buf = new char[len]; @@ -199,11 +220,6 @@ CopyFiles(DiskFS* pDiskFS, int argc, char** argv) pNewFile->GetPathName(), DIStrError(dierr)); return -1; } - - /* - * On to the next file. - */ - argv++; } return 0;