aboutgitcodelistschat:MatrixIRC
path: root/demo/open_by_handle_at.c
blob: 1f48eca26724412806d89176a1b242959c078011 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
#define _GNU_SOURCE
#include <sys/stat.h>
#include <sys/xattr.h>
#include <fcntl.h>
#include <string.h>
#include <stdio.h>
#include <unistd.h>

int main(int argc, char **argv)
{
	struct {
		struct file_handle f;
		unsigned char h[MAX_HANDLE_SZ];
	} handle = { .f.handle_bytes = MAX_HANDLE_SZ };
	int mount_fd, fd;
	char buf[BUFSIZ];

	name_to_handle_at(AT_FDCWD, argv[1], &handle.f, &mount_fd, 0);
	fd = open_by_handle_at(mount_fd, &handle.f, 0);
	read(fd, buf, BUFSIZ);
	fprintf(stdout, "%s", buf);
}