dmapi: fix build failure if libdm is provided via -ldm
[xfstests-dev.git] / dmapi / src / suite1 / cmd / obj_ref_rele.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_obj_ref_rele().  The
28 command line is:
29
30         obj_ref_rele {-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 {pathname|handle}\n",
60                 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         char            *object;
73         void            *hanp;
74         size_t          hlen;
75         int             Fflag = 0;
76         char            *name;
77         int             opt;
78
79         Progname = strrchr(argv[0], '/');
80         if (Progname) {
81                 Progname++;
82         } else {
83                 Progname = argv[0];
84         }
85
86         /* Crack and validate the command line options. */
87
88         while ((opt = getopt(argc, argv, "Fs:")) != EOF) {
89                 switch (opt) {
90                 case 'F':
91                         Fflag++;
92                         break;
93                 case 's':
94                         sid = atol(optarg);
95                         break;
96                 case '?':
97                         usage();
98                 }
99         }
100         if (optind + 2 != argc)
101                 usage();
102         token = atol(argv[optind++]);
103         object = argv[optind];
104
105         if (dm_init_service(&name) == -1)  {
106                 fprintf(stderr, "Can't initialize the DMAPI\n");
107                 exit(1);
108         }
109         if (sid == DM_NO_SESSION)
110                 find_test_session(&sid);
111
112         /* Get the file or filesystem's handle. */
113
114         if (opaque_to_handle(object, &hanp, &hlen)) {
115                 fprintf(stderr, "can't get handle from %s\n", object);
116                 exit(1);
117         }
118         if (Fflag) {
119                 void    *fshanp;
120                 size_t  fshlen;
121
122                 if (dm_handle_to_fshandle(hanp, hlen, &fshanp, &fshlen)) {
123                         fprintf(stderr, "can't get filesystem handle from %s\n",
124                                 object);
125                         exit(1);
126                 }
127                 dm_handle_free(hanp, hlen);
128                 hanp = fshanp;
129                 hlen = fshlen;
130         }
131
132         if (dm_obj_ref_rele(sid, token, hanp, hlen)) {
133                 fprintf(stderr, "dm_obj_ref_rele failed, %s\n",
134                         strerror(errno));
135                 return(1);
136         }
137
138         dm_handle_free(hanp, hlen);
139         exit(0);
140 }