common/rc: factor out _scratch_xfs_[get|set]_sb_field
[xfstests-dev.git] / dmapi / src / suite1 / cmd / handle_to_fshandle.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 /* Given an object's handle, print the filesystem handle. */
20
21 #include <lib/hsm.h>
22
23 #include <string.h>
24
25 /*---------------------------------------------------------------------------
26
27 Test program used to test dm_handle_to_fshandle().  The command line is:
28
29         handle_to_fshandle handle
30
31 where handle is an object's handle.
32
33 ----------------------------------------------------------------------------*/
34
35
36 char    *Progname;
37
38
39 static void
40 usage(void)
41 {
42         fprintf(stderr, "usage:\t%s handle\n", Progname);
43         exit(1);
44 }
45
46
47 int
48 main(
49         int             argc,
50         char            **argv)
51 {
52         char            *han_str;
53         char            *name;
54         void            *hanp, *fshanp;
55         size_t          hlen, fshlen;
56         char            buffer[100];
57         int             error;
58
59         Progname = strrchr(argv[0], '/');
60         if (Progname) {
61                 Progname++;
62         } else {
63                 Progname = argv[0];
64         }
65
66         if (argc != 2)
67                 usage();
68         han_str = argv[1];
69
70         (void)dm_init_service(&name);
71
72         if ((error = atohan(han_str, &hanp, &hlen)) != 0) {
73                 fprintf(stderr, "atohan() failed, %s\n", strerror(error));
74                 return(1);
75         }
76
77         if (dm_handle_to_fshandle(hanp, hlen, &fshanp, &fshlen) != 0) {
78                 fprintf(stderr, "dm_handle_to_fshandle failed, %s\n",
79                         strerror(errno));
80                 return(1);
81         }
82         hantoa(fshanp, fshlen, buffer);
83         fprintf(stdout, "%s\n", buffer);
84
85         dm_handle_free(hanp, hlen);
86         dm_handle_free(fshanp, fshlen);
87         return(0);
88 }