Remove unused function
[project/make_ext4fs.git] / make_ext4fs.c
index fc1802b..cb18161 100644 (file)
@@ -14,7 +14,6 @@
  * limitations under the License.
  */
 
-#include "make_ext4fs.h"
 #include "ext4_utils.h"
 #include "allocate.h"
 #include "contents.h"
@@ -45,28 +44,6 @@ 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)
-{
-       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,
-       };
-       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;
-}
-
-#ifndef USE_MINGW
 /* Read a local directory and create the same tree in the generated filesystem.
    Calls itself recursively with each directory in the given directory.
    full_path is an absolute or relative path, with a trailing slash, to the
@@ -255,7 +232,6 @@ static u32 build_directory_structure(const char *full_path, const char *dir_path
        free(dentries);
        return inode;
 }
-#endif
 
 static u32 compute_block_size()
 {
@@ -314,48 +290,6 @@ static u32 compute_bg_desc_reserve_blocks()
        return bg_desc_reserve_blocks;
 }
 
-void reset_ext4fs_info() {
-       // Reset all the global data structures used by make_ext4fs so it
-       // can be called again.
-       memset(&info, 0, sizeof(info));
-       memset(&aux_info, 0, sizeof(aux_info));
-
-       if (ext4_sparse_file) {
-               sparse_file_destroy(ext4_sparse_file);
-               ext4_sparse_file = NULL;
-       }
-}
-
-int make_ext4fs_sparse_fd(int fd, long long len,
-                               const char *mountpoint)
-{
-       reset_ext4fs_info();
-       info.len = len;
-
-       return make_ext4fs_internal(fd, NULL, mountpoint, NULL, 0, 1, 0, 0, 0, -1, NULL);
-}
-
-int make_ext4fs(const char *filename, long long len,
-                               const char *mountpoint)
-{
-       int fd;
-       int status;
-
-       reset_ext4fs_info();
-       info.len = len;
-
-       fd = open(filename, O_WRONLY | O_CREAT | O_TRUNC, 0644);
-       if (fd < 0) {
-               error_errno("open");
-               return EXIT_FAILURE;
-       }
-
-       status = make_ext4fs_internal(fd, NULL, mountpoint, NULL, 0, 0, 0, 1, 0, -1, NULL);
-       close(fd);
-
-       return status;
-}
-
 /* return a newly-malloc'd string that is a copy of str.  The new string
    is guaranteed to have a trailing slash.  If absolute is true, the new string
    is also guaranteed to have a leading slash.
@@ -417,28 +351,24 @@ static char *canonicalize_rel_slashes(const char *str)
 }
 
 int make_ext4fs_internal(int fd, const char *_directory,
-                                                const char *_mountpoint, fs_config_func_t fs_config_func, int gzip,
+                                                fs_config_func_t fs_config_func, int gzip,
                                                 int sparse, int crc, int wipe,
                                                 int verbose, time_t fixed_time,
                                                 FILE* block_list_file)
 {
        u32 root_inode_num;
        u16 root_mode;
-       char *mountpoint;
        char *directory = NULL;
 
        if (setjmp(setjmp_env))
                return EXIT_FAILURE; /* Handle a call to longjmp() */
 
-       if (_mountpoint == NULL) {
-               mountpoint = strdup("");
-       } else {
-               mountpoint = canonicalize_abs_slashes(_mountpoint);
+       if (_directory == NULL) {
+               fprintf(stderr, "Need a source directory\n");
+               return EXIT_FAILURE;
        }
 
-       if (_directory) {
-               directory = canonicalize_rel_slashes(_directory);
-       }
+       directory = canonicalize_rel_slashes(_directory);
 
        if (info.len <= 0)
                info.len = get_file_size(fd);
@@ -505,6 +435,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);
@@ -522,17 +453,8 @@ int make_ext4fs_internal(int fd, const char *_directory,
        if (info.feat_compat & EXT4_FEATURE_COMPAT_RESIZE_INODE)
                ext4_create_resize_inode();
 
-#ifdef USE_MINGW
-       // Windows needs only 'create an empty fs image' functionality
-       assert(!directory);
-       root_inode_num = build_default_directory_structure(mountpoint);
-#else
-       if (directory)
-               root_inode_num = build_directory_structure(directory, mountpoint, 0,
-                       fs_config_func, verbose, fixed_time);
-       else
-               root_inode_num = build_default_directory_structure(mountpoint);
-#endif
+       root_inode_num = build_directory_structure(directory, "", 0,
+               fs_config_func, verbose, 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);
@@ -542,12 +464,11 @@ int make_ext4fs_internal(int fd, const char *_directory,
        ext4_queue_sb();
 
        if (block_list_file) {
-               size_t dirlen = directory ? strlen(directory) : 0;
+               size_t dirlen = strlen(directory);
                struct block_allocation* p = get_saved_allocation_chain();
                while (p) {
-                       if (directory && strncmp(p->filename, directory, dirlen) == 0) {
-                               // substitute mountpoint for the leading directory in the filename, in the output file
-                               fprintf(block_list_file, "%s%s", mountpoint, p->filename + dirlen);
+                       if (strncmp(p->filename, directory, dirlen) == 0) {
+                               fprintf(block_list_file, "%s", p->filename + dirlen);
                        } else {
                                fprintf(block_list_file, "%s", p->filename);
                        }
@@ -573,7 +494,6 @@ int make_ext4fs_internal(int fd, const char *_directory,
        sparse_file_destroy(ext4_sparse_file);
        ext4_sparse_file = NULL;
 
-       free(mountpoint);
        free(directory);
 
        return 0;