erofs-utils: introduce fsck.erofs
Subsystems (2)
PATCH v3 1/1 erofs-utils: introduce fsck.erofs
From: Daeho Jeong <[email protected]>
I made a fsck.erofs tool to check erofs filesystem image integrity and calculate filesystem compression ratio.
Here are options to support now.
fsck.erofs [options] IMAGE
-V print the version number of fsck.erofs and exit. -d# set output message level to # (maximum 9) -p print total compression ratio of all files -c check if all compressed files are well decompressed
---
v3: added man page
v2: merged options printing compression ratio into "-p"
added "-c" option to check if compressed files are well decompressed added alphabetical order of dirent entries
changed the way to calculate compression rate
changed the way to check special named dirent entries
--- Makefile.am | 2 +- configure.ac | 3 +- fsck/Makefile.am | 9 + fsck/main.c | 606 +++++++++++++++++++++++++++++++++++++++ include/erofs/internal.h | 5 + include/erofs_fs.h | 13 + lib/data.c | 4 +- lib/namei.c | 2 +- lib/super.c | 1 + man/fsck.erofs.1 | 38 +++ mkfs/main.c | 13 - 11 files changed, 678 insertions(+), 18 deletions(-) create mode 100644 fsck/Makefile.am create mode 100644 fsck/main.c create mode 100644 man/fsck.erofs.1
Makefile.am +1 -1
@@ -2,7 +2,7 @@ ACLOCAL_AMFLAGS = -I m4 -SUBDIRS = man lib mkfs dump +SUBDIRS = man lib mkfs dump fsck if ENABLE_FUSE SUBDIRS += fuse endif
configure.ac +2 -1
@@ -298,5 +298,6 @@ AC_CONFIG_FILES([Makefile lib/Makefile mkfs/Makefile dump/Makefile - fuse/Makefile]) + fuse/Makefile + fsck/Makefile]) AC_OUTPUT
fsck/Makefile.am new file +9 -0
@@ -0,0 +1,9 @@ +# SPDX-License-Identifier: GPL-2.0+ +# Makefile.am + +AUTOMAKE_OPTIONS = foreign +bin_PROGRAMS = fsck.erofs +AM_CPPFLAGS = ${libuuid_CFLAGS} +fsck_erofs_SOURCES = main.c +fsck_erofs_CFLAGS = -Wall -Werror -I$(top_srcdir)/include +fsck_erofs_LDADD = $(top_builddir)/lib/liberofs.la ${libuuid_LIBS} ${liblz4_LIBS}
fsck/main.c new file +606 -0
606 lines not on this page · raw message
include/erofs/internal.h +5 -0
@@ -82,6 +82,8 @@ struct erofs_sb_info {u16 available_compr_algs;u16 lz4_max_distance; + +u32 checksum; };/* global sbi */
@@ -264,10 +266,13 @@ int erofs_read_superblock(void);/* namei.c */ int erofs_ilookup (const char *path,struct erofs_inode *vi); +int erofs_read_inode_from_disk (struct erofs_inode *vi);/* data.c */ int erofs_pread (struct erofs_inode *inode,char *buf,erofs_off_t count,erofs_off_t offset); +int erofs_map_blocks (struct erofs_inode *inode, +struct erofs_map_blocks *map,int flags);/* zmap.c */ int z_erofs_fill_inode (struct erofs_inode *vi); int z_erofs_map_blocks_iter(struct erofs_inode *vi,
include/erofs_fs.h +13 -0
@@ -400,4 +400,17 @@ static inline void erofs_check_ondisk_layout_definitions(void) Z_EROFS_VLE_CLUSTER_TYPE_MAX - 1); } +#define CRC32C_POLY_LE 0x82F63B78 +static inline u32 crc32c (u32 crc,const u8 *in,size_t len) +{ +int i; + +while (len--) { + crc ^= *in++; +for (i =0 ; i <8 ; i++) + crc = (crc >>1 ) ^ ((crc &1 ) ?CRC32C_POLY_LE :0 ); + } +return crc; +} +#endif
lib/data.c +2 -2
@@ -61,8 +61,8 @@ err_out:return err; } -static int erofs_map_blocks (struct erofs_inode *inode, -struct erofs_map_blocks *map,int flags) +int erofs_map_blocks (struct erofs_inode *inode, +struct erofs_map_blocks *map,int flags) {struct erofs_inode *vi = inode;struct erofs_inode_chunk_index *idx;
lib/namei.c +1 -1
@@ -22,7 +22,7 @@ static dev_t erofs_new_decode_dev(u32 dev)return makedev (major, minor); } -static int erofs_read_inode_from_disk (struct erofs_inode *vi) +int erofs_read_inode_from_disk (struct erofs_inode *vi) {int ret, ifmt;char buf[sizeof (struct erofs_inode_extended )];
lib/super.c +1 -0
@@ -62,6 +62,7 @@ int erofs_read_superblock(void) sbi.islotbits =EROFS_ISLOTBITS ; sbi.root_nid =le16_to_cpu (dsb->root_nid); sbi.inos =le64_to_cpu (dsb->inos); + sbi.checksum =le32_to_cpu (dsb->checksum); sbi.build_time =le64_to_cpu (dsb->build_time); sbi.build_time_nsec =le32_to_cpu (dsb->build_time_nsec);
man/fsck.erofs.1 new file +38 -0
@@ -0,0 +1,38 @@ +.\" Copyright (c) 2021 Daeho Jeong <[email protected]> +.\" +.TH FSCK.EROFS 1 +.SH NAME +fsck.erofs \- tool to check the EROFS filesystem's integrity +.SH SYNOPSIS +\fBfsck.erofs\fR [\fIOPTIONS\fR] \fIIMAGE\fR +.SH DESCRIPTION +fsck.erofs is used to scan an EROFS filesystem \fIIMAGE\fR and check the +integrity of it. +.SH OPTIONS +.TP +.BI "\-V " +Print the version number of fsck.erofs and exit. +.TP +.BI "\-d " # +Specify the level of debugging messages. The default is 2, which shows basic +warning messages. +.TP +.BI "\-p " +Print total compression ratio of all files including compressed and +non-compressed files. +.TP +.BI "\-c " +Check if all the compressed files are well decompressed. This will induce more +I/Os to read compressed file data, so it might take too much time depending on +the image. +.TP +.B \-\-help +Display this help and exit. +.SH AUTHOR +This version of \fBfsck.erofs\fR is written by +Daeho Jeong <[email protected]>. +.SH AVAILABILITY +\fBfsck.erofs\fR is part of erofs-utils package and is available from +git://git.kernel.org/pub/scm/linux/kernel/git/xiang/erofs-utils.git. +.SH SEE ALSO +.BR fsck (8).
mkfs/main.c +0 -13
@@ -424,19 +424,6 @@ int erofs_mkfs_update_super_block(struct erofs_buffer_head *bh,return 0 ; } -#define CRC32C_POLY_LE 0x82F63B78 -static inline u32 crc32c (u32 crc,const u8 *in,size_t len) -{ -int i; - -while (len--) { - crc ^= *in++; -for (i =0 ; i <8 ; i++) - crc = (crc >>1 ) ^ ((crc &1 ) ?CRC32C_POLY_LE :0 ); - } -return crc; -} -static int erofs_mkfs_superblock_csum_set (void ) {int ret;
Signature · 1 line
2.33.1.1089.g2158813163f-goog
Hi Daeho,
Quoted 12 lines · Daeho Jeong
From: Daeho Jeong <[email protected]>
I made a fsck.erofs tool to check erofs filesystem image integrity and calculate filesystem compression ratio.
Here are options to support now.fsck.erofs [options] IMAGE
(quoted diff) +0
-4-V print the version number of fsck.erofs and exit. -d# set output message level to # (maximum 9) -p print total compression ratio of all files -c check if all compressed files are well decompressed
Quoted 1 line
Signed-off-by Daeho Jeong <[email protected]>
Applied with some minor updates, e.g. update .gitignore, etc.
https://git.kernel.org/pub/scm/linux/kernel/git/xiang/erofs-utils.git/commit/?id=f44043561491255c37903a9ad1334f2e88c95005
Thanks,
Gao Xiang
2021년 11월 9일 (화) 오전 3:26, Gao Xiang <[email protected]>님이 작성:
Quoted 16 lines
Hi Daeho,
Quoted 12 lines · Daeho Jeong
From: Daeho Jeong <[email protected]>
I made a fsck.erofs tool to check erofs filesystem image integrity and calculate filesystem compression ratio.
Here are options to support now.fsck.erofs [options] IMAGE
(quoted diff) +0
-4-V print the version number of fsck.erofs and exit. -d# set output message level to # (maximum 9) -p print total compression ratio of all files -c check if all compressed files are well decompressed
Quoted 7 lines
Quoted 1 line
Signed-off-by Daeho Jeong <[email protected]>Applied with some minor updates, e.g. update .gitignore, etc.
https://git.kernel.org/pub/scm/linux/kernel/git/xiang/erofs-utils.git/commit/?id=f44043561491255c37903a9ad1334f2e88c95005Thanks,
Gao Xiang
Hi Gao,
Many thanks~! :)
Quoted 1 line
Hi Gao,
After merging all the latest patches, the build fails now, since we don't have the lzma library on the build system now.
external/erofs-utils/lib/compressor_liblzma.c:8:10: fatal error:
'lzma.h' file not found
#include <lzma.h>
^~~~~~~~1 error generated.
16:13:47 ninja failed with: exit status 1
Can you fix this to make it built without the lzma library?
Hi Daeho,
Quoted 5 lines · Daeho Jeong
Hi Gao,
After merging all the latest patches, the build fails now, since we don't have the lzma library on the build system now.
Quoted 8 lines
external/erofs-utils/lib/compressor_liblzma.c:8:10: fatal error:
'lzma.h' file not found#include <lzma.h> ^~~~~~~~1 error generated.
16:13:47 ninja failed with: exit status 1Can you fix this to make it built without the lzma library?
I think it's mainly due to Android.bp configuration, because in lib/Makefile.am it wrote as:
...
if ENABLE_LIBLZMAliberofs_la_CFLAGS += ${liblzma_CFLAGS}liberofs_la_SOURCES += compressor_liblzma.c
endif
I could add some macro in compressor_liblzma.c as well if needed.
btw, I suggest updating the patches when 1.4 is out (next week), since I still do some cleanup work.
Thanks,
Gao Xiang