Skip to contentSkip to conversation

erofs-utils: fix incorrect field conversions

PATCH Superseded Yifan Zhao 1 participant 2 messages Aug 27 – Aug 28 Library code

lore
Share & tools
lore

Yifan Zhao

author
#0 lore raw

PATCH 1/1 erofs-utils: fix incorrect field conversions

Assisted-by Codex:gpt-5.6-sol
---
 dump/main.c    | 4 ++--
 lib/compress.c | 4 ++--
 lib/gzran.c    | 4 ++--
 lib/inode.c    | 2 +-
 lib/namei.c    | 2 +-
 lib/super.c    | 2 +-
 6 files changed, 9 insertions(+), 9 deletions(-)
dump/main.c +2 -2
index 9eebcb8..28f104b 100644
@@ -694,7 +694,7 @@ static void erofsdump_show_superblock(void)
 	for (i = 0; i < ARRAY_SIZE(feature_lists); i++) {
 		if (!feature_lists[i].compat)
 			continue;
-		if (le32_to_cpu(g_sbi.feature_compat) & feature_lists[i].flag) {
+		if (g_sbi.feature_compat & feature_lists[i].flag) {
 			fprintf(stdout, "%s ", feature_lists[i].name);
 			if (feature_lists[i].lkver > minkver)
 				minkver = feature_lists[i].lkver;
@@ -704,7 +704,7 @@ static void erofsdump_show_superblock(void)
 	for (i = 0; i < ARRAY_SIZE(feature_lists); i++) {
 		if (feature_lists[i].compat)
 			continue;
-		if (le32_to_cpu(g_sbi.feature_incompat) & feature_lists[i].flag) {
+		if (g_sbi.feature_incompat & feature_lists[i].flag) {
 			fprintf(stdout, "%s ", feature_lists[i].name);
 			if (feature_lists[i].lkver > minkver)
 				minkver = feature_lists[i].lkver;
lib/compress.c +2 -2
index 9262afa..9bbb127 100644
@@ -2153,9 +2153,9 @@ static int z_erofs_build_compr_cfgs(struct erofs_importer *im,
 		} __packed zalg = {
 			.size = cpu_to_le16(sizeof(struct z_erofs_deflate_cfgs)),
 			.z = {
-				.windowbits = cpu_to_le32(ilog2(
+				.windowbits = ilog2(
 					max_dict_size
-						[Z_EROFS_COMPRESSION_DEFLATE])),
+						[Z_EROFS_COMPRESSION_DEFLATE]),
 			}
 		};
 
lib/gzran.c +2 -2
index 3973c1f..a75756c 100644
@@ -208,7 +208,7 @@ struct erofs_gzran_iostream {
 	struct erofs_vfile *vin;
 	struct erofs_gzran_cutpoint *cp;
 	u32 entries;
-	u32 span_size;
+	u64 span_size;
 };
 
 static void erofs_gzran_ios_vfclose(struct erofs_vfile *vf)
@@ -346,7 +346,7 @@ struct erofs_vfile *erofs_gzran_zinfo_open(struct erofs_vfile *vin,
 	ios = (struct erofs_gzran_iostream *)vf->payload;
 	h = zinfo_buf;
 	ios->entries = le32_to_cpu(h->have);
-	ios->span_size = le32_to_cpu(h->span_size);
+	ios->span_size = le64_to_cpu(h->span_size);
 
 	v2_size = sizeof(*c) * ios->entries + sizeof(*h);
 	if (!len || v2_size == len) {
lib/inode.c +1 -1
index 0547b60..a69439c 100644
@@ -851,7 +851,7 @@ int erofs_iflush(struct erofs_inode *inode)
 
 		u.dic.i_uid = cpu_to_le16((u16)inode->i_uid);
 		u.dic.i_gid = cpu_to_le16((u16)inode->i_gid);
-		u.dic.i_mtime = cpu_to_le64(inode->i_mtime - sbi->epoch);
+		u.dic.i_mtime = cpu_to_le32(inode->i_mtime - sbi->epoch);
 		u.dic.i_u = u1;
 
 		if (nlink_1) {
lib/namei.c +1 -1
index f19e4b1..9d04693 100644
@@ -96,7 +96,7 @@ int erofs_read_inode_from_disk(struct erofs_inode *vi)
 		vi->i_nlink = le32_to_cpu(die->i_nlink);
 
 		vi->i_mtime = le64_to_cpu(die->i_mtime);
-		vi->i_mtime_nsec = le64_to_cpu(die->i_mtime_nsec);
+		vi->i_mtime_nsec = le32_to_cpu(die->i_mtime_nsec);
 		vi->i_size = le64_to_cpu(die->i_size);
 		break;
 	case EROFS_INODE_LAYOUT_COMPACT:
lib/super.c +1 -1
index d138f84..e263f65 100644
@@ -212,7 +212,7 @@ int erofs_writesb(struct erofs_sb_info *sbi)
 		.rb.rootnid_2b  = cpu_to_le16(sbi->root_nid),
 		.inos      = cpu_to_le64(sbi->inos),
 		.epoch     = cpu_to_le64(sbi->epoch),
-		.build_time = cpu_to_le64(sbi->build_time),
+		.build_time = cpu_to_le32(sbi->build_time),
 		.fixed_nsec = cpu_to_le32(sbi->fixed_nsec),
 		.meta_blkaddr  = cpu_to_le32(sbi->meta_blkaddr),
 		.xattr_blkaddr = cpu_to_le32(sbi->xattr_blkaddr),
Signature · 1 line
2.55.0
author
#1 lore raw

PATCH v2 1/1 erofs-utils: fix incorrect field conversions

---
Changes since v1:
- v2 only adds the missing cpu_to_le16() conversion for the 16-bit startblk_hi field in lib/blobchunk.c.

 dump/main.c     | 4 ++--
 lib/blobchunk.c | 2 +-
 lib/compress.c  | 4 ++--
 lib/gzran.c     | 4 ++--
 lib/inode.c     | 2 +-
 lib/namei.c     | 2 +-
 lib/super.c     | 2 +-
 7 files changed, 10 insertions(+), 10 deletions(-)
dump/main.c +2 -2
index 9eebcb8..28f104b 100644
@@ -694,7 +694,7 @@ static void erofsdump_show_superblock(void)
 	for (i = 0; i < ARRAY_SIZE(feature_lists); i++) {
 		if (!feature_lists[i].compat)
 			continue;
-		if (le32_to_cpu(g_sbi.feature_compat) & feature_lists[i].flag) {
+		if (g_sbi.feature_compat & feature_lists[i].flag) {
 			fprintf(stdout, "%s ", feature_lists[i].name);
 			if (feature_lists[i].lkver > minkver)
 				minkver = feature_lists[i].lkver;
@@ -704,7 +704,7 @@ static void erofsdump_show_superblock(void)
 	for (i = 0; i < ARRAY_SIZE(feature_lists); i++) {
 		if (feature_lists[i].compat)
 			continue;
-		if (le32_to_cpu(g_sbi.feature_incompat) & feature_lists[i].flag) {
+		if (g_sbi.feature_incompat & feature_lists[i].flag) {
 			fprintf(stdout, "%s ", feature_lists[i].name);
 			if (feature_lists[i].lkver > minkver)
 				minkver = feature_lists[i].lkver;
lib/blobchunk.c +1 -1
index d307a4f..f969cf2 100644
@@ -245,7 +245,7 @@ int erofs_write_chunk_indexes(struct erofs_inode *inode, struct erofs_vfile *vf,
 		startblk &= addrmask;
 		idx.device_id = cpu_to_le16(chunk->device_id);
 		idx.startblk_lo = cpu_to_le32(startblk);
-		idx.startblk_hi = cpu_to_le32(startblk >> 32);
+		idx.startblk_hi = cpu_to_le16(startblk >> 32);
 		DBG_BUGON(!_48bit && idx.startblk_hi);
 
 		if (unit == EROFS_BLOCK_MAP_ENTRY_SIZE)
lib/compress.c +2 -2
index 9262afa..9bbb127 100644
@@ -2153,9 +2153,9 @@ static int z_erofs_build_compr_cfgs(struct erofs_importer *im,
 		} __packed zalg = {
 			.size = cpu_to_le16(sizeof(struct z_erofs_deflate_cfgs)),
 			.z = {
-				.windowbits = cpu_to_le32(ilog2(
+				.windowbits = ilog2(
 					max_dict_size
-						[Z_EROFS_COMPRESSION_DEFLATE])),
+						[Z_EROFS_COMPRESSION_DEFLATE]),
 			}
 		};
 
lib/gzran.c +2 -2
index 3973c1f..a75756c 100644
@@ -208,7 +208,7 @@ struct erofs_gzran_iostream {
 	struct erofs_vfile *vin;
 	struct erofs_gzran_cutpoint *cp;
 	u32 entries;
-	u32 span_size;
+	u64 span_size;
 };
 
 static void erofs_gzran_ios_vfclose(struct erofs_vfile *vf)
@@ -346,7 +346,7 @@ struct erofs_vfile *erofs_gzran_zinfo_open(struct erofs_vfile *vin,
 	ios = (struct erofs_gzran_iostream *)vf->payload;
 	h = zinfo_buf;
 	ios->entries = le32_to_cpu(h->have);
-	ios->span_size = le32_to_cpu(h->span_size);
+	ios->span_size = le64_to_cpu(h->span_size);
 
 	v2_size = sizeof(*c) * ios->entries + sizeof(*h);
 	if (!len || v2_size == len) {
lib/inode.c +1 -1
index 0547b60..a69439c 100644
@@ -851,7 +851,7 @@ int erofs_iflush(struct erofs_inode *inode)
 
 		u.dic.i_uid = cpu_to_le16((u16)inode->i_uid);
 		u.dic.i_gid = cpu_to_le16((u16)inode->i_gid);
-		u.dic.i_mtime = cpu_to_le64(inode->i_mtime - sbi->epoch);
+		u.dic.i_mtime = cpu_to_le32(inode->i_mtime - sbi->epoch);
 		u.dic.i_u = u1;
 
 		if (nlink_1) {
lib/namei.c +1 -1
index f19e4b1..9d04693 100644
@@ -96,7 +96,7 @@ int erofs_read_inode_from_disk(struct erofs_inode *vi)
 		vi->i_nlink = le32_to_cpu(die->i_nlink);
 
 		vi->i_mtime = le64_to_cpu(die->i_mtime);
-		vi->i_mtime_nsec = le64_to_cpu(die->i_mtime_nsec);
+		vi->i_mtime_nsec = le32_to_cpu(die->i_mtime_nsec);
 		vi->i_size = le64_to_cpu(die->i_size);
 		break;
 	case EROFS_INODE_LAYOUT_COMPACT:
lib/super.c +1 -1
index 25116fe..98e1711 100644
@@ -222,7 +222,7 @@ int erofs_writesb(struct erofs_sb_info *sbi)
 		.rb.rootnid_2b  = cpu_to_le16(sbi->root_nid),
 		.inos      = cpu_to_le64(sbi->inos),
 		.epoch     = cpu_to_le64(sbi->epoch),
-		.build_time = cpu_to_le64(sbi->build_time),
+		.build_time = cpu_to_le32(sbi->build_time),
 		.fixed_nsec = cpu_to_le32(sbi->fixed_nsec),
 		.meta_blkaddr  = cpu_to_le32(sbi->meta_blkaddr),
 		.xattr_blkaddr = cpu_to_le32(sbi->xattr_blkaddr),
Signature · 1 line
2.55.0