[mtd-utils] mkfs.ubifs: Fix xattr nlink value

Message ID 20180927093643.18097-1-s.hauer@pengutronix.de
State Accepted
Headers show
  • [mtd-utils] mkfs.ubifs: Fix xattr nlink value
Related show

Commit Message

Sascha Hauer Sept. 27, 2018, 9:36 a.m.
The nlink value of a xattr node must always be one, it has nothing to do
with the nlink value of the inode the attribute belongs to.

The bug can be observed when mounting a mkfs.ubifs generated image which
contains xattrs on directories or files with hardlinks to them. When
mounting such an image with chk_fs = 1 it fails with:

UBIFS error (ubi0:0 pid 1833): dbg_check_filesystem: inode 3308 nlink is 3, but calculated nlink is 1

Another bug that can be triggered is an assertion in
ubifs_xattr_remove() which assures that the xattr i_nlink count should
be one when the xattr is removed.

Fixes: 50044ef ("mkfs.ubifs: Add extended attribute support")

Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
 ubifs-utils/mkfs.ubifs/mkfs.ubifs.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)


David Oberhollenzer Oct. 2, 2018, 12:07 p.m. | #1
Applied to mtd-utils.git master.




diff --git a/ubifs-utils/mkfs.ubifs/mkfs.ubifs.c b/ubifs-utils/mkfs.ubifs/mkfs.ubifs.c
index f0518b9..845c9f5 100644
--- a/ubifs-utils/mkfs.ubifs/mkfs.ubifs.c
+++ b/ubifs-utils/mkfs.ubifs/mkfs.ubifs.c
@@ -1070,7 +1070,7 @@  static int add_xattr(struct stat *st, ino_t inum, const void *data,
 		goto out;
 	ino->creat_sqnum = cpu_to_le64(creat_sqnum);
-	ino->nlink      = cpu_to_le32(st->st_nlink);
+	ino->nlink      = cpu_to_le32(1);
 	 * The time fields are updated assuming the default time granularity
 	 * of 1 second. To support finer granularities, utime() would be needed.