5bfab99678a1aed45f338f6a7382282f49ed785f
[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 #ifdef linux
39 #else
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
53 static void
54 hantoa(
55         void    *hanp,
56         size_t   hlen,
57         char    *handle_str)
58 {
59         u_char  *cp= (u_char *)hanp;
60         int     i;
61
62         for (i = 0;i < hlen; i++, handle_str += 2)
63                 sprintf(handle_str, "%.2x", *cp++);
64         *handle_str = '\0';
65 }
66
67 int
68 main(
69         int             argc,
70         char            **argv)
71 {
72 /*      xfs_fsop_geom_t geom;*/
73         char            *uuid_str;
74         u_int           status;
75         char            *name;
76         int             fd;
77         void            *fshanp;
78         size_t          fshlen;
79         char            buffer[100];
80
81         if (argc != 2) {
82                 fprintf(stderr, "usage: %s path\n", argv[0]);
83                 exit(1);
84         }
85         (void)dm_init_service(&name);
86
87         if (dm_path_to_fshandle(argv[1], &fshanp, &fshlen) != 0) {
88                 fprintf(stderr, "dm_path_to_fshandle failed, %s\n",
89                         strerror(errno));
90         }
91         hantoa(fshanp, fshlen, buffer);
92
93         if ((fd = open(argv[1], O_RDONLY)) < 0) {
94                 fprintf(stderr, "Open of %s failed, %s\n", argv[1],
95                         strerror(errno));
96                 exit(1);
97         }
98
99 /*
100         syssgi(SGI_XFS_FSOPERATIONS, fd, XFS_FS_GEOMETRY, NULL, &geom);
101
102         uuid_to_string(&geom.uuid, &uuid_str, &status);
103
104         fprintf(stdout, "fshandle %s, uuid %s, %s\n",
105                 buffer, uuid_str, argv[1]);
106 */
107         fprintf(stdout, "fshandle %s, %s\n",
108                 buffer, argv[1]);
109 }