Add name_hash to files_struct. Set within fsp_set_smb_fname().
authorJeremy Allison <jra@samba.org>
Tue, 25 Jan 2011 21:49:01 +0000 (13:49 -0800)
committerJeremy Allison <jra@samba.org>
Tue, 25 Jan 2011 21:49:01 +0000 (13:49 -0800)
source3/include/proto.h
source3/include/smb.h
source3/smbd/files.c

index 29dbcc97635ab00b89dce93552daf12c228a513b..fafcf6be52e8a3574ac5ce62b83ce84966fc2cb9 100644 (file)
@@ -4764,6 +4764,8 @@ files_struct *file_fsp(struct smb_request *req, uint16 fid);
 NTSTATUS dup_file_fsp(struct smb_request *req, files_struct *from,
                      uint32 access_mask, uint32 share_access,
                      uint32 create_options, files_struct *to);
+NTSTATUS file_name_hash(connection_struct *conn,
+                       const char *name, uint32_t *p_name_hash);
 NTSTATUS fsp_set_smb_fname(struct files_struct *fsp,
                           const struct smb_filename *smb_fname_in);
 
index 1a76691a44a4664977c64fcd9f28026f5470a3fa..6cfb6307d0f66aaddfb4db453fcb43fe6c8436b9 100644 (file)
@@ -346,6 +346,7 @@ typedef struct files_struct {
        bool posix_open;
        bool is_sparse;
        struct smb_filename *fsp_name;
+       uint32_t name_hash;             /* Jenkins hash of full pathname. */
 
        struct vfs_fsp_data *vfs_extension;
        struct fake_file_handle *fake_file_handle;
index 7275868ffae45302f8bf59cb418ed3ed3af70d41..f01da2c8a21aac4486e547deb2b4b440881f4bc9 100644 (file)
@@ -590,6 +590,35 @@ NTSTATUS dup_file_fsp(struct smb_request *req, files_struct *from,
        return fsp_set_smb_fname(to, from->fsp_name);
 }
 
+/**
+ * Return a jenkins hash of a pathname on a connection.
+ */
+
+NTSTATUS file_name_hash(connection_struct *conn,
+                       const char *name, uint32_t *p_name_hash)
+{
+       TDB_DATA key;
+       char *fullpath = NULL;
+
+       /* Set the hash of the full pathname. */
+       fullpath = talloc_asprintf(talloc_tos(),
+                       "%s/%s",
+                       conn->connectpath,
+                       name);
+       if (!fullpath) {
+               return NT_STATUS_NO_MEMORY;
+       }
+       key = string_term_tdb_data(fullpath);
+       *p_name_hash = tdb_jenkins_hash(&key);
+
+       DEBUG(10,("file_name_hash: %s hash 0x%x\n",
+               fullpath,
+               (unsigned int)*p_name_hash ));
+
+       TALLOC_FREE(fullpath);
+       return NT_STATUS_OK;
+}
+
 /**
  * The only way that the fsp->fsp_name field should ever be set.
  */
@@ -607,5 +636,7 @@ NTSTATUS fsp_set_smb_fname(struct files_struct *fsp,
        TALLOC_FREE(fsp->fsp_name);
        fsp->fsp_name = smb_fname_new;
 
-       return NT_STATUS_OK;
+       return file_name_hash(fsp->conn,
+                       smb_fname_str_dbg(fsp->fsp_name),
+                       &fsp->name_hash);
 }