udf_vfsops.c revision 1.2.4.2 1 1.2.4.2 yamt /* $NetBSD: udf_vfsops.c,v 1.2.4.2 2006/02/18 15:39:18 yamt Exp $ */
2 1.2.4.2 yamt
3 1.2.4.2 yamt /*
4 1.2.4.2 yamt * Copyright (c) 2006 Reinoud Zandijk
5 1.2.4.2 yamt * All rights reserved.
6 1.2.4.2 yamt *
7 1.2.4.2 yamt * Redistribution and use in source and binary forms, with or without
8 1.2.4.2 yamt * modification, are permitted provided that the following conditions
9 1.2.4.2 yamt * are met:
10 1.2.4.2 yamt * 1. Redistributions of source code must retain the above copyright
11 1.2.4.2 yamt * notice, this list of conditions and the following disclaimer.
12 1.2.4.2 yamt * 2. Redistributions in binary form must reproduce the above copyright
13 1.2.4.2 yamt * notice, this list of conditions and the following disclaimer in the
14 1.2.4.2 yamt * documentation and/or other materials provided with the distribution.
15 1.2.4.2 yamt * 3. All advertising materials mentioning features or use of this software
16 1.2.4.2 yamt * must display the following acknowledgement:
17 1.2.4.2 yamt * This product includes software developed for the
18 1.2.4.2 yamt * NetBSD Project. See http://www.NetBSD.org/ for
19 1.2.4.2 yamt * information about NetBSD.
20 1.2.4.2 yamt * 4. The name of the author may not be used to endorse or promote products
21 1.2.4.2 yamt * derived from this software without specific prior written permission.
22 1.2.4.2 yamt *
23 1.2.4.2 yamt * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
24 1.2.4.2 yamt * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
25 1.2.4.2 yamt * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
26 1.2.4.2 yamt * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
27 1.2.4.2 yamt * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
28 1.2.4.2 yamt * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
29 1.2.4.2 yamt * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
30 1.2.4.2 yamt * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
31 1.2.4.2 yamt * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
32 1.2.4.2 yamt * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
33 1.2.4.2 yamt *
34 1.2.4.2 yamt */
35 1.2.4.2 yamt
36 1.2.4.2 yamt
37 1.2.4.2 yamt #include <sys/cdefs.h>
38 1.2.4.2 yamt #ifndef lint
39 1.2.4.2 yamt __RCSID("$NetBSD: udf_vfsops.c,v 1.2.4.2 2006/02/18 15:39:18 yamt Exp $");
40 1.2.4.2 yamt #endif /* not lint */
41 1.2.4.2 yamt
42 1.2.4.2 yamt
43 1.2.4.2 yamt #if defined(_KERNEL_OPT)
44 1.2.4.2 yamt #include "opt_quota.h"
45 1.2.4.2 yamt #include "opt_compat_netbsd.h"
46 1.2.4.2 yamt #endif
47 1.2.4.2 yamt
48 1.2.4.2 yamt #include <sys/param.h>
49 1.2.4.2 yamt #include <sys/systm.h>
50 1.2.4.2 yamt #include <sys/sysctl.h>
51 1.2.4.2 yamt #include <sys/namei.h>
52 1.2.4.2 yamt #include <sys/proc.h>
53 1.2.4.2 yamt #include <sys/kernel.h>
54 1.2.4.2 yamt #include <sys/vnode.h>
55 1.2.4.2 yamt #include <miscfs/specfs/specdev.h>
56 1.2.4.2 yamt #include <sys/mount.h>
57 1.2.4.2 yamt #include <sys/buf.h>
58 1.2.4.2 yamt #include <sys/file.h>
59 1.2.4.2 yamt #include <sys/device.h>
60 1.2.4.2 yamt #include <sys/disklabel.h>
61 1.2.4.2 yamt #include <sys/ioctl.h>
62 1.2.4.2 yamt #include <sys/malloc.h>
63 1.2.4.2 yamt #include <sys/dirent.h>
64 1.2.4.2 yamt #include <sys/stat.h>
65 1.2.4.2 yamt #include <sys/conf.h>
66 1.2.4.2 yamt
67 1.2.4.2 yamt #include <fs/udf/ecma167-udf.h>
68 1.2.4.2 yamt #include <fs/udf/udf_mount.h>
69 1.2.4.2 yamt
70 1.2.4.2 yamt #include "udf.h"
71 1.2.4.2 yamt #include "udf_subr.h"
72 1.2.4.2 yamt #include "udf_bswap.h"
73 1.2.4.2 yamt
74 1.2.4.2 yamt
75 1.2.4.2 yamt /* verbose levels of the udf filingsystem */
76 1.2.4.2 yamt int udf_verbose = UDF_DEBUGGING;
77 1.2.4.2 yamt
78 1.2.4.2 yamt /* malloc regions */
79 1.2.4.2 yamt MALLOC_DEFINE(M_UDFMNT, "UDF mount", "UDF mount structures");
80 1.2.4.2 yamt MALLOC_DEFINE(M_UDFVOLD, "UDF volspace", "UDF volume space descriptors");
81 1.2.4.2 yamt MALLOC_DEFINE(M_UDFTEMP, "UDF temp", "UDF scrap space");
82 1.2.4.2 yamt struct pool udf_node_pool;
83 1.2.4.2 yamt
84 1.2.4.2 yamt /* supported functions predefined */
85 1.2.4.2 yamt int udf_mountroot(void);
86 1.2.4.2 yamt int udf_mount(struct mount *, const char *, void *, struct nameidata *, struct lwp *);
87 1.2.4.2 yamt int udf_start(struct mount *, int, struct lwp *);
88 1.2.4.2 yamt int udf_unmount(struct mount *, int, struct lwp *);
89 1.2.4.2 yamt int udf_root(struct mount *, struct vnode **);
90 1.2.4.2 yamt int udf_quotactl(struct mount *, int, uid_t, void *, struct lwp *);
91 1.2.4.2 yamt int udf_statvfs(struct mount *, struct statvfs *, struct lwp *);
92 1.2.4.2 yamt int udf_sync(struct mount *, int, struct ucred *, struct lwp *);
93 1.2.4.2 yamt int udf_vget(struct mount *, ino_t, struct vnode **);
94 1.2.4.2 yamt int udf_fhtovp(struct mount *, struct fid *, struct vnode **);
95 1.2.4.2 yamt int udf_checkexp(struct mount *, struct mbuf *, int *, struct ucred **);
96 1.2.4.2 yamt int udf_vptofh(struct vnode *, struct fid *);
97 1.2.4.2 yamt int udf_snapshot(struct mount *, struct vnode *, struct timespec *);
98 1.2.4.2 yamt
99 1.2.4.2 yamt void udf_init(void);
100 1.2.4.2 yamt void udf_reinit(void);
101 1.2.4.2 yamt void udf_done(void);
102 1.2.4.2 yamt
103 1.2.4.2 yamt
104 1.2.4.2 yamt /* internal functions */
105 1.2.4.2 yamt static int udf_mountfs(struct vnode *, struct mount *, struct lwp *, struct udf_args *);
106 1.2.4.2 yamt #if 0
107 1.2.4.2 yamt static int update_mp(struct mount *, struct udf_args *);
108 1.2.4.2 yamt #endif
109 1.2.4.2 yamt
110 1.2.4.2 yamt
111 1.2.4.2 yamt /* handies */
112 1.2.4.2 yamt #define VFSTOUDF(mp) ((struct udf_mount *)mp->mnt_data)
113 1.2.4.2 yamt
114 1.2.4.2 yamt
115 1.2.4.2 yamt /* --------------------------------------------------------------------- */
116 1.2.4.2 yamt
117 1.2.4.2 yamt /* predefine vnode-op list descriptor */
118 1.2.4.2 yamt extern const struct vnodeopv_desc udf_vnodeop_opv_desc;
119 1.2.4.2 yamt
120 1.2.4.2 yamt const struct vnodeopv_desc * const udf_vnodeopv_descs[] = {
121 1.2.4.2 yamt &udf_vnodeop_opv_desc,
122 1.2.4.2 yamt NULL,
123 1.2.4.2 yamt };
124 1.2.4.2 yamt
125 1.2.4.2 yamt
126 1.2.4.2 yamt /* vfsops descriptor linked in as anchor point for the filingsystem */
127 1.2.4.2 yamt struct vfsops udf_vfsops = {
128 1.2.4.2 yamt MOUNT_UDF, /* vfs_name */
129 1.2.4.2 yamt udf_mount,
130 1.2.4.2 yamt udf_start,
131 1.2.4.2 yamt udf_unmount,
132 1.2.4.2 yamt udf_root,
133 1.2.4.2 yamt udf_quotactl,
134 1.2.4.2 yamt udf_statvfs,
135 1.2.4.2 yamt udf_sync,
136 1.2.4.2 yamt udf_vget,
137 1.2.4.2 yamt udf_fhtovp,
138 1.2.4.2 yamt udf_vptofh,
139 1.2.4.2 yamt udf_init,
140 1.2.4.2 yamt udf_reinit,
141 1.2.4.2 yamt udf_done,
142 1.2.4.2 yamt udf_mountroot,
143 1.2.4.2 yamt udf_snapshot,
144 1.2.4.2 yamt vfs_stdextattrctl,
145 1.2.4.2 yamt udf_vnodeopv_descs,
146 1.2.4.2 yamt /* int vfs_refcount */
147 1.2.4.2 yamt /* LIST_ENTRY(vfsops) */
148 1.2.4.2 yamt };
149 1.2.4.2 yamt VFS_ATTACH(udf_vfsops);
150 1.2.4.2 yamt
151 1.2.4.2 yamt
152 1.2.4.2 yamt /* --------------------------------------------------------------------- */
153 1.2.4.2 yamt
154 1.2.4.2 yamt /* file system starts here */
155 1.2.4.2 yamt void
156 1.2.4.2 yamt udf_init(void)
157 1.2.4.2 yamt {
158 1.2.4.2 yamt size_t size;
159 1.2.4.2 yamt
160 1.2.4.2 yamt #ifdef _LKM
161 1.2.4.2 yamt malloc_type_attach(M_UDFMNT);
162 1.2.4.2 yamt malloc_type_attach(M_UDFVOLD);
163 1.2.4.2 yamt malloc_type_attach(M_UDFTEMP);
164 1.2.4.2 yamt #endif
165 1.2.4.2 yamt
166 1.2.4.2 yamt /* init hashtables and pools */
167 1.2.4.2 yamt size = sizeof(struct udf_node);
168 1.2.4.2 yamt pool_init(&udf_node_pool, size, 0, 0, 0, "udf_node_pool", NULL);
169 1.2.4.2 yamt }
170 1.2.4.2 yamt
171 1.2.4.2 yamt /* --------------------------------------------------------------------- */
172 1.2.4.2 yamt
173 1.2.4.2 yamt void
174 1.2.4.2 yamt udf_reinit(void)
175 1.2.4.2 yamt {
176 1.2.4.2 yamt /* recreate hashtables */
177 1.2.4.2 yamt /* reinit pool? */
178 1.2.4.2 yamt }
179 1.2.4.2 yamt
180 1.2.4.2 yamt /* --------------------------------------------------------------------- */
181 1.2.4.2 yamt
182 1.2.4.2 yamt void
183 1.2.4.2 yamt udf_done(void)
184 1.2.4.2 yamt {
185 1.2.4.2 yamt /* remove hashtables and pools */
186 1.2.4.2 yamt pool_destroy(&udf_node_pool);
187 1.2.4.2 yamt
188 1.2.4.2 yamt #ifdef _LKM
189 1.2.4.2 yamt malloc_type_detach(M_UDFMNT);
190 1.2.4.2 yamt malloc_type_detach(M_UDFVOLD);
191 1.2.4.2 yamt malloc_type_detach(M_UDFTEMP);
192 1.2.4.2 yamt #endif
193 1.2.4.2 yamt }
194 1.2.4.2 yamt
195 1.2.4.2 yamt /* --------------------------------------------------------------------- */
196 1.2.4.2 yamt
197 1.2.4.2 yamt int
198 1.2.4.2 yamt udf_mountroot(void)
199 1.2.4.2 yamt {
200 1.2.4.2 yamt return EOPNOTSUPP;
201 1.2.4.2 yamt }
202 1.2.4.2 yamt
203 1.2.4.2 yamt /* --------------------------------------------------------------------- */
204 1.2.4.2 yamt
205 1.2.4.2 yamt #define MPFREE(a, lst) \
206 1.2.4.2 yamt if ((a)) free((a), lst);
207 1.2.4.2 yamt static void
208 1.2.4.2 yamt free_udf_mountinfo(struct mount *mp)
209 1.2.4.2 yamt {
210 1.2.4.2 yamt struct udf_mount *ump;
211 1.2.4.2 yamt int i;
212 1.2.4.2 yamt
213 1.2.4.2 yamt ump = VFSTOUDF(mp);
214 1.2.4.2 yamt if (ump) {
215 1.2.4.2 yamt mp->mnt_data = NULL;
216 1.2.4.2 yamt for (i = 0; i < UDF_ANCHORS; i++)
217 1.2.4.2 yamt MPFREE(ump->anchors[i], M_UDFVOLD);
218 1.2.4.2 yamt MPFREE(ump->primary_vol, M_UDFVOLD);
219 1.2.4.2 yamt MPFREE(ump->logical_vol, M_UDFVOLD);
220 1.2.4.2 yamt MPFREE(ump->unallocated, M_UDFVOLD);
221 1.2.4.2 yamt MPFREE(ump->implementation, M_UDFVOLD);
222 1.2.4.2 yamt MPFREE(ump->logvol_integrity, M_UDFVOLD);
223 1.2.4.2 yamt for (i = 0; i < UDF_PARTITIONS; i++)
224 1.2.4.2 yamt MPFREE(ump->partitions[i], M_UDFVOLD);
225 1.2.4.2 yamt MPFREE(ump->fileset_desc, M_UDFVOLD);
226 1.2.4.2 yamt MPFREE(ump->vat_table, M_UDFVOLD);
227 1.2.4.2 yamt MPFREE(ump->sparing_table, M_UDFVOLD);
228 1.2.4.2 yamt
229 1.2.4.2 yamt /*
230 1.2.4.2 yamt * Note that the node related (e)fe descriptors pool is
231 1.2.4.2 yamt * destroyed allready if it was used.
232 1.2.4.2 yamt */
233 1.2.4.2 yamt
234 1.2.4.2 yamt free(ump, M_UDFMNT);
235 1.2.4.2 yamt };
236 1.2.4.2 yamt }
237 1.2.4.2 yamt #undef MPFREE
238 1.2.4.2 yamt
239 1.2.4.2 yamt /* --------------------------------------------------------------------- */
240 1.2.4.2 yamt
241 1.2.4.2 yamt int
242 1.2.4.2 yamt udf_mount(struct mount *mp, const char *path,
243 1.2.4.2 yamt void *data, struct nameidata *ndp, struct lwp *l)
244 1.2.4.2 yamt {
245 1.2.4.2 yamt struct udf_args args;
246 1.2.4.2 yamt struct udf_mount *ump;
247 1.2.4.2 yamt struct vnode *devvp;
248 1.2.4.2 yamt struct proc *p;
249 1.2.4.2 yamt int openflags, accessmode, error;
250 1.2.4.2 yamt
251 1.2.4.2 yamt DPRINTF(CALL, ("udf_mount called\n"));
252 1.2.4.2 yamt
253 1.2.4.2 yamt p = l->l_proc;
254 1.2.4.2 yamt if (mp->mnt_flag & MNT_GETARGS) {
255 1.2.4.2 yamt /* request for the mount arguments */
256 1.2.4.2 yamt ump = VFSTOUDF(mp);
257 1.2.4.2 yamt if (ump == NULL)
258 1.2.4.2 yamt return EINVAL;
259 1.2.4.2 yamt return copyout(&ump->mount_args, data, sizeof(args));
260 1.2.4.2 yamt };
261 1.2.4.2 yamt
262 1.2.4.2 yamt /* handle request for updating mount parameters */
263 1.2.4.2 yamt /* TODO can't update my mountpoint yet */
264 1.2.4.2 yamt if (mp->mnt_flag & MNT_UPDATE) {
265 1.2.4.2 yamt return EOPNOTSUPP;
266 1.2.4.2 yamt };
267 1.2.4.2 yamt
268 1.2.4.2 yamt /* OK, so we are asked to mount the device/file! */
269 1.2.4.2 yamt error = copyin(data, &args, sizeof(struct udf_args));
270 1.2.4.2 yamt if (error)
271 1.2.4.2 yamt return error;
272 1.2.4.2 yamt
273 1.2.4.2 yamt /* check/translate struct version */
274 1.2.4.2 yamt /* TODO sanity checking other mount arguments */
275 1.2.4.2 yamt if (args.version != 1) {
276 1.2.4.2 yamt printf("mount_udf: unrecognized argument structure version\n");
277 1.2.4.2 yamt return EINVAL;
278 1.2.4.2 yamt };
279 1.2.4.2 yamt
280 1.2.4.2 yamt /* lookup name to get its vnode */
281 1.2.4.2 yamt NDINIT(ndp, LOOKUP, FOLLOW | LOCKLEAF, UIO_USERSPACE, args.fspec, l);
282 1.2.4.2 yamt error = namei(ndp);
283 1.2.4.2 yamt if (error)
284 1.2.4.2 yamt return error;
285 1.2.4.2 yamt
286 1.2.4.2 yamt /* devvp is *locked* now */
287 1.2.4.2 yamt devvp = ndp->ni_vp;
288 1.2.4.2 yamt #ifdef DEBUG
289 1.2.4.2 yamt if (udf_verbose & UDF_DEBUG_VOLUMES)
290 1.2.4.2 yamt vprint("UDF mount, trying to mount \n", devvp);
291 1.2.4.2 yamt #endif
292 1.2.4.2 yamt
293 1.2.4.2 yamt /* check if its a block device specified */
294 1.2.4.2 yamt if (devvp->v_type != VBLK) {
295 1.2.4.2 yamt vrele(devvp);
296 1.2.4.2 yamt return ENOTBLK;
297 1.2.4.2 yamt }
298 1.2.4.2 yamt if (bdevsw_lookup(devvp->v_rdev) == NULL) {
299 1.2.4.2 yamt vrele(devvp);
300 1.2.4.2 yamt return ENXIO;
301 1.2.4.2 yamt }
302 1.2.4.2 yamt
303 1.2.4.2 yamt /* force read-only for now */
304 1.2.4.2 yamt mp->mnt_flag |= MNT_RDONLY;
305 1.2.4.2 yamt
306 1.2.4.2 yamt /*
307 1.2.4.2 yamt * If mount by non-root, then verify that user has necessary
308 1.2.4.2 yamt * permissions on the device.
309 1.2.4.2 yamt */
310 1.2.4.2 yamt if (p->p_ucred->cr_uid != 0) {
311 1.2.4.2 yamt accessmode = VREAD;
312 1.2.4.2 yamt if ((mp->mnt_flag & MNT_RDONLY) == 0)
313 1.2.4.2 yamt accessmode |= VWRITE;
314 1.2.4.2 yamt error = VOP_ACCESS(devvp, accessmode, p->p_ucred, l);
315 1.2.4.2 yamt if (error) {
316 1.2.4.2 yamt vput(devvp);
317 1.2.4.2 yamt return (error);
318 1.2.4.2 yamt }
319 1.2.4.2 yamt }
320 1.2.4.2 yamt
321 1.2.4.2 yamt /*
322 1.2.4.2 yamt * Disallow multiple mounts of the same device. Disallow mounting of
323 1.2.4.2 yamt * a device that is currently in use (except for root, which might
324 1.2.4.2 yamt * share swap device for miniroot).
325 1.2.4.2 yamt */
326 1.2.4.2 yamt error = vfs_mountedon(devvp);
327 1.2.4.2 yamt if (error) {
328 1.2.4.2 yamt vput(devvp);
329 1.2.4.2 yamt return error;
330 1.2.4.2 yamt };
331 1.2.4.2 yamt if ((vcount(devvp) > 1) && (devvp != rootvp)) {
332 1.2.4.2 yamt vput(devvp);
333 1.2.4.2 yamt return EBUSY;
334 1.2.4.2 yamt }
335 1.2.4.2 yamt
336 1.2.4.2 yamt /*
337 1.2.4.2 yamt * Open device and try to mount it!
338 1.2.4.2 yamt */
339 1.2.4.2 yamt if (mp->mnt_flag & MNT_RDONLY) {
340 1.2.4.2 yamt openflags = FREAD;
341 1.2.4.2 yamt } else {
342 1.2.4.2 yamt openflags = FREAD | FWRITE;
343 1.2.4.2 yamt };
344 1.2.4.2 yamt error = VOP_OPEN(devvp, openflags, FSCRED, l);
345 1.2.4.2 yamt if (error == 0) {
346 1.2.4.2 yamt /* opened ok, try mounting */
347 1.2.4.2 yamt error = udf_mountfs(devvp, mp, l, &args);
348 1.2.4.2 yamt if (error) {
349 1.2.4.2 yamt free_udf_mountinfo(mp);
350 1.2.4.2 yamt /* devvp is still locked */
351 1.2.4.2 yamt (void) VOP_CLOSE(devvp, openflags, NOCRED, l);
352 1.2.4.2 yamt };
353 1.2.4.2 yamt };
354 1.2.4.2 yamt if (error) {
355 1.2.4.2 yamt /* devvp is still locked */
356 1.2.4.2 yamt vput(devvp);
357 1.2.4.2 yamt return error;
358 1.2.4.2 yamt };
359 1.2.4.2 yamt
360 1.2.4.2 yamt /* register our mountpoint being on this device */
361 1.2.4.2 yamt devvp->v_specmountpoint = mp;
362 1.2.4.2 yamt
363 1.2.4.2 yamt /* successfully mounted */
364 1.2.4.2 yamt DPRINTF(VOLUMES, ("udf_mount() successfull\n"));
365 1.2.4.2 yamt
366 1.2.4.2 yamt /* unlock it but dont deref it */
367 1.2.4.2 yamt VOP_UNLOCK(devvp, 0);
368 1.2.4.2 yamt
369 1.2.4.2 yamt return set_statvfs_info(path, UIO_USERSPACE, args.fspec, UIO_USERSPACE, mp, l);
370 1.2.4.2 yamt }
371 1.2.4.2 yamt
372 1.2.4.2 yamt /* --------------------------------------------------------------------- */
373 1.2.4.2 yamt
374 1.2.4.2 yamt #ifdef DEBUG
375 1.2.4.2 yamt static void
376 1.2.4.2 yamt udf_unmount_sanity_check(struct mount *mp)
377 1.2.4.2 yamt {
378 1.2.4.2 yamt struct vnode *vp;
379 1.2.4.2 yamt
380 1.2.4.2 yamt printf("On unmount, i found the following nodes:\n");
381 1.2.4.2 yamt LIST_FOREACH(vp, &mp->mnt_vnodelist, v_mntvnodes) {
382 1.2.4.2 yamt vprint("", vp);
383 1.2.4.2 yamt if (VOP_ISLOCKED(vp) == LK_EXCLUSIVE) {
384 1.2.4.2 yamt printf(" is locked\n");
385 1.2.4.2 yamt };
386 1.2.4.2 yamt if (vp->v_usecount > 1)
387 1.2.4.2 yamt printf(" more than one usecount %d\n", vp->v_usecount);
388 1.2.4.2 yamt };
389 1.2.4.2 yamt }
390 1.2.4.2 yamt #endif
391 1.2.4.2 yamt
392 1.2.4.2 yamt
393 1.2.4.2 yamt int
394 1.2.4.2 yamt udf_unmount(struct mount *mp, int mntflags, struct lwp *l)
395 1.2.4.2 yamt {
396 1.2.4.2 yamt struct udf_mount *ump;
397 1.2.4.2 yamt int error, flags, closeflags;
398 1.2.4.2 yamt
399 1.2.4.2 yamt DPRINTF(CALL, ("udf_umount called\n"));
400 1.2.4.2 yamt
401 1.2.4.2 yamt /*
402 1.2.4.2 yamt * By specifying SKIPSYSTEM we can skip vnodes marked with VSYSTEM.
403 1.2.4.2 yamt * This hardly documented feature allows us to exempt certain files
404 1.2.4.2 yamt * from being flushed.
405 1.2.4.2 yamt */
406 1.2.4.2 yamt flags = SKIPSYSTEM; /* allow for system vnodes to stay alive */
407 1.2.4.2 yamt if (mntflags & MNT_FORCE)
408 1.2.4.2 yamt flags |= FORCECLOSE;
409 1.2.4.2 yamt
410 1.2.4.2 yamt ump = VFSTOUDF(mp);
411 1.2.4.2 yamt if (!ump)
412 1.2.4.2 yamt panic("UDF unmount: empty ump\n");
413 1.2.4.2 yamt
414 1.2.4.2 yamt /* TODO remove these paranoid functions */
415 1.2.4.2 yamt #ifdef DEBUG
416 1.2.4.2 yamt if (udf_verbose & UDF_DEBUG_LOCKING)
417 1.2.4.2 yamt udf_unmount_sanity_check(mp);
418 1.2.4.2 yamt #endif
419 1.2.4.2 yamt
420 1.2.4.2 yamt if ((error = vflush(mp, NULLVP, flags)) != 0)
421 1.2.4.2 yamt return error;
422 1.2.4.2 yamt
423 1.2.4.2 yamt #ifdef DEBUG
424 1.2.4.2 yamt if (udf_verbose & UDF_DEBUG_LOCKING)
425 1.2.4.2 yamt udf_unmount_sanity_check(mp);
426 1.2.4.2 yamt #endif
427 1.2.4.2 yamt
428 1.2.4.2 yamt DPRINTF(VOLUMES, ("flush OK\n"));
429 1.2.4.2 yamt
430 1.2.4.2 yamt /*
431 1.2.4.2 yamt * TODO close logical volume and close session if requested.
432 1.2.4.2 yamt *
433 1.2.4.2 yamt * XXX no system nodes defined yet. Code to reclaim them is calling
434 1.2.4.2 yamt * VOP_RECLAIM on the nodes themselves.
435 1.2.4.2 yamt */
436 1.2.4.2 yamt
437 1.2.4.2 yamt /* dispose of our descriptor pool */
438 1.2.4.2 yamt pool_destroy(&ump->desc_pool);
439 1.2.4.2 yamt
440 1.2.4.2 yamt /* close device */
441 1.2.4.2 yamt DPRINTF(VOLUMES, ("closing device\n"));
442 1.2.4.2 yamt if (mp->mnt_flag & MNT_RDONLY) {
443 1.2.4.2 yamt closeflags = FREAD;
444 1.2.4.2 yamt } else {
445 1.2.4.2 yamt closeflags = FREAD | FWRITE;
446 1.2.4.2 yamt };
447 1.2.4.2 yamt
448 1.2.4.2 yamt /* devvp is still locked by us */
449 1.2.4.2 yamt vn_lock(ump->devvp, LK_EXCLUSIVE | LK_RETRY);
450 1.2.4.2 yamt error = VOP_CLOSE(ump->devvp, closeflags, NOCRED, l);
451 1.2.4.2 yamt if (error)
452 1.2.4.2 yamt printf("Error during closure of device! error %d, "
453 1.2.4.2 yamt "device might stay locked\n", error);
454 1.2.4.2 yamt DPRINTF(VOLUMES, ("device close ok\n"));
455 1.2.4.2 yamt
456 1.2.4.2 yamt /* clear our mount reference and release device node */
457 1.2.4.2 yamt ump->devvp->v_specmountpoint = NULL;
458 1.2.4.2 yamt vput(ump->devvp);
459 1.2.4.2 yamt
460 1.2.4.2 yamt /* free ump struct */
461 1.2.4.2 yamt mp->mnt_data = NULL;
462 1.2.4.2 yamt mp->mnt_flag &= ~MNT_LOCAL;
463 1.2.4.2 yamt
464 1.2.4.2 yamt /* free up umt structure */
465 1.2.4.2 yamt free_udf_mountinfo(mp);
466 1.2.4.2 yamt
467 1.2.4.2 yamt DPRINTF(VOLUMES, ("Fin unmount\n"));
468 1.2.4.2 yamt return error;
469 1.2.4.2 yamt }
470 1.2.4.2 yamt
471 1.2.4.2 yamt /* --------------------------------------------------------------------- */
472 1.2.4.2 yamt
473 1.2.4.2 yamt /*
474 1.2.4.2 yamt * Helper function of udf_mount() that actually mounts the disc.
475 1.2.4.2 yamt */
476 1.2.4.2 yamt
477 1.2.4.2 yamt static int
478 1.2.4.2 yamt udf_mountfs(struct vnode *devvp, struct mount *mp,
479 1.2.4.2 yamt struct lwp *l, struct udf_args *args)
480 1.2.4.2 yamt {
481 1.2.4.2 yamt struct udf_mount *ump;
482 1.2.4.2 yamt uint32_t sector_size, lb_size, bshift;
483 1.2.4.2 yamt int num_anchors, error, lst;
484 1.2.4.2 yamt
485 1.2.4.2 yamt /* flush out any old buffers remaining from a previous use. */
486 1.2.4.2 yamt error = vinvalbuf(devvp, V_SAVE, l->l_proc->p_ucred, l, 0, 0);
487 1.2.4.2 yamt if (error)
488 1.2.4.2 yamt return error;
489 1.2.4.2 yamt
490 1.2.4.2 yamt /* allocate udf part of mount structure; malloc allways succeeds */
491 1.2.4.2 yamt ump = malloc(sizeof(struct udf_mount), M_UDFMNT, M_WAITOK);
492 1.2.4.2 yamt memset(ump, 0, sizeof(struct udf_mount));
493 1.2.4.2 yamt
494 1.2.4.2 yamt /* init locks */
495 1.2.4.2 yamt simple_lock_init(&ump->ihash_slock);
496 1.2.4.2 yamt lockinit(&ump->get_node_lock, PINOD, "udf_getnode", 0, 0);
497 1.2.4.2 yamt
498 1.2.4.2 yamt /* init `ino_t' to udf_node hash table */
499 1.2.4.2 yamt for (lst = 0; lst < UDF_INODE_HASHSIZE; lst++) {
500 1.2.4.2 yamt LIST_INIT(&ump->udf_nodes[lst]);
501 1.2.4.2 yamt };
502 1.2.4.2 yamt
503 1.2.4.2 yamt /* set up linkage */
504 1.2.4.2 yamt mp->mnt_data = ump;
505 1.2.4.2 yamt ump->vfs_mountp = mp;
506 1.2.4.2 yamt
507 1.2.4.2 yamt /* set up arguments and device */
508 1.2.4.2 yamt ump->mount_args = *args;
509 1.2.4.2 yamt ump->devvp = devvp;
510 1.2.4.2 yamt error = udf_update_discinfo(ump);
511 1.2.4.2 yamt
512 1.2.4.2 yamt if (error) {
513 1.2.4.2 yamt printf("UDF mount: error inspecting fs node\n");
514 1.2.4.2 yamt return error;
515 1.2.4.2 yamt };
516 1.2.4.2 yamt
517 1.2.4.2 yamt /* inspect sector size */
518 1.2.4.2 yamt sector_size = ump->discinfo.sector_size;
519 1.2.4.2 yamt bshift = 1;
520 1.2.4.2 yamt while ((1 << bshift) < sector_size)
521 1.2.4.2 yamt bshift++;
522 1.2.4.2 yamt if ((1 << bshift) != sector_size) {
523 1.2.4.2 yamt printf("UDF mount: "
524 1.2.4.2 yamt "hit NetBSD implementation fence on sector size\n");
525 1.2.4.2 yamt return EIO;
526 1.2.4.2 yamt };
527 1.2.4.2 yamt
528 1.2.4.2 yamt /* read all anchors to get volume descriptor sequence */
529 1.2.4.2 yamt num_anchors = udf_read_anchors(ump, args);
530 1.2.4.2 yamt if (num_anchors == 0)
531 1.2.4.2 yamt return ENOENT;
532 1.2.4.2 yamt
533 1.2.4.2 yamt DPRINTF(VOLUMES, ("Read %d anchors on this disc, session %d\n",
534 1.2.4.2 yamt num_anchors, args->sessionnr));
535 1.2.4.2 yamt
536 1.2.4.2 yamt /* read in volume descriptor sequence */
537 1.2.4.2 yamt error = udf_read_vds_space(ump);
538 1.2.4.2 yamt if (error)
539 1.2.4.2 yamt printf("UDF mount: error reading volume space\n");
540 1.2.4.2 yamt
541 1.2.4.2 yamt /* check consistency and completeness */
542 1.2.4.2 yamt if (!error) {
543 1.2.4.2 yamt error = udf_process_vds(ump, args);
544 1.2.4.2 yamt if (error)
545 1.2.4.2 yamt printf("UDF mount: disc not properly formatted\n");
546 1.2.4.2 yamt };
547 1.2.4.2 yamt
548 1.2.4.2 yamt /*
549 1.2.4.2 yamt * Initialise pool for descriptors associated with nodes. This is done
550 1.2.4.2 yamt * in lb_size units though currently lb_size is dictated to be
551 1.2.4.2 yamt * sector_size.
552 1.2.4.2 yamt */
553 1.2.4.2 yamt lb_size = udf_rw32(ump->logical_vol->lb_size);
554 1.2.4.2 yamt pool_init(&ump->desc_pool, lb_size, 0, 0, 0, "udf_desc_pool", NULL);
555 1.2.4.2 yamt
556 1.2.4.2 yamt /* read vds support tables like VAT, sparable etc. */
557 1.2.4.2 yamt if (!error) {
558 1.2.4.2 yamt error = udf_read_vds_tables(ump, args);
559 1.2.4.2 yamt if (error)
560 1.2.4.2 yamt printf("UDF mount: error in format or damaged disc\n");
561 1.2.4.2 yamt };
562 1.2.4.2 yamt if (!error) {
563 1.2.4.2 yamt error = udf_read_rootdirs(ump, args);
564 1.2.4.2 yamt if (error)
565 1.2.4.2 yamt printf("UDF mount: "
566 1.2.4.2 yamt "disc not properly formatted or damaged disc\n");
567 1.2.4.2 yamt };
568 1.2.4.2 yamt if (error)
569 1.2.4.2 yamt return error;
570 1.2.4.2 yamt
571 1.2.4.2 yamt /* setup rest of mount information */
572 1.2.4.2 yamt mp->mnt_data = ump;
573 1.2.4.2 yamt mp->mnt_stat.f_fsidx.__fsid_val[0] = (uint32_t) devvp->v_rdev;
574 1.2.4.2 yamt mp->mnt_stat.f_fsidx.__fsid_val[1] = makefstype(MOUNT_UDF);
575 1.2.4.2 yamt mp->mnt_stat.f_fsid = mp->mnt_stat.f_fsidx.__fsid_val[0];
576 1.2.4.2 yamt mp->mnt_stat.f_namemax = UDF_MAX_NAMELEN;
577 1.2.4.2 yamt mp->mnt_flag |= MNT_LOCAL;
578 1.2.4.2 yamt
579 1.2.4.2 yamt /* bshift is allways equal to disc sector size */
580 1.2.4.2 yamt mp->mnt_dev_bshift = bshift;
581 1.2.4.2 yamt mp->mnt_fs_bshift = bshift;
582 1.2.4.2 yamt
583 1.2.4.2 yamt /* do we have to set this? */
584 1.2.4.2 yamt devvp->v_specmountpoint = mp;
585 1.2.4.2 yamt
586 1.2.4.2 yamt /* success! */
587 1.2.4.2 yamt return 0;
588 1.2.4.2 yamt }
589 1.2.4.2 yamt
590 1.2.4.2 yamt /* --------------------------------------------------------------------- */
591 1.2.4.2 yamt
592 1.2.4.2 yamt int
593 1.2.4.2 yamt udf_start(struct mount *mp, int flags, struct lwp *l)
594 1.2.4.2 yamt {
595 1.2.4.2 yamt /* do we have to do something here? */
596 1.2.4.2 yamt return 0;
597 1.2.4.2 yamt }
598 1.2.4.2 yamt
599 1.2.4.2 yamt /* --------------------------------------------------------------------- */
600 1.2.4.2 yamt
601 1.2.4.2 yamt int
602 1.2.4.2 yamt udf_root(struct mount *mp, struct vnode **vpp)
603 1.2.4.2 yamt {
604 1.2.4.2 yamt struct vnode *vp;
605 1.2.4.2 yamt struct long_ad *dir_loc;
606 1.2.4.2 yamt struct udf_mount *ump = VFSTOUDF(mp);
607 1.2.4.2 yamt struct udf_node *root_dir;
608 1.2.4.2 yamt int error;
609 1.2.4.2 yamt
610 1.2.4.2 yamt DPRINTF(CALL, ("udf_root called\n"));
611 1.2.4.2 yamt
612 1.2.4.2 yamt dir_loc = &ump->fileset_desc->rootdir_icb;
613 1.2.4.2 yamt error = udf_get_node(ump, dir_loc, &root_dir);
614 1.2.4.2 yamt
615 1.2.4.2 yamt if (!root_dir)
616 1.2.4.2 yamt error = ENOENT;
617 1.2.4.2 yamt if (error)
618 1.2.4.2 yamt return error;
619 1.2.4.2 yamt
620 1.2.4.2 yamt vp = root_dir->vnode;
621 1.2.4.2 yamt simple_lock(&vp->v_interlock);
622 1.2.4.2 yamt root_dir->vnode->v_flag |= VROOT;
623 1.2.4.2 yamt simple_unlock(&vp->v_interlock);
624 1.2.4.2 yamt
625 1.2.4.2 yamt *vpp = vp;
626 1.2.4.2 yamt return 0;
627 1.2.4.2 yamt }
628 1.2.4.2 yamt
629 1.2.4.2 yamt /* --------------------------------------------------------------------- */
630 1.2.4.2 yamt
631 1.2.4.2 yamt int
632 1.2.4.2 yamt udf_quotactl(struct mount *mp, int cmds, uid_t uid, void *arg, struct lwp *l)
633 1.2.4.2 yamt {
634 1.2.4.2 yamt DPRINTF(NOTIMPL, ("udf_quotactl called\n"));
635 1.2.4.2 yamt return EOPNOTSUPP;
636 1.2.4.2 yamt }
637 1.2.4.2 yamt
638 1.2.4.2 yamt /* --------------------------------------------------------------------- */
639 1.2.4.2 yamt
640 1.2.4.2 yamt int
641 1.2.4.2 yamt udf_statvfs(struct mount *mp, struct statvfs *sbp, struct lwp *l)
642 1.2.4.2 yamt {
643 1.2.4.2 yamt struct udf_mount *ump = VFSTOUDF(mp);
644 1.2.4.2 yamt struct logvol_int_desc *lvid;
645 1.2.4.2 yamt struct udf_logvol_info *impl;
646 1.2.4.2 yamt uint64_t freeblks, sizeblks;
647 1.2.4.2 yamt uint32_t *pos1, *pos2;
648 1.2.4.2 yamt int part, num_part;
649 1.2.4.2 yamt
650 1.2.4.2 yamt DPRINTF(CALL, ("udf_statvfs called\n"));
651 1.2.4.2 yamt sbp->f_flag = mp->mnt_flag;
652 1.2.4.2 yamt sbp->f_bsize = ump->discinfo.sector_size;
653 1.2.4.2 yamt sbp->f_frsize = ump->discinfo.sector_size;
654 1.2.4.2 yamt sbp->f_iosize = ump->discinfo.sector_size;
655 1.2.4.2 yamt
656 1.2.4.2 yamt /* TODO integrity locking */
657 1.2.4.2 yamt /* free and used space for mountpoint based on logvol integrity */
658 1.2.4.2 yamt lvid = ump->logvol_integrity;
659 1.2.4.2 yamt if (lvid) {
660 1.2.4.2 yamt num_part = udf_rw32(lvid->num_part);
661 1.2.4.2 yamt impl = (struct udf_logvol_info *) (lvid->tables + 2*num_part);
662 1.2.4.2 yamt
663 1.2.4.2 yamt freeblks = sizeblks = 0;
664 1.2.4.2 yamt for (part=0; part < num_part; part++) {
665 1.2.4.2 yamt pos1 = &lvid->tables[0] + part;
666 1.2.4.2 yamt pos2 = &lvid->tables[0] + num_part + part;
667 1.2.4.2 yamt if (udf_rw32(*pos1) != (uint32_t) -1) {
668 1.2.4.2 yamt freeblks += udf_rw32(*pos1);
669 1.2.4.2 yamt sizeblks += udf_rw32(*pos2);
670 1.2.4.2 yamt };
671 1.2.4.2 yamt };
672 1.2.4.2 yamt sbp->f_blocks = sizeblks;
673 1.2.4.2 yamt sbp->f_bfree = freeblks;
674 1.2.4.2 yamt sbp->f_files = udf_rw32(impl->num_files);
675 1.2.4.2 yamt sbp->f_files += udf_rw32(impl->num_directories);
676 1.2.4.2 yamt
677 1.2.4.2 yamt /* XXX read only for now XXX */
678 1.2.4.2 yamt sbp->f_bavail = 0;
679 1.2.4.2 yamt sbp->f_bresvd = 0;
680 1.2.4.2 yamt
681 1.2.4.2 yamt /* tricky, next only aplies to ffs i think, so set to zero */
682 1.2.4.2 yamt sbp->f_ffree = 0;
683 1.2.4.2 yamt sbp->f_favail = 0;
684 1.2.4.2 yamt sbp->f_fresvd = 0;
685 1.2.4.2 yamt };
686 1.2.4.2 yamt
687 1.2.4.2 yamt copy_statvfs_info(sbp, mp);
688 1.2.4.2 yamt return 0;
689 1.2.4.2 yamt }
690 1.2.4.2 yamt
691 1.2.4.2 yamt /* --------------------------------------------------------------------- */
692 1.2.4.2 yamt
693 1.2.4.2 yamt int
694 1.2.4.2 yamt udf_sync(struct mount *mp, int waitfor, struct ucred *cred, struct lwp *p)
695 1.2.4.2 yamt {
696 1.2.4.2 yamt DPRINTF(CALL, ("udf_sync called\n"));
697 1.2.4.2 yamt /* nothing to be done as upto now read-only */
698 1.2.4.2 yamt return 0;
699 1.2.4.2 yamt }
700 1.2.4.2 yamt
701 1.2.4.2 yamt /* --------------------------------------------------------------------- */
702 1.2.4.2 yamt
703 1.2.4.2 yamt /*
704 1.2.4.2 yamt * Get vnode for the file system type specific file id ino for the fs. Its
705 1.2.4.2 yamt * used for reference to files by unique ID and for NFSv3.
706 1.2.4.2 yamt * (optional) TODO lookup why some sources state NFSv3
707 1.2.4.2 yamt */
708 1.2.4.2 yamt int
709 1.2.4.2 yamt udf_vget(struct mount *mp, ino_t ino, struct vnode **vpp)
710 1.2.4.2 yamt {
711 1.2.4.2 yamt DPRINTF(NOTIMPL, ("udf_vget called\n"));
712 1.2.4.2 yamt return EOPNOTSUPP;
713 1.2.4.2 yamt }
714 1.2.4.2 yamt
715 1.2.4.2 yamt /* --------------------------------------------------------------------- */
716 1.2.4.2 yamt
717 1.2.4.2 yamt /*
718 1.2.4.2 yamt * Lookup vnode for file handle specified
719 1.2.4.2 yamt */
720 1.2.4.2 yamt int
721 1.2.4.2 yamt udf_fhtovp(struct mount *mp, struct fid *fhp, struct vnode **vpp)
722 1.2.4.2 yamt {
723 1.2.4.2 yamt DPRINTF(NOTIMPL, ("udf_fhtovp called\n"));
724 1.2.4.2 yamt return EOPNOTSUPP;
725 1.2.4.2 yamt }
726 1.2.4.2 yamt
727 1.2.4.2 yamt /* --------------------------------------------------------------------- */
728 1.2.4.2 yamt
729 1.2.4.2 yamt /*
730 1.2.4.2 yamt * Create an unique file handle. Its structure is opaque and won't be used by
731 1.2.4.2 yamt * other subsystems. It should uniquely identify the file in the filingsystem
732 1.2.4.2 yamt * and enough information to know if a file has been removed and/or resources
733 1.2.4.2 yamt * have been recycled.
734 1.2.4.2 yamt */
735 1.2.4.2 yamt int
736 1.2.4.2 yamt udf_vptofh(struct vnode *vp, struct fid *fid)
737 1.2.4.2 yamt {
738 1.2.4.2 yamt DPRINTF(NOTIMPL, ("udf_vptofh called\n"));
739 1.2.4.2 yamt return EOPNOTSUPP;
740 1.2.4.2 yamt }
741 1.2.4.2 yamt
742 1.2.4.2 yamt /* --------------------------------------------------------------------- */
743 1.2.4.2 yamt
744 1.2.4.2 yamt /*
745 1.2.4.2 yamt * Create a filingsystem snapshot at the specified timestamp. Could be
746 1.2.4.2 yamt * implemented by explicitly creating a new session or with spare room in the
747 1.2.4.2 yamt * integrity descriptor space
748 1.2.4.2 yamt */
749 1.2.4.2 yamt int
750 1.2.4.2 yamt udf_snapshot(struct mount *mp, struct vnode *vp, struct timespec *tm)
751 1.2.4.2 yamt {
752 1.2.4.2 yamt DPRINTF(NOTIMPL, ("udf_snapshot called\n"));
753 1.2.4.2 yamt return EOPNOTSUPP;
754 1.2.4.2 yamt }
755 1.2.4.2 yamt
756 1.2.4.2 yamt
757