cd9660_vfsops.c revision 1.1.2.2 1 1.1.2.2 thorpej /* $NetBSD: cd9660_vfsops.c,v 1.1.2.2 2002/12/29 19:55:40 thorpej Exp $ */
2 1.1.2.2 thorpej
3 1.1.2.2 thorpej /*-
4 1.1.2.2 thorpej * Copyright (c) 1994
5 1.1.2.2 thorpej * The Regents of the University of California. All rights reserved.
6 1.1.2.2 thorpej *
7 1.1.2.2 thorpej * This code is derived from software contributed to Berkeley
8 1.1.2.2 thorpej * by Pace Willisson (pace (at) blitz.com). The Rock Ridge Extension
9 1.1.2.2 thorpej * Support code is derived from software contributed to Berkeley
10 1.1.2.2 thorpej * by Atsushi Murai (amurai (at) spec.co.jp).
11 1.1.2.2 thorpej *
12 1.1.2.2 thorpej * Redistribution and use in source and binary forms, with or without
13 1.1.2.2 thorpej * modification, are permitted provided that the following conditions
14 1.1.2.2 thorpej * are met:
15 1.1.2.2 thorpej * 1. Redistributions of source code must retain the above copyright
16 1.1.2.2 thorpej * notice, this list of conditions and the following disclaimer.
17 1.1.2.2 thorpej * 2. Redistributions in binary form must reproduce the above copyright
18 1.1.2.2 thorpej * notice, this list of conditions and the following disclaimer in the
19 1.1.2.2 thorpej * documentation and/or other materials provided with the distribution.
20 1.1.2.2 thorpej * 3. All advertising materials mentioning features or use of this software
21 1.1.2.2 thorpej * must display the following acknowledgement:
22 1.1.2.2 thorpej * This product includes software developed by the University of
23 1.1.2.2 thorpej * California, Berkeley and its contributors.
24 1.1.2.2 thorpej * 4. Neither the name of the University nor the names of its contributors
25 1.1.2.2 thorpej * may be used to endorse or promote products derived from this software
26 1.1.2.2 thorpej * without specific prior written permission.
27 1.1.2.2 thorpej *
28 1.1.2.2 thorpej * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
29 1.1.2.2 thorpej * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
30 1.1.2.2 thorpej * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
31 1.1.2.2 thorpej * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
32 1.1.2.2 thorpej * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
33 1.1.2.2 thorpej * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
34 1.1.2.2 thorpej * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
35 1.1.2.2 thorpej * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
36 1.1.2.2 thorpej * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
37 1.1.2.2 thorpej * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
38 1.1.2.2 thorpej * SUCH DAMAGE.
39 1.1.2.2 thorpej *
40 1.1.2.2 thorpej * @(#)cd9660_vfsops.c 8.18 (Berkeley) 5/22/95
41 1.1.2.2 thorpej */
42 1.1.2.2 thorpej
43 1.1.2.2 thorpej #include <sys/cdefs.h>
44 1.1.2.2 thorpej __KERNEL_RCSID(0, "$NetBSD: cd9660_vfsops.c,v 1.1.2.2 2002/12/29 19:55:40 thorpej Exp $");
45 1.1.2.2 thorpej
46 1.1.2.2 thorpej #if defined(_KERNEL_OPT)
47 1.1.2.2 thorpej #include "opt_compat_netbsd.h"
48 1.1.2.2 thorpej #endif
49 1.1.2.2 thorpej
50 1.1.2.2 thorpej #include <sys/param.h>
51 1.1.2.2 thorpej #include <sys/systm.h>
52 1.1.2.2 thorpej #include <sys/namei.h>
53 1.1.2.2 thorpej #include <sys/proc.h>
54 1.1.2.2 thorpej #include <sys/kernel.h>
55 1.1.2.2 thorpej #include <sys/vnode.h>
56 1.1.2.2 thorpej #include <miscfs/specfs/specdev.h>
57 1.1.2.2 thorpej #include <sys/mount.h>
58 1.1.2.2 thorpej #include <sys/buf.h>
59 1.1.2.2 thorpej #include <sys/file.h>
60 1.1.2.2 thorpej #include <sys/disklabel.h>
61 1.1.2.2 thorpej #include <sys/device.h>
62 1.1.2.2 thorpej #include <sys/ioctl.h>
63 1.1.2.2 thorpej #include <sys/cdio.h>
64 1.1.2.2 thorpej #include <sys/errno.h>
65 1.1.2.2 thorpej #include <sys/malloc.h>
66 1.1.2.2 thorpej #include <sys/pool.h>
67 1.1.2.2 thorpej #include <sys/stat.h>
68 1.1.2.2 thorpej #include <sys/conf.h>
69 1.1.2.2 thorpej
70 1.1.2.2 thorpej #include <fs/cd9660/iso.h>
71 1.1.2.2 thorpej #include <fs/cd9660/cd9660_extern.h>
72 1.1.2.2 thorpej #include <fs/cd9660/iso_rrip.h>
73 1.1.2.2 thorpej #include <fs/cd9660/cd9660_node.h>
74 1.1.2.2 thorpej #include <fs/cd9660/cd9660_mount.h>
75 1.1.2.2 thorpej
76 1.1.2.2 thorpej extern const struct vnodeopv_desc cd9660_vnodeop_opv_desc;
77 1.1.2.2 thorpej extern const struct vnodeopv_desc cd9660_specop_opv_desc;
78 1.1.2.2 thorpej extern const struct vnodeopv_desc cd9660_fifoop_opv_desc;
79 1.1.2.2 thorpej
80 1.1.2.2 thorpej const struct vnodeopv_desc * const cd9660_vnodeopv_descs[] = {
81 1.1.2.2 thorpej &cd9660_vnodeop_opv_desc,
82 1.1.2.2 thorpej &cd9660_specop_opv_desc,
83 1.1.2.2 thorpej &cd9660_fifoop_opv_desc,
84 1.1.2.2 thorpej NULL,
85 1.1.2.2 thorpej };
86 1.1.2.2 thorpej
87 1.1.2.2 thorpej struct vfsops cd9660_vfsops = {
88 1.1.2.2 thorpej MOUNT_CD9660,
89 1.1.2.2 thorpej cd9660_mount,
90 1.1.2.2 thorpej cd9660_start,
91 1.1.2.2 thorpej cd9660_unmount,
92 1.1.2.2 thorpej cd9660_root,
93 1.1.2.2 thorpej cd9660_quotactl,
94 1.1.2.2 thorpej cd9660_statfs,
95 1.1.2.2 thorpej cd9660_sync,
96 1.1.2.2 thorpej cd9660_vget,
97 1.1.2.2 thorpej cd9660_fhtovp,
98 1.1.2.2 thorpej cd9660_vptofh,
99 1.1.2.2 thorpej cd9660_init,
100 1.1.2.2 thorpej cd9660_reinit,
101 1.1.2.2 thorpej cd9660_done,
102 1.1.2.2 thorpej cd9660_sysctl,
103 1.1.2.2 thorpej cd9660_mountroot,
104 1.1.2.2 thorpej cd9660_check_export,
105 1.1.2.2 thorpej cd9660_vnodeopv_descs,
106 1.1.2.2 thorpej };
107 1.1.2.2 thorpej
108 1.1.2.2 thorpej struct genfs_ops cd9660_genfsops = {
109 1.1.2.2 thorpej genfs_size,
110 1.1.2.2 thorpej };
111 1.1.2.2 thorpej
112 1.1.2.2 thorpej /*
113 1.1.2.2 thorpej * Called by vfs_mountroot when iso is going to be mounted as root.
114 1.1.2.2 thorpej *
115 1.1.2.2 thorpej * Name is updated by mount(8) after booting.
116 1.1.2.2 thorpej */
117 1.1.2.2 thorpej #define ROOTNAME "root_device"
118 1.1.2.2 thorpej
119 1.1.2.2 thorpej static int iso_makemp __P((struct iso_mnt *isomp, struct buf *bp, int *ea_len));
120 1.1.2.2 thorpej static int iso_mountfs __P((struct vnode *devvp, struct mount *mp,
121 1.1.2.2 thorpej struct proc *p, struct iso_args *argp));
122 1.1.2.2 thorpej
123 1.1.2.2 thorpej int
124 1.1.2.2 thorpej cd9660_mountroot()
125 1.1.2.2 thorpej {
126 1.1.2.2 thorpej struct mount *mp;
127 1.1.2.2 thorpej struct proc *p = curproc; /* XXX */
128 1.1.2.2 thorpej int error;
129 1.1.2.2 thorpej struct iso_args args;
130 1.1.2.2 thorpej
131 1.1.2.2 thorpej if (root_device->dv_class != DV_DISK)
132 1.1.2.2 thorpej return (ENODEV);
133 1.1.2.2 thorpej
134 1.1.2.2 thorpej /*
135 1.1.2.2 thorpej * Get vnodes for swapdev and rootdev.
136 1.1.2.2 thorpej */
137 1.1.2.2 thorpej if (bdevvp(rootdev, &rootvp))
138 1.1.2.2 thorpej panic("cd9660_mountroot: can't setup rootvp");
139 1.1.2.2 thorpej
140 1.1.2.2 thorpej if ((error = vfs_rootmountalloc(MOUNT_CD9660, "root_device", &mp))
141 1.1.2.2 thorpej != 0) {
142 1.1.2.2 thorpej vrele(rootvp);
143 1.1.2.2 thorpej return (error);
144 1.1.2.2 thorpej }
145 1.1.2.2 thorpej
146 1.1.2.2 thorpej args.flags = ISOFSMNT_ROOT;
147 1.1.2.2 thorpej if ((error = iso_mountfs(rootvp, mp, p, &args)) != 0) {
148 1.1.2.2 thorpej mp->mnt_op->vfs_refcount--;
149 1.1.2.2 thorpej vfs_unbusy(mp);
150 1.1.2.2 thorpej free(mp, M_MOUNT);
151 1.1.2.2 thorpej vrele(rootvp);
152 1.1.2.2 thorpej return (error);
153 1.1.2.2 thorpej }
154 1.1.2.2 thorpej simple_lock(&mountlist_slock);
155 1.1.2.2 thorpej CIRCLEQ_INSERT_TAIL(&mountlist, mp, mnt_list);
156 1.1.2.2 thorpej simple_unlock(&mountlist_slock);
157 1.1.2.2 thorpej (void)cd9660_statfs(mp, &mp->mnt_stat, p);
158 1.1.2.2 thorpej vfs_unbusy(mp);
159 1.1.2.2 thorpej inittodr(0);
160 1.1.2.2 thorpej return (0);
161 1.1.2.2 thorpej }
162 1.1.2.2 thorpej
163 1.1.2.2 thorpej /*
164 1.1.2.2 thorpej * VFS Operations.
165 1.1.2.2 thorpej *
166 1.1.2.2 thorpej * mount system call
167 1.1.2.2 thorpej */
168 1.1.2.2 thorpej int
169 1.1.2.2 thorpej cd9660_mount(mp, path, data, ndp, p)
170 1.1.2.2 thorpej struct mount *mp;
171 1.1.2.2 thorpej const char *path;
172 1.1.2.2 thorpej void *data;
173 1.1.2.2 thorpej struct nameidata *ndp;
174 1.1.2.2 thorpej struct proc *p;
175 1.1.2.2 thorpej {
176 1.1.2.2 thorpej struct vnode *devvp;
177 1.1.2.2 thorpej struct iso_args args;
178 1.1.2.2 thorpej size_t size;
179 1.1.2.2 thorpej int error;
180 1.1.2.2 thorpej struct iso_mnt *imp = NULL;
181 1.1.2.2 thorpej
182 1.1.2.2 thorpej if (mp->mnt_flag & MNT_GETARGS) {
183 1.1.2.2 thorpej imp = VFSTOISOFS(mp);
184 1.1.2.2 thorpej if (imp == NULL)
185 1.1.2.2 thorpej return EIO;
186 1.1.2.2 thorpej args.fspec = NULL;
187 1.1.2.2 thorpej args.flags = imp->im_flags;
188 1.1.2.2 thorpej vfs_showexport(mp, &args.export, &imp->im_export);
189 1.1.2.2 thorpej return copyout(&args, data, sizeof(args));
190 1.1.2.2 thorpej }
191 1.1.2.2 thorpej error = copyin(data, (caddr_t)&args, sizeof (struct iso_args));
192 1.1.2.2 thorpej if (error)
193 1.1.2.2 thorpej return (error);
194 1.1.2.2 thorpej
195 1.1.2.2 thorpej if ((mp->mnt_flag & MNT_RDONLY) == 0)
196 1.1.2.2 thorpej return (EROFS);
197 1.1.2.2 thorpej
198 1.1.2.2 thorpej /*
199 1.1.2.2 thorpej * If updating, check whether changing from read-only to
200 1.1.2.2 thorpej * read/write; if there is no device name, that's all we do.
201 1.1.2.2 thorpej */
202 1.1.2.2 thorpej if (mp->mnt_flag & MNT_UPDATE) {
203 1.1.2.2 thorpej imp = VFSTOISOFS(mp);
204 1.1.2.2 thorpej if (args.fspec == 0)
205 1.1.2.2 thorpej return (vfs_export(mp, &imp->im_export, &args.export));
206 1.1.2.2 thorpej }
207 1.1.2.2 thorpej /*
208 1.1.2.2 thorpej * Not an update, or updating the name: look up the name
209 1.1.2.2 thorpej * and verify that it refers to a sensible block device.
210 1.1.2.2 thorpej */
211 1.1.2.2 thorpej NDINIT(ndp, LOOKUP, FOLLOW, UIO_USERSPACE, args.fspec, p);
212 1.1.2.2 thorpej if ((error = namei(ndp)) != 0)
213 1.1.2.2 thorpej return (error);
214 1.1.2.2 thorpej devvp = ndp->ni_vp;
215 1.1.2.2 thorpej
216 1.1.2.2 thorpej if (devvp->v_type != VBLK) {
217 1.1.2.2 thorpej vrele(devvp);
218 1.1.2.2 thorpej return ENOTBLK;
219 1.1.2.2 thorpej }
220 1.1.2.2 thorpej if (bdevsw_lookup(devvp->v_rdev) == NULL) {
221 1.1.2.2 thorpej vrele(devvp);
222 1.1.2.2 thorpej return ENXIO;
223 1.1.2.2 thorpej }
224 1.1.2.2 thorpej /*
225 1.1.2.2 thorpej * If mount by non-root, then verify that user has necessary
226 1.1.2.2 thorpej * permissions on the device.
227 1.1.2.2 thorpej */
228 1.1.2.2 thorpej if (p->p_ucred->cr_uid != 0) {
229 1.1.2.2 thorpej vn_lock(devvp, LK_EXCLUSIVE | LK_RETRY);
230 1.1.2.2 thorpej error = VOP_ACCESS(devvp, VREAD, p->p_ucred, p);
231 1.1.2.2 thorpej VOP_UNLOCK(devvp, 0);
232 1.1.2.2 thorpej if (error) {
233 1.1.2.2 thorpej vrele(devvp);
234 1.1.2.2 thorpej return (error);
235 1.1.2.2 thorpej }
236 1.1.2.2 thorpej }
237 1.1.2.2 thorpej if ((mp->mnt_flag & MNT_UPDATE) == 0)
238 1.1.2.2 thorpej error = iso_mountfs(devvp, mp, p, &args);
239 1.1.2.2 thorpej else {
240 1.1.2.2 thorpej if (devvp != imp->im_devvp)
241 1.1.2.2 thorpej error = EINVAL; /* needs translation */
242 1.1.2.2 thorpej else
243 1.1.2.2 thorpej vrele(devvp);
244 1.1.2.2 thorpej }
245 1.1.2.2 thorpej if (error) {
246 1.1.2.2 thorpej vrele(devvp);
247 1.1.2.2 thorpej return error;
248 1.1.2.2 thorpej }
249 1.1.2.2 thorpej imp = VFSTOISOFS(mp);
250 1.1.2.2 thorpej (void) copyinstr(path, mp->mnt_stat.f_mntonname, MNAMELEN - 1, &size);
251 1.1.2.2 thorpej memset(mp->mnt_stat.f_mntonname + size, 0, MNAMELEN - size);
252 1.1.2.2 thorpej (void) copyinstr(args.fspec, mp->mnt_stat.f_mntfromname, MNAMELEN - 1,
253 1.1.2.2 thorpej &size);
254 1.1.2.2 thorpej memset(mp->mnt_stat.f_mntfromname + size, 0, MNAMELEN - size);
255 1.1.2.2 thorpej return 0;
256 1.1.2.2 thorpej }
257 1.1.2.2 thorpej
258 1.1.2.2 thorpej /*
259 1.1.2.2 thorpej * Make a mount point from a volume descriptor
260 1.1.2.2 thorpej */
261 1.1.2.2 thorpej static int
262 1.1.2.2 thorpej iso_makemp(isomp, bp, ea_len)
263 1.1.2.2 thorpej struct iso_mnt *isomp;
264 1.1.2.2 thorpej struct buf *bp;
265 1.1.2.2 thorpej int *ea_len;
266 1.1.2.2 thorpej {
267 1.1.2.2 thorpej struct iso_primary_descriptor *pri;
268 1.1.2.2 thorpej int logical_block_size;
269 1.1.2.2 thorpej struct iso_directory_record *rootp;
270 1.1.2.2 thorpej
271 1.1.2.2 thorpej pri = (struct iso_primary_descriptor *)bp->b_data;
272 1.1.2.2 thorpej
273 1.1.2.2 thorpej logical_block_size = isonum_723 (pri->logical_block_size);
274 1.1.2.2 thorpej
275 1.1.2.2 thorpej if (logical_block_size < DEV_BSIZE || logical_block_size > MAXBSIZE
276 1.1.2.2 thorpej || (logical_block_size & (logical_block_size - 1)) != 0)
277 1.1.2.2 thorpej return -1;
278 1.1.2.2 thorpej
279 1.1.2.2 thorpej rootp = (struct iso_directory_record *)pri->root_directory_record;
280 1.1.2.2 thorpej
281 1.1.2.2 thorpej isomp->logical_block_size = logical_block_size;
282 1.1.2.2 thorpej isomp->volume_space_size = isonum_733 (pri->volume_space_size);
283 1.1.2.2 thorpej memcpy(isomp->root, rootp, sizeof(isomp->root));
284 1.1.2.2 thorpej isomp->root_extent = isonum_733 (rootp->extent);
285 1.1.2.2 thorpej isomp->root_size = isonum_733 (rootp->size);
286 1.1.2.2 thorpej isomp->im_joliet_level = 0;
287 1.1.2.2 thorpej
288 1.1.2.2 thorpej isomp->im_bmask = logical_block_size - 1;
289 1.1.2.2 thorpej isomp->im_bshift = 0;
290 1.1.2.2 thorpej while ((1 << isomp->im_bshift) < isomp->logical_block_size)
291 1.1.2.2 thorpej isomp->im_bshift++;
292 1.1.2.2 thorpej
293 1.1.2.2 thorpej if (ea_len != NULL)
294 1.1.2.2 thorpej *ea_len = isonum_711(rootp->ext_attr_length);
295 1.1.2.2 thorpej
296 1.1.2.2 thorpej return 0;
297 1.1.2.2 thorpej }
298 1.1.2.2 thorpej
299 1.1.2.2 thorpej /*
300 1.1.2.2 thorpej * Common code for mount and mountroot
301 1.1.2.2 thorpej */
302 1.1.2.2 thorpej static int
303 1.1.2.2 thorpej iso_mountfs(devvp, mp, p, argp)
304 1.1.2.2 thorpej struct vnode *devvp;
305 1.1.2.2 thorpej struct mount *mp;
306 1.1.2.2 thorpej struct proc *p;
307 1.1.2.2 thorpej struct iso_args *argp;
308 1.1.2.2 thorpej {
309 1.1.2.2 thorpej struct iso_mnt *isomp = (struct iso_mnt *)0;
310 1.1.2.2 thorpej struct buf *bp = NULL, *pribp = NULL, *supbp = NULL;
311 1.1.2.2 thorpej dev_t dev = devvp->v_rdev;
312 1.1.2.2 thorpej int error = EINVAL;
313 1.1.2.2 thorpej int needclose = 0;
314 1.1.2.2 thorpej int ronly = (mp->mnt_flag & MNT_RDONLY) != 0;
315 1.1.2.2 thorpej int iso_bsize;
316 1.1.2.2 thorpej int iso_blknum;
317 1.1.2.2 thorpej int joliet_level;
318 1.1.2.2 thorpej struct iso_volume_descriptor *vdp;
319 1.1.2.2 thorpej struct iso_supplementary_descriptor *sup;
320 1.1.2.2 thorpej int sess = 0;
321 1.1.2.2 thorpej int ext_attr_length;
322 1.1.2.2 thorpej struct disklabel label;
323 1.1.2.2 thorpej
324 1.1.2.2 thorpej if (!ronly)
325 1.1.2.2 thorpej return EROFS;
326 1.1.2.2 thorpej
327 1.1.2.2 thorpej /*
328 1.1.2.2 thorpej * Disallow multiple mounts of the same device.
329 1.1.2.2 thorpej * Disallow mounting of a device that is currently in use
330 1.1.2.2 thorpej * (except for root, which might share swap device for miniroot).
331 1.1.2.2 thorpej * Flush out any old buffers remaining from a previous use.
332 1.1.2.2 thorpej */
333 1.1.2.2 thorpej if ((error = vfs_mountedon(devvp)) != 0)
334 1.1.2.2 thorpej return error;
335 1.1.2.2 thorpej if (vcount(devvp) > 1 && devvp != rootvp)
336 1.1.2.2 thorpej return EBUSY;
337 1.1.2.2 thorpej if ((error = vinvalbuf(devvp, V_SAVE, p->p_ucred, p, 0, 0)) != 0)
338 1.1.2.2 thorpej return (error);
339 1.1.2.2 thorpej
340 1.1.2.2 thorpej error = VOP_OPEN(devvp, ronly ? FREAD : FREAD|FWRITE, FSCRED, p);
341 1.1.2.2 thorpej if (error)
342 1.1.2.2 thorpej return error;
343 1.1.2.2 thorpej needclose = 1;
344 1.1.2.2 thorpej
345 1.1.2.2 thorpej /* This is the "logical sector size". The standard says this
346 1.1.2.2 thorpej * should be 2048 or the physical sector size on the device,
347 1.1.2.2 thorpej * whichever is greater. For now, we'll just use a constant.
348 1.1.2.2 thorpej */
349 1.1.2.2 thorpej iso_bsize = ISO_DEFAULT_BLOCK_SIZE;
350 1.1.2.2 thorpej
351 1.1.2.2 thorpej error = VOP_IOCTL(devvp, DIOCGDINFO, (caddr_t)&label, FREAD, FSCRED, p);
352 1.1.2.2 thorpej if (!error &&
353 1.1.2.2 thorpej label.d_partitions[DISKPART(dev)].p_fstype == FS_ISO9660) {
354 1.1.2.2 thorpej /* XXX more sanity checks? */
355 1.1.2.2 thorpej sess = label.d_partitions[DISKPART(dev)].p_cdsession;
356 1.1.2.2 thorpej } else {
357 1.1.2.2 thorpej /* fallback to old method */
358 1.1.2.2 thorpej error = VOP_IOCTL(devvp, CDIOREADMSADDR, (caddr_t)&sess, 0,
359 1.1.2.2 thorpej FSCRED, p);
360 1.1.2.2 thorpej if (error)
361 1.1.2.2 thorpej sess = 0; /* never mind */
362 1.1.2.2 thorpej }
363 1.1.2.2 thorpej #ifdef DEBUG
364 1.1.2.2 thorpej printf("isofs: session offset (part %d) %d\n", DISKPART(dev), sess);
365 1.1.2.2 thorpej #endif
366 1.1.2.2 thorpej
367 1.1.2.2 thorpej for (iso_blknum = 16; iso_blknum < 100; iso_blknum++) {
368 1.1.2.2 thorpej if ((error = bread(devvp, (iso_blknum+sess) * btodb(iso_bsize),
369 1.1.2.2 thorpej iso_bsize, NOCRED, &bp)) != 0)
370 1.1.2.2 thorpej goto out;
371 1.1.2.2 thorpej
372 1.1.2.2 thorpej vdp = (struct iso_volume_descriptor *)bp->b_data;
373 1.1.2.2 thorpej if (memcmp(vdp->id, ISO_STANDARD_ID, sizeof(vdp->id)) != 0) {
374 1.1.2.2 thorpej error = EINVAL;
375 1.1.2.2 thorpej goto out;
376 1.1.2.2 thorpej }
377 1.1.2.2 thorpej
378 1.1.2.2 thorpej switch (isonum_711(vdp->type)) {
379 1.1.2.2 thorpej case ISO_VD_PRIMARY:
380 1.1.2.2 thorpej if (pribp == NULL) {
381 1.1.2.2 thorpej pribp = bp;
382 1.1.2.2 thorpej bp = NULL;
383 1.1.2.2 thorpej }
384 1.1.2.2 thorpej break;
385 1.1.2.2 thorpej
386 1.1.2.2 thorpej case ISO_VD_SUPPLEMENTARY:
387 1.1.2.2 thorpej if (supbp == NULL) {
388 1.1.2.2 thorpej supbp = bp;
389 1.1.2.2 thorpej bp = NULL;
390 1.1.2.2 thorpej }
391 1.1.2.2 thorpej break;
392 1.1.2.2 thorpej
393 1.1.2.2 thorpej default:
394 1.1.2.2 thorpej break;
395 1.1.2.2 thorpej }
396 1.1.2.2 thorpej
397 1.1.2.2 thorpej if (isonum_711 (vdp->type) == ISO_VD_END) {
398 1.1.2.2 thorpej brelse(bp);
399 1.1.2.2 thorpej bp = NULL;
400 1.1.2.2 thorpej break;
401 1.1.2.2 thorpej }
402 1.1.2.2 thorpej
403 1.1.2.2 thorpej if (bp != NULL) {
404 1.1.2.2 thorpej brelse(bp);
405 1.1.2.2 thorpej bp = NULL;
406 1.1.2.2 thorpej }
407 1.1.2.2 thorpej }
408 1.1.2.2 thorpej
409 1.1.2.2 thorpej if (pribp == NULL) {
410 1.1.2.2 thorpej error = EINVAL;
411 1.1.2.2 thorpej goto out;
412 1.1.2.2 thorpej }
413 1.1.2.2 thorpej
414 1.1.2.2 thorpej isomp = malloc(sizeof *isomp, M_ISOFSMNT, M_WAITOK);
415 1.1.2.2 thorpej memset((caddr_t)isomp, 0, sizeof *isomp);
416 1.1.2.2 thorpej if (iso_makemp(isomp, pribp, &ext_attr_length) == -1) {
417 1.1.2.2 thorpej error = EINVAL;
418 1.1.2.2 thorpej goto out;
419 1.1.2.2 thorpej }
420 1.1.2.2 thorpej
421 1.1.2.2 thorpej isomp->volume_space_size += sess;
422 1.1.2.2 thorpej
423 1.1.2.2 thorpej pribp->b_flags |= B_AGE;
424 1.1.2.2 thorpej brelse(pribp);
425 1.1.2.2 thorpej pribp = NULL;
426 1.1.2.2 thorpej
427 1.1.2.2 thorpej mp->mnt_data = isomp;
428 1.1.2.2 thorpej mp->mnt_stat.f_fsid.val[0] = (long)dev;
429 1.1.2.2 thorpej mp->mnt_stat.f_fsid.val[1] = makefstype(MOUNT_CD9660);
430 1.1.2.2 thorpej mp->mnt_maxsymlinklen = 0;
431 1.1.2.2 thorpej mp->mnt_flag |= MNT_LOCAL;
432 1.1.2.2 thorpej mp->mnt_dev_bshift = iso_bsize;
433 1.1.2.2 thorpej mp->mnt_fs_bshift = isomp->im_bshift;
434 1.1.2.2 thorpej isomp->im_mountp = mp;
435 1.1.2.2 thorpej isomp->im_dev = dev;
436 1.1.2.2 thorpej isomp->im_devvp = devvp;
437 1.1.2.2 thorpej
438 1.1.2.2 thorpej devvp->v_specmountpoint = mp;
439 1.1.2.2 thorpej
440 1.1.2.2 thorpej /* Check the Rock Ridge Extension support */
441 1.1.2.2 thorpej if (!(argp->flags & ISOFSMNT_NORRIP)) {
442 1.1.2.2 thorpej struct iso_directory_record *rootp;
443 1.1.2.2 thorpej
444 1.1.2.2 thorpej if ((error = bread(isomp->im_devvp,
445 1.1.2.2 thorpej (isomp->root_extent + ext_attr_length) <<
446 1.1.2.2 thorpej (isomp->im_bshift - DEV_BSHIFT),
447 1.1.2.2 thorpej isomp->logical_block_size, NOCRED,
448 1.1.2.2 thorpej &bp)) != 0)
449 1.1.2.2 thorpej goto out;
450 1.1.2.2 thorpej
451 1.1.2.2 thorpej rootp = (struct iso_directory_record *)bp->b_data;
452 1.1.2.2 thorpej
453 1.1.2.2 thorpej if ((isomp->rr_skip = cd9660_rrip_offset(rootp,isomp)) < 0) {
454 1.1.2.2 thorpej argp->flags |= ISOFSMNT_NORRIP;
455 1.1.2.2 thorpej } else {
456 1.1.2.2 thorpej argp->flags &= ~ISOFSMNT_GENS;
457 1.1.2.2 thorpej }
458 1.1.2.2 thorpej
459 1.1.2.2 thorpej /*
460 1.1.2.2 thorpej * The contents are valid,
461 1.1.2.2 thorpej * but they will get reread as part of another vnode, so...
462 1.1.2.2 thorpej */
463 1.1.2.2 thorpej bp->b_flags |= B_AGE;
464 1.1.2.2 thorpej brelse(bp);
465 1.1.2.2 thorpej bp = NULL;
466 1.1.2.2 thorpej }
467 1.1.2.2 thorpej isomp->im_flags = argp->flags & (ISOFSMNT_NORRIP | ISOFSMNT_GENS |
468 1.1.2.2 thorpej ISOFSMNT_EXTATT | ISOFSMNT_NOJOLIET | ISOFSMNT_RRCASEINS);
469 1.1.2.2 thorpej
470 1.1.2.2 thorpej if (isomp->im_flags & ISOFSMNT_GENS)
471 1.1.2.2 thorpej isomp->iso_ftype = ISO_FTYPE_9660;
472 1.1.2.2 thorpej else if (isomp->im_flags & ISOFSMNT_NORRIP) {
473 1.1.2.2 thorpej isomp->iso_ftype = ISO_FTYPE_DEFAULT;
474 1.1.2.2 thorpej if (argp->flags & ISOFSMNT_NOCASETRANS)
475 1.1.2.2 thorpej isomp->im_flags |= ISOFSMNT_NOCASETRANS;
476 1.1.2.2 thorpej } else
477 1.1.2.2 thorpej isomp->iso_ftype = ISO_FTYPE_RRIP;
478 1.1.2.2 thorpej
479 1.1.2.2 thorpej /* Check the Joliet Extension support */
480 1.1.2.2 thorpej if ((argp->flags & ISOFSMNT_NORRIP) != 0 &&
481 1.1.2.2 thorpej (argp->flags & ISOFSMNT_NOJOLIET) == 0 &&
482 1.1.2.2 thorpej supbp != NULL) {
483 1.1.2.2 thorpej joliet_level = 0;
484 1.1.2.2 thorpej sup = (struct iso_supplementary_descriptor *)supbp->b_data;
485 1.1.2.2 thorpej
486 1.1.2.2 thorpej if ((isonum_711(sup->flags) & 1) == 0) {
487 1.1.2.2 thorpej if (memcmp(sup->escape, "%/@", 3) == 0)
488 1.1.2.2 thorpej joliet_level = 1;
489 1.1.2.2 thorpej if (memcmp(sup->escape, "%/C", 3) == 0)
490 1.1.2.2 thorpej joliet_level = 2;
491 1.1.2.2 thorpej if (memcmp(sup->escape, "%/E", 3) == 0)
492 1.1.2.2 thorpej joliet_level = 3;
493 1.1.2.2 thorpej }
494 1.1.2.2 thorpej if (joliet_level != 0) {
495 1.1.2.2 thorpej if (iso_makemp(isomp, supbp, NULL) == -1) {
496 1.1.2.2 thorpej error = EINVAL;
497 1.1.2.2 thorpej goto out;
498 1.1.2.2 thorpej }
499 1.1.2.2 thorpej isomp->im_joliet_level = joliet_level;
500 1.1.2.2 thorpej }
501 1.1.2.2 thorpej }
502 1.1.2.2 thorpej
503 1.1.2.2 thorpej if (supbp != NULL) {
504 1.1.2.2 thorpej brelse(supbp);
505 1.1.2.2 thorpej supbp = NULL;
506 1.1.2.2 thorpej }
507 1.1.2.2 thorpej
508 1.1.2.2 thorpej return 0;
509 1.1.2.2 thorpej out:
510 1.1.2.2 thorpej if (bp)
511 1.1.2.2 thorpej brelse(bp);
512 1.1.2.2 thorpej if (pribp)
513 1.1.2.2 thorpej brelse(pribp);
514 1.1.2.2 thorpej if (supbp)
515 1.1.2.2 thorpej brelse(supbp);
516 1.1.2.2 thorpej if (needclose) {
517 1.1.2.2 thorpej vn_lock(devvp, LK_EXCLUSIVE | LK_RETRY);
518 1.1.2.2 thorpej (void)VOP_CLOSE(devvp, ronly ? FREAD : FREAD|FWRITE, NOCRED, p);
519 1.1.2.2 thorpej VOP_UNLOCK(devvp, 0);
520 1.1.2.2 thorpej }
521 1.1.2.2 thorpej if (isomp) {
522 1.1.2.2 thorpej free((caddr_t)isomp, M_ISOFSMNT);
523 1.1.2.2 thorpej mp->mnt_data = NULL;
524 1.1.2.2 thorpej }
525 1.1.2.2 thorpej return error;
526 1.1.2.2 thorpej }
527 1.1.2.2 thorpej
528 1.1.2.2 thorpej /*
529 1.1.2.2 thorpej * Make a filesystem operational.
530 1.1.2.2 thorpej * Nothing to do at the moment.
531 1.1.2.2 thorpej */
532 1.1.2.2 thorpej /* ARGSUSED */
533 1.1.2.2 thorpej int
534 1.1.2.2 thorpej cd9660_start(mp, flags, p)
535 1.1.2.2 thorpej struct mount *mp;
536 1.1.2.2 thorpej int flags;
537 1.1.2.2 thorpej struct proc *p;
538 1.1.2.2 thorpej {
539 1.1.2.2 thorpej return 0;
540 1.1.2.2 thorpej }
541 1.1.2.2 thorpej
542 1.1.2.2 thorpej /*
543 1.1.2.2 thorpej * unmount system call
544 1.1.2.2 thorpej */
545 1.1.2.2 thorpej int
546 1.1.2.2 thorpej cd9660_unmount(mp, mntflags, p)
547 1.1.2.2 thorpej struct mount *mp;
548 1.1.2.2 thorpej int mntflags;
549 1.1.2.2 thorpej struct proc *p;
550 1.1.2.2 thorpej {
551 1.1.2.2 thorpej struct iso_mnt *isomp;
552 1.1.2.2 thorpej int error, flags = 0;
553 1.1.2.2 thorpej
554 1.1.2.2 thorpej if (mntflags & MNT_FORCE)
555 1.1.2.2 thorpej flags |= FORCECLOSE;
556 1.1.2.2 thorpej #if 0
557 1.1.2.2 thorpej mntflushbuf(mp, 0);
558 1.1.2.2 thorpej if (mntinvalbuf(mp))
559 1.1.2.2 thorpej return EBUSY;
560 1.1.2.2 thorpej #endif
561 1.1.2.2 thorpej if ((error = vflush(mp, NULLVP, flags)) != 0)
562 1.1.2.2 thorpej return (error);
563 1.1.2.2 thorpej
564 1.1.2.2 thorpej isomp = VFSTOISOFS(mp);
565 1.1.2.2 thorpej
566 1.1.2.2 thorpej #ifdef ISODEVMAP
567 1.1.2.2 thorpej if (isomp->iso_ftype == ISO_FTYPE_RRIP)
568 1.1.2.2 thorpej iso_dunmap(isomp->im_dev);
569 1.1.2.2 thorpej #endif
570 1.1.2.2 thorpej
571 1.1.2.2 thorpej if (isomp->im_devvp->v_type != VBAD)
572 1.1.2.2 thorpej isomp->im_devvp->v_specmountpoint = NULL;
573 1.1.2.2 thorpej
574 1.1.2.2 thorpej vn_lock(isomp->im_devvp, LK_EXCLUSIVE | LK_RETRY);
575 1.1.2.2 thorpej error = VOP_CLOSE(isomp->im_devvp, FREAD, NOCRED, p);
576 1.1.2.2 thorpej vput(isomp->im_devvp);
577 1.1.2.2 thorpej free((caddr_t)isomp, M_ISOFSMNT);
578 1.1.2.2 thorpej mp->mnt_data = NULL;
579 1.1.2.2 thorpej mp->mnt_flag &= ~MNT_LOCAL;
580 1.1.2.2 thorpej return (error);
581 1.1.2.2 thorpej }
582 1.1.2.2 thorpej
583 1.1.2.2 thorpej /*
584 1.1.2.2 thorpej * Return root of a filesystem
585 1.1.2.2 thorpej */
586 1.1.2.2 thorpej int
587 1.1.2.2 thorpej cd9660_root(mp, vpp)
588 1.1.2.2 thorpej struct mount *mp;
589 1.1.2.2 thorpej struct vnode **vpp;
590 1.1.2.2 thorpej {
591 1.1.2.2 thorpej struct iso_mnt *imp = VFSTOISOFS(mp);
592 1.1.2.2 thorpej struct iso_directory_record *dp =
593 1.1.2.2 thorpej (struct iso_directory_record *)imp->root;
594 1.1.2.2 thorpej ino_t ino = isodirino(dp, imp);
595 1.1.2.2 thorpej
596 1.1.2.2 thorpej /*
597 1.1.2.2 thorpej * With RRIP we must use the `.' entry of the root directory.
598 1.1.2.2 thorpej * Simply tell vget, that it's a relocated directory.
599 1.1.2.2 thorpej */
600 1.1.2.2 thorpej return (cd9660_vget_internal(mp, ino, vpp,
601 1.1.2.2 thorpej imp->iso_ftype == ISO_FTYPE_RRIP, dp));
602 1.1.2.2 thorpej }
603 1.1.2.2 thorpej
604 1.1.2.2 thorpej /*
605 1.1.2.2 thorpej * Do operations associated with quotas, not supported
606 1.1.2.2 thorpej */
607 1.1.2.2 thorpej /* ARGSUSED */
608 1.1.2.2 thorpej int
609 1.1.2.2 thorpej cd9660_quotactl(mp, cmd, uid, arg, p)
610 1.1.2.2 thorpej struct mount *mp;
611 1.1.2.2 thorpej int cmd;
612 1.1.2.2 thorpej uid_t uid;
613 1.1.2.2 thorpej caddr_t arg;
614 1.1.2.2 thorpej struct proc *p;
615 1.1.2.2 thorpej {
616 1.1.2.2 thorpej
617 1.1.2.2 thorpej return (EOPNOTSUPP);
618 1.1.2.2 thorpej }
619 1.1.2.2 thorpej
620 1.1.2.2 thorpej /*
621 1.1.2.2 thorpej * Get file system statistics.
622 1.1.2.2 thorpej */
623 1.1.2.2 thorpej int
624 1.1.2.2 thorpej cd9660_statfs(mp, sbp, p)
625 1.1.2.2 thorpej struct mount *mp;
626 1.1.2.2 thorpej struct statfs *sbp;
627 1.1.2.2 thorpej struct proc *p;
628 1.1.2.2 thorpej {
629 1.1.2.2 thorpej struct iso_mnt *isomp;
630 1.1.2.2 thorpej
631 1.1.2.2 thorpej isomp = VFSTOISOFS(mp);
632 1.1.2.2 thorpej
633 1.1.2.2 thorpej #ifdef COMPAT_09
634 1.1.2.2 thorpej sbp->f_type = 5;
635 1.1.2.2 thorpej #else
636 1.1.2.2 thorpej sbp->f_type = 0;
637 1.1.2.2 thorpej #endif
638 1.1.2.2 thorpej sbp->f_bsize = isomp->logical_block_size;
639 1.1.2.2 thorpej sbp->f_iosize = sbp->f_bsize; /* XXX */
640 1.1.2.2 thorpej sbp->f_blocks = isomp->volume_space_size;
641 1.1.2.2 thorpej sbp->f_bfree = 0; /* total free blocks */
642 1.1.2.2 thorpej sbp->f_bavail = 0; /* blocks free for non superuser */
643 1.1.2.2 thorpej sbp->f_files = 0; /* total files */
644 1.1.2.2 thorpej sbp->f_ffree = 0; /* free file nodes */
645 1.1.2.2 thorpej if (sbp != &mp->mnt_stat) {
646 1.1.2.2 thorpej memcpy(sbp->f_mntonname, mp->mnt_stat.f_mntonname, MNAMELEN);
647 1.1.2.2 thorpej memcpy(sbp->f_mntfromname, mp->mnt_stat.f_mntfromname, MNAMELEN);
648 1.1.2.2 thorpej }
649 1.1.2.2 thorpej strncpy(sbp->f_fstypename, mp->mnt_op->vfs_name, MFSNAMELEN);
650 1.1.2.2 thorpej /* Use the first spare for flags: */
651 1.1.2.2 thorpej sbp->f_spare[0] = isomp->im_flags;
652 1.1.2.2 thorpej return 0;
653 1.1.2.2 thorpej }
654 1.1.2.2 thorpej
655 1.1.2.2 thorpej /* ARGSUSED */
656 1.1.2.2 thorpej int
657 1.1.2.2 thorpej cd9660_sync(mp, waitfor, cred, p)
658 1.1.2.2 thorpej struct mount *mp;
659 1.1.2.2 thorpej int waitfor;
660 1.1.2.2 thorpej struct ucred *cred;
661 1.1.2.2 thorpej struct proc *p;
662 1.1.2.2 thorpej {
663 1.1.2.2 thorpej return (0);
664 1.1.2.2 thorpej }
665 1.1.2.2 thorpej
666 1.1.2.2 thorpej /*
667 1.1.2.2 thorpej * File handle to vnode
668 1.1.2.2 thorpej *
669 1.1.2.2 thorpej * Have to be really careful about stale file handles:
670 1.1.2.2 thorpej * - check that the inode number is in range
671 1.1.2.2 thorpej * - call iget() to get the locked inode
672 1.1.2.2 thorpej * - check for an unallocated inode (i_mode == 0)
673 1.1.2.2 thorpej * - check that the generation number matches
674 1.1.2.2 thorpej */
675 1.1.2.2 thorpej
676 1.1.2.2 thorpej struct ifid {
677 1.1.2.2 thorpej ushort ifid_len;
678 1.1.2.2 thorpej ushort ifid_pad;
679 1.1.2.2 thorpej int ifid_ino;
680 1.1.2.2 thorpej long ifid_start;
681 1.1.2.2 thorpej };
682 1.1.2.2 thorpej
683 1.1.2.2 thorpej /* ARGSUSED */
684 1.1.2.2 thorpej int
685 1.1.2.2 thorpej cd9660_fhtovp(mp, fhp, vpp)
686 1.1.2.2 thorpej struct mount *mp;
687 1.1.2.2 thorpej struct fid *fhp;
688 1.1.2.2 thorpej struct vnode **vpp;
689 1.1.2.2 thorpej {
690 1.1.2.2 thorpej struct ifid *ifhp = (struct ifid *)fhp;
691 1.1.2.2 thorpej struct iso_node *ip;
692 1.1.2.2 thorpej struct vnode *nvp;
693 1.1.2.2 thorpej int error;
694 1.1.2.2 thorpej
695 1.1.2.2 thorpej #ifdef ISOFS_DBG
696 1.1.2.2 thorpej printf("fhtovp: ino %d, start %ld\n",
697 1.1.2.2 thorpej ifhp->ifid_ino, ifhp->ifid_start);
698 1.1.2.2 thorpej #endif
699 1.1.2.2 thorpej
700 1.1.2.2 thorpej if ((error = VFS_VGET(mp, ifhp->ifid_ino, &nvp)) != 0) {
701 1.1.2.2 thorpej *vpp = NULLVP;
702 1.1.2.2 thorpej return (error);
703 1.1.2.2 thorpej }
704 1.1.2.2 thorpej ip = VTOI(nvp);
705 1.1.2.2 thorpej if (ip->inode.iso_mode == 0) {
706 1.1.2.2 thorpej vput(nvp);
707 1.1.2.2 thorpej *vpp = NULLVP;
708 1.1.2.2 thorpej return (ESTALE);
709 1.1.2.2 thorpej }
710 1.1.2.2 thorpej *vpp = nvp;
711 1.1.2.2 thorpej return (0);
712 1.1.2.2 thorpej }
713 1.1.2.2 thorpej
714 1.1.2.2 thorpej /* ARGSUSED */
715 1.1.2.2 thorpej int
716 1.1.2.2 thorpej cd9660_check_export(mp, nam, exflagsp, credanonp)
717 1.1.2.2 thorpej struct mount *mp;
718 1.1.2.2 thorpej struct mbuf *nam;
719 1.1.2.2 thorpej int *exflagsp;
720 1.1.2.2 thorpej struct ucred **credanonp;
721 1.1.2.2 thorpej {
722 1.1.2.2 thorpej struct netcred *np;
723 1.1.2.2 thorpej struct iso_mnt *imp = VFSTOISOFS(mp);
724 1.1.2.2 thorpej
725 1.1.2.2 thorpej #ifdef ISOFS_DBG
726 1.1.2.2 thorpej printf("check_export: ino %d, start %ld\n",
727 1.1.2.2 thorpej ifhp->ifid_ino, ifhp->ifid_start);
728 1.1.2.2 thorpej #endif
729 1.1.2.2 thorpej
730 1.1.2.2 thorpej /*
731 1.1.2.2 thorpej * Get the export permission structure for this <mp, client> tuple.
732 1.1.2.2 thorpej */
733 1.1.2.2 thorpej np = vfs_export_lookup(mp, &imp->im_export, nam);
734 1.1.2.2 thorpej if (np == NULL)
735 1.1.2.2 thorpej return (EACCES);
736 1.1.2.2 thorpej
737 1.1.2.2 thorpej *exflagsp = np->netc_exflags;
738 1.1.2.2 thorpej *credanonp = &np->netc_anon;
739 1.1.2.2 thorpej return (0);
740 1.1.2.2 thorpej }
741 1.1.2.2 thorpej
742 1.1.2.2 thorpej int
743 1.1.2.2 thorpej cd9660_vget(mp, ino, vpp)
744 1.1.2.2 thorpej struct mount *mp;
745 1.1.2.2 thorpej ino_t ino;
746 1.1.2.2 thorpej struct vnode **vpp;
747 1.1.2.2 thorpej {
748 1.1.2.2 thorpej
749 1.1.2.2 thorpej /*
750 1.1.2.2 thorpej * XXXX
751 1.1.2.2 thorpej * It would be nice if we didn't always set the `relocated' flag
752 1.1.2.2 thorpej * and force the extra read, but I don't want to think about fixing
753 1.1.2.2 thorpej * that right now.
754 1.1.2.2 thorpej */
755 1.1.2.2 thorpej return (cd9660_vget_internal(mp, ino, vpp,
756 1.1.2.2 thorpej #if 0
757 1.1.2.2 thorpej VFSTOISOFS(mp)->iso_ftype == ISO_FTYPE_RRIP,
758 1.1.2.2 thorpej #else
759 1.1.2.2 thorpej 0,
760 1.1.2.2 thorpej #endif
761 1.1.2.2 thorpej NULL));
762 1.1.2.2 thorpej }
763 1.1.2.2 thorpej
764 1.1.2.2 thorpej int
765 1.1.2.2 thorpej cd9660_vget_internal(mp, ino, vpp, relocated, isodir)
766 1.1.2.2 thorpej struct mount *mp;
767 1.1.2.2 thorpej ino_t ino;
768 1.1.2.2 thorpej struct vnode **vpp;
769 1.1.2.2 thorpej int relocated;
770 1.1.2.2 thorpej struct iso_directory_record *isodir;
771 1.1.2.2 thorpej {
772 1.1.2.2 thorpej struct iso_mnt *imp;
773 1.1.2.2 thorpej struct iso_node *ip;
774 1.1.2.2 thorpej #ifdef ISODEVMAP
775 1.1.2.2 thorpej struct iso_dnode *dp;
776 1.1.2.2 thorpej #endif
777 1.1.2.2 thorpej struct buf *bp;
778 1.1.2.2 thorpej struct vnode *vp, *nvp;
779 1.1.2.2 thorpej dev_t dev;
780 1.1.2.2 thorpej int error;
781 1.1.2.2 thorpej
782 1.1.2.2 thorpej imp = VFSTOISOFS(mp);
783 1.1.2.2 thorpej dev = imp->im_dev;
784 1.1.2.2 thorpej if ((*vpp = cd9660_ihashget(dev, ino)) != NULLVP)
785 1.1.2.2 thorpej return (0);
786 1.1.2.2 thorpej
787 1.1.2.2 thorpej /* Allocate a new vnode/iso_node. */
788 1.1.2.2 thorpej if ((error = getnewvnode(VT_ISOFS, mp, cd9660_vnodeop_p, &vp)) != 0) {
789 1.1.2.2 thorpej *vpp = NULLVP;
790 1.1.2.2 thorpej return (error);
791 1.1.2.2 thorpej }
792 1.1.2.2 thorpej ip = pool_get(&cd9660_node_pool, PR_WAITOK);
793 1.1.2.2 thorpej memset((caddr_t)ip, 0, sizeof(struct iso_node));
794 1.1.2.2 thorpej vp->v_data = ip;
795 1.1.2.2 thorpej ip->i_vnode = vp;
796 1.1.2.2 thorpej ip->i_dev = dev;
797 1.1.2.2 thorpej ip->i_number = ino;
798 1.1.2.2 thorpej
799 1.1.2.2 thorpej /*
800 1.1.2.2 thorpej * Put it onto its hash chain and lock it so that other requests for
801 1.1.2.2 thorpej * this inode will block if they arrive while we are sleeping waiting
802 1.1.2.2 thorpej * for old data structures to be purged or for the contents of the
803 1.1.2.2 thorpej * disk portion of this inode to be read.
804 1.1.2.2 thorpej */
805 1.1.2.2 thorpej cd9660_ihashins(ip);
806 1.1.2.2 thorpej
807 1.1.2.2 thorpej if (isodir == 0) {
808 1.1.2.2 thorpej int lbn, off;
809 1.1.2.2 thorpej
810 1.1.2.2 thorpej lbn = lblkno(imp, ino);
811 1.1.2.2 thorpej if (lbn >= imp->volume_space_size) {
812 1.1.2.2 thorpej vput(vp);
813 1.1.2.2 thorpej printf("fhtovp: lbn exceed volume space %d\n", lbn);
814 1.1.2.2 thorpej return (ESTALE);
815 1.1.2.2 thorpej }
816 1.1.2.2 thorpej
817 1.1.2.2 thorpej off = blkoff(imp, ino);
818 1.1.2.2 thorpej if (off + ISO_DIRECTORY_RECORD_SIZE > imp->logical_block_size) {
819 1.1.2.2 thorpej vput(vp);
820 1.1.2.2 thorpej printf("fhtovp: crosses block boundary %d\n",
821 1.1.2.2 thorpej off + ISO_DIRECTORY_RECORD_SIZE);
822 1.1.2.2 thorpej return (ESTALE);
823 1.1.2.2 thorpej }
824 1.1.2.2 thorpej
825 1.1.2.2 thorpej error = bread(imp->im_devvp,
826 1.1.2.2 thorpej lbn << (imp->im_bshift - DEV_BSHIFT),
827 1.1.2.2 thorpej imp->logical_block_size, NOCRED, &bp);
828 1.1.2.2 thorpej if (error) {
829 1.1.2.2 thorpej vput(vp);
830 1.1.2.2 thorpej brelse(bp);
831 1.1.2.2 thorpej printf("fhtovp: bread error %d\n",error);
832 1.1.2.2 thorpej return (error);
833 1.1.2.2 thorpej }
834 1.1.2.2 thorpej isodir = (struct iso_directory_record *)(bp->b_data + off);
835 1.1.2.2 thorpej
836 1.1.2.2 thorpej if (off + isonum_711(isodir->length) >
837 1.1.2.2 thorpej imp->logical_block_size) {
838 1.1.2.2 thorpej vput(vp);
839 1.1.2.2 thorpej if (bp != 0)
840 1.1.2.2 thorpej brelse(bp);
841 1.1.2.2 thorpej printf("fhtovp: directory crosses block boundary %d[off=%d/len=%d]\n",
842 1.1.2.2 thorpej off +isonum_711(isodir->length), off,
843 1.1.2.2 thorpej isonum_711(isodir->length));
844 1.1.2.2 thorpej return (ESTALE);
845 1.1.2.2 thorpej }
846 1.1.2.2 thorpej
847 1.1.2.2 thorpej #if 0
848 1.1.2.2 thorpej if (isonum_733(isodir->extent) +
849 1.1.2.2 thorpej isonum_711(isodir->ext_attr_length) != ifhp->ifid_start) {
850 1.1.2.2 thorpej if (bp != 0)
851 1.1.2.2 thorpej brelse(bp);
852 1.1.2.2 thorpej printf("fhtovp: file start miss %d vs %d\n",
853 1.1.2.2 thorpej isonum_733(isodir->extent) + isonum_711(isodir->ext_attr_length),
854 1.1.2.2 thorpej ifhp->ifid_start);
855 1.1.2.2 thorpej return (ESTALE);
856 1.1.2.2 thorpej }
857 1.1.2.2 thorpej #endif
858 1.1.2.2 thorpej } else
859 1.1.2.2 thorpej bp = 0;
860 1.1.2.2 thorpej
861 1.1.2.2 thorpej ip->i_mnt = imp;
862 1.1.2.2 thorpej ip->i_devvp = imp->im_devvp;
863 1.1.2.2 thorpej VREF(ip->i_devvp);
864 1.1.2.2 thorpej
865 1.1.2.2 thorpej if (relocated) {
866 1.1.2.2 thorpej /*
867 1.1.2.2 thorpej * On relocated directories we must
868 1.1.2.2 thorpej * read the `.' entry out of a dir.
869 1.1.2.2 thorpej */
870 1.1.2.2 thorpej ip->iso_start = ino >> imp->im_bshift;
871 1.1.2.2 thorpej if (bp != 0)
872 1.1.2.2 thorpej brelse(bp);
873 1.1.2.2 thorpej if ((error = VOP_BLKATOFF(vp, (off_t)0, NULL, &bp)) != 0) {
874 1.1.2.2 thorpej vput(vp);
875 1.1.2.2 thorpej return (error);
876 1.1.2.2 thorpej }
877 1.1.2.2 thorpej isodir = (struct iso_directory_record *)bp->b_data;
878 1.1.2.2 thorpej }
879 1.1.2.2 thorpej
880 1.1.2.2 thorpej ip->iso_extent = isonum_733(isodir->extent);
881 1.1.2.2 thorpej ip->i_size = isonum_733(isodir->size);
882 1.1.2.2 thorpej ip->iso_start = isonum_711(isodir->ext_attr_length) + ip->iso_extent;
883 1.1.2.2 thorpej
884 1.1.2.2 thorpej /*
885 1.1.2.2 thorpej * Setup time stamp, attribute
886 1.1.2.2 thorpej */
887 1.1.2.2 thorpej vp->v_type = VNON;
888 1.1.2.2 thorpej switch (imp->iso_ftype) {
889 1.1.2.2 thorpej default: /* ISO_FTYPE_9660 */
890 1.1.2.2 thorpej {
891 1.1.2.2 thorpej struct buf *bp2;
892 1.1.2.2 thorpej int off;
893 1.1.2.2 thorpej if ((imp->im_flags & ISOFSMNT_EXTATT)
894 1.1.2.2 thorpej && (off = isonum_711(isodir->ext_attr_length)))
895 1.1.2.2 thorpej VOP_BLKATOFF(vp, (off_t)-(off << imp->im_bshift), NULL,
896 1.1.2.2 thorpej &bp2);
897 1.1.2.2 thorpej else
898 1.1.2.2 thorpej bp2 = NULL;
899 1.1.2.2 thorpej cd9660_defattr(isodir, ip, bp2);
900 1.1.2.2 thorpej cd9660_deftstamp(isodir, ip, bp2);
901 1.1.2.2 thorpej if (bp2)
902 1.1.2.2 thorpej brelse(bp2);
903 1.1.2.2 thorpej break;
904 1.1.2.2 thorpej }
905 1.1.2.2 thorpej case ISO_FTYPE_RRIP:
906 1.1.2.2 thorpej cd9660_rrip_analyze(isodir, ip, imp);
907 1.1.2.2 thorpej break;
908 1.1.2.2 thorpej }
909 1.1.2.2 thorpej
910 1.1.2.2 thorpej if (bp != 0)
911 1.1.2.2 thorpej brelse(bp);
912 1.1.2.2 thorpej
913 1.1.2.2 thorpej /*
914 1.1.2.2 thorpej * Initialize the associated vnode
915 1.1.2.2 thorpej */
916 1.1.2.2 thorpej switch (vp->v_type = IFTOVT(ip->inode.iso_mode)) {
917 1.1.2.2 thorpej case VFIFO:
918 1.1.2.2 thorpej vp->v_op = cd9660_fifoop_p;
919 1.1.2.2 thorpej break;
920 1.1.2.2 thorpej case VCHR:
921 1.1.2.2 thorpej case VBLK:
922 1.1.2.2 thorpej /*
923 1.1.2.2 thorpej * if device, look at device number table for translation
924 1.1.2.2 thorpej */
925 1.1.2.2 thorpej #ifdef ISODEVMAP
926 1.1.2.2 thorpej if ((dp = iso_dmap(dev, ino, 0)) != NULL)
927 1.1.2.2 thorpej ip->inode.iso_rdev = dp->d_dev;
928 1.1.2.2 thorpej #endif
929 1.1.2.2 thorpej vp->v_op = cd9660_specop_p;
930 1.1.2.2 thorpej if ((nvp = checkalias(vp, ip->inode.iso_rdev, mp)) != NULL) {
931 1.1.2.2 thorpej /*
932 1.1.2.2 thorpej * Discard unneeded vnode, but save its iso_node.
933 1.1.2.2 thorpej * Note that the lock is carried over in the iso_node
934 1.1.2.2 thorpej * to the replacement vnode.
935 1.1.2.2 thorpej */
936 1.1.2.2 thorpej nvp->v_data = vp->v_data;
937 1.1.2.2 thorpej vp->v_data = NULL;
938 1.1.2.2 thorpej VOP_UNLOCK(vp, 0);
939 1.1.2.2 thorpej vp->v_op = spec_vnodeop_p;
940 1.1.2.2 thorpej vrele(vp);
941 1.1.2.2 thorpej vgone(vp);
942 1.1.2.2 thorpej lockmgr(&nvp->v_lock, LK_EXCLUSIVE, &nvp->v_interlock);
943 1.1.2.2 thorpej /*
944 1.1.2.2 thorpej * Reinitialize aliased inode.
945 1.1.2.2 thorpej */
946 1.1.2.2 thorpej vp = nvp;
947 1.1.2.2 thorpej ip->i_vnode = vp;
948 1.1.2.2 thorpej }
949 1.1.2.2 thorpej break;
950 1.1.2.2 thorpej case VLNK:
951 1.1.2.2 thorpej case VNON:
952 1.1.2.2 thorpej case VSOCK:
953 1.1.2.2 thorpej case VDIR:
954 1.1.2.2 thorpej case VBAD:
955 1.1.2.2 thorpej break;
956 1.1.2.2 thorpej case VREG:
957 1.1.2.2 thorpej uvm_vnp_setsize(vp, ip->i_size);
958 1.1.2.2 thorpej break;
959 1.1.2.2 thorpej }
960 1.1.2.2 thorpej
961 1.1.2.2 thorpej if (ip->iso_extent == imp->root_extent)
962 1.1.2.2 thorpej vp->v_flag |= VROOT;
963 1.1.2.2 thorpej
964 1.1.2.2 thorpej /*
965 1.1.2.2 thorpej * XXX need generation number?
966 1.1.2.2 thorpej */
967 1.1.2.2 thorpej
968 1.1.2.2 thorpej genfs_node_init(vp, &cd9660_genfsops);
969 1.1.2.2 thorpej *vpp = vp;
970 1.1.2.2 thorpej return (0);
971 1.1.2.2 thorpej }
972 1.1.2.2 thorpej
973 1.1.2.2 thorpej /*
974 1.1.2.2 thorpej * Vnode pointer to File handle
975 1.1.2.2 thorpej */
976 1.1.2.2 thorpej /* ARGSUSED */
977 1.1.2.2 thorpej int
978 1.1.2.2 thorpej cd9660_vptofh(vp, fhp)
979 1.1.2.2 thorpej struct vnode *vp;
980 1.1.2.2 thorpej struct fid *fhp;
981 1.1.2.2 thorpej {
982 1.1.2.2 thorpej struct iso_node *ip = VTOI(vp);
983 1.1.2.2 thorpej struct ifid *ifhp;
984 1.1.2.2 thorpej
985 1.1.2.2 thorpej ifhp = (struct ifid *)fhp;
986 1.1.2.2 thorpej ifhp->ifid_len = sizeof(struct ifid);
987 1.1.2.2 thorpej
988 1.1.2.2 thorpej ifhp->ifid_ino = ip->i_number;
989 1.1.2.2 thorpej ifhp->ifid_start = ip->iso_start;
990 1.1.2.2 thorpej
991 1.1.2.2 thorpej #ifdef ISOFS_DBG
992 1.1.2.2 thorpej printf("vptofh: ino %d, start %ld\n",
993 1.1.2.2 thorpej ifhp->ifid_ino,ifhp->ifid_start);
994 1.1.2.2 thorpej #endif
995 1.1.2.2 thorpej return 0;
996 1.1.2.2 thorpej }
997 1.1.2.2 thorpej
998 1.1.2.2 thorpej int
999 1.1.2.2 thorpej cd9660_sysctl(name, namelen, oldp, oldlenp, newp, newlen, p)
1000 1.1.2.2 thorpej int *name;
1001 1.1.2.2 thorpej u_int namelen;
1002 1.1.2.2 thorpej void *oldp;
1003 1.1.2.2 thorpej size_t *oldlenp;
1004 1.1.2.2 thorpej void *newp;
1005 1.1.2.2 thorpej size_t newlen;
1006 1.1.2.2 thorpej struct proc *p;
1007 1.1.2.2 thorpej {
1008 1.1.2.2 thorpej return (EOPNOTSUPP);
1009 1.1.2.2 thorpej }
1010