---
daemon/devsparts.c | 27 +++++++++++++++++++++++++++
generator/actions.ml | 17 +++++++++++++++++
src/MAX_PROC_NR | 2 +-
3 files changed, 45 insertions(+), 1 deletion(-)
diff --git a/daemon/devsparts.c b/daemon/devsparts.c
index 9a2ce9a..1939f2a 100644
--- a/daemon/devsparts.c
+++ b/daemon/devsparts.c
@@ -245,6 +245,33 @@ do_part_to_partnum (const char *part)
}
int
+do_is_whole_device (const char *device)
+{
+ #define PREFIX "/dev/"
+
+ /* Shouldn't be possible because we already sanity checked our input */
+ if (!STRPREFIX (device, PREFIX)) return 0;
+
+ CLEANUP_FREE char *devpath = NULL;
+ if (asprintf (&devpath, "/sys/block/%s/device",
+ device + strlen (PREFIX)) == -1)
+ {
+ reply_with_perror ("asprintf");
+ return -1;
+ }
+
+ struct stat statbuf;
+ if (stat (devpath, &statbuf) == -1) {
+ if (errno == ENOENT || errno == ENOTDIR) return 0;
+
+ reply_with_perror ("stat");
+ return -1;
+ }
+
+ return 1;
+}
+
+int
do_device_index (const char *device)
{
size_t i;
diff --git a/generator/actions.ml b/generator/actions.ml
index 96702f7..711f97e 100644
--- a/generator/actions.ml
+++ b/generator/actions.ml
@@ -10704,6 +10704,23 @@ Rename a file to a new place on the same filesystem. This is
the same as the Linux L<rename(2)> system call. In most cases
you are better to use C<guestfs_mv> instead." };
+ { defaults with
+ name = "is_whole_device";
+ style = RBool "flag", [Device "device"], [];
+ proc_nr = Some 395;
+ tests = [
+ InitEmpty, Always, TestOutputTrue (
+ [["is_whole_device"; "/dev/sda"]]);
+ InitPartition, Always, TestOutputFalse (
+ [["is_whole_device"; "/dev/sda1"]]);
+ InitBasicFSonLVM, Always, TestOutputFalse (
+ [["is_whole_device"; "/dev/VG/LV"]]);
+ ];
+ shortdesc = "test if a device is a whole device";
+ longdesc = "\
+This returns C<true> if and only if C<device> refers to a whole block
+device. That is, not a partition or a logical device." };
+
]
(* Non-API meta-commands available only in guestfish.
diff --git a/src/MAX_PROC_NR b/src/MAX_PROC_NR
index 0ca45a0..e537bfe 100644
--- a/src/MAX_PROC_NR
+++ b/src/MAX_PROC_NR
@@ -1 +1 @@
-394
+395
--
1.8.1