xref: /titanic_52/usr/src/uts/common/sharefs/sharetab.h (revision b6c3f7863936abeae522e48a13887dddeb691a45)
1 /*
2  * CDDL HEADER START
3  *
4  * The contents of this file are subject to the terms of the
5  * Common Development and Distribution License (the "License").
6  * You may not use this file except in compliance with the License.
7  *
8  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
9  * or http://www.opensolaris.org/os/licensing.
10  * See the License for the specific language governing permissions
11  * and limitations under the License.
12  *
13  * When distributing Covered Code, include this CDDL HEADER in each
14  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
15  * If applicable, add the following below this CDDL HEADER, with the
16  * fields enclosed by brackets "[]" replaced with your own identifying
17  * information: Portions Copyright [yyyy] [name of copyright owner]
18  *
19  * CDDL HEADER END
20  */
21 
22 /*
23  * Copyright 2007 Sun Microsystems, Inc.  All rights reserved.
24  * Use is subject to license terms.
25  */
26 
27 #ifndef _SHAREFS_SHARETAB_H
28 #define	_SHAREFS_SHARETAB_H
29 
30 #pragma ident	"%Z%%M%	%I%	%E% SMI"
31 
32 /*
33  * This header defines the glue to keeping a sharetab in memory.
34  * It is broken out from sharefs.h in the case that it will be
35  * reused in userland.
36  */
37 
38 /*
39  * Note:
40  * Must include share/share.h before this header.
41  */
42 
43 #ifdef __cplusplus
44 extern "C" {
45 #endif
46 
47 typedef struct sh_list {		/* cached share list */
48 	struct sh_list	*shl_next;
49 	share_t		*shl_sh;
50 } sh_list_t;
51 
52 typedef struct sharefs_hash_head {
53 	share_t		*ssh_sh;
54 	uint_t		ssh_count;
55 } sharefs_hash_head_t;
56 
57 #define	SHARETAB_HASHES		256
58 
59 typedef struct sharetab {
60 	sharefs_hash_head_t	s_buckets[SHARETAB_HASHES];
61 	char			*s_fstype;
62 	struct sharetab		*s_next;
63 	uint_t			s_count;
64 } sharetab_t;
65 
66 #define	MOD2(a, pow_of_2)	(a) & ((pow_of_2) - 1)
67 
68 /*
69  * Pearson's string hash
70  *
71  * See: Communications of the ACM, June 1990 Vol 33 pp 677-680
72  * http://www.acm.org/pubs/citations/journals/cacm/1990-33-6/p677-pearson
73  */
74 #define	SHARETAB_HASH_IT(hash, path)					\
75 {									\
76 	uint_t		key = 0x12345678;	/* arbitrary value */	\
77 	int		i, len;						\
78 									\
79 	len = strlen((path));						\
80 									\
81 	(hash) = MOD2((key + len), SHARETAB_HASHES);			\
82 									\
83 	for (i = 0; i < len; i++) {					\
84 		(hash) = MOD2(((hash) + (path)[i]), SHARETAB_HASHES);	\
85 		(hash) = pkp_tab[(hash)];				\
86 	}								\
87 }
88 
89 #ifdef __cplusplus
90 }
91 #endif
92 
93 #endif /* !_SHAREFS_SHARETAB_H */
94