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