erofs-utils:code for calculating crc checksum of erofs blocks
PATCH v4 1/1 erofs-utils:code for calculating crc checksum of erofs blocks
Added code for calculating crc of erofs blocks (4K size).for now it calculates checksum of first block. but can modified to calculate crc for any no. of blocks
Fill 'feature_compat' field of erofs_super_block so that it can be used on kernel side.
.
Signed-off-by Pratik Shinde <[email protected]>
--- include/erofs/internal.h | 1 + include/erofs/io.h | 8 ++++++ include/erofs_fs.h | 5 ++-- lib/io.c | 27 ++++++++++++++++++ mkfs/main.c | 71 ++++++++++++++++++++++++++++++++++++++++++++++++ 5 files changed, 110 insertions(+), 2 deletions(-)
include/erofs/internal.h +1 -0
@@ -55,6 +55,7 @@ struct erofs_sb_info {u32 feature_incompat;u64 build_time;u32 build_time_nsec; +u32 feature; };/* global sbi */
include/erofs/io.h +8 -0
@@ -19,6 +19,7 @@int dev_open (const char *devname);void dev_close (void );int dev_write (const void *buf,u64 offset,size_t len); +int dev_read (void *buf,u64 offset,size_t len);int dev_fillzero (u64 offset,size_t len,bool padding);int dev_fsync (void );int dev_resize (erofs_blk_t nblocks);
@@ -31,5 +32,12 @@ static inline int blk_write(const void *buf, erofs_blk_t blkaddr, blknr_to_addr(nblocks)); } +static inline int blk_read (void *buf,erofs_blk_t start, +u32 nblocks) +{ +return dev_read (buf,blknr_to_addr (start), +blknr_to_addr (nblocks)); +} +#endif
include/erofs_fs.h +3 -2
@@ -19,6 +19,7 @@*/ #define EROFS_FEATURE_INCOMPAT_LZ4_0PADDING 0x00000001#define EROFS_ALL_FEATURE_INCOMPAT EROFS_FEATURE_INCOMPAT_LZ4_0PADDING +#define EROFS_FEATURE_SB_CHKSUM 0x0001/* 128-byte erofs on-disk super block */ struct erofs_super_block {
@@ -39,8 +40,8 @@ struct erofs_super_block {__u8 uuid[16 ];/* 128-bit uuid for volume */ __u8 volume_name[16 ];/* volume name */ __le32 feature_incompat; - -__u8 reserved2[44 ]; +__le32 chksum_blocks;/* number of blocks used for checksum */ +__u8 reserved2[40 ]; };/*
lib/io.c +27 -0
@@ -207,3 +207,30 @@ int dev_resize(unsigned int blocks)return dev_fillzero (st.st_size, length, true); } +int dev_read (void *buf,u64 offset,size_t len) +{ +int ret; + +if (cfg.c_dry_run) +return 0 ; + +if (!buf) { +erofs_err ("buf is NULL" ); +return -EINVAL ; + } +if (offset >= erofs_devsz || len > erofs_devsz || + offset > erofs_devsz - len) { +erofs_err ("read posion[%" PRIu64", %zd] is too large beyond" +"the end of device(%" PRIu64")." , + offset, len, erofs_devsz); +return -EINVAL ; + } + + ret =pread64 (erofs_devfd, buf, len, (off64_t )offset); +if (ret != (int )len) { +erofs_err ("Failed to read data from device - %s:[%" PRIu64", %zd]." , + erofs_devname, offset, len); +return -errno; + } +return 0 ; +}
mkfs/main.c +71 -0
107 lines not on this page · raw message
Signature · 1 line
2.9.3