1 /* libguestfs - the guestfsd daemon
2 * Copyright (C) 2009 Red Hat Inc.
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation; either version 2 of the License, or
7 * (at your option) any later version.
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
14 * You should have received a copy of the GNU General Public License
15 * along with this program; if not, write to the Free Software
16 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
26 #include "../src/guestfs_protocol.h"
29 #include "optgroups.h"
31 /* Convenient place to test for the later version of e2fsprogs
32 * and util-linux which supports -U parameters to specify UUIDs.
33 * (Not supported in RHEL 5).
36 optgroup_linuxfsuuid_available (void)
41 /* Ignore return code - mkswap --help *will* fail. */
42 command (NULL, &err, "mkswap", "--help", NULL);
44 av = strstr (err, "-U") != NULL;
50 mkswap (const char *device, const char *flag, const char *value)
56 r = command (NULL, &err, "mkswap", "-f", device, NULL);
58 r = command (NULL, &err, "mkswap", "-f", flag, value, device, NULL);
61 reply_with_error ("%s", err);
72 do_mkswap (const char *device)
74 return mkswap (device, NULL, NULL);
78 do_mkswap_L (const char *label, const char *device)
80 return mkswap (device, "-L", label);
84 do_mkswap_U (const char *uuid, const char *device)
86 return mkswap (device, "-U", uuid);
90 do_mkswap_file (const char *path)
95 buf = sysroot_path (path);
97 reply_with_perror ("malloc");
101 r = mkswap (buf, NULL, NULL);
107 swaponoff (const char *cmd, const char *flag, const char *value)
113 r = command (NULL, &err, cmd, value, NULL);
115 r = command (NULL, &err, cmd, flag, value, NULL);
118 reply_with_error ("%s: %s", value, err);
129 do_swapon_device (const char *device)
131 return swaponoff ("swapon", NULL, device);
135 do_swapoff_device (const char *device)
137 return swaponoff ("swapoff", NULL, device);
141 do_swapon_file (const char *path)
146 buf = sysroot_path (path);
148 reply_with_perror ("malloc");
152 r = swaponoff ("swapon", NULL, buf);
158 do_swapoff_file (const char *path)
163 buf = sysroot_path (path);
165 reply_with_perror ("malloc");
169 r = swaponoff ("swapoff", NULL, buf);
175 do_swapon_label (const char *label)
177 return swaponoff ("swapon", "-L", label);
181 do_swapoff_label (const char *label)
183 return swaponoff ("swapoff", "-L", label);
187 do_swapon_uuid (const char *uuid)
189 return swaponoff ("swapon", "-U", uuid);
193 do_swapoff_uuid (const char *uuid)
195 return swaponoff ("swapoff", "-U", uuid);