+/* Helper for functions that need an argument ("path") that is absolute.
+ * NB. Cannot be used for FileIn functions.
+ */
+#define ABS_PATH(path,errcode) \
+ do { \
+ if ((path)[0] != '/') { \
+ reply_with_error ("%s: path must start with a / character", __func__); \
+ return (errcode); \
+ } \
+ } while (0)
+
+/* Helper for functions that need an argument ("path") that is a device.
+ * NB. Cannot be used for FileIn functions.
+ */
+#define IS_DEVICE(path,errcode) \
+ do { \
+ struct stat statbuf; \
+ if (strncmp ((path), "/dev/", 5) != 0) { \
+ reply_with_error ("%s: %s: expecting a device name", __func__, (path)); \
+ return (errcode); \
+ } \
+ if (stat ((path), &statbuf) == -1) { \
+ reply_with_perror ("%s: %s", __func__, (path)); \
+ 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.
+ */
+#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)
+