Global variables aren't bad, until you start mutating them in multiple places.
Signed-off-by: Kelvin Zhang <[email protected]> --- include/erofs/cache.h | 8 ++++---- lib/cache.c | 6 +++--- lib/compressor.c | 2 +- lib/compressor.h | 8 ++++---- lib/compressor_liblzma.c | 2 +- lib/compressor_lz4.c | 2 +- lib/compressor_lz4hc.c | 2 +- 7 files changed, 15 insertions(+), 15 deletions(-) diff --git a/include/erofs/cache.h b/include/erofs/cache.h index 051c696..fd13614 100644 --- a/include/erofs/cache.h +++ b/include/erofs/cache.h @@ -31,7 +31,7 @@ struct erofs_buffer_head { struct erofs_buffer_block *block; erofs_off_t off; - struct erofs_bhops *op; + const struct erofs_bhops *op; void *fsprivate; }; @@ -64,9 +64,9 @@ static inline const int get_alignsize(int type, int *type_ret) return -EINVAL; } -extern struct erofs_bhops erofs_drop_directly_bhops; -extern struct erofs_bhops erofs_skip_write_bhops; -extern struct erofs_bhops erofs_buf_write_bhops; +extern const struct erofs_bhops erofs_drop_directly_bhops; +extern const struct erofs_bhops erofs_skip_write_bhops; +extern const struct erofs_bhops erofs_buf_write_bhops; static inline erofs_off_t erofs_btell(struct erofs_buffer_head *bh, bool end) { diff --git a/lib/cache.c b/lib/cache.c index bae172c..afb29d0 100644 --- a/lib/cache.c +++ b/lib/cache.c @@ -28,7 +28,7 @@ static bool erofs_bh_flush_drop_directly( return erofs_bh_flush_generic_end(bh); } -struct erofs_bhops erofs_drop_directly_bhops = { +const struct erofs_bhops erofs_drop_directly_bhops = { .flush = erofs_bh_flush_drop_directly, }; @@ -39,7 +39,7 @@ static bool erofs_bh_flush_skip_write( return false; } -struct erofs_bhops erofs_skip_write_bhops = { +const struct erofs_bhops erofs_skip_write_bhops = { .flush = erofs_bh_flush_skip_write, }; @@ -65,7 +65,7 @@ static bool erofs_bh_flush_buf_write( } -struct erofs_bhops erofs_buf_write_bhops = { +const struct erofs_bhops erofs_buf_write_bhops = { .flush = erofs_bh_flush_buf_write, }; diff --git a/lib/compressor.c b/lib/compressor.c index ad12cdf..6362825 100644 --- a/lib/compressor.c +++ b/lib/compressor.c @@ -10,7 +10,7 @@ #define EROFS_CONFIG_COMPR_DEF_BOUNDARY (128) -static struct erofs_compressor *compressors[] = { +static const struct erofs_compressor *compressors[] = { #if LZ4_ENABLED #if LZ4HC_ENABLED &erofs_compressor_lz4hc, diff --git a/lib/compressor.h b/lib/compressor.h index aa85ae0..1ea2724 100644 --- a/lib/compressor.h +++ b/lib/compressor.h @@ -27,7 +27,7 @@ struct erofs_compressor { }; struct erofs_compress { - struct erofs_compressor *alg; + const struct erofs_compressor *alg; unsigned int compress_threshold; unsigned int compression_level; @@ -41,9 +41,9 @@ struct erofs_compress { }; /* list of compression algorithms */ -extern struct erofs_compressor erofs_compressor_lz4; -extern struct erofs_compressor erofs_compressor_lz4hc; -extern struct erofs_compressor erofs_compressor_lzma; +extern const struct erofs_compressor erofs_compressor_lz4; +extern const struct erofs_compressor erofs_compressor_lz4hc; +extern const struct erofs_compressor erofs_compressor_lzma; int erofs_compress_destsize(struct erofs_compress *c, void *src, unsigned int *srcsize, diff --git a/lib/compressor_liblzma.c b/lib/compressor_liblzma.c index 576cdae..3229841 100644 --- a/lib/compressor_liblzma.c +++ b/lib/compressor_liblzma.c @@ -96,7 +96,7 @@ static int erofs_compressor_liblzma_init(struct erofs_compress *c) return 0; } -struct erofs_compressor erofs_compressor_lzma = { +const struct erofs_compressor erofs_compressor_lzma = { .name = "lzma", .default_level = LZMA_PRESET_DEFAULT, .best_level = LZMA_PRESET_EXTREME, diff --git a/lib/compressor_lz4.c b/lib/compressor_lz4.c index f6832be..fc8c23c 100644 --- a/lib/compressor_lz4.c +++ b/lib/compressor_lz4.c @@ -37,7 +37,7 @@ static int compressor_lz4_init(struct erofs_compress *c) return 0; } -struct erofs_compressor erofs_compressor_lz4 = { +const struct erofs_compressor erofs_compressor_lz4 = { .name = "lz4", .default_level = 0, .best_level = 0, diff --git a/lib/compressor_lz4hc.c b/lib/compressor_lz4hc.c index fd801ab..3f68b00 100644 --- a/lib/compressor_lz4hc.c +++ b/lib/compressor_lz4hc.c @@ -59,7 +59,7 @@ static int compressor_lz4hc_setlevel(struct erofs_compress *c, return 0; } -struct erofs_compressor erofs_compressor_lz4hc = { +const struct erofs_compressor erofs_compressor_lz4hc = { .name = "lz4hc", .default_level = LZ4HC_CLEVEL_DEFAULT, .best_level = LZ4HC_CLEVEL_MAX, -- 2.34.0.rc2.393.gf8c9666880-goog
