#include #include #include #include #include #include #include #include #include struct fsuuid2 { __u8 len; __u8 uuid[16]; }; #define FS_IOC_GETFSUUID _IOR(0x15, 0, struct fsuuid2) 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 fsuuid2 uuid; if (ioctl(fd, FS_IOC_GETFSUUID, (unsigned long) &uuid)) die("FS_IOC_GETFSUUID error: %m\n"); if (uuid.len == 16) { uuid_t u; memcpy(&u, uuid.uuid, 16); char str[37]; uuid_unparse(u, str); puts(str); } else { for (unsigned i = 0; i < uuid.len; i++) printf("%x", uuid.uuid[i]); } }