From 573d7d4ac666ed311c78ab5b08b73f2fb921cf65 Mon Sep 17 00:00:00 2001 From: Markus Volk Date: Wed, 9 May 2018 11:48:26 +0200 Subject: [PATCH] hdd_menu.cpp: add support for sgdisk; fix sfdisk usage Signed-off-by: Markus Volk Signed-off-by: Thilo Graf - sfdisk is used primarily - ensures detection of large hard drives - using gpt tables with sfdisk or sgdisk Note: busybox fdisk doesn't support gpt tables and no large hard disks, but fallback to old behavior should work unchanged newer util versions of fdisk can do this but with different syntax. Please test. --- src/gui/hdd_menu.cpp | 22 +++++++++++++++------- 1 file changed, 15 insertions(+), 7 deletions(-) diff --git a/src/gui/hdd_menu.cpp b/src/gui/hdd_menu.cpp index 5d5c01ecd..a99069a7b 100644 --- a/src/gui/hdd_menu.cpp +++ b/src/gui/hdd_menu.cpp @@ -998,7 +998,7 @@ int CHDDMenuHandler::formatDevice(std::string dev) int res; FILE * f; CProgressWindow * progress; - std::string fdisk, sfdisk, tune2fs; + std::string fdisk, sfdisk, sgdisk, tune2fs; printf("CHDDMenuHandler::formatDevice: dev %s hdd_fs %d\n", dev.c_str(), g_settings.hdd_fs); @@ -1050,16 +1050,22 @@ int CHDDMenuHandler::formatDevice(std::string dev) fdisk = find_executable("fdisk"); sfdisk = find_executable("sfdisk"); + sgdisk = find_executable("sgdisk"); tune2fs = find_executable("tune2fs"); if (! sfdisk.empty()) { - snprintf(cmd, sizeof(cmd), "%s -f -uM %s", sfdisk.c_str(), devname.c_str()); - strcpy(cmd2, "0,\n;\n;\n;\ny\n"); - } else if (! fdisk.empty()) { + std::string conf = "echo 'label: gpt\n;' | "; + snprintf(cmd, sizeof(cmd), "%s %s -f %s", conf.c_str(), sfdisk.c_str(), devname.c_str()); + } + else if (! sgdisk.empty()) { + snprintf(cmd, sizeof(cmd), "%s -Z -N 0 %s", sgdisk.c_str(), devname.c_str()); + } + else if (! fdisk.empty()) { snprintf(cmd, sizeof(cmd), "%s -u %s", fdisk.c_str(), devname.c_str()); strcpy(cmd2, "o\nn\np\n1\n2048\n\nw\n"); - } else { + } + else { /* cannot do anything */ - fprintf(stderr, "CHDDFmtExec: neither fdisk nor sfdisk found in $PATH :-(\n"); + fprintf(stderr, "CHDDFmtExec: neither fdisk, sfdisk or sgdisk found in $PATH :-(\n"); showError(LOCALE_HDD_FORMAT_FAILED); goto _remount; } @@ -1080,7 +1086,7 @@ int CHDDMenuHandler::formatDevice(std::string dev) fprintf(f, "%s", cmd2); res = pclose(f); - printf("CHDDMenuHandler::formatDevice: (s)fdisk res: %d\n", res); + printf("CHDDMenuHandler::formatDevice: (s(g))(f)disk res: %d\n", res); if (res) { showError(LOCALE_HDD_FORMAT_FAILED); goto _remount; @@ -1092,6 +1098,8 @@ int CHDDMenuHandler::formatDevice(std::string dev) #endif progress->showStatusMessageUTF(mkfscmd.c_str()); + res = umount_all(dev); + printf("CHDDMenuHandler::formatDevice: umount res %d\n", res); f = popen(mkfscmd.c_str(), "r"); if (!f) { showError(LOCALE_HDD_FORMAT_FAILED);