From d10051437558f581bee350620848cf98e7e3915f Mon Sep 17 00:00:00 2001 From: Ralph Boehme Date: Wed, 17 May 2023 16:37:36 +0200 Subject: [PATCH 1/3] mdssvc: prepare for returning timestamps with sub-seconds granularity BUG: https://bugzilla.samba.org/show_bug.cgi?id=15427 Signed-off-by: Ralph Boehme Reviewed-by: Jeremy Allison (cherry picked from commit 9dc66fecf7c1743d264c5c4f8978b77bab75ed86) --- source3/rpc_server/mdssvc/mdssvc.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/source3/rpc_server/mdssvc/mdssvc.c b/source3/rpc_server/mdssvc/mdssvc.c index c394a180b1ac..7a8cbcf3588e 100644 --- a/source3/rpc_server/mdssvc/mdssvc.c +++ b/source3/rpc_server/mdssvc/mdssvc.c @@ -189,7 +189,7 @@ static bool add_filemeta(struct mds_ctx *mds_ctx, return false; } } else if (strcmp(attribute, "kMDItemFSContentChangeDate") == 0) { - sl_time.tv_sec = sp->st_ex_mtime.tv_sec; + sl_time = convert_timespec_to_timeval(sp->st_ex_mtime); result = dalloc_add_copy(meta, &sl_time, sl_time_t); if (result != 0) { return false; -- 2.41.0 From 442807b3fc2c801a190d50dcf0f3e90535f76b77 Mon Sep 17 00:00:00 2001 From: Ralph Boehme Date: Wed, 17 May 2023 16:38:39 +0200 Subject: [PATCH 2/3] mdssvc: fix date marshalling Did this ever work? Possible just copied over from Netatalk and was always broken... The Mac client expects the timevalue as seconds relative to 2001-01-01 00:00:00 UTC, packed as IEEE float. BUG: https://bugzilla.samba.org/show_bug.cgi?id=15427 Signed-off-by: Ralph Boehme Reviewed-by: Jeremy Allison (cherry picked from commit 620ca1e68d02be45a94aa41217a141d211fceb1f) --- source3/rpc_server/mdssvc/marshalling.c | 29 ++++++++++++++++++++----- 1 file changed, 23 insertions(+), 6 deletions(-) diff --git a/source3/rpc_server/mdssvc/marshalling.c b/source3/rpc_server/mdssvc/marshalling.c index 5f866d7fb6ea..b3e16d9c18f2 100644 --- a/source3/rpc_server/mdssvc/marshalling.c +++ b/source3/rpc_server/mdssvc/marshalling.c @@ -43,8 +43,8 @@ * RPC data marshalling and unmarshalling ******************************************************************************/ -/* Spotlight epoch is UNIX epoch minus SPOTLIGHT_TIME_DELTA */ -#define SPOTLIGHT_TIME_DELTA 280878921600ULL +/* Spotlight epoch is 1.1.2001 00:00 UTC */ +#define SPOTLIGHT_TIME_DELTA 978307200 /* Diff from UNIX epoch to Spotlight epoch */ #define SQ_TYPE_NULL 0x0000 #define SQ_TYPE_COMPLEX 0x0200 @@ -253,6 +253,10 @@ static ssize_t sl_pack_date(sl_time_t t, char *buf, ssize_t offset, size_t bufsi { uint64_t data; uint64_t tag; + union { + double d; + uint64_t w; + } ieee_fp_union; tag = sl_pack_tag(SQ_TYPE_DATE, 2, 1); offset = sl_push_uint64_val(buf, offset, bufsize, tag); @@ -260,7 +264,10 @@ static ssize_t sl_pack_date(sl_time_t t, char *buf, ssize_t offset, size_t bufsi return -1; } - data = (t.tv_sec + SPOTLIGHT_TIME_DELTA) << 24; + ieee_fp_union.d = (double)(t.tv_sec - SPOTLIGHT_TIME_DELTA); + ieee_fp_union.d += (double)t.tv_usec / 1000000; + + data = ieee_fp_union.w; offset = sl_push_uint64_val(buf, offset, bufsize, data); if (offset == -1) { return -1; @@ -723,6 +730,11 @@ static int sl_unpack_date(DALLOC_CTX *query, int i, result; struct sl_tag tag; uint64_t query_data64; + union { + double d; + uint64_t w; + } ieee_fp_union; + double fraction; sl_time_t t; offset = sl_unpack_tag(buf, offset, bufsize, encoding, &tag); @@ -735,9 +747,14 @@ static int sl_unpack_date(DALLOC_CTX *query, if (offset == -1) { return -1; } - query_data64 = query_data64 >> 24; - t.tv_sec = query_data64 - SPOTLIGHT_TIME_DELTA; - t.tv_usec = 0; + ieee_fp_union.w = query_data64; + fraction = ieee_fp_union.d - (uint64_t)ieee_fp_union.d; + + t = (sl_time_t) { + .tv_sec = ieee_fp_union.d + SPOTLIGHT_TIME_DELTA, + .tv_usec = fraction * 1000000 + }; + result = dalloc_add_copy(query, &t, sl_time_t); if (result != 0) { return -1; -- 2.41.0 From 6c081e55338ad97e4e6d0868c584cb405d29ac02 Mon Sep 17 00:00:00 2001 From: Ralph Boehme Date: Thu, 18 May 2023 18:12:19 +0200 Subject: [PATCH 3/3] mdssvc: fix returning file modification date for older Mac releases Mac 10.10 uses kMDItemContentModificationDate instead of kMDItemFSContentChangeDate. BUG: https://bugzilla.samba.org/show_bug.cgi?id=15427 Signed-off-by: Ralph Boehme Reviewed-by: Jeremy Allison Autobuild-User(master): Jeremy Allison Autobuild-Date(master): Wed Jul 26 23:42:44 UTC 2023 on atb-devel-224 (cherry picked from commit c2e83ebe726b7bc42b329198214c784936f19888) --- source3/rpc_server/mdssvc/mdssvc.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/source3/rpc_server/mdssvc/mdssvc.c b/source3/rpc_server/mdssvc/mdssvc.c index 7a8cbcf3588e..a7d5d7afc029 100644 --- a/source3/rpc_server/mdssvc/mdssvc.c +++ b/source3/rpc_server/mdssvc/mdssvc.c @@ -188,7 +188,9 @@ static bool add_filemeta(struct mds_ctx *mds_ctx, if (result != 0) { return false; } - } else if (strcmp(attribute, "kMDItemFSContentChangeDate") == 0) { + } else if (strcmp(attribute, "kMDItemFSContentChangeDate") == 0 || + strcmp(attribute, "kMDItemContentModificationDate") == 0) + { sl_time = convert_timespec_to_timeval(sp->st_ex_mtime); result = dalloc_add_copy(meta, &sl_time, sl_time_t); if (result != 0) { -- 2.41.0