Adjust some comments with reality.
[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 $
b478fdce 40 * $DragonFly: src/sys/vfs/isofs/cd9660/cd9660_vnops.c,v 1.35 2007/08/08 00:12:51 swildner 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>
70aac194 58#include <sys/objcache.h>
984263bc
MD
59
60#include <vm/vm.h>
984263bc
MD
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 88 *
31bd717a
MD
89 * cd9660_setattr(struct vnode *a_vp, struct vattr *a_vap,
90 * 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 197/*
b478fdce 198 * cd9660_getattr(struct vnode *a_vp, struct vattr *a_vap)
3fa8192b 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;
0e9b9130
MD
217 vap->va_rmajor = umajor(ip->inode.iso_rdev);
218 vap->va_rminor = uminor(ip->inode.iso_rdev);
984263bc 219
6d7c7288 220 vap->va_size = (u_quad_t)(unsigned long)ip->i_size;
984263bc
MD
221 if (ip->i_size == 0 && (vap->va_mode & S_IFMT) == S_IFLNK) {
222 struct vop_readlink_args rdlnk;
223 struct iovec aiov;
224 struct uio auio;
225 char *cp;
226
227 MALLOC(cp, char *, MAXPATHLEN, M_TEMP, M_WAITOK);
228 aiov.iov_base = cp;
229 aiov.iov_len = MAXPATHLEN;
230 auio.uio_iov = &aiov;
231 auio.uio_iovcnt = 1;
232 auio.uio_offset = 0;
233 auio.uio_rw = UIO_READ;
234 auio.uio_segflg = UIO_SYSSPACE;
87de5057 235 auio.uio_td = curthread;
984263bc
MD
236 auio.uio_resid = MAXPATHLEN;
237 rdlnk.a_uio = &auio;
238 rdlnk.a_vp = ap->a_vp;
3b568787 239 rdlnk.a_cred = proc0.p_ucred; /* use root cred */
984263bc
MD
240 if (cd9660_readlink(&rdlnk) == 0)
241 vap->va_size = MAXPATHLEN - auio.uio_resid;
242 FREE(cp, M_TEMP);
243 }
244 vap->va_flags = 0;
245 vap->va_gen = 1;
246 vap->va_blocksize = ip->i_mnt->logical_block_size;
247 vap->va_bytes = (u_quad_t) ip->i_size;
248 vap->va_type = vp->v_type;
249 vap->va_filerev = 0;
250 return (0);
251}
252
253/*
254 * Vnode op for ioctl.
3fa8192b
CP
255 *
256 * cd9660_ioctl(struct vnode *a_vp, int a_command, caddr_t a_data,
257 * int a_fflag, struct ucred *a_cred, struct proc *a_p)
984263bc
MD
258 */
259static int
3fa8192b 260cd9660_ioctl(struct vop_ioctl_args *ap)
984263bc
MD
261{
262 struct vnode *vp = ap->a_vp;
263 struct iso_node *ip = VTOI(vp);
264
265 switch (ap->a_command) {
266
267 case FIOGETLBA:
268 *(int *)(ap->a_data) = ip->iso_start;
269 return 0;
270 default:
271 return (ENOTTY);
272 }
273}
274
7540ab49
MD
275/*
276 * open is called when the kernel intends to read or memory map a vnode.
277 */
278static int
279cd9660_open(struct vop_open_args *ap)
280{
8ddc6004 281 return(vop_stdopen(ap));
7540ab49
MD
282}
283
984263bc
MD
284/*
285 * Vnode op for reading.
3fa8192b
CP
286 *
287 * cd9660_read(struct vnode *a_vp, struct uio *a_uio, int a_ioflag,
288 * struct ucred *a_cred)
984263bc
MD
289 */
290static int
3fa8192b 291cd9660_read(struct vop_read_args *ap)
984263bc
MD
292{
293 struct vnode *vp = ap->a_vp;
3a1b0fdc
RG
294 struct uio *uio = ap->a_uio;
295 struct iso_node *ip = VTOI(vp);
296 struct iso_mnt *imp;
984263bc
MD
297 struct buf *bp;
298 daddr_t lbn, rablock;
54078292
MD
299 off_t raoffset;
300 off_t loffset;
984263bc
MD
301 off_t diff;
302 int rasize, error = 0;
303 int seqcount;
304 long size, n, on;
305
306 seqcount = ap->a_ioflag >> 16;
307
308 if (uio->uio_resid == 0)
309 return (0);
310 if (uio->uio_offset < 0)
311 return (EINVAL);
312 ip->i_flag |= IN_ACCESS;
313 imp = ip->i_mnt;
314 do {
315 lbn = lblkno(imp, uio->uio_offset);
54078292 316 loffset = lblktooff(imp, lbn);
984263bc
MD
317 on = blkoff(imp, uio->uio_offset);
318 n = min((u_int)(imp->logical_block_size - on),
319 uio->uio_resid);
320 diff = (off_t)ip->i_size - uio->uio_offset;
321 if (diff <= 0)
322 return (0);
323 if (diff < n)
324 n = diff;
325 size = blksize(imp, ip, lbn);
326 rablock = lbn + 1;
54078292 327 raoffset = lblktooff(imp, rablock);
984263bc 328 if ((vp->v_mount->mnt_flag & MNT_NOCLUSTERR) == 0) {
54078292 329 if (raoffset < ip->i_size)
984263bc 330 error = cluster_read(vp, (off_t)ip->i_size,
54078292
MD
331 loffset, size,
332 uio->uio_resid,
984263bc
MD
333 (ap->a_ioflag >> 16), &bp);
334 else
54078292 335 error = bread(vp, loffset, size, &bp);
984263bc
MD
336 } else {
337 if (seqcount > 1 &&
338 lblktosize(imp, rablock) < ip->i_size) {
339 rasize = blksize(imp, ip, rablock);
54078292 340 error = breadn(vp, loffset, size, &raoffset,
3b568787 341 &rasize, 1, &bp);
984263bc 342 } else
54078292 343 error = bread(vp, loffset, size, &bp);
984263bc
MD
344 }
345 n = min(n, size - bp->b_resid);
346 if (error) {
347 brelse(bp);
348 return (error);
349 }
350
351 error = uiomove(bp->b_data + on, (int)n, uio);
352 brelse(bp);
353 } while (error == 0 && uio->uio_resid > 0 && n != 0);
354 return (error);
355}
356
01f31ab3
JS
357/* struct dirent + enough space for the maximum supported size */
358struct iso_dirent {
359 struct dirent de;
360 char de_name[_DIRENT_RECLEN(NAME_MAX) - sizeof(struct dirent)];
361};
362
984263bc
MD
363/*
364 * Structure for reading directories
365 */
366struct isoreaddir {
01f31ab3
JS
367 struct iso_dirent saveent;
368 struct iso_dirent assocent;
369 struct iso_dirent current;
984263bc
MD
370 off_t saveoff;
371 off_t assocoff;
372 off_t curroff;
373 struct uio *uio;
374 off_t uio_off;
375 int eofflag;
376 u_long *cookies;
377 int ncookies;
378};
379
380int
3fa8192b 381iso_uiodir(struct isoreaddir *idp, struct dirent *dp, off_t off)
984263bc
MD
382{
383 int error;
384
385 dp->d_name[dp->d_namlen] = 0;
984263bc 386
01f31ab3 387 if (idp->uio->uio_resid < _DIRENT_DIRSIZ(dp)) {
984263bc
MD
388 idp->eofflag = 0;
389 return (-1);
390 }
391
392 if (idp->cookies) {
393 if (idp->ncookies <= 0) {
394 idp->eofflag = 0;
395 return (-1);
396 }
397
398 *idp->cookies++ = off;
399 --idp->ncookies;
400 }
401
01f31ab3 402 if ((error = uiomove((caddr_t) dp,_DIRENT_DIRSIZ(dp),idp->uio)) != 0)
984263bc
MD
403 return (error);
404 idp->uio_off = off;
405 return (0);
406}
407
408int
3fa8192b 409iso_shipdir(struct isoreaddir *idp)
984263bc
MD
410{
411 struct dirent *dp;
412 int cl, sl, assoc;
413 int error;
414 char *cname, *sname;
415
01f31ab3
JS
416 cl = idp->current.de.d_namlen;
417 cname = idp->current.de.d_name;
984263bc
MD
418assoc = (cl > 1) && (*cname == ASSOCCHAR);
419 if (assoc) {
420 cl--;
421 cname++;
422 }
423
01f31ab3 424 dp = &idp->saveent.de;
984263bc
MD
425 sname = dp->d_name;
426 if (!(sl = dp->d_namlen)) {
01f31ab3 427 dp = &idp->assocent.de;
984263bc
MD
428 sname = dp->d_name + 1;
429 sl = dp->d_namlen - 1;
430 }
431 if (sl > 0) {
432 if (sl != cl
433 || bcmp(sname,cname,sl)) {
01f31ab3
JS
434 if (idp->assocent.de.d_namlen) {
435 if ((error = iso_uiodir(idp,&idp->assocent.de,idp->assocoff)) != 0)
984263bc 436 return (error);
01f31ab3 437 idp->assocent.de.d_namlen = 0;
984263bc 438 }
01f31ab3
JS
439 if (idp->saveent.de.d_namlen) {
440 if ((error = iso_uiodir(idp,&idp->saveent.de,idp->saveoff)) != 0)
984263bc 441 return (error);
01f31ab3 442 idp->saveent.de.d_namlen = 0;
984263bc
MD
443 }
444 }
445 }
984263bc
MD
446 if (assoc) {
447 idp->assocoff = idp->curroff;
01f31ab3 448 bcopy(&idp->current,&idp->assocent,_DIRENT_DIRSIZ(&idp->current.de));
984263bc
MD
449 } else {
450 idp->saveoff = idp->curroff;
01f31ab3 451 bcopy(&idp->current,&idp->saveent,_DIRENT_DIRSIZ(&idp->current.de));
984263bc
MD
452 }
453 return (0);
454}
455
456/*
457 * Vnode op for readdir
3fa8192b
CP
458 *
459 * cd9660_readdir(struct vnode *a_vp, struct uio *a_uio, struct ucred *a_cred,
460 * int *a_eofflag, int *a_ncookies, u_long *a_cookies)
984263bc
MD
461 */
462static int
3fa8192b 463cd9660_readdir(struct vop_readdir_args *ap)
984263bc 464{
3a1b0fdc 465 struct uio *uio = ap->a_uio;
984263bc
MD
466 struct isoreaddir *idp;
467 struct vnode *vdp = ap->a_vp;
468 struct iso_node *dp;
469 struct iso_mnt *imp;
470 struct buf *bp = NULL;
471 struct iso_directory_record *ep;
472 int entryoffsetinblock;
473 doff_t endsearch;
474 u_long bmask;
475 int error = 0;
476 int reclen;
477 u_short namelen;
478 int ncookies = 0;
479 u_long *cookies = NULL;
480
481 dp = VTOI(vdp);
482 imp = dp->i_mnt;
483 bmask = imp->im_bmask;
484
885ecb13
MD
485 if ((error = vn_lock(vdp, LK_EXCLUSIVE|LK_RETRY)) != 0)
486 return (error);
487
984263bc 488 MALLOC(idp, struct isoreaddir *, sizeof(*idp), M_TEMP, M_WAITOK);
01f31ab3 489 idp->saveent.de.d_namlen = idp->assocent.de.d_namlen = 0;
984263bc
MD
490 /*
491 * XXX
492 * Is it worth trying to figure out the type?
493 */
01f31ab3
JS
494 idp->saveent.de.d_type = DT_UNKNOWN;
495 idp->assocent.de.d_type = DT_UNKNOWN;
496 idp->current.de.d_type = DT_UNKNOWN;
984263bc
MD
497 idp->uio = uio;
498 if (ap->a_ncookies == NULL) {
499 idp->cookies = NULL;
500 } else {
501 /*
fb0466c9
MD
502 * Guess the number of cookies needed. Guess at least
503 * 1 to avoid a degenerate case in malloc, and cap at
504 * a reasonable limit.
984263bc 505 */
fb0466c9
MD
506 ncookies = uio->uio_resid / 16 + 1;
507 if (ncookies > 1024)
508 ncookies = 1024;
509 MALLOC(cookies, u_long *, ncookies * sizeof(u_int),
510 M_TEMP, M_WAITOK);
984263bc
MD
511 idp->cookies = cookies;
512 idp->ncookies = ncookies;
513 }
514 idp->eofflag = 1;
515 idp->curroff = uio->uio_offset;
516
517 if ((entryoffsetinblock = idp->curroff & bmask) &&
899483f5 518 (error = cd9660_devblkatoff(vdp, (off_t)idp->curroff, NULL, &bp))) {
984263bc 519 FREE(idp, M_TEMP);
885ecb13 520 goto done;
984263bc
MD
521 }
522 endsearch = dp->i_size;
523
524 while (idp->curroff < endsearch) {
525 /*
526 * If offset is on a block boundary,
527 * read the next directory block.
528 * Release previous if it exists.
529 */
530 if ((idp->curroff & bmask) == 0) {
531 if (bp != NULL)
532 brelse(bp);
533 if ((error =
899483f5 534 cd9660_devblkatoff(vdp, (off_t)idp->curroff, NULL, &bp)) != 0)
984263bc
MD
535 break;
536 entryoffsetinblock = 0;
537 }
538 /*
539 * Get pointer to next entry.
540 */
541 ep = (struct iso_directory_record *)
542 ((char *)bp->b_data + entryoffsetinblock);
543
544 reclen = isonum_711(ep->length);
545 if (reclen == 0) {
546 /* skip to next block, if any */
547 idp->curroff =
548 (idp->curroff & ~bmask) + imp->logical_block_size;
549 continue;
550 }
551
552 if (reclen < ISO_DIRECTORY_RECORD_SIZE) {
553 error = EINVAL;
554 /* illegal entry, stop */
555 break;
556 }
557
558 if (entryoffsetinblock + reclen > imp->logical_block_size) {
559 error = EINVAL;
560 /* illegal directory, so stop looking */
561 break;
562 }
563
01f31ab3 564 idp->current.de.d_namlen = isonum_711(ep->name_len);
984263bc 565
01f31ab3 566 if (reclen < ISO_DIRECTORY_RECORD_SIZE + idp->current.de.d_namlen) {
984263bc
MD
567 error = EINVAL;
568 /* illegal entry, stop */
569 break;
570 }
571
572 if (isonum_711(ep->flags)&2)
01f31ab3 573 idp->current.de.d_ino = isodirino(ep, imp);
984263bc 574 else
899483f5 575 idp->current.de.d_ino = bp->b_bio1.bio_offset +
54078292 576 entryoffsetinblock;
984263bc
MD
577
578 idp->curroff += reclen;
579
580 switch (imp->iso_ftype) {
581 case ISO_FTYPE_RRIP:
f91a71dd 582 {
01f31ab3
JS
583 ino_t cur_fileno = idp->current.de.d_ino;
584 cd9660_rrip_getname(ep,idp->current.de.d_name, &namelen,
f91a71dd 585 &cur_fileno,imp);
01f31ab3
JS
586 idp->current.de.d_ino = cur_fileno;
587 idp->current.de.d_namlen = namelen;
588 if (idp->current.de.d_namlen)
589 error = iso_uiodir(idp,&idp->current.de,idp->curroff);
984263bc 590 break;
f91a71dd 591 }
984263bc 592 default: /* ISO_FTYPE_DEFAULT || ISO_FTYPE_9660 || ISO_FTYPE_HIGH_SIERRA*/
01f31ab3
JS
593 strcpy(idp->current.de.d_name,"..");
594 if (idp->current.de.d_namlen == 1 && ep->name[0] == 0) {
595 idp->current.de.d_namlen = 1;
596 error = iso_uiodir(idp,&idp->current.de,idp->curroff);
597 } else if (idp->current.de.d_namlen == 1 && ep->name[0] == 1) {
598 idp->current.de.d_namlen = 2;
599 error = iso_uiodir(idp,&idp->current.de,idp->curroff);
984263bc 600 } else {
01f31ab3
JS
601 isofntrans(ep->name,idp->current.de.d_namlen,
602 idp->current.de.d_name, &namelen,
984263bc
MD
603 imp->iso_ftype == ISO_FTYPE_9660,
604 isonum_711(ep->flags)&4,
605 imp->joliet_level);
01f31ab3 606 idp->current.de.d_namlen = namelen;
984263bc
MD
607 if (imp->iso_ftype == ISO_FTYPE_DEFAULT)
608 error = iso_shipdir(idp);
609 else
01f31ab3 610 error = iso_uiodir(idp,&idp->current.de,idp->curroff);
984263bc
MD
611 }
612 }
613 if (error)
614 break;
615
616 entryoffsetinblock += reclen;
617 }
618
619 if (!error && imp->iso_ftype == ISO_FTYPE_DEFAULT) {
01f31ab3 620 idp->current.de.d_namlen = 0;
984263bc
MD
621 error = iso_shipdir(idp);
622 }
623 if (error < 0)
624 error = 0;
625
626 if (ap->a_ncookies != NULL) {
627 if (error)
efda3bd0 628 kfree(cookies, M_TEMP);
984263bc
MD
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
885ecb13
MD
646done:
647 vn_unlock(vdp);
984263bc
MD
648 return (error);
649}
650
651/*
652 * Return target name of a symbolic link
653 * Shouldn't we get the parent vnode and read the data from there?
654 * This could eventually result in deadlocks in cd9660_lookup.
655 * But otherwise the block read here is in the block buffer two times.
656 */
657typedef struct iso_directory_record ISODIR;
658typedef struct iso_node ISONODE;
659typedef struct iso_mnt ISOMNT;
3fa8192b
CP
660/*
661 * cd9660_readlink(struct vnode *a_vp, struct uio *a_uio, struct ucred *a_cred)
662 */
984263bc 663static int
3fa8192b 664cd9660_readlink(struct vop_readlink_args *ap)
984263bc
MD
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,
54078292 686 (off_t)ip->i_number & ~((1 << imp->im_bshift) - 1),
3b568787 687 imp->logical_block_size, &bp);
984263bc
MD
688 if (error) {
689 brelse(bp);
690 return (EINVAL);
691 }
692
693 /*
694 * Setup the directory pointer for this inode
695 */
696 dirp = (ISODIR *)(bp->b_data + (ip->i_number & imp->im_bmask));
697
698 /*
699 * Just make sure, we have a right one....
700 * 1: Check not cross boundary on block
701 */
702 if ((ip->i_number & imp->im_bmask) + isonum_711(dirp->length)
703 > (unsigned)imp->logical_block_size) {
704 brelse(bp);
705 return (EINVAL);
706 }
707
708 /*
709 * Now get a buffer
710 * Abuse a namei buffer for now.
711 */
712 if (uio->uio_segflg == UIO_SYSSPACE)
713 symname = uio->uio_iov->iov_base;
714 else
70aac194 715 symname = objcache_get(namei_oc, M_WAITOK);
984263bc
MD
716
717 /*
718 * Ok, we just gathering a symbolic name in SL record.
719 */
720 if (cd9660_rrip_getsymname(dirp, symname, &symlen, imp) == 0) {
721 if (uio->uio_segflg != UIO_SYSSPACE)
70aac194 722 objcache_put(namei_oc, symname);
984263bc
MD
723 brelse(bp);
724 return (EINVAL);
725 }
726 /*
727 * Don't forget before you leave from home ;-)
728 */
729 brelse(bp);
730
731 /*
732 * return with the symbolic name to caller's.
733 */
734 if (uio->uio_segflg != UIO_SYSSPACE) {
735 error = uiomove(symname, symlen, uio);
70aac194 736 objcache_put(namei_oc, symname);
984263bc
MD
737 return (error);
738 }
739 uio->uio_resid -= symlen;
740 uio->uio_iov->iov_base += symlen;
741 uio->uio_iov->iov_len -= symlen;
742 return (0);
743}
744
745/*
746 * Calculate the logical to physical mapping if not done already,
747 * then call the device strategy routine.
3fa8192b 748 *
81b5c339 749 * cd9660_strategy(struct buf *a_vp, struct buf *a_bio)
984263bc
MD
750 */
751static int
3fa8192b 752cd9660_strategy(struct vop_strategy_args *ap)
984263bc 753{
81b5c339
MD
754 struct bio *bio = ap->a_bio;
755 struct bio *nbio;
756 struct buf *bp = bio->bio_buf;
757 struct vnode *vp = ap->a_vp;
3a1b0fdc 758 struct iso_node *ip;
984263bc
MD
759 int error;
760
761 ip = VTOI(vp);
762 if (vp->v_type == VBLK || vp->v_type == VCHR)
763 panic("cd9660_strategy: spec");
81b5c339 764 nbio = push_bio(bio);
54078292
MD
765 if (nbio->bio_offset == NOOFFSET) {
766 error = VOP_BMAP(vp, bio->bio_offset, NULL,
767 &nbio->bio_offset, NULL, NULL);
81b5c339 768 if (error) {
984263bc
MD
769 bp->b_error = error;
770 bp->b_flags |= B_ERROR;
81b5c339
MD
771 /* I/O was never started on nbio, must biodone(bio) */
772 biodone(bio);
984263bc
MD
773 return (error);
774 }
54078292 775 if (nbio->bio_offset == NOOFFSET)
984263bc
MD
776 clrbuf(bp);
777 }
54078292 778 if (nbio->bio_offset == NOOFFSET) {
81b5c339
MD
779 /* I/O was never started on nbio, must biodone(bio) */
780 biodone(bio);
984263bc
MD
781 return (0);
782 }
783 vp = ip->i_devvp;
81b5c339 784 vn_strategy(vp, nbio);
984263bc
MD
785 return (0);
786}
787
788/*
789 * Print out the contents of an inode.
3fa8192b
CP
790 *
791 * cd9660_print(struct vnode *a_vp)
984263bc
MD
792 */
793static int
3fa8192b 794cd9660_print(struct vop_print_args *ap)
984263bc 795{
086c1d7e 796 kprintf("tag VT_ISOFS, isofs vnode\n");
984263bc
MD
797 return (0);
798}
799
800/*
801 * Return POSIX pathconf information applicable to cd9660 filesystems.
3fa8192b
CP
802 *
803 * cd9660_pathconf(struct vnode *a_vp, int a_name, register_t *a_retval)
984263bc
MD
804 */
805static int
3fa8192b 806cd9660_pathconf(struct vop_pathconf_args *ap)
984263bc 807{
984263bc
MD
808 switch (ap->a_name) {
809 case _PC_LINK_MAX:
810 *ap->a_retval = 1;
811 return (0);
812 case _PC_NAME_MAX:
813 if (VTOI(ap->a_vp)->i_mnt->iso_ftype == ISO_FTYPE_RRIP)
814 *ap->a_retval = NAME_MAX;
815 else
816 *ap->a_retval = 37;
817 return (0);
818 case _PC_PATH_MAX:
819 *ap->a_retval = PATH_MAX;
820 return (0);
821 case _PC_PIPE_BUF:
822 *ap->a_retval = PIPE_BUF;
823 return (0);
824 case _PC_CHOWN_RESTRICTED:
825 *ap->a_retval = 1;
826 return (0);
827 case _PC_NO_TRUNC:
828 *ap->a_retval = 1;
829 return (0);
830 default:
831 return (EINVAL);
832 }
833 /* NOTREACHED */
834}
835
836/*
837 * get page routine
838 *
839 * XXX By default, wimp out... note that a_offset is ignored (and always
840 * XXX has been).
841 */
842int
3fa8192b 843cd9660_getpages(struct vop_getpages_args *ap)
984263bc
MD
844{
845 return vnode_pager_generic_getpages(ap->a_vp, ap->a_m, ap->a_count,
846 ap->a_reqpage);
847}
848
849/*
850 * put page routine
851 *
852 * XXX By default, wimp out... note that a_offset is ignored (and always
853 * XXX has been).
854 */
855int
3fa8192b 856cd9660_putpages(struct vop_putpages_args *ap)
984263bc
MD
857{
858 return vnode_pager_generic_putpages(ap->a_vp, ap->a_m, ap->a_count,
859 ap->a_sync, ap->a_rtvals);
860}
861
f308cd58
DR
862/*
863 * Advisory lock support
864 */
865static int
b1ce5639 866cd9660_advlock(struct vop_advlock_args *ap)
f308cd58
DR
867{
868 struct iso_node *ip = VTOI(ap->a_vp);
869 return (lf_advlock(ap, &(ip->i_lockf), ip->i_size));
870}
871
872
984263bc
MD
873/*
874 * Global vfs data structures for cd9660
875 */
66a1ddf5
MD
876struct vop_ops cd9660_vnode_vops = {
877 .vop_default = vop_defaultop,
878 .vop_open = cd9660_open,
879 .vop_access = cd9660_access,
880 .vop_advlock = cd9660_advlock,
881 .vop_bmap = cd9660_bmap,
882 .vop_old_lookup = cd9660_lookup,
883 .vop_getattr = cd9660_getattr,
884 .vop_inactive = cd9660_inactive,
885 .vop_ioctl = cd9660_ioctl,
66a1ddf5
MD
886 .vop_pathconf = cd9660_pathconf,
887 .vop_print = cd9660_print,
888 .vop_read = cd9660_read,
889 .vop_readdir = cd9660_readdir,
890 .vop_readlink = cd9660_readlink,
891 .vop_reclaim = cd9660_reclaim,
892 .vop_setattr = cd9660_setattr,
893 .vop_strategy = cd9660_strategy,
66a1ddf5
MD
894 .vop_getpages = cd9660_getpages,
895 .vop_putpages = cd9660_putpages
984263bc 896};
984263bc
MD
897
898/*
899 * Special device vnode ops
900 */
66a1ddf5
MD
901struct vop_ops cd9660_spec_vops = {
902 .vop_default = spec_vnoperate,
903 .vop_access = cd9660_access,
904 .vop_getattr = cd9660_getattr,
905 .vop_inactive = cd9660_inactive,
66a1ddf5
MD
906 .vop_print = cd9660_print,
907 .vop_reclaim = cd9660_reclaim,
908 .vop_setattr = cd9660_setattr,
984263bc 909};
984263bc 910
66a1ddf5
MD
911struct vop_ops cd9660_fifo_vops = {
912 .vop_default = fifo_vnoperate,
913 .vop_access = cd9660_access,
914 .vop_getattr = cd9660_getattr,
915 .vop_inactive = cd9660_inactive,
66a1ddf5
MD
916 .vop_print = cd9660_print,
917 .vop_reclaim = cd9660_reclaim,
918 .vop_setattr = cd9660_setattr,
984263bc 919};
984263bc 920