2 * Copyright (c) 1995, 2001-2003 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 /* attributes.h (purposefully) unavailable to xfsprogs, make do */
37 struct attrlist_cursor
{ __u32 opaque
[4]; };
41 /* just pick a value we know is more than big enough */
45 * The actual content of a handle is supposed to be opaque here.
46 * But, to do handle_to_fshandle, we need to know what it is. Sigh.
47 * However we can get by with knowing only that the first 8 bytes of
48 * a file handle are the file system ID, and that a file system handle
49 * consists of only those 8 bytes.
75 * Filesystem Handle -> Open File Descriptor Cache
77 * Maps filesystem handles to a corresponding open file descriptor for that
78 * filesystem. We need this because we're doing handle operations via xfsctl
79 * and we need to remember the open file descriptor for each filesystem.
86 char fspath
[MAXPATHLEN
];
89 static struct fdhash
*fdhash_head
= NULL
;
93 char *path
, /* input, path to convert */
94 void **hanp
, /* output, pointer to data */
95 size_t *hlen
) /* output, size of returned data */
102 fd
= open(path
, O_RDONLY
);
111 result
= obj_to_handle(path
, fd
, XFS_IOC_PATH_TO_FSHANDLE
,
115 fdhp
= malloc(sizeof(struct fdhash
));
123 strncpy(fdhp
->fspath
, path
, sizeof(fdhp
->fspath
));
124 memcpy(fdhp
->fsh
, *hanp
, FSIDSIZE
);
127 fdhash_head
->fnxt
= fdhp
;
138 char *path
, /* input, path to convert */
139 void **hanp
, /* output, pointer to data */
140 size_t *hlen
) /* output, size of returned data */
146 fd
= open(path
, O_RDONLY
);
155 result
= obj_to_handle (path
, fd
, XFS_IOC_PATH_TO_HANDLE
, obj
, hanp
, hlen
);
173 *fshanp
= malloc (FSIDSIZE
);
180 memcpy(*fshanp
, hanp
, FSIDSIZE
);
187 handle_to_fsfd(void *hanp
, char **path
)
191 for (fdhp
= fdhash_head
; fdhp
!= NULL
; fdhp
= fdhp
->fnxt
) {
192 if (memcmp(fdhp
->fsh
, hanp
, FSIDSIZE
) == 0) {
193 *path
= fdhp
->fspath
;
210 char hbuf
[MAXHANSIZ
];
212 xfs_fsop_handlereq_t hreq
;
214 if (opcode
== XFS_IOC_FD_TO_HANDLE
) {
219 hreq
.path
= obj
.path
;
222 hreq
.oflags
= O_LARGEFILE
;
226 hreq
.ohandlen
= (__u32
*)hlen
;
228 ret
= xfsctl(fspath
, fsfd
, opcode
, &hreq
);
232 *hanp
= malloc(*hlen
);
238 memcpy(*hanp
, hbuf
, (int) *hlen
);
252 xfs_fsop_handlereq_t hreq
;
254 if ((fd
= handle_to_fsfd(hanp
, &path
)) < 0) {
261 hreq
.oflags
= rw
| O_LARGEFILE
;
263 hreq
.ihandlen
= hlen
;
265 hreq
.ohandlen
= NULL
;
267 return xfsctl(path
, fd
, XFS_IOC_OPEN_BY_HANDLE
, &hreq
);
279 xfs_fsop_handlereq_t hreq
;
282 if ((fd
= handle_to_fsfd(hanp
, &path
)) < 0) {
289 hreq
.oflags
= O_LARGEFILE
;
291 hreq
.ihandlen
= hlen
;
293 hreq
.ohandlen
= (__u32
*)&bufsiz
;
295 return xfsctl(path
, fd
, XFS_IOC_READLINK_BY_HANDLE
, &hreq
);
299 attr_multi_by_handle(
308 xfs_fsop_attrmulti_handlereq_t amhreq
;
310 if ((fd
= handle_to_fsfd(hanp
, &path
)) < 0) {
316 amhreq
.hreq
.path
= NULL
;
317 amhreq
.hreq
.oflags
= O_LARGEFILE
;
318 amhreq
.hreq
.ihandle
= hanp
;
319 amhreq
.hreq
.ihandlen
= hlen
;
320 amhreq
.hreq
.ohandle
= NULL
;
321 amhreq
.hreq
.ohandlen
= NULL
;
323 amhreq
.opcount
= rtrvcnt
;
326 return xfsctl(path
, fd
, XFS_IOC_ATTRMULTI_BY_HANDLE
, &amhreq
);
336 struct attrlist_cursor
*cursor
)
340 xfs_fsop_attrlist_handlereq_t alhreq
;
342 if ((fd
= handle_to_fsfd(hanp
, &path
)) < 0) {
348 alhreq
.hreq
.path
= NULL
;
349 alhreq
.hreq
.oflags
= O_LARGEFILE
;
350 alhreq
.hreq
.ihandle
= hanp
;
351 alhreq
.hreq
.ihandlen
= hlen
;
352 alhreq
.hreq
.ohandle
= NULL
;
353 alhreq
.hreq
.ohandlen
= NULL
;
355 memcpy(&alhreq
.pos
, cursor
, sizeof(alhreq
.pos
));
356 alhreq
.flags
= flags
;
357 alhreq
.buflen
= bufsize
;
360 return xfsctl(path
, fd
, XFS_IOC_ATTRLIST_BY_HANDLE
, &alhreq
);
367 struct fsdmidata
*fsdmidata
)
371 xfs_fsop_setdm_handlereq_t dmhreq
;
374 if ((fd
= handle_to_fsfd(hanp
, &path
)) < 0) {
380 dmhreq
.hreq
.path
= NULL
;
381 dmhreq
.hreq
.oflags
= O_LARGEFILE
;
382 dmhreq
.hreq
.ihandle
= hanp
;
383 dmhreq
.hreq
.ihandlen
= hlen
;
384 dmhreq
.hreq
.ohandle
= NULL
;
385 dmhreq
.hreq
.ohandlen
= NULL
;
387 dmhreq
.data
= fsdmidata
;
389 return xfsctl(path
, fd
, XFS_IOC_FSSETDM_BY_HANDLE
, &dmhreq
);