#include <dirent.h>
#include <sys/stat.h>
+#include "c-ctype.h"
+
#include "daemon.h"
#include "actions.h"
{
return foreach_block_device(add_partitions);
}
+
+char *
+do_part_to_dev (const char *part)
+{
+ int err = 1;
+ size_t n = strlen (part);
+
+ while (n >= 1 && c_isdigit (part[n-1])) {
+ err = 0;
+ n--;
+ }
+
+ if (err) {
+ reply_with_error ("device name is not a partition");
+ return NULL;
+ }
+
+ char *r = strndup (part, n);
+ if (r == NULL) {
+ reply_with_perror ("strdup");
+ return NULL;
+ }
+
+ return r;
+}
See also C<guestfs_stat>.");
+ ("part_to_dev", (RString "device", [Device "partition"]), 272, [],
+ [InitPartition, Always, TestOutputDevice (
+ [["part_to_dev"; "/dev/sda1"]], "/dev/sda");
+ InitEmpty, Always, TestLastFail (
+ [["part_to_dev"; "/dev/sda"]])],
+ "convert partition name to device name",
+ "\
+This function takes a partition name (eg. \"/dev/sdb1\") and
+removes the partition number, returning the device name
+(eg. \"/dev/sdb\").
+
+The named partition must exist, for example as a string returned
+from C<guestfs_list_partitions>.");
+
]
let all_functions = non_daemon_functions @ daemon_functions