1 /* $NetBSD: vfs.c,v 1.7 2018/05/28 21:05:09 chs 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, vnode_t **dirvpp, vnode_t **compvpp) 44 { 45 return (lookupnameat(dirname, seg, follow, dirvpp, compvpp, NULL)); 46 } 47 48 int 49 lookupnameat(char *dirname, enum uio_seg seg, enum symfollow follow, 50 vnode_t **dirvpp, vnode_t **compvpp, vnode_t *startvp) 51 { 52 53 struct nameidata nd; 54 int error; 55 56 error = EOPNOTSUPP; 57 58 /* XXX Disable until I upgrade testing kernel. 59 KASSERT(dirvpp == NULL); 60 61 NDINIT(&nd, LOOKUP, FOLLOW, UIO_SYSSPACE, dirname); 62 63 if ((error = nameiat(&nd, startvp)) != 0) 64 return error; 65 66 *compvpp = nd.ni_vp;*/ 67 68 return (error); 69 } 70 71 72 void 73 vfs_setmntopt(vfs_t *vfsp, const char *name, const char *arg, 74 int flags) 75 { 76 77 if (strcmp("ro", name) == 0) 78 vfsp->mnt_flag |= MNT_RDONLY; 79 80 if (strcmp("rw", name) == 0) 81 vfsp->mnt_flag &= ~MNT_RDONLY; 82 83 if (strcmp("nodevices", name) == 0) 84 vfsp->mnt_flag |= MNT_NODEV; 85 86 if (strcmp("noatime", name) == 0) 87 vfsp->mnt_flag |= MNT_NOATIME; 88 89 if (strcmp("atime", name) == 0) 90 vfsp->mnt_flag &= ~MNT_NOATIME; 91 92 if (strcmp("nosuid", name) == 0) 93 vfsp->mnt_flag |= MNT_NOSUID; 94 95 if (strcmp("suid", name) == 0) 96 vfsp->mnt_flag &= ~MNT_NOSUID; 97 98 if (strcmp("noexec", name) == 0) 99 vfsp->mnt_flag |= MNT_NOEXEC; 100 101 if (strcmp("exec", name) == 0) 102 vfsp->mnt_flag &= ~MNT_NOEXEC; 103 104 vfsp->mnt_flag |= MNT_LOCAL; 105 } 106 107 void 108 vfs_clearmntopt(vfs_t *vfsp, const char *name) 109 { 110 111 if (strcmp("ro", name) == 0) 112 vfsp->mnt_flag |= MNT_RDONLY; 113 114 if (strcmp("rw", name) == 0) 115 vfsp->mnt_flag &= ~MNT_RDONLY; 116 117 if (strcmp("nodevices", name) == 0) 118 vfsp->mnt_flag &= ~MNT_NODEV; 119 120 if (strcmp("noatime", name) == 0) 121 vfsp->mnt_flag &= ~MNT_NOATIME; 122 123 if (strcmp("atime", name) == 0) 124 vfsp->mnt_flag |= MNT_NOATIME; 125 126 if (strcmp("nosuid", name) == 0) 127 vfsp->mnt_flag &= ~MNT_NOSUID; 128 129 if (strcmp("suid", name) == 0) 130 vfsp->mnt_flag |= MNT_NOSUID; 131 132 if (strcmp("noexec", name) == 0) 133 vfsp->mnt_flag &= ~MNT_NOEXEC; 134 135 if (strcmp("exec", name) == 0) 136 vfsp->mnt_flag |= MNT_NOEXEC; 137 } 138 139 int 140 vfs_optionisset(const vfs_t *vfsp, const char *name, char **argp) 141 { 142 143 if (strcmp("ro", name) == 0) 144 return (vfsp->mnt_flag & MNT_RDONLY) != 0; 145 146 if (strcmp("rw", name) == 0) 147 return (vfsp->mnt_flag & MNT_RDONLY) == 0; 148 149 if (strcmp("nodevices", name) == 0) 150 return (vfsp->mnt_flag & MNT_NODEV) != 0; 151 152 if (strcmp("noatime", name) == 0) 153 return (vfsp->mnt_flag & MNT_NOATIME) != 0; 154 155 if (strcmp("atime", name) == 0) 156 return (vfsp->mnt_flag & MNT_NOATIME) == 0; 157 158 if (strcmp("nosuid", name) == 0) 159 return (vfsp->mnt_flag & MNT_NOSUID) != 0; 160 161 if (strcmp("suid", name) == 0) 162 return (vfsp->mnt_flag & MNT_NOSUID) == 0; 163 164 if (strcmp("noexec", name) == 0) 165 return (vfsp->mnt_flag & MNT_NOEXEC) != 0; 166 167 if (strcmp("exec", name) == 0) 168 return (vfsp->mnt_flag & MNT_NOEXEC) == 0; 169 170 return 0; 171 } 172