2 * Copyright (c) 2000-2003 Silicon Graphics, Inc.
5 * This program is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU General Public License as
7 * published by the Free Software Foundation.
9 * This program is distributed in the hope that it would be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
14 * You should have received a copy of the GNU General Public License
15 * along with this program; if not, write the Free Software Foundation,
16 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
23 #include <sys/types.h>
29 /* simple test program to try out a bunch of xfsctls:
33 * XFS_IOC_PATH_TO_FSHANDLE
34 * XFS_IOC_PATH_TO_HANDLE
35 * XFS_IOC_FD_TO_HANDLE
36 * XFS_IOC_OPEN_BY_HANDLE
37 * XFS_IOC_READLINK_BY_HANDLE
41 void fscounts(char *fname, int fsfd)
43 xfs_fsop_counts_t counts;
46 ret=xfsctl(fname, fsfd, XFS_IOC_FSCOUNTS, &counts);
48 perror("xfsctl(XFS_IOC_FSCOUNTS)");
52 printf("XFS_IOC_FSCOUNTS-\n freedata: %lld freertx: %lld freeino: %lld allocino: %lld\n",
53 (long long)counts.freedata, (long long)counts.freertx,
54 (long long)counts.freeino, (long long)counts.allocino);
57 __u64 getresblks(char *fname, int fsfd)
59 xfs_fsop_resblks_t res;
62 ret=xfsctl(fname, fsfd, XFS_IOC_GET_RESBLKS, &res);
64 perror("xfsctl(XFS_IOC_GET_RESBLKS)");
68 printf("XFS_IOC_GET_RESBLKS-\n resblks: %lld blksavail: %lld\n",
69 (long long)res.resblks, (long long)res.resblks_avail);
74 __u64 setresblks(char *fname, int fsfd, __u64 blks)
76 xfs_fsop_resblks_t res;
80 ret=xfsctl(fname, fsfd, XFS_IOC_SET_RESBLKS, &res);
82 perror("xfsctl(XFS_IOC_SET_RESBLKS)");
86 printf("XFS_IOC_SET_RESBLKS-\n resblks: %lld blksavail: %lld\n",
87 (long long)res.resblks, (long long)res.resblks_avail);
92 void handle_print(void *handle, int handlen)
95 if (!handle||!handlen) {
96 printf("%s",handle?"<zero len>":"<NULL>");
102 printf("%02x", *p++);
105 void stat_print(int fd)
109 if (fstat(fd, &buf)) {
113 printf("dev: %llu ino: %llu mode: %o\n",
114 (unsigned long long)buf.st_dev, (unsigned long long)buf.st_ino, buf.st_mode);
118 void handle(char *fname, int fsfd, char *path)
120 xfs_fsop_handlereq_t handle;
129 handle.ohandle=buffer;
130 handle.ohandlen=&len;
131 ret=xfsctl(fname, fsfd, XFS_IOC_PATH_TO_FSHANDLE, &handle);
133 perror("xfsctl(XFS_IOC_PATH_TO_FSHANDLE)");
136 printf("XFS_IOC_PATH_TO_FSHANDLE-\n handle: ");
137 handle_print(handle.ohandle, *handle.ohandlen);
140 fd=open(path,O_RDONLY);
147 handle.ohandle=buffer;
148 handle.ohandlen=&len;
149 ret=xfsctl(fname, fsfd, XFS_IOC_FD_TO_HANDLE, &handle);
151 perror("ioctl(XFS_IOC_FD_TO_HANDLE)");
155 printf("XFS_IOC_FD_TO_HANDLE-\n path: %s\n handle: ", path);
156 handle_print(handle.ohandle, *handle.ohandlen);
163 handle.ihandle=buffer;
166 handle.ohandlen=NULL;
167 ret=xfsctl(fname, fsfd, XFS_IOC_OPEN_BY_HANDLE, &handle);
169 perror("xfsctl(XFS_IOC_OPEN_BY_HANDLE)");
172 printf("XFS_IOC_OPEN_BY_HANDLE-\n handle: ");
173 handle_print(handle.ihandle, handle.ihandlen);
174 printf("\n fd: %d\n stat- ", ret);
179 handle.ohandle=buffer;
180 handle.ohandlen=&len;
181 ret=xfsctl(fname, fsfd, XFS_IOC_PATH_TO_HANDLE, &handle);
183 perror("xfsctl(XFS_IOC_PATH_TO_HANDLE)");
186 printf("XFS_IOC_PATH_TO_HANDLE-\n path: %s\n handle: ", path);
187 handle_print(handle.ohandle, *handle.ohandlen);
192 handle.ihandle=buffer;
195 linklen=sizeof(link);
196 handle.ohandlen=&linklen;
197 ret=xfsctl(fname, fsfd, XFS_IOC_READLINK_BY_HANDLE, &handle);
199 perror("xfsctl(XFS_IOC_READLINK_BY_HANDLE)");
200 fprintf(stderr,"ERROR IGNORED\n");
202 printf("XFS_IOC_READLINK_BY_HANDLE-\n handle: ");
203 handle_print(handle.ihandle, handle.ihandlen);
204 printf("\n link=\"%*.*s\"\n",
205 ret, ret, (char*)handle.ohandle);
210 main(int argc, char **argv)
215 fprintf(stderr,"usage: %s <filesystem> <file/link in FS>\n",
220 fsfd = open(argv[1], O_RDONLY);
226 /* XFS_IOC_FSCOUNTS */
227 fscounts(argv[0], fsfd);
228 /* XFS_IOC_GET_RESBLKS & XFS_IOC_SET_RESBLKS */
229 getresblks(argv[0], fsfd);
230 setresblks(argv[0], fsfd, 1000);
231 getresblks(argv[0], fsfd);
232 setresblks(argv[0], fsfd, 0);
233 /* TODO - XFS_IOC_FSINUMBERS */
235 /* XFS_IOC_PATH_TO_FSHANDLE */
236 /* XFS_IOC_PATH_TO_HANDLE */
237 /* XFS_IOC_FD_TO_HANDLE */
238 /* XFS_IOC_OPEN_BY_HANDLE */
239 /* XFS_IOC_READLINK_BY_HANDLE */
240 handle(argv[0], fsfd, argv[2]);