Skip to content

Commit

Permalink
Fix MakeDisk utility
Browse files Browse the repository at this point in the history
This addresses two issues: (1) failing to check for regular files;
(2) failing to test for files larger than 2GB.

(issue fadden#44)
  • Loading branch information
fadden committed Nov 7, 2020
1 parent 9de0b42 commit 7c637c4
Showing 1 changed file with 21 additions and 5 deletions.
26 changes: 21 additions & 5 deletions linux/MakeDisk.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@
#include <time.h>
#include <errno.h>
#include <assert.h>
#include <sys/types.h>
#include <sys/stat.h>
#include "../diskimg/DiskImg.h"

using namespace DiskImgLib;
Expand Down Expand Up @@ -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);

/*
Expand Down Expand Up @@ -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];
Expand Down Expand Up @@ -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;
Expand Down

0 comments on commit 7c637c4

Please sign in to comment.