1df8bae1dSRodney W. Grimes /*-
251369649SPedro F. Giffuni * SPDX-License-Identifier: BSD-3-Clause
351369649SPedro F. Giffuni *
4df8bae1dSRodney W. Grimes * Copyright (c) 1994
5df8bae1dSRodney W. Grimes * The Regents of the University of California. All rights reserved.
6df8bae1dSRodney W. Grimes *
7df8bae1dSRodney W. Grimes * This code is derived from software contributed to Berkeley
8df8bae1dSRodney W. Grimes * by Pace Willisson (pace@blitz.com). The Rock Ridge Extension
9df8bae1dSRodney W. Grimes * Support code is derived from software contributed to Berkeley
10df8bae1dSRodney W. Grimes * by Atsushi Murai (amurai@spec.co.jp).
11df8bae1dSRodney W. Grimes *
12df8bae1dSRodney W. Grimes * Redistribution and use in source and binary forms, with or without
13df8bae1dSRodney W. Grimes * modification, are permitted provided that the following conditions
14df8bae1dSRodney W. Grimes * are met:
15df8bae1dSRodney W. Grimes * 1. Redistributions of source code must retain the above copyright
16df8bae1dSRodney W. Grimes * notice, this list of conditions and the following disclaimer.
17df8bae1dSRodney W. Grimes * 2. Redistributions in binary form must reproduce the above copyright
18df8bae1dSRodney W. Grimes * notice, this list of conditions and the following disclaimer in the
19df8bae1dSRodney W. Grimes * documentation and/or other materials provided with the distribution.
20fbbd9655SWarner Losh * 3. Neither the name of the University nor the names of its contributors
21df8bae1dSRodney W. Grimes * may be used to endorse or promote products derived from this software
22df8bae1dSRodney W. Grimes * without specific prior written permission.
23df8bae1dSRodney W. Grimes *
24df8bae1dSRodney W. Grimes * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
25df8bae1dSRodney W. Grimes * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
26df8bae1dSRodney W. Grimes * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
27df8bae1dSRodney W. Grimes * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
28df8bae1dSRodney W. Grimes * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
29df8bae1dSRodney W. Grimes * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
30df8bae1dSRodney W. Grimes * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
31df8bae1dSRodney W. Grimes * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
32df8bae1dSRodney W. Grimes * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
33df8bae1dSRodney W. Grimes * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
34df8bae1dSRodney W. Grimes * SUCH DAMAGE.
35df8bae1dSRodney W. Grimes */
36df8bae1dSRodney W. Grimes
37df8bae1dSRodney W. Grimes #include <sys/param.h>
38df8bae1dSRodney W. Grimes #include <sys/systm.h>
39df8bae1dSRodney W. Grimes #include <sys/namei.h>
40acd3428bSRobert Watson #include <sys/priv.h>
41df8bae1dSRodney W. Grimes #include <sys/proc.h>
42df8bae1dSRodney W. Grimes #include <sys/kernel.h>
43df8bae1dSRodney W. Grimes #include <sys/vnode.h>
44df8bae1dSRodney W. Grimes #include <sys/mount.h>
459626b608SPoul-Henning Kamp #include <sys/bio.h>
46df8bae1dSRodney W. Grimes #include <sys/buf.h>
475a9714deSJoerg Wunsch #include <sys/cdio.h>
485a9714deSJoerg Wunsch #include <sys/conf.h>
493ac4d1efSBruce Evans #include <sys/fcntl.h>
50df8bae1dSRodney W. Grimes #include <sys/malloc.h>
51996c772fSJohn Dyson #include <sys/stat.h>
5244e568e2SDaniel C. Sobral #include <sys/syslog.h>
53c4f02a89SMax Khon #include <sys/iconv.h>
54df8bae1dSRodney W. Grimes
55a8d36d0dSCraig Rodrigues #include <fs/cd9660/iso.h>
56a8d36d0dSCraig Rodrigues #include <fs/cd9660/iso_rrip.h>
57a8d36d0dSCraig Rodrigues #include <fs/cd9660/cd9660_node.h>
58a8d36d0dSCraig Rodrigues #include <fs/cd9660/cd9660_mount.h>
59df8bae1dSRodney W. Grimes
60bf7e2ae1SPoul-Henning Kamp #include <geom/geom.h>
61bf7e2ae1SPoul-Henning Kamp #include <geom/geom_vfs.h>
62bf7e2ae1SPoul-Henning Kamp
635bb84bc8SRobert Watson MALLOC_DEFINE(M_ISOFSMNT, "isofs_mount", "ISOFS mount structure");
645bb84bc8SRobert Watson MALLOC_DEFINE(M_ISOFSNODE, "isofs_node", "ISOFS vnode private part");
65605e9724SPoul-Henning Kamp
66c4f02a89SMax Khon struct iconv_functions *cd9660_iconv = NULL;
67c4f02a89SMax Khon
6820a92a18SPoul-Henning Kamp static vfs_mount_t cd9660_mount;
6920a92a18SPoul-Henning Kamp static vfs_cmount_t cd9660_cmount;
709bf1a756SPoul-Henning Kamp static vfs_unmount_t cd9660_unmount;
719bf1a756SPoul-Henning Kamp static vfs_root_t cd9660_root;
729bf1a756SPoul-Henning Kamp static vfs_statfs_t cd9660_statfs;
739bf1a756SPoul-Henning Kamp static vfs_vget_t cd9660_vget;
749bf1a756SPoul-Henning Kamp static vfs_fhtovp_t cd9660_fhtovp;
75605e9724SPoul-Henning Kamp
76605e9724SPoul-Henning Kamp static struct vfsops cd9660_vfsops = {
777652131bSPoul-Henning Kamp .vfs_fhtovp = cd9660_fhtovp,
7820a92a18SPoul-Henning Kamp .vfs_mount = cd9660_mount,
7920a92a18SPoul-Henning Kamp .vfs_cmount = cd9660_cmount,
807652131bSPoul-Henning Kamp .vfs_root = cd9660_root,
817652131bSPoul-Henning Kamp .vfs_statfs = cd9660_statfs,
827652131bSPoul-Henning Kamp .vfs_unmount = cd9660_unmount,
837652131bSPoul-Henning Kamp .vfs_vget = cd9660_vget,
84df8bae1dSRodney W. Grimes };
858994ca3cSBruce Evans VFS_SET(cd9660_vfsops, cd9660, VFCF_READONLY);
86a7436e68SMaxim Sobolev MODULE_VERSION(cd9660, 1);
87c901836cSGarrett Wollman
88bedd4620SMateusz Guzik static int cd9660_vfs_hash_cmp(struct vnode *vp, void *pino);
890d7935fdSAttilio Rao static int iso_mountfs(struct vnode *devvp, struct mount *mp);
90df8bae1dSRodney W. Grimes
91df8bae1dSRodney W. Grimes /*
92df8bae1dSRodney W. Grimes * VFS Operations.
93df8bae1dSRodney W. Grimes */
9420a92a18SPoul-Henning Kamp
95605e9724SPoul-Henning Kamp static int
cd9660_cmount(struct mntarg * ma,void * data,uint64_t flags)96cc672d35SKirk McKusick cd9660_cmount(struct mntarg *ma, void *data, uint64_t flags)
9720a92a18SPoul-Henning Kamp {
9820a92a18SPoul-Henning Kamp struct iso_args args;
9920a92a18SPoul-Henning Kamp int error;
10020a92a18SPoul-Henning Kamp
10120a92a18SPoul-Henning Kamp error = copyin(data, &args, sizeof args);
10220a92a18SPoul-Henning Kamp if (error)
10320a92a18SPoul-Henning Kamp return (error);
10420a92a18SPoul-Henning Kamp
10520a92a18SPoul-Henning Kamp ma = mount_argsu(ma, "from", args.fspec, MAXPATHLEN);
1061f7104d7SRick Macklem ma = mount_arg(ma, "export", &args.export, sizeof(args.export));
10782f2275bSRicardo Branco if (args.flags & ISOFSMNT_UID)
10882f2275bSRicardo Branco ma = mount_argf(ma, "uid", "%d", args.uid);
10982f2275bSRicardo Branco if (args.flags & ISOFSMNT_GID)
11082f2275bSRicardo Branco ma = mount_argf(ma, "gid", "%d", args.gid);
11182f2275bSRicardo Branco ma = mount_argf(ma, "mask", "%d", args.fmask);
11282f2275bSRicardo Branco ma = mount_argf(ma, "dirmask", "%d", args.dmask);
11320a92a18SPoul-Henning Kamp ma = mount_argsu(ma, "cs_disk", args.cs_disk, 64);
11420a92a18SPoul-Henning Kamp ma = mount_argsu(ma, "cs_local", args.cs_local, 64);
11520a92a18SPoul-Henning Kamp ma = mount_argf(ma, "ssector", "%u", args.ssector);
11620a92a18SPoul-Henning Kamp ma = mount_argb(ma, !(args.flags & ISOFSMNT_NORRIP), "norrip");
11720a92a18SPoul-Henning Kamp ma = mount_argb(ma, args.flags & ISOFSMNT_GENS, "nogens");
11820a92a18SPoul-Henning Kamp ma = mount_argb(ma, args.flags & ISOFSMNT_EXTATT, "noextatt");
11920a92a18SPoul-Henning Kamp ma = mount_argb(ma, !(args.flags & ISOFSMNT_NOJOLIET), "nojoliet");
12020a92a18SPoul-Henning Kamp ma = mount_argb(ma,
12120a92a18SPoul-Henning Kamp args.flags & ISOFSMNT_BROKENJOLIET, "nobrokenjoliet");
12220a92a18SPoul-Henning Kamp ma = mount_argb(ma, args.flags & ISOFSMNT_KICONV, "nokiconv");
12320a92a18SPoul-Henning Kamp
12420a92a18SPoul-Henning Kamp error = kernel_mount(ma, flags);
12520a92a18SPoul-Henning Kamp
12620a92a18SPoul-Henning Kamp return (error);
12720a92a18SPoul-Henning Kamp }
12820a92a18SPoul-Henning Kamp
12920a92a18SPoul-Henning Kamp static int
cd9660_mount(struct mount * mp)130dfd233edSAttilio Rao cd9660_mount(struct mount *mp)
131df8bae1dSRodney W. Grimes {
132df8bae1dSRodney W. Grimes struct vnode *devvp;
133dfd233edSAttilio Rao struct thread *td;
13420a92a18SPoul-Henning Kamp char *fspec;
1355eb304a9SCraig Rodrigues int error;
13615bc6b2bSEdward Tomasz Napierala accmode_t accmode;
1375e8c582aSPoul-Henning Kamp struct nameidata ndp;
138f7a3729cSKevin Lo struct iso_mnt *imp = NULL;
139df8bae1dSRodney W. Grimes
140dfd233edSAttilio Rao td = curthread;
141dfd233edSAttilio Rao
142c583f369SCraig Rodrigues /*
143c583f369SCraig Rodrigues * Unconditionally mount as read-only.
144c583f369SCraig Rodrigues */
1455da56ddbSTor Egge MNT_ILOCK(mp);
146c583f369SCraig Rodrigues mp->mnt_flag |= MNT_RDONLY;
1475da56ddbSTor Egge MNT_IUNLOCK(mp);
148df8bae1dSRodney W. Grimes
14920a92a18SPoul-Henning Kamp fspec = vfs_getopts(mp->mnt_optnew, "from", &error);
15020a92a18SPoul-Henning Kamp if (error)
15120a92a18SPoul-Henning Kamp return (error);
15220a92a18SPoul-Henning Kamp
15320a92a18SPoul-Henning Kamp imp = VFSTOISOFS(mp);
1545eb304a9SCraig Rodrigues
155df8bae1dSRodney W. Grimes if (mp->mnt_flag & MNT_UPDATE) {
1565eb304a9SCraig Rodrigues if (vfs_flagopt(mp->mnt_optnew, "export", NULL, 0))
1575eb304a9SCraig Rodrigues return (0);
15820a92a18SPoul-Henning Kamp }
159df8bae1dSRodney W. Grimes /*
160df8bae1dSRodney W. Grimes * Not an update, or updating the name: look up the name
161df8bae1dSRodney W. Grimes * and verify that it refers to a sensible block device.
162df8bae1dSRodney W. Grimes */
1637e1d3eefSMateusz Guzik NDINIT(&ndp, LOOKUP, FOLLOW | LOCKLEAF, UIO_SYSSPACE, fspec);
1645e8c582aSPoul-Henning Kamp if ((error = namei(&ndp)))
165df8bae1dSRodney W. Grimes return (error);
166bb92cd7bSMateusz Guzik NDFREE_PNBUF(&ndp);
1675e8c582aSPoul-Henning Kamp devvp = ndp.ni_vp;
168df8bae1dSRodney W. Grimes
1697ad2a82dSMateusz Guzik if (!vn_isdisk_error(devvp, &error)) {
17077ddca67SJohn Baldwin vput(devvp);
171ba4ad1fcSPoul-Henning Kamp return (error);
172df8bae1dSRodney W. Grimes }
173a031dfd5SGuido van Rooij
174a031dfd5SGuido van Rooij /*
175904efa5aSPoul-Henning Kamp * Verify that user has necessary permissions on the device,
176904efa5aSPoul-Henning Kamp * or has superuser abilities
177a031dfd5SGuido van Rooij */
17815bc6b2bSEdward Tomasz Napierala accmode = VREAD;
17915bc6b2bSEdward Tomasz Napierala error = VOP_ACCESS(devvp, accmode, td->td_ucred, td);
180904efa5aSPoul-Henning Kamp if (error)
181acd3428bSRobert Watson error = priv_check(td, PRIV_VFS_MOUNT_PERM);
182904efa5aSPoul-Henning Kamp if (error) {
183a031dfd5SGuido van Rooij vput(devvp);
184a031dfd5SGuido van Rooij return (error);
185a031dfd5SGuido van Rooij }
186a031dfd5SGuido van Rooij
18781bca6ddSKATO Takenori if ((mp->mnt_flag & MNT_UPDATE) == 0) {
1880d7935fdSAttilio Rao error = iso_mountfs(devvp, mp);
18977ddca67SJohn Baldwin if (error)
19077ddca67SJohn Baldwin vrele(devvp);
19181bca6ddSKATO Takenori } else {
192df8bae1dSRodney W. Grimes if (devvp != imp->im_devvp)
193df8bae1dSRodney W. Grimes error = EINVAL; /* needs translation */
19477ddca67SJohn Baldwin vput(devvp);
195df8bae1dSRodney W. Grimes }
19677ddca67SJohn Baldwin if (error)
19777ddca67SJohn Baldwin return (error);
19820a92a18SPoul-Henning Kamp vfs_mountedfrom(mp, fspec);
19977ddca67SJohn Baldwin return (0);
200df8bae1dSRodney W. Grimes }
201df8bae1dSRodney W. Grimes
202df8bae1dSRodney W. Grimes /*
203df8bae1dSRodney W. Grimes * Common code for mount and mountroot
204df8bae1dSRodney W. Grimes */
20526f9a767SRodney W. Grimes static int
iso_mountfs(struct vnode * devvp,struct mount * mp)206a5f59e85SEd Maste iso_mountfs(struct vnode *devvp, struct mount *mp)
207df8bae1dSRodney W. Grimes {
2083d74f18bSKevin Lo struct iso_mnt *isomp = NULL;
209df8bae1dSRodney W. Grimes struct buf *bp = NULL;
21044e568e2SDaniel C. Sobral struct buf *pribp = NULL, *supbp = NULL;
2110b2ab5ecSJohn Baldwin struct cdev *dev;
2121295d82eSGary Palmer int error = EINVAL;
213988fa8efSJoerg Wunsch int high_sierra = 0;
214df8bae1dSRodney W. Grimes int iso_bsize;
215df8bae1dSRodney W. Grimes int iso_blknum;
21644e568e2SDaniel C. Sobral int joliet_level;
2179a81ba0fSStephen J. Kiernan int isverified = 0;
218f7a3729cSKevin Lo struct iso_volume_descriptor *vdp = NULL;
21944e568e2SDaniel C. Sobral struct iso_primary_descriptor *pri = NULL;
22044e568e2SDaniel C. Sobral struct iso_sierra_primary_descriptor *pri_sierra = NULL;
22144e568e2SDaniel C. Sobral struct iso_supplementary_descriptor *sup = NULL;
222df8bae1dSRodney W. Grimes struct iso_directory_record *rootp;
22320a92a18SPoul-Henning Kamp int logical_block_size, ssector;
224bf7e2ae1SPoul-Henning Kamp struct g_consumer *cp;
225bf7e2ae1SPoul-Henning Kamp struct bufobj *bo;
22620a92a18SPoul-Henning Kamp char *cs_local, *cs_disk;
22782f2275bSRicardo Branco int v;
228df8bae1dSRodney W. Grimes
2290b2ab5ecSJohn Baldwin dev = devvp->v_rdev;
2300b2ab5ecSJohn Baldwin dev_ref(dev);
231bf7e2ae1SPoul-Henning Kamp g_topology_lock();
232bf7e2ae1SPoul-Henning Kamp error = g_vfs_open(devvp, &cp, "cd9660", 0);
2339a81ba0fSStephen J. Kiernan if (error == 0)
2349a81ba0fSStephen J. Kiernan g_getattr("MNT::verified", cp, &isverified);
235bf7e2ae1SPoul-Henning Kamp g_topology_unlock();
236b249ce48SMateusz Guzik VOP_UNLOCK(devvp);
237698f9cf8SPoul-Henning Kamp if (error)
2380b2ab5ecSJohn Baldwin goto out;
2390508986cSBruce Evans if (devvp->v_rdev->si_iosize_max != 0)
2400508986cSBruce Evans mp->mnt_iosize_max = devvp->v_rdev->si_iosize_max;
241cd853791SKonstantin Belousov if (mp->mnt_iosize_max > maxphys)
242cd853791SKonstantin Belousov mp->mnt_iosize_max = maxphys;
243698f9cf8SPoul-Henning Kamp
244bf7e2ae1SPoul-Henning Kamp bo = &devvp->v_bufobj;
245df8bae1dSRodney W. Grimes
246df8bae1dSRodney W. Grimes /* This is the "logical sector size". The standard says this
247df8bae1dSRodney W. Grimes * should be 2048 or the physical sector size on the device,
248b137e1c8SCraig Rodrigues * whichever is greater.
249df8bae1dSRodney W. Grimes */
250b137e1c8SCraig Rodrigues if ((ISO_DEFAULT_BLOCK_SIZE % cp->provider->sectorsize) != 0) {
2510b2ab5ecSJohn Baldwin error = EINVAL;
2520b2ab5ecSJohn Baldwin goto out;
253b137e1c8SCraig Rodrigues }
254b137e1c8SCraig Rodrigues
255b137e1c8SCraig Rodrigues iso_bsize = cp->provider->sectorsize;
256df8bae1dSRodney W. Grimes
25744e568e2SDaniel C. Sobral joliet_level = 0;
25820a92a18SPoul-Henning Kamp if (1 != vfs_scanopt(mp->mnt_optnew, "ssector", "%d", &ssector))
25920a92a18SPoul-Henning Kamp ssector = 0;
26020a92a18SPoul-Henning Kamp for (iso_blknum = 16 + ssector;
26120a92a18SPoul-Henning Kamp iso_blknum < 100 + ssector;
2623e1cf431SJoerg Wunsch iso_blknum++) {
263b137e1c8SCraig Rodrigues if ((error = bread(devvp, iso_blknum * btodb(ISO_DEFAULT_BLOCK_SIZE),
264d254af07SMatthew Dillon iso_bsize, NOCRED, &bp)) != 0)
265df8bae1dSRodney W. Grimes goto out;
266df8bae1dSRodney W. Grimes
267996c772fSJohn Dyson vdp = (struct iso_volume_descriptor *)bp->b_data;
268df8bae1dSRodney W. Grimes if (bcmp (vdp->id, ISO_STANDARD_ID, sizeof vdp->id) != 0) {
269988fa8efSJoerg Wunsch if (bcmp (vdp->id_sierra, ISO_SIERRA_ID,
270bb5d3b71SWarner Losh sizeof vdp->id_sierra) != 0) {
271988fa8efSJoerg Wunsch error = EINVAL;
272988fa8efSJoerg Wunsch goto out;
273988fa8efSJoerg Wunsch } else
274988fa8efSJoerg Wunsch high_sierra = 1;
275988fa8efSJoerg Wunsch }
27644e568e2SDaniel C. Sobral switch (isonum_711 (high_sierra? vdp->type_sierra: vdp->type)){
27744e568e2SDaniel C. Sobral case ISO_VD_PRIMARY:
27844e568e2SDaniel C. Sobral if (pribp == NULL) {
27944e568e2SDaniel C. Sobral pribp = bp;
28044e568e2SDaniel C. Sobral bp = NULL;
281df8bae1dSRodney W. Grimes pri = (struct iso_primary_descriptor *)vdp;
28244e568e2SDaniel C. Sobral pri_sierra =
28344e568e2SDaniel C. Sobral (struct iso_sierra_primary_descriptor *)vdp;
28444e568e2SDaniel C. Sobral }
28544e568e2SDaniel C. Sobral break;
28644e568e2SDaniel C. Sobral
28744e568e2SDaniel C. Sobral case ISO_VD_SUPPLEMENTARY:
28844e568e2SDaniel C. Sobral if (supbp == NULL) {
28944e568e2SDaniel C. Sobral supbp = bp;
29044e568e2SDaniel C. Sobral bp = NULL;
29144e568e2SDaniel C. Sobral sup = (struct iso_supplementary_descriptor *)vdp;
29244e568e2SDaniel C. Sobral
29314dcd40fSPeter Grehan if (!vfs_flagopt(mp->mnt_optnew, "nojoliet", NULL, 0)) {
29444e568e2SDaniel C. Sobral if (bcmp(sup->escape, "%/@", 3) == 0)
29544e568e2SDaniel C. Sobral joliet_level = 1;
29644e568e2SDaniel C. Sobral if (bcmp(sup->escape, "%/C", 3) == 0)
29744e568e2SDaniel C. Sobral joliet_level = 2;
29844e568e2SDaniel C. Sobral if (bcmp(sup->escape, "%/E", 3) == 0)
29944e568e2SDaniel C. Sobral joliet_level = 3;
30044e568e2SDaniel C. Sobral
301c35e8e54SBoris Popov if ((isonum_711 (sup->flags) & 1) &&
30220a92a18SPoul-Henning Kamp !vfs_flagopt(mp->mnt_optnew, "brokenjoliet", NULL, 0))
30344e568e2SDaniel C. Sobral joliet_level = 0;
30444e568e2SDaniel C. Sobral }
30544e568e2SDaniel C. Sobral }
30644e568e2SDaniel C. Sobral break;
30744e568e2SDaniel C. Sobral
30844e568e2SDaniel C. Sobral case ISO_VD_END:
30944e568e2SDaniel C. Sobral goto vd_end;
31044e568e2SDaniel C. Sobral
31144e568e2SDaniel C. Sobral default:
31244e568e2SDaniel C. Sobral break;
31344e568e2SDaniel C. Sobral }
314e296c1dfSPedro F. Giffuni if (bp != NULL) {
31544e568e2SDaniel C. Sobral brelse(bp);
31644e568e2SDaniel C. Sobral bp = NULL;
31744e568e2SDaniel C. Sobral }
31844e568e2SDaniel C. Sobral }
31944e568e2SDaniel C. Sobral vd_end:
320e296c1dfSPedro F. Giffuni if (bp != NULL) {
32144e568e2SDaniel C. Sobral brelse(bp);
32244e568e2SDaniel C. Sobral bp = NULL;
32344e568e2SDaniel C. Sobral }
32444e568e2SDaniel C. Sobral
32544e568e2SDaniel C. Sobral if (pri == NULL) {
32644e568e2SDaniel C. Sobral error = EINVAL;
32744e568e2SDaniel C. Sobral goto out;
32844e568e2SDaniel C. Sobral }
329df8bae1dSRodney W. Grimes
330988fa8efSJoerg Wunsch logical_block_size =
331988fa8efSJoerg Wunsch isonum_723 (high_sierra?
332988fa8efSJoerg Wunsch pri_sierra->logical_block_size:
333988fa8efSJoerg Wunsch pri->logical_block_size);
334df8bae1dSRodney W. Grimes
335df8bae1dSRodney W. Grimes if (logical_block_size < DEV_BSIZE || logical_block_size > MAXBSIZE
336df8bae1dSRodney W. Grimes || (logical_block_size & (logical_block_size - 1)) != 0) {
337df8bae1dSRodney W. Grimes error = EINVAL;
338df8bae1dSRodney W. Grimes goto out;
339df8bae1dSRodney W. Grimes }
340df8bae1dSRodney W. Grimes
3414af849d7SJohn Baldwin if (logical_block_size < cp->provider->sectorsize) {
3424af849d7SJohn Baldwin printf("cd9660: Unsupported logical block size %u\n",
3434af849d7SJohn Baldwin logical_block_size);
3444af849d7SJohn Baldwin error = EINVAL;
3454af849d7SJohn Baldwin goto out;
3464af849d7SJohn Baldwin }
3474af849d7SJohn Baldwin
348988fa8efSJoerg Wunsch rootp = (struct iso_directory_record *)
349988fa8efSJoerg Wunsch (high_sierra?
350988fa8efSJoerg Wunsch pri_sierra->root_directory_record:
351988fa8efSJoerg Wunsch pri->root_directory_record);
352df8bae1dSRodney W. Grimes
353a163d034SWarner Losh isomp = malloc(sizeof *isomp, M_ISOFSMNT, M_WAITOK | M_ZERO);
354bf7e2ae1SPoul-Henning Kamp isomp->im_cp = cp;
355bf7e2ae1SPoul-Henning Kamp isomp->im_bo = bo;
356df8bae1dSRodney W. Grimes isomp->logical_block_size = logical_block_size;
357988fa8efSJoerg Wunsch isomp->volume_space_size =
358988fa8efSJoerg Wunsch isonum_733 (high_sierra?
359988fa8efSJoerg Wunsch pri_sierra->volume_space_size:
360988fa8efSJoerg Wunsch pri->volume_space_size);
36144e568e2SDaniel C. Sobral isomp->joliet_level = 0;
3627d322c73SJoerg Wunsch /*
3637d322c73SJoerg Wunsch * Since an ISO9660 multi-session CD can also access previous
3647d322c73SJoerg Wunsch * sessions, we have to include them into the space consider-
3657d322c73SJoerg Wunsch * ations. This doesn't yield a very accurate number since
3667d322c73SJoerg Wunsch * parts of the old sessions might be inaccessible now, but we
3677d322c73SJoerg Wunsch * can't do much better. This is also important for the NFS
3687d322c73SJoerg Wunsch * filehandle validation.
3697d322c73SJoerg Wunsch */
37020a92a18SPoul-Henning Kamp isomp->volume_space_size += ssector;
371a6274b81SEd Maste memcpy(isomp->root, rootp, sizeof isomp->root);
372df8bae1dSRodney W. Grimes isomp->root_extent = isonum_733 (rootp->extent);
373df8bae1dSRodney W. Grimes isomp->root_size = isonum_733 (rootp->size);
374df8bae1dSRodney W. Grimes
375df8bae1dSRodney W. Grimes isomp->im_bmask = logical_block_size - 1;
37644e568e2SDaniel C. Sobral isomp->im_bshift = ffs(logical_block_size) - 1;
377df8bae1dSRodney W. Grimes
37844e568e2SDaniel C. Sobral pribp->b_flags |= B_AGE;
37944e568e2SDaniel C. Sobral brelse(pribp);
38044e568e2SDaniel C. Sobral pribp = NULL;
381c9b24e38SJohn-Mark Gurney rootp = NULL;
382c9b24e38SJohn-Mark Gurney pri = NULL;
383c9b24e38SJohn-Mark Gurney pri_sierra = NULL;
384df8bae1dSRodney W. Grimes
38577465d93SAlfred Perlstein mp->mnt_data = isomp;
386939cb752SBruce Evans mp->mnt_stat.f_fsid.val[0] = dev2udev(dev);
387996c772fSJohn Dyson mp->mnt_stat.f_fsid.val[1] = mp->mnt_vfc->vfc_typenum;
3885da56ddbSTor Egge MNT_ILOCK(mp);
3899a81ba0fSStephen J. Kiernan if (isverified)
3909a81ba0fSStephen J. Kiernan mp->mnt_flag |= MNT_VERIFIED;
391df8bae1dSRodney W. Grimes mp->mnt_flag |= MNT_LOCAL;
392bc2258daSAttilio Rao mp->mnt_kern_flag |= MNTK_LOOKUP_SHARED | MNTK_EXTENDED_SHARED;
3935da56ddbSTor Egge MNT_IUNLOCK(mp);
394df8bae1dSRodney W. Grimes isomp->im_mountp = mp;
395df8bae1dSRodney W. Grimes isomp->im_dev = dev;
396df8bae1dSRodney W. Grimes isomp->im_devvp = devvp;
397*c1ad5b4bSJohn Baldwin isomp->im_fmask = isomp->im_dmask = ALLPERMS;
398df8bae1dSRodney W. Grimes
39914dcd40fSPeter Grehan vfs_flagopt(mp->mnt_optnew, "norrip", &isomp->im_flags, ISOFSMNT_NORRIP);
40020a92a18SPoul-Henning Kamp vfs_flagopt(mp->mnt_optnew, "gens", &isomp->im_flags, ISOFSMNT_GENS);
40120a92a18SPoul-Henning Kamp vfs_flagopt(mp->mnt_optnew, "extatt", &isomp->im_flags, ISOFSMNT_EXTATT);
40214dcd40fSPeter Grehan vfs_flagopt(mp->mnt_optnew, "nojoliet", &isomp->im_flags, ISOFSMNT_NOJOLIET);
40320a92a18SPoul-Henning Kamp vfs_flagopt(mp->mnt_optnew, "kiconv", &isomp->im_flags, ISOFSMNT_KICONV);
40414dcd40fSPeter Grehan
40582f2275bSRicardo Branco if (vfs_scanopt(mp->mnt_optnew, "uid", "%d", &v) == 1) {
40682f2275bSRicardo Branco isomp->im_flags |= ISOFSMNT_UID;
40782f2275bSRicardo Branco isomp->im_uid = v;
40882f2275bSRicardo Branco }
40982f2275bSRicardo Branco if (vfs_scanopt(mp->mnt_optnew, "gid", "%d", &v) == 1) {
41082f2275bSRicardo Branco isomp->im_flags |= ISOFSMNT_GID;
41182f2275bSRicardo Branco isomp->im_gid = v;
41282f2275bSRicardo Branco }
41382f2275bSRicardo Branco if (vfs_scanopt(mp->mnt_optnew, "mask", "%d", &v) == 1) {
41482f2275bSRicardo Branco isomp->im_fmask &= v;
41582f2275bSRicardo Branco }
41682f2275bSRicardo Branco if (vfs_scanopt(mp->mnt_optnew, "dirmask", "%d", &v) == 1) {
41782f2275bSRicardo Branco isomp->im_dmask &= v;
41882f2275bSRicardo Branco }
41982f2275bSRicardo Branco
42014dcd40fSPeter Grehan /* Check the Rock Ridge Extension support */
42114dcd40fSPeter Grehan if (!(isomp->im_flags & ISOFSMNT_NORRIP)) {
422fb180e21SJohn-Mark Gurney if ((error = bread(isomp->im_devvp, (isomp->root_extent +
423fb180e21SJohn-Mark Gurney isonum_711(((struct iso_directory_record *)isomp->root)->
424fb180e21SJohn-Mark Gurney ext_attr_length)) << (isomp->im_bshift - DEV_BSHIFT),
425d254af07SMatthew Dillon isomp->logical_block_size, NOCRED, &bp)) != 0)
426df8bae1dSRodney W. Grimes goto out;
427df8bae1dSRodney W. Grimes
428996c772fSJohn Dyson rootp = (struct iso_directory_record *)bp->b_data;
429df8bae1dSRodney W. Grimes
430df8bae1dSRodney W. Grimes if ((isomp->rr_skip = cd9660_rrip_offset(rootp,isomp)) < 0) {
43120a92a18SPoul-Henning Kamp isomp->im_flags |= ISOFSMNT_NORRIP;
432df8bae1dSRodney W. Grimes } else {
43320a92a18SPoul-Henning Kamp isomp->im_flags &= ~ISOFSMNT_GENS;
434df8bae1dSRodney W. Grimes }
435df8bae1dSRodney W. Grimes
436df8bae1dSRodney W. Grimes /*
437df8bae1dSRodney W. Grimes * The contents are valid,
438df8bae1dSRodney W. Grimes * but they will get reread as part of another vnode, so...
439df8bae1dSRodney W. Grimes */
440df8bae1dSRodney W. Grimes bp->b_flags |= B_AGE;
441df8bae1dSRodney W. Grimes brelse(bp);
442df8bae1dSRodney W. Grimes bp = NULL;
443c9b24e38SJohn-Mark Gurney rootp = NULL;
444df8bae1dSRodney W. Grimes }
445c4f02a89SMax Khon
446c4f02a89SMax Khon if (isomp->im_flags & ISOFSMNT_KICONV && cd9660_iconv) {
44720a92a18SPoul-Henning Kamp cs_local = vfs_getopts(mp->mnt_optnew, "cs_local", &error);
44820a92a18SPoul-Henning Kamp if (error)
44920a92a18SPoul-Henning Kamp goto out;
45020a92a18SPoul-Henning Kamp cs_disk = vfs_getopts(mp->mnt_optnew, "cs_disk", &error);
45120a92a18SPoul-Henning Kamp if (error)
45220a92a18SPoul-Henning Kamp goto out;
45320a92a18SPoul-Henning Kamp cd9660_iconv->open(cs_local, cs_disk, &isomp->im_d2l);
45420a92a18SPoul-Henning Kamp cd9660_iconv->open(cs_disk, cs_local, &isomp->im_l2d);
455c4f02a89SMax Khon } else {
456c4f02a89SMax Khon isomp->im_d2l = NULL;
457c4f02a89SMax Khon isomp->im_l2d = NULL;
458c4f02a89SMax Khon }
459988fa8efSJoerg Wunsch
46044e568e2SDaniel C. Sobral if (high_sierra) {
461988fa8efSJoerg Wunsch /* this effectively ignores all the mount flags */
4625d0c377bSRobert Watson if (bootverbose)
46344e568e2SDaniel C. Sobral log(LOG_INFO, "cd9660: High Sierra Format\n");
464988fa8efSJoerg Wunsch isomp->iso_ftype = ISO_FTYPE_HIGH_SIERRA;
46544e568e2SDaniel C. Sobral } else
466df8bae1dSRodney W. Grimes switch (isomp->im_flags&(ISOFSMNT_NORRIP|ISOFSMNT_GENS)) {
467df8bae1dSRodney W. Grimes default:
468df8bae1dSRodney W. Grimes isomp->iso_ftype = ISO_FTYPE_DEFAULT;
469df8bae1dSRodney W. Grimes break;
470df8bae1dSRodney W. Grimes case ISOFSMNT_GENS|ISOFSMNT_NORRIP:
471df8bae1dSRodney W. Grimes isomp->iso_ftype = ISO_FTYPE_9660;
472df8bae1dSRodney W. Grimes break;
473df8bae1dSRodney W. Grimes case 0:
4745d0c377bSRobert Watson if (bootverbose)
47544e568e2SDaniel C. Sobral log(LOG_INFO, "cd9660: RockRidge Extension\n");
476df8bae1dSRodney W. Grimes isomp->iso_ftype = ISO_FTYPE_RRIP;
477df8bae1dSRodney W. Grimes break;
478df8bae1dSRodney W. Grimes }
479df8bae1dSRodney W. Grimes
48044e568e2SDaniel C. Sobral /* Decide whether to use the Joliet descriptor */
48144e568e2SDaniel C. Sobral
48244e568e2SDaniel C. Sobral if (isomp->iso_ftype != ISO_FTYPE_RRIP && joliet_level) {
4835d0c377bSRobert Watson if (bootverbose)
4845d0c377bSRobert Watson log(LOG_INFO, "cd9660: Joliet Extension (Level %d)\n",
4855d0c377bSRobert Watson joliet_level);
48644e568e2SDaniel C. Sobral rootp = (struct iso_directory_record *)
48744e568e2SDaniel C. Sobral sup->root_directory_record;
488a6274b81SEd Maste memcpy(isomp->root, rootp, sizeof isomp->root);
48944e568e2SDaniel C. Sobral isomp->root_extent = isonum_733 (rootp->extent);
49044e568e2SDaniel C. Sobral isomp->root_size = isonum_733 (rootp->size);
49144e568e2SDaniel C. Sobral isomp->joliet_level = joliet_level;
49244e568e2SDaniel C. Sobral supbp->b_flags |= B_AGE;
49344e568e2SDaniel C. Sobral }
49444e568e2SDaniel C. Sobral
49544e568e2SDaniel C. Sobral if (supbp) {
49644e568e2SDaniel C. Sobral brelse(supbp);
49744e568e2SDaniel C. Sobral supbp = NULL;
498c9b24e38SJohn-Mark Gurney sup = NULL;
49944e568e2SDaniel C. Sobral }
50044e568e2SDaniel C. Sobral
501df8bae1dSRodney W. Grimes return 0;
502df8bae1dSRodney W. Grimes out:
503e296c1dfSPedro F. Giffuni if (bp != NULL)
504df8bae1dSRodney W. Grimes brelse(bp);
505e296c1dfSPedro F. Giffuni if (pribp != NULL)
50644e568e2SDaniel C. Sobral brelse(pribp);
507e296c1dfSPedro F. Giffuni if (supbp != NULL)
50844e568e2SDaniel C. Sobral brelse(supbp);
509bf7e2ae1SPoul-Henning Kamp if (cp != NULL) {
510bf7e2ae1SPoul-Henning Kamp g_topology_lock();
5110d7935fdSAttilio Rao g_vfs_close(cp);
512bf7e2ae1SPoul-Henning Kamp g_topology_unlock();
513bf7e2ae1SPoul-Henning Kamp }
514df8bae1dSRodney W. Grimes if (isomp) {
515c225ad03SKevin Lo free(isomp, M_ISOFSMNT);
51677465d93SAlfred Perlstein mp->mnt_data = NULL;
517df8bae1dSRodney W. Grimes }
5180b2ab5ecSJohn Baldwin dev_rel(dev);
519df8bae1dSRodney W. Grimes return error;
520df8bae1dSRodney W. Grimes }
521df8bae1dSRodney W. Grimes
522df8bae1dSRodney W. Grimes /*
523df8bae1dSRodney W. Grimes * unmount system call
524df8bae1dSRodney W. Grimes */
525605e9724SPoul-Henning Kamp static int
cd9660_unmount(struct mount * mp,int mntflags)526a5f59e85SEd Maste cd9660_unmount(struct mount *mp, int mntflags)
527df8bae1dSRodney W. Grimes {
528bffd1b7aSPoul-Henning Kamp struct iso_mnt *isomp;
5291295d82eSGary Palmer int error, flags = 0;
530df8bae1dSRodney W. Grimes
531996c772fSJohn Dyson if (mntflags & MNT_FORCE)
532df8bae1dSRodney W. Grimes flags |= FORCECLOSE;
533dfd233edSAttilio Rao if ((error = vflush(mp, 0, flags, curthread)))
534df8bae1dSRodney W. Grimes return (error);
535df8bae1dSRodney W. Grimes
536df8bae1dSRodney W. Grimes isomp = VFSTOISOFS(mp);
537df8bae1dSRodney W. Grimes
538c4f02a89SMax Khon if (isomp->im_flags & ISOFSMNT_KICONV && cd9660_iconv) {
539c4f02a89SMax Khon if (isomp->im_d2l)
540c4f02a89SMax Khon cd9660_iconv->close(isomp->im_d2l);
541c4f02a89SMax Khon if (isomp->im_l2d)
542c4f02a89SMax Khon cd9660_iconv->close(isomp->im_l2d);
543c4f02a89SMax Khon }
544bf7e2ae1SPoul-Henning Kamp g_topology_lock();
5450d7935fdSAttilio Rao g_vfs_close(isomp->im_cp);
546bf7e2ae1SPoul-Henning Kamp g_topology_unlock();
547df8bae1dSRodney W. Grimes vrele(isomp->im_devvp);
5480b2ab5ecSJohn Baldwin dev_rel(isomp->im_dev);
549c225ad03SKevin Lo free(isomp, M_ISOFSMNT);
55077465d93SAlfred Perlstein mp->mnt_data = NULL;
551df8bae1dSRodney W. Grimes return (error);
552df8bae1dSRodney W. Grimes }
553df8bae1dSRodney W. Grimes
554df8bae1dSRodney W. Grimes /*
555df8bae1dSRodney W. Grimes * Return root of a filesystem
556df8bae1dSRodney W. Grimes */
557605e9724SPoul-Henning Kamp static int
cd9660_root(struct mount * mp,int flags,struct vnode ** vpp)558a5f59e85SEd Maste cd9660_root(struct mount *mp, int flags, struct vnode **vpp)
559df8bae1dSRodney W. Grimes {
560df8bae1dSRodney W. Grimes struct iso_mnt *imp = VFSTOISOFS(mp);
561996c772fSJohn Dyson struct iso_directory_record *dp =
562996c772fSJohn Dyson (struct iso_directory_record *)imp->root;
56396e69c8eSMark Johnston ino_t ino = isodirino(dp, imp);
564df8bae1dSRodney W. Grimes
565df8bae1dSRodney W. Grimes /*
566df8bae1dSRodney W. Grimes * With RRIP we must use the `.' entry of the root directory.
567996c772fSJohn Dyson * Simply tell vget, that it's a relocated directory.
568df8bae1dSRodney W. Grimes */
569c222ece0SJohn Baldwin return (cd9660_vget_internal(mp, ino, flags, vpp,
570996c772fSJohn Dyson imp->iso_ftype == ISO_FTYPE_RRIP, dp));
571df8bae1dSRodney W. Grimes }
572df8bae1dSRodney W. Grimes
573df8bae1dSRodney W. Grimes /*
574df8bae1dSRodney W. Grimes * Get filesystem statistics.
575df8bae1dSRodney W. Grimes */
57637c84183SPoul-Henning Kamp static int
cd9660_statfs(struct mount * mp,struct statfs * sbp)577a5f59e85SEd Maste cd9660_statfs(struct mount *mp, struct statfs *sbp)
578df8bae1dSRodney W. Grimes {
579bffd1b7aSPoul-Henning Kamp struct iso_mnt *isomp;
580df8bae1dSRodney W. Grimes
581df8bae1dSRodney W. Grimes isomp = VFSTOISOFS(mp);
582df8bae1dSRodney W. Grimes
583df8bae1dSRodney W. Grimes sbp->f_bsize = isomp->logical_block_size;
584df8bae1dSRodney W. Grimes sbp->f_iosize = sbp->f_bsize; /* XXX */
585df8bae1dSRodney W. Grimes sbp->f_blocks = isomp->volume_space_size;
586df8bae1dSRodney W. Grimes sbp->f_bfree = 0; /* total free blocks */
587df8bae1dSRodney W. Grimes sbp->f_bavail = 0; /* blocks free for non superuser */
588df8bae1dSRodney W. Grimes sbp->f_files = 0; /* total files */
589df8bae1dSRodney W. Grimes sbp->f_ffree = 0; /* free file nodes */
590df8bae1dSRodney W. Grimes return 0;
591df8bae1dSRodney W. Grimes }
592df8bae1dSRodney W. Grimes
593df8bae1dSRodney W. Grimes /*
594df8bae1dSRodney W. Grimes * File handle to vnode
595df8bae1dSRodney W. Grimes *
596df8bae1dSRodney W. Grimes * Have to be really careful about stale file handles:
597df8bae1dSRodney W. Grimes * - check that the inode number is in range
598df8bae1dSRodney W. Grimes * - call iget() to get the locked inode
599df8bae1dSRodney W. Grimes * - check for an unallocated inode (i_mode == 0)
600df8bae1dSRodney W. Grimes * - check that the generation number matches
601df8bae1dSRodney W. Grimes */
602df8bae1dSRodney W. Grimes
603df8bae1dSRodney W. Grimes /* ARGSUSED */
60437c84183SPoul-Henning Kamp static int
cd9660_fhtovp(struct mount * mp,struct fid * fhp,int flags,struct vnode ** vpp)605a5f59e85SEd Maste cd9660_fhtovp(struct mount *mp, struct fid *fhp, int flags, struct vnode **vpp)
606df8bae1dSRodney W. Grimes {
6079251d56fSMarius Strobl struct ifid ifh;
608bffd1b7aSPoul-Henning Kamp struct iso_node *ip;
609996c772fSJohn Dyson struct vnode *nvp;
610df8bae1dSRodney W. Grimes int error;
611df8bae1dSRodney W. Grimes
6129251d56fSMarius Strobl memcpy(&ifh, fhp, sizeof(ifh));
6139251d56fSMarius Strobl
614df8bae1dSRodney W. Grimes #ifdef ISOFS_DBG
615df8bae1dSRodney W. Grimes printf("fhtovp: ino %d, start %ld\n",
6169251d56fSMarius Strobl ifh.ifid_ino, ifh.ifid_start);
617df8bae1dSRodney W. Grimes #endif
618df8bae1dSRodney W. Grimes
6199251d56fSMarius Strobl if ((error = VFS_VGET(mp, ifh.ifid_ino, LK_EXCLUSIVE, &nvp)) != 0) {
620996c772fSJohn Dyson *vpp = NULLVP;
621996c772fSJohn Dyson return (error);
622996c772fSJohn Dyson }
623996c772fSJohn Dyson ip = VTOI(nvp);
624996c772fSJohn Dyson if (ip->inode.iso_mode == 0) {
625996c772fSJohn Dyson vput(nvp);
626996c772fSJohn Dyson *vpp = NULLVP;
627996c772fSJohn Dyson return (ESTALE);
628996c772fSJohn Dyson }
629996c772fSJohn Dyson *vpp = nvp;
63072b3e305SPeter Edwards vnode_create_vobject(*vpp, ip->i_size, curthread);
631c24fda81SAlfred Perlstein return (0);
632c24fda81SAlfred Perlstein }
633c24fda81SAlfred Perlstein
634dbaab6e6SConrad Meyer /*
635dbaab6e6SConrad Meyer * Conform to standard VFS interface; can't vget arbitrary inodes beyond 4GB
636dbaab6e6SConrad Meyer * into media with current inode scheme and 32-bit ino_t. This shouldn't be
637dbaab6e6SConrad Meyer * needed for anything other than nfsd, and who exports a mounted DVD over NFS?
638dbaab6e6SConrad Meyer */
63937c84183SPoul-Henning Kamp static int
cd9660_vget(struct mount * mp,ino_t ino,int flags,struct vnode ** vpp)640a5f59e85SEd Maste cd9660_vget(struct mount *mp, ino_t ino, int flags, struct vnode **vpp)
641996c772fSJohn Dyson {
642996c772fSJohn Dyson
643996c772fSJohn Dyson /*
644996c772fSJohn Dyson * XXXX
645996c772fSJohn Dyson * It would be nice if we didn't always set the `relocated' flag
646996c772fSJohn Dyson * and force the extra read, but I don't want to think about fixing
647996c772fSJohn Dyson * that right now.
648996c772fSJohn Dyson */
649a0595d02SKirk McKusick return (cd9660_vget_internal(mp, ino, flags, vpp,
650996c772fSJohn Dyson #if 0
651996c772fSJohn Dyson VFSTOISOFS(mp)->iso_ftype == ISO_FTYPE_RRIP,
652996c772fSJohn Dyson #else
653996c772fSJohn Dyson 0,
654996c772fSJohn Dyson #endif
655996c772fSJohn Dyson (struct iso_directory_record *)0));
656996c772fSJohn Dyson }
657996c772fSJohn Dyson
658dbaab6e6SConrad Meyer /* Use special comparator for full 64-bit ino comparison. */
659dbaab6e6SConrad Meyer static int
cd9660_vfs_hash_cmp(struct vnode * vp,void * pino)660a5f59e85SEd Maste cd9660_vfs_hash_cmp(struct vnode *vp, void *pino)
661dbaab6e6SConrad Meyer {
662dbaab6e6SConrad Meyer struct iso_node *ip;
66396e69c8eSMark Johnston ino_t ino;
664dbaab6e6SConrad Meyer
665dbaab6e6SConrad Meyer ip = VTOI(vp);
66696e69c8eSMark Johnston ino = *(ino_t *)pino;
667bedd4620SMateusz Guzik return (ip->i_number != ino);
668dbaab6e6SConrad Meyer }
669dbaab6e6SConrad Meyer
670996c772fSJohn Dyson int
cd9660_vget_internal(struct mount * mp,ino_t ino,int flags,struct vnode ** vpp,int relocated,struct iso_directory_record * isodir)67196e69c8eSMark Johnston cd9660_vget_internal(struct mount *mp, ino_t ino, int flags,
672a5f59e85SEd Maste struct vnode **vpp, int relocated, struct iso_directory_record *isodir)
673996c772fSJohn Dyson {
674996c772fSJohn Dyson struct iso_mnt *imp;
675996c772fSJohn Dyson struct iso_node *ip;
676996c772fSJohn Dyson struct buf *bp;
67794db13feSPoul-Henning Kamp struct vnode *vp;
678996c772fSJohn Dyson int error;
67961b9d89fSTor Egge struct thread *td;
680996c772fSJohn Dyson
68161b9d89fSTor Egge td = curthread;
682dbaab6e6SConrad Meyer error = vfs_hash_get(mp, ino, flags, td, vpp, cd9660_vfs_hash_cmp,
683dbaab6e6SConrad Meyer &ino);
684e82ef95cSPoul-Henning Kamp if (error || *vpp != NULL)
685a0595d02SKirk McKusick return (error);
686996c772fSJohn Dyson
687c222ece0SJohn Baldwin /*
688c222ece0SJohn Baldwin * We must promote to an exclusive lock for vnode creation. This
689c222ece0SJohn Baldwin * can happen if lookup is passed LOCKSHARED.
690c222ece0SJohn Baldwin */
691c222ece0SJohn Baldwin if ((flags & LK_TYPE_MASK) == LK_SHARED) {
692c222ece0SJohn Baldwin flags &= ~LK_TYPE_MASK;
693c222ece0SJohn Baldwin flags |= LK_EXCLUSIVE;
694c222ece0SJohn Baldwin }
695c222ece0SJohn Baldwin
696c222ece0SJohn Baldwin /*
697c222ece0SJohn Baldwin * We do not lock vnode creation as it is believed to be too
698c222ece0SJohn Baldwin * expensive for such rare case as simultaneous creation of vnode
699c222ece0SJohn Baldwin * for same ino by different processes. We just allow them to race
700c222ece0SJohn Baldwin * and check later to decide who wins. Let the race begin!
701c222ece0SJohn Baldwin */
702c222ece0SJohn Baldwin
703dfb9f846SPoul-Henning Kamp imp = VFSTOISOFS(mp);
704dfb9f846SPoul-Henning Kamp
705996c772fSJohn Dyson /* Allocate a new vnode/iso_node. */
706aec0fb7bSPoul-Henning Kamp if ((error = getnewvnode("isofs", mp, &cd9660_vnodeops, &vp)) != 0) {
707996c772fSJohn Dyson *vpp = NULLVP;
708996c772fSJohn Dyson return (error);
709996c772fSJohn Dyson }
7101ede983cSDag-Erling Smørgrav ip = malloc(sizeof(struct iso_node), M_ISOFSNODE,
711a163d034SWarner Losh M_WAITOK | M_ZERO);
712996c772fSJohn Dyson vp->v_data = ip;
713996c772fSJohn Dyson ip->i_vnode = vp;
714996c772fSJohn Dyson ip->i_number = ino;
715996c772fSJohn Dyson
7160e9eb108SAttilio Rao lockmgr(vp->v_vnlock, LK_EXCLUSIVE, NULL);
71761b9d89fSTor Egge error = insmntque(vp, mp);
71861b9d89fSTor Egge if (error != 0) {
71961b9d89fSTor Egge free(ip, M_ISOFSNODE);
72061b9d89fSTor Egge *vpp = NULLVP;
72161b9d89fSTor Egge return (error);
72261b9d89fSTor Egge }
723dbaab6e6SConrad Meyer error = vfs_hash_insert(vp, ino, flags, td, vpp, cd9660_vfs_hash_cmp,
724dbaab6e6SConrad Meyer &ino);
72545c26fa2SPoul-Henning Kamp if (error || *vpp != NULL)
726a0595d02SKirk McKusick return (error);
727a0595d02SKirk McKusick
7280d3e502fSPedro F. Giffuni if (isodir == NULL) {
729996c772fSJohn Dyson int lbn, off;
730996c772fSJohn Dyson
731996c772fSJohn Dyson lbn = lblkno(imp, ino);
732df8bae1dSRodney W. Grimes if (lbn >= imp->volume_space_size) {
733996c772fSJohn Dyson vput(vp);
734df8bae1dSRodney W. Grimes printf("fhtovp: lbn exceed volume space %d\n", lbn);
735df8bae1dSRodney W. Grimes return (ESTALE);
736df8bae1dSRodney W. Grimes }
737df8bae1dSRodney W. Grimes
738996c772fSJohn Dyson off = blkoff(imp, ino);
739df8bae1dSRodney W. Grimes if (off + ISO_DIRECTORY_RECORD_SIZE > imp->logical_block_size) {
740996c772fSJohn Dyson vput(vp);
741df8bae1dSRodney W. Grimes printf("fhtovp: crosses block boundary %d\n",
742df8bae1dSRodney W. Grimes off + ISO_DIRECTORY_RECORD_SIZE);
743df8bae1dSRodney W. Grimes return (ESTALE);
744df8bae1dSRodney W. Grimes }
745df8bae1dSRodney W. Grimes
746996c772fSJohn Dyson error = bread(imp->im_devvp,
747996c772fSJohn Dyson lbn << (imp->im_bshift - DEV_BSHIFT),
748df8bae1dSRodney W. Grimes imp->logical_block_size, NOCRED, &bp);
749df8bae1dSRodney W. Grimes if (error) {
750996c772fSJohn Dyson vput(vp);
751996c772fSJohn Dyson printf("fhtovp: bread error %d\n",error);
752df8bae1dSRodney W. Grimes return (error);
753df8bae1dSRodney W. Grimes }
754996c772fSJohn Dyson isodir = (struct iso_directory_record *)(bp->b_data + off);
755df8bae1dSRodney W. Grimes
756996c772fSJohn Dyson if (off + isonum_711(isodir->length) >
757996c772fSJohn Dyson imp->logical_block_size) {
758996c772fSJohn Dyson vput(vp);
759df8bae1dSRodney W. Grimes brelse(bp);
760df8bae1dSRodney W. Grimes printf("fhtovp: directory crosses block boundary %d[off=%d/len=%d]\n",
761996c772fSJohn Dyson off +isonum_711(isodir->length), off,
762996c772fSJohn Dyson isonum_711(isodir->length));
763df8bae1dSRodney W. Grimes return (ESTALE);
764df8bae1dSRodney W. Grimes }
765df8bae1dSRodney W. Grimes
766996c772fSJohn Dyson #if 0
767996c772fSJohn Dyson if (isonum_733(isodir->extent) +
768996c772fSJohn Dyson isonum_711(isodir->ext_attr_length) != ifhp->ifid_start) {
769df8bae1dSRodney W. Grimes brelse(bp);
770996c772fSJohn Dyson printf("fhtovp: file start miss %d vs %d\n",
771996c772fSJohn Dyson isonum_733(isodir->extent) + isonum_711(isodir->ext_attr_length),
772df8bae1dSRodney W. Grimes ifhp->ifid_start);
773df8bae1dSRodney W. Grimes return (ESTALE);
774df8bae1dSRodney W. Grimes }
775996c772fSJohn Dyson #endif
776996c772fSJohn Dyson } else
7770d3e502fSPedro F. Giffuni bp = NULL;
778df8bae1dSRodney W. Grimes
779996c772fSJohn Dyson ip->i_mnt = imp;
780996c772fSJohn Dyson
781996c772fSJohn Dyson if (relocated) {
782996c772fSJohn Dyson /*
783996c772fSJohn Dyson * On relocated directories we must
784996c772fSJohn Dyson * read the `.' entry out of a dir.
785996c772fSJohn Dyson */
786996c772fSJohn Dyson ip->iso_start = ino >> imp->im_bshift;
787e296c1dfSPedro F. Giffuni if (bp != NULL)
788996c772fSJohn Dyson brelse(bp);
789d254af07SMatthew Dillon if ((error = cd9660_blkatoff(vp, (off_t)0, NULL, &bp)) != 0) {
790996c772fSJohn Dyson vput(vp);
791df8bae1dSRodney W. Grimes return (error);
792df8bae1dSRodney W. Grimes }
793996c772fSJohn Dyson isodir = (struct iso_directory_record *)bp->b_data;
794996c772fSJohn Dyson }
795996c772fSJohn Dyson
796996c772fSJohn Dyson ip->iso_extent = isonum_733(isodir->extent);
797996c772fSJohn Dyson ip->i_size = isonum_733(isodir->size);
798996c772fSJohn Dyson ip->iso_start = isonum_711(isodir->ext_attr_length) + ip->iso_extent;
799996c772fSJohn Dyson
800996c772fSJohn Dyson /*
801996c772fSJohn Dyson * Setup time stamp, attribute
802996c772fSJohn Dyson */
803996c772fSJohn Dyson vp->v_type = VNON;
804996c772fSJohn Dyson switch (imp->iso_ftype) {
805996c772fSJohn Dyson default: /* ISO_FTYPE_9660 */
806996c772fSJohn Dyson {
807996c772fSJohn Dyson struct buf *bp2;
808996c772fSJohn Dyson int off;
809996c772fSJohn Dyson if ((imp->im_flags & ISOFSMNT_EXTATT)
810996c772fSJohn Dyson && (off = isonum_711(isodir->ext_attr_length)))
811cec0f20cSPoul-Henning Kamp cd9660_blkatoff(vp, (off_t)-(off << imp->im_bshift), NULL,
812996c772fSJohn Dyson &bp2);
813996c772fSJohn Dyson else
814996c772fSJohn Dyson bp2 = NULL;
815996c772fSJohn Dyson cd9660_defattr(isodir, ip, bp2, ISO_FTYPE_9660);
816996c772fSJohn Dyson cd9660_deftstamp(isodir, ip, bp2, ISO_FTYPE_9660);
817996c772fSJohn Dyson if (bp2)
818996c772fSJohn Dyson brelse(bp2);
819996c772fSJohn Dyson break;
820996c772fSJohn Dyson }
821996c772fSJohn Dyson case ISO_FTYPE_RRIP:
822996c772fSJohn Dyson cd9660_rrip_analyze(isodir, ip, imp);
823996c772fSJohn Dyson break;
824996c772fSJohn Dyson }
825996c772fSJohn Dyson
826996c772fSJohn Dyson brelse(bp);
827996c772fSJohn Dyson
828996c772fSJohn Dyson /*
829996c772fSJohn Dyson * Initialize the associated vnode
830996c772fSJohn Dyson */
831996c772fSJohn Dyson switch (vp->v_type = IFTOVT(ip->inode.iso_mode)) {
832996c772fSJohn Dyson case VFIFO:
833aec0fb7bSPoul-Henning Kamp vp->v_op = &cd9660_fifoops;
834996c772fSJohn Dyson break;
835d254af07SMatthew Dillon default:
836c222ece0SJohn Baldwin VN_LOCK_ASHARE(vp);
837d254af07SMatthew Dillon break;
838996c772fSJohn Dyson }
839996c772fSJohn Dyson
840996c772fSJohn Dyson if (ip->iso_extent == imp->root_extent)
841e6e370a7SJeff Roberson vp->v_vflag |= VV_ROOT;
842996c772fSJohn Dyson
843df8bae1dSRodney W. Grimes /*
844df8bae1dSRodney W. Grimes * XXX need generation number?
845df8bae1dSRodney W. Grimes */
846996c772fSJohn Dyson
847829f0bcbSMateusz Guzik vn_set_state(vp, VSTATE_CONSTRUCTED);
848996c772fSJohn Dyson *vpp = vp;
849996c772fSJohn Dyson return (0);
850df8bae1dSRodney W. Grimes }
851