blob: 57788f1ba2dabedfed8a9b7f7286eb3b42176cc2 [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001/*
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 *
Linus Torvalds1da177e2005-04-16 15:20:36 -070017 * 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
Marcin Slusarz3a71fc52008-02-08 04:20:28 -080036 * 12/06/98 blf really hosed things royally. vat/sparing support. sequenced
37 * vol descs. rewrote option handling based on isofs
Linus Torvalds1da177e2005-04-16 15:20:36 -070038 * 12/20/98 find the free space bitmap (if it exists)
39 */
40
Cyrill Gorcunovcb00ea32007-07-19 01:47:43 -070041#include "udfdecl.h"
Linus Torvalds1da177e2005-04-16 15:20:36 -070042
Linus Torvalds1da177e2005-04-16 15:20:36 -070043#include <linux/blkdev.h>
44#include <linux/slab.h>
45#include <linux/kernel.h>
46#include <linux/module.h>
47#include <linux/parser.h>
48#include <linux/stat.h>
49#include <linux/cdrom.h>
50#include <linux/nls.h>
51#include <linux/smp_lock.h>
52#include <linux/buffer_head.h>
53#include <linux/vfs.h>
54#include <linux/vmalloc.h>
55#include <asm/byteorder.h>
56
57#include <linux/udf_fs.h>
58#include "udf_sb.h"
59#include "udf_i.h"
60
61#include <linux/init.h>
62#include <asm/uaccess.h>
63
64#define VDS_POS_PRIMARY_VOL_DESC 0
65#define VDS_POS_UNALLOC_SPACE_DESC 1
66#define VDS_POS_LOGICAL_VOL_DESC 2
67#define VDS_POS_PARTITION_DESC 3
68#define VDS_POS_IMP_USE_VOL_DESC 4
69#define VDS_POS_VOL_DESC_PTR 5
70#define VDS_POS_TERMINATING_DESC 6
71#define VDS_POS_LENGTH 7
72
73static char error_buf[1024];
74
75/* These are the "meat" - everything else is stuffing */
76static int udf_fill_super(struct super_block *, void *, int);
77static void udf_put_super(struct super_block *);
78static void udf_write_super(struct super_block *);
79static int udf_remount_fs(struct super_block *, int *, char *);
80static int udf_check_valid(struct super_block *, int, int);
81static int udf_vrs(struct super_block *sb, int silent);
82static int udf_load_partition(struct super_block *, kernel_lb_addr *);
Cyrill Gorcunovcb00ea32007-07-19 01:47:43 -070083static int udf_load_logicalvol(struct super_block *, struct buffer_head *,
84 kernel_lb_addr *);
Linus Torvalds1da177e2005-04-16 15:20:36 -070085static void udf_load_logicalvolint(struct super_block *, kernel_extent_ad);
86static void udf_find_anchor(struct super_block *);
Cyrill Gorcunovcb00ea32007-07-19 01:47:43 -070087static int udf_find_fileset(struct super_block *, kernel_lb_addr *,
88 kernel_lb_addr *);
Linus Torvalds1da177e2005-04-16 15:20:36 -070089static void udf_load_pvoldesc(struct super_block *, struct buffer_head *);
Cyrill Gorcunovcb00ea32007-07-19 01:47:43 -070090static void udf_load_fileset(struct super_block *, struct buffer_head *,
91 kernel_lb_addr *);
Jan Karabcec4472007-08-30 23:56:22 -070092static int udf_load_partdesc(struct super_block *, struct buffer_head *);
Linus Torvalds1da177e2005-04-16 15:20:36 -070093static void udf_open_lvid(struct super_block *);
94static void udf_close_lvid(struct super_block *);
95static unsigned int udf_count_free(struct super_block *);
David Howells726c3342006-06-23 02:02:58 -070096static int udf_statfs(struct dentry *, struct kstatfs *);
Linus Torvalds1da177e2005-04-16 15:20:36 -070097
98/* UDF filesystem type */
David Howells454e2392006-06-23 02:02:57 -070099static int udf_get_sb(struct file_system_type *fs_type,
Cyrill Gorcunovcb00ea32007-07-19 01:47:43 -0700100 int flags, const char *dev_name, void *data,
101 struct vfsmount *mnt)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700102{
David Howells454e2392006-06-23 02:02:57 -0700103 return get_sb_bdev(fs_type, flags, dev_name, data, udf_fill_super, mnt);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700104}
105
106static struct file_system_type udf_fstype = {
Cyrill Gorcunov28de7942007-07-21 04:37:18 -0700107 .owner = THIS_MODULE,
108 .name = "udf",
109 .get_sb = udf_get_sb,
110 .kill_sb = kill_block_super,
111 .fs_flags = FS_REQUIRES_DEV,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700112};
113
Cyrill Gorcunovcb00ea32007-07-19 01:47:43 -0700114static struct kmem_cache *udf_inode_cachep;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700115
116static struct inode *udf_alloc_inode(struct super_block *sb)
117{
118 struct udf_inode_info *ei;
Marcin Slusarz3a71fc52008-02-08 04:20:28 -0800119 ei = kmem_cache_alloc(udf_inode_cachep, GFP_KERNEL);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700120 if (!ei)
121 return NULL;
Dan Bastone95f87972006-08-13 23:24:18 -0700122
123 ei->i_unique = 0;
124 ei->i_lenExtents = 0;
125 ei->i_next_alloc_block = 0;
126 ei->i_next_alloc_goal = 0;
127 ei->i_strat4096 = 0;
128
Linus Torvalds1da177e2005-04-16 15:20:36 -0700129 return &ei->vfs_inode;
130}
131
132static void udf_destroy_inode(struct inode *inode)
133{
134 kmem_cache_free(udf_inode_cachep, UDF_I(inode));
135}
136
Christoph Lameter4ba9b9d2007-10-16 23:25:51 -0700137static void init_once(struct kmem_cache *cachep, void *foo)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700138{
Cyrill Gorcunovcb00ea32007-07-19 01:47:43 -0700139 struct udf_inode_info *ei = (struct udf_inode_info *)foo;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700140
Christoph Lametera35afb82007-05-16 22:10:57 -0700141 ei->i_ext.i_data = NULL;
142 inode_init_once(&ei->vfs_inode);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700143}
144
145static int init_inodecache(void)
146{
147 udf_inode_cachep = kmem_cache_create("udf_inode_cache",
148 sizeof(struct udf_inode_info),
Cyrill Gorcunovcb00ea32007-07-19 01:47:43 -0700149 0, (SLAB_RECLAIM_ACCOUNT |
150 SLAB_MEM_SPREAD),
Paul Mundt20c2df82007-07-20 10:11:58 +0900151 init_once);
Cyrill Gorcunov28de7942007-07-21 04:37:18 -0700152 if (!udf_inode_cachep)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700153 return -ENOMEM;
154 return 0;
155}
156
157static void destroy_inodecache(void)
158{
Alexey Dobriyan1a1d92c2006-09-27 01:49:40 -0700159 kmem_cache_destroy(udf_inode_cachep);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700160}
161
162/* Superblock operations */
Josef 'Jeff' Sipekee9b6d62007-02-12 00:55:41 -0800163static const struct super_operations udf_sb_ops = {
Cyrill Gorcunov28de7942007-07-21 04:37:18 -0700164 .alloc_inode = udf_alloc_inode,
165 .destroy_inode = udf_destroy_inode,
166 .write_inode = udf_write_inode,
167 .delete_inode = udf_delete_inode,
168 .clear_inode = udf_clear_inode,
169 .put_super = udf_put_super,
170 .write_super = udf_write_super,
171 .statfs = udf_statfs,
172 .remount_fs = udf_remount_fs,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700173};
174
Cyrill Gorcunovcb00ea32007-07-19 01:47:43 -0700175struct udf_options {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700176 unsigned char novrs;
177 unsigned int blocksize;
178 unsigned int session;
179 unsigned int lastblock;
180 unsigned int anchor;
181 unsigned int volume;
182 unsigned short partition;
183 unsigned int fileset;
184 unsigned int rootdir;
185 unsigned int flags;
186 mode_t umask;
187 gid_t gid;
188 uid_t uid;
189 struct nls_table *nls_map;
190};
191
192static int __init init_udf_fs(void)
193{
194 int err;
Cyrill Gorcunov28de7942007-07-21 04:37:18 -0700195
Linus Torvalds1da177e2005-04-16 15:20:36 -0700196 err = init_inodecache();
197 if (err)
198 goto out1;
199 err = register_filesystem(&udf_fstype);
200 if (err)
201 goto out;
Cyrill Gorcunov28de7942007-07-21 04:37:18 -0700202
Linus Torvalds1da177e2005-04-16 15:20:36 -0700203 return 0;
Cyrill Gorcunov28de7942007-07-21 04:37:18 -0700204
205out:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700206 destroy_inodecache();
Cyrill Gorcunov28de7942007-07-21 04:37:18 -0700207
208out1:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700209 return err;
210}
211
212static void __exit exit_udf_fs(void)
213{
214 unregister_filesystem(&udf_fstype);
215 destroy_inodecache();
216}
217
218module_init(init_udf_fs)
Cyrill Gorcunov28de7942007-07-21 04:37:18 -0700219module_exit(exit_udf_fs)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700220
221/*
222 * udf_parse_options
223 *
224 * PURPOSE
225 * Parse mount options.
226 *
227 * DESCRIPTION
228 * The following mount options are supported:
229 *
230 * gid= Set the default group.
231 * umask= Set the default umask.
232 * uid= Set the default user.
233 * bs= Set the block size.
234 * unhide Show otherwise hidden files.
235 * undelete Show deleted files in lists.
236 * adinicb Embed data in the inode (default)
237 * noadinicb Don't embed data in the inode
238 * shortad Use short ad's
239 * longad Use long ad's (default)
240 * nostrict Unset strict conformance
241 * iocharset= Set the NLS character set
242 *
243 * The remaining are for debugging and disaster recovery:
244 *
Cyrill Gorcunov28de7942007-07-21 04:37:18 -0700245 * novrs Skip volume sequence recognition
Linus Torvalds1da177e2005-04-16 15:20:36 -0700246 *
247 * The following expect a offset from 0.
248 *
249 * session= Set the CDROM session (default= last session)
250 * anchor= Override standard anchor location. (default= 256)
251 * volume= Override the VolumeDesc location. (unused)
252 * partition= Override the PartitionDesc location. (unused)
253 * lastblock= Set the last block of the filesystem/
254 *
255 * The following expect a offset from the partition root.
256 *
257 * fileset= Override the fileset block location. (unused)
258 * rootdir= Override the root directory location. (unused)
259 * WARNING: overriding the rootdir to a non-directory may
260 * yield highly unpredictable results.
261 *
262 * PRE-CONDITIONS
263 * options Pointer to mount options string.
264 * uopts Pointer to mount options variable.
265 *
266 * POST-CONDITIONS
267 * <return> 1 Mount options parsed okay.
268 * <return> 0 Error parsing mount options.
269 *
270 * HISTORY
271 * July 1, 1997 - Andrew E. Mileski
272 * Written, tested, and released.
273 */
Cyrill Gorcunov28de7942007-07-21 04:37:18 -0700274
Linus Torvalds1da177e2005-04-16 15:20:36 -0700275enum {
276 Opt_novrs, Opt_nostrict, Opt_bs, Opt_unhide, Opt_undelete,
277 Opt_noadinicb, Opt_adinicb, Opt_shortad, Opt_longad,
278 Opt_gid, Opt_uid, Opt_umask, Opt_session, Opt_lastblock,
279 Opt_anchor, Opt_volume, Opt_partition, Opt_fileset,
280 Opt_rootdir, Opt_utf8, Opt_iocharset,
Phillip Susi4d6660e2006-03-07 21:55:24 -0800281 Opt_err, Opt_uforget, Opt_uignore, Opt_gforget, Opt_gignore
Linus Torvalds1da177e2005-04-16 15:20:36 -0700282};
283
284static match_table_t tokens = {
Cyrill Gorcunov28de7942007-07-21 04:37:18 -0700285 {Opt_novrs, "novrs"},
286 {Opt_nostrict, "nostrict"},
287 {Opt_bs, "bs=%u"},
288 {Opt_unhide, "unhide"},
289 {Opt_undelete, "undelete"},
290 {Opt_noadinicb, "noadinicb"},
291 {Opt_adinicb, "adinicb"},
292 {Opt_shortad, "shortad"},
293 {Opt_longad, "longad"},
294 {Opt_uforget, "uid=forget"},
295 {Opt_uignore, "uid=ignore"},
296 {Opt_gforget, "gid=forget"},
297 {Opt_gignore, "gid=ignore"},
298 {Opt_gid, "gid=%u"},
299 {Opt_uid, "uid=%u"},
300 {Opt_umask, "umask=%o"},
301 {Opt_session, "session=%u"},
302 {Opt_lastblock, "lastblock=%u"},
303 {Opt_anchor, "anchor=%u"},
304 {Opt_volume, "volume=%u"},
305 {Opt_partition, "partition=%u"},
306 {Opt_fileset, "fileset=%u"},
307 {Opt_rootdir, "rootdir=%u"},
308 {Opt_utf8, "utf8"},
309 {Opt_iocharset, "iocharset=%s"},
310 {Opt_err, NULL}
Linus Torvalds1da177e2005-04-16 15:20:36 -0700311};
312
Cyrill Gorcunovcb00ea32007-07-19 01:47:43 -0700313static int udf_parse_options(char *options, struct udf_options *uopt)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700314{
315 char *p;
316 int option;
317
318 uopt->novrs = 0;
319 uopt->blocksize = 2048;
320 uopt->partition = 0xFFFF;
321 uopt->session = 0xFFFFFFFF;
322 uopt->lastblock = 0;
323 uopt->anchor = 0;
324 uopt->volume = 0xFFFFFFFF;
325 uopt->rootdir = 0xFFFFFFFF;
326 uopt->fileset = 0xFFFFFFFF;
327 uopt->nls_map = NULL;
328
329 if (!options)
330 return 1;
331
Cyrill Gorcunovcb00ea32007-07-19 01:47:43 -0700332 while ((p = strsep(&options, ",")) != NULL) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700333 substring_t args[MAX_OPT_ARGS];
334 int token;
335 if (!*p)
336 continue;
337
338 token = match_token(p, tokens, args);
Cyrill Gorcunovcb00ea32007-07-19 01:47:43 -0700339 switch (token) {
340 case Opt_novrs:
341 uopt->novrs = 1;
342 case Opt_bs:
343 if (match_int(&args[0], &option))
344 return 0;
345 uopt->blocksize = option;
346 break;
347 case Opt_unhide:
348 uopt->flags |= (1 << UDF_FLAG_UNHIDE);
349 break;
350 case Opt_undelete:
351 uopt->flags |= (1 << UDF_FLAG_UNDELETE);
352 break;
353 case Opt_noadinicb:
354 uopt->flags &= ~(1 << UDF_FLAG_USE_AD_IN_ICB);
355 break;
356 case Opt_adinicb:
357 uopt->flags |= (1 << UDF_FLAG_USE_AD_IN_ICB);
358 break;
359 case Opt_shortad:
360 uopt->flags |= (1 << UDF_FLAG_USE_SHORT_AD);
361 break;
362 case Opt_longad:
363 uopt->flags &= ~(1 << UDF_FLAG_USE_SHORT_AD);
364 break;
365 case Opt_gid:
366 if (match_int(args, &option))
367 return 0;
368 uopt->gid = option;
Cyrill Gorcunovca76d2d2007-07-31 00:39:40 -0700369 uopt->flags |= (1 << UDF_FLAG_GID_SET);
Cyrill Gorcunovcb00ea32007-07-19 01:47:43 -0700370 break;
371 case Opt_uid:
372 if (match_int(args, &option))
373 return 0;
374 uopt->uid = option;
Cyrill Gorcunovca76d2d2007-07-31 00:39:40 -0700375 uopt->flags |= (1 << UDF_FLAG_UID_SET);
Cyrill Gorcunovcb00ea32007-07-19 01:47:43 -0700376 break;
377 case Opt_umask:
378 if (match_octal(args, &option))
379 return 0;
380 uopt->umask = option;
381 break;
382 case Opt_nostrict:
383 uopt->flags &= ~(1 << UDF_FLAG_STRICT);
384 break;
385 case Opt_session:
386 if (match_int(args, &option))
387 return 0;
388 uopt->session = option;
389 break;
390 case Opt_lastblock:
391 if (match_int(args, &option))
392 return 0;
393 uopt->lastblock = option;
394 break;
395 case Opt_anchor:
396 if (match_int(args, &option))
397 return 0;
398 uopt->anchor = option;
399 break;
400 case Opt_volume:
401 if (match_int(args, &option))
402 return 0;
403 uopt->volume = option;
404 break;
405 case Opt_partition:
406 if (match_int(args, &option))
407 return 0;
408 uopt->partition = option;
409 break;
410 case Opt_fileset:
411 if (match_int(args, &option))
412 return 0;
413 uopt->fileset = option;
414 break;
415 case Opt_rootdir:
416 if (match_int(args, &option))
417 return 0;
418 uopt->rootdir = option;
419 break;
420 case Opt_utf8:
421 uopt->flags |= (1 << UDF_FLAG_UTF8);
422 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700423#ifdef CONFIG_UDF_NLS
Cyrill Gorcunovcb00ea32007-07-19 01:47:43 -0700424 case Opt_iocharset:
425 uopt->nls_map = load_nls(args[0].from);
426 uopt->flags |= (1 << UDF_FLAG_NLS_MAP);
427 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700428#endif
Cyrill Gorcunovcb00ea32007-07-19 01:47:43 -0700429 case Opt_uignore:
430 uopt->flags |= (1 << UDF_FLAG_UID_IGNORE);
431 break;
432 case Opt_uforget:
433 uopt->flags |= (1 << UDF_FLAG_UID_FORGET);
434 break;
435 case Opt_gignore:
436 uopt->flags |= (1 << UDF_FLAG_GID_IGNORE);
437 break;
438 case Opt_gforget:
439 uopt->flags |= (1 << UDF_FLAG_GID_FORGET);
440 break;
441 default:
442 printk(KERN_ERR "udf: bad mount option \"%s\" "
443 "or missing value\n", p);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700444 return 0;
445 }
446 }
447 return 1;
448}
449
Cyrill Gorcunovcb00ea32007-07-19 01:47:43 -0700450void udf_write_super(struct super_block *sb)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700451{
452 lock_kernel();
Cyrill Gorcunov28de7942007-07-21 04:37:18 -0700453
Linus Torvalds1da177e2005-04-16 15:20:36 -0700454 if (!(sb->s_flags & MS_RDONLY))
455 udf_open_lvid(sb);
456 sb->s_dirt = 0;
Cyrill Gorcunov28de7942007-07-21 04:37:18 -0700457
Linus Torvalds1da177e2005-04-16 15:20:36 -0700458 unlock_kernel();
459}
460
Cyrill Gorcunovcb00ea32007-07-19 01:47:43 -0700461static int udf_remount_fs(struct super_block *sb, int *flags, char *options)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700462{
463 struct udf_options uopt;
464
Cyrill Gorcunovcb00ea32007-07-19 01:47:43 -0700465 uopt.flags = UDF_SB(sb)->s_flags;
Cyrill Gorcunov28de7942007-07-21 04:37:18 -0700466 uopt.uid = UDF_SB(sb)->s_uid;
467 uopt.gid = UDF_SB(sb)->s_gid;
Cyrill Gorcunovcb00ea32007-07-19 01:47:43 -0700468 uopt.umask = UDF_SB(sb)->s_umask;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700469
Cyrill Gorcunovcb00ea32007-07-19 01:47:43 -0700470 if (!udf_parse_options(options, &uopt))
Linus Torvalds1da177e2005-04-16 15:20:36 -0700471 return -EINVAL;
472
473 UDF_SB(sb)->s_flags = uopt.flags;
Cyrill Gorcunov28de7942007-07-21 04:37:18 -0700474 UDF_SB(sb)->s_uid = uopt.uid;
475 UDF_SB(sb)->s_gid = uopt.gid;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700476 UDF_SB(sb)->s_umask = uopt.umask;
477
478 if (UDF_SB_LVIDBH(sb)) {
479 int write_rev = le16_to_cpu(UDF_SB_LVIDIU(sb)->minUDFWriteRev);
480 if (write_rev > UDF_MAX_WRITE_VERSION)
481 *flags |= MS_RDONLY;
482 }
483
484 if ((*flags & MS_RDONLY) == (sb->s_flags & MS_RDONLY))
485 return 0;
486 if (*flags & MS_RDONLY)
487 udf_close_lvid(sb);
488 else
489 udf_open_lvid(sb);
490
491 return 0;
492}
493
494/*
495 * udf_set_blocksize
496 *
497 * PURPOSE
498 * Set the block size to be used in all transfers.
499 *
500 * DESCRIPTION
501 * To allow room for a DMA transfer, it is best to guess big when unsure.
502 * This routine picks 2048 bytes as the blocksize when guessing. This
503 * should be adequate until devices with larger block sizes become common.
504 *
505 * Note that the Linux kernel can currently only deal with blocksizes of
506 * 512, 1024, 2048, 4096, and 8192 bytes.
507 *
508 * PRE-CONDITIONS
509 * sb Pointer to _locked_ superblock.
510 *
511 * POST-CONDITIONS
512 * sb->s_blocksize Blocksize.
513 * sb->s_blocksize_bits log2 of blocksize.
514 * <return> 0 Blocksize is valid.
515 * <return> 1 Blocksize is invalid.
516 *
517 * HISTORY
518 * July 1, 1997 - Andrew E. Mileski
519 * Written, tested, and released.
520 */
Cyrill Gorcunovcb00ea32007-07-19 01:47:43 -0700521static int udf_set_blocksize(struct super_block *sb, int bsize)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700522{
523 if (!sb_min_blocksize(sb, bsize)) {
524 udf_debug("Bad block size (%d)\n", bsize);
525 printk(KERN_ERR "udf: bad block size (%d)\n", bsize);
526 return 0;
527 }
Cyrill Gorcunov28de7942007-07-21 04:37:18 -0700528
Linus Torvalds1da177e2005-04-16 15:20:36 -0700529 return sb->s_blocksize;
530}
531
Cyrill Gorcunovcb00ea32007-07-19 01:47:43 -0700532static int udf_vrs(struct super_block *sb, int silent)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700533{
534 struct volStructDesc *vsd = NULL;
535 int sector = 32768;
536 int sectorsize;
537 struct buffer_head *bh = NULL;
Cyrill Gorcunovcb00ea32007-07-19 01:47:43 -0700538 int iso9660 = 0;
539 int nsr02 = 0;
540 int nsr03 = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700541
542 /* Block size must be a multiple of 512 */
543 if (sb->s_blocksize & 511)
544 return 0;
545
546 if (sb->s_blocksize < sizeof(struct volStructDesc))
547 sectorsize = sizeof(struct volStructDesc);
548 else
549 sectorsize = sb->s_blocksize;
550
551 sector += (UDF_SB_SESSION(sb) << sb->s_blocksize_bits);
552
553 udf_debug("Starting at sector %u (%ld byte sectors)\n",
Cyrill Gorcunovcb00ea32007-07-19 01:47:43 -0700554 (sector >> sb->s_blocksize_bits), sb->s_blocksize);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700555 /* Process the sequence (if applicable) */
Cyrill Gorcunovcb00ea32007-07-19 01:47:43 -0700556 for (; !nsr02 && !nsr03; sector += sectorsize) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700557 /* Read a block */
558 bh = udf_tread(sb, sector >> sb->s_blocksize_bits);
559 if (!bh)
560 break;
561
562 /* Look for ISO descriptors */
563 vsd = (struct volStructDesc *)(bh->b_data +
Marcin Slusarz3a71fc52008-02-08 04:20:28 -0800564 (sector & (sb->s_blocksize - 1)));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700565
Cyrill Gorcunovcb00ea32007-07-19 01:47:43 -0700566 if (vsd->stdIdent[0] == 0) {
Jan Kara3bf25cb2007-05-08 00:35:16 -0700567 brelse(bh);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700568 break;
Marcin Slusarz3a71fc52008-02-08 04:20:28 -0800569 } else if (!strncmp(vsd->stdIdent, VSD_STD_ID_CD001,
570 VSD_STD_ID_LEN)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700571 iso9660 = sector;
Cyrill Gorcunovcb00ea32007-07-19 01:47:43 -0700572 switch (vsd->structType) {
573 case 0:
574 udf_debug("ISO9660 Boot Record found\n");
575 break;
576 case 1:
Marcin Slusarz3a71fc52008-02-08 04:20:28 -0800577 udf_debug("ISO9660 Primary Volume Descriptor "
578 "found\n");
Cyrill Gorcunovcb00ea32007-07-19 01:47:43 -0700579 break;
580 case 2:
Marcin Slusarz3a71fc52008-02-08 04:20:28 -0800581 udf_debug("ISO9660 Supplementary Volume "
582 "Descriptor found\n");
Cyrill Gorcunovcb00ea32007-07-19 01:47:43 -0700583 break;
584 case 3:
Marcin Slusarz3a71fc52008-02-08 04:20:28 -0800585 udf_debug("ISO9660 Volume Partition Descriptor "
586 "found\n");
Cyrill Gorcunovcb00ea32007-07-19 01:47:43 -0700587 break;
588 case 255:
Marcin Slusarz3a71fc52008-02-08 04:20:28 -0800589 udf_debug("ISO9660 Volume Descriptor Set "
590 "Terminator found\n");
Cyrill Gorcunovcb00ea32007-07-19 01:47:43 -0700591 break;
592 default:
593 udf_debug("ISO9660 VRS (%u) found\n",
594 vsd->structType);
595 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700596 }
Marcin Slusarz3a71fc52008-02-08 04:20:28 -0800597 } else if (!strncmp(vsd->stdIdent, VSD_STD_ID_BEA01,
598 VSD_STD_ID_LEN))
599 ; /* nothing */
600 else if (!strncmp(vsd->stdIdent, VSD_STD_ID_TEA01,
601 VSD_STD_ID_LEN)) {
Jan Kara3bf25cb2007-05-08 00:35:16 -0700602 brelse(bh);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700603 break;
Marcin Slusarz3a71fc52008-02-08 04:20:28 -0800604 } else if (!strncmp(vsd->stdIdent, VSD_STD_ID_NSR02,
605 VSD_STD_ID_LEN))
Linus Torvalds1da177e2005-04-16 15:20:36 -0700606 nsr02 = sector;
Marcin Slusarz3a71fc52008-02-08 04:20:28 -0800607 else if (!strncmp(vsd->stdIdent, VSD_STD_ID_NSR03,
608 VSD_STD_ID_LEN))
Linus Torvalds1da177e2005-04-16 15:20:36 -0700609 nsr03 = sector;
Jan Kara3bf25cb2007-05-08 00:35:16 -0700610 brelse(bh);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700611 }
612
613 if (nsr03)
614 return nsr03;
615 else if (nsr02)
616 return nsr02;
617 else if (sector - (UDF_SB_SESSION(sb) << sb->s_blocksize_bits) == 32768)
618 return -1;
619 else
620 return 0;
621}
622
623/*
624 * udf_find_anchor
625 *
626 * PURPOSE
627 * Find an anchor volume descriptor.
628 *
629 * PRE-CONDITIONS
630 * sb Pointer to _locked_ superblock.
631 * lastblock Last block on media.
632 *
633 * POST-CONDITIONS
634 * <return> 1 if not found, 0 if ok
635 *
636 * HISTORY
637 * July 1, 1997 - Andrew E. Mileski
638 * Written, tested, and released.
639 */
Cyrill Gorcunovcb00ea32007-07-19 01:47:43 -0700640static void udf_find_anchor(struct super_block *sb)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700641{
642 int lastblock = UDF_SB_LASTBLOCK(sb);
643 struct buffer_head *bh = NULL;
644 uint16_t ident;
645 uint32_t location;
646 int i;
647
Cyrill Gorcunovcb00ea32007-07-19 01:47:43 -0700648 if (lastblock) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700649 int varlastblock = udf_variable_to_fixed(lastblock);
Cyrill Gorcunov28de7942007-07-21 04:37:18 -0700650 int last[] = { lastblock, lastblock - 2,
651 lastblock - 150, lastblock - 152,
652 varlastblock, varlastblock - 2,
653 varlastblock - 150, varlastblock - 152 };
Linus Torvalds1da177e2005-04-16 15:20:36 -0700654
655 lastblock = 0;
656
657 /* Search for an anchor volume descriptor pointer */
658
659 /* according to spec, anchor is in either:
660 * block 256
661 * lastblock-256
662 * lastblock
663 * however, if the disc isn't closed, it could be 512 */
664
Tobias Klausere8c96f82006-03-24 03:15:34 -0800665 for (i = 0; !lastblock && i < ARRAY_SIZE(last); i++) {
Marcin Slusarz3a71fc52008-02-08 04:20:28 -0800666 ident = location = 0;
667 if (last[i] >= 0) {
668 bh = sb_bread(sb, last[i]);
669 if (bh) {
670 tag *t = (tag *)bh->b_data;
671 ident = le16_to_cpu(t->tagIdent);
672 location = le32_to_cpu(t->tagLocation);
673 brelse(bh);
674 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700675 }
Tobias Klausere8c96f82006-03-24 03:15:34 -0800676
Cyrill Gorcunovcb00ea32007-07-19 01:47:43 -0700677 if (ident == TAG_IDENT_AVDP) {
678 if (location == last[i] - UDF_SB_SESSION(sb)) {
Marcin Slusarz3a71fc52008-02-08 04:20:28 -0800679 lastblock = last[i] - UDF_SB_SESSION(sb);
680 UDF_SB_ANCHOR(sb)[0] = lastblock;
681 UDF_SB_ANCHOR(sb)[1] = lastblock - 256;
Cyrill Gorcunov28de7942007-07-21 04:37:18 -0700682 } else if (location == udf_variable_to_fixed(last[i]) - UDF_SB_SESSION(sb)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700683 UDF_SET_FLAG(sb, UDF_FLAG_VARCONV);
Marcin Slusarz3a71fc52008-02-08 04:20:28 -0800684 lastblock = udf_variable_to_fixed(last[i]) - UDF_SB_SESSION(sb);
685 UDF_SB_ANCHOR(sb)[0] = lastblock;
Cyrill Gorcunov28de7942007-07-21 04:37:18 -0700686 UDF_SB_ANCHOR(sb)[1] = lastblock - 256 - UDF_SB_SESSION(sb);
687 } else {
688 udf_debug("Anchor found at block %d, location mismatch %d.\n",
689 last[i], location);
690 }
691 } else if (ident == TAG_IDENT_FE || ident == TAG_IDENT_EFE) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700692 lastblock = last[i];
693 UDF_SB_ANCHOR(sb)[3] = 512;
Cyrill Gorcunovcb00ea32007-07-19 01:47:43 -0700694 } else {
Marcin Slusarz3a71fc52008-02-08 04:20:28 -0800695 ident = location = 0;
696 if (last[i] >= 256) {
697 bh = sb_bread(sb, last[i] - 256);
698 if (bh) {
699 tag *t = (tag *)bh->b_data;
700 ident = le16_to_cpu(t->tagIdent);
701 location = le32_to_cpu(t->tagLocation);
702 brelse(bh);
703 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700704 }
Cyrill Gorcunovcb00ea32007-07-19 01:47:43 -0700705
Linus Torvalds1da177e2005-04-16 15:20:36 -0700706 if (ident == TAG_IDENT_AVDP &&
Cyrill Gorcunov28de7942007-07-21 04:37:18 -0700707 location == last[i] - 256 - UDF_SB_SESSION(sb)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700708 lastblock = last[i];
709 UDF_SB_ANCHOR(sb)[1] = last[i] - 256;
Cyrill Gorcunovcb00ea32007-07-19 01:47:43 -0700710 } else {
Marcin Slusarz3a71fc52008-02-08 04:20:28 -0800711 ident = location = 0;
712 if (last[i] >= 312 + UDF_SB_SESSION(sb)) {
713 bh = sb_bread(sb, last[i] - 312 - UDF_SB_SESSION(sb));
714 if (bh) {
715 tag *t = (tag *)bh->b_data;
716 ident = le16_to_cpu(t->tagIdent);
717 location = le32_to_cpu(t->tagLocation);
718 brelse(bh);
719 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700720 }
Cyrill Gorcunovcb00ea32007-07-19 01:47:43 -0700721
Linus Torvalds1da177e2005-04-16 15:20:36 -0700722 if (ident == TAG_IDENT_AVDP &&
Cyrill Gorcunov28de7942007-07-21 04:37:18 -0700723 location == udf_variable_to_fixed(last[i]) - 256) {
724 UDF_SET_FLAG(sb, UDF_FLAG_VARCONV);
725 lastblock = udf_variable_to_fixed(last[i]);
726 UDF_SB_ANCHOR(sb)[1] = lastblock - 256;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700727 }
728 }
729 }
730 }
731 }
732
Cyrill Gorcunovcb00ea32007-07-19 01:47:43 -0700733 if (!lastblock) {
Marcin Slusarz3a71fc52008-02-08 04:20:28 -0800734 /* We haven't found the lastblock. check 312 */
735 bh = sb_bread(sb, 312 + UDF_SB_SESSION(sb));
736 if (bh) {
737 tag *t = (tag *)bh->b_data;
738 ident = le16_to_cpu(t->tagIdent);
739 location = le32_to_cpu(t->tagLocation);
Jan Kara3bf25cb2007-05-08 00:35:16 -0700740 brelse(bh);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700741
742 if (ident == TAG_IDENT_AVDP && location == 256)
743 UDF_SET_FLAG(sb, UDF_FLAG_VARCONV);
744 }
745 }
746
Tobias Klausere8c96f82006-03-24 03:15:34 -0800747 for (i = 0; i < ARRAY_SIZE(UDF_SB_ANCHOR(sb)); i++) {
Cyrill Gorcunovcb00ea32007-07-19 01:47:43 -0700748 if (UDF_SB_ANCHOR(sb)[i]) {
Marcin Slusarz3a71fc52008-02-08 04:20:28 -0800749 bh = udf_read_tagged(sb, UDF_SB_ANCHOR(sb)[i],
750 UDF_SB_ANCHOR(sb)[i], &ident);
751 if (!bh)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700752 UDF_SB_ANCHOR(sb)[i] = 0;
Marcin Slusarz3a71fc52008-02-08 04:20:28 -0800753 else {
Jan Kara3bf25cb2007-05-08 00:35:16 -0700754 brelse(bh);
Cyrill Gorcunov28de7942007-07-21 04:37:18 -0700755 if ((ident != TAG_IDENT_AVDP) &&
Marcin Slusarz3a71fc52008-02-08 04:20:28 -0800756 (i || (ident != TAG_IDENT_FE && ident != TAG_IDENT_EFE)))
Linus Torvalds1da177e2005-04-16 15:20:36 -0700757 UDF_SB_ANCHOR(sb)[i] = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700758 }
759 }
760 }
761
762 UDF_SB_LASTBLOCK(sb) = lastblock;
763}
764
Marcin Slusarz3a71fc52008-02-08 04:20:28 -0800765static int udf_find_fileset(struct super_block *sb,
766 kernel_lb_addr *fileset,
767 kernel_lb_addr *root)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700768{
769 struct buffer_head *bh = NULL;
770 long lastblock;
771 uint16_t ident;
772
773 if (fileset->logicalBlockNum != 0xFFFFFFFF ||
Cyrill Gorcunovcb00ea32007-07-19 01:47:43 -0700774 fileset->partitionReferenceNum != 0xFFFF) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700775 bh = udf_read_ptagged(sb, *fileset, 0, &ident);
776
Cyrill Gorcunov28de7942007-07-21 04:37:18 -0700777 if (!bh) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700778 return 1;
Cyrill Gorcunov28de7942007-07-21 04:37:18 -0700779 } else if (ident != TAG_IDENT_FSD) {
Jan Kara3bf25cb2007-05-08 00:35:16 -0700780 brelse(bh);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700781 return 1;
782 }
Cyrill Gorcunovcb00ea32007-07-19 01:47:43 -0700783
Linus Torvalds1da177e2005-04-16 15:20:36 -0700784 }
785
Marcin Slusarz3a71fc52008-02-08 04:20:28 -0800786 if (!bh) {
787 /* Search backwards through the partitions */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700788 kernel_lb_addr newfileset;
789
Cyrill Gorcunov28de7942007-07-21 04:37:18 -0700790/* --> cvg: FIXME - is it reasonable? */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700791 return 1;
Cyrill Gorcunovcb00ea32007-07-19 01:47:43 -0700792
793 for (newfileset.partitionReferenceNum = UDF_SB_NUMPARTS(sb) - 1;
794 (newfileset.partitionReferenceNum != 0xFFFF &&
795 fileset->logicalBlockNum == 0xFFFFFFFF &&
796 fileset->partitionReferenceNum == 0xFFFF);
797 newfileset.partitionReferenceNum--) {
Marcin Slusarz3a71fc52008-02-08 04:20:28 -0800798 lastblock = UDF_SB_PARTLEN(sb,
799 newfileset.partitionReferenceNum);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700800 newfileset.logicalBlockNum = 0;
801
Cyrill Gorcunovcb00ea32007-07-19 01:47:43 -0700802 do {
Marcin Slusarz3a71fc52008-02-08 04:20:28 -0800803 bh = udf_read_ptagged(sb, newfileset, 0,
804 &ident);
Cyrill Gorcunovcb00ea32007-07-19 01:47:43 -0700805 if (!bh) {
806 newfileset.logicalBlockNum++;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700807 continue;
808 }
809
Cyrill Gorcunovcb00ea32007-07-19 01:47:43 -0700810 switch (ident) {
811 case TAG_IDENT_SBD:
Cyrill Gorcunov28de7942007-07-21 04:37:18 -0700812 {
813 struct spaceBitmapDesc *sp;
814 sp = (struct spaceBitmapDesc *)bh->b_data;
815 newfileset.logicalBlockNum += 1 +
816 ((le32_to_cpu(sp->numOfBytes) +
817 sizeof(struct spaceBitmapDesc) - 1)
818 >> sb->s_blocksize_bits);
819 brelse(bh);
820 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700821 }
Cyrill Gorcunov28de7942007-07-21 04:37:18 -0700822 case TAG_IDENT_FSD:
823 *fileset = newfileset;
824 break;
825 default:
826 newfileset.logicalBlockNum++;
827 brelse(bh);
828 bh = NULL;
829 break;
830 }
831 } while (newfileset.logicalBlockNum < lastblock &&
832 fileset->logicalBlockNum == 0xFFFFFFFF &&
833 fileset->partitionReferenceNum == 0xFFFF);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700834 }
835 }
836
837 if ((fileset->logicalBlockNum != 0xFFFFFFFF ||
Cyrill Gorcunovcb00ea32007-07-19 01:47:43 -0700838 fileset->partitionReferenceNum != 0xFFFF) && bh) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700839 udf_debug("Fileset at block=%d, partition=%d\n",
Cyrill Gorcunovcb00ea32007-07-19 01:47:43 -0700840 fileset->logicalBlockNum,
841 fileset->partitionReferenceNum);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700842
843 UDF_SB_PARTITION(sb) = fileset->partitionReferenceNum;
844 udf_load_fileset(sb, bh, root);
Jan Kara3bf25cb2007-05-08 00:35:16 -0700845 brelse(bh);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700846 return 0;
847 }
848 return 1;
849}
850
Cyrill Gorcunovcb00ea32007-07-19 01:47:43 -0700851static void udf_load_pvoldesc(struct super_block *sb, struct buffer_head *bh)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700852{
853 struct primaryVolDesc *pvoldesc;
854 time_t recording;
855 long recording_usec;
856 struct ustr instr;
857 struct ustr outstr;
858
859 pvoldesc = (struct primaryVolDesc *)bh->b_data;
860
Cyrill Gorcunovcb00ea32007-07-19 01:47:43 -0700861 if (udf_stamp_to_time(&recording, &recording_usec,
862 lets_to_cpu(pvoldesc->recordingDateAndTime))) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700863 kernel_timestamp ts;
864 ts = lets_to_cpu(pvoldesc->recordingDateAndTime);
Marcin Slusarz3a71fc52008-02-08 04:20:28 -0800865 udf_debug("recording time %ld/%ld, %04u/%02u/%02u"
866 " %02u:%02u (%x)\n",
Cyrill Gorcunov28de7942007-07-21 04:37:18 -0700867 recording, recording_usec,
868 ts.year, ts.month, ts.day, ts.hour,
869 ts.minute, ts.typeAndTimezone);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700870 UDF_SB_RECORDTIME(sb).tv_sec = recording;
871 UDF_SB_RECORDTIME(sb).tv_nsec = recording_usec * 1000;
872 }
873
Cyrill Gorcunovcb00ea32007-07-19 01:47:43 -0700874 if (!udf_build_ustr(&instr, pvoldesc->volIdent, 32)) {
875 if (udf_CS0toUTF8(&outstr, &instr)) {
876 strncpy(UDF_SB_VOLIDENT(sb), outstr.u_name,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700877 outstr.u_len > 31 ? 31 : outstr.u_len);
878 udf_debug("volIdent[] = '%s'\n", UDF_SB_VOLIDENT(sb));
879 }
880 }
881
Cyrill Gorcunovcb00ea32007-07-19 01:47:43 -0700882 if (!udf_build_ustr(&instr, pvoldesc->volSetIdent, 128)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700883 if (udf_CS0toUTF8(&outstr, &instr))
884 udf_debug("volSetIdent[] = '%s'\n", outstr.u_name);
885 }
886}
887
Cyrill Gorcunov28de7942007-07-21 04:37:18 -0700888static void udf_load_fileset(struct super_block *sb, struct buffer_head *bh,
889 kernel_lb_addr *root)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700890{
891 struct fileSetDesc *fset;
892
893 fset = (struct fileSetDesc *)bh->b_data;
894
895 *root = lelb_to_cpu(fset->rootDirectoryICB.extLocation);
896
897 UDF_SB_SERIALNUM(sb) = le16_to_cpu(fset->descTag.tagSerialNum);
898
Cyrill Gorcunovcb00ea32007-07-19 01:47:43 -0700899 udf_debug("Rootdir at block=%d, partition=%d\n",
900 root->logicalBlockNum, root->partitionReferenceNum);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700901}
902
Jan Karabcec4472007-08-30 23:56:22 -0700903static int udf_load_partdesc(struct super_block *sb, struct buffer_head *bh)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700904{
905 struct partitionDesc *p;
906 int i;
907
908 p = (struct partitionDesc *)bh->b_data;
909
Cyrill Gorcunovcb00ea32007-07-19 01:47:43 -0700910 for (i = 0; i < UDF_SB_NUMPARTS(sb); i++) {
911 udf_debug("Searching map: (%d == %d)\n",
Cyrill Gorcunov28de7942007-07-21 04:37:18 -0700912 UDF_SB_PARTMAPS(sb)[i].s_partition_num, le16_to_cpu(p->partitionNumber));
913 if (UDF_SB_PARTMAPS(sb)[i].s_partition_num == le16_to_cpu(p->partitionNumber)) {
Marcin Slusarz3a71fc52008-02-08 04:20:28 -0800914 UDF_SB_PARTLEN(sb, i) = le32_to_cpu(p->partitionLength); /* blocks */
915 UDF_SB_PARTROOT(sb, i) = le32_to_cpu(p->partitionStartingLocation);
Cyrill Gorcunov28de7942007-07-21 04:37:18 -0700916 if (le32_to_cpu(p->accessType) == PD_ACCESS_TYPE_READ_ONLY)
Marcin Slusarz3a71fc52008-02-08 04:20:28 -0800917 UDF_SB_PARTFLAGS(sb, i) |= UDF_PART_FLAG_READ_ONLY;
Cyrill Gorcunov28de7942007-07-21 04:37:18 -0700918 if (le32_to_cpu(p->accessType) == PD_ACCESS_TYPE_WRITE_ONCE)
Marcin Slusarz3a71fc52008-02-08 04:20:28 -0800919 UDF_SB_PARTFLAGS(sb, i) |= UDF_PART_FLAG_WRITE_ONCE;
Cyrill Gorcunov28de7942007-07-21 04:37:18 -0700920 if (le32_to_cpu(p->accessType) == PD_ACCESS_TYPE_REWRITABLE)
Marcin Slusarz3a71fc52008-02-08 04:20:28 -0800921 UDF_SB_PARTFLAGS(sb, i) |= UDF_PART_FLAG_REWRITABLE;
Cyrill Gorcunov28de7942007-07-21 04:37:18 -0700922 if (le32_to_cpu(p->accessType) == PD_ACCESS_TYPE_OVERWRITABLE)
Marcin Slusarz3a71fc52008-02-08 04:20:28 -0800923 UDF_SB_PARTFLAGS(sb, i) |= UDF_PART_FLAG_OVERWRITABLE;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700924
Marcin Slusarz3a71fc52008-02-08 04:20:28 -0800925 if (!strcmp(p->partitionContents.ident,
926 PD_PARTITION_CONTENTS_NSR02) ||
927 !strcmp(p->partitionContents.ident,
928 PD_PARTITION_CONTENTS_NSR03)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700929 struct partitionHeaderDesc *phd;
930
Cyrill Gorcunov28de7942007-07-21 04:37:18 -0700931 phd = (struct partitionHeaderDesc *)(p->partitionContentsUse);
Cyrill Gorcunovcb00ea32007-07-19 01:47:43 -0700932 if (phd->unallocSpaceTable.extLength) {
Cyrill Gorcunov28de7942007-07-21 04:37:18 -0700933 kernel_lb_addr loc = {
934 .logicalBlockNum = le32_to_cpu(phd->unallocSpaceTable.extPosition),
935 .partitionReferenceNum = i,
936 };
Linus Torvalds1da177e2005-04-16 15:20:36 -0700937
Cyrill Gorcunov28de7942007-07-21 04:37:18 -0700938 UDF_SB_PARTMAPS(sb)[i].s_uspace.s_table =
939 udf_iget(sb, loc);
Jan Karabcec4472007-08-30 23:56:22 -0700940 if (!UDF_SB_PARTMAPS(sb)[i].s_uspace.s_table) {
Cyrill Gorcunovb1e7a4b12007-10-16 23:30:08 -0700941 udf_debug("cannot load unallocSpaceTable (part %d)\n", i);
Jan Karabcec4472007-08-30 23:56:22 -0700942 return 1;
943 }
Marcin Slusarz3a71fc52008-02-08 04:20:28 -0800944 UDF_SB_PARTFLAGS(sb, i) |= UDF_PART_FLAG_UNALLOC_TABLE;
Cyrill Gorcunov28de7942007-07-21 04:37:18 -0700945 udf_debug("unallocSpaceTable (part %d) @ %ld\n",
946 i, UDF_SB_PARTMAPS(sb)[i].s_uspace.s_table->i_ino);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700947 }
Cyrill Gorcunovcb00ea32007-07-19 01:47:43 -0700948 if (phd->unallocSpaceBitmap.extLength) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700949 UDF_SB_ALLOC_BITMAP(sb, i, s_uspace);
Cyrill Gorcunov28de7942007-07-21 04:37:18 -0700950 if (UDF_SB_PARTMAPS(sb)[i].s_uspace.s_bitmap != NULL) {
951 UDF_SB_PARTMAPS(sb)[i].s_uspace.s_bitmap->s_extLength =
952 le32_to_cpu(phd->unallocSpaceBitmap.extLength);
953 UDF_SB_PARTMAPS(sb)[i].s_uspace.s_bitmap->s_extPosition =
954 le32_to_cpu(phd->unallocSpaceBitmap.extPosition);
Marcin Slusarz3a71fc52008-02-08 04:20:28 -0800955 UDF_SB_PARTFLAGS(sb, i) |= UDF_PART_FLAG_UNALLOC_BITMAP;
Cyrill Gorcunov28de7942007-07-21 04:37:18 -0700956 udf_debug("unallocSpaceBitmap (part %d) @ %d\n",
957 i, UDF_SB_PARTMAPS(sb)[i].s_uspace.s_bitmap->s_extPosition);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700958 }
959 }
960 if (phd->partitionIntegrityTable.extLength)
Cyrill Gorcunov28de7942007-07-21 04:37:18 -0700961 udf_debug("partitionIntegrityTable (part %d)\n", i);
Cyrill Gorcunovcb00ea32007-07-19 01:47:43 -0700962 if (phd->freedSpaceTable.extLength) {
Cyrill Gorcunov28de7942007-07-21 04:37:18 -0700963 kernel_lb_addr loc = {
964 .logicalBlockNum = le32_to_cpu(phd->freedSpaceTable.extPosition),
965 .partitionReferenceNum = i,
966 };
Linus Torvalds1da177e2005-04-16 15:20:36 -0700967
Cyrill Gorcunov28de7942007-07-21 04:37:18 -0700968 UDF_SB_PARTMAPS(sb)[i].s_fspace.s_table =
969 udf_iget(sb, loc);
Jan Karabcec4472007-08-30 23:56:22 -0700970 if (!UDF_SB_PARTMAPS(sb)[i].s_fspace.s_table) {
Cyrill Gorcunovb1e7a4b12007-10-16 23:30:08 -0700971 udf_debug("cannot load freedSpaceTable (part %d)\n", i);
Jan Karabcec4472007-08-30 23:56:22 -0700972 return 1;
973 }
Marcin Slusarz3a71fc52008-02-08 04:20:28 -0800974 UDF_SB_PARTFLAGS(sb, i) |= UDF_PART_FLAG_FREED_TABLE;
Cyrill Gorcunov28de7942007-07-21 04:37:18 -0700975 udf_debug("freedSpaceTable (part %d) @ %ld\n",
976 i, UDF_SB_PARTMAPS(sb)[i].s_fspace.s_table->i_ino);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700977 }
Cyrill Gorcunovcb00ea32007-07-19 01:47:43 -0700978 if (phd->freedSpaceBitmap.extLength) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700979 UDF_SB_ALLOC_BITMAP(sb, i, s_fspace);
Cyrill Gorcunov28de7942007-07-21 04:37:18 -0700980 if (UDF_SB_PARTMAPS(sb)[i].s_fspace.s_bitmap != NULL) {
981 UDF_SB_PARTMAPS(sb)[i].s_fspace.s_bitmap->s_extLength =
982 le32_to_cpu(phd->freedSpaceBitmap.extLength);
983 UDF_SB_PARTMAPS(sb)[i].s_fspace.s_bitmap->s_extPosition =
984 le32_to_cpu(phd->freedSpaceBitmap.extPosition);
Marcin Slusarz3a71fc52008-02-08 04:20:28 -0800985 UDF_SB_PARTFLAGS(sb, i) |= UDF_PART_FLAG_FREED_BITMAP;
Cyrill Gorcunov28de7942007-07-21 04:37:18 -0700986 udf_debug("freedSpaceBitmap (part %d) @ %d\n",
987 i, UDF_SB_PARTMAPS(sb)[i].s_fspace.s_bitmap->s_extPosition);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700988 }
989 }
990 }
991 break;
992 }
993 }
Cyrill Gorcunovcb00ea32007-07-19 01:47:43 -0700994 if (i == UDF_SB_NUMPARTS(sb)) {
995 udf_debug("Partition (%d) not found in partition map\n",
996 le16_to_cpu(p->partitionNumber));
997 } else {
Marcin Slusarz3a71fc52008-02-08 04:20:28 -0800998 udf_debug("Partition (%d:%d type %x) starts at physical %d, "
999 "block length %d\n",
1000 le16_to_cpu(p->partitionNumber), i,
1001 UDF_SB_PARTTYPE(sb, i), UDF_SB_PARTROOT(sb, i),
1002 UDF_SB_PARTLEN(sb, i));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001003 }
Jan Karabcec4472007-08-30 23:56:22 -07001004 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001005}
1006
Cyrill Gorcunov28de7942007-07-21 04:37:18 -07001007static int udf_load_logicalvol(struct super_block *sb, struct buffer_head *bh,
1008 kernel_lb_addr *fileset)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001009{
1010 struct logicalVolDesc *lvd;
1011 int i, j, offset;
1012 uint8_t type;
1013
1014 lvd = (struct logicalVolDesc *)bh->b_data;
1015
1016 UDF_SB_ALLOC_PARTMAPS(sb, le32_to_cpu(lvd->numPartitionMaps));
1017
Cyrill Gorcunovcb00ea32007-07-19 01:47:43 -07001018 for (i = 0, offset = 0;
Cyrill Gorcunov28de7942007-07-21 04:37:18 -07001019 i < UDF_SB_NUMPARTS(sb) && offset < le32_to_cpu(lvd->mapTableLength);
1020 i++, offset += ((struct genericPartitionMap *)&(lvd->partitionMaps[offset]))->partitionMapLength) {
1021 type = ((struct genericPartitionMap *)&(lvd->partitionMaps[offset]))->partitionMapType;
Cyrill Gorcunovcb00ea32007-07-19 01:47:43 -07001022 if (type == 1) {
Cyrill Gorcunov28de7942007-07-21 04:37:18 -07001023 struct genericPartitionMap1 *gpm1 = (struct genericPartitionMap1 *)&(lvd->partitionMaps[offset]);
Marcin Slusarz3a71fc52008-02-08 04:20:28 -08001024 UDF_SB_PARTTYPE(sb, i) = UDF_TYPE1_MAP15;
1025 UDF_SB_PARTVSN(sb, i) = le16_to_cpu(gpm1->volSeqNum);
1026 UDF_SB_PARTNUM(sb, i) = le16_to_cpu(gpm1->partitionNum);
1027 UDF_SB_PARTFUNC(sb, i) = NULL;
Cyrill Gorcunovcb00ea32007-07-19 01:47:43 -07001028 } else if (type == 2) {
Cyrill Gorcunov28de7942007-07-21 04:37:18 -07001029 struct udfPartitionMap2 *upm2 = (struct udfPartitionMap2 *)&(lvd->partitionMaps[offset]);
1030 if (!strncmp(upm2->partIdent.ident, UDF_ID_VIRTUAL, strlen(UDF_ID_VIRTUAL))) {
1031 if (le16_to_cpu(((__le16 *)upm2->partIdent.identSuffix)[0]) == 0x0150) {
Marcin Slusarz3a71fc52008-02-08 04:20:28 -08001032 UDF_SB_PARTTYPE(sb, i) = UDF_VIRTUAL_MAP15;
1033 UDF_SB_PARTFUNC(sb, i) = udf_get_pblock_virt15;
Cyrill Gorcunov28de7942007-07-21 04:37:18 -07001034 } else if (le16_to_cpu(((__le16 *)upm2->partIdent.identSuffix)[0]) == 0x0200) {
Marcin Slusarz3a71fc52008-02-08 04:20:28 -08001035 UDF_SB_PARTTYPE(sb, i) = UDF_VIRTUAL_MAP20;
1036 UDF_SB_PARTFUNC(sb, i) = udf_get_pblock_virt20;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001037 }
Cyrill Gorcunov28de7942007-07-21 04:37:18 -07001038 } else if (!strncmp(upm2->partIdent.ident, UDF_ID_SPARABLE, strlen(UDF_ID_SPARABLE))) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001039 uint32_t loc;
1040 uint16_t ident;
1041 struct sparingTable *st;
Cyrill Gorcunov28de7942007-07-21 04:37:18 -07001042 struct sparablePartitionMap *spm = (struct sparablePartitionMap *)&(lvd->partitionMaps[offset]);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001043
Marcin Slusarz3a71fc52008-02-08 04:20:28 -08001044 UDF_SB_PARTTYPE(sb, i) = UDF_SPARABLE_MAP15;
1045 UDF_SB_TYPESPAR(sb, i).s_packet_len = le16_to_cpu(spm->packetLength);
Cyrill Gorcunovcb00ea32007-07-19 01:47:43 -07001046 for (j = 0; j < spm->numSparingTables; j++) {
Cyrill Gorcunov28de7942007-07-21 04:37:18 -07001047 loc = le32_to_cpu(spm->locSparingTable[j]);
Marcin Slusarz3a71fc52008-02-08 04:20:28 -08001048 UDF_SB_TYPESPAR(sb, i).s_spar_map[j] =
Cyrill Gorcunov28de7942007-07-21 04:37:18 -07001049 udf_read_tagged(sb, loc, loc, &ident);
Marcin Slusarz3a71fc52008-02-08 04:20:28 -08001050 if (UDF_SB_TYPESPAR(sb, i).s_spar_map[j] != NULL) {
1051 st = (struct sparingTable *)UDF_SB_TYPESPAR(sb, i).s_spar_map[j]->b_data;
Cyrill Gorcunov28de7942007-07-21 04:37:18 -07001052 if (ident != 0 ||
1053 strncmp(st->sparingIdent.ident, UDF_ID_SPARING, strlen(UDF_ID_SPARING))) {
Marcin Slusarz3a71fc52008-02-08 04:20:28 -08001054 brelse(UDF_SB_TYPESPAR(sb, i).s_spar_map[j]);
1055 UDF_SB_TYPESPAR(sb, i).s_spar_map[j] = NULL;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001056 }
1057 }
1058 }
Marcin Slusarz3a71fc52008-02-08 04:20:28 -08001059 UDF_SB_PARTFUNC(sb, i) = udf_get_pblock_spar15;
Cyrill Gorcunovcb00ea32007-07-19 01:47:43 -07001060 } else {
Marcin Slusarz3a71fc52008-02-08 04:20:28 -08001061 udf_debug("Unknown ident: %s\n",
1062 upm2->partIdent.ident);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001063 continue;
1064 }
Marcin Slusarz3a71fc52008-02-08 04:20:28 -08001065 UDF_SB_PARTVSN(sb, i) = le16_to_cpu(upm2->volSeqNum);
1066 UDF_SB_PARTNUM(sb, i) = le16_to_cpu(upm2->partitionNum);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001067 }
1068 udf_debug("Partition (%d:%d) type %d on volume %d\n",
Marcin Slusarz3a71fc52008-02-08 04:20:28 -08001069 i, UDF_SB_PARTNUM(sb, i), type,
1070 UDF_SB_PARTVSN(sb, i));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001071 }
1072
Cyrill Gorcunovcb00ea32007-07-19 01:47:43 -07001073 if (fileset) {
Cyrill Gorcunov28de7942007-07-21 04:37:18 -07001074 long_ad *la = (long_ad *)&(lvd->logicalVolContentsUse[0]);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001075
1076 *fileset = lelb_to_cpu(la->extLocation);
Marcin Slusarz3a71fc52008-02-08 04:20:28 -08001077 udf_debug("FileSet found in LogicalVolDesc at block=%d, "
1078 "partition=%d\n", fileset->logicalBlockNum,
Cyrill Gorcunov28de7942007-07-21 04:37:18 -07001079 fileset->partitionReferenceNum);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001080 }
1081 if (lvd->integritySeqExt.extLength)
1082 udf_load_logicalvolint(sb, leea_to_cpu(lvd->integritySeqExt));
Cyrill Gorcunov28de7942007-07-21 04:37:18 -07001083
Linus Torvalds1da177e2005-04-16 15:20:36 -07001084 return 0;
1085}
1086
1087/*
1088 * udf_load_logicalvolint
1089 *
1090 */
Cyrill Gorcunovcb00ea32007-07-19 01:47:43 -07001091static void udf_load_logicalvolint(struct super_block *sb, kernel_extent_ad loc)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001092{
1093 struct buffer_head *bh = NULL;
1094 uint16_t ident;
1095
1096 while (loc.extLength > 0 &&
Cyrill Gorcunovcb00ea32007-07-19 01:47:43 -07001097 (bh = udf_read_tagged(sb, loc.extLocation,
1098 loc.extLocation, &ident)) &&
1099 ident == TAG_IDENT_LVID) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001100 UDF_SB_LVIDBH(sb) = bh;
Cyrill Gorcunovcb00ea32007-07-19 01:47:43 -07001101
Linus Torvalds1da177e2005-04-16 15:20:36 -07001102 if (UDF_SB_LVID(sb)->nextIntegrityExt.extLength)
Marcin Slusarz3a71fc52008-02-08 04:20:28 -08001103 udf_load_logicalvolint(sb,
1104 leea_to_cpu(UDF_SB_LVID(sb)->nextIntegrityExt));
Cyrill Gorcunovcb00ea32007-07-19 01:47:43 -07001105
Linus Torvalds1da177e2005-04-16 15:20:36 -07001106 if (UDF_SB_LVIDBH(sb) != bh)
Jan Kara3bf25cb2007-05-08 00:35:16 -07001107 brelse(bh);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001108 loc.extLength -= sb->s_blocksize;
Cyrill Gorcunovcb00ea32007-07-19 01:47:43 -07001109 loc.extLocation++;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001110 }
1111 if (UDF_SB_LVIDBH(sb) != bh)
Jan Kara3bf25cb2007-05-08 00:35:16 -07001112 brelse(bh);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001113}
1114
1115/*
1116 * udf_process_sequence
1117 *
1118 * PURPOSE
1119 * Process a main/reserve volume descriptor sequence.
1120 *
1121 * PRE-CONDITIONS
1122 * sb Pointer to _locked_ superblock.
1123 * block First block of first extent of the sequence.
1124 * lastblock Lastblock of first extent of the sequence.
1125 *
1126 * HISTORY
1127 * July 1, 1997 - Andrew E. Mileski
1128 * Written, tested, and released.
1129 */
Marcin Slusarz3a71fc52008-02-08 04:20:28 -08001130static int udf_process_sequence(struct super_block *sb, long block,
1131 long lastblock, kernel_lb_addr *fileset)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001132{
1133 struct buffer_head *bh = NULL;
1134 struct udf_vds_record vds[VDS_POS_LENGTH];
1135 struct generic_desc *gd;
1136 struct volDescPtr *vdp;
Cyrill Gorcunovcb00ea32007-07-19 01:47:43 -07001137 int done = 0;
1138 int i, j;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001139 uint32_t vdsn;
1140 uint16_t ident;
1141 long next_s = 0, next_e = 0;
1142
1143 memset(vds, 0, sizeof(struct udf_vds_record) * VDS_POS_LENGTH);
1144
1145 /* Read the main descriptor sequence */
Cyrill Gorcunovcb00ea32007-07-19 01:47:43 -07001146 for (; (!done && block <= lastblock); block++) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001147
1148 bh = udf_read_tagged(sb, block, block, &ident);
Cyrill Gorcunovcb00ea32007-07-19 01:47:43 -07001149 if (!bh)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001150 break;
1151
1152 /* Process each descriptor (ISO 13346 3/8.3-8.4) */
1153 gd = (struct generic_desc *)bh->b_data;
1154 vdsn = le32_to_cpu(gd->volDescSeqNum);
Cyrill Gorcunovcb00ea32007-07-19 01:47:43 -07001155 switch (ident) {
Cyrill Gorcunov28de7942007-07-21 04:37:18 -07001156 case TAG_IDENT_PVD: /* ISO 13346 3/10.1 */
Cyrill Gorcunovcb00ea32007-07-19 01:47:43 -07001157 if (vdsn >= vds[VDS_POS_PRIMARY_VOL_DESC].volDescSeqNum) {
Cyrill Gorcunov28de7942007-07-21 04:37:18 -07001158 vds[VDS_POS_PRIMARY_VOL_DESC].volDescSeqNum = vdsn;
Cyrill Gorcunovcb00ea32007-07-19 01:47:43 -07001159 vds[VDS_POS_PRIMARY_VOL_DESC].block = block;
1160 }
1161 break;
Cyrill Gorcunov28de7942007-07-21 04:37:18 -07001162 case TAG_IDENT_VDP: /* ISO 13346 3/10.3 */
Cyrill Gorcunovcb00ea32007-07-19 01:47:43 -07001163 if (vdsn >= vds[VDS_POS_VOL_DESC_PTR].volDescSeqNum) {
1164 vds[VDS_POS_VOL_DESC_PTR].volDescSeqNum = vdsn;
1165 vds[VDS_POS_VOL_DESC_PTR].block = block;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001166
Cyrill Gorcunovcb00ea32007-07-19 01:47:43 -07001167 vdp = (struct volDescPtr *)bh->b_data;
Cyrill Gorcunov28de7942007-07-21 04:37:18 -07001168 next_s = le32_to_cpu(vdp->nextVolDescSeqExt.extLocation);
1169 next_e = le32_to_cpu(vdp->nextVolDescSeqExt.extLength);
Cyrill Gorcunovcb00ea32007-07-19 01:47:43 -07001170 next_e = next_e >> sb->s_blocksize_bits;
1171 next_e += next_s;
1172 }
1173 break;
Cyrill Gorcunov28de7942007-07-21 04:37:18 -07001174 case TAG_IDENT_IUVD: /* ISO 13346 3/10.4 */
Cyrill Gorcunovcb00ea32007-07-19 01:47:43 -07001175 if (vdsn >= vds[VDS_POS_IMP_USE_VOL_DESC].volDescSeqNum) {
Cyrill Gorcunov28de7942007-07-21 04:37:18 -07001176 vds[VDS_POS_IMP_USE_VOL_DESC].volDescSeqNum = vdsn;
Cyrill Gorcunovcb00ea32007-07-19 01:47:43 -07001177 vds[VDS_POS_IMP_USE_VOL_DESC].block = block;
1178 }
1179 break;
Cyrill Gorcunov28de7942007-07-21 04:37:18 -07001180 case TAG_IDENT_PD: /* ISO 13346 3/10.5 */
Cyrill Gorcunovcb00ea32007-07-19 01:47:43 -07001181 if (!vds[VDS_POS_PARTITION_DESC].block)
1182 vds[VDS_POS_PARTITION_DESC].block = block;
1183 break;
Cyrill Gorcunov28de7942007-07-21 04:37:18 -07001184 case TAG_IDENT_LVD: /* ISO 13346 3/10.6 */
Cyrill Gorcunovcb00ea32007-07-19 01:47:43 -07001185 if (vdsn >= vds[VDS_POS_LOGICAL_VOL_DESC].volDescSeqNum) {
Cyrill Gorcunov28de7942007-07-21 04:37:18 -07001186 vds[VDS_POS_LOGICAL_VOL_DESC].volDescSeqNum = vdsn;
Cyrill Gorcunovcb00ea32007-07-19 01:47:43 -07001187 vds[VDS_POS_LOGICAL_VOL_DESC].block = block;
1188 }
1189 break;
Cyrill Gorcunov28de7942007-07-21 04:37:18 -07001190 case TAG_IDENT_USD: /* ISO 13346 3/10.8 */
1191 if (vdsn >= vds[VDS_POS_UNALLOC_SPACE_DESC].volDescSeqNum) {
1192 vds[VDS_POS_UNALLOC_SPACE_DESC].volDescSeqNum = vdsn;
Cyrill Gorcunovcb00ea32007-07-19 01:47:43 -07001193 vds[VDS_POS_UNALLOC_SPACE_DESC].block = block;
1194 }
1195 break;
Cyrill Gorcunov28de7942007-07-21 04:37:18 -07001196 case TAG_IDENT_TD: /* ISO 13346 3/10.9 */
Cyrill Gorcunovcb00ea32007-07-19 01:47:43 -07001197 vds[VDS_POS_TERMINATING_DESC].block = block;
1198 if (next_e) {
1199 block = next_s;
1200 lastblock = next_e;
1201 next_s = next_e = 0;
Cyrill Gorcunov28de7942007-07-21 04:37:18 -07001202 } else {
Cyrill Gorcunovcb00ea32007-07-19 01:47:43 -07001203 done = 1;
Cyrill Gorcunov28de7942007-07-21 04:37:18 -07001204 }
Cyrill Gorcunovcb00ea32007-07-19 01:47:43 -07001205 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001206 }
Jan Kara3bf25cb2007-05-08 00:35:16 -07001207 brelse(bh);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001208 }
Cyrill Gorcunovcb00ea32007-07-19 01:47:43 -07001209 for (i = 0; i < VDS_POS_LENGTH; i++) {
1210 if (vds[i].block) {
Marcin Slusarz3a71fc52008-02-08 04:20:28 -08001211 bh = udf_read_tagged(sb, vds[i].block, vds[i].block,
1212 &ident);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001213
Cyrill Gorcunov28de7942007-07-21 04:37:18 -07001214 if (i == VDS_POS_PRIMARY_VOL_DESC) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001215 udf_load_pvoldesc(sb, bh);
Cyrill Gorcunov28de7942007-07-21 04:37:18 -07001216 } else if (i == VDS_POS_LOGICAL_VOL_DESC) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001217 udf_load_logicalvol(sb, bh, fileset);
Cyrill Gorcunov28de7942007-07-21 04:37:18 -07001218 } else if (i == VDS_POS_PARTITION_DESC) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001219 struct buffer_head *bh2 = NULL;
Jan Karabcec4472007-08-30 23:56:22 -07001220 if (udf_load_partdesc(sb, bh)) {
1221 brelse(bh);
1222 return 1;
1223 }
Marcin Slusarz3a71fc52008-02-08 04:20:28 -08001224 for (j = vds[i].block + 1;
1225 j < vds[VDS_POS_TERMINATING_DESC].block;
1226 j++) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001227 bh2 = udf_read_tagged(sb, j, j, &ident);
1228 gd = (struct generic_desc *)bh2->b_data;
1229 if (ident == TAG_IDENT_PD)
Marcin Slusarz3a71fc52008-02-08 04:20:28 -08001230 if (udf_load_partdesc(sb,
1231 bh2)) {
Jan Karabcec4472007-08-30 23:56:22 -07001232 brelse(bh);
1233 brelse(bh2);
1234 return 1;
1235 }
Jan Kara3bf25cb2007-05-08 00:35:16 -07001236 brelse(bh2);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001237 }
1238 }
Jan Kara3bf25cb2007-05-08 00:35:16 -07001239 brelse(bh);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001240 }
1241 }
1242
1243 return 0;
1244}
1245
1246/*
1247 * udf_check_valid()
1248 */
Cyrill Gorcunovcb00ea32007-07-19 01:47:43 -07001249static int udf_check_valid(struct super_block *sb, int novrs, int silent)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001250{
1251 long block;
1252
Cyrill Gorcunovcb00ea32007-07-19 01:47:43 -07001253 if (novrs) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001254 udf_debug("Validity check skipped because of novrs option\n");
1255 return 0;
1256 }
1257 /* Check that it is NSR02 compliant */
1258 /* Process any "CD-ROM Volume Descriptor Set" (ECMA 167 2/8.3.1) */
Marcin Slusarz3a71fc52008-02-08 04:20:28 -08001259 else {
1260 block = udf_vrs(sb, silent);
1261 if (block == -1) {
1262 udf_debug("Failed to read byte 32768. Assuming open "
1263 "disc. Skipping validity check\n");
1264 if (!UDF_SB_LASTBLOCK(sb))
1265 UDF_SB_LASTBLOCK(sb) = udf_get_last_block(sb);
1266 return 0;
1267 } else
1268 return !block;
Cyrill Gorcunov28de7942007-07-21 04:37:18 -07001269 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001270}
1271
Cyrill Gorcunov28de7942007-07-21 04:37:18 -07001272static int udf_load_partition(struct super_block *sb, kernel_lb_addr *fileset)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001273{
1274 struct anchorVolDescPtr *anchor;
1275 uint16_t ident;
1276 struct buffer_head *bh;
1277 long main_s, main_e, reserve_s, reserve_e;
1278 int i, j;
1279
1280 if (!sb)
1281 return 1;
1282
Tobias Klausere8c96f82006-03-24 03:15:34 -08001283 for (i = 0; i < ARRAY_SIZE(UDF_SB_ANCHOR(sb)); i++) {
Cyrill Gorcunov28de7942007-07-21 04:37:18 -07001284 if (UDF_SB_ANCHOR(sb)[i] &&
1285 (bh = udf_read_tagged(sb, UDF_SB_ANCHOR(sb)[i],
1286 UDF_SB_ANCHOR(sb)[i], &ident))) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001287 anchor = (struct anchorVolDescPtr *)bh->b_data;
1288
1289 /* Locate the main sequence */
Cyrill Gorcunov28de7942007-07-21 04:37:18 -07001290 main_s = le32_to_cpu(anchor->mainVolDescSeqExt.extLocation);
Marcin Slusarz3a71fc52008-02-08 04:20:28 -08001291 main_e = le32_to_cpu(anchor->mainVolDescSeqExt.extLength);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001292 main_e = main_e >> sb->s_blocksize_bits;
1293 main_e += main_s;
Tobias Klausere8c96f82006-03-24 03:15:34 -08001294
Linus Torvalds1da177e2005-04-16 15:20:36 -07001295 /* Locate the reserve sequence */
Cyrill Gorcunov28de7942007-07-21 04:37:18 -07001296 reserve_s = le32_to_cpu(anchor->reserveVolDescSeqExt.extLocation);
1297 reserve_e = le32_to_cpu(anchor->reserveVolDescSeqExt.extLength);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001298 reserve_e = reserve_e >> sb->s_blocksize_bits;
1299 reserve_e += reserve_s;
1300
Jan Kara3bf25cb2007-05-08 00:35:16 -07001301 brelse(bh);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001302
1303 /* Process the main & reserve sequences */
1304 /* responsible for finding the PartitionDesc(s) */
Cyrill Gorcunov28de7942007-07-21 04:37:18 -07001305 if (!(udf_process_sequence(sb, main_s, main_e, fileset) &&
Marcin Slusarz3a71fc52008-02-08 04:20:28 -08001306 udf_process_sequence(sb, reserve_s, reserve_e, fileset)))
Linus Torvalds1da177e2005-04-16 15:20:36 -07001307 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001308 }
1309 }
1310
Tobias Klausere8c96f82006-03-24 03:15:34 -08001311 if (i == ARRAY_SIZE(UDF_SB_ANCHOR(sb))) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001312 udf_debug("No Anchor block found\n");
1313 return 1;
Tobias Klausere8c96f82006-03-24 03:15:34 -08001314 } else
Linus Torvalds1da177e2005-04-16 15:20:36 -07001315 udf_debug("Using anchor in block %d\n", UDF_SB_ANCHOR(sb)[i]);
1316
Cyrill Gorcunovcb00ea32007-07-19 01:47:43 -07001317 for (i = 0; i < UDF_SB_NUMPARTS(sb); i++) {
Cyrill Gorcunov28de7942007-07-21 04:37:18 -07001318 kernel_lb_addr uninitialized_var(ino);
Cyrill Gorcunovcb00ea32007-07-19 01:47:43 -07001319 switch (UDF_SB_PARTTYPE(sb, i)) {
1320 case UDF_VIRTUAL_MAP15:
1321 case UDF_VIRTUAL_MAP20:
Cyrill Gorcunov28de7942007-07-21 04:37:18 -07001322 if (!UDF_SB_LASTBLOCK(sb)) {
1323 UDF_SB_LASTBLOCK(sb) = udf_get_last_block(sb);
1324 udf_find_anchor(sb);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001325 }
Cyrill Gorcunov28de7942007-07-21 04:37:18 -07001326
1327 if (!UDF_SB_LASTBLOCK(sb)) {
1328 udf_debug("Unable to determine Lastblock (For "
Cyrill Gorcunovb1e7a4b12007-10-16 23:30:08 -07001329 "Virtual Partition)\n");
Cyrill Gorcunov28de7942007-07-21 04:37:18 -07001330 return 1;
1331 }
1332
1333 for (j = 0; j < UDF_SB_NUMPARTS(sb); j++) {
Cyrill Gorcunovb1e7a4b12007-10-16 23:30:08 -07001334 if (j != i &&
1335 UDF_SB_PARTVSN(sb, i) == UDF_SB_PARTVSN(sb, j) &&
1336 UDF_SB_PARTNUM(sb, i) == UDF_SB_PARTNUM(sb, j)) {
Cyrill Gorcunov28de7942007-07-21 04:37:18 -07001337 ino.partitionReferenceNum = j;
Cyrill Gorcunovb1e7a4b12007-10-16 23:30:08 -07001338 ino.logicalBlockNum = UDF_SB_LASTBLOCK(sb) - UDF_SB_PARTROOT(sb, j);
Cyrill Gorcunov28de7942007-07-21 04:37:18 -07001339 break;
1340 }
1341 }
1342
1343 if (j == UDF_SB_NUMPARTS(sb))
1344 return 1;
1345
Marcin Slusarz3a71fc52008-02-08 04:20:28 -08001346 UDF_SB_VAT(sb) = udf_iget(sb, ino);
1347 if (!UDF_SB_VAT(sb))
Cyrill Gorcunov28de7942007-07-21 04:37:18 -07001348 return 1;
1349
1350 if (UDF_SB_PARTTYPE(sb, i) == UDF_VIRTUAL_MAP15) {
1351 UDF_SB_TYPEVIRT(sb, i).s_start_offset =
Cyrill Gorcunovb1e7a4b12007-10-16 23:30:08 -07001352 udf_ext0_offset(UDF_SB_VAT(sb));
Cyrill Gorcunov28de7942007-07-21 04:37:18 -07001353 UDF_SB_TYPEVIRT(sb, i).s_num_entries =
Cyrill Gorcunovb1e7a4b12007-10-16 23:30:08 -07001354 (UDF_SB_VAT(sb)->i_size - 36) >> 2;
Cyrill Gorcunov28de7942007-07-21 04:37:18 -07001355 } else if (UDF_SB_PARTTYPE(sb, i) == UDF_VIRTUAL_MAP20) {
1356 struct buffer_head *bh = NULL;
1357 uint32_t pos;
1358
1359 pos = udf_block_map(UDF_SB_VAT(sb), 0);
1360 bh = sb_bread(sb, pos);
1361 if (!bh)
1362 return 1;
1363 UDF_SB_TYPEVIRT(sb, i).s_start_offset =
Cyrill Gorcunovb1e7a4b12007-10-16 23:30:08 -07001364 le16_to_cpu(((struct virtualAllocationTable20 *)bh->b_data +
1365 udf_ext0_offset(UDF_SB_VAT(sb)))->lengthHeader) +
1366 udf_ext0_offset(UDF_SB_VAT(sb));
1367 UDF_SB_TYPEVIRT(sb, i).s_num_entries = (UDF_SB_VAT(sb)->i_size -
1368 UDF_SB_TYPEVIRT(sb, i).s_start_offset) >> 2;
Cyrill Gorcunov28de7942007-07-21 04:37:18 -07001369 brelse(bh);
1370 }
1371 UDF_SB_PARTROOT(sb, i) = udf_get_pblock(sb, 0, i, 0);
Cyrill Gorcunovb1e7a4b12007-10-16 23:30:08 -07001372 UDF_SB_PARTLEN(sb, i) = UDF_SB_PARTLEN(sb, ino.partitionReferenceNum);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001373 }
1374 }
1375 return 0;
1376}
1377
1378static void udf_open_lvid(struct super_block *sb)
1379{
Cyrill Gorcunovcb00ea32007-07-19 01:47:43 -07001380 if (UDF_SB_LVIDBH(sb)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001381 int i;
1382 kernel_timestamp cpu_time;
1383
1384 UDF_SB_LVIDIU(sb)->impIdent.identSuffix[0] = UDF_OS_CLASS_UNIX;
1385 UDF_SB_LVIDIU(sb)->impIdent.identSuffix[1] = UDF_OS_ID_LINUX;
1386 if (udf_time_to_stamp(&cpu_time, CURRENT_TIME))
Cyrill Gorcunovb1e7a4b12007-10-16 23:30:08 -07001387 UDF_SB_LVID(sb)->recordingDateAndTime = cpu_to_lets(cpu_time);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001388 UDF_SB_LVID(sb)->integrityType = LVID_INTEGRITY_TYPE_OPEN;
1389
Cyrill Gorcunovb1e7a4b12007-10-16 23:30:08 -07001390 UDF_SB_LVID(sb)->descTag.descCRC = cpu_to_le16(udf_crc((char *)UDF_SB_LVID(sb) + sizeof(tag),
1391 le16_to_cpu(UDF_SB_LVID(sb)->descTag.descCRCLength), 0));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001392
1393 UDF_SB_LVID(sb)->descTag.tagChecksum = 0;
Cyrill Gorcunovcb00ea32007-07-19 01:47:43 -07001394 for (i = 0; i < 16; i++)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001395 if (i != 4)
1396 UDF_SB_LVID(sb)->descTag.tagChecksum +=
Cyrill Gorcunovb1e7a4b12007-10-16 23:30:08 -07001397 ((uint8_t *) &(UDF_SB_LVID(sb)->descTag))[i];
Linus Torvalds1da177e2005-04-16 15:20:36 -07001398
1399 mark_buffer_dirty(UDF_SB_LVIDBH(sb));
1400 }
1401}
1402
1403static void udf_close_lvid(struct super_block *sb)
1404{
Cyrill Gorcunov28de7942007-07-21 04:37:18 -07001405 kernel_timestamp cpu_time;
1406 int i;
1407
Linus Torvalds1da177e2005-04-16 15:20:36 -07001408 if (UDF_SB_LVIDBH(sb) &&
Cyrill Gorcunovcb00ea32007-07-19 01:47:43 -07001409 UDF_SB_LVID(sb)->integrityType == LVID_INTEGRITY_TYPE_OPEN) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001410 UDF_SB_LVIDIU(sb)->impIdent.identSuffix[0] = UDF_OS_CLASS_UNIX;
1411 UDF_SB_LVIDIU(sb)->impIdent.identSuffix[1] = UDF_OS_ID_LINUX;
1412 if (udf_time_to_stamp(&cpu_time, CURRENT_TIME))
Cyrill Gorcunov28de7942007-07-21 04:37:18 -07001413 UDF_SB_LVID(sb)->recordingDateAndTime = cpu_to_lets(cpu_time);
1414 if (UDF_MAX_WRITE_VERSION > le16_to_cpu(UDF_SB_LVIDIU(sb)->maxUDFWriteRev))
1415 UDF_SB_LVIDIU(sb)->maxUDFWriteRev = cpu_to_le16(UDF_MAX_WRITE_VERSION);
1416 if (UDF_SB_UDFREV(sb) > le16_to_cpu(UDF_SB_LVIDIU(sb)->minUDFReadRev))
1417 UDF_SB_LVIDIU(sb)->minUDFReadRev = cpu_to_le16(UDF_SB_UDFREV(sb));
1418 if (UDF_SB_UDFREV(sb) > le16_to_cpu(UDF_SB_LVIDIU(sb)->minUDFWriteRev))
1419 UDF_SB_LVIDIU(sb)->minUDFWriteRev = cpu_to_le16(UDF_SB_UDFREV(sb));
1420 UDF_SB_LVID(sb)->integrityType = cpu_to_le32(LVID_INTEGRITY_TYPE_CLOSE);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001421
1422 UDF_SB_LVID(sb)->descTag.descCRC =
Cyrill Gorcunov28de7942007-07-21 04:37:18 -07001423 cpu_to_le16(udf_crc((char *)UDF_SB_LVID(sb) + sizeof(tag),
1424 le16_to_cpu(UDF_SB_LVID(sb)->descTag.descCRCLength), 0));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001425
1426 UDF_SB_LVID(sb)->descTag.tagChecksum = 0;
Cyrill Gorcunovcb00ea32007-07-19 01:47:43 -07001427 for (i = 0; i < 16; i++)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001428 if (i != 4)
1429 UDF_SB_LVID(sb)->descTag.tagChecksum +=
Cyrill Gorcunov28de7942007-07-21 04:37:18 -07001430 ((uint8_t *)&(UDF_SB_LVID(sb)->descTag))[i];
Linus Torvalds1da177e2005-04-16 15:20:36 -07001431
1432 mark_buffer_dirty(UDF_SB_LVIDBH(sb));
1433 }
1434}
1435
1436/*
1437 * udf_read_super
1438 *
1439 * PURPOSE
1440 * Complete the specified super block.
1441 *
1442 * PRE-CONDITIONS
1443 * sb Pointer to superblock to complete - never NULL.
1444 * sb->s_dev Device to read suberblock from.
1445 * options Pointer to mount options.
1446 * silent Silent flag.
1447 *
1448 * HISTORY
1449 * July 1, 1997 - Andrew E. Mileski
1450 * Written, tested, and released.
1451 */
1452static int udf_fill_super(struct super_block *sb, void *options, int silent)
1453{
1454 int i;
Cyrill Gorcunovcb00ea32007-07-19 01:47:43 -07001455 struct inode *inode = NULL;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001456 struct udf_options uopt;
1457 kernel_lb_addr rootdir, fileset;
1458 struct udf_sb_info *sbi;
1459
1460 uopt.flags = (1 << UDF_FLAG_USE_AD_IN_ICB) | (1 << UDF_FLAG_STRICT);
1461 uopt.uid = -1;
1462 uopt.gid = -1;
1463 uopt.umask = 0;
1464
1465 sbi = kmalloc(sizeof(struct udf_sb_info), GFP_KERNEL);
1466 if (!sbi)
1467 return -ENOMEM;
Cyrill Gorcunov28de7942007-07-21 04:37:18 -07001468
Linus Torvalds1da177e2005-04-16 15:20:36 -07001469 sb->s_fs_info = sbi;
1470 memset(UDF_SB(sb), 0x00, sizeof(struct udf_sb_info));
1471
Ingo Molnar1e7933d2006-03-23 03:00:44 -08001472 mutex_init(&sbi->s_alloc_mutex);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001473
1474 if (!udf_parse_options((char *)options, &uopt))
1475 goto error_out;
1476
1477 if (uopt.flags & (1 << UDF_FLAG_UTF8) &&
Cyrill Gorcunovcb00ea32007-07-19 01:47:43 -07001478 uopt.flags & (1 << UDF_FLAG_NLS_MAP)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001479 udf_error(sb, "udf_read_super",
Cyrill Gorcunovcb00ea32007-07-19 01:47:43 -07001480 "utf8 cannot be combined with iocharset\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07001481 goto error_out;
1482 }
1483#ifdef CONFIG_UDF_NLS
Cyrill Gorcunovcb00ea32007-07-19 01:47:43 -07001484 if ((uopt.flags & (1 << UDF_FLAG_NLS_MAP)) && !uopt.nls_map) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001485 uopt.nls_map = load_nls_default();
1486 if (!uopt.nls_map)
1487 uopt.flags &= ~(1 << UDF_FLAG_NLS_MAP);
1488 else
1489 udf_debug("Using default NLS map\n");
1490 }
1491#endif
1492 if (!(uopt.flags & (1 << UDF_FLAG_NLS_MAP)))
1493 uopt.flags |= (1 << UDF_FLAG_UTF8);
1494
1495 fileset.logicalBlockNum = 0xFFFFFFFF;
1496 fileset.partitionReferenceNum = 0xFFFF;
1497
1498 UDF_SB(sb)->s_flags = uopt.flags;
1499 UDF_SB(sb)->s_uid = uopt.uid;
1500 UDF_SB(sb)->s_gid = uopt.gid;
1501 UDF_SB(sb)->s_umask = uopt.umask;
1502 UDF_SB(sb)->s_nls_map = uopt.nls_map;
1503
1504 /* Set the block size for all transfers */
1505 if (!udf_set_blocksize(sb, uopt.blocksize))
1506 goto error_out;
1507
Cyrill Gorcunovcb00ea32007-07-19 01:47:43 -07001508 if (uopt.session == 0xFFFFFFFF)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001509 UDF_SB_SESSION(sb) = udf_get_last_session(sb);
1510 else
1511 UDF_SB_SESSION(sb) = uopt.session;
1512
1513 udf_debug("Multi-session=%d\n", UDF_SB_SESSION(sb));
1514
1515 UDF_SB_LASTBLOCK(sb) = uopt.lastblock;
1516 UDF_SB_ANCHOR(sb)[0] = UDF_SB_ANCHOR(sb)[1] = 0;
1517 UDF_SB_ANCHOR(sb)[2] = uopt.anchor;
1518 UDF_SB_ANCHOR(sb)[3] = 256;
1519
Marcin Slusarz3a71fc52008-02-08 04:20:28 -08001520 if (udf_check_valid(sb, uopt.novrs, silent)) {
1521 /* read volume recognition sequences */
1522 printk(KERN_WARNING "UDF-fs: No VRS found\n");
Cyrill Gorcunovcb00ea32007-07-19 01:47:43 -07001523 goto error_out;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001524 }
1525
1526 udf_find_anchor(sb);
1527
1528 /* Fill in the rest of the superblock */
1529 sb->s_op = &udf_sb_ops;
1530 sb->dq_op = NULL;
1531 sb->s_dirt = 0;
1532 sb->s_magic = UDF_SUPER_MAGIC;
1533 sb->s_time_gran = 1000;
1534
Cyrill Gorcunovcb00ea32007-07-19 01:47:43 -07001535 if (udf_load_partition(sb, &fileset)) {
Marcin Slusarz3a71fc52008-02-08 04:20:28 -08001536 printk(KERN_WARNING "UDF-fs: No partition found (1)\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07001537 goto error_out;
1538 }
1539
1540 udf_debug("Lastblock=%d\n", UDF_SB_LASTBLOCK(sb));
1541
Cyrill Gorcunovcb00ea32007-07-19 01:47:43 -07001542 if (UDF_SB_LVIDBH(sb)) {
Cyrill Gorcunov28de7942007-07-21 04:37:18 -07001543 uint16_t minUDFReadRev = le16_to_cpu(UDF_SB_LVIDIU(sb)->minUDFReadRev);
1544 uint16_t minUDFWriteRev = le16_to_cpu(UDF_SB_LVIDIU(sb)->minUDFWriteRev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001545 /* uint16_t maxUDFWriteRev = le16_to_cpu(UDF_SB_LVIDIU(sb)->maxUDFWriteRev); */
1546
Cyrill Gorcunovcb00ea32007-07-19 01:47:43 -07001547 if (minUDFReadRev > UDF_MAX_READ_VERSION) {
Marcin Slusarz3a71fc52008-02-08 04:20:28 -08001548 printk(KERN_ERR "UDF-fs: minUDFReadRev=%x (max is %x)\n",
Cyrill Gorcunovcb00ea32007-07-19 01:47:43 -07001549 le16_to_cpu(UDF_SB_LVIDIU(sb)->minUDFReadRev),
1550 UDF_MAX_READ_VERSION);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001551 goto error_out;
Cyrill Gorcunovcb00ea32007-07-19 01:47:43 -07001552 } else if (minUDFWriteRev > UDF_MAX_WRITE_VERSION) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001553 sb->s_flags |= MS_RDONLY;
1554 }
1555
1556 UDF_SB_UDFREV(sb) = minUDFWriteRev;
1557
1558 if (minUDFReadRev >= UDF_VERS_USE_EXTENDED_FE)
1559 UDF_SET_FLAG(sb, UDF_FLAG_USE_EXTENDED_FE);
1560 if (minUDFReadRev >= UDF_VERS_USE_STREAMS)
1561 UDF_SET_FLAG(sb, UDF_FLAG_USE_STREAMS);
1562 }
1563
Cyrill Gorcunovcb00ea32007-07-19 01:47:43 -07001564 if (!UDF_SB_NUMPARTS(sb)) {
Marcin Slusarz3a71fc52008-02-08 04:20:28 -08001565 printk(KERN_WARNING "UDF-fs: No partition found (2)\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07001566 goto error_out;
1567 }
1568
Cyrill Gorcunov28de7942007-07-21 04:37:18 -07001569 if (UDF_SB_PARTFLAGS(sb, UDF_SB_PARTITION(sb)) & UDF_PART_FLAG_READ_ONLY) {
Marcin Slusarz3a71fc52008-02-08 04:20:28 -08001570 printk(KERN_NOTICE "UDF-fs: Partition marked readonly; forcing readonly mount\n");
Eric Sandeen39b3f6d2006-09-29 01:59:41 -07001571 sb->s_flags |= MS_RDONLY;
Peter Osterlundc1a26e72006-10-05 21:17:50 +02001572 }
Eric Sandeen39b3f6d2006-09-29 01:59:41 -07001573
Cyrill Gorcunovcb00ea32007-07-19 01:47:43 -07001574 if (udf_find_fileset(sb, &fileset, &rootdir)) {
Marcin Slusarz3a71fc52008-02-08 04:20:28 -08001575 printk(KERN_WARNING "UDF-fs: No fileset found\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07001576 goto error_out;
1577 }
1578
Cyrill Gorcunovcb00ea32007-07-19 01:47:43 -07001579 if (!silent) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001580 kernel_timestamp ts;
1581 udf_time_to_stamp(&ts, UDF_SB_RECORDTIME(sb));
Cyrill Gorcunov28de7942007-07-21 04:37:18 -07001582 udf_info("UDF %s (%s) Mounting volume '%s', "
1583 "timestamp %04u/%02u/%02u %02u:%02u (%x)\n",
1584 UDFFS_VERSION, UDFFS_DATE,
1585 UDF_SB_VOLIDENT(sb), ts.year, ts.month, ts.day, ts.hour, ts.minute,
1586 ts.typeAndTimezone);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001587 }
1588 if (!(sb->s_flags & MS_RDONLY))
1589 udf_open_lvid(sb);
1590
1591 /* Assign the root inode */
1592 /* assign inodes by physical block number */
1593 /* perhaps it's not extensible enough, but for now ... */
Cyrill Gorcunovcb00ea32007-07-19 01:47:43 -07001594 inode = udf_iget(sb, rootdir);
1595 if (!inode) {
Marcin Slusarz3a71fc52008-02-08 04:20:28 -08001596 printk(KERN_ERR "UDF-fs: Error in udf_iget, block=%d, partition=%d\n",
Cyrill Gorcunovcb00ea32007-07-19 01:47:43 -07001597 rootdir.logicalBlockNum, rootdir.partitionReferenceNum);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001598 goto error_out;
1599 }
1600
1601 /* Allocate a dentry for the root inode */
1602 sb->s_root = d_alloc_root(inode);
Cyrill Gorcunovcb00ea32007-07-19 01:47:43 -07001603 if (!sb->s_root) {
Marcin Slusarz3a71fc52008-02-08 04:20:28 -08001604 printk(KERN_ERR "UDF-fs: Couldn't allocate root dentry\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07001605 iput(inode);
1606 goto error_out;
1607 }
Jan Kara31170b62007-05-08 00:35:21 -07001608 sb->s_maxbytes = MAX_LFS_FILESIZE;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001609 return 0;
1610
Cyrill Gorcunov28de7942007-07-21 04:37:18 -07001611error_out:
Linus Torvalds1da177e2005-04-16 15:20:36 -07001612 if (UDF_SB_VAT(sb))
1613 iput(UDF_SB_VAT(sb));
Cyrill Gorcunovcb00ea32007-07-19 01:47:43 -07001614 if (UDF_SB_NUMPARTS(sb)) {
Cyrill Gorcunov28de7942007-07-21 04:37:18 -07001615 if (UDF_SB_PARTFLAGS(sb, UDF_SB_PARTITION(sb)) & UDF_PART_FLAG_UNALLOC_TABLE)
1616 iput(UDF_SB_PARTMAPS(sb)[UDF_SB_PARTITION(sb)].s_uspace.s_table);
1617 if (UDF_SB_PARTFLAGS(sb, UDF_SB_PARTITION(sb)) & UDF_PART_FLAG_FREED_TABLE)
1618 iput(UDF_SB_PARTMAPS(sb)[UDF_SB_PARTITION(sb)].s_fspace.s_table);
1619 if (UDF_SB_PARTFLAGS(sb, UDF_SB_PARTITION(sb)) & UDF_PART_FLAG_UNALLOC_BITMAP)
Marcin Slusarz3a71fc52008-02-08 04:20:28 -08001620 UDF_SB_FREE_BITMAP(sb, UDF_SB_PARTITION(sb), s_uspace);
Cyrill Gorcunov28de7942007-07-21 04:37:18 -07001621 if (UDF_SB_PARTFLAGS(sb, UDF_SB_PARTITION(sb)) & UDF_PART_FLAG_FREED_BITMAP)
Marcin Slusarz3a71fc52008-02-08 04:20:28 -08001622 UDF_SB_FREE_BITMAP(sb, UDF_SB_PARTITION(sb), s_fspace);
Cyrill Gorcunov28de7942007-07-21 04:37:18 -07001623 if (UDF_SB_PARTTYPE(sb, UDF_SB_PARTITION(sb)) == UDF_SPARABLE_MAP15) {
Cyrill Gorcunovcb00ea32007-07-19 01:47:43 -07001624 for (i = 0; i < 4; i++)
Cyrill Gorcunov28de7942007-07-21 04:37:18 -07001625 brelse(UDF_SB_TYPESPAR(sb, UDF_SB_PARTITION(sb)).s_spar_map[i]);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001626 }
1627 }
1628#ifdef CONFIG_UDF_NLS
1629 if (UDF_QUERY_FLAG(sb, UDF_FLAG_NLS_MAP))
1630 unload_nls(UDF_SB(sb)->s_nls_map);
1631#endif
1632 if (!(sb->s_flags & MS_RDONLY))
1633 udf_close_lvid(sb);
Jan Kara3bf25cb2007-05-08 00:35:16 -07001634 brelse(UDF_SB_LVIDBH(sb));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001635 UDF_SB_FREE(sb);
1636 kfree(sbi);
1637 sb->s_fs_info = NULL;
Cyrill Gorcunov28de7942007-07-21 04:37:18 -07001638
Linus Torvalds1da177e2005-04-16 15:20:36 -07001639 return -EINVAL;
1640}
1641
1642void udf_error(struct super_block *sb, const char *function,
Cyrill Gorcunovcb00ea32007-07-19 01:47:43 -07001643 const char *fmt, ...)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001644{
1645 va_list args;
1646
Cyrill Gorcunovcb00ea32007-07-19 01:47:43 -07001647 if (!(sb->s_flags & MS_RDONLY)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001648 /* mark sb error */
1649 sb->s_dirt = 1;
1650 }
1651 va_start(args, fmt);
Alexey Dobriyan4a6e6172006-12-06 20:37:04 -08001652 vsnprintf(error_buf, sizeof(error_buf), fmt, args);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001653 va_end(args);
Marcin Slusarz3a71fc52008-02-08 04:20:28 -08001654 printk(KERN_CRIT "UDF-fs error (device %s): %s: %s\n",
Cyrill Gorcunov28de7942007-07-21 04:37:18 -07001655 sb->s_id, function, error_buf);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001656}
1657
1658void udf_warning(struct super_block *sb, const char *function,
Cyrill Gorcunovcb00ea32007-07-19 01:47:43 -07001659 const char *fmt, ...)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001660{
1661 va_list args;
1662
Cyrill Gorcunovcb00ea32007-07-19 01:47:43 -07001663 va_start(args, fmt);
Alexey Dobriyan4a6e6172006-12-06 20:37:04 -08001664 vsnprintf(error_buf, sizeof(error_buf), fmt, args);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001665 va_end(args);
1666 printk(KERN_WARNING "UDF-fs warning (device %s): %s: %s\n",
Cyrill Gorcunovcb00ea32007-07-19 01:47:43 -07001667 sb->s_id, function, error_buf);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001668}
1669
1670/*
1671 * udf_put_super
1672 *
1673 * PURPOSE
1674 * Prepare for destruction of the superblock.
1675 *
1676 * DESCRIPTION
1677 * Called before the filesystem is unmounted.
1678 *
1679 * HISTORY
1680 * July 1, 1997 - Andrew E. Mileski
1681 * Written, tested, and released.
1682 */
Cyrill Gorcunovcb00ea32007-07-19 01:47:43 -07001683static void udf_put_super(struct super_block *sb)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001684{
1685 int i;
1686
1687 if (UDF_SB_VAT(sb))
1688 iput(UDF_SB_VAT(sb));
Cyrill Gorcunovcb00ea32007-07-19 01:47:43 -07001689 if (UDF_SB_NUMPARTS(sb)) {
Cyrill Gorcunov28de7942007-07-21 04:37:18 -07001690 if (UDF_SB_PARTFLAGS(sb, UDF_SB_PARTITION(sb)) & UDF_PART_FLAG_UNALLOC_TABLE)
1691 iput(UDF_SB_PARTMAPS(sb)[UDF_SB_PARTITION(sb)].s_uspace.s_table);
1692 if (UDF_SB_PARTFLAGS(sb, UDF_SB_PARTITION(sb)) & UDF_PART_FLAG_FREED_TABLE)
1693 iput(UDF_SB_PARTMAPS(sb)[UDF_SB_PARTITION(sb)].s_fspace.s_table);
1694 if (UDF_SB_PARTFLAGS(sb, UDF_SB_PARTITION(sb)) & UDF_PART_FLAG_UNALLOC_BITMAP)
Marcin Slusarz3a71fc52008-02-08 04:20:28 -08001695 UDF_SB_FREE_BITMAP(sb, UDF_SB_PARTITION(sb), s_uspace);
Cyrill Gorcunov28de7942007-07-21 04:37:18 -07001696 if (UDF_SB_PARTFLAGS(sb, UDF_SB_PARTITION(sb)) & UDF_PART_FLAG_FREED_BITMAP)
Marcin Slusarz3a71fc52008-02-08 04:20:28 -08001697 UDF_SB_FREE_BITMAP(sb, UDF_SB_PARTITION(sb), s_fspace);
Cyrill Gorcunov28de7942007-07-21 04:37:18 -07001698 if (UDF_SB_PARTTYPE(sb, UDF_SB_PARTITION(sb)) == UDF_SPARABLE_MAP15) {
Cyrill Gorcunovcb00ea32007-07-19 01:47:43 -07001699 for (i = 0; i < 4; i++)
Cyrill Gorcunov28de7942007-07-21 04:37:18 -07001700 brelse(UDF_SB_TYPESPAR(sb, UDF_SB_PARTITION(sb)).s_spar_map[i]);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001701 }
1702 }
1703#ifdef CONFIG_UDF_NLS
1704 if (UDF_QUERY_FLAG(sb, UDF_FLAG_NLS_MAP))
1705 unload_nls(UDF_SB(sb)->s_nls_map);
1706#endif
1707 if (!(sb->s_flags & MS_RDONLY))
1708 udf_close_lvid(sb);
Jan Kara3bf25cb2007-05-08 00:35:16 -07001709 brelse(UDF_SB_LVIDBH(sb));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001710 UDF_SB_FREE(sb);
1711 kfree(sb->s_fs_info);
1712 sb->s_fs_info = NULL;
1713}
1714
1715/*
1716 * udf_stat_fs
1717 *
1718 * PURPOSE
1719 * Return info about the filesystem.
1720 *
1721 * DESCRIPTION
1722 * Called by sys_statfs()
1723 *
1724 * HISTORY
1725 * July 1, 1997 - Andrew E. Mileski
1726 * Written, tested, and released.
1727 */
Cyrill Gorcunovcb00ea32007-07-19 01:47:43 -07001728static int udf_statfs(struct dentry *dentry, struct kstatfs *buf)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001729{
David Howells726c3342006-06-23 02:02:58 -07001730 struct super_block *sb = dentry->d_sb;
1731
Linus Torvalds1da177e2005-04-16 15:20:36 -07001732 buf->f_type = UDF_SUPER_MAGIC;
1733 buf->f_bsize = sb->s_blocksize;
1734 buf->f_blocks = UDF_SB_PARTLEN(sb, UDF_SB_PARTITION(sb));
1735 buf->f_bfree = udf_count_free(sb);
1736 buf->f_bavail = buf->f_bfree;
1737 buf->f_files = (UDF_SB_LVIDBH(sb) ?
Cyrill Gorcunovcb00ea32007-07-19 01:47:43 -07001738 (le32_to_cpu(UDF_SB_LVIDIU(sb)->numFiles) +
Cyrill Gorcunov28de7942007-07-21 04:37:18 -07001739 le32_to_cpu(UDF_SB_LVIDIU(sb)->numDirs)) : 0) + buf->f_bfree;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001740 buf->f_ffree = buf->f_bfree;
1741 /* __kernel_fsid_t f_fsid */
Cyrill Gorcunovcb00ea32007-07-19 01:47:43 -07001742 buf->f_namelen = UDF_NAME_LEN - 2;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001743
1744 return 0;
1745}
1746
1747static unsigned char udf_bitmap_lookup[16] = {
1748 0, 1, 1, 2, 1, 2, 2, 3, 1, 2, 2, 3, 2, 3, 3, 4
1749};
1750
Cyrill Gorcunov28de7942007-07-21 04:37:18 -07001751static unsigned int udf_count_free_bitmap(struct super_block *sb, struct udf_bitmap *bitmap)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001752{
1753 struct buffer_head *bh = NULL;
1754 unsigned int accum = 0;
1755 int index;
1756 int block = 0, newblock;
1757 kernel_lb_addr loc;
1758 uint32_t bytes;
1759 uint8_t value;
1760 uint8_t *ptr;
1761 uint16_t ident;
1762 struct spaceBitmapDesc *bm;
1763
1764 lock_kernel();
1765
1766 loc.logicalBlockNum = bitmap->s_extPosition;
1767 loc.partitionReferenceNum = UDF_SB_PARTITION(sb);
1768 bh = udf_read_ptagged(sb, loc, 0, &ident);
1769
Cyrill Gorcunovcb00ea32007-07-19 01:47:43 -07001770 if (!bh) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001771 printk(KERN_ERR "udf: udf_count_free failed\n");
1772 goto out;
Cyrill Gorcunovcb00ea32007-07-19 01:47:43 -07001773 } else if (ident != TAG_IDENT_SBD) {
Jan Kara3bf25cb2007-05-08 00:35:16 -07001774 brelse(bh);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001775 printk(KERN_ERR "udf: udf_count_free failed\n");
1776 goto out;
1777 }
1778
1779 bm = (struct spaceBitmapDesc *)bh->b_data;
1780 bytes = le32_to_cpu(bm->numOfBytes);
Cyrill Gorcunov28de7942007-07-21 04:37:18 -07001781 index = sizeof(struct spaceBitmapDesc); /* offset in first block only */
1782 ptr = (uint8_t *)bh->b_data;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001783
Cyrill Gorcunovcb00ea32007-07-19 01:47:43 -07001784 while (bytes > 0) {
1785 while ((bytes > 0) && (index < sb->s_blocksize)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001786 value = ptr[index];
Cyrill Gorcunovcb00ea32007-07-19 01:47:43 -07001787 accum += udf_bitmap_lookup[value & 0x0f];
1788 accum += udf_bitmap_lookup[value >> 4];
Linus Torvalds1da177e2005-04-16 15:20:36 -07001789 index++;
1790 bytes--;
1791 }
Cyrill Gorcunovcb00ea32007-07-19 01:47:43 -07001792 if (bytes) {
Jan Kara3bf25cb2007-05-08 00:35:16 -07001793 brelse(bh);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001794 newblock = udf_get_lb_pblock(sb, loc, ++block);
1795 bh = udf_tread(sb, newblock);
Cyrill Gorcunovcb00ea32007-07-19 01:47:43 -07001796 if (!bh) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001797 udf_debug("read failed\n");
1798 goto out;
1799 }
1800 index = 0;
Cyrill Gorcunov28de7942007-07-21 04:37:18 -07001801 ptr = (uint8_t *)bh->b_data;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001802 }
1803 }
Jan Kara3bf25cb2007-05-08 00:35:16 -07001804 brelse(bh);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001805
Cyrill Gorcunov28de7942007-07-21 04:37:18 -07001806out:
Linus Torvalds1da177e2005-04-16 15:20:36 -07001807 unlock_kernel();
1808
1809 return accum;
1810}
1811
Cyrill Gorcunov28de7942007-07-21 04:37:18 -07001812static unsigned int udf_count_free_table(struct super_block *sb, struct inode *table)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001813{
1814 unsigned int accum = 0;
Jan Karaff116fc2007-05-08 00:35:14 -07001815 uint32_t elen;
1816 kernel_lb_addr eloc;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001817 int8_t etype;
Jan Karaff116fc2007-05-08 00:35:14 -07001818 struct extent_position epos;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001819
1820 lock_kernel();
1821
Jan Karaff116fc2007-05-08 00:35:14 -07001822 epos.block = UDF_I_LOCATION(table);
1823 epos.offset = sizeof(struct unallocSpaceEntry);
1824 epos.bh = NULL;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001825
Marcin Slusarz3a71fc52008-02-08 04:20:28 -08001826 while ((etype = udf_next_aext(table, &epos, &eloc, &elen, 1)) != -1)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001827 accum += (elen >> table->i_sb->s_blocksize_bits);
Marcin Slusarz3a71fc52008-02-08 04:20:28 -08001828
Jan Kara3bf25cb2007-05-08 00:35:16 -07001829 brelse(epos.bh);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001830
1831 unlock_kernel();
1832
1833 return accum;
1834}
Cyrill Gorcunovcb00ea32007-07-19 01:47:43 -07001835
1836static unsigned int udf_count_free(struct super_block *sb)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001837{
1838 unsigned int accum = 0;
1839
Cyrill Gorcunovcb00ea32007-07-19 01:47:43 -07001840 if (UDF_SB_LVIDBH(sb)) {
Cyrill Gorcunov28de7942007-07-21 04:37:18 -07001841 if (le32_to_cpu(UDF_SB_LVID(sb)->numOfPartitions) > UDF_SB_PARTITION(sb)) {
1842 accum = le32_to_cpu(UDF_SB_LVID(sb)->freeSpaceTable[UDF_SB_PARTITION(sb)]);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001843 if (accum == 0xFFFFFFFF)
1844 accum = 0;
1845 }
1846 }
1847
1848 if (accum)
1849 return accum;
1850
Marcin Slusarz3a71fc52008-02-08 04:20:28 -08001851 if (UDF_SB_PARTFLAGS(sb, UDF_SB_PARTITION(sb)) & UDF_PART_FLAG_UNALLOC_BITMAP) {
Cyrill Gorcunov28de7942007-07-21 04:37:18 -07001852 accum += udf_count_free_bitmap(sb,
1853 UDF_SB_PARTMAPS(sb)[UDF_SB_PARTITION(sb)].s_uspace.s_bitmap);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001854 }
Marcin Slusarz3a71fc52008-02-08 04:20:28 -08001855 if (UDF_SB_PARTFLAGS(sb, UDF_SB_PARTITION(sb)) & UDF_PART_FLAG_FREED_BITMAP) {
Cyrill Gorcunov28de7942007-07-21 04:37:18 -07001856 accum += udf_count_free_bitmap(sb,
1857 UDF_SB_PARTMAPS(sb)[UDF_SB_PARTITION(sb)].s_fspace.s_bitmap);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001858 }
1859 if (accum)
1860 return accum;
1861
Marcin Slusarz3a71fc52008-02-08 04:20:28 -08001862 if (UDF_SB_PARTFLAGS(sb, UDF_SB_PARTITION(sb)) & UDF_PART_FLAG_UNALLOC_TABLE) {
Cyrill Gorcunov28de7942007-07-21 04:37:18 -07001863 accum += udf_count_free_table(sb,
1864 UDF_SB_PARTMAPS(sb)[UDF_SB_PARTITION(sb)].s_uspace.s_table);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001865 }
Marcin Slusarz3a71fc52008-02-08 04:20:28 -08001866 if (UDF_SB_PARTFLAGS(sb, UDF_SB_PARTITION(sb)) & UDF_PART_FLAG_FREED_TABLE) {
Cyrill Gorcunov28de7942007-07-21 04:37:18 -07001867 accum += udf_count_free_table(sb,
1868 UDF_SB_PARTMAPS(sb)[UDF_SB_PARTITION(sb)].s_fspace.s_table);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001869 }
1870
1871 return accum;
1872}