mirror of
https://github.com/nilfs-dev/nilfs-utils.git
synced 2026-01-26 13:43:15 +00:00
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 <konishi.ryusuke@gmail.com>
This commit is contained in:
parent
7fd3a405ae
commit
adf84611ed
@ -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)
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user