diff options
author | Richard Jones <rjones@centos5x32.home.annexia.org> | 2009-07-03 00:22:14 +0100 |
---|---|---|
committer | Richard Jones <rjones@centos5x32.home.annexia.org> | 2009-07-03 00:22:14 +0100 |
commit | 6fb57e430c8daa06d8d938ac02a104c8aadbbda5 (patch) | |
tree | 38586363a6a7d68e5559347d1cc7671593c81aed /daemon/sfdisk.c | |
parent | b7e094fa14b306fe776b9b2695cf82fa32d4923f (diff) | |
parent | ee4c49fad5a3e36c6e909ab90bcb7d719c9395b3 (diff) | |
download | libguestfs-6fb57e430c8daa06d8d938ac02a104c8aadbbda5.tar.gz libguestfs-6fb57e430c8daa06d8d938ac02a104c8aadbbda5.tar.xz libguestfs-6fb57e430c8daa06d8d938ac02a104c8aadbbda5.zip |
Merge branch 'master' of git+ssh://192.168.122.1/home/rjones/d/libguestfs
Diffstat (limited to 'daemon/sfdisk.c')
-rw-r--r-- | daemon/sfdisk.c | 26 |
1 files changed, 20 insertions, 6 deletions
diff --git a/daemon/sfdisk.c b/daemon/sfdisk.c index 95f04af4..f1726fc9 100644 --- a/daemon/sfdisk.c +++ b/daemon/sfdisk.c @@ -31,6 +31,7 @@ static int sfdisk (char *device, int n, int cyls, int heads, int sectors, + const char *extra_flag, char * const* const lines) { FILE *fp; @@ -40,6 +41,7 @@ sfdisk (char *device, int n, int cyls, int heads, int sectors, IS_DEVICE (device, -1); strcpy (buf, "/sbin/sfdisk"); + if (n > 0) sprintf (buf + strlen (buf), " -N %d", n); if (cyls) @@ -48,6 +50,9 @@ sfdisk (char *device, int n, int cyls, int heads, int sectors, sprintf (buf + strlen (buf), " -H %d", heads); if (sectors) sprintf (buf + strlen (buf), " -S %d", sectors); + if (extra_flag) + sprintf (buf + strlen (buf), " %s", extra_flag); + /* Safe because of IS_DEVICE above: */ sprintf (buf + strlen (buf), " %s", device); @@ -63,17 +68,18 @@ sfdisk (char *device, int n, int cyls, int heads, int sectors, for (i = 0; lines[i] != NULL; ++i) { if (fprintf (fp, "%s\n", lines[i]) < 0) { reply_with_perror (buf); - fclose (fp); + pclose (fp); return -1; } } - if (fclose (fp) == EOF) { - reply_with_perror (buf); - fclose (fp); + if (pclose (fp) != 0) { + reply_with_error ("%s: external command failed", buf); return -1; } + udev_settle (); + return 0; } @@ -81,7 +87,7 @@ int do_sfdisk (char *device, int cyls, int heads, int sectors, char **lines) { - return sfdisk (device, 0, cyls, heads, sectors, lines); + return sfdisk (device, 0, cyls, heads, sectors, NULL, lines); } int @@ -90,7 +96,13 @@ do_sfdisk_N (char *device, int n, int cyls, int heads, int sectors, { const char *lines[2] = { line, NULL }; - return sfdisk (device, n, cyls, heads, sectors, lines); + return sfdisk (device, n, cyls, heads, sectors, NULL, lines); +} + +int +do_sfdiskM (char *device, char **lines) +{ + return sfdisk (device, 0, 0, 0, 0, "-uM", lines); } static char * @@ -111,6 +123,8 @@ sfdisk_flag (char *device, const char *flag) free (err); + udev_settle (); + return out; /* caller frees */ } |