Skip to contentSkip to conversation

erofs-utils: fix incorrect i_nlink in the unified rebuild logic

PATCH New Gao Xiang 1 participant 1 message Jun 13, 2024 Library code

lore
Share & tools
lore

Gao Xiang

author
#0 lore raw

PATCH 1/1 erofs-utils: fix incorrect i_nlink in the unified rebuild logic

Fixes 203c847cc7d1 ("erofs-utils: unify the tree traversal for the rebuild mode")
---
 lib/inode.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)
lib/inode.c +3 -1
index 7d4ccc4..9219759 100644
@@ -1386,7 +1386,7 @@ static int erofs_rebuild_handle_directory(struct erofs_inode *dir)
 	int ret;
 
 	nr_subdirs = 0;
-	i_nlink = 2;
+	i_nlink = 0;
 	list_for_each_entry_safe(d, n, &dir->i_subdirs, d_child) {
 		if (cfg.c_ovlfs_strip && erofs_inode_is_whiteout(d->inode)) {
 			erofs_dbg("remove whiteout %s", d->inode->i_srcpath);
@@ -1399,6 +1399,8 @@ static int erofs_rebuild_handle_directory(struct erofs_inode *dir)
 		++nr_subdirs;
 	}
 
+	DBG_BUGON(i_nlink < 2);		/* should have `.` and `..` */
+	DBG_BUGON(nr_subdirs < i_nlink);
 	ret = erofs_prepare_dir_layout(dir, nr_subdirs);
 	if (ret)
 		return ret;
Signature · 1 line
2.39.3