[PATCH] mkfs.ubifs: make failure to list extended attributes quiet and non-fatal

Pavel Roskin plroskin at gmail.com
Fri Oct 20 12:28:07 PDT 2017


mkfs.ubifs treats all errors returned by llistxattr() except ENOENT as
fatal. In particular, if the host system doesn't support extended
attributes, mkfs.ubifs would fail. It happens even without any flags that
would explicitly request extended attribute support.

As a result, it's impossible to build an OpenEmbedded based UBI image on
a system without extended attribute support if the xattr feature is
enabled in DISTRO_FEATURES.

Take a clue from mkfs.jffs2, which treats llistxattr() errors as
non-fatal and doesn't report them by default. Report the error at the
debug level 1 and higher.

The second llistxattr() error remains fatal, as it indicates unexpected
behavior.

Don't use goto before the buffer is allocated. Don't initialize buf with
NULL, it should not be used before the xmalloc() call.

Signed-off-by: Pavel Roskin <plroskin at gmail.com>
---
 ubifs-utils/mkfs.ubifs/mkfs.ubifs.c | 21 ++++++---------------
 1 file changed, 6 insertions(+), 15 deletions(-)

diff --git a/ubifs-utils/mkfs.ubifs/mkfs.ubifs.c b/ubifs-utils/mkfs.ubifs/mkfs.ubifs.c
index d432dfe..e390b5a 100644
--- a/ubifs-utils/mkfs.ubifs/mkfs.ubifs.c
+++ b/ubifs-utils/mkfs.ubifs/mkfs.ubifs.c
@@ -1122,22 +1122,17 @@ static int inode_add_xattr(struct ubifs_ino_node *host_ino,
 {
 	int ret;
 	struct qstr nm;
-	void *buf = NULL;
+	void *buf;
 	ssize_t len;
 	ssize_t pos = 0;
 
 	len = llistxattr(path_name, NULL, 0);
-	if (len < 0) {
-		if (errno == ENOENT)
-			return 0;
-
-		sys_err_msg("llistxattr failed on %s", path_name);
-
-		return len;
-	}
+	if (len < 0)
+		dbg_msg(1, "llistxattr('%s') = %d : %s\n", path_name,
+			errno, strerror(errno));
 
-	if (len == 0)
-		goto noxattr;
+	if (len <= 0)
+		return 0;
 
 	buf = xmalloc(len);
 
@@ -1191,10 +1186,6 @@ static int inode_add_xattr(struct ubifs_ino_node *host_ino,
 			goto out_free;
 	}
 
-noxattr:
-	free(buf);
-	return 0;
-
 out_free:
 	free(buf);
 
-- 
2.14.2




More information about the linux-mtd mailing list