All of lore.kernel.org
 help / color / mirror / Atom feed
* Errors from basic open_by_handle operations
@ 2015-04-09 12:53 Mark Hills
  2015-04-09 13:09 ` Roger Willcocks
                   ` (3 more replies)
  0 siblings, 4 replies; 8+ messages in thread
From: Mark Hills @ 2015-04-09 12:53 UTC (permalink / raw)
  To: xfs

I am having troubles with elementary file handle functions in libhandle.

A basic open_by_handle is giving "Bad file descriptor".

But I am suspicious of a side effect; using path_to_fshandle earlier in 
the program changes these errors to "Operation not permitted".

Is there a basic mistake in my use of these calls, or a bug/unmaintained 
code?

I am on an XFS filesystem (otherwise the first call fails with 
'inappropriate ioctl'). The only documentation I can find is the man page; 
no mention about initialising the library, and I wasn't able to find any 
examples.

I'm on Scientific Linux 6.6 (like RedHat 6, kernel 2.6.32-504.1.3), and 
also tried updating to the latest xfsprogs from Git, with the same 
results.

Many thanks

-- 
Mark


$ ./test-xfs ~/scratch/tmp/xfs/file.c; echo $?
Handle 24 bytes: bd2c94ba959858e0000000870000000
readlink_by_handle: Bad file descriptor
open_by_handle: Bad file descriptor
0


$ ./test-xfs ~/scratch/tmp/xfs/file.c; echo $?
Handle 8 bytes: bd2c94ba959858
Handle 24 bytes: bd2c94ba959858e0000000870000000
readlink_by_handle: Operation not permitted
open_by_handle: Operation not permitted
0


/*
 * xfs file handle test
 *
 * compile with: gcc -o test-xfs test-xfs.c -lhandle -Wall
 */

#include <fcntl.h>
#include <limits.h>
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <sys/types.h>
#include <xfs/handle.h>

static void dump(FILE *f, void *m, size_t len)
{
	fprintf(f, "Handle %zu bytes: ", len);

	while (len--) {
		fprintf(f, "%hhx", *(unsigned char*)m);
		m++;
	}

	putchar('\n');
}

int main(int argc, char *argv[])
{
	int fd;
	char *pathname;
	void *hanp = NULL;
	size_t hlen;
	char buf[PATH_MAX];

	pathname = argv[1];

#if 0
	/*
	 * Switching this section on changes changes the
	 * errors from the later calls
	 */

	if (path_to_fshandle(pathname, &hanp, &hlen) == -1) {
		perror("path_to_fshandle");
		return -1;
	}

	dump(stderr, hanp, hlen);

	free_handle(hanp, hlen);
#endif

	if (path_to_handle(pathname, &hanp, &hlen) == -1) {
		perror("path_to_handle");
		return -1;
	}

	dump(stderr, hanp, hlen);

        /*
	 * The above calls were successful, but the next part always
	 * fails
	 */

	if (readlink_by_handle(hanp, hlen, buf, sizeof buf) == -1)
		perror("readlink_by_handle");
	else
		printf("Link: %s\n", buf);

	fd = open_by_handle(hanp, hlen, O_RDONLY);
	if (fd == -1) {
		perror("open_by_handle");
	} else {
		if (close(fd) == -1)
			abort();
	}

	free_handle(hanp, hlen);

	return 0;
}

_______________________________________________
xfs mailing list
xfs@oss.sgi.com
http://oss.sgi.com/mailman/listinfo/xfs

^ permalink raw reply	[flat|nested] 8+ messages in thread

end of thread, other threads:[~2015-04-13  0:25 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2015-04-09 12:53 Errors from basic open_by_handle operations Mark Hills
2015-04-09 13:09 ` Roger Willcocks
2015-04-09 13:36   ` Mark Hills
2015-04-09 13:27 ` Dave Chinner
2015-04-09 13:31 ` [PATCH] libhandle: document the need for path_to_handle tinguely
2015-04-13  0:25   ` Dave Chinner
2015-04-09 14:09 ` Errors from basic open_by_handle operations Roger Willcocks
2015-04-09 14:34   ` Mark Hills

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.