From 3eed4803f943e2937325e81140b88e2e8eea8deb Mon Sep 17 00:00:00 2001 From: John Baldwin Date: Sat, 18 Nov 2023 11:08:34 -0800 Subject: [PATCH] vfs mount: Consistently use ENODEV internally for an invalid fstype Change vfs_byname_kld to always return an error value of ENODEV to indicate an unsupported fstype leaving ENOENT to indicate errors such as a missing mount point or invalid path. This allows nmount(2) to better distinguish these cases and avoid treating a missing device node as an invalid fstype after commit 6e8272f317b8. While here, change mount(2) to return EINVAL instead of ENODEV for an invalid fstype to match nmount(2). PR: 274600 Reviewed by: pstef, markj Differential Revision: https://reviews.freebsd.org/D42327 --- sys/kern/vfs_init.c | 4 +++- sys/kern/vfs_mount.c | 4 ++-- 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/sys/kern/vfs_init.c b/sys/kern/vfs_init.c index c57e1471e35..64263caaef9 100644 --- a/sys/kern/vfs_init.c +++ b/sys/kern/vfs_init.c @@ -149,8 +149,10 @@ vfs_byname_kld(const char *fstype, struct thread *td, int *error) loaded = (*error == 0); if (*error == EEXIST) *error = 0; - if (*error) + if (*error) { + *error = ENODEV; return (NULL); + } /* Look up again to see if the VFS was loaded. */ vfsp = vfs_byname(fstype); diff --git a/sys/kern/vfs_mount.c b/sys/kern/vfs_mount.c index 1a559bfd998..10b29b569cc 100644 --- a/sys/kern/vfs_mount.c +++ b/sys/kern/vfs_mount.c @@ -996,7 +996,7 @@ vfs_donmount(struct thread *td, uint64_t fsflags, struct uio *fsoptions) jail_export = false; error = vfs_domount(td, fstype, fspath, fsflags, jail_export, &optlist); - if (error == ENOENT) { + if (error == ENODEV) { error = EINVAL; if (errmsg != NULL) strncpy(errmsg, "Invalid fstype", errmsg_len); @@ -1086,7 +1086,7 @@ sys_mount(struct thread *td, struct mount_args *uap) vfsp = vfs_byname_kld(fstype, td, &error); free(fstype, M_TEMP); if (vfsp == NULL) - return (ENOENT); + return (EINVAL); if (((vfsp->vfc_flags & VFCF_SBDRY) != 0 && vfsp->vfc_vfsops_sd->vfs_cmount == NULL) || ((vfsp->vfc_flags & VFCF_SBDRY) == 0 && -- 2.45.0