xfs: test fallocate ops when rt extent size is and isn't a power of 2
[xfstests-dev.git] / dmapi / src / suite1 / cmd / probe_hole.c
1 // SPDX-License-Identifier: GPL-2.0
2 /*
3  * Copyright (c) 2000-2001 Silicon Graphics, Inc.
4  * All Rights Reserved.
5  */
6
7 #include <lib/hsm.h>
8
9 #include <getopt.h>
10 #include <string.h>
11
12
13 /*---------------------------------------------------------------------------
14
15 Test program used to test the DMAPI function dm_probe_hole().  The
16 command line is:
17
18         probe_hole [-o offset] [-l length] [-s sid] pathname
19
20 where pathname is the name of a file, offset is the offset of the start of
21 the proposed punch, and length is the length of the punch.  sid is the
22 session ID whose events you you are interested in.
23
24 ----------------------------------------------------------------------------*/
25
26 #ifndef linux
27 extern  char    *sys_errlist[];
28 #endif
29 extern  int     optind;
30 extern  char    *optarg;
31
32
33 char    *Progname;
34
35
36 static void
37 usage(void)
38 {
39         fprintf(stderr, "usage:\t%s [-o offset] [-l length] "
40                 "[-s sid] pathname\n", Progname);
41         exit(1);
42 }
43
44
45 int
46 main(
47         int     argc, 
48         char    **argv)
49 {
50         dm_sessid_t     sid = DM_NO_SESSION;
51         char            *pathname = NULL;
52         dm_off_t        offset = 0;
53         dm_size_t       length = 0;
54         dm_off_t        roffp;
55         dm_size_t       rlenp;
56         void            *hanp;
57         size_t          hlen;
58         char            *name;
59         int             opt;
60
61         Progname = strrchr(argv[0], '/');
62         if (Progname) {
63                 Progname++;
64         } else {
65                 Progname = argv[0];
66         }
67
68         /* Crack and validate the command line options. */
69
70         while ((opt = getopt(argc, argv, "o:l:s:")) != EOF) {
71                 switch (opt) {
72                 case 'o':
73                         offset = atol(optarg);
74                         break;
75                 case 'l':
76                         length = atol(optarg);
77                         break;
78                 case 's':
79                         sid = atol(optarg);
80                         break;
81                 case '?':
82                         usage();
83                 }
84         }
85         if (optind + 1 != argc)
86                 usage();
87         pathname = argv[optind];
88
89         if (dm_init_service(&name) == -1)  {
90                 fprintf(stderr, "Can't initialize the DMAPI\n");
91                 exit(1);
92         }
93         if (sid == DM_NO_SESSION)
94                 find_test_session(&sid);
95
96         /* Get the file's handle. */
97
98         if (dm_path_to_handle(pathname, &hanp, &hlen)) {
99                 fprintf(stderr, "can't get handle for file %s\n", pathname);
100                 exit(1);
101         }
102
103         if (dm_probe_hole(sid, hanp, hlen, DM_NO_TOKEN, offset, length,
104             &roffp, &rlenp)) {
105                 fprintf(stderr, "dm_probe_hole failed, %s\n",
106                         strerror(errno));
107                 exit(1);
108         }
109         fprintf(stdout, "roffp is %lld, rlenp is %llu\n",
110                 (long long) roffp, (unsigned long long) rlenp);
111         dm_handle_free(hanp, hlen);
112         exit(0);
113 }