2 * Copyright (c) 2000-2002 Silicon Graphics, Inc.
5 * This program is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU General Public License as
7 * published by the Free Software Foundation.
9 * This program is distributed in the hope that it would be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
14 * You should have received a copy of the GNU General Public License
15 * along with this program; if not, write the Free Software Foundation,
16 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
24 #include <lib/dmport.h>
28 #include <xfs/xfs_fs.h>
29 #include <xfs/handle.h>
32 /*---------------------------------------------------------------------------
34 Test program used to test the DMAPI function dm_handle_to_path(). The
37 handle_to_path [-b buflen] {dirpath|dirhandle} {objpath|objhandle}
39 There are two parameters. The first is the pathname of a directory,
40 and the second is the pathname of a file, directory, or symbolic link
41 within that directory. The second parameter can also be the same as
42 the first if you want to specify "." (this is how EMASS uses it).
43 Pathnames can either be relative or full.
45 buflen is the size of the buffer to use in the call.
47 This program will return the full pathname of the object which is the
48 second parameter using the dm_handle_to_path() function.
50 The program should work successfully for files, directories, and
51 symbolic links, and does not have to work for any other type of
52 object. It doesn't have to work across mount points. There shouldn't
53 be any "/." crud on the end of the returned pathname either.
55 ----------------------------------------------------------------------------*/
67 fprintf(stderr, "usage:\t%s [-b buflen] {dirpath|dirhandle} {objpath|objhandle}\n", Progname);
87 if (Progname = strrchr(argv[0], '/')) {
93 /* Crack and validate the command line options. */
95 while ((opt = getopt(argc, argv, "b:")) != EOF) {
98 buflen = atol(optarg);
104 if (optind + 2 != argc)
106 dirpath = argv[optind++];
107 objpath = argv[optind];
109 if (dm_init_service(&name)) {
110 fprintf(stderr, "Can't initialize the DMAPI\n");
114 if (opaque_to_handle(dirpath, &hanp1, &hlen1)) {
115 fprintf(stderr, "can't get handle for dir %s\n", dirpath);
119 if (opaque_to_handle(objpath, &hanp2, &hlen2)) {
120 fprintf(stderr, "can't get handle for obj %s\n", objpath);
124 if ((pathbufp = malloc(buflen == 0 ? 1 : buflen)) == NULL) {
125 fprintf(stderr, "malloc failed\n");
129 if (dm_handle_to_path(hanp1, hlen1, hanp2, hlen2,
130 buflen, pathbufp, &rlenp)) {
131 if (errno == E2BIG) {
132 fprintf(stderr, "dm_handle_to_path buffer too small, "
133 "should be %d bytes\n", rlenp);
135 fprintf(stderr, "dm_handle_to_path failed, (%d) %s\n",
136 errno, strerror(errno));
140 fprintf(stderr, "rlenp is %d, pathbufp is %s\n", rlenp, (char*)pathbufp);
141 if (strlen(pathbufp) + 1 != rlenp) {
142 fprintf(stderr, "rlenp is %d, should be %d\n", rlenp,
143 strlen(pathbufp) + 1);