Due to continuing issues with VOP_READ/VOP_WRITE ops being called without
[dragonfly.git] / sys / vfs / isofs / cd9660 / cd9660_vnops.c
CommitLineData
984263bc
MD
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 * 3. All advertising materials mentioning features or use of this software
19 * must display the following acknowledgement:
20 * This product includes software developed by the University of
21 * California, Berkeley and its contributors.
22 * 4. Neither the name of the University nor the names of its contributors
23 * may be used to endorse or promote products derived from this software
24 * without specific prior written permission.
25 *
26 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
27 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
28 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
29 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
30 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
31 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
32 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
33 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
34 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
35 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
36 * SUCH DAMAGE.
37 *
38 * @(#)cd9660_vnops.c 8.19 (Berkeley) 5/27/95
39 * $FreeBSD: src/sys/isofs/cd9660/cd9660_vnops.c,v 1.62 1999/12/15 23:01:51 eivind Exp $
1c843a13 40 * $DragonFly: src/sys/vfs/isofs/cd9660/cd9660_vnops.c,v 1.24 2006/04/07 06:38:31 dillon Exp $
984263bc
MD
41 */
42
43#include <sys/param.h>
44#include <sys/systm.h>
dadab5e9 45#include <sys/proc.h>
984263bc
MD
46#include <sys/namei.h>
47#include <sys/kernel.h>
48#include <sys/stat.h>
49#include <sys/buf.h>
50#include <sys/mount.h>
51#include <sys/vnode.h>
1f2de5d4 52#include <vfs/fifofs/fifo.h>
984263bc
MD
53#include <sys/malloc.h>
54#include <sys/dirent.h>
55#include <sys/unistd.h>
56#include <sys/filio.h>
f308cd58 57#include <sys/lockf.h>
984263bc
MD
58
59#include <vm/vm.h>
60#include <vm/vm_zone.h>
61#include <vm/vnode_pager.h>
62
1f2de5d4
MD
63#include "iso.h"
64#include "cd9660_node.h"
65#include "iso_rrip.h"
984263bc 66
a6ee311a 67static int cd9660_access (struct vop_access_args *);
f308cd58 68static int cd9660_advlock (struct vop_advlock_args *);
a6ee311a
RG
69static int cd9660_getattr (struct vop_getattr_args *);
70static int cd9660_ioctl (struct vop_ioctl_args *);
71static int cd9660_pathconf (struct vop_pathconf_args *);
7540ab49 72static int cd9660_open (struct vop_open_args *);
a6ee311a 73static int cd9660_read (struct vop_read_args *);
f308cd58 74static int cd9660_setattr (struct vop_setattr_args *);
984263bc 75struct isoreaddir;
a6ee311a
RG
76static int iso_uiodir (struct isoreaddir *idp, struct dirent *dp,
77 off_t off);
78static int iso_shipdir (struct isoreaddir *idp);
79static int cd9660_readdir (struct vop_readdir_args *);
80static int cd9660_readlink (struct vop_readlink_args *ap);
81static int cd9660_strategy (struct vop_strategy_args *);
82static int cd9660_print (struct vop_print_args *);
83static int cd9660_getpages (struct vop_getpages_args *);
84static int cd9660_putpages (struct vop_putpages_args *);
984263bc
MD
85
86/*
87 * Setattr call. Only allowed for block and character special devices.
3fa8192b
CP
88 *
89 * cd9660_setattr(struct vnodeop_desc *a_desc, struct vnode *a_vp,
90 * struct vattr *a_vap, struct ucred *a_cred, struct proc *a_p)
984263bc
MD
91 */
92int
3fa8192b 93cd9660_setattr(struct vop_setattr_args *ap)
984263bc
MD
94{
95 struct vnode *vp = ap->a_vp;
96 struct vattr *vap = ap->a_vap;
97
98 if (vap->va_flags != (u_long)VNOVAL || vap->va_uid != (uid_t)VNOVAL ||
99 vap->va_gid != (gid_t)VNOVAL || vap->va_atime.tv_sec != VNOVAL ||
100 vap->va_mtime.tv_sec != VNOVAL || vap->va_mode != (mode_t)VNOVAL)
101 return (EROFS);
102 if (vap->va_size != (u_quad_t)VNOVAL) {
103 switch (vp->v_type) {
104 case VDIR:
105 return (EISDIR);
106 case VLNK:
107 case VREG:
108 return (EROFS);
109 case VCHR:
110 case VBLK:
111 case VSOCK:
112 case VFIFO:
113 case VNON:
114 case VBAD:
115 return (0);
116 }
117 }
118 return (0);
119}
120
121/*
122 * Check mode permission on inode pointer. Mode is READ, WRITE or EXEC.
123 * The mode is shifted to select the owner/group/other fields. The
124 * super user is granted all permissions.
3fa8192b
CP
125 *
126 * cd9660_access(struct vnode *a_vp, int a_mode, struct ucred *a_cred,
127 * struct proc *a_p)
984263bc
MD
128 */
129/* ARGSUSED */
130static int
3fa8192b 131cd9660_access(struct vop_access_args *ap)
984263bc
MD
132{
133 struct vnode *vp = ap->a_vp;
134 struct iso_node *ip = VTOI(vp);
135 struct ucred *cred = ap->a_cred;
136 mode_t mask, mode = ap->a_mode;
137 gid_t *gp;
138 int i;
139
140 /*
141 * Disallow write attempts unless the file is a socket,
142 * fifo, or a block or character device resident on the
143 * file system.
144 */
145 if (mode & VWRITE) {
146 switch (vp->v_type) {
147 case VDIR:
148 case VLNK:
149 case VREG:
150 return (EROFS);
151 /* NOT REACHED */
152 default:
153 break;
154 }
155 }
156
157 /* User id 0 always gets access. */
158 if (cred->cr_uid == 0)
159 return (0);
160
161 mask = 0;
162
163 /* Otherwise, check the owner. */
164 if (cred->cr_uid == ip->inode.iso_uid) {
165 if (mode & VEXEC)
166 mask |= S_IXUSR;
167 if (mode & VREAD)
168 mask |= S_IRUSR;
169 if (mode & VWRITE)
170 mask |= S_IWUSR;
171 return ((ip->inode.iso_mode & mask) == mask ? 0 : EACCES);
172 }
173
174 /* Otherwise, check the groups. */
175 for (i = 0, gp = cred->cr_groups; i < cred->cr_ngroups; i++, gp++)
176 if (ip->inode.iso_gid == *gp) {
177 if (mode & VEXEC)
178 mask |= S_IXGRP;
179 if (mode & VREAD)
180 mask |= S_IRGRP;
181 if (mode & VWRITE)
182 mask |= S_IWGRP;
183 return ((ip->inode.iso_mode & mask) == mask ?
184 0 : EACCES);
185 }
186
187 /* Otherwise, check everyone else. */
188 if (mode & VEXEC)
189 mask |= S_IXOTH;
190 if (mode & VREAD)
191 mask |= S_IROTH;
192 if (mode & VWRITE)
193 mask |= S_IWOTH;
194 return ((ip->inode.iso_mode & mask) == mask ? 0 : EACCES);
195}
196
3fa8192b
CP
197/*
198 * cd9660_getattr(struct vnode *a_vp, struct vattr *a_vap, struct thread *a_td)
199 */
984263bc 200static int
3fa8192b 201cd9660_getattr(struct vop_getattr_args *ap)
984263bc
MD
202{
203 struct vnode *vp = ap->a_vp;
3a1b0fdc
RG
204 struct vattr *vap = ap->a_vap;
205 struct iso_node *ip = VTOI(vp);
984263bc
MD
206
207 vap->va_fsid = dev2udev(ip->i_dev);
208 vap->va_fileid = ip->i_number;
209
210 vap->va_mode = ip->inode.iso_mode;
211 vap->va_nlink = ip->inode.iso_links;
212 vap->va_uid = ip->inode.iso_uid;
213 vap->va_gid = ip->inode.iso_gid;
214 vap->va_atime = ip->inode.iso_atime;
215 vap->va_mtime = ip->inode.iso_mtime;
216 vap->va_ctime = ip->inode.iso_ctime;
217 vap->va_rdev = ip->inode.iso_rdev;
218
6d7c7288 219 vap->va_size = (u_quad_t)(unsigned long)ip->i_size;
984263bc
MD
220 if (ip->i_size == 0 && (vap->va_mode & S_IFMT) == S_IFLNK) {
221 struct vop_readlink_args rdlnk;
222 struct iovec aiov;
223 struct uio auio;
224 char *cp;
225
226 MALLOC(cp, char *, MAXPATHLEN, M_TEMP, M_WAITOK);
227 aiov.iov_base = cp;
228 aiov.iov_len = MAXPATHLEN;
229 auio.uio_iov = &aiov;
230 auio.uio_iovcnt = 1;
231 auio.uio_offset = 0;
232 auio.uio_rw = UIO_READ;
233 auio.uio_segflg = UIO_SYSSPACE;
dadab5e9 234 auio.uio_td = ap->a_td;
984263bc
MD
235 auio.uio_resid = MAXPATHLEN;
236 rdlnk.a_uio = &auio;
237 rdlnk.a_vp = ap->a_vp;
3b568787 238 rdlnk.a_cred = proc0.p_ucred; /* use root cred */
984263bc
MD
239 if (cd9660_readlink(&rdlnk) == 0)
240 vap->va_size = MAXPATHLEN - auio.uio_resid;
241 FREE(cp, M_TEMP);
242 }
243 vap->va_flags = 0;
244 vap->va_gen = 1;
245 vap->va_blocksize = ip->i_mnt->logical_block_size;
246 vap->va_bytes = (u_quad_t) ip->i_size;
247 vap->va_type = vp->v_type;
248 vap->va_filerev = 0;
249 return (0);
250}
251
252/*
253 * Vnode op for ioctl.
3fa8192b
CP
254 *
255 * cd9660_ioctl(struct vnode *a_vp, int a_command, caddr_t a_data,
256 * int a_fflag, struct ucred *a_cred, struct proc *a_p)
984263bc
MD
257 */
258static int
3fa8192b 259cd9660_ioctl(struct vop_ioctl_args *ap)
984263bc
MD
260{
261 struct vnode *vp = ap->a_vp;
262 struct iso_node *ip = VTOI(vp);
263
264 switch (ap->a_command) {
265
266 case FIOGETLBA:
267 *(int *)(ap->a_data) = ip->iso_start;
268 return 0;
269 default:
270 return (ENOTTY);
271 }
272}
273
7540ab49
MD
274/*
275 * open is called when the kernel intends to read or memory map a vnode.
276 */
277static int
278cd9660_open(struct vop_open_args *ap)
279{
8ddc6004 280 return(vop_stdopen(ap));
7540ab49
MD
281}
282
984263bc
MD
283/*
284 * Vnode op for reading.
3fa8192b
CP
285 *
286 * cd9660_read(struct vnode *a_vp, struct uio *a_uio, int a_ioflag,
287 * struct ucred *a_cred)
984263bc
MD
288 */
289static int
3fa8192b 290cd9660_read(struct vop_read_args *ap)
984263bc
MD
291{
292 struct vnode *vp = ap->a_vp;
3a1b0fdc
RG
293 struct uio *uio = ap->a_uio;
294 struct iso_node *ip = VTOI(vp);
295 struct iso_mnt *imp;
984263bc
MD
296 struct buf *bp;
297 daddr_t lbn, rablock;
54078292
MD
298 off_t raoffset;
299 off_t loffset;
984263bc
MD
300 off_t diff;
301 int rasize, error = 0;
302 int seqcount;
303 long size, n, on;
304
305 seqcount = ap->a_ioflag >> 16;
306
307 if (uio->uio_resid == 0)
308 return (0);
309 if (uio->uio_offset < 0)
310 return (EINVAL);
311 ip->i_flag |= IN_ACCESS;
312 imp = ip->i_mnt;
313 do {
314 lbn = lblkno(imp, uio->uio_offset);
54078292 315 loffset = lblktooff(imp, lbn);
984263bc
MD
316 on = blkoff(imp, uio->uio_offset);
317 n = min((u_int)(imp->logical_block_size - on),
318 uio->uio_resid);
319 diff = (off_t)ip->i_size - uio->uio_offset;
320 if (diff <= 0)
321 return (0);
322 if (diff < n)
323 n = diff;
324 size = blksize(imp, ip, lbn);
325 rablock = lbn + 1;
54078292 326 raoffset = lblktooff(imp, rablock);
984263bc 327 if ((vp->v_mount->mnt_flag & MNT_NOCLUSTERR) == 0) {
54078292 328 if (raoffset < ip->i_size)
984263bc 329 error = cluster_read(vp, (off_t)ip->i_size,
54078292
MD
330 loffset, size,
331 uio->uio_resid,
984263bc
MD
332 (ap->a_ioflag >> 16), &bp);
333 else
54078292 334 error = bread(vp, loffset, size, &bp);
984263bc
MD
335 } else {
336 if (seqcount > 1 &&
337 lblktosize(imp, rablock) < ip->i_size) {
338 rasize = blksize(imp, ip, rablock);
54078292 339 error = breadn(vp, loffset, size, &raoffset,
3b568787 340 &rasize, 1, &bp);
984263bc 341 } else
54078292 342 error = bread(vp, loffset, size, &bp);
984263bc
MD
343 }
344 n = min(n, size - bp->b_resid);
345 if (error) {
346 brelse(bp);
347 return (error);
348 }
349
350 error = uiomove(bp->b_data + on, (int)n, uio);
351 brelse(bp);
352 } while (error == 0 && uio->uio_resid > 0 && n != 0);
353 return (error);
354}
355
01f31ab3
JS
356/* struct dirent + enough space for the maximum supported size */
357struct iso_dirent {
358 struct dirent de;
359 char de_name[_DIRENT_RECLEN(NAME_MAX) - sizeof(struct dirent)];
360};
361
984263bc
MD
362/*
363 * Structure for reading directories
364 */
365struct isoreaddir {
01f31ab3
JS
366 struct iso_dirent saveent;
367 struct iso_dirent assocent;
368 struct iso_dirent current;
984263bc
MD
369 off_t saveoff;
370 off_t assocoff;
371 off_t curroff;
372 struct uio *uio;
373 off_t uio_off;
374 int eofflag;
375 u_long *cookies;
376 int ncookies;
377};
378
379int
3fa8192b 380iso_uiodir(struct isoreaddir *idp, struct dirent *dp, off_t off)
984263bc
MD
381{
382 int error;
383
384 dp->d_name[dp->d_namlen] = 0;
984263bc 385
01f31ab3 386 if (idp->uio->uio_resid < _DIRENT_DIRSIZ(dp)) {
984263bc
MD
387 idp->eofflag = 0;
388 return (-1);
389 }
390
391 if (idp->cookies) {
392 if (idp->ncookies <= 0) {
393 idp->eofflag = 0;
394 return (-1);
395 }
396
397 *idp->cookies++ = off;
398 --idp->ncookies;
399 }
400
01f31ab3 401 if ((error = uiomove((caddr_t) dp,_DIRENT_DIRSIZ(dp),idp->uio)) != 0)
984263bc
MD
402 return (error);
403 idp->uio_off = off;
404 return (0);
405}
406
407int
3fa8192b 408iso_shipdir(struct isoreaddir *idp)
984263bc
MD
409{
410 struct dirent *dp;
411 int cl, sl, assoc;
412 int error;
413 char *cname, *sname;
414
01f31ab3
JS
415 cl = idp->current.de.d_namlen;
416 cname = idp->current.de.d_name;
984263bc
MD
417assoc = (cl > 1) && (*cname == ASSOCCHAR);
418 if (assoc) {
419 cl--;
420 cname++;
421 }
422
01f31ab3 423 dp = &idp->saveent.de;
984263bc
MD
424 sname = dp->d_name;
425 if (!(sl = dp->d_namlen)) {
01f31ab3 426 dp = &idp->assocent.de;
984263bc
MD
427 sname = dp->d_name + 1;
428 sl = dp->d_namlen - 1;
429 }
430 if (sl > 0) {
431 if (sl != cl
432 || bcmp(sname,cname,sl)) {
01f31ab3
JS
433 if (idp->assocent.de.d_namlen) {
434 if ((error = iso_uiodir(idp,&idp->assocent.de,idp->assocoff)) != 0)
984263bc 435 return (error);
01f31ab3 436 idp->assocent.de.d_namlen = 0;
984263bc 437 }
01f31ab3
JS
438 if (idp->saveent.de.d_namlen) {
439 if ((error = iso_uiodir(idp,&idp->saveent.de,idp->saveoff)) != 0)
984263bc 440 return (error);
01f31ab3 441 idp->saveent.de.d_namlen = 0;
984263bc
MD
442 }
443 }
444 }
984263bc
MD
445 if (assoc) {
446 idp->assocoff = idp->curroff;
01f31ab3 447 bcopy(&idp->current,&idp->assocent,_DIRENT_DIRSIZ(&idp->current.de));
984263bc
MD
448 } else {
449 idp->saveoff = idp->curroff;
01f31ab3 450 bcopy(&idp->current,&idp->saveent,_DIRENT_DIRSIZ(&idp->current.de));
984263bc
MD
451 }
452 return (0);
453}
454
455/*
456 * Vnode op for readdir
3fa8192b
CP
457 *
458 * cd9660_readdir(struct vnode *a_vp, struct uio *a_uio, struct ucred *a_cred,
459 * int *a_eofflag, int *a_ncookies, u_long *a_cookies)
984263bc
MD
460 */
461static int
3fa8192b 462cd9660_readdir(struct vop_readdir_args *ap)
984263bc 463{
3a1b0fdc 464 struct uio *uio = ap->a_uio;
984263bc
MD
465 struct isoreaddir *idp;
466 struct vnode *vdp = ap->a_vp;
467 struct iso_node *dp;
468 struct iso_mnt *imp;
469 struct buf *bp = NULL;
470 struct iso_directory_record *ep;
471 int entryoffsetinblock;
472 doff_t endsearch;
473 u_long bmask;
474 int error = 0;
475 int reclen;
476 u_short namelen;
477 int ncookies = 0;
478 u_long *cookies = NULL;
479
480 dp = VTOI(vdp);
481 imp = dp->i_mnt;
482 bmask = imp->im_bmask;
483
484 MALLOC(idp, struct isoreaddir *, sizeof(*idp), M_TEMP, M_WAITOK);
01f31ab3 485 idp->saveent.de.d_namlen = idp->assocent.de.d_namlen = 0;
984263bc
MD
486 /*
487 * XXX
488 * Is it worth trying to figure out the type?
489 */
01f31ab3
JS
490 idp->saveent.de.d_type = DT_UNKNOWN;
491 idp->assocent.de.d_type = DT_UNKNOWN;
492 idp->current.de.d_type = DT_UNKNOWN;
984263bc
MD
493 idp->uio = uio;
494 if (ap->a_ncookies == NULL) {
495 idp->cookies = NULL;
496 } else {
497 /*
498 * Guess the number of cookies needed.
499 */
500 ncookies = uio->uio_resid / 16;
501 MALLOC(cookies, u_long *, ncookies * sizeof(u_int), M_TEMP,
502 M_WAITOK);
503 idp->cookies = cookies;
504 idp->ncookies = ncookies;
505 }
506 idp->eofflag = 1;
507 idp->curroff = uio->uio_offset;
508
509 if ((entryoffsetinblock = idp->curroff & bmask) &&
899483f5 510 (error = cd9660_devblkatoff(vdp, (off_t)idp->curroff, NULL, &bp))) {
984263bc
MD
511 FREE(idp, M_TEMP);
512 return (error);
513 }
514 endsearch = dp->i_size;
515
516 while (idp->curroff < endsearch) {
517 /*
518 * If offset is on a block boundary,
519 * read the next directory block.
520 * Release previous if it exists.
521 */
522 if ((idp->curroff & bmask) == 0) {
523 if (bp != NULL)
524 brelse(bp);
525 if ((error =
899483f5 526 cd9660_devblkatoff(vdp, (off_t)idp->curroff, NULL, &bp)) != 0)
984263bc
MD
527 break;
528 entryoffsetinblock = 0;
529 }
530 /*
531 * Get pointer to next entry.
532 */
533 ep = (struct iso_directory_record *)
534 ((char *)bp->b_data + entryoffsetinblock);
535
536 reclen = isonum_711(ep->length);
537 if (reclen == 0) {
538 /* skip to next block, if any */
539 idp->curroff =
540 (idp->curroff & ~bmask) + imp->logical_block_size;
541 continue;
542 }
543
544 if (reclen < ISO_DIRECTORY_RECORD_SIZE) {
545 error = EINVAL;
546 /* illegal entry, stop */
547 break;
548 }
549
550 if (entryoffsetinblock + reclen > imp->logical_block_size) {
551 error = EINVAL;
552 /* illegal directory, so stop looking */
553 break;
554 }
555
01f31ab3 556 idp->current.de.d_namlen = isonum_711(ep->name_len);
984263bc 557
01f31ab3 558 if (reclen < ISO_DIRECTORY_RECORD_SIZE + idp->current.de.d_namlen) {
984263bc
MD
559 error = EINVAL;
560 /* illegal entry, stop */
561 break;
562 }
563
564 if (isonum_711(ep->flags)&2)
01f31ab3 565 idp->current.de.d_ino = isodirino(ep, imp);
984263bc 566 else
899483f5 567 idp->current.de.d_ino = bp->b_bio1.bio_offset +
54078292 568 entryoffsetinblock;
984263bc
MD
569
570 idp->curroff += reclen;
571
572 switch (imp->iso_ftype) {
573 case ISO_FTYPE_RRIP:
f91a71dd 574 {
01f31ab3
JS
575 ino_t cur_fileno = idp->current.de.d_ino;
576 cd9660_rrip_getname(ep,idp->current.de.d_name, &namelen,
f91a71dd 577 &cur_fileno,imp);
01f31ab3
JS
578 idp->current.de.d_ino = cur_fileno;
579 idp->current.de.d_namlen = namelen;
580 if (idp->current.de.d_namlen)
581 error = iso_uiodir(idp,&idp->current.de,idp->curroff);
984263bc 582 break;
f91a71dd 583 }
984263bc 584 default: /* ISO_FTYPE_DEFAULT || ISO_FTYPE_9660 || ISO_FTYPE_HIGH_SIERRA*/
01f31ab3
JS
585 strcpy(idp->current.de.d_name,"..");
586 if (idp->current.de.d_namlen == 1 && ep->name[0] == 0) {
587 idp->current.de.d_namlen = 1;
588 error = iso_uiodir(idp,&idp->current.de,idp->curroff);
589 } else if (idp->current.de.d_namlen == 1 && ep->name[0] == 1) {
590 idp->current.de.d_namlen = 2;
591 error = iso_uiodir(idp,&idp->current.de,idp->curroff);
984263bc 592 } else {
01f31ab3
JS
593 isofntrans(ep->name,idp->current.de.d_namlen,
594 idp->current.de.d_name, &namelen,
984263bc
MD
595 imp->iso_ftype == ISO_FTYPE_9660,
596 isonum_711(ep->flags)&4,
597 imp->joliet_level);
01f31ab3 598 idp->current.de.d_namlen = namelen;
984263bc
MD
599 if (imp->iso_ftype == ISO_FTYPE_DEFAULT)
600 error = iso_shipdir(idp);
601 else
01f31ab3 602 error = iso_uiodir(idp,&idp->current.de,idp->curroff);
984263bc
MD
603 }
604 }
605 if (error)
606 break;
607
608 entryoffsetinblock += reclen;
609 }
610
611 if (!error && imp->iso_ftype == ISO_FTYPE_DEFAULT) {
01f31ab3 612 idp->current.de.d_namlen = 0;
984263bc
MD
613 error = iso_shipdir(idp);
614 }
615 if (error < 0)
616 error = 0;
617
618 if (ap->a_ncookies != NULL) {
619 if (error)
620 free(cookies, M_TEMP);
621 else {
622 /*
623 * Work out the number of cookies actually used.
624 */
625 *ap->a_ncookies = ncookies - idp->ncookies;
626 *ap->a_cookies = cookies;
627 }
628 }
629
630 if (bp)
631 brelse (bp);
632
633 uio->uio_offset = idp->uio_off;
634 *ap->a_eofflag = idp->eofflag;
635
636 FREE(idp, M_TEMP);
637
638 return (error);
639}
640
641/*
642 * Return target name of a symbolic link
643 * Shouldn't we get the parent vnode and read the data from there?
644 * This could eventually result in deadlocks in cd9660_lookup.
645 * But otherwise the block read here is in the block buffer two times.
646 */
647typedef struct iso_directory_record ISODIR;
648typedef struct iso_node ISONODE;
649typedef struct iso_mnt ISOMNT;
3fa8192b
CP
650/*
651 * cd9660_readlink(struct vnode *a_vp, struct uio *a_uio, struct ucred *a_cred)
652 */
984263bc 653static int
3fa8192b 654cd9660_readlink(struct vop_readlink_args *ap)
984263bc
MD
655{
656 ISONODE *ip;
657 ISODIR *dirp;
658 ISOMNT *imp;
659 struct buf *bp;
660 struct uio *uio;
661 u_short symlen;
662 int error;
663 char *symname;
664
665 ip = VTOI(ap->a_vp);
666 imp = ip->i_mnt;
667 uio = ap->a_uio;
668
669 if (imp->iso_ftype != ISO_FTYPE_RRIP)
670 return (EINVAL);
671
672 /*
673 * Get parents directory record block that this inode included.
674 */
675 error = bread(imp->im_devvp,
54078292 676 (off_t)ip->i_number & ~((1 << imp->im_bshift) - 1),
3b568787 677 imp->logical_block_size, &bp);
984263bc
MD
678 if (error) {
679 brelse(bp);
680 return (EINVAL);
681 }
682
683 /*
684 * Setup the directory pointer for this inode
685 */
686 dirp = (ISODIR *)(bp->b_data + (ip->i_number & imp->im_bmask));
687
688 /*
689 * Just make sure, we have a right one....
690 * 1: Check not cross boundary on block
691 */
692 if ((ip->i_number & imp->im_bmask) + isonum_711(dirp->length)
693 > (unsigned)imp->logical_block_size) {
694 brelse(bp);
695 return (EINVAL);
696 }
697
698 /*
699 * Now get a buffer
700 * Abuse a namei buffer for now.
701 */
702 if (uio->uio_segflg == UIO_SYSSPACE)
703 symname = uio->uio_iov->iov_base;
704 else
705 symname = zalloc(namei_zone);
706
707 /*
708 * Ok, we just gathering a symbolic name in SL record.
709 */
710 if (cd9660_rrip_getsymname(dirp, symname, &symlen, imp) == 0) {
711 if (uio->uio_segflg != UIO_SYSSPACE)
712 zfree(namei_zone, symname);
713 brelse(bp);
714 return (EINVAL);
715 }
716 /*
717 * Don't forget before you leave from home ;-)
718 */
719 brelse(bp);
720
721 /*
722 * return with the symbolic name to caller's.
723 */
724 if (uio->uio_segflg != UIO_SYSSPACE) {
725 error = uiomove(symname, symlen, uio);
726 zfree(namei_zone, symname);
727 return (error);
728 }
729 uio->uio_resid -= symlen;
730 uio->uio_iov->iov_base += symlen;
731 uio->uio_iov->iov_len -= symlen;
732 return (0);
733}
734
735/*
736 * Calculate the logical to physical mapping if not done already,
737 * then call the device strategy routine.
3fa8192b 738 *
81b5c339 739 * cd9660_strategy(struct buf *a_vp, struct buf *a_bio)
984263bc
MD
740 */
741static int
3fa8192b 742cd9660_strategy(struct vop_strategy_args *ap)
984263bc 743{
81b5c339
MD
744 struct bio *bio = ap->a_bio;
745 struct bio *nbio;
746 struct buf *bp = bio->bio_buf;
747 struct vnode *vp = ap->a_vp;
3a1b0fdc 748 struct iso_node *ip;
984263bc
MD
749 int error;
750
751 ip = VTOI(vp);
752 if (vp->v_type == VBLK || vp->v_type == VCHR)
753 panic("cd9660_strategy: spec");
81b5c339 754 nbio = push_bio(bio);
54078292
MD
755 if (nbio->bio_offset == NOOFFSET) {
756 error = VOP_BMAP(vp, bio->bio_offset, NULL,
757 &nbio->bio_offset, NULL, NULL);
81b5c339 758 if (error) {
984263bc
MD
759 bp->b_error = error;
760 bp->b_flags |= B_ERROR;
81b5c339
MD
761 /* I/O was never started on nbio, must biodone(bio) */
762 biodone(bio);
984263bc
MD
763 return (error);
764 }
54078292 765 if (nbio->bio_offset == NOOFFSET)
984263bc
MD
766 clrbuf(bp);
767 }
54078292 768 if (nbio->bio_offset == NOOFFSET) {
81b5c339
MD
769 /* I/O was never started on nbio, must biodone(bio) */
770 biodone(bio);
984263bc
MD
771 return (0);
772 }
773 vp = ip->i_devvp;
81b5c339 774 vn_strategy(vp, nbio);
984263bc
MD
775 return (0);
776}
777
778/*
779 * Print out the contents of an inode.
3fa8192b
CP
780 *
781 * cd9660_print(struct vnode *a_vp)
984263bc
MD
782 */
783static int
3fa8192b 784cd9660_print(struct vop_print_args *ap)
984263bc 785{
984263bc
MD
786 printf("tag VT_ISOFS, isofs vnode\n");
787 return (0);
788}
789
790/*
791 * Return POSIX pathconf information applicable to cd9660 filesystems.
3fa8192b
CP
792 *
793 * cd9660_pathconf(struct vnode *a_vp, int a_name, register_t *a_retval)
984263bc
MD
794 */
795static int
3fa8192b 796cd9660_pathconf(struct vop_pathconf_args *ap)
984263bc 797{
984263bc
MD
798 switch (ap->a_name) {
799 case _PC_LINK_MAX:
800 *ap->a_retval = 1;
801 return (0);
802 case _PC_NAME_MAX:
803 if (VTOI(ap->a_vp)->i_mnt->iso_ftype == ISO_FTYPE_RRIP)
804 *ap->a_retval = NAME_MAX;
805 else
806 *ap->a_retval = 37;
807 return (0);
808 case _PC_PATH_MAX:
809 *ap->a_retval = PATH_MAX;
810 return (0);
811 case _PC_PIPE_BUF:
812 *ap->a_retval = PIPE_BUF;
813 return (0);
814 case _PC_CHOWN_RESTRICTED:
815 *ap->a_retval = 1;
816 return (0);
817 case _PC_NO_TRUNC:
818 *ap->a_retval = 1;
819 return (0);
820 default:
821 return (EINVAL);
822 }
823 /* NOTREACHED */
824}
825
826/*
827 * get page routine
828 *
829 * XXX By default, wimp out... note that a_offset is ignored (and always
830 * XXX has been).
831 */
832int
3fa8192b 833cd9660_getpages(struct vop_getpages_args *ap)
984263bc
MD
834{
835 return vnode_pager_generic_getpages(ap->a_vp, ap->a_m, ap->a_count,
836 ap->a_reqpage);
837}
838
839/*
840 * put page routine
841 *
842 * XXX By default, wimp out... note that a_offset is ignored (and always
843 * XXX has been).
844 */
845int
3fa8192b 846cd9660_putpages(struct vop_putpages_args *ap)
984263bc
MD
847{
848 return vnode_pager_generic_putpages(ap->a_vp, ap->a_m, ap->a_count,
849 ap->a_sync, ap->a_rtvals);
850}
851
f308cd58
DR
852/*
853 * Advisory lock support
854 */
855static int
b1ce5639 856cd9660_advlock(struct vop_advlock_args *ap)
f308cd58
DR
857{
858 struct iso_node *ip = VTOI(ap->a_vp);
859 return (lf_advlock(ap, &(ip->i_lockf), ip->i_size));
860}
861
862
984263bc
MD
863/*
864 * Global vfs data structures for cd9660
865 */
0961aa92 866struct vnodeopv_entry_desc cd9660_vnodeop_entries[] = {
625ddaba 867 { &vop_default_desc, (vnodeopv_entry_t) vop_defaultop },
7540ab49 868 { &vop_open_desc, (vnodeopv_entry_t) cd9660_open},
625ddaba
JS
869 { &vop_access_desc, (vnodeopv_entry_t) cd9660_access },
870 { &vop_advlock_desc, (vnodeopv_entry_t) cd9660_advlock },
871 { &vop_bmap_desc, (vnodeopv_entry_t) cd9660_bmap },
e62afb5f 872 { &vop_old_lookup_desc, (vnodeopv_entry_t) cd9660_lookup },
625ddaba
JS
873 { &vop_getattr_desc, (vnodeopv_entry_t) cd9660_getattr },
874 { &vop_inactive_desc, (vnodeopv_entry_t) cd9660_inactive },
875 { &vop_ioctl_desc, (vnodeopv_entry_t) cd9660_ioctl },
876 { &vop_islocked_desc, (vnodeopv_entry_t) vop_stdislocked },
877 { &vop_lock_desc, (vnodeopv_entry_t) vop_stdlock },
878 { &vop_pathconf_desc, (vnodeopv_entry_t) cd9660_pathconf },
879 { &vop_print_desc, (vnodeopv_entry_t) cd9660_print },
880 { &vop_read_desc, (vnodeopv_entry_t) cd9660_read },
881 { &vop_readdir_desc, (vnodeopv_entry_t) cd9660_readdir },
882 { &vop_readlink_desc, (vnodeopv_entry_t) cd9660_readlink },
883 { &vop_reclaim_desc, (vnodeopv_entry_t) cd9660_reclaim },
884 { &vop_setattr_desc, (vnodeopv_entry_t) cd9660_setattr },
885 { &vop_strategy_desc, (vnodeopv_entry_t) cd9660_strategy },
886 { &vop_unlock_desc, (vnodeopv_entry_t) vop_stdunlock },
887 { &vop_getpages_desc, (vnodeopv_entry_t) cd9660_getpages },
888 { &vop_putpages_desc, (vnodeopv_entry_t) cd9660_putpages },
984263bc
MD
889 { NULL, NULL }
890};
984263bc
MD
891
892/*
893 * Special device vnode ops
894 */
0961aa92 895struct vnodeopv_entry_desc cd9660_specop_entries[] = {
625ddaba
JS
896 { &vop_default_desc, (vnodeopv_entry_t) spec_vnoperate },
897 { &vop_access_desc, (vnodeopv_entry_t) cd9660_access },
898 { &vop_getattr_desc, (vnodeopv_entry_t) cd9660_getattr },
899 { &vop_inactive_desc, (vnodeopv_entry_t) cd9660_inactive },
900 { &vop_islocked_desc, (vnodeopv_entry_t) vop_stdislocked },
901 { &vop_lock_desc, (vnodeopv_entry_t) vop_stdlock },
902 { &vop_print_desc, (vnodeopv_entry_t) cd9660_print },
903 { &vop_reclaim_desc, (vnodeopv_entry_t) cd9660_reclaim },
904 { &vop_setattr_desc, (vnodeopv_entry_t) cd9660_setattr },
905 { &vop_unlock_desc, (vnodeopv_entry_t) vop_stdunlock },
984263bc
MD
906 { NULL, NULL }
907};
984263bc 908
0961aa92 909struct vnodeopv_entry_desc cd9660_fifoop_entries[] = {
625ddaba
JS
910 { &vop_default_desc, (vnodeopv_entry_t) fifo_vnoperate },
911 { &vop_access_desc, (vnodeopv_entry_t) cd9660_access },
912 { &vop_getattr_desc, (vnodeopv_entry_t) cd9660_getattr },
913 { &vop_inactive_desc, (vnodeopv_entry_t) cd9660_inactive },
914 { &vop_islocked_desc, (vnodeopv_entry_t) vop_stdislocked },
915 { &vop_lock_desc, (vnodeopv_entry_t) vop_stdlock },
916 { &vop_print_desc, (vnodeopv_entry_t) cd9660_print },
917 { &vop_reclaim_desc, (vnodeopv_entry_t) cd9660_reclaim },
918 { &vop_setattr_desc, (vnodeopv_entry_t) cd9660_setattr },
919 { &vop_unlock_desc, (vnodeopv_entry_t) vop_stdunlock },
984263bc
MD
920 { NULL, NULL }
921};
984263bc 922