Add an option to allow disk syncing to be turned off
Bug: 27795746
Change-Id: I47447a8467c409db526483ac7e4a9394cd68578a
(cherry picked from commit fd9b918d2e49de4b7b7568aaa39f7e179752766d)
(cherry picked from commit 2c2deeb032f6c158cf4f782e1765a4a21af88cb3)
diff --git a/gpt.cc b/gpt.cc
index 18247c5..91fa18f 100644
--- a/gpt.cc
+++ b/gpt.cc
@@ -69,6 +69,7 @@
state = gpt_valid;
device = "";
justLooking = 0;
+ syncing = 1;
mainCrcOk = 0;
secondCrcOk = 0;
mainPartsCrcOk = 0;
@@ -93,6 +94,7 @@
state = gpt_invalid;
device = "";
justLooking = 0;
+ syncing = 1;
mainCrcOk = 0;
secondCrcOk = 0;
mainPartsCrcOk = 0;
@@ -128,6 +130,7 @@
diskSize = orig.diskSize;
state = orig.state;
justLooking = orig.justLooking;
+ syncing = orig.syncing;
mainCrcOk = orig.mainCrcOk;
secondCrcOk = orig.secondCrcOk;
mainPartsCrcOk = orig.mainPartsCrcOk;
@@ -1142,7 +1145,7 @@
// original partition table from its cache. OTOH, such restoration might be
// desirable if the error occurs later; but that seems unlikely unless the initial
// write fails....
- if (syncIt)
+ if (syncIt && syncing)
myDisk.DiskSync();
if (allOK) { // writes completed OK
@@ -1374,7 +1377,9 @@
allOK = 0;
} // if
} // if
- myDisk.DiskSync();
+ if (syncing) {
+ myDisk.DiskSync();
+ }
myDisk.Close();
cout << "GPT data structures destroyed! You may now partition the disk using fdisk or\n"
<< "other utilities.\n";
diff --git a/gpt.h b/gpt.h
index e9afd06..1c0eaaf 100644
--- a/gpt.h
+++ b/gpt.h
@@ -72,6 +72,7 @@
uint64_t diskSize; // size of device, in blocks
GPTValidity state; // is GPT valid?
int justLooking; // Set to 1 if program launched with "-l" or if read-only
+ bool syncing; // Set to true if we should sync and reload the partition table
int mainCrcOk;
int secondCrcOk;
int mainPartsCrcOk;
@@ -189,6 +190,7 @@
uint32_t ComputeAlignment(void); // Set alignment based on current partitions
uint32_t GetAlignment(void) {return sectorAlignment;}
void JustLooking(int i = 1) {justLooking = i;}
+ void TurnOffSyncing() {syncing = 0;}
void BeQuiet(int i = 1) {beQuiet = i;}
WhichToUse WhichWasUsed(void) {return whichWasUsed;}
diff --git a/gptcl.cc b/gptcl.cc
index e20048e..602be5c 100644
--- a/gptcl.cc
+++ b/gptcl.cc
@@ -86,6 +86,7 @@
{"randomize-guids", 'G', POPT_ARG_NONE, NULL, 'G', "randomize disk and partition GUIDs", ""},
{"hybrid", 'h', POPT_ARG_STRING, &hybrids, 'h', "create hybrid MBR", "partnum[:partnum...]"},
{"info", 'i', POPT_ARG_INT, &infoPartNum, 'i', "show detailed information on partition", "partnum"},
+ {"skip-sync", 'j', POPT_ARG_NONE, NULL, 'j', "Don't atempt to sync and update the parittion table", ""},
{"load-backup", 'l', POPT_ARG_STRING, &backupFile, 'l', "load GPT backup from file", "file"},
{"list-types", 'L', POPT_ARG_NONE, NULL, 'L', "list known partition types", ""},
{"gpttombr", 'm', POPT_ARG_STRING, &mbrParts, 'm', "convert GPT to MBR", "partnum[:partnum...]"},
@@ -260,6 +261,9 @@
case 'i':
ShowPartDetails(infoPartNum - 1);
break;
+ case 'j':
+ TurnOffSyncing();
+ break;
case 'l':
LoadBackupFile(backupFile, saveData, neverSaveData);
free(backupFile);