Re: [PATCH v2] erofs-utils: mkfs_erofs.h: clean up definitions
On 2018/12/19 20:23, Gao Xiang wrote: > remove some duplicated definitions and > keep these in line with kernel names. > > Signed-off-by: Gao Xiang > --- > v1 -> v2: > - fix compilation > > erofs_cache.c | 11 --- > erofs_io.c| 3 +-- > mkfs_erofs.h | 24 ++-- > mkfs_file.c | 4 ++-- > mkfs_inode.c | 28 ++-- > mkfs_main.c | 6 +++--- > 6 files changed, 34 insertions(+), 42 deletions(-) > > diff --git a/erofs_cache.c b/erofs_cache.c > index 5b80592..cfecd7f 100644 > --- a/erofs_cache.c > +++ b/erofs_cache.c > @@ -45,10 +45,10 @@ u32 erofs_alloc_blocks(u32 nblocks) > devlen = dev_length(); > if (erofs_current_block > (u64)UINT32_MAX || > erofs_current_block + nblocks > ((u64)UINT32_MAX) + 1 || > - (erofs_current_block + nblocks) << EROFS_BLOCKSIZE_BITS > devlen) { > + blknr_to_addr(erofs_current_block + nblocks) > devlen) { > erofs_err("There is no enough free space(curr: %llu, need: %u, > device blocks: %llu).", > (unsigned long long)erofs_current_block, nblocks, > - (unsigned long long)devlen >> EROFS_BLOCKSIZE_BITS); > + (unsigned long long)erofs_blknr(devlen)); > return 0; > } > > @@ -143,7 +143,6 @@ int erofs_flush_all_blocks(void) > char *pbuf; > int count; > int ret; > - u32 addr; > > erofs_blk_buf = malloc(EROFS_BLKSIZE); > if (!erofs_blk_buf) > @@ -175,10 +174,8 @@ int erofs_flush_all_blocks(void) > pbuf += count; > } > > - addr = blk->bb_blkaddr; > - > - ret = dev_write( > - erofs_blk_buf, BLKNO_TO_ADDR(addr), EROFS_BLKSIZE); > + ret = dev_write(erofs_blk_buf, > + blknr_to_addr(blk->bb_blkaddr), EROFS_BLKSIZE); > if (ret) > break; > } > diff --git a/erofs_io.c b/erofs_io.c > index 8112ade..57e283e 100644 > --- a/erofs_io.c > +++ b/erofs_io.c > @@ -155,8 +155,7 @@ int dev_write_block(void *buf, u32 blkaddr) > { > erofs_info("Write data to block %u", blkaddr); > > - return dev_write(buf, ((off64_t)blkaddr) << EROFS_BLOCKSIZE_BITS, > - EROFS_BLKSIZE); > + return dev_write(buf, blknr_to_addr(blkaddr), EROFS_BLKSIZE); > } > > int dev_fsync(void) > diff --git a/mkfs_erofs.h b/mkfs_erofs.h > index be6305e..7fdc4c5 100644 > --- a/mkfs_erofs.h > +++ b/mkfs_erofs.h > @@ -9,6 +9,7 @@ > */ > #ifndef __EROFS_MKFS_H > #define __EROFS_MKFS_H > + > #include > #include "list_head.h" > #include "erofs_types.h" > @@ -19,19 +20,11 @@ typedef unsigned int __u32; > > #include "erofs_fs.h" > > -#ifndef PAGE_SIZE > -#define PAGE_SIZE (4096) > -#endif > - > -#ifndef EROFS_BLKSIZE > +#define LOG_BLOCK_SIZE (12) > #define EROFS_BLKSIZE (4096) > -#define EROFS_BLOCKSIZE_BITS(12) > -#endif > > -#define EROFS_BLOCK_SIZE_SHIFT_BITS (12) > #define EROFS_SLOTSIZE_BITS (5) > #define EROFS_SLOTSIZE (32) > -#define MKFS_DIFF_SHIFT_8_BITS (8) > > #define __round_mask(x, y) ((__typeof__(x))((y)-1)) > #define round_up(x, y) x)-1) | __round_mask(x, y))+1) > @@ -39,16 +32,19 @@ typedef unsigned int __u32; > > #define SIZE_ALIGN(val, size) (((val) + (size) - 1) & (~(size-1))) > #define SLOT_ALIGN(slots) SIZE_ALIGN(slots, EROFS_SLOTSIZE) > -#define PAGE_ALIGN(pages) SIZE_ALIGN(pages, PAGE_SIZE) > #define BLK_ALIGN(blks) SIZE_ALIGN(blks, EROFS_BLKSIZE) > #define IS_SLOT_ALIGN(__ADDR) (((__ADDR)%(EROFS_SLOTSIZE))?0:1) > #define IS_BLK_ALIGN(__ADDR)(((__ADDR)%(EROFS_BLKSIZE))?0:1) > -#define ADDR_TO_BLKNO(__ADDR) ((__ADDR) >> EROFS_BLOCKSIZE_BITS) > -#define BLKNO_TO_ADDR(__ADDR) ((u64)(__ADDR) << EROFS_BLOCKSIZE_BITS) > #define MAX_NID_INDEX_PER_BLK (EROFS_BLKSIZE / EROFS_SLOTSIZE) > > -#define EROFS_INODE_V1_SIZE sizeof(struct erofs_inode_v1) > -#define EROFS_INODE_V2_SIZE sizeof(struct erofs_inode_v2) > +typedef u64 erofs_off_t; > + > +/* data type for filesystem-wide blocks number */ > +typedef u32 erofs_blk_t; > + > +#define erofs_blknr(addr) ((addr) / EROFS_BLKSIZE) > +#define erofs_blkoff(addr) ((addr) % EROFS_BLKSIZE) > +#define blknr_to_addr(nr) ((erofs_off_t)(nr) * EROFS_BLKSIZE) > > #define EROFS_DIRENT_SIZE sizeof(struct erofs_dirent) > > diff --git a/mkfs_file.c b/mkfs_file.c > index 634208e..9aa62e2 100644 > --- a/mkfs_file.c > +++ b/mkfs_file.c > @@ -437,7 +437,7 @@ static int erofs_compress_noinline_file_data(struct > erofs_compr_info *cinfo, > else > cross = end - start; > > - clusterofs = pos % PAGE_SIZE; > + clusterofs = pos % EROFS_BLKSIZE; > delta = 0; > > /* > @@ -508,7 +508,7 @@ int
[PATCH v2] erofs-utils: mkfs_erofs.h: clean up definitions
remove some duplicated definitions and keep these in line with kernel names. Signed-off-by: Gao Xiang --- v1 -> v2: - fix compilation erofs_cache.c | 11 --- erofs_io.c| 3 +-- mkfs_erofs.h | 24 ++-- mkfs_file.c | 4 ++-- mkfs_inode.c | 28 ++-- mkfs_main.c | 6 +++--- 6 files changed, 34 insertions(+), 42 deletions(-) diff --git a/erofs_cache.c b/erofs_cache.c index 5b80592..cfecd7f 100644 --- a/erofs_cache.c +++ b/erofs_cache.c @@ -45,10 +45,10 @@ u32 erofs_alloc_blocks(u32 nblocks) devlen = dev_length(); if (erofs_current_block > (u64)UINT32_MAX || erofs_current_block + nblocks > ((u64)UINT32_MAX) + 1 || - (erofs_current_block + nblocks) << EROFS_BLOCKSIZE_BITS > devlen) { + blknr_to_addr(erofs_current_block + nblocks) > devlen) { erofs_err("There is no enough free space(curr: %llu, need: %u, device blocks: %llu).", (unsigned long long)erofs_current_block, nblocks, - (unsigned long long)devlen >> EROFS_BLOCKSIZE_BITS); + (unsigned long long)erofs_blknr(devlen)); return 0; } @@ -143,7 +143,6 @@ int erofs_flush_all_blocks(void) char *pbuf; int count; int ret; - u32 addr; erofs_blk_buf = malloc(EROFS_BLKSIZE); if (!erofs_blk_buf) @@ -175,10 +174,8 @@ int erofs_flush_all_blocks(void) pbuf += count; } - addr = blk->bb_blkaddr; - - ret = dev_write( - erofs_blk_buf, BLKNO_TO_ADDR(addr), EROFS_BLKSIZE); + ret = dev_write(erofs_blk_buf, + blknr_to_addr(blk->bb_blkaddr), EROFS_BLKSIZE); if (ret) break; } diff --git a/erofs_io.c b/erofs_io.c index 8112ade..57e283e 100644 --- a/erofs_io.c +++ b/erofs_io.c @@ -155,8 +155,7 @@ int dev_write_block(void *buf, u32 blkaddr) { erofs_info("Write data to block %u", blkaddr); - return dev_write(buf, ((off64_t)blkaddr) << EROFS_BLOCKSIZE_BITS, -EROFS_BLKSIZE); + return dev_write(buf, blknr_to_addr(blkaddr), EROFS_BLKSIZE); } int dev_fsync(void) diff --git a/mkfs_erofs.h b/mkfs_erofs.h index be6305e..7fdc4c5 100644 --- a/mkfs_erofs.h +++ b/mkfs_erofs.h @@ -9,6 +9,7 @@ */ #ifndef __EROFS_MKFS_H #define __EROFS_MKFS_H + #include #include "list_head.h" #include "erofs_types.h" @@ -19,19 +20,11 @@ typedef unsigned int __u32; #include "erofs_fs.h" -#ifndef PAGE_SIZE -#define PAGE_SIZE (4096) -#endif - -#ifndef EROFS_BLKSIZE +#define LOG_BLOCK_SIZE (12) #define EROFS_BLKSIZE (4096) -#define EROFS_BLOCKSIZE_BITS(12) -#endif -#define EROFS_BLOCK_SIZE_SHIFT_BITS (12) #define EROFS_SLOTSIZE_BITS (5) #define EROFS_SLOTSIZE (32) -#define MKFS_DIFF_SHIFT_8_BITS (8) #define __round_mask(x, y) ((__typeof__(x))((y)-1)) #define round_up(x, y) x)-1) | __round_mask(x, y))+1) @@ -39,16 +32,19 @@ typedef unsigned int __u32; #define SIZE_ALIGN(val, size) (((val) + (size) - 1) & (~(size-1))) #define SLOT_ALIGN(slots) SIZE_ALIGN(slots, EROFS_SLOTSIZE) -#define PAGE_ALIGN(pages) SIZE_ALIGN(pages, PAGE_SIZE) #define BLK_ALIGN(blks) SIZE_ALIGN(blks, EROFS_BLKSIZE) #define IS_SLOT_ALIGN(__ADDR) (((__ADDR)%(EROFS_SLOTSIZE))?0:1) #define IS_BLK_ALIGN(__ADDR)(((__ADDR)%(EROFS_BLKSIZE))?0:1) -#define ADDR_TO_BLKNO(__ADDR) ((__ADDR) >> EROFS_BLOCKSIZE_BITS) -#define BLKNO_TO_ADDR(__ADDR) ((u64)(__ADDR) << EROFS_BLOCKSIZE_BITS) #define MAX_NID_INDEX_PER_BLK (EROFS_BLKSIZE / EROFS_SLOTSIZE) -#define EROFS_INODE_V1_SIZE sizeof(struct erofs_inode_v1) -#define EROFS_INODE_V2_SIZE sizeof(struct erofs_inode_v2) +typedef u64 erofs_off_t; + +/* data type for filesystem-wide blocks number */ +typedef u32 erofs_blk_t; + +#define erofs_blknr(addr) ((addr) / EROFS_BLKSIZE) +#define erofs_blkoff(addr) ((addr) % EROFS_BLKSIZE) +#define blknr_to_addr(nr) ((erofs_off_t)(nr) * EROFS_BLKSIZE) #define EROFS_DIRENT_SIZE sizeof(struct erofs_dirent) diff --git a/mkfs_file.c b/mkfs_file.c index 634208e..9aa62e2 100644 --- a/mkfs_file.c +++ b/mkfs_file.c @@ -437,7 +437,7 @@ static int erofs_compress_noinline_file_data(struct erofs_compr_info *cinfo, else cross = end - start; - clusterofs = pos % PAGE_SIZE; + clusterofs = pos % EROFS_BLKSIZE; delta = 0; /* @@ -508,7 +508,7 @@ int erofs_write_compress_data(struct erofs_compr_ctx *cctx) if (!blkaddr) return -ENOSPC; - ret = dev_write(cctx->cc_dstbuf, BLKNO_TO_ADDR(blkaddr), + ret = dev_write(cctx->cc_dstbuf, blknr_to_addr(blkaddr),