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 (const char *device, const char *switc, int extraarg, int prints)
40 const char *argv[] = {
50 snprintf (buf, sizeof buf, "%d", extraarg);
56 r = commandv (&out, &err, argv);
59 reply_with_error ("%s: %s", argv[0], err);
68 if (sscanf (out, "%" SCNi64, &rv) != 1) {
69 reply_with_error ("%s: expected output, but got nothing", argv[0]);
81 do_blockdev_setro (const char *device)
83 return (int) call_blockdev (device, "--setro", 0, 0);
87 do_blockdev_setrw (const char *device)
89 return (int) call_blockdev (device, "--setrw", 0, 0);
93 do_blockdev_getro (const char *device)
95 return (int) call_blockdev (device, "--getro", 0, 1);
99 do_blockdev_getss (const char *device)
101 return (int) call_blockdev (device, "--getss", 0, 1);
105 do_blockdev_getbsz (const char *device)
107 return (int) call_blockdev (device, "--getbsz", 0, 1);
111 do_blockdev_setbsz (const char *device, int blocksize)
113 if (blocksize <= 0 /* || blocksize >= what? */) {
114 reply_with_error ("blockdev_setbsz: blocksize must be > 0");
117 return (int) call_blockdev (device, "--setbsz", blocksize, 0);
121 do_blockdev_getsz (const char *device)
123 return call_blockdev (device, "--getsz", 0, 1);
127 do_blockdev_getsize64 (const char *device)
129 return call_blockdev (device, "--getsize64", 0, 1);
133 do_blockdev_flushbufs (const char *device)
135 return call_blockdev (device, "--flushbufs", 0, 0);
139 do_blockdev_rereadpt (const char *device)
141 return call_blockdev (device, "--rereadpt", 0, 0);