+/* All functions that need an argument that is a device or partition name
+ * must call this macro. It checks that the device exists and does
+ * device name translation (described in the guestfs(3) manpage).
+ * Note that the "path" argument may be modified.
+ *
+ * NB. Cannot be used for FileIn functions.
+ */
+#define IS_DEVICE(path,errcode) \
+ do { \
+ if (strncmp ((path), "/dev/", 5) != 0) { \
+ reply_with_error ("%s: %s: expecting a device name", __func__, (path)); \
+ return (errcode); \
+ } \
+ if (device_name_translation ((path), __func__) == -1) \
+ return (errcode); \
+ } while (0)
+
+/* Helper for functions which need either an absolute path in the
+ * mounted filesystem, OR a /dev/ device which exists.
+ *
+ * NB. Cannot be used for FileIn functions.
+ *
+ * NB #2: Functions which mix filenames and device paths should be
+ * avoided, and existing functions should be deprecated. This is
+ * because we intend in future to make device parameters a distinct
+ * type from filenames.
+ */
+#define NEED_ROOT_OR_IS_DEVICE(path,errcode) \
+ do { \
+ if (strncmp ((path), "/dev/", 5) == 0) \
+ IS_DEVICE ((path),(errcode)); \
+ else { \
+ NEED_ROOT ((errcode)); \
+ ABS_PATH ((path),(errcode)); \
+ } \
+ } while (0)
+