From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from lists.ozlabs.org (lists.ozlabs.org [112.213.38.117]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 6B181C433FE for ; Wed, 1 Dec 2021 17:58:38 +0000 (UTC) Received: from boromir.ozlabs.org (localhost [IPv6:::1]) by lists.ozlabs.org (Postfix) with ESMTP id 4J46Jr14S1z30RK for ; Thu, 2 Dec 2021 04:58:36 +1100 (AEDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=lists.ozlabs.org; s=201707; t=1638381516; bh=E5QiemI+WyyBIvLqZJnyJ1orWFc/xAWCenDyA+taZlE=; h=References:In-Reply-To:Date:Subject:To:List-Id:List-Unsubscribe: List-Archive:List-Post:List-Help:List-Subscribe:From:Reply-To:Cc: From; b=ox/cP+evwHKmJJNLgBdyYefaiLMMZp0PANEmo3GA65c7mXTSW4X3rxLBianZy7BE6 F69wXrlcOlSxlItK0vGR7umyWXenScp/YT8zSUo98ilPBgpR0eu6oSXC6LfXVOUeYN pAtUKA8twbHZNbR3fo7rRZwcn7ByjThtc4uICjKhVvs50Lb0xUcEEN1Le/FW2rL6Yb AdyAZvIw155VFOgFm6vkP/UPhTt+fzDc35lGqiMB/aU8axIERNQMuIswg2lJYXQPCA R2RritgBOgnBG5s1TV0wEFwhmsIrS+jLU6pjxH82ZsuPJK8yQ6hqscZu7RI8cdzjRb y50qaOtMDwCkw== Authentication-Results: lists.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=google.com (client-ip=2607:f8b0:4864:20::735; helo=mail-qk1-x735.google.com; envelope-from=zhangkelvin@google.com; receiver=) Authentication-Results: lists.ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=google.com header.i=@google.com header.a=rsa-sha256 header.s=20210112 header.b=V/HhH5Jl; dkim-atps=neutral Received: from mail-qk1-x735.google.com (mail-qk1-x735.google.com [IPv6:2607:f8b0:4864:20::735]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by lists.ozlabs.org (Postfix) with ESMTPS id 4J46Jh50J5z2x9K for ; Thu, 2 Dec 2021 04:58:26 +1100 (AEDT) Received: by mail-qk1-x735.google.com with SMTP id 132so31870775qkj.11 for ; Wed, 01 Dec 2021 09:58:26 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=E5QiemI+WyyBIvLqZJnyJ1orWFc/xAWCenDyA+taZlE=; b=fIXcMkBfBLrh5cnToSylBm+WQmulvn0i2ocKkPfwT2yzjHlcm79I1JexxNl+++UXQ8 rTq02gjwF1AdhVvEavK/AtuFJyKW8VtQ5B+ESdSrcl1h2w69l78uHl30rqFfgW0GXGg5 YW4s+02JONrtIlAip5Zjed8N1IQLKPZfkoAh7rIq+d2YxrbvgKtG3otM8QLS8mQkJaVg 4JgJ1z+RtkAe+nvrBrxJBM5eNTJdDYa2Re08YVAL0J9KKWD8E7LMC9gibJsddeUZ2/yS PO9DcwBb83ttNbzsbdfY1NeOOUI3I3EqLlK8AbW43GFRXptqKvV/NoMpeAD/RyjuO5Lg oDiA== X-Gm-Message-State: AOAM530KoQMPt38zCD7WPdS1LkVcfc0NCaq/Ilijdl28hBcUCDJKREHz zKvZrWO5DDNTPdqqN/f0Py5As9HgwiVBe25sLPVT9A== X-Google-Smtp-Source: ABdhPJwnw+YySMMcddbeYIiXcY4WVjCwbQuKgI6R5OMrgO7T6XYwz/+WK5AfmGb/OKm3rNW4ChZuKH5Qk82Pgg4XRcc= X-Received: by 2002:a37:670b:: with SMTP id b11mr7765893qkc.122.1638381500738; Wed, 01 Dec 2021 09:58:20 -0800 (PST) MIME-Version: 1.0 References: <20211201135315.3732-1-xiang@kernel.org> In-Reply-To: <20211201135315.3732-1-xiang@kernel.org> Date: Wed, 1 Dec 2021 09:58:09 -0800 Message-ID: Subject: Re: [PATCH] erofs-utils: make liberofs more C++ friendly To: Gao Xiang Content-Type: multipart/alternative; boundary="0000000000005c29c805d2196b19" X-BeenThere: linux-erofs@lists.ozlabs.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Development of Linux EROFS file system List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , From: Kelvin Zhang via Linux-erofs Reply-To: Kelvin Zhang Cc: linux-erofs@lists.ozlabs.org Errors-To: linux-erofs-bounces+linux-erofs=archiver.kernel.org@lists.ozlabs.org Sender: "Linux-erofs" --0000000000005c29c805d2196b19 Content-Type: text/plain; charset="UTF-8" This patch works for me, thanks! On Wed, Dec 1, 2021 at 5:53 AM Gao Xiang wrote: > From: Kelvin Zhang > > 1. Add extern "C" wrappers to headers, so that they can be included > from C++ > 2. Add const keywords to certain pointer type params > > Signed-off-by: Kelvin Zhang > Signed-off-by: Gao Xiang > --- > v3: > https://lore.kernel.org/r/20211130055604.2876828-2-zhangkelvin@google.com/ > Hi Kelvin, > > Please help check if this patch meets your requirement. > And I've applied to experimental branch. > > Thanks, > Gao Xiang > > include/erofs/blobchunk.h | 9 +++++++++ > include/erofs/block_list.h | 10 ++++++++++ > include/erofs/cache.h | 9 +++++++++ > include/erofs/compress.h | 9 +++++++++ > include/erofs/compress_hints.h | 10 ++++++++++ > include/erofs/config.h | 20 +++++++++----------- > include/erofs/decompress.h | 9 +++++++++ > include/erofs/defs.h | 17 ++++++++++++++++- > include/erofs/err.h | 9 +++++++++ > include/erofs/exclude.h | 10 ++++++++++ > include/erofs/flex-array.h | 9 +++++++++ > include/erofs/hashmap.h | 9 +++++++++ > include/erofs/hashtable.h | 9 +++++++++ > include/erofs/inode.h | 9 +++++++++ > include/erofs/internal.h | 9 +++++++++ > include/erofs/io.h | 11 +++++++++++ > include/erofs/list.h | 10 ++++++++++ > include/erofs/print.h | 9 +++++++++ > include/erofs/trace.h | 9 +++++++++ > include/erofs/xattr.h | 9 +++++++++ > lib/Makefile.am | 3 ++- > lib/config.c | 1 + > lib/inode.c | 1 + > lib/liberofs_private.h | 13 +++++++++++++ > lib/xattr.c | 1 + > 25 files changed, 211 insertions(+), 13 deletions(-) > create mode 100644 lib/liberofs_private.h > > diff --git a/include/erofs/blobchunk.h b/include/erofs/blobchunk.h > index 59a47013017f..4e1ae79938d6 100644 > --- a/include/erofs/blobchunk.h > +++ b/include/erofs/blobchunk.h > @@ -7,6 +7,11 @@ > #ifndef __EROFS_BLOBCHUNK_H > #define __EROFS_BLOBCHUNK_H > > +#ifdef __cplusplus > +extern "C" > +{ > +#endif > + > #include "erofs/internal.h" > > int erofs_blob_write_chunk_indexes(struct erofs_inode *inode, erofs_off_t > off); > @@ -16,4 +21,8 @@ void erofs_blob_exit(void); > int erofs_blob_init(const char *blobfile_path); > int erofs_generate_devtable(void); > > +#ifdef __cplusplus > +} > +#endif > + > #endif > diff --git a/include/erofs/block_list.h b/include/erofs/block_list.h > index 40df2282bf0c..ca8053ed28b7 100644 > --- a/include/erofs/block_list.h > +++ b/include/erofs/block_list.h > @@ -6,6 +6,11 @@ > #ifndef __EROFS_BLOCK_LIST_H > #define __EROFS_BLOCK_LIST_H > > +#ifdef __cplusplus > +extern "C" > +{ > +#endif > + > #include "internal.h" > > #ifdef WITH_ANDROID > @@ -29,4 +34,9 @@ erofs_droid_blocklist_write_extent(struct erofs_inode > *inode, > erofs_blk_t blk_start, erofs_blk_t > nblocks, > bool first_extent, bool last_extent) {} > #endif > + > +#ifdef __cplusplus > +} > +#endif > + > #endif > diff --git a/include/erofs/cache.h b/include/erofs/cache.h > index 87cd51d9473b..7957ee5d0b73 100644 > --- a/include/erofs/cache.h > +++ b/include/erofs/cache.h > @@ -8,6 +8,11 @@ > #ifndef __EROFS_CACHE_H > #define __EROFS_CACHE_H > > +#ifdef __cplusplus > +extern "C" > +{ > +#endif > + > #include "internal.h" > > struct erofs_buffer_head; > @@ -104,4 +109,8 @@ bool erofs_bflush(struct erofs_buffer_block *bb); > > void erofs_bdrop(struct erofs_buffer_head *bh, bool tryrevoke); > > +#ifdef __cplusplus > +} > +#endif > + > #endif > diff --git a/include/erofs/compress.h b/include/erofs/compress.h > index 4434aaa75b54..fdbf5ff66558 100644 > --- a/include/erofs/compress.h > +++ b/include/erofs/compress.h > @@ -7,6 +7,11 @@ > #ifndef __EROFS_COMPRESS_H > #define __EROFS_COMPRESS_H > > +#ifdef __cplusplus > +extern "C" > +{ > +#endif > + > #include "internal.h" > > /* workaround for an upstream lz4 compression issue, which can crash us */ > @@ -21,4 +26,8 @@ int z_erofs_compress_exit(void); > > const char *z_erofs_list_available_compressors(unsigned int i); > > +#ifdef __cplusplus > +} > +#endif > + > #endif > diff --git a/include/erofs/compress_hints.h > b/include/erofs/compress_hints.h > index a5772c72b1c4..43f80e117816 100644 > --- a/include/erofs/compress_hints.h > +++ b/include/erofs/compress_hints.h > @@ -6,6 +6,11 @@ > #ifndef __EROFS_COMPRESS_HINTS_H > #define __EROFS_COMPRESS_HINTS_H > > +#ifdef __cplusplus > +extern "C" > +{ > +#endif > + > #include "erofs/internal.h" > #include > #include > @@ -20,4 +25,9 @@ struct erofs_compress_hints { > bool z_erofs_apply_compress_hints(struct erofs_inode *inode); > void erofs_cleanup_compress_hints(void); > int erofs_load_compress_hints(void); > + > +#ifdef __cplusplus > +} > +#endif > + > #endif > diff --git a/include/erofs/config.h b/include/erofs/config.h > index 2040dc6ff154..cb064b651835 100644 > --- a/include/erofs/config.h > +++ b/include/erofs/config.h > @@ -7,20 +7,14 @@ > #ifndef __EROFS_CONFIG_H > #define __EROFS_CONFIG_H > > +#ifdef __cplusplus > +extern "C" > +{ > +#endif > + > #include "defs.h" > #include "err.h" > > -#ifdef HAVE_LIBSELINUX > -#include > -#include > -#endif > - > -#ifdef WITH_ANDROID > -#include > -#include > -#include > -#include > -#endif > > enum { > FORCE_INODE_COMPACT = 1, > @@ -96,4 +90,8 @@ static inline int erofs_selabel_open(const char > *file_contexts) > } > #endif > > +#ifdef __cplusplus > +} > +#endif > + > #endif > diff --git a/include/erofs/decompress.h b/include/erofs/decompress.h > index 3d0d9633865d..e649c80cf3a7 100644 > --- a/include/erofs/decompress.h > +++ b/include/erofs/decompress.h > @@ -6,6 +6,11 @@ > #ifndef __EROFS_DECOMPRESS_H > #define __EROFS_DECOMPRESS_H > > +#ifdef __cplusplus > +extern "C" > +{ > +#endif > + > #include "internal.h" > > struct z_erofs_decompress_req { > @@ -25,4 +30,8 @@ struct z_erofs_decompress_req { > > int z_erofs_decompress(struct z_erofs_decompress_req *rq); > > +#ifdef __cplusplus > +} > +#endif > + > #endif > diff --git a/include/erofs/defs.h b/include/erofs/defs.h > index 6398cbb2aa4d..4db237f4dfb0 100644 > --- a/include/erofs/defs.h > +++ b/include/erofs/defs.h > @@ -8,6 +8,11 @@ > #ifndef __EROFS_DEFS_H > #define __EROFS_DEFS_H > > +#ifdef __cplusplus > +extern "C" > +{ > +#endif > + > #include > #include > #include > @@ -82,7 +87,9 @@ typedef int64_t s64; > #endif > #endif > > -#ifndef __OPTIMIZE__ > +#ifdef __cplusplus > +#define BUILD_BUG_ON(condition) static_assert(!(condition)) > +#elif !defined(__OPTIMIZE__) > #define BUILD_BUG_ON(condition) ((void)sizeof(char[1 - 2 * > !!(condition)])) > #else > #define BUILD_BUG_ON(condition) assert(!(condition)) > @@ -110,6 +117,8 @@ typedef int64_t s64; > } \ > ) > > +/* Can easily conflict with C++'s std::min */ > +#ifndef __cplusplus > #define min(x, y) ({ \ > typeof(x) _min1 = (x); \ > typeof(y) _min2 = (y); \ > @@ -121,6 +130,7 @@ typedef int64_t s64; > typeof(y) _max2 = (y); \ > (void) (&_max1 == &_max2); \ > _max1 > _max2 ? _max1 : _max2; }) > +#endif > > /* > * ..and if you can't take the strict types, you can specify one yourself. > @@ -308,4 +318,9 @@ unsigned long __roundup_pow_of_two(unsigned long n) > #define stat64 stat > #define lstat64 lstat > #endif > + > +#ifdef __cplusplus > +} > +#endif > + > #endif > diff --git a/include/erofs/err.h b/include/erofs/err.h > index a33bdd137879..18f152aa4608 100644 > --- a/include/erofs/err.h > +++ b/include/erofs/err.h > @@ -7,6 +7,11 @@ > #ifndef __EROFS_ERR_H > #define __EROFS_ERR_H > > +#ifdef __cplusplus > +extern "C" > +{ > +#endif > + > #include > > #define MAX_ERRNO (4095) > @@ -28,4 +33,8 @@ static inline long PTR_ERR(const void *ptr) > return (long) ptr; > } > > +#ifdef __cplusplus > +} > +#endif > + > #endif > diff --git a/include/erofs/exclude.h b/include/erofs/exclude.h > index 6930f2b43a47..599f01895807 100644 > --- a/include/erofs/exclude.h > +++ b/include/erofs/exclude.h > @@ -5,6 +5,11 @@ > #ifndef __EROFS_EXCLUDE_H > #define __EROFS_EXCLUDE_H > > +#ifdef __cplusplus > +extern "C" > +{ > +#endif > + > #include > #include > > @@ -21,4 +26,9 @@ void erofs_cleanup_exclude_rules(void); > int erofs_parse_exclude_path(const char *args, bool is_regex); > struct erofs_exclude_rule *erofs_is_exclude_path(const char *dir, > const char *name); > + > +#ifdef __cplusplus > +} > +#endif > + > #endif > diff --git a/include/erofs/flex-array.h b/include/erofs/flex-array.h > index 59168d05ee5a..9b1642f77740 100644 > --- a/include/erofs/flex-array.h > +++ b/include/erofs/flex-array.h > @@ -2,6 +2,11 @@ > #ifndef __EROFS_FLEX_ARRAY_H > #define __EROFS_FLEX_ARRAY_H > > +#ifdef __cplusplus > +extern "C" > +{ > +#endif > + > #include > #include > #include > @@ -144,4 +149,8 @@ static inline size_t st_add(size_t a, size_t b) > #define FLEXPTR_ALLOC_STR(x, ptrname, str) \ > FLEXPTR_ALLOC_MEM((x), ptrname, (str), strlen(str)) > > +#ifdef __cplusplus > +} > +#endif > + > #endif > diff --git a/include/erofs/hashmap.h b/include/erofs/hashmap.h > index 024a14e497d4..3d3857890077 100644 > --- a/include/erofs/hashmap.h > +++ b/include/erofs/hashmap.h > @@ -2,6 +2,11 @@ > #ifndef __EROFS_HASHMAP_H > #define __EROFS_HASHMAP_H > > +#ifdef __cplusplus > +extern "C" > +{ > +#endif > + > /* Copied from https://github.com/git/git.git */ > #include > #include > @@ -100,4 +105,8 @@ static inline const char *strintern(const char *string) > return memintern(string, strlen(string)); > } > > +#ifdef __cplusplus > +} > +#endif > + > #endif > diff --git a/include/erofs/hashtable.h b/include/erofs/hashtable.h > index 90eb84ee8598..3c4dfc128eaa 100644 > --- a/include/erofs/hashtable.h > +++ b/include/erofs/hashtable.h > @@ -5,6 +5,11 @@ > #ifndef __EROFS_HASHTABLE_H > #define __EROFS_HASHTABLE_H > > +#ifdef __cplusplus > +extern "C" > +{ > +#endif > + > /* > * Fast hashing routine for ints, longs and pointers. > * (C) 2002 Nadia Yvette Chambers, IBM > @@ -380,4 +385,8 @@ static inline void hash_del(struct hlist_node *node) > #define hash_for_each_possible(name, obj, member, key) \ > hlist_for_each_entry(obj, &name[hash_min(key, HASH_BITS(name))], > member) > > +#ifdef __cplusplus > +} > +#endif > + > #endif > diff --git a/include/erofs/inode.h b/include/erofs/inode.h > index d5343c242aee..e23d65f42249 100644 > --- a/include/erofs/inode.h > +++ b/include/erofs/inode.h > @@ -8,6 +8,11 @@ > #ifndef __EROFS_INODE_H > #define __EROFS_INODE_H > > +#ifdef __cplusplus > +extern "C" > +{ > +#endif > + > #include "erofs/internal.h" > > unsigned char erofs_mode_to_ftype(umode_t mode); > @@ -17,4 +22,8 @@ erofs_nid_t erofs_lookupnid(struct erofs_inode *inode); > struct erofs_inode *erofs_mkfs_build_tree_from_path(struct erofs_inode > *parent, > const char *path); > > +#ifdef __cplusplus > +} > +#endif > + > #endif > diff --git a/include/erofs/internal.h b/include/erofs/internal.h > index 666d1f2df466..a68de325da39 100644 > --- a/include/erofs/internal.h > +++ b/include/erofs/internal.h > @@ -7,6 +7,11 @@ > #ifndef __EROFS_INTERNAL_H > #define __EROFS_INTERNAL_H > > +#ifdef __cplusplus > +extern "C" > +{ > +#endif > + > #include "list.h" > #include "err.h" > > @@ -331,4 +336,8 @@ static inline u32 erofs_crc32c(u32 crc, const u8 *in, > size_t len) > return crc; > } > > +#ifdef __cplusplus > +} > +#endif > + > #endif > diff --git a/include/erofs/io.h b/include/erofs/io.h > index 10a3681882e1..6f51e06ee7c2 100644 > --- a/include/erofs/io.h > +++ b/include/erofs/io.h > @@ -7,7 +7,14 @@ > #ifndef __EROFS_IO_H > #define __EROFS_IO_H > > +#ifdef __cplusplus > +extern "C" > +{ > +#endif > + > +#ifndef _GNU_SOURCE > #define _GNU_SOURCE > +#endif > #include > #include "internal.h" > > @@ -47,4 +54,8 @@ static inline int blk_read(int device_id, void *buf, > blknr_to_addr(nblocks)); > } > > +#ifdef __cplusplus > +} > #endif > + > +#endif // EROFS_IO_H_ > diff --git a/include/erofs/list.h b/include/erofs/list.h > index d2bc704ae64b..fd5358d6bd19 100644 > --- a/include/erofs/list.h > +++ b/include/erofs/list.h > @@ -7,6 +7,11 @@ > #ifndef __EROFS_LIST_HEAD_H > #define __EROFS_LIST_HEAD_H > > +#ifdef __cplusplus > +extern "C" > +{ > +#endif > + > #include "defs.h" > > struct list_head { > @@ -105,4 +110,9 @@ static inline int list_empty(struct list_head *head) > &pos->member != (head); > \ > pos = n, n = list_next_entry(n, member)) > > + > +#ifdef __cplusplus > +} > +#endif > + > #endif > diff --git a/include/erofs/print.h b/include/erofs/print.h > index 91f864bacd55..2213d1d58de5 100644 > --- a/include/erofs/print.h > +++ b/include/erofs/print.h > @@ -7,6 +7,11 @@ > #ifndef __EROFS_PRINT_H > #define __EROFS_PRINT_H > > +#ifdef __cplusplus > +extern "C" > +{ > +#endif > + > #include "config.h" > #include > > @@ -72,4 +77,8 @@ enum { > > #define erofs_dump(fmt, ...) fprintf(stderr, fmt, ##__VA_ARGS__) > > +#ifdef __cplusplus > +} > +#endif > + > #endif > diff --git a/include/erofs/trace.h b/include/erofs/trace.h > index d70d23674c1a..893e16c5d6c1 100644 > --- a/include/erofs/trace.h > +++ b/include/erofs/trace.h > @@ -5,7 +5,16 @@ > #ifndef __EROFS_TRACE_H > #define __EROFS_TRACE_H > > +#ifdef __cplusplus > +extern "C" > +{ > +#endif > + > #define trace_erofs_map_blocks_flatmode_enter(inode, map, flags) ((void)0) > #define trace_erofs_map_blocks_flatmode_exit(inode, map, flags, ret) > ((void)0) > > +#ifdef __cplusplus > +} > +#endif > + > #endif > diff --git a/include/erofs/xattr.h b/include/erofs/xattr.h > index f0c4c268fecc..8e6881247f42 100644 > --- a/include/erofs/xattr.h > +++ b/include/erofs/xattr.h > @@ -7,6 +7,11 @@ > #ifndef __EROFS_XATTR_H > #define __EROFS_XATTR_H > > +#ifdef __cplusplus > +extern "C" > +{ > +#endif > + > #include "internal.h" > > #define EROFS_INODE_XATTR_ICOUNT(_size) ({\ > @@ -44,4 +49,8 @@ int erofs_prepare_xattr_ibody(struct erofs_inode *inode); > char *erofs_export_xattr_ibody(struct list_head *ixattrs, unsigned int > size); > int erofs_build_shared_xattrs_from_path(const char *path); > > +#ifdef __cplusplus > +} > +#endif > + > #endif > diff --git a/lib/Makefile.am b/lib/Makefile.am > index 395c712811b8..67ba798672b9 100644 > --- a/lib/Makefile.am > +++ b/lib/Makefile.am > @@ -21,7 +21,8 @@ noinst_HEADERS = $(top_srcdir)/include/erofs_fs.h \ > $(top_srcdir)/include/erofs/print.h \ > $(top_srcdir)/include/erofs/trace.h \ > $(top_srcdir)/include/erofs/xattr.h \ > - $(top_srcdir)/include/erofs/compress_hints.h > + $(top_srcdir)/include/erofs/compress_hints.h \ > + $(top_srcdir)/lib/liberofs_private.h > > noinst_HEADERS += compressor.h > liberofs_la_SOURCES = config.c io.c cache.c super.c inode.c xattr.c > exclude.c \ > diff --git a/lib/config.c b/lib/config.c > index 363dcc5a0525..f1c8edfda2dc 100644 > --- a/lib/config.c > +++ b/lib/config.c > @@ -8,6 +8,7 @@ > #include > #include "erofs/print.h" > #include "erofs/internal.h" > +#include "liberofs_private.h" > > struct erofs_configure cfg; > struct erofs_sb_info sbi; > diff --git a/lib/inode.c b/lib/inode.c > index 2fa74e2686c9..461c7978dbdf 100644 > --- a/lib/inode.c > +++ b/lib/inode.c > @@ -25,6 +25,7 @@ > #include "erofs/block_list.h" > #include "erofs/compress_hints.h" > #include "erofs/blobchunk.h" > +#include "liberofs_private.h" > > #define S_SHIFT 12 > static unsigned char erofs_ftype_by_mode[S_IFMT >> S_SHIFT] = { > diff --git a/lib/liberofs_private.h b/lib/liberofs_private.h > new file mode 100644 > index 000000000000..c2312e8e7a31 > --- /dev/null > +++ b/lib/liberofs_private.h > @@ -0,0 +1,13 @@ > +/* SPDX-License-Identifier: GPL-2.0-only OR Apache-2.0 */ > + > +#ifdef HAVE_LIBSELINUX > +#include > +#include > +#endif > + > +#ifdef WITH_ANDROID > +#include > +#include > +#include > +#include > +#endif > diff --git a/lib/xattr.c b/lib/xattr.c > index 196133a1a798..00fb963c68ef 100644 > --- a/lib/xattr.c > +++ b/lib/xattr.c > @@ -17,6 +17,7 @@ > #include "erofs/xattr.h" > #include "erofs/cache.h" > #include "erofs/io.h" > +#include "liberofs_private.h" > > #define EA_HASHTABLE_BITS 16 > > -- > 2.20.1 > > -- Sincerely, Kelvin Zhang --0000000000005c29c805d2196b19 Content-Type: text/html; charset="UTF-8" Content-Transfer-Encoding: quoted-printable
This patch works for me, thanks!

On Wed, Dec 1, 2021 at 5:5= 3 AM Gao Xiang <xiang@kernel.org= > wrote:
From= : Kelvin Zhang <zhangkelvin@google.com>

1. Add extern "C" wrappers to headers, so that they can be includ= ed
=C2=A0 =C2=A0from C++
2. Add const keywords to certain pointer type params

Signed-off-by: Kelvin Zhang <zhangkelvin@google.com>
Signed-off-by: Gao Xiang <xiang@kernel.org>
---
v3: https://lore.kernel.or= g/r/20211130055604.2876828-2-zhangkelvin@google.com/
Hi Kelvin,

Please help check if this patch meets your requirement.
And I've applied to experimental branch.

Thanks,
Gao Xiang

=C2=A0include/erofs/blobchunk.h=C2=A0 =C2=A0 =C2=A0 |=C2=A0 9 +++++++++
=C2=A0include/erofs/block_list.h=C2=A0 =C2=A0 =C2=A0| 10 ++++++++++
=C2=A0include/erofs/cache.h=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 |=C2=A0 9 +++= ++++++
=C2=A0include/erofs/compress.h=C2=A0 =C2=A0 =C2=A0 =C2=A0|=C2=A0 9 ++++++++= +
=C2=A0include/erofs/compress_hints.h | 10 ++++++++++
=C2=A0include/erofs/config.h=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0| 20 ++++++++= +-----------
=C2=A0include/erofs/decompress.h=C2=A0 =C2=A0 =C2=A0|=C2=A0 9 +++++++++
=C2=A0include/erofs/defs.h=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0| 17 +++= +++++++++++++-
=C2=A0include/erofs/err.h=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 |=C2=A0 = 9 +++++++++
=C2=A0include/erofs/exclude.h=C2=A0 =C2=A0 =C2=A0 =C2=A0 | 10 ++++++++++ =C2=A0include/erofs/flex-array.h=C2=A0 =C2=A0 =C2=A0|=C2=A0 9 +++++++++
=C2=A0include/erofs/hashmap.h=C2=A0 =C2=A0 =C2=A0 =C2=A0 |=C2=A0 9 ++++++++= +
=C2=A0include/erofs/hashtable.h=C2=A0 =C2=A0 =C2=A0 |=C2=A0 9 +++++++++
=C2=A0include/erofs/inode.h=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 |=C2=A0 9 +++= ++++++
=C2=A0include/erofs/internal.h=C2=A0 =C2=A0 =C2=A0 =C2=A0|=C2=A0 9 ++++++++= +
=C2=A0include/erofs/io.h=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0| 1= 1 +++++++++++
=C2=A0include/erofs/list.h=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0| 10 +++= +++++++
=C2=A0include/erofs/print.h=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 |=C2=A0 9 +++= ++++++
=C2=A0include/erofs/trace.h=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 |=C2=A0 9 +++= ++++++
=C2=A0include/erofs/xattr.h=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 |=C2=A0 9 +++= ++++++
=C2=A0lib/Makefile.am=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2= =A0 |=C2=A0 3 ++-
=C2=A0lib/config.c=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 = =C2=A0 =C2=A0|=C2=A0 1 +
=C2=A0lib/inode.c=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 = =C2=A0 =C2=A0 |=C2=A0 1 +
=C2=A0lib/liberofs_private.h=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0| 13 ++++++++= +++++
=C2=A0lib/xattr.c=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 = =C2=A0 =C2=A0 |=C2=A0 1 +
=C2=A025 files changed, 211 insertions(+), 13 deletions(-)
=C2=A0create mode 100644 lib/liberofs_private.h

diff --git a/include/erofs/blobchunk.h b/include/erofs/blobchunk.h
index 59a47013017f..4e1ae79938d6 100644
--- a/include/erofs/blobchunk.h
+++ b/include/erofs/blobchunk.h
@@ -7,6 +7,11 @@
=C2=A0#ifndef __EROFS_BLOBCHUNK_H
=C2=A0#define __EROFS_BLOBCHUNK_H

+#ifdef __cplusplus
+extern "C"
+{
+#endif
+
=C2=A0#include "erofs/internal.h"

=C2=A0int erofs_blob_write_chunk_indexes(struct erofs_inode *inode, erofs_o= ff_t off);
@@ -16,4 +21,8 @@ void erofs_blob_exit(void);
=C2=A0int erofs_blob_init(const char *blobfile_path);
=C2=A0int erofs_generate_devtable(void);

+#ifdef __cplusplus
+}
+#endif
+
=C2=A0#endif
diff --git a/include/erofs/block_list.h b/include/erofs/block_list.h
index 40df2282bf0c..ca8053ed28b7 100644
--- a/include/erofs/block_list.h
+++ b/include/erofs/block_list.h
@@ -6,6 +6,11 @@
=C2=A0#ifndef __EROFS_BLOCK_LIST_H
=C2=A0#define __EROFS_BLOCK_LIST_H

+#ifdef __cplusplus
+extern "C"
+{
+#endif
+
=C2=A0#include "internal.h"

=C2=A0#ifdef WITH_ANDROID
@@ -29,4 +34,9 @@ erofs_droid_blocklist_write_extent(struct erofs_inode *in= ode,
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2= =A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0erofs_blk_t blk_start, = erofs_blk_t nblocks,
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2= =A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0bool first_extent, bool= last_extent) {}
=C2=A0#endif
+
+#ifdef __cplusplus
+}
+#endif
+
=C2=A0#endif
diff --git a/include/erofs/cache.h b/include/erofs/cache.h
index 87cd51d9473b..7957ee5d0b73 100644
--- a/include/erofs/cache.h
+++ b/include/erofs/cache.h
@@ -8,6 +8,11 @@
=C2=A0#ifndef __EROFS_CACHE_H
=C2=A0#define __EROFS_CACHE_H

+#ifdef __cplusplus
+extern "C"
+{
+#endif
+
=C2=A0#include "internal.h"

=C2=A0struct erofs_buffer_head;
@@ -104,4 +109,8 @@ bool erofs_bflush(struct erofs_buffer_block *bb);

=C2=A0void erofs_bdrop(struct erofs_buffer_head *bh, bool tryrevoke);

+#ifdef __cplusplus
+}
+#endif
+
=C2=A0#endif
diff --git a/include/erofs/compress.h b/include/erofs/compress.h
index 4434aaa75b54..fdbf5ff66558 100644
--- a/include/erofs/compress.h
+++ b/include/erofs/compress.h
@@ -7,6 +7,11 @@
=C2=A0#ifndef __EROFS_COMPRESS_H
=C2=A0#define __EROFS_COMPRESS_H

+#ifdef __cplusplus
+extern "C"
+{
+#endif
+
=C2=A0#include "internal.h"

=C2=A0/* workaround for an upstream lz4 compression issue, which can crash = us */
@@ -21,4 +26,8 @@ int z_erofs_compress_exit(void);

=C2=A0const char *z_erofs_list_available_compressors(unsigned int i);

+#ifdef __cplusplus
+}
+#endif
+
=C2=A0#endif
diff --git a/include/erofs/compress_hints.h b/include/erofs/compress_hints.= h
index a5772c72b1c4..43f80e117816 100644
--- a/include/erofs/compress_hints.h
+++ b/include/erofs/compress_hints.h
@@ -6,6 +6,11 @@
=C2=A0#ifndef __EROFS_COMPRESS_HINTS_H
=C2=A0#define __EROFS_COMPRESS_HINTS_H

+#ifdef __cplusplus
+extern "C"
+{
+#endif
+
=C2=A0#include "erofs/internal.h"
=C2=A0#include <sys/types.h>
=C2=A0#include <regex.h>
@@ -20,4 +25,9 @@ struct erofs_compress_hints {
=C2=A0bool z_erofs_apply_compress_hints(struct erofs_inode *inode);
=C2=A0void erofs_cleanup_compress_hints(void);
=C2=A0int erofs_load_compress_hints(void);
+
+#ifdef __cplusplus
+}
+#endif
+
=C2=A0#endif
diff --git a/include/erofs/config.h b/include/erofs/config.h
index 2040dc6ff154..cb064b651835 100644
--- a/include/erofs/config.h
+++ b/include/erofs/config.h
@@ -7,20 +7,14 @@
=C2=A0#ifndef __EROFS_CONFIG_H
=C2=A0#define __EROFS_CONFIG_H

+#ifdef __cplusplus
+extern "C"
+{
+#endif
+
=C2=A0#include "defs.h"
=C2=A0#include "err.h"

-#ifdef HAVE_LIBSELINUX
-#include <selinux/selinux.h>
-#include <selinux/label.h>
-#endif
-
-#ifdef WITH_ANDROID
-#include <selinux/android.h>
-#include <private/android_filesystem_config.h>
-#include <private/canned_fs_config.h>
-#include <private/fs_config.h>
-#endif

=C2=A0enum {
=C2=A0 =C2=A0 =C2=A0 =C2=A0 FORCE_INODE_COMPACT =3D 1,
@@ -96,4 +90,8 @@ static inline int erofs_selabel_open(const char *file_con= texts)
=C2=A0}
=C2=A0#endif

+#ifdef __cplusplus
+}
+#endif
+
=C2=A0#endif
diff --git a/include/erofs/decompress.h b/include/erofs/decompress.h
index 3d0d9633865d..e649c80cf3a7 100644
--- a/include/erofs/decompress.h
+++ b/include/erofs/decompress.h
@@ -6,6 +6,11 @@
=C2=A0#ifndef __EROFS_DECOMPRESS_H
=C2=A0#define __EROFS_DECOMPRESS_H

+#ifdef __cplusplus
+extern "C"
+{
+#endif
+
=C2=A0#include "internal.h"

=C2=A0struct z_erofs_decompress_req {
@@ -25,4 +30,8 @@ struct z_erofs_decompress_req {

=C2=A0int z_erofs_decompress(struct z_erofs_decompress_req *rq);

+#ifdef __cplusplus
+}
+#endif
+
=C2=A0#endif
diff --git a/include/erofs/defs.h b/include/erofs/defs.h
index 6398cbb2aa4d..4db237f4dfb0 100644
--- a/include/erofs/defs.h
+++ b/include/erofs/defs.h
@@ -8,6 +8,11 @@
=C2=A0#ifndef __EROFS_DEFS_H
=C2=A0#define __EROFS_DEFS_H

+#ifdef __cplusplus
+extern "C"
+{
+#endif
+
=C2=A0#include <stddef.h>
=C2=A0#include <stdint.h>
=C2=A0#include <assert.h>
@@ -82,7 +87,9 @@ typedef int64_t=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0s64;
=C2=A0#endif
=C2=A0#endif

-#ifndef __OPTIMIZE__
+#ifdef __cplusplus
+#define BUILD_BUG_ON(condition) static_assert(!(condition))
+#elif !defined(__OPTIMIZE__)
=C2=A0#define BUILD_BUG_ON(condition) ((void)sizeof(char[1 - 2 * !!(conditi= on)]))
=C2=A0#else
=C2=A0#define BUILD_BUG_ON(condition) assert(!(condition))
@@ -110,6 +117,8 @@ typedef int64_t=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0s64; =C2=A0}=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2= =A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 = =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 \
=C2=A0)

+/* Can easily conflict with C++'s std::min */
+#ifndef __cplusplus
=C2=A0#define min(x, y) ({=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 = =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0\
=C2=A0 =C2=A0 =C2=A0 =C2=A0 typeof(x) _min1 =3D (x);=C2=A0 =C2=A0 =C2=A0 = =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 \
=C2=A0 =C2=A0 =C2=A0 =C2=A0 typeof(y) _min2 =3D (y);=C2=A0 =C2=A0 =C2=A0 = =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 \
@@ -121,6 +130,7 @@ typedef int64_t=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0s64; =C2=A0 =C2=A0 =C2=A0 =C2=A0 typeof(y) _max2 =3D (y);=C2=A0 =C2=A0 =C2=A0 = =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 \
=C2=A0 =C2=A0 =C2=A0 =C2=A0 (void) (&_max1 =3D=3D &_max2);=C2=A0 = =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 \
=C2=A0 =C2=A0 =C2=A0 =C2=A0 _max1 > _max2 ? _max1 : _max2; })
+#endif

=C2=A0/*
=C2=A0 * ..and if you can't take the strict types, you can specify one = yourself.
@@ -308,4 +318,9 @@ unsigned long __roundup_pow_of_two(unsigned long n)
=C2=A0#define stat64=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0stat
=C2=A0#define lstat64=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2= =A0 lstat
=C2=A0#endif
+
+#ifdef __cplusplus
+}
+#endif
+
=C2=A0#endif
diff --git a/include/erofs/err.h b/include/erofs/err.h
index a33bdd137879..18f152aa4608 100644
--- a/include/erofs/err.h
+++ b/include/erofs/err.h
@@ -7,6 +7,11 @@
=C2=A0#ifndef __EROFS_ERR_H
=C2=A0#define __EROFS_ERR_H

+#ifdef __cplusplus
+extern "C"
+{
+#endif
+
=C2=A0#include <errno.h>

=C2=A0#define MAX_ERRNO (4095)
@@ -28,4 +33,8 @@ static inline long PTR_ERR(const void *ptr)
=C2=A0 =C2=A0 =C2=A0 =C2=A0 return (long) ptr;
=C2=A0}

+#ifdef __cplusplus
+}
+#endif
+
=C2=A0#endif
diff --git a/include/erofs/exclude.h b/include/erofs/exclude.h
index 6930f2b43a47..599f01895807 100644
--- a/include/erofs/exclude.h
+++ b/include/erofs/exclude.h
@@ -5,6 +5,11 @@
=C2=A0#ifndef __EROFS_EXCLUDE_H
=C2=A0#define __EROFS_EXCLUDE_H

+#ifdef __cplusplus
+extern "C"
+{
+#endif
+
=C2=A0#include <sys/types.h>
=C2=A0#include <regex.h>

@@ -21,4 +26,9 @@ void erofs_cleanup_exclude_rules(void);
=C2=A0int erofs_parse_exclude_path(const char *args, bool is_regex);
=C2=A0struct erofs_exclude_rule *erofs_is_exclude_path(const char *dir,
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2= =A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 = =C2=A0 =C2=A0 =C2=A0 =C2=A0const char *name);
+
+#ifdef __cplusplus
+}
+#endif
+
=C2=A0#endif
diff --git a/include/erofs/flex-array.h b/include/erofs/flex-array.h
index 59168d05ee5a..9b1642f77740 100644
--- a/include/erofs/flex-array.h
+++ b/include/erofs/flex-array.h
@@ -2,6 +2,11 @@
=C2=A0#ifndef __EROFS_FLEX_ARRAY_H
=C2=A0#define __EROFS_FLEX_ARRAY_H

+#ifdef __cplusplus
+extern "C"
+{
+#endif
+
=C2=A0#include <stdio.h>
=C2=A0#include <stdlib.h>
=C2=A0#include <limits.h>
@@ -144,4 +149,8 @@ static inline size_t st_add(size_t a, size_t b)
=C2=A0#define FLEXPTR_ALLOC_STR(x, ptrname, str) \
=C2=A0 =C2=A0 =C2=A0 =C2=A0 FLEXPTR_ALLOC_MEM((x), ptrname, (str), strlen(s= tr))

+#ifdef __cplusplus
+}
+#endif
+
=C2=A0#endif
diff --git a/include/erofs/hashmap.h b/include/erofs/hashmap.h
index 024a14e497d4..3d3857890077 100644
--- a/include/erofs/hashmap.h
+++ b/include/erofs/hashmap.h
@@ -2,6 +2,11 @@
=C2=A0#ifndef __EROFS_HASHMAP_H
=C2=A0#define __EROFS_HASHMAP_H

+#ifdef __cplusplus
+extern "C"
+{
+#endif
+
=C2=A0/* Copied from https://github.com/git/git.git */
=C2=A0#include <stdio.h>
=C2=A0#include <stdlib.h>
@@ -100,4 +105,8 @@ static inline const char *strintern(const char *string)=
=C2=A0 =C2=A0 =C2=A0 =C2=A0 return memintern(string, strlen(string));
=C2=A0}

+#ifdef __cplusplus
+}
+#endif
+
=C2=A0#endif
diff --git a/include/erofs/hashtable.h b/include/erofs/hashtable.h
index 90eb84ee8598..3c4dfc128eaa 100644
--- a/include/erofs/hashtable.h
+++ b/include/erofs/hashtable.h
@@ -5,6 +5,11 @@
=C2=A0#ifndef __EROFS_HASHTABLE_H
=C2=A0#define __EROFS_HASHTABLE_H

+#ifdef __cplusplus
+extern "C"
+{
+#endif
+
=C2=A0/*
=C2=A0 * Fast hashing routine for ints,=C2=A0 longs and pointers.
=C2=A0 * (C) 2002 Nadia Yvette Chambers, IBM
@@ -380,4 +385,8 @@ static inline void hash_del(struct hlist_node *node) =C2=A0#define hash_for_each_possible(name, obj, member, key)=C2=A0 =C2=A0 = =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0\
=C2=A0 =C2=A0 =C2=A0 =C2=A0 hlist_for_each_entry(obj, &name[hash_min(ke= y, HASH_BITS(name))], member)

+#ifdef __cplusplus
+}
+#endif
+
=C2=A0#endif
diff --git a/include/erofs/inode.h b/include/erofs/inode.h
index d5343c242aee..e23d65f42249 100644
--- a/include/erofs/inode.h
+++ b/include/erofs/inode.h
@@ -8,6 +8,11 @@
=C2=A0#ifndef __EROFS_INODE_H
=C2=A0#define __EROFS_INODE_H

+#ifdef __cplusplus
+extern "C"
+{
+#endif
+
=C2=A0#include "erofs/internal.h"

=C2=A0unsigned char erofs_mode_to_ftype(umode_t mode);
@@ -17,4 +22,8 @@ erofs_nid_t erofs_lookupnid(struct erofs_inode *inode); =C2=A0struct erofs_inode *erofs_mkfs_build_tree_from_path(struct erofs_inod= e *parent,
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2= =A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 = =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 const char *path);

+#ifdef __cplusplus
+}
+#endif
+
=C2=A0#endif
diff --git a/include/erofs/internal.h b/include/erofs/internal.h
index 666d1f2df466..a68de325da39 100644
--- a/include/erofs/internal.h
+++ b/include/erofs/internal.h
@@ -7,6 +7,11 @@
=C2=A0#ifndef __EROFS_INTERNAL_H
=C2=A0#define __EROFS_INTERNAL_H

+#ifdef __cplusplus
+extern "C"
+{
+#endif
+
=C2=A0#include "list.h"
=C2=A0#include "err.h"

@@ -331,4 +336,8 @@ static inline u32 erofs_crc32c(u32 crc, const u8 *in, s= ize_t len)
=C2=A0 =C2=A0 =C2=A0 =C2=A0 return crc;
=C2=A0}

+#ifdef __cplusplus
+}
+#endif
+
=C2=A0#endif
diff --git a/include/erofs/io.h b/include/erofs/io.h
index 10a3681882e1..6f51e06ee7c2 100644
--- a/include/erofs/io.h
+++ b/include/erofs/io.h
@@ -7,7 +7,14 @@
=C2=A0#ifndef __EROFS_IO_H
=C2=A0#define __EROFS_IO_H

+#ifdef __cplusplus
+extern "C"
+{
+#endif
+
+#ifndef _GNU_SOURCE
=C2=A0#define _GNU_SOURCE
+#endif
=C2=A0#include <unistd.h>
=C2=A0#include "internal.h"

@@ -47,4 +54,8 @@ static inline int blk_read(int device_id, void *buf,
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2= =A0 =C2=A0 =C2=A0blknr_to_addr(nblocks));
=C2=A0}

+#ifdef __cplusplus
+}
=C2=A0#endif
+
+#endif // EROFS_IO_H_
diff --git a/include/erofs/list.h b/include/erofs/list.h
index d2bc704ae64b..fd5358d6bd19 100644
--- a/include/erofs/list.h
+++ b/include/erofs/list.h
@@ -7,6 +7,11 @@
=C2=A0#ifndef __EROFS_LIST_HEAD_H
=C2=A0#define __EROFS_LIST_HEAD_H

+#ifdef __cplusplus
+extern "C"
+{
+#endif
+
=C2=A0#include "defs.h"

=C2=A0struct list_head {
@@ -105,4 +110,9 @@ static inline int list_empty(struct list_head *head) =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0&pos->member !=3D (h= ead);=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 = =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2= =A0 =C2=A0\
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0pos =3D n, n =3D list_next_= entry(n, member))

+
+#ifdef __cplusplus
+}
+#endif
+
=C2=A0#endif
diff --git a/include/erofs/print.h b/include/erofs/print.h
index 91f864bacd55..2213d1d58de5 100644
--- a/include/erofs/print.h
+++ b/include/erofs/print.h
@@ -7,6 +7,11 @@
=C2=A0#ifndef __EROFS_PRINT_H
=C2=A0#define __EROFS_PRINT_H

+#ifdef __cplusplus
+extern "C"
+{
+#endif
+
=C2=A0#include "config.h"
=C2=A0#include <stdio.h>

@@ -72,4 +77,8 @@ enum {

=C2=A0#define erofs_dump(fmt, ...) fprintf(stderr, fmt, ##__VA_ARGS__)

+#ifdef __cplusplus
+}
+#endif
+
=C2=A0#endif
diff --git a/include/erofs/trace.h b/include/erofs/trace.h
index d70d23674c1a..893e16c5d6c1 100644
--- a/include/erofs/trace.h
+++ b/include/erofs/trace.h
@@ -5,7 +5,16 @@
=C2=A0#ifndef __EROFS_TRACE_H
=C2=A0#define __EROFS_TRACE_H

+#ifdef __cplusplus
+extern "C"
+{
+#endif
+
=C2=A0#define trace_erofs_map_blocks_flatmode_enter(inode, map, flags) ((vo= id)0)
=C2=A0#define trace_erofs_map_blocks_flatmode_exit(inode, map, flags, ret) = ((void)0)

+#ifdef __cplusplus
+}
+#endif
+
=C2=A0#endif
diff --git a/include/erofs/xattr.h b/include/erofs/xattr.h
index f0c4c268fecc..8e6881247f42 100644
--- a/include/erofs/xattr.h
+++ b/include/erofs/xattr.h
@@ -7,6 +7,11 @@
=C2=A0#ifndef __EROFS_XATTR_H
=C2=A0#define __EROFS_XATTR_H

+#ifdef __cplusplus
+extern "C"
+{
+#endif
+
=C2=A0#include "internal.h"

=C2=A0#define EROFS_INODE_XATTR_ICOUNT(_size)=C2=A0 =C2=A0 =C2=A0 =C2=A0 ({= \
@@ -44,4 +49,8 @@ int erofs_prepare_xattr_ibody(struct erofs_inode *inode);=
=C2=A0char *erofs_export_xattr_ibody(struct list_head *ixattrs, unsigned in= t size);
=C2=A0int erofs_build_shared_xattrs_from_path(const char *path);

+#ifdef __cplusplus
+}
+#endif
+
=C2=A0#endif
diff --git a/lib/Makefile.am b/lib/Makefile.am
index 395c712811b8..67ba798672b9 100644
--- a/lib/Makefile.am
+++ b/lib/Makefile.am
@@ -21,7 +21,8 @@ noinst_HEADERS =3D $(top_srcdir)/include/erofs_fs.h \
=C2=A0 =C2=A0 =C2=A0 =C2=A0$(top_srcdir)/include/erofs/print.h \
=C2=A0 =C2=A0 =C2=A0 =C2=A0$(top_srcdir)/include/erofs/trace.h \
=C2=A0 =C2=A0 =C2=A0 =C2=A0$(top_srcdir)/include/erofs/xattr.h \
-=C2=A0 =C2=A0 =C2=A0 $(top_srcdir)/include/erofs/compress_hints.h
+=C2=A0 =C2=A0 =C2=A0 $(top_srcdir)/include/erofs/compress_hints.h \
+=C2=A0 =C2=A0 =C2=A0 $(top_srcdir)/lib/liberofs_private.h

=C2=A0noinst_HEADERS +=3D compressor.h
=C2=A0liberofs_la_SOURCES =3D config.c io.c cache.c super.c inode.c xattr.c= exclude.c \
diff --git a/lib/config.c b/lib/config.c
index 363dcc5a0525..f1c8edfda2dc 100644
--- a/lib/config.c
+++ b/lib/config.c
@@ -8,6 +8,7 @@
=C2=A0#include <stdlib.h>
=C2=A0#include "erofs/print.h"
=C2=A0#include "erofs/internal.h"
+#include "liberofs_private.h"

=C2=A0struct erofs_configure cfg;
=C2=A0struct erofs_sb_info sbi;
diff --git a/lib/inode.c b/lib/inode.c
index 2fa74e2686c9..461c7978dbdf 100644
--- a/lib/inode.c
+++ b/lib/inode.c
@@ -25,6 +25,7 @@
=C2=A0#include "erofs/block_list.h"
=C2=A0#include "erofs/compress_hints.h"
=C2=A0#include "erofs/blobchunk.h"
+#include "liberofs_private.h"

=C2=A0#define S_SHIFT=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2= =A0 =C2=A012
=C2=A0static unsigned char erofs_ftype_by_mode[S_IFMT >> S_SHIFT] =3D= {
diff --git a/lib/liberofs_private.h b/lib/liberofs_private.h
new file mode 100644
index 000000000000..c2312e8e7a31
--- /dev/null
+++ b/lib/liberofs_private.h
@@ -0,0 +1,13 @@
+/* SPDX-License-Identifier: GPL-2.0-only OR Apache-2.0 */
+
+#ifdef HAVE_LIBSELINUX
+#include <selinux/selinux.h>
+#include <selinux/label.h>
+#endif
+
+#ifdef WITH_ANDROID
+#include <selinux/android.h>
+#include <private/android_filesystem_config.h>
+#include <private/canned_fs_config.h>
+#include <private/fs_config.h>
+#endif
diff --git a/lib/xattr.c b/lib/xattr.c
index 196133a1a798..00fb963c68ef 100644
--- a/lib/xattr.c
+++ b/lib/xattr.c
@@ -17,6 +17,7 @@
=C2=A0#include "erofs/xattr.h"
=C2=A0#include "erofs/cache.h"
=C2=A0#include "erofs/io.h"
+#include "liberofs_private.h"

=C2=A0#define EA_HASHTABLE_BITS 16

--
2.20.1



--
Sincerely,

K= elvin Zhang
--0000000000005c29c805d2196b19--