s3:smbd: add a fsp_persistent_id() function
authorStefan Metzmacher <metze@samba.org>
Thu, 14 Jun 2012 08:32:43 +0000 (10:32 +0200)
committerKarolin Seeger <kseeger@samba.org>
Sun, 17 Jun 2012 19:01:26 +0000 (21:01 +0200)
This calculates a 64-bit value that most likely uniquely identifies
the files_struct globally to the server.

* 32-bit random gen_id
* 16-bit truncated open_time
* 16-bit fnum (valatile_id)

Based on code from Ira Cooper. Use fsp->fh->gen_id as the persistent
fileid in SMB2.

Pair-Programmed-With: Michael Adam <obnox@samba.org>

metze

Signed-off-by: Jeremy Allison <jra@samba.org>
source3/smbd/files.c
source3/smbd/proto.h

index 0018ceed5e51cf0b45afa3606b5a78c9146704c6..1031ccfecba2dd06199f414bac2704c02f0d6205 100644 (file)
@@ -566,6 +566,30 @@ files_struct *file_fsp(struct smb_request *req, uint16 fid)
        return fsp;
 }
 
+uint64_t fsp_persistent_id(const struct files_struct *fsp)
+{
+       uint64_t persistent_id;
+
+       /*
+        * This calculates a number that is most likely
+        * globally unique. In future we will have a database
+        * to make it completely unique.
+        *
+        * 32-bit random gen_id
+        * 16-bit truncated open_time
+        * 16-bit fnum (valatile_id)
+        */
+       persistent_id = fsp->fh->gen_id & UINT32_MAX;
+       persistent_id <<= 16;
+       persistent_id &= 0x0000FFFFFFFF0000LLU;
+       persistent_id |= fsp->open_time.tv_usec & UINT16_MAX;
+       persistent_id <<= 16;
+       persistent_id &= 0xFFFFFFFFFFFF0000LLU;
+       persistent_id |= fsp->fnum & UINT16_MAX;
+
+       return persistent_id;
+}
+
 struct files_struct *file_fsp_smb2(struct smbd_smb2_request *smb2req,
                                   uint64_t persistent_id,
                                   uint64_t volatile_id)
index 929387b21939636e48740a85557a19676e87bc52..d75138b117b703c325f50c778e4cd57aaa628a32 100644 (file)
@@ -373,6 +373,7 @@ bool file_find_subpath(files_struct *dir_fsp);
 void file_sync_all(connection_struct *conn);
 void file_free(struct smb_request *req, files_struct *fsp);
 files_struct *file_fsp(struct smb_request *req, uint16 fid);
+uint64_t fsp_persistent_id(const struct files_struct *fsp);
 struct files_struct *file_fsp_smb2(struct smbd_smb2_request *smb2req,
                                   uint64_t persistent_id,
                                   uint64_t volatile_id);