From: Michael Tremer Date: Sun, 26 Oct 2014 15:00:03 +0000 (+0100) Subject: installer: Allow to disable creation of swap space on command line X-Git-Tag: v2.17-core87~103^2~45 X-Git-Url: http://git.ipfire.org/?p=ipfire-2.x.git;a=commitdiff_plain;h=a8fca24560c74f0c37a270f93bd957f0c0b981f6 installer: Allow to disable creation of swap space on command line --- diff --git a/src/installer/hw.c b/src/installer/hw.c index e14a47016e..d745260500 100644 --- a/src/installer/hw.c +++ b/src/installer/hw.c @@ -440,7 +440,7 @@ static int hw_device_has_p_suffix(const struct hw_destination* dest) { return 0; } -static int hw_calculate_partition_table(struct hw_destination* dest) { +static int hw_calculate_partition_table(struct hw_destination* dest, int disable_swap) { char path[DEV_SIZE]; int part_idx = 1; @@ -493,9 +493,14 @@ static int hw_calculate_partition_table(struct hw_destination* dest) { } dest->size_boot = hw_boot_size(dest); - dest->size_swap = hw_swap_size(dest); dest->size_root = hw_root_size(dest); + // Should we use swap? + if (disable_swap) + dest->size_swap = 0; + else + dest->size_swap = hw_swap_size(dest); + // Determine the size of the data partition. unsigned long long used_space = dest->size_bootldr + dest->size_boot + dest->size_swap + dest->size_root; @@ -540,7 +545,7 @@ static int hw_calculate_partition_table(struct hw_destination* dest) { return 0; } -struct hw_destination* hw_make_destination(int part_type, struct hw_disk** disks) { +struct hw_destination* hw_make_destination(int part_type, struct hw_disk** disks, int disable_swap) { struct hw_destination* dest = malloc(sizeof(*dest)); if (part_type == HW_PART_TYPE_NORMAL) { @@ -560,7 +565,7 @@ struct hw_destination* hw_make_destination(int part_type, struct hw_disk** disks // Is this a RAID device? dest->is_raid = (part_type > HW_PART_TYPE_NORMAL); - int r = hw_calculate_partition_table(dest); + int r = hw_calculate_partition_table(dest, disable_swap); if (r) return NULL; diff --git a/src/installer/hw.h b/src/installer/hw.h index 83753fdc0d..f16b39cb6a 100644 --- a/src/installer/hw.h +++ b/src/installer/hw.h @@ -111,7 +111,8 @@ unsigned int hw_count_disks(const struct hw_disk** disks); struct hw_disk** hw_select_disks(struct hw_disk** disks, int* selection); struct hw_disk** hw_select_first_disk(const struct hw_disk** disks); -struct hw_destination* hw_make_destination(int part_type, struct hw_disk** disks); +struct hw_destination* hw_make_destination(int part_type, struct hw_disk** disks, + int disable_swap); unsigned long long hw_memory(); diff --git a/src/installer/main.c b/src/installer/main.c index 1d8abb81ba..d3e1c6e3ed 100644 --- a/src/installer/main.c +++ b/src/installer/main.c @@ -231,12 +231,14 @@ static struct config { int serial_console; int require_networking; int perform_download; + int disable_swap; char download_url[STRING_SIZE]; } config = { .unattended = 0, .serial_console = 0, .require_networking = 0, .perform_download = 0, + .disable_swap = 0, .download_url = DOWNLOAD_URL, }; @@ -269,6 +271,10 @@ static void parse_command_line(struct config* c) { else if (strcmp(token, "installer.unattended") == 0) c->unattended = 1; + // disable swap + else if (strcmp(token, "installer.disable-swap") == 0) + c->disable_swap = 1; + // download url else if (strcmp(key, "installer.download-url") == 0) { strncpy(c->download_url, val, sizeof(c->download_url)); @@ -601,7 +607,7 @@ int main(int argc, char *argv[]) { hw_free_disks(disks); - struct hw_destination* destination = hw_make_destination(part_type, selected_disks); + struct hw_destination* destination = hw_make_destination(part_type, selected_disks, config.disable_swap); if (!destination) { errorbox(_("Your harddisk is too small.")); @@ -617,19 +623,21 @@ int main(int argc, char *argv[]) { fprintf(flog, "Memory : %lluMB\n", BYTES2MB(hw_memory())); // Warn the user if there is not enough space to create a swap partition - if (!config.unattended && !*destination->part_swap) { - rc = newtWinChoice(title, _("OK"), _("Cancel"), - _("Your harddisk is very small, but you can continue without a swap partition.")); + if (!config.unattended) { + if (!config.disable_swap && !*destination->part_swap) { + rc = newtWinChoice(title, _("OK"), _("Cancel"), + _("Your harddisk is very small, but you can continue without a swap partition.")); - if (rc != 1) - goto EXIT; + if (rc != 1) + goto EXIT; + } } // Filesystem selection if (!config.unattended) { struct filesystems { int fstype; - const char* description; + char* description; } filesystems[] = { { HW_FS_EXT4, _("ext4 Filesystem") }, { HW_FS_EXT4_WO_JOURNAL, _("ext4 Filesystem without journal") }, @@ -645,7 +653,7 @@ int main(int argc, char *argv[]) { if (HW_FS_DEFAULT == filesystems[i].fstype) fs_choice = i; - fs_names[i] = &filesystems[i].description; + fs_names[i] = filesystems[i].description; } rc = newtWinMenu(_("Filesystem Selection"), _("Please choose your filesystem:"),