e4850182b6a2e5dda8046f4b189fb6a462e579ef
[xfstests-dev.git] / dmapi / src / suite1 / cmd / getall_disp.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_getall_disp().  The
41 command line is:
42
43         getall_disp [-b buflen] sid
44
45 where buflen is the size of the buffer to use, and sid is the session ID
46 whose dispositions you you are interested in.
47
48 ----------------------------------------------------------------------------*/
49
50 #ifndef linux
51 extern  char    *sys_errlist[];
52 #endif
53 extern  int     optind;
54 extern  char    *optarg;
55
56
57 char    *Progname;
58
59 static void
60 usage(void)
61 {
62         fprintf(stderr, "usage:\t%s [-b buflen] sid\n",
63                 Progname);
64         exit(1);
65 }
66
67
68 int
69 main(
70         int     argc, 
71         char    **argv)
72 {
73         dm_dispinfo_t   *disp;
74         dm_sessid_t     sid;
75         void            *bufp;
76         size_t          buflen = 10000;
77         void            *hanp;
78         size_t          hlen;
79         char            hans1[HANDLE_STR];
80         size_t          rlenp;
81         char            *name;
82         int             opt;
83
84         if (Progname = strrchr(argv[0], '/')) {
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, "b:")) != EOF) {
93                 switch (opt) {
94                 case 'b':
95                         buflen = atol(optarg);
96                         break;
97                 case '?':
98                         usage();
99                 }
100         }
101         if (optind + 1 != argc)
102                 usage();
103         sid = atol(argv[optind]);
104
105         if (dm_init_service(&name) == -1)  {
106                 fprintf(stderr, "Can't initialize the DMAPI\n");
107                 exit(1);
108         }
109
110         if (buflen > 0) {
111                 if ((bufp = malloc(buflen)) == NULL) {
112                         fprintf(stderr, "malloc failed, %s\n", strerror(errno));
113                         exit(1);
114                 }
115         }
116
117         if (dm_getall_disp(sid, buflen, bufp, &rlenp)) {
118                 if (errno == E2BIG) {
119                         fprintf(stderr, "dm_getall_disp buffer too small, "
120                                 "should be %d bytes\n", rlenp);
121                 } else {
122                         fprintf(stderr, "dm_getall_disp failed, %s\n",
123                                 strerror(errno));
124                 }
125                 exit(1);
126         }
127         fprintf(stdout, "rlenp is %d\n", rlenp);
128         if (rlenp == 0)
129                 return(0);
130
131         disp = bufp;
132         while (disp != NULL) {
133                 hanp = DM_GET_VALUE(disp, di_fshandle, void *);
134                 hlen = DM_GET_LEN(disp, di_fshandle);
135                 if (hanp && hlen) {
136                         hantoa(hanp, hlen, hans1);
137                 } else {
138                         sprintf(hans1, "<BAD HANDLE, hlen %d>", hlen);
139                 }
140                 printf("%-15s %s dm_eventset_t 0%llo\n",
141                         "fshandle", hans1,
142                         disp->di_eventset);
143
144                 disp = DM_STEP_TO_NEXT(disp, dm_dispinfo_t *);
145         }
146         return(0);
147 }