1 1.127 reinoud /* $NetBSD: udf_vnops.c,v 1.127 2023/06/27 09:58:50 reinoud Exp $ */ 2 1.1 reinoud 3 1.1 reinoud /* 4 1.18 reinoud * Copyright (c) 2006, 2008 Reinoud Zandijk 5 1.1 reinoud * All rights reserved. 6 1.1 reinoud * 7 1.1 reinoud * Redistribution and use in source and binary forms, with or without 8 1.1 reinoud * modification, are permitted provided that the following conditions 9 1.1 reinoud * are met: 10 1.1 reinoud * 1. Redistributions of source code must retain the above copyright 11 1.1 reinoud * notice, this list of conditions and the following disclaimer. 12 1.1 reinoud * 2. Redistributions in binary form must reproduce the above copyright 13 1.1 reinoud * notice, this list of conditions and the following disclaimer in the 14 1.1 reinoud * documentation and/or other materials provided with the distribution. 15 1.1 reinoud * 16 1.1 reinoud * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR 17 1.1 reinoud * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 18 1.1 reinoud * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 19 1.1 reinoud * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, 20 1.1 reinoud * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 21 1.1 reinoud * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 22 1.1 reinoud * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 23 1.1 reinoud * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 24 1.1 reinoud * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF 25 1.1 reinoud * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 26 1.1 reinoud * 27 1.18 reinoud * Generic parts are derived from software contributed to The NetBSD Foundation 28 1.18 reinoud * by Julio M. Merino Vidal, developed as part of Google's Summer of Code 29 1.18 reinoud * 2005 program. 30 1.18 reinoud * 31 1.1 reinoud */ 32 1.1 reinoud 33 1.1 reinoud #include <sys/cdefs.h> 34 1.1 reinoud #ifndef lint 35 1.127 reinoud __KERNEL_RCSID(0, "$NetBSD: udf_vnops.c,v 1.127 2023/06/27 09:58:50 reinoud Exp $"); 36 1.1 reinoud #endif /* not lint */ 37 1.1 reinoud 38 1.1 reinoud 39 1.1 reinoud #include <sys/param.h> 40 1.1 reinoud #include <sys/systm.h> 41 1.1 reinoud #include <sys/namei.h> 42 1.1 reinoud #include <sys/resourcevar.h> /* defines plimit structure in proc struct */ 43 1.1 reinoud #include <sys/kernel.h> 44 1.1 reinoud #include <sys/file.h> /* define FWRITE ... */ 45 1.1 reinoud #include <sys/stat.h> 46 1.1 reinoud #include <sys/buf.h> 47 1.1 reinoud #include <sys/proc.h> 48 1.1 reinoud #include <sys/mount.h> 49 1.1 reinoud #include <sys/vnode.h> 50 1.1 reinoud #include <sys/signalvar.h> 51 1.1 reinoud #include <sys/malloc.h> 52 1.1 reinoud #include <sys/dirent.h> 53 1.1 reinoud #include <sys/lockf.h> 54 1.18 reinoud #include <sys/kauth.h> 55 1.1 reinoud 56 1.1 reinoud #include <miscfs/genfs/genfs.h> 57 1.1 reinoud #include <uvm/uvm_extern.h> 58 1.1 reinoud 59 1.1 reinoud #include <fs/udf/ecma167-udf.h> 60 1.1 reinoud #include <fs/udf/udf_mount.h> 61 1.78 reinoud #include <sys/dirhash.h> 62 1.78 reinoud 63 1.1 reinoud #include "udf.h" 64 1.1 reinoud #include "udf_subr.h" 65 1.1 reinoud #include "udf_bswap.h" 66 1.1 reinoud 67 1.1 reinoud 68 1.18 reinoud #define VTOI(vnode) ((struct udf_node *) (vnode)->v_data) 69 1.1 reinoud 70 1.94 reinoud /* forward declarations */ 71 1.94 reinoud static int udf_do_readlink(struct udf_node *udf_node, uint64_t filesize, 72 1.94 reinoud uint8_t *targetbuf, int *length); 73 1.1 reinoud 74 1.1 reinoud /* implementations of vnode functions; table follows at end */ 75 1.1 reinoud /* --------------------------------------------------------------------- */ 76 1.1 reinoud 77 1.1 reinoud int 78 1.1 reinoud udf_inactive(void *v) 79 1.1 reinoud { 80 1.103 riastrad struct vop_inactive_v2_args /* { 81 1.1 reinoud struct vnode *a_vp; 82 1.18 reinoud bool *a_recycle; 83 1.1 reinoud } */ *ap = v; 84 1.1 reinoud struct vnode *vp = ap->a_vp; 85 1.18 reinoud struct udf_node *udf_node = VTOI(vp); 86 1.18 reinoud int refcnt; 87 1.1 reinoud 88 1.18 reinoud DPRINTF(NODE, ("udf_inactive called for udf_node %p\n", VTOI(vp))); 89 1.1 reinoud 90 1.18 reinoud if (udf_node == NULL) { 91 1.18 reinoud DPRINTF(NODE, ("udf_inactive: inactive NULL UDF node\n")); 92 1.18 reinoud return 0; 93 1.18 reinoud } 94 1.1 reinoud 95 1.1 reinoud /* 96 1.99 hannken * Optionally flush metadata to disc. 97 1.1 reinoud */ 98 1.18 reinoud if (udf_node->fe) { 99 1.18 reinoud refcnt = udf_rw16(udf_node->fe->link_cnt); 100 1.18 reinoud } else { 101 1.18 reinoud assert(udf_node->efe); 102 1.18 reinoud refcnt = udf_rw16(udf_node->efe->link_cnt); 103 1.18 reinoud } 104 1.18 reinoud 105 1.53 reinoud if ((refcnt == 0) && (vp->v_vflag & VV_SYSTEM)) { 106 1.18 reinoud DPRINTF(VOLUMES, ("UDF_INACTIVE deleting VV_SYSTEM\n")); 107 1.119 andvar /* system nodes are not written out on inactive, so flush */ 108 1.53 reinoud udf_node->i_flags = 0; 109 1.53 reinoud } 110 1.18 reinoud 111 1.18 reinoud *ap->a_recycle = false; 112 1.18 reinoud if ((refcnt == 0) && ((vp->v_vflag & VV_SYSTEM) == 0)) { 113 1.18 reinoud *ap->a_recycle = true; 114 1.18 reinoud return 0; 115 1.18 reinoud } 116 1.18 reinoud 117 1.18 reinoud /* write out its node */ 118 1.18 reinoud if (udf_node->i_flags & (IN_CHANGE | IN_UPDATE | IN_MODIFIED)) 119 1.20 reinoud udf_update(vp, NULL, NULL, NULL, 0); 120 1.1 reinoud 121 1.1 reinoud return 0; 122 1.1 reinoud } 123 1.1 reinoud 124 1.1 reinoud /* --------------------------------------------------------------------- */ 125 1.1 reinoud 126 1.1 reinoud int 127 1.1 reinoud udf_reclaim(void *v) 128 1.1 reinoud { 129 1.105 riastrad struct vop_reclaim_v2_args /* { 130 1.1 reinoud struct vnode *a_vp; 131 1.1 reinoud } */ *ap = v; 132 1.1 reinoud struct vnode *vp = ap->a_vp; 133 1.18 reinoud struct udf_node *udf_node = VTOI(vp); 134 1.99 hannken int refcnt; 135 1.1 reinoud 136 1.105 riastrad VOP_UNLOCK(vp); 137 1.105 riastrad 138 1.18 reinoud DPRINTF(NODE, ("udf_reclaim called for node %p\n", udf_node)); 139 1.1 reinoud 140 1.18 reinoud if (udf_node == NULL) { 141 1.18 reinoud DPRINTF(NODE, ("udf_reclaim(): null udfnode\n")); 142 1.18 reinoud return 0; 143 1.18 reinoud } 144 1.18 reinoud 145 1.99 hannken /* 146 1.99 hannken * If the file has not been referenced anymore in a directory 147 1.99 hannken * we ought to free up the resources on disc if applicable. 148 1.99 hannken */ 149 1.99 hannken if (udf_node->fe) { 150 1.99 hannken refcnt = udf_rw16(udf_node->fe->link_cnt); 151 1.99 hannken } else { 152 1.99 hannken assert(udf_node->efe); 153 1.99 hannken refcnt = udf_rw16(udf_node->efe->link_cnt); 154 1.99 hannken } 155 1.99 hannken 156 1.99 hannken if ((refcnt == 0) && ((vp->v_vflag & VV_SYSTEM) == 0)) { 157 1.99 hannken /* remove this file's allocation */ 158 1.99 hannken DPRINTF(NODE, ("udf_inactive deleting unlinked file\n")); 159 1.99 hannken udf_delete_node(udf_node); 160 1.99 hannken } 161 1.99 hannken 162 1.18 reinoud /* update note for closure */ 163 1.20 reinoud udf_update(vp, NULL, NULL, NULL, UPDATE_CLOSE); 164 1.18 reinoud 165 1.18 reinoud /* async check to see if all node descriptors are written out */ 166 1.127 reinoud mutex_enter(&udf_node->node_mutex); 167 1.18 reinoud while ((volatile int) udf_node->outstanding_nodedscr > 0) { 168 1.18 reinoud vprint("udf_reclaim(): waiting for writeout\n", vp); 169 1.127 reinoud cv_timedwait(&udf_node->node_lock, &udf_node->node_mutex, hz/8); 170 1.18 reinoud } 171 1.127 reinoud mutex_exit(&udf_node->node_mutex); 172 1.18 reinoud 173 1.1 reinoud /* dispose all node knowledge */ 174 1.18 reinoud udf_dispose_node(udf_node); 175 1.1 reinoud 176 1.1 reinoud return 0; 177 1.1 reinoud } 178 1.1 reinoud 179 1.1 reinoud /* --------------------------------------------------------------------- */ 180 1.1 reinoud 181 1.1 reinoud int 182 1.1 reinoud udf_read(void *v) 183 1.1 reinoud { 184 1.1 reinoud struct vop_read_args /* { 185 1.1 reinoud struct vnode *a_vp; 186 1.1 reinoud struct uio *a_uio; 187 1.1 reinoud int a_ioflag; 188 1.5 elad kauth_cred_t a_cred; 189 1.1 reinoud } */ *ap = v; 190 1.1 reinoud struct vnode *vp = ap->a_vp; 191 1.1 reinoud struct uio *uio = ap->a_uio; 192 1.1 reinoud int ioflag = ap->a_ioflag; 193 1.18 reinoud int advice = IO_ADV_DECODE(ap->a_ioflag); 194 1.1 reinoud struct uvm_object *uobj; 195 1.1 reinoud struct udf_node *udf_node = VTOI(vp); 196 1.1 reinoud struct file_entry *fe; 197 1.1 reinoud struct extfile_entry *efe; 198 1.1 reinoud uint64_t file_size; 199 1.1 reinoud vsize_t len; 200 1.1 reinoud int error; 201 1.1 reinoud 202 1.18 reinoud /* 203 1.18 reinoud * XXX reading from extended attributes not yet implemented. FreeBSD 204 1.18 reinoud * has it in mind to forward the IO_EXT read call to the 205 1.18 reinoud * VOP_READEXTATTR(). 206 1.18 reinoud */ 207 1.1 reinoud 208 1.1 reinoud DPRINTF(READ, ("udf_read called\n")); 209 1.1 reinoud 210 1.1 reinoud /* can this happen? some filingsystems have this check */ 211 1.1 reinoud if (uio->uio_offset < 0) 212 1.1 reinoud return EINVAL; 213 1.18 reinoud if (uio->uio_resid == 0) 214 1.18 reinoud return 0; 215 1.18 reinoud 216 1.18 reinoud /* protect against rogue programs reading raw directories and links */ 217 1.18 reinoud if ((ioflag & IO_ALTSEMANTICS) == 0) { 218 1.18 reinoud if (vp->v_type == VDIR) 219 1.18 reinoud return EISDIR; 220 1.18 reinoud /* all but regular files just give EINVAL */ 221 1.18 reinoud if (vp->v_type != VREG) 222 1.18 reinoud return EINVAL; 223 1.18 reinoud } 224 1.1 reinoud 225 1.1 reinoud assert(udf_node); 226 1.1 reinoud assert(udf_node->fe || udf_node->efe); 227 1.1 reinoud 228 1.18 reinoud /* get file/directory filesize */ 229 1.1 reinoud if (udf_node->fe) { 230 1.1 reinoud fe = udf_node->fe; 231 1.1 reinoud file_size = udf_rw64(fe->inf_len); 232 1.1 reinoud } else { 233 1.1 reinoud assert(udf_node->efe); 234 1.1 reinoud efe = udf_node->efe; 235 1.1 reinoud file_size = udf_rw64(efe->inf_len); 236 1.6 christos } 237 1.1 reinoud 238 1.18 reinoud /* read contents using buffercache */ 239 1.18 reinoud uobj = &vp->v_uobj; 240 1.18 reinoud error = 0; 241 1.18 reinoud while (uio->uio_resid > 0) { 242 1.18 reinoud /* reached end? */ 243 1.18 reinoud if (file_size <= uio->uio_offset) 244 1.18 reinoud break; 245 1.18 reinoud 246 1.18 reinoud /* maximise length to file extremity */ 247 1.18 reinoud len = MIN(file_size - uio->uio_offset, uio->uio_resid); 248 1.18 reinoud if (len == 0) 249 1.18 reinoud break; 250 1.18 reinoud 251 1.18 reinoud /* ubc, here we come, prepare to trap */ 252 1.31 pooka error = ubc_uiomove(uobj, uio, len, advice, 253 1.112 ad UBC_READ | UBC_PARTIALOK | UBC_VNODE_FLAGS(vp)); 254 1.18 reinoud if (error) 255 1.18 reinoud break; 256 1.6 christos } 257 1.1 reinoud 258 1.18 reinoud /* note access time unless not requested */ 259 1.18 reinoud if (!(vp->v_mount->mnt_flag & MNT_NOATIME)) { 260 1.18 reinoud udf_node->i_flags |= IN_ACCESS; 261 1.98 riastrad if ((ioflag & IO_SYNC) == IO_SYNC) { 262 1.98 riastrad int uerror; 263 1.98 riastrad 264 1.98 riastrad uerror = udf_update(vp, NULL, NULL, NULL, UPDATE_WAIT); 265 1.98 riastrad if (error == 0) 266 1.98 riastrad error = uerror; 267 1.98 riastrad } 268 1.6 christos } 269 1.1 reinoud 270 1.18 reinoud return error; 271 1.1 reinoud } 272 1.1 reinoud 273 1.1 reinoud /* --------------------------------------------------------------------- */ 274 1.1 reinoud 275 1.1 reinoud int 276 1.1 reinoud udf_write(void *v) 277 1.1 reinoud { 278 1.1 reinoud struct vop_write_args /* { 279 1.1 reinoud struct vnode *a_vp; 280 1.1 reinoud struct uio *a_uio; 281 1.1 reinoud int a_ioflag; 282 1.5 elad kauth_cred_t a_cred; 283 1.1 reinoud } */ *ap = v; 284 1.18 reinoud struct vnode *vp = ap->a_vp; 285 1.18 reinoud struct uio *uio = ap->a_uio; 286 1.18 reinoud int ioflag = ap->a_ioflag; 287 1.43 reinoud kauth_cred_t cred = ap->a_cred; 288 1.18 reinoud int advice = IO_ADV_DECODE(ap->a_ioflag); 289 1.18 reinoud struct uvm_object *uobj; 290 1.18 reinoud struct udf_node *udf_node = VTOI(vp); 291 1.18 reinoud struct file_entry *fe; 292 1.18 reinoud struct extfile_entry *efe; 293 1.35 reinoud uint64_t file_size, old_size, old_offset; 294 1.18 reinoud vsize_t len; 295 1.46 reinoud int aflag = ioflag & IO_SYNC ? B_SYNC : 0; 296 1.18 reinoud int error; 297 1.31 pooka int resid, extended; 298 1.18 reinoud 299 1.18 reinoud /* 300 1.18 reinoud * XXX writing to extended attributes not yet implemented. FreeBSD has 301 1.18 reinoud * it in mind to forward the IO_EXT read call to the 302 1.18 reinoud * VOP_READEXTATTR(). 303 1.18 reinoud */ 304 1.18 reinoud 305 1.18 reinoud DPRINTF(WRITE, ("udf_write called\n")); 306 1.18 reinoud 307 1.18 reinoud /* can this happen? some filingsystems have this check */ 308 1.18 reinoud if (uio->uio_offset < 0) 309 1.18 reinoud return EINVAL; 310 1.18 reinoud if (uio->uio_resid == 0) 311 1.18 reinoud return 0; 312 1.18 reinoud 313 1.18 reinoud /* protect against rogue programs writing raw directories or links */ 314 1.18 reinoud if ((ioflag & IO_ALTSEMANTICS) == 0) { 315 1.18 reinoud if (vp->v_type == VDIR) 316 1.18 reinoud return EISDIR; 317 1.18 reinoud /* all but regular files just give EINVAL for now */ 318 1.18 reinoud if (vp->v_type != VREG) 319 1.18 reinoud return EINVAL; 320 1.18 reinoud } 321 1.1 reinoud 322 1.18 reinoud assert(udf_node); 323 1.18 reinoud assert(udf_node->fe || udf_node->efe); 324 1.18 reinoud 325 1.18 reinoud /* get file/directory filesize */ 326 1.18 reinoud if (udf_node->fe) { 327 1.18 reinoud fe = udf_node->fe; 328 1.18 reinoud file_size = udf_rw64(fe->inf_len); 329 1.18 reinoud } else { 330 1.18 reinoud assert(udf_node->efe); 331 1.18 reinoud efe = udf_node->efe; 332 1.18 reinoud file_size = udf_rw64(efe->inf_len); 333 1.18 reinoud } 334 1.18 reinoud old_size = file_size; 335 1.18 reinoud 336 1.18 reinoud /* if explicitly asked to append, uio_offset can be wrong? */ 337 1.18 reinoud if (ioflag & IO_APPEND) 338 1.18 reinoud uio->uio_offset = file_size; 339 1.18 reinoud 340 1.18 reinoud extended = (uio->uio_offset + uio->uio_resid > file_size); 341 1.18 reinoud if (extended) { 342 1.18 reinoud DPRINTF(WRITE, ("extending file from %"PRIu64" to %"PRIu64"\n", 343 1.18 reinoud file_size, uio->uio_offset + uio->uio_resid)); 344 1.18 reinoud error = udf_grow_node(udf_node, uio->uio_offset + uio->uio_resid); 345 1.18 reinoud if (error) 346 1.18 reinoud return error; 347 1.18 reinoud file_size = uio->uio_offset + uio->uio_resid; 348 1.18 reinoud } 349 1.1 reinoud 350 1.18 reinoud /* write contents using buffercache */ 351 1.18 reinoud uobj = &vp->v_uobj; 352 1.18 reinoud resid = uio->uio_resid; 353 1.18 reinoud error = 0; 354 1.18 reinoud 355 1.18 reinoud uvm_vnp_setwritesize(vp, file_size); 356 1.36 reinoud old_offset = uio->uio_offset; 357 1.18 reinoud while (uio->uio_resid > 0) { 358 1.18 reinoud /* maximise length to file extremity */ 359 1.18 reinoud len = MIN(file_size - uio->uio_offset, uio->uio_resid); 360 1.18 reinoud if (len == 0) 361 1.18 reinoud break; 362 1.18 reinoud 363 1.46 reinoud genfs_node_wrlock(vp); 364 1.46 reinoud error = GOP_ALLOC(vp, uio->uio_offset, len, aflag, cred); 365 1.46 reinoud genfs_node_unlock(vp); 366 1.46 reinoud if (error) 367 1.46 reinoud break; 368 1.46 reinoud 369 1.18 reinoud /* ubc, here we come, prepare to trap */ 370 1.31 pooka error = ubc_uiomove(uobj, uio, len, advice, 371 1.112 ad UBC_WRITE | UBC_VNODE_FLAGS(vp)); 372 1.18 reinoud if (error) 373 1.18 reinoud break; 374 1.35 reinoud 375 1.35 reinoud /* 376 1.35 reinoud * flush what we just wrote if necessary. 377 1.35 reinoud * XXXUBC simplistic async flushing. 378 1.36 reinoud * 379 1.55 reinoud * Directories are excluded since its file data that we want 380 1.55 reinoud * to purge. 381 1.35 reinoud */ 382 1.76 reinoud if ((vp->v_type != VDIR) && 383 1.55 reinoud (old_offset >> 16 != uio->uio_offset >> 16)) { 384 1.109 ad rw_enter(vp->v_uobj.vmobjlock, RW_WRITER); 385 1.55 reinoud error = VOP_PUTPAGES(vp, (old_offset >> 16) << 16, 386 1.71 chs (uio->uio_offset >> 16) << 16, 387 1.71 chs PGO_CLEANIT | PGO_LAZY); 388 1.36 reinoud old_offset = uio->uio_offset; 389 1.35 reinoud } 390 1.18 reinoud } 391 1.18 reinoud uvm_vnp_setsize(vp, file_size); 392 1.18 reinoud 393 1.18 reinoud /* mark node changed and request update */ 394 1.18 reinoud udf_node->i_flags |= IN_CHANGE | IN_UPDATE; 395 1.69 christos if (vp->v_mount->mnt_flag & MNT_RELATIME) 396 1.69 christos udf_node->i_flags |= IN_ACCESS; 397 1.18 reinoud 398 1.18 reinoud /* 399 1.18 reinoud * XXX TODO FFS has code here to reset setuid & setgid when we're not 400 1.18 reinoud * the superuser as a precaution against tampering. 401 1.18 reinoud */ 402 1.18 reinoud 403 1.18 reinoud if (error) { 404 1.18 reinoud /* bring back file size to its former size */ 405 1.18 reinoud /* take notice of its errors? */ 406 1.42 reinoud (void) udf_chsize(vp, (u_quad_t) old_size, cred); 407 1.18 reinoud 408 1.18 reinoud /* roll back uio */ 409 1.18 reinoud uio->uio_offset -= resid - uio->uio_resid; 410 1.18 reinoud uio->uio_resid = resid; 411 1.18 reinoud } else { 412 1.18 reinoud /* if we write and we're synchronous, update node */ 413 1.18 reinoud if ((resid > uio->uio_resid) && ((ioflag & IO_SYNC) == IO_SYNC)) 414 1.20 reinoud error = udf_update(vp, NULL, NULL, NULL, UPDATE_WAIT); 415 1.18 reinoud } 416 1.18 reinoud 417 1.18 reinoud return error; 418 1.1 reinoud } 419 1.1 reinoud 420 1.1 reinoud 421 1.1 reinoud /* --------------------------------------------------------------------- */ 422 1.1 reinoud 423 1.1 reinoud /* 424 1.126 andvar * `Special' bmap functionality that translates all incoming requests to 425 1.1 reinoud * translate to vop_strategy() calls with the same blocknumbers effectively 426 1.1 reinoud * not translating at all. 427 1.1 reinoud */ 428 1.1 reinoud 429 1.1 reinoud int 430 1.1 reinoud udf_trivial_bmap(void *v) 431 1.1 reinoud { 432 1.1 reinoud struct vop_bmap_args /* { 433 1.1 reinoud struct vnode *a_vp; 434 1.1 reinoud daddr_t a_bn; 435 1.1 reinoud struct vnode **a_vpp; 436 1.1 reinoud daddr_t *a_bnp; 437 1.1 reinoud int *a_runp; 438 1.1 reinoud } */ *ap = v; 439 1.1 reinoud struct vnode *vp = ap->a_vp; /* our node */ 440 1.1 reinoud struct vnode **vpp = ap->a_vpp; /* return node */ 441 1.1 reinoud daddr_t *bnp = ap->a_bnp; /* translated */ 442 1.126 andvar daddr_t bn = ap->a_bn; /* original */ 443 1.1 reinoud int *runp = ap->a_runp; 444 1.1 reinoud struct udf_node *udf_node = VTOI(vp); 445 1.1 reinoud uint32_t lb_size; 446 1.1 reinoud 447 1.1 reinoud /* get logical block size */ 448 1.1 reinoud lb_size = udf_rw32(udf_node->ump->logical_vol->lb_size); 449 1.1 reinoud 450 1.1 reinoud /* could return `-1' to indicate holes/zeros */ 451 1.1 reinoud /* translate 1:1 */ 452 1.1 reinoud *bnp = bn; 453 1.1 reinoud 454 1.1 reinoud /* set the vnode to read the data from with strategy on itself */ 455 1.1 reinoud if (vpp) 456 1.1 reinoud *vpp = vp; 457 1.1 reinoud 458 1.1 reinoud /* set runlength of maximum block size */ 459 1.1 reinoud if (runp) 460 1.1 reinoud *runp = MAXPHYS / lb_size; /* or with -1 ? */ 461 1.1 reinoud 462 1.1 reinoud /* return success */ 463 1.1 reinoud return 0; 464 1.1 reinoud } 465 1.1 reinoud 466 1.1 reinoud /* --------------------------------------------------------------------- */ 467 1.1 reinoud 468 1.1 reinoud int 469 1.18 reinoud udf_vfsstrategy(void *v) 470 1.1 reinoud { 471 1.1 reinoud struct vop_strategy_args /* { 472 1.1 reinoud struct vnode *a_vp; 473 1.1 reinoud struct buf *a_bp; 474 1.1 reinoud } */ *ap = v; 475 1.1 reinoud struct vnode *vp = ap->a_vp; 476 1.1 reinoud struct buf *bp = ap->a_bp; 477 1.1 reinoud struct udf_node *udf_node = VTOI(vp); 478 1.87 christos uint32_t lb_size, sectors; 479 1.1 reinoud 480 1.1 reinoud DPRINTF(STRATEGY, ("udf_strategy called\n")); 481 1.1 reinoud 482 1.1 reinoud /* check if we ought to be here */ 483 1.1 reinoud if (vp->v_type == VBLK || vp->v_type == VCHR) 484 1.1 reinoud panic("udf_strategy: spec"); 485 1.1 reinoud 486 1.18 reinoud /* only filebuffers ought to be read/write by this, no descriptors */ 487 1.1 reinoud assert(bp->b_blkno >= 0); 488 1.1 reinoud 489 1.1 reinoud /* get sector size */ 490 1.1 reinoud lb_size = udf_rw32(udf_node->ump->logical_vol->lb_size); 491 1.1 reinoud 492 1.1 reinoud /* calculate length to fetch/store in sectors */ 493 1.1 reinoud sectors = bp->b_bcount / lb_size; 494 1.1 reinoud assert(bp->b_bcount > 0); 495 1.1 reinoud 496 1.3 snj /* NEVER assume later that this buffer is already translated */ 497 1.1 reinoud /* bp->b_lblkno = bp->b_blkno; */ 498 1.1 reinoud 499 1.10 msaitoh /* check assertions: we OUGHT to always get multiples of this */ 500 1.1 reinoud assert(sectors * lb_size == bp->b_bcount); 501 1.91 christos __USE(sectors); 502 1.1 reinoud 503 1.18 reinoud /* issue buffer */ 504 1.1 reinoud if (bp->b_flags & B_READ) { 505 1.18 reinoud DPRINTF(STRATEGY, ("\tread vp %p buf %p (blk no %"PRIu64")" 506 1.87 christos ", for %d sectors\n", 507 1.87 christos vp, bp, bp->b_blkno, sectors)); 508 1.18 reinoud 509 1.1 reinoud /* read buffer from the udf_node, translate vtop on the way*/ 510 1.1 reinoud udf_read_filebuf(udf_node, bp); 511 1.18 reinoud } else { 512 1.18 reinoud DPRINTF(STRATEGY, ("\twrite vp %p buf %p (blk no %"PRIu64")" 513 1.87 christos ", for %d sectors\n", 514 1.87 christos vp, bp, bp->b_blkno, sectors)); 515 1.18 reinoud 516 1.18 reinoud /* write buffer to the udf_node, translate vtop on the way*/ 517 1.18 reinoud udf_write_filebuf(udf_node, bp); 518 1.6 christos } 519 1.1 reinoud 520 1.18 reinoud return bp->b_error; 521 1.1 reinoud } 522 1.1 reinoud 523 1.1 reinoud /* --------------------------------------------------------------------- */ 524 1.1 reinoud 525 1.1 reinoud int 526 1.1 reinoud udf_readdir(void *v) 527 1.1 reinoud { 528 1.1 reinoud struct vop_readdir_args /* { 529 1.1 reinoud struct vnode *a_vp; 530 1.1 reinoud struct uio *a_uio; 531 1.5 elad kauth_cred_t a_cred; 532 1.1 reinoud int *a_eofflag; 533 1.1 reinoud off_t **a_cookies; 534 1.1 reinoud int *a_ncookies; 535 1.1 reinoud } */ *ap = v; 536 1.1 reinoud struct uio *uio = ap->a_uio; 537 1.1 reinoud struct vnode *vp = ap->a_vp; 538 1.1 reinoud struct udf_node *udf_node = VTOI(vp); 539 1.1 reinoud struct file_entry *fe; 540 1.1 reinoud struct extfile_entry *efe; 541 1.1 reinoud struct fileid_desc *fid; 542 1.11 rumble struct dirent *dirent; 543 1.1 reinoud uint64_t file_size, diroffset, transoffset; 544 1.1 reinoud uint32_t lb_size; 545 1.1 reinoud int error; 546 1.1 reinoud 547 1.1 reinoud DPRINTF(READDIR, ("udf_readdir called\n")); 548 1.1 reinoud 549 1.1 reinoud /* This operation only makes sense on directory nodes. */ 550 1.1 reinoud if (vp->v_type != VDIR) 551 1.1 reinoud return ENOTDIR; 552 1.1 reinoud 553 1.1 reinoud /* get directory filesize */ 554 1.1 reinoud if (udf_node->fe) { 555 1.1 reinoud fe = udf_node->fe; 556 1.1 reinoud file_size = udf_rw64(fe->inf_len); 557 1.1 reinoud } else { 558 1.1 reinoud assert(udf_node->efe); 559 1.1 reinoud efe = udf_node->efe; 560 1.1 reinoud file_size = udf_rw64(efe->inf_len); 561 1.6 christos } 562 1.1 reinoud 563 1.11 rumble dirent = malloc(sizeof(struct dirent), M_UDFTEMP, M_WAITOK | M_ZERO); 564 1.11 rumble 565 1.1 reinoud /* 566 1.1 reinoud * Add `.' pseudo entry if at offset zero since its not in the fid 567 1.1 reinoud * stream 568 1.1 reinoud */ 569 1.1 reinoud if (uio->uio_offset == 0) { 570 1.1 reinoud DPRINTF(READDIR, ("\t'.' inserted\n")); 571 1.11 rumble strcpy(dirent->d_name, "."); 572 1.51 reinoud dirent->d_fileno = udf_get_node_id(&udf_node->loc); 573 1.11 rumble dirent->d_type = DT_DIR; 574 1.11 rumble dirent->d_namlen = strlen(dirent->d_name); 575 1.11 rumble dirent->d_reclen = _DIRENT_SIZE(dirent); 576 1.11 rumble uiomove(dirent, _DIRENT_SIZE(dirent), uio); 577 1.1 reinoud 578 1.1 reinoud /* mark with magic value that we have done the dummy */ 579 1.1 reinoud uio->uio_offset = UDF_DIRCOOKIE_DOT; 580 1.6 christos } 581 1.1 reinoud 582 1.1 reinoud /* we are called just as long as we keep on pushing data in */ 583 1.1 reinoud error = 0; 584 1.34 reinoud if (uio->uio_offset < file_size) { 585 1.1 reinoud /* allocate temporary space for fid */ 586 1.1 reinoud lb_size = udf_rw32(udf_node->ump->logical_vol->lb_size); 587 1.11 rumble fid = malloc(lb_size, M_UDFTEMP, M_WAITOK); 588 1.1 reinoud 589 1.1 reinoud if (uio->uio_offset == UDF_DIRCOOKIE_DOT) 590 1.1 reinoud uio->uio_offset = 0; 591 1.1 reinoud 592 1.1 reinoud diroffset = uio->uio_offset; 593 1.1 reinoud transoffset = diroffset; 594 1.1 reinoud while (diroffset < file_size) { 595 1.1 reinoud DPRINTF(READDIR, ("\tread in fid stream\n")); 596 1.1 reinoud /* transfer a new fid/dirent */ 597 1.50 reinoud error = udf_read_fid_stream(vp, &diroffset, fid, dirent); 598 1.1 reinoud DPRINTFIF(READDIR, error, ("read error in read fid " 599 1.1 reinoud "stream : %d\n", error)); 600 1.1 reinoud if (error) 601 1.1 reinoud break; 602 1.1 reinoud 603 1.1 reinoud /* 604 1.1 reinoud * If there isn't enough space in the uio to return a 605 1.1 reinoud * whole dirent, break off read 606 1.1 reinoud */ 607 1.11 rumble if (uio->uio_resid < _DIRENT_SIZE(dirent)) 608 1.1 reinoud break; 609 1.1 reinoud 610 1.107 msaitoh /* remember the last entry we transferred */ 611 1.1 reinoud transoffset = diroffset; 612 1.1 reinoud 613 1.1 reinoud /* skip deleted entries */ 614 1.1 reinoud if (fid->file_char & UDF_FILE_CHAR_DEL) 615 1.1 reinoud continue; 616 1.1 reinoud 617 1.1 reinoud /* skip not visible files */ 618 1.1 reinoud if (fid->file_char & UDF_FILE_CHAR_VIS) 619 1.1 reinoud continue; 620 1.1 reinoud 621 1.1 reinoud /* copy dirent to the caller */ 622 1.1 reinoud DPRINTF(READDIR, ("\tread dirent `%s', type %d\n", 623 1.11 rumble dirent->d_name, dirent->d_type)); 624 1.11 rumble uiomove(dirent, _DIRENT_SIZE(dirent), uio); 625 1.6 christos } 626 1.1 reinoud 627 1.116 andvar /* pass on last transferred offset */ 628 1.1 reinoud uio->uio_offset = transoffset; 629 1.11 rumble free(fid, M_UDFTEMP); 630 1.6 christos } 631 1.1 reinoud 632 1.1 reinoud if (ap->a_eofflag) 633 1.34 reinoud *ap->a_eofflag = (uio->uio_offset >= file_size); 634 1.1 reinoud 635 1.1 reinoud #ifdef DEBUG 636 1.1 reinoud if (udf_verbose & UDF_DEBUG_READDIR) { 637 1.1 reinoud printf("returning offset %d\n", (uint32_t) uio->uio_offset); 638 1.1 reinoud if (ap->a_eofflag) 639 1.1 reinoud printf("returning EOF ? %d\n", *ap->a_eofflag); 640 1.1 reinoud if (error) 641 1.1 reinoud printf("readdir returning error %d\n", error); 642 1.6 christos } 643 1.1 reinoud #endif 644 1.1 reinoud 645 1.11 rumble free(dirent, M_UDFTEMP); 646 1.1 reinoud return error; 647 1.1 reinoud } 648 1.1 reinoud 649 1.1 reinoud /* --------------------------------------------------------------------- */ 650 1.1 reinoud 651 1.1 reinoud int 652 1.1 reinoud udf_lookup(void *v) 653 1.1 reinoud { 654 1.90 hannken struct vop_lookup_v2_args /* { 655 1.1 reinoud struct vnode *a_dvp; 656 1.1 reinoud struct vnode **a_vpp; 657 1.1 reinoud struct componentname *a_cnp; 658 1.1 reinoud } */ *ap = v; 659 1.1 reinoud struct vnode *dvp = ap->a_dvp; 660 1.1 reinoud struct vnode **vpp = ap->a_vpp; 661 1.1 reinoud struct componentname *cnp = ap->a_cnp; 662 1.1 reinoud struct udf_node *dir_node, *res_node; 663 1.1 reinoud struct udf_mount *ump; 664 1.1 reinoud struct long_ad icb_loc; 665 1.80 reinoud mode_t mode; 666 1.80 reinoud uid_t d_uid; 667 1.80 reinoud gid_t d_gid; 668 1.1 reinoud const char *name; 669 1.8 chs int namelen, nameiop, islastcn, mounted_ro; 670 1.1 reinoud int error, found; 671 1.1 reinoud 672 1.1 reinoud dir_node = VTOI(dvp); 673 1.1 reinoud ump = dir_node->ump; 674 1.1 reinoud *vpp = NULL; 675 1.1 reinoud 676 1.85 reinoud DPRINTF(LOOKUP, ("udf_lookup called, lookup `%s`\n", 677 1.85 reinoud cnp->cn_nameptr)); 678 1.1 reinoud 679 1.1 reinoud /* simplify/clarification flags */ 680 1.1 reinoud nameiop = cnp->cn_nameiop; 681 1.1 reinoud islastcn = cnp->cn_flags & ISLASTCN; 682 1.1 reinoud mounted_ro = dvp->v_mount->mnt_flag & MNT_RDONLY; 683 1.1 reinoud 684 1.1 reinoud /* check exec/dirread permissions first */ 685 1.13 pooka error = VOP_ACCESS(dvp, VEXEC, cnp->cn_cred); 686 1.1 reinoud if (error) 687 1.1 reinoud return error; 688 1.1 reinoud 689 1.1 reinoud DPRINTF(LOOKUP, ("\taccess ok\n")); 690 1.1 reinoud 691 1.1 reinoud /* 692 1.1 reinoud * If requesting a modify on the last path element on a read-only 693 1.1 reinoud * filingsystem, reject lookup; XXX why is this repeated in every FS ? 694 1.1 reinoud */ 695 1.1 reinoud if (islastcn && mounted_ro && (nameiop == DELETE || nameiop == RENAME)) 696 1.1 reinoud return EROFS; 697 1.1 reinoud 698 1.1 reinoud DPRINTF(LOOKUP, ("\tlooking up cnp->cn_nameptr '%s'\n", 699 1.1 reinoud cnp->cn_nameptr)); 700 1.73 dholland /* look in the namecache */ 701 1.74 dholland if (cache_lookup(dvp, cnp->cn_nameptr, cnp->cn_namelen, 702 1.74 dholland cnp->cn_nameiop, cnp->cn_flags, NULL, vpp)) { 703 1.73 dholland return *vpp == NULLVP ? ENOENT : 0; 704 1.73 dholland } 705 1.1 reinoud 706 1.1 reinoud DPRINTF(LOOKUP, ("\tNOT found in cache\n")); 707 1.1 reinoud 708 1.1 reinoud /* 709 1.1 reinoud * Obviously, the file is not (anymore) in the namecache, we have to 710 1.1 reinoud * search for it. There are three basic cases: '.', '..' and others. 711 1.1 reinoud * 712 1.1 reinoud * Following the guidelines of VOP_LOOKUP manpage and tmpfs. 713 1.1 reinoud */ 714 1.1 reinoud error = 0; 715 1.1 reinoud if ((cnp->cn_namelen == 1) && (cnp->cn_nameptr[0] == '.')) { 716 1.1 reinoud DPRINTF(LOOKUP, ("\tlookup '.'\n")); 717 1.1 reinoud /* special case 1 '.' */ 718 1.80 reinoud if (islastcn && cnp->cn_nameiop == RENAME) { 719 1.80 reinoud error = EISDIR; 720 1.80 reinoud goto out; 721 1.80 reinoud } 722 1.57 pooka vref(dvp); 723 1.1 reinoud *vpp = dvp; 724 1.1 reinoud /* done */ 725 1.80 reinoud goto done; 726 1.1 reinoud } else if (cnp->cn_flags & ISDOTDOT) { 727 1.1 reinoud /* special case 2 '..' */ 728 1.1 reinoud DPRINTF(LOOKUP, ("\tlookup '..'\n")); 729 1.1 reinoud 730 1.85 reinoud if (islastcn && cnp->cn_nameiop == RENAME) { 731 1.85 reinoud error = EINVAL; 732 1.85 reinoud goto out; 733 1.85 reinoud } 734 1.85 reinoud 735 1.1 reinoud /* get our node */ 736 1.1 reinoud name = ".."; 737 1.1 reinoud namelen = 2; 738 1.30 reinoud error = udf_lookup_name_in_dir(dvp, name, namelen, 739 1.30 reinoud &icb_loc, &found); 740 1.30 reinoud if (error) 741 1.30 reinoud goto out; 742 1.1 reinoud if (!found) 743 1.1 reinoud error = ENOENT; 744 1.1 reinoud 745 1.28 reinoud /* first unlock parent */ 746 1.59 hannken VOP_UNLOCK(dvp); 747 1.28 reinoud 748 1.18 reinoud if (error == 0) { 749 1.1 reinoud DPRINTF(LOOKUP, ("\tfound '..'\n")); 750 1.1 reinoud /* try to create/reuse the node */ 751 1.108 ad error = udf_get_node(ump, &icb_loc, &res_node, 752 1.108 ad LK_EXCLUSIVE); 753 1.1 reinoud 754 1.1 reinoud if (!error) { 755 1.30 reinoud DPRINTF(LOOKUP, 756 1.30 reinoud ("\tnode retrieved/created OK\n")); 757 1.1 reinoud *vpp = res_node->vnode; 758 1.6 christos } 759 1.6 christos } 760 1.1 reinoud 761 1.8 chs /* try to relock parent */ 762 1.8 chs vn_lock(dvp, LK_EXCLUSIVE | LK_RETRY); 763 1.80 reinoud goto out; 764 1.80 reinoud } 765 1.80 reinoud 766 1.80 reinoud /* all other files */ 767 1.80 reinoud DPRINTF(LOOKUP, ("\tlookup file/dir in directory\n")); 768 1.80 reinoud 769 1.80 reinoud /* lookup filename in the directory; location icb_loc */ 770 1.80 reinoud name = cnp->cn_nameptr; 771 1.80 reinoud namelen = cnp->cn_namelen; 772 1.80 reinoud error = udf_lookup_name_in_dir(dvp, name, namelen, 773 1.80 reinoud &icb_loc, &found); 774 1.80 reinoud if (error) 775 1.80 reinoud goto out; 776 1.80 reinoud if (!found) { 777 1.80 reinoud DPRINTF(LOOKUP, ("\tNOT found\n")); 778 1.80 reinoud /* 779 1.80 reinoud * The entry was not found in the directory. This is 780 1.80 reinoud * valid if we are creating or renaming an entry and 781 1.80 reinoud * are working on the last component of the path name. 782 1.80 reinoud */ 783 1.80 reinoud if (islastcn && (cnp->cn_nameiop == CREATE || 784 1.80 reinoud cnp->cn_nameiop == RENAME)) { 785 1.80 reinoud error = VOP_ACCESS(dvp, VWRITE, cnp->cn_cred); 786 1.80 reinoud if (error) { 787 1.80 reinoud goto out; 788 1.80 reinoud } 789 1.80 reinoud error = EJUSTRETURN; 790 1.80 reinoud } else { 791 1.80 reinoud error = ENOENT; 792 1.80 reinoud } 793 1.80 reinoud /* done */ 794 1.80 reinoud goto done; 795 1.80 reinoud } 796 1.80 reinoud 797 1.80 reinoud /* 798 1.80 reinoud * XXX NOTE tmpfs has a test here that tests that intermediate 799 1.80 reinoud * components i.e. not the last one ought to be either a directory or 800 1.80 reinoud * a link. It seems to function well without this code. 801 1.80 reinoud */ 802 1.80 reinoud 803 1.83 reinoud /* try to create/reuse the node */ 804 1.108 ad error = udf_get_node(ump, &icb_loc, &res_node, LK_EXCLUSIVE); 805 1.83 reinoud if (error) 806 1.83 reinoud goto out; 807 1.83 reinoud 808 1.84 reinoud /* check permissions */ 809 1.80 reinoud if (islastcn && (cnp->cn_nameiop == DELETE || 810 1.80 reinoud cnp->cn_nameiop == RENAME) ) { 811 1.80 reinoud error = VOP_ACCESS(dvp, VWRITE, cnp->cn_cred); 812 1.83 reinoud if (error) { 813 1.83 reinoud vput(res_node->vnode); 814 1.30 reinoud goto out; 815 1.83 reinoud } 816 1.1 reinoud 817 1.84 reinoud /* 818 1.84 reinoud * Check if the directory has its sticky bit set. If so, ask 819 1.84 reinoud * for clearance since only the owner of a file or directory 820 1.125 andvar * can remove/rename from that directory. 821 1.84 reinoud */ 822 1.80 reinoud mode = udf_getaccessmode(dir_node); 823 1.80 reinoud if ((mode & S_ISTXT) != 0) { 824 1.84 reinoud udf_getownership(dir_node, &d_uid, &d_gid); 825 1.80 reinoud error = kauth_authorize_vnode(cnp->cn_cred, 826 1.80 reinoud KAUTH_VNODE_DELETE, res_node->vnode, 827 1.113 christos dir_node->vnode, genfs_can_sticky(dvp, cnp->cn_cred, 828 1.80 reinoud d_uid, d_uid)); 829 1.80 reinoud if (error) { 830 1.80 reinoud error = EPERM; 831 1.83 reinoud vput(res_node->vnode); 832 1.80 reinoud goto out; 833 1.6 christos } 834 1.6 christos } 835 1.80 reinoud } 836 1.83 reinoud 837 1.80 reinoud *vpp = res_node->vnode; 838 1.1 reinoud 839 1.80 reinoud done: 840 1.1 reinoud /* 841 1.1 reinoud * Store result in the cache if requested. If we are creating a file, 842 1.1 reinoud * the file might not be found and thus putting it into the namecache 843 1.1 reinoud * might be seen as negative caching. 844 1.1 reinoud */ 845 1.72 rmind if (nameiop != CREATE) 846 1.74 dholland cache_enter(dvp, *vpp, cnp->cn_nameptr, cnp->cn_namelen, 847 1.74 dholland cnp->cn_flags); 848 1.1 reinoud 849 1.80 reinoud out: 850 1.90 hannken if (error == 0 && *vpp != dvp) 851 1.90 hannken VOP_UNLOCK(*vpp); 852 1.123 andvar DPRINTFIF(LOOKUP, error, ("udf_lookup returning error %d\n", error)); 853 1.1 reinoud 854 1.1 reinoud return error; 855 1.1 reinoud } 856 1.1 reinoud 857 1.1 reinoud /* --------------------------------------------------------------------- */ 858 1.1 reinoud 859 1.1 reinoud int 860 1.1 reinoud udf_getattr(void *v) 861 1.1 reinoud { 862 1.1 reinoud struct vop_getattr_args /* { 863 1.1 reinoud struct vnode *a_vp; 864 1.1 reinoud struct vattr *a_vap; 865 1.5 elad kauth_cred_t a_cred; 866 1.18 reinoud struct lwp *a_l; 867 1.1 reinoud } */ *ap = v; 868 1.1 reinoud struct vnode *vp = ap->a_vp; 869 1.1 reinoud struct udf_node *udf_node = VTOI(vp); 870 1.1 reinoud struct udf_mount *ump = udf_node->ump; 871 1.18 reinoud struct file_entry *fe = udf_node->fe; 872 1.18 reinoud struct extfile_entry *efe = udf_node->efe; 873 1.21 reinoud struct filetimes_extattr_entry *ft_extattr; 874 1.18 reinoud struct device_extattr_entry *devattr; 875 1.1 reinoud struct vattr *vap = ap->a_vap; 876 1.18 reinoud struct timestamp *atime, *mtime, *attrtime, *creatime; 877 1.18 reinoud uint64_t filesize, blkssize; 878 1.1 reinoud uint32_t nlink; 879 1.21 reinoud uint32_t offset, a_l; 880 1.94 reinoud uint8_t *filedata, *targetbuf; 881 1.1 reinoud uid_t uid; 882 1.1 reinoud gid_t gid; 883 1.94 reinoud int length, error; 884 1.1 reinoud 885 1.1 reinoud DPRINTF(CALL, ("udf_getattr called\n")); 886 1.1 reinoud 887 1.18 reinoud /* update times before we returning values */ 888 1.18 reinoud udf_itimes(udf_node, NULL, NULL, NULL); 889 1.18 reinoud 890 1.1 reinoud /* get descriptor information */ 891 1.18 reinoud if (fe) { 892 1.1 reinoud nlink = udf_rw16(fe->link_cnt); 893 1.1 reinoud uid = (uid_t)udf_rw32(fe->uid); 894 1.1 reinoud gid = (gid_t)udf_rw32(fe->gid); 895 1.1 reinoud filesize = udf_rw64(fe->inf_len); 896 1.1 reinoud blkssize = udf_rw64(fe->logblks_rec); 897 1.1 reinoud atime = &fe->atime; 898 1.1 reinoud mtime = &fe->mtime; 899 1.1 reinoud attrtime = &fe->attrtime; 900 1.21 reinoud filedata = fe->data; 901 1.21 reinoud 902 1.21 reinoud /* initial guess */ 903 1.18 reinoud creatime = mtime; 904 1.21 reinoud 905 1.21 reinoud /* check our extended attribute if present */ 906 1.21 reinoud error = udf_extattr_search_intern(udf_node, 907 1.21 reinoud UDF_FILETIMES_ATTR_NO, "", &offset, &a_l); 908 1.21 reinoud if (!error) { 909 1.21 reinoud ft_extattr = (struct filetimes_extattr_entry *) 910 1.21 reinoud (filedata + offset); 911 1.21 reinoud if (ft_extattr->existence & UDF_FILETIMES_FILE_CREATION) 912 1.21 reinoud creatime = &ft_extattr->times[0]; 913 1.21 reinoud } 914 1.1 reinoud } else { 915 1.1 reinoud assert(udf_node->efe); 916 1.1 reinoud nlink = udf_rw16(efe->link_cnt); 917 1.1 reinoud uid = (uid_t)udf_rw32(efe->uid); 918 1.1 reinoud gid = (gid_t)udf_rw32(efe->gid); 919 1.1 reinoud filesize = udf_rw64(efe->inf_len); /* XXX or obj_size? */ 920 1.1 reinoud blkssize = udf_rw64(efe->logblks_rec); 921 1.1 reinoud atime = &efe->atime; 922 1.1 reinoud mtime = &efe->mtime; 923 1.1 reinoud attrtime = &efe->attrtime; 924 1.18 reinoud creatime = &efe->ctime; 925 1.18 reinoud filedata = efe->data; 926 1.6 christos } 927 1.1 reinoud 928 1.1 reinoud /* do the uid/gid translation game */ 929 1.32 reinoud if (uid == (uid_t) -1) 930 1.1 reinoud uid = ump->mount_args.anon_uid; 931 1.32 reinoud if (gid == (gid_t) -1) 932 1.1 reinoud gid = ump->mount_args.anon_gid; 933 1.18 reinoud 934 1.1 reinoud /* fill in struct vattr with values from the node */ 935 1.57 pooka vattr_null(vap); 936 1.1 reinoud vap->va_type = vp->v_type; 937 1.1 reinoud vap->va_mode = udf_getaccessmode(udf_node); 938 1.1 reinoud vap->va_nlink = nlink; 939 1.1 reinoud vap->va_uid = uid; 940 1.1 reinoud vap->va_gid = gid; 941 1.1 reinoud vap->va_fsid = vp->v_mount->mnt_stat.f_fsidx.__fsid_val[0]; 942 1.51 reinoud vap->va_fileid = udf_get_node_id(&udf_node->loc); /* inode hash XXX */ 943 1.1 reinoud vap->va_size = filesize; 944 1.1 reinoud vap->va_blocksize = udf_node->ump->discinfo.sector_size; /* wise? */ 945 1.1 reinoud 946 1.1 reinoud /* 947 1.1 reinoud * BUG-ALERT: UDF doesn't count '.' as an entry, so we'll have to add 948 1.1 reinoud * 1 to the link count if its a directory we're requested attributes 949 1.1 reinoud * of. 950 1.1 reinoud */ 951 1.1 reinoud if (vap->va_type == VDIR) 952 1.1 reinoud vap->va_nlink++; 953 1.1 reinoud 954 1.94 reinoud /* 955 1.94 reinoud * BUG-ALERT: Posix requires the va_size to be pathlength for symbolic 956 1.94 reinoud * links. 957 1.94 reinoud */ 958 1.94 reinoud if (vap->va_type == VLNK) { 959 1.94 reinoud /* claim temporary buffers for translation */ 960 1.94 reinoud targetbuf = malloc(PATH_MAX+1, M_UDFTEMP, M_WAITOK); 961 1.94 reinoud error = udf_do_readlink(udf_node, filesize, targetbuf, &length); 962 1.94 reinoud if (!error) { 963 1.94 reinoud vap->va_size = length; 964 1.94 reinoud KASSERT(length == strlen(targetbuf)); 965 1.94 reinoud } 966 1.94 reinoud free(targetbuf, M_UDFTEMP); 967 1.94 reinoud /* XXX return error? */ 968 1.94 reinoud } 969 1.94 reinoud 970 1.1 reinoud /* access times */ 971 1.1 reinoud udf_timestamp_to_timespec(ump, atime, &vap->va_atime); 972 1.1 reinoud udf_timestamp_to_timespec(ump, mtime, &vap->va_mtime); 973 1.1 reinoud udf_timestamp_to_timespec(ump, attrtime, &vap->va_ctime); 974 1.18 reinoud udf_timestamp_to_timespec(ump, creatime, &vap->va_birthtime); 975 1.1 reinoud 976 1.1 reinoud vap->va_gen = 1; /* no multiple generations yes (!?) */ 977 1.1 reinoud vap->va_flags = 0; /* no flags */ 978 1.9 reinoud vap->va_bytes = blkssize * udf_node->ump->discinfo.sector_size; 979 1.1 reinoud vap->va_filerev = 1; /* TODO file revision numbers? */ 980 1.18 reinoud vap->va_vaflags = 0; 981 1.18 reinoud /* TODO get vaflags from the extended attributes? */ 982 1.18 reinoud 983 1.18 reinoud if ((vap->va_type == VBLK) || (vap->va_type == VCHR)) { 984 1.18 reinoud error = udf_extattr_search_intern(udf_node, 985 1.18 reinoud UDF_DEVICESPEC_ATTR_NO, "", 986 1.21 reinoud &offset, &a_l); 987 1.18 reinoud /* if error, deny access */ 988 1.18 reinoud if (error || (filedata == NULL)) { 989 1.18 reinoud vap->va_mode = 0; /* or v_type = VNON? */ 990 1.18 reinoud } else { 991 1.18 reinoud devattr = (struct device_extattr_entry *) 992 1.18 reinoud filedata + offset; 993 1.18 reinoud vap->va_rdev = makedev( 994 1.18 reinoud udf_rw32(devattr->major), 995 1.18 reinoud udf_rw32(devattr->minor) 996 1.18 reinoud ); 997 1.18 reinoud /* TODO we could check the implementator */ 998 1.18 reinoud } 999 1.18 reinoud } 1000 1.1 reinoud 1001 1.1 reinoud return 0; 1002 1.1 reinoud } 1003 1.1 reinoud 1004 1.1 reinoud /* --------------------------------------------------------------------- */ 1005 1.1 reinoud 1006 1.18 reinoud static int 1007 1.18 reinoud udf_chown(struct vnode *vp, uid_t new_uid, gid_t new_gid, 1008 1.18 reinoud kauth_cred_t cred) 1009 1.18 reinoud { 1010 1.18 reinoud struct udf_node *udf_node = VTOI(vp); 1011 1.39 elad uid_t uid; 1012 1.39 elad gid_t gid; 1013 1.18 reinoud int error; 1014 1.18 reinoud 1015 1.18 reinoud #ifdef notyet 1016 1.18 reinoud /* TODO get vaflags from the extended attributes? */ 1017 1.18 reinoud /* Immutable or append-only files cannot be modified, either. */ 1018 1.18 reinoud if (udf_node->flags & (IMMUTABLE | APPEND)) 1019 1.18 reinoud return EPERM; 1020 1.18 reinoud #endif 1021 1.18 reinoud 1022 1.18 reinoud if (vp->v_mount->mnt_flag & MNT_RDONLY) 1023 1.18 reinoud return EROFS; 1024 1.18 reinoud 1025 1.18 reinoud /* retrieve old values */ 1026 1.18 reinoud udf_getownership(udf_node, &uid, &gid); 1027 1.18 reinoud 1028 1.18 reinoud /* only one could be specified */ 1029 1.18 reinoud if (new_uid == VNOVAL) 1030 1.18 reinoud new_uid = uid; 1031 1.18 reinoud if (new_gid == VNOVAL) 1032 1.18 reinoud new_gid = gid; 1033 1.18 reinoud 1034 1.18 reinoud /* check if we can fit it in an 32 bits */ 1035 1.54 reinoud if ((uid_t) ((uint32_t) new_uid) != new_uid) 1036 1.18 reinoud return EINVAL; 1037 1.54 reinoud if ((gid_t) ((uint32_t) new_gid) != new_gid) 1038 1.18 reinoud return EINVAL; 1039 1.18 reinoud 1040 1.18 reinoud /* check permissions */ 1041 1.70 elad error = kauth_authorize_vnode(cred, KAUTH_VNODE_CHANGE_OWNERSHIP, 1042 1.113 christos vp, NULL, genfs_can_chown(vp, cred, uid, gid, new_uid, new_gid)); 1043 1.39 elad if (error) 1044 1.39 elad return (error); 1045 1.18 reinoud 1046 1.18 reinoud /* change the ownership */ 1047 1.18 reinoud udf_setownership(udf_node, new_uid, new_gid); 1048 1.18 reinoud 1049 1.18 reinoud /* mark node changed */ 1050 1.18 reinoud udf_node->i_flags |= IN_CHANGE; 1051 1.18 reinoud 1052 1.18 reinoud return 0; 1053 1.18 reinoud } 1054 1.18 reinoud 1055 1.18 reinoud 1056 1.18 reinoud static int 1057 1.18 reinoud udf_chmod(struct vnode *vp, mode_t mode, kauth_cred_t cred) 1058 1.18 reinoud { 1059 1.18 reinoud struct udf_node *udf_node = VTOI(vp); 1060 1.39 elad uid_t uid; 1061 1.39 elad gid_t gid; 1062 1.18 reinoud int error; 1063 1.18 reinoud 1064 1.18 reinoud #ifdef notyet 1065 1.18 reinoud /* TODO get vaflags from the extended attributes? */ 1066 1.18 reinoud /* Immutable or append-only files cannot be modified, either. */ 1067 1.18 reinoud if (udf_node->flags & (IMMUTABLE | APPEND)) 1068 1.18 reinoud return EPERM; 1069 1.18 reinoud #endif 1070 1.18 reinoud 1071 1.18 reinoud if (vp->v_mount->mnt_flag & MNT_RDONLY) 1072 1.18 reinoud return EROFS; 1073 1.18 reinoud 1074 1.18 reinoud /* retrieve uid/gid values */ 1075 1.18 reinoud udf_getownership(udf_node, &uid, &gid); 1076 1.18 reinoud 1077 1.18 reinoud /* check permissions */ 1078 1.70 elad error = kauth_authorize_vnode(cred, KAUTH_VNODE_WRITE_SECURITY, vp, 1079 1.113 christos NULL, genfs_can_chmod(vp, cred, uid, gid, mode)); 1080 1.39 elad if (error) 1081 1.39 elad return (error); 1082 1.18 reinoud 1083 1.18 reinoud /* change mode */ 1084 1.18 reinoud udf_setaccessmode(udf_node, mode); 1085 1.18 reinoud 1086 1.18 reinoud /* mark node changed */ 1087 1.18 reinoud udf_node->i_flags |= IN_CHANGE; 1088 1.18 reinoud 1089 1.18 reinoud return 0; 1090 1.18 reinoud } 1091 1.18 reinoud 1092 1.18 reinoud 1093 1.18 reinoud /* exported */ 1094 1.18 reinoud int 1095 1.18 reinoud udf_chsize(struct vnode *vp, u_quad_t newsize, kauth_cred_t cred) 1096 1.18 reinoud { 1097 1.18 reinoud struct udf_node *udf_node = VTOI(vp); 1098 1.18 reinoud int error, extended; 1099 1.18 reinoud 1100 1.18 reinoud if (vp->v_mount->mnt_flag & MNT_RDONLY) 1101 1.18 reinoud return EROFS; 1102 1.18 reinoud 1103 1.18 reinoud /* Decide whether this is a valid operation based on the file type. */ 1104 1.18 reinoud switch (vp->v_type) { 1105 1.18 reinoud case VDIR: 1106 1.18 reinoud return EISDIR; 1107 1.18 reinoud case VREG: 1108 1.18 reinoud if (vp->v_mount->mnt_flag & MNT_RDONLY) 1109 1.18 reinoud return EROFS; 1110 1.18 reinoud break; 1111 1.18 reinoud case VBLK: 1112 1.18 reinoud /* FALLTHROUGH */ 1113 1.18 reinoud case VCHR: 1114 1.18 reinoud /* FALLTHROUGH */ 1115 1.18 reinoud case VFIFO: 1116 1.18 reinoud /* Allow modifications of special files even if in the file 1117 1.18 reinoud * system is mounted read-only (we are not modifying the 1118 1.18 reinoud * files themselves, but the objects they represent). */ 1119 1.18 reinoud return 0; 1120 1.18 reinoud default: 1121 1.18 reinoud /* Anything else is unsupported. */ 1122 1.18 reinoud return EOPNOTSUPP; 1123 1.18 reinoud } 1124 1.18 reinoud 1125 1.18 reinoud #if notyet 1126 1.18 reinoud /* TODO get vaflags from the extended attributes? */ 1127 1.18 reinoud /* Immutable or append-only files cannot be modified, either. */ 1128 1.18 reinoud if (node->flags & (IMMUTABLE | APPEND)) 1129 1.18 reinoud return EPERM; 1130 1.18 reinoud #endif 1131 1.18 reinoud 1132 1.18 reinoud /* resize file to the requested size */ 1133 1.18 reinoud error = udf_resize_node(udf_node, newsize, &extended); 1134 1.18 reinoud 1135 1.18 reinoud if (error == 0) { 1136 1.18 reinoud /* mark change */ 1137 1.18 reinoud udf_node->i_flags |= IN_CHANGE | IN_MODIFY; 1138 1.69 christos if (vp->v_mount->mnt_flag & MNT_RELATIME) 1139 1.69 christos udf_node->i_flags |= IN_ACCESS; 1140 1.20 reinoud udf_update(vp, NULL, NULL, NULL, 0); 1141 1.18 reinoud } 1142 1.18 reinoud 1143 1.18 reinoud return error; 1144 1.18 reinoud } 1145 1.18 reinoud 1146 1.18 reinoud 1147 1.18 reinoud static int 1148 1.18 reinoud udf_chflags(struct vnode *vp, mode_t mode, kauth_cred_t cred) 1149 1.18 reinoud { 1150 1.18 reinoud if (vp->v_mount->mnt_flag & MNT_RDONLY) 1151 1.18 reinoud return EROFS; 1152 1.18 reinoud 1153 1.81 reinoud /* 1154 1.81 reinoud * XXX we can't do this yet, as its not described in the standard yet 1155 1.81 reinoud */ 1156 1.18 reinoud 1157 1.81 reinoud return EOPNOTSUPP; 1158 1.18 reinoud } 1159 1.18 reinoud 1160 1.18 reinoud 1161 1.18 reinoud static int 1162 1.18 reinoud udf_chtimes(struct vnode *vp, 1163 1.18 reinoud struct timespec *atime, struct timespec *mtime, 1164 1.18 reinoud struct timespec *birthtime, int setattrflags, 1165 1.18 reinoud kauth_cred_t cred) 1166 1.18 reinoud { 1167 1.18 reinoud struct udf_node *udf_node = VTOI(vp); 1168 1.41 elad uid_t uid; 1169 1.18 reinoud gid_t gid; 1170 1.18 reinoud int error; 1171 1.18 reinoud 1172 1.18 reinoud #ifdef notyet 1173 1.18 reinoud /* TODO get vaflags from the extended attributes? */ 1174 1.18 reinoud /* Immutable or append-only files cannot be modified, either. */ 1175 1.18 reinoud if (udf_node->flags & (IMMUTABLE | APPEND)) 1176 1.18 reinoud return EPERM; 1177 1.18 reinoud #endif 1178 1.18 reinoud 1179 1.18 reinoud if (vp->v_mount->mnt_flag & MNT_RDONLY) 1180 1.18 reinoud return EROFS; 1181 1.18 reinoud 1182 1.18 reinoud /* retrieve uid/gid values */ 1183 1.18 reinoud udf_getownership(udf_node, &uid, &gid); 1184 1.18 reinoud 1185 1.18 reinoud /* check permissions */ 1186 1.70 elad error = kauth_authorize_vnode(cred, KAUTH_VNODE_WRITE_TIMES, vp, 1187 1.113 christos NULL, genfs_can_chtimes(vp, cred, uid, setattrflags)); 1188 1.41 elad if (error) 1189 1.41 elad return (error); 1190 1.18 reinoud 1191 1.18 reinoud /* update node flags depending on what times are passed */ 1192 1.18 reinoud if (atime->tv_sec != VNOVAL) 1193 1.18 reinoud if (!(vp->v_mount->mnt_flag & MNT_NOATIME)) 1194 1.18 reinoud udf_node->i_flags |= IN_ACCESS; 1195 1.69 christos if ((mtime->tv_sec != VNOVAL) || (birthtime->tv_sec != VNOVAL)) { 1196 1.18 reinoud udf_node->i_flags |= IN_CHANGE | IN_UPDATE; 1197 1.69 christos if (vp->v_mount->mnt_flag & MNT_RELATIME) 1198 1.69 christos udf_node->i_flags |= IN_ACCESS; 1199 1.69 christos } 1200 1.18 reinoud 1201 1.20 reinoud return udf_update(vp, atime, mtime, birthtime, 0); 1202 1.18 reinoud } 1203 1.18 reinoud 1204 1.18 reinoud 1205 1.1 reinoud int 1206 1.1 reinoud udf_setattr(void *v) 1207 1.1 reinoud { 1208 1.1 reinoud struct vop_setattr_args /* { 1209 1.1 reinoud struct vnode *a_vp; 1210 1.1 reinoud struct vattr *a_vap; 1211 1.5 elad kauth_cred_t a_cred; 1212 1.18 reinoud struct lwp *a_l; 1213 1.1 reinoud } */ *ap = v; 1214 1.1 reinoud struct vnode *vp = ap->a_vp; 1215 1.18 reinoud /* struct udf_node *udf_node = VTOI(vp); */ 1216 1.18 reinoud /* struct udf_mount *ump = udf_node->ump; */ 1217 1.18 reinoud kauth_cred_t cred = ap->a_cred; 1218 1.1 reinoud struct vattr *vap = ap->a_vap; 1219 1.18 reinoud int error; 1220 1.18 reinoud 1221 1.18 reinoud DPRINTF(CALL, ("udf_setattr called\n")); 1222 1.18 reinoud 1223 1.18 reinoud /* Abort if any unsettable attribute is given. */ 1224 1.18 reinoud error = 0; 1225 1.18 reinoud if (vap->va_type != VNON || 1226 1.18 reinoud vap->va_nlink != VNOVAL || 1227 1.18 reinoud vap->va_fsid != VNOVAL || 1228 1.18 reinoud vap->va_fileid != VNOVAL || 1229 1.18 reinoud vap->va_blocksize != VNOVAL || 1230 1.18 reinoud #ifdef notyet 1231 1.20 reinoud /* checks are debated */ 1232 1.18 reinoud vap->va_ctime.tv_sec != VNOVAL || 1233 1.18 reinoud vap->va_ctime.tv_nsec != VNOVAL || 1234 1.18 reinoud vap->va_birthtime.tv_sec != VNOVAL || 1235 1.18 reinoud vap->va_birthtime.tv_nsec != VNOVAL || 1236 1.20 reinoud #endif 1237 1.18 reinoud vap->va_gen != VNOVAL || 1238 1.18 reinoud vap->va_rdev != VNOVAL || 1239 1.18 reinoud vap->va_bytes != VNOVAL) 1240 1.18 reinoud error = EINVAL; 1241 1.18 reinoud 1242 1.18 reinoud DPRINTF(ATTR, ("setattr changing:\n")); 1243 1.18 reinoud if (error == 0 && (vap->va_flags != VNOVAL)) { 1244 1.18 reinoud DPRINTF(ATTR, ("\tchflags\n")); 1245 1.18 reinoud error = udf_chflags(vp, vap->va_flags, cred); 1246 1.18 reinoud } 1247 1.1 reinoud 1248 1.18 reinoud if (error == 0 && (vap->va_size != VNOVAL)) { 1249 1.18 reinoud DPRINTF(ATTR, ("\tchsize\n")); 1250 1.18 reinoud error = udf_chsize(vp, vap->va_size, cred); 1251 1.18 reinoud } 1252 1.1 reinoud 1253 1.18 reinoud if (error == 0 && (vap->va_uid != VNOVAL || vap->va_gid != VNOVAL)) { 1254 1.18 reinoud DPRINTF(ATTR, ("\tchown\n")); 1255 1.18 reinoud error = udf_chown(vp, vap->va_uid, vap->va_gid, cred); 1256 1.18 reinoud } 1257 1.1 reinoud 1258 1.18 reinoud if (error == 0 && (vap->va_mode != VNOVAL)) { 1259 1.18 reinoud DPRINTF(ATTR, ("\tchmod\n")); 1260 1.18 reinoud error = udf_chmod(vp, vap->va_mode, cred); 1261 1.18 reinoud } 1262 1.1 reinoud 1263 1.18 reinoud if (error == 0 && 1264 1.18 reinoud ((vap->va_atime.tv_sec != VNOVAL && 1265 1.18 reinoud vap->va_atime.tv_nsec != VNOVAL) || 1266 1.18 reinoud (vap->va_mtime.tv_sec != VNOVAL && 1267 1.18 reinoud vap->va_mtime.tv_nsec != VNOVAL)) 1268 1.18 reinoud ) { 1269 1.18 reinoud DPRINTF(ATTR, ("\tchtimes\n")); 1270 1.18 reinoud error = udf_chtimes(vp, &vap->va_atime, &vap->va_mtime, 1271 1.18 reinoud &vap->va_birthtime, vap->va_vaflags, cred); 1272 1.6 christos } 1273 1.18 reinoud 1274 1.18 reinoud return error; 1275 1.1 reinoud } 1276 1.1 reinoud 1277 1.1 reinoud /* --------------------------------------------------------------------- */ 1278 1.1 reinoud 1279 1.1 reinoud /* 1280 1.1 reinoud * Return POSIX pathconf information for UDF file systems. 1281 1.1 reinoud */ 1282 1.1 reinoud int 1283 1.1 reinoud udf_pathconf(void *v) 1284 1.1 reinoud { 1285 1.1 reinoud struct vop_pathconf_args /* { 1286 1.1 reinoud struct vnode *a_vp; 1287 1.1 reinoud int a_name; 1288 1.1 reinoud register_t *a_retval; 1289 1.1 reinoud } */ *ap = v; 1290 1.1 reinoud uint32_t bits; 1291 1.1 reinoud 1292 1.1 reinoud DPRINTF(CALL, ("udf_pathconf called\n")); 1293 1.1 reinoud 1294 1.1 reinoud switch (ap->a_name) { 1295 1.1 reinoud case _PC_LINK_MAX: 1296 1.1 reinoud *ap->a_retval = (1<<16)-1; /* 16 bits */ 1297 1.1 reinoud return 0; 1298 1.1 reinoud case _PC_NAME_MAX: 1299 1.67 christos *ap->a_retval = UDF_MAXNAMLEN; 1300 1.1 reinoud return 0; 1301 1.1 reinoud case _PC_PATH_MAX: 1302 1.1 reinoud *ap->a_retval = PATH_MAX; 1303 1.1 reinoud return 0; 1304 1.1 reinoud case _PC_PIPE_BUF: 1305 1.1 reinoud *ap->a_retval = PIPE_BUF; 1306 1.1 reinoud return 0; 1307 1.1 reinoud case _PC_CHOWN_RESTRICTED: 1308 1.1 reinoud *ap->a_retval = 1; 1309 1.1 reinoud return 0; 1310 1.1 reinoud case _PC_NO_TRUNC: 1311 1.1 reinoud *ap->a_retval = 1; 1312 1.1 reinoud return 0; 1313 1.1 reinoud case _PC_SYNC_IO: 1314 1.1 reinoud *ap->a_retval = 0; /* synchronised is off for performance */ 1315 1.1 reinoud return 0; 1316 1.1 reinoud case _PC_FILESIZEBITS: 1317 1.18 reinoud /* 64 bit file offsets -> 2+floor(2log(2^64-1)) = 2 + 63 = 65 */ 1318 1.18 reinoud bits = 64; /* XXX ought to deliver 65 */ 1319 1.18 reinoud #if 0 1320 1.1 reinoud if (udf_node) 1321 1.18 reinoud bits = 64 * vp->v_mount->mnt_dev_bshift; 1322 1.18 reinoud #endif 1323 1.1 reinoud *ap->a_retval = bits; 1324 1.1 reinoud return 0; 1325 1.114 christos default: 1326 1.114 christos return genfs_pathconf(ap); 1327 1.6 christos } 1328 1.1 reinoud } 1329 1.1 reinoud 1330 1.1 reinoud 1331 1.1 reinoud /* --------------------------------------------------------------------- */ 1332 1.1 reinoud 1333 1.1 reinoud int 1334 1.1 reinoud udf_open(void *v) 1335 1.1 reinoud { 1336 1.1 reinoud struct vop_open_args /* { 1337 1.1 reinoud struct vnode *a_vp; 1338 1.1 reinoud int a_mode; 1339 1.5 elad kauth_cred_t a_cred; 1340 1.1 reinoud struct proc *a_p; 1341 1.7 christos } */ *ap = v; 1342 1.18 reinoud int flags; 1343 1.1 reinoud 1344 1.1 reinoud DPRINTF(CALL, ("udf_open called\n")); 1345 1.18 reinoud 1346 1.18 reinoud /* 1347 1.18 reinoud * Files marked append-only must be opened for appending. 1348 1.126 andvar * TODO: get chflags(2) flags from extended attribute. 1349 1.18 reinoud */ 1350 1.18 reinoud flags = 0; 1351 1.18 reinoud if ((flags & APPEND) && (ap->a_mode & (FWRITE | O_APPEND)) == FWRITE) 1352 1.18 reinoud return (EPERM); 1353 1.1 reinoud 1354 1.1 reinoud return 0; 1355 1.1 reinoud } 1356 1.1 reinoud 1357 1.1 reinoud 1358 1.1 reinoud /* --------------------------------------------------------------------- */ 1359 1.1 reinoud 1360 1.1 reinoud int 1361 1.1 reinoud udf_close(void *v) 1362 1.1 reinoud { 1363 1.1 reinoud struct vop_close_args /* { 1364 1.1 reinoud struct vnode *a_vp; 1365 1.1 reinoud int a_fflag; 1366 1.5 elad kauth_cred_t a_cred; 1367 1.1 reinoud struct proc *a_p; 1368 1.1 reinoud } */ *ap = v; 1369 1.1 reinoud struct vnode *vp = ap->a_vp; 1370 1.1 reinoud struct udf_node *udf_node = VTOI(vp); 1371 1.55 reinoud int async = vp->v_mount->mnt_flag & MNT_ASYNC; 1372 1.55 reinoud int error; 1373 1.1 reinoud 1374 1.1 reinoud DPRINTF(CALL, ("udf_close called\n")); 1375 1.1 reinoud udf_node = udf_node; /* shut up gcc */ 1376 1.1 reinoud 1377 1.55 reinoud if (!async && (vp->v_type != VDIR)) { 1378 1.109 ad rw_enter(vp->v_uobj.vmobjlock, RW_WRITER); 1379 1.55 reinoud error = VOP_PUTPAGES(vp, 0, 0, PGO_CLEANIT); 1380 1.55 reinoud if (error) 1381 1.55 reinoud return error; 1382 1.55 reinoud } 1383 1.55 reinoud 1384 1.66 rmind mutex_enter(vp->v_interlock); 1385 1.110 ad if (vrefcnt(vp) > 1) 1386 1.110 ad udf_itimes(udf_node, NULL, NULL, NULL); 1387 1.66 rmind mutex_exit(vp->v_interlock); 1388 1.1 reinoud 1389 1.1 reinoud return 0; 1390 1.1 reinoud } 1391 1.1 reinoud 1392 1.1 reinoud 1393 1.1 reinoud /* --------------------------------------------------------------------- */ 1394 1.1 reinoud 1395 1.48 elad static int 1396 1.49 pgoyette udf_check_possible(struct vnode *vp, struct vattr *vap, mode_t mode) 1397 1.1 reinoud { 1398 1.18 reinoud int flags; 1399 1.1 reinoud 1400 1.1 reinoud /* check if we are allowed to write */ 1401 1.48 elad switch (vap->va_type) { 1402 1.1 reinoud case VDIR: 1403 1.1 reinoud case VLNK: 1404 1.1 reinoud case VREG: 1405 1.1 reinoud /* 1406 1.1 reinoud * normal nodes: check if we're on a read-only mounted 1407 1.1 reinoud * filingsystem and bomb out if we're trying to write. 1408 1.1 reinoud */ 1409 1.1 reinoud if ((mode & VWRITE) && (vp->v_mount->mnt_flag & MNT_RDONLY)) 1410 1.1 reinoud return EROFS; 1411 1.1 reinoud break; 1412 1.1 reinoud case VBLK: 1413 1.1 reinoud case VCHR: 1414 1.1 reinoud case VSOCK: 1415 1.1 reinoud case VFIFO: 1416 1.1 reinoud /* 1417 1.1 reinoud * special nodes: even on read-only mounted filingsystems 1418 1.1 reinoud * these are allowed to be written to if permissions allow. 1419 1.1 reinoud */ 1420 1.1 reinoud break; 1421 1.1 reinoud default: 1422 1.1 reinoud /* no idea what this is */ 1423 1.1 reinoud return EINVAL; 1424 1.1 reinoud } 1425 1.1 reinoud 1426 1.18 reinoud /* noone may write immutable files */ 1427 1.126 andvar /* TODO: get chflags(2) flags from extended attribute. */ 1428 1.18 reinoud flags = 0; 1429 1.18 reinoud if ((mode & VWRITE) && (flags & IMMUTABLE)) 1430 1.18 reinoud return EPERM; 1431 1.1 reinoud 1432 1.48 elad return 0; 1433 1.48 elad } 1434 1.48 elad 1435 1.48 elad static int 1436 1.113 christos udf_check_permitted(struct vnode *vp, struct vattr *vap, accmode_t accmode, 1437 1.48 elad kauth_cred_t cred) 1438 1.48 elad { 1439 1.44 elad /* ask the generic genfs_can_access to advice on security */ 1440 1.113 christos return kauth_authorize_vnode(cred, KAUTH_ACCESS_ACTION(accmode, 1441 1.113 christos vp->v_type, vap->va_mode), vp, NULL, genfs_can_access(vp, cred, 1442 1.113 christos vap->va_uid, vap->va_gid, vap->va_mode, NULL, accmode)); 1443 1.1 reinoud } 1444 1.1 reinoud 1445 1.48 elad int 1446 1.48 elad udf_access(void *v) 1447 1.48 elad { 1448 1.48 elad struct vop_access_args /* { 1449 1.48 elad struct vnode *a_vp; 1450 1.113 christos accmode_t a_accmode; 1451 1.48 elad kauth_cred_t a_cred; 1452 1.48 elad struct proc *a_p; 1453 1.48 elad } */ *ap = v; 1454 1.48 elad struct vnode *vp = ap->a_vp; 1455 1.113 christos accmode_t accmode = ap->a_accmode; 1456 1.48 elad kauth_cred_t cred = ap->a_cred; 1457 1.48 elad /* struct udf_node *udf_node = VTOI(vp); */ 1458 1.48 elad struct vattr vap; 1459 1.48 elad int error; 1460 1.48 elad 1461 1.48 elad DPRINTF(CALL, ("udf_access called\n")); 1462 1.48 elad 1463 1.48 elad error = VOP_GETATTR(vp, &vap, NULL); 1464 1.48 elad if (error) 1465 1.48 elad return error; 1466 1.48 elad 1467 1.113 christos error = udf_check_possible(vp, &vap, accmode); 1468 1.48 elad if (error) 1469 1.48 elad return error; 1470 1.48 elad 1471 1.113 christos error = udf_check_permitted(vp, &vap, accmode, cred); 1472 1.48 elad 1473 1.48 elad return error; 1474 1.48 elad } 1475 1.48 elad 1476 1.1 reinoud /* --------------------------------------------------------------------- */ 1477 1.1 reinoud 1478 1.1 reinoud int 1479 1.1 reinoud udf_create(void *v) 1480 1.1 reinoud { 1481 1.89 hannken struct vop_create_v3_args /* { 1482 1.1 reinoud struct vnode *a_dvp; 1483 1.1 reinoud struct vnode **a_vpp; 1484 1.1 reinoud struct componentname *a_cnp; 1485 1.1 reinoud struct vattr *a_vap; 1486 1.1 reinoud } */ *ap = v; 1487 1.18 reinoud struct vnode *dvp = ap->a_dvp; 1488 1.18 reinoud struct vnode **vpp = ap->a_vpp; 1489 1.18 reinoud struct vattr *vap = ap->a_vap; 1490 1.1 reinoud struct componentname *cnp = ap->a_cnp; 1491 1.18 reinoud int error; 1492 1.1 reinoud 1493 1.18 reinoud DPRINTF(CALL, ("udf_create called\n")); 1494 1.18 reinoud error = udf_create_node(dvp, vpp, vap, cnp); 1495 1.1 reinoud 1496 1.18 reinoud return error; 1497 1.1 reinoud } 1498 1.1 reinoud 1499 1.1 reinoud /* --------------------------------------------------------------------- */ 1500 1.1 reinoud 1501 1.1 reinoud int 1502 1.1 reinoud udf_mknod(void *v) 1503 1.1 reinoud { 1504 1.89 hannken struct vop_mknod_v3_args /* { 1505 1.1 reinoud struct vnode *a_dvp; 1506 1.1 reinoud struct vnode **a_vpp; 1507 1.1 reinoud struct componentname *a_cnp; 1508 1.1 reinoud struct vattr *a_vap; 1509 1.1 reinoud } */ *ap = v; 1510 1.18 reinoud struct vnode *dvp = ap->a_dvp; 1511 1.18 reinoud struct vnode **vpp = ap->a_vpp; 1512 1.18 reinoud struct vattr *vap = ap->a_vap; 1513 1.18 reinoud struct componentname *cnp = ap->a_cnp; 1514 1.18 reinoud int error; 1515 1.1 reinoud 1516 1.18 reinoud DPRINTF(CALL, ("udf_mknod called\n")); 1517 1.18 reinoud error = udf_create_node(dvp, vpp, vap, cnp); 1518 1.1 reinoud 1519 1.18 reinoud return error; 1520 1.1 reinoud } 1521 1.1 reinoud 1522 1.1 reinoud /* --------------------------------------------------------------------- */ 1523 1.1 reinoud 1524 1.1 reinoud int 1525 1.18 reinoud udf_mkdir(void *v) 1526 1.1 reinoud { 1527 1.89 hannken struct vop_mkdir_v3_args /* { 1528 1.1 reinoud struct vnode *a_dvp; 1529 1.18 reinoud struct vnode **a_vpp; 1530 1.1 reinoud struct componentname *a_cnp; 1531 1.18 reinoud struct vattr *a_vap; 1532 1.1 reinoud } */ *ap = v; 1533 1.18 reinoud struct vnode *dvp = ap->a_dvp; 1534 1.18 reinoud struct vnode **vpp = ap->a_vpp; 1535 1.18 reinoud struct vattr *vap = ap->a_vap; 1536 1.18 reinoud struct componentname *cnp = ap->a_cnp; 1537 1.18 reinoud int error; 1538 1.1 reinoud 1539 1.18 reinoud DPRINTF(CALL, ("udf_mkdir called\n")); 1540 1.18 reinoud error = udf_create_node(dvp, vpp, vap, cnp); 1541 1.1 reinoud 1542 1.18 reinoud return error; 1543 1.1 reinoud } 1544 1.1 reinoud 1545 1.1 reinoud /* --------------------------------------------------------------------- */ 1546 1.1 reinoud 1547 1.121 christos int 1548 1.121 christos udf_link(void *v) 1549 1.18 reinoud { 1550 1.121 christos struct vop_link_v2_args /* { 1551 1.121 christos struct vnode *a_dvp; 1552 1.121 christos struct vnode *a_vp; 1553 1.121 christos struct componentname *a_cnp; 1554 1.121 christos } */ *ap = v; 1555 1.121 christos struct vnode *dvp = ap->a_dvp; 1556 1.121 christos struct vnode *vp = ap->a_vp; 1557 1.121 christos struct componentname *cnp = ap->a_cnp; 1558 1.18 reinoud struct udf_node *udf_node, *dir_node; 1559 1.18 reinoud struct vattr vap; 1560 1.121 christos int error, abrt = 1; 1561 1.18 reinoud 1562 1.18 reinoud DPRINTF(CALL, ("udf_link called\n")); 1563 1.63 rmind KASSERT(dvp != vp); 1564 1.63 rmind KASSERT(vp->v_type != VDIR); 1565 1.63 rmind KASSERT(dvp->v_mount == vp->v_mount); 1566 1.18 reinoud 1567 1.18 reinoud /* get attributes */ 1568 1.18 reinoud dir_node = VTOI(dvp); 1569 1.18 reinoud udf_node = VTOI(vp); 1570 1.18 reinoud 1571 1.121 christos if ((error = vn_lock(vp, LK_EXCLUSIVE))) { 1572 1.122 reinoud DPRINTF(LOCKING, ("exclusive lock failed for vnode %p\n", vp)); 1573 1.121 christos goto out; 1574 1.121 christos } 1575 1.121 christos 1576 1.18 reinoud error = VOP_GETATTR(vp, &vap, FSCRED); 1577 1.120 christos if (error) 1578 1.121 christos goto out1; 1579 1.18 reinoud 1580 1.18 reinoud /* check link count overflow */ 1581 1.58 hannken if (vap.va_nlink >= (1<<16)-1) { /* uint16_t */ 1582 1.120 christos error = EMLINK; 1583 1.121 christos goto out1; 1584 1.58 hannken } 1585 1.120 christos error = kauth_authorize_vnode(cnp->cn_cred, KAUTH_VNODE_ADD_LINK, vp, 1586 1.120 christos dvp, 0); 1587 1.120 christos if (error) 1588 1.121 christos goto out1; 1589 1.121 christos abrt = 0; 1590 1.58 hannken error = udf_dir_attach(dir_node->ump, dir_node, udf_node, &vap, cnp); 1591 1.121 christos out1: 1592 1.121 christos VOP_UNLOCK(vp); 1593 1.120 christos out: 1594 1.121 christos if (abrt) 1595 1.18 reinoud VOP_ABORTOP(dvp, cnp); 1596 1.18 reinoud return error; 1597 1.1 reinoud } 1598 1.1 reinoud 1599 1.1 reinoud /* --------------------------------------------------------------------- */ 1600 1.1 reinoud 1601 1.18 reinoud static int 1602 1.18 reinoud udf_do_symlink(struct udf_node *udf_node, char *target) 1603 1.18 reinoud { 1604 1.18 reinoud struct pathcomp pathcomp; 1605 1.18 reinoud uint8_t *pathbuf, *pathpos, *compnamepos; 1606 1.18 reinoud char *mntonname; 1607 1.18 reinoud int pathlen, len, compnamelen, mntonnamelen; 1608 1.18 reinoud int error; 1609 1.18 reinoud 1610 1.18 reinoud /* process `target' to an UDF structure */ 1611 1.18 reinoud pathbuf = malloc(UDF_SYMLINKBUFLEN, M_UDFTEMP, M_WAITOK); 1612 1.18 reinoud pathpos = pathbuf; 1613 1.18 reinoud pathlen = 0; 1614 1.18 reinoud 1615 1.18 reinoud if (*target == '/') { 1616 1.18 reinoud /* symlink starts from the root */ 1617 1.18 reinoud len = UDF_PATH_COMP_SIZE; 1618 1.18 reinoud memset(&pathcomp, 0, len); 1619 1.18 reinoud pathcomp.type = UDF_PATH_COMP_ROOT; 1620 1.18 reinoud 1621 1.18 reinoud /* check if its mount-point relative! */ 1622 1.18 reinoud mntonname = udf_node->ump->vfs_mountp->mnt_stat.f_mntonname; 1623 1.18 reinoud mntonnamelen = strlen(mntonname); 1624 1.18 reinoud if (strlen(target) >= mntonnamelen) { 1625 1.18 reinoud if (strncmp(target, mntonname, mntonnamelen) == 0) { 1626 1.18 reinoud pathcomp.type = UDF_PATH_COMP_MOUNTROOT; 1627 1.18 reinoud target += mntonnamelen; 1628 1.18 reinoud } 1629 1.18 reinoud } else { 1630 1.18 reinoud target++; 1631 1.18 reinoud } 1632 1.18 reinoud 1633 1.18 reinoud memcpy(pathpos, &pathcomp, len); 1634 1.18 reinoud pathpos += len; 1635 1.18 reinoud pathlen += len; 1636 1.18 reinoud } 1637 1.18 reinoud 1638 1.18 reinoud error = 0; 1639 1.18 reinoud while (*target) { 1640 1.18 reinoud /* ignore multiple '/' */ 1641 1.18 reinoud while (*target == '/') { 1642 1.18 reinoud target++; 1643 1.18 reinoud } 1644 1.18 reinoud if (!*target) 1645 1.18 reinoud break; 1646 1.18 reinoud 1647 1.18 reinoud /* extract component name */ 1648 1.18 reinoud compnamelen = 0; 1649 1.18 reinoud compnamepos = target; 1650 1.18 reinoud while ((*target) && (*target != '/')) { 1651 1.18 reinoud target++; 1652 1.18 reinoud compnamelen++; 1653 1.18 reinoud } 1654 1.18 reinoud 1655 1.18 reinoud /* just trunc if too long ?? (security issue) */ 1656 1.18 reinoud if (compnamelen >= 127) { 1657 1.18 reinoud error = ENAMETOOLONG; 1658 1.18 reinoud break; 1659 1.18 reinoud } 1660 1.18 reinoud 1661 1.18 reinoud /* convert unix name to UDF name */ 1662 1.18 reinoud len = sizeof(struct pathcomp); 1663 1.18 reinoud memset(&pathcomp, 0, len); 1664 1.18 reinoud pathcomp.type = UDF_PATH_COMP_NAME; 1665 1.18 reinoud len = UDF_PATH_COMP_SIZE; 1666 1.18 reinoud 1667 1.18 reinoud if ((compnamelen == 2) && (strncmp(compnamepos, "..", 2) == 0)) 1668 1.18 reinoud pathcomp.type = UDF_PATH_COMP_PARENTDIR; 1669 1.18 reinoud if ((compnamelen == 1) && (*compnamepos == '.')) 1670 1.18 reinoud pathcomp.type = UDF_PATH_COMP_CURDIR; 1671 1.18 reinoud 1672 1.18 reinoud if (pathcomp.type == UDF_PATH_COMP_NAME) { 1673 1.18 reinoud unix_to_udf_name( 1674 1.18 reinoud (char *) &pathcomp.ident, &pathcomp.l_ci, 1675 1.18 reinoud compnamepos, compnamelen, 1676 1.18 reinoud &udf_node->ump->logical_vol->desc_charset); 1677 1.18 reinoud len = UDF_PATH_COMP_SIZE + pathcomp.l_ci; 1678 1.18 reinoud } 1679 1.18 reinoud 1680 1.18 reinoud if (pathlen + len >= UDF_SYMLINKBUFLEN) { 1681 1.18 reinoud error = ENAMETOOLONG; 1682 1.18 reinoud break; 1683 1.18 reinoud } 1684 1.18 reinoud 1685 1.18 reinoud memcpy(pathpos, &pathcomp, len); 1686 1.18 reinoud pathpos += len; 1687 1.18 reinoud pathlen += len; 1688 1.18 reinoud } 1689 1.18 reinoud 1690 1.18 reinoud if (error) { 1691 1.118 andvar /* apparently too big */ 1692 1.18 reinoud free(pathbuf, M_UDFTEMP); 1693 1.18 reinoud return error; 1694 1.18 reinoud } 1695 1.18 reinoud 1696 1.18 reinoud error = udf_grow_node(udf_node, pathlen); 1697 1.18 reinoud if (error) { 1698 1.18 reinoud /* failed to pregrow node */ 1699 1.18 reinoud free(pathbuf, M_UDFTEMP); 1700 1.18 reinoud return error; 1701 1.18 reinoud } 1702 1.18 reinoud 1703 1.18 reinoud /* write out structure on the new file */ 1704 1.18 reinoud error = vn_rdwr(UIO_WRITE, udf_node->vnode, 1705 1.18 reinoud pathbuf, pathlen, 0, 1706 1.124 hannken UIO_SYSSPACE, IO_ALTSEMANTICS, 1707 1.18 reinoud FSCRED, NULL, NULL); 1708 1.18 reinoud 1709 1.38 reinoud /* return status of symlink contents writeout */ 1710 1.38 reinoud free(pathbuf, M_UDFTEMP); 1711 1.38 reinoud return error; 1712 1.18 reinoud } 1713 1.18 reinoud 1714 1.18 reinoud 1715 1.1 reinoud int 1716 1.1 reinoud udf_symlink(void *v) 1717 1.1 reinoud { 1718 1.89 hannken struct vop_symlink_v3_args /* { 1719 1.1 reinoud struct vnode *a_dvp; 1720 1.1 reinoud struct vnode **a_vpp; 1721 1.1 reinoud struct componentname *a_cnp; 1722 1.1 reinoud struct vattr *a_vap; 1723 1.1 reinoud char *a_target; 1724 1.1 reinoud } */ *ap = v; 1725 1.18 reinoud struct vnode *dvp = ap->a_dvp; 1726 1.18 reinoud struct vnode **vpp = ap->a_vpp; 1727 1.18 reinoud struct vattr *vap = ap->a_vap; 1728 1.1 reinoud struct componentname *cnp = ap->a_cnp; 1729 1.18 reinoud struct udf_node *dir_node; 1730 1.18 reinoud struct udf_node *udf_node; 1731 1.18 reinoud int error; 1732 1.1 reinoud 1733 1.18 reinoud DPRINTF(CALL, ("udf_symlink called\n")); 1734 1.18 reinoud DPRINTF(CALL, ("\tlinking to `%s`\n", ap->a_target)); 1735 1.18 reinoud error = udf_create_node(dvp, vpp, vap, cnp); 1736 1.18 reinoud KASSERT(((error == 0) && (*vpp != NULL)) || ((error && (*vpp == NULL)))); 1737 1.18 reinoud if (!error) { 1738 1.18 reinoud dir_node = VTOI(dvp); 1739 1.18 reinoud udf_node = VTOI(*vpp); 1740 1.18 reinoud KASSERT(udf_node); 1741 1.18 reinoud error = udf_do_symlink(udf_node, ap->a_target); 1742 1.18 reinoud if (error) { 1743 1.18 reinoud /* remove node */ 1744 1.18 reinoud udf_dir_detach(udf_node->ump, dir_node, udf_node, cnp); 1745 1.96 reinoud vrele(*vpp); 1746 1.96 reinoud *vpp = NULL; 1747 1.18 reinoud } 1748 1.18 reinoud } 1749 1.18 reinoud return error; 1750 1.1 reinoud } 1751 1.1 reinoud 1752 1.1 reinoud /* --------------------------------------------------------------------- */ 1753 1.1 reinoud 1754 1.94 reinoud static int 1755 1.94 reinoud udf_do_readlink(struct udf_node *udf_node, uint64_t filesize, 1756 1.94 reinoud uint8_t *targetbuf, int *length) 1757 1.1 reinoud { 1758 1.18 reinoud struct pathcomp pathcomp; 1759 1.94 reinoud uint8_t *pathbuf, *tmpname; 1760 1.18 reinoud uint8_t *pathpos, *targetpos; 1761 1.18 reinoud char *mntonname; 1762 1.18 reinoud int pathlen, targetlen, namelen, mntonnamelen, len, l_ci; 1763 1.18 reinoud int first, error; 1764 1.18 reinoud 1765 1.18 reinoud pathbuf = malloc(UDF_SYMLINKBUFLEN, M_UDFTEMP, M_WAITOK); 1766 1.18 reinoud tmpname = malloc(PATH_MAX+1, M_UDFTEMP, M_WAITOK); 1767 1.18 reinoud memset(pathbuf, 0, UDF_SYMLINKBUFLEN); 1768 1.18 reinoud memset(targetbuf, 0, PATH_MAX); 1769 1.18 reinoud 1770 1.18 reinoud /* read contents of file in our temporary buffer */ 1771 1.18 reinoud error = vn_rdwr(UIO_READ, udf_node->vnode, 1772 1.94 reinoud pathbuf, filesize, 0, 1773 1.18 reinoud UIO_SYSSPACE, IO_NODELOCKED | IO_ALTSEMANTICS, 1774 1.18 reinoud FSCRED, NULL, NULL); 1775 1.18 reinoud if (error) { 1776 1.18 reinoud /* failed to read in symlink contents */ 1777 1.18 reinoud free(pathbuf, M_UDFTEMP); 1778 1.18 reinoud free(tmpname, M_UDFTEMP); 1779 1.18 reinoud return error; 1780 1.18 reinoud } 1781 1.1 reinoud 1782 1.18 reinoud /* convert to a unix path */ 1783 1.18 reinoud pathpos = pathbuf; 1784 1.18 reinoud pathlen = 0; 1785 1.18 reinoud targetpos = targetbuf; 1786 1.18 reinoud targetlen = PATH_MAX; 1787 1.18 reinoud mntonname = udf_node->ump->vfs_mountp->mnt_stat.f_mntonname; 1788 1.18 reinoud mntonnamelen = strlen(mntonname); 1789 1.1 reinoud 1790 1.18 reinoud error = 0; 1791 1.18 reinoud first = 1; 1792 1.94 reinoud while (filesize - pathlen >= UDF_PATH_COMP_SIZE) { 1793 1.18 reinoud len = UDF_PATH_COMP_SIZE; 1794 1.18 reinoud memcpy(&pathcomp, pathpos, len); 1795 1.18 reinoud l_ci = pathcomp.l_ci; 1796 1.18 reinoud switch (pathcomp.type) { 1797 1.18 reinoud case UDF_PATH_COMP_ROOT : 1798 1.23 reinoud /* XXX should check for l_ci; bugcompatible now */ 1799 1.23 reinoud if ((targetlen < 1) || !first) { 1800 1.18 reinoud error = EINVAL; 1801 1.18 reinoud break; 1802 1.18 reinoud } 1803 1.18 reinoud *targetpos++ = '/'; targetlen--; 1804 1.18 reinoud break; 1805 1.18 reinoud case UDF_PATH_COMP_MOUNTROOT : 1806 1.23 reinoud /* XXX what should it be if l_ci > 0 ? [4/48.16.1.2] */ 1807 1.18 reinoud if (l_ci || (targetlen < mntonnamelen+1) || !first) { 1808 1.18 reinoud error = EINVAL; 1809 1.18 reinoud break; 1810 1.18 reinoud } 1811 1.18 reinoud memcpy(targetpos, mntonname, mntonnamelen); 1812 1.18 reinoud targetpos += mntonnamelen; targetlen -= mntonnamelen; 1813 1.94 reinoud if (filesize-pathlen > UDF_PATH_COMP_SIZE+l_ci) { 1814 1.18 reinoud /* more follows, so must be directory */ 1815 1.18 reinoud *targetpos++ = '/'; targetlen--; 1816 1.18 reinoud } 1817 1.18 reinoud break; 1818 1.18 reinoud case UDF_PATH_COMP_PARENTDIR : 1819 1.23 reinoud /* XXX should check for l_ci; bugcompatible now */ 1820 1.23 reinoud if (targetlen < 3) { 1821 1.18 reinoud error = EINVAL; 1822 1.18 reinoud break; 1823 1.18 reinoud } 1824 1.18 reinoud *targetpos++ = '.'; targetlen--; 1825 1.18 reinoud *targetpos++ = '.'; targetlen--; 1826 1.18 reinoud *targetpos++ = '/'; targetlen--; 1827 1.18 reinoud break; 1828 1.18 reinoud case UDF_PATH_COMP_CURDIR : 1829 1.23 reinoud /* XXX should check for l_ci; bugcompatible now */ 1830 1.23 reinoud if (targetlen < 2) { 1831 1.18 reinoud error = EINVAL; 1832 1.18 reinoud break; 1833 1.18 reinoud } 1834 1.18 reinoud *targetpos++ = '.'; targetlen--; 1835 1.18 reinoud *targetpos++ = '/'; targetlen--; 1836 1.18 reinoud break; 1837 1.18 reinoud case UDF_PATH_COMP_NAME : 1838 1.22 reinoud if (l_ci == 0) { 1839 1.22 reinoud error = EINVAL; 1840 1.22 reinoud break; 1841 1.22 reinoud } 1842 1.18 reinoud memset(tmpname, 0, PATH_MAX); 1843 1.18 reinoud memcpy(&pathcomp, pathpos, len + l_ci); 1844 1.19 reinoud udf_to_unix_name(tmpname, MAXPATHLEN, 1845 1.19 reinoud pathcomp.ident, l_ci, 1846 1.18 reinoud &udf_node->ump->logical_vol->desc_charset); 1847 1.18 reinoud namelen = strlen(tmpname); 1848 1.18 reinoud if (targetlen < namelen + 1) { 1849 1.18 reinoud error = EINVAL; 1850 1.18 reinoud break; 1851 1.18 reinoud } 1852 1.18 reinoud memcpy(targetpos, tmpname, namelen); 1853 1.18 reinoud targetpos += namelen; targetlen -= namelen; 1854 1.94 reinoud if (filesize-pathlen > UDF_PATH_COMP_SIZE+l_ci) { 1855 1.18 reinoud /* more follows, so must be directory */ 1856 1.18 reinoud *targetpos++ = '/'; targetlen--; 1857 1.18 reinoud } 1858 1.18 reinoud break; 1859 1.18 reinoud default : 1860 1.18 reinoud error = EINVAL; 1861 1.18 reinoud break; 1862 1.18 reinoud } 1863 1.18 reinoud first = 0; 1864 1.18 reinoud if (error) 1865 1.18 reinoud break; 1866 1.18 reinoud pathpos += UDF_PATH_COMP_SIZE + l_ci; 1867 1.18 reinoud pathlen += UDF_PATH_COMP_SIZE + l_ci; 1868 1.18 reinoud 1869 1.18 reinoud } 1870 1.18 reinoud /* all processed? */ 1871 1.94 reinoud if (filesize - pathlen > 0) 1872 1.18 reinoud error = EINVAL; 1873 1.18 reinoud 1874 1.94 reinoud free(pathbuf, M_UDFTEMP); 1875 1.94 reinoud free(tmpname, M_UDFTEMP); 1876 1.94 reinoud 1877 1.94 reinoud *length = PATH_MAX - targetlen; 1878 1.94 reinoud return error; 1879 1.94 reinoud } 1880 1.94 reinoud 1881 1.94 reinoud 1882 1.94 reinoud int 1883 1.94 reinoud udf_readlink(void *v) 1884 1.94 reinoud { 1885 1.94 reinoud struct vop_readlink_args /* { 1886 1.94 reinoud struct vnode *a_vp; 1887 1.94 reinoud struct uio *a_uio; 1888 1.94 reinoud kauth_cred_t a_cred; 1889 1.94 reinoud } */ *ap = v; 1890 1.94 reinoud struct vnode *vp = ap->a_vp; 1891 1.94 reinoud struct udf_node *udf_node = VTOI(vp); 1892 1.94 reinoud struct file_entry *fe = udf_node->fe; 1893 1.94 reinoud struct extfile_entry *efe = udf_node->efe; 1894 1.94 reinoud struct uio *uio = ap->a_uio; 1895 1.94 reinoud uint64_t filesize; 1896 1.94 reinoud uint8_t *targetbuf; 1897 1.94 reinoud int length; 1898 1.94 reinoud int error; 1899 1.94 reinoud 1900 1.94 reinoud DPRINTF(CALL, ("udf_readlink called\n")); 1901 1.94 reinoud 1902 1.94 reinoud if (fe) { 1903 1.94 reinoud filesize = udf_rw64(fe->inf_len); 1904 1.94 reinoud } else { 1905 1.94 reinoud assert(udf_node->efe); 1906 1.94 reinoud filesize = udf_rw64(efe->inf_len); 1907 1.94 reinoud } 1908 1.94 reinoud 1909 1.94 reinoud /* claim temporary buffers for translation */ 1910 1.94 reinoud targetbuf = malloc(PATH_MAX+1, M_UDFTEMP, M_WAITOK); 1911 1.94 reinoud 1912 1.94 reinoud error = udf_do_readlink(udf_node, filesize, targetbuf, &length); 1913 1.94 reinoud 1914 1.18 reinoud /* uiomove() to destination */ 1915 1.18 reinoud if (!error) 1916 1.94 reinoud uiomove(targetbuf, length, uio); 1917 1.18 reinoud 1918 1.18 reinoud free(targetbuf, M_UDFTEMP); 1919 1.18 reinoud return error; 1920 1.1 reinoud } 1921 1.1 reinoud 1922 1.1 reinoud /* --------------------------------------------------------------------- */ 1923 1.1 reinoud 1924 1.47 reinoud /* 1925 1.85 reinoud * udf_rename() moved to udf_rename.c 1926 1.47 reinoud */ 1927 1.47 reinoud 1928 1.1 reinoud /* --------------------------------------------------------------------- */ 1929 1.1 reinoud 1930 1.1 reinoud int 1931 1.18 reinoud udf_remove(void *v) 1932 1.1 reinoud { 1933 1.117 thorpej struct vop_remove_v3_args /* { 1934 1.1 reinoud struct vnode *a_dvp; 1935 1.18 reinoud struct vnode *a_vp; 1936 1.1 reinoud struct componentname *a_cnp; 1937 1.117 thorpej nlink_t ctx_vp_new_nlink; 1938 1.1 reinoud } */ *ap = v; 1939 1.1 reinoud struct vnode *dvp = ap->a_dvp; 1940 1.18 reinoud struct vnode *vp = ap->a_vp; 1941 1.1 reinoud struct componentname *cnp = ap->a_cnp; 1942 1.56 mbalmer struct udf_node *dir_node = VTOI(dvp); 1943 1.18 reinoud struct udf_node *udf_node = VTOI(vp); 1944 1.18 reinoud struct udf_mount *ump = dir_node->ump; 1945 1.18 reinoud int error; 1946 1.18 reinoud 1947 1.18 reinoud DPRINTF(CALL, ("udf_remove called\n")); 1948 1.18 reinoud if (vp->v_type != VDIR) { 1949 1.18 reinoud error = udf_dir_detach(ump, dir_node, udf_node, cnp); 1950 1.18 reinoud DPRINTFIF(NODE, error, ("\tgot error removing file\n")); 1951 1.117 thorpej if (error == 0) { 1952 1.117 thorpej if (udf_node->fe) { 1953 1.117 thorpej ap->ctx_vp_new_nlink = 1954 1.117 thorpej udf_rw16(udf_node->fe->link_cnt); 1955 1.117 thorpej } else { 1956 1.117 thorpej KASSERT(udf_node->efe != NULL); 1957 1.117 thorpej ap->ctx_vp_new_nlink = 1958 1.117 thorpej udf_rw16(udf_node->efe->link_cnt); 1959 1.117 thorpej } 1960 1.117 thorpej } 1961 1.18 reinoud } else { 1962 1.18 reinoud DPRINTF(NODE, ("\tis a directory: perm. denied\n")); 1963 1.18 reinoud error = EPERM; 1964 1.18 reinoud } 1965 1.1 reinoud 1966 1.18 reinoud if (dvp == vp) 1967 1.18 reinoud vrele(vp); 1968 1.18 reinoud else 1969 1.18 reinoud vput(vp); 1970 1.1 reinoud 1971 1.18 reinoud return error; 1972 1.1 reinoud } 1973 1.1 reinoud 1974 1.1 reinoud /* --------------------------------------------------------------------- */ 1975 1.1 reinoud 1976 1.1 reinoud int 1977 1.1 reinoud udf_rmdir(void *v) 1978 1.1 reinoud { 1979 1.104 riastrad struct vop_rmdir_v2_args /* { 1980 1.1 reinoud struct vnode *a_dvp; 1981 1.1 reinoud struct vnode *a_vp; 1982 1.1 reinoud struct componentname *a_cnp; 1983 1.1 reinoud } */ *ap = v; 1984 1.1 reinoud struct vnode *vp = ap->a_vp; 1985 1.1 reinoud struct vnode *dvp = ap->a_dvp; 1986 1.1 reinoud struct componentname *cnp = ap->a_cnp; 1987 1.56 mbalmer struct udf_node *dir_node = VTOI(dvp); 1988 1.18 reinoud struct udf_node *udf_node = VTOI(vp); 1989 1.18 reinoud struct udf_mount *ump = dir_node->ump; 1990 1.82 reinoud int error, isempty; 1991 1.1 reinoud 1992 1.111 reinoud DPRINTF(CALL, ("udf_rmdir '%s' called\n", cnp->cn_nameptr)); 1993 1.1 reinoud 1994 1.18 reinoud /* don't allow '.' to be deleted */ 1995 1.18 reinoud if (dir_node == udf_node) { 1996 1.104 riastrad vrele(vp); 1997 1.18 reinoud return EINVAL; 1998 1.18 reinoud } 1999 1.1 reinoud 2000 1.82 reinoud /* make sure our `leaf' node's hash is populated */ 2001 1.82 reinoud dirhash_get(&udf_node->dir_hash); 2002 1.82 reinoud error = udf_dirhash_fill(udf_node); 2003 1.82 reinoud if (error) { 2004 1.82 reinoud dirhash_put(udf_node->dir_hash); 2005 1.82 reinoud return error; 2006 1.82 reinoud } 2007 1.82 reinoud 2008 1.18 reinoud /* check to see if the directory is empty */ 2009 1.82 reinoud isempty = dirhash_dir_isempty(udf_node->dir_hash); 2010 1.82 reinoud dirhash_put(udf_node->dir_hash); 2011 1.82 reinoud 2012 1.82 reinoud if (!isempty) { 2013 1.1 reinoud vput(vp); 2014 1.18 reinoud return ENOTEMPTY; 2015 1.18 reinoud } 2016 1.18 reinoud 2017 1.78 reinoud /* detach the node from the directory, udf_node is an empty dir here */ 2018 1.18 reinoud error = udf_dir_detach(ump, dir_node, udf_node, cnp); 2019 1.18 reinoud if (error == 0) { 2020 1.18 reinoud cache_purge(vp); 2021 1.18 reinoud // cache_purge(dvp); /* XXX from msdosfs, why? */ 2022 1.78 reinoud /* 2023 1.78 reinoud * Bug alert: we need to remove '..' from the detaching 2024 1.78 reinoud * udf_node so further lookups of this are not possible. This 2025 1.78 reinoud * prevents a process in a deleted directory from going to its 2026 1.126 andvar * deleted parent. Since `udf_node' is guaranteed to be empty 2027 1.78 reinoud * here, trunc it so no fids are there. 2028 1.78 reinoud */ 2029 1.78 reinoud dirhash_purge(&udf_node->dir_hash); 2030 1.78 reinoud udf_shrink_node(udf_node, 0); 2031 1.1 reinoud } 2032 1.77 reinoud DPRINTFIF(NODE, error, ("\tgot error removing dir\n")); 2033 1.18 reinoud 2034 1.104 riastrad /* put the node and exit */ 2035 1.18 reinoud vput(vp); 2036 1.1 reinoud 2037 1.1 reinoud return error; 2038 1.1 reinoud } 2039 1.1 reinoud 2040 1.1 reinoud /* --------------------------------------------------------------------- */ 2041 1.1 reinoud 2042 1.1 reinoud int 2043 1.1 reinoud udf_fsync(void *v) 2044 1.1 reinoud { 2045 1.1 reinoud struct vop_fsync_args /* { 2046 1.1 reinoud struct vnode *a_vp; 2047 1.5 elad kauth_cred_t a_cred; 2048 1.1 reinoud int a_flags; 2049 1.1 reinoud off_t offlo; 2050 1.1 reinoud off_t offhi; 2051 1.1 reinoud struct proc *a_p; 2052 1.1 reinoud } */ *ap = v; 2053 1.1 reinoud struct vnode *vp = ap->a_vp; 2054 1.18 reinoud struct udf_node *udf_node = VTOI(vp); 2055 1.18 reinoud int error, flags, wait; 2056 1.18 reinoud 2057 1.33 reinoud DPRINTF(SYNC, ("udf_fsync called on %p : %s, %s\n", 2058 1.33 reinoud udf_node, 2059 1.18 reinoud (ap->a_flags & FSYNC_WAIT) ? "wait":"no wait", 2060 1.18 reinoud (ap->a_flags & FSYNC_DATAONLY) ? "data_only":"complete")); 2061 1.18 reinoud 2062 1.18 reinoud /* flush data and wait for it when requested */ 2063 1.18 reinoud wait = (ap->a_flags & FSYNC_WAIT) ? UPDATE_WAIT : 0; 2064 1.71 chs error = vflushbuf(vp, ap->a_flags); 2065 1.64 hannken if (error) 2066 1.64 hannken return error; 2067 1.18 reinoud 2068 1.24 reinoud if (udf_node == NULL) { 2069 1.24 reinoud printf("udf_fsync() called on NULL udf_node!\n"); 2070 1.24 reinoud return 0; 2071 1.24 reinoud } 2072 1.24 reinoud if (vp->v_tag != VT_UDF) { 2073 1.24 reinoud printf("udf_fsync() called on node not tagged as UDF node!\n"); 2074 1.24 reinoud return 0; 2075 1.24 reinoud } 2076 1.24 reinoud 2077 1.18 reinoud /* set our times */ 2078 1.18 reinoud udf_itimes(udf_node, NULL, NULL, NULL); 2079 1.1 reinoud 2080 1.18 reinoud /* if called when mounted readonly, never write back */ 2081 1.18 reinoud if (vp->v_mount->mnt_flag & MNT_RDONLY) 2082 1.18 reinoud return 0; 2083 1.18 reinoud 2084 1.18 reinoud /* if only data is requested, return */ 2085 1.18 reinoud if (ap->a_flags & FSYNC_DATAONLY) 2086 1.18 reinoud return 0; 2087 1.18 reinoud 2088 1.18 reinoud /* check if the node is dirty 'enough'*/ 2089 1.18 reinoud flags = udf_node->i_flags & (IN_MODIFIED | IN_ACCESSED); 2090 1.18 reinoud if (flags == 0) 2091 1.18 reinoud return 0; 2092 1.18 reinoud 2093 1.18 reinoud /* if we don't have to wait, check for IO pending */ 2094 1.18 reinoud if (!wait) { 2095 1.18 reinoud if (vp->v_numoutput > 0) { 2096 1.33 reinoud DPRINTF(SYNC, ("udf_fsync %p, rejecting on v_numoutput\n", udf_node)); 2097 1.18 reinoud return 0; 2098 1.18 reinoud } 2099 1.18 reinoud if (udf_node->outstanding_bufs > 0) { 2100 1.33 reinoud DPRINTF(SYNC, ("udf_fsync %p, rejecting on outstanding_bufs\n", udf_node)); 2101 1.18 reinoud return 0; 2102 1.18 reinoud } 2103 1.18 reinoud if (udf_node->outstanding_nodedscr > 0) { 2104 1.33 reinoud DPRINTF(SYNC, ("udf_fsync %p, rejecting on outstanding_nodedscr\n", udf_node)); 2105 1.18 reinoud return 0; 2106 1.18 reinoud } 2107 1.18 reinoud } 2108 1.18 reinoud 2109 1.18 reinoud /* wait until vp->v_numoutput reaches zero i.e. is finished */ 2110 1.18 reinoud if (wait) { 2111 1.33 reinoud DPRINTF(SYNC, ("udf_fsync %p, waiting\n", udf_node)); 2112 1.66 rmind mutex_enter(vp->v_interlock); 2113 1.18 reinoud while (vp->v_numoutput) { 2114 1.33 reinoud DPRINTF(SYNC, ("udf_fsync %p, v_numoutput %d\n", udf_node, vp->v_numoutput)); 2115 1.66 rmind cv_timedwait(&vp->v_cv, vp->v_interlock, hz/8); 2116 1.18 reinoud } 2117 1.66 rmind mutex_exit(vp->v_interlock); 2118 1.33 reinoud DPRINTF(SYNC, ("udf_fsync %p, fin wait\n", udf_node)); 2119 1.18 reinoud } 2120 1.18 reinoud 2121 1.18 reinoud /* write out node and wait for it if requested */ 2122 1.33 reinoud DPRINTF(SYNC, ("udf_fsync %p, writeout node\n", udf_node)); 2123 1.18 reinoud error = udf_writeout_node(udf_node, wait); 2124 1.18 reinoud if (error) 2125 1.18 reinoud return error; 2126 1.1 reinoud 2127 1.18 reinoud /* TODO/XXX if ap->a_flags & FSYNC_CACHE, we ought to do a disc sync */ 2128 1.1 reinoud 2129 1.1 reinoud return 0; 2130 1.1 reinoud } 2131 1.1 reinoud 2132 1.1 reinoud /* --------------------------------------------------------------------- */ 2133 1.1 reinoud 2134 1.1 reinoud int 2135 1.1 reinoud udf_advlock(void *v) 2136 1.1 reinoud { 2137 1.1 reinoud struct vop_advlock_args /* { 2138 1.1 reinoud struct vnode *a_vp; 2139 1.1 reinoud void *a_id; 2140 1.1 reinoud int a_op; 2141 1.1 reinoud struct flock *a_fl; 2142 1.1 reinoud int a_flags; 2143 1.1 reinoud } */ *ap = v; 2144 1.1 reinoud struct vnode *vp = ap->a_vp; 2145 1.1 reinoud struct udf_node *udf_node = VTOI(vp); 2146 1.1 reinoud struct file_entry *fe; 2147 1.1 reinoud struct extfile_entry *efe; 2148 1.1 reinoud uint64_t file_size; 2149 1.1 reinoud 2150 1.1 reinoud DPRINTF(LOCKING, ("udf_advlock called\n")); 2151 1.1 reinoud 2152 1.1 reinoud /* get directory filesize */ 2153 1.1 reinoud if (udf_node->fe) { 2154 1.1 reinoud fe = udf_node->fe; 2155 1.1 reinoud file_size = udf_rw64(fe->inf_len); 2156 1.1 reinoud } else { 2157 1.1 reinoud assert(udf_node->efe); 2158 1.1 reinoud efe = udf_node->efe; 2159 1.1 reinoud file_size = udf_rw64(efe->inf_len); 2160 1.6 christos } 2161 1.1 reinoud 2162 1.1 reinoud return lf_advlock(ap, &udf_node->lockf, file_size); 2163 1.1 reinoud } 2164 1.1 reinoud 2165 1.1 reinoud /* --------------------------------------------------------------------- */ 2166 1.1 reinoud 2167 1.1 reinoud /* Global vfs vnode data structures for udfs */ 2168 1.37 dsl int (**udf_vnodeop_p)(void *); 2169 1.1 reinoud 2170 1.1 reinoud const struct vnodeopv_entry_desc udf_vnodeop_entries[] = { 2171 1.1 reinoud { &vop_default_desc, vn_default_error }, 2172 1.115 dholland { &vop_parsepath_desc, genfs_parsepath }, /* parsepath */ 2173 1.1 reinoud { &vop_lookup_desc, udf_lookup }, /* lookup */ 2174 1.18 reinoud { &vop_create_desc, udf_create }, /* create */ 2175 1.1 reinoud { &vop_mknod_desc, udf_mknod }, /* mknod */ /* TODO */ 2176 1.1 reinoud { &vop_open_desc, udf_open }, /* open */ 2177 1.1 reinoud { &vop_close_desc, udf_close }, /* close */ 2178 1.1 reinoud { &vop_access_desc, udf_access }, /* access */ 2179 1.113 christos { &vop_accessx_desc, genfs_accessx }, /* accessx */ 2180 1.1 reinoud { &vop_getattr_desc, udf_getattr }, /* getattr */ 2181 1.18 reinoud { &vop_setattr_desc, udf_setattr }, /* setattr */ /* TODO chflags */ 2182 1.1 reinoud { &vop_read_desc, udf_read }, /* read */ 2183 1.1 reinoud { &vop_write_desc, udf_write }, /* write */ /* WRITE */ 2184 1.92 dholland { &vop_fallocate_desc, genfs_eopnotsupp }, /* fallocate */ 2185 1.92 dholland { &vop_fdiscard_desc, genfs_eopnotsupp }, /* fdiscard */ 2186 1.1 reinoud { &vop_fcntl_desc, genfs_fcntl }, /* fcntl */ /* TODO? */ 2187 1.1 reinoud { &vop_ioctl_desc, genfs_enoioctl }, /* ioctl */ /* TODO? */ 2188 1.1 reinoud { &vop_poll_desc, genfs_poll }, /* poll */ /* TODO/OK? */ 2189 1.1 reinoud { &vop_kqfilter_desc, genfs_kqfilter }, /* kqfilter */ /* ? */ 2190 1.1 reinoud { &vop_revoke_desc, genfs_revoke }, /* revoke */ /* TODO? */ 2191 1.1 reinoud { &vop_mmap_desc, genfs_mmap }, /* mmap */ /* OK? */ 2192 1.18 reinoud { &vop_fsync_desc, udf_fsync }, /* fsync */ 2193 1.1 reinoud { &vop_seek_desc, genfs_seek }, /* seek */ 2194 1.18 reinoud { &vop_remove_desc, udf_remove }, /* remove */ 2195 1.1 reinoud { &vop_link_desc, udf_link }, /* link */ /* TODO */ 2196 1.1 reinoud { &vop_rename_desc, udf_rename }, /* rename */ /* TODO */ 2197 1.18 reinoud { &vop_mkdir_desc, udf_mkdir }, /* mkdir */ 2198 1.18 reinoud { &vop_rmdir_desc, udf_rmdir }, /* rmdir */ 2199 1.1 reinoud { &vop_symlink_desc, udf_symlink }, /* symlink */ /* TODO */ 2200 1.1 reinoud { &vop_readdir_desc, udf_readdir }, /* readdir */ 2201 1.1 reinoud { &vop_readlink_desc, udf_readlink }, /* readlink */ /* TEST ME */ 2202 1.1 reinoud { &vop_abortop_desc, genfs_abortop }, /* abortop */ /* TODO/OK? */ 2203 1.1 reinoud { &vop_inactive_desc, udf_inactive }, /* inactive */ 2204 1.1 reinoud { &vop_reclaim_desc, udf_reclaim }, /* reclaim */ 2205 1.1 reinoud { &vop_lock_desc, genfs_lock }, /* lock */ 2206 1.1 reinoud { &vop_unlock_desc, genfs_unlock }, /* unlock */ 2207 1.1 reinoud { &vop_bmap_desc, udf_trivial_bmap }, /* bmap */ /* 1:1 bmap */ 2208 1.18 reinoud { &vop_strategy_desc, udf_vfsstrategy },/* strategy */ 2209 1.1 reinoud /* { &vop_print_desc, udf_print }, */ /* print */ 2210 1.1 reinoud { &vop_islocked_desc, genfs_islocked }, /* islocked */ 2211 1.1 reinoud { &vop_pathconf_desc, udf_pathconf }, /* pathconf */ 2212 1.1 reinoud { &vop_advlock_desc, udf_advlock }, /* advlock */ /* TEST ME */ 2213 1.1 reinoud { &vop_bwrite_desc, vn_bwrite }, /* bwrite */ /* ->strategy */ 2214 1.1 reinoud { &vop_getpages_desc, genfs_getpages }, /* getpages */ 2215 1.1 reinoud { &vop_putpages_desc, genfs_putpages }, /* putpages */ 2216 1.1 reinoud { NULL, NULL } 2217 1.1 reinoud }; 2218 1.1 reinoud 2219 1.1 reinoud 2220 1.1 reinoud const struct vnodeopv_desc udf_vnodeop_opv_desc = { 2221 1.1 reinoud &udf_vnodeop_p, udf_vnodeop_entries 2222 1.1 reinoud }; 2223