svn commit: samba r4956 - in branches/SAMBA_4_0/source/ntvfs/posix: .

tridge at samba.org tridge at samba.org
Mon Jan 24 03:33:37 GMT 2005


Author: tridge
Date: 2005-01-24 03:33:36 +0000 (Mon, 24 Jan 2005)
New Revision: 4956

WebSVN: http://websvn.samba.org/cgi-bin/viewcvs.cgi?view=rev&root=samba&rev=4956

Log:
- moved the definition of the mangle context structure into a pvfs_shortname

- made the mangle cache size configurable


Modified:
   branches/SAMBA_4_0/source/ntvfs/posix/pvfs_shortname.c
   branches/SAMBA_4_0/source/ntvfs/posix/vfs_posix.h


Changeset:
Modified: branches/SAMBA_4_0/source/ntvfs/posix/pvfs_shortname.c
===================================================================
--- branches/SAMBA_4_0/source/ntvfs/posix/pvfs_shortname.c	2005-01-24 02:19:57 UTC (rev 4955)
+++ branches/SAMBA_4_0/source/ntvfs/posix/pvfs_shortname.c	2005-01-24 03:33:36 UTC (rev 4956)
@@ -71,11 +71,6 @@
 #define FLAG_POSSIBLE3 64
 #define FLAG_POSSIBLE4 128
 
-/* by default have a max of 512 entries in the cache. */
-#ifndef MANGLE_CACHE_SIZE
-#define MANGLE_CACHE_SIZE 512
-#endif
-
 #define DEFAULT_MANGLE_PREFIX 4
 
 #define MANGLE_BASECHARS "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ"
@@ -87,6 +82,31 @@
   "LPT1", "LPT2", "LPT3", "NUL", "PRN", NULL };
 
 
+struct pvfs_mangle_context {
+	uint8_t char_flags[256];
+	/*
+	  this determines how many characters are used from the original
+	  filename in the 8.3 mangled name. A larger value leads to a weaker
+	  hash and more collisions.  The largest possible value is 6.
+	*/
+	int mangle_prefix;
+	uint32_t mangle_modulus;
+
+	/* we will use a very simple direct mapped prefix cache. The big
+	   advantage of this cache structure is speed and low memory usage 
+
+	   The cache is indexed by the low-order bits of the hash, and confirmed by
+	   hashing the resulting cache entry to match the known hash
+	*/
+	uint32_t cache_size;
+	char **prefix_cache;
+	uint32_t *prefix_cache_hashes;
+
+	/* this is used to reverse the base 36 mapping */
+	unsigned char base_reverse[256];
+};
+
+
 /* 
    hash a string of the specified length. The string does not need to be
    null terminated 
@@ -105,7 +125,7 @@
 static void cache_insert(struct pvfs_mangle_context *ctx,
 			 const char *prefix, int length, uint32_t hash)
 {
-	int i = hash % MANGLE_CACHE_SIZE;
+	int i = hash % ctx->cache_size;
 
 	if (ctx->prefix_cache[i]) {
 		talloc_free(ctx->prefix_cache[i]);
@@ -120,7 +140,7 @@
 */
 static const char *cache_lookup(struct pvfs_mangle_context *ctx, uint32_t hash)
 {
-	int i = hash % MANGLE_CACHE_SIZE;
+	int i = hash % ctx->cache_size;
 
 
 	if (!ctx->prefix_cache[i] || hash != ctx->prefix_cache_hashes[i]) {
@@ -592,17 +612,21 @@
 	if (ctx == NULL) {
 		return NT_STATUS_NO_MEMORY;
 	}
-	ctx->prefix_cache = talloc_array_p(ctx, char *, MANGLE_CACHE_SIZE);
+
+	/* by default have a max of 512 entries in the cache. */
+	ctx->cache_size = lp_parm_int(-1, "mangle", "cachesize", 512);
+
+	ctx->prefix_cache = talloc_array(ctx, char *, ctx->cache_size);
 	if (ctx->prefix_cache == NULL) {
 		return NT_STATUS_NO_MEMORY;
 	}
-	ctx->prefix_cache_hashes = talloc_array_p(ctx, uint32_t, MANGLE_CACHE_SIZE);
+	ctx->prefix_cache_hashes = talloc_array(ctx, uint32_t, ctx->cache_size);
 	if (ctx->prefix_cache_hashes == NULL) {
 		return NT_STATUS_NO_MEMORY;
 	}
 
-	memset(ctx->prefix_cache, 0, sizeof(char *)*MANGLE_CACHE_SIZE);
-	memset(ctx->prefix_cache_hashes, 0, sizeof(uint32_t)*MANGLE_CACHE_SIZE);
+	memset(ctx->prefix_cache, 0, sizeof(char *) * ctx->cache_size);
+	memset(ctx->prefix_cache_hashes, 0, sizeof(uint32_t) * ctx->cache_size);
 
 	ctx->mangle_prefix = lp_parm_int(-1, "mangle", "prefix", -1);
 	if (ctx->mangle_prefix < 0 || ctx->mangle_prefix > 6) {

Modified: branches/SAMBA_4_0/source/ntvfs/posix/vfs_posix.h
===================================================================
--- branches/SAMBA_4_0/source/ntvfs/posix/vfs_posix.h	2005-01-24 02:19:57 UTC (rev 4955)
+++ branches/SAMBA_4_0/source/ntvfs/posix/vfs_posix.h	2005-01-24 03:33:36 UTC (rev 4956)
@@ -164,31 +164,6 @@
 };
 
 
-struct pvfs_mangle_context {
-	uint8_t char_flags[256];
-	/*
-	  this determines how many characters are used from the original
-	  filename in the 8.3 mangled name. A larger value leads to a weaker
-	  hash and more collisions.  The largest possible value is 6.
-	*/
-	int mangle_prefix;
-	uint32_t mangle_modulus;
-
-	/* we will use a very simple direct mapped prefix cache. The big
-	   advantage of this cache structure is speed and low memory usage 
-
-	   The cache is indexed by the low-order bits of the hash, and confirmed by
-	   hashing the resulting cache entry to match the known hash
-	*/
-	char **prefix_cache;
-	uint32_t *prefix_cache_hashes;
-
-	/* this is used to reverse the base 36 mapping */
-	unsigned char base_reverse[256];
-};
-
-
-
 /* flags to pvfs_resolve_name() */
 #define PVFS_RESOLVE_WILDCARD    (1<<0)
 #define PVFS_RESOLVE_STREAMS     (1<<1)



More information about the samba-cvs mailing list