]> git.ipfire.org Git - thirdparty/samba.git/commitdiff
s3/lib: add make_file_index_from_itime()
authorRalph Boehme <slow@samba.org>
Tue, 25 Jun 2019 12:13:28 +0000 (14:13 +0200)
committerJeremy Allison <jra@samba.org>
Mon, 1 Jul 2019 21:43:24 +0000 (21:43 +0000)
Signed-off-by: Ralph Boehme <slow@samba.org>
Reviewed-by: Jeremy Allison <jra@samba.org>
source3/lib/file_id.c
source3/lib/file_id.h

index f8295ce738a8dda3f73536cc8354352611429370..7d4fb006afec805ca37a50efca60b2b2ae618cc1 100644 (file)
@@ -90,3 +90,37 @@ void pull_file_id_24(const char *buf, struct file_id *id)
        id->extid  = IVAL(buf,  16);
        id->extid |= ((uint64_t)IVAL(buf,20))<<32;
 }
+
+uint64_t make_file_id_from_itime(SMB_STRUCT_STAT *st)
+{
+       struct timespec itime = st->st_ex_itime;
+       ino_t ino = st->st_ex_ino;
+       uint64_t file_id_low;
+       uint64_t file_id;
+
+       if (st->st_ex_iflags & ST_EX_IFLAG_CALCULATED_ITIME) {
+               return ino;
+       }
+
+       file_id_low = itime.tv_nsec;
+       if (file_id_low == 0) {
+               /*
+                * This could be by coincidence, but more likely the filesystem
+                * is only giving us seconds granularity. We need more fine
+                * grained granularity for the File-ID, so combine with the
+                * inode number.
+                */
+               file_id_low = ino & ((1 << 30) - 1);
+       }
+
+       /*
+        * Set the high bit so ideally File-IDs based on inode numbers and
+        * File-IDs based on Birth Time use disjoint ranges, given inodes never
+        * have the high bit set.
+        */
+       file_id = ((uint64_t)1) << 63;
+       file_id |= (uint64_t)itime.tv_sec << 30;
+       file_id |= file_id_low;
+
+       return file_id;
+}
index 6fa98400b85a6546f60f6714776e5ac668e0124a..509e924c1fe341afccdcd25d6a6e0e40f2fe1de8 100644 (file)
@@ -35,3 +35,8 @@ const char *file_id_string(TALLOC_CTX *mem_ctx, const struct file_id *id);
 void push_file_id_16(char *buf, const struct file_id *id);
 void push_file_id_24(char *buf, const struct file_id *id);
 void pull_file_id_24(const char *buf, struct file_id *id);
+
+/*
+ * Make a SMB File-ID from itime
+ */
+uint64_t make_file_id_from_itime(SMB_STRUCT_STAT *st);