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