From: Gao Xiang Date: Sun, 14 Jul 2024 04:41:19 +0000 (+0800) Subject: erofs-utils: lib: tar: fix garbage ns timestamps X-Git-Tag: v1.8~19 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=617d708925b3c5d1dd132853e47d9d9f51443e6f;p=platform%2Fupstream%2Ferofs-utils.git erofs-utils: lib: tar: fix garbage ns timestamps Some "#if" directives were used incorrectly. Fixes: 95d315fd7958 ("erofs-utils: introduce tarerofs") Signed-off-by: Gao Xiang Link: https://lore.kernel.org/r/20240714044119.1119717-1-hsiangkao@linux.alibaba.com --- diff --git a/include/erofs/defs.h b/include/erofs/defs.h index 310a6ab..e462338 100644 --- a/include/erofs/defs.h +++ b/include/erofs/defs.h @@ -332,15 +332,18 @@ unsigned long __roundup_pow_of_two(unsigned long n) #define ST_ATIM_NSEC(stbuf) ((stbuf)->st_atim.tv_nsec) #define ST_CTIM_NSEC(stbuf) ((stbuf)->st_ctim.tv_nsec) #define ST_MTIM_NSEC(stbuf) ((stbuf)->st_mtim.tv_nsec) +#define ST_MTIM_NSEC_SET(stbuf, val) (stbuf)->st_mtim.tv_nsec = (val) #elif defined(HAVE_STRUCT_STAT_ST_ATIMENSEC) /* macOS */ #define ST_ATIM_NSEC(stbuf) ((stbuf)->st_atimensec) #define ST_CTIM_NSEC(stbuf) ((stbuf)->st_ctimensec) #define ST_MTIM_NSEC(stbuf) ((stbuf)->st_mtimensec) +#define ST_MTIM_NSEC_SET(stbuf, val) (stbuf)->st_mtimensec = (val) #else #define ST_ATIM_NSEC(stbuf) 0 #define ST_CTIM_NSEC(stbuf) 0 #define ST_MTIM_NSEC(stbuf) 0 +#define ST_MTIM_NSEC_SET(stbuf, val) do { } while (0) #endif #define __erofs_likely(x) __builtin_expect(!!(x), 1) diff --git a/lib/tar.c b/lib/tar.c index cefda37..a9b425e 100644 --- a/lib/tar.c +++ b/lib/tar.c @@ -490,9 +490,9 @@ int tarerofs_parse_pax_header(struct erofs_iostream *ios, ret = -EIO; goto out; } -#if ST_MTIM_NSEC - ST_MTIM_NSEC(&eh->st) = n; -#endif + ST_MTIM_NSEC_SET(&eh->st, n); + } else { + ST_MTIM_NSEC_SET(&eh->st, 0); } eh->use_mtime = true; } else if (!strncmp(kv, "size=", @@ -733,13 +733,12 @@ restart: if (eh.use_mtime) { st.st_mtime = eh.st.st_mtime; -#if ST_MTIM_NSEC - ST_MTIM_NSEC(&st) = ST_MTIM_NSEC(&eh.st); -#endif + ST_MTIM_NSEC_SET(&st, ST_MTIM_NSEC(&eh.st)); } else { st.st_mtime = tarerofs_parsenum(th->mtime, sizeof(th->mtime)); if (errno) goto invalid_tar; + ST_MTIM_NSEC_SET(&st, 0); } if (th->typeflag <= '7' && !eh.path) {