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>
29 #include <xfs/xfs_fs.h>
30 #include <xfs/handle.h>
33 /*---------------------------------------------------------------------------
35 Test program used to test the DMAPI function dm_handle_to_path(). The
38 handle_to_path [-b buflen] {dirpath|dirhandle} {objpath|objhandle}
40 There are two parameters. The first is the pathname of a directory,
41 and the second is the pathname of a file, directory, or symbolic link
42 within that directory. The second parameter can also be the same as
43 the first if you want to specify "." (this is how EMASS uses it).
44 Pathnames can either be relative or full.
46 buflen is the size of the buffer to use in the call.
48 This program will return the full pathname of the object which is the
49 second parameter using the dm_handle_to_path() function.
51 The program should work successfully for files, directories, and
52 symbolic links, and does not have to work for any other type of
53 object. It doesn't have to work across mount points. There shouldn't
54 be any "/." crud on the end of the returned pathname either.
56 ----------------------------------------------------------------------------*/
68 fprintf(stderr, "usage:\t%s [-b buflen] {dirpath|dirhandle} {objpath|objhandle}\n", Progname);
88 Progname = strrchr(argv[0], '/');
95 /* Crack and validate the command line options. */
97 while ((opt = getopt(argc, argv, "b:")) != EOF) {
100 buflen = atol(optarg);
106 if (optind + 2 != argc)
108 dirpath = argv[optind++];
109 objpath = argv[optind];
111 if (dm_init_service(&name)) {
112 fprintf(stderr, "Can't initialize the DMAPI\n");
116 if (opaque_to_handle(dirpath, &hanp1, &hlen1)) {
117 fprintf(stderr, "can't get handle for dir %s\n", dirpath);
121 if (opaque_to_handle(objpath, &hanp2, &hlen2)) {
122 fprintf(stderr, "can't get handle for obj %s\n", objpath);
126 if ((pathbufp = malloc(buflen == 0 ? 1 : buflen)) == NULL) {
127 fprintf(stderr, "malloc failed\n");
131 if (dm_handle_to_path(hanp1, hlen1, hanp2, hlen2,
132 buflen, pathbufp, &rlenp)) {
133 if (errno == E2BIG) {
134 fprintf(stderr, "dm_handle_to_path buffer too small, "
135 "should be %zd bytes\n", rlenp);
137 fprintf(stderr, "dm_handle_to_path failed, (%d) %s\n",
138 errno, strerror(errno));
142 fprintf(stderr, "rlenp is %zd, pathbufp is %s\n", rlenp, (char*)pathbufp);
143 if (strlen(pathbufp) + 1 != rlenp) {
144 fprintf(stderr, "rlenp is %zd, should be %zd\n", rlenp,
145 strlen(pathbufp) + 1);