1 /* $NetBSD: kernfs_vfsops.c,v 1.56 2003/09/27 13:29:02 darcy Exp $ */ 2 3 /* 4 * Copyright (c) 1992, 1993, 1995 5 * The Regents of the University of California. All rights reserved. 6 * 7 * This code is derived from software donated to Berkeley by 8 * Jan-Simon Pendry. 9 * 10 * Redistribution and use in source and binary forms, with or without 11 * modification, are permitted provided that the following conditions 12 * are met: 13 * 1. Redistributions of source code must retain the above copyright 14 * notice, this list of conditions and the following disclaimer. 15 * 2. Redistributions in binary form must reproduce the above copyright 16 * notice, this list of conditions and the following disclaimer in the 17 * documentation and/or other materials provided with the distribution. 18 * 3. Neither the name of the University nor the names of its contributors 19 * may be used to endorse or promote products derived from this software 20 * without specific prior written permission. 21 * 22 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND 23 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 24 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 25 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE 26 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 27 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 28 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 29 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 30 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 31 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 32 * SUCH DAMAGE. 33 * 34 * @(#)kernfs_vfsops.c 8.10 (Berkeley) 5/14/95 35 */ 36 37 /* 38 * Kernel params Filesystem 39 */ 40 41 #include <sys/cdefs.h> 42 __KERNEL_RCSID(0, "$NetBSD: kernfs_vfsops.c,v 1.56 2003/09/27 13:29:02 darcy Exp $"); 43 44 #ifdef _KERNEL_OPT 45 #include "opt_compat_netbsd.h" 46 #endif 47 48 #include <sys/param.h> 49 #include <sys/systm.h> 50 #include <sys/conf.h> 51 #include <sys/proc.h> 52 #include <sys/vnode.h> 53 #include <sys/mount.h> 54 #include <sys/namei.h> 55 #include <sys/malloc.h> 56 #include <sys/syslog.h> 57 58 #include <miscfs/specfs/specdev.h> 59 #include <miscfs/kernfs/kernfs.h> 60 61 MALLOC_DEFINE(M_KERNFSMNT, "kernfs mount", "kernfs mount structures"); 62 63 dev_t rrootdev = NODEV; 64 65 void kernfs_init __P((void)); 66 void kernfs_reinit __P((void)); 67 void kernfs_done __P((void)); 68 void kernfs_get_rrootdev __P((void)); 69 int kernfs_mount __P((struct mount *, const char *, void *, 70 struct nameidata *, struct proc *)); 71 int kernfs_start __P((struct mount *, int, struct proc *)); 72 int kernfs_unmount __P((struct mount *, int, struct proc *)); 73 int kernfs_statfs __P((struct mount *, struct statfs *, struct proc *)); 74 int kernfs_quotactl __P((struct mount *, int, uid_t, caddr_t, 75 struct proc *)); 76 int kernfs_sync __P((struct mount *, int, struct ucred *, struct proc *)); 77 int kernfs_vget __P((struct mount *, ino_t, struct vnode **)); 78 int kernfs_fhtovp __P((struct mount *, struct fid *, struct vnode **)); 79 int kernfs_checkexp __P((struct mount *, struct mbuf *, int *, 80 struct ucred **)); 81 int kernfs_vptofh __P((struct vnode *, struct fid *)); 82 int kernfs_sysctl __P((int *, u_int, void *, size_t *, void *, size_t, 83 struct proc *)); 84 85 void 86 kernfs_init() 87 { 88 #ifdef _LKM 89 malloc_type_attach(M_KERNFSMNT); 90 #endif 91 kernfs_hashinit(); 92 } 93 94 void 95 kernfs_reinit() 96 { 97 kernfs_hashreinit(); 98 } 99 100 void 101 kernfs_done() 102 { 103 #ifdef _LKM 104 malloc_type_detach(M_KERNFSMNT); 105 #endif 106 kernfs_hashdone(); 107 } 108 109 void 110 kernfs_get_rrootdev() 111 { 112 static int tried = 0; 113 114 if (tried) { 115 /* Already did it once. */ 116 return; 117 } 118 tried = 1; 119 120 if (rootdev == NODEV) 121 return; 122 rrootdev = devsw_blk2chr(rootdev); 123 if (rrootdev != NODEV) 124 return; 125 rrootdev = NODEV; 126 printf("kernfs_get_rrootdev: no raw root device\n"); 127 } 128 129 /* 130 * Mount the Kernel params filesystem 131 */ 132 int 133 kernfs_mount(mp, path, data, ndp, p) 134 struct mount *mp; 135 const char *path; 136 void *data; 137 struct nameidata *ndp; 138 struct proc *p; 139 { 140 int error = 0; 141 struct kernfs_mount *fmp; 142 143 if (UIO_MX & (UIO_MX - 1)) { 144 log(LOG_ERR, "kernfs: invalid directory entry size"); 145 return (EINVAL); 146 } 147 148 if (mp->mnt_flag & MNT_GETARGS) 149 return 0; 150 /* 151 * Update is a no-op 152 */ 153 if (mp->mnt_flag & MNT_UPDATE) 154 return (EOPNOTSUPP); 155 156 MALLOC(fmp, struct kernfs_mount *, sizeof(struct kernfs_mount), 157 M_KERNFSMNT, M_WAITOK); 158 memset(fmp, 0, sizeof(*fmp)); 159 TAILQ_INIT(&fmp->nodelist); 160 161 mp->mnt_data = fmp; 162 mp->mnt_flag |= MNT_LOCAL; 163 vfs_getnewfsid(mp); 164 165 error = set_statfs_info(path, UIO_USERSPACE, "kernfs", UIO_SYSSPACE, 166 mp, p); 167 168 kernfs_get_rrootdev(); 169 return error; 170 } 171 172 int 173 kernfs_start(mp, flags, p) 174 struct mount *mp; 175 int flags; 176 struct proc *p; 177 { 178 179 return (0); 180 } 181 182 int 183 kernfs_unmount(mp, mntflags, p) 184 struct mount *mp; 185 int mntflags; 186 struct proc *p; 187 { 188 int error; 189 int flags = 0; 190 191 if (mntflags & MNT_FORCE) 192 flags |= FORCECLOSE; 193 194 if ((error = vflush(mp, 0, flags)) != 0) 195 return (error); 196 197 /* 198 * Finally, throw away the kernfs_mount structure 199 */ 200 free(mp->mnt_data, M_KERNFSMNT); 201 mp->mnt_data = 0; 202 return (0); 203 } 204 205 int 206 kernfs_root(mp, vpp) 207 struct mount *mp; 208 struct vnode **vpp; 209 { 210 211 /* setup "." */ 212 return (kernfs_allocvp(mp, vpp, KFSkern, &kern_targets[0], 0)); 213 } 214 215 int 216 kernfs_quotactl(mp, cmd, uid, arg, p) 217 struct mount *mp; 218 int cmd; 219 uid_t uid; 220 caddr_t arg; 221 struct proc *p; 222 { 223 224 return (EOPNOTSUPP); 225 } 226 227 int 228 kernfs_statfs(mp, sbp, p) 229 struct mount *mp; 230 struct statfs *sbp; 231 struct proc *p; 232 { 233 234 sbp->f_bsize = DEV_BSIZE; 235 sbp->f_iosize = DEV_BSIZE; 236 sbp->f_blocks = 2; /* 1K to keep df happy */ 237 sbp->f_bfree = 0; 238 sbp->f_bavail = 0; 239 sbp->f_files = 1024; /* XXX lie */ 240 sbp->f_ffree = 128; /* XXX lie */ 241 #ifdef COMPAT_09 242 sbp->f_type = 7; 243 #else 244 sbp->f_type = 0; 245 #endif 246 copy_statfs_info(sbp, mp); 247 return (0); 248 } 249 250 /*ARGSUSED*/ 251 int 252 kernfs_sync(mp, waitfor, uc, p) 253 struct mount *mp; 254 int waitfor; 255 struct ucred *uc; 256 struct proc *p; 257 { 258 259 return (0); 260 } 261 262 /* 263 * Kernfs flat namespace lookup. 264 * Currently unsupported. 265 */ 266 int 267 kernfs_vget(mp, ino, vpp) 268 struct mount *mp; 269 ino_t ino; 270 struct vnode **vpp; 271 { 272 273 return (EOPNOTSUPP); 274 } 275 276 /*ARGSUSED*/ 277 int 278 kernfs_fhtovp(mp, fhp, vpp) 279 struct mount *mp; 280 struct fid *fhp; 281 struct vnode **vpp; 282 { 283 284 return (EOPNOTSUPP); 285 } 286 287 /*ARGSUSED*/ 288 int 289 kernfs_checkexp(mp, mb, what, anon) 290 struct mount *mp; 291 struct mbuf *mb; 292 int *what; 293 struct ucred **anon; 294 { 295 296 return (EOPNOTSUPP); 297 } 298 299 /*ARGSUSED*/ 300 int 301 kernfs_vptofh(vp, fhp) 302 struct vnode *vp; 303 struct fid *fhp; 304 { 305 306 return (EOPNOTSUPP); 307 } 308 309 int 310 kernfs_sysctl(name, namelen, oldp, oldlenp, newp, newlen, p) 311 int *name; 312 u_int namelen; 313 void *oldp; 314 size_t *oldlenp; 315 void *newp; 316 size_t newlen; 317 struct proc *p; 318 { 319 return (EOPNOTSUPP); 320 } 321 322 extern const struct vnodeopv_desc kernfs_vnodeop_opv_desc; 323 324 const struct vnodeopv_desc * const kernfs_vnodeopv_descs[] = { 325 &kernfs_vnodeop_opv_desc, 326 NULL, 327 }; 328 329 struct vfsops kernfs_vfsops = { 330 MOUNT_KERNFS, 331 kernfs_mount, 332 kernfs_start, 333 kernfs_unmount, 334 kernfs_root, 335 kernfs_quotactl, 336 kernfs_statfs, 337 kernfs_sync, 338 kernfs_vget, 339 kernfs_fhtovp, 340 kernfs_vptofh, 341 kernfs_init, 342 kernfs_reinit, 343 kernfs_done, 344 kernfs_sysctl, 345 NULL, /* vfs_mountroot */ 346 kernfs_checkexp, 347 kernfs_vnodeopv_descs, 348 }; 349