From 53062ff0bf9e09ac95c32a6adba570eee97f2104 Mon Sep 17 00:00:00 2001 From: Laurent Vivier Date: Wed, 11 Nov 2015 18:42:51 +0100 Subject: [PATCH] emile-mktable: force the size of the disk in the table Signed-off-by: Laurent Vivier --- tools/emile-mktable.c | 33 +++++++++++++++++++++++++-------- 1 file changed, 25 insertions(+), 8 deletions(-) diff --git a/tools/emile-mktable.c b/tools/emile-mktable.c index 292b3bd..19e10c5 100644 --- a/tools/emile-mktable.c +++ b/tools/emile-mktable.c @@ -18,6 +18,7 @@ #include #include #include +#include #include #include @@ -42,12 +43,14 @@ enum { ARG_NONE = 0, ARG_HELP ='h', ARG_EMILEDRIVER = 'e', + ARG_FORCE_SIZE = 'f', }; static struct option long_options[] = { {"help", 0, NULL, ARG_HELP }, {"emiledriver", 1, NULL, ARG_EMILEDRIVER }, + {"force-size", 1, NULL, ARG_FORCE_SIZE }, {NULL, 0, NULL, 0 }, }; @@ -56,15 +59,17 @@ static void usage(int argc, char** argv) fprintf(stderr, "Usage %s [FLAGS] disk\n", argv[0]); fprintf(stderr, "Create and EMILE bootable disk\n"); - fprintf(stderr, " -h, --help display this text\n"); - fprintf(stderr, " -e, --emiledriver=FILE " + fprintf(stderr, " -h, --help display this text\n"); + fprintf(stderr, " -f, --force-size=SECTORS " + "force the size of the disk in the table\n"); + fprintf(stderr, " -e, --emiledriver=FILE " "emiledriver to copy to disk\n"); fprintf(stderr, "\nbuild: \n%s\n", SIGNATURE); } #define BLOCKSIZE (512) -static int emile_mktable(char *filename, char *appledriver) +static int emile_mktable(char *filename, char *appledriver, unsigned long force_size) { struct DriverDescriptor block0; struct Partition *map512; @@ -87,9 +92,13 @@ static int emile_mktable(char *filename, char *appledriver) filename); return -1; } - if (ioctl(fd, BLKGETSIZE, &disk_block_count) == -1) { - fstat(fd, &st); - disk_block_count = (st.st_size + 512 - 1) / 512; + if (force_size == 0) { + if (ioctl(fd, BLKGETSIZE, &disk_block_count) == -1) { + fstat(fd, &st); + disk_block_count = (st.st_size + 512 - 1) / 512; + } + } else { + disk_block_count = force_size; } /* read apple driver */ @@ -242,11 +251,12 @@ int main(int argc, char** argv) int option_index = 0; char* image = NULL; char* emiledriver = NULL; + unsigned long force_size = 0; int c; while(1) { - c = getopt_long(argc, argv, "he:c:", + c = getopt_long(argc, argv, "he:f:", long_options, &option_index); if (c == -1) break; @@ -258,6 +268,13 @@ int main(int argc, char** argv) case ARG_EMILEDRIVER: emiledriver = optarg; break; + case ARG_FORCE_SIZE: + force_size = strtoull(optarg, NULL, 0); + if (force_size == ULONG_MAX && errno == ERANGE) { + fprintf(stderr, "ERROR: invalid size\n"); + return 1; + } + break; } } @@ -275,7 +292,7 @@ int main(int argc, char** argv) emiledriver = DRIVER_PATH; - if (emile_mktable(image, emiledriver)) + if (emile_mktable(image, emiledriver, force_size)) return 1; return 0;