2 * Copyright (c) 1995-2001 Silicon Graphics, Inc. All Rights Reserved.
4 * This program is free software; you can redistribute it and/or modify it
5 * under the terms of version 2.1 of the GNU Lesser General Public License
6 * as published by the Free Software Foundation.
8 * This program is distributed in the hope that it would be useful, but
9 * WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
12 * Further, this software is distributed without any warranty that it is
13 * free of the rightful claim of any third person regarding infringement
14 * or the like. Any license provided herein, whether implied or
15 * otherwise, applies only to this software file. Patent licenses, if
16 * any, provided herein do not apply to combinations of this program with
17 * other software, or any other product whatsoever.
19 * You should have received a copy of the GNU Lesser General Public
20 * License along with this program; if not, write the Free Software
21 * Foundation, Inc., 59 Temple Place - Suite 330, Boston MA 02111-1307,
24 * Contact information: Silicon Graphics, Inc., 1600 Amphitheatre Pkwy,
25 * Mountain View, CA 94043, or:
29 * For further information regarding this notice, see:
31 * http://oss.sgi.com/projects/GenInfo/SGIGPLNoticeExplan/
36 #include <sys/ioctl.h>
39 /* just pick a value we know is more than big enough */
43 * The actual content of a handle is supposed to be opaque here.
44 * But, to do handle_to_fshandle, we need to know what it is. Sigh.
45 * However we can get by with knowing only that the first 8 bytes of
46 * a file handle are the file system ID, and that a file system handle
47 * consists of only those 8 bytes.
68 * Filesystem Handle -> Open File Descriptor Cache
70 * Maps filesystem handles to a corresponding open file descriptor for that
71 * filesystem. We need this because we're doing handle operations via ioctl
72 * and we need to remember the open file descriptor for each filesystem.
81 struct fdhash
*fdhash_head
= NULL
;
85 char *path
, /* input, path to convert */
86 void **hanp
, /* output, pointer to data */
87 size_t *hlen
) /* output, size of returned data */
94 fd
= open(path
, O_RDONLY
);
103 result
= obj_to_handle (fd
, XFS_IOC_PATH_TO_FSHANDLE
,
107 fdhp
= malloc(sizeof(struct fdhash
));
117 memcpy(fdhp
->fsh
, *hanp
, FSIDSIZE
);
120 fdhash_head
->fnxt
= fdhp
;
131 char *path
, /* input, path to convert */
132 void **hanp
, /* output, pointer to data */
133 size_t *hlen
) /* output, size of returned data */
139 fd
= open(path
, O_RDONLY
);
148 result
= obj_to_handle (fd
, XFS_IOC_PATH_TO_HANDLE
, obj
, hanp
, hlen
);
158 int fd
, /* input, file descriptor */
159 void **hanp
, /* output, pointer to data */
160 size_t *hlen
) /* output, size of returned data */
166 return obj_to_handle (fd
, XFS_IOC_FD_TO_HANDLE
, obj
, hanp
, hlen
);
180 *fshanp
= malloc (FSIDSIZE
);
187 memcpy(*fshanp
, hanp
, FSIDSIZE
);
194 handle_to_fsfd(void *hanp
)
198 for (fdhp
= fdhash_head
; fdhp
!= NULL
; fdhp
= fdhp
->fnxt
) {
199 if (memcmp(fdhp
->fsh
, hanp
, FSIDSIZE
) == 0)
214 char hbuf
[MAXHANSIZ
];
216 xfs_fsop_handlereq_t hreq
;
218 if (opcode
== XFS_IOC_FD_TO_HANDLE
) {
223 hreq
.path
= obj
.path
;
230 hreq
.ohandlen
= (__u32
*)hlen
;
232 ret
= (int) ioctl(fsfd
, opcode
, &hreq
);
237 *hanp
= malloc(*hlen
);
244 memcpy(*hanp
, hbuf
, (int) *hlen
);
259 xfs_fsop_handlereq_t hreq
;
261 if ((fd
= handle_to_fsfd(hanp
)) < 0) {
270 hreq
.ihandlen
= hlen
;
272 hreq
.ohandlen
= NULL
;
274 result
= ioctl(fd
, XFS_IOC_OPEN_BY_HANDLE
, &hreq
);
287 xfs_fsop_handlereq_t hreq
;
290 if ((fd
= handle_to_fsfd(hanp
)) < 0) {
299 hreq
.ihandlen
= hlen
;
301 hreq
.ohandlen
= (__u32
*)&bufsiz
;
303 return (int) ioctl(fd
, XFS_IOC_READLINK_BY_HANDLE
, &hreq
);
310 struct fsdmidata
*fsdmidata
)
313 xfs_fsop_setdm_handlereq_t dmhreq
;
316 if ((fd
= handle_to_fsfd(hanp
)) < 0) {
322 dmhreq
.hreq
.path
= NULL
;
323 dmhreq
.hreq
.oflags
= 0;
324 dmhreq
.hreq
.ihandle
= hanp
;
325 dmhreq
.hreq
.ihandlen
= hlen
;
326 dmhreq
.hreq
.ohandle
= NULL
;
327 dmhreq
.hreq
.ohandlen
= NULL
;
329 dmhreq
.data
= fsdmidata
;
331 return (int) ioctl(fd
, XFS_IOC_FSSETDM_BY_HANDLE
, &dmhreq
);