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
24 /* simple test program to try out a bunch of xfsctls:
28 * XFS_IOC_PATH_TO_FSHANDLE
29 * XFS_IOC_PATH_TO_HANDLE
30 * XFS_IOC_FD_TO_HANDLE
31 * XFS_IOC_OPEN_BY_HANDLE
32 * XFS_IOC_READLINK_BY_HANDLE
36 void fscounts(char *fname, int fsfd)
38 xfs_fsop_counts_t counts;
41 ret=xfsctl(fname, fsfd, XFS_IOC_FSCOUNTS, &counts);
43 perror("xfsctl(XFS_IOC_FSCOUNTS)");
47 printf("XFS_IOC_FSCOUNTS-\n freedata: %lld freertx: %lld freeino: %lld allocino: %lld\n",
48 (long long)counts.freedata, (long long)counts.freertx,
49 (long long)counts.freeino, (long long)counts.allocino);
52 __u64 getresblks(char *fname, int fsfd)
54 xfs_fsop_resblks_t res;
57 ret=xfsctl(fname, fsfd, XFS_IOC_GET_RESBLKS, &res);
59 perror("xfsctl(XFS_IOC_GET_RESBLKS)");
63 printf("XFS_IOC_GET_RESBLKS-\n resblks: %lld blksavail: %lld\n",
64 (long long)res.resblks, (long long)res.resblks_avail);
69 __u64 setresblks(char *fname, int fsfd, __u64 blks)
71 xfs_fsop_resblks_t res;
75 ret=xfsctl(fname, fsfd, XFS_IOC_SET_RESBLKS, &res);
77 perror("xfsctl(XFS_IOC_SET_RESBLKS)");
81 printf("XFS_IOC_SET_RESBLKS-\n resblks: %lld blksavail: %lld\n",
82 (long long)res.resblks, (long long)res.resblks_avail);
87 void handle_print(void *handle, int handlen)
90 if (!handle||!handlen) {
91 printf("%s",handle?"<zero len>":"<NULL>");
100 void stat_print(int fd)
104 if (fstat(fd, &buf)) {
108 printf("dev: %llu ino: %llu mode: %o\n",
109 (unsigned long long)buf.st_dev, (unsigned long long)buf.st_ino, buf.st_mode);
113 void handle(char *fname, int fsfd, char *path)
115 xfs_fsop_handlereq_t handle;
124 handle.ohandle=buffer;
125 handle.ohandlen=&len;
126 ret=xfsctl(fname, fsfd, XFS_IOC_PATH_TO_FSHANDLE, &handle);
128 perror("xfsctl(XFS_IOC_PATH_TO_FSHANDLE)");
131 printf("XFS_IOC_PATH_TO_FSHANDLE-\n handle: ");
132 handle_print(handle.ohandle, *handle.ohandlen);
135 fd=open(path,O_RDONLY);
142 handle.ohandle=buffer;
143 handle.ohandlen=&len;
144 ret=xfsctl(fname, fsfd, XFS_IOC_FD_TO_HANDLE, &handle);
146 perror("ioctl(XFS_IOC_FD_TO_HANDLE)");
150 printf("XFS_IOC_FD_TO_HANDLE-\n path: %s\n handle: ", path);
151 handle_print(handle.ohandle, *handle.ohandlen);
158 handle.ihandle=buffer;
161 handle.ohandlen=NULL;
162 ret=xfsctl(fname, fsfd, XFS_IOC_OPEN_BY_HANDLE, &handle);
164 perror("xfsctl(XFS_IOC_OPEN_BY_HANDLE)");
167 printf("XFS_IOC_OPEN_BY_HANDLE-\n handle: ");
168 handle_print(handle.ihandle, handle.ihandlen);
169 printf("\n fd: %d\n stat- ", ret);
174 handle.ohandle=buffer;
175 handle.ohandlen=&len;
176 ret=xfsctl(fname, fsfd, XFS_IOC_PATH_TO_HANDLE, &handle);
178 perror("xfsctl(XFS_IOC_PATH_TO_HANDLE)");
181 printf("XFS_IOC_PATH_TO_HANDLE-\n path: %s\n handle: ", path);
182 handle_print(handle.ohandle, *handle.ohandlen);
187 handle.ihandle=buffer;
190 linklen=sizeof(link);
191 handle.ohandlen=&linklen;
192 ret=xfsctl(fname, fsfd, XFS_IOC_READLINK_BY_HANDLE, &handle);
194 perror("xfsctl(XFS_IOC_READLINK_BY_HANDLE)");
195 fprintf(stderr,"ERROR IGNORED\n");
197 printf("XFS_IOC_READLINK_BY_HANDLE-\n handle: ");
198 handle_print(handle.ihandle, handle.ihandlen);
199 printf("\n link=\"%*.*s\"\n",
200 ret, ret, (char*)handle.ohandle);
205 main(int argc, char **argv)
210 fprintf(stderr,"usage: %s <filesystem> <file/link in FS>\n",
215 fsfd = open(argv[1], O_RDONLY);
221 /* XFS_IOC_FSCOUNTS */
222 fscounts(argv[0], fsfd);
223 /* XFS_IOC_GET_RESBLKS & XFS_IOC_SET_RESBLKS */
224 getresblks(argv[0], fsfd);
225 setresblks(argv[0], fsfd, 1000);
226 getresblks(argv[0], fsfd);
227 setresblks(argv[0], fsfd, 0);
228 /* TODO - XFS_IOC_FSINUMBERS */
230 /* XFS_IOC_PATH_TO_FSHANDLE */
231 /* XFS_IOC_PATH_TO_HANDLE */
232 /* XFS_IOC_FD_TO_HANDLE */
233 /* XFS_IOC_OPEN_BY_HANDLE */
234 /* XFS_IOC_READLINK_BY_HANDLE */
235 handle(argv[0], fsfd, argv[2]);