struct attrlist_cursor;
extern int path_to_handle (char *__path, void **__hanp, size_t *__hlen);
-extern int path_to_fshandle (char *__path, void **__hanp, size_t *__hlen);
+extern int path_to_fshandle (char *__path, void **__fshanp, size_t *__fshlen);
extern int handle_to_fshandle (void *__hanp, size_t __hlen, void **__fshanp,
size_t *__fshlen);
extern void free_handle (void *__hanp, size_t __hlen);
+extern int open_by_fshandle (void *__fshanp, size_t __fshlen, int __rw);
extern int open_by_handle (void *__hanp, size_t __hlen, int __rw);
extern int readlink_by_handle (void *__hanp, size_t __hlen, void *__buf,
size_t __bs);
int
path_to_fshandle(
char *path, /* input, path to convert */
- void **hanp, /* output, pointer to data */
- size_t *hlen) /* output, size of returned data */
+ void **fshanp, /* output, pointer to data */
+ size_t *fshlen) /* output, size of returned data */
{
int result;
int fd;
comarg_t obj;
struct fdhash *fdhp;
+ struct fdhash *tmphp=NULL;
fd = open(path, O_RDONLY);
if (fd < 0)
obj.path = path;
result = obj_to_handle(path, fd, XFS_IOC_PATH_TO_FSHANDLE,
- obj, hanp, hlen);
+ obj, fshanp, fshlen);
if (result >= 0) {
fdhp = malloc(sizeof(struct fdhash));
if (fdhp == NULL) {
fdhp->fsfd = fd;
fdhp->fnxt = NULL;
strncpy(fdhp->fspath, path, sizeof(fdhp->fspath));
- memcpy(fdhp->fsh, *hanp, FSIDSIZE);
-
- if (fdhash_head)
- fdhash_head->fnxt = fdhp;
- else
- fdhash_head = fdhp;
+ memcpy(fdhp->fsh, *fshanp, FSIDSIZE);
+
+ if (fdhash_head) {
+ for( tmphp=fdhash_head; tmphp; tmphp=tmphp->fnxt ) {
+ if ( fdhp->fsfd == tmphp->fsfd ) {
+ free (fdhp); /* already in hash */
+ break;
+ }
+ }
+ if (tmphp == NULL) { /* not in hash, add it now */
+ fdhp->fnxt = fdhash_head;
+ fdhash_head = fdhp;
+ }
+ } else {
+ fdhash_head = fdhp;
+ }
}
return result;
return 0;
}
+int
+open_by_fshandle(
+ void *fshanp,
+ size_t fshlen,
+ int rw)
+{
+ int fsfd;
+ char *path;
+ xfs_fsop_handlereq_t hreq;
+
+ if ((fsfd = handle_to_fsfd(fshanp, &path)) < 0)
+ return -1;
+
+ hreq.fd = 0;
+ hreq.path = NULL;
+ hreq.oflags = rw | O_LARGEFILE;
+ hreq.ihandle = fshanp;
+ hreq.ihandlen = fshlen;
+ hreq.ohandle = NULL;
+ hreq.ohandlen = NULL;
+
+ return xfsctl(path, fsfd, XFS_IOC_OPEN_BY_HANDLE, &hreq);
+}
+
int
open_by_handle(
void *hanp,
size_t hlen,
int rw)
{
- int fd;
+ int fsfd;
char *path;
+ void *fshanp;
+ size_t fshlen;
xfs_fsop_handlereq_t hreq;
- if ((fd = handle_to_fsfd(hanp, &path)) < 0)
+ if (handle_to_fshandle(hanp, hlen, &fshanp, &fshlen) != 0)
+ return -1;
+
+ if ((fsfd = handle_to_fsfd(fshanp, &path)) < 0)
return -1;
hreq.fd = 0;
hreq.ohandle = NULL;
hreq.ohandlen = NULL;
- return xfsctl(path, fd, XFS_IOC_OPEN_BY_HANDLE, &hreq);
+ return xfsctl(path, fsfd, XFS_IOC_OPEN_BY_HANDLE, &hreq);
}
int
char fsh_space[FSHANDLE_SZ];
} fshandle_t;
-/* private file handle - for use by open_by_handle */
+/* private file handle - for use by open_by_fshandle */
#define FILEHANDLE_SZ 24
#define FILEHANDLE_SZ_FOLLOWING 14
#define FILEHANDLE_SZ_PAD 2
intgen_t fd;
jdm_fill_filehandle( &filehandle, fshandlep, statp );
- fd = open_by_handle( ( void * )&filehandle,
+ fd = open_by_fshandle( ( void * )&filehandle,
sizeof( filehandle ),
oflags );
return fd;