diff options
-rw-r--r-- | bin/gensquashfs/src/fstree_from_file.c | 31 | ||||
-rw-r--r-- | bin/gensquashfs/src/mkfs.c | 3 | ||||
-rw-r--r-- | include/util/dir_tree_iterator.h | 11 | ||||
-rw-r--r-- | lib/util/src/dir_tree_iterator.c | 20 | ||||
-rw-r--r-- | lib/util/test/dir_tree_iterator.c | 51 |
5 files changed, 89 insertions, 27 deletions
diff --git a/bin/gensquashfs/src/fstree_from_file.c b/bin/gensquashfs/src/fstree_from_file.c index 77f9ebd..8f1b50b 100644 --- a/bin/gensquashfs/src/fstree_from_file.c +++ b/bin/gensquashfs/src/fstree_from_file.c @@ -21,17 +21,13 @@ struct glob_context { const char *filename; size_t line_num; - struct stat *basic; unsigned int glob_flags; char *name_pattern; }; enum { - GLOB_MODE_FROM_SRC = 0x01, - GLOB_UID_FROM_SRC = 0x02, - GLOB_GID_FROM_SRC = 0x04, - GLOB_FLAG_PATH = 0x08, + GLOB_FLAG_PATH = 0x00010000, }; static const struct { @@ -167,17 +163,6 @@ static int glob_node_callback(void *user, tree_node_t *root, dir_entry_t *ent) struct glob_context *ctx = user; int ret; - if (!(ctx->glob_flags & GLOB_MODE_FROM_SRC)) { - ent->mode &= ~(07777); - ent->mode |= ctx->basic->st_mode & 07777; - } - - if (!(ctx->glob_flags & GLOB_UID_FROM_SRC)) - ent->uid = ctx->basic->st_uid; - - if (!(ctx->glob_flags & GLOB_GID_FROM_SRC)) - ent->gid = ctx->basic->st_gid; - if (ctx->name_pattern != NULL) { if (ctx->glob_flags & GLOB_FLAG_PATH) { char *path = full_path(root, ent); @@ -256,7 +241,6 @@ static int glob_files(fstree_t *fs, const char *filename, size_t line_num, memset(&ctx, 0, sizeof(ctx)); ctx.filename = filename; ctx.line_num = line_num; - ctx.basic = basic; ctx.glob_flags = glob_flags; /* fetch the actual target node */ @@ -365,8 +349,11 @@ static int glob_files(fstree_t *fs, const char *filename, size_t line_num, /* do the scan */ memset(&cfg, 0, sizeof(cfg)); - cfg.flags = scan_flags; - cfg.def_mtime = fs->defaults.mtime; + cfg.flags = scan_flags | glob_flags; + cfg.def_mtime = basic->st_mtime; + cfg.def_uid = basic->st_uid; + cfg.def_gid = basic->st_gid; + cfg.def_mode = basic->st_mode; if (basepath == NULL) { dir = dir_tree_iterator_create(extra == NULL ? "." : extra, @@ -530,7 +517,7 @@ static int handle_line(fstree_t *fs, const char *filename, if (cb->is_glob && *line == '*') { ++line; mode = 0; - glob_flags |= GLOB_MODE_FROM_SRC; + glob_flags |= DIR_SCAN_KEEP_MODE; } else { if ((line = read_u32(line, &mode, 8)) == NULL || mode > 07777) goto fail_mode; @@ -542,7 +529,7 @@ static int handle_line(fstree_t *fs, const char *filename, if (cb->is_glob && *line == '*') { ++line; uid = 0; - glob_flags |= GLOB_UID_FROM_SRC; + glob_flags |= DIR_SCAN_KEEP_UID; } else { if ((line = read_u32(line, &uid, 10)) == NULL) goto fail_uid_gid; @@ -554,7 +541,7 @@ static int handle_line(fstree_t *fs, const char *filename, if (cb->is_glob && *line == '*') { ++line; gid = 0; - glob_flags |= GLOB_GID_FROM_SRC; + glob_flags |= DIR_SCAN_KEEP_GID; } else { if ((line = read_u32(line, &gid, 10)) == NULL) goto fail_uid_gid; diff --git a/bin/gensquashfs/src/mkfs.c b/bin/gensquashfs/src/mkfs.c index f2973b6..051b6ac 100644 --- a/bin/gensquashfs/src/mkfs.c +++ b/bin/gensquashfs/src/mkfs.c @@ -171,7 +171,8 @@ int main(int argc, char **argv) int ret; memset(&cfg, 0, sizeof(cfg)); - cfg.flags = opt.dirscan_flags; + cfg.flags = opt.dirscan_flags | DIR_SCAN_KEEP_UID | + DIR_SCAN_KEEP_GID | DIR_SCAN_KEEP_MODE; cfg.def_mtime = sqfs.fs.defaults.mtime; dir = dir_tree_iterator_create(opt.packdir, &cfg); diff --git a/include/util/dir_tree_iterator.h b/include/util/dir_tree_iterator.h index c865738..b5ebe90 100644 --- a/include/util/dir_tree_iterator.h +++ b/include/util/dir_tree_iterator.h @@ -19,12 +19,19 @@ enum { DIR_SCAN_NO_FIFO = 0x0040, DIR_SCAN_KEEP_TIME = 0x0100, - DIR_SCAN_ONE_FILESYSTEM = 0x0200, - DIR_SCAN_NO_RECURSION = 0x0400, + DIR_SCAN_KEEP_UID = 0x0200, + DIR_SCAN_KEEP_GID = 0x0400, + DIR_SCAN_KEEP_MODE = 0x0800, + + DIR_SCAN_ONE_FILESYSTEM = 0x1000, + DIR_SCAN_NO_RECURSION = 0x2000, }; typedef struct { sqfs_u32 flags; + sqfs_u32 def_uid; + sqfs_u32 def_gid; + sqfs_u32 def_mode; sqfs_s64 def_mtime; const char *prefix; } dir_tree_cfg_t; diff --git a/lib/util/src/dir_tree_iterator.c b/lib/util/src/dir_tree_iterator.c index 775039d..55fbabb 100644 --- a/lib/util/src/dir_tree_iterator.c +++ b/lib/util/src/dir_tree_iterator.c @@ -120,6 +120,23 @@ static dir_entry_t *expand_path(const dir_tree_iterator_t *it, dir_entry_t *ent) return ent; } +static void apply_changes(const dir_tree_iterator_t *it, dir_entry_t *ent) +{ + if (!(it->cfg.flags & DIR_SCAN_KEEP_TIME)) + ent->mtime = it->cfg.def_mtime; + + if (!(it->cfg.flags & DIR_SCAN_KEEP_UID)) + ent->uid = it->cfg.def_uid; + + if (!(it->cfg.flags & DIR_SCAN_KEEP_GID)) + ent->gid = it->cfg.def_gid; + + if (!(it->cfg.flags & DIR_SCAN_KEEP_MODE)) { + ent->mode &= ~(07777); + ent->mode |= it->cfg.def_mode & 07777; + } +} + /*****************************************************************************/ static void destroy(sqfs_object_t *obj) @@ -176,8 +193,7 @@ retry: return it->state; } - if (!(it->cfg.flags & DIR_SCAN_KEEP_TIME)) - ent->mtime = it->cfg.def_mtime; + apply_changes(it, ent); if (S_ISDIR(ent->mode)) { if (!(it->cfg.flags & DIR_SCAN_NO_RECURSION)) { diff --git a/lib/util/test/dir_tree_iterator.c b/lib/util/test/dir_tree_iterator.c index 7c1aa88..a45cc30 100644 --- a/lib/util/test/dir_tree_iterator.c +++ b/lib/util/test/dir_tree_iterator.c @@ -29,6 +29,9 @@ int main(int argc, char **argv) (void)argc; (void)argv; memset(&cfg, 0, sizeof(cfg)); + cfg.def_mtime = 1337; + cfg.def_uid = 42; + cfg.def_gid = 23; dir = dir_tree_iterator_create(TEST_PATH, &cfg); TEST_NOT_NULL(dir); @@ -54,36 +57,84 @@ int main(int argc, char **argv) TEST_STR_EQUAL(ent[0]->name, "dira"); TEST_ASSERT(S_ISDIR(ent[0]->mode)); + TEST_EQUAL_UI(ent[0]->mtime, 1337); + TEST_EQUAL_UI(ent[0]->uid, 42); + TEST_EQUAL_UI(ent[0]->gid, 23); TEST_STR_EQUAL(ent[1]->name, "dira/file_a0"); TEST_ASSERT(S_ISREG(ent[1]->mode)); + TEST_EQUAL_UI(ent[1]->mtime, 1337); + TEST_EQUAL_UI(ent[1]->uid, 42); + TEST_EQUAL_UI(ent[1]->gid, 23); TEST_STR_EQUAL(ent[2]->name, "dira/file_a1"); TEST_ASSERT(S_ISREG(ent[2]->mode)); + TEST_EQUAL_UI(ent[2]->mtime, 1337); + TEST_EQUAL_UI(ent[2]->uid, 42); + TEST_EQUAL_UI(ent[2]->gid, 23); TEST_STR_EQUAL(ent[3]->name, "dira/file_a2"); TEST_ASSERT(S_ISREG(ent[3]->mode)); + TEST_EQUAL_UI(ent[3]->mtime, 1337); + TEST_EQUAL_UI(ent[3]->uid, 42); + TEST_EQUAL_UI(ent[3]->gid, 23); TEST_STR_EQUAL(ent[4]->name, "dirb"); TEST_ASSERT(S_ISDIR(ent[4]->mode)); + TEST_EQUAL_UI(ent[4]->mtime, 1337); + TEST_EQUAL_UI(ent[4]->uid, 42); + TEST_EQUAL_UI(ent[4]->gid, 23); TEST_STR_EQUAL(ent[5]->name, "dirb/dirx"); TEST_ASSERT(S_ISDIR(ent[5]->mode)); + TEST_EQUAL_UI(ent[5]->mtime, 1337); + TEST_EQUAL_UI(ent[5]->uid, 42); + TEST_EQUAL_UI(ent[5]->gid, 23); TEST_STR_EQUAL(ent[6]->name, "dirb/dirx/file_x0"); TEST_ASSERT(S_ISREG(ent[6]->mode)); + TEST_EQUAL_UI(ent[6]->mtime, 1337); + TEST_EQUAL_UI(ent[6]->uid, 42); + TEST_EQUAL_UI(ent[6]->gid, 23); TEST_STR_EQUAL(ent[7]->name, "dirb/dirx/file_x1"); TEST_ASSERT(S_ISREG(ent[7]->mode)); + TEST_EQUAL_UI(ent[7]->mtime, 1337); + TEST_EQUAL_UI(ent[7]->uid, 42); + TEST_EQUAL_UI(ent[7]->gid, 23); TEST_STR_EQUAL(ent[8]->name, "dirb/dirx/file_x2"); TEST_ASSERT(S_ISREG(ent[8]->mode)); + TEST_EQUAL_UI(ent[8]->mtime, 1337); + TEST_EQUAL_UI(ent[8]->uid, 42); + TEST_EQUAL_UI(ent[8]->gid, 23); TEST_STR_EQUAL(ent[9]->name, "dirb/file_b0"); TEST_ASSERT(S_ISREG(ent[9]->mode)); + TEST_EQUAL_UI(ent[9]->mtime, 1337); + TEST_EQUAL_UI(ent[9]->uid, 42); + TEST_EQUAL_UI(ent[9]->gid, 23); TEST_STR_EQUAL(ent[10]->name, "dirb/file_b1"); TEST_ASSERT(S_ISREG(ent[10]->mode)); + TEST_EQUAL_UI(ent[10]->mtime, 1337); + TEST_EQUAL_UI(ent[10]->uid, 42); + TEST_EQUAL_UI(ent[10]->gid, 23); TEST_STR_EQUAL(ent[11]->name, "dirb/file_b2"); TEST_ASSERT(S_ISREG(ent[11]->mode)); + TEST_EQUAL_UI(ent[11]->mtime, 1337); + TEST_EQUAL_UI(ent[11]->uid, 42); + TEST_EQUAL_UI(ent[11]->gid, 23); TEST_STR_EQUAL(ent[12]->name, "dirc"); TEST_ASSERT(S_ISDIR(ent[12]->mode)); + TEST_EQUAL_UI(ent[12]->mtime, 1337); + TEST_EQUAL_UI(ent[12]->uid, 42); + TEST_EQUAL_UI(ent[12]->gid, 23); TEST_STR_EQUAL(ent[13]->name, "dirc/file_c0"); TEST_ASSERT(S_ISREG(ent[13]->mode)); + TEST_EQUAL_UI(ent[13]->mtime, 1337); + TEST_EQUAL_UI(ent[13]->uid, 42); + TEST_EQUAL_UI(ent[13]->gid, 23); TEST_STR_EQUAL(ent[14]->name, "dirc/file_c1"); TEST_ASSERT(S_ISREG(ent[14]->mode)); + TEST_EQUAL_UI(ent[14]->mtime, 1337); + TEST_EQUAL_UI(ent[14]->uid, 42); + TEST_EQUAL_UI(ent[14]->gid, 23); TEST_STR_EQUAL(ent[15]->name, "dirc/file_c2"); TEST_ASSERT(S_ISREG(ent[15]->mode)); + TEST_EQUAL_UI(ent[15]->mtime, 1337); + TEST_EQUAL_UI(ent[15]->uid, 42); + TEST_EQUAL_UI(ent[15]->gid, 23); for (i = 0; i < 16; ++i) free(ent[i]); |