1 // SPDX-License-Identifier: GPL-2.0
3 * Copyright (c) 2000-2002 Silicon Graphics, Inc.
12 #include <lib/dmport.h>
17 #include <xfs/xfs_fs.h>
18 #include <xfs/handle.h>
21 /*---------------------------------------------------------------------------
23 Test program used to test the DMAPI function dm_handle_to_path(). The
26 handle_to_path [-b buflen] {dirpath|dirhandle} {objpath|objhandle}
28 There are two parameters. The first is the pathname of a directory,
29 and the second is the pathname of a file, directory, or symbolic link
30 within that directory. The second parameter can also be the same as
31 the first if you want to specify "." (this is how EMASS uses it).
32 Pathnames can either be relative or full.
34 buflen is the size of the buffer to use in the call.
36 This program will return the full pathname of the object which is the
37 second parameter using the dm_handle_to_path() function.
39 The program should work successfully for files, directories, and
40 symbolic links, and does not have to work for any other type of
41 object. It doesn't have to work across mount points. There shouldn't
42 be any "/." crud on the end of the returned pathname either.
44 ----------------------------------------------------------------------------*/
56 fprintf(stderr, "usage:\t%s [-b buflen] {dirpath|dirhandle} {objpath|objhandle}\n", Progname);
76 Progname = strrchr(argv[0], '/');
83 /* Crack and validate the command line options. */
85 while ((opt = getopt(argc, argv, "b:")) != EOF) {
88 buflen = atol(optarg);
94 if (optind + 2 != argc)
96 dirpath = argv[optind++];
97 objpath = argv[optind];
99 if (dm_init_service(&name)) {
100 fprintf(stderr, "Can't initialize the DMAPI\n");
104 if (opaque_to_handle(dirpath, &hanp1, &hlen1)) {
105 fprintf(stderr, "can't get handle for dir %s\n", dirpath);
109 if (opaque_to_handle(objpath, &hanp2, &hlen2)) {
110 fprintf(stderr, "can't get handle for obj %s\n", objpath);
114 if ((pathbufp = malloc(buflen == 0 ? 1 : buflen)) == NULL) {
115 fprintf(stderr, "malloc failed\n");
119 if (dm_handle_to_path(hanp1, hlen1, hanp2, hlen2,
120 buflen, pathbufp, &rlenp)) {
121 if (errno == E2BIG) {
122 fprintf(stderr, "dm_handle_to_path buffer too small, "
123 "should be %zd bytes\n", rlenp);
125 fprintf(stderr, "dm_handle_to_path failed, (%d) %s\n",
126 errno, strerror(errno));
130 fprintf(stderr, "rlenp is %zd, pathbufp is %s\n", rlenp, (char*)pathbufp);
131 if (strlen(pathbufp) + 1 != rlenp) {
132 fprintf(stderr, "rlenp is %zd, should be %zd\n", rlenp,
133 strlen(pathbufp) + 1);