From: Ralph Boehme Date: Tue, 25 Jun 2019 12:13:28 +0000 (+0200) Subject: s3/lib: add make_file_index_from_itime() X-Git-Tag: ldb-2.0.5~108 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=a5a2ce953bbfff72ab66f24604c347259321f266;p=thirdparty%2Fsamba.git s3/lib: add make_file_index_from_itime() Signed-off-by: Ralph Boehme Reviewed-by: Jeremy Allison --- diff --git a/source3/lib/file_id.c b/source3/lib/file_id.c index f8295ce738a..7d4fb006afe 100644 --- a/source3/lib/file_id.c +++ b/source3/lib/file_id.c @@ -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; +} diff --git a/source3/lib/file_id.h b/source3/lib/file_id.h index 6fa98400b85..509e924c1fe 100644 --- a/source3/lib/file_id.h +++ b/source3/lib/file_id.h @@ -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);