common/rc: factor out _scratch_xfs_[get|set]_sb_field
[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         Progname = strrchr(argv[0], '/');
69         if (Progname) {
70                 Progname++;
71         } else {
72                 Progname = argv[0];
73         }
74
75         /* Crack and validate the command line options. */
76
77         while ((opt = getopt(argc, argv, "n:")) != EOF) {
78                 switch (opt) {
79                 case 'n':
80                         nelem = atol(optarg);
81                         break;
82                 case '?':
83                         usage();
84                 }
85         }
86         if (optind + 1 != argc)
87                 usage();
88         han_str = argv[optind];
89         if ((error = atohan(han_str, &hanp, &hlen)) != 0) {
90                 fprintf(stderr, "atohan() failed, %s\n", strerror(error));
91                 return(1);
92         }
93
94         if (dm_init_service(&name))  {
95                 fprintf(stderr, "Can't initialize the DMAPI\n");
96                 return(1);
97         }
98
99         DMEV_ZERO(eventset);
100
101         if (dm_get_config_events(hanp, hlen, nelem, &eventset, &nelemp)) {
102                 fprintf(stderr, "dm_get_config_events failed, %s\n",
103                         strerror(errno));
104                 return(1);
105         }
106
107         fprintf(stdout, "Events supported (0x%llx), nelemp %d:\n",
108                 (unsigned long long) eventset, nelemp);
109
110         for (i = 0; i < nelemp; i++) {
111                 if (!DMEV_ISSET(i, eventset))
112                         continue;
113                 switch (i) {
114                 case DM_EVENT_CANCEL:
115                         fprintf(stdout, "DM_EVENT_CANCEL");
116                         break;
117                 case DM_EVENT_MOUNT:
118                         fprintf(stdout, "DM_EVENT_MOUNT");
119                         break;
120                 case DM_EVENT_PREUNMOUNT:
121                         fprintf(stdout, "DM_EVENT_PREUNMOUNT");
122                         break;
123                 case DM_EVENT_UNMOUNT:
124                         fprintf(stdout, "DM_EVENT_UNMOUNT");
125                         break;
126                 case DM_EVENT_DEBUT:
127                         fprintf(stdout, "DM_EVENT_DEBUT");
128                         break;
129                 case DM_EVENT_CREATE:
130                         fprintf(stdout, "DM_EVENT_CREATE");
131                         break;
132                 case DM_EVENT_CLOSE:
133                         fprintf(stdout, "DM_EVENT_CLOSE");
134                         break;
135                 case DM_EVENT_POSTCREATE:
136                         fprintf(stdout, "DM_EVENT_POSTCREATE");
137                         break;
138                 case DM_EVENT_REMOVE:
139                         fprintf(stdout, "DM_EVENT_REMOVE");
140                         break;
141                 case DM_EVENT_POSTREMOVE:
142                         fprintf(stdout, "DM_EVENT_POSTREMOVE");
143                         break;
144                 case DM_EVENT_RENAME:
145                         fprintf(stdout, "DM_EVENT_RENAME");
146                         break;
147                 case DM_EVENT_POSTRENAME:
148                         fprintf(stdout, "DM_EVENT_POSTRENAME");
149                         break;
150                 case DM_EVENT_LINK:
151                         fprintf(stdout, "DM_EVENT_LINK");
152                         break;
153                 case DM_EVENT_POSTLINK:
154                         fprintf(stdout, "DM_EVENT_POSTLINK");
155                         break;
156                 case DM_EVENT_SYMLINK:
157                         fprintf(stdout, "DM_EVENT_SYMLINK");
158                         break;
159                 case DM_EVENT_POSTSYMLINK:
160                         fprintf(stdout, "DM_EVENT_POSTSYMLINK");
161                         break;
162                 case DM_EVENT_READ:
163                         fprintf(stdout, "DM_EVENT_READ");
164                         break;
165                 case DM_EVENT_WRITE:
166                         fprintf(stdout, "DM_EVENT_WRITE");
167                         break;
168                 case DM_EVENT_TRUNCATE:
169                         fprintf(stdout, "DM_EVENT_TRUNCATE");
170                         break;
171                 case DM_EVENT_ATTRIBUTE:
172                         fprintf(stdout, "DM_EVENT_ATTRIBUTE");
173                         break;
174                 case DM_EVENT_DESTROY:
175                         fprintf(stdout, "DM_EVENT_DESTROY");
176                         break;
177                 case DM_EVENT_NOSPACE:
178                         fprintf(stdout, "DM_EVENT_NOSPACE");
179                         break;
180                 case DM_EVENT_USER:
181                         fprintf(stdout, "DM_EVENT_USER");
182                         break;
183                 case DM_EVENT_MAX:
184                         fprintf(stdout, "DM_EVENT_23");
185                         break;
186                 }
187                 fprintf(stdout, " (%d)\n", i);
188         }
189
190         dm_handle_free(hanp, hlen);
191         return(0);
192 }