Import Upstream version 1.8.5
[hcoop/debian/openafs.git] / src / vol / test / utilities.c
1 /*
2 * Copyright 2000, International Business Machines Corporation and others.
3 * All Rights Reserved.
4 *
5 * This software has been released under the terms of the IBM Public
6 * License. For details, see the LICENSE file in the top-level source
7 * directory or online at http://www.openafs.org/dl/license10.html
8 */
9
10 #include <afsconfig.h>
11 #include <afs/param.h>
12
13
14 #include <stdio.h>
15 #include <assert.h>
16
17 #include "listVicepx.h"
18
19 DirEnt *hash[MAX_HASH_SIZE];
20 static char *stack[MAX_STACK_SIZE];
21 static int stackSize;
22 static char fileName[2048];
23
24 /* hashes a number in the range 1.. MAX_HASH_SIZE */
25 mountHash(num)
26 int num;
27 {
28 return (num % MAX_HASH_SIZE);
29 }
30
31
32 /* insert entry in hash table */
33 insertHash(dir)
34 DirEnt *dir;
35 {
36 int h;
37 h = mountHash(dir->vnode);
38
39 /* insert in hash table */
40 dir->next = hash[h];
41 hash[h] = dir;
42 }
43
44 DirEnt *
45 lookup(vnode)
46 int vnode;
47 {
48 DirEnt *ptr;
49 ptr = hash[mountHash(vnode)];
50 while (ptr)
51 if (ptr->vnode == vnode)
52 return ptr;
53 else
54 ptr = ptr->next;
55 return 0;
56 }
57
58 char *
59 getDirName(dir, node)
60 DirEnt *dir;
61 int node;
62 {
63 int i;
64 for (i = 0; i < dir->numEntries; i++)
65 if (dir->vnodeName[i].vnode == node)
66 return dir->vnodeName[i].name;
67 return 0;
68 }
69
70
71 /* this shud be called on a vnode for a file only */
72 char *
73 getFileName(dir, unique)
74 DirEnt *dir;
75 int unique;
76 {
77 /* go down the linked list */
78 int i;
79 for (i = 0; i < dir->numEntries; i++)
80 if (dir->vnodeName[i].vunique == unique)
81 return dir->vnodeName[i].name;
82 return 0;
83 }
84
85 /* for debugging */
86 printHash()
87 {
88 int i, j;
89 for (i = 0; i < MAX_HASH_SIZE; i++) {
90 DirEnt *ptr = hash[i];
91 while (ptr) {
92 #ifdef DEBUG
93 printf("Vnode: %d Parent Vnode : %d \n", ptr->vnode,
94 ptr->vnodeParent);
95 #endif
96 for (j = 0; j < ptr->numEntries; j++)
97 printf("\t %s %d %d\n", ptr->vnodeName[j].name,
98 ptr->vnodeName[j].vnode, ptr->vnodeName[j].vunique);
99 ptr = ptr->next;
100 }
101 }
102 }
103
104 pushStack(name)
105 char *name;
106 {
107 assert(stackSize < MAX_STACK_SIZE);
108 assert(stack[stackSize] = strdup(name));
109 stackSize++;
110 }
111
112 char *
113 popStack()
114 {
115 if (stackSize == 0)
116 return 0; /* stack empty */
117 return stack[--stackSize];
118 }
119
120 char *
121 printStack()
122 {
123 char *name;
124 fileName[0] = 0;
125 while (name = popStack()) {
126 strcat(fileName, "/");
127 strcat(fileName, name);
128 free(name);
129 }
130 return fileName;
131 }