]>
Commit | Line | Data |
---|---|---|
1da177e4 LT |
1 | /* |
2 | * super.c | |
3 | * | |
4 | * PURPOSE | |
5 | * Super block routines for the OSTA-UDF(tm) filesystem. | |
6 | * | |
7 | * DESCRIPTION | |
8 | * OSTA-UDF(tm) = Optical Storage Technology Association | |
9 | * Universal Disk Format. | |
10 | * | |
11 | * This code is based on version 2.00 of the UDF specification, | |
12 | * and revision 3 of the ECMA 167 standard [equivalent to ISO 13346]. | |
13 | * http://www.osta.org/ | |
14 | * http://www.ecma.ch/ | |
15 | * http://www.iso.org/ | |
16 | * | |
1da177e4 LT |
17 | * COPYRIGHT |
18 | * This file is distributed under the terms of the GNU General Public | |
19 | * License (GPL). Copies of the GPL can be obtained from: | |
20 | * ftp://prep.ai.mit.edu/pub/gnu/GPL | |
21 | * Each contributing author retains all rights to their own work. | |
22 | * | |
23 | * (C) 1998 Dave Boynton | |
24 | * (C) 1998-2004 Ben Fennema | |
25 | * (C) 2000 Stelias Computing Inc | |
26 | * | |
27 | * HISTORY | |
28 | * | |
29 | * 09/24/98 dgb changed to allow compiling outside of kernel, and | |
30 | * added some debugging. | |
31 | * 10/01/98 dgb updated to allow (some) possibility of compiling w/2.0.34 | |
32 | * 10/16/98 attempting some multi-session support | |
33 | * 10/17/98 added freespace count for "df" | |
34 | * 11/11/98 gr added novrs option | |
35 | * 11/26/98 dgb added fileset,anchor mount options | |
36 | * 12/06/98 blf really hosed things royally. vat/sparing support. sequenced vol descs | |
37 | * rewrote option handling based on isofs | |
38 | * 12/20/98 find the free space bitmap (if it exists) | |
39 | */ | |
40 | ||
cb00ea35 | 41 | #include "udfdecl.h" |
1da177e4 | 42 | |
1da177e4 LT |
43 | #include <linux/blkdev.h> |
44 | #include <linux/slab.h> | |
45 | #include <linux/kernel.h> | |
46 | #include <linux/module.h> | |
47 | #include <linux/parser.h> | |
48 | #include <linux/stat.h> | |
49 | #include <linux/cdrom.h> | |
50 | #include <linux/nls.h> | |
51 | #include <linux/smp_lock.h> | |
52 | #include <linux/buffer_head.h> | |
53 | #include <linux/vfs.h> | |
54 | #include <linux/vmalloc.h> | |
55 | #include <asm/byteorder.h> | |
56 | ||
57 | #include <linux/udf_fs.h> | |
58 | #include "udf_sb.h" | |
59 | #include "udf_i.h" | |
60 | ||
61 | #include <linux/init.h> | |
62 | #include <asm/uaccess.h> | |
63 | ||
64 | #define VDS_POS_PRIMARY_VOL_DESC 0 | |
65 | #define VDS_POS_UNALLOC_SPACE_DESC 1 | |
66 | #define VDS_POS_LOGICAL_VOL_DESC 2 | |
67 | #define VDS_POS_PARTITION_DESC 3 | |
68 | #define VDS_POS_IMP_USE_VOL_DESC 4 | |
69 | #define VDS_POS_VOL_DESC_PTR 5 | |
70 | #define VDS_POS_TERMINATING_DESC 6 | |
71 | #define VDS_POS_LENGTH 7 | |
72 | ||
73 | static char error_buf[1024]; | |
74 | ||
75 | /* These are the "meat" - everything else is stuffing */ | |
76 | static int udf_fill_super(struct super_block *, void *, int); | |
77 | static void udf_put_super(struct super_block *); | |
78 | static void udf_write_super(struct super_block *); | |
79 | static int udf_remount_fs(struct super_block *, int *, char *); | |
80 | static int udf_check_valid(struct super_block *, int, int); | |
81 | static int udf_vrs(struct super_block *sb, int silent); | |
82 | static int udf_load_partition(struct super_block *, kernel_lb_addr *); | |
cb00ea35 CG |
83 | static int udf_load_logicalvol(struct super_block *, struct buffer_head *, |
84 | kernel_lb_addr *); | |
1da177e4 LT |
85 | static void udf_load_logicalvolint(struct super_block *, kernel_extent_ad); |
86 | static void udf_find_anchor(struct super_block *); | |
cb00ea35 CG |
87 | static int udf_find_fileset(struct super_block *, kernel_lb_addr *, |
88 | kernel_lb_addr *); | |
1da177e4 | 89 | static void udf_load_pvoldesc(struct super_block *, struct buffer_head *); |
cb00ea35 CG |
90 | static void udf_load_fileset(struct super_block *, struct buffer_head *, |
91 | kernel_lb_addr *); | |
bcec4477 | 92 | static int udf_load_partdesc(struct super_block *, struct buffer_head *); |
1da177e4 LT |
93 | static void udf_open_lvid(struct super_block *); |
94 | static void udf_close_lvid(struct super_block *); | |
95 | static unsigned int udf_count_free(struct super_block *); | |
726c3342 | 96 | static int udf_statfs(struct dentry *, struct kstatfs *); |
1da177e4 LT |
97 | |
98 | /* UDF filesystem type */ | |
454e2398 | 99 | static int udf_get_sb(struct file_system_type *fs_type, |
cb00ea35 CG |
100 | int flags, const char *dev_name, void *data, |
101 | struct vfsmount *mnt) | |
1da177e4 | 102 | { |
454e2398 | 103 | return get_sb_bdev(fs_type, flags, dev_name, data, udf_fill_super, mnt); |
1da177e4 LT |
104 | } |
105 | ||
106 | static struct file_system_type udf_fstype = { | |
28de7948 CG |
107 | .owner = THIS_MODULE, |
108 | .name = "udf", | |
109 | .get_sb = udf_get_sb, | |
110 | .kill_sb = kill_block_super, | |
111 | .fs_flags = FS_REQUIRES_DEV, | |
1da177e4 LT |
112 | }; |
113 | ||
cb00ea35 | 114 | static struct kmem_cache *udf_inode_cachep; |
1da177e4 LT |
115 | |
116 | static struct inode *udf_alloc_inode(struct super_block *sb) | |
117 | { | |
118 | struct udf_inode_info *ei; | |
28de7948 | 119 | ei = (struct udf_inode_info *)kmem_cache_alloc(udf_inode_cachep, GFP_KERNEL); |
1da177e4 LT |
120 | if (!ei) |
121 | return NULL; | |
95f8797f DB |
122 | |
123 | ei->i_unique = 0; | |
124 | ei->i_lenExtents = 0; | |
125 | ei->i_next_alloc_block = 0; | |
126 | ei->i_next_alloc_goal = 0; | |
127 | ei->i_strat4096 = 0; | |
128 | ||
1da177e4 LT |
129 | return &ei->vfs_inode; |
130 | } | |
131 | ||
132 | static void udf_destroy_inode(struct inode *inode) | |
133 | { | |
134 | kmem_cache_free(udf_inode_cachep, UDF_I(inode)); | |
135 | } | |
136 | ||
cb00ea35 | 137 | static void init_once(void *foo, struct kmem_cache *cachep, unsigned long flags) |
1da177e4 | 138 | { |
cb00ea35 | 139 | struct udf_inode_info *ei = (struct udf_inode_info *)foo; |
1da177e4 | 140 | |
a35afb83 CL |
141 | ei->i_ext.i_data = NULL; |
142 | inode_init_once(&ei->vfs_inode); | |
1da177e4 LT |
143 | } |
144 | ||
145 | static int init_inodecache(void) | |
146 | { | |
147 | udf_inode_cachep = kmem_cache_create("udf_inode_cache", | |
148 | sizeof(struct udf_inode_info), | |
cb00ea35 CG |
149 | 0, (SLAB_RECLAIM_ACCOUNT | |
150 | SLAB_MEM_SPREAD), | |
20c2df83 | 151 | init_once); |
28de7948 | 152 | if (!udf_inode_cachep) |
1da177e4 LT |
153 | return -ENOMEM; |
154 | return 0; | |
155 | } | |
156 | ||
157 | static void destroy_inodecache(void) | |
158 | { | |
1a1d92c1 | 159 | kmem_cache_destroy(udf_inode_cachep); |
1da177e4 LT |
160 | } |
161 | ||
162 | /* Superblock operations */ | |
ee9b6d61 | 163 | static const struct super_operations udf_sb_ops = { |
28de7948 CG |
164 | .alloc_inode = udf_alloc_inode, |
165 | .destroy_inode = udf_destroy_inode, | |
166 | .write_inode = udf_write_inode, | |
167 | .delete_inode = udf_delete_inode, | |
168 | .clear_inode = udf_clear_inode, | |
169 | .put_super = udf_put_super, | |
170 | .write_super = udf_write_super, | |
171 | .statfs = udf_statfs, | |
172 | .remount_fs = udf_remount_fs, | |
1da177e4 LT |
173 | }; |
174 | ||
cb00ea35 | 175 | struct udf_options { |
1da177e4 LT |
176 | unsigned char novrs; |
177 | unsigned int blocksize; | |
178 | unsigned int session; | |
179 | unsigned int lastblock; | |
180 | unsigned int anchor; | |
181 | unsigned int volume; | |
182 | unsigned short partition; | |
183 | unsigned int fileset; | |
184 | unsigned int rootdir; | |
185 | unsigned int flags; | |
186 | mode_t umask; | |
187 | gid_t gid; | |
188 | uid_t uid; | |
189 | struct nls_table *nls_map; | |
190 | }; | |
191 | ||
192 | static int __init init_udf_fs(void) | |
193 | { | |
194 | int err; | |
28de7948 | 195 | |
1da177e4 LT |
196 | err = init_inodecache(); |
197 | if (err) | |
198 | goto out1; | |
199 | err = register_filesystem(&udf_fstype); | |
200 | if (err) | |
201 | goto out; | |
28de7948 | 202 | |
1da177e4 | 203 | return 0; |
28de7948 CG |
204 | |
205 | out: | |
1da177e4 | 206 | destroy_inodecache(); |
28de7948 CG |
207 | |
208 | out1: | |
1da177e4 LT |
209 | return err; |
210 | } | |
211 | ||
212 | static void __exit exit_udf_fs(void) | |
213 | { | |
214 | unregister_filesystem(&udf_fstype); | |
215 | destroy_inodecache(); | |
216 | } | |
217 | ||
218 | module_init(init_udf_fs) | |
28de7948 | 219 | module_exit(exit_udf_fs) |
1da177e4 LT |
220 | |
221 | /* | |
222 | * udf_parse_options | |
223 | * | |
224 | * PURPOSE | |
225 | * Parse mount options. | |
226 | * | |
227 | * DESCRIPTION | |
228 | * The following mount options are supported: | |
229 | * | |
230 | * gid= Set the default group. | |
231 | * umask= Set the default umask. | |
232 | * uid= Set the default user. | |
233 | * bs= Set the block size. | |
234 | * unhide Show otherwise hidden files. | |
235 | * undelete Show deleted files in lists. | |
236 | * adinicb Embed data in the inode (default) | |
237 | * noadinicb Don't embed data in the inode | |
238 | * shortad Use short ad's | |
239 | * longad Use long ad's (default) | |
240 | * nostrict Unset strict conformance | |
241 | * iocharset= Set the NLS character set | |
242 | * | |
243 | * The remaining are for debugging and disaster recovery: | |
244 | * | |
28de7948 | 245 | * novrs Skip volume sequence recognition |
1da177e4 LT |
246 | * |
247 | * The following expect a offset from 0. | |
248 | * | |
249 | * session= Set the CDROM session (default= last session) | |
250 | * anchor= Override standard anchor location. (default= 256) | |
251 | * volume= Override the VolumeDesc location. (unused) | |
252 | * partition= Override the PartitionDesc location. (unused) | |
253 | * lastblock= Set the last block of the filesystem/ | |
254 | * | |
255 | * The following expect a offset from the partition root. | |
256 | * | |
257 | * fileset= Override the fileset block location. (unused) | |
258 | * rootdir= Override the root directory location. (unused) | |
259 | * WARNING: overriding the rootdir to a non-directory may | |
260 | * yield highly unpredictable results. | |
261 | * | |
262 | * PRE-CONDITIONS | |
263 | * options Pointer to mount options string. | |
264 | * uopts Pointer to mount options variable. | |
265 | * | |
266 | * POST-CONDITIONS | |
267 | * <return> 1 Mount options parsed okay. | |
268 | * <return> 0 Error parsing mount options. | |
269 | * | |
270 | * HISTORY | |
271 | * July 1, 1997 - Andrew E. Mileski | |
272 | * Written, tested, and released. | |
273 | */ | |
28de7948 | 274 | |
1da177e4 LT |
275 | enum { |
276 | Opt_novrs, Opt_nostrict, Opt_bs, Opt_unhide, Opt_undelete, | |
277 | Opt_noadinicb, Opt_adinicb, Opt_shortad, Opt_longad, | |
278 | Opt_gid, Opt_uid, Opt_umask, Opt_session, Opt_lastblock, | |
279 | Opt_anchor, Opt_volume, Opt_partition, Opt_fileset, | |
280 | Opt_rootdir, Opt_utf8, Opt_iocharset, | |
4d6660eb | 281 | Opt_err, Opt_uforget, Opt_uignore, Opt_gforget, Opt_gignore |
1da177e4 LT |
282 | }; |
283 | ||
284 | static match_table_t tokens = { | |
28de7948 CG |
285 | {Opt_novrs, "novrs"}, |
286 | {Opt_nostrict, "nostrict"}, | |
287 | {Opt_bs, "bs=%u"}, | |
288 | {Opt_unhide, "unhide"}, | |
289 | {Opt_undelete, "undelete"}, | |
290 | {Opt_noadinicb, "noadinicb"}, | |
291 | {Opt_adinicb, "adinicb"}, | |
292 | {Opt_shortad, "shortad"}, | |
293 | {Opt_longad, "longad"}, | |
294 | {Opt_uforget, "uid=forget"}, | |
295 | {Opt_uignore, "uid=ignore"}, | |
296 | {Opt_gforget, "gid=forget"}, | |
297 | {Opt_gignore, "gid=ignore"}, | |
298 | {Opt_gid, "gid=%u"}, | |
299 | {Opt_uid, "uid=%u"}, | |
300 | {Opt_umask, "umask=%o"}, | |
301 | {Opt_session, "session=%u"}, | |
302 | {Opt_lastblock, "lastblock=%u"}, | |
303 | {Opt_anchor, "anchor=%u"}, | |
304 | {Opt_volume, "volume=%u"}, | |
305 | {Opt_partition, "partition=%u"}, | |
306 | {Opt_fileset, "fileset=%u"}, | |
307 | {Opt_rootdir, "rootdir=%u"}, | |
308 | {Opt_utf8, "utf8"}, | |
309 | {Opt_iocharset, "iocharset=%s"}, | |
310 | {Opt_err, NULL} | |
1da177e4 LT |
311 | }; |
312 | ||
cb00ea35 | 313 | static int udf_parse_options(char *options, struct udf_options *uopt) |
1da177e4 LT |
314 | { |
315 | char *p; | |
316 | int option; | |
317 | ||
318 | uopt->novrs = 0; | |
319 | uopt->blocksize = 2048; | |
320 | uopt->partition = 0xFFFF; | |
321 | uopt->session = 0xFFFFFFFF; | |
322 | uopt->lastblock = 0; | |
323 | uopt->anchor = 0; | |
324 | uopt->volume = 0xFFFFFFFF; | |
325 | uopt->rootdir = 0xFFFFFFFF; | |
326 | uopt->fileset = 0xFFFFFFFF; | |
327 | uopt->nls_map = NULL; | |
328 | ||
329 | if (!options) | |
330 | return 1; | |
331 | ||
cb00ea35 | 332 | while ((p = strsep(&options, ",")) != NULL) { |
1da177e4 LT |
333 | substring_t args[MAX_OPT_ARGS]; |
334 | int token; | |
335 | if (!*p) | |
336 | continue; | |
337 | ||
338 | token = match_token(p, tokens, args); | |
cb00ea35 CG |
339 | switch (token) { |
340 | case Opt_novrs: | |
341 | uopt->novrs = 1; | |
342 | case Opt_bs: | |
343 | if (match_int(&args[0], &option)) | |
344 | return 0; | |
345 | uopt->blocksize = option; | |
346 | break; | |
347 | case Opt_unhide: | |
348 | uopt->flags |= (1 << UDF_FLAG_UNHIDE); | |
349 | break; | |
350 | case Opt_undelete: | |
351 | uopt->flags |= (1 << UDF_FLAG_UNDELETE); | |
352 | break; | |
353 | case Opt_noadinicb: | |
354 | uopt->flags &= ~(1 << UDF_FLAG_USE_AD_IN_ICB); | |
355 | break; | |
356 | case Opt_adinicb: | |
357 | uopt->flags |= (1 << UDF_FLAG_USE_AD_IN_ICB); | |
358 | break; | |
359 | case Opt_shortad: | |
360 | uopt->flags |= (1 << UDF_FLAG_USE_SHORT_AD); | |
361 | break; | |
362 | case Opt_longad: | |
363 | uopt->flags &= ~(1 << UDF_FLAG_USE_SHORT_AD); | |
364 | break; | |
365 | case Opt_gid: | |
366 | if (match_int(args, &option)) | |
367 | return 0; | |
368 | uopt->gid = option; | |
ca76d2d8 | 369 | uopt->flags |= (1 << UDF_FLAG_GID_SET); |
cb00ea35 CG |
370 | break; |
371 | case Opt_uid: | |
372 | if (match_int(args, &option)) | |
373 | return 0; | |
374 | uopt->uid = option; | |
ca76d2d8 | 375 | uopt->flags |= (1 << UDF_FLAG_UID_SET); |
cb00ea35 CG |
376 | break; |
377 | case Opt_umask: | |
378 | if (match_octal(args, &option)) | |
379 | return 0; | |
380 | uopt->umask = option; | |
381 | break; | |
382 | case Opt_nostrict: | |
383 | uopt->flags &= ~(1 << UDF_FLAG_STRICT); | |
384 | break; | |
385 | case Opt_session: | |
386 | if (match_int(args, &option)) | |
387 | return 0; | |
388 | uopt->session = option; | |
389 | break; | |
390 | case Opt_lastblock: | |
391 | if (match_int(args, &option)) | |
392 | return 0; | |
393 | uopt->lastblock = option; | |
394 | break; | |
395 | case Opt_anchor: | |
396 | if (match_int(args, &option)) | |
397 | return 0; | |
398 | uopt->anchor = option; | |
399 | break; | |
400 | case Opt_volume: | |
401 | if (match_int(args, &option)) | |
402 | return 0; | |
403 | uopt->volume = option; | |
404 | break; | |
405 | case Opt_partition: | |
406 | if (match_int(args, &option)) | |
407 | return 0; | |
408 | uopt->partition = option; | |
409 | break; | |
410 | case Opt_fileset: | |
411 | if (match_int(args, &option)) | |
412 | return 0; | |
413 | uopt->fileset = option; | |
414 | break; | |
415 | case Opt_rootdir: | |
416 | if (match_int(args, &option)) | |
417 | return 0; | |
418 | uopt->rootdir = option; | |
419 | break; | |
420 | case Opt_utf8: | |
421 | uopt->flags |= (1 << UDF_FLAG_UTF8); | |
422 | break; | |
1da177e4 | 423 | #ifdef CONFIG_UDF_NLS |
cb00ea35 CG |
424 | case Opt_iocharset: |
425 | uopt->nls_map = load_nls(args[0].from); | |
426 | uopt->flags |= (1 << UDF_FLAG_NLS_MAP); | |
427 | break; | |
1da177e4 | 428 | #endif |
cb00ea35 CG |
429 | case Opt_uignore: |
430 | uopt->flags |= (1 << UDF_FLAG_UID_IGNORE); | |
431 | break; | |
432 | case Opt_uforget: | |
433 | uopt->flags |= (1 << UDF_FLAG_UID_FORGET); | |
434 | break; | |
435 | case Opt_gignore: | |
436 | uopt->flags |= (1 << UDF_FLAG_GID_IGNORE); | |
437 | break; | |
438 | case Opt_gforget: | |
439 | uopt->flags |= (1 << UDF_FLAG_GID_FORGET); | |
440 | break; | |
441 | default: | |
442 | printk(KERN_ERR "udf: bad mount option \"%s\" " | |
443 | "or missing value\n", p); | |
1da177e4 LT |
444 | return 0; |
445 | } | |
446 | } | |
447 | return 1; | |
448 | } | |
449 | ||
cb00ea35 | 450 | void udf_write_super(struct super_block *sb) |
1da177e4 LT |
451 | { |
452 | lock_kernel(); | |
28de7948 | 453 | |
1da177e4 LT |
454 | if (!(sb->s_flags & MS_RDONLY)) |
455 | udf_open_lvid(sb); | |
456 | sb->s_dirt = 0; | |
28de7948 | 457 | |
1da177e4 LT |
458 | unlock_kernel(); |
459 | } | |
460 | ||
cb00ea35 | 461 | static int udf_remount_fs(struct super_block *sb, int *flags, char *options) |
1da177e4 LT |
462 | { |
463 | struct udf_options uopt; | |
464 | ||
cb00ea35 | 465 | uopt.flags = UDF_SB(sb)->s_flags; |
28de7948 CG |
466 | uopt.uid = UDF_SB(sb)->s_uid; |
467 | uopt.gid = UDF_SB(sb)->s_gid; | |
cb00ea35 | 468 | uopt.umask = UDF_SB(sb)->s_umask; |
1da177e4 | 469 | |
cb00ea35 | 470 | if (!udf_parse_options(options, &uopt)) |
1da177e4 LT |
471 | return -EINVAL; |
472 | ||
473 | UDF_SB(sb)->s_flags = uopt.flags; | |
28de7948 CG |
474 | UDF_SB(sb)->s_uid = uopt.uid; |
475 | UDF_SB(sb)->s_gid = uopt.gid; | |
1da177e4 LT |
476 | UDF_SB(sb)->s_umask = uopt.umask; |
477 | ||
478 | if (UDF_SB_LVIDBH(sb)) { | |
479 | int write_rev = le16_to_cpu(UDF_SB_LVIDIU(sb)->minUDFWriteRev); | |
480 | if (write_rev > UDF_MAX_WRITE_VERSION) | |
481 | *flags |= MS_RDONLY; | |
482 | } | |
483 | ||
484 | if ((*flags & MS_RDONLY) == (sb->s_flags & MS_RDONLY)) | |
485 | return 0; | |
486 | if (*flags & MS_RDONLY) | |
487 | udf_close_lvid(sb); | |
488 | else | |
489 | udf_open_lvid(sb); | |
490 | ||
491 | return 0; | |
492 | } | |
493 | ||
494 | /* | |
495 | * udf_set_blocksize | |
496 | * | |
497 | * PURPOSE | |
498 | * Set the block size to be used in all transfers. | |
499 | * | |
500 | * DESCRIPTION | |
501 | * To allow room for a DMA transfer, it is best to guess big when unsure. | |
502 | * This routine picks 2048 bytes as the blocksize when guessing. This | |
503 | * should be adequate until devices with larger block sizes become common. | |
504 | * | |
505 | * Note that the Linux kernel can currently only deal with blocksizes of | |
506 | * 512, 1024, 2048, 4096, and 8192 bytes. | |
507 | * | |
508 | * PRE-CONDITIONS | |
509 | * sb Pointer to _locked_ superblock. | |
510 | * | |
511 | * POST-CONDITIONS | |
512 | * sb->s_blocksize Blocksize. | |
513 | * sb->s_blocksize_bits log2 of blocksize. | |
514 | * <return> 0 Blocksize is valid. | |
515 | * <return> 1 Blocksize is invalid. | |
516 | * | |
517 | * HISTORY | |
518 | * July 1, 1997 - Andrew E. Mileski | |
519 | * Written, tested, and released. | |
520 | */ | |
cb00ea35 | 521 | static int udf_set_blocksize(struct super_block *sb, int bsize) |
1da177e4 LT |
522 | { |
523 | if (!sb_min_blocksize(sb, bsize)) { | |
524 | udf_debug("Bad block size (%d)\n", bsize); | |
525 | printk(KERN_ERR "udf: bad block size (%d)\n", bsize); | |
526 | return 0; | |
527 | } | |
28de7948 | 528 | |
1da177e4 LT |
529 | return sb->s_blocksize; |
530 | } | |
531 | ||
cb00ea35 | 532 | static int udf_vrs(struct super_block *sb, int silent) |
1da177e4 LT |
533 | { |
534 | struct volStructDesc *vsd = NULL; | |
535 | int sector = 32768; | |
536 | int sectorsize; | |
537 | struct buffer_head *bh = NULL; | |
cb00ea35 CG |
538 | int iso9660 = 0; |
539 | int nsr02 = 0; | |
540 | int nsr03 = 0; | |
1da177e4 LT |
541 | |
542 | /* Block size must be a multiple of 512 */ | |
543 | if (sb->s_blocksize & 511) | |
544 | return 0; | |
545 | ||
546 | if (sb->s_blocksize < sizeof(struct volStructDesc)) | |
547 | sectorsize = sizeof(struct volStructDesc); | |
548 | else | |
549 | sectorsize = sb->s_blocksize; | |
550 | ||
551 | sector += (UDF_SB_SESSION(sb) << sb->s_blocksize_bits); | |
552 | ||
553 | udf_debug("Starting at sector %u (%ld byte sectors)\n", | |
cb00ea35 | 554 | (sector >> sb->s_blocksize_bits), sb->s_blocksize); |
1da177e4 | 555 | /* Process the sequence (if applicable) */ |
cb00ea35 | 556 | for (; !nsr02 && !nsr03; sector += sectorsize) { |
1da177e4 LT |
557 | /* Read a block */ |
558 | bh = udf_tread(sb, sector >> sb->s_blocksize_bits); | |
559 | if (!bh) | |
560 | break; | |
561 | ||
562 | /* Look for ISO descriptors */ | |
563 | vsd = (struct volStructDesc *)(bh->b_data + | |
28de7948 | 564 | (sector & (sb->s_blocksize - 1))); |
1da177e4 | 565 | |
cb00ea35 | 566 | if (vsd->stdIdent[0] == 0) { |
3bf25cb4 | 567 | brelse(bh); |
1da177e4 | 568 | break; |
28de7948 | 569 | } else if (!strncmp(vsd->stdIdent, VSD_STD_ID_CD001, VSD_STD_ID_LEN)) { |
1da177e4 | 570 | iso9660 = sector; |
cb00ea35 CG |
571 | switch (vsd->structType) { |
572 | case 0: | |
573 | udf_debug("ISO9660 Boot Record found\n"); | |
574 | break; | |
575 | case 1: | |
576 | udf_debug | |
577 | ("ISO9660 Primary Volume Descriptor found\n"); | |
578 | break; | |
579 | case 2: | |
580 | udf_debug | |
581 | ("ISO9660 Supplementary Volume Descriptor found\n"); | |
582 | break; | |
583 | case 3: | |
584 | udf_debug | |
585 | ("ISO9660 Volume Partition Descriptor found\n"); | |
586 | break; | |
587 | case 255: | |
588 | udf_debug | |
589 | ("ISO9660 Volume Descriptor Set Terminator found\n"); | |
590 | break; | |
591 | default: | |
592 | udf_debug("ISO9660 VRS (%u) found\n", | |
593 | vsd->structType); | |
594 | break; | |
1da177e4 | 595 | } |
28de7948 CG |
596 | } else if (!strncmp(vsd->stdIdent, VSD_STD_ID_BEA01, VSD_STD_ID_LEN)) { |
597 | } else if (!strncmp(vsd->stdIdent, VSD_STD_ID_TEA01, VSD_STD_ID_LEN)) { | |
3bf25cb4 | 598 | brelse(bh); |
1da177e4 | 599 | break; |
28de7948 | 600 | } else if (!strncmp(vsd->stdIdent, VSD_STD_ID_NSR02, VSD_STD_ID_LEN)) { |
1da177e4 | 601 | nsr02 = sector; |
28de7948 | 602 | } else if (!strncmp(vsd->stdIdent, VSD_STD_ID_NSR03, VSD_STD_ID_LEN)) { |
1da177e4 LT |
603 | nsr03 = sector; |
604 | } | |
3bf25cb4 | 605 | brelse(bh); |
1da177e4 LT |
606 | } |
607 | ||
608 | if (nsr03) | |
609 | return nsr03; | |
610 | else if (nsr02) | |
611 | return nsr02; | |
612 | else if (sector - (UDF_SB_SESSION(sb) << sb->s_blocksize_bits) == 32768) | |
613 | return -1; | |
614 | else | |
615 | return 0; | |
616 | } | |
617 | ||
618 | /* | |
619 | * udf_find_anchor | |
620 | * | |
621 | * PURPOSE | |
622 | * Find an anchor volume descriptor. | |
623 | * | |
624 | * PRE-CONDITIONS | |
625 | * sb Pointer to _locked_ superblock. | |
626 | * lastblock Last block on media. | |
627 | * | |
628 | * POST-CONDITIONS | |
629 | * <return> 1 if not found, 0 if ok | |
630 | * | |
631 | * HISTORY | |
632 | * July 1, 1997 - Andrew E. Mileski | |
633 | * Written, tested, and released. | |
634 | */ | |
cb00ea35 | 635 | static void udf_find_anchor(struct super_block *sb) |
1da177e4 LT |
636 | { |
637 | int lastblock = UDF_SB_LASTBLOCK(sb); | |
638 | struct buffer_head *bh = NULL; | |
639 | uint16_t ident; | |
640 | uint32_t location; | |
641 | int i; | |
642 | ||
cb00ea35 | 643 | if (lastblock) { |
1da177e4 | 644 | int varlastblock = udf_variable_to_fixed(lastblock); |
28de7948 CG |
645 | int last[] = { lastblock, lastblock - 2, |
646 | lastblock - 150, lastblock - 152, | |
647 | varlastblock, varlastblock - 2, | |
648 | varlastblock - 150, varlastblock - 152 }; | |
1da177e4 LT |
649 | |
650 | lastblock = 0; | |
651 | ||
652 | /* Search for an anchor volume descriptor pointer */ | |
653 | ||
654 | /* according to spec, anchor is in either: | |
655 | * block 256 | |
656 | * lastblock-256 | |
657 | * lastblock | |
658 | * however, if the disc isn't closed, it could be 512 */ | |
659 | ||
e8c96f8c | 660 | for (i = 0; !lastblock && i < ARRAY_SIZE(last); i++) { |
cb00ea35 | 661 | if (last[i] < 0 || !(bh = sb_bread(sb, last[i]))) { |
1da177e4 | 662 | ident = location = 0; |
cb00ea35 | 663 | } else { |
28de7948 CG |
664 | ident = le16_to_cpu(((tag *)bh->b_data)->tagIdent); |
665 | location = le32_to_cpu(((tag *)bh->b_data)->tagLocation); | |
3bf25cb4 | 666 | brelse(bh); |
1da177e4 | 667 | } |
e8c96f8c | 668 | |
cb00ea35 CG |
669 | if (ident == TAG_IDENT_AVDP) { |
670 | if (location == last[i] - UDF_SB_SESSION(sb)) { | |
28de7948 CG |
671 | lastblock = UDF_SB_ANCHOR(sb)[0] = last[i] - UDF_SB_SESSION(sb); |
672 | UDF_SB_ANCHOR(sb)[1] = last[i] - 256 - UDF_SB_SESSION(sb); | |
673 | } else if (location == udf_variable_to_fixed(last[i]) - UDF_SB_SESSION(sb)) { | |
1da177e4 | 674 | UDF_SET_FLAG(sb, UDF_FLAG_VARCONV); |
28de7948 CG |
675 | lastblock = UDF_SB_ANCHOR(sb)[0] = udf_variable_to_fixed(last[i]) - UDF_SB_SESSION(sb); |
676 | UDF_SB_ANCHOR(sb)[1] = lastblock - 256 - UDF_SB_SESSION(sb); | |
677 | } else { | |
678 | udf_debug("Anchor found at block %d, location mismatch %d.\n", | |
679 | last[i], location); | |
680 | } | |
681 | } else if (ident == TAG_IDENT_FE || ident == TAG_IDENT_EFE) { | |
1da177e4 LT |
682 | lastblock = last[i]; |
683 | UDF_SB_ANCHOR(sb)[3] = 512; | |
cb00ea35 | 684 | } else { |
28de7948 | 685 | if (last[i] < 256 || !(bh = sb_bread(sb, last[i] - 256))) { |
1da177e4 | 686 | ident = location = 0; |
cb00ea35 | 687 | } else { |
28de7948 CG |
688 | ident = le16_to_cpu(((tag *)bh->b_data)->tagIdent); |
689 | location = le32_to_cpu(((tag *)bh->b_data)->tagLocation); | |
3bf25cb4 | 690 | brelse(bh); |
1da177e4 | 691 | } |
cb00ea35 | 692 | |
1da177e4 | 693 | if (ident == TAG_IDENT_AVDP && |
28de7948 | 694 | location == last[i] - 256 - UDF_SB_SESSION(sb)) { |
1da177e4 LT |
695 | lastblock = last[i]; |
696 | UDF_SB_ANCHOR(sb)[1] = last[i] - 256; | |
cb00ea35 | 697 | } else { |
28de7948 CG |
698 | if (last[i] < 312 + UDF_SB_SESSION(sb) || |
699 | !(bh = sb_bread(sb, last[i] - 312 - UDF_SB_SESSION(sb)))) { | |
1da177e4 | 700 | ident = location = 0; |
cb00ea35 | 701 | } else { |
28de7948 CG |
702 | ident = le16_to_cpu(((tag *)bh->b_data)->tagIdent); |
703 | location = le32_to_cpu(((tag *)bh->b_data)->tagLocation); | |
3bf25cb4 | 704 | brelse(bh); |
1da177e4 | 705 | } |
cb00ea35 | 706 | |
1da177e4 | 707 | if (ident == TAG_IDENT_AVDP && |
28de7948 CG |
708 | location == udf_variable_to_fixed(last[i]) - 256) { |
709 | UDF_SET_FLAG(sb, UDF_FLAG_VARCONV); | |
710 | lastblock = udf_variable_to_fixed(last[i]); | |
711 | UDF_SB_ANCHOR(sb)[1] = lastblock - 256; | |
1da177e4 LT |
712 | } |
713 | } | |
714 | } | |
715 | } | |
716 | } | |
717 | ||
cb00ea35 | 718 | if (!lastblock) { |
1da177e4 | 719 | /* We havn't found the lastblock. check 312 */ |
cb00ea35 | 720 | if ((bh = sb_bread(sb, 312 + UDF_SB_SESSION(sb)))) { |
28de7948 CG |
721 | ident = le16_to_cpu(((tag *)bh->b_data)->tagIdent); |
722 | location = le32_to_cpu(((tag *)bh->b_data)->tagLocation); | |
3bf25cb4 | 723 | brelse(bh); |
1da177e4 LT |
724 | |
725 | if (ident == TAG_IDENT_AVDP && location == 256) | |
726 | UDF_SET_FLAG(sb, UDF_FLAG_VARCONV); | |
727 | } | |
728 | } | |
729 | ||
e8c96f8c | 730 | for (i = 0; i < ARRAY_SIZE(UDF_SB_ANCHOR(sb)); i++) { |
cb00ea35 | 731 | if (UDF_SB_ANCHOR(sb)[i]) { |
28de7948 CG |
732 | if (!(bh = udf_read_tagged(sb, UDF_SB_ANCHOR(sb)[i], |
733 | UDF_SB_ANCHOR(sb)[i], &ident))) { | |
1da177e4 | 734 | UDF_SB_ANCHOR(sb)[i] = 0; |
cb00ea35 | 735 | } else { |
3bf25cb4 | 736 | brelse(bh); |
28de7948 CG |
737 | if ((ident != TAG_IDENT_AVDP) && |
738 | (i || (ident != TAG_IDENT_FE && ident != TAG_IDENT_EFE))) { | |
1da177e4 LT |
739 | UDF_SB_ANCHOR(sb)[i] = 0; |
740 | } | |
741 | } | |
742 | } | |
743 | } | |
744 | ||
745 | UDF_SB_LASTBLOCK(sb) = lastblock; | |
746 | } | |
747 | ||
28de7948 | 748 | static int udf_find_fileset(struct super_block *sb, kernel_lb_addr *fileset, kernel_lb_addr *root) |
1da177e4 LT |
749 | { |
750 | struct buffer_head *bh = NULL; | |
751 | long lastblock; | |
752 | uint16_t ident; | |
753 | ||
754 | if (fileset->logicalBlockNum != 0xFFFFFFFF || | |
cb00ea35 | 755 | fileset->partitionReferenceNum != 0xFFFF) { |
1da177e4 LT |
756 | bh = udf_read_ptagged(sb, *fileset, 0, &ident); |
757 | ||
28de7948 | 758 | if (!bh) { |
1da177e4 | 759 | return 1; |
28de7948 | 760 | } else if (ident != TAG_IDENT_FSD) { |
3bf25cb4 | 761 | brelse(bh); |
1da177e4 LT |
762 | return 1; |
763 | } | |
cb00ea35 | 764 | |
1da177e4 LT |
765 | } |
766 | ||
28de7948 | 767 | if (!bh) { /* Search backwards through the partitions */ |
1da177e4 LT |
768 | kernel_lb_addr newfileset; |
769 | ||
28de7948 | 770 | /* --> cvg: FIXME - is it reasonable? */ |
1da177e4 | 771 | return 1; |
cb00ea35 CG |
772 | |
773 | for (newfileset.partitionReferenceNum = UDF_SB_NUMPARTS(sb) - 1; | |
774 | (newfileset.partitionReferenceNum != 0xFFFF && | |
775 | fileset->logicalBlockNum == 0xFFFFFFFF && | |
776 | fileset->partitionReferenceNum == 0xFFFF); | |
777 | newfileset.partitionReferenceNum--) { | |
28de7948 | 778 | lastblock = UDF_SB_PARTLEN(sb, newfileset.partitionReferenceNum); |
1da177e4 LT |
779 | newfileset.logicalBlockNum = 0; |
780 | ||
cb00ea35 | 781 | do { |
28de7948 | 782 | bh = udf_read_ptagged(sb, newfileset, 0, &ident); |
cb00ea35 CG |
783 | if (!bh) { |
784 | newfileset.logicalBlockNum++; | |
1da177e4 LT |
785 | continue; |
786 | } | |
787 | ||
cb00ea35 CG |
788 | switch (ident) { |
789 | case TAG_IDENT_SBD: | |
28de7948 CG |
790 | { |
791 | struct spaceBitmapDesc *sp; | |
792 | sp = (struct spaceBitmapDesc *)bh->b_data; | |
793 | newfileset.logicalBlockNum += 1 + | |
794 | ((le32_to_cpu(sp->numOfBytes) + | |
795 | sizeof(struct spaceBitmapDesc) - 1) | |
796 | >> sb->s_blocksize_bits); | |
797 | brelse(bh); | |
798 | break; | |
799 | } | |
cb00ea35 | 800 | case TAG_IDENT_FSD: |
28de7948 CG |
801 | *fileset = newfileset; |
802 | break; | |
cb00ea35 | 803 | default: |
28de7948 CG |
804 | newfileset.logicalBlockNum++; |
805 | brelse(bh); | |
806 | bh = NULL; | |
807 | break; | |
1da177e4 | 808 | } |
28de7948 CG |
809 | } while (newfileset.logicalBlockNum < lastblock && |
810 | fileset->logicalBlockNum == 0xFFFFFFFF && | |
811 | fileset->partitionReferenceNum == 0xFFFF); | |
1da177e4 LT |
812 | } |
813 | } | |
814 | ||
815 | if ((fileset->logicalBlockNum != 0xFFFFFFFF || | |
cb00ea35 | 816 | fileset->partitionReferenceNum != 0xFFFF) && bh) { |
1da177e4 | 817 | udf_debug("Fileset at block=%d, partition=%d\n", |
cb00ea35 CG |
818 | fileset->logicalBlockNum, |
819 | fileset->partitionReferenceNum); | |
1da177e4 LT |
820 | |
821 | UDF_SB_PARTITION(sb) = fileset->partitionReferenceNum; | |
822 | udf_load_fileset(sb, bh, root); | |
3bf25cb4 | 823 | brelse(bh); |
1da177e4 LT |
824 | return 0; |
825 | } | |
826 | return 1; | |
827 | } | |
828 | ||
cb00ea35 | 829 | static void udf_load_pvoldesc(struct super_block *sb, struct buffer_head *bh) |
1da177e4 LT |
830 | { |
831 | struct primaryVolDesc *pvoldesc; | |
832 | time_t recording; | |
833 | long recording_usec; | |
834 | struct ustr instr; | |
835 | struct ustr outstr; | |
836 | ||
837 | pvoldesc = (struct primaryVolDesc *)bh->b_data; | |
838 | ||
cb00ea35 CG |
839 | if (udf_stamp_to_time(&recording, &recording_usec, |
840 | lets_to_cpu(pvoldesc->recordingDateAndTime))) { | |
1da177e4 LT |
841 | kernel_timestamp ts; |
842 | ts = lets_to_cpu(pvoldesc->recordingDateAndTime); | |
28de7948 CG |
843 | udf_debug("recording time %ld/%ld, %04u/%02u/%02u %02u:%02u (%x)\n", |
844 | recording, recording_usec, | |
845 | ts.year, ts.month, ts.day, ts.hour, | |
846 | ts.minute, ts.typeAndTimezone); | |
1da177e4 LT |
847 | UDF_SB_RECORDTIME(sb).tv_sec = recording; |
848 | UDF_SB_RECORDTIME(sb).tv_nsec = recording_usec * 1000; | |
849 | } | |
850 | ||
cb00ea35 CG |
851 | if (!udf_build_ustr(&instr, pvoldesc->volIdent, 32)) { |
852 | if (udf_CS0toUTF8(&outstr, &instr)) { | |
853 | strncpy(UDF_SB_VOLIDENT(sb), outstr.u_name, | |
1da177e4 LT |
854 | outstr.u_len > 31 ? 31 : outstr.u_len); |
855 | udf_debug("volIdent[] = '%s'\n", UDF_SB_VOLIDENT(sb)); | |
856 | } | |
857 | } | |
858 | ||
cb00ea35 | 859 | if (!udf_build_ustr(&instr, pvoldesc->volSetIdent, 128)) { |
1da177e4 LT |
860 | if (udf_CS0toUTF8(&outstr, &instr)) |
861 | udf_debug("volSetIdent[] = '%s'\n", outstr.u_name); | |
862 | } | |
863 | } | |
864 | ||
28de7948 CG |
865 | static void udf_load_fileset(struct super_block *sb, struct buffer_head *bh, |
866 | kernel_lb_addr *root) | |
1da177e4 LT |
867 | { |
868 | struct fileSetDesc *fset; | |
869 | ||
870 | fset = (struct fileSetDesc *)bh->b_data; | |
871 | ||
872 | *root = lelb_to_cpu(fset->rootDirectoryICB.extLocation); | |
873 | ||
874 | UDF_SB_SERIALNUM(sb) = le16_to_cpu(fset->descTag.tagSerialNum); | |
875 | ||
cb00ea35 CG |
876 | udf_debug("Rootdir at block=%d, partition=%d\n", |
877 | root->logicalBlockNum, root->partitionReferenceNum); | |
1da177e4 LT |
878 | } |
879 | ||
bcec4477 | 880 | static int udf_load_partdesc(struct super_block *sb, struct buffer_head *bh) |
1da177e4 LT |
881 | { |
882 | struct partitionDesc *p; | |
883 | int i; | |
884 | ||
885 | p = (struct partitionDesc *)bh->b_data; | |
886 | ||
cb00ea35 CG |
887 | for (i = 0; i < UDF_SB_NUMPARTS(sb); i++) { |
888 | udf_debug("Searching map: (%d == %d)\n", | |
28de7948 CG |
889 | UDF_SB_PARTMAPS(sb)[i].s_partition_num, le16_to_cpu(p->partitionNumber)); |
890 | if (UDF_SB_PARTMAPS(sb)[i].s_partition_num == le16_to_cpu(p->partitionNumber)) { | |
891 | UDF_SB_PARTLEN(sb,i) = le32_to_cpu(p->partitionLength); /* blocks */ | |
892 | UDF_SB_PARTROOT(sb,i) = le32_to_cpu(p->partitionStartingLocation); | |
893 | if (le32_to_cpu(p->accessType) == PD_ACCESS_TYPE_READ_ONLY) | |
894 | UDF_SB_PARTFLAGS(sb,i) |= UDF_PART_FLAG_READ_ONLY; | |
895 | if (le32_to_cpu(p->accessType) == PD_ACCESS_TYPE_WRITE_ONCE) | |
896 | UDF_SB_PARTFLAGS(sb,i) |= UDF_PART_FLAG_WRITE_ONCE; | |
897 | if (le32_to_cpu(p->accessType) == PD_ACCESS_TYPE_REWRITABLE) | |
898 | UDF_SB_PARTFLAGS(sb,i) |= UDF_PART_FLAG_REWRITABLE; | |
899 | if (le32_to_cpu(p->accessType) == PD_ACCESS_TYPE_OVERWRITABLE) | |
900 | UDF_SB_PARTFLAGS(sb,i) |= UDF_PART_FLAG_OVERWRITABLE; | |
901 | ||
902 | if (!strcmp(p->partitionContents.ident, PD_PARTITION_CONTENTS_NSR02) || | |
903 | !strcmp(p->partitionContents.ident, PD_PARTITION_CONTENTS_NSR03)) { | |
1da177e4 LT |
904 | struct partitionHeaderDesc *phd; |
905 | ||
28de7948 | 906 | phd = (struct partitionHeaderDesc *)(p->partitionContentsUse); |
cb00ea35 | 907 | if (phd->unallocSpaceTable.extLength) { |
28de7948 CG |
908 | kernel_lb_addr loc = { |
909 | .logicalBlockNum = le32_to_cpu(phd->unallocSpaceTable.extPosition), | |
910 | .partitionReferenceNum = i, | |
911 | }; | |
912 | ||
913 | UDF_SB_PARTMAPS(sb)[i].s_uspace.s_table = | |
914 | udf_iget(sb, loc); | |
bcec4477 JK |
915 | if (!UDF_SB_PARTMAPS(sb)[i].s_uspace.s_table) { |
916 | udf_debug("cannot load unallocSpaceTable (part %d)\n", | |
917 | i); | |
918 | return 1; | |
919 | } | |
28de7948 CG |
920 | UDF_SB_PARTFLAGS(sb,i) |= UDF_PART_FLAG_UNALLOC_TABLE; |
921 | udf_debug("unallocSpaceTable (part %d) @ %ld\n", | |
922 | i, UDF_SB_PARTMAPS(sb)[i].s_uspace.s_table->i_ino); | |
1da177e4 | 923 | } |
cb00ea35 | 924 | if (phd->unallocSpaceBitmap.extLength) { |
1da177e4 | 925 | UDF_SB_ALLOC_BITMAP(sb, i, s_uspace); |
28de7948 CG |
926 | if (UDF_SB_PARTMAPS(sb)[i].s_uspace.s_bitmap != NULL) { |
927 | UDF_SB_PARTMAPS(sb)[i].s_uspace.s_bitmap->s_extLength = | |
928 | le32_to_cpu(phd->unallocSpaceBitmap.extLength); | |
929 | UDF_SB_PARTMAPS(sb)[i].s_uspace.s_bitmap->s_extPosition = | |
930 | le32_to_cpu(phd->unallocSpaceBitmap.extPosition); | |
931 | UDF_SB_PARTFLAGS(sb,i) |= UDF_PART_FLAG_UNALLOC_BITMAP; | |
932 | udf_debug("unallocSpaceBitmap (part %d) @ %d\n", | |
933 | i, UDF_SB_PARTMAPS(sb)[i].s_uspace.s_bitmap->s_extPosition); | |
1da177e4 LT |
934 | } |
935 | } | |
936 | if (phd->partitionIntegrityTable.extLength) | |
28de7948 | 937 | udf_debug("partitionIntegrityTable (part %d)\n", i); |
cb00ea35 | 938 | if (phd->freedSpaceTable.extLength) { |
28de7948 CG |
939 | kernel_lb_addr loc = { |
940 | .logicalBlockNum = le32_to_cpu(phd->freedSpaceTable.extPosition), | |
941 | .partitionReferenceNum = i, | |
942 | }; | |
943 | ||
944 | UDF_SB_PARTMAPS(sb)[i].s_fspace.s_table = | |
945 | udf_iget(sb, loc); | |
bcec4477 JK |
946 | if (!UDF_SB_PARTMAPS(sb)[i].s_fspace.s_table) { |
947 | udf_debug("cannot load freedSpaceTable (part %d)\n", | |
948 | i); | |
949 | return 1; | |
950 | } | |
28de7948 CG |
951 | UDF_SB_PARTFLAGS(sb,i) |= UDF_PART_FLAG_FREED_TABLE; |
952 | udf_debug("freedSpaceTable (part %d) @ %ld\n", | |
953 | i, UDF_SB_PARTMAPS(sb)[i].s_fspace.s_table->i_ino); | |
1da177e4 | 954 | } |
cb00ea35 | 955 | if (phd->freedSpaceBitmap.extLength) { |
1da177e4 | 956 | UDF_SB_ALLOC_BITMAP(sb, i, s_fspace); |
28de7948 CG |
957 | if (UDF_SB_PARTMAPS(sb)[i].s_fspace.s_bitmap != NULL) { |
958 | UDF_SB_PARTMAPS(sb)[i].s_fspace.s_bitmap->s_extLength = | |
959 | le32_to_cpu(phd->freedSpaceBitmap.extLength); | |
960 | UDF_SB_PARTMAPS(sb)[i].s_fspace.s_bitmap->s_extPosition = | |
961 | le32_to_cpu(phd->freedSpaceBitmap.extPosition); | |
962 | UDF_SB_PARTFLAGS(sb,i) |= UDF_PART_FLAG_FREED_BITMAP; | |
963 | udf_debug("freedSpaceBitmap (part %d) @ %d\n", | |
964 | i, UDF_SB_PARTMAPS(sb)[i].s_fspace.s_bitmap->s_extPosition); | |
1da177e4 LT |
965 | } |
966 | } | |
967 | } | |
968 | break; | |
969 | } | |
970 | } | |
cb00ea35 CG |
971 | if (i == UDF_SB_NUMPARTS(sb)) { |
972 | udf_debug("Partition (%d) not found in partition map\n", | |
973 | le16_to_cpu(p->partitionNumber)); | |
974 | } else { | |
28de7948 CG |
975 | udf_debug("Partition (%d:%d type %x) starts at physical %d, block length %d\n", |
976 | le16_to_cpu(p->partitionNumber), i, UDF_SB_PARTTYPE(sb,i), | |
977 | UDF_SB_PARTROOT(sb,i), UDF_SB_PARTLEN(sb,i)); | |
1da177e4 | 978 | } |
bcec4477 | 979 | return 0; |
1da177e4 LT |
980 | } |
981 | ||
28de7948 CG |
982 | static int udf_load_logicalvol(struct super_block *sb, struct buffer_head *bh, |
983 | kernel_lb_addr *fileset) | |
1da177e4 LT |
984 | { |
985 | struct logicalVolDesc *lvd; | |
986 | int i, j, offset; | |
987 | uint8_t type; | |
988 | ||
989 | lvd = (struct logicalVolDesc *)bh->b_data; | |
990 | ||
991 | UDF_SB_ALLOC_PARTMAPS(sb, le32_to_cpu(lvd->numPartitionMaps)); | |
992 | ||
cb00ea35 | 993 | for (i = 0, offset = 0; |
28de7948 CG |
994 | i < UDF_SB_NUMPARTS(sb) && offset < le32_to_cpu(lvd->mapTableLength); |
995 | i++, offset += ((struct genericPartitionMap *)&(lvd->partitionMaps[offset]))->partitionMapLength) { | |
996 | type = ((struct genericPartitionMap *)&(lvd->partitionMaps[offset]))->partitionMapType; | |
cb00ea35 | 997 | if (type == 1) { |
28de7948 CG |
998 | struct genericPartitionMap1 *gpm1 = (struct genericPartitionMap1 *)&(lvd->partitionMaps[offset]); |
999 | UDF_SB_PARTTYPE(sb,i) = UDF_TYPE1_MAP15; | |
1000 | UDF_SB_PARTVSN(sb,i) = le16_to_cpu(gpm1->volSeqNum); | |
1001 | UDF_SB_PARTNUM(sb,i) = le16_to_cpu(gpm1->partitionNum); | |
1002 | UDF_SB_PARTFUNC(sb,i) = NULL; | |
cb00ea35 | 1003 | } else if (type == 2) { |
28de7948 CG |
1004 | struct udfPartitionMap2 *upm2 = (struct udfPartitionMap2 *)&(lvd->partitionMaps[offset]); |
1005 | if (!strncmp(upm2->partIdent.ident, UDF_ID_VIRTUAL, strlen(UDF_ID_VIRTUAL))) { | |
1006 | if (le16_to_cpu(((__le16 *)upm2->partIdent.identSuffix)[0]) == 0x0150) { | |
1007 | UDF_SB_PARTTYPE(sb,i) = UDF_VIRTUAL_MAP15; | |
1008 | UDF_SB_PARTFUNC(sb,i) = udf_get_pblock_virt15; | |
1009 | } else if (le16_to_cpu(((__le16 *)upm2->partIdent.identSuffix)[0]) == 0x0200) { | |
1010 | UDF_SB_PARTTYPE(sb,i) = UDF_VIRTUAL_MAP20; | |
1011 | UDF_SB_PARTFUNC(sb,i) = udf_get_pblock_virt20; | |
1da177e4 | 1012 | } |
28de7948 | 1013 | } else if (!strncmp(upm2->partIdent.ident, UDF_ID_SPARABLE, strlen(UDF_ID_SPARABLE))) { |
1da177e4 LT |
1014 | uint32_t loc; |
1015 | uint16_t ident; | |
1016 | struct sparingTable *st; | |
28de7948 CG |
1017 | struct sparablePartitionMap *spm = (struct sparablePartitionMap *)&(lvd->partitionMaps[offset]); |
1018 | ||
1019 | UDF_SB_PARTTYPE(sb,i) = UDF_SPARABLE_MAP15; | |
1020 | UDF_SB_TYPESPAR(sb,i).s_packet_len = le16_to_cpu(spm->packetLength); | |
cb00ea35 | 1021 | for (j = 0; j < spm->numSparingTables; j++) { |
28de7948 CG |
1022 | loc = le32_to_cpu(spm->locSparingTable[j]); |
1023 | UDF_SB_TYPESPAR(sb,i).s_spar_map[j] = | |
1024 | udf_read_tagged(sb, loc, loc, &ident); | |
1025 | if (UDF_SB_TYPESPAR(sb,i).s_spar_map[j] != NULL) { | |
1026 | st = (struct sparingTable *)UDF_SB_TYPESPAR(sb,i).s_spar_map[j]->b_data; | |
1027 | if (ident != 0 || | |
1028 | strncmp(st->sparingIdent.ident, UDF_ID_SPARING, strlen(UDF_ID_SPARING))) { | |
1029 | brelse(UDF_SB_TYPESPAR(sb,i).s_spar_map[j]); | |
1030 | UDF_SB_TYPESPAR(sb,i).s_spar_map[j] = NULL; | |
1da177e4 LT |
1031 | } |
1032 | } | |
1033 | } | |
28de7948 | 1034 | UDF_SB_PARTFUNC(sb,i) = udf_get_pblock_spar15; |
cb00ea35 | 1035 | } else { |
28de7948 | 1036 | udf_debug("Unknown ident: %s\n", upm2->partIdent.ident); |
1da177e4 LT |
1037 | continue; |
1038 | } | |
28de7948 CG |
1039 | UDF_SB_PARTVSN(sb,i) = le16_to_cpu(upm2->volSeqNum); |
1040 | UDF_SB_PARTNUM(sb,i) = le16_to_cpu(upm2->partitionNum); | |
1da177e4 LT |
1041 | } |
1042 | udf_debug("Partition (%d:%d) type %d on volume %d\n", | |
28de7948 | 1043 | i, UDF_SB_PARTNUM(sb,i), type, UDF_SB_PARTVSN(sb,i)); |
1da177e4 LT |
1044 | } |
1045 | ||
cb00ea35 | 1046 | if (fileset) { |
28de7948 | 1047 | long_ad *la = (long_ad *)&(lvd->logicalVolContentsUse[0]); |
1da177e4 LT |
1048 | |
1049 | *fileset = lelb_to_cpu(la->extLocation); | |
28de7948 CG |
1050 | udf_debug("FileSet found in LogicalVolDesc at block=%d, partition=%d\n", |
1051 | fileset->logicalBlockNum, | |
1052 | fileset->partitionReferenceNum); | |
1da177e4 LT |
1053 | } |
1054 | if (lvd->integritySeqExt.extLength) | |
1055 | udf_load_logicalvolint(sb, leea_to_cpu(lvd->integritySeqExt)); | |
28de7948 | 1056 | |
1da177e4 LT |
1057 | return 0; |
1058 | } | |
1059 | ||
1060 | /* | |
1061 | * udf_load_logicalvolint | |
1062 | * | |
1063 | */ | |
cb00ea35 | 1064 | static void udf_load_logicalvolint(struct super_block *sb, kernel_extent_ad loc) |
1da177e4 LT |
1065 | { |
1066 | struct buffer_head *bh = NULL; | |
1067 | uint16_t ident; | |
1068 | ||
1069 | while (loc.extLength > 0 && | |
cb00ea35 CG |
1070 | (bh = udf_read_tagged(sb, loc.extLocation, |
1071 | loc.extLocation, &ident)) && | |
1072 | ident == TAG_IDENT_LVID) { | |
1da177e4 | 1073 | UDF_SB_LVIDBH(sb) = bh; |
cb00ea35 | 1074 | |
1da177e4 | 1075 | if (UDF_SB_LVID(sb)->nextIntegrityExt.extLength) |
28de7948 | 1076 | udf_load_logicalvolint(sb, leea_to_cpu(UDF_SB_LVID(sb)->nextIntegrityExt)); |
cb00ea35 | 1077 | |
1da177e4 | 1078 | if (UDF_SB_LVIDBH(sb) != bh) |
3bf25cb4 | 1079 | brelse(bh); |
1da177e4 | 1080 | loc.extLength -= sb->s_blocksize; |
cb00ea35 | 1081 | loc.extLocation++; |
1da177e4 LT |
1082 | } |
1083 | if (UDF_SB_LVIDBH(sb) != bh) | |
3bf25cb4 | 1084 | brelse(bh); |
1da177e4 LT |
1085 | } |
1086 | ||
1087 | /* | |
1088 | * udf_process_sequence | |
1089 | * | |
1090 | * PURPOSE | |
1091 | * Process a main/reserve volume descriptor sequence. | |
1092 | * | |
1093 | * PRE-CONDITIONS | |
1094 | * sb Pointer to _locked_ superblock. | |
1095 | * block First block of first extent of the sequence. | |
1096 | * lastblock Lastblock of first extent of the sequence. | |
1097 | * | |
1098 | * HISTORY | |
1099 | * July 1, 1997 - Andrew E. Mileski | |
1100 | * Written, tested, and released. | |
1101 | */ | |
28de7948 CG |
1102 | static int udf_process_sequence(struct super_block *sb, long block, long lastblock, |
1103 | kernel_lb_addr *fileset) | |
1da177e4 LT |
1104 | { |
1105 | struct buffer_head *bh = NULL; | |
1106 | struct udf_vds_record vds[VDS_POS_LENGTH]; | |
1107 | struct generic_desc *gd; | |
1108 | struct volDescPtr *vdp; | |
cb00ea35 CG |
1109 | int done = 0; |
1110 | int i, j; | |
1da177e4 LT |
1111 | uint32_t vdsn; |
1112 | uint16_t ident; | |
1113 | long next_s = 0, next_e = 0; | |
1114 | ||
1115 | memset(vds, 0, sizeof(struct udf_vds_record) * VDS_POS_LENGTH); | |
1116 | ||
1117 | /* Read the main descriptor sequence */ | |
cb00ea35 | 1118 | for (; (!done && block <= lastblock); block++) { |
1da177e4 LT |
1119 | |
1120 | bh = udf_read_tagged(sb, block, block, &ident); | |
cb00ea35 | 1121 | if (!bh) |
1da177e4 LT |
1122 | break; |
1123 | ||
1124 | /* Process each descriptor (ISO 13346 3/8.3-8.4) */ | |
1125 | gd = (struct generic_desc *)bh->b_data; | |
1126 | vdsn = le32_to_cpu(gd->volDescSeqNum); | |
cb00ea35 | 1127 | switch (ident) { |
28de7948 | 1128 | case TAG_IDENT_PVD: /* ISO 13346 3/10.1 */ |
cb00ea35 | 1129 | if (vdsn >= vds[VDS_POS_PRIMARY_VOL_DESC].volDescSeqNum) { |
28de7948 | 1130 | vds[VDS_POS_PRIMARY_VOL_DESC].volDescSeqNum = vdsn; |
cb00ea35 CG |
1131 | vds[VDS_POS_PRIMARY_VOL_DESC].block = block; |
1132 | } | |
1133 | break; | |
28de7948 | 1134 | case TAG_IDENT_VDP: /* ISO 13346 3/10.3 */ |
cb00ea35 CG |
1135 | if (vdsn >= vds[VDS_POS_VOL_DESC_PTR].volDescSeqNum) { |
1136 | vds[VDS_POS_VOL_DESC_PTR].volDescSeqNum = vdsn; | |
1137 | vds[VDS_POS_VOL_DESC_PTR].block = block; | |
1138 | ||
1139 | vdp = (struct volDescPtr *)bh->b_data; | |
28de7948 CG |
1140 | next_s = le32_to_cpu(vdp->nextVolDescSeqExt.extLocation); |
1141 | next_e = le32_to_cpu(vdp->nextVolDescSeqExt.extLength); | |
cb00ea35 CG |
1142 | next_e = next_e >> sb->s_blocksize_bits; |
1143 | next_e += next_s; | |
1144 | } | |
1145 | break; | |
28de7948 | 1146 | case TAG_IDENT_IUVD: /* ISO 13346 3/10.4 */ |
cb00ea35 | 1147 | if (vdsn >= vds[VDS_POS_IMP_USE_VOL_DESC].volDescSeqNum) { |
28de7948 | 1148 | vds[VDS_POS_IMP_USE_VOL_DESC].volDescSeqNum = vdsn; |
cb00ea35 CG |
1149 | vds[VDS_POS_IMP_USE_VOL_DESC].block = block; |
1150 | } | |
1151 | break; | |
28de7948 | 1152 | case TAG_IDENT_PD: /* ISO 13346 3/10.5 */ |
cb00ea35 CG |
1153 | if (!vds[VDS_POS_PARTITION_DESC].block) |
1154 | vds[VDS_POS_PARTITION_DESC].block = block; | |
1155 | break; | |
28de7948 | 1156 | case TAG_IDENT_LVD: /* ISO 13346 3/10.6 */ |
cb00ea35 | 1157 | if (vdsn >= vds[VDS_POS_LOGICAL_VOL_DESC].volDescSeqNum) { |
28de7948 | 1158 | vds[VDS_POS_LOGICAL_VOL_DESC].volDescSeqNum = vdsn; |
cb00ea35 CG |
1159 | vds[VDS_POS_LOGICAL_VOL_DESC].block = block; |
1160 | } | |
1161 | break; | |
28de7948 CG |
1162 | case TAG_IDENT_USD: /* ISO 13346 3/10.8 */ |
1163 | if (vdsn >= vds[VDS_POS_UNALLOC_SPACE_DESC].volDescSeqNum) { | |
1164 | vds[VDS_POS_UNALLOC_SPACE_DESC].volDescSeqNum = vdsn; | |
cb00ea35 CG |
1165 | vds[VDS_POS_UNALLOC_SPACE_DESC].block = block; |
1166 | } | |
1167 | break; | |
28de7948 | 1168 | case TAG_IDENT_TD: /* ISO 13346 3/10.9 */ |
cb00ea35 CG |
1169 | vds[VDS_POS_TERMINATING_DESC].block = block; |
1170 | if (next_e) { | |
1171 | block = next_s; | |
1172 | lastblock = next_e; | |
1173 | next_s = next_e = 0; | |
28de7948 | 1174 | } else { |
cb00ea35 | 1175 | done = 1; |
28de7948 | 1176 | } |
cb00ea35 | 1177 | break; |
1da177e4 | 1178 | } |
3bf25cb4 | 1179 | brelse(bh); |
1da177e4 | 1180 | } |
cb00ea35 CG |
1181 | for (i = 0; i < VDS_POS_LENGTH; i++) { |
1182 | if (vds[i].block) { | |
28de7948 | 1183 | bh = udf_read_tagged(sb, vds[i].block, vds[i].block, &ident); |
1da177e4 | 1184 | |
28de7948 | 1185 | if (i == VDS_POS_PRIMARY_VOL_DESC) { |
1da177e4 | 1186 | udf_load_pvoldesc(sb, bh); |
28de7948 | 1187 | } else if (i == VDS_POS_LOGICAL_VOL_DESC) { |
1da177e4 | 1188 | udf_load_logicalvol(sb, bh, fileset); |
28de7948 | 1189 | } else if (i == VDS_POS_PARTITION_DESC) { |
1da177e4 | 1190 | struct buffer_head *bh2 = NULL; |
bcec4477 JK |
1191 | if (udf_load_partdesc(sb, bh)) { |
1192 | brelse(bh); | |
1193 | return 1; | |
1194 | } | |
28de7948 | 1195 | for (j = vds[i].block + 1; j < vds[VDS_POS_TERMINATING_DESC].block; j++) { |
1da177e4 LT |
1196 | bh2 = udf_read_tagged(sb, j, j, &ident); |
1197 | gd = (struct generic_desc *)bh2->b_data; | |
1198 | if (ident == TAG_IDENT_PD) | |
bcec4477 JK |
1199 | if (udf_load_partdesc(sb, bh2)) { |
1200 | brelse(bh); | |
1201 | brelse(bh2); | |
1202 | return 1; | |
1203 | } | |
3bf25cb4 | 1204 | brelse(bh2); |
1da177e4 LT |
1205 | } |
1206 | } | |
3bf25cb4 | 1207 | brelse(bh); |
1da177e4 LT |
1208 | } |
1209 | } | |
1210 | ||
1211 | return 0; | |
1212 | } | |
1213 | ||
1214 | /* | |
1215 | * udf_check_valid() | |
1216 | */ | |
cb00ea35 | 1217 | static int udf_check_valid(struct super_block *sb, int novrs, int silent) |
1da177e4 LT |
1218 | { |
1219 | long block; | |
1220 | ||
cb00ea35 | 1221 | if (novrs) { |
1da177e4 LT |
1222 | udf_debug("Validity check skipped because of novrs option\n"); |
1223 | return 0; | |
1224 | } | |
1225 | /* Check that it is NSR02 compliant */ | |
1226 | /* Process any "CD-ROM Volume Descriptor Set" (ECMA 167 2/8.3.1) */ | |
cb00ea35 | 1227 | else if ((block = udf_vrs(sb, silent)) == -1) { |
28de7948 CG |
1228 | udf_debug("Failed to read byte 32768. Assuming open disc. " |
1229 | "Skipping validity check\n"); | |
1da177e4 LT |
1230 | if (!UDF_SB_LASTBLOCK(sb)) |
1231 | UDF_SB_LASTBLOCK(sb) = udf_get_last_block(sb); | |
1232 | return 0; | |
28de7948 | 1233 | } else { |
1da177e4 | 1234 | return !block; |
28de7948 | 1235 | } |
1da177e4 LT |
1236 | } |
1237 | ||
28de7948 | 1238 | static int udf_load_partition(struct super_block *sb, kernel_lb_addr *fileset) |
1da177e4 LT |
1239 | { |
1240 | struct anchorVolDescPtr *anchor; | |
1241 | uint16_t ident; | |
1242 | struct buffer_head *bh; | |
1243 | long main_s, main_e, reserve_s, reserve_e; | |
1244 | int i, j; | |
1245 | ||
1246 | if (!sb) | |
1247 | return 1; | |
1248 | ||
e8c96f8c | 1249 | for (i = 0; i < ARRAY_SIZE(UDF_SB_ANCHOR(sb)); i++) { |
28de7948 CG |
1250 | if (UDF_SB_ANCHOR(sb)[i] && |
1251 | (bh = udf_read_tagged(sb, UDF_SB_ANCHOR(sb)[i], | |
1252 | UDF_SB_ANCHOR(sb)[i], &ident))) { | |
1da177e4 LT |
1253 | anchor = (struct anchorVolDescPtr *)bh->b_data; |
1254 | ||
1255 | /* Locate the main sequence */ | |
28de7948 CG |
1256 | main_s = le32_to_cpu(anchor->mainVolDescSeqExt.extLocation); |
1257 | main_e = le32_to_cpu(anchor->mainVolDescSeqExt.extLength ); | |
1da177e4 LT |
1258 | main_e = main_e >> sb->s_blocksize_bits; |
1259 | main_e += main_s; | |
e8c96f8c | 1260 | |
1da177e4 | 1261 | /* Locate the reserve sequence */ |
28de7948 CG |
1262 | reserve_s = le32_to_cpu(anchor->reserveVolDescSeqExt.extLocation); |
1263 | reserve_e = le32_to_cpu(anchor->reserveVolDescSeqExt.extLength); | |
1da177e4 LT |
1264 | reserve_e = reserve_e >> sb->s_blocksize_bits; |
1265 | reserve_e += reserve_s; | |
1266 | ||
3bf25cb4 | 1267 | brelse(bh); |
1da177e4 LT |
1268 | |
1269 | /* Process the main & reserve sequences */ | |
1270 | /* responsible for finding the PartitionDesc(s) */ | |
28de7948 CG |
1271 | if (!(udf_process_sequence(sb, main_s, main_e, fileset) && |
1272 | udf_process_sequence(sb, reserve_s, reserve_e, fileset))) { | |
1da177e4 LT |
1273 | break; |
1274 | } | |
1275 | } | |
1276 | } | |
1277 | ||
e8c96f8c | 1278 | if (i == ARRAY_SIZE(UDF_SB_ANCHOR(sb))) { |
1da177e4 LT |
1279 | udf_debug("No Anchor block found\n"); |
1280 | return 1; | |
e8c96f8c | 1281 | } else |
1da177e4 LT |
1282 | udf_debug("Using anchor in block %d\n", UDF_SB_ANCHOR(sb)[i]); |
1283 | ||
cb00ea35 | 1284 | for (i = 0; i < UDF_SB_NUMPARTS(sb); i++) { |
28de7948 | 1285 | kernel_lb_addr uninitialized_var(ino); |
cb00ea35 CG |
1286 | switch (UDF_SB_PARTTYPE(sb, i)) { |
1287 | case UDF_VIRTUAL_MAP15: | |
1288 | case UDF_VIRTUAL_MAP20: | |
28de7948 CG |
1289 | if (!UDF_SB_LASTBLOCK(sb)) { |
1290 | UDF_SB_LASTBLOCK(sb) = udf_get_last_block(sb); | |
1291 | udf_find_anchor(sb); | |
1292 | } | |
1da177e4 | 1293 | |
28de7948 CG |
1294 | if (!UDF_SB_LASTBLOCK(sb)) { |
1295 | udf_debug("Unable to determine Lastblock (For " | |
1296 | "Virtual Partition)\n"); | |
1297 | return 1; | |
1298 | } | |
1da177e4 | 1299 | |
28de7948 CG |
1300 | for (j = 0; j < UDF_SB_NUMPARTS(sb); j++) { |
1301 | if (j != i && UDF_SB_PARTVSN(sb, i) == | |
1302 | UDF_SB_PARTVSN(sb, j) && | |
1303 | UDF_SB_PARTNUM(sb, i) == | |
1304 | UDF_SB_PARTNUM(sb, j)) { | |
1305 | ino.partitionReferenceNum = j; | |
1306 | ino.logicalBlockNum = | |
1307 | UDF_SB_LASTBLOCK(sb) - | |
1308 | UDF_SB_PARTROOT(sb, j); | |
1309 | break; | |
1da177e4 | 1310 | } |
28de7948 | 1311 | } |
1da177e4 | 1312 | |
28de7948 CG |
1313 | if (j == UDF_SB_NUMPARTS(sb)) |
1314 | return 1; | |
1da177e4 | 1315 | |
28de7948 CG |
1316 | if (!(UDF_SB_VAT(sb) = udf_iget(sb, ino))) |
1317 | return 1; | |
1da177e4 | 1318 | |
28de7948 CG |
1319 | if (UDF_SB_PARTTYPE(sb, i) == UDF_VIRTUAL_MAP15) { |
1320 | UDF_SB_TYPEVIRT(sb, i).s_start_offset = | |
1321 | udf_ext0_offset(UDF_SB_VAT(sb)); | |
1322 | UDF_SB_TYPEVIRT(sb, i).s_num_entries = | |
1323 | (UDF_SB_VAT(sb)->i_size - 36) >> 2; | |
1324 | } else if (UDF_SB_PARTTYPE(sb, i) == UDF_VIRTUAL_MAP20) { | |
1325 | struct buffer_head *bh = NULL; | |
1326 | uint32_t pos; | |
1da177e4 | 1327 | |
28de7948 CG |
1328 | pos = udf_block_map(UDF_SB_VAT(sb), 0); |
1329 | bh = sb_bread(sb, pos); | |
1330 | if (!bh) | |
1331 | return 1; | |
1332 | UDF_SB_TYPEVIRT(sb, i).s_start_offset = | |
1333 | le16_to_cpu(((struct | |
1334 | virtualAllocationTable20 *)bh->b_data + | |
1335 | udf_ext0_offset(UDF_SB_VAT(sb)))-> | |
1336 | lengthHeader) + | |
1337 | udf_ext0_offset(UDF_SB_VAT(sb)); | |
1338 | UDF_SB_TYPEVIRT(sb, i).s_num_entries = | |
1339 | (UDF_SB_VAT(sb)->i_size - | |
1340 | UDF_SB_TYPEVIRT(sb, i).s_start_offset) >> 2; | |
1341 | brelse(bh); | |
1da177e4 | 1342 | } |
28de7948 CG |
1343 | UDF_SB_PARTROOT(sb, i) = udf_get_pblock(sb, 0, i, 0); |
1344 | UDF_SB_PARTLEN(sb, i) = UDF_SB_PARTLEN(sb, | |
1345 | ino.partitionReferenceNum); | |
1da177e4 LT |
1346 | } |
1347 | } | |
1348 | return 0; | |
1349 | } | |
1350 | ||
1351 | static void udf_open_lvid(struct super_block *sb) | |
1352 | { | |
cb00ea35 | 1353 | if (UDF_SB_LVIDBH(sb)) { |
1da177e4 LT |
1354 | int i; |
1355 | kernel_timestamp cpu_time; | |
1356 | ||
1357 | UDF_SB_LVIDIU(sb)->impIdent.identSuffix[0] = UDF_OS_CLASS_UNIX; | |
1358 | UDF_SB_LVIDIU(sb)->impIdent.identSuffix[1] = UDF_OS_ID_LINUX; | |
1359 | if (udf_time_to_stamp(&cpu_time, CURRENT_TIME)) | |
cb00ea35 CG |
1360 | UDF_SB_LVID(sb)->recordingDateAndTime = |
1361 | cpu_to_lets(cpu_time); | |
1da177e4 LT |
1362 | UDF_SB_LVID(sb)->integrityType = LVID_INTEGRITY_TYPE_OPEN; |
1363 | ||
1364 | UDF_SB_LVID(sb)->descTag.descCRC = | |
cb00ea35 CG |
1365 | cpu_to_le16(udf_crc((char *)UDF_SB_LVID(sb) + sizeof(tag), |
1366 | le16_to_cpu(UDF_SB_LVID(sb)->descTag. | |
1367 | descCRCLength), 0)); | |
1da177e4 LT |
1368 | |
1369 | UDF_SB_LVID(sb)->descTag.tagChecksum = 0; | |
cb00ea35 | 1370 | for (i = 0; i < 16; i++) |
1da177e4 LT |
1371 | if (i != 4) |
1372 | UDF_SB_LVID(sb)->descTag.tagChecksum += | |
cb00ea35 CG |
1373 | ((uint8_t *) & |
1374 | (UDF_SB_LVID(sb)->descTag))[i]; | |
1da177e4 LT |
1375 | |
1376 | mark_buffer_dirty(UDF_SB_LVIDBH(sb)); | |
1377 | } | |
1378 | } | |
1379 | ||
1380 | static void udf_close_lvid(struct super_block *sb) | |
1381 | { | |
28de7948 CG |
1382 | kernel_timestamp cpu_time; |
1383 | int i; | |
1384 | ||
1da177e4 | 1385 | if (UDF_SB_LVIDBH(sb) && |
cb00ea35 | 1386 | UDF_SB_LVID(sb)->integrityType == LVID_INTEGRITY_TYPE_OPEN) { |
1da177e4 LT |
1387 | UDF_SB_LVIDIU(sb)->impIdent.identSuffix[0] = UDF_OS_CLASS_UNIX; |
1388 | UDF_SB_LVIDIU(sb)->impIdent.identSuffix[1] = UDF_OS_ID_LINUX; | |
1389 | if (udf_time_to_stamp(&cpu_time, CURRENT_TIME)) | |
28de7948 CG |
1390 | UDF_SB_LVID(sb)->recordingDateAndTime = cpu_to_lets(cpu_time); |
1391 | if (UDF_MAX_WRITE_VERSION > le16_to_cpu(UDF_SB_LVIDIU(sb)->maxUDFWriteRev)) | |
1392 | UDF_SB_LVIDIU(sb)->maxUDFWriteRev = cpu_to_le16(UDF_MAX_WRITE_VERSION); | |
1393 | if (UDF_SB_UDFREV(sb) > le16_to_cpu(UDF_SB_LVIDIU(sb)->minUDFReadRev)) | |
1394 | UDF_SB_LVIDIU(sb)->minUDFReadRev = cpu_to_le16(UDF_SB_UDFREV(sb)); | |
1395 | if (UDF_SB_UDFREV(sb) > le16_to_cpu(UDF_SB_LVIDIU(sb)->minUDFWriteRev)) | |
1396 | UDF_SB_LVIDIU(sb)->minUDFWriteRev = cpu_to_le16(UDF_SB_UDFREV(sb)); | |
1397 | UDF_SB_LVID(sb)->integrityType = cpu_to_le32(LVID_INTEGRITY_TYPE_CLOSE); | |
1da177e4 LT |
1398 | |
1399 | UDF_SB_LVID(sb)->descTag.descCRC = | |
28de7948 CG |
1400 | cpu_to_le16(udf_crc((char *)UDF_SB_LVID(sb) + sizeof(tag), |
1401 | le16_to_cpu(UDF_SB_LVID(sb)->descTag.descCRCLength), 0)); | |
1da177e4 LT |
1402 | |
1403 | UDF_SB_LVID(sb)->descTag.tagChecksum = 0; | |
cb00ea35 | 1404 | for (i = 0; i < 16; i++) |
1da177e4 LT |
1405 | if (i != 4) |
1406 | UDF_SB_LVID(sb)->descTag.tagChecksum += | |
28de7948 | 1407 | ((uint8_t *)&(UDF_SB_LVID(sb)->descTag))[i]; |
1da177e4 LT |
1408 | |
1409 | mark_buffer_dirty(UDF_SB_LVIDBH(sb)); | |
1410 | } | |
1411 | } | |
1412 | ||
1413 | /* | |
1414 | * udf_read_super | |
1415 | * | |
1416 | * PURPOSE | |
1417 | * Complete the specified super block. | |
1418 | * | |
1419 | * PRE-CONDITIONS | |
1420 | * sb Pointer to superblock to complete - never NULL. | |
1421 | * sb->s_dev Device to read suberblock from. | |
1422 | * options Pointer to mount options. | |
1423 | * silent Silent flag. | |
1424 | * | |
1425 | * HISTORY | |
1426 | * July 1, 1997 - Andrew E. Mileski | |
1427 | * Written, tested, and released. | |
1428 | */ | |
1429 | static int udf_fill_super(struct super_block *sb, void *options, int silent) | |
1430 | { | |
1431 | int i; | |
cb00ea35 | 1432 | struct inode *inode = NULL; |
1da177e4 LT |
1433 | struct udf_options uopt; |
1434 | kernel_lb_addr rootdir, fileset; | |
1435 | struct udf_sb_info *sbi; | |
1436 | ||
1437 | uopt.flags = (1 << UDF_FLAG_USE_AD_IN_ICB) | (1 << UDF_FLAG_STRICT); | |
1438 | uopt.uid = -1; | |
1439 | uopt.gid = -1; | |
1440 | uopt.umask = 0; | |
1441 | ||
1442 | sbi = kmalloc(sizeof(struct udf_sb_info), GFP_KERNEL); | |
1443 | if (!sbi) | |
1444 | return -ENOMEM; | |
28de7948 | 1445 | |
1da177e4 LT |
1446 | sb->s_fs_info = sbi; |
1447 | memset(UDF_SB(sb), 0x00, sizeof(struct udf_sb_info)); | |
1448 | ||
1e7933de | 1449 | mutex_init(&sbi->s_alloc_mutex); |
1da177e4 LT |
1450 | |
1451 | if (!udf_parse_options((char *)options, &uopt)) | |
1452 | goto error_out; | |
1453 | ||
1454 | if (uopt.flags & (1 << UDF_FLAG_UTF8) && | |
cb00ea35 | 1455 | uopt.flags & (1 << UDF_FLAG_NLS_MAP)) { |
1da177e4 | 1456 | udf_error(sb, "udf_read_super", |
cb00ea35 | 1457 | "utf8 cannot be combined with iocharset\n"); |
1da177e4 LT |
1458 | goto error_out; |
1459 | } | |
1460 | #ifdef CONFIG_UDF_NLS | |
cb00ea35 | 1461 | if ((uopt.flags & (1 << UDF_FLAG_NLS_MAP)) && !uopt.nls_map) { |
1da177e4 LT |
1462 | uopt.nls_map = load_nls_default(); |
1463 | if (!uopt.nls_map) | |
1464 | uopt.flags &= ~(1 << UDF_FLAG_NLS_MAP); | |
1465 | else | |
1466 | udf_debug("Using default NLS map\n"); | |
1467 | } | |
1468 | #endif | |
1469 | if (!(uopt.flags & (1 << UDF_FLAG_NLS_MAP))) | |
1470 | uopt.flags |= (1 << UDF_FLAG_UTF8); | |
1471 | ||
1472 | fileset.logicalBlockNum = 0xFFFFFFFF; | |
1473 | fileset.partitionReferenceNum = 0xFFFF; | |
1474 | ||
1475 | UDF_SB(sb)->s_flags = uopt.flags; | |
1476 | UDF_SB(sb)->s_uid = uopt.uid; | |
1477 | UDF_SB(sb)->s_gid = uopt.gid; | |
1478 | UDF_SB(sb)->s_umask = uopt.umask; | |
1479 | UDF_SB(sb)->s_nls_map = uopt.nls_map; | |
1480 | ||
1481 | /* Set the block size for all transfers */ | |
1482 | if (!udf_set_blocksize(sb, uopt.blocksize)) | |
1483 | goto error_out; | |
1484 | ||
cb00ea35 | 1485 | if (uopt.session == 0xFFFFFFFF) |
1da177e4 LT |
1486 | UDF_SB_SESSION(sb) = udf_get_last_session(sb); |
1487 | else | |
1488 | UDF_SB_SESSION(sb) = uopt.session; | |
1489 | ||
1490 | udf_debug("Multi-session=%d\n", UDF_SB_SESSION(sb)); | |
1491 | ||
1492 | UDF_SB_LASTBLOCK(sb) = uopt.lastblock; | |
1493 | UDF_SB_ANCHOR(sb)[0] = UDF_SB_ANCHOR(sb)[1] = 0; | |
1494 | UDF_SB_ANCHOR(sb)[2] = uopt.anchor; | |
1495 | UDF_SB_ANCHOR(sb)[3] = 256; | |
1496 | ||
28de7948 | 1497 | if (udf_check_valid(sb, uopt.novrs, silent)) { /* read volume recognition sequences */ |
1da177e4 | 1498 | printk("UDF-fs: No VRS found\n"); |
cb00ea35 | 1499 | goto error_out; |
1da177e4 LT |
1500 | } |
1501 | ||
1502 | udf_find_anchor(sb); | |
1503 | ||
1504 | /* Fill in the rest of the superblock */ | |
1505 | sb->s_op = &udf_sb_ops; | |
1506 | sb->dq_op = NULL; | |
1507 | sb->s_dirt = 0; | |
1508 | sb->s_magic = UDF_SUPER_MAGIC; | |
1509 | sb->s_time_gran = 1000; | |
1510 | ||
cb00ea35 | 1511 | if (udf_load_partition(sb, &fileset)) { |
1da177e4 LT |
1512 | printk("UDF-fs: No partition found (1)\n"); |
1513 | goto error_out; | |
1514 | } | |
1515 | ||
1516 | udf_debug("Lastblock=%d\n", UDF_SB_LASTBLOCK(sb)); | |
1517 | ||
cb00ea35 | 1518 | if (UDF_SB_LVIDBH(sb)) { |
28de7948 CG |
1519 | uint16_t minUDFReadRev = le16_to_cpu(UDF_SB_LVIDIU(sb)->minUDFReadRev); |
1520 | uint16_t minUDFWriteRev = le16_to_cpu(UDF_SB_LVIDIU(sb)->minUDFWriteRev); | |
1da177e4 LT |
1521 | /* uint16_t maxUDFWriteRev = le16_to_cpu(UDF_SB_LVIDIU(sb)->maxUDFWriteRev); */ |
1522 | ||
cb00ea35 | 1523 | if (minUDFReadRev > UDF_MAX_READ_VERSION) { |
1da177e4 | 1524 | printk("UDF-fs: minUDFReadRev=%x (max is %x)\n", |
cb00ea35 CG |
1525 | le16_to_cpu(UDF_SB_LVIDIU(sb)->minUDFReadRev), |
1526 | UDF_MAX_READ_VERSION); | |
1da177e4 | 1527 | goto error_out; |
cb00ea35 | 1528 | } else if (minUDFWriteRev > UDF_MAX_WRITE_VERSION) { |
1da177e4 LT |
1529 | sb->s_flags |= MS_RDONLY; |
1530 | } | |
1531 | ||
1532 | UDF_SB_UDFREV(sb) = minUDFWriteRev; | |
1533 | ||
1534 | if (minUDFReadRev >= UDF_VERS_USE_EXTENDED_FE) | |
1535 | UDF_SET_FLAG(sb, UDF_FLAG_USE_EXTENDED_FE); | |
1536 | if (minUDFReadRev >= UDF_VERS_USE_STREAMS) | |
1537 | UDF_SET_FLAG(sb, UDF_FLAG_USE_STREAMS); | |
1538 | } | |
1539 | ||
cb00ea35 | 1540 | if (!UDF_SB_NUMPARTS(sb)) { |
1da177e4 LT |
1541 | printk("UDF-fs: No partition found (2)\n"); |
1542 | goto error_out; | |
1543 | } | |
1544 | ||
28de7948 CG |
1545 | if (UDF_SB_PARTFLAGS(sb, UDF_SB_PARTITION(sb)) & UDF_PART_FLAG_READ_ONLY) { |
1546 | printk("UDF-fs: Partition marked readonly; forcing readonly mount\n"); | |
39b3f6d6 | 1547 | sb->s_flags |= MS_RDONLY; |
c1a26e7d | 1548 | } |
39b3f6d6 | 1549 | |
cb00ea35 | 1550 | if (udf_find_fileset(sb, &fileset, &rootdir)) { |
1da177e4 LT |
1551 | printk("UDF-fs: No fileset found\n"); |
1552 | goto error_out; | |
1553 | } | |
1554 | ||
cb00ea35 | 1555 | if (!silent) { |
1da177e4 LT |
1556 | kernel_timestamp ts; |
1557 | udf_time_to_stamp(&ts, UDF_SB_RECORDTIME(sb)); | |
28de7948 CG |
1558 | udf_info("UDF %s (%s) Mounting volume '%s', " |
1559 | "timestamp %04u/%02u/%02u %02u:%02u (%x)\n", | |
1560 | UDFFS_VERSION, UDFFS_DATE, | |
1561 | UDF_SB_VOLIDENT(sb), ts.year, ts.month, ts.day, ts.hour, ts.minute, | |
1562 | ts.typeAndTimezone); | |
1da177e4 LT |
1563 | } |
1564 | if (!(sb->s_flags & MS_RDONLY)) | |
1565 | udf_open_lvid(sb); | |
1566 | ||
1567 | /* Assign the root inode */ | |
1568 | /* assign inodes by physical block number */ | |
1569 | /* perhaps it's not extensible enough, but for now ... */ | |
cb00ea35 CG |
1570 | inode = udf_iget(sb, rootdir); |
1571 | if (!inode) { | |
1da177e4 | 1572 | printk("UDF-fs: Error in udf_iget, block=%d, partition=%d\n", |
cb00ea35 | 1573 | rootdir.logicalBlockNum, rootdir.partitionReferenceNum); |
1da177e4 LT |
1574 | goto error_out; |
1575 | } | |
1576 | ||
1577 | /* Allocate a dentry for the root inode */ | |
1578 | sb->s_root = d_alloc_root(inode); | |
cb00ea35 | 1579 | if (!sb->s_root) { |
1da177e4 LT |
1580 | printk("UDF-fs: Couldn't allocate root dentry\n"); |
1581 | iput(inode); | |
1582 | goto error_out; | |
1583 | } | |
31170b6a | 1584 | sb->s_maxbytes = MAX_LFS_FILESIZE; |
1da177e4 LT |
1585 | return 0; |
1586 | ||
28de7948 | 1587 | error_out: |
1da177e4 LT |
1588 | if (UDF_SB_VAT(sb)) |
1589 | iput(UDF_SB_VAT(sb)); | |
cb00ea35 | 1590 | if (UDF_SB_NUMPARTS(sb)) { |
28de7948 CG |
1591 | if (UDF_SB_PARTFLAGS(sb, UDF_SB_PARTITION(sb)) & UDF_PART_FLAG_UNALLOC_TABLE) |
1592 | iput(UDF_SB_PARTMAPS(sb)[UDF_SB_PARTITION(sb)].s_uspace.s_table); | |
1593 | if (UDF_SB_PARTFLAGS(sb, UDF_SB_PARTITION(sb)) & UDF_PART_FLAG_FREED_TABLE) | |
1594 | iput(UDF_SB_PARTMAPS(sb)[UDF_SB_PARTITION(sb)].s_fspace.s_table); | |
1595 | if (UDF_SB_PARTFLAGS(sb, UDF_SB_PARTITION(sb)) & UDF_PART_FLAG_UNALLOC_BITMAP) | |
1596 | UDF_SB_FREE_BITMAP(sb,UDF_SB_PARTITION(sb), s_uspace); | |
1597 | if (UDF_SB_PARTFLAGS(sb, UDF_SB_PARTITION(sb)) & UDF_PART_FLAG_FREED_BITMAP) | |
1598 | UDF_SB_FREE_BITMAP(sb,UDF_SB_PARTITION(sb), s_fspace); | |
1599 | if (UDF_SB_PARTTYPE(sb, UDF_SB_PARTITION(sb)) == UDF_SPARABLE_MAP15) { | |
cb00ea35 | 1600 | for (i = 0; i < 4; i++) |
28de7948 | 1601 | brelse(UDF_SB_TYPESPAR(sb, UDF_SB_PARTITION(sb)).s_spar_map[i]); |
1da177e4 LT |
1602 | } |
1603 | } | |
1604 | #ifdef CONFIG_UDF_NLS | |
1605 | if (UDF_QUERY_FLAG(sb, UDF_FLAG_NLS_MAP)) | |
1606 | unload_nls(UDF_SB(sb)->s_nls_map); | |
1607 | #endif | |
1608 | if (!(sb->s_flags & MS_RDONLY)) | |
1609 | udf_close_lvid(sb); | |
3bf25cb4 | 1610 | brelse(UDF_SB_LVIDBH(sb)); |
1da177e4 LT |
1611 | UDF_SB_FREE(sb); |
1612 | kfree(sbi); | |
1613 | sb->s_fs_info = NULL; | |
28de7948 | 1614 | |
1da177e4 LT |
1615 | return -EINVAL; |
1616 | } | |
1617 | ||
1618 | void udf_error(struct super_block *sb, const char *function, | |
cb00ea35 | 1619 | const char *fmt, ...) |
1da177e4 LT |
1620 | { |
1621 | va_list args; | |
1622 | ||
cb00ea35 | 1623 | if (!(sb->s_flags & MS_RDONLY)) { |
1da177e4 LT |
1624 | /* mark sb error */ |
1625 | sb->s_dirt = 1; | |
1626 | } | |
1627 | va_start(args, fmt); | |
4a6e617a | 1628 | vsnprintf(error_buf, sizeof(error_buf), fmt, args); |
1da177e4 | 1629 | va_end(args); |
28de7948 CG |
1630 | printk (KERN_CRIT "UDF-fs error (device %s): %s: %s\n", |
1631 | sb->s_id, function, error_buf); | |
1da177e4 LT |
1632 | } |
1633 | ||
1634 | void udf_warning(struct super_block *sb, const char *function, | |
cb00ea35 | 1635 | const char *fmt, ...) |
1da177e4 LT |
1636 | { |
1637 | va_list args; | |
1638 | ||
cb00ea35 | 1639 | va_start(args, fmt); |
4a6e617a | 1640 | vsnprintf(error_buf, sizeof(error_buf), fmt, args); |
1da177e4 LT |
1641 | va_end(args); |
1642 | printk(KERN_WARNING "UDF-fs warning (device %s): %s: %s\n", | |
cb00ea35 | 1643 | sb->s_id, function, error_buf); |
1da177e4 LT |
1644 | } |
1645 | ||
1646 | /* | |
1647 | * udf_put_super | |
1648 | * | |
1649 | * PURPOSE | |
1650 | * Prepare for destruction of the superblock. | |
1651 | * | |
1652 | * DESCRIPTION | |
1653 | * Called before the filesystem is unmounted. | |
1654 | * | |
1655 | * HISTORY | |
1656 | * July 1, 1997 - Andrew E. Mileski | |
1657 | * Written, tested, and released. | |
1658 | */ | |
cb00ea35 | 1659 | static void udf_put_super(struct super_block *sb) |
1da177e4 LT |
1660 | { |
1661 | int i; | |
1662 | ||
1663 | if (UDF_SB_VAT(sb)) | |
1664 | iput(UDF_SB_VAT(sb)); | |
cb00ea35 | 1665 | if (UDF_SB_NUMPARTS(sb)) { |
28de7948 CG |
1666 | if (UDF_SB_PARTFLAGS(sb, UDF_SB_PARTITION(sb)) & UDF_PART_FLAG_UNALLOC_TABLE) |
1667 | iput(UDF_SB_PARTMAPS(sb)[UDF_SB_PARTITION(sb)].s_uspace.s_table); | |
1668 | if (UDF_SB_PARTFLAGS(sb, UDF_SB_PARTITION(sb)) & UDF_PART_FLAG_FREED_TABLE) | |
1669 | iput(UDF_SB_PARTMAPS(sb)[UDF_SB_PARTITION(sb)].s_fspace.s_table); | |
1670 | if (UDF_SB_PARTFLAGS(sb, UDF_SB_PARTITION(sb)) & UDF_PART_FLAG_UNALLOC_BITMAP) | |
1671 | UDF_SB_FREE_BITMAP(sb,UDF_SB_PARTITION(sb), s_uspace); | |
1672 | if (UDF_SB_PARTFLAGS(sb, UDF_SB_PARTITION(sb)) & UDF_PART_FLAG_FREED_BITMAP) | |
1673 | UDF_SB_FREE_BITMAP(sb,UDF_SB_PARTITION(sb), s_fspace); | |
1674 | if (UDF_SB_PARTTYPE(sb, UDF_SB_PARTITION(sb)) == UDF_SPARABLE_MAP15) { | |
cb00ea35 | 1675 | for (i = 0; i < 4; i++) |
28de7948 | 1676 | brelse(UDF_SB_TYPESPAR(sb, UDF_SB_PARTITION(sb)).s_spar_map[i]); |
1da177e4 LT |
1677 | } |
1678 | } | |
1679 | #ifdef CONFIG_UDF_NLS | |
1680 | if (UDF_QUERY_FLAG(sb, UDF_FLAG_NLS_MAP)) | |
1681 | unload_nls(UDF_SB(sb)->s_nls_map); | |
1682 | #endif | |
1683 | if (!(sb->s_flags & MS_RDONLY)) | |
1684 | udf_close_lvid(sb); | |
3bf25cb4 | 1685 | brelse(UDF_SB_LVIDBH(sb)); |
1da177e4 LT |
1686 | UDF_SB_FREE(sb); |
1687 | kfree(sb->s_fs_info); | |
1688 | sb->s_fs_info = NULL; | |
1689 | } | |
1690 | ||
1691 | /* | |
1692 | * udf_stat_fs | |
1693 | * | |
1694 | * PURPOSE | |
1695 | * Return info about the filesystem. | |
1696 | * | |
1697 | * DESCRIPTION | |
1698 | * Called by sys_statfs() | |
1699 | * | |
1700 | * HISTORY | |
1701 | * July 1, 1997 - Andrew E. Mileski | |
1702 | * Written, tested, and released. | |
1703 | */ | |
cb00ea35 | 1704 | static int udf_statfs(struct dentry *dentry, struct kstatfs *buf) |
1da177e4 | 1705 | { |
726c3342 DH |
1706 | struct super_block *sb = dentry->d_sb; |
1707 | ||
1da177e4 LT |
1708 | buf->f_type = UDF_SUPER_MAGIC; |
1709 | buf->f_bsize = sb->s_blocksize; | |
1710 | buf->f_blocks = UDF_SB_PARTLEN(sb, UDF_SB_PARTITION(sb)); | |
1711 | buf->f_bfree = udf_count_free(sb); | |
1712 | buf->f_bavail = buf->f_bfree; | |
1713 | buf->f_files = (UDF_SB_LVIDBH(sb) ? | |
cb00ea35 | 1714 | (le32_to_cpu(UDF_SB_LVIDIU(sb)->numFiles) + |
28de7948 | 1715 | le32_to_cpu(UDF_SB_LVIDIU(sb)->numDirs)) : 0) + buf->f_bfree; |
1da177e4 LT |
1716 | buf->f_ffree = buf->f_bfree; |
1717 | /* __kernel_fsid_t f_fsid */ | |
cb00ea35 | 1718 | buf->f_namelen = UDF_NAME_LEN - 2; |
1da177e4 LT |
1719 | |
1720 | return 0; | |
1721 | } | |
1722 | ||
1723 | static unsigned char udf_bitmap_lookup[16] = { | |
1724 | 0, 1, 1, 2, 1, 2, 2, 3, 1, 2, 2, 3, 2, 3, 3, 4 | |
1725 | }; | |
1726 | ||
28de7948 | 1727 | static unsigned int udf_count_free_bitmap(struct super_block *sb, struct udf_bitmap *bitmap) |
1da177e4 LT |
1728 | { |
1729 | struct buffer_head *bh = NULL; | |
1730 | unsigned int accum = 0; | |
1731 | int index; | |
1732 | int block = 0, newblock; | |
1733 | kernel_lb_addr loc; | |
1734 | uint32_t bytes; | |
1735 | uint8_t value; | |
1736 | uint8_t *ptr; | |
1737 | uint16_t ident; | |
1738 | struct spaceBitmapDesc *bm; | |
1739 | ||
1740 | lock_kernel(); | |
1741 | ||
1742 | loc.logicalBlockNum = bitmap->s_extPosition; | |
1743 | loc.partitionReferenceNum = UDF_SB_PARTITION(sb); | |
1744 | bh = udf_read_ptagged(sb, loc, 0, &ident); | |
1745 | ||
cb00ea35 | 1746 | if (!bh) { |
1da177e4 LT |
1747 | printk(KERN_ERR "udf: udf_count_free failed\n"); |
1748 | goto out; | |
cb00ea35 | 1749 | } else if (ident != TAG_IDENT_SBD) { |
3bf25cb4 | 1750 | brelse(bh); |
1da177e4 LT |
1751 | printk(KERN_ERR "udf: udf_count_free failed\n"); |
1752 | goto out; | |
1753 | } | |
1754 | ||
1755 | bm = (struct spaceBitmapDesc *)bh->b_data; | |
1756 | bytes = le32_to_cpu(bm->numOfBytes); | |
28de7948 CG |
1757 | index = sizeof(struct spaceBitmapDesc); /* offset in first block only */ |
1758 | ptr = (uint8_t *)bh->b_data; | |
1da177e4 | 1759 | |
cb00ea35 CG |
1760 | while (bytes > 0) { |
1761 | while ((bytes > 0) && (index < sb->s_blocksize)) { | |
1da177e4 | 1762 | value = ptr[index]; |
cb00ea35 CG |
1763 | accum += udf_bitmap_lookup[value & 0x0f]; |
1764 | accum += udf_bitmap_lookup[value >> 4]; | |
1da177e4 LT |
1765 | index++; |
1766 | bytes--; | |
1767 | } | |
cb00ea35 | 1768 | if (bytes) { |
3bf25cb4 | 1769 | brelse(bh); |
1da177e4 LT |
1770 | newblock = udf_get_lb_pblock(sb, loc, ++block); |
1771 | bh = udf_tread(sb, newblock); | |
cb00ea35 | 1772 | if (!bh) { |
1da177e4 LT |
1773 | udf_debug("read failed\n"); |
1774 | goto out; | |
1775 | } | |
1776 | index = 0; | |
28de7948 | 1777 | ptr = (uint8_t *)bh->b_data; |
1da177e4 LT |
1778 | } |
1779 | } | |
3bf25cb4 | 1780 | brelse(bh); |
1da177e4 | 1781 | |
28de7948 | 1782 | out: |
1da177e4 LT |
1783 | unlock_kernel(); |
1784 | ||
1785 | return accum; | |
1786 | } | |
1787 | ||
28de7948 | 1788 | static unsigned int udf_count_free_table(struct super_block *sb, struct inode *table) |
1da177e4 LT |
1789 | { |
1790 | unsigned int accum = 0; | |
ff116fc8 JK |
1791 | uint32_t elen; |
1792 | kernel_lb_addr eloc; | |
1da177e4 | 1793 | int8_t etype; |
ff116fc8 | 1794 | struct extent_position epos; |
1da177e4 LT |
1795 | |
1796 | lock_kernel(); | |
1797 | ||
ff116fc8 JK |
1798 | epos.block = UDF_I_LOCATION(table); |
1799 | epos.offset = sizeof(struct unallocSpaceEntry); | |
1800 | epos.bh = NULL; | |
1da177e4 | 1801 | |
28de7948 | 1802 | while ((etype = udf_next_aext(table, &epos, &eloc, &elen, 1)) != -1) { |
1da177e4 | 1803 | accum += (elen >> table->i_sb->s_blocksize_bits); |
28de7948 | 1804 | } |
3bf25cb4 | 1805 | brelse(epos.bh); |
1da177e4 LT |
1806 | |
1807 | unlock_kernel(); | |
1808 | ||
1809 | return accum; | |
1810 | } | |
cb00ea35 CG |
1811 | |
1812 | static unsigned int udf_count_free(struct super_block *sb) | |
1da177e4 LT |
1813 | { |
1814 | unsigned int accum = 0; | |
1815 | ||
cb00ea35 | 1816 | if (UDF_SB_LVIDBH(sb)) { |
28de7948 CG |
1817 | if (le32_to_cpu(UDF_SB_LVID(sb)->numOfPartitions) > UDF_SB_PARTITION(sb)) { |
1818 | accum = le32_to_cpu(UDF_SB_LVID(sb)->freeSpaceTable[UDF_SB_PARTITION(sb)]); | |
1da177e4 LT |
1819 | if (accum == 0xFFFFFFFF) |
1820 | accum = 0; | |
1821 | } | |
1822 | } | |
1823 | ||
1824 | if (accum) | |
1825 | return accum; | |
1826 | ||
28de7948 CG |
1827 | if (UDF_SB_PARTFLAGS(sb,UDF_SB_PARTITION(sb)) & UDF_PART_FLAG_UNALLOC_BITMAP) { |
1828 | accum += udf_count_free_bitmap(sb, | |
1829 | UDF_SB_PARTMAPS(sb)[UDF_SB_PARTITION(sb)].s_uspace.s_bitmap); | |
1da177e4 | 1830 | } |
28de7948 CG |
1831 | if (UDF_SB_PARTFLAGS(sb,UDF_SB_PARTITION(sb)) & UDF_PART_FLAG_FREED_BITMAP) { |
1832 | accum += udf_count_free_bitmap(sb, | |
1833 | UDF_SB_PARTMAPS(sb)[UDF_SB_PARTITION(sb)].s_fspace.s_bitmap); | |
1da177e4 LT |
1834 | } |
1835 | if (accum) | |
1836 | return accum; | |
1837 | ||
28de7948 CG |
1838 | if (UDF_SB_PARTFLAGS(sb,UDF_SB_PARTITION(sb)) & UDF_PART_FLAG_UNALLOC_TABLE) { |
1839 | accum += udf_count_free_table(sb, | |
1840 | UDF_SB_PARTMAPS(sb)[UDF_SB_PARTITION(sb)].s_uspace.s_table); | |
1da177e4 | 1841 | } |
28de7948 CG |
1842 | if (UDF_SB_PARTFLAGS(sb,UDF_SB_PARTITION(sb)) & UDF_PART_FLAG_FREED_TABLE) { |
1843 | accum += udf_count_free_table(sb, | |
1844 | UDF_SB_PARTMAPS(sb)[UDF_SB_PARTITION(sb)].s_fspace.s_table); | |
1da177e4 LT |
1845 | } |
1846 | ||
1847 | return accum; | |
1848 | } |