Git-Url: http://git.frugalware.org/gitweb/gitweb.cgi?p=fwsetup-ng.git;a=commitdiff;h=ccb13147020043339acb720d28491b3aa3b828b2
commit ccb13147020043339acb720d28491b3aa3b828b2 Author: James Buren <[email protected]> Date: Mon Aug 27 16:58:21 2012 -0500 add command for zapping the disk label diff --git a/Utility.cc b/Utility.cc index a39254f..a6807b8 100644 --- a/Utility.cc +++ b/Utility.cc @@ -3,6 +3,7 @@ #include <string.h> #include <errno.h> #include <stdlib.h> +#include <sys/wait.h> #include <sstream> #include "Utility.hh" @@ -10,6 +11,7 @@ using std::stringstream; using std::ios; +using std::endl; ofstream logfile(LOGFILE,ios::app); @@ -40,6 +42,33 @@ pid_t execute(const string &cmd) return pid; } +bool zapLabel(const string &path) +{ + string cmd; + pid_t pid = -1; + int status = 0; + + cmd = "sgdisk --zap-all " + path; + + logfile << "Executing command: " << cmd << endl; + + if((pid == execute(cmd)) == -1 || waitpid(pid,&status,0) == -1) + { + logfile << __func__ << ": " << strerror(errno) << endl; + return false; + } + + if(!WIFEXITED(status) || WEXITSTATUS(status) != 0) + { + logfile << "Command did not exit normally: " << cmd << endl; + return false; + } + + logfile << "Finished executing command: " << cmd << endl; + + return true; +} + unsigned long long string_to_size(const string &text) { unsigned long long n = 0; diff --git a/Utility.hh b/Utility.hh index 0c88d59..23ec076 100644 --- a/Utility.hh +++ b/Utility.hh @@ -15,5 +15,6 @@ using std::ofstream; extern ofstream logfile; pid_t execute(const string &cmd); +bool zapLabel(const string &path); unsigned long long string_to_size(const string &text); string size_to_string(unsigned long long n); _______________________________________________ Frugalware-git mailing list [email protected] http://frugalware.org/mailman/listinfo/frugalware-git
