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>
40 /*---------------------------------------------------------------------------
42 Test program used to test the DMAPI function dm_handle_to_path(). The
45 handle_to_path [-b buflen] dirpath objpath
47 There are two parameters. The first is the pathname of a directory,
48 and the second is the pathname of a file, directory, or symbolic link
49 within that directory. The second parameter can also be the same as
50 the first if you want to specify "." (this is how EMASS uses it).
51 Pathnames can either be relative or full.
53 buflen is the size of the buffer to use in the call.
55 This program will return the full pathname of the object which is the
56 second parameter using the dm_handle_to_path() function.
58 The program should work successfully for files, directories, and
59 symbolic links, and does not have to work for any other type of
60 object. It doesn't have to work across mount points. There shouldn't
61 be any "/." crud on the end of the returned pathname either.
63 ----------------------------------------------------------------------------*/
75 fprintf(stderr, "usage:\t%s [-b buflen] dirpath objpath\n", Progname);
87 void *hanp1, *hanp2, *hanp1a;
88 size_t hlen1, hlen2, hlen1a;
95 if (Progname = strrchr(argv[0], '/')) {
101 /* Crack and validate the command line options. */
103 while ((opt = getopt(argc, argv, "b:")) != EOF) {
106 buflen = atol(optarg);
112 if (optind + 2 != argc)
114 dirpath = argv[optind++];
115 objpath = argv[optind];
117 if (dm_init_service(&name)) {
118 fprintf(stderr, "Can't inititalize the DMAPI\n");
122 printf("about to call dm_path_to_handle for %s\n", dirpath);
123 if (dm_path_to_handle(dirpath, &hanp1, &hlen1)) {
124 fprintf(stderr, "dm_path_to_handle failed for %s, (%d) %s\n",
125 dirpath, errno, strerror(errno));
128 printf("about to call path_to_handle for %s\n", dirpath);
129 if (path_to_handle(dirpath, &hanp1a, &hlen1a)) {
130 fprintf(stderr, "path_to_handle failed for %s, (%d) %s\n",
131 dirpath, errno, strerror(errno));
135 fprintf(stderr, "dm_path_to_handle != path_to_handle, %d != %d\n",
138 if( memcmp(hanp1, hanp1a, hlen1) != 0 ){
139 fprintf(stderr, "dm_path_to_handle != path_to_handle, handles differ\n");
141 printf("about to call dm_path_to_handle for %s\n", objpath);
142 if (dm_path_to_handle(objpath, &hanp2, &hlen2)) {
143 fprintf(stderr, "dm_path_to_handle failed for %s, (%d) %s\n",
144 objpath, errno, strerror(errno));
148 if ((pathbufp = malloc(buflen == 0 ? 1 : buflen)) == NULL) {
149 fprintf(stderr, "malloc failed\n");
153 printf("about to call handle_to_path\n");
154 if (dm_handle_to_path(hanp1, hlen1, hanp2, hlen2,
155 buflen, pathbufp, &rlenp)) {
156 if (errno == E2BIG) {
157 fprintf(stderr, "dm_handle_to_path buffer too small, "
158 "should be %d bytes\n", rlenp);
160 fprintf(stderr, "dm_handle_to_path failed, (%d) %s\n",
161 errno, strerror(errno));
165 fprintf(stderr, "rlenp is %d, pathbufp is %s\n", rlenp, pathbufp);
166 if (strlen(pathbufp) + 1 != rlenp) {
167 fprintf(stderr, "rlenp is %d, should be %d\n", rlenp,
168 strlen(pathbufp) + 1);