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 (const char *device, const char *flag, const char *value)
37 r = command (NULL, &err, "/sbin/mkswap", "-f", device, NULL);
39 r = command (NULL, &err, "/sbin/mkswap", "-f", flag, value, device, NULL);
42 reply_with_error ("mkswap: %s", err);
53 do_mkswap (const char *device)
55 return mkswap (device, NULL, NULL);
59 do_mkswap_L (const char *label, const char *device)
61 return mkswap (device, "-L", label);
65 do_mkswap_U (const char *uuid, const char *device)
67 return mkswap (device, "-U", uuid);
71 do_mkswap_file (const char *path)
76 buf = sysroot_path (path);
78 reply_with_perror ("malloc");
82 r = mkswap (buf, NULL, NULL);
88 swaponoff (const char *cmd, const char *flag, const char *value)
94 r = command (NULL, &err, cmd, value, NULL);
96 r = command (NULL, &err, cmd, flag, value, NULL);
99 reply_with_error ("%s: %s: %s", cmd, value, err);
110 do_swapon_device (const char *device)
112 return swaponoff ("/sbin/swapon", NULL, device);
116 do_swapoff_device (const char *device)
118 return swaponoff ("/sbin/swapoff", NULL, device);
122 do_swapon_file (const char *path)
127 buf = sysroot_path (path);
129 reply_with_perror ("malloc");
133 r = swaponoff ("/sbin/swapon", NULL, buf);
139 do_swapoff_file (const char *path)
144 buf = sysroot_path (path);
146 reply_with_perror ("malloc");
150 r = swaponoff ("/sbin/swapoff", NULL, buf);
156 do_swapon_label (const char *label)
158 return swaponoff ("/sbin/swapon", "-L", label);
162 do_swapoff_label (const char *label)
164 return swaponoff ("/sbin/swapoff", "-L", label);
168 do_swapon_uuid (const char *uuid)
170 return swaponoff ("/sbin/swapon", "-U", uuid);
174 do_swapoff_uuid (const char *uuid)
176 return swaponoff ("/sbin/swapoff", "-U", uuid);