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