udf_vnops.c revision 1.10.8.1 1 /* $NetBSD: udf_vnops.c,v 1.10.8.1 2007/11/06 23:31:23 matt Exp $ */
2
3 /*
4 * Copyright (c) 2006 Reinoud Zandijk
5 * All rights reserved.
6 *
7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions
9 * are met:
10 * 1. Redistributions of source code must retain the above copyright
11 * notice, this list of conditions and the following disclaimer.
12 * 2. Redistributions in binary form must reproduce the above copyright
13 * notice, this list of conditions and the following disclaimer in the
14 * documentation and/or other materials provided with the distribution.
15 * 3. All advertising materials mentioning features or use of this software
16 * must display the following acknowledgement:
17 * This product includes software developed for the
18 * NetBSD Project. See http://www.NetBSD.org/ for
19 * information about NetBSD.
20 * 4. The name of the author may not be used to endorse or promote products
21 * derived from this software without specific prior written permission.
22 *
23 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
24 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
25 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
26 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
27 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
28 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
29 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
30 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
31 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
32 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
33 *
34 */
35
36
37 #include <sys/cdefs.h>
38 #ifndef lint
39 __RCSID("$NetBSD: udf_vnops.c,v 1.10.8.1 2007/11/06 23:31:23 matt Exp $");
40 #endif /* not lint */
41
42
43 #include <sys/param.h>
44 #include <sys/systm.h>
45 #include <sys/namei.h>
46 #include <sys/resourcevar.h> /* defines plimit structure in proc struct */
47 #include <sys/kernel.h>
48 #include <sys/file.h> /* define FWRITE ... */
49 #include <sys/stat.h>
50 #include <sys/buf.h>
51 #include <sys/proc.h>
52 #include <sys/mount.h>
53 #include <sys/vnode.h>
54 #include <sys/signalvar.h>
55 #include <sys/malloc.h>
56 #include <sys/dirent.h>
57 #include <sys/lockf.h>
58
59 #include <miscfs/genfs/genfs.h>
60 #include <uvm/uvm_extern.h>
61
62 #include <fs/udf/ecma167-udf.h>
63 #include <fs/udf/udf_mount.h>
64 #include "udf.h"
65 #include "udf_subr.h"
66 #include "udf_bswap.h"
67
68
69 #define VTOI(vnode) ((struct udf_node *) vnode->v_data)
70
71
72 /* externs */
73 extern int prtactive;
74
75
76 /* implementations of vnode functions; table follows at end */
77 /* --------------------------------------------------------------------- */
78
79 int
80 udf_inactive(void *v)
81 {
82 struct vop_inactive_args /* {
83 struct vnode *a_vp;
84 struct proc *a_p;
85 } */ *ap = v;
86 struct vnode *vp = ap->a_vp;
87
88 if (prtactive && vp->v_usecount != 0)
89 vprint("udf_inactive(): pushing active", vp);
90
91 VOP_UNLOCK(vp, 0);
92
93 DPRINTF(LOCKING, ("udf_inactive called for node %p\n", VTOI(vp)));
94
95 /*
96 * Optionally flush metadata to disc. If the file has not been
97 * referenced anymore in a directory we ought to free up the resources
98 * on disc if applicable.
99 */
100
101 return 0;
102 }
103
104 /* --------------------------------------------------------------------- */
105
106 int
107 udf_reclaim(void *v)
108 {
109 struct vop_reclaim_args /* {
110 struct vnode *a_vp;
111 } */ *ap = v;
112 struct vnode *vp = ap->a_vp;
113 struct udf_node *node = VTOI(vp);
114
115 if (prtactive && vp->v_usecount != 0)
116 vprint("udf_reclaim(): pushing active", vp);
117
118 /* purge old data from namei */
119 cache_purge(vp);
120
121 DPRINTF(LOCKING, ("udf_reclaim called for node %p\n", node));
122 /* dispose all node knowledge */
123 udf_dispose_node(node);
124
125 return 0;
126 }
127
128 /* --------------------------------------------------------------------- */
129
130 int
131 udf_read(void *v)
132 {
133 struct vop_read_args /* {
134 struct vnode *a_vp;
135 struct uio *a_uio;
136 int a_ioflag;
137 kauth_cred_t a_cred;
138 } */ *ap = v;
139 struct vnode *vp = ap->a_vp;
140 struct uio *uio = ap->a_uio;
141 int ioflag = ap->a_ioflag;
142 struct uvm_object *uobj;
143 struct udf_node *udf_node = VTOI(vp);
144 struct file_entry *fe;
145 struct extfile_entry *efe;
146 uint64_t file_size;
147 vsize_t len;
148 void *win;
149 int error;
150 int flags;
151
152 /* XXX how to deal with xtended attributes (files) */
153
154 DPRINTF(READ, ("udf_read called\n"));
155
156 /* can this happen? some filingsystems have this check */
157 if (uio->uio_offset < 0)
158 return EINVAL;
159
160 assert(udf_node);
161 assert(udf_node->fe || udf_node->efe);
162
163 /* TODO set access time */
164
165 /* get directory filesize */
166 if (udf_node->fe) {
167 fe = udf_node->fe;
168 file_size = udf_rw64(fe->inf_len);
169 } else {
170 assert(udf_node->efe);
171 efe = udf_node->efe;
172 file_size = udf_rw64(efe->inf_len);
173 }
174
175 if (vp->v_type == VDIR) {
176 /* protect against rogue programs reading raw directories */
177 if ((ioflag & IO_ALTSEMANTICS) == 0)
178 return EISDIR;
179 }
180 if (vp->v_type == VREG || vp->v_type == VDIR) {
181 const int advice = IO_ADV_DECODE(ap->a_ioflag);
182
183 /* read contents using buffercache */
184 uobj = &vp->v_uobj;
185 flags = UBC_WANT_UNMAP(vp) ? UBC_UNMAP : 0;
186 error = 0;
187 while (uio->uio_resid > 0) {
188 /* reached end? */
189 if (file_size <= uio->uio_offset)
190 break;
191
192 /* maximise length to file extremity */
193 len = MIN(file_size - uio->uio_offset, uio->uio_resid);
194 if (len == 0)
195 break;
196
197 /* ubc, here we come, prepare to trap */
198 win = ubc_alloc(uobj, uio->uio_offset, &len,
199 advice, UBC_READ);
200 error = uiomove(win, len, uio);
201 ubc_release(win, flags);
202 if (error)
203 break;
204 }
205 /* TODO note access time */
206 return error;
207 }
208
209 return EINVAL;
210 }
211
212 /* --------------------------------------------------------------------- */
213
214 int
215 udf_write(void *v)
216 {
217 struct vop_write_args /* {
218 struct vnode *a_vp;
219 struct uio *a_uio;
220 int a_ioflag;
221 kauth_cred_t a_cred;
222 } */ *ap = v;
223
224 DPRINTF(NOTIMPL, ("udf_write called\n"));
225 ap = ap; /* shut up gcc */
226
227 /* TODO implement writing */
228 return EROFS;
229 }
230
231
232 /* --------------------------------------------------------------------- */
233
234 /*
235 * `Special' bmap functionality that translates all incomming requests to
236 * translate to vop_strategy() calls with the same blocknumbers effectively
237 * not translating at all.
238 */
239
240 int
241 udf_trivial_bmap(void *v)
242 {
243 struct vop_bmap_args /* {
244 struct vnode *a_vp;
245 daddr_t a_bn;
246 struct vnode **a_vpp;
247 daddr_t *a_bnp;
248 int *a_runp;
249 } */ *ap = v;
250 struct vnode *vp = ap->a_vp; /* our node */
251 struct vnode **vpp = ap->a_vpp; /* return node */
252 daddr_t *bnp = ap->a_bnp; /* translated */
253 daddr_t bn = ap->a_bn; /* origional */
254 int *runp = ap->a_runp;
255 struct udf_node *udf_node = VTOI(vp);
256 uint32_t lb_size;
257
258 /* get logical block size */
259 lb_size = udf_rw32(udf_node->ump->logical_vol->lb_size);
260
261 /* could return `-1' to indicate holes/zeros */
262 /* translate 1:1 */
263 *bnp = bn;
264
265 /* set the vnode to read the data from with strategy on itself */
266 if (vpp)
267 *vpp = vp;
268
269 /* set runlength of maximum block size */
270 if (runp)
271 *runp = MAXPHYS / lb_size; /* or with -1 ? */
272
273 /* return success */
274 return 0;
275 }
276
277 /* --------------------------------------------------------------------- */
278
279 int
280 udf_strategy(void *v)
281 {
282 struct vop_strategy_args /* {
283 struct vnode *a_vp;
284 struct buf *a_bp;
285 } */ *ap = v;
286 struct vnode *vp = ap->a_vp;
287 struct buf *bp = ap->a_bp;
288 struct udf_node *udf_node = VTOI(vp);
289 uint32_t lb_size, from, sectors;
290 int error;
291
292 DPRINTF(STRATEGY, ("udf_strategy called\n"));
293
294 /* check if we ought to be here */
295 if (vp->v_type == VBLK || vp->v_type == VCHR)
296 panic("udf_strategy: spec");
297
298 /* only filebuffers ought to be read by this, no descriptors */
299 assert(bp->b_blkno >= 0);
300
301 /* get sector size */
302 lb_size = udf_rw32(udf_node->ump->logical_vol->lb_size);
303
304 /* calculate sector to start from */
305 from = bp->b_blkno;
306
307 /* calculate length to fetch/store in sectors */
308 sectors = bp->b_bcount / lb_size;
309 assert(bp->b_bcount > 0);
310
311 /* NEVER assume later that this buffer is already translated */
312 /* bp->b_lblkno = bp->b_blkno; */
313
314 DPRINTF(STRATEGY, ("\tread vp %p buf %p (blk no %"PRIu64")"
315 ", sector %d for %d sectors\n",
316 vp, bp, bp->b_blkno, from, sectors));
317
318 /* check assertions: we OUGHT to always get multiples of this */
319 assert(sectors * lb_size == bp->b_bcount);
320
321 /* determine mode */
322 error = 0;
323 if (bp->b_flags & B_READ) {
324 /* read buffer from the udf_node, translate vtop on the way*/
325 udf_read_filebuf(udf_node, bp);
326 return bp->b_error;
327 }
328
329 printf("udf_strategy: can't write yet\n");
330 return ENOTSUP;
331 }
332
333 /* --------------------------------------------------------------------- */
334
335 int
336 udf_readdir(void *v)
337 {
338 struct vop_readdir_args /* {
339 struct vnode *a_vp;
340 struct uio *a_uio;
341 kauth_cred_t a_cred;
342 int *a_eofflag;
343 off_t **a_cookies;
344 int *a_ncookies;
345 } */ *ap = v;
346 struct uio *uio = ap->a_uio;
347 struct vnode *vp = ap->a_vp;
348 struct udf_node *udf_node = VTOI(vp);
349 struct file_entry *fe;
350 struct extfile_entry *efe;
351 struct fileid_desc *fid;
352 struct dirent *dirent;
353 uint64_t file_size, diroffset, transoffset;
354 uint32_t lb_size;
355 int error;
356
357 DPRINTF(READDIR, ("udf_readdir called\n"));
358
359 /* This operation only makes sense on directory nodes. */
360 if (vp->v_type != VDIR)
361 return ENOTDIR;
362
363 /* get directory filesize */
364 if (udf_node->fe) {
365 fe = udf_node->fe;
366 file_size = udf_rw64(fe->inf_len);
367 } else {
368 assert(udf_node->efe);
369 efe = udf_node->efe;
370 file_size = udf_rw64(efe->inf_len);
371 }
372
373 dirent = malloc(sizeof(struct dirent), M_UDFTEMP, M_WAITOK | M_ZERO);
374
375 /*
376 * Add `.' pseudo entry if at offset zero since its not in the fid
377 * stream
378 */
379 if (uio->uio_offset == 0) {
380 DPRINTF(READDIR, ("\t'.' inserted\n"));
381 strcpy(dirent->d_name, ".");
382 dirent->d_fileno = udf_calchash(&udf_node->loc);
383 dirent->d_type = DT_DIR;
384 dirent->d_namlen = strlen(dirent->d_name);
385 dirent->d_reclen = _DIRENT_SIZE(dirent);
386 uiomove(dirent, _DIRENT_SIZE(dirent), uio);
387
388 /* mark with magic value that we have done the dummy */
389 uio->uio_offset = UDF_DIRCOOKIE_DOT;
390 }
391
392 /* we are called just as long as we keep on pushing data in */
393 error = 0;
394 if ((uio->uio_offset < file_size) &&
395 (uio->uio_resid >= sizeof(struct dirent))) {
396 /* allocate temporary space for fid */
397 lb_size = udf_rw32(udf_node->ump->logical_vol->lb_size);
398 fid = malloc(lb_size, M_UDFTEMP, M_WAITOK);
399
400 if (uio->uio_offset == UDF_DIRCOOKIE_DOT)
401 uio->uio_offset = 0;
402
403 diroffset = uio->uio_offset;
404 transoffset = diroffset;
405 while (diroffset < file_size) {
406 DPRINTF(READDIR, ("\tread in fid stream\n"));
407 /* transfer a new fid/dirent */
408 error = udf_read_fid_stream(vp, &diroffset,
409 fid, dirent);
410 DPRINTFIF(READDIR, error, ("read error in read fid "
411 "stream : %d\n", error));
412 if (error)
413 break;
414
415 /*
416 * If there isn't enough space in the uio to return a
417 * whole dirent, break off read
418 */
419 if (uio->uio_resid < _DIRENT_SIZE(dirent))
420 break;
421
422 /* remember the last entry we transfered */
423 transoffset = diroffset;
424
425 /* skip deleted entries */
426 if (fid->file_char & UDF_FILE_CHAR_DEL)
427 continue;
428
429 /* skip not visible files */
430 if (fid->file_char & UDF_FILE_CHAR_VIS)
431 continue;
432
433 /* copy dirent to the caller */
434 DPRINTF(READDIR, ("\tread dirent `%s', type %d\n",
435 dirent->d_name, dirent->d_type));
436 uiomove(dirent, _DIRENT_SIZE(dirent), uio);
437 }
438
439 /* pass on last transfered offset */
440 uio->uio_offset = transoffset;
441 free(fid, M_UDFTEMP);
442 }
443
444 if (ap->a_eofflag)
445 *ap->a_eofflag = (uio->uio_offset == file_size);
446
447 #ifdef DEBUG
448 if (udf_verbose & UDF_DEBUG_READDIR) {
449 printf("returning offset %d\n", (uint32_t) uio->uio_offset);
450 if (ap->a_eofflag)
451 printf("returning EOF ? %d\n", *ap->a_eofflag);
452 if (error)
453 printf("readdir returning error %d\n", error);
454 }
455 #endif
456
457 free(dirent, M_UDFTEMP);
458 return error;
459 }
460
461 /* --------------------------------------------------------------------- */
462
463 int
464 udf_lookup(void *v)
465 {
466 struct vop_lookup_args /* {
467 struct vnode *a_dvp;
468 struct vnode **a_vpp;
469 struct componentname *a_cnp;
470 } */ *ap = v;
471 struct vnode *dvp = ap->a_dvp;
472 struct vnode **vpp = ap->a_vpp;
473 struct componentname *cnp = ap->a_cnp;
474 struct udf_node *dir_node, *res_node;
475 struct udf_mount *ump;
476 struct long_ad icb_loc;
477 const char *name;
478 int namelen, nameiop, islastcn, mounted_ro;
479 int vnodetp;
480 int error, found;
481
482 dir_node = VTOI(dvp);
483 ump = dir_node->ump;
484 *vpp = NULL;
485
486 DPRINTF(LOOKUP, ("udf_lookup called\n"));
487
488 /* simplify/clarification flags */
489 nameiop = cnp->cn_nameiop;
490 islastcn = cnp->cn_flags & ISLASTCN;
491 mounted_ro = dvp->v_mount->mnt_flag & MNT_RDONLY;
492
493 /* check exec/dirread permissions first */
494 error = VOP_ACCESS(dvp, VEXEC, cnp->cn_cred, cnp->cn_lwp);
495 if (error)
496 return error;
497
498 DPRINTF(LOOKUP, ("\taccess ok\n"));
499
500 /*
501 * If requesting a modify on the last path element on a read-only
502 * filingsystem, reject lookup; XXX why is this repeated in every FS ?
503 */
504 if (islastcn && mounted_ro && (nameiop == DELETE || nameiop == RENAME))
505 return EROFS;
506
507 DPRINTF(LOOKUP, ("\tlooking up cnp->cn_nameptr '%s'\n",
508 cnp->cn_nameptr));
509 /* look in the nami cache; returns 0 on success!! */
510 error = cache_lookup(dvp, vpp, cnp);
511 if (error >= 0)
512 return error;
513
514 DPRINTF(LOOKUP, ("\tNOT found in cache\n"));
515
516 /*
517 * Obviously, the file is not (anymore) in the namecache, we have to
518 * search for it. There are three basic cases: '.', '..' and others.
519 *
520 * Following the guidelines of VOP_LOOKUP manpage and tmpfs.
521 */
522 error = 0;
523 if ((cnp->cn_namelen == 1) && (cnp->cn_nameptr[0] == '.')) {
524 DPRINTF(LOOKUP, ("\tlookup '.'\n"));
525 /* special case 1 '.' */
526 VREF(dvp);
527 *vpp = dvp;
528 /* done */
529 } else if (cnp->cn_flags & ISDOTDOT) {
530 /* special case 2 '..' */
531 DPRINTF(LOOKUP, ("\tlookup '..'\n"));
532
533 /* first unlock parent */
534 VOP_UNLOCK(dvp, 0);
535
536 /* get our node */
537 name = "..";
538 namelen = 2;
539 found = udf_lookup_name_in_dir(dvp, name, namelen, &icb_loc);
540 if (!found)
541 error = ENOENT;
542
543 if (!error) {
544 DPRINTF(LOOKUP, ("\tfound '..'\n"));
545 /* try to create/reuse the node */
546 error = udf_get_node(ump, &icb_loc, &res_node);
547
548 if (!error) {
549 DPRINTF(LOOKUP, ("\tnode retrieved/created OK\n"));
550 *vpp = res_node->vnode;
551 }
552 }
553
554 /* try to relock parent */
555 vn_lock(dvp, LK_EXCLUSIVE | LK_RETRY);
556 } else {
557 DPRINTF(LOOKUP, ("\tlookup file\n"));
558 /* all other files */
559 /* lookup filename in the directory; location icb_loc */
560 name = cnp->cn_nameptr;
561 namelen = cnp->cn_namelen;
562 found = udf_lookup_name_in_dir(dvp, name, namelen, &icb_loc);
563 if (!found) {
564 DPRINTF(LOOKUP, ("\tNOT found\n"));
565 /*
566 * UGH, didn't find name. If we're creating or naming
567 * on the last name this is OK and we ought to return
568 * EJUSTRETURN if its allowed to be created.
569 */
570 error = ENOENT;
571 if (islastcn &&
572 (nameiop == CREATE || nameiop == RENAME))
573 error = 0;
574 if (!error) {
575 error = VOP_ACCESS(dvp, VWRITE, cnp->cn_cred,
576 cnp->cn_lwp);
577 if (!error) {
578 /* keep the component name */
579 cnp->cn_flags |= SAVENAME;
580 error = EJUSTRETURN;
581 }
582 }
583 /* done */
584 } else {
585 /* try to create/reuse the node */
586 error = udf_get_node(ump, &icb_loc, &res_node);
587 if (!error) {
588 /*
589 * If we are not at the last path component
590 * and found a non-directory or non-link entry
591 * (which may itself be pointing to a
592 * directory), raise an error.
593 */
594 vnodetp = res_node->vnode->v_type;
595 if ((vnodetp != VDIR) && (vnodetp != VLNK)) {
596 if (!islastcn)
597 error = ENOTDIR;
598 }
599
600 }
601 if (!error) {
602 *vpp = res_node->vnode;
603 }
604 }
605 }
606
607 /*
608 * Store result in the cache if requested. If we are creating a file,
609 * the file might not be found and thus putting it into the namecache
610 * might be seen as negative caching.
611 */
612 if (cnp->cn_flags & MAKEENTRY)
613 cache_enter(dvp, *vpp, cnp);
614
615 DPRINTFIF(LOOKUP, error, ("udf_lookup returing error %d\n", error));
616
617 return error;
618 }
619
620 /* --------------------------------------------------------------------- */
621
622 int
623 udf_getattr(void *v)
624 {
625 struct vop_getattr_args /* {
626 struct vnode *a_vp;
627 struct vattr *a_vap;
628 kauth_cred_t a_cred;
629 struct proc *a_p;
630 } */ *ap = v;
631 struct vnode *vp = ap->a_vp;
632 struct udf_node *udf_node = VTOI(vp);
633 struct udf_mount *ump = udf_node->ump;
634 struct vattr *vap = ap->a_vap;
635 struct file_entry *fe;
636 struct extfile_entry *efe;
637 struct timestamp *atime, *mtime, *attrtime;
638 uint32_t nlink;
639 uint64_t filesize, blkssize;
640 uid_t uid;
641 gid_t gid;
642
643 DPRINTF(CALL, ("udf_getattr called\n"));
644
645 /* get descriptor information */
646 if (udf_node->fe) {
647 fe = udf_node->fe;
648 nlink = udf_rw16(fe->link_cnt);
649 uid = (uid_t)udf_rw32(fe->uid);
650 gid = (gid_t)udf_rw32(fe->gid);
651 filesize = udf_rw64(fe->inf_len);
652 blkssize = udf_rw64(fe->logblks_rec);
653 atime = &fe->atime;
654 mtime = &fe->mtime;
655 attrtime = &fe->attrtime;
656 } else {
657 assert(udf_node->efe);
658 efe = udf_node->efe;
659 nlink = udf_rw16(efe->link_cnt);
660 uid = (uid_t)udf_rw32(efe->uid);
661 gid = (gid_t)udf_rw32(efe->gid);
662 filesize = udf_rw64(efe->inf_len); /* XXX or obj_size? */
663 blkssize = udf_rw64(efe->logblks_rec);
664 atime = &efe->atime;
665 mtime = &efe->mtime;
666 attrtime = &efe->attrtime;
667 }
668
669 /* do the uid/gid translation game */
670 if ((uid == (uid_t) -1) && (gid == (gid_t) -1)) {
671 uid = ump->mount_args.anon_uid;
672 gid = ump->mount_args.anon_gid;
673 }
674
675 /* fill in struct vattr with values from the node */
676 VATTR_NULL(vap);
677 vap->va_type = vp->v_type;
678 vap->va_mode = udf_getaccessmode(udf_node);
679 vap->va_nlink = nlink;
680 vap->va_uid = uid;
681 vap->va_gid = gid;
682 vap->va_fsid = vp->v_mount->mnt_stat.f_fsidx.__fsid_val[0];
683 vap->va_fileid = udf_calchash(&udf_node->loc); /* inode hash XXX */
684 vap->va_size = filesize;
685 vap->va_blocksize = udf_node->ump->discinfo.sector_size; /* wise? */
686
687 /*
688 * BUG-ALERT: UDF doesn't count '.' as an entry, so we'll have to add
689 * 1 to the link count if its a directory we're requested attributes
690 * of.
691 */
692 if (vap->va_type == VDIR)
693 vap->va_nlink++;
694
695 /* access times */
696 udf_timestamp_to_timespec(ump, atime, &vap->va_atime);
697 udf_timestamp_to_timespec(ump, mtime, &vap->va_mtime);
698 udf_timestamp_to_timespec(ump, attrtime, &vap->va_ctime);
699
700 vap->va_gen = 1; /* no multiple generations yes (!?) */
701 vap->va_flags = 0; /* no flags */
702 vap->va_rdev = udf_node->rdev;
703 vap->va_bytes = blkssize * udf_node->ump->discinfo.sector_size;
704 vap->va_filerev = 1; /* TODO file revision numbers? */
705 vap->va_vaflags = 0; /* TODO which va_vaflags? */
706
707 return 0;
708 }
709
710 /* --------------------------------------------------------------------- */
711
712 int
713 udf_setattr(void *v)
714 {
715 struct vop_setattr_args /* {
716 struct vnode *a_vp;
717 struct vattr *a_vap;
718 kauth_cred_t a_cred;
719 struct proc *a_p;
720 } */ *ap = v;
721 struct vnode *vp = ap->a_vp;
722 struct udf_node *udf_node = VTOI(vp);
723 struct udf_mount *ump = udf_node->ump;
724 struct vattr *vap = ap->a_vap;
725 uid_t uid, nobody_uid;
726 gid_t gid, nobody_gid;
727
728 /* shut up gcc for now */
729 ap = ap;
730 vp = vp;
731 uid = 0; /* XXX gcc */
732 gid = 0; /* XXX gcc */
733 udf_node = udf_node;
734
735 DPRINTF(NOTIMPL, ("udf_setattr called\n"));
736
737 /*
738 * BUG-ALERT: UDF doesn't count '.' as an entry, so we'll have to
739 * subtract 1 to the link count if its a directory we're setting
740 * attributes on. See getattr.
741 */
742 if (vap->va_type == VDIR)
743 vap->va_nlink--;
744
745 /* do the uid/gid translation game */
746 nobody_uid = ump->mount_args.nobody_uid;
747 nobody_gid = ump->mount_args.nobody_gid;
748 if ((uid == nobody_uid) && (gid == nobody_gid)) {
749 uid = (uid_t) -1;
750 gid = (gid_t) -1;
751 }
752
753 /* TODO implement setattr!! NOT IMPLEMENTED yet */
754 return 0;
755 }
756
757 /* --------------------------------------------------------------------- */
758
759 /*
760 * Return POSIX pathconf information for UDF file systems.
761 */
762 int
763 udf_pathconf(void *v)
764 {
765 struct vop_pathconf_args /* {
766 struct vnode *a_vp;
767 int a_name;
768 register_t *a_retval;
769 } */ *ap = v;
770 struct vnode *vp = ap->a_vp;
771 struct udf_node *udf_node = VTOI(vp);
772 uint32_t bits;
773
774 DPRINTF(CALL, ("udf_pathconf called\n"));
775
776 switch (ap->a_name) {
777 case _PC_LINK_MAX:
778 *ap->a_retval = (1<<16)-1; /* 16 bits */
779 return 0;
780 case _PC_NAME_MAX:
781 *ap->a_retval = NAME_MAX;
782 return 0;
783 case _PC_PATH_MAX:
784 *ap->a_retval = PATH_MAX;
785 return 0;
786 case _PC_PIPE_BUF:
787 *ap->a_retval = PIPE_BUF;
788 return 0;
789 case _PC_CHOWN_RESTRICTED:
790 *ap->a_retval = 1;
791 return 0;
792 case _PC_NO_TRUNC:
793 *ap->a_retval = 1;
794 return 0;
795 case _PC_SYNC_IO:
796 *ap->a_retval = 0; /* synchronised is off for performance */
797 return 0;
798 case _PC_FILESIZEBITS:
799 bits = 32;
800 if (udf_node)
801 bits = 32 * vp->v_mount->mnt_dev_bshift;
802 *ap->a_retval = bits;
803 return 0;
804 }
805
806 return EINVAL;
807 }
808
809
810 /* --------------------------------------------------------------------- */
811
812 int
813 udf_open(void *v)
814 {
815 struct vop_open_args /* {
816 struct vnode *a_vp;
817 int a_mode;
818 kauth_cred_t a_cred;
819 struct proc *a_p;
820 } */ *ap = v;
821
822 DPRINTF(CALL, ("udf_open called\n"));
823 ap = 0; /* XXX gcc */
824
825 return 0;
826 }
827
828
829 /* --------------------------------------------------------------------- */
830
831 int
832 udf_close(void *v)
833 {
834 struct vop_close_args /* {
835 struct vnode *a_vp;
836 int a_fflag;
837 kauth_cred_t a_cred;
838 struct proc *a_p;
839 } */ *ap = v;
840 struct vnode *vp = ap->a_vp;
841 struct udf_node *udf_node = VTOI(vp);
842
843 DPRINTF(CALL, ("udf_close called\n"));
844 udf_node = udf_node; /* shut up gcc */
845
846 simple_lock(&vp->v_interlock);
847 if (vp->v_usecount > 1) {
848 /* TODO update times */
849 }
850 simple_unlock(&vp->v_interlock);
851
852 return 0;
853 }
854
855
856 /* --------------------------------------------------------------------- */
857
858 int
859 udf_access(void *v)
860 {
861 struct vop_access_args /* {
862 struct vnode *a_vp;
863 int a_mode;
864 kauth_cred_t a_cred;
865 struct proc *a_p;
866 } */ *ap = v;
867 struct vnode *vp = ap->a_vp;
868 mode_t mode = ap->a_mode;
869 kauth_cred_t cred = ap->a_cred;
870 struct udf_node *udf_node = VTOI(vp);
871 struct file_entry *fe;
872 struct extfile_entry *efe;
873 mode_t node_mode;
874 uid_t uid;
875 gid_t gid;
876
877 DPRINTF(CALL, ("udf_access called\n"));
878
879 /* get access mode to compare to */
880 node_mode = udf_getaccessmode(udf_node);
881
882 /* get uid/gid pair */
883 if (udf_node->fe) {
884 fe = udf_node->fe;
885 uid = (uid_t)udf_rw32(fe->uid);
886 gid = (gid_t)udf_rw32(fe->gid);
887 } else {
888 assert(udf_node->efe);
889 efe = udf_node->efe;
890 uid = (uid_t)udf_rw32(efe->uid);
891 gid = (gid_t)udf_rw32(efe->gid);
892 }
893
894 /* check if we are allowed to write */
895 switch (vp->v_type) {
896 case VDIR:
897 case VLNK:
898 case VREG:
899 /*
900 * normal nodes: check if we're on a read-only mounted
901 * filingsystem and bomb out if we're trying to write.
902 */
903 if ((mode & VWRITE) && (vp->v_mount->mnt_flag & MNT_RDONLY))
904 return EROFS;
905 break;
906 case VBLK:
907 case VCHR:
908 case VSOCK:
909 case VFIFO:
910 /*
911 * special nodes: even on read-only mounted filingsystems
912 * these are allowed to be written to if permissions allow.
913 */
914 break;
915 default:
916 /* no idea what this is */
917 return EINVAL;
918 }
919
920 /* TODO support for chflags checking i.e. IMMUTABLE flag */
921
922 /* ask the generic vaccess to advice on security */
923 return vaccess(vp->v_type, node_mode, uid, gid, mode, cred);
924 }
925
926 /* --------------------------------------------------------------------- */
927
928 int
929 udf_create(void *v)
930 {
931 struct vop_create_args /* {
932 struct vnode *a_dvp;
933 struct vnode **a_vpp;
934 struct componentname *a_cnp;
935 struct vattr *a_vap;
936 } */ *ap = v;
937 struct componentname *cnp = ap->a_cnp;
938
939 DPRINTF(NOTIMPL, ("udf_create called\n"));
940
941 /* error out */
942 PNBUF_PUT(cnp->cn_pnbuf);
943 vput(ap->a_dvp);
944 return ENOTSUP;
945 }
946
947 /* --------------------------------------------------------------------- */
948
949 int
950 udf_mknod(void *v)
951 {
952 struct vop_mknod_args /* {
953 struct vnode *a_dvp;
954 struct vnode **a_vpp;
955 struct componentname *a_cnp;
956 struct vattr *a_vap;
957 } */ *ap = v;
958
959 DPRINTF(NOTIMPL, ("udf_mknod called\n"));
960
961 /* error out */
962 PNBUF_PUT(ap->a_cnp->cn_pnbuf);
963 vput(ap->a_dvp);
964 return ENOTSUP;
965 }
966
967 /* --------------------------------------------------------------------- */
968
969 int
970 udf_remove(void *v)
971 {
972 struct vop_remove_args /* {
973 struct vnode *a_dvp;
974 struct vnode *a_vp;
975 struct componentname *a_cnp;
976 } */ *ap = v;
977 struct vnode *dvp = ap->a_dvp;
978 struct vnode *vp = ap->a_vp;
979
980 DPRINTF(NOTIMPL, ("udf_remove called\n"));
981
982 /* error out */
983 vput(dvp);
984 vput(vp);
985
986 return ENOTSUP;
987 }
988
989 /* --------------------------------------------------------------------- */
990
991 int
992 udf_link(void *v)
993 {
994 struct vop_link_args /* {
995 struct vnode *a_dvp;
996 struct vnode *a_vp;
997 struct componentname *a_cnp;
998 } */ *ap = v;
999 struct vnode *dvp = ap->a_dvp;
1000 struct vnode *vp = ap->a_vp;
1001 struct componentname *cnp = ap->a_cnp;
1002
1003 DPRINTF(NOTIMPL, ("udf_link called\n"));
1004
1005 /* error out */
1006 /* XXX or just VOP_ABORTOP(dvp, a_cnp); ? */
1007 if (VOP_ISLOCKED(vp) == LK_EXCLUSIVE)
1008 VOP_UNLOCK(vp, 0);
1009 PNBUF_PUT(cnp->cn_pnbuf);
1010 vput(dvp);
1011
1012 return ENOTSUP;
1013 }
1014
1015 /* --------------------------------------------------------------------- */
1016
1017 int
1018 udf_symlink(void *v)
1019 {
1020 struct vop_symlink_args /* {
1021 struct vnode *a_dvp;
1022 struct vnode **a_vpp;
1023 struct componentname *a_cnp;
1024 struct vattr *a_vap;
1025 char *a_target;
1026 } */ *ap = v;
1027 struct vnode *dvp = ap->a_dvp;
1028 struct componentname *cnp = ap->a_cnp;
1029
1030 DPRINTF(NOTIMPL, ("udf_symlink called\n"));
1031
1032 /* error out */
1033 VOP_ABORTOP(dvp, cnp);
1034 vput(dvp);
1035
1036 return ENOTSUP;
1037 }
1038
1039 /* --------------------------------------------------------------------- */
1040
1041 int
1042 udf_readlink(void *v)
1043 {
1044 struct vop_readlink_args /* {
1045 struct vnode *a_vp;
1046 struct uio *a_uio;
1047 kauth_cred_t a_cred;
1048 } */ *ap = v;
1049 #ifdef notyet
1050 struct vnode *vp = ap->a_vp;
1051 struct uio *uio = ap->a_uio;
1052 kauth_cred_t cred = ap->a_cred;
1053 #endif
1054
1055 ap = ap; /* shut up gcc */
1056
1057 DPRINTF(NOTIMPL, ("udf_readlink called\n"));
1058
1059 /* TODO read `file' contents and process pathcomponents into a path */
1060 return ENOTSUP;
1061 }
1062
1063 /* --------------------------------------------------------------------- */
1064
1065 int
1066 udf_rename(void *v)
1067 {
1068 struct vop_rename_args /* {
1069 struct vnode *a_fdvp;
1070 struct vnode *a_fvp;
1071 struct componentname *a_fcnp;
1072 struct vnode *a_tdvp;
1073 struct vnode *a_tvp;
1074 struct componentname *a_tcnp;
1075 } */ *ap = v;
1076 struct vnode *tvp = ap->a_tvp;
1077 struct vnode *tdvp = ap->a_tdvp;
1078 struct vnode *fvp = ap->a_fvp;
1079 struct vnode *fdvp = ap->a_fdvp;
1080
1081 DPRINTF(NOTIMPL, ("udf_rename called\n"));
1082
1083 /* error out */
1084 if (tdvp == tvp)
1085 vrele(tdvp);
1086 else
1087 vput(tdvp);
1088 if (tvp != NULL)
1089 vput(tvp);
1090
1091 /* release source nodes. */
1092 vrele(fdvp);
1093 vrele(fvp);
1094
1095 return ENOTSUP;
1096 }
1097
1098 /* --------------------------------------------------------------------- */
1099
1100 int
1101 udf_mkdir(void *v)
1102 {
1103 struct vop_mkdir_args /* {
1104 struct vnode *a_dvp;
1105 struct vnode **a_vpp;
1106 struct componentname *a_cnp;
1107 struct vattr *a_vap;
1108 } */ *ap = v;
1109 struct vnode *dvp = ap->a_dvp;
1110 struct componentname *cnp = ap->a_cnp;
1111
1112 DPRINTF(NOTIMPL, ("udf_mkdir called\n"));
1113
1114 /* error out */
1115 PNBUF_PUT(cnp->cn_pnbuf);
1116 vput(dvp);
1117
1118 return ENOTSUP;
1119 }
1120
1121 /* --------------------------------------------------------------------- */
1122
1123 int
1124 udf_rmdir(void *v)
1125 {
1126 struct vop_rmdir_args /* {
1127 struct vnode *a_dvp;
1128 struct vnode *a_vp;
1129 struct componentname *a_cnp;
1130 } */ *ap = v;
1131 struct vnode *vp = ap->a_vp;
1132 struct vnode *dvp = ap->a_dvp;
1133 struct componentname *cnp = ap->a_cnp;
1134 int error;
1135
1136 cnp = cnp; /* shut up gcc */
1137
1138 DPRINTF(NOTIMPL, ("udf_rmdir called\n"));
1139
1140 error = ENOTSUP;
1141 /* error out */
1142 if (error != 0) {
1143 vput(dvp);
1144 vput(vp);
1145 }
1146
1147 return error;
1148 }
1149
1150 /* --------------------------------------------------------------------- */
1151
1152 int
1153 udf_fsync(void *v)
1154 {
1155 struct vop_fsync_args /* {
1156 struct vnode *a_vp;
1157 kauth_cred_t a_cred;
1158 int a_flags;
1159 off_t offlo;
1160 off_t offhi;
1161 struct proc *a_p;
1162 } */ *ap = v;
1163 struct vnode *vp = ap->a_vp;
1164
1165 DPRINTF(NOTIMPL, ("udf_fsync called\n"));
1166
1167 vp = vp; /* shut up gcc */
1168
1169 return 0;
1170 }
1171
1172 /* --------------------------------------------------------------------- */
1173
1174 int
1175 udf_advlock(void *v)
1176 {
1177 struct vop_advlock_args /* {
1178 struct vnode *a_vp;
1179 void *a_id;
1180 int a_op;
1181 struct flock *a_fl;
1182 int a_flags;
1183 } */ *ap = v;
1184 struct vnode *vp = ap->a_vp;
1185 struct udf_node *udf_node = VTOI(vp);
1186 struct file_entry *fe;
1187 struct extfile_entry *efe;
1188 uint64_t file_size;
1189
1190 DPRINTF(LOCKING, ("udf_advlock called\n"));
1191
1192 /* get directory filesize */
1193 if (udf_node->fe) {
1194 fe = udf_node->fe;
1195 file_size = udf_rw64(fe->inf_len);
1196 } else {
1197 assert(udf_node->efe);
1198 efe = udf_node->efe;
1199 file_size = udf_rw64(efe->inf_len);
1200 }
1201
1202 return lf_advlock(ap, &udf_node->lockf, file_size);
1203 }
1204
1205 /* --------------------------------------------------------------------- */
1206
1207
1208 /* Global vfs vnode data structures for udfs */
1209 int (**udf_vnodeop_p) __P((void *));
1210
1211 const struct vnodeopv_entry_desc udf_vnodeop_entries[] = {
1212 { &vop_default_desc, vn_default_error },
1213 { &vop_lookup_desc, udf_lookup }, /* lookup */
1214 { &vop_create_desc, udf_create }, /* create */ /* TODO */
1215 { &vop_mknod_desc, udf_mknod }, /* mknod */ /* TODO */
1216 { &vop_open_desc, udf_open }, /* open */
1217 { &vop_close_desc, udf_close }, /* close */
1218 { &vop_access_desc, udf_access }, /* access */
1219 { &vop_getattr_desc, udf_getattr }, /* getattr */
1220 { &vop_setattr_desc, udf_setattr }, /* setattr */ /* TODO */
1221 { &vop_read_desc, udf_read }, /* read */
1222 { &vop_write_desc, udf_write }, /* write */ /* WRITE */
1223 { &vop_lease_desc, genfs_lease_check }, /* lease */ /* TODO? */
1224 { &vop_fcntl_desc, genfs_fcntl }, /* fcntl */ /* TODO? */
1225 { &vop_ioctl_desc, genfs_enoioctl }, /* ioctl */ /* TODO? */
1226 { &vop_poll_desc, genfs_poll }, /* poll */ /* TODO/OK? */
1227 { &vop_kqfilter_desc, genfs_kqfilter }, /* kqfilter */ /* ? */
1228 { &vop_revoke_desc, genfs_revoke }, /* revoke */ /* TODO? */
1229 { &vop_mmap_desc, genfs_mmap }, /* mmap */ /* OK? */
1230 { &vop_fsync_desc, udf_fsync }, /* fsync */ /* TODO */
1231 { &vop_seek_desc, genfs_seek }, /* seek */
1232 { &vop_remove_desc, udf_remove }, /* remove */ /* TODO */
1233 { &vop_link_desc, udf_link }, /* link */ /* TODO */
1234 { &vop_rename_desc, udf_rename }, /* rename */ /* TODO */
1235 { &vop_mkdir_desc, udf_mkdir }, /* mkdir */ /* TODO */
1236 { &vop_rmdir_desc, udf_rmdir }, /* rmdir */ /* TODO */
1237 { &vop_symlink_desc, udf_symlink }, /* symlink */ /* TODO */
1238 { &vop_readdir_desc, udf_readdir }, /* readdir */
1239 { &vop_readlink_desc, udf_readlink }, /* readlink */ /* TEST ME */
1240 { &vop_abortop_desc, genfs_abortop }, /* abortop */ /* TODO/OK? */
1241 { &vop_inactive_desc, udf_inactive }, /* inactive */
1242 { &vop_reclaim_desc, udf_reclaim }, /* reclaim */
1243 { &vop_lock_desc, genfs_lock }, /* lock */
1244 { &vop_unlock_desc, genfs_unlock }, /* unlock */
1245 { &vop_bmap_desc, udf_trivial_bmap }, /* bmap */ /* 1:1 bmap */
1246 { &vop_strategy_desc, udf_strategy }, /* strategy */
1247 /* { &vop_print_desc, udf_print }, */ /* print */
1248 { &vop_islocked_desc, genfs_islocked }, /* islocked */
1249 { &vop_pathconf_desc, udf_pathconf }, /* pathconf */
1250 { &vop_advlock_desc, udf_advlock }, /* advlock */ /* TEST ME */
1251 { &vop_bwrite_desc, vn_bwrite }, /* bwrite */ /* ->strategy */
1252 { &vop_getpages_desc, genfs_getpages }, /* getpages */
1253 { &vop_putpages_desc, genfs_putpages }, /* putpages */
1254 { NULL, NULL }
1255 };
1256
1257
1258 const struct vnodeopv_desc udf_vnodeop_opv_desc = {
1259 &udf_vnodeop_p, udf_vnodeop_entries
1260 };
1261
1262