summaryrefslogtreecommitdiff
path: root/query-sysfspath.c
blob: e17bd28061149dbb704b86b5394eb38a7f2c7660 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
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);
}