All of lore.kernel.org
 help / color / mirror / Atom feed
From: Mark Hills <mark.hills@framestore.com>
To: xfs@oss.sgi.com
Subject: Errors from basic open_by_handle operations
Date: Thu, 9 Apr 2015 13:53:31 +0100 (BST)	[thread overview]
Message-ID: <1504091316590.18609@sys953.ldn.framestore.com> (raw)

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

             reply	other threads:[~2015-04-09 12:53 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-04-09 12:53 Mark Hills [this message]
2015-04-09 13:09 ` Errors from basic open_by_handle operations 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

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1504091316590.18609@sys953.ldn.framestore.com \
    --to=mark.hills@framestore.com \
    --cc=xfs@oss.sgi.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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.