From: Hongzhen Luo Date: Mon, 24 Jun 2024 06:32:17 +0000 (+0800) Subject: erofs-utils: improve compatibility and reduce header conflicts X-Git-Tag: v1.8~33 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=79f6e168d94cf2c7ebc46ebf97b13be663bcd270;p=platform%2Fupstream%2Ferofs-utils.git erofs-utils: improve compatibility and reduce header conflicts Adjust initializers of union in erofs-utils to ensure compatibility with various compilers. The original C99 designated initializer style was not supported in other compilers (e.g., C++11), leading to build failures. Additionally, change the codebase to minimize potential conflicts with headers from other projects. Signed-off-by: Hongzhen Luo Link: https://lore.kernel.org/r/20240624063217.170251-1-hongzhen@linux.alibaba.com [ Gao Xiang: minor commit message update. ] Signed-off-by: Gao Xiang --- diff --git a/include/erofs/defs.h b/include/erofs/defs.h index 5b62054..e0798c8 100644 --- a/include/erofs/defs.h +++ b/include/erofs/defs.h @@ -343,8 +343,8 @@ unsigned long __roundup_pow_of_two(unsigned long n) #define ST_MTIM_NSEC(stbuf) 0 #endif -#define likely(x) __builtin_expect(!!(x), 1) -#define unlikely(x) __builtin_expect(!!(x), 0) +#define __erofs_likely(x) __builtin_expect(!!(x), 1) +#define __erofs_unlikely(x) __builtin_expect(!!(x), 0) #ifdef __cplusplus } diff --git a/include/erofs/internal.h b/include/erofs/internal.h index f61a453..61250d1 100644 --- a/include/erofs/internal.h +++ b/include/erofs/internal.h @@ -301,7 +301,7 @@ static inline unsigned int erofs_inode_datalayout(unsigned int value) static inline struct erofs_inode *erofs_parent_inode(struct erofs_inode *inode) { - return (void *)((unsigned long)inode->i_parent & ~1UL); + return (struct erofs_inode *)((unsigned long)inode->i_parent & ~1UL); } #define IS_ROOT(x) ((x) == erofs_parent_inode(x)) diff --git a/include/erofs_fs.h b/include/erofs_fs.h index 907f3d8..0d603c4 100644 --- a/include/erofs_fs.h +++ b/include/erofs_fs.h @@ -454,7 +454,9 @@ static inline void erofs_check_ondisk_layout_definitions(void) struct z_erofs_map_header h; __le64 v; } fmh __maybe_unused = { - .h.h_clusterbits = 1 << Z_EROFS_FRAGMENT_INODE_BIT, + .h = { + .h_clusterbits = 1 <ccfg[alg_id]; int ret; - if (likely(lc->enable)) + if (__erofs_likely(lc->enable)) return 0; ret = erofs_compressor_init(sbi, &lc->handle, alg_name, diff --git a/lib/inode.c b/lib/inode.c index aa14e5c..703dc63 100644 --- a/lib/inode.c +++ b/lib/inode.c @@ -323,7 +323,7 @@ erofs_nid_t erofs_lookupnid(struct erofs_inode *inode) erofs_dbg("Assign nid %llu to file %s (mode %05o)", inode->nid, inode->i_srcpath, inode->i_mode); } - if (unlikely(IS_ROOT(inode)) && inode->nid > 0xffff) + if (__erofs_unlikely(IS_ROOT(inode)) && inode->nid > 0xffff) return sbi->root_nid; return inode->nid; } diff --git a/lib/io.c b/lib/io.c index aa8d77b..9167321 100644 --- a/lib/io.c +++ b/lib/io.c @@ -28,7 +28,7 @@ int erofs_io_fstat(struct erofs_vfile *vf, struct stat *buf) { - if (unlikely(cfg.c_dry_run)) { + if (__erofs_unlikely(cfg.c_dry_run)) { buf->st_size = 0; buf->st_mode = S_IFREG | 0777; return 0; @@ -44,7 +44,7 @@ ssize_t erofs_io_pwrite(struct erofs_vfile *vf, const void *buf, { ssize_t ret, written = 0; - if (unlikely(cfg.c_dry_run)) + if (__erofs_unlikely(cfg.c_dry_run)) return 0; if (vf->ops) @@ -78,7 +78,7 @@ int erofs_io_fsync(struct erofs_vfile *vf) { int ret; - if (unlikely(cfg.c_dry_run)) + if (__erofs_unlikely(cfg.c_dry_run)) return 0; if (vf->ops) @@ -98,7 +98,7 @@ ssize_t erofs_io_fallocate(struct erofs_vfile *vf, u64 offset, static const char zero[EROFS_MAX_BLOCK_SIZE] = {0}; ssize_t ret; - if (unlikely(cfg.c_dry_run)) + if (__erofs_unlikely(cfg.c_dry_run)) return 0; if (vf->ops) @@ -124,7 +124,7 @@ int erofs_io_ftruncate(struct erofs_vfile *vf, u64 length) int ret; struct stat st; - if (unlikely(cfg.c_dry_run)) + if (__erofs_unlikely(cfg.c_dry_run)) return 0; if (vf->ops) @@ -145,7 +145,7 @@ ssize_t erofs_io_pread(struct erofs_vfile *vf, void *buf, u64 pos, size_t len) { ssize_t ret, read = 0; - if (unlikely(cfg.c_dry_run)) + if (__erofs_unlikely(cfg.c_dry_run)) return 0; if (vf->ops) diff --git a/lib/kite_deflate.c b/lib/kite_deflate.c index 570bc5a..a5ebd66 100644 --- a/lib/kite_deflate.c +++ b/lib/kite_deflate.c @@ -866,7 +866,7 @@ static void kite_mf_reset(struct kite_matchfinder *mf, * * [1] https://github.com/tukaani-project/xz/blob/v5.4.0/src/liblzma/lz/lz_encoder_mf.c#L94 */ - if (unlikely(mf->base > ((typeof(mf->base))-1) >> 1)) { + if (__erofs_unlikely(mf->base > ((typeof(mf->base))-1) >> 1)) { mf->base = kHistorySize32 + 1; memset(mf->hash, 0, 0x10000 * sizeof(mf->hash[0])); } diff --git a/lib/tar.c b/lib/tar.c index 532e566..5e2c5b8 100644 --- a/lib/tar.c +++ b/lib/tar.c @@ -202,7 +202,7 @@ int erofs_iostream_read(struct erofs_iostream *ios, void **buf, u64 bytes) if (ret < ios->bufsize - rabytes) ios->feof = true; } - if (unlikely(ios->dumpfd >= 0)) + if (__erofs_unlikely(ios->dumpfd >= 0)) if (write(ios->dumpfd, ios->buffer + rabytes, ret) < ret) erofs_err("failed to dump %d bytes of the raw stream: %s", ret, erofs_strerror(-errno)); @@ -246,7 +246,7 @@ int erofs_iostream_lskip(struct erofs_iostream *ios, u64 sz) if (ios->feof) return sz; - if (ios->sz && likely(ios->dumpfd < 0)) { + if (ios->sz && __erofs_likely(ios->dumpfd < 0)) { s64 cur = erofs_io_lseek(&ios->vf, sz, SEEK_CUR); if (cur > ios->sz)