Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 25 additions & 5 deletions etc/afpd/spotlight.c
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,14 @@

#define MAX_SL_RESULTS 20

struct timeval convert_timespec_to_timeval(const struct timespec ts)
{
struct timeval tv;
tv.tv_sec = ts.tv_sec;
tv.tv_usec = ts.tv_nsec / 1000;
return tv;
}

struct slq_state_names {
slq_state_t state;
const char *state_name;
Expand Down Expand Up @@ -346,7 +354,8 @@ static bool add_filemeta(sl_array_t *reqinfo,

for (i = 0; i < metacount; i++) {
if (strequal(reqinfo->dd_talloc_array[i], "kMDItemDisplayName")
|| strequal(reqinfo->dd_talloc_array[i], "kMDItemFSName")) {
|| strequal(reqinfo->dd_talloc_array[i], "kMDItemFSName")
|| strequal(reqinfo->dd_talloc_array[i], "_kMDItemFileName")) {
if ((p = strrchr(path, '/'))) {
name = dalloc_strdup(meta, p + 1);
dalloc_add(meta, name, "char *");
Expand All @@ -355,8 +364,8 @@ static bool add_filemeta(sl_array_t *reqinfo,
"kMDItemPath")) {
name = dalloc_strdup(meta, path);
dalloc_add(meta, name, "char *");
} else if (strequal(reqinfo->dd_talloc_array[i],
"kMDItemFSSize")) {
} else if (strequal(reqinfo->dd_talloc_array[i], "kMDItemFSSize")
|| strequal(reqinfo->dd_talloc_array[i], "kMDItemLogicalSize")) {
uint64var = sp->st_size;
dalloc_add_copy(meta, &uint64var, uint64_t);
} else if (strequal(reqinfo->dd_talloc_array[i],
Expand All @@ -369,7 +378,11 @@ static bool add_filemeta(sl_array_t *reqinfo,
dalloc_add_copy(meta, &uint64var, uint64_t);
} else if (strequal(reqinfo->dd_talloc_array[i],
"kMDItemFSContentChangeDate")) {
sl_time.tv_sec = sp->st_mtime;
sl_time = convert_timespec_to_timeval(sp->st_mtim);
dalloc_add_copy(meta, &sl_time, sl_time_t);
} else if (strequal(reqinfo->dd_talloc_array[i],
"kMDItemLastUsedDate")) {
sl_time = convert_timespec_to_timeval(sp->st_atim);
dalloc_add_copy(meta, &sl_time, sl_time_t);
} else {
dalloc_add_copy(meta, &nil, sl_nil_t);
Expand Down Expand Up @@ -1090,7 +1103,14 @@ static int sl_rpc_storeAttributesForOIDArray(const AFPObj *obj,
utimes.actime = utimes.modtime = sl_time->tv_sec;
utime(path, &utimes);
}

else if ((sl_time = dalloc_value_for_key(query, "DALLOC_CTX", 0, "DALLOC_CTX", 1,
"DALLOC_CTX", 1,
"kMDItemLastUsedDate", "sl_time_t"))) {
struct utimbuf atimes;
atimes.actime = sl_time->tv_sec;
utime(path, &atimes);
}

array = talloc_zero(reply, sl_array_t);
uint64_t sl_res = 0;
dalloc_add_copy(array, &sl_res, uint64_t);
Expand Down
28 changes: 22 additions & 6 deletions etc/afpd/spotlight_marshalling.c
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,8 @@
* RPC data marshalling and unmarshalling
**************************************************************************************************/

/*! Spotlight epoch is UNIX epoch minus SPOTLIGHT_TIME_DELTA */
#define SPOTLIGHT_TIME_DELTA INT64_C(280878921600U)
/* 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
Expand Down Expand Up @@ -199,7 +199,13 @@ static int sl_pack_date(sl_time_t t, char *buf, int offset)
{
EC_INIT;
uint64_t data = 0;
data = (t.tv_sec + SPOTLIGHT_TIME_DELTA) << 24;
union {
double d;
uint64_t w;
} ieee_fp_union;
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;
EC_ZERO(slvalc(buf, offset, MAX_SLQ_DAT, sl_pack_tag(SQ_TYPE_DATE, 2, 1)));
EC_ZERO(slvalc(buf, offset + 8, MAX_SLQ_DAT, data));
EC_CLEANUP:
Expand Down Expand Up @@ -482,16 +488,26 @@ static int sl_unpack_date(DALLOC_CTX *query, const char *buf, int offset,
{
int count, i;
uint64_t query_data64;
union {
double d;
uint64_t w;
} ieee_fp_union;
double fraction;
sl_time_t t;
query_data64 = sl_unpack_uint64(buf, offset, encoding);
count = query_data64 >> 32;
offset += 8;
i = 0;

while (i++ < count) {
query_data64 = sl_unpack_uint64(buf, offset, encoding) >> 24;
t.tv_sec = query_data64 - SPOTLIGHT_TIME_DELTA;
t.tv_usec = 0;
query_data64 = sl_unpack_uint64(buf, offset, encoding);
ieee_fp_union.w = query_data64;
Comment thread
NJRoadfan marked this conversation as resolved.
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
};
dalloc_add_copy(query, &t, sl_time_t);
offset += 8;
}
Expand Down