1 // SPDX-License-Identifier: GPL-2.0
3 * Copyright (c) 2000-2003 Silicon Graphics, Inc.
11 #include <sys/types.h>
17 /* simple test program to try out a bunch of xfsctls:
21 * XFS_IOC_PATH_TO_FSHANDLE
22 * XFS_IOC_PATH_TO_HANDLE
23 * XFS_IOC_FD_TO_HANDLE
24 * XFS_IOC_OPEN_BY_HANDLE
25 * XFS_IOC_READLINK_BY_HANDLE
29 void fscounts(char *fname, int fsfd)
31 xfs_fsop_counts_t counts;
34 ret=xfsctl(fname, fsfd, XFS_IOC_FSCOUNTS, &counts);
36 perror("xfsctl(XFS_IOC_FSCOUNTS)");
40 printf("XFS_IOC_FSCOUNTS-\n freedata: %lld freertx: %lld freeino: %lld allocino: %lld\n",
41 (long long)counts.freedata, (long long)counts.freertx,
42 (long long)counts.freeino, (long long)counts.allocino);
45 __u64 getresblks(char *fname, int fsfd)
47 xfs_fsop_resblks_t res;
50 ret=xfsctl(fname, fsfd, XFS_IOC_GET_RESBLKS, &res);
52 perror("xfsctl(XFS_IOC_GET_RESBLKS)");
56 printf("XFS_IOC_GET_RESBLKS-\n resblks: %lld blksavail: %lld\n",
57 (long long)res.resblks, (long long)res.resblks_avail);
62 __u64 setresblks(char *fname, int fsfd, __u64 blks)
64 xfs_fsop_resblks_t res;
68 ret=xfsctl(fname, fsfd, XFS_IOC_SET_RESBLKS, &res);
70 perror("xfsctl(XFS_IOC_SET_RESBLKS)");
74 printf("XFS_IOC_SET_RESBLKS-\n resblks: %lld blksavail: %lld\n",
75 (long long)res.resblks, (long long)res.resblks_avail);
80 void handle_print(void *handle, int handlen)
83 if (!handle||!handlen) {
84 printf("%s",handle?"<zero len>":"<NULL>");
93 void stat_print(int fd)
97 if (fstat(fd, &buf)) {
101 printf("dev: %llu ino: %llu mode: %o\n",
102 (unsigned long long)buf.st_dev, (unsigned long long)buf.st_ino, buf.st_mode);
106 void handle(char *fname, int fsfd, char *path)
108 xfs_fsop_handlereq_t handle;
117 handle.ohandle=buffer;
118 handle.ohandlen=&len;
119 ret=xfsctl(fname, fsfd, XFS_IOC_PATH_TO_FSHANDLE, &handle);
121 perror("xfsctl(XFS_IOC_PATH_TO_FSHANDLE)");
124 printf("XFS_IOC_PATH_TO_FSHANDLE-\n handle: ");
125 handle_print(handle.ohandle, *handle.ohandlen);
128 fd=open(path,O_RDONLY);
135 handle.ohandle=buffer;
136 handle.ohandlen=&len;
137 ret=xfsctl(fname, fsfd, XFS_IOC_FD_TO_HANDLE, &handle);
139 perror("ioctl(XFS_IOC_FD_TO_HANDLE)");
143 printf("XFS_IOC_FD_TO_HANDLE-\n path: %s\n handle: ", path);
144 handle_print(handle.ohandle, *handle.ohandlen);
151 handle.ihandle=buffer;
154 handle.ohandlen=NULL;
155 ret=xfsctl(fname, fsfd, XFS_IOC_OPEN_BY_HANDLE, &handle);
157 perror("xfsctl(XFS_IOC_OPEN_BY_HANDLE)");
160 printf("XFS_IOC_OPEN_BY_HANDLE-\n handle: ");
161 handle_print(handle.ihandle, handle.ihandlen);
162 printf("\n fd: %d\n stat- ", ret);
167 handle.ohandle=buffer;
168 handle.ohandlen=&len;
169 ret=xfsctl(fname, fsfd, XFS_IOC_PATH_TO_HANDLE, &handle);
171 perror("xfsctl(XFS_IOC_PATH_TO_HANDLE)");
174 printf("XFS_IOC_PATH_TO_HANDLE-\n path: %s\n handle: ", path);
175 handle_print(handle.ohandle, *handle.ohandlen);
180 handle.ihandle=buffer;
183 linklen=sizeof(link);
184 handle.ohandlen=&linklen;
185 ret=xfsctl(fname, fsfd, XFS_IOC_READLINK_BY_HANDLE, &handle);
187 perror("xfsctl(XFS_IOC_READLINK_BY_HANDLE)");
188 fprintf(stderr,"ERROR IGNORED\n");
190 printf("XFS_IOC_READLINK_BY_HANDLE-\n handle: ");
191 handle_print(handle.ihandle, handle.ihandlen);
192 printf("\n link=\"%*.*s\"\n",
193 ret, ret, (char*)handle.ohandle);
198 main(int argc, char **argv)
203 fprintf(stderr,"usage: %s <filesystem> <file/link in FS>\n",
208 fsfd = open(argv[1], O_RDONLY);
214 /* XFS_IOC_FSCOUNTS */
215 fscounts(argv[0], fsfd);
216 /* XFS_IOC_GET_RESBLKS & XFS_IOC_SET_RESBLKS */
217 getresblks(argv[0], fsfd);
218 setresblks(argv[0], fsfd, 1000);
219 getresblks(argv[0], fsfd);
220 setresblks(argv[0], fsfd, 0);
221 /* TODO - XFS_IOC_FSINUMBERS */
223 /* XFS_IOC_PATH_TO_FSHANDLE */
224 /* XFS_IOC_PATH_TO_HANDLE */
225 /* XFS_IOC_FD_TO_HANDLE */
226 /* XFS_IOC_OPEN_BY_HANDLE */
227 /* XFS_IOC_READLINK_BY_HANDLE */
228 handle(argv[0], fsfd, argv[2]);