X-Git-Url: http://git.annexia.org/?a=blobdiff_plain;f=daemon%2Fsfdisk.c;h=1ec0c859b61b9eb80e453f3d58b85f2fe258feb8;hb=1f0810eb3a98cbfd347af59b6b9bc624ddff6028;hp=5fb30c0eaabcefcab7840a808d4f8da1b3b2ffab;hpb=99e28249d52ca5495b636e14ae3e4387ee62c8fe;p=libguestfs.git diff --git a/daemon/sfdisk.c b/daemon/sfdisk.c index 5fb30c0..1ec0c85 100644 --- a/daemon/sfdisk.c +++ b/daemon/sfdisk.c @@ -1,5 +1,5 @@ /* libguestfs - the guestfsd daemon - * Copyright (C) 2009 Red Hat Inc. + * Copyright (C) 2009 Red Hat Inc. * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -30,16 +30,16 @@ #include "actions.h" static int -sfdisk (char *device, int n, int cyls, int heads, int sectors, - char * const* const lines) +sfdisk (const char *device, int n, int cyls, int heads, int sectors, + const char *extra_flag, + char * const* const lines) { FILE *fp; char buf[256]; int i; - IS_DEVICE (device, -1); - strcpy (buf, "/sbin/sfdisk"); + if (n > 0) sprintf (buf + strlen (buf), " -N %d", n); if (cyls) @@ -48,7 +48,10 @@ 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); - /* Safe because of IS_DEVICE above: */ + if (extra_flag) + sprintf (buf + strlen (buf), " %s", extra_flag); + + /* Safe because of RESOLVE_DEVICE above: */ sprintf (buf + strlen (buf), " %s", device); if (verbose) @@ -79,29 +82,33 @@ sfdisk (char *device, int n, int cyls, int heads, int sectors, } int -do_sfdisk (char *device, int cyls, int heads, int sectors, - char **lines) +do_sfdisk (const 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 -do_sfdisk_N (char *device, int n, int cyls, int heads, int sectors, - char *line) +do_sfdisk_N (const char *device, int n, int cyls, int heads, int sectors, + const char *line) { 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 (const char *device, char **lines) +{ + return sfdisk (device, 0, 0, 0, 0, "-uM", lines); } static char * -sfdisk_flag (char *device, const char *flag) +sfdisk_flag (const char *device, const char *flag) { char *out, *err; int r; - IS_DEVICE (device, NULL); - r = command (&out, &err, "/sbin/sfdisk", flag, device, NULL); if (r == -1) { reply_with_error ("sfdisk: %s: %s", device, err); @@ -118,19 +125,19 @@ sfdisk_flag (char *device, const char *flag) } char * -do_sfdisk_l (char *device) +do_sfdisk_l (const char *device) { return sfdisk_flag (device, "-l"); } char * -do_sfdisk_kernel_geometry (char *device) +do_sfdisk_kernel_geometry (const char *device) { return sfdisk_flag (device, "-g"); } char * -do_sfdisk_disk_geometry (char *device) +do_sfdisk_disk_geometry (const char *device) { return sfdisk_flag (device, "-G"); }