1
0
mirror of https://github.com/hsoft/collapseos.git synced 2024-11-23 20:18:04 +11:00

cfspack: add the ability to spit a single file

This commit is contained in:
Virgil Dupras 2019-06-02 16:35:41 -04:00
parent c317fbdcf9
commit 8e2a89cea5
2 changed files with 17 additions and 1 deletions

View File

@ -15,6 +15,9 @@ to the filenames under it.
`cfspack` takes an optional second argument, a "fnmatch" pattern. If specified,
only files patching the pattern will be included.
If path is a file, a CFS with a single file will be spit and its name will
exclude the directory part of that filename.
The program errors out if a file name is too long (> 26 bytes) or too big
(> 0x10000 - 0x20 bytes).

View File

@ -3,12 +3,20 @@
#include <dirent.h>
#include <string.h>
#include <fnmatch.h>
#include <sys/stat.h>
#define BLKSIZE 0x100
#define HEADERSIZE 0x20
#define MAX_FN_LEN 25 // 26 - null char
#define MAX_FILE_SIZE (BLKSIZE * 0x100) - HEADERSIZE
int is_regular_file(char *path)
{
struct stat path_stat;
stat(path, &path_stat);
return S_ISREG(path_stat.st_mode);
}
int spitblock(char *fullpath, char *fn)
{
FILE *fp = fopen(fullpath, "r");
@ -124,6 +132,11 @@ int main(int argc, char *argv[])
if (argc == 3) {
pattern = argv[2];
}
if (is_regular_file(srcpath)) {
// special case: just one file
return spitblock(srcpath, basename(srcpath));
} else {
return spitdir(srcpath, "", pattern);
}
}