erofs: on-disk format should have explicitly assigned numbers
PATCH 1/2 erofs: on-disk format should have explicitly assigned numbers
As Christoph claimed [1], on-disk format should have explicitly assigned numbers.
[1] https://lore.kernel.org/r/[email protected]/
Reported-by Christoph Hellwig <[email protected]>
Signed-off-by Gao Xiang <[email protected]>
--- fs/erofs/erofs_fs.h | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-)
fs/erofs/erofs_fs.h +9 -9
@@ -52,10 +52,10 @@ struct erofs_super_block {* 4~7 - reserved */ enum { -EROFS_INODE_FLAT_PLAIN , -EROFS_INODE_FLAT_COMPRESSION_LEGACY , -EROFS_INODE_FLAT_INLINE , -EROFS_INODE_FLAT_COMPRESSION , +EROFS_INODE_FLAT_PLAIN =0 , +EROFS_INODE_FLAT_COMPRESSION_LEGACY =1 , +EROFS_INODE_FLAT_INLINE =2 , +EROFS_INODE_FLAT_COMPRESSION =3 ,EROFS_INODE_LAYOUT_MAX };
@@ -181,7 +181,7 @@ struct erofs_xattr_entry {/* available compression algorithm types */ enum { -Z_EROFS_COMPRESSION_LZ4 , +Z_EROFS_COMPRESSION_LZ4 =0 ,Z_EROFS_COMPRESSION_MAX };
@@ -239,10 +239,10 @@ struct z_erofs_map_header {* (di_advise could be 0, 1 or 2) */ enum { -Z_EROFS_VLE_CLUSTER_TYPE_PLAIN , -Z_EROFS_VLE_CLUSTER_TYPE_HEAD , -Z_EROFS_VLE_CLUSTER_TYPE_NONHEAD , -Z_EROFS_VLE_CLUSTER_TYPE_RESERVED , +Z_EROFS_VLE_CLUSTER_TYPE_PLAIN =0 , +Z_EROFS_VLE_CLUSTER_TYPE_HEAD =1 , +Z_EROFS_VLE_CLUSTER_TYPE_NONHEAD =2 , +Z_EROFS_VLE_CLUSTER_TYPE_RESERVED =3 ,Z_EROFS_VLE_CLUSTER_TYPE_MAX };
Signature · 1 line
2.17.1
PATCH 2/2 erofs: some marcos are much more readable as a function
As Christoph suggested [1], these marcos are much
more readable as a function.
[1] https://lore.kernel.org/r/[email protected]/
Reported-by Christoph Hellwig <[email protected]>
Signed-off-by Gao Xiang <[email protected]>
--- fs/erofs/erofs_fs.h | 24 ++++++++++++++++-------- fs/erofs/inode.c | 4 ++-- fs/erofs/xattr.c | 2 +- 3 files changed, 19 insertions(+), 11 deletions(-)
fs/erofs/erofs_fs.h +16 -8
@@ -168,16 +168,24 @@ struct erofs_xattr_entry {char e_name[0 ];/* attribute name */ } __packed; -#define ondisk_xattr_ibody_size (count) ({\ - u32 __count = le16_to_cpu(count); \ - ((__count) == 0) ? 0 : \ - sizeof(struct erofs_xattr_ibody_header) + \ - sizeof(__u32) * ((__count) - 1); }) +static inline unsigned int erofs_xattr_ibody_size (__le16 d_icount) +{ +unsigned int icount =le16_to_cpu (d_icount); + +if (!icount) +return 0 ; + +return sizeof (struct erofs_xattr_ibody_header ) + +sizeof (__u32) * (icount -1 ); +}#define EROFS_XATTR_ALIGN (size) round_up(size, sizeof(struct erofs_xattr_entry)) -#define EROFS_XATTR_ENTRY_SIZE (entry) EROFS_XATTR_ALIGN( \ - sizeof(struct erofs_xattr_entry) + \ - (entry)->e_name_len + le16_to_cpu((entry)->e_value_size)) + +static inline unsigned int erofs_xattr_entry_size (struct erofs_xattr_entry *e) +{ +return EROFS_XATTR_ALIGN (sizeof (struct erofs_xattr_entry ) + + e->e_name_len +le16_to_cpu (e->e_value_size)); +}/* available compression algorithm types */ enum {
fs/erofs/inode.c +2 -2
@@ -29,7 +29,7 @@ static int read_inode(struct inode *inode, void *data)struct erofs_inode_v2 *v2 = data; vi->inode_isize =sizeof (struct erofs_inode_v2 ); - vi->xattr_isize =ondisk_xattr_ibody_size (v2->i_xattr_icount); + vi->xattr_isize =erofs_xattr_ibody_size (v2->i_xattr_icount); inode->i_mode =le16_to_cpu (v2->i_mode); if (S_ISREG(inode->i_mode) || S_ISDIR(inode->i_mode) ||
@@ -62,7 +62,7 @@ static int read_inode(struct inode *inode, void *data)struct erofs_sb_info *sbi =EROFS_SB (inode->i_sb); vi->inode_isize =sizeof (struct erofs_inode_v1 ); - vi->xattr_isize =ondisk_xattr_ibody_size (v1->i_xattr_icount); + vi->xattr_isize =erofs_xattr_ibody_size (v1->i_xattr_icount); inode->i_mode =le16_to_cpu (v1->i_mode); if (S_ISREG(inode->i_mode) || S_ISDIR(inode->i_mode) ||
fs/erofs/xattr.c +1 -1
@@ -231,7 +231,7 @@ static int xattr_foreach(struct xattr_iter *it,*/ entry = *(struct erofs_xattr_entry *)(it->kaddr + it->ofs);if (tlimit) { -unsigned int entry_sz =EROFS_XATTR_ENTRY_SIZE (&entry); +unsigned int entry_sz =erofs_xattr_entry_size (&entry);/* xattr on-disk corruption: xattr entry beyond xattr_isize */ if (unlikely (*tlimit < entry_sz)) {
Signature · 1 line
2.17.1