2 * Copyright (c) 2000-2001 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/
33 #include <sys/types.h>
43 /*---------------------------------------------------------------------------
45 Test program used to test all the DMAPI functions in dm_handle.c. The
50 where pathname is the name of a file. If any function fails, an error message
51 containing the work ERROR will be written to stderr.
53 Tested DMAPI functions are:
68 ----------------------------------------------------------------------------*/
82 void *hanp1, *hanp2, *hanp3, *fshanp1, *fshanp2, *fshanp3;
83 size_t hlen1, hlen2, hlen3, fshlen1, fshlen2, fshlen3;
84 u_int hash1, hash2, hash3, fshash1, fshash2, fshash3;
97 if (Progname = strrchr(argv[0], '/')) {
104 fprintf(stderr, "usage: %s path\n", argv[0]);
109 (void)dm_init_service(&name);
111 if (dm_path_to_handle(pathname, &hanp1, &hlen1) != 0) {
112 fprintf(stderr, "dm_path_to_handle failed, %s\n",
116 hash1 = dm_handle_hash(hanp1, hlen1);
117 hantoa(hanp1, hlen1, buffer1);
118 fprintf(stdout, " han1: hash %u value %s (dm_path_to_handle)\n",
120 if (dm_handle_is_valid(hanp1, hlen1) == DM_FALSE) {
121 fprintf(stderr, "ERROR: han1 is not valid\n");
124 if (dm_path_to_fshandle(pathname, &fshanp1, &fshlen1) != 0) {
125 fprintf(stderr, "dm_path_to_fshandle failed, %s\n",
129 fshash1 = dm_handle_hash(fshanp1, fshlen1);
130 hantoa(fshanp1, fshlen1, fsbuffer1);
131 fprintf(stdout, "fshan1: hash %u value %s (dm_path_to_fshandle\n",
133 if (dm_handle_is_valid(fshanp1, fshlen1) == DM_FALSE) {
134 fprintf(stderr, "ERROR: fshan1 is not valid\n");
137 if ((fd = open(pathname, O_RDONLY)) < 0) {
138 fprintf(stderr, "open of %s failed, %s\n", pathname,
142 if (dm_fd_to_handle(fd, &hanp2, &hlen2) != 0) {
143 fprintf(stderr, "dm_fd_to_handle failed, %s\n",
148 hash2 = dm_handle_hash(hanp2, hlen2);
149 hantoa(hanp2, hlen2, buffer2);
150 fprintf(stdout, " han2: hash %u value %s (dm_fd_to_handle)\n",
152 if (dm_handle_is_valid(hanp2, hlen2) == DM_FALSE) {
153 fprintf(stderr, "ERROR: han2 is not valid\n");
156 if (dm_handle_to_fshandle(hanp2, hlen2, &fshanp2, &fshlen2) != 0) {
157 fprintf(stderr, "dm_handle_to_fshandle failed, %s\n",
161 fshash2 = dm_handle_hash(fshanp2, fshlen2);
162 hantoa(fshanp2, fshlen2, fsbuffer2);
163 fprintf(stdout, "fshan2: hash %u value %s (dm_handle_to_fshandle)\n",
165 if (dm_handle_is_valid(fshanp2, fshlen2) == DM_FALSE) {
166 fprintf(stderr, "ERROR: fshan2 is not valid\n");
169 if (dm_handle_cmp(hanp1, hlen1, hanp2, hlen2)) {
170 fprintf(stderr, "ERROR: han1 and han2 differ in dm_handle_cmp\n");
172 if (strcmp(buffer1, buffer2)) {
173 fprintf(stderr, "ERROR: han1 and han2 differ in strcmp\n");
175 if (hash1 != hash2) {
176 fprintf(stderr, "ERROR: hash1 and hash2 differ\n");
179 if (dm_handle_cmp(fshanp1, fshlen1, fshanp2, fshlen2)) {
180 fprintf(stderr, "ERROR: fshan1 and fshan2 differ in dm_handle_cmp\n");
182 if (strcmp(fsbuffer1, fsbuffer2)) {
183 fprintf(stderr, "ERROR: fshan1 and fshan2 differ in strcmp\n");
185 if (fshash1 != fshash2) {
186 fprintf(stderr, "ERROR: fshash1 and fshash2 differ\n");
189 /* Break the handle into its component parts and display them. Use
190 hantoa() instead of printing the parts directly because some are
191 32 bits on Veritas and 64 bits on SGI.
194 if (dm_handle_to_fsid(hanp1, hlen1, &fsid) != 0) {
195 fprintf(stderr, "dm_handle_to_fsid failed, %s\n",
199 hantoa(&fsid, sizeof(fsid), buffer);
200 fprintf(stdout, "fsid %s (dm_handle_to_fsid)\n", buffer);
202 if (dm_handle_to_ino(hanp1, hlen1, &ino) != 0) {
203 fprintf(stderr, "dm_handle_to_ino failed, %s\n",
207 hantoa(&ino, sizeof(ino), buffer);
208 fprintf(stdout, "ino %s (dm_handle_to_ino)\n", buffer);
210 if (dm_handle_to_igen(hanp1, hlen1, &igen) != 0) {
211 fprintf(stderr, "dm_handle_to_igen failed, %s\n",
215 hantoa(&igen, sizeof(igen), buffer);
216 fprintf(stdout, "igen %s (dm_handle_to_igen)\n", buffer);
218 /* Now use the parts to remake the handle and verify we get the same
222 if (dm_make_handle(&fsid, &ino, &igen, &hanp3, &hlen3) != 0) {
223 fprintf(stderr, "dm_make_handle failed, %s\n",
227 hash3 = dm_handle_hash(hanp3, hlen3);
228 hantoa(hanp3, hlen3, buffer3);
229 fprintf(stdout, " han3: hash %u value %s (dm_make_handle)\n",
231 if (dm_handle_is_valid(hanp3, hlen3) == DM_FALSE) {
232 fprintf(stderr, "ERROR: han3 is not valid\n");
235 if (dm_handle_cmp(hanp1, hlen1, hanp3, hlen3)) {
236 fprintf(stderr, "ERROR: hanp1 and hanp3 differ in dm_handle_cmp\n");
238 if (strcmp(buffer1, buffer3)) {
239 fprintf(stderr, "ERROR: hanp1 and hanp3 differ in strcmp\n");
241 if (hash1 != hash3) {
242 fprintf(stderr, "ERROR: hash1 and hash3 differ\n");
245 if (dm_make_fshandle(&fsid, &fshanp3, &fshlen3) != 0) {
246 fprintf(stderr, "dm_make_fshandle failed, %s\n",
250 fshash3 = dm_handle_hash(fshanp3, fshlen3);
251 hantoa(fshanp3, fshlen3, fsbuffer3);
252 fprintf(stdout, "fshan3: hash %u value %s (dm_make_fshandle)\n",
254 if (dm_handle_is_valid(fshanp3, fshlen3) == DM_FALSE) {
255 fprintf(stderr, "ERROR: fshan3 is not valid\n");
258 if (dm_handle_cmp(fshanp1, fshlen1, fshanp3, fshlen3)) {
259 fprintf(stderr, "ERROR: fshan1 and fshan3 differ in dm_handle_cmp\n");
261 if (strcmp(fsbuffer1, fsbuffer3)) {
262 fprintf(stderr, "ERROR: fshan1 and fshan3 differ in strcmp\n");
264 if (fshash1 != fshash3) {
265 fprintf(stderr, "ERROR: fshash1 and fshash3 differ\n");
268 dm_handle_free(hanp1, hlen1);
269 dm_handle_free(hanp2, hlen2);
270 dm_handle_free(hanp3, hlen3);
271 dm_handle_free(fshanp1, fshlen1);
272 dm_handle_free(fshanp2, fshlen2);
273 dm_handle_free(fshanp3, fshlen3);