Allow creating empty filesystem images
Support creating empty filesystem images by making the source directory argument optional. Signed-off-by: Jo-Philipp Wich <jo@mein.io>
This commit is contained in:
parent
3af931b0b6
commit
484903e433
@ -45,6 +45,27 @@ static int filter_dot(const struct dirent *d)
|
|||||||
return (strcmp(d->d_name, "..") && strcmp(d->d_name, "."));
|
return (strcmp(d->d_name, "..") && strcmp(d->d_name, "."));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
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 = (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);
|
||||||
|
|
||||||
|
return root_inode;
|
||||||
|
}
|
||||||
|
|
||||||
/* Read a local directory and create the same tree in the generated filesystem.
|
/* Read a local directory and create the same tree in the generated filesystem.
|
||||||
Calls itself recursively with each directory in the given directory.
|
Calls itself recursively with each directory in the given directory.
|
||||||
full_path is an absolute or relative path, with a trailing slash, to the
|
full_path is an absolute or relative path, with a trailing slash, to the
|
||||||
@ -367,11 +388,7 @@ int make_ext4fs_internal(int fd, const char *_directory,
|
|||||||
if (setjmp(setjmp_env))
|
if (setjmp(setjmp_env))
|
||||||
return EXIT_FAILURE; /* Handle a call to longjmp() */
|
return EXIT_FAILURE; /* Handle a call to longjmp() */
|
||||||
|
|
||||||
if (_directory == NULL) {
|
if (_directory)
|
||||||
fprintf(stderr, "Need a source directory\n");
|
|
||||||
return EXIT_FAILURE;
|
|
||||||
}
|
|
||||||
|
|
||||||
directory = canonicalize_rel_slashes(_directory);
|
directory = canonicalize_rel_slashes(_directory);
|
||||||
|
|
||||||
if (info.len <= 0)
|
if (info.len <= 0)
|
||||||
@ -457,11 +474,15 @@ int make_ext4fs_internal(int fd, const char *_directory,
|
|||||||
if (info.feat_compat & EXT4_FEATURE_COMPAT_RESIZE_INODE)
|
if (info.feat_compat & EXT4_FEATURE_COMPAT_RESIZE_INODE)
|
||||||
ext4_create_resize_inode();
|
ext4_create_resize_inode();
|
||||||
|
|
||||||
|
if (directory)
|
||||||
root_inode_num = build_directory_structure(directory, "", 0,
|
root_inode_num = build_directory_structure(directory, "", 0,
|
||||||
fs_config_func, verbose, fixed_time);
|
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;
|
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();
|
ext4_update_free();
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user