2 * Copyright (c) 2000-2001 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
25 /*---------------------------------------------------------------------------
27 Test program used to test the DMAPI function dm_probe_hole(). The
30 probe_hole [-o offset] [-l length] [-s sid] pathname
32 where pathname is the name of a file, offset is the offset of the start of
33 the proposed punch, and length is the length of the punch. sid is the
34 session ID whose events you you are interested in.
36 ----------------------------------------------------------------------------*/
39 extern char *sys_errlist[];
47 #define METHOD_DMAPI_PROBE 0
48 #define METHOD_DMAPI_PUNCH 1
49 #define METHOD_XFSCTL 2
51 char *methodmap[] = {"DMAPI probe hole",
53 "Punch hole with xfsctl(XFS_IOC_FREESP64)"};
58 fprintf(stderr, "usage:\t%s [-x|-p] [-o offset] [-l length] "
59 "[-s sid] pathname\n", Progname);
72 if ((fd = open(path, O_RDWR|O_CREAT)) < 0) {
78 flock.l_start = offset;
81 if (xfsctl(path, fd, XFS_IOC_FREESP64, &flock)) {
82 fprintf(stderr, "can't XFS_IOC_FREESP64 %s: %s\n",
83 path, strerror(errno));
98 dm_sessid_t sid = DM_NO_SESSION;
99 char *pathname = NULL;
101 dm_size_t length = 0;
109 int method = METHOD_DMAPI_PROBE;
111 if (Progname = strrchr(argv[0], '/')) {
117 /* Crack and validate the command line options. */
119 while ((opt = getopt(argc, argv, "o:l:s:xp")) != EOF) {
122 offset = strtoll(optarg, &p, 10);
123 if (p && (*p == 'k' || *p == 'K'))
127 length = strtoll(optarg, &p, 10);
128 if (p && (*p == 'k' || *p == 'K'))
135 method = METHOD_XFSCTL;
138 method = METHOD_DMAPI_PUNCH;
144 if (optind + 1 != argc)
146 pathname = argv[optind];
151 printf("Running %s on %s with settings:\n", methodmap[method], pathname);
152 printf(" offset = '%lld', length = '%lld', sid = '%lld'\n", offset, length, sid);
154 if (method == METHOD_XFSCTL)
155 return xfsctl_punch_hole(pathname, offset, length);
157 if (dm_init_service(&name) == -1) {
158 fprintf(stderr, "Can't initialize the DMAPI\n");
161 if (sid == DM_NO_SESSION)
162 find_test_session(&sid);
164 /* Get the file's handle. */
166 if (dm_path_to_handle(pathname, &hanp, &hlen)) {
167 fprintf(stderr, "can't get handle for file %s\n", pathname);
172 case METHOD_DMAPI_PROBE:
173 if (dm_probe_hole(sid, hanp, hlen, DM_NO_TOKEN, offset, length,
175 fprintf(stderr, "dm_probe_hole failed, %s\n",
179 fprintf(stdout, "roffp is %lld, rlenp is %lld\n", roffp, rlenp);
181 case METHOD_DMAPI_PUNCH:
182 if (dm_punch_hole(sid, hanp, hlen, DM_NO_TOKEN, offset, length)) {
183 fprintf(stderr, "dm_punch_hole failed, %s\n",
189 dm_handle_free(hanp, hlen);