Update NEWS for 1.6.22
[pkg-k5-afs_openafs.git] / src / vol / test / utilities.c
blob21858ec4681d18b9fc50d81e9532b078db9c0eca
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 */
10 #include <afsconfig.h>
11 #include <afs/param.h>
14 #include <stdio.h>
15 #include <assert.h>
17 #include "listVicepx.h"
19 DirEnt *hash[MAX_HASH_SIZE];
20 static char *stack[MAX_STACK_SIZE];
21 static int stackSize;
22 static char fileName[2048];
24 /* hashes a number in the range 1.. MAX_HASH_SIZE */
25 mountHash(num)
26 int num;
28 return (num % MAX_HASH_SIZE);
32 /* insert entry in hash table */
33 insertHash(dir)
34 DirEnt *dir;
36 int h;
37 h = mountHash(dir->vnode);
39 /* insert in hash table */
40 dir->next = hash[h];
41 hash[h] = dir;
44 DirEnt *
45 lookup(vnode)
46 int vnode;
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;
58 char *
59 getDirName(dir, node)
60 DirEnt *dir;
61 int node;
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;
71 /* this shud be called on a vnode for a file only */
72 char *
73 getFileName(dir, unique)
74 DirEnt *dir;
75 int unique;
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;
85 /* for debugging */
86 printHash()
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;
104 pushStack(name)
105 char *name;
107 assert(stackSize < MAX_STACK_SIZE);
108 assert(stack[stackSize] = (char *)malloc(strlen(name) + 1));
109 strcpy(stack[stackSize], name);
110 stackSize++;
113 char *
114 popStack()
116 if (stackSize == 0)
117 return 0; /* stack empty */
118 return stack[--stackSize];
121 char *
122 printStack()
124 char *name;
125 fileName[0] = 0;
126 while (name = popStack()) {
127 strcat(fileName, "/");
128 strcat(fileName, name);
129 free(name);
131 return fileName;