erofs-utils: improve compatibility and reduce header conflicts
authorHongzhen Luo <hongzhen@linux.alibaba.com>
Mon, 24 Jun 2024 06:32:17 +0000 (14:32 +0800)
committerGao Xiang <hsiangkao@linux.alibaba.com>
Mon, 24 Jun 2024 13:16:20 +0000 (21:16 +0800)
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 <hongzhen@linux.alibaba.com>
Link: https://lore.kernel.org/r/20240624063217.170251-1-hongzhen@linux.alibaba.com
[ Gao Xiang: minor commit message update. ]
Signed-off-by: Gao Xiang <hsiangkao@linux.alibaba.com>
include/erofs/defs.h
include/erofs/internal.h
include/erofs_fs.h
lib/compress.c
lib/inode.c
lib/io.c
lib/kite_deflate.c
lib/tar.c

index 5b620549c84dc33e7f1aebc45a6eeb6ae1fabe71..e0798c841ce08c53943a4286b1b71e90d775483b 100644 (file)
@@ -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
 }
index f61a45349fb6cd83df4153a782e222984f92ef06..61250d1cefbd550a95af2ce3c5827b5661080891 100644 (file)
@@ -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))
index 907f3d867c6bf5cc6712e647fcdccb1c417d7006..0d603c4872ea4416ac6953b265b7f336c759d2d6 100644 (file)
@@ -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 <<Z_EROFS_FRAGMENT_INODE_BIT,
+               },
        };
 
        BUILD_BUG_ON(sizeof(struct erofs_super_block) != 128);
index c9fd5b658e27dd904042d1cdc4bf38584ea544a0..b47358752f20262e592518a50aac9df058f7ef5a 100644 (file)
@@ -1197,7 +1197,7 @@ int z_erofs_mt_wq_tls_init_compr(struct erofs_sb_info *sbi,
        struct erofs_compress_cfg *lc = &tls->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,
index aa14e5c38cff713765681247bce37681ec9543ca..703dc63fc92b77152bffe9b3e3bbde96238f8967 100644 (file)
@@ -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;
 }
index aa8d77b1623282b3e26d65bdd67f2ba0850935b3..91673213fc94fa20835e822f24db4dd89c858f32 100644 (file)
--- 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)
index 570bc5a6d6b625b730199c01ebe5e6bfe4dbadf7..a5ebd661010aea1d9ca39461ca1946b80fb953dd 100644 (file)
@@ -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]));
        }
index 532e5669782fa3f25e2fdbb8f03577f4de34d08e..5e2c5b82a9173a34e3358ce02527da78a986900a 100644 (file)
--- 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)