generic/60[78]: ensure the initial DAX file flag state before test
[xfstests-dev.git] / dmapi / src / suite1 / cmd / handle_to_fshandle.c
1 // SPDX-License-Identifier: GPL-2.0
2 /*
3  * Copyright (c) 2000-2001 Silicon Graphics, Inc.
4  * All Rights Reserved.
5  */
6
7 /* Given an object's handle, print the filesystem handle. */
8
9 #include <lib/hsm.h>
10
11 #include <string.h>
12
13 /*---------------------------------------------------------------------------
14
15 Test program used to test dm_handle_to_fshandle().  The command line is:
16
17         handle_to_fshandle handle
18
19 where handle is an object's handle.
20
21 ----------------------------------------------------------------------------*/
22
23
24 char    *Progname;
25
26
27 static void
28 usage(void)
29 {
30         fprintf(stderr, "usage:\t%s handle\n", Progname);
31         exit(1);
32 }
33
34
35 int
36 main(
37         int             argc,
38         char            **argv)
39 {
40         char            *han_str;
41         char            *name;
42         void            *hanp, *fshanp;
43         size_t          hlen, fshlen;
44         char            buffer[100];
45         int             error;
46
47         Progname = strrchr(argv[0], '/');
48         if (Progname) {
49                 Progname++;
50         } else {
51                 Progname = argv[0];
52         }
53
54         if (argc != 2)
55                 usage();
56         han_str = argv[1];
57
58         (void)dm_init_service(&name);
59
60         if ((error = atohan(han_str, &hanp, &hlen)) != 0) {
61                 fprintf(stderr, "atohan() failed, %s\n", strerror(error));
62                 return(1);
63         }
64
65         if (dm_handle_to_fshandle(hanp, hlen, &fshanp, &fshlen) != 0) {
66                 fprintf(stderr, "dm_handle_to_fshandle failed, %s\n",
67                         strerror(errno));
68                 return(1);
69         }
70         hantoa(fshanp, fshlen, buffer);
71         fprintf(stdout, "%s\n", buffer);
72
73         dm_handle_free(hanp, hlen);
74         dm_handle_free(fshanp, fshlen);
75         return(0);
76 }