diff options
author | Kent Overstreet <kent.overstreet@linux.dev> | 2024-03-14 23:11:15 -0400 |
---|---|---|
committer | Kent Overstreet <kent.overstreet@linux.dev> | 2024-03-14 23:11:15 -0400 |
commit | 975493d51e4fd97cc20ddf1ace8be0515bff08e9 (patch) | |
tree | 7bdbef0c624dd1e9204868d904b40a72f4e9300f | |
parent | baa981737d65a23b1c0c55d004d4f2301a212a4b (diff) |
Signed-off-by: Kent Overstreet <kent.overstreet@linux.dev>
-rw-r--r-- | Makefile | 4 | ||||
-rw-r--r-- | query-sysfspath.c | 42 |
2 files changed, 46 insertions, 0 deletions
@@ -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); +} |