2 * Copyright (c) 2000 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 of the GNU General Public License as
6 * 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 General Public License along
20 * with this program; if not, write the Free Software Foundation, Inc., 59
21 * Temple Place - Suite 330, Boston MA 02111-1307, USA.
23 * Contact information: Silicon Graphics, Inc., 1600 Amphitheatre Pkwy,
24 * Mountain View, CA 94043, or:
28 * For further information regarding this notice, see:
30 * http://oss.sgi.com/projects/GenInfo/SGIGPLNoticeExplan/
36 #include <sys/ioctl.h>
38 /* simple test program to try out a bunch of ioctls:
42 * XFS_IOC_PATH_TO_FSHANDLE
43 * XFS_IOC_PATH_TO_HANDLE
44 * XFS_IOC_FD_TO_HANDLE
45 * XFS_IOC_OPEN_BY_HANDLE
46 * XFS_IOC_READLINK_BY_HANDLE
50 void fscounts(int fsfd)
52 xfs_fsop_counts_t counts;
55 ret=ioctl(fsfd, XFS_IOC_FSCOUNTS, &counts);
57 perror("ioctl(XFS_IOC_FSCOUNTS)");
61 printf("XFS_IOC_FSCOUNTS-\n freedata: %lld freertx: %lld freeino: %lld allocino: %lld\n",
62 counts.freedata, counts.freertx, counts.freeino, counts.allocino);
65 __u64 getresblks(int fsfd)
67 xfs_fsop_resblks_t res;
70 ret=ioctl(fsfd, XFS_IOC_GET_RESBLKS, &res);
72 perror("ioctl(XFS_IOC_GET_RESBLKS)");
76 printf("XFS_IOC_GET_RESBLKS-\n resblks: %lld blksavail: %lld\n",
77 res.resblks, res.resblks_avail);
82 __u64 setresblks(int fsfd, __u64 blks)
84 xfs_fsop_resblks_t res;
88 ret=ioctl(fsfd, XFS_IOC_SET_RESBLKS, &res);
90 perror("ioctl(XFS_IOC_SET_RESBLKS)");
94 printf("XFS_IOC_SET_RESBLKS-\n resblks: %lld blksavail: %lld\n",
95 res.resblks, res.resblks_avail);
100 void handle_print(void *handle, int handlen)
103 if (!handle||!handlen) {
104 printf("%s",handle?"<zero len>":"<NULL>");
110 printf("%02x", *p++);
113 void stat_print(int fd)
117 if (fstat(fd, &buf)) {
121 printf("dev: %llu ino: %llu mode: %o\n",
122 (__u64)buf.st_dev, (__u64)buf.st_ino, buf.st_mode);
126 void handle(int fsfd, char *path)
128 xfs_fsop_handlereq_t handle;
137 handle.ohandle=buffer;
138 handle.ohandlen=&len;
139 ret=ioctl(fsfd, XFS_IOC_PATH_TO_FSHANDLE, &handle);
141 perror("ioctl(XFS_IOC_PATH_TO_FSHANDLE)");
144 printf("XFS_IOC_PATH_TO_FSHANDLE-\n handle: ");
145 handle_print(handle.ohandle, *handle.ohandlen);
148 fd=open(path,O_RDONLY);
155 handle.ohandle=buffer;
156 handle.ohandlen=&len;
157 ret=ioctl(fsfd, XFS_IOC_FD_TO_HANDLE, &handle);
159 perror("ioctl(XFS_IOC_FD_TO_HANDLE)");
163 printf("XFS_IOC_FD_TO_HANDLE-\n path: %s\n handle: ", path);
164 handle_print(handle.ohandle, *handle.ohandlen);
171 handle.ihandle=buffer;
174 handle.ohandlen=NULL;
175 ret=ioctl(fsfd, XFS_IOC_OPEN_BY_HANDLE, &handle);
177 perror("ioctl(XFS_IOC_OPEN_BY_HANDLE)");
180 printf("XFS_IOC_OPEN_BY_HANDLE-\n handle: ");
181 handle_print(handle.ihandle, handle.ihandlen);
182 printf("\n fd: %d\n stat- ", ret);
187 handle.ohandle=buffer;
188 handle.ohandlen=&len;
189 ret=ioctl(fsfd, XFS_IOC_PATH_TO_HANDLE, &handle);
191 perror("ioctl(XFS_IOC_PATH_TO_HANDLE)");
194 printf("XFS_IOC_PATH_TO_HANDLE-\n path: %s\n handle: ", path);
195 handle_print(handle.ohandle, *handle.ohandlen);
200 handle.ihandle=buffer;
203 linklen=sizeof(link);
204 handle.ohandlen=&linklen;
205 ret=ioctl(fsfd, XFS_IOC_READLINK_BY_HANDLE, &handle);
207 perror("ioctl(XFS_IOC_READLINK_BY_HANDLE)");
208 fprintf(stderr,"ERROR IGNORED\n");
210 printf("XFS_IOC_READLINK_BY_HANDLE-\n handle: ");
211 handle_print(handle.ihandle, handle.ihandlen);
212 printf("\n link=\"%*.*s\"\n",
213 ret, ret, (char*)handle.ohandle);
218 main(int argc, char **argv)
223 fprintf(stderr,"usage: %s <filesystem> <file/link in FS>\n",
228 fsfd = open(argv[1], O_RDONLY);
234 /* XFS_IOC_FSCOUNTS */
236 /* XFS_IOC_GET_RESBLKS & XFS_IOC_SET_RESBLKS */
238 setresblks(fsfd, 1000);
241 /* XFS_IOC_FSINUMBERS */
245 /* XFS_IOC_PATH_TO_FSHANDLE */
246 /* XFS_IOC_PATH_TO_HANDLE */
247 /* XFS_IOC_FD_TO_HANDLE */
248 /* XFS_IOC_OPEN_BY_HANDLE */
249 /* XFS_IOC_READLINK_BY_HANDLE */
250 handle(fsfd, argv[2]);