Allow specifying reserved blocks percentage
[project/make_ext4fs.git] / make_ext4fs_main.c
index a6c5f61..88254c3 100644 (file)
 #include <sys/disk.h>
 #endif
 
-#ifdef ANDROID
-#include <private/android_filesystem_config.h>
-#endif
-
-#ifndef USE_MINGW
-#include <selinux/selinux.h>
-#include <selinux/label.h>
-#include <selinux/android.h>
-#else
-struct selabel_handle;
-#endif
-
-#include "make_ext4fs.h"
 #include "ext4_utils.h"
 #include "canned_fs_config.h"
 
-#ifndef USE_MINGW /* O_BINARY is windows-specific flag */
-#define O_BINARY 0
-#endif
-
 extern struct fs_info info;
 
 
@@ -52,7 +35,7 @@ static void usage(char *path)
 {
        fprintf(stderr, "%s [ -l <len> ] [ -j <journal size> ] [ -b <block_size> ]\n", basename(path));
        fprintf(stderr, "    [ -g <blocks per group> ] [ -i <inodes> ] [ -I <inode size> ]\n");
-       fprintf(stderr, "    [ -L <label> ] [ -f ] [ -a <android mountpoint> ]\n");
+       fprintf(stderr, "    [ -m <reserved blocks percent> ] [ -L <label> ] [ -f ]\n");
        fprintf(stderr, "    [ -S file_contexts ] [ -C fs_config ] [ -T timestamp ]\n");
        fprintf(stderr, "    [ -z | -s ] [ -w ] [ -c ] [ -J ] [ -v ] [ -B <block_list_file> ]\n");
        fprintf(stderr, "    <filename> [<directory>]\n");
@@ -63,7 +46,6 @@ int main(int argc, char **argv)
        int opt;
        const char *filename = NULL;
        const char *directory = NULL;
-       char *mountpoint = NULL;
        fs_config_func_t fs_config_func = NULL;
        const char *fs_config_file = NULL;
        int gzip = 0;
@@ -74,13 +56,9 @@ int main(int argc, char **argv)
        int exitcode;
        int verbose = 0;
        time_t fixed_time = -1;
-       struct selabel_handle *sehnd = NULL;
        FILE* block_list_file = NULL;
-#ifndef USE_MINGW
-       struct selinux_opt seopts[] = { { SELABEL_OPT_PATH, "" } };
-#endif
 
-       while ((opt = getopt(argc, argv, "l:j:b:g:i:I:L:a:S:T:C:B:fwzJsctv")) != -1) {
+       while ((opt = getopt(argc, argv, "l:j:b:g:i:I:L:T:C:B:m:fwzJsctv")) != -1) {
                switch (opt) {
                case 'l':
                        info.len = parse_num(optarg);
@@ -106,15 +84,6 @@ int main(int argc, char **argv)
                case 'f':
                        force = 1;
                        break;
-               case 'a':
-#ifdef ANDROID
-                       mountpoint = optarg;
-#else
-                       fprintf(stderr, "can't set android permissions - built without android support\n");
-                       usage(argv[0]);
-                       exit(EXIT_FAILURE);
-#endif
-                       break;
                case 'w':
                        wipe = 1;
                        break;
@@ -133,16 +102,6 @@ int main(int argc, char **argv)
                case 't':
                        fprintf(stderr, "Warning: -t (initialize inode tables) is deprecated\n");
                        break;
-               case 'S':
-#ifndef USE_MINGW
-                       seopts[0].value = optarg;
-                       sehnd = selabel_open(SELABEL_CTX_FILE, seopts, 1);
-                       if (!sehnd) {
-                               perror(optarg);
-                               exit(EXIT_FAILURE);
-                       }
-#endif
-                       break;
                case 'v':
                        verbose = 1;
                        break;
@@ -159,32 +118,21 @@ int main(int argc, char **argv)
                                exit(EXIT_FAILURE);
                        }
                        break;
+               case 'm':
+                       info.reserve_pcnt = strtoul(optarg, NULL, 0);
+                       break;
                default: /* '?' */
                        usage(argv[0]);
                        exit(EXIT_FAILURE);
                }
        }
 
-#if !defined(HOST)
-       // Use only if -S option not requested
-       if (!sehnd && mountpoint) {
-               sehnd = selinux_android_file_context_handle();
-
-               if (!sehnd) {
-                       perror(optarg);
-                       exit(EXIT_FAILURE);
-               }
-       }
-#endif
-
        if (fs_config_file) {
                if (load_canned_fs_config(fs_config_file) < 0) {
                        fprintf(stderr, "failed to load %s\n", fs_config_file);
                        exit(EXIT_FAILURE);
                }
                fs_config_func = canned_fs_config;
-       } else if (mountpoint) {
-               fs_config_func = fs_config;
        }
 
        if (wipe && sparse) {
@@ -217,7 +165,7 @@ int main(int argc, char **argv)
        }
 
        if (strcmp(filename, "-")) {
-               fd = open(filename, O_WRONLY | O_CREAT | O_TRUNC | O_BINARY, 0644);
+               fd = open(filename, O_WRONLY | O_CREAT | O_TRUNC, 0644);
                if (fd < 0) {
                        perror("open");
                        return EXIT_FAILURE;
@@ -226,8 +174,8 @@ int main(int argc, char **argv)
                fd = STDOUT_FILENO;
        }
 
-       exitcode = make_ext4fs_internal(fd, directory, mountpoint, fs_config_func, gzip,
-               sparse, crc, wipe, sehnd, verbose, fixed_time, block_list_file);
+       exitcode = make_ext4fs_internal(fd, directory, fs_config_func, gzip,
+               sparse, crc, wipe, verbose, fixed_time, block_list_file);
        close(fd);
        if (block_list_file)
                fclose(block_list_file);