Whamcloud - gitweb
ext4.5: document the stable_inodes feature
[tools/e2fsprogs.git] / misc / mk_hugefiles.c
index f34fa41..24acca8 100644 (file)
@@ -32,7 +32,9 @@ extern int optind;
 #ifdef HAVE_ERRNO_H
 #include <errno.h>
 #endif
+#ifdef HAVE_SYS_IOCTL_H
 #include <sys/ioctl.h>
+#endif
 #include <sys/types.h>
 #include <sys/stat.h>
 #ifdef HAVE_SYS_SYSMACROS_H
@@ -66,7 +68,7 @@ static char *fn_buf;
 static char *fn_numbuf;
 int zero_hugefile = 1;
 
-#define SYSFS_PATH_LEN 256
+#define SYSFS_PATH_LEN 300
 typedef char sysfs_path_t[SYSFS_PATH_LEN];
 
 #ifndef HAVE_SNPRINTF
@@ -425,7 +427,8 @@ static blk64_t calc_overhead(ext2_filsys fs, blk64_t num)
        e_blocks2 = (e_blocks + extents_per_block - 1) / extents_per_block;
        e_blocks3 = (e_blocks2 + extents_per_block - 1) / extents_per_block;
        e_blocks4 = (e_blocks3 + extents_per_block - 1) / extents_per_block;
-       return e_blocks + e_blocks2 + e_blocks3 + e_blocks4;
+       return (e_blocks + e_blocks2 + e_blocks3 + e_blocks4) *
+               EXT2FS_CLUSTER_RATIO(fs);
 }
 
 /*
@@ -565,7 +568,8 @@ errcode_t mk_hugefiles(ext2_filsys fs, const char *device_name)
                num_blocks = fs_blocks / num_files;
        }
 
-       num_slack += calc_overhead(fs, num_blocks) * num_files;
+       num_slack += (calc_overhead(fs, num_blocks ? num_blocks : fs_blocks) *
+                     num_files);
        num_slack += (num_files / 16) + 1; /* space for dir entries */
        goal = get_start_block(fs, num_slack);
        goal = round_up_align(goal, align, part_offset);