Fix build failure.
[xfstests-dev.git] / dmapi / src / suite2 / src / region_test.c
1 /*
2  * Copyright (c) 2000-2001 Silicon Graphics, Inc.
3  * All Rights Reserved.
4  *
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.
8  *
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.
13  *
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
17  */
18
19 #include <sys/types.h>
20
21 #include <lib/hsm.h>
22 #include <lib/errtest.h>
23
24 #include <getopt.h>
25 #include <string.h>
26
27
28 /*---------------------------------------------------------------------------
29
30 Manual test for the DMAPI functions dm_set_region() and dm_get_region().
31
32 The command line is:
33
34         region_test [-Rv] [-s sid] [-l len] [-o offset] ls_path directory 
35
36 where 
37    -R
38         reuse the existing test file
39    pathname
40       is the name of a file
41    ls_path
42       is the path to a specific copy of ls, important only for its size
43    sid
44       is the session ID whose events you you are interested in.
45 ----------------------------------------------------------------------------*/
46
47 #define NELEM   1
48
49 #ifndef linux
50 extern  char    *sys_errlist[];
51 #endif
52 extern  int     optind;
53 extern  char    *optarg;
54
55
56 char    *Progname;
57
58
59 static void
60 usage(void)
61 {
62         fprintf(stderr, "usage:\t%s [-Rv] [-s sid] [-l len] [-o offset] ls_path pathname\n", Progname);
63         exit(1);
64 }
65
66
67 int
68 main(
69         int     argc, 
70         char    **argv)
71 {
72         dm_sessid_t     sid = DM_NO_SESSION;
73         char            *dir_name = NULL;
74         char            *ls_path = NULL;
75         char            command[1024];
76         char            test_file[128];
77         int             opt;
78         int             Vflag = 0;
79         dm_region_t     region = { 0, 0, 0 };
80         char            *name;
81         int             reuse_file = 0;
82         void            *hanp;
83         size_t           hlen;
84         dm_boolean_t    exactflag;
85
86         if (Progname = strrchr(argv[0], '/')) {
87                 Progname++;
88         } else {
89                 Progname = argv[0];
90         }
91
92         /* Crack and validate the command line options. */
93
94         while ((opt = getopt(argc, argv, "vo:l:s:R")) != EOF) {
95                 switch (opt) {
96                 case 'v':
97                         Vflag++;
98                         break;
99                 case 'R':
100                         reuse_file++;
101                         break;
102                 case 'o':
103                         region.rg_offset = atol(optarg);
104                         break;
105                 case 'l':
106                         region.rg_size = atol(optarg);
107                         break;
108                 case 's':
109                         sid = atol(optarg);
110                         break;
111                 case '?':
112                         usage();
113                 }
114         }
115         if (optind + 2 > argc)
116                 usage();
117         ls_path = argv[optind];
118         dir_name = argv[optind+1];
119
120         if (dm_init_service(&name) == -1)  {
121                 fprintf(stderr, "Can't initialize the DMAPI\n");
122                 exit(1);
123         }
124         if (sid == DM_NO_SESSION)
125                 find_test_session(&sid);
126
127         sprintf(test_file, "%s/DMAPI_test_file", dir_name);
128         if( !reuse_file ){
129                 sprintf(command, "cp %s %s\n", ls_path, test_file); 
130                 system(command);
131         }
132
133         if (dm_path_to_handle(test_file, &hanp, &hlen)) {
134                 fprintf(stderr, "can't get handle for file %s\n", test_file);
135                 exit(1);
136         }
137
138         region.rg_flags = DM_REGION_READ | DM_REGION_WRITE | DM_REGION_TRUNCATE;
139         if( dm_set_region( sid, hanp, hlen, DM_NO_TOKEN, NELEM,
140                           &region, &exactflag ) ){
141                 fprintf(stderr, "dm_set_region failed, err=%d\n", errno);
142                 dm_handle_free(hanp,hlen);
143                 exit(1);
144         }
145         if( exactflag == DM_FALSE )
146                 fprintf(stderr, "exact flag was false\n");
147
148         dm_handle_free(hanp, hlen);
149         exit(0);
150 }