Removed version number from file header.
[ira/wip.git] / source3 / smbd / statcache.c
index b66c5e2fe9e689f2419c0a912bcf5c663f7929f2..93782b9bb01109c75cb2b339b54a1f2c6bb466a3 100644 (file)
@@ -1,9 +1,8 @@
 /* 
-   Unix SMB/Netbios implementation.
-   Version 3.0
+   Unix SMB/CIFS implementation.
    stat cache code
    Copyright (C) Andrew Tridgell 1992-2000
-   Copyright (C) Jeremy Allison 1999-200
+   Copyright (C) Jeremy Allison 1999-2000
    
    
    This program is free software; you can redistribute it and/or modify
@@ -30,28 +29,6 @@ extern BOOL case_sensitive;
  Stat cache code used in unix_convert.
 *****************************************************************************/
 
-static int global_stat_cache_lookups;
-static int global_stat_cache_misses;
-static int global_stat_cache_hits;
-
-/****************************************************************************
- Stat cache statistics code.
-*****************************************************************************/
-
-void print_stat_cache_statistics(void)
-{
-  double eff;
-
-  if(global_stat_cache_lookups == 0)
-    return;
-
-  eff = (100.0* (double)global_stat_cache_hits)/(double)global_stat_cache_lookups;
-
-  DEBUG(0,("stat cache stats: lookups = %d, hits = %d, misses = %d, \
-stat cache was %f%% effective.\n", global_stat_cache_lookups,
-       global_stat_cache_hits, global_stat_cache_misses, eff ));
-}
-
 typedef struct {
   int name_len;
   char names[2]; /* This is extended via malloc... */
@@ -175,13 +152,14 @@ BOOL stat_cache_lookup(connection_struct *conn, char *name, char *dirpath,
   namelen = strlen(name);
 
   *start = name;
-  global_stat_cache_lookups++;
+
+  DO_PROFILE_INC(statcache_lookups);
 
   /*
    * Don't lookup trivial valid directory entries.
    */
   if((*name == '\0') || (strcmp(name, ".") == 0) || (strcmp(name, "..") == 0)) {
-    global_stat_cache_misses++;
+    DO_PROFILE_INC(statcache_misses);
     return False;
   }
 
@@ -195,26 +173,26 @@ BOOL stat_cache_lookup(connection_struct *conn, char *name, char *dirpath,
       /*
        * Didn't find it - remove last component for next try.
        */
-      sp = strrchr(chk_name, '/');
+      sp = strrchr_m(chk_name, '/');
       if (sp) {
         *sp = '\0';
       } else {
         /*
          * We reached the end of the name - no match.
          */
-        global_stat_cache_misses++;
+       DO_PROFILE_INC(statcache_misses);
         return False;
       }
       if((*chk_name == '\0') || (strcmp(chk_name, ".") == 0)
                           || (strcmp(chk_name, "..") == 0)) {
-        global_stat_cache_misses++;
+       DO_PROFILE_INC(statcache_misses);
         return False;
       }
     } else {
       scp = (stat_cache_entry *)(hash_elem->value);
-      global_stat_cache_hits++;
+      DO_PROFILE_INC(statcache_hits);
       trans_name = scp->names+scp->name_len+1;
-      if(conn->vfs_ops.stat(conn,dos_to_unix(trans_name,False), pst) != 0) {
+      if(vfs_stat(conn,trans_name, pst) != 0) {
         /* Discard this entry - it doesn't exist in the filesystem.  */
         hash_remove(&stat_cache, hash_elem);
         return False;
@@ -242,11 +220,11 @@ BOOL reset_stat_cache( void )
        static BOOL initialised;
        if (!lp_stat_cache()) return True;
 
-       if (!initialised) {
-               initialised = True;
-               return hash_table_init( &stat_cache, INIT_STAT_CACHE_SIZE, (compare_function)(strcmp));
+       if (initialised) {
+               hash_clear(&stat_cache);
        }
-       hash_clear(&stat_cache);
-       return hash_table_init( &stat_cache, INIT_STAT_CACHE_SIZE, (compare_function)(strcmp));
 
+       initialised = hash_table_init( &stat_cache, INIT_STAT_CACHE_SIZE, 
+                                      (compare_function)(strcmp));
+       return initialised;
 } /* reset_stat_cache  */