From adf84611edcd9c349e3c5f0c8281272ea9431f9a Mon Sep 17 00:00:00 2001 From: Ryusuke Konishi Date: Tue, 13 Jan 2026 17:15:10 +0900 Subject: [PATCH] mount.nilfs2: fix error code handling in nilfs_do_mount_one() nilfs_do_mount_one() relies on the global variable 'errno' when mnt_context_do_mount() fails. However, mnt_context_do_mount() returns a positive errno for syscall errors and a negative error code for library errors. In the latter case, 'errno' is not guaranteed to be set correctly, potentially leading to incorrect error messages. Fix this by using the return value of mnt_context_do_mount() instead of 'errno'. Signed-off-by: Ryusuke Konishi --- sbin/mount/mount_libmount.c | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) diff --git a/sbin/mount/mount_libmount.c b/sbin/mount/mount_libmount.c index 5706f1b..d495f1e 100644 --- a/sbin/mount/mount_libmount.c +++ b/sbin/mount/mount_libmount.c @@ -379,14 +379,21 @@ static int nilfs_prepare_mount(struct nilfs_mount_info *mi) static int nilfs_do_mount_one(struct nilfs_mount_info *mi) { struct libmnt_context *cxt = mi->cxt; - int res, errsv; + int res, ec; res = mnt_context_do_mount(cxt); if (!res) goto out; - errsv = errno; - switch (errsv) { + /* + * mnt_context_do_mount() returns: + * 0: success + * > 0: syscall error (positive errno) + * < 0: library error (negative error code) + */ + ec = res < 0 ? -res : res; + + switch (ec) { case ENODEV: error(_("%s: cannot find or load %s filesystem"), progname, fstype); @@ -394,7 +401,7 @@ static int nilfs_do_mount_one(struct nilfs_mount_info *mi) default: error(_("%s: Error while mounting %s on %s: %s"), progname, mnt_context_get_source(cxt), - mnt_context_get_target(cxt), strerror(errsv)); + mnt_context_get_target(cxt), strerror(ec)); break; } if (mi->type != RW2RO_REMOUNT && mi->type != RW2RW_REMOUNT)