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"
31 mkswap (char *device, const char *flag, const char *value)
37 r = command (NULL, &err, "/sbin/mkswap", device, NULL);
39 r = command (NULL, &err, "/sbin/mkswap", flag, value, device, NULL);
42 reply_with_error ("mkswap: %s", err);
53 do_mkswap (char *device)
55 IS_DEVICE (device, -1);
57 return mkswap (device, NULL, NULL);
61 do_mkswap_L (char *label, char *device)
63 IS_DEVICE (device, -1);
65 return mkswap (device, "-L", label);
69 do_mkswap_U (char *uuid, char *device)
71 IS_DEVICE (device, -1);
73 return mkswap (device, "-U", uuid);
77 do_mkswap_file (char *path)
85 buf = sysroot_path (path);
87 reply_with_perror ("malloc");
91 r = mkswap (buf, NULL, NULL);
97 swaponoff (const char *cmd, const char *flag, const char *value)
103 r = command (NULL, &err, cmd, value, NULL);
105 r = command (NULL, &err, cmd, flag, value, NULL);
108 reply_with_error ("%s: %s: %s", cmd, value, err);
119 do_swapon_device (char *device)
121 IS_DEVICE (device, -1);
123 return swaponoff ("/sbin/swapon", NULL, device);
127 do_swapoff_device (char *device)
129 IS_DEVICE (device, -1);
131 return swaponoff ("/sbin/swapoff", NULL, device);
135 do_swapon_file (char *path)
143 buf = sysroot_path (path);
145 reply_with_perror ("malloc");
149 r = swaponoff ("/sbin/swapon", NULL, buf);
155 do_swapoff_file (char *path)
163 buf = sysroot_path (path);
165 reply_with_perror ("malloc");
169 r = swaponoff ("/sbin/swapoff", NULL, buf);
175 do_swapon_label (char *label)
177 return swaponoff ("/sbin/swapon", "-L", label);
181 do_swapoff_label (char *label)
183 return swaponoff ("/sbin/swapoff", "-L", label);
187 do_swapon_uuid (char *uuid)
189 return swaponoff ("/sbin/swapon", "-U", uuid);
193 do_swapoff_uuid (char *uuid)
195 return swaponoff ("/sbin/swapoff", "-U", uuid);