diff options
author | Richard Jones <rjones@redhat.com> | 2009-04-10 18:25:07 +0100 |
---|---|---|
committer | Richard Jones <rjones@redhat.com> | 2009-04-11 17:04:35 +0100 |
commit | b4d2a01828e5de85e5eee3631f7fe3925a0312ca (patch) | |
tree | 6f77ecceccd53a84afce4cecf0fe199ba7707752 /daemon/devsparts.c | |
parent | 99f68f259f92eee884c6c7396f61b9c16e2bf354 (diff) | |
download | libguestfs-b4d2a01828e5de85e5eee3631f7fe3925a0312ca.tar.gz libguestfs-b4d2a01828e5de85e5eee3631f7fe3925a0312ca.tar.xz libguestfs-b4d2a01828e5de85e5eee3631f7fe3925a0312ca.zip |
Added test suite.
Diffstat (limited to 'daemon/devsparts.c')
-rw-r--r-- | daemon/devsparts.c | 62 |
1 files changed, 62 insertions, 0 deletions
diff --git a/daemon/devsparts.c b/daemon/devsparts.c index b0d79569..324b8870 100644 --- a/daemon/devsparts.c +++ b/daemon/devsparts.c @@ -131,3 +131,65 @@ do_list_partitions (void) sort_strings (r, size-1); return r; } + +int +do_mkfs (const char *fstype, const char *device) +{ + char *err; + int r; + + IS_DEVICE (device, -1); + + r = command (NULL, &err, "/sbin/mkfs", "-t", fstype, device, NULL); + if (r == -1) { + reply_with_error ("mkfs: %s", err); + free (err); + return -1; + } + + free (err); + return 0; +} + +int +do_sfdisk (const char *device, int cyls, int heads, int sectors, + char * const* const lines) +{ + FILE *fp; + char buf[256]; + int i; + + IS_DEVICE (device, -1); + + /* Safe because of IS_DEVICE above. */ + strcpy (buf, "/sbin/sfdisk"); + if (cyls) + sprintf (buf + strlen (buf), " -C %d", cyls); + if (heads) + sprintf (buf + strlen (buf), " -H %d", heads); + if (sectors) + sprintf (buf + strlen (buf), " -S %d", sectors); + sprintf (buf + strlen (buf), " %s", device); + + fp = popen (buf, "w"); + if (fp == NULL) { + reply_with_perror (buf); + return -1; + } + + for (i = 0; lines[i] != NULL; ++i) { + if (fprintf (fp, "%s\n", lines[i]) < 0) { + reply_with_perror (buf); + fclose (fp); + return -1; + } + } + + if (fclose (fp) == EOF) { + reply_with_perror (buf); + fclose (fp); + return -1; + } + + return 0; +} |