OpenCores
URL https://opencores.org/ocsvn/or1k/or1k/trunk

Subversion Repositories or1k

[/] [or1k/] [trunk/] [rc203soc/] [sw/] [uClinux/] [fs/] [autofs/] [dirhash.c] - Blame information for rev 1777

Go to most recent revision | Details | Compare with Previous | View Log

Line No. Rev Author Line
1 1628 jcastillo
/* -*- linux-c -*- --------------------------------------------------------- *
2
 *
3
 * linux/fs/autofs/dirhash.c
4
 *
5
 *  Copyright 1997 Transmeta Corporation -- All Rights Reserved
6
 *
7
 * This file is part of the Linux kernel and is made available under
8
 * the terms of the GNU General Public License, version 2, or at your
9
 * option, any later version, incorporated herein by reference.
10
 *
11
 * ------------------------------------------------------------------------- */
12
 
13
#include "autofs_i.h"
14
 
15
/* Functions for maintenance of expiry queue */
16
 
17
static void autofs_init_usage(struct autofs_dirhash *dh,
18
                              struct autofs_dir_ent *ent)
19
{
20
        ent->exp_next = &dh->expiry_head;
21
        ent->exp_prev = dh->expiry_head.exp_prev;
22
        dh->expiry_head.exp_prev->exp_next = ent;
23
        dh->expiry_head.exp_prev = ent;
24
        ent->last_usage = jiffies;
25
}
26
 
27
static void autofs_delete_usage(struct autofs_dir_ent *ent)
28
{
29
        ent->exp_prev->exp_next = ent->exp_next;
30
        ent->exp_next->exp_prev = ent->exp_prev;
31
}
32
 
33
void autofs_update_usage(struct autofs_dirhash *dh,
34
                         struct autofs_dir_ent *ent)
35
{
36
        autofs_delete_usage(ent);   /* Unlink from current position */
37
        autofs_init_usage(dh,ent);  /* Relink at queue tail */
38
}
39
 
40
struct autofs_dir_ent *autofs_expire(struct autofs_dirhash *dh,
41
                                     unsigned long timeout)
42
{
43
        struct autofs_dir_ent *ent;
44
 
45
        ent = dh->expiry_head.exp_next;
46
 
47
        if ( ent == &(dh->expiry_head) ) return NULL;
48
        return (jiffies - ent->last_usage >= timeout) ? ent : NULL;
49
}
50
 
51
/* Adapted from the Dragon Book, page 436 */
52
/* This particular hashing algorithm requires autofs_hash_t == u32 */
53
autofs_hash_t autofs_hash(const char *name, int len)
54
{
55
        autofs_hash_t h = 0;
56
        while ( len-- ) {
57
                h = (h << 4) + (unsigned char) (*name++);
58
                h ^= ((h & 0xf0000000) >> 24);
59
        }
60
        return h;
61
}
62
 
63
void autofs_initialize_hash(struct autofs_dirhash *dh) {
64
        memset(&dh->h, 0, AUTOFS_HASH_SIZE*sizeof(struct autofs_dir_ent *));
65
        dh->expiry_head.exp_next = dh->expiry_head.exp_prev =
66
                &dh->expiry_head;
67
}
68
 
69
struct autofs_dir_ent *autofs_hash_lookup(const struct autofs_dirhash *dh, autofs_hash_t hash, const char *name, int len)
70
{
71
        struct autofs_dir_ent *dhn;
72
 
73
        DPRINTK(("autofs_hash_lookup: hash = 0x%08x, name = ", hash));
74
        autofs_say(name,len);
75
 
76
        for ( dhn = dh->h[hash % AUTOFS_HASH_SIZE] ; dhn ; dhn = dhn->next ) {
77
                if ( hash == dhn->hash &&
78
                     len == dhn->len &&
79
                     !memcmp(name, dhn->name, len) )
80
                        break;
81
        }
82
 
83
        return dhn;
84
}
85
 
86
void autofs_hash_insert(struct autofs_dirhash *dh, struct autofs_dir_ent *ent)
87
{
88
        struct autofs_dir_ent **dhnp;
89
 
90
        DPRINTK(("autofs_hash_insert: hash = 0x%08x, name = ", ent->hash));
91
        autofs_say(ent->name,ent->len);
92
 
93
        autofs_init_usage(dh,ent);
94
 
95
        dhnp = &dh->h[ent->hash % AUTOFS_HASH_SIZE];
96
        ent->next = *dhnp;
97
        ent->back = dhnp;
98
        *dhnp = ent;
99
}
100
 
101
void autofs_hash_delete(struct autofs_dir_ent *ent)
102
{
103
        *(ent->back) = ent->next;
104
 
105
        autofs_delete_usage(ent);
106
 
107
        kfree(ent->name);
108
        kfree(ent);
109
}
110
 
111
/*
112
 * Used by readdir().  We must validate "ptr", so we can't simply make it
113
 * a pointer.  Values below 0xffff are reserved; calling with any value
114
 * <= 0x10000 will return the first entry found.
115
 */
116
struct autofs_dir_ent *autofs_hash_enum(const struct autofs_dirhash *dh, off_t *ptr)
117
{
118
        int bucket, ecount, i;
119
        struct autofs_dir_ent *ent;
120
 
121
        bucket = (*ptr >> 16) - 1;
122
        ecount = *ptr & 0xffff;
123
 
124
        if ( bucket < 0 ) {
125
                bucket = ecount = 0;
126
        }
127
 
128
        DPRINTK(("autofs_hash_enum: bucket %d, entry %d\n", bucket, ecount));
129
 
130
        ent = NULL;
131
 
132
        while  ( bucket < AUTOFS_HASH_SIZE ) {
133
                ent = dh->h[bucket];
134
                for ( i = ecount ; ent && i ; i-- )
135
                        ent = ent->next;
136
 
137
                if (ent) {
138
                        ecount++; /* Point to *next* entry */
139
                        break;
140
                }
141
 
142
                bucket++; ecount = 0;
143
        }
144
 
145
#ifdef DEBUG
146
        if ( !ent )
147
                printk("autofs_hash_enum: nothing found\n");
148
        else {
149
                printk("autofs_hash_enum: found hash %08x, name", ent->hash);
150
                autofs_say(ent->name,ent->len);
151
        }
152
#endif
153
 
154
        *ptr = ((bucket+1) << 16) + ecount;
155
        return ent;
156
}
157
 
158
/* Delete everything.  This is used on filesystem destruction, so we
159
   make no attempt to keep the pointers valid */
160
void autofs_hash_nuke(struct autofs_dirhash *dh)
161
{
162
        int i;
163
        struct autofs_dir_ent *ent, *nent;
164
 
165
        for ( i = 0 ; i < AUTOFS_HASH_SIZE ; i++ ) {
166
                for ( ent = dh->h[i] ; ent ; ent = nent ) {
167
                        nent = ent->next;
168
                        kfree(ent->name);
169
                        kfree(ent);
170
                }
171
        }
172
}

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.