1 /*-
2 * Copyright (c) 1994
3 * The Regents of the University of California. All rights reserved.
4 *
5 * This code is derived from software contributed to Berkeley
6 * by Pace Willisson (pace@blitz.com). The Rock Ridge Extension
7 * Support code is derived from software contributed to Berkeley
8 * by Atsushi Murai (amurai@spec.co.jp).
9 *
10 * Redistribution and use in source and binary forms, with or without
11 * modification, are permitted provided that the following conditions
12 * are met:
13 * 1. Redistributions of source code must retain the above copyright
14 * notice, this list of conditions and the following disclaimer.
15 * 2. Redistributions in binary form must reproduce the above copyright
16 * notice, this list of conditions and the following disclaimer in the
17 * documentation and/or other materials provided with the distribution.
18 * 4. Neither the name of the University nor the names of its contributors
19 * may be used to endorse or promote products derived from this software
20 * without specific prior written permission.
21 *
22 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
23 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
24 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
25 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
26 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
27 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
28 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
29 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
30 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
31 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
32 * SUCH DAMAGE.
33 *
34 * @(#)cd9660_vnops.c 8.19 (Berkeley) 5/27/95
35 */
36
37 #include <sys/cdefs.h>
38 __FBSDID("$FreeBSD$");
39
40 #include <sys/param.h>
41 #include <sys/systm.h>
42 #include <sys/namei.h>
43 #include <sys/kernel.h>
44 #include <sys/conf.h>
45 #include <sys/stat.h>
46 #include <sys/bio.h>
47 #include <sys/buf.h>
48 #include <sys/mount.h>
49 #include <sys/vnode.h>
50 #include <fs/fifofs/fifo.h>
51 #include <sys/malloc.h>
52 #include <sys/dirent.h>
53 #include <sys/unistd.h>
54 #include <sys/filio.h>
55
56 #include <vm/vm.h>
57 #include <vm/vnode_pager.h>
58 #include <vm/uma.h>
59
60 #include <fs/cd9660/iso.h>
61 #include <fs/cd9660/cd9660_node.h>
62 #include <fs/cd9660/iso_rrip.h>
63
64 static vop_setattr_t cd9660_setattr;
65 static vop_open_t cd9660_open;
66 static vop_access_t cd9660_access;
67 static vop_getattr_t cd9660_getattr;
68 static vop_ioctl_t cd9660_ioctl;
69 static vop_pathconf_t cd9660_pathconf;
70 static vop_read_t cd9660_read;
71 struct isoreaddir;
72 static int iso_uiodir(struct isoreaddir *idp, struct dirent *dp, off_t off);
73 static int iso_shipdir(struct isoreaddir *idp);
74 static vop_readdir_t cd9660_readdir;
75 static vop_readlink_t cd9660_readlink;
76 static vop_strategy_t cd9660_strategy;
77 static vop_vptofh_t cd9660_vptofh;
78
79 /*
80 * Setattr call. Only allowed for block and character special devices.
81 */
82 static int
83 cd9660_setattr(ap)
84 struct vop_setattr_args /* {
85 struct vnodeop_desc *a_desc;
86 struct vnode *a_vp;
87 struct vattr *a_vap;
88 struct ucred *a_cred;
89 struct thread *a_td;
90 } */ *ap;
91 {
92 struct vnode *vp = ap->a_vp;
93 struct vattr *vap = ap->a_vap;
94
95 if (vap->va_flags != (u_long)VNOVAL || vap->va_uid != (uid_t)VNOVAL ||
96 vap->va_gid != (gid_t)VNOVAL || vap->va_atime.tv_sec != VNOVAL ||
97 vap->va_mtime.tv_sec != VNOVAL || vap->va_mode != (mode_t)VNOVAL)
98 return (EROFS);
99 if (vap->va_size != (u_quad_t)VNOVAL) {
100 switch (vp->v_type) {
101 case VDIR:
102 return (EISDIR);
103 case VLNK:
104 case VREG:
105 return (EROFS);
106 case VCHR:
107 case VBLK:
108 case VSOCK:
109 case VFIFO:
110 case VNON:
111 case VBAD:
112 case VMARKER:
113 return (0);
114 }
115 }
116 return (0);
117 }
118
119 /*
120 * Check mode permission on inode pointer. Mode is READ, WRITE or EXEC.
121 * The mode is shifted to select the owner/group/other fields. The
122 * super user is granted all permissions.
123 */
124 /* ARGSUSED */
125 static int
126 cd9660_access(ap)
127 struct vop_access_args /* {
128 struct vnode *a_vp;
129 int a_mode;
130 struct ucred *a_cred;
131 struct thread *a_td;
132 } */ *ap;
133 {
134 struct vnode *vp = ap->a_vp;
135 struct iso_node *ip = VTOI(vp);
136 mode_t mode = ap->a_mode;
137
138 if (vp->v_type == VCHR || vp->v_type == VBLK)
139 return (EOPNOTSUPP);
140
141 /*
142 * Disallow write attempts unless the file is a socket,
143 * fifo, or a block or character device resident on the
144 * filesystem.
145 */
146 if (mode & VWRITE) {
147 switch (vp->v_type) {
148 case VDIR:
149 case VLNK:
150 case VREG:
151 return (EROFS);
152 /* NOT REACHED */
153 default:
154 break;
155 }
156 }
157
158 return (vaccess(vp->v_type, ip->inode.iso_mode, ip->inode.iso_uid,
159 ip->inode.iso_gid, ap->a_mode, ap->a_cred, NULL));
160 }
161
162 static int
163 cd9660_open(ap)
164 struct vop_open_args /* {
165 struct vnode *a_vp;
166 int a_mode;
167 struct ucred *a_cred;
168 struct thread *a_td;
169 struct file *a_fp;
170 } */ *ap;
171 {
172 struct vnode *vp = ap->a_vp;
173 struct iso_node *ip = VTOI(vp);
174
175 if (vp->v_type == VCHR || vp->v_type == VBLK)
176 return (EOPNOTSUPP);
177
178 vnode_create_vobject(vp, ip->i_size, ap->a_td);
179 return (0);
180 }
181
182
183 static int
184 cd9660_getattr(ap)
185 struct vop_getattr_args /* {
186 struct vnode *a_vp;
187 struct vattr *a_vap;
188 struct ucred *a_cred;
189 struct thread *a_td;
190 } */ *ap;
191
192 {
193 struct vnode *vp = ap->a_vp;
194 struct vattr *vap = ap->a_vap;
195 struct iso_node *ip = VTOI(vp);
196
197 vap->va_fsid = dev2udev(ip->i_mnt->im_dev);
198 vap->va_fileid = ip->i_number;
199
200 vap->va_mode = ip->inode.iso_mode;
201 vap->va_nlink = ip->inode.iso_links;
202 vap->va_uid = ip->inode.iso_uid;
203 vap->va_gid = ip->inode.iso_gid;
204 vap->va_atime = ip->inode.iso_atime;
205 vap->va_mtime = ip->inode.iso_mtime;
206 vap->va_ctime = ip->inode.iso_ctime;
207 vap->va_rdev = ip->inode.iso_rdev;
208
209 vap->va_size = (u_quad_t) ip->i_size;
210 if (ip->i_size == 0 && (vap->va_mode & S_IFMT) == S_IFLNK) {
211 struct vop_readlink_args rdlnk;
212 struct iovec aiov;
213 struct uio auio;
214 char *cp;
215
216 MALLOC(cp, char *, MAXPATHLEN, M_TEMP, M_WAITOK);
217 aiov.iov_base = cp;
218 aiov.iov_len = MAXPATHLEN;
219 auio.uio_iov = &aiov;
220 auio.uio_iovcnt = 1;
221 auio.uio_offset = 0;
222 auio.uio_rw = UIO_READ;
223 auio.uio_segflg = UIO_SYSSPACE;
224 auio.uio_td = ap->a_td;
225 auio.uio_resid = MAXPATHLEN;
226 rdlnk.a_uio = &auio;
227 rdlnk.a_vp = ap->a_vp;
228 rdlnk.a_cred = ap->a_cred;
229 if (cd9660_readlink(&rdlnk) == 0)
230 vap->va_size = MAXPATHLEN - auio.uio_resid;
231 FREE(cp, M_TEMP);
232 }
233 vap->va_flags = 0;
234 vap->va_gen = 1;
235 vap->va_blocksize = ip->i_mnt->logical_block_size;
236 vap->va_bytes = (u_quad_t) ip->i_size;
237 vap->va_type = vp->v_type;
238 vap->va_filerev = 0;
239 return (0);
240 }
241
242 /*
243 * Vnode op for ioctl.
244 */
245 static int
246 cd9660_ioctl(ap)
247 struct vop_ioctl_args /* {
248 struct vnode *a_vp;
249 u_long a_command;
250 caddr_t a_data;
251 int a_fflag;
252 struct ucred *a_cred;
253 struct thread *a_td;
254 } */ *ap;
255 {
256 struct vnode *vp;
257 struct iso_node *ip;
258 int error;
259
260 vp = ap->a_vp;
261 vn_lock(vp, LK_SHARED | LK_RETRY, ap->a_td);
262 if (vp->v_iflag & VI_DOOMED) {
263 VOP_UNLOCK(vp, 0, ap->a_td);
264 return (EBADF);
265 }
266 if (vp->v_type == VCHR || vp->v_type == VBLK) {
267 VOP_UNLOCK(vp, 0, ap->a_td);
268 return (EOPNOTSUPP);
269 }
270
271 ip = VTOI(vp);
272 error = 0;
273
274 switch (ap->a_command) {
275 case FIOGETLBA:
276 *(int *)(ap->a_data) = ip->iso_start;
277 break;
278 default:
279 error = ENOTTY;
280 break;
281 }
282
283 VOP_UNLOCK(vp, 0, ap->a_td);
284 return (error);
285 }
286
287 /*
288 * Vnode op for reading.
289 */
290 static int
291 cd9660_read(ap)
292 struct vop_read_args /* {
293 struct vnode *a_vp;
294 struct uio *a_uio;
295 int a_ioflag;
296 struct ucred *a_cred;
297 } */ *ap;
298 {
299 struct vnode *vp = ap->a_vp;
300 struct uio *uio = ap->a_uio;
301 struct iso_node *ip = VTOI(vp);
302 struct iso_mnt *imp;
303 struct buf *bp;
304 daddr_t lbn, rablock;
305 off_t diff;
306 int rasize, error = 0;
307 int seqcount;
308 long size, n, on;
309
310 if (vp->v_type == VCHR || vp->v_type == VBLK)
311 return (EOPNOTSUPP);
312
313 seqcount = ap->a_ioflag >> IO_SEQSHIFT;
314
315 if (uio->uio_resid == 0)
316 return (0);
317 if (uio->uio_offset < 0)
318 return (EINVAL);
319 ip->i_flag |= IN_ACCESS;
320 imp = ip->i_mnt;
321 do {
322 lbn = lblkno(imp, uio->uio_offset);
323 on = blkoff(imp, uio->uio_offset);
324 n = min((u_int)(imp->logical_block_size - on),
325 uio->uio_resid);
326 diff = (off_t)ip->i_size - uio->uio_offset;
327 if (diff <= 0)
328 return (0);
329 if (diff < n)
330 n = diff;
331 size = blksize(imp, ip, lbn);
332 rablock = lbn + 1;
333 if ((vp->v_mount->mnt_flag & MNT_NOCLUSTERR) == 0) {
334 if (lblktosize(imp, rablock) < ip->i_size)
335 error = cluster_read(vp, (off_t)ip->i_size,
336 lbn, size, NOCRED, uio->uio_resid,
337 (ap->a_ioflag >> 16), &bp);
338 else
339 error = bread(vp, lbn, size, NOCRED, &bp);
340 } else {
341 if (seqcount > 1 &&
342 lblktosize(imp, rablock) < ip->i_size) {
343 rasize = blksize(imp, ip, rablock);
344 error = breadn(vp, lbn, size, &rablock,
345 &rasize, 1, NOCRED, &bp);
346 } else
347 error = bread(vp, lbn, size, NOCRED, &bp);
348 }
349 n = min(n, size - bp->b_resid);
350 if (error) {
351 brelse(bp);
352 return (error);
353 }
354
355 error = uiomove(bp->b_data + on, (int)n, uio);
356 brelse(bp);
357 } while (error == 0 && uio->uio_resid > 0 && n != 0);
358 return (error);
359 }
360
361 /*
362 * Structure for reading directories
363 */
364 struct isoreaddir {
365 struct dirent saveent;
366 struct dirent assocent;
367 struct dirent current;
368 off_t saveoff;
369 off_t assocoff;
370 off_t curroff;
371 struct uio *uio;
372 off_t uio_off;
373 int eofflag;
374 u_long *cookies;
375 int ncookies;
376 };
377
378 static int
379 iso_uiodir(idp,dp,off)
380 struct isoreaddir *idp;
381 struct dirent *dp;
382 off_t off;
383 {
384 int error;
385
386 dp->d_name[dp->d_namlen] = 0;
387 dp->d_reclen = GENERIC_DIRSIZ(dp);
388
389 if (idp->uio->uio_resid < dp->d_reclen) {
390 idp->eofflag = 0;
391 return (-1);
392 }
393
394 if (idp->cookies) {
395 if (idp->ncookies <= 0) {
396 idp->eofflag = 0;
397 return (-1);
398 }
399
400 *idp->cookies++ = off;
401 --idp->ncookies;
402 }
403
404 if ((error = uiomove(dp, dp->d_reclen, idp->uio)) != 0)
405 return (error);
406 idp->uio_off = off;
407 return (0);
408 }
409
410 static int
411 iso_shipdir(idp)
412 struct isoreaddir *idp;
413 {
414 struct dirent *dp;
415 int cl, sl, assoc;
416 int error;
417 char *cname, *sname;
418
419 cl = idp->current.d_namlen;
420 cname = idp->current.d_name;
421 assoc = (cl > 1) && (*cname == ASSOCCHAR);
422 if (assoc) {
423 cl--;
424 cname++;
425 }
426
427 dp = &idp->saveent;
428 sname = dp->d_name;
429 if (!(sl = dp->d_namlen)) {
430 dp = &idp->assocent;
431 sname = dp->d_name + 1;
432 sl = dp->d_namlen - 1;
433 }
434 if (sl > 0) {
435 if (sl != cl
436 || bcmp(sname,cname,sl)) {
437 if (idp->assocent.d_namlen) {
438 if ((error = iso_uiodir(idp,&idp->assocent,idp->assocoff)) != 0)
439 return (error);
440 idp->assocent.d_namlen = 0;
441 }
442 if (idp->saveent.d_namlen) {
443 if ((error = iso_uiodir(idp,&idp->saveent,idp->saveoff)) != 0)
444 return (error);
445 idp->saveent.d_namlen = 0;
446 }
447 }
448 }
449 idp->current.d_reclen = GENERIC_DIRSIZ(&idp->current);
450 if (assoc) {
451 idp->assocoff = idp->curroff;
452 bcopy(&idp->current,&idp->assocent,idp->current.d_reclen);
453 } else {
454 idp->saveoff = idp->curroff;
455 bcopy(&idp->current,&idp->saveent,idp->current.d_reclen);
456 }
457 return (0);
458 }
459
460 /*
461 * Vnode op for readdir
462 */
463 static int
464 cd9660_readdir(ap)
465 struct vop_readdir_args /* {
466 struct vnode *a_vp;
467 struct uio *a_uio;
468 struct ucred *a_cred;
469 int *a_eofflag;
470 int *a_ncookies;
471 u_long **a_cookies;
472 } */ *ap;
473 {
474 struct uio *uio = ap->a_uio;
475 struct isoreaddir *idp;
476 struct vnode *vdp = ap->a_vp;
477 struct iso_node *dp;
478 struct iso_mnt *imp;
479 struct buf *bp = NULL;
480 struct iso_directory_record *ep;
481 int entryoffsetinblock;
482 doff_t endsearch;
483 u_long bmask;
484 int error = 0;
485 int reclen;
486 u_short namelen;
487 int ncookies = 0;
488 u_long *cookies = NULL;
489
490 dp = VTOI(vdp);
491 imp = dp->i_mnt;
492 bmask = imp->im_bmask;
493
494 MALLOC(idp, struct isoreaddir *, sizeof(*idp), M_TEMP, M_WAITOK);
495 idp->saveent.d_namlen = idp->assocent.d_namlen = 0;
496 /*
497 * XXX
498 * Is it worth trying to figure out the type?
499 */
500 idp->saveent.d_type = idp->assocent.d_type = idp->current.d_type =
501 DT_UNKNOWN;
502 idp->uio = uio;
503 if (ap->a_ncookies == NULL) {
504 idp->cookies = NULL;
505 } else {
506 /*
507 * Guess the number of cookies needed.
508 */
509 ncookies = uio->uio_resid / 16;
510 MALLOC(cookies, u_long *, ncookies * sizeof(u_long),
511 M_TEMP, M_WAITOK);
512 idp->cookies = cookies;
513 idp->ncookies = ncookies;
514 }
515 idp->eofflag = 1;
516 idp->curroff = uio->uio_offset;
517 idp->uio_off = uio->uio_offset;
518
519 if ((entryoffsetinblock = idp->curroff & bmask) &&
520 (error = cd9660_blkatoff(vdp, (off_t)idp->curroff, NULL, &bp))) {
521 FREE(idp, M_TEMP);
522 return (error);
523 }
524 endsearch = dp->i_size;
525
526 while (idp->curroff < endsearch) {
527 /*
528 * If offset is on a block boundary,
529 * read the next directory block.
530 * Release previous if it exists.
531 */
532 if ((idp->curroff & bmask) == 0) {
533 if (bp != NULL)
534 brelse(bp);
535 if ((error =
536 cd9660_blkatoff(vdp, (off_t)idp->curroff, NULL, &bp)) != 0)
537 break;
538 entryoffsetinblock = 0;
539 }
540 /*
541 * Get pointer to next entry.
542 */
543 ep = (struct iso_directory_record *)
544 ((char *)bp->b_data + entryoffsetinblock);
545
546 reclen = isonum_711(ep->length);
547 if (reclen == 0) {
548 /* skip to next block, if any */
549 idp->curroff =
550 (idp->curroff & ~bmask) + imp->logical_block_size;
551 continue;
552 }
553
554 if (reclen < ISO_DIRECTORY_RECORD_SIZE) {
555 error = EINVAL;
556 /* illegal entry, stop */
557 break;
558 }
559
560 if (entryoffsetinblock + reclen > imp->logical_block_size) {
561 error = EINVAL;
562 /* illegal directory, so stop looking */
563 break;
564 }
565
566 idp->current.d_namlen = isonum_711(ep->name_len);
567
568 if (reclen < ISO_DIRECTORY_RECORD_SIZE + idp->current.d_namlen) {
569 error = EINVAL;
570 /* illegal entry, stop */
571 break;
572 }
573
574 if (isonum_711(ep->flags)&2)
575 idp->current.d_fileno = isodirino(ep, imp);
576 else
577 idp->current.d_fileno = dbtob(bp->b_blkno) +
578 entryoffsetinblock;
579
580 idp->curroff += reclen;
581
582 switch (imp->iso_ftype) {
583 case ISO_FTYPE_RRIP:
584 cd9660_rrip_getname(ep,idp->current.d_name, &namelen,
585 &idp->current.d_fileno,imp);
586 idp->current.d_namlen = (u_char)namelen;
587 if (idp->current.d_namlen)
588 error = iso_uiodir(idp,&idp->current,idp->curroff);
589 break;
590 default: /* ISO_FTYPE_DEFAULT || ISO_FTYPE_9660 || ISO_FTYPE_HIGH_SIERRA*/
591 strcpy(idp->current.d_name,"..");
592 if (idp->current.d_namlen == 1 && ep->name[0] == 0) {
593 idp->current.d_namlen = 1;
594 error = iso_uiodir(idp,&idp->current,idp->curroff);
595 } else if (idp->current.d_namlen == 1 && ep->name[0] == 1) {
596 idp->current.d_namlen = 2;
597 error = iso_uiodir(idp,&idp->current,idp->curroff);
598 } else {
599 isofntrans(ep->name,idp->current.d_namlen,
600 idp->current.d_name, &namelen,
601 imp->iso_ftype == ISO_FTYPE_9660,
602 isonum_711(ep->flags)&4,
603 imp->joliet_level,
604 imp->im_flags,
605 imp->im_d2l);
606 idp->current.d_namlen = (u_char)namelen;
607 if (imp->iso_ftype == ISO_FTYPE_DEFAULT)
608 error = iso_shipdir(idp);
609 else
610 error = iso_uiodir(idp,&idp->current,idp->curroff);
611 }
612 }
613 if (error)
614 break;
615
616 entryoffsetinblock += reclen;
617 }
618
619 if (!error && imp->iso_ftype == ISO_FTYPE_DEFAULT) {
620 idp->current.d_namlen = 0;
621 error = iso_shipdir(idp);
622 }
623 if (error < 0)
624 error = 0;
625
626 if (ap->a_ncookies != NULL) {
627 if (error)
628 free(cookies, M_TEMP);
629 else {
630 /*
631 * Work out the number of cookies actually used.
632 */
633 *ap->a_ncookies = ncookies - idp->ncookies;
634 *ap->a_cookies = cookies;
635 }
636 }
637
638 if (bp)
639 brelse (bp);
640
641 uio->uio_offset = idp->uio_off;
642 *ap->a_eofflag = idp->eofflag;
643
644 FREE(idp, M_TEMP);
645
646 return (error);
647 }
648
649 /*
650 * Return target name of a symbolic link
651 * Shouldn't we get the parent vnode and read the data from there?
652 * This could eventually result in deadlocks in cd9660_lookup.
653 * But otherwise the block read here is in the block buffer two times.
654 */
655 typedef struct iso_directory_record ISODIR;
656 typedef struct iso_node ISONODE;
657 typedef struct iso_mnt ISOMNT;
658 static int
659 cd9660_readlink(ap)
660 struct vop_readlink_args /* {
661 struct vnode *a_vp;
662 struct uio *a_uio;
663 struct ucred *a_cred;
664 } */ *ap;
665 {
666 ISONODE *ip;
667 ISODIR *dirp;
668 ISOMNT *imp;
669 struct buf *bp;
670 struct uio *uio;
671 u_short symlen;
672 int error;
673 char *symname;
674
675 ip = VTOI(ap->a_vp);
676 imp = ip->i_mnt;
677 uio = ap->a_uio;
678
679 if (imp->iso_ftype != ISO_FTYPE_RRIP)
680 return (EINVAL);
681
682 /*
683 * Get parents directory record block that this inode included.
684 */
685 error = bread(imp->im_devvp,
686 (ip->i_number >> imp->im_bshift) <<
687 (imp->im_bshift - DEV_BSHIFT),
688 imp->logical_block_size, NOCRED, &bp);
689 if (error) {
690 brelse(bp);
691 return (EINVAL);
692 }
693
694 /*
695 * Setup the directory pointer for this inode
696 */
697 dirp = (ISODIR *)(bp->b_data + (ip->i_number & imp->im_bmask));
698
699 /*
700 * Just make sure, we have a right one....
701 * 1: Check not cross boundary on block
702 */
703 if ((ip->i_number & imp->im_bmask) + isonum_711(dirp->length)
704 > (unsigned)imp->logical_block_size) {
705 brelse(bp);
706 return (EINVAL);
707 }
708
709 /*
710 * Now get a buffer
711 * Abuse a namei buffer for now.
712 */
713 if (uio->uio_segflg == UIO_SYSSPACE)
714 symname = uio->uio_iov->iov_base;
715 else
716 symname = uma_zalloc(namei_zone, M_WAITOK);
717
718 /*
719 * Ok, we just gathering a symbolic name in SL record.
720 */
721 if (cd9660_rrip_getsymname(dirp, symname, &symlen, imp) == 0) {
722 if (uio->uio_segflg != UIO_SYSSPACE)
723 uma_zfree(namei_zone, symname);
724 brelse(bp);
725 return (EINVAL);
726 }
727 /*
728 * Don't forget before you leave from home ;-)
729 */
730 brelse(bp);
731
732 /*
733 * return with the symbolic name to caller's.
734 */
735 if (uio->uio_segflg != UIO_SYSSPACE) {
736 error = uiomove(symname, symlen, uio);
737 uma_zfree(namei_zone, symname);
738 return (error);
739 }
740 uio->uio_resid -= symlen;
741 uio->uio_iov->iov_base = (char *)uio->uio_iov->iov_base + symlen;
742 uio->uio_iov->iov_len -= symlen;
743 return (0);
744 }
745
746 /*
747 * Calculate the logical to physical mapping if not done already,
748 * then call the device strategy routine.
749 */
750 static int
751 cd9660_strategy(ap)
752 struct vop_strategy_args /* {
753 struct buf *a_vp;
754 struct buf *a_bp;
755 } */ *ap;
756 {
757 struct buf *bp = ap->a_bp;
758 struct vnode *vp = ap->a_vp;
759 struct iso_node *ip;
760 struct bufobj *bo;
761
762 ip = VTOI(vp);
763 if (vp->v_type == VBLK || vp->v_type == VCHR)
764 panic("cd9660_strategy: spec");
765 if (bp->b_blkno == bp->b_lblkno) {
766 bp->b_blkno = (ip->iso_start + bp->b_lblkno) <<
767 (ip->i_mnt->im_bshift - DEV_BSHIFT);
768 if ((long)bp->b_blkno == -1) /* XXX: cut&paste junk ? */
769 clrbuf(bp);
770 }
771 if ((long)bp->b_blkno == -1) { /* XXX: cut&paste junk ? */
772 bufdone(bp);
773 return (0);
774 }
775 bp->b_iooffset = dbtob(bp->b_blkno);
776 bo = ip->i_mnt->im_bo;
777 BO_STRATEGY(bo, bp);
778 return (0);
779 }
780
781 /*
782 * Return POSIX pathconf information applicable to cd9660 filesystems.
783 */
784 static int
785 cd9660_pathconf(ap)
786 struct vop_pathconf_args /* {
787 struct vnode *a_vp;
788 int a_name;
789 register_t *a_retval;
790 } */ *ap;
791 {
792
793 switch (ap->a_name) {
794 case _PC_LINK_MAX:
795 *ap->a_retval = 1;
796 return (0);
797 case _PC_NAME_MAX:
798 if (VTOI(ap->a_vp)->i_mnt->iso_ftype == ISO_FTYPE_RRIP)
799 *ap->a_retval = NAME_MAX;
800 else
801 *ap->a_retval = 37;
802 return (0);
803 case _PC_PATH_MAX:
804 *ap->a_retval = PATH_MAX;
805 return (0);
806 case _PC_PIPE_BUF:
807 *ap->a_retval = PIPE_BUF;
808 return (0);
809 case _PC_CHOWN_RESTRICTED:
810 *ap->a_retval = 1;
811 return (0);
812 case _PC_NO_TRUNC:
813 *ap->a_retval = 1;
814 return (0);
815 default:
816 return (EINVAL);
817 }
818 /* NOTREACHED */
819 }
820
821 /*
822 * Vnode pointer to File handle
823 */
824 static int
825 cd9660_vptofh(ap)
826 struct vop_vptofh_args /* {
827 struct vnode *a_vp;
828 struct fid *a_fhp;
829 } */ *ap;
830 {
831 struct ifid ifh;
832 struct iso_node *ip = VTOI(ap->a_vp);
833
834 ifh.ifid_len = sizeof(struct ifid);
835
836 ifh.ifid_ino = ip->i_number;
837 ifh.ifid_start = ip->iso_start;
838 /*
839 * This intentionally uses sizeof(ifh) in order to not copy stack
840 * garbage on ILP32.
841 */
842 memcpy(ap->a_fhp, &ifh, sizeof(ifh));
843
844 #ifdef ISOFS_DBG
845 printf("vptofh: ino %d, start %ld\n",
846 ifh.ifid_ino, ifh.ifid_start);
847 #endif
848
849 return (0);
850 }
851
852 /*
853 * Global vfs data structures for cd9660
854 */
855 struct vop_vector cd9660_vnodeops = {
856 .vop_default = &default_vnodeops,
857 .vop_open = cd9660_open,
858 .vop_access = cd9660_access,
859 .vop_bmap = cd9660_bmap,
860 .vop_cachedlookup = cd9660_lookup,
861 .vop_getattr = cd9660_getattr,
862 .vop_inactive = cd9660_inactive,
863 .vop_ioctl = cd9660_ioctl,
864 .vop_lookup = vfs_cache_lookup,
865 .vop_pathconf = cd9660_pathconf,
866 .vop_read = cd9660_read,
867 .vop_readdir = cd9660_readdir,
868 .vop_readlink = cd9660_readlink,
869 .vop_reclaim = cd9660_reclaim,
870 .vop_setattr = cd9660_setattr,
871 .vop_strategy = cd9660_strategy,
872 .vop_vptofh = cd9660_vptofh,
873 };
874
875 /*
876 * Special device vnode ops
877 */
878
879 struct vop_vector cd9660_fifoops = {
880 .vop_default = &fifo_specops,
881 .vop_access = cd9660_access,
882 .vop_getattr = cd9660_getattr,
883 .vop_inactive = cd9660_inactive,
884 .vop_reclaim = cd9660_reclaim,
885 .vop_setattr = cd9660_setattr,
886 .vop_vptofh = cd9660_vptofh,
887 };
Cache object: c05ed253f0211c515fee4a8cd299520f
|