xfstests: eliminate warnings under dmapi/src/suite1/cmd (3)
[xfstests-dev.git] / dmapi / src / suite1 / cmd / get_eventlist.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 <lib/hsm.h>
20
21 #include <string.h>
22 #include <getopt.h>
23
24 /*---------------------------------------------------------------------------
25
26 Test program used to test the DMAPI function dm_get_eventlist().  The
27 command line is:
28
29         get_eventlist [-F] [-n nelem] [-s sid] [-t token] {pathname|handle}
30
31 where:
32 {pathname|handle}
33         is the pathname of a file or filesystem or a handle.
34 -n nelem
35         is the value to use for the nelem parameter to dm_get_eventlist().
36 -s sid
37         is the dm_sessid_t to use in place of the default test session.
38 -t token
39         is the dm_token_t to use in place of DM_NO_TOKEN.
40 -F
41         is used when a pathname is specified to indicate that you want its
42         filesystem handle, not its file handle.
43
44 ----------------------------------------------------------------------------*/
45
46 extern  int     optind;
47 extern  char    *optarg;
48
49
50 char    *Progname;
51
52
53
54 static void
55 usage(void)
56 {
57         fprintf(stderr, "usage:\t%s [-F] [-n nelem] [-s sid] [-t token] "
58                 "{pathname|handle}\n",
59                 Progname);
60         exit(1);
61 }
62
63
64 int
65 main(
66         int     argc, 
67         char    **argv)
68 {
69         dm_sessid_t      sid = DM_NO_SESSION;
70         dm_token_t      token = DM_NO_TOKEN;
71         u_int           nelem = DM_EVENT_MAX;
72         char            *object;
73         dm_eventset_t   eventset;
74         void            *hanp;
75         size_t           hlen;
76         u_int           nelemp;
77         char            *name;
78         int             Fflag = 0;
79         int             error;
80         int             opt;
81         int             i;
82
83         Progname = strrchr(argv[0], '/');
84         if (Progname) {
85                 Progname++;
86         } else {
87                 Progname = argv[0];
88         }
89
90         /* Crack and validate the command line options. */
91
92         while ((opt = getopt(argc, argv, "Fn:s:t:")) != EOF) {
93                 switch (opt) {
94                 case 'F':
95                         Fflag++;
96                         break;
97                 case 'n':
98                         nelem = atol(optarg);
99                         break;
100                 case 's':
101                         sid = atol(optarg);
102                         break;
103                 case 't':
104                         token = atol(optarg);
105                         break;
106                 case '?':
107                         usage();
108                 }
109         }
110         if (optind + 1 != argc)
111                 usage();
112         object = argv[optind];
113
114         if (dm_init_service(&name) == -1)  {
115                 fprintf(stderr, "Can't initialize the DMAPI\n");
116                 exit(1);
117         }
118
119         if ((error = opaque_to_handle(object, &hanp, &hlen)) != 0) {
120                 fprintf(stderr, "can't get a handle from %s, %s\n",
121                         object, strerror(error));
122                 return(1);
123         }
124
125         if (Fflag) {
126                 void    *fshanp;
127                 size_t  fshlen;
128
129                 if (dm_handle_to_fshandle(hanp, hlen, &fshanp, &fshlen)) {
130                         fprintf(stderr, "can't get filesystem handle from %s\n",
131                                 object);
132                         exit(1);
133                 }
134                 dm_handle_free(hanp, hlen);
135                 hanp = fshanp;
136                 hlen = fshlen;
137         }
138
139         if (sid == DM_NO_SESSION)
140                 find_test_session(&sid);
141
142         DMEV_ZERO(eventset);
143
144         if (dm_get_eventlist(sid, hanp, hlen, token, nelem,
145             &eventset, &nelemp)) {
146                 fprintf(stderr, "dm_get_eventlist failed, %s\n",
147                         strerror(errno));
148                 return(1);
149         }
150
151         fprintf(stdout, "Events on object %s (0x%llx), nelemp %d:\n",
152                 object, (unsigned long long) eventset, nelemp);
153
154         for (i = 0; i < nelemp; i++) {
155                 if (!DMEV_ISSET(i, eventset))
156                         continue;
157                 switch (i) {
158                 case DM_EVENT_CANCEL:
159                         fprintf(stdout, "DM_EVENT_CANCEL");
160                         break;
161                 case DM_EVENT_MOUNT:
162                         fprintf(stdout, "DM_EVENT_MOUNT");
163                         break;
164                 case DM_EVENT_PREUNMOUNT:
165                         fprintf(stdout, "DM_EVENT_PREUNMOUNT");
166                         break;
167                 case DM_EVENT_UNMOUNT:
168                         fprintf(stdout, "DM_EVENT_UNMOUNT");
169                         break;
170                 case DM_EVENT_DEBUT:
171                         fprintf(stdout, "DM_EVENT_DEBUT");
172                         break;
173                 case DM_EVENT_CREATE:
174                         fprintf(stdout, "DM_EVENT_CREATE");
175                         break;
176                 case DM_EVENT_CLOSE:
177                         fprintf(stdout, "DM_EVENT_CLOSE");
178                         break;
179                 case DM_EVENT_POSTCREATE:
180                         fprintf(stdout, "DM_EVENT_POSTCREATE");
181                         break;
182                 case DM_EVENT_REMOVE:
183                         fprintf(stdout, "DM_EVENT_REMOVE");
184                         break;
185                 case DM_EVENT_POSTREMOVE:
186                         fprintf(stdout, "DM_EVENT_POSTREMOVE");
187                         break;
188                 case DM_EVENT_RENAME:
189                         fprintf(stdout, "DM_EVENT_RENAME");
190                         break;
191                 case DM_EVENT_POSTRENAME:
192                         fprintf(stdout, "DM_EVENT_POSTRENAME");
193                         break;
194                 case DM_EVENT_LINK:
195                         fprintf(stdout, "DM_EVENT_LINK");
196                         break;
197                 case DM_EVENT_POSTLINK:
198                         fprintf(stdout, "DM_EVENT_POSTLINK");
199                         break;
200                 case DM_EVENT_SYMLINK:
201                         fprintf(stdout, "DM_EVENT_SYMLINK");
202                         break;
203                 case DM_EVENT_POSTSYMLINK:
204                         fprintf(stdout, "DM_EVENT_POSTSYMLINK");
205                         break;
206                 case DM_EVENT_READ:
207                         fprintf(stdout, "DM_EVENT_READ");
208                         break;
209                 case DM_EVENT_WRITE:
210                         fprintf(stdout, "DM_EVENT_WRITE");
211                         break;
212                 case DM_EVENT_TRUNCATE:
213                         fprintf(stdout, "DM_EVENT_TRUNCATE");
214                         break;
215                 case DM_EVENT_ATTRIBUTE:
216                         fprintf(stdout, "DM_EVENT_ATTRIBUTE");
217                         break;
218                 case DM_EVENT_DESTROY:
219                         fprintf(stdout, "DM_EVENT_DESTROY");
220                         break;
221                 case DM_EVENT_NOSPACE:
222                         fprintf(stdout, "DM_EVENT_NOSPACE");
223                         break;
224                 case DM_EVENT_USER:
225                         fprintf(stdout, "DM_EVENT_USER");
226                         break;
227                 case DM_EVENT_MAX:
228                         fprintf(stdout, "DM_EVENT_23");
229                         break;
230                 }
231                 fprintf(stdout, " (%d)\n", i);
232         }
233
234         dm_handle_free(hanp, hlen);
235         return(0);
236 }