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