udf_vfsops.c revision 1.45 1 1.45 reinoud /* $NetBSD: udf_vfsops.c,v 1.45 2008/07/27 11:21:21 reinoud Exp $ */
2 1.1 reinoud
3 1.1 reinoud /*
4 1.38 reinoud * Copyright (c) 2006, 2008 Reinoud Zandijk
5 1.1 reinoud * All rights reserved.
6 1.1 reinoud *
7 1.1 reinoud * Redistribution and use in source and binary forms, with or without
8 1.1 reinoud * modification, are permitted provided that the following conditions
9 1.1 reinoud * are met:
10 1.1 reinoud * 1. Redistributions of source code must retain the above copyright
11 1.1 reinoud * notice, this list of conditions and the following disclaimer.
12 1.1 reinoud * 2. Redistributions in binary form must reproduce the above copyright
13 1.1 reinoud * notice, this list of conditions and the following disclaimer in the
14 1.1 reinoud * documentation and/or other materials provided with the distribution.
15 1.1 reinoud *
16 1.1 reinoud * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
17 1.1 reinoud * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
18 1.1 reinoud * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
19 1.1 reinoud * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
20 1.1 reinoud * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
21 1.1 reinoud * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
22 1.1 reinoud * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
23 1.1 reinoud * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
24 1.1 reinoud * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
25 1.1 reinoud * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
26 1.1 reinoud *
27 1.1 reinoud */
28 1.1 reinoud
29 1.1 reinoud #include <sys/cdefs.h>
30 1.1 reinoud #ifndef lint
31 1.45 reinoud __KERNEL_RCSID(0, "$NetBSD: udf_vfsops.c,v 1.45 2008/07/27 11:21:21 reinoud Exp $");
32 1.1 reinoud #endif /* not lint */
33 1.1 reinoud
34 1.1 reinoud
35 1.1 reinoud #if defined(_KERNEL_OPT)
36 1.1 reinoud #include "opt_quota.h"
37 1.1 reinoud #include "opt_compat_netbsd.h"
38 1.38 reinoud #include "opt_udf.h"
39 1.1 reinoud #endif
40 1.1 reinoud
41 1.1 reinoud #include <sys/param.h>
42 1.1 reinoud #include <sys/systm.h>
43 1.1 reinoud #include <sys/sysctl.h>
44 1.1 reinoud #include <sys/namei.h>
45 1.1 reinoud #include <sys/proc.h>
46 1.1 reinoud #include <sys/kernel.h>
47 1.1 reinoud #include <sys/vnode.h>
48 1.35 dholland #include <miscfs/genfs/genfs.h>
49 1.1 reinoud #include <miscfs/specfs/specdev.h>
50 1.1 reinoud #include <sys/mount.h>
51 1.1 reinoud #include <sys/buf.h>
52 1.1 reinoud #include <sys/file.h>
53 1.1 reinoud #include <sys/device.h>
54 1.1 reinoud #include <sys/disklabel.h>
55 1.1 reinoud #include <sys/ioctl.h>
56 1.1 reinoud #include <sys/malloc.h>
57 1.1 reinoud #include <sys/dirent.h>
58 1.1 reinoud #include <sys/stat.h>
59 1.1 reinoud #include <sys/conf.h>
60 1.5 christos #include <sys/kauth.h>
61 1.37 rumble #include <sys/module.h>
62 1.1 reinoud
63 1.1 reinoud #include <fs/udf/ecma167-udf.h>
64 1.1 reinoud #include <fs/udf/udf_mount.h>
65 1.1 reinoud
66 1.1 reinoud #include "udf.h"
67 1.1 reinoud #include "udf_subr.h"
68 1.1 reinoud #include "udf_bswap.h"
69 1.1 reinoud
70 1.37 rumble MODULE(MODULE_CLASS_VFS, udf, NULL);
71 1.1 reinoud
72 1.38 reinoud #define VTOI(vnode) ((struct udf_node *) vnode->v_data)
73 1.38 reinoud
74 1.1 reinoud /* verbose levels of the udf filingsystem */
75 1.1 reinoud int udf_verbose = UDF_DEBUGGING;
76 1.1 reinoud
77 1.43 reinoud /* maximum dirhash size of all UDF filesystems combined(!) */
78 1.43 reinoud kmutex_t udf_dirhashmutex;
79 1.43 reinoud uint32_t udf_maxdirhashsize = UDF_DIRHASH_DEFAULTMEM;
80 1.43 reinoud uint32_t udf_dirhashsize = 0;
81 1.43 reinoud struct _udf_dirhash udf_dirhash_queue;
82 1.43 reinoud
83 1.1 reinoud /* malloc regions */
84 1.25 pooka MALLOC_JUSTDEFINE(M_UDFMNT, "UDF mount", "UDF mount structures");
85 1.25 pooka MALLOC_JUSTDEFINE(M_UDFVOLD, "UDF volspace", "UDF volume space descriptors");
86 1.25 pooka MALLOC_JUSTDEFINE(M_UDFTEMP, "UDF temp", "UDF scrap space");
87 1.1 reinoud struct pool udf_node_pool;
88 1.1 reinoud
89 1.1 reinoud /* supported functions predefined */
90 1.29 pooka VFS_PROTOS(udf);
91 1.1 reinoud
92 1.39 rumble static struct sysctllog *udf_sysctl_log;
93 1.1 reinoud
94 1.1 reinoud /* internal functions */
95 1.1 reinoud static int udf_mountfs(struct vnode *, struct mount *, struct lwp *, struct udf_args *);
96 1.1 reinoud
97 1.1 reinoud
98 1.1 reinoud /* --------------------------------------------------------------------- */
99 1.1 reinoud
100 1.1 reinoud /* predefine vnode-op list descriptor */
101 1.1 reinoud extern const struct vnodeopv_desc udf_vnodeop_opv_desc;
102 1.1 reinoud
103 1.1 reinoud const struct vnodeopv_desc * const udf_vnodeopv_descs[] = {
104 1.1 reinoud &udf_vnodeop_opv_desc,
105 1.1 reinoud NULL,
106 1.1 reinoud };
107 1.1 reinoud
108 1.1 reinoud
109 1.1 reinoud /* vfsops descriptor linked in as anchor point for the filingsystem */
110 1.1 reinoud struct vfsops udf_vfsops = {
111 1.1 reinoud MOUNT_UDF, /* vfs_name */
112 1.26 dsl sizeof (struct udf_args),
113 1.1 reinoud udf_mount,
114 1.1 reinoud udf_start,
115 1.1 reinoud udf_unmount,
116 1.1 reinoud udf_root,
117 1.31 pooka (void *)eopnotsupp, /* vfs_quotactl */
118 1.1 reinoud udf_statvfs,
119 1.1 reinoud udf_sync,
120 1.1 reinoud udf_vget,
121 1.1 reinoud udf_fhtovp,
122 1.1 reinoud udf_vptofh,
123 1.1 reinoud udf_init,
124 1.1 reinoud udf_reinit,
125 1.1 reinoud udf_done,
126 1.1 reinoud udf_mountroot,
127 1.1 reinoud udf_snapshot,
128 1.1 reinoud vfs_stdextattrctl,
129 1.28 pooka (void *)eopnotsupp, /* vfs_suspendctl */
130 1.35 dholland genfs_renamelock_enter,
131 1.35 dholland genfs_renamelock_exit,
132 1.36 ad (void *)eopnotsupp,
133 1.1 reinoud udf_vnodeopv_descs,
134 1.12 christos 0, /* int vfs_refcount */
135 1.12 christos { NULL, NULL, }, /* LIST_ENTRY(vfsops) */
136 1.1 reinoud };
137 1.1 reinoud
138 1.1 reinoud /* --------------------------------------------------------------------- */
139 1.1 reinoud
140 1.1 reinoud /* file system starts here */
141 1.1 reinoud void
142 1.1 reinoud udf_init(void)
143 1.1 reinoud {
144 1.1 reinoud size_t size;
145 1.43 reinoud uint32_t max_entries;
146 1.43 reinoud
147 1.43 reinoud /* initialise dirhash queue */
148 1.43 reinoud TAILQ_INIT(&udf_dirhash_queue);
149 1.1 reinoud
150 1.43 reinoud /* setup memory types */
151 1.1 reinoud malloc_type_attach(M_UDFMNT);
152 1.1 reinoud malloc_type_attach(M_UDFVOLD);
153 1.1 reinoud malloc_type_attach(M_UDFTEMP);
154 1.1 reinoud
155 1.40 reinoud /* init node pools */
156 1.1 reinoud size = sizeof(struct udf_node);
157 1.40 reinoud pool_init(&udf_node_pool, size, 0, 0, 0,
158 1.40 reinoud "udf_node_pool", NULL, IPL_NONE);
159 1.40 reinoud
160 1.40 reinoud /* init dirhash pools */
161 1.40 reinoud size = sizeof(struct udf_dirhash);
162 1.40 reinoud pool_init(&udf_dirhash_pool, size, 0, 0, 0,
163 1.40 reinoud "udf_dirhash_pool", NULL, IPL_NONE);
164 1.40 reinoud
165 1.40 reinoud size = sizeof(struct udf_dirhash_entry);
166 1.40 reinoud pool_init(&udf_dirhash_entry_pool, size, 0, 0, 0,
167 1.40 reinoud "udf_dirhash_entry_pool", NULL, IPL_NONE);
168 1.43 reinoud
169 1.43 reinoud mutex_init(&udf_dirhashmutex, MUTEX_DEFAULT, IPL_NONE);
170 1.43 reinoud max_entries = udf_maxdirhashsize / size;
171 1.43 reinoud pool_sethiwat(&udf_dirhash_entry_pool, max_entries);
172 1.43 reinoud udf_dirhashsize = 0;
173 1.1 reinoud }
174 1.1 reinoud
175 1.1 reinoud
176 1.1 reinoud void
177 1.1 reinoud udf_reinit(void)
178 1.1 reinoud {
179 1.40 reinoud /* nothing to do */
180 1.1 reinoud }
181 1.1 reinoud
182 1.1 reinoud
183 1.1 reinoud void
184 1.1 reinoud udf_done(void)
185 1.1 reinoud {
186 1.40 reinoud /* remove pools */
187 1.1 reinoud pool_destroy(&udf_node_pool);
188 1.40 reinoud pool_destroy(&udf_dirhash_pool);
189 1.40 reinoud pool_destroy(&udf_dirhash_entry_pool);
190 1.1 reinoud
191 1.1 reinoud malloc_type_detach(M_UDFMNT);
192 1.1 reinoud malloc_type_detach(M_UDFVOLD);
193 1.1 reinoud malloc_type_detach(M_UDFTEMP);
194 1.1 reinoud }
195 1.1 reinoud
196 1.39 rumble /*
197 1.39 rumble * If running a DEBUG kernel, provide an easy way to set the debug flags when
198 1.39 rumble * running into a problem.
199 1.39 rumble */
200 1.43 reinoud #define UDF_VERBOSE_SYSCTLOPT 1
201 1.43 reinoud #define UDF_CURDIRHASHSIZE_SYSCTLOPT 2
202 1.43 reinoud #define UDF_MAXDIRHASHSIZE_SYSCTLOPT 3
203 1.38 reinoud
204 1.38 reinoud static int
205 1.38 reinoud udf_modcmd(modcmd_t cmd, void *arg)
206 1.38 reinoud {
207 1.43 reinoud const struct sysctlnode *node;
208 1.39 rumble int error;
209 1.38 reinoud
210 1.38 reinoud switch (cmd) {
211 1.38 reinoud case MODULE_CMD_INIT:
212 1.39 rumble error = vfs_attach(&udf_vfsops);
213 1.39 rumble if (error != 0)
214 1.39 rumble break;
215 1.39 rumble /*
216 1.39 rumble * XXX the "24" below could be dynamic, thereby eliminating one
217 1.39 rumble * more instance of the "number to vfs" mapping problem, but
218 1.39 rumble * "24" is the order as taken from sys/mount.h
219 1.39 rumble */
220 1.39 rumble sysctl_createv(&udf_sysctl_log, 0, NULL, NULL,
221 1.39 rumble CTLFLAG_PERMANENT,
222 1.39 rumble CTLTYPE_NODE, "vfs", NULL,
223 1.39 rumble NULL, 0, NULL, 0,
224 1.39 rumble CTL_VFS, CTL_EOL);
225 1.43 reinoud sysctl_createv(&udf_sysctl_log, 0, NULL, &node,
226 1.39 rumble CTLFLAG_PERMANENT,
227 1.39 rumble CTLTYPE_NODE, "udf",
228 1.39 rumble SYSCTL_DESCR("OSTA Universal File System"),
229 1.39 rumble NULL, 0, NULL, 0,
230 1.39 rumble CTL_VFS, 24, CTL_EOL);
231 1.43 reinoud sysctl_createv(&udf_sysctl_log, 0, NULL, &node,
232 1.43 reinoud CTLFLAG_PERMANENT,
233 1.43 reinoud CTLTYPE_INT, "curdirhashsize",
234 1.43 reinoud SYSCTL_DESCR("Current memory to be used by dirhash"),
235 1.43 reinoud NULL, 0, &udf_dirhashsize, 0,
236 1.43 reinoud CTL_VFS, 24, UDF_CURDIRHASHSIZE_SYSCTLOPT, CTL_EOL);
237 1.43 reinoud sysctl_createv(&udf_sysctl_log, 0, NULL, &node,
238 1.43 reinoud CTLFLAG_PERMANENT|CTLFLAG_READWRITE,
239 1.43 reinoud CTLTYPE_INT, "maxdirhashsize",
240 1.43 reinoud SYSCTL_DESCR("Max memory to be used by dirhash"),
241 1.43 reinoud NULL, 0, &udf_maxdirhashsize, 0,
242 1.43 reinoud CTL_VFS, 24, UDF_MAXDIRHASHSIZE_SYSCTLOPT, CTL_EOL);
243 1.39 rumble #ifdef DEBUG
244 1.43 reinoud sysctl_createv(&udf_sysctl_log, 0, NULL, &node,
245 1.39 rumble CTLFLAG_PERMANENT|CTLFLAG_READWRITE,
246 1.39 rumble CTLTYPE_INT, "verbose",
247 1.39 rumble SYSCTL_DESCR("Bitmask for filesystem debugging"),
248 1.39 rumble NULL, 0, &udf_verbose, 0,
249 1.39 rumble CTL_VFS, 24, UDF_VERBOSE_SYSCTLOPT, CTL_EOL);
250 1.39 rumble #endif
251 1.39 rumble break;
252 1.38 reinoud case MODULE_CMD_FINI:
253 1.39 rumble error = vfs_detach(&udf_vfsops);
254 1.39 rumble if (error != 0)
255 1.39 rumble break;
256 1.39 rumble sysctl_teardown(&udf_sysctl_log);
257 1.39 rumble break;
258 1.38 reinoud default:
259 1.39 rumble error = ENOTTY;
260 1.39 rumble break;
261 1.38 reinoud }
262 1.39 rumble
263 1.39 rumble return (error);
264 1.38 reinoud }
265 1.38 reinoud
266 1.1 reinoud /* --------------------------------------------------------------------- */
267 1.1 reinoud
268 1.1 reinoud int
269 1.1 reinoud udf_mountroot(void)
270 1.1 reinoud {
271 1.1 reinoud return EOPNOTSUPP;
272 1.1 reinoud }
273 1.1 reinoud
274 1.1 reinoud /* --------------------------------------------------------------------- */
275 1.1 reinoud
276 1.1 reinoud #define MPFREE(a, lst) \
277 1.1 reinoud if ((a)) free((a), lst);
278 1.1 reinoud static void
279 1.1 reinoud free_udf_mountinfo(struct mount *mp)
280 1.1 reinoud {
281 1.1 reinoud struct udf_mount *ump;
282 1.1 reinoud int i;
283 1.1 reinoud
284 1.15 reinoud if (!mp)
285 1.15 reinoud return;
286 1.15 reinoud
287 1.1 reinoud ump = VFSTOUDF(mp);
288 1.1 reinoud if (ump) {
289 1.10 reinoud /* clear our data */
290 1.1 reinoud for (i = 0; i < UDF_ANCHORS; i++)
291 1.1 reinoud MPFREE(ump->anchors[i], M_UDFVOLD);
292 1.1 reinoud MPFREE(ump->primary_vol, M_UDFVOLD);
293 1.1 reinoud MPFREE(ump->logical_vol, M_UDFVOLD);
294 1.1 reinoud MPFREE(ump->unallocated, M_UDFVOLD);
295 1.1 reinoud MPFREE(ump->implementation, M_UDFVOLD);
296 1.1 reinoud MPFREE(ump->logvol_integrity, M_UDFVOLD);
297 1.38 reinoud for (i = 0; i < UDF_PARTITIONS; i++) {
298 1.45 reinoud MPFREE(ump->partitions[i], M_UDFVOLD);
299 1.38 reinoud MPFREE(ump->part_unalloc_dscr[i], M_UDFVOLD);
300 1.45 reinoud MPFREE(ump->part_freed_dscr[i], M_UDFVOLD);
301 1.38 reinoud }
302 1.45 reinoud MPFREE(ump->metadata_unalloc_dscr, M_UDFVOLD);
303 1.45 reinoud
304 1.45 reinoud MPFREE(ump->fileset_desc, M_UDFVOLD);
305 1.45 reinoud MPFREE(ump->sparing_table, M_UDFVOLD);
306 1.38 reinoud
307 1.38 reinoud MPFREE(ump->la_node_ad_cpy, M_UDFMNT);
308 1.45 reinoud MPFREE(ump->la_pmapping, M_TEMP);
309 1.45 reinoud MPFREE(ump->la_lmapping, M_TEMP);
310 1.1 reinoud
311 1.30 ad mutex_destroy(&ump->ihash_lock);
312 1.30 ad mutex_destroy(&ump->get_node_lock);
313 1.38 reinoud
314 1.38 reinoud mutex_destroy(&ump->allocate_mutex);
315 1.38 reinoud MPFREE(ump->vat_table, M_UDFVOLD);
316 1.38 reinoud
317 1.1 reinoud free(ump, M_UDFMNT);
318 1.6 christos }
319 1.1 reinoud }
320 1.1 reinoud #undef MPFREE
321 1.1 reinoud
322 1.1 reinoud /* --------------------------------------------------------------------- */
323 1.1 reinoud
324 1.38 reinoud /* if the system nodes exist, release them */
325 1.38 reinoud static void
326 1.38 reinoud udf_release_system_nodes(struct mount *mp)
327 1.38 reinoud {
328 1.38 reinoud struct udf_mount *ump = VFSTOUDF(mp);
329 1.38 reinoud int error;
330 1.38 reinoud
331 1.38 reinoud /* if we haven't even got an ump, dont bother */
332 1.38 reinoud if (!ump)
333 1.38 reinoud return;
334 1.38 reinoud
335 1.38 reinoud /* VAT partition support */
336 1.38 reinoud if (ump->vat_node)
337 1.38 reinoud vrele(ump->vat_node->vnode);
338 1.38 reinoud
339 1.38 reinoud /* Metadata partition support */
340 1.38 reinoud if (ump->metadata_node)
341 1.38 reinoud vrele(ump->metadata_node->vnode);
342 1.38 reinoud if (ump->metadatamirror_node)
343 1.38 reinoud vrele(ump->metadatamirror_node->vnode);
344 1.38 reinoud if (ump->metadatabitmap_node)
345 1.38 reinoud vrele(ump->metadatabitmap_node->vnode);
346 1.38 reinoud
347 1.38 reinoud /* This flush should NOT write anything nor allow any node to remain */
348 1.38 reinoud if ((error = vflush(ump->vfs_mountp, NULLVP, 0)) != 0)
349 1.38 reinoud panic("Failure to flush UDF system vnodes\n");
350 1.38 reinoud }
351 1.38 reinoud
352 1.38 reinoud
353 1.1 reinoud int
354 1.1 reinoud udf_mount(struct mount *mp, const char *path,
355 1.31 pooka void *data, size_t *data_len)
356 1.1 reinoud {
357 1.31 pooka struct lwp *l = curlwp;
358 1.29 pooka struct nameidata nd;
359 1.26 dsl struct udf_args *args = data;
360 1.1 reinoud struct udf_mount *ump;
361 1.1 reinoud struct vnode *devvp;
362 1.1 reinoud int openflags, accessmode, error;
363 1.1 reinoud
364 1.1 reinoud DPRINTF(CALL, ("udf_mount called\n"));
365 1.1 reinoud
366 1.26 dsl if (*data_len < sizeof *args)
367 1.26 dsl return EINVAL;
368 1.26 dsl
369 1.1 reinoud if (mp->mnt_flag & MNT_GETARGS) {
370 1.1 reinoud /* request for the mount arguments */
371 1.1 reinoud ump = VFSTOUDF(mp);
372 1.1 reinoud if (ump == NULL)
373 1.1 reinoud return EINVAL;
374 1.26 dsl *args = ump->mount_args;
375 1.26 dsl *data_len = sizeof *args;
376 1.26 dsl return 0;
377 1.6 christos }
378 1.1 reinoud
379 1.1 reinoud /* handle request for updating mount parameters */
380 1.1 reinoud /* TODO can't update my mountpoint yet */
381 1.1 reinoud if (mp->mnt_flag & MNT_UPDATE) {
382 1.1 reinoud return EOPNOTSUPP;
383 1.6 christos }
384 1.1 reinoud
385 1.15 reinoud /* OK, so we are asked to mount the device */
386 1.1 reinoud
387 1.1 reinoud /* check/translate struct version */
388 1.1 reinoud /* TODO sanity checking other mount arguments */
389 1.26 dsl if (args->version != 1) {
390 1.1 reinoud printf("mount_udf: unrecognized argument structure version\n");
391 1.1 reinoud return EINVAL;
392 1.6 christos }
393 1.1 reinoud
394 1.1 reinoud /* lookup name to get its vnode */
395 1.32 pooka NDINIT(&nd, LOOKUP, FOLLOW, UIO_USERSPACE, args->fspec);
396 1.29 pooka error = namei(&nd);
397 1.1 reinoud if (error)
398 1.1 reinoud return error;
399 1.29 pooka devvp = nd.ni_vp;
400 1.1 reinoud
401 1.1 reinoud #ifdef DEBUG
402 1.1 reinoud if (udf_verbose & UDF_DEBUG_VOLUMES)
403 1.1 reinoud vprint("UDF mount, trying to mount \n", devvp);
404 1.1 reinoud #endif
405 1.1 reinoud
406 1.1 reinoud /* check if its a block device specified */
407 1.1 reinoud if (devvp->v_type != VBLK) {
408 1.1 reinoud vrele(devvp);
409 1.1 reinoud return ENOTBLK;
410 1.1 reinoud }
411 1.1 reinoud if (bdevsw_lookup(devvp->v_rdev) == NULL) {
412 1.1 reinoud vrele(devvp);
413 1.1 reinoud return ENXIO;
414 1.1 reinoud }
415 1.1 reinoud
416 1.38 reinoud #ifndef UDF_READWRITE
417 1.1 reinoud /* force read-only for now */
418 1.38 reinoud if ((mp->mnt_flag & MNT_RDONLY) == 0) {
419 1.41 reinoud printf( "Enable kernel/module option UDF_READWRITE for "
420 1.41 reinoud "writing, downgrading access to read-only\n");
421 1.41 reinoud mp->mnt_flag |= MNT_RDONLY;
422 1.38 reinoud }
423 1.38 reinoud #endif
424 1.1 reinoud
425 1.1 reinoud /*
426 1.1 reinoud * If mount by non-root, then verify that user has necessary
427 1.1 reinoud * permissions on the device.
428 1.1 reinoud */
429 1.20 elad if (kauth_authorize_generic(l->l_cred, KAUTH_GENERIC_ISSUSER, NULL)) {
430 1.1 reinoud accessmode = VREAD;
431 1.1 reinoud if ((mp->mnt_flag & MNT_RDONLY) == 0)
432 1.1 reinoud accessmode |= VWRITE;
433 1.13 reinoud vn_lock(devvp, LK_EXCLUSIVE | LK_RETRY);
434 1.31 pooka error = VOP_ACCESS(devvp, accessmode, l->l_cred);
435 1.13 reinoud VOP_UNLOCK(devvp, 0);
436 1.1 reinoud if (error) {
437 1.13 reinoud vrele(devvp);
438 1.13 reinoud return error;
439 1.1 reinoud }
440 1.1 reinoud }
441 1.1 reinoud
442 1.1 reinoud /*
443 1.1 reinoud * Open device and try to mount it!
444 1.1 reinoud */
445 1.1 reinoud if (mp->mnt_flag & MNT_RDONLY) {
446 1.1 reinoud openflags = FREAD;
447 1.1 reinoud } else {
448 1.1 reinoud openflags = FREAD | FWRITE;
449 1.6 christos }
450 1.31 pooka error = VOP_OPEN(devvp, openflags, FSCRED);
451 1.1 reinoud if (error == 0) {
452 1.1 reinoud /* opened ok, try mounting */
453 1.26 dsl error = udf_mountfs(devvp, mp, l, args);
454 1.1 reinoud if (error) {
455 1.38 reinoud udf_release_system_nodes(mp);
456 1.38 reinoud /* cleanup */
457 1.38 reinoud udf_discstrat_finish(VFSTOUDF(mp));
458 1.1 reinoud free_udf_mountinfo(mp);
459 1.13 reinoud vn_lock(devvp, LK_EXCLUSIVE | LK_RETRY);
460 1.31 pooka (void) VOP_CLOSE(devvp, openflags, NOCRED);
461 1.13 reinoud VOP_UNLOCK(devvp, 0);
462 1.6 christos }
463 1.6 christos }
464 1.1 reinoud if (error) {
465 1.1 reinoud /* devvp is still locked */
466 1.13 reinoud vrele(devvp);
467 1.1 reinoud return error;
468 1.6 christos }
469 1.1 reinoud
470 1.1 reinoud /* register our mountpoint being on this device */
471 1.1 reinoud devvp->v_specmountpoint = mp;
472 1.1 reinoud
473 1.1 reinoud /* successfully mounted */
474 1.1 reinoud DPRINTF(VOLUMES, ("udf_mount() successfull\n"));
475 1.1 reinoud
476 1.38 reinoud error = set_statvfs_info(path, UIO_USERSPACE, args->fspec, UIO_USERSPACE,
477 1.27 pooka mp->mnt_op->vfs_name, mp, l);
478 1.38 reinoud if (error)
479 1.38 reinoud return error;
480 1.38 reinoud
481 1.38 reinoud /* If we're not opened read-only, open its logical volume */
482 1.38 reinoud if ((mp->mnt_flag & MNT_RDONLY) == 0) {
483 1.38 reinoud if ((error = udf_open_logvol(VFSTOUDF(mp))) != 0) {
484 1.38 reinoud printf( "mount_udf: can't open logical volume for "
485 1.41 reinoud "writing, downgrading access to read-only\n");
486 1.38 reinoud mp->mnt_flag |= MNT_RDONLY;
487 1.38 reinoud /* FIXME we can't return error now on open failure */
488 1.38 reinoud return 0;
489 1.38 reinoud }
490 1.38 reinoud }
491 1.38 reinoud
492 1.38 reinoud return 0;
493 1.1 reinoud }
494 1.1 reinoud
495 1.1 reinoud /* --------------------------------------------------------------------- */
496 1.1 reinoud
497 1.1 reinoud #ifdef DEBUG
498 1.1 reinoud static void
499 1.1 reinoud udf_unmount_sanity_check(struct mount *mp)
500 1.1 reinoud {
501 1.1 reinoud struct vnode *vp;
502 1.1 reinoud
503 1.1 reinoud printf("On unmount, i found the following nodes:\n");
504 1.17 reinoud TAILQ_FOREACH(vp, &mp->mnt_vnodelist, v_mntvnodes) {
505 1.1 reinoud vprint("", vp);
506 1.1 reinoud if (VOP_ISLOCKED(vp) == LK_EXCLUSIVE) {
507 1.1 reinoud printf(" is locked\n");
508 1.6 christos }
509 1.1 reinoud if (vp->v_usecount > 1)
510 1.1 reinoud printf(" more than one usecount %d\n", vp->v_usecount);
511 1.6 christos }
512 1.1 reinoud }
513 1.1 reinoud #endif
514 1.1 reinoud
515 1.1 reinoud
516 1.1 reinoud int
517 1.31 pooka udf_unmount(struct mount *mp, int mntflags)
518 1.1 reinoud {
519 1.1 reinoud struct udf_mount *ump;
520 1.1 reinoud int error, flags, closeflags;
521 1.1 reinoud
522 1.1 reinoud DPRINTF(CALL, ("udf_umount called\n"));
523 1.1 reinoud
524 1.1 reinoud ump = VFSTOUDF(mp);
525 1.1 reinoud if (!ump)
526 1.1 reinoud panic("UDF unmount: empty ump\n");
527 1.1 reinoud
528 1.19 reinoud flags = (mntflags & MNT_FORCE) ? FORCECLOSE : 0;
529 1.1 reinoud /* TODO remove these paranoid functions */
530 1.1 reinoud #ifdef DEBUG
531 1.1 reinoud if (udf_verbose & UDF_DEBUG_LOCKING)
532 1.1 reinoud udf_unmount_sanity_check(mp);
533 1.1 reinoud #endif
534 1.1 reinoud
535 1.19 reinoud /*
536 1.30 ad * By specifying SKIPSYSTEM we can skip vnodes marked with VV_SYSTEM.
537 1.19 reinoud * This hardly documented feature allows us to exempt certain files
538 1.19 reinoud * from being flushed.
539 1.19 reinoud */
540 1.30 ad if ((error = vflush(mp, NULLVP, flags | SKIPSYSTEM)) != 0)
541 1.1 reinoud return error;
542 1.1 reinoud
543 1.38 reinoud /* update nodes and wait for completion of writeout of system nodes */
544 1.38 reinoud udf_sync(mp, FSYNC_WAIT, NOCRED);
545 1.38 reinoud
546 1.1 reinoud #ifdef DEBUG
547 1.1 reinoud if (udf_verbose & UDF_DEBUG_LOCKING)
548 1.1 reinoud udf_unmount_sanity_check(mp);
549 1.1 reinoud #endif
550 1.1 reinoud
551 1.38 reinoud /* flush again, to check if we are still busy for something else */
552 1.38 reinoud if ((error = vflush(ump->vfs_mountp, NULLVP, flags | SKIPSYSTEM)) != 0)
553 1.38 reinoud return error;
554 1.38 reinoud
555 1.38 reinoud DPRINTF(VOLUMES, ("flush OK on unmount\n"));
556 1.1 reinoud
557 1.38 reinoud /* close logical volume and close session if requested */
558 1.38 reinoud if ((error = udf_close_logvol(ump, mntflags)) != 0)
559 1.38 reinoud return error;
560 1.38 reinoud
561 1.38 reinoud #ifdef DEBUG
562 1.38 reinoud DPRINTF(VOLUMES, ("FINAL sanity check\n"));
563 1.38 reinoud if (udf_verbose & UDF_DEBUG_LOCKING)
564 1.38 reinoud udf_unmount_sanity_check(mp);
565 1.38 reinoud #endif
566 1.38 reinoud
567 1.38 reinoud /* NOTE release system nodes should NOT write anything */
568 1.38 reinoud udf_release_system_nodes(mp);
569 1.38 reinoud
570 1.38 reinoud /* finalise disc strategy */
571 1.38 reinoud udf_discstrat_finish(ump);
572 1.38 reinoud
573 1.38 reinoud /* synchronise device caches */
574 1.38 reinoud (void) udf_synchronise_caches(ump);
575 1.1 reinoud
576 1.1 reinoud /* close device */
577 1.1 reinoud DPRINTF(VOLUMES, ("closing device\n"));
578 1.1 reinoud if (mp->mnt_flag & MNT_RDONLY) {
579 1.1 reinoud closeflags = FREAD;
580 1.1 reinoud } else {
581 1.1 reinoud closeflags = FREAD | FWRITE;
582 1.6 christos }
583 1.1 reinoud
584 1.1 reinoud /* devvp is still locked by us */
585 1.1 reinoud vn_lock(ump->devvp, LK_EXCLUSIVE | LK_RETRY);
586 1.31 pooka error = VOP_CLOSE(ump->devvp, closeflags, NOCRED);
587 1.1 reinoud if (error)
588 1.1 reinoud printf("Error during closure of device! error %d, "
589 1.1 reinoud "device might stay locked\n", error);
590 1.1 reinoud DPRINTF(VOLUMES, ("device close ok\n"));
591 1.1 reinoud
592 1.1 reinoud /* clear our mount reference and release device node */
593 1.1 reinoud ump->devvp->v_specmountpoint = NULL;
594 1.1 reinoud vput(ump->devvp);
595 1.1 reinoud
596 1.38 reinoud /* free our ump */
597 1.15 reinoud free_udf_mountinfo(mp);
598 1.15 reinoud
599 1.38 reinoud /* free ump struct references */
600 1.1 reinoud mp->mnt_data = NULL;
601 1.1 reinoud mp->mnt_flag &= ~MNT_LOCAL;
602 1.1 reinoud
603 1.1 reinoud DPRINTF(VOLUMES, ("Fin unmount\n"));
604 1.1 reinoud return error;
605 1.1 reinoud }
606 1.1 reinoud
607 1.1 reinoud /* --------------------------------------------------------------------- */
608 1.1 reinoud
609 1.1 reinoud /*
610 1.1 reinoud * Helper function of udf_mount() that actually mounts the disc.
611 1.1 reinoud */
612 1.1 reinoud
613 1.1 reinoud static int
614 1.1 reinoud udf_mountfs(struct vnode *devvp, struct mount *mp,
615 1.1 reinoud struct lwp *l, struct udf_args *args)
616 1.1 reinoud {
617 1.1 reinoud struct udf_mount *ump;
618 1.1 reinoud uint32_t sector_size, lb_size, bshift;
619 1.38 reinoud uint32_t logvol_integrity;
620 1.1 reinoud int num_anchors, error, lst;
621 1.1 reinoud
622 1.1 reinoud /* flush out any old buffers remaining from a previous use. */
623 1.9 reinoud if ((error = vinvalbuf(devvp, V_SAVE, l->l_cred, l, 0, 0)))
624 1.1 reinoud return error;
625 1.1 reinoud
626 1.38 reinoud /* setup basic mount information */
627 1.38 reinoud mp->mnt_data = NULL;
628 1.38 reinoud mp->mnt_stat.f_fsidx.__fsid_val[0] = (uint32_t) devvp->v_rdev;
629 1.38 reinoud mp->mnt_stat.f_fsidx.__fsid_val[1] = makefstype(MOUNT_UDF);
630 1.38 reinoud mp->mnt_stat.f_fsid = mp->mnt_stat.f_fsidx.__fsid_val[0];
631 1.38 reinoud mp->mnt_stat.f_namemax = UDF_MAX_NAMELEN;
632 1.38 reinoud mp->mnt_flag |= MNT_LOCAL;
633 1.38 reinoud
634 1.24 msaitoh /* allocate udf part of mount structure; malloc always succeeds */
635 1.30 ad ump = malloc(sizeof(struct udf_mount), M_UDFMNT, M_WAITOK | M_ZERO);
636 1.1 reinoud
637 1.1 reinoud /* init locks */
638 1.38 reinoud mutex_init(&ump->logvol_mutex, MUTEX_DEFAULT, IPL_NONE);
639 1.30 ad mutex_init(&ump->ihash_lock, MUTEX_DEFAULT, IPL_NONE);
640 1.30 ad mutex_init(&ump->get_node_lock, MUTEX_DEFAULT, IPL_NONE);
641 1.38 reinoud mutex_init(&ump->allocate_mutex, MUTEX_DEFAULT, IPL_NONE);
642 1.38 reinoud cv_init(&ump->dirtynodes_cv, "udfsync2");
643 1.1 reinoud
644 1.38 reinoud /* init `ino_t' to udf_node hash table and other lists */
645 1.1 reinoud for (lst = 0; lst < UDF_INODE_HASHSIZE; lst++) {
646 1.1 reinoud LIST_INIT(&ump->udf_nodes[lst]);
647 1.6 christos }
648 1.1 reinoud
649 1.1 reinoud /* set up linkage */
650 1.1 reinoud mp->mnt_data = ump;
651 1.1 reinoud ump->vfs_mountp = mp;
652 1.1 reinoud
653 1.1 reinoud /* set up arguments and device */
654 1.1 reinoud ump->mount_args = *args;
655 1.1 reinoud ump->devvp = devvp;
656 1.9 reinoud if ((error = udf_update_discinfo(ump))) {
657 1.1 reinoud printf("UDF mount: error inspecting fs node\n");
658 1.1 reinoud return error;
659 1.6 christos }
660 1.1 reinoud
661 1.1 reinoud /* inspect sector size */
662 1.1 reinoud sector_size = ump->discinfo.sector_size;
663 1.1 reinoud bshift = 1;
664 1.1 reinoud while ((1 << bshift) < sector_size)
665 1.1 reinoud bshift++;
666 1.1 reinoud if ((1 << bshift) != sector_size) {
667 1.1 reinoud printf("UDF mount: "
668 1.1 reinoud "hit NetBSD implementation fence on sector size\n");
669 1.1 reinoud return EIO;
670 1.6 christos }
671 1.1 reinoud
672 1.42 reinoud /* temporary check to overcome sectorsize >= 8192 bytes panic */
673 1.42 reinoud if (sector_size >= 8192) {
674 1.42 reinoud printf("UDF mount: "
675 1.42 reinoud "hit implementation limit, sectorsize to big\n");
676 1.42 reinoud return EIO;
677 1.42 reinoud }
678 1.42 reinoud
679 1.38 reinoud /*
680 1.38 reinoud * Inspect if we're asked to mount read-write on a non recordable or
681 1.38 reinoud * closed sequential disc.
682 1.38 reinoud */
683 1.38 reinoud if ((mp->mnt_flag & MNT_RDONLY) == 0) {
684 1.38 reinoud if ((ump->discinfo.mmc_cur & MMC_CAP_RECORDABLE) == 0) {
685 1.38 reinoud printf("UDF mount: disc is not recordable\n");
686 1.38 reinoud return EROFS;
687 1.38 reinoud }
688 1.38 reinoud /*
689 1.38 reinoud * TODO if on sequential media and last session is closed,
690 1.38 reinoud * check for enough space to open/close new session
691 1.38 reinoud */
692 1.38 reinoud }
693 1.38 reinoud
694 1.38 reinoud /* initialise bootstrap disc strategy */
695 1.38 reinoud ump->strategy = &udf_strat_bootstrap;
696 1.38 reinoud udf_discstrat_init(ump);
697 1.38 reinoud
698 1.1 reinoud /* read all anchors to get volume descriptor sequence */
699 1.38 reinoud num_anchors = udf_read_anchors(ump);
700 1.1 reinoud if (num_anchors == 0)
701 1.38 reinoud return EINVAL;
702 1.1 reinoud
703 1.1 reinoud DPRINTF(VOLUMES, ("Read %d anchors on this disc, session %d\n",
704 1.1 reinoud num_anchors, args->sessionnr));
705 1.1 reinoud
706 1.1 reinoud /* read in volume descriptor sequence */
707 1.9 reinoud if ((error = udf_read_vds_space(ump))) {
708 1.1 reinoud printf("UDF mount: error reading volume space\n");
709 1.9 reinoud return error;
710 1.9 reinoud }
711 1.1 reinoud
712 1.38 reinoud /* close down (direct) disc strategy */
713 1.38 reinoud udf_discstrat_finish(ump);
714 1.38 reinoud
715 1.1 reinoud /* check consistency and completeness */
716 1.38 reinoud if ((error = udf_process_vds(ump))) {
717 1.19 reinoud printf( "UDF mount: disc not properly formatted"
718 1.19 reinoud "(bad VDS)\n");
719 1.9 reinoud return error;
720 1.6 christos }
721 1.1 reinoud
722 1.38 reinoud /* switch to new disc strategy */
723 1.38 reinoud KASSERT(ump->strategy != &udf_strat_bootstrap);
724 1.38 reinoud udf_discstrat_init(ump);
725 1.38 reinoud
726 1.38 reinoud /* initialise late allocation administration space */
727 1.38 reinoud ump->la_lmapping = malloc(sizeof(uint64_t) * UDF_MAX_MAPPINGS,
728 1.38 reinoud M_TEMP, M_WAITOK);
729 1.38 reinoud ump->la_pmapping = malloc(sizeof(uint64_t) * UDF_MAX_MAPPINGS,
730 1.38 reinoud M_TEMP, M_WAITOK);
731 1.38 reinoud
732 1.38 reinoud /* setup node cleanup extents copy space */
733 1.1 reinoud lb_size = udf_rw32(ump->logical_vol->lb_size);
734 1.38 reinoud ump->la_node_ad_cpy = malloc(lb_size * UDF_MAX_ALLOC_EXTENTS,
735 1.38 reinoud M_UDFMNT, M_WAITOK);
736 1.38 reinoud memset(ump->la_node_ad_cpy, 0, lb_size * UDF_MAX_ALLOC_EXTENTS);
737 1.38 reinoud
738 1.38 reinoud /* setup rest of mount information */
739 1.38 reinoud mp->mnt_data = ump;
740 1.38 reinoud
741 1.38 reinoud /* bshift is allways equal to disc sector size */
742 1.38 reinoud mp->mnt_dev_bshift = bshift;
743 1.38 reinoud mp->mnt_fs_bshift = bshift;
744 1.1 reinoud
745 1.38 reinoud /* note that the mp info needs to be initialised for reading! */
746 1.1 reinoud /* read vds support tables like VAT, sparable etc. */
747 1.38 reinoud if ((error = udf_read_vds_tables(ump))) {
748 1.19 reinoud printf( "UDF mount: error in format or damaged disc "
749 1.19 reinoud "(VDS tables failing)\n");
750 1.9 reinoud return error;
751 1.6 christos }
752 1.9 reinoud
753 1.38 reinoud /* check if volume integrity is closed otherwise its dirty */
754 1.38 reinoud logvol_integrity = udf_rw32(ump->logvol_integrity->integrity_type);
755 1.38 reinoud if (logvol_integrity != UDF_INTEGRITY_CLOSED) {
756 1.38 reinoud printf("UDF mount: file system is not clean; ");
757 1.38 reinoud printf("please fsck(8)\n");
758 1.38 reinoud return EPERM;
759 1.38 reinoud }
760 1.38 reinoud
761 1.38 reinoud /* read root directory */
762 1.38 reinoud if ((error = udf_read_rootdirs(ump))) {
763 1.19 reinoud printf( "UDF mount: "
764 1.19 reinoud "disc not properly formatted or damaged disc "
765 1.19 reinoud "(rootdirs failing)\n");
766 1.1 reinoud return error;
767 1.9 reinoud }
768 1.1 reinoud
769 1.1 reinoud /* do we have to set this? */
770 1.1 reinoud devvp->v_specmountpoint = mp;
771 1.1 reinoud
772 1.1 reinoud /* success! */
773 1.1 reinoud return 0;
774 1.1 reinoud }
775 1.1 reinoud
776 1.1 reinoud /* --------------------------------------------------------------------- */
777 1.1 reinoud
778 1.1 reinoud int
779 1.31 pooka udf_start(struct mount *mp, int flags)
780 1.1 reinoud {
781 1.1 reinoud /* do we have to do something here? */
782 1.1 reinoud return 0;
783 1.1 reinoud }
784 1.1 reinoud
785 1.1 reinoud /* --------------------------------------------------------------------- */
786 1.1 reinoud
787 1.1 reinoud int
788 1.1 reinoud udf_root(struct mount *mp, struct vnode **vpp)
789 1.1 reinoud {
790 1.1 reinoud struct vnode *vp;
791 1.1 reinoud struct long_ad *dir_loc;
792 1.1 reinoud struct udf_mount *ump = VFSTOUDF(mp);
793 1.1 reinoud struct udf_node *root_dir;
794 1.1 reinoud int error;
795 1.1 reinoud
796 1.1 reinoud DPRINTF(CALL, ("udf_root called\n"));
797 1.1 reinoud
798 1.1 reinoud dir_loc = &ump->fileset_desc->rootdir_icb;
799 1.1 reinoud error = udf_get_node(ump, dir_loc, &root_dir);
800 1.1 reinoud
801 1.1 reinoud if (!root_dir)
802 1.1 reinoud error = ENOENT;
803 1.1 reinoud if (error)
804 1.1 reinoud return error;
805 1.1 reinoud
806 1.1 reinoud vp = root_dir->vnode;
807 1.30 ad root_dir->vnode->v_vflag |= VV_ROOT;
808 1.1 reinoud
809 1.1 reinoud *vpp = vp;
810 1.1 reinoud return 0;
811 1.1 reinoud }
812 1.1 reinoud
813 1.1 reinoud /* --------------------------------------------------------------------- */
814 1.1 reinoud
815 1.1 reinoud int
816 1.31 pooka udf_statvfs(struct mount *mp, struct statvfs *sbp)
817 1.1 reinoud {
818 1.1 reinoud struct udf_mount *ump = VFSTOUDF(mp);
819 1.1 reinoud struct logvol_int_desc *lvid;
820 1.1 reinoud struct udf_logvol_info *impl;
821 1.1 reinoud uint64_t freeblks, sizeblks;
822 1.1 reinoud uint32_t *pos1, *pos2;
823 1.1 reinoud int part, num_part;
824 1.1 reinoud
825 1.1 reinoud DPRINTF(CALL, ("udf_statvfs called\n"));
826 1.1 reinoud sbp->f_flag = mp->mnt_flag;
827 1.1 reinoud sbp->f_bsize = ump->discinfo.sector_size;
828 1.1 reinoud sbp->f_frsize = ump->discinfo.sector_size;
829 1.1 reinoud sbp->f_iosize = ump->discinfo.sector_size;
830 1.1 reinoud
831 1.38 reinoud mutex_enter(&ump->allocate_mutex);
832 1.1 reinoud lvid = ump->logvol_integrity;
833 1.38 reinoud freeblks = sizeblks = 0;
834 1.1 reinoud
835 1.38 reinoud /* Sequentials report free space directly (CD/DVD/BD-R) */
836 1.38 reinoud KASSERT(lvid);
837 1.38 reinoud num_part = udf_rw32(lvid->num_part);
838 1.38 reinoud impl = (struct udf_logvol_info *) (lvid->tables + 2*num_part);
839 1.38 reinoud
840 1.38 reinoud if (ump->discinfo.mmc_cur & MMC_CAP_SEQUENTIAL) {
841 1.38 reinoud /* XXX assumption at most two tracks open */
842 1.38 reinoud freeblks = ump->data_track.free_blocks;
843 1.38 reinoud if (ump->data_track.tracknr != ump->metadata_track.tracknr)
844 1.38 reinoud freeblks += ump->metadata_track.free_blocks;
845 1.38 reinoud sizeblks = ump->discinfo.last_possible_lba;
846 1.38 reinoud } else {
847 1.38 reinoud /* free and used space for mountpoint based on logvol integrity */
848 1.1 reinoud for (part=0; part < num_part; part++) {
849 1.1 reinoud pos1 = &lvid->tables[0] + part;
850 1.1 reinoud pos2 = &lvid->tables[0] + num_part + part;
851 1.1 reinoud if (udf_rw32(*pos1) != (uint32_t) -1) {
852 1.1 reinoud freeblks += udf_rw32(*pos1);
853 1.1 reinoud sizeblks += udf_rw32(*pos2);
854 1.6 christos }
855 1.6 christos }
856 1.38 reinoud }
857 1.38 reinoud freeblks -= ump->uncomitted_lb;
858 1.38 reinoud
859 1.38 reinoud sbp->f_blocks = sizeblks;
860 1.38 reinoud sbp->f_bfree = freeblks;
861 1.38 reinoud sbp->f_files = 0;
862 1.38 reinoud if (impl) {
863 1.1 reinoud sbp->f_files = udf_rw32(impl->num_files);
864 1.1 reinoud sbp->f_files += udf_rw32(impl->num_directories);
865 1.38 reinoud }
866 1.38 reinoud
867 1.38 reinoud /* XXX read only for now XXX */
868 1.38 reinoud sbp->f_bavail = 0;
869 1.38 reinoud sbp->f_bresvd = 0;
870 1.38 reinoud
871 1.38 reinoud /* tricky, next only aplies to ffs i think, so set to zero */
872 1.38 reinoud sbp->f_ffree = 0;
873 1.38 reinoud sbp->f_favail = 0;
874 1.38 reinoud sbp->f_fresvd = 0;
875 1.1 reinoud
876 1.38 reinoud mutex_exit(&ump->allocate_mutex);
877 1.1 reinoud
878 1.1 reinoud copy_statvfs_info(sbp, mp);
879 1.1 reinoud return 0;
880 1.1 reinoud }
881 1.1 reinoud
882 1.1 reinoud /* --------------------------------------------------------------------- */
883 1.1 reinoud
884 1.38 reinoud /*
885 1.38 reinoud * TODO what about writing out free space maps, lvid etc? only on `waitfor'
886 1.38 reinoud * i.e. explicit syncing by the user?
887 1.38 reinoud */
888 1.38 reinoud
889 1.1 reinoud int
890 1.38 reinoud udf_sync(struct mount *mp, int waitfor, kauth_cred_t cred)
891 1.1 reinoud {
892 1.38 reinoud struct udf_mount *ump = VFSTOUDF(mp);
893 1.38 reinoud int error;
894 1.38 reinoud
895 1.1 reinoud DPRINTF(CALL, ("udf_sync called\n"));
896 1.38 reinoud /* if called when mounted readonly, just ignore */
897 1.38 reinoud if (mp->mnt_flag & MNT_RDONLY)
898 1.38 reinoud return 0;
899 1.38 reinoud
900 1.38 reinoud if (ump->syncing && !waitfor) {
901 1.38 reinoud printf("UDF: skipping autosync\n");
902 1.38 reinoud return 0;
903 1.38 reinoud }
904 1.38 reinoud
905 1.38 reinoud /* get sync lock */
906 1.38 reinoud ump->syncing = 1;
907 1.38 reinoud
908 1.38 reinoud udf_do_sync(ump, cred, waitfor);
909 1.38 reinoud
910 1.38 reinoud if (waitfor == MNT_WAIT) {
911 1.38 reinoud /* XXX lock for VAT en bitmaps? */
912 1.38 reinoud /* metadata nodes are written synchronous */
913 1.38 reinoud DPRINTF(CALL, ("udf_sync: syncing metadata\n"));
914 1.38 reinoud if (ump->lvclose & UDF_WRITE_VAT)
915 1.38 reinoud udf_writeout_vat(ump);
916 1.38 reinoud if (ump->lvclose & UDF_WRITE_PART_BITMAPS) {
917 1.44 reinoud error = udf_write_physical_partition_spacetables(ump,
918 1.44 reinoud waitfor);
919 1.38 reinoud if (error) {
920 1.38 reinoud printf( "udf_close_logvol: writeout of space "
921 1.38 reinoud "tables failed\n");
922 1.38 reinoud }
923 1.38 reinoud ump->lvclose &= ~UDF_WRITE_PART_BITMAPS;
924 1.38 reinoud }
925 1.38 reinoud
926 1.38 reinoud }
927 1.38 reinoud DPRINTF(CALL, ("end of udf_sync()\n"));
928 1.38 reinoud ump->syncing = 0;
929 1.38 reinoud
930 1.1 reinoud return 0;
931 1.1 reinoud }
932 1.1 reinoud
933 1.1 reinoud /* --------------------------------------------------------------------- */
934 1.1 reinoud
935 1.1 reinoud /*
936 1.1 reinoud * Get vnode for the file system type specific file id ino for the fs. Its
937 1.1 reinoud * used for reference to files by unique ID and for NFSv3.
938 1.1 reinoud * (optional) TODO lookup why some sources state NFSv3
939 1.1 reinoud */
940 1.1 reinoud int
941 1.18 christos udf_vget(struct mount *mp, ino_t ino,
942 1.18 christos struct vnode **vpp)
943 1.1 reinoud {
944 1.1 reinoud DPRINTF(NOTIMPL, ("udf_vget called\n"));
945 1.1 reinoud return EOPNOTSUPP;
946 1.1 reinoud }
947 1.1 reinoud
948 1.1 reinoud /* --------------------------------------------------------------------- */
949 1.1 reinoud
950 1.1 reinoud /*
951 1.1 reinoud * Lookup vnode for file handle specified
952 1.1 reinoud */
953 1.1 reinoud int
954 1.18 christos udf_fhtovp(struct mount *mp, struct fid *fhp,
955 1.18 christos struct vnode **vpp)
956 1.1 reinoud {
957 1.1 reinoud DPRINTF(NOTIMPL, ("udf_fhtovp called\n"));
958 1.1 reinoud return EOPNOTSUPP;
959 1.1 reinoud }
960 1.1 reinoud
961 1.1 reinoud /* --------------------------------------------------------------------- */
962 1.1 reinoud
963 1.1 reinoud /*
964 1.1 reinoud * Create an unique file handle. Its structure is opaque and won't be used by
965 1.1 reinoud * other subsystems. It should uniquely identify the file in the filingsystem
966 1.1 reinoud * and enough information to know if a file has been removed and/or resources
967 1.1 reinoud * have been recycled.
968 1.1 reinoud */
969 1.1 reinoud int
970 1.18 christos udf_vptofh(struct vnode *vp, struct fid *fid,
971 1.18 christos size_t *fh_size)
972 1.1 reinoud {
973 1.1 reinoud DPRINTF(NOTIMPL, ("udf_vptofh called\n"));
974 1.1 reinoud return EOPNOTSUPP;
975 1.1 reinoud }
976 1.1 reinoud
977 1.1 reinoud /* --------------------------------------------------------------------- */
978 1.1 reinoud
979 1.1 reinoud /*
980 1.1 reinoud * Create a filingsystem snapshot at the specified timestamp. Could be
981 1.1 reinoud * implemented by explicitly creating a new session or with spare room in the
982 1.1 reinoud * integrity descriptor space
983 1.1 reinoud */
984 1.1 reinoud int
985 1.18 christos udf_snapshot(struct mount *mp, struct vnode *vp,
986 1.18 christos struct timespec *tm)
987 1.1 reinoud {
988 1.1 reinoud DPRINTF(NOTIMPL, ("udf_snapshot called\n"));
989 1.1 reinoud return EOPNOTSUPP;
990 1.1 reinoud }
991 1.14 reinoud
992 1.14 reinoud /* --------------------------------------------------------------------- */
993