X-Git-Url: http://git.archive.openwrt.org/?a=blobdiff_plain;ds=inline;f=make_ext4fs.c;h=051052bb4b1f1252163049f14b68a6e96e63fca7;hb=HEAD;hp=d25dc0ce0cd3479da921731a0d60b8ba1305479b;hpb=67cbf164c72c2916641e2d4900f7cf497375b4c3;p=project%2Fmake_ext4fs.git diff --git a/make_ext4fs.c b/make_ext4fs.c index d25dc0c..051052b 100644 --- a/make_ext4fs.c +++ b/make_ext4fs.c @@ -33,6 +33,7 @@ #include #include #include +#include /* TODO: Not implemented: Allocating blocks in the same block group as the file inode @@ -44,23 +45,23 @@ static int filter_dot(const struct dirent *d) return (strcmp(d->d_name, "..") && strcmp(d->d_name, ".")); } -static u32 build_default_directory_structure(const char *dir_path) +static u32 build_default_directory_structure(time_t fixed_time) { u32 inode; u32 root_inode; struct dentry dentries = { - .filename = "lost+found", - .file_type = EXT4_FT_DIR, - .mode = S_IRWXU, - .uid = 0, - .gid = 0, - .mtime = 0, + .filename = "lost+found", + .file_type = EXT4_FT_DIR, + .mode = S_IRWXU, + .uid = 0, + .gid = 0, + .mtime = (fixed_time != -1) ? fixed_time : 0, }; root_inode = make_directory(0, 1, &dentries, 1); inode = make_directory(root_inode, 0, NULL, 0); *dentries.inode = inode; inode_set_permissions(inode, dentries.mode, - dentries.uid, dentries.gid, dentries.mtime); + dentries.uid, dentries.gid, dentries.mtime); return root_inode; } @@ -87,6 +88,9 @@ static u32 build_directory_structure(const char *full_path, const char *dir_path u32 dirs = 0; bool needs_lost_and_found = false; + /* alphasort is locale-dependent; let's fix the locale to some sane value */ + setlocale(LC_COLLATE, "C"); + if (full_path) { entries = scandir(full_path, &namelist, filter_dot, (void*)alphasort); if (entries < 0) { @@ -254,12 +258,12 @@ static u32 build_directory_structure(const char *full_path, const char *dir_path return inode; } -static u32 compute_block_size() +static u32 compute_block_size(void) { return 4096; } -static u32 compute_journal_blocks() +static u32 compute_journal_blocks(void) { u32 journal_blocks = DIV_ROUND_UP(info.len, info.block_size) / 64; if (journal_blocks < 1024) @@ -269,17 +273,17 @@ static u32 compute_journal_blocks() return journal_blocks; } -static u32 compute_blocks_per_group() +static u32 compute_blocks_per_group(void) { return info.block_size * 8; } -static u32 compute_inodes() +static u32 compute_inodes(void) { return DIV_ROUND_UP(info.len, info.block_size) / 4; } -static u32 compute_inodes_per_group() +static u32 compute_inodes_per_group(void) { u32 blocks = DIV_ROUND_UP(info.len, info.block_size); u32 block_groups = DIV_ROUND_UP(blocks, info.blocks_per_group); @@ -294,7 +298,7 @@ static u32 compute_inodes_per_group() return inodes; } -static u32 compute_bg_desc_reserve_blocks() +static u32 compute_bg_desc_reserve_blocks(void) { u32 blocks = DIV_ROUND_UP(info.len, info.block_size); u32 block_groups = DIV_ROUND_UP(blocks, info.blocks_per_group); @@ -384,12 +388,8 @@ int make_ext4fs_internal(int fd, const char *_directory, if (setjmp(setjmp_env)) return EXIT_FAILURE; /* Handle a call to longjmp() */ - if (_directory == NULL) { - fprintf(stderr, "Need a source directory\n"); - return EXIT_FAILURE; - } - - directory = canonicalize_rel_slashes(_directory); + if (_directory) + directory = canonicalize_rel_slashes(_directory); if (info.len <= 0) info.len = get_file_size(fd); @@ -456,6 +456,7 @@ int make_ext4fs_internal(int fd, const char *_directory, printf(" Blocks: %"PRIu64"\n", aux_info.len_blocks); printf(" Block groups: %d\n", aux_info.groups); + printf(" Reserved blocks: %"PRIu64"\n", (aux_info.len_blocks / 100) * info.reserve_pcnt); printf(" Reserved block group size: %d\n", info.bg_desc_reserve_blocks); ext4_sparse_file = sparse_file_new(info.block_size, info.len); @@ -473,11 +474,15 @@ int make_ext4fs_internal(int fd, const char *_directory, if (info.feat_compat & EXT4_FEATURE_COMPAT_RESIZE_INODE) ext4_create_resize_inode(); - root_inode_num = build_directory_structure(directory, "", 0, - fs_config_func, verbose, fixed_time); + if (directory) + root_inode_num = build_directory_structure(directory, "", 0, + fs_config_func, verbose, fixed_time); + else + root_inode_num = build_default_directory_structure(fixed_time); root_mode = S_IRWXU | S_IRGRP | S_IXGRP | S_IROTH | S_IXOTH; - inode_set_permissions(root_inode_num, root_mode, 0, 0, 0); + inode_set_permissions(root_inode_num, root_mode, 0, 0, + (fixed_time != 1) ? fixed_time : 0); ext4_update_free();