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.
31 /* These functions are all about using the blockdev command, so
32 * we centralize it in one call.
35 call_blockdev (char *device, char *switc, int extraarg, int prints)
40 const char *argv[] = {
49 IS_DEVICE (device, -1);
52 snprintf (buf, sizeof buf, "%d", extraarg);
58 r = commandv (&out, &err, argv);
61 reply_with_error ("%s: %s", argv[0], err);
70 if (sscanf (out, "%" SCNi64, &rv) != 1) {
71 reply_with_error ("%s: expected output, but got nothing", argv[0]);
83 do_blockdev_setro (char *device)
85 return (int) call_blockdev (device, "--setro", 0, 0);
89 do_blockdev_setrw (char *device)
91 return (int) call_blockdev (device, "--setrw", 0, 0);
95 do_blockdev_getro (char *device)
97 return (int) call_blockdev (device, "--getro", 0, 1);
101 do_blockdev_getss (char *device)
103 return (int) call_blockdev (device, "--getss", 0, 1);
107 do_blockdev_getbsz (char *device)
109 return (int) call_blockdev (device, "--getbsz", 0, 1);
113 do_blockdev_setbsz (char *device, int blocksize)
115 if (blocksize <= 0 /* || blocksize >= what? */) {
116 reply_with_error ("blockdev_setbsz: blocksize must be > 0");
119 return (int) call_blockdev (device, "--setbsz", blocksize, 0);
123 do_blockdev_getsz (char *device)
125 return call_blockdev (device, "--getsz", 0, 1);
129 do_blockdev_getsize64 (char *device)
131 return call_blockdev (device, "--getsize64", 0, 1);
135 do_blockdev_flushbufs (char *device)
137 return call_blockdev (device, "--flushbufs", 0, 0);
141 do_blockdev_rereadpt (char *device)
143 return call_blockdev (device, "--rereadpt", 0, 0);