1 /* $NetBSD: vfs.c,v 1.8 2019/05/22 08:42:57 hannken Exp $ */ 2 3 /*- 4 * Copyright (c) 2006-2007 Pawel Jakub Dawidek <pjd@FreeBSD.org> 5 * All rights reserved. 6 * 7 * Redistribution and use in source and binary forms, with or without 8 * modification, are permitted provided that the following conditions 9 * are met: 10 * 1. Redistributions of source code must retain the above copyright 11 * notice, this list of conditions and the following disclaimer. 12 * 2. Redistributions in binary form must reproduce the above copyright 13 * notice, this list of conditions and the following disclaimer in the 14 * documentation and/or other materials provided with the distribution. 15 * 16 * THIS SOFTWARE IS PROVIDED BY THE AUTHORS AND CONTRIBUTORS ``AS IS'' AND 17 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 18 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 19 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHORS OR CONTRIBUTORS BE LIABLE 20 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 21 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 22 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 23 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 24 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 25 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 26 * SUCH DAMAGE. 27 */ 28 29 #include <sys/cdefs.h> 30 #define __FBSDID(x) 31 __FBSDID("$FreeBSD: head/sys/cddl/compat/opensolaris/kern/opensolaris_lookup.c 314194 2017-02-24 07:53:56Z avg $"); 32 33 #include <sys/param.h> 34 #include <sys/kernel.h> 35 #include <sys/systm.h> 36 #include <sys/mount.h> 37 #include <sys/cred.h> 38 #include <sys/vfs.h> 39 #include <sys/pathname.h> 40 #include <lib/libkern/libkern.h> 41 42 int 43 lookupname(char *dirname, enum uio_seg seg, enum symfollow follow, 44 vnode_t **dirvpp, vnode_t **compvpp) 45 { 46 int error; 47 48 KASSERT(seg == UIO_SYSSPACE); 49 KASSERT(dirvpp == NULL); 50 51 *compvpp = NULL; 52 error = namei_simple_kernel(dirname, 53 follow == FOLLOW ? NSM_FOLLOW_NOEMULROOT : NSM_NOFOLLOW_NOEMULROOT, 54 compvpp); 55 56 KASSERT(error == 0 || *compvpp == NULL); 57 58 return error; 59 } 60 61 void 62 vfs_setmntopt(vfs_t *vfsp, const char *name, const char *arg, 63 int flags) 64 { 65 66 if (strcmp("ro", name) == 0) 67 vfsp->mnt_flag |= MNT_RDONLY; 68 69 if (strcmp("rw", name) == 0) 70 vfsp->mnt_flag &= ~MNT_RDONLY; 71 72 if (strcmp("nodevices", name) == 0) 73 vfsp->mnt_flag |= MNT_NODEV; 74 75 if (strcmp("noatime", name) == 0) 76 vfsp->mnt_flag |= MNT_NOATIME; 77 78 if (strcmp("atime", name) == 0) 79 vfsp->mnt_flag &= ~MNT_NOATIME; 80 81 if (strcmp("nosuid", name) == 0) 82 vfsp->mnt_flag |= MNT_NOSUID; 83 84 if (strcmp("suid", name) == 0) 85 vfsp->mnt_flag &= ~MNT_NOSUID; 86 87 if (strcmp("noexec", name) == 0) 88 vfsp->mnt_flag |= MNT_NOEXEC; 89 90 if (strcmp("exec", name) == 0) 91 vfsp->mnt_flag &= ~MNT_NOEXEC; 92 93 vfsp->mnt_flag |= MNT_LOCAL; 94 } 95 96 void 97 vfs_clearmntopt(vfs_t *vfsp, const char *name) 98 { 99 100 if (strcmp("ro", name) == 0) 101 vfsp->mnt_flag |= MNT_RDONLY; 102 103 if (strcmp("rw", name) == 0) 104 vfsp->mnt_flag &= ~MNT_RDONLY; 105 106 if (strcmp("nodevices", name) == 0) 107 vfsp->mnt_flag &= ~MNT_NODEV; 108 109 if (strcmp("noatime", name) == 0) 110 vfsp->mnt_flag &= ~MNT_NOATIME; 111 112 if (strcmp("atime", name) == 0) 113 vfsp->mnt_flag |= MNT_NOATIME; 114 115 if (strcmp("nosuid", name) == 0) 116 vfsp->mnt_flag &= ~MNT_NOSUID; 117 118 if (strcmp("suid", name) == 0) 119 vfsp->mnt_flag |= MNT_NOSUID; 120 121 if (strcmp("noexec", name) == 0) 122 vfsp->mnt_flag &= ~MNT_NOEXEC; 123 124 if (strcmp("exec", name) == 0) 125 vfsp->mnt_flag |= MNT_NOEXEC; 126 } 127 128 int 129 vfs_optionisset(const vfs_t *vfsp, const char *name, char **argp) 130 { 131 132 if (strcmp("ro", name) == 0) 133 return (vfsp->mnt_flag & MNT_RDONLY) != 0; 134 135 if (strcmp("rw", name) == 0) 136 return (vfsp->mnt_flag & MNT_RDONLY) == 0; 137 138 if (strcmp("nodevices", name) == 0) 139 return (vfsp->mnt_flag & MNT_NODEV) != 0; 140 141 if (strcmp("noatime", name) == 0) 142 return (vfsp->mnt_flag & MNT_NOATIME) != 0; 143 144 if (strcmp("atime", name) == 0) 145 return (vfsp->mnt_flag & MNT_NOATIME) == 0; 146 147 if (strcmp("nosuid", name) == 0) 148 return (vfsp->mnt_flag & MNT_NOSUID) != 0; 149 150 if (strcmp("suid", name) == 0) 151 return (vfsp->mnt_flag & MNT_NOSUID) == 0; 152 153 if (strcmp("noexec", name) == 0) 154 return (vfsp->mnt_flag & MNT_NOEXEC) != 0; 155 156 if (strcmp("exec", name) == 0) 157 return (vfsp->mnt_flag & MNT_NOEXEC) == 0; 158 159 return 0; 160 } 161