Add kern_unmount() and use in Linuxulator. No functional changes.

Reviewed by:	kib
MFC after:	2 weeks
Sponsored by:	The FreeBSD Foundation
Differential Revision:	https://reviews.freebsd.org/D22646
This commit is contained in:
Edward Tomasz Napierala 2020-01-24 11:57:55 +00:00
parent 197f150c0c
commit b3fb13eb55
3 changed files with 22 additions and 14 deletions

View File

@ -1107,11 +1107,8 @@ out:
int
linux_oldumount(struct thread *td, struct linux_oldumount_args *args)
{
struct linux_umount_args args2;
args2.path = args->path;
args2.flags = 0;
return (linux_umount(td, &args2));
return (kern_unmount(td, args->path, 0));
}
#endif /* __i386__ || (__amd64__ && COMPAT_LINUX32) */
@ -1119,16 +1116,19 @@ linux_oldumount(struct thread *td, struct linux_oldumount_args *args)
int
linux_umount(struct thread *td, struct linux_umount_args *args)
{
struct unmount_args bsd;
int flags;
flags = 0;
if ((args->flags & LINUX_MNT_FORCE) != 0)
if ((args->flags & LINUX_MNT_FORCE) != 0) {
args->flags &= ~LINUX_MNT_FORCE;
flags |= MNT_FORCE;
}
if (args->flags != 0) {
linux_msg(td, "unsupported umount2 flags %#x", args->flags);
return (EINVAL);
}
bsd.path = args->path;
bsd.flags = flags;
return (sys_unmount(td, &bsd));
return (kern_unmount(td, args->path, flags));
}
#endif

View File

@ -1293,13 +1293,20 @@ struct unmount_args {
/* ARGSUSED */
int
sys_unmount(struct thread *td, struct unmount_args *uap)
{
return (kern_unmount(td, uap->path, uap->flags));
}
int
kern_unmount(struct thread *td, const char *path, int flags)
{
struct nameidata nd;
struct mount *mp;
char *pathbuf;
int error, id0, id1;
AUDIT_ARG_VALUE(uap->flags);
AUDIT_ARG_VALUE(flags);
if (jailed(td->td_ucred) || usermount == 0) {
error = priv_check(td, PRIV_VFS_UNMOUNT);
if (error)
@ -1307,12 +1314,12 @@ sys_unmount(struct thread *td, struct unmount_args *uap)
}
pathbuf = malloc(MNAMELEN, M_TEMP, M_WAITOK);
error = copyinstr(uap->path, pathbuf, MNAMELEN, NULL);
error = copyinstr(path, pathbuf, MNAMELEN, NULL);
if (error) {
free(pathbuf, M_TEMP);
return (error);
}
if (uap->flags & MNT_BYFSID) {
if (flags & MNT_BYFSID) {
AUDIT_ARG_TEXT(pathbuf);
/* Decode the filesystem ID. */
if (sscanf(pathbuf, "FSID:%d:%d", &id0, &id1) != 2) {
@ -1359,7 +1366,7 @@ sys_unmount(struct thread *td, struct unmount_args *uap)
* now, so in the !MNT_BYFSID case return the more likely
* EINVAL for compatibility.
*/
return ((uap->flags & MNT_BYFSID) ? ENOENT : EINVAL);
return ((flags & MNT_BYFSID) ? ENOENT : EINVAL);
}
/*
@ -1369,7 +1376,7 @@ sys_unmount(struct thread *td, struct unmount_args *uap)
vfs_rel(mp);
return (EINVAL);
}
error = dounmount(mp, uap->flags, td);
error = dounmount(mp, flags, td);
return (error);
}

View File

@ -315,6 +315,7 @@ int kern_wait6(struct thread *td, enum idtype idtype, id_t id, int *status,
int kern_writev(struct thread *td, int fd, struct uio *auio);
int kern_socketpair(struct thread *td, int domain, int type, int protocol,
int *rsv);
int kern_unmount(struct thread *td, const char *path, int flags);
/* flags for kern_sigaction */
#define KSA_OSIGSET 0x0001 /* uses osigact_t */