No Message Supplied
[xfstests-dev.git] / dmapi / src / suite1 / cmd / get_config_events.c
1 /*
2  * Copyright (c) 2000 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_config_events().  The
41 command line is:
42
43         get_config_events [-n nelem] handle
44
45 where handle is the handle of a file or filesystem, and nelem is the value
46 to use for the nelem parameter to dm_get_eventlist().
47
48 ----------------------------------------------------------------------------*/
49
50 extern  int     optind;
51 extern  char    *optarg;
52
53
54 char    *Progname;
55
56
57
58 static void
59 usage(void)
60 {
61         fprintf(stderr, "usage:\t%s [-n nelem] handle\n", Progname);
62         exit(1);
63 }
64
65
66 int
67 main(
68         int     argc, 
69         char    **argv)
70 {
71         u_int           nelem = DM_EVENT_MAX;
72         char            *han_str;
73         dm_eventset_t   eventset;
74         void            *hanp;
75         size_t           hlen;
76         u_int           nelemp;
77         char            *name;
78         int             error;
79         int             opt;
80         int             i;
81
82         if (Progname = strrchr(argv[0], '/')) {
83                 Progname++;
84         } else {
85                 Progname = argv[0];
86         }
87
88         /* Crack and validate the command line options. */
89
90         while ((opt = getopt(argc, argv, "n:")) != EOF) {
91                 switch (opt) {
92                 case 'n':
93                         nelem = atol(optarg);
94                         break;
95                 case '?':
96                         usage();
97                 }
98         }
99         if (optind + 1 != argc)
100                 usage();
101         han_str = argv[optind];
102         if ((error = atohan(han_str, &hanp, &hlen)) != 0) {
103                 fprintf(stderr, "atohan() failed, %s\n", strerror(error));
104                 return(1);
105         }
106
107         if (dm_init_service(&name))  {
108                 fprintf(stderr, "Can't initialize the DMAPI\n");
109                 return(1);
110         }
111
112         DMEV_ZERO(eventset);
113
114         if (dm_get_config_events(hanp, hlen, nelem, &eventset, &nelemp)) {
115                 fprintf(stderr, "dm_get_config_events failed, %s\n",
116                         strerror(errno));
117                 return(1);
118         }
119
120         fprintf(stdout, "Events supported (0x%llx), nelemp %d:\n",
121                 eventset, nelemp);
122
123         for (i = 0; i < nelemp; i++) {
124                 if (!DMEV_ISSET(i, eventset))
125                         continue;
126                 switch (i) {
127                 case DM_EVENT_CANCEL:
128                         fprintf(stdout, "DM_EVENT_CANCEL");
129                         break;
130                 case DM_EVENT_MOUNT:
131                         fprintf(stdout, "DM_EVENT_MOUNT");
132                         break;
133                 case DM_EVENT_PREUNMOUNT:
134                         fprintf(stdout, "DM_EVENT_PREUNMOUNT");
135                         break;
136                 case DM_EVENT_UNMOUNT:
137                         fprintf(stdout, "DM_EVENT_UNMOUNT");
138                         break;
139                 case DM_EVENT_DEBUT:
140                         fprintf(stdout, "DM_EVENT_DEBUT");
141                         break;
142                 case DM_EVENT_CREATE:
143                         fprintf(stdout, "DM_EVENT_CREATE");
144                         break;
145                 case DM_EVENT_CLOSE:
146                         fprintf(stdout, "DM_EVENT_CLOSE");
147                         break;
148                 case DM_EVENT_POSTCREATE:
149                         fprintf(stdout, "DM_EVENT_POSTCREATE");
150                         break;
151                 case DM_EVENT_REMOVE:
152                         fprintf(stdout, "DM_EVENT_REMOVE");
153                         break;
154                 case DM_EVENT_POSTREMOVE:
155                         fprintf(stdout, "DM_EVENT_POSTREMOVE");
156                         break;
157                 case DM_EVENT_RENAME:
158                         fprintf(stdout, "DM_EVENT_RENAME");
159                         break;
160                 case DM_EVENT_POSTRENAME:
161                         fprintf(stdout, "DM_EVENT_POSTRENAME");
162                         break;
163                 case DM_EVENT_LINK:
164                         fprintf(stdout, "DM_EVENT_LINK");
165                         break;
166                 case DM_EVENT_POSTLINK:
167                         fprintf(stdout, "DM_EVENT_POSTLINK");
168                         break;
169                 case DM_EVENT_SYMLINK:
170                         fprintf(stdout, "DM_EVENT_SYMLINK");
171                         break;
172                 case DM_EVENT_POSTSYMLINK:
173                         fprintf(stdout, "DM_EVENT_POSTSYMLINK");
174                         break;
175                 case DM_EVENT_READ:
176                         fprintf(stdout, "DM_EVENT_READ");
177                         break;
178                 case DM_EVENT_WRITE:
179                         fprintf(stdout, "DM_EVENT_WRITE");
180                         break;
181                 case DM_EVENT_TRUNCATE:
182                         fprintf(stdout, "DM_EVENT_TRUNCATE");
183                         break;
184                 case DM_EVENT_ATTRIBUTE:
185                         fprintf(stdout, "DM_EVENT_ATTRIBUTE");
186                         break;
187                 case DM_EVENT_DESTROY:
188                         fprintf(stdout, "DM_EVENT_DESTROY");
189                         break;
190                 case DM_EVENT_NOSPACE:
191                         fprintf(stdout, "DM_EVENT_NOSPACE");
192                         break;
193                 case DM_EVENT_USER:
194                         fprintf(stdout, "DM_EVENT_USER");
195                         break;
196                 case DM_EVENT_MAX:
197                         fprintf(stdout, "DM_EVENT_23");
198                         break;
199                 }
200                 fprintf(stdout, " (%d)\n", i);
201         }
202
203         dm_handle_free(hanp, hlen);
204         return(0);
205 }