summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--Makefile4
-rw-r--r--query-sysfspath.c42
2 files changed, 46 insertions, 0 deletions
diff --git a/Makefile b/Makefile
index 4c364c5..3d3cc68 100644
--- a/Makefile
+++ b/Makefile
@@ -8,4 +8,8 @@ CFLAGS+=-std=gnu11 -O2 -g -Wall
CFLAGS+=$(shell $(PKG_CONFIG) --cflags $(PKGCONFIG_LIBS))
LDLIBS+=$(shell $(PKG_CONFIG) --libs $(PKGCONFIG_LIBS))
+all: query-uuid query-sysfspath
+
query-uuid: query-uuid.o
+
+query-sysfspath: query-sysfspath.o
diff --git a/query-sysfspath.c b/query-sysfspath.c
new file mode 100644
index 0000000..e17bd28
--- /dev/null
+++ b/query-sysfspath.c
@@ -0,0 +1,42 @@
+#include <fcntl.h>
+#include <stdarg.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <sys/ioctl.h>
+#include <unistd.h>
+#include <linux/types.h>
+
+#include <uuid/uuid.h>
+
+struct fs_sysfs_path {
+ __u8 len;
+ __u8 name[128];
+};
+#define FS_IOC_GETFSSYSFSPATH _IOR(0x15, 1, struct fs_sysfs_path)
+
+void die(const char *fmt, ...)
+{
+ va_list args;
+
+ va_start(args, fmt);
+ vfprintf(stderr, fmt, args);
+ va_end(args);
+ fputc('\n', stderr);
+
+ _exit(EXIT_FAILURE);
+}
+
+int main(int argc, char *argv[])
+{
+ const char *path = argv[1] ?: ".";
+ int fd = open(path, O_RDONLY);
+ if (fd < 0)
+ die("Error opening %s: %m\n", path);
+
+ struct fs_sysfs_path sysfspath;
+ if (ioctl(fd, FS_IOC_GETFSSYSFSPATH, (unsigned long) &sysfspath))
+ die("FS_IOC_GETFSSYSFSPATH error: %m\n");
+
+ write(STDOUT_FILENO, sysfspath.name, sysfspath.len);
+}