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>
38 /* attributes.h (purposefully) unavailable to xfsprogs, make do */
39 struct attrlist_cursor
{ __u32 opaque
[4]; };
43 /* just pick a value we know is more than big enough */
47 * The actual content of a handle is supposed to be opaque here.
48 * But, to do handle_to_fshandle, we need to know what it is. Sigh.
49 * However we can get by with knowing only that the first 8 bytes of
50 * a file handle are the file system ID, and that a file system handle
51 * consists of only those 8 bytes.
71 * Filesystem Handle -> Open File Descriptor Cache
73 * Maps filesystem handles to a corresponding open file descriptor for that
74 * filesystem. We need this because we're doing handle operations via ioctl
75 * and we need to remember the open file descriptor for each filesystem.
84 struct fdhash
*fdhash_head
= NULL
;
88 char *path
, /* input, path to convert */
89 void **hanp
, /* output, pointer to data */
90 size_t *hlen
) /* output, size of returned data */
97 fd
= open(path
, O_RDONLY
);
106 result
= obj_to_handle (fd
, XFS_IOC_PATH_TO_FSHANDLE
,
110 fdhp
= malloc(sizeof(struct fdhash
));
120 memcpy(fdhp
->fsh
, *hanp
, FSIDSIZE
);
123 fdhash_head
->fnxt
= fdhp
;
134 char *path
, /* input, path to convert */
135 void **hanp
, /* output, pointer to data */
136 size_t *hlen
) /* output, size of returned data */
142 fd
= open(path
, O_RDONLY
);
151 result
= obj_to_handle (fd
, XFS_IOC_PATH_TO_HANDLE
, obj
, hanp
, hlen
);
161 int fd
, /* input, file descriptor */
162 void **hanp
, /* output, pointer to data */
163 size_t *hlen
) /* output, size of returned data */
169 return obj_to_handle (fd
, XFS_IOC_FD_TO_HANDLE
, obj
, hanp
, hlen
);
183 *fshanp
= malloc (FSIDSIZE
);
190 memcpy(*fshanp
, hanp
, FSIDSIZE
);
197 handle_to_fsfd(void *hanp
)
201 for (fdhp
= fdhash_head
; fdhp
!= NULL
; fdhp
= fdhp
->fnxt
) {
202 if (memcmp(fdhp
->fsh
, hanp
, FSIDSIZE
) == 0)
217 char hbuf
[MAXHANSIZ
];
219 xfs_fsop_handlereq_t hreq
;
221 if (opcode
== XFS_IOC_FD_TO_HANDLE
) {
226 hreq
.path
= obj
.path
;
229 hreq
.oflags
= O_LARGEFILE
;
233 hreq
.ohandlen
= (__u32
*)hlen
;
235 ret
= (int) ioctl(fsfd
, opcode
, &hreq
);
240 *hanp
= malloc(*hlen
);
247 memcpy(*hanp
, hbuf
, (int) *hlen
);
262 xfs_fsop_handlereq_t hreq
;
264 if ((fd
= handle_to_fsfd(hanp
)) < 0) {
271 hreq
.oflags
= rw
| O_LARGEFILE
;
273 hreq
.ihandlen
= hlen
;
275 hreq
.ohandlen
= NULL
;
277 result
= ioctl(fd
, XFS_IOC_OPEN_BY_HANDLE
, &hreq
);
290 xfs_fsop_handlereq_t hreq
;
293 if ((fd
= handle_to_fsfd(hanp
)) < 0) {
300 hreq
.oflags
= O_LARGEFILE
;
302 hreq
.ihandlen
= hlen
;
304 hreq
.ohandlen
= (__u32
*)&bufsiz
;
306 return (int) ioctl(fd
, XFS_IOC_READLINK_BY_HANDLE
, &hreq
);
310 attr_multi_by_handle(
318 xfs_fsop_attrmulti_handlereq_t amhreq
;
320 if ((fd
= handle_to_fsfd(hanp
)) < 0) {
326 amhreq
.hreq
.path
= NULL
;
327 amhreq
.hreq
.oflags
= O_LARGEFILE
;
328 amhreq
.hreq
.ihandle
= hanp
;
329 amhreq
.hreq
.ihandlen
= hlen
;
330 amhreq
.hreq
.ohandle
= NULL
;
331 amhreq
.hreq
.ohandlen
= NULL
;
333 amhreq
.opcount
= rtrvcnt
;
336 return (int) ioctl(fd
, XFS_IOC_ATTRMULTI_BY_HANDLE
, &amhreq
);
346 struct attrlist_cursor
*cursor
)
349 xfs_fsop_attrlist_handlereq_t alhreq
;
351 if ((fd
= handle_to_fsfd(hanp
)) < 0) {
357 alhreq
.hreq
.path
= NULL
;
358 alhreq
.hreq
.oflags
= O_LARGEFILE
;
359 alhreq
.hreq
.ihandle
= hanp
;
360 alhreq
.hreq
.ihandlen
= hlen
;
361 alhreq
.hreq
.ohandle
= NULL
;
362 alhreq
.hreq
.ohandlen
= NULL
;
364 memcpy(&alhreq
.pos
, cursor
, sizeof(alhreq
.pos
));
365 alhreq
.flags
= flags
;
366 alhreq
.buflen
= bufsize
;
369 return (int) ioctl(fd
, XFS_IOC_ATTRLIST_BY_HANDLE
, &alhreq
);
376 struct fsdmidata
*fsdmidata
)
379 xfs_fsop_setdm_handlereq_t dmhreq
;
382 if ((fd
= handle_to_fsfd(hanp
)) < 0) {
388 dmhreq
.hreq
.path
= NULL
;
389 dmhreq
.hreq
.oflags
= O_LARGEFILE
;
390 dmhreq
.hreq
.ihandle
= hanp
;
391 dmhreq
.hreq
.ihandlen
= hlen
;
392 dmhreq
.hreq
.ohandle
= NULL
;
393 dmhreq
.hreq
.ohandlen
= NULL
;
395 dmhreq
.data
= fsdmidata
;
397 return (int) ioctl(fd
, XFS_IOC_FSSETDM_BY_HANDLE
, &dmhreq
);