xfstests: eliminate warnings under dmapi/src/suite1/cmd (3)
[xfstests-dev.git] / dmapi / src / suite1 / cmd / query_right.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 <getopt.h>
22 #include <string.h>
23
24
25 /*---------------------------------------------------------------------------
26
27 Test program used to test the DMAPI function dm_query_right().  The
28 command line is:
29
30         query_right [-F] [-s sid] token {pathname|handle}
31
32 where
33 -F
34         when a pathname is specified, -F indicates that its filesystem handle
35         should be used rather than its file object handle.
36 sid
37         is the dm_sessid_t to use rather than the default test session.
38 token
39         is the dm_token_t to use.
40 {pathname|handle}
41         is either a handle, or is the pathname of a file whose handle is
42         to be used.
43
44 ----------------------------------------------------------------------------*/
45
46 #ifndef linux
47 extern  char    *sys_errlist[];
48 #endif
49 extern  int     optind;
50 extern  char    *optarg;
51
52
53 char    *Progname;
54
55
56 static void
57 usage(void)
58 {
59         fprintf(stderr, "usage:\t%s [-F] [-s sid] token "
60                 "{pathname|handle}\n", Progname);
61         exit(1);
62 }
63
64
65 int
66 main(
67         int     argc,
68         char    **argv)
69 {
70         dm_sessid_t     sid = DM_NO_SESSION;
71         dm_token_t      token;
72         dm_right_t      right;
73         char            *object;
74         void            *hanp;
75         size_t          hlen;
76         int             Fflag = 0;
77         char            *name;
78         int             opt;
79
80         Progname = strrchr(argv[0], '/');
81         if (Progname) {
82                 Progname++;
83         } else {
84                 Progname = argv[0];
85         }
86
87         /* Crack and validate the command line options. */
88
89         while ((opt = getopt(argc, argv, "Fs:")) != EOF) {
90                 switch (opt) {
91                 case 'F':
92                         Fflag++;
93                         break;
94                 case 's':
95                         sid = atol(optarg);
96                         break;
97                 case '?':
98                         usage();
99                 }
100         }
101         if (optind + 2 != argc)
102                 usage();
103         token = atol(argv[optind++]);
104         object = argv[optind++];
105
106         if (dm_init_service(&name) == -1)  {
107                 fprintf(stderr, "Can't initialize the DMAPI\n");
108                 exit(1);
109         }
110         if (sid == DM_NO_SESSION)
111                 find_test_session(&sid);
112
113         /* Get the file or filesystem's handle. */
114
115         if (opaque_to_handle(object, &hanp, &hlen)) {
116                 fprintf(stderr, "can't get handle from %s\n", object);
117                 exit(1);
118         }
119         if (Fflag) {
120                 void    *fshanp;
121                 size_t  fshlen;
122
123                 if (dm_handle_to_fshandle(hanp, hlen, &fshanp, &fshlen)) {
124                         fprintf(stderr, "can't get filesystem handle from %s\n",
125                                 object);
126                         exit(1);
127                 }
128                 dm_handle_free(hanp, hlen);
129                 hanp = fshanp;
130                 hlen = fshlen;
131         }
132
133         if (dm_query_right(sid, hanp, hlen, token, &right)) {
134                 fprintf(stderr, "dm_query_right failed, %s\n",
135                         strerror(errno));
136                 return(1);
137         }
138
139         fprintf(stderr, "right is %s\n", rt_value_to_name(right));
140
141         dm_handle_free(hanp, hlen);
142         exit(0);
143 }