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