Update copyright dates (again)
[xfstests-dev.git] / dmapi / src / suite1 / cmd / get_eventlist.c
1 /*
2  * Copyright (c) 2000-2001 Silicon Graphics, Inc.  All Rights Reserved.
3  * 
4  * This program is free software; you can redistribute it and/or modify it
5  * under the terms of version 2 of the GNU General Public License as
6  * published by the Free Software Foundation.
7  * 
8  * This program is distributed in the hope that it would be useful, but
9  * WITHOUT ANY WARRANTY; without even the implied warranty of
10  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
11  * 
12  * Further, this software is distributed without any warranty that it is
13  * free of the rightful claim of any third person regarding infringement
14  * or the like.  Any license provided herein, whether implied or
15  * otherwise, applies only to this software file.  Patent licenses, if
16  * any, provided herein do not apply to combinations of this program with
17  * other software, or any other product whatsoever.
18  * 
19  * You should have received a copy of the GNU General Public License along
20  * with this program; if not, write the Free Software Foundation, Inc., 59
21  * Temple Place - Suite 330, Boston MA 02111-1307, USA.
22  * 
23  * Contact information: Silicon Graphics, Inc., 1600 Amphitheatre Pkwy,
24  * Mountain View, CA  94043, or:
25  * 
26  * http://www.sgi.com 
27  * 
28  * For further information regarding this notice, see: 
29  * 
30  * http://oss.sgi.com/projects/GenInfo/SGIGPLNoticeExplan/
31  */
32
33 #include <lib/hsm.h>
34
35 #include <string.h>
36 #include <getopt.h>
37
38 /*---------------------------------------------------------------------------
39
40 Test program used to test the DMAPI function dm_get_eventlist().  The
41 command line is:
42
43         get_eventlist [-F] [-n nelem] [-s sid] [-t token] {pathname|handle}
44
45 where:
46 {pathname|handle}
47         is the pathname of a file or filesystem or a handle.
48 -n nelem
49         is the value to use for the nelem parameter to dm_get_eventlist().
50 -s sid
51         is the dm_sessid_t to use in place of the default test session.
52 -t token
53         is the dm_token_t to use in place of DM_NO_TOKEN.
54 -F
55         is used when a pathname is specified to indicate that you want its
56         filesystem handle, not its file handle.
57
58 ----------------------------------------------------------------------------*/
59
60 extern  int     optind;
61 extern  char    *optarg;
62
63
64 char    *Progname;
65
66
67
68 static void
69 usage(void)
70 {
71         fprintf(stderr, "usage:\t%s [-F] [-n nelem] [-s sid] [-t token] "
72                 "{pathname|handle}\n",
73                 Progname);
74         exit(1);
75 }
76
77
78 int
79 main(
80         int     argc, 
81         char    **argv)
82 {
83         dm_sessid_t      sid = DM_NO_SESSION;
84         dm_token_t      token = DM_NO_TOKEN;
85         u_int           nelem = DM_EVENT_MAX;
86         char            *object;
87         dm_eventset_t   eventset;
88         void            *hanp;
89         size_t           hlen;
90         u_int           nelemp;
91         char            *name;
92         int             Fflag = 0;
93         int             error;
94         int             opt;
95         int             i;
96
97         if (Progname = strrchr(argv[0], '/')) {
98                 Progname++;
99         } else {
100                 Progname = argv[0];
101         }
102
103         /* Crack and validate the command line options. */
104
105         while ((opt = getopt(argc, argv, "Fn:s:t:")) != EOF) {
106                 switch (opt) {
107                 case 'F':
108                         Fflag++;
109                         break;
110                 case 'n':
111                         nelem = atol(optarg);
112                         break;
113                 case 's':
114                         sid = atol(optarg);
115                         break;
116                 case 't':
117                         token = atol(optarg);
118                         break;
119                 case '?':
120                         usage();
121                 }
122         }
123         if (optind + 1 != argc)
124                 usage();
125         object = argv[optind];
126
127         if (dm_init_service(&name) == -1)  {
128                 fprintf(stderr, "Can't initialize the DMAPI\n");
129                 exit(1);
130         }
131
132         if ((error = opaque_to_handle(object, &hanp, &hlen)) != 0) {
133                 fprintf(stderr, "can't get a handle from %s, %s\n",
134                         object, strerror(error));
135                 return(1);
136         }
137
138         if (Fflag) {
139                 void    *fshanp;
140                 size_t  fshlen;
141
142                 if (dm_handle_to_fshandle(hanp, hlen, &fshanp, &fshlen)) {
143                         fprintf(stderr, "can't get filesystem handle from %s\n",
144                                 object);
145                         exit(1);
146                 }
147                 dm_handle_free(hanp, hlen);
148                 hanp = fshanp;
149                 hlen = fshlen;
150         }
151
152         if (sid == DM_NO_SESSION)
153                 find_test_session(&sid);
154
155         DMEV_ZERO(eventset);
156
157         if (dm_get_eventlist(sid, hanp, hlen, token, nelem,
158             &eventset, &nelemp)) {
159                 fprintf(stderr, "dm_get_eventlist failed, %s\n",
160                         strerror(errno));
161                 return(1);
162         }
163
164 #ifdef  VERITAS_21
165         fprintf(stdout, "Events on object %s (0x%x), nelemp %d:\n",
166 #else
167         fprintf(stdout, "Events on object %s (0x%llx), nelemp %d:\n",
168 #endif
169                 object, eventset, nelemp);
170
171         for (i = 0; i < nelemp; i++) {
172                 if (!DMEV_ISSET(i, eventset))
173                         continue;
174                 switch (i) {
175                 case DM_EVENT_CANCEL:
176                         fprintf(stdout, "DM_EVENT_CANCEL");
177                         break;
178                 case DM_EVENT_MOUNT:
179                         fprintf(stdout, "DM_EVENT_MOUNT");
180                         break;
181                 case DM_EVENT_PREUNMOUNT:
182                         fprintf(stdout, "DM_EVENT_PREUNMOUNT");
183                         break;
184                 case DM_EVENT_UNMOUNT:
185                         fprintf(stdout, "DM_EVENT_UNMOUNT");
186                         break;
187                 case DM_EVENT_DEBUT:
188                         fprintf(stdout, "DM_EVENT_DEBUT");
189                         break;
190                 case DM_EVENT_CREATE:
191                         fprintf(stdout, "DM_EVENT_CREATE");
192                         break;
193                 case DM_EVENT_CLOSE:
194                         fprintf(stdout, "DM_EVENT_CLOSE");
195                         break;
196                 case DM_EVENT_POSTCREATE:
197                         fprintf(stdout, "DM_EVENT_POSTCREATE");
198                         break;
199                 case DM_EVENT_REMOVE:
200                         fprintf(stdout, "DM_EVENT_REMOVE");
201                         break;
202                 case DM_EVENT_POSTREMOVE:
203                         fprintf(stdout, "DM_EVENT_POSTREMOVE");
204                         break;
205                 case DM_EVENT_RENAME:
206                         fprintf(stdout, "DM_EVENT_RENAME");
207                         break;
208                 case DM_EVENT_POSTRENAME:
209                         fprintf(stdout, "DM_EVENT_POSTRENAME");
210                         break;
211                 case DM_EVENT_LINK:
212                         fprintf(stdout, "DM_EVENT_LINK");
213                         break;
214                 case DM_EVENT_POSTLINK:
215                         fprintf(stdout, "DM_EVENT_POSTLINK");
216                         break;
217                 case DM_EVENT_SYMLINK:
218                         fprintf(stdout, "DM_EVENT_SYMLINK");
219                         break;
220                 case DM_EVENT_POSTSYMLINK:
221                         fprintf(stdout, "DM_EVENT_POSTSYMLINK");
222                         break;
223                 case DM_EVENT_READ:
224                         fprintf(stdout, "DM_EVENT_READ");
225                         break;
226                 case DM_EVENT_WRITE:
227                         fprintf(stdout, "DM_EVENT_WRITE");
228                         break;
229                 case DM_EVENT_TRUNCATE:
230                         fprintf(stdout, "DM_EVENT_TRUNCATE");
231                         break;
232                 case DM_EVENT_ATTRIBUTE:
233                         fprintf(stdout, "DM_EVENT_ATTRIBUTE");
234                         break;
235                 case DM_EVENT_DESTROY:
236                         fprintf(stdout, "DM_EVENT_DESTROY");
237                         break;
238                 case DM_EVENT_NOSPACE:
239                         fprintf(stdout, "DM_EVENT_NOSPACE");
240                         break;
241                 case DM_EVENT_USER:
242                         fprintf(stdout, "DM_EVENT_USER");
243                         break;
244                 case DM_EVENT_MAX:
245                         fprintf(stdout, "DM_EVENT_23");
246                         break;
247                 }
248                 fprintf(stdout, " (%d)\n", i);
249         }
250
251         dm_handle_free(hanp, hlen);
252         return(0);
253 }