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