Cosmetic changes to erofs-utils
cover Cosmetic changes to erofs-utils
The following patches make erofs-utils more C++ friendly. It does not perform any refactoring, instead it simply added extern "C" keywords so that C++ code can call into EROFS.
Kelvin Zhang (2):
Add android build target to build erofs as library Make erofs-utils more C++ friendly
Android.bp | 38 +++++++++++++++++++++++++++++++--- include/erofs/blobchunk.h | 10 +++++++++ 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 | 20 ++++++++++++++++++ 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 ++++++++ include/erofs_fs.h | 9 ++++++++ lib/config.c | 12 +++++++++++ lib/inode.c | 7 +++++++ lib/xattr.c | 12 +++++++++++ mkfs/main.c | 7 +++++++ 26 files changed, 280 insertions(+), 14 deletions(-)
Signature · 1 line
2.34.0.rc2.393.gf8c9666880-goog
PATCH 1/2 Add android build target to build erofs as library
--- Android.bp | 38 ++++++++++++++++++++++++++++++++++++-- include/erofs/defs.h | 5 +++++ 2 files changed, 41 insertions(+), 2 deletions(-)
Android.bp +36 -2
@@ -52,7 +52,7 @@ genrule { } cc_defaults { - name: "erofs-utils_defaults", + name: "erofs-utils_export_defaults", cflags: [ "-Wall",
@@ -60,7 +60,7 @@ cc_defaults { "-Wno-ignored-qualifiers", "-Wno-pointer-arith", "-Wno-unused-parameter", - "-include erofs-utils-version.h", + "-Wno-unused-function", "-DHAVE_FALLOCATE", "-DHAVE_LINUX_TYPES_H", "-DHAVE_LIBSELINUX",
@@ -69,6 +69,15 @@ cc_defaults { "-DLZ4HC_ENABLED", "-DWITH_ANDROID", ], +} + +cc_defaults { + name: "erofs-utils_defaults", + defaults: ["erofs-utils_export_defaults"], + + cflags: [ + "-include erofs-utils-version.h", + ], local_include_dirs: [ "include", ],
@@ -86,6 +95,22 @@ cc_defaults { ], } +cc_library { + host_supported: true, + name: "liberofs", + defaults: ["erofs-utils_defaults"], + srcs: [ + "lib/*.c", + ], + export_include_dirs: ["include"], + + target: { + darwin: { + enabled: false, + }, + }, +} + cc_defaults { name: "mkfs-erofs_defaults",
@@ -95,6 +120,9 @@ cc_defaults { "lib/*.c", "mkfs/*.c", ], + static_libs: [ + "liberofs", + ], target: { darwin: {
@@ -122,6 +150,9 @@ cc_binary_host { "lib/*.c", "dump/*.c", ], + static_libs: [ + "liberofs", + ], target: { darwin: { enabled: false,
@@ -136,6 +167,9 @@ cc_binary_host { "lib/*.c", "fsck/*.c", ], + static_libs: [ + "liberofs", + ], target: { darwin: { enabled: false,
include/erofs/defs.h +5 -0
@@ -82,11 +82,16 @@ typedef int64_t s64;#endif #endif +#ifdef __cplusplus +#define BUILD_BUG_ON (condition) static_assert(!(condition)) +#else +#ifndef __OPTIMIZE__#define BUILD_BUG_ON (condition) ((void)sizeof(char[1 - 2 * !!(condition)]))#else #define BUILD_BUG_ON (condition) assert(!(condition))#endif +#endif #define DIV_ROUND_UP (n, d) (((n) + (d) - 1) / (d))
Signature · 1 line
2.34.0.rc2.393.gf8c9666880-goog
PATCH 2/2 Make erofs-utils more C++ friendly
In reply to Kelvin Zhang via Linux-erofs1. Add extern "C" wrappers to headers, so that they can be included from C++
2. Add const keyworkds to certain pointer type params
--- Android.bp | 4 +--- include/erofs/blobchunk.h | 10 ++++++++++ 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 | 15 +++++++++++++++ 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 +++++++++ include/erofs_fs.h | 9 +++++++++ lib/config.c | 12 ++++++++++++ lib/inode.c | 7 +++++++ lib/xattr.c | 12 ++++++++++++ mkfs/main.c | 7 +++++++ 26 files changed, 241 insertions(+), 14 deletions(-)
Android.bp +1 -3
@@ -50,7 +50,6 @@ genrule { out: ["erofs-utils-version.h"], cmd: "sed -n '1p' $(in) | tr -d '\n' | sed 's/\\(.*\\)/#define PACKAGE_VERSION \"\\1\"/' > $(out)", } - cc_defaults { name: "erofs-utils_export_defaults",
@@ -74,7 +73,6 @@ cc_defaults { cc_defaults { name: "erofs-utils_defaults", defaults: ["erofs-utils_export_defaults"], - cflags: [ "-include erofs-utils-version.h", ],
@@ -102,8 +100,8 @@ cc_library { srcs: [ "lib/*.c", ], - export_include_dirs: ["include"], + export_include_dirs: ["include"], target: { darwin: { enabled: false,
include/erofs/blobchunk.h +10 -0
@@ -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,9 @@ void erofs_blob_exit(void);int erofs_blob_init (const char *blobfile_path);int erofs_generate_devtable (void ); +#ifdef __cplusplus +extern "C" +} +#endif +#endif
include/erofs/block_list.h +10 -0
@@ -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
include/erofs/cache.h +9 -0
@@ -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
include/erofs/compress.h +9 -0
@@ -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
include/erofs/compress_hints.h +10 -0
@@ -6,6 +6,11 @@ #ifndef __EROFS_COMPRESS_HINTS_H #define __EROFS_COMPRESS_HINTS_H +#ifdef __cplusplus +extern "C" +{ +#endif + #include "erofs/internal.h" #include <sys/types.h> #include <regex.h>
@@ -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
include/erofs/config.h +9 -11
@@ -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 <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 enum { FORCE_INODE_COMPACT = 1,
@@ -96,4 +90,8 @@ static inline int erofs_selabel_open(const char *file_contexts) }#endif +#ifdef __cplusplus +}#endif + +#endif // EROFS_CONFIG_H_
include/erofs/decompress.h +9 -0
@@ -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
include/erofs/defs.h +15 -0
@@ -8,6 +8,11 @@ #ifndef __EROFS_DEFS_H #define __EROFS_DEFS_H +#ifdef __cplusplus +extern "C" +{ +#endif + #include <stddef.h> #include <stdint.h> #include <assert.h>
@@ -115,6 +120,9 @@ 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); \
@@ -127,6 +135,8 @@ typedef int64_t s64; (void ) (&_max1 == &_max2); \ _max1 > _max2 ? _max1 : _max2; }) +#endif +/* * ..and if you can't take the strict types, you can specify one yourself. * Or don't use min/max at all, of course.
@@ -313,4 +323,9 @@ unsigned long __roundup_pow_of_two(unsigned long n)#define stat64 stat#define lstat64 lstat#endif + +#ifdef __cplusplus +} +#endif +#endif
include/erofs/err.h +9 -0
@@ -7,6 +7,11 @@ #ifndef __EROFS_ERR_H #define __EROFS_ERR_H +#ifdef __cplusplus +extern "C" +{ +#endif + #include <errno.h> #define MAX_ERRNO (4095)
@@ -28,4 +33,8 @@ static inline long PTR_ERR(const void *ptr)return (long ) ptr; } +#ifdef __cplusplus +} +#endif +#endif
include/erofs/exclude.h +10 -0
@@ -5,6 +5,11 @@ #ifndef __EROFS_EXCLUDE_H #define __EROFS_EXCLUDE_H +#ifdef __cplusplus +extern "C" +{ +#endif + #include <sys/types.h> #include <regex.h>
@@ -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
include/erofs/flex-array.h +9 -0
@@ -2,6 +2,11 @@ #ifndef __EROFS_FLEX_ARRAY_H #define __EROFS_FLEX_ARRAY_H +#ifdef __cplusplus +extern "C" +{ +#endif + #include <stdio.h> #include <stdlib.h> #include <limits.h>
@@ -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
include/erofs/hashmap.h +9 -0
@@ -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 <stdio.h> #include <stdlib.h>
@@ -100,4 +105,8 @@ static inline const char *strintern(const char *string)return memintern (string,strlen (string)); } +#ifdef __cplusplus +} +#endif +#endif
include/erofs/hashtable.h +9 -0
@@ -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
include/erofs/inode.h +9 -0
@@ -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
include/erofs/internal.h +9 -0
@@ -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
include/erofs/io.h +11 -0
@@ -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 <unistd.h> #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_
include/erofs/list.h +10 -0
@@ -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
include/erofs/print.h +9 -0
@@ -7,6 +7,11 @@ #ifndef __EROFS_PRINT_H #define __EROFS_PRINT_H +#ifdef __cplusplus +extern "C" +{ +#endif + #include "config.h" #include <stdio.h>
@@ -72,4 +77,8 @@ enum {#define erofs_dump (fmt, ...) fprintf(stderr, fmt, ##__VA_ARGS__) +#ifdef __cplusplus +} +#endif +#endif
include/erofs/trace.h +9 -0
@@ -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
include/erofs/xattr.h +9 -0
@@ -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
include/erofs_fs.h +9 -0
@@ -9,6 +9,11 @@ #ifndef __EROFS_FS_H #define __EROFS_FS_H +#ifdef __cplusplus +extern "C" +{ +#endif + #define EROFS_SUPER_MAGIC_V1 0xE0F5E1E2 #define EROFS_SUPER_OFFSET 1024
@@ -425,4 +430,8 @@ static inline void erofs_check_ondisk_layout_definitions(void) Z_EROFS_VLE_CLUSTER_TYPE_MAX - 1); } +#ifdef __cplusplus +} +#endif +#endif
lib/config.c +12 -0
@@ -9,6 +9,18 @@#include "erofs/print.h" #include "erofs/internal.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 +struct erofs_configure cfg;struct erofs_sb_info sbi;
lib/inode.c +7 -0
@@ -26,6 +26,13 @@#include "erofs/compress_hints.h" #include "erofs/blobchunk.h" +#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 +#define S_SHIFT 12static unsigned char erofs_ftype_by_mode[S_IFMT >>S_SHIFT ] = { [S_IFREG >>S_SHIFT ] =EROFS_FT_REG_FILE ,
lib/xattr.c +12 -0
@@ -18,6 +18,18 @@#include "erofs/cache.h" #include "erofs/io.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 +#define EA_HASHTABLE_BITS 16struct xattr_item {
mkfs/main.c +7 -0
@@ -24,6 +24,13 @@#include "erofs/compress_hints.h" #include "erofs/blobchunk.h" +#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 +#ifdef HAVE_LIBUUID #include <uuid.h> #endif
Signature · 1 line
2.34.0.rc2.393.gf8c9666880-goog
Hi Kelvin,
Quoted 6 lines · Kelvin Zhang
The following patches make erofs-utils more C++ friendly. It does not perform any refactoring, instead it simply added extern "C" keywords so that C++ code can call into EROFS.
Kelvin Zhang (2):
Add android build target to build erofs as library
Thanks for your patches.
Once we discussed earlier, Android.bp is not a part of erofs-utils since I couldn't maintain it without Android build environment. Android build environment is somewhat hard for me to keep up with....
I think Android.bp can be resolved when upgrading AOSP erofs-utils code base.
Quoted 1 line
Make erofs-utils more C++ friendly
At glance, it looks good to me, I will test later in the evening.
Btw, how about adding "erofs-utils:" prefix to each patch. It will be easier for me to apply these...
Thanks,
Gao Xiang
Quoted 31 lines
Android.bp | 38 +++++++++++++++++++++++++++++++--- include/erofs/blobchunk.h | 10 +++++++++ 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 | 20 ++++++++++++++++++ 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 ++++++++ include/erofs_fs.h | 9 ++++++++ lib/config.c | 12 +++++++++++ lib/inode.c | 7 +++++++ lib/xattr.c | 12 +++++++++++ mkfs/main.c | 7 +++++++ 26 files changed, 280 insertions(+), 14 deletions(-)Signature · 1 line
2.34.0.rc2.393.gf8c9666880-goog
PATCH v2 1/2 erofs-utils: Add android build target to build erofs as library
--- Android.bp | 38 ++++++++++++++++++++++++++++++++++++-- 1 file changed, 36 insertions(+), 2 deletions(-)
Android.bp +36 -2
@@ -52,7 +52,7 @@ genrule { } cc_defaults { - name: "erofs-utils_defaults", + name: "erofs-utils_export_defaults", cflags: [ "-Wall",
@@ -60,7 +60,7 @@ cc_defaults { "-Wno-ignored-qualifiers", "-Wno-pointer-arith", "-Wno-unused-parameter", - "-include erofs-utils-version.h", + "-Wno-unused-function", "-DHAVE_FALLOCATE", "-DHAVE_LINUX_TYPES_H", "-DHAVE_LIBSELINUX",
@@ -69,6 +69,15 @@ cc_defaults { "-DLZ4HC_ENABLED", "-DWITH_ANDROID", ], +} + +cc_defaults { + name: "erofs-utils_defaults", + defaults: ["erofs-utils_export_defaults"], + + cflags: [ + "-include erofs-utils-version.h", + ], local_include_dirs: [ "include", ],
@@ -86,6 +95,22 @@ cc_defaults { ], } +cc_library { + host_supported: true, + name: "liberofs", + defaults: ["erofs-utils_defaults"], + srcs: [ + "lib/*.c", + ], + export_include_dirs: ["include"], + + target: { + darwin: { + enabled: false, + }, + }, +} + cc_defaults { name: "mkfs-erofs_defaults",
@@ -95,6 +120,9 @@ cc_defaults { "lib/*.c", "mkfs/*.c", ], + static_libs: [ + "liberofs", + ], target: { darwin: {
@@ -122,6 +150,9 @@ cc_binary_host { "lib/*.c", "dump/*.c", ], + static_libs: [ + "liberofs", + ], target: { darwin: { enabled: false,
@@ -136,6 +167,9 @@ cc_binary_host { "lib/*.c", "fsck/*.c", ], + static_libs: [ + "liberofs", + ], target: { darwin: { enabled: false,
Signature · 1 line
2.34.0.rc2.393.gf8c9666880-goog
PATCH v2 2/2 erofs-utils: Make erofs-utils more C++ friendly
1. Add extern "C" wrappers to headers, so that they can be included from C++
2. Add const keyworkds to certain pointer type params
--- include/erofs/blobchunk.h | 10 ++++++++++ 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 | 20 ++++++++++++++++++++ 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 +++++++++ include/erofs_fs.h | 9 +++++++++ lib/config.c | 12 ++++++++++++ lib/inode.c | 7 +++++++ lib/xattr.c | 12 ++++++++++++ mkfs/main.c | 7 +++++++ 25 files changed, 245 insertions(+), 11 deletions(-)
include/erofs/blobchunk.h +10 -0
@@ -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,9 @@ void erofs_blob_exit(void);int erofs_blob_init (const char *blobfile_path);int erofs_generate_devtable (void ); +#ifdef __cplusplus +extern "C" +} +#endif +#endif
include/erofs/block_list.h +10 -0
@@ -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
include/erofs/cache.h +9 -0
@@ -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
include/erofs/compress.h +9 -0
@@ -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
include/erofs/compress_hints.h +10 -0
@@ -6,6 +6,11 @@ #ifndef __EROFS_COMPRESS_HINTS_H #define __EROFS_COMPRESS_HINTS_H +#ifdef __cplusplus +extern "C" +{ +#endif + #include "erofs/internal.h" #include <sys/types.h> #include <regex.h>
@@ -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
include/erofs/config.h +9 -11
@@ -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 <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 enum { FORCE_INODE_COMPACT = 1,
@@ -96,4 +90,8 @@ static inline int erofs_selabel_open(const char *file_contexts) }#endif +#ifdef __cplusplus +}#endif + +#endif // EROFS_CONFIG_H_
include/erofs/decompress.h +9 -0
@@ -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
include/erofs/defs.h +20 -0
@@ -8,6 +8,11 @@ #ifndef __EROFS_DEFS_H #define __EROFS_DEFS_H +#ifdef __cplusplus +extern "C" +{ +#endif + #include <stddef.h> #include <stdint.h> #include <assert.h>
@@ -82,11 +87,16 @@ typedef int64_t s64;#endif #endif +#ifdef __cplusplus +#define BUILD_BUG_ON (condition) static_assert(!(condition)) +#else +#ifndef __OPTIMIZE__#define BUILD_BUG_ON (condition) ((void)sizeof(char[1 - 2 * !!(condition)]))#else #define BUILD_BUG_ON (condition) assert(!(condition))#endif +#endif #define DIV_ROUND_UP (n, d) (((n) + (d) - 1) / (d))
@@ -110,6 +120,9 @@ 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); \
@@ -122,6 +135,8 @@ typedef int64_t s64; (void ) (&_max1 == &_max2); \ _max1 > _max2 ? _max1 : _max2; }) +#endif +/* * ..and if you can't take the strict types, you can specify one yourself. * Or don't use min/max at all, of course.
@@ -308,4 +323,9 @@ unsigned long __roundup_pow_of_two(unsigned long n)#define stat64 stat#define lstat64 lstat#endif + +#ifdef __cplusplus +} +#endif +#endif
include/erofs/err.h +9 -0
@@ -7,6 +7,11 @@ #ifndef __EROFS_ERR_H #define __EROFS_ERR_H +#ifdef __cplusplus +extern "C" +{ +#endif + #include <errno.h> #define MAX_ERRNO (4095)
@@ -28,4 +33,8 @@ static inline long PTR_ERR(const void *ptr)return (long ) ptr; } +#ifdef __cplusplus +} +#endif +#endif
include/erofs/exclude.h +10 -0
@@ -5,6 +5,11 @@ #ifndef __EROFS_EXCLUDE_H #define __EROFS_EXCLUDE_H +#ifdef __cplusplus +extern "C" +{ +#endif + #include <sys/types.h> #include <regex.h>
@@ -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
include/erofs/flex-array.h +9 -0
@@ -2,6 +2,11 @@ #ifndef __EROFS_FLEX_ARRAY_H #define __EROFS_FLEX_ARRAY_H +#ifdef __cplusplus +extern "C" +{ +#endif + #include <stdio.h> #include <stdlib.h> #include <limits.h>
@@ -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
include/erofs/hashmap.h +9 -0
@@ -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 <stdio.h> #include <stdlib.h>
@@ -100,4 +105,8 @@ static inline const char *strintern(const char *string)return memintern (string,strlen (string)); } +#ifdef __cplusplus +} +#endif +#endif
include/erofs/hashtable.h +9 -0
@@ -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
include/erofs/inode.h +9 -0
@@ -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
include/erofs/internal.h +9 -0
@@ -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
include/erofs/io.h +11 -0
@@ -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 <unistd.h> #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_
include/erofs/list.h +10 -0
@@ -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
include/erofs/print.h +9 -0
@@ -7,6 +7,11 @@ #ifndef __EROFS_PRINT_H #define __EROFS_PRINT_H +#ifdef __cplusplus +extern "C" +{ +#endif + #include "config.h" #include <stdio.h>
@@ -72,4 +77,8 @@ enum {#define erofs_dump (fmt, ...) fprintf(stderr, fmt, ##__VA_ARGS__) +#ifdef __cplusplus +} +#endif +#endif
include/erofs/trace.h +9 -0
@@ -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
include/erofs/xattr.h +9 -0
@@ -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
include/erofs_fs.h +9 -0
@@ -9,6 +9,11 @@ #ifndef __EROFS_FS_H #define __EROFS_FS_H +#ifdef __cplusplus +extern "C" +{ +#endif + #define EROFS_SUPER_MAGIC_V1 0xE0F5E1E2 #define EROFS_SUPER_OFFSET 1024
@@ -425,4 +430,8 @@ static inline void erofs_check_ondisk_layout_definitions(void) Z_EROFS_VLE_CLUSTER_TYPE_MAX - 1); } +#ifdef __cplusplus +} +#endif +#endif
lib/config.c +12 -0
@@ -9,6 +9,18 @@#include "erofs/print.h" #include "erofs/internal.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 +struct erofs_configure cfg;struct erofs_sb_info sbi;
lib/inode.c +7 -0
@@ -26,6 +26,13 @@#include "erofs/compress_hints.h" #include "erofs/blobchunk.h" +#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 +#define S_SHIFT 12static unsigned char erofs_ftype_by_mode[S_IFMT >>S_SHIFT ] = { [S_IFREG >>S_SHIFT ] =EROFS_FT_REG_FILE ,
lib/xattr.c +12 -0
@@ -18,6 +18,18 @@#include "erofs/cache.h" #include "erofs/io.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 +#define EA_HASHTABLE_BITS 16struct xattr_item {
mkfs/main.c +7 -0
@@ -24,6 +24,13 @@#include "erofs/compress_hints.h" #include "erofs/blobchunk.h" +#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 +#ifdef HAVE_LIBUUID #include <uuid.h> #endif
Signature · 1 line
2.34.0.rc2.393.gf8c9666880-goog
Re: [PATCH v2 2/2] erofs-utils: Make erofs-utils more C++ friendly
Quoted 34 lines · Kelvin Zhang
1. Add extern "C" wrappers to headers, so that they can be included from C++
2. Add const keyworkds to certain pointer type paramsChange-Id Ica96c5626de7cc511ffa9a73e0e5ddf7601a7451Signed-off-by Kelvin Zhang <[email protected]>--- include/erofs/blobchunk.h | 10 ++++++++++ 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 | 20 ++++++++++++++++++++ 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 +++++++++ include/erofs_fs.h | 9 +++++++++ lib/config.c | 12 ++++++++++++ lib/inode.c | 7 +++++++ lib/xattr.c | 12 ++++++++++++ mkfs/main.c | 7 +++++++ 25 files changed, 245 insertions(+), 11 deletions(-)
...
Quoted 18 lines
include/erofs/config.h +5
-2@@ -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 <selinux/selinux.h>
include/erofs/config.h line 18
Quoted 10 lines
include/erofs/config.h +0
-9-#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
Out of curiousity, why do we move these headers to each source files?
Thanks,
Gao Xiang
PATCH v3 1/2 erofs-utils: Add android build target to build erofs as library
In reply to Gao Xiang--- Android.bp | 38 ++++++++++++++++++++++++++++++++++++-- 1 file changed, 36 insertions(+), 2 deletions(-)
Android.bp +36 -2
@@ -52,7 +52,7 @@ genrule { } cc_defaults { - name: "erofs-utils_defaults", + name: "erofs-utils_export_defaults", cflags: [ "-Wall",
@@ -60,7 +60,7 @@ cc_defaults { "-Wno-ignored-qualifiers", "-Wno-pointer-arith", "-Wno-unused-parameter", - "-include erofs-utils-version.h", + "-Wno-unused-function", "-DHAVE_FALLOCATE", "-DHAVE_LINUX_TYPES_H", "-DHAVE_LIBSELINUX",
@@ -69,6 +69,15 @@ cc_defaults { "-DLZ4HC_ENABLED", "-DWITH_ANDROID", ], +} + +cc_defaults { + name: "erofs-utils_defaults", + defaults: ["erofs-utils_export_defaults"], + + cflags: [ + "-include erofs-utils-version.h", + ], local_include_dirs: [ "include", ],
@@ -86,6 +95,22 @@ cc_defaults { ], } +cc_library { + host_supported: true, + name: "liberofs", + defaults: ["erofs-utils_defaults"], + srcs: [ + "lib/*.c", + ], + export_include_dirs: ["include"], + + target: { + darwin: { + enabled: false, + }, + }, +} + cc_defaults { name: "mkfs-erofs_defaults",
@@ -95,6 +120,9 @@ cc_defaults { "lib/*.c", "mkfs/*.c", ], + static_libs: [ + "liberofs", + ], target: { darwin: {
@@ -122,6 +150,9 @@ cc_binary_host { "lib/*.c", "dump/*.c", ], + static_libs: [ + "liberofs", + ], target: { darwin: { enabled: false,
@@ -136,6 +167,9 @@ cc_binary_host { "lib/*.c", "fsck/*.c", ], + static_libs: [ + "liberofs", + ], target: { darwin: { enabled: false,
Signature · 1 line
2.34.0.rc2.393.gf8c9666880-goog
PATCH v3 2/2 erofs-utils: Make erofs-utils more C++ friendly
1. Add extern "C" wrappers to headers, so that they can be included from C++
2. Add const keyworkds to certain pointer type params
--- include/erofs/blobchunk.h | 10 ++++++++++ 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 | 20 ++++++++++++++++++++ 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 +++++++++ include/erofs_fs.h | 9 +++++++++ lib/config.c | 1 + lib/erofs_selinux.h | 13 +++++++++++++ lib/inode.c | 1 + lib/xattr.c | 2 ++ 25 files changed, 224 insertions(+), 11 deletions(-) create mode 100644 lib/erofs_selinux.h
include/erofs/blobchunk.h +10 -0
@@ -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,9 @@ void erofs_blob_exit(void);int erofs_blob_init (const char *blobfile_path);int erofs_generate_devtable (void ); +#ifdef __cplusplus +extern "C" +} +#endif +#endif
include/erofs/block_list.h +10 -0
@@ -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
include/erofs/cache.h +9 -0
@@ -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
include/erofs/compress.h +9 -0
@@ -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
include/erofs/compress_hints.h +10 -0
@@ -6,6 +6,11 @@ #ifndef __EROFS_COMPRESS_HINTS_H #define __EROFS_COMPRESS_HINTS_H +#ifdef __cplusplus +extern "C" +{ +#endif + #include "erofs/internal.h" #include <sys/types.h> #include <regex.h>
@@ -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
include/erofs/config.h +9 -11
@@ -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 <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 enum { FORCE_INODE_COMPACT = 1,
@@ -96,4 +90,8 @@ static inline int erofs_selabel_open(const char *file_contexts) }#endif +#ifdef __cplusplus +}#endif + +#endif // EROFS_CONFIG_H_
include/erofs/decompress.h +9 -0
@@ -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
include/erofs/defs.h +20 -0
@@ -8,6 +8,11 @@ #ifndef __EROFS_DEFS_H #define __EROFS_DEFS_H +#ifdef __cplusplus +extern "C" +{ +#endif + #include <stddef.h> #include <stdint.h> #include <assert.h>
@@ -82,11 +87,16 @@ typedef int64_t s64;#endif #endif +#ifdef __cplusplus +#define BUILD_BUG_ON (condition) static_assert(!(condition)) +#else +#ifndef __OPTIMIZE__#define BUILD_BUG_ON (condition) ((void)sizeof(char[1 - 2 * !!(condition)]))#else #define BUILD_BUG_ON (condition) assert(!(condition))#endif +#endif #define DIV_ROUND_UP (n, d) (((n) + (d) - 1) / (d))
@@ -110,6 +120,9 @@ 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); \
@@ -122,6 +135,8 @@ typedef int64_t s64; (void ) (&_max1 == &_max2); \ _max1 > _max2 ? _max1 : _max2; }) +#endif +/* * ..and if you can't take the strict types, you can specify one yourself. * Or don't use min/max at all, of course.
@@ -308,4 +323,9 @@ unsigned long __roundup_pow_of_two(unsigned long n)#define stat64 stat#define lstat64 lstat#endif + +#ifdef __cplusplus +} +#endif +#endif
include/erofs/err.h +9 -0
@@ -7,6 +7,11 @@ #ifndef __EROFS_ERR_H #define __EROFS_ERR_H +#ifdef __cplusplus +extern "C" +{ +#endif + #include <errno.h> #define MAX_ERRNO (4095)
@@ -28,4 +33,8 @@ static inline long PTR_ERR(const void *ptr)return (long ) ptr; } +#ifdef __cplusplus +} +#endif +#endif
include/erofs/exclude.h +10 -0
@@ -5,6 +5,11 @@ #ifndef __EROFS_EXCLUDE_H #define __EROFS_EXCLUDE_H +#ifdef __cplusplus +extern "C" +{ +#endif + #include <sys/types.h> #include <regex.h>
@@ -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
include/erofs/flex-array.h +9 -0
@@ -2,6 +2,11 @@ #ifndef __EROFS_FLEX_ARRAY_H #define __EROFS_FLEX_ARRAY_H +#ifdef __cplusplus +extern "C" +{ +#endif + #include <stdio.h> #include <stdlib.h> #include <limits.h>
@@ -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
include/erofs/hashmap.h +9 -0
@@ -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 <stdio.h> #include <stdlib.h>
@@ -100,4 +105,8 @@ static inline const char *strintern(const char *string)return memintern (string,strlen (string)); } +#ifdef __cplusplus +} +#endif +#endif
include/erofs/hashtable.h +9 -0
@@ -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
include/erofs/inode.h +9 -0
@@ -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
include/erofs/internal.h +9 -0
@@ -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
include/erofs/io.h +11 -0
@@ -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 <unistd.h> #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_
include/erofs/list.h +10 -0
@@ -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
include/erofs/print.h +9 -0
@@ -7,6 +7,11 @@ #ifndef __EROFS_PRINT_H #define __EROFS_PRINT_H +#ifdef __cplusplus +extern "C" +{ +#endif + #include "config.h" #include <stdio.h>
@@ -72,4 +77,8 @@ enum {#define erofs_dump (fmt, ...) fprintf(stderr, fmt, ##__VA_ARGS__) +#ifdef __cplusplus +} +#endif +#endif
include/erofs/trace.h +9 -0
@@ -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
include/erofs/xattr.h +9 -0
@@ -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
include/erofs_fs.h +9 -0
@@ -9,6 +9,11 @@ #ifndef __EROFS_FS_H #define __EROFS_FS_H +#ifdef __cplusplus +extern "C" +{ +#endif + #define EROFS_SUPER_MAGIC_V1 0xE0F5E1E2 #define EROFS_SUPER_OFFSET 1024
@@ -425,4 +430,8 @@ static inline void erofs_check_ondisk_layout_definitions(void) Z_EROFS_VLE_CLUSTER_TYPE_MAX - 1); } +#ifdef __cplusplus +} +#endif +#endif
lib/config.c +1 -0
@@ -8,6 +8,7 @@#include <stdlib.h> #include "erofs/print.h" #include "erofs/internal.h" +#include "erofs_selinux.h" struct erofs_configure cfg;struct erofs_sb_info sbi;
lib/erofs_selinux.h new file +13 -0
@@ -0,0 +1,13 @@ + + +#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
lib/inode.c +1 -0
@@ -25,6 +25,7 @@#include "erofs/block_list.h" #include "erofs/compress_hints.h" #include "erofs/blobchunk.h" +#include "erofs_selinux.h" #define S_SHIFT 12static unsigned char erofs_ftype_by_mode[S_IFMT >>S_SHIFT ] = {
lib/xattr.c +2 -0
@@ -18,6 +18,8 @@#include "erofs/cache.h" #include "erofs/io.h" +#include "erofs_selinux.h" +#define EA_HASHTABLE_BITS 16struct xattr_item {
Signature · 1 line
2.34.0.rc2.393.gf8c9666880-goog