Undoes mod: xfs-cmds:slinx:120772a
[xfstests-dev.git] / dmapi / src / suite1 / cmd / print_fshandle.c
1 /*
2  * Copyright (c) 2000 Silicon Graphics, Inc.  All Rights Reserved.
3  * 
4  * This program is free software; you can redistribute it and/or modify it
5  * under the terms of version 2 of the GNU General Public License as
6  * published by the Free Software Foundation.
7  * 
8  * This program is distributed in the hope that it would be useful, but
9  * WITHOUT ANY WARRANTY; without even the implied warranty of
10  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
11  * 
12  * Further, this software is distributed without any warranty that it is
13  * free of the rightful claim of any third person regarding infringement
14  * or the like.  Any license provided herein, whether implied or
15  * otherwise, applies only to this software file.  Patent licenses, if
16  * any, provided herein do not apply to combinations of this program with
17  * other software, or any other product whatsoever.
18  * 
19  * You should have received a copy of the GNU General Public License along
20  * with this program; if not, write the Free Software Foundation, Inc., 59
21  * Temple Place - Suite 330, Boston MA 02111-1307, USA.
22  * 
23  * Contact information: Silicon Graphics, Inc., 1600 Amphitheatre Pkwy,
24  * Mountain View, CA  94043, or:
25  * 
26  * http://www.sgi.com 
27  * 
28  * For further information regarding this notice, see: 
29  * 
30  * http://oss.sgi.com/projects/GenInfo/SGIGPLNoticeExplan/
31  */
32
33 /* Given a file pathname, print the filesystem handle and the uuid_t for
34    the filesystem that contains the file.
35 */
36
37 #include <sys/types.h>
38 #include <string.h>
39 #ifdef __sgi
40 #include <sys/syssgi.h>
41 #include <sys/uuid.h>
42 #include <sys/fs/xfs_fsops.h>
43 #endif
44
45 #include <errno.h>
46 #include <fcntl.h>
47 #include <stdio.h>
48 #include <stdlib.h>
49
50 #include <lib/dmport.h>
51
52 char *Progname;
53
54 static void
55 hantoa(
56         void    *hanp,
57         size_t   hlen,
58         char    *handle_str)
59 {
60         u_char  *cp= (u_char *)hanp;
61         int     i;
62
63         for (i = 0;i < hlen; i++, handle_str += 2)
64                 sprintf(handle_str, "%.2x", *cp++);
65         *handle_str = '\0';
66 }
67
68 int
69 main(
70         int             argc,
71         char            **argv)
72 {
73 #ifdef __sgi
74         xfs_fsop_geom_t geom;
75         char            *uuid_str;
76         u_int           status;
77 #endif
78         char            *name;
79         int             fd;
80         void            *fshanp;
81         size_t          fshlen;
82         char            buffer[100];
83
84         if (argc != 2) {
85                 fprintf(stderr, "usage: %s path\n", argv[0]);
86                 exit(1);
87         }
88         Progname = argv[0];
89         (void)dm_init_service(&name);
90
91         if (dm_path_to_fshandle(argv[1], &fshanp, &fshlen) != 0) {
92                 fprintf(stderr, "dm_path_to_fshandle failed, %s\n",
93                         strerror(errno));
94         }
95         hantoa(fshanp, fshlen, buffer);
96
97         if ((fd = open(argv[1], O_RDONLY)) < 0) {
98                 fprintf(stderr, "Open of %s failed, %s\n", argv[1],
99                         strerror(errno));
100                 exit(1);
101         }
102
103 #ifdef __sgi
104         syssgi(SGI_XFS_FSOPERATIONS, fd, XFS_FS_GEOMETRY, NULL, &geom);
105
106         uuid_to_string(&geom.uuid, &uuid_str, &status);
107
108         fprintf(stdout, "fshandle %s, uuid %s, %s\n",
109                 buffer, uuid_str, argv[1]);
110 #endif
111         fprintf(stdout, "fshandle %s, %s\n",
112                 buffer, argv[1]);
113         exit(0);
114 }