1 1.50 christos /* $NetBSD: filecore_vnops.c,v 1.50 2022/03/27 17:10:55 christos Exp $ */ 2 1.1 jdolecek 3 1.1 jdolecek /*- 4 1.1 jdolecek * Copyright (c) 1994 The Regents of the University of California. 5 1.1 jdolecek * All rights reserved. 6 1.1 jdolecek * 7 1.1 jdolecek * Redistribution and use in source and binary forms, with or without 8 1.1 jdolecek * modification, are permitted provided that the following conditions 9 1.1 jdolecek * are met: 10 1.1 jdolecek * 1. Redistributions of source code must retain the above copyright 11 1.1 jdolecek * notice, this list of conditions and the following disclaimer. 12 1.1 jdolecek * 2. Redistributions in binary form must reproduce the above copyright 13 1.1 jdolecek * notice, this list of conditions and the following disclaimer in the 14 1.1 jdolecek * documentation and/or other materials provided with the distribution. 15 1.6 agc * 3. Neither the name of the University nor the names of its contributors 16 1.6 agc * may be used to endorse or promote products derived from this software 17 1.6 agc * without specific prior written permission. 18 1.6 agc * 19 1.6 agc * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND 20 1.6 agc * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 21 1.6 agc * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 22 1.6 agc * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE 23 1.6 agc * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 24 1.6 agc * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 25 1.6 agc * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 26 1.6 agc * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 27 1.6 agc * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 28 1.6 agc * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 29 1.6 agc * SUCH DAMAGE. 30 1.6 agc * 31 1.6 agc * filecore_vnops.c 1.2 1998/8/18 32 1.6 agc */ 33 1.6 agc 34 1.6 agc /*- 35 1.6 agc * Copyright (c) 1998 Andrew McMurry 36 1.6 agc * 37 1.6 agc * Redistribution and use in source and binary forms, with or without 38 1.6 agc * modification, are permitted provided that the following conditions 39 1.6 agc * are met: 40 1.6 agc * 1. Redistributions of source code must retain the above copyright 41 1.6 agc * notice, this list of conditions and the following disclaimer. 42 1.6 agc * 2. Redistributions in binary form must reproduce the above copyright 43 1.6 agc * notice, this list of conditions and the following disclaimer in the 44 1.6 agc * documentation and/or other materials provided with the distribution. 45 1.1 jdolecek * 3. All advertising materials mentioning features or use of this software 46 1.1 jdolecek * must display the following acknowledgement: 47 1.1 jdolecek * This product includes software developed by the University of 48 1.1 jdolecek * California, Berkeley and its contributors. 49 1.1 jdolecek * 4. Neither the name of the University nor the names of its contributors 50 1.1 jdolecek * may be used to endorse or promote products derived from this software 51 1.1 jdolecek * without specific prior written permission. 52 1.1 jdolecek * 53 1.1 jdolecek * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND 54 1.1 jdolecek * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 55 1.1 jdolecek * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 56 1.1 jdolecek * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE 57 1.1 jdolecek * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 58 1.1 jdolecek * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 59 1.1 jdolecek * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 60 1.1 jdolecek * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 61 1.1 jdolecek * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 62 1.1 jdolecek * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 63 1.1 jdolecek * SUCH DAMAGE. 64 1.1 jdolecek * 65 1.1 jdolecek * filecore_vnops.c 1.2 1998/8/18 66 1.1 jdolecek */ 67 1.1 jdolecek 68 1.1 jdolecek #include <sys/cdefs.h> 69 1.50 christos __KERNEL_RCSID(0, "$NetBSD: filecore_vnops.c,v 1.50 2022/03/27 17:10:55 christos Exp $"); 70 1.1 jdolecek 71 1.1 jdolecek #include <sys/param.h> 72 1.1 jdolecek #include <sys/systm.h> 73 1.1 jdolecek #include <sys/namei.h> 74 1.1 jdolecek #include <sys/resourcevar.h> 75 1.1 jdolecek #include <sys/kernel.h> 76 1.1 jdolecek #include <sys/file.h> 77 1.1 jdolecek #include <sys/stat.h> 78 1.1 jdolecek #include <sys/buf.h> 79 1.1 jdolecek #include <sys/proc.h> 80 1.1 jdolecek #include <sys/conf.h> 81 1.1 jdolecek #include <sys/mount.h> 82 1.1 jdolecek #include <sys/vnode.h> 83 1.1 jdolecek #include <sys/malloc.h> 84 1.1 jdolecek #include <sys/dirent.h> 85 1.18 christos #include <sys/kauth.h> 86 1.1 jdolecek 87 1.1 jdolecek #include <miscfs/genfs/genfs.h> 88 1.1 jdolecek #include <miscfs/specfs/specdev.h> 89 1.1 jdolecek 90 1.1 jdolecek #include <fs/filecorefs/filecore.h> 91 1.1 jdolecek #include <fs/filecorefs/filecore_extern.h> 92 1.1 jdolecek #include <fs/filecorefs/filecore_node.h> 93 1.1 jdolecek 94 1.32 elad static int 95 1.32 elad filecore_check_possible(struct vnode *vp, struct filecore_node *ip, 96 1.32 elad mode_t mode) 97 1.32 elad { 98 1.32 elad 99 1.32 elad /* 100 1.32 elad * Disallow write attempts unless the file is a socket, 101 1.32 elad * fifo, or a block or character device resident on the 102 1.32 elad * file system. 103 1.32 elad */ 104 1.32 elad if (mode & VWRITE) { 105 1.32 elad switch (vp->v_type) { 106 1.32 elad case VDIR: 107 1.32 elad case VLNK: 108 1.32 elad case VREG: 109 1.32 elad return (EROFS); 110 1.32 elad default: 111 1.32 elad break; 112 1.32 elad } 113 1.32 elad } 114 1.32 elad 115 1.32 elad return 0; 116 1.32 elad } 117 1.32 elad 118 1.1 jdolecek /* 119 1.1 jdolecek * Check mode permission on inode pointer. Mode is READ, WRITE or EXEC. 120 1.1 jdolecek * The mode is shifted to select the owner/group/other fields. The 121 1.1 jdolecek * super user is granted all permissions. 122 1.1 jdolecek */ 123 1.32 elad static int 124 1.32 elad filecore_check_permitted(struct vnode *vp, struct filecore_node *ip, 125 1.46 christos accmode_t accmode, kauth_cred_t cred) 126 1.32 elad { 127 1.32 elad struct filecore_mnt *fcmp = ip->i_mnt; 128 1.32 elad 129 1.46 christos return kauth_authorize_vnode(cred, KAUTH_ACCESS_ACTION(accmode, 130 1.34 elad vp->v_type, filecore_mode(ip)), vp, NULL, 131 1.46 christos genfs_can_access(vp, cred, fcmp->fc_uid, fcmp->fc_gid, 132 1.46 christos filecore_mode(ip), NULL, accmode)); 133 1.32 elad } 134 1.32 elad 135 1.1 jdolecek int 136 1.30 dsl filecore_access(void *v) 137 1.1 jdolecek { 138 1.1 jdolecek struct vop_access_args /* { 139 1.1 jdolecek struct vnode *a_vp; 140 1.46 christos accmode_t a_accmode; 141 1.17 elad kauth_cred_t a_cred; 142 1.1 jdolecek } */ *ap = v; 143 1.1 jdolecek struct vnode *vp = ap->a_vp; 144 1.1 jdolecek struct filecore_node *ip = VTOI(vp); 145 1.32 elad int error; 146 1.32 elad 147 1.46 christos error = filecore_check_possible(vp, ip, ap->a_accmode); 148 1.32 elad if (error) 149 1.32 elad return error; 150 1.1 jdolecek 151 1.46 christos error = filecore_check_permitted(vp, ip, ap->a_accmode, ap->a_cred); 152 1.1 jdolecek 153 1.32 elad return error; 154 1.1 jdolecek } 155 1.1 jdolecek 156 1.1 jdolecek int 157 1.30 dsl filecore_getattr(void *v) 158 1.1 jdolecek { 159 1.1 jdolecek struct vop_getattr_args /* { 160 1.1 jdolecek struct vnode *a_vp; 161 1.1 jdolecek struct vattr *a_vap; 162 1.17 elad kauth_cred_t a_cred; 163 1.1 jdolecek } */ *ap = v; 164 1.1 jdolecek struct vnode *vp = ap->a_vp; 165 1.1 jdolecek struct filecore_node *ip = VTOI(vp); 166 1.1 jdolecek struct vattr *vap = ap->a_vap; 167 1.1 jdolecek struct filecore_mnt *fcmp = ip->i_mnt; 168 1.1 jdolecek 169 1.1 jdolecek vap->va_fsid = ip->i_dev; 170 1.1 jdolecek vap->va_fileid = ip->i_number; 171 1.1 jdolecek 172 1.1 jdolecek vap->va_mode = filecore_mode(ip); 173 1.1 jdolecek vap->va_nlink = 1; 174 1.1 jdolecek vap->va_uid = fcmp->fc_uid; 175 1.1 jdolecek vap->va_gid = fcmp->fc_gid; 176 1.1 jdolecek vap->va_atime = filecore_time(ip); 177 1.1 jdolecek vap->va_mtime = filecore_time(ip); 178 1.1 jdolecek vap->va_ctime = filecore_time(ip); 179 1.1 jdolecek vap->va_rdev = 0; /* We don't support specials */ 180 1.1 jdolecek 181 1.1 jdolecek vap->va_size = (u_quad_t) ip->i_size; 182 1.1 jdolecek vap->va_flags = 0; 183 1.1 jdolecek vap->va_gen = 1; 184 1.1 jdolecek vap->va_blocksize = fcmp->blksize; 185 1.1 jdolecek vap->va_bytes = vap->va_size; 186 1.1 jdolecek vap->va_type = vp->v_type; 187 1.1 jdolecek return (0); 188 1.1 jdolecek } 189 1.1 jdolecek 190 1.1 jdolecek /* 191 1.1 jdolecek * Vnode op for reading. 192 1.1 jdolecek */ 193 1.1 jdolecek int 194 1.30 dsl filecore_read(void *v) 195 1.1 jdolecek { 196 1.1 jdolecek struct vop_read_args /* { 197 1.1 jdolecek struct vnode *a_vp; 198 1.1 jdolecek struct uio *a_uio; 199 1.1 jdolecek int a_ioflag; 200 1.17 elad kauth_cred_t a_cred; 201 1.1 jdolecek } */ *ap = v; 202 1.1 jdolecek struct vnode *vp = ap->a_vp; 203 1.1 jdolecek struct uio *uio = ap->a_uio; 204 1.1 jdolecek struct filecore_node *ip = VTOI(vp); 205 1.1 jdolecek struct filecore_mnt *fcmp; 206 1.1 jdolecek struct buf *bp; 207 1.39 christos daddr_t lbn; 208 1.1 jdolecek off_t diff; 209 1.1 jdolecek int error = 0; 210 1.1 jdolecek long size, n, on; 211 1.1 jdolecek 212 1.1 jdolecek if (uio->uio_resid == 0) 213 1.1 jdolecek return (0); 214 1.1 jdolecek if (uio->uio_offset < 0) 215 1.1 jdolecek return (EINVAL); 216 1.1 jdolecek if (uio->uio_offset >= ip->i_size) 217 1.1 jdolecek return (0); 218 1.1 jdolecek ip->i_flag |= IN_ACCESS; 219 1.1 jdolecek fcmp = ip->i_mnt; 220 1.1 jdolecek 221 1.1 jdolecek if (vp->v_type == VREG) { 222 1.15 yamt const int advice = IO_ADV_DECODE(ap->a_ioflag); 223 1.1 jdolecek error = 0; 224 1.15 yamt 225 1.1 jdolecek while (uio->uio_resid > 0) { 226 1.1 jdolecek vsize_t bytelen = MIN(ip->i_size - uio->uio_offset, 227 1.1 jdolecek uio->uio_resid); 228 1.1 jdolecek 229 1.1 jdolecek if (bytelen == 0) { 230 1.1 jdolecek break; 231 1.1 jdolecek } 232 1.28 pooka error = ubc_uiomove(&vp->v_uobj, uio, bytelen, advice, 233 1.45 ad UBC_READ | UBC_PARTIALOK | UBC_VNODE_FLAGS(vp)); 234 1.1 jdolecek if (error) { 235 1.1 jdolecek break; 236 1.1 jdolecek } 237 1.1 jdolecek } 238 1.1 jdolecek goto out; 239 1.1 jdolecek } 240 1.1 jdolecek 241 1.1 jdolecek do { 242 1.38 dholland lbn = filecore_lblkno(fcmp, uio->uio_offset); 243 1.37 dholland on = filecore_blkoff(fcmp, uio->uio_offset); 244 1.37 dholland n = MIN(filecore_blksize(fcmp, ip, lbn) - on, uio->uio_resid); 245 1.1 jdolecek diff = (off_t)ip->i_size - uio->uio_offset; 246 1.1 jdolecek if (diff <= 0) 247 1.1 jdolecek return (0); 248 1.1 jdolecek if (diff < n) 249 1.1 jdolecek n = diff; 250 1.37 dholland size = filecore_blksize(fcmp, ip, lbn); 251 1.1 jdolecek if (ip->i_dirent.attr & FILECORE_ATTR_DIR) { 252 1.1 jdolecek error = filecore_dbread(ip, &bp); 253 1.1 jdolecek on = uio->uio_offset; 254 1.1 jdolecek n = MIN(FILECORE_DIR_SIZE - on, uio->uio_resid); 255 1.1 jdolecek size = FILECORE_DIR_SIZE; 256 1.1 jdolecek } else { 257 1.43 maxv error = bread(vp, lbn, size, 0, &bp); 258 1.1 jdolecek #ifdef FILECORE_DEBUG_BR 259 1.26 ad printf("bread(%p, %llx, %ld, CRED, %p)=%d\n", 260 1.26 ad vp, (long long)lbn, size, bp, error); 261 1.1 jdolecek #endif 262 1.1 jdolecek } 263 1.1 jdolecek if (error) { 264 1.1 jdolecek return (error); 265 1.1 jdolecek } 266 1.35 hannken n = MIN(n, size - bp->b_resid); 267 1.1 jdolecek 268 1.19 jnemeth error = uiomove((char *)(bp->b_data) + on, (int)n, uio); 269 1.1 jdolecek #ifdef FILECORE_DEBUG_BR 270 1.1 jdolecek printf("brelse(%p) vn2\n", bp); 271 1.1 jdolecek #endif 272 1.23 ad brelse(bp, 0); 273 1.1 jdolecek } while (error == 0 && uio->uio_resid > 0 && n != 0); 274 1.1 jdolecek 275 1.1 jdolecek out: 276 1.1 jdolecek return (error); 277 1.1 jdolecek } 278 1.1 jdolecek 279 1.1 jdolecek /* 280 1.1 jdolecek * Vnode op for readdir 281 1.1 jdolecek */ 282 1.1 jdolecek int 283 1.30 dsl filecore_readdir(void *v) 284 1.1 jdolecek { 285 1.1 jdolecek struct vop_readdir_args /* { 286 1.1 jdolecek struct vnode *a_vp; 287 1.1 jdolecek struct uio *a_uio; 288 1.17 elad kauth_cred_t a_cred; 289 1.1 jdolecek int *a_eofflag; 290 1.1 jdolecek off_t **a_cookies; 291 1.1 jdolecek int *a_ncookies; 292 1.1 jdolecek } */ *ap = v; 293 1.1 jdolecek struct uio *uio = ap->a_uio; 294 1.1 jdolecek struct vnode *vdp = ap->a_vp; 295 1.1 jdolecek struct filecore_node *dp; 296 1.1 jdolecek struct buf *bp = NULL; 297 1.22 rumble struct dirent *de; 298 1.1 jdolecek struct filecore_direntry *dep = NULL; 299 1.1 jdolecek int error = 0; 300 1.1 jdolecek off_t *cookies = NULL; 301 1.1 jdolecek int ncookies = 0; 302 1.1 jdolecek int i; 303 1.1 jdolecek off_t uiooff; 304 1.1 jdolecek 305 1.1 jdolecek dp = VTOI(vdp); 306 1.1 jdolecek 307 1.1 jdolecek if ((dp->i_dirent.attr & FILECORE_ATTR_DIR) == 0) 308 1.1 jdolecek return (ENOTDIR); 309 1.1 jdolecek 310 1.1 jdolecek if (uio->uio_offset % FILECORE_DIRENT_SIZE != 0) 311 1.1 jdolecek return (EINVAL); 312 1.1 jdolecek i = uio->uio_offset / FILECORE_DIRENT_SIZE; 313 1.1 jdolecek uiooff = uio->uio_offset; 314 1.1 jdolecek 315 1.1 jdolecek *ap->a_eofflag = 0; 316 1.1 jdolecek 317 1.1 jdolecek error = filecore_dbread(dp, &bp); 318 1.1 jdolecek if (error) { 319 1.1 jdolecek return error; 320 1.1 jdolecek } 321 1.1 jdolecek 322 1.1 jdolecek if (ap->a_ncookies == NULL) 323 1.1 jdolecek cookies = NULL; 324 1.1 jdolecek else { 325 1.1 jdolecek *ap->a_ncookies = 0; 326 1.21 rumble ncookies = uio->uio_resid / _DIRENT_MINSIZE((struct dirent *)0); 327 1.1 jdolecek cookies = malloc(ncookies * sizeof(off_t), M_TEMP, M_WAITOK); 328 1.1 jdolecek } 329 1.1 jdolecek 330 1.33 rmind de = kmem_zalloc(sizeof(struct dirent), KM_SLEEP); 331 1.22 rumble 332 1.1 jdolecek for (; ; i++) { 333 1.1 jdolecek switch (i) { 334 1.1 jdolecek case 0: 335 1.1 jdolecek /* Fake the '.' entry */ 336 1.22 rumble de->d_fileno = dp->i_number; 337 1.22 rumble de->d_type = DT_DIR; 338 1.22 rumble de->d_namlen = 1; 339 1.22 rumble strlcpy(de->d_name, ".", sizeof(de->d_name)); 340 1.1 jdolecek break; 341 1.1 jdolecek case 1: 342 1.1 jdolecek /* Fake the '..' entry */ 343 1.22 rumble de->d_fileno = filecore_getparent(dp); 344 1.22 rumble de->d_type = DT_DIR; 345 1.22 rumble de->d_namlen = 2; 346 1.22 rumble strlcpy(de->d_name, "..", sizeof(de->d_name)); 347 1.1 jdolecek break; 348 1.1 jdolecek default: 349 1.22 rumble de->d_fileno = dp->i_dirent.addr + 350 1.1 jdolecek ((i - 2) << FILECORE_INO_INDEX); 351 1.1 jdolecek dep = fcdirentry(bp->b_data, i - 2); 352 1.1 jdolecek if (dep->attr & FILECORE_ATTR_DIR) 353 1.22 rumble de->d_type = DT_DIR; 354 1.1 jdolecek else 355 1.22 rumble de->d_type = DT_REG; 356 1.22 rumble if (filecore_fn2unix(dep->name, de->d_name, 357 1.13 christos /*###346 [cc] warning: passing arg 3 of `filecore_fn2unix' from incompatible pointer type%%%*/ 358 1.22 rumble &de->d_namlen)) { 359 1.1 jdolecek *ap->a_eofflag = 1; 360 1.1 jdolecek goto out; 361 1.1 jdolecek } 362 1.1 jdolecek break; 363 1.1 jdolecek } 364 1.22 rumble de->d_reclen = _DIRENT_SIZE(de); 365 1.22 rumble if (uio->uio_resid < de->d_reclen) 366 1.1 jdolecek goto out; 367 1.22 rumble error = uiomove(de, de->d_reclen, uio); 368 1.1 jdolecek if (error) 369 1.1 jdolecek goto out; 370 1.1 jdolecek uiooff += FILECORE_DIRENT_SIZE; 371 1.1 jdolecek 372 1.1 jdolecek if (cookies) { 373 1.1 jdolecek *cookies++ = i*FILECORE_DIRENT_SIZE; 374 1.1 jdolecek (*ap->a_ncookies)++; 375 1.1 jdolecek if (--ncookies == 0) goto out; 376 1.1 jdolecek } 377 1.1 jdolecek } 378 1.1 jdolecek out: 379 1.1 jdolecek if (cookies) { 380 1.1 jdolecek *ap->a_cookies = cookies; 381 1.1 jdolecek if (error) { 382 1.1 jdolecek free(cookies, M_TEMP); 383 1.1 jdolecek *ap->a_ncookies = 0; 384 1.1 jdolecek *ap->a_cookies = NULL; 385 1.1 jdolecek } 386 1.1 jdolecek } 387 1.1 jdolecek uio->uio_offset = uiooff; 388 1.1 jdolecek 389 1.1 jdolecek #ifdef FILECORE_DEBUG_BR 390 1.1 jdolecek printf("brelse(%p) vn3\n", bp); 391 1.1 jdolecek #endif 392 1.23 ad brelse (bp, 0); 393 1.1 jdolecek 394 1.33 rmind kmem_free(de, sizeof(*de)); 395 1.22 rumble 396 1.1 jdolecek return (error); 397 1.1 jdolecek } 398 1.1 jdolecek 399 1.1 jdolecek /* 400 1.1 jdolecek * Return target name of a symbolic link 401 1.1 jdolecek * Shouldn't we get the parent vnode and read the data from there? 402 1.1 jdolecek * This could eventually result in deadlocks in filecore_lookup. 403 1.1 jdolecek * But otherwise the block read here is in the block buffer two times. 404 1.1 jdolecek */ 405 1.1 jdolecek int 406 1.30 dsl filecore_readlink(void *v) 407 1.1 jdolecek { 408 1.1 jdolecek #if 0 409 1.1 jdolecek struct vop_readlink_args /* { 410 1.1 jdolecek struct vnode *a_vp; 411 1.1 jdolecek struct uio *a_uio; 412 1.17 elad kauth_cred_t a_cred; 413 1.1 jdolecek } */ *ap = v; 414 1.1 jdolecek #endif 415 1.1 jdolecek 416 1.1 jdolecek return (EINVAL); 417 1.1 jdolecek } 418 1.1 jdolecek 419 1.1 jdolecek /* 420 1.1 jdolecek * Calculate the logical to physical mapping if not done already, 421 1.1 jdolecek * then call the device strategy routine. 422 1.1 jdolecek */ 423 1.1 jdolecek int 424 1.30 dsl filecore_strategy(void *v) 425 1.1 jdolecek { 426 1.1 jdolecek struct vop_strategy_args /* { 427 1.8 hannken struct vnode *a_vp; 428 1.1 jdolecek struct buf *a_bp; 429 1.1 jdolecek } */ *ap = v; 430 1.1 jdolecek struct buf *bp = ap->a_bp; 431 1.8 hannken struct vnode *vp = ap->a_vp; 432 1.1 jdolecek struct filecore_node *ip; 433 1.1 jdolecek int error; 434 1.1 jdolecek 435 1.1 jdolecek ip = VTOI(vp); 436 1.1 jdolecek if (bp->b_blkno == bp->b_lblkno) { 437 1.1 jdolecek error = VOP_BMAP(vp, bp->b_lblkno, NULL, &bp->b_blkno, NULL); 438 1.1 jdolecek if (error) { 439 1.1 jdolecek bp->b_error = error; 440 1.1 jdolecek biodone(bp); 441 1.1 jdolecek return (error); 442 1.1 jdolecek } 443 1.1 jdolecek if ((long)bp->b_blkno == -1) 444 1.1 jdolecek clrbuf(bp); 445 1.1 jdolecek } 446 1.1 jdolecek if ((long)bp->b_blkno == -1) { 447 1.1 jdolecek biodone(bp); 448 1.1 jdolecek return (0); 449 1.1 jdolecek } 450 1.1 jdolecek vp = ip->i_devvp; 451 1.7 hannken return (VOP_STRATEGY(vp, bp)); 452 1.1 jdolecek } 453 1.1 jdolecek 454 1.1 jdolecek /* 455 1.1 jdolecek * Print out the contents of an inode. 456 1.1 jdolecek */ 457 1.1 jdolecek /*ARGSUSED*/ 458 1.1 jdolecek int 459 1.30 dsl filecore_print(void *v) 460 1.1 jdolecek { 461 1.1 jdolecek 462 1.1 jdolecek printf("tag VT_FILECORE, filecore vnode\n"); 463 1.1 jdolecek return (0); 464 1.1 jdolecek } 465 1.1 jdolecek 466 1.1 jdolecek /* 467 1.1 jdolecek * Return POSIX pathconf information applicable to filecore filesystems. 468 1.1 jdolecek */ 469 1.1 jdolecek int 470 1.30 dsl filecore_pathconf(void *v) 471 1.1 jdolecek { 472 1.1 jdolecek struct vop_pathconf_args /* { 473 1.1 jdolecek struct vnode *a_vp; 474 1.1 jdolecek int a_name; 475 1.1 jdolecek register_t *a_retval; 476 1.1 jdolecek } */ *ap = v; 477 1.1 jdolecek switch (ap->a_name) { 478 1.1 jdolecek case _PC_LINK_MAX: 479 1.1 jdolecek *ap->a_retval = 1; 480 1.1 jdolecek return (0); 481 1.1 jdolecek case _PC_NAME_MAX: 482 1.10 jdolecek *ap->a_retval = ap->a_vp->v_mount->mnt_stat.f_namemax; 483 1.1 jdolecek return (0); 484 1.1 jdolecek case _PC_PATH_MAX: 485 1.1 jdolecek *ap->a_retval = 256; 486 1.1 jdolecek return (0); 487 1.1 jdolecek case _PC_CHOWN_RESTRICTED: 488 1.1 jdolecek *ap->a_retval = 1; 489 1.1 jdolecek return (0); 490 1.1 jdolecek case _PC_NO_TRUNC: 491 1.1 jdolecek *ap->a_retval = 1; 492 1.1 jdolecek return (0); 493 1.1 jdolecek case _PC_SYNC_IO: 494 1.1 jdolecek *ap->a_retval = 1; 495 1.1 jdolecek return (0); 496 1.1 jdolecek case _PC_FILESIZEBITS: 497 1.1 jdolecek *ap->a_retval = 32; 498 1.1 jdolecek return (0); 499 1.1 jdolecek default: 500 1.47 christos return genfs_pathconf(ap); 501 1.1 jdolecek } 502 1.1 jdolecek /* NOTREACHED */ 503 1.1 jdolecek } 504 1.1 jdolecek 505 1.1 jdolecek /* 506 1.1 jdolecek * Global vfs data structures for filecore 507 1.1 jdolecek */ 508 1.29 dsl int (**filecore_vnodeop_p)(void *); 509 1.1 jdolecek const struct vnodeopv_entry_desc filecore_vnodeop_entries[] = { 510 1.1 jdolecek { &vop_default_desc, vn_default_error }, 511 1.48 dholland { &vop_parsepath_desc, genfs_parsepath }, /* parsepath */ 512 1.1 jdolecek { &vop_lookup_desc, filecore_lookup }, /* lookup */ 513 1.49 dholland { &vop_create_desc, genfs_eopnotsupp }, /* create */ 514 1.49 dholland { &vop_mknod_desc, genfs_eopnotsupp }, /* mknod */ 515 1.49 dholland { &vop_open_desc, genfs_nullop }, /* open */ 516 1.49 dholland { &vop_close_desc, genfs_nullop }, /* close */ 517 1.1 jdolecek { &vop_access_desc, filecore_access }, /* access */ 518 1.46 christos { &vop_accessx_desc, genfs_accessx }, /* accessx */ 519 1.1 jdolecek { &vop_getattr_desc, filecore_getattr }, /* getattr */ 520 1.49 dholland { &vop_setattr_desc, genfs_eopnotsupp }, /* setattr */ 521 1.1 jdolecek { &vop_read_desc, filecore_read }, /* read */ 522 1.49 dholland { &vop_write_desc, genfs_eopnotsupp }, /* write */ 523 1.42 dholland { &vop_fallocate_desc, genfs_eopnotsupp }, /* fallocate */ 524 1.42 dholland { &vop_fdiscard_desc, genfs_eopnotsupp }, /* fdiscard */ 525 1.49 dholland { &vop_fcntl_desc, genfs_fcntl }, /* fcntl */ 526 1.49 dholland { &vop_ioctl_desc, genfs_enoioctl }, /* ioctl */ 527 1.49 dholland { &vop_poll_desc, genfs_poll }, /* poll */ 528 1.1 jdolecek { &vop_kqfilter_desc, genfs_kqfilter }, /* kqfilter */ 529 1.49 dholland { &vop_revoke_desc, genfs_revoke }, /* revoke */ 530 1.49 dholland { &vop_mmap_desc, genfs_mmap }, /* mmap */ 531 1.49 dholland { &vop_fsync_desc, genfs_nullop }, /* fsync */ 532 1.49 dholland { &vop_seek_desc, genfs_seek }, /* seek */ 533 1.49 dholland { &vop_remove_desc, genfs_eopnotsupp }, /* remove */ 534 1.50 christos { &vop_link_desc, genfs_erofs_link }, /* link */ 535 1.49 dholland { &vop_rename_desc, genfs_eopnotsupp }, /* rename */ 536 1.49 dholland { &vop_mkdir_desc, genfs_eopnotsupp }, /* mkdir */ 537 1.49 dholland { &vop_rmdir_desc, genfs_eopnotsupp }, /* rmdir */ 538 1.50 christos { &vop_symlink_desc, genfs_erofs_symlink }, /* symlink */ 539 1.1 jdolecek { &vop_readdir_desc, filecore_readdir }, /* readdir */ 540 1.1 jdolecek { &vop_readlink_desc, filecore_readlink }, /* readlink */ 541 1.49 dholland { &vop_abortop_desc, genfs_abortop }, /* abortop */ 542 1.1 jdolecek { &vop_inactive_desc, filecore_inactive }, /* inactive */ 543 1.1 jdolecek { &vop_reclaim_desc, filecore_reclaim }, /* reclaim */ 544 1.1 jdolecek { &vop_lock_desc, genfs_lock }, /* lock */ 545 1.1 jdolecek { &vop_unlock_desc, genfs_unlock }, /* unlock */ 546 1.1 jdolecek { &vop_bmap_desc, filecore_bmap }, /* bmap */ 547 1.1 jdolecek { &vop_strategy_desc, filecore_strategy }, /* strategy */ 548 1.1 jdolecek { &vop_print_desc, filecore_print }, /* print */ 549 1.1 jdolecek { &vop_islocked_desc, genfs_islocked }, /* islocked */ 550 1.1 jdolecek { &vop_pathconf_desc, filecore_pathconf }, /* pathconf */ 551 1.49 dholland { &vop_advlock_desc, genfs_eopnotsupp }, /* advlock */ 552 1.1 jdolecek { &vop_bwrite_desc, vn_bwrite }, /* bwrite */ 553 1.1 jdolecek { &vop_getpages_desc, genfs_getpages }, /* getpages */ 554 1.1 jdolecek { &vop_putpages_desc, genfs_putpages }, /* putpages */ 555 1.1 jdolecek { NULL, NULL } 556 1.1 jdolecek }; 557 1.1 jdolecek const struct vnodeopv_desc filecore_vnodeop_opv_desc = 558 1.1 jdolecek { &filecore_vnodeop_p, filecore_vnodeop_entries }; 559