2 * Copyright (c) 2000 Silicon Graphics, Inc. All Rights Reserved.
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.
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.
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.
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.
23 * Contact information: Silicon Graphics, Inc., 1600 Amphitheatre Pkwy,
24 * Mountain View, CA 94043, or:
28 * For further information regarding this notice, see:
30 * http://oss.sgi.com/projects/GenInfo/SGIGPLNoticeExplan/
38 #include <lib/dmport.h>
42 #include <xfs/xfs_fs.h>
43 #include <xfs/handle.h>
46 /*---------------------------------------------------------------------------
48 Test program used to test the DMAPI function dm_handle_to_path(). The
51 handle_to_path [-b buflen] dirpath objpath
53 There are two parameters. The first is the pathname of a directory,
54 and the second is the pathname of a file, directory, or symbolic link
55 within that directory. The second parameter can also be the same as
56 the first if you want to specify "." (this is how EMASS uses it).
57 Pathnames can either be relative or full.
59 buflen is the size of the buffer to use in the call.
61 This program will return the full pathname of the object which is the
62 second parameter using the dm_handle_to_path() function.
64 The program should work successfully for files, directories, and
65 symbolic links, and does not have to work for any other type of
66 object. It doesn't have to work across mount points. There shouldn't
67 be any "/." crud on the end of the returned pathname either.
69 ----------------------------------------------------------------------------*/
81 fprintf(stderr, "usage:\t%s [-b buflen] dirpath objpath\n", Progname);
93 void *hanp1, *hanp2, *hanp1a;
94 size_t hlen1, hlen2, hlen1a;
101 if (Progname = strrchr(argv[0], '/')) {
107 /* Crack and validate the command line options. */
109 while ((opt = getopt(argc, argv, "b:")) != EOF) {
112 buflen = atol(optarg);
118 if (optind + 2 != argc)
120 dirpath = argv[optind++];
121 objpath = argv[optind];
123 if (dm_init_service(&name)) {
124 fprintf(stderr, "Can't initialize the DMAPI\n");
128 if (dm_path_to_handle(dirpath, &hanp1, &hlen1)) {
129 fprintf(stderr, "dm_path_to_handle failed for %s, (%d) %s\n",
130 dirpath, errno, strerror(errno));
133 if (path_to_handle(dirpath, &hanp1a, &hlen1a)) {
134 fprintf(stderr, "path_to_handle failed for %s, (%d) %s\n",
135 dirpath, errno, strerror(errno));
139 fprintf(stderr, "dm_path_to_handle != path_to_handle, %d != %d\n",
142 if( memcmp(hanp1, hanp1a, hlen1) != 0 ){
143 fprintf(stderr, "dm_path_to_handle != path_to_handle, handles differ\n");
145 if (dm_path_to_handle(objpath, &hanp2, &hlen2)) {
146 fprintf(stderr, "dm_path_to_handle failed for %s, (%d) %s\n",
147 objpath, errno, strerror(errno));
151 if ((pathbufp = malloc(buflen == 0 ? 1 : buflen)) == NULL) {
152 fprintf(stderr, "malloc failed\n");
156 if (dm_handle_to_path(hanp1, hlen1, hanp2, hlen2,
157 buflen, pathbufp, &rlenp)) {
158 if (errno == E2BIG) {
159 fprintf(stderr, "dm_handle_to_path buffer too small, "
160 "should be %d bytes\n", rlenp);
162 fprintf(stderr, "dm_handle_to_path failed, (%d) %s\n",
163 errno, strerror(errno));
167 fprintf(stderr, "rlenp is %d, pathbufp is %s\n", rlenp, (char*)pathbufp);
168 if (strlen(pathbufp) + 1 != rlenp) {
169 fprintf(stderr, "rlenp is %d, should be %d\n", rlenp,
170 strlen(pathbufp) + 1);