blob: 18fc038a438da4b6bbf58fa73c23c27ecd0cb721 [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>
Linus Torvalds1da177e2005-04-16 15:20:36 -070051#include <linux/buffer_head.h>
52#include <linux/vfs.h>
53#include <linux/vmalloc.h>
Marcin Slusarzdc5d39b2008-02-08 04:20:32 -080054#include <linux/errno.h>
Miklos Szeredi6da80892008-02-08 04:21:50 -080055#include <linux/mount.h>
56#include <linux/seq_file.h>
Marcin Slusarz01b954a2008-02-02 22:37:07 +010057#include <linux/bitmap.h>
Bob Copelandf845fce2008-04-17 09:47:48 +020058#include <linux/crc-itu-t.h>
Jan Kara1df2ae32012-06-27 21:23:07 +020059#include <linux/log2.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070060#include <asm/byteorder.h>
61
Linus Torvalds1da177e2005-04-16 15:20:36 -070062#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
Miklos Szeredi6da80892008-02-08 04:21:50 -080077#define UDF_DEFAULT_BLOCKSIZE 2048
78
Al Viro8de52772012-02-06 12:45:27 -050079enum { UDF_MAX_LINKS = 0xffff };
80
Linus Torvalds1da177e2005-04-16 15:20:36 -070081/* These are the "meat" - everything else is stuffing */
82static int udf_fill_super(struct super_block *, void *, int);
83static void udf_put_super(struct super_block *);
Jan Kara146bca72009-03-16 18:27:37 +010084static int udf_sync_fs(struct super_block *, int);
Linus Torvalds1da177e2005-04-16 15:20:36 -070085static int udf_remount_fs(struct super_block *, int *, char *);
Pekka Enberg5ca4e4b2008-10-15 12:28:03 +020086static void udf_load_logicalvolint(struct super_block *, struct kernel_extent_ad);
Pekka Enberg5ca4e4b2008-10-15 12:28:03 +020087static int udf_find_fileset(struct super_block *, struct kernel_lb_addr *,
88 struct kernel_lb_addr *);
Cyrill Gorcunovcb00ea32007-07-19 01:47:43 -070089static void udf_load_fileset(struct super_block *, struct buffer_head *,
Pekka Enberg5ca4e4b2008-10-15 12:28:03 +020090 struct kernel_lb_addr *);
Linus Torvalds1da177e2005-04-16 15:20:36 -070091static void udf_open_lvid(struct super_block *);
92static void udf_close_lvid(struct super_block *);
93static unsigned int udf_count_free(struct super_block *);
David Howells726c3342006-06-23 02:02:58 -070094static int udf_statfs(struct dentry *, struct kstatfs *);
Al Viro34c80b12011-12-08 21:32:45 -050095static int udf_show_options(struct seq_file *, struct dentry *);
Linus Torvalds1da177e2005-04-16 15:20:36 -070096
Marcin Slusarz6c79e982008-02-08 04:20:30 -080097struct logicalVolIntegrityDescImpUse *udf_sb_lvidiu(struct udf_sb_info *sbi)
98{
Marcin Slusarz4b111112008-02-08 04:20:36 -080099 struct logicalVolIntegrityDesc *lvid =
100 (struct logicalVolIntegrityDesc *)sbi->s_lvid_bh->b_data;
Marcin Slusarz6c79e982008-02-08 04:20:30 -0800101 __u32 number_of_partitions = le32_to_cpu(lvid->numOfPartitions);
Marcin Slusarz4b111112008-02-08 04:20:36 -0800102 __u32 offset = number_of_partitions * 2 *
103 sizeof(uint32_t)/sizeof(uint8_t);
Marcin Slusarz6c79e982008-02-08 04:20:30 -0800104 return (struct logicalVolIntegrityDescImpUse *)&(lvid->impUse[offset]);
105}
106
Linus Torvalds1da177e2005-04-16 15:20:36 -0700107/* UDF filesystem type */
Al Viro152a0832010-07-25 00:46:55 +0400108static struct dentry *udf_mount(struct file_system_type *fs_type,
109 int flags, const char *dev_name, void *data)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700110{
Al Viro152a0832010-07-25 00:46:55 +0400111 return mount_bdev(fs_type, flags, dev_name, data, udf_fill_super);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700112}
113
114static struct file_system_type udf_fstype = {
Cyrill Gorcunov28de7942007-07-21 04:37:18 -0700115 .owner = THIS_MODULE,
116 .name = "udf",
Al Viro152a0832010-07-25 00:46:55 +0400117 .mount = udf_mount,
Cyrill Gorcunov28de7942007-07-21 04:37:18 -0700118 .kill_sb = kill_block_super,
119 .fs_flags = FS_REQUIRES_DEV,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700120};
121
Cyrill Gorcunovcb00ea32007-07-19 01:47:43 -0700122static struct kmem_cache *udf_inode_cachep;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700123
124static struct inode *udf_alloc_inode(struct super_block *sb)
125{
126 struct udf_inode_info *ei;
Marcin Slusarz3a71fc52008-02-08 04:20:28 -0800127 ei = kmem_cache_alloc(udf_inode_cachep, GFP_KERNEL);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700128 if (!ei)
129 return NULL;
Dan Bastone95f87972006-08-13 23:24:18 -0700130
131 ei->i_unique = 0;
132 ei->i_lenExtents = 0;
133 ei->i_next_alloc_block = 0;
134 ei->i_next_alloc_goal = 0;
135 ei->i_strat4096 = 0;
Alessio Igor Bogani4d0fb622010-11-16 18:40:47 +0100136 init_rwsem(&ei->i_data_sem);
Dan Bastone95f87972006-08-13 23:24:18 -0700137
Linus Torvalds1da177e2005-04-16 15:20:36 -0700138 return &ei->vfs_inode;
139}
140
Nick Pigginfa0d7e3d2011-01-07 17:49:49 +1100141static void udf_i_callback(struct rcu_head *head)
142{
143 struct inode *inode = container_of(head, struct inode, i_rcu);
Nick Pigginfa0d7e3d2011-01-07 17:49:49 +1100144 kmem_cache_free(udf_inode_cachep, UDF_I(inode));
145}
146
Linus Torvalds1da177e2005-04-16 15:20:36 -0700147static void udf_destroy_inode(struct inode *inode)
148{
Nick Pigginfa0d7e3d2011-01-07 17:49:49 +1100149 call_rcu(&inode->i_rcu, udf_i_callback);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700150}
151
Alexey Dobriyan51cc5062008-07-25 19:45:34 -0700152static void init_once(void *foo)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700153{
Cyrill Gorcunovcb00ea32007-07-19 01:47:43 -0700154 struct udf_inode_info *ei = (struct udf_inode_info *)foo;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700155
Christoph Lametera35afb82007-05-16 22:10:57 -0700156 ei->i_ext.i_data = NULL;
157 inode_init_once(&ei->vfs_inode);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700158}
159
160static int init_inodecache(void)
161{
162 udf_inode_cachep = kmem_cache_create("udf_inode_cache",
163 sizeof(struct udf_inode_info),
Cyrill Gorcunovcb00ea32007-07-19 01:47:43 -0700164 0, (SLAB_RECLAIM_ACCOUNT |
165 SLAB_MEM_SPREAD),
Paul Mundt20c2df82007-07-20 10:11:58 +0900166 init_once);
Cyrill Gorcunov28de7942007-07-21 04:37:18 -0700167 if (!udf_inode_cachep)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700168 return -ENOMEM;
169 return 0;
170}
171
172static void destroy_inodecache(void)
173{
Alexey Dobriyan1a1d92c2006-09-27 01:49:40 -0700174 kmem_cache_destroy(udf_inode_cachep);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700175}
176
177/* Superblock operations */
Josef 'Jeff' Sipekee9b6d62007-02-12 00:55:41 -0800178static const struct super_operations udf_sb_ops = {
Cyrill Gorcunov28de7942007-07-21 04:37:18 -0700179 .alloc_inode = udf_alloc_inode,
180 .destroy_inode = udf_destroy_inode,
181 .write_inode = udf_write_inode,
Al Viro3aac2b62010-06-07 00:43:39 -0400182 .evict_inode = udf_evict_inode,
Cyrill Gorcunov28de7942007-07-21 04:37:18 -0700183 .put_super = udf_put_super,
Jan Kara146bca72009-03-16 18:27:37 +0100184 .sync_fs = udf_sync_fs,
Cyrill Gorcunov28de7942007-07-21 04:37:18 -0700185 .statfs = udf_statfs,
186 .remount_fs = udf_remount_fs,
Miklos Szeredi6da80892008-02-08 04:21:50 -0800187 .show_options = udf_show_options,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700188};
189
Cyrill Gorcunovcb00ea32007-07-19 01:47:43 -0700190struct udf_options {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700191 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;
Al Virofaa17292011-07-26 03:18:29 -0400201 umode_t umask;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700202 gid_t gid;
203 uid_t uid;
Al Virofaa17292011-07-26 03:18:29 -0400204 umode_t fmode;
205 umode_t dmode;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700206 struct nls_table *nls_map;
207};
208
209static int __init init_udf_fs(void)
210{
211 int err;
Cyrill Gorcunov28de7942007-07-21 04:37:18 -0700212
Linus Torvalds1da177e2005-04-16 15:20:36 -0700213 err = init_inodecache();
214 if (err)
215 goto out1;
216 err = register_filesystem(&udf_fstype);
217 if (err)
218 goto out;
Cyrill Gorcunov28de7942007-07-21 04:37:18 -0700219
Linus Torvalds1da177e2005-04-16 15:20:36 -0700220 return 0;
Cyrill Gorcunov28de7942007-07-21 04:37:18 -0700221
222out:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700223 destroy_inodecache();
Cyrill Gorcunov28de7942007-07-21 04:37:18 -0700224
225out1:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700226 return err;
227}
228
229static void __exit exit_udf_fs(void)
230{
231 unregister_filesystem(&udf_fstype);
232 destroy_inodecache();
233}
234
235module_init(init_udf_fs)
Cyrill Gorcunov28de7942007-07-21 04:37:18 -0700236module_exit(exit_udf_fs)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700237
Marcin Slusarzdc5d39b2008-02-08 04:20:32 -0800238static 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) {
Joe Perches8076c362011-10-10 01:08:03 -0700245 udf_err(sb, "Unable to allocate space for %d partition maps\n",
246 count);
Marcin Slusarzdc5d39b2008-02-08 04:20:32 -0800247 sbi->s_partitions = 0;
248 return -ENOMEM;
249 }
250
251 sbi->s_partitions = count;
252 return 0;
253}
254
Jan Karabff943a2012-06-27 22:27:05 +0200255static void udf_sb_free_bitmap(struct udf_bitmap *bitmap)
256{
257 int i;
258 int nr_groups = bitmap->s_nr_groups;
259 int size = sizeof(struct udf_bitmap) + (sizeof(struct buffer_head *) *
260 nr_groups);
261
262 for (i = 0; i < nr_groups; i++)
263 if (bitmap->s_block_bitmap[i])
264 brelse(bitmap->s_block_bitmap[i]);
265
266 if (size <= PAGE_SIZE)
267 kfree(bitmap);
268 else
269 vfree(bitmap);
270}
271
272static void udf_free_partition(struct udf_part_map *map)
273{
274 int i;
275 struct udf_meta_data *mdata;
276
277 if (map->s_partition_flags & UDF_PART_FLAG_UNALLOC_TABLE)
278 iput(map->s_uspace.s_table);
279 if (map->s_partition_flags & UDF_PART_FLAG_FREED_TABLE)
280 iput(map->s_fspace.s_table);
281 if (map->s_partition_flags & UDF_PART_FLAG_UNALLOC_BITMAP)
282 udf_sb_free_bitmap(map->s_uspace.s_bitmap);
283 if (map->s_partition_flags & UDF_PART_FLAG_FREED_BITMAP)
284 udf_sb_free_bitmap(map->s_fspace.s_bitmap);
285 if (map->s_partition_type == UDF_SPARABLE_MAP15)
286 for (i = 0; i < 4; i++)
287 brelse(map->s_type_specific.s_sparing.s_spar_map[i]);
288 else if (map->s_partition_type == UDF_METADATA_MAP25) {
289 mdata = &map->s_type_specific.s_metadata;
290 iput(mdata->s_metadata_fe);
291 mdata->s_metadata_fe = NULL;
292
293 iput(mdata->s_mirror_fe);
294 mdata->s_mirror_fe = NULL;
295
296 iput(mdata->s_bitmap_fe);
297 mdata->s_bitmap_fe = NULL;
298 }
299}
300
301static void udf_sb_free_partitions(struct super_block *sb)
302{
303 struct udf_sb_info *sbi = UDF_SB(sb);
304 int i;
305
306 for (i = 0; i < sbi->s_partitions; i++)
307 udf_free_partition(&sbi->s_partmaps[i]);
308 kfree(sbi->s_partmaps);
309 sbi->s_partmaps = NULL;
310}
311
Al Viro34c80b12011-12-08 21:32:45 -0500312static int udf_show_options(struct seq_file *seq, struct dentry *root)
Miklos Szeredi6da80892008-02-08 04:21:50 -0800313{
Al Viro34c80b12011-12-08 21:32:45 -0500314 struct super_block *sb = root->d_sb;
Miklos Szeredi6da80892008-02-08 04:21:50 -0800315 struct udf_sb_info *sbi = UDF_SB(sb);
316
317 if (!UDF_QUERY_FLAG(sb, UDF_FLAG_STRICT))
318 seq_puts(seq, ",nostrict");
Clemens Ladisch1197e4d2009-03-11 15:57:47 +0100319 if (UDF_QUERY_FLAG(sb, UDF_FLAG_BLOCKSIZE_SET))
Miklos Szeredi6da80892008-02-08 04:21:50 -0800320 seq_printf(seq, ",bs=%lu", sb->s_blocksize);
321 if (UDF_QUERY_FLAG(sb, UDF_FLAG_UNHIDE))
322 seq_puts(seq, ",unhide");
323 if (UDF_QUERY_FLAG(sb, UDF_FLAG_UNDELETE))
324 seq_puts(seq, ",undelete");
325 if (!UDF_QUERY_FLAG(sb, UDF_FLAG_USE_AD_IN_ICB))
326 seq_puts(seq, ",noadinicb");
327 if (UDF_QUERY_FLAG(sb, UDF_FLAG_USE_SHORT_AD))
328 seq_puts(seq, ",shortad");
329 if (UDF_QUERY_FLAG(sb, UDF_FLAG_UID_FORGET))
330 seq_puts(seq, ",uid=forget");
331 if (UDF_QUERY_FLAG(sb, UDF_FLAG_UID_IGNORE))
332 seq_puts(seq, ",uid=ignore");
333 if (UDF_QUERY_FLAG(sb, UDF_FLAG_GID_FORGET))
334 seq_puts(seq, ",gid=forget");
335 if (UDF_QUERY_FLAG(sb, UDF_FLAG_GID_IGNORE))
336 seq_puts(seq, ",gid=ignore");
337 if (UDF_QUERY_FLAG(sb, UDF_FLAG_UID_SET))
338 seq_printf(seq, ",uid=%u", sbi->s_uid);
339 if (UDF_QUERY_FLAG(sb, UDF_FLAG_GID_SET))
340 seq_printf(seq, ",gid=%u", sbi->s_gid);
341 if (sbi->s_umask != 0)
Al Virofaa17292011-07-26 03:18:29 -0400342 seq_printf(seq, ",umask=%ho", sbi->s_umask);
Marcin Slusarz87bc7302008-12-02 13:40:11 +0100343 if (sbi->s_fmode != UDF_INVALID_MODE)
Al Virofaa17292011-07-26 03:18:29 -0400344 seq_printf(seq, ",mode=%ho", sbi->s_fmode);
Marcin Slusarz87bc7302008-12-02 13:40:11 +0100345 if (sbi->s_dmode != UDF_INVALID_MODE)
Al Virofaa17292011-07-26 03:18:29 -0400346 seq_printf(seq, ",dmode=%ho", sbi->s_dmode);
Miklos Szeredi6da80892008-02-08 04:21:50 -0800347 if (UDF_QUERY_FLAG(sb, UDF_FLAG_SESSION_SET))
348 seq_printf(seq, ",session=%u", sbi->s_session);
349 if (UDF_QUERY_FLAG(sb, UDF_FLAG_LASTBLOCK_SET))
350 seq_printf(seq, ",lastblock=%u", sbi->s_last_block);
Jan Kara40346002009-03-19 16:21:38 +0100351 if (sbi->s_anchor != 0)
352 seq_printf(seq, ",anchor=%u", sbi->s_anchor);
Miklos Szeredi6da80892008-02-08 04:21:50 -0800353 /*
354 * volume, partition, fileset and rootdir seem to be ignored
355 * currently
356 */
357 if (UDF_QUERY_FLAG(sb, UDF_FLAG_UTF8))
358 seq_puts(seq, ",utf8");
359 if (UDF_QUERY_FLAG(sb, UDF_FLAG_NLS_MAP) && sbi->s_nls_map)
360 seq_printf(seq, ",iocharset=%s", sbi->s_nls_map->charset);
361
362 return 0;
363}
364
Linus Torvalds1da177e2005-04-16 15:20:36 -0700365/*
366 * udf_parse_options
367 *
368 * PURPOSE
369 * Parse mount options.
370 *
371 * DESCRIPTION
372 * The following mount options are supported:
373 *
374 * gid= Set the default group.
375 * umask= Set the default umask.
Marcin Slusarz7ac9bcd52008-11-16 20:52:19 +0100376 * mode= Set the default file permissions.
377 * dmode= Set the default directory permissions.
Linus Torvalds1da177e2005-04-16 15:20:36 -0700378 * uid= Set the default user.
379 * bs= Set the block size.
380 * unhide Show otherwise hidden files.
381 * undelete Show deleted files in lists.
382 * adinicb Embed data in the inode (default)
383 * noadinicb Don't embed data in the inode
384 * shortad Use short ad's
385 * longad Use long ad's (default)
386 * nostrict Unset strict conformance
387 * iocharset= Set the NLS character set
388 *
389 * The remaining are for debugging and disaster recovery:
390 *
Cyrill Gorcunov28de7942007-07-21 04:37:18 -0700391 * novrs Skip volume sequence recognition
Linus Torvalds1da177e2005-04-16 15:20:36 -0700392 *
393 * The following expect a offset from 0.
394 *
395 * session= Set the CDROM session (default= last session)
396 * anchor= Override standard anchor location. (default= 256)
397 * volume= Override the VolumeDesc location. (unused)
398 * partition= Override the PartitionDesc location. (unused)
399 * lastblock= Set the last block of the filesystem/
400 *
401 * The following expect a offset from the partition root.
402 *
403 * fileset= Override the fileset block location. (unused)
404 * rootdir= Override the root directory location. (unused)
405 * WARNING: overriding the rootdir to a non-directory may
406 * yield highly unpredictable results.
407 *
408 * PRE-CONDITIONS
409 * options Pointer to mount options string.
410 * uopts Pointer to mount options variable.
411 *
412 * POST-CONDITIONS
413 * <return> 1 Mount options parsed okay.
414 * <return> 0 Error parsing mount options.
415 *
416 * HISTORY
417 * July 1, 1997 - Andrew E. Mileski
418 * Written, tested, and released.
419 */
Cyrill Gorcunov28de7942007-07-21 04:37:18 -0700420
Linus Torvalds1da177e2005-04-16 15:20:36 -0700421enum {
422 Opt_novrs, Opt_nostrict, Opt_bs, Opt_unhide, Opt_undelete,
423 Opt_noadinicb, Opt_adinicb, Opt_shortad, Opt_longad,
424 Opt_gid, Opt_uid, Opt_umask, Opt_session, Opt_lastblock,
425 Opt_anchor, Opt_volume, Opt_partition, Opt_fileset,
426 Opt_rootdir, Opt_utf8, Opt_iocharset,
Marcin Slusarz7ac9bcd52008-11-16 20:52:19 +0100427 Opt_err, Opt_uforget, Opt_uignore, Opt_gforget, Opt_gignore,
428 Opt_fmode, Opt_dmode
Linus Torvalds1da177e2005-04-16 15:20:36 -0700429};
430
Steven Whitehousea447c092008-10-13 10:46:57 +0100431static const match_table_t tokens = {
Cyrill Gorcunov28de7942007-07-21 04:37:18 -0700432 {Opt_novrs, "novrs"},
433 {Opt_nostrict, "nostrict"},
434 {Opt_bs, "bs=%u"},
435 {Opt_unhide, "unhide"},
436 {Opt_undelete, "undelete"},
437 {Opt_noadinicb, "noadinicb"},
438 {Opt_adinicb, "adinicb"},
439 {Opt_shortad, "shortad"},
440 {Opt_longad, "longad"},
441 {Opt_uforget, "uid=forget"},
442 {Opt_uignore, "uid=ignore"},
443 {Opt_gforget, "gid=forget"},
444 {Opt_gignore, "gid=ignore"},
445 {Opt_gid, "gid=%u"},
446 {Opt_uid, "uid=%u"},
447 {Opt_umask, "umask=%o"},
448 {Opt_session, "session=%u"},
449 {Opt_lastblock, "lastblock=%u"},
450 {Opt_anchor, "anchor=%u"},
451 {Opt_volume, "volume=%u"},
452 {Opt_partition, "partition=%u"},
453 {Opt_fileset, "fileset=%u"},
454 {Opt_rootdir, "rootdir=%u"},
455 {Opt_utf8, "utf8"},
456 {Opt_iocharset, "iocharset=%s"},
Marcin Slusarz7ac9bcd52008-11-16 20:52:19 +0100457 {Opt_fmode, "mode=%o"},
458 {Opt_dmode, "dmode=%o"},
Cyrill Gorcunov28de7942007-07-21 04:37:18 -0700459 {Opt_err, NULL}
Linus Torvalds1da177e2005-04-16 15:20:36 -0700460};
461
Miklos Szeredi6da80892008-02-08 04:21:50 -0800462static int udf_parse_options(char *options, struct udf_options *uopt,
463 bool remount)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700464{
465 char *p;
466 int option;
467
468 uopt->novrs = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700469 uopt->partition = 0xFFFF;
470 uopt->session = 0xFFFFFFFF;
471 uopt->lastblock = 0;
472 uopt->anchor = 0;
473 uopt->volume = 0xFFFFFFFF;
474 uopt->rootdir = 0xFFFFFFFF;
475 uopt->fileset = 0xFFFFFFFF;
476 uopt->nls_map = NULL;
477
478 if (!options)
479 return 1;
480
Cyrill Gorcunovcb00ea32007-07-19 01:47:43 -0700481 while ((p = strsep(&options, ",")) != NULL) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700482 substring_t args[MAX_OPT_ARGS];
483 int token;
484 if (!*p)
485 continue;
486
487 token = match_token(p, tokens, args);
Cyrill Gorcunovcb00ea32007-07-19 01:47:43 -0700488 switch (token) {
489 case Opt_novrs:
490 uopt->novrs = 1;
Clemens Ladisch41368012009-03-06 09:16:49 +0100491 break;
Cyrill Gorcunovcb00ea32007-07-19 01:47:43 -0700492 case Opt_bs:
493 if (match_int(&args[0], &option))
494 return 0;
495 uopt->blocksize = option;
Clemens Ladisch1197e4d2009-03-11 15:57:47 +0100496 uopt->flags |= (1 << UDF_FLAG_BLOCKSIZE_SET);
Cyrill Gorcunovcb00ea32007-07-19 01:47:43 -0700497 break;
498 case Opt_unhide:
499 uopt->flags |= (1 << UDF_FLAG_UNHIDE);
500 break;
501 case Opt_undelete:
502 uopt->flags |= (1 << UDF_FLAG_UNDELETE);
503 break;
504 case Opt_noadinicb:
505 uopt->flags &= ~(1 << UDF_FLAG_USE_AD_IN_ICB);
506 break;
507 case Opt_adinicb:
508 uopt->flags |= (1 << UDF_FLAG_USE_AD_IN_ICB);
509 break;
510 case Opt_shortad:
511 uopt->flags |= (1 << UDF_FLAG_USE_SHORT_AD);
512 break;
513 case Opt_longad:
514 uopt->flags &= ~(1 << UDF_FLAG_USE_SHORT_AD);
515 break;
516 case Opt_gid:
517 if (match_int(args, &option))
518 return 0;
519 uopt->gid = option;
Cyrill Gorcunovca76d2d2007-07-31 00:39:40 -0700520 uopt->flags |= (1 << UDF_FLAG_GID_SET);
Cyrill Gorcunovcb00ea32007-07-19 01:47:43 -0700521 break;
522 case Opt_uid:
523 if (match_int(args, &option))
524 return 0;
525 uopt->uid = option;
Cyrill Gorcunovca76d2d2007-07-31 00:39:40 -0700526 uopt->flags |= (1 << UDF_FLAG_UID_SET);
Cyrill Gorcunovcb00ea32007-07-19 01:47:43 -0700527 break;
528 case Opt_umask:
529 if (match_octal(args, &option))
530 return 0;
531 uopt->umask = option;
532 break;
533 case Opt_nostrict:
534 uopt->flags &= ~(1 << UDF_FLAG_STRICT);
535 break;
536 case Opt_session:
537 if (match_int(args, &option))
538 return 0;
539 uopt->session = option;
Miklos Szeredi6da80892008-02-08 04:21:50 -0800540 if (!remount)
541 uopt->flags |= (1 << UDF_FLAG_SESSION_SET);
Cyrill Gorcunovcb00ea32007-07-19 01:47:43 -0700542 break;
543 case Opt_lastblock:
544 if (match_int(args, &option))
545 return 0;
546 uopt->lastblock = option;
Miklos Szeredi6da80892008-02-08 04:21:50 -0800547 if (!remount)
548 uopt->flags |= (1 << UDF_FLAG_LASTBLOCK_SET);
Cyrill Gorcunovcb00ea32007-07-19 01:47:43 -0700549 break;
550 case Opt_anchor:
551 if (match_int(args, &option))
552 return 0;
553 uopt->anchor = option;
554 break;
555 case Opt_volume:
556 if (match_int(args, &option))
557 return 0;
558 uopt->volume = option;
559 break;
560 case Opt_partition:
561 if (match_int(args, &option))
562 return 0;
563 uopt->partition = option;
564 break;
565 case Opt_fileset:
566 if (match_int(args, &option))
567 return 0;
568 uopt->fileset = option;
569 break;
570 case Opt_rootdir:
571 if (match_int(args, &option))
572 return 0;
573 uopt->rootdir = option;
574 break;
575 case Opt_utf8:
576 uopt->flags |= (1 << UDF_FLAG_UTF8);
577 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700578#ifdef CONFIG_UDF_NLS
Cyrill Gorcunovcb00ea32007-07-19 01:47:43 -0700579 case Opt_iocharset:
580 uopt->nls_map = load_nls(args[0].from);
581 uopt->flags |= (1 << UDF_FLAG_NLS_MAP);
582 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700583#endif
Cyrill Gorcunovcb00ea32007-07-19 01:47:43 -0700584 case Opt_uignore:
585 uopt->flags |= (1 << UDF_FLAG_UID_IGNORE);
586 break;
587 case Opt_uforget:
588 uopt->flags |= (1 << UDF_FLAG_UID_FORGET);
589 break;
590 case Opt_gignore:
591 uopt->flags |= (1 << UDF_FLAG_GID_IGNORE);
592 break;
593 case Opt_gforget:
594 uopt->flags |= (1 << UDF_FLAG_GID_FORGET);
595 break;
Marcin Slusarz7ac9bcd52008-11-16 20:52:19 +0100596 case Opt_fmode:
597 if (match_octal(args, &option))
598 return 0;
599 uopt->fmode = option & 0777;
600 break;
601 case Opt_dmode:
602 if (match_octal(args, &option))
603 return 0;
604 uopt->dmode = option & 0777;
605 break;
Cyrill Gorcunovcb00ea32007-07-19 01:47:43 -0700606 default:
Joe Perches78ace702011-10-10 01:08:05 -0700607 pr_err("bad mount option \"%s\" or missing value\n", p);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700608 return 0;
609 }
610 }
611 return 1;
612}
613
Cyrill Gorcunovcb00ea32007-07-19 01:47:43 -0700614static int udf_remount_fs(struct super_block *sb, int *flags, char *options)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700615{
616 struct udf_options uopt;
Marcin Slusarz6c79e982008-02-08 04:20:30 -0800617 struct udf_sb_info *sbi = UDF_SB(sb);
Christoph Hellwigc79d9672010-05-19 07:16:40 -0400618 int error = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700619
Marcin Slusarz6c79e982008-02-08 04:20:30 -0800620 uopt.flags = sbi->s_flags;
621 uopt.uid = sbi->s_uid;
622 uopt.gid = sbi->s_gid;
623 uopt.umask = sbi->s_umask;
Marcin Slusarz7ac9bcd52008-11-16 20:52:19 +0100624 uopt.fmode = sbi->s_fmode;
625 uopt.dmode = sbi->s_dmode;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700626
Miklos Szeredi6da80892008-02-08 04:21:50 -0800627 if (!udf_parse_options(options, &uopt, true))
Linus Torvalds1da177e2005-04-16 15:20:36 -0700628 return -EINVAL;
629
Jan Karac03cad22010-10-20 22:17:28 +0200630 write_lock(&sbi->s_cred_lock);
Marcin Slusarz6c79e982008-02-08 04:20:30 -0800631 sbi->s_flags = uopt.flags;
632 sbi->s_uid = uopt.uid;
633 sbi->s_gid = uopt.gid;
634 sbi->s_umask = uopt.umask;
Marcin Slusarz7ac9bcd52008-11-16 20:52:19 +0100635 sbi->s_fmode = uopt.fmode;
636 sbi->s_dmode = uopt.dmode;
Jan Karac03cad22010-10-20 22:17:28 +0200637 write_unlock(&sbi->s_cred_lock);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700638
Marcin Slusarz6c79e982008-02-08 04:20:30 -0800639 if (sbi->s_lvid_bh) {
640 int write_rev = le16_to_cpu(udf_sb_lvidiu(sbi)->minUDFWriteRev);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700641 if (write_rev > UDF_MAX_WRITE_VERSION)
642 *flags |= MS_RDONLY;
643 }
644
Christoph Hellwigc79d9672010-05-19 07:16:40 -0400645 if ((*flags & MS_RDONLY) == (sb->s_flags & MS_RDONLY))
646 goto out_unlock;
647
Jan Kara36350462010-05-19 16:28:56 +0200648 if (*flags & MS_RDONLY)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700649 udf_close_lvid(sb);
Jan Kara36350462010-05-19 16:28:56 +0200650 else
Linus Torvalds1da177e2005-04-16 15:20:36 -0700651 udf_open_lvid(sb);
652
Christoph Hellwigc79d9672010-05-19 07:16:40 -0400653out_unlock:
Christoph Hellwigc79d9672010-05-19 07:16:40 -0400654 return error;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700655}
656
Jan Kara40346002009-03-19 16:21:38 +0100657/* Check Volume Structure Descriptors (ECMA 167 2/9.1) */
658/* We also check any "CD-ROM Volume Descriptor Set" (ECMA 167 2/8.3.1) */
659static loff_t udf_check_vsd(struct super_block *sb)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700660{
661 struct volStructDesc *vsd = NULL;
Sebastian Manciuleaf4bcbbd2008-04-08 14:02:11 +0200662 loff_t sector = 32768;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700663 int sectorsize;
664 struct buffer_head *bh = NULL;
Cyrill Gorcunovcb00ea32007-07-19 01:47:43 -0700665 int nsr02 = 0;
666 int nsr03 = 0;
Marcin Slusarz6c79e982008-02-08 04:20:30 -0800667 struct udf_sb_info *sbi;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700668
Marcin Slusarz6c79e982008-02-08 04:20:30 -0800669 sbi = UDF_SB(sb);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700670 if (sb->s_blocksize < sizeof(struct volStructDesc))
671 sectorsize = sizeof(struct volStructDesc);
672 else
673 sectorsize = sb->s_blocksize;
674
Marcin Slusarz6c79e982008-02-08 04:20:30 -0800675 sector += (sbi->s_session << sb->s_blocksize_bits);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700676
677 udf_debug("Starting at sector %u (%ld byte sectors)\n",
Sebastian Manciulea706047a2008-04-14 17:13:01 +0200678 (unsigned int)(sector >> sb->s_blocksize_bits),
679 sb->s_blocksize);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700680 /* Process the sequence (if applicable) */
Cyrill Gorcunovcb00ea32007-07-19 01:47:43 -0700681 for (; !nsr02 && !nsr03; sector += sectorsize) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700682 /* Read a block */
683 bh = udf_tread(sb, sector >> sb->s_blocksize_bits);
684 if (!bh)
685 break;
686
687 /* Look for ISO descriptors */
688 vsd = (struct volStructDesc *)(bh->b_data +
Marcin Slusarz3a71fc52008-02-08 04:20:28 -0800689 (sector & (sb->s_blocksize - 1)));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700690
Cyrill Gorcunovcb00ea32007-07-19 01:47:43 -0700691 if (vsd->stdIdent[0] == 0) {
Jan Kara3bf25cb2007-05-08 00:35:16 -0700692 brelse(bh);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700693 break;
Marcin Slusarz3a71fc52008-02-08 04:20:28 -0800694 } else if (!strncmp(vsd->stdIdent, VSD_STD_ID_CD001,
695 VSD_STD_ID_LEN)) {
Cyrill Gorcunovcb00ea32007-07-19 01:47:43 -0700696 switch (vsd->structType) {
697 case 0:
698 udf_debug("ISO9660 Boot Record found\n");
699 break;
700 case 1:
Joe Perchesa983f362011-10-10 01:08:07 -0700701 udf_debug("ISO9660 Primary Volume Descriptor found\n");
Cyrill Gorcunovcb00ea32007-07-19 01:47:43 -0700702 break;
703 case 2:
Joe Perchesa983f362011-10-10 01:08:07 -0700704 udf_debug("ISO9660 Supplementary Volume Descriptor found\n");
Cyrill Gorcunovcb00ea32007-07-19 01:47:43 -0700705 break;
706 case 3:
Joe Perchesa983f362011-10-10 01:08:07 -0700707 udf_debug("ISO9660 Volume Partition Descriptor found\n");
Cyrill Gorcunovcb00ea32007-07-19 01:47:43 -0700708 break;
709 case 255:
Joe Perchesa983f362011-10-10 01:08:07 -0700710 udf_debug("ISO9660 Volume Descriptor Set Terminator found\n");
Cyrill Gorcunovcb00ea32007-07-19 01:47:43 -0700711 break;
712 default:
713 udf_debug("ISO9660 VRS (%u) found\n",
714 vsd->structType);
715 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700716 }
Marcin Slusarz3a71fc52008-02-08 04:20:28 -0800717 } else if (!strncmp(vsd->stdIdent, VSD_STD_ID_BEA01,
718 VSD_STD_ID_LEN))
719 ; /* nothing */
720 else if (!strncmp(vsd->stdIdent, VSD_STD_ID_TEA01,
721 VSD_STD_ID_LEN)) {
Jan Kara3bf25cb2007-05-08 00:35:16 -0700722 brelse(bh);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700723 break;
Marcin Slusarz3a71fc52008-02-08 04:20:28 -0800724 } else if (!strncmp(vsd->stdIdent, VSD_STD_ID_NSR02,
725 VSD_STD_ID_LEN))
Linus Torvalds1da177e2005-04-16 15:20:36 -0700726 nsr02 = sector;
Marcin Slusarz3a71fc52008-02-08 04:20:28 -0800727 else if (!strncmp(vsd->stdIdent, VSD_STD_ID_NSR03,
728 VSD_STD_ID_LEN))
Linus Torvalds1da177e2005-04-16 15:20:36 -0700729 nsr03 = sector;
Jan Kara3bf25cb2007-05-08 00:35:16 -0700730 brelse(bh);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700731 }
732
733 if (nsr03)
734 return nsr03;
735 else if (nsr02)
736 return nsr02;
Marcin Slusarz6c79e982008-02-08 04:20:30 -0800737 else if (sector - (sbi->s_session << sb->s_blocksize_bits) == 32768)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700738 return -1;
739 else
740 return 0;
741}
742
Marcin Slusarz3a71fc52008-02-08 04:20:28 -0800743static int udf_find_fileset(struct super_block *sb,
Pekka Enberg5ca4e4b2008-10-15 12:28:03 +0200744 struct kernel_lb_addr *fileset,
745 struct kernel_lb_addr *root)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700746{
747 struct buffer_head *bh = NULL;
748 long lastblock;
749 uint16_t ident;
Marcin Slusarz6c79e982008-02-08 04:20:30 -0800750 struct udf_sb_info *sbi;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700751
752 if (fileset->logicalBlockNum != 0xFFFFFFFF ||
Cyrill Gorcunovcb00ea32007-07-19 01:47:43 -0700753 fileset->partitionReferenceNum != 0xFFFF) {
Pekka Enberg97e961f2008-10-15 12:29:03 +0200754 bh = udf_read_ptagged(sb, fileset, 0, &ident);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700755
Cyrill Gorcunov28de7942007-07-21 04:37:18 -0700756 if (!bh) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700757 return 1;
Cyrill Gorcunov28de7942007-07-21 04:37:18 -0700758 } else if (ident != TAG_IDENT_FSD) {
Jan Kara3bf25cb2007-05-08 00:35:16 -0700759 brelse(bh);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700760 return 1;
761 }
Cyrill Gorcunovcb00ea32007-07-19 01:47:43 -0700762
Linus Torvalds1da177e2005-04-16 15:20:36 -0700763 }
764
Marcin Slusarz6c79e982008-02-08 04:20:30 -0800765 sbi = UDF_SB(sb);
Marcin Slusarz3a71fc52008-02-08 04:20:28 -0800766 if (!bh) {
767 /* Search backwards through the partitions */
Pekka Enberg5ca4e4b2008-10-15 12:28:03 +0200768 struct kernel_lb_addr newfileset;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700769
Cyrill Gorcunov28de7942007-07-21 04:37:18 -0700770/* --> cvg: FIXME - is it reasonable? */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700771 return 1;
Cyrill Gorcunovcb00ea32007-07-19 01:47:43 -0700772
Marcin Slusarz6c79e982008-02-08 04:20:30 -0800773 for (newfileset.partitionReferenceNum = sbi->s_partitions - 1;
Cyrill Gorcunovcb00ea32007-07-19 01:47:43 -0700774 (newfileset.partitionReferenceNum != 0xFFFF &&
775 fileset->logicalBlockNum == 0xFFFFFFFF &&
776 fileset->partitionReferenceNum == 0xFFFF);
777 newfileset.partitionReferenceNum--) {
Marcin Slusarz6c79e982008-02-08 04:20:30 -0800778 lastblock = sbi->s_partmaps
779 [newfileset.partitionReferenceNum]
780 .s_partition_len;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700781 newfileset.logicalBlockNum = 0;
782
Cyrill Gorcunovcb00ea32007-07-19 01:47:43 -0700783 do {
Pekka Enberg97e961f2008-10-15 12:29:03 +0200784 bh = udf_read_ptagged(sb, &newfileset, 0,
Marcin Slusarz3a71fc52008-02-08 04:20:28 -0800785 &ident);
Cyrill Gorcunovcb00ea32007-07-19 01:47:43 -0700786 if (!bh) {
787 newfileset.logicalBlockNum++;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700788 continue;
789 }
790
Cyrill Gorcunovcb00ea32007-07-19 01:47:43 -0700791 switch (ident) {
792 case TAG_IDENT_SBD:
Cyrill Gorcunov28de7942007-07-21 04:37:18 -0700793 {
794 struct spaceBitmapDesc *sp;
Marcin Slusarz4b111112008-02-08 04:20:36 -0800795 sp = (struct spaceBitmapDesc *)
796 bh->b_data;
Cyrill Gorcunov28de7942007-07-21 04:37:18 -0700797 newfileset.logicalBlockNum += 1 +
798 ((le32_to_cpu(sp->numOfBytes) +
Marcin Slusarz4b111112008-02-08 04:20:36 -0800799 sizeof(struct spaceBitmapDesc)
800 - 1) >> sb->s_blocksize_bits);
Cyrill Gorcunov28de7942007-07-21 04:37:18 -0700801 brelse(bh);
802 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700803 }
Cyrill Gorcunov28de7942007-07-21 04:37:18 -0700804 case TAG_IDENT_FSD:
805 *fileset = newfileset;
806 break;
807 default:
808 newfileset.logicalBlockNum++;
809 brelse(bh);
810 bh = NULL;
811 break;
812 }
813 } while (newfileset.logicalBlockNum < lastblock &&
814 fileset->logicalBlockNum == 0xFFFFFFFF &&
815 fileset->partitionReferenceNum == 0xFFFF);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700816 }
817 }
818
819 if ((fileset->logicalBlockNum != 0xFFFFFFFF ||
Cyrill Gorcunovcb00ea32007-07-19 01:47:43 -0700820 fileset->partitionReferenceNum != 0xFFFF) && bh) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700821 udf_debug("Fileset at block=%d, partition=%d\n",
Cyrill Gorcunovcb00ea32007-07-19 01:47:43 -0700822 fileset->logicalBlockNum,
823 fileset->partitionReferenceNum);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700824
Marcin Slusarz6c79e982008-02-08 04:20:30 -0800825 sbi->s_partition = fileset->partitionReferenceNum;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700826 udf_load_fileset(sb, bh, root);
Jan Kara3bf25cb2007-05-08 00:35:16 -0700827 brelse(bh);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700828 return 0;
829 }
830 return 1;
831}
832
Jan Karac0eb31e2008-04-01 16:50:35 +0200833static int udf_load_pvoldesc(struct super_block *sb, sector_t block)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700834{
835 struct primaryVolDesc *pvoldesc;
Marcin Slusarzba9aadd2008-11-16 19:01:44 +0100836 struct ustr *instr, *outstr;
Jan Karac0eb31e2008-04-01 16:50:35 +0200837 struct buffer_head *bh;
838 uint16_t ident;
Marcin Slusarzba9aadd2008-11-16 19:01:44 +0100839 int ret = 1;
840
841 instr = kmalloc(sizeof(struct ustr), GFP_NOFS);
842 if (!instr)
843 return 1;
844
845 outstr = kmalloc(sizeof(struct ustr), GFP_NOFS);
846 if (!outstr)
847 goto out1;
Jan Karac0eb31e2008-04-01 16:50:35 +0200848
849 bh = udf_read_tagged(sb, block, block, &ident);
850 if (!bh)
Marcin Slusarzba9aadd2008-11-16 19:01:44 +0100851 goto out2;
852
Jan Karac0eb31e2008-04-01 16:50:35 +0200853 BUG_ON(ident != TAG_IDENT_PVD);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700854
855 pvoldesc = (struct primaryVolDesc *)bh->b_data;
856
Marcin Slusarz56774802008-02-10 11:25:31 +0100857 if (udf_disk_stamp_to_time(&UDF_SB(sb)->s_record_time,
858 pvoldesc->recordingDateAndTime)) {
Marcin Slusarzaf15a292008-02-10 11:29:10 +0100859#ifdef UDFFS_DEBUG
Pekka Enberg5ca4e4b2008-10-15 12:28:03 +0200860 struct timestamp *ts = &pvoldesc->recordingDateAndTime;
Joe Perchesa983f362011-10-10 01:08:07 -0700861 udf_debug("recording time %04u/%02u/%02u %02u:%02u (%x)\n",
Marcin Slusarzaf15a292008-02-10 11:29:10 +0100862 le16_to_cpu(ts->year), ts->month, ts->day, ts->hour,
863 ts->minute, le16_to_cpu(ts->typeAndTimezone));
864#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -0700865 }
866
Marcin Slusarzba9aadd2008-11-16 19:01:44 +0100867 if (!udf_build_ustr(instr, pvoldesc->volIdent, 32))
868 if (udf_CS0toUTF8(outstr, instr)) {
869 strncpy(UDF_SB(sb)->s_volume_ident, outstr->u_name,
870 outstr->u_len > 31 ? 31 : outstr->u_len);
Marcin Slusarz4b111112008-02-08 04:20:36 -0800871 udf_debug("volIdent[] = '%s'\n",
Joe Perchesa983f362011-10-10 01:08:07 -0700872 UDF_SB(sb)->s_volume_ident);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700873 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700874
Marcin Slusarzba9aadd2008-11-16 19:01:44 +0100875 if (!udf_build_ustr(instr, pvoldesc->volSetIdent, 128))
876 if (udf_CS0toUTF8(outstr, instr))
877 udf_debug("volSetIdent[] = '%s'\n", outstr->u_name);
Jan Karac0eb31e2008-04-01 16:50:35 +0200878
879 brelse(bh);
Marcin Slusarzba9aadd2008-11-16 19:01:44 +0100880 ret = 0;
881out2:
882 kfree(outstr);
883out1:
884 kfree(instr);
885 return ret;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700886}
887
Namjae Jeon3080a742011-10-23 19:28:32 +0900888struct inode *udf_find_metadata_inode_efe(struct super_block *sb,
889 u32 meta_file_loc, u32 partition_num)
890{
891 struct kernel_lb_addr addr;
892 struct inode *metadata_fe;
893
894 addr.logicalBlockNum = meta_file_loc;
895 addr.partitionReferenceNum = partition_num;
896
897 metadata_fe = udf_iget(sb, &addr);
898
899 if (metadata_fe == NULL)
900 udf_warn(sb, "metadata inode efe not found\n");
901 else if (UDF_I(metadata_fe)->i_alloc_type != ICBTAG_FLAG_AD_SHORT) {
902 udf_warn(sb, "metadata inode efe does not have short allocation descriptors!\n");
903 iput(metadata_fe);
904 metadata_fe = NULL;
905 }
906
907 return metadata_fe;
908}
909
Jan Karabfb257a2008-04-08 20:37:21 +0200910static int udf_load_metadata_files(struct super_block *sb, int partition)
911{
912 struct udf_sb_info *sbi = UDF_SB(sb);
913 struct udf_part_map *map;
914 struct udf_meta_data *mdata;
Pekka Enberg5ca4e4b2008-10-15 12:28:03 +0200915 struct kernel_lb_addr addr;
Jan Karabfb257a2008-04-08 20:37:21 +0200916
917 map = &sbi->s_partmaps[partition];
918 mdata = &map->s_type_specific.s_metadata;
919
920 /* metadata address */
Jan Karabfb257a2008-04-08 20:37:21 +0200921 udf_debug("Metadata file location: block = %d part = %d\n",
Namjae Jeon3080a742011-10-23 19:28:32 +0900922 mdata->s_meta_file_loc, map->s_partition_num);
Jan Karabfb257a2008-04-08 20:37:21 +0200923
Namjae Jeon3080a742011-10-23 19:28:32 +0900924 mdata->s_metadata_fe = udf_find_metadata_inode_efe(sb,
925 mdata->s_meta_file_loc, map->s_partition_num);
Jan Karabfb257a2008-04-08 20:37:21 +0200926
927 if (mdata->s_metadata_fe == NULL) {
Namjae Jeon3080a742011-10-23 19:28:32 +0900928 /* mirror file entry */
929 udf_debug("Mirror metadata file location: block = %d part = %d\n",
930 mdata->s_mirror_file_loc, map->s_partition_num);
Jan Karabfb257a2008-04-08 20:37:21 +0200931
Namjae Jeon3080a742011-10-23 19:28:32 +0900932 mdata->s_mirror_fe = udf_find_metadata_inode_efe(sb,
933 mdata->s_mirror_file_loc, map->s_partition_num);
Jan Karabfb257a2008-04-08 20:37:21 +0200934
Namjae Jeon3080a742011-10-23 19:28:32 +0900935 if (mdata->s_mirror_fe == NULL) {
936 udf_err(sb, "Both metadata and mirror metadata inode efe can not found\n");
Jan Karabfb257a2008-04-08 20:37:21 +0200937 goto error_exit;
Namjae Jeon3080a742011-10-23 19:28:32 +0900938 }
Jan Karabfb257a2008-04-08 20:37:21 +0200939 }
940
941 /*
942 * bitmap file entry
943 * Note:
944 * Load only if bitmap file location differs from 0xFFFFFFFF (DCN-5102)
945 */
946 if (mdata->s_bitmap_file_loc != 0xFFFFFFFF) {
947 addr.logicalBlockNum = mdata->s_bitmap_file_loc;
948 addr.partitionReferenceNum = map->s_partition_num;
949
950 udf_debug("Bitmap file location: block = %d part = %d\n",
Joe Perchesa983f362011-10-10 01:08:07 -0700951 addr.logicalBlockNum, addr.partitionReferenceNum);
Jan Karabfb257a2008-04-08 20:37:21 +0200952
Pekka Enberg97e961f2008-10-15 12:29:03 +0200953 mdata->s_bitmap_fe = udf_iget(sb, &addr);
Jan Karabfb257a2008-04-08 20:37:21 +0200954
955 if (mdata->s_bitmap_fe == NULL) {
956 if (sb->s_flags & MS_RDONLY)
Joe Perchesa40ecd72011-10-10 01:08:04 -0700957 udf_warn(sb, "bitmap inode efe not found but it's ok since the disc is mounted read-only\n");
Jan Karabfb257a2008-04-08 20:37:21 +0200958 else {
Joe Perches8076c362011-10-10 01:08:03 -0700959 udf_err(sb, "bitmap inode efe not found and attempted read-write mount\n");
Jan Karabfb257a2008-04-08 20:37:21 +0200960 goto error_exit;
961 }
962 }
963 }
964
965 udf_debug("udf_load_metadata_files Ok\n");
966
967 return 0;
968
969error_exit:
970 return 1;
971}
972
Cyrill Gorcunov28de7942007-07-21 04:37:18 -0700973static void udf_load_fileset(struct super_block *sb, struct buffer_head *bh,
Pekka Enberg5ca4e4b2008-10-15 12:28:03 +0200974 struct kernel_lb_addr *root)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700975{
976 struct fileSetDesc *fset;
977
978 fset = (struct fileSetDesc *)bh->b_data;
979
980 *root = lelb_to_cpu(fset->rootDirectoryICB.extLocation);
981
Marcin Slusarz6c79e982008-02-08 04:20:30 -0800982 UDF_SB(sb)->s_serial_number = le16_to_cpu(fset->descTag.tagSerialNum);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700983
Cyrill Gorcunovcb00ea32007-07-19 01:47:43 -0700984 udf_debug("Rootdir at block=%d, partition=%d\n",
985 root->logicalBlockNum, root->partitionReferenceNum);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700986}
987
Marcin Slusarz883cb9d2008-02-08 04:20:34 -0800988int udf_compute_nr_groups(struct super_block *sb, u32 partition)
989{
990 struct udf_part_map *map = &UDF_SB(sb)->s_partmaps[partition];
Julia Lawall8dee00b2008-02-14 16:15:45 +0100991 return DIV_ROUND_UP(map->s_partition_len +
992 (sizeof(struct spaceBitmapDesc) << 3),
993 sb->s_blocksize * 8);
Marcin Slusarz883cb9d2008-02-08 04:20:34 -0800994}
995
Marcin Slusarz66e1da32008-02-08 04:20:33 -0800996static struct udf_bitmap *udf_sb_alloc_bitmap(struct super_block *sb, u32 index)
997{
Marcin Slusarz66e1da32008-02-08 04:20:33 -0800998 struct udf_bitmap *bitmap;
999 int nr_groups;
1000 int size;
1001
Marcin Slusarz883cb9d2008-02-08 04:20:34 -08001002 nr_groups = udf_compute_nr_groups(sb, index);
Marcin Slusarz66e1da32008-02-08 04:20:33 -08001003 size = sizeof(struct udf_bitmap) +
1004 (sizeof(struct buffer_head *) * nr_groups);
1005
1006 if (size <= PAGE_SIZE)
Joe Perchesed2ae6f2010-11-04 20:08:04 -07001007 bitmap = kzalloc(size, GFP_KERNEL);
Marcin Slusarz66e1da32008-02-08 04:20:33 -08001008 else
Joe Perchesed2ae6f2010-11-04 20:08:04 -07001009 bitmap = vzalloc(size); /* TODO: get rid of vzalloc */
Marcin Slusarz66e1da32008-02-08 04:20:33 -08001010
Joe Perches75b09e02012-01-31 14:42:10 -08001011 if (bitmap == NULL)
Marcin Slusarz66e1da32008-02-08 04:20:33 -08001012 return NULL;
Marcin Slusarz66e1da32008-02-08 04:20:33 -08001013
Marcin Slusarz66e1da32008-02-08 04:20:33 -08001014 bitmap->s_block_bitmap = (struct buffer_head **)(bitmap + 1);
1015 bitmap->s_nr_groups = nr_groups;
1016 return bitmap;
1017}
1018
Jan Kara3fb38df2008-04-02 12:26:36 +02001019static int udf_fill_partdesc_info(struct super_block *sb,
1020 struct partitionDesc *p, int p_index)
1021{
1022 struct udf_part_map *map;
1023 struct udf_sb_info *sbi = UDF_SB(sb);
1024 struct partitionHeaderDesc *phd;
1025
1026 map = &sbi->s_partmaps[p_index];
1027
1028 map->s_partition_len = le32_to_cpu(p->partitionLength); /* blocks */
1029 map->s_partition_root = le32_to_cpu(p->partitionStartingLocation);
1030
1031 if (p->accessType == cpu_to_le32(PD_ACCESS_TYPE_READ_ONLY))
1032 map->s_partition_flags |= UDF_PART_FLAG_READ_ONLY;
1033 if (p->accessType == cpu_to_le32(PD_ACCESS_TYPE_WRITE_ONCE))
1034 map->s_partition_flags |= UDF_PART_FLAG_WRITE_ONCE;
1035 if (p->accessType == cpu_to_le32(PD_ACCESS_TYPE_REWRITABLE))
1036 map->s_partition_flags |= UDF_PART_FLAG_REWRITABLE;
1037 if (p->accessType == cpu_to_le32(PD_ACCESS_TYPE_OVERWRITABLE))
1038 map->s_partition_flags |= UDF_PART_FLAG_OVERWRITABLE;
1039
Joe Perchesa983f362011-10-10 01:08:07 -07001040 udf_debug("Partition (%d type %x) starts at physical %d, block length %d\n",
1041 p_index, map->s_partition_type,
1042 map->s_partition_root, map->s_partition_len);
Jan Kara3fb38df2008-04-02 12:26:36 +02001043
1044 if (strcmp(p->partitionContents.ident, PD_PARTITION_CONTENTS_NSR02) &&
1045 strcmp(p->partitionContents.ident, PD_PARTITION_CONTENTS_NSR03))
1046 return 0;
1047
1048 phd = (struct partitionHeaderDesc *)p->partitionContentsUse;
1049 if (phd->unallocSpaceTable.extLength) {
Pekka Enberg5ca4e4b2008-10-15 12:28:03 +02001050 struct kernel_lb_addr loc = {
Jan Kara3fb38df2008-04-02 12:26:36 +02001051 .logicalBlockNum = le32_to_cpu(
1052 phd->unallocSpaceTable.extPosition),
1053 .partitionReferenceNum = p_index,
1054 };
1055
Pekka Enberg97e961f2008-10-15 12:29:03 +02001056 map->s_uspace.s_table = udf_iget(sb, &loc);
Jan Kara3fb38df2008-04-02 12:26:36 +02001057 if (!map->s_uspace.s_table) {
1058 udf_debug("cannot load unallocSpaceTable (part %d)\n",
Joe Perchesa983f362011-10-10 01:08:07 -07001059 p_index);
Jan Kara3fb38df2008-04-02 12:26:36 +02001060 return 1;
1061 }
1062 map->s_partition_flags |= UDF_PART_FLAG_UNALLOC_TABLE;
1063 udf_debug("unallocSpaceTable (part %d) @ %ld\n",
Joe Perchesa983f362011-10-10 01:08:07 -07001064 p_index, map->s_uspace.s_table->i_ino);
Jan Kara3fb38df2008-04-02 12:26:36 +02001065 }
1066
1067 if (phd->unallocSpaceBitmap.extLength) {
1068 struct udf_bitmap *bitmap = udf_sb_alloc_bitmap(sb, p_index);
1069 if (!bitmap)
1070 return 1;
1071 map->s_uspace.s_bitmap = bitmap;
1072 bitmap->s_extLength = le32_to_cpu(
1073 phd->unallocSpaceBitmap.extLength);
1074 bitmap->s_extPosition = le32_to_cpu(
1075 phd->unallocSpaceBitmap.extPosition);
1076 map->s_partition_flags |= UDF_PART_FLAG_UNALLOC_BITMAP;
Joe Perchesa983f362011-10-10 01:08:07 -07001077 udf_debug("unallocSpaceBitmap (part %d) @ %d\n",
1078 p_index, bitmap->s_extPosition);
Jan Kara3fb38df2008-04-02 12:26:36 +02001079 }
1080
1081 if (phd->partitionIntegrityTable.extLength)
1082 udf_debug("partitionIntegrityTable (part %d)\n", p_index);
1083
1084 if (phd->freedSpaceTable.extLength) {
Pekka Enberg5ca4e4b2008-10-15 12:28:03 +02001085 struct kernel_lb_addr loc = {
Jan Kara3fb38df2008-04-02 12:26:36 +02001086 .logicalBlockNum = le32_to_cpu(
1087 phd->freedSpaceTable.extPosition),
1088 .partitionReferenceNum = p_index,
1089 };
1090
Pekka Enberg97e961f2008-10-15 12:29:03 +02001091 map->s_fspace.s_table = udf_iget(sb, &loc);
Jan Kara3fb38df2008-04-02 12:26:36 +02001092 if (!map->s_fspace.s_table) {
1093 udf_debug("cannot load freedSpaceTable (part %d)\n",
Joe Perchesa983f362011-10-10 01:08:07 -07001094 p_index);
Jan Kara3fb38df2008-04-02 12:26:36 +02001095 return 1;
1096 }
1097
1098 map->s_partition_flags |= UDF_PART_FLAG_FREED_TABLE;
1099 udf_debug("freedSpaceTable (part %d) @ %ld\n",
Joe Perchesa983f362011-10-10 01:08:07 -07001100 p_index, map->s_fspace.s_table->i_ino);
Jan Kara3fb38df2008-04-02 12:26:36 +02001101 }
1102
1103 if (phd->freedSpaceBitmap.extLength) {
1104 struct udf_bitmap *bitmap = udf_sb_alloc_bitmap(sb, p_index);
1105 if (!bitmap)
1106 return 1;
1107 map->s_fspace.s_bitmap = bitmap;
1108 bitmap->s_extLength = le32_to_cpu(
1109 phd->freedSpaceBitmap.extLength);
1110 bitmap->s_extPosition = le32_to_cpu(
1111 phd->freedSpaceBitmap.extPosition);
1112 map->s_partition_flags |= UDF_PART_FLAG_FREED_BITMAP;
Joe Perchesa983f362011-10-10 01:08:07 -07001113 udf_debug("freedSpaceBitmap (part %d) @ %d\n",
1114 p_index, bitmap->s_extPosition);
Jan Kara3fb38df2008-04-02 12:26:36 +02001115 }
1116 return 0;
1117}
1118
Jan Karae971b0b2009-11-30 19:47:55 +01001119static void udf_find_vat_block(struct super_block *sb, int p_index,
1120 int type1_index, sector_t start_block)
1121{
1122 struct udf_sb_info *sbi = UDF_SB(sb);
1123 struct udf_part_map *map = &sbi->s_partmaps[p_index];
1124 sector_t vat_block;
1125 struct kernel_lb_addr ino;
1126
1127 /*
1128 * VAT file entry is in the last recorded block. Some broken disks have
1129 * it a few blocks before so try a bit harder...
1130 */
1131 ino.partitionReferenceNum = type1_index;
1132 for (vat_block = start_block;
1133 vat_block >= map->s_partition_root &&
1134 vat_block >= start_block - 3 &&
1135 !sbi->s_vat_inode; vat_block--) {
1136 ino.logicalBlockNum = vat_block - map->s_partition_root;
1137 sbi->s_vat_inode = udf_iget(sb, &ino);
1138 }
1139}
1140
Jan Kara38b74a52008-04-02 16:01:35 +02001141static int udf_load_vat(struct super_block *sb, int p_index, int type1_index)
1142{
1143 struct udf_sb_info *sbi = UDF_SB(sb);
1144 struct udf_part_map *map = &sbi->s_partmaps[p_index];
Jan Karafa5e0812008-04-08 02:08:53 +02001145 struct buffer_head *bh = NULL;
1146 struct udf_inode_info *vati;
1147 uint32_t pos;
1148 struct virtualAllocationTable20 *vat20;
Jan Kara4bf17af2009-07-14 19:30:23 +02001149 sector_t blocks = sb->s_bdev->bd_inode->i_size >> sb->s_blocksize_bits;
Jan Kara38b74a52008-04-02 16:01:35 +02001150
Jan Karae971b0b2009-11-30 19:47:55 +01001151 udf_find_vat_block(sb, p_index, type1_index, sbi->s_last_block);
Jan Kara4bf17af2009-07-14 19:30:23 +02001152 if (!sbi->s_vat_inode &&
1153 sbi->s_last_block != blocks - 1) {
Joe Perches78ace702011-10-10 01:08:05 -07001154 pr_notice("Failed to read VAT inode from the last recorded block (%lu), retrying with the last block of the device (%lu).\n",
1155 (unsigned long)sbi->s_last_block,
1156 (unsigned long)blocks - 1);
Jan Karae971b0b2009-11-30 19:47:55 +01001157 udf_find_vat_block(sb, p_index, type1_index, blocks - 1);
Jan Kara4bf17af2009-07-14 19:30:23 +02001158 }
Jan Kara38b74a52008-04-02 16:01:35 +02001159 if (!sbi->s_vat_inode)
1160 return 1;
1161
1162 if (map->s_partition_type == UDF_VIRTUAL_MAP15) {
Sebastian Manciulea47c93582008-04-14 17:06:36 +02001163 map->s_type_specific.s_virtual.s_start_offset = 0;
Jan Kara38b74a52008-04-02 16:01:35 +02001164 map->s_type_specific.s_virtual.s_num_entries =
1165 (sbi->s_vat_inode->i_size - 36) >> 2;
1166 } else if (map->s_partition_type == UDF_VIRTUAL_MAP20) {
Jan Karafa5e0812008-04-08 02:08:53 +02001167 vati = UDF_I(sbi->s_vat_inode);
1168 if (vati->i_alloc_type != ICBTAG_FLAG_AD_IN_ICB) {
1169 pos = udf_block_map(sbi->s_vat_inode, 0);
1170 bh = sb_bread(sb, pos);
1171 if (!bh)
1172 return 1;
1173 vat20 = (struct virtualAllocationTable20 *)bh->b_data;
1174 } else {
1175 vat20 = (struct virtualAllocationTable20 *)
1176 vati->i_ext.i_data;
1177 }
Jan Kara38b74a52008-04-02 16:01:35 +02001178
Jan Kara38b74a52008-04-02 16:01:35 +02001179 map->s_type_specific.s_virtual.s_start_offset =
Sebastian Manciulea47c93582008-04-14 17:06:36 +02001180 le16_to_cpu(vat20->lengthHeader);
Jan Kara38b74a52008-04-02 16:01:35 +02001181 map->s_type_specific.s_virtual.s_num_entries =
1182 (sbi->s_vat_inode->i_size -
1183 map->s_type_specific.s_virtual.
1184 s_start_offset) >> 2;
1185 brelse(bh);
1186 }
1187 return 0;
1188}
1189
Jan Karac0eb31e2008-04-01 16:50:35 +02001190static int udf_load_partdesc(struct super_block *sb, sector_t block)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001191{
Jan Karac0eb31e2008-04-01 16:50:35 +02001192 struct buffer_head *bh;
Jan Karac0eb31e2008-04-01 16:50:35 +02001193 struct partitionDesc *p;
Marcin Slusarz6c79e982008-02-08 04:20:30 -08001194 struct udf_part_map *map;
Marcin Slusarz165923f2008-02-10 11:33:08 +01001195 struct udf_sb_info *sbi = UDF_SB(sb);
Jan Kara38b74a52008-04-02 16:01:35 +02001196 int i, type1_idx;
Jan Karac0eb31e2008-04-01 16:50:35 +02001197 uint16_t partitionNumber;
1198 uint16_t ident;
1199 int ret = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001200
Jan Karac0eb31e2008-04-01 16:50:35 +02001201 bh = udf_read_tagged(sb, block, block, &ident);
1202 if (!bh)
1203 return 1;
1204 if (ident != TAG_IDENT_PD)
1205 goto out_bh;
1206
1207 p = (struct partitionDesc *)bh->b_data;
1208 partitionNumber = le16_to_cpu(p->partitionNumber);
Jan Kara38b74a52008-04-02 16:01:35 +02001209
Jan Karabfb257a2008-04-08 20:37:21 +02001210 /* First scan for TYPE1, SPARABLE and METADATA partitions */
Marcin Slusarz6c79e982008-02-08 04:20:30 -08001211 for (i = 0; i < sbi->s_partitions; i++) {
1212 map = &sbi->s_partmaps[i];
Cyrill Gorcunovcb00ea32007-07-19 01:47:43 -07001213 udf_debug("Searching map: (%d == %d)\n",
Marcin Slusarz165923f2008-02-10 11:33:08 +01001214 map->s_partition_num, partitionNumber);
Jan Kara38b74a52008-04-02 16:01:35 +02001215 if (map->s_partition_num == partitionNumber &&
1216 (map->s_partition_type == UDF_TYPE1_MAP15 ||
1217 map->s_partition_type == UDF_SPARABLE_MAP15))
Linus Torvalds1da177e2005-04-16 15:20:36 -07001218 break;
Marcin Slusarz165923f2008-02-10 11:33:08 +01001219 }
1220
Jan Kara38b74a52008-04-02 16:01:35 +02001221 if (i >= sbi->s_partitions) {
Marcin Slusarz165923f2008-02-10 11:33:08 +01001222 udf_debug("Partition (%d) not found in partition map\n",
1223 partitionNumber);
Jan Karac0eb31e2008-04-01 16:50:35 +02001224 goto out_bh;
Marcin Slusarz165923f2008-02-10 11:33:08 +01001225 }
1226
Jan Kara3fb38df2008-04-02 12:26:36 +02001227 ret = udf_fill_partdesc_info(sb, p, i);
Jan Kara38b74a52008-04-02 16:01:35 +02001228
1229 /*
Jan Karabfb257a2008-04-08 20:37:21 +02001230 * Now rescan for VIRTUAL or METADATA partitions when SPARABLE and
1231 * PHYSICAL partitions are already set up
Jan Kara38b74a52008-04-02 16:01:35 +02001232 */
1233 type1_idx = i;
1234 for (i = 0; i < sbi->s_partitions; i++) {
1235 map = &sbi->s_partmaps[i];
1236
1237 if (map->s_partition_num == partitionNumber &&
1238 (map->s_partition_type == UDF_VIRTUAL_MAP15 ||
Jan Karabfb257a2008-04-08 20:37:21 +02001239 map->s_partition_type == UDF_VIRTUAL_MAP20 ||
1240 map->s_partition_type == UDF_METADATA_MAP25))
Jan Kara38b74a52008-04-02 16:01:35 +02001241 break;
1242 }
1243
1244 if (i >= sbi->s_partitions)
1245 goto out_bh;
1246
1247 ret = udf_fill_partdesc_info(sb, p, i);
1248 if (ret)
1249 goto out_bh;
1250
Jan Karabfb257a2008-04-08 20:37:21 +02001251 if (map->s_partition_type == UDF_METADATA_MAP25) {
1252 ret = udf_load_metadata_files(sb, i);
1253 if (ret) {
Joe Perches78ace702011-10-10 01:08:05 -07001254 udf_err(sb, "error loading MetaData partition map %d\n",
1255 i);
Jan Karabfb257a2008-04-08 20:37:21 +02001256 goto out_bh;
1257 }
1258 } else {
1259 ret = udf_load_vat(sb, i, type1_idx);
1260 if (ret)
1261 goto out_bh;
1262 /*
1263 * Mark filesystem read-only if we have a partition with
1264 * virtual map since we don't handle writing to it (we
1265 * overwrite blocks instead of relocating them).
1266 */
1267 sb->s_flags |= MS_RDONLY;
Joe Perches78ace702011-10-10 01:08:05 -07001268 pr_notice("Filesystem marked read-only because writing to pseudooverwrite partition is not implemented\n");
Jan Karabfb257a2008-04-08 20:37:21 +02001269 }
Jan Karac0eb31e2008-04-01 16:50:35 +02001270out_bh:
Jan Kara2e0838f2008-04-01 18:08:51 +02001271 /* In case loading failed, we handle cleanup in udf_fill_super */
Jan Karac0eb31e2008-04-01 16:50:35 +02001272 brelse(bh);
1273 return ret;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001274}
1275
Jan Kara1df2ae32012-06-27 21:23:07 +02001276static int udf_load_sparable_map(struct super_block *sb,
1277 struct udf_part_map *map,
1278 struct sparablePartitionMap *spm)
1279{
1280 uint32_t loc;
1281 uint16_t ident;
1282 struct sparingTable *st;
1283 struct udf_sparing_data *sdata = &map->s_type_specific.s_sparing;
1284 int i;
1285 struct buffer_head *bh;
1286
1287 map->s_partition_type = UDF_SPARABLE_MAP15;
1288 sdata->s_packet_len = le16_to_cpu(spm->packetLength);
1289 if (!is_power_of_2(sdata->s_packet_len)) {
1290 udf_err(sb, "error loading logical volume descriptor: "
1291 "Invalid packet length %u\n",
1292 (unsigned)sdata->s_packet_len);
1293 return -EIO;
1294 }
1295 if (spm->numSparingTables > 4) {
1296 udf_err(sb, "error loading logical volume descriptor: "
1297 "Too many sparing tables (%d)\n",
1298 (int)spm->numSparingTables);
1299 return -EIO;
1300 }
1301
1302 for (i = 0; i < spm->numSparingTables; i++) {
1303 loc = le32_to_cpu(spm->locSparingTable[i]);
1304 bh = udf_read_tagged(sb, loc, loc, &ident);
1305 if (!bh)
1306 continue;
1307
1308 st = (struct sparingTable *)bh->b_data;
1309 if (ident != 0 ||
1310 strncmp(st->sparingIdent.ident, UDF_ID_SPARING,
1311 strlen(UDF_ID_SPARING)) ||
1312 sizeof(*st) + le16_to_cpu(st->reallocationTableLen) >
1313 sb->s_blocksize) {
1314 brelse(bh);
1315 continue;
1316 }
1317
1318 sdata->s_spar_map[i] = bh;
1319 }
1320 map->s_partition_func = udf_get_pblock_spar15;
1321 return 0;
1322}
1323
Jan Karac0eb31e2008-04-01 16:50:35 +02001324static int udf_load_logicalvol(struct super_block *sb, sector_t block,
Pekka Enberg5ca4e4b2008-10-15 12:28:03 +02001325 struct kernel_lb_addr *fileset)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001326{
1327 struct logicalVolDesc *lvd;
Jan Kara1df2ae32012-06-27 21:23:07 +02001328 int i, offset;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001329 uint8_t type;
Marcin Slusarz6c79e982008-02-08 04:20:30 -08001330 struct udf_sb_info *sbi = UDF_SB(sb);
Marcin Slusarz4b111112008-02-08 04:20:36 -08001331 struct genericPartitionMap *gpm;
Jan Karac0eb31e2008-04-01 16:50:35 +02001332 uint16_t ident;
1333 struct buffer_head *bh;
Jan Karaadee11b2012-06-27 20:20:22 +02001334 unsigned int table_len;
Jan Karac0eb31e2008-04-01 16:50:35 +02001335 int ret = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001336
Jan Karac0eb31e2008-04-01 16:50:35 +02001337 bh = udf_read_tagged(sb, block, block, &ident);
1338 if (!bh)
1339 return 1;
1340 BUG_ON(ident != TAG_IDENT_LVD);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001341 lvd = (struct logicalVolDesc *)bh->b_data;
Jan Karaadee11b2012-06-27 20:20:22 +02001342 table_len = le32_to_cpu(lvd->mapTableLength);
Jan Kara57b96552012-07-10 17:58:04 +02001343 if (table_len > sb->s_blocksize - sizeof(*lvd)) {
Jan Karaadee11b2012-06-27 20:20:22 +02001344 udf_err(sb, "error loading logical volume descriptor: "
1345 "Partition table too long (%u > %lu)\n", table_len,
1346 sb->s_blocksize - sizeof(*lvd));
Nikola Pajkovsky68766a22012-08-15 00:38:08 +02001347 ret = 1;
Jan Karaadee11b2012-06-27 20:20:22 +02001348 goto out_bh;
1349 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001350
Jan Karacb14d342012-06-27 20:08:44 +02001351 ret = udf_sb_alloc_partition_maps(sb, le32_to_cpu(lvd->numPartitionMaps));
1352 if (ret)
Jan Karac0eb31e2008-04-01 16:50:35 +02001353 goto out_bh;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001354
Cyrill Gorcunovcb00ea32007-07-19 01:47:43 -07001355 for (i = 0, offset = 0;
Jan Karaadee11b2012-06-27 20:20:22 +02001356 i < sbi->s_partitions && offset < table_len;
Marcin Slusarz4b111112008-02-08 04:20:36 -08001357 i++, offset += gpm->partitionMapLength) {
1358 struct udf_part_map *map = &sbi->s_partmaps[i];
1359 gpm = (struct genericPartitionMap *)
1360 &(lvd->partitionMaps[offset]);
1361 type = gpm->partitionMapType;
Cyrill Gorcunovcb00ea32007-07-19 01:47:43 -07001362 if (type == 1) {
Marcin Slusarz4b111112008-02-08 04:20:36 -08001363 struct genericPartitionMap1 *gpm1 =
1364 (struct genericPartitionMap1 *)gpm;
Marcin Slusarz6c79e982008-02-08 04:20:30 -08001365 map->s_partition_type = UDF_TYPE1_MAP15;
1366 map->s_volumeseqnum = le16_to_cpu(gpm1->volSeqNum);
1367 map->s_partition_num = le16_to_cpu(gpm1->partitionNum);
1368 map->s_partition_func = NULL;
Cyrill Gorcunovcb00ea32007-07-19 01:47:43 -07001369 } else if (type == 2) {
Marcin Slusarz4b111112008-02-08 04:20:36 -08001370 struct udfPartitionMap2 *upm2 =
1371 (struct udfPartitionMap2 *)gpm;
1372 if (!strncmp(upm2->partIdent.ident, UDF_ID_VIRTUAL,
1373 strlen(UDF_ID_VIRTUAL))) {
1374 u16 suf =
1375 le16_to_cpu(((__le16 *)upm2->partIdent.
1376 identSuffix)[0]);
Jan Karac82a1272008-04-08 01:16:32 +02001377 if (suf < 0x0200) {
Marcin Slusarz4b111112008-02-08 04:20:36 -08001378 map->s_partition_type =
1379 UDF_VIRTUAL_MAP15;
1380 map->s_partition_func =
1381 udf_get_pblock_virt15;
Jan Karac82a1272008-04-08 01:16:32 +02001382 } else {
Marcin Slusarz4b111112008-02-08 04:20:36 -08001383 map->s_partition_type =
1384 UDF_VIRTUAL_MAP20;
1385 map->s_partition_func =
1386 udf_get_pblock_virt20;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001387 }
Marcin Slusarz4b111112008-02-08 04:20:36 -08001388 } else if (!strncmp(upm2->partIdent.ident,
1389 UDF_ID_SPARABLE,
1390 strlen(UDF_ID_SPARABLE))) {
Jan Kara1df2ae32012-06-27 21:23:07 +02001391 if (udf_load_sparable_map(sb, map,
Nikola Pajkovsky68766a22012-08-15 00:38:08 +02001392 (struct sparablePartitionMap *)gpm) < 0) {
1393 ret = 1;
Jan Kara1df2ae32012-06-27 21:23:07 +02001394 goto out_bh;
Nikola Pajkovsky68766a22012-08-15 00:38:08 +02001395 }
Jan Karabfb257a2008-04-08 20:37:21 +02001396 } else if (!strncmp(upm2->partIdent.ident,
1397 UDF_ID_METADATA,
1398 strlen(UDF_ID_METADATA))) {
1399 struct udf_meta_data *mdata =
1400 &map->s_type_specific.s_metadata;
1401 struct metadataPartitionMap *mdm =
1402 (struct metadataPartitionMap *)
1403 &(lvd->partitionMaps[offset]);
Joe Perchesa983f362011-10-10 01:08:07 -07001404 udf_debug("Parsing Logical vol part %d type %d id=%s\n",
1405 i, type, UDF_ID_METADATA);
Jan Karabfb257a2008-04-08 20:37:21 +02001406
1407 map->s_partition_type = UDF_METADATA_MAP25;
1408 map->s_partition_func = udf_get_pblock_meta25;
1409
1410 mdata->s_meta_file_loc =
1411 le32_to_cpu(mdm->metadataFileLoc);
1412 mdata->s_mirror_file_loc =
1413 le32_to_cpu(mdm->metadataMirrorFileLoc);
1414 mdata->s_bitmap_file_loc =
1415 le32_to_cpu(mdm->metadataBitmapFileLoc);
1416 mdata->s_alloc_unit_size =
1417 le32_to_cpu(mdm->allocUnitSize);
1418 mdata->s_align_unit_size =
1419 le16_to_cpu(mdm->alignUnitSize);
Jan Karaed47a7d2011-10-24 16:47:48 +02001420 if (mdm->flags & 0x01)
1421 mdata->s_flags |= MF_DUPLICATE_MD;
Jan Karabfb257a2008-04-08 20:37:21 +02001422
1423 udf_debug("Metadata Ident suffix=0x%x\n",
Joe Perchesa983f362011-10-10 01:08:07 -07001424 le16_to_cpu(*(__le16 *)
1425 mdm->partIdent.identSuffix));
Jan Karabfb257a2008-04-08 20:37:21 +02001426 udf_debug("Metadata part num=%d\n",
Joe Perchesa983f362011-10-10 01:08:07 -07001427 le16_to_cpu(mdm->partitionNum));
Jan Karabfb257a2008-04-08 20:37:21 +02001428 udf_debug("Metadata part alloc unit size=%d\n",
Joe Perchesa983f362011-10-10 01:08:07 -07001429 le32_to_cpu(mdm->allocUnitSize));
Jan Karabfb257a2008-04-08 20:37:21 +02001430 udf_debug("Metadata file loc=%d\n",
Joe Perchesa983f362011-10-10 01:08:07 -07001431 le32_to_cpu(mdm->metadataFileLoc));
Jan Karabfb257a2008-04-08 20:37:21 +02001432 udf_debug("Mirror file loc=%d\n",
Joe Perchesa983f362011-10-10 01:08:07 -07001433 le32_to_cpu(mdm->metadataMirrorFileLoc));
Jan Karabfb257a2008-04-08 20:37:21 +02001434 udf_debug("Bitmap file loc=%d\n",
Joe Perchesa983f362011-10-10 01:08:07 -07001435 le32_to_cpu(mdm->metadataBitmapFileLoc));
Jan Karaed47a7d2011-10-24 16:47:48 +02001436 udf_debug("Flags: %d %d\n",
1437 mdata->s_flags, mdm->flags);
Cyrill Gorcunovcb00ea32007-07-19 01:47:43 -07001438 } else {
Marcin Slusarz3a71fc52008-02-08 04:20:28 -08001439 udf_debug("Unknown ident: %s\n",
1440 upm2->partIdent.ident);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001441 continue;
1442 }
Marcin Slusarz6c79e982008-02-08 04:20:30 -08001443 map->s_volumeseqnum = le16_to_cpu(upm2->volSeqNum);
1444 map->s_partition_num = le16_to_cpu(upm2->partitionNum);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001445 }
1446 udf_debug("Partition (%d:%d) type %d on volume %d\n",
Joe Perchesa983f362011-10-10 01:08:07 -07001447 i, map->s_partition_num, type, map->s_volumeseqnum);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001448 }
1449
Cyrill Gorcunovcb00ea32007-07-19 01:47:43 -07001450 if (fileset) {
Pekka Enberg5ca4e4b2008-10-15 12:28:03 +02001451 struct long_ad *la = (struct long_ad *)&(lvd->logicalVolContentsUse[0]);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001452
1453 *fileset = lelb_to_cpu(la->extLocation);
Joe Perchesa983f362011-10-10 01:08:07 -07001454 udf_debug("FileSet found in LogicalVolDesc at block=%d, partition=%d\n",
1455 fileset->logicalBlockNum,
Cyrill Gorcunov28de7942007-07-21 04:37:18 -07001456 fileset->partitionReferenceNum);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001457 }
1458 if (lvd->integritySeqExt.extLength)
1459 udf_load_logicalvolint(sb, leea_to_cpu(lvd->integritySeqExt));
Cyrill Gorcunov28de7942007-07-21 04:37:18 -07001460
Jan Karac0eb31e2008-04-01 16:50:35 +02001461out_bh:
1462 brelse(bh);
1463 return ret;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001464}
1465
1466/*
1467 * udf_load_logicalvolint
1468 *
1469 */
Pekka Enberg5ca4e4b2008-10-15 12:28:03 +02001470static void udf_load_logicalvolint(struct super_block *sb, struct kernel_extent_ad loc)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001471{
1472 struct buffer_head *bh = NULL;
1473 uint16_t ident;
Marcin Slusarz6c79e982008-02-08 04:20:30 -08001474 struct udf_sb_info *sbi = UDF_SB(sb);
1475 struct logicalVolIntegrityDesc *lvid;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001476
1477 while (loc.extLength > 0 &&
Cyrill Gorcunovcb00ea32007-07-19 01:47:43 -07001478 (bh = udf_read_tagged(sb, loc.extLocation,
1479 loc.extLocation, &ident)) &&
1480 ident == TAG_IDENT_LVID) {
Marcin Slusarz6c79e982008-02-08 04:20:30 -08001481 sbi->s_lvid_bh = bh;
1482 lvid = (struct logicalVolIntegrityDesc *)bh->b_data;
Cyrill Gorcunovcb00ea32007-07-19 01:47:43 -07001483
Marcin Slusarz6c79e982008-02-08 04:20:30 -08001484 if (lvid->nextIntegrityExt.extLength)
Marcin Slusarz3a71fc52008-02-08 04:20:28 -08001485 udf_load_logicalvolint(sb,
Marcin Slusarz6c79e982008-02-08 04:20:30 -08001486 leea_to_cpu(lvid->nextIntegrityExt));
Cyrill Gorcunovcb00ea32007-07-19 01:47:43 -07001487
Marcin Slusarz6c79e982008-02-08 04:20:30 -08001488 if (sbi->s_lvid_bh != bh)
Jan Kara3bf25cb2007-05-08 00:35:16 -07001489 brelse(bh);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001490 loc.extLength -= sb->s_blocksize;
Cyrill Gorcunovcb00ea32007-07-19 01:47:43 -07001491 loc.extLocation++;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001492 }
Marcin Slusarz6c79e982008-02-08 04:20:30 -08001493 if (sbi->s_lvid_bh != bh)
Jan Kara3bf25cb2007-05-08 00:35:16 -07001494 brelse(bh);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001495}
1496
1497/*
1498 * udf_process_sequence
1499 *
1500 * PURPOSE
1501 * Process a main/reserve volume descriptor sequence.
1502 *
1503 * PRE-CONDITIONS
1504 * sb Pointer to _locked_ superblock.
1505 * block First block of first extent of the sequence.
1506 * lastblock Lastblock of first extent of the sequence.
1507 *
1508 * HISTORY
1509 * July 1, 1997 - Andrew E. Mileski
1510 * Written, tested, and released.
1511 */
Jan Kara200a3592008-03-04 13:03:09 +01001512static noinline int udf_process_sequence(struct super_block *sb, long block,
Pekka Enberg5ca4e4b2008-10-15 12:28:03 +02001513 long lastblock, struct kernel_lb_addr *fileset)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001514{
1515 struct buffer_head *bh = NULL;
1516 struct udf_vds_record vds[VDS_POS_LENGTH];
Marcin Slusarz4b111112008-02-08 04:20:36 -08001517 struct udf_vds_record *curr;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001518 struct generic_desc *gd;
1519 struct volDescPtr *vdp;
Cyrill Gorcunovcb00ea32007-07-19 01:47:43 -07001520 int done = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001521 uint32_t vdsn;
1522 uint16_t ident;
1523 long next_s = 0, next_e = 0;
1524
1525 memset(vds, 0, sizeof(struct udf_vds_record) * VDS_POS_LENGTH);
1526
Jan Karac0eb31e2008-04-01 16:50:35 +02001527 /*
1528 * Read the main descriptor sequence and find which descriptors
1529 * are in it.
1530 */
Cyrill Gorcunovcb00ea32007-07-19 01:47:43 -07001531 for (; (!done && block <= lastblock); block++) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001532
1533 bh = udf_read_tagged(sb, block, block, &ident);
Jan Karac0eb31e2008-04-01 16:50:35 +02001534 if (!bh) {
Joe Perches78ace702011-10-10 01:08:05 -07001535 udf_err(sb,
1536 "Block %llu of volume descriptor sequence is corrupted or we could not read it\n",
1537 (unsigned long long)block);
Jan Karac0eb31e2008-04-01 16:50:35 +02001538 return 1;
1539 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001540
1541 /* Process each descriptor (ISO 13346 3/8.3-8.4) */
1542 gd = (struct generic_desc *)bh->b_data;
1543 vdsn = le32_to_cpu(gd->volDescSeqNum);
Cyrill Gorcunovcb00ea32007-07-19 01:47:43 -07001544 switch (ident) {
Cyrill Gorcunov28de7942007-07-21 04:37:18 -07001545 case TAG_IDENT_PVD: /* ISO 13346 3/10.1 */
Marcin Slusarz4b111112008-02-08 04:20:36 -08001546 curr = &vds[VDS_POS_PRIMARY_VOL_DESC];
1547 if (vdsn >= curr->volDescSeqNum) {
1548 curr->volDescSeqNum = vdsn;
1549 curr->block = block;
Cyrill Gorcunovcb00ea32007-07-19 01:47:43 -07001550 }
1551 break;
Cyrill Gorcunov28de7942007-07-21 04:37:18 -07001552 case TAG_IDENT_VDP: /* ISO 13346 3/10.3 */
Marcin Slusarz4b111112008-02-08 04:20:36 -08001553 curr = &vds[VDS_POS_VOL_DESC_PTR];
1554 if (vdsn >= curr->volDescSeqNum) {
1555 curr->volDescSeqNum = vdsn;
1556 curr->block = block;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001557
Cyrill Gorcunovcb00ea32007-07-19 01:47:43 -07001558 vdp = (struct volDescPtr *)bh->b_data;
Marcin Slusarz4b111112008-02-08 04:20:36 -08001559 next_s = le32_to_cpu(
1560 vdp->nextVolDescSeqExt.extLocation);
1561 next_e = le32_to_cpu(
1562 vdp->nextVolDescSeqExt.extLength);
Cyrill Gorcunovcb00ea32007-07-19 01:47:43 -07001563 next_e = next_e >> sb->s_blocksize_bits;
1564 next_e += next_s;
1565 }
1566 break;
Cyrill Gorcunov28de7942007-07-21 04:37:18 -07001567 case TAG_IDENT_IUVD: /* ISO 13346 3/10.4 */
Marcin Slusarz4b111112008-02-08 04:20:36 -08001568 curr = &vds[VDS_POS_IMP_USE_VOL_DESC];
1569 if (vdsn >= curr->volDescSeqNum) {
1570 curr->volDescSeqNum = vdsn;
1571 curr->block = block;
Cyrill Gorcunovcb00ea32007-07-19 01:47:43 -07001572 }
1573 break;
Cyrill Gorcunov28de7942007-07-21 04:37:18 -07001574 case TAG_IDENT_PD: /* ISO 13346 3/10.5 */
Marcin Slusarz4b111112008-02-08 04:20:36 -08001575 curr = &vds[VDS_POS_PARTITION_DESC];
1576 if (!curr->block)
1577 curr->block = block;
Cyrill Gorcunovcb00ea32007-07-19 01:47:43 -07001578 break;
Cyrill Gorcunov28de7942007-07-21 04:37:18 -07001579 case TAG_IDENT_LVD: /* ISO 13346 3/10.6 */
Marcin Slusarz4b111112008-02-08 04:20:36 -08001580 curr = &vds[VDS_POS_LOGICAL_VOL_DESC];
1581 if (vdsn >= curr->volDescSeqNum) {
1582 curr->volDescSeqNum = vdsn;
1583 curr->block = block;
Cyrill Gorcunovcb00ea32007-07-19 01:47:43 -07001584 }
1585 break;
Cyrill Gorcunov28de7942007-07-21 04:37:18 -07001586 case TAG_IDENT_USD: /* ISO 13346 3/10.8 */
Marcin Slusarz4b111112008-02-08 04:20:36 -08001587 curr = &vds[VDS_POS_UNALLOC_SPACE_DESC];
1588 if (vdsn >= curr->volDescSeqNum) {
1589 curr->volDescSeqNum = vdsn;
1590 curr->block = block;
Cyrill Gorcunovcb00ea32007-07-19 01:47:43 -07001591 }
1592 break;
Cyrill Gorcunov28de7942007-07-21 04:37:18 -07001593 case TAG_IDENT_TD: /* ISO 13346 3/10.9 */
Cyrill Gorcunovcb00ea32007-07-19 01:47:43 -07001594 vds[VDS_POS_TERMINATING_DESC].block = block;
1595 if (next_e) {
1596 block = next_s;
1597 lastblock = next_e;
1598 next_s = next_e = 0;
Marcin Slusarz4b111112008-02-08 04:20:36 -08001599 } else
Cyrill Gorcunovcb00ea32007-07-19 01:47:43 -07001600 done = 1;
1601 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001602 }
Jan Kara3bf25cb2007-05-08 00:35:16 -07001603 brelse(bh);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001604 }
Jan Karac0eb31e2008-04-01 16:50:35 +02001605 /*
1606 * Now read interesting descriptors again and process them
1607 * in a suitable order
1608 */
1609 if (!vds[VDS_POS_PRIMARY_VOL_DESC].block) {
Joe Perches78ace702011-10-10 01:08:05 -07001610 udf_err(sb, "Primary Volume Descriptor not found!\n");
Jan Karac0eb31e2008-04-01 16:50:35 +02001611 return 1;
1612 }
1613 if (udf_load_pvoldesc(sb, vds[VDS_POS_PRIMARY_VOL_DESC].block))
1614 return 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001615
Jan Karac0eb31e2008-04-01 16:50:35 +02001616 if (vds[VDS_POS_LOGICAL_VOL_DESC].block && udf_load_logicalvol(sb,
1617 vds[VDS_POS_LOGICAL_VOL_DESC].block, fileset))
1618 return 1;
Marcin Slusarz165923f2008-02-10 11:33:08 +01001619
Jan Karac0eb31e2008-04-01 16:50:35 +02001620 if (vds[VDS_POS_PARTITION_DESC].block) {
1621 /*
1622 * We rescan the whole descriptor sequence to find
1623 * partition descriptor blocks and process them.
1624 */
1625 for (block = vds[VDS_POS_PARTITION_DESC].block;
1626 block < vds[VDS_POS_TERMINATING_DESC].block;
1627 block++)
1628 if (udf_load_partdesc(sb, block))
Marcin Slusarz165923f2008-02-10 11:33:08 +01001629 return 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001630 }
1631
1632 return 0;
1633}
1634
Jan Kara40346002009-03-19 16:21:38 +01001635static int udf_load_sequence(struct super_block *sb, struct buffer_head *bh,
1636 struct kernel_lb_addr *fileset)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001637{
Jan Kara40346002009-03-19 16:21:38 +01001638 struct anchorVolDescPtr *anchor;
1639 long main_s, main_e, reserve_s, reserve_e;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001640
Jan Kara40346002009-03-19 16:21:38 +01001641 anchor = (struct anchorVolDescPtr *)bh->b_data;
1642
1643 /* Locate the main sequence */
1644 main_s = le32_to_cpu(anchor->mainVolDescSeqExt.extLocation);
1645 main_e = le32_to_cpu(anchor->mainVolDescSeqExt.extLength);
1646 main_e = main_e >> sb->s_blocksize_bits;
1647 main_e += main_s;
1648
1649 /* Locate the reserve sequence */
1650 reserve_s = le32_to_cpu(anchor->reserveVolDescSeqExt.extLocation);
1651 reserve_e = le32_to_cpu(anchor->reserveVolDescSeqExt.extLength);
1652 reserve_e = reserve_e >> sb->s_blocksize_bits;
1653 reserve_e += reserve_s;
1654
1655 /* Process the main & reserve sequences */
1656 /* responsible for finding the PartitionDesc(s) */
1657 if (!udf_process_sequence(sb, main_s, main_e, fileset))
1658 return 1;
Jan Karabff943a2012-06-27 22:27:05 +02001659 udf_sb_free_partitions(sb);
1660 if (!udf_process_sequence(sb, reserve_s, reserve_e, fileset))
1661 return 1;
1662 udf_sb_free_partitions(sb);
1663 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001664}
1665
Jan Kara40346002009-03-19 16:21:38 +01001666/*
1667 * Check whether there is an anchor block in the given block and
1668 * load Volume Descriptor Sequence if so.
1669 */
1670static int udf_check_anchor_block(struct super_block *sb, sector_t block,
1671 struct kernel_lb_addr *fileset)
1672{
1673 struct buffer_head *bh;
1674 uint16_t ident;
1675 int ret;
1676
1677 if (UDF_QUERY_FLAG(sb, UDF_FLAG_VARCONV) &&
1678 udf_fixed_to_variable(block) >=
1679 sb->s_bdev->bd_inode->i_size >> sb->s_blocksize_bits)
1680 return 0;
1681
1682 bh = udf_read_tagged(sb, block, block, &ident);
1683 if (!bh)
1684 return 0;
1685 if (ident != TAG_IDENT_AVDP) {
1686 brelse(bh);
1687 return 0;
1688 }
1689 ret = udf_load_sequence(sb, bh, fileset);
1690 brelse(bh);
1691 return ret;
1692}
1693
1694/* Search for an anchor volume descriptor pointer */
1695static sector_t udf_scan_anchors(struct super_block *sb, sector_t lastblock,
1696 struct kernel_lb_addr *fileset)
1697{
1698 sector_t last[6];
1699 int i;
1700 struct udf_sb_info *sbi = UDF_SB(sb);
1701 int last_count = 0;
1702
1703 /* First try user provided anchor */
1704 if (sbi->s_anchor) {
1705 if (udf_check_anchor_block(sb, sbi->s_anchor, fileset))
1706 return lastblock;
1707 }
1708 /*
1709 * according to spec, anchor is in either:
1710 * block 256
1711 * lastblock-256
1712 * lastblock
1713 * however, if the disc isn't closed, it could be 512.
1714 */
1715 if (udf_check_anchor_block(sb, sbi->s_session + 256, fileset))
1716 return lastblock;
1717 /*
1718 * The trouble is which block is the last one. Drives often misreport
1719 * this so we try various possibilities.
1720 */
1721 last[last_count++] = lastblock;
1722 if (lastblock >= 1)
1723 last[last_count++] = lastblock - 1;
1724 last[last_count++] = lastblock + 1;
1725 if (lastblock >= 2)
1726 last[last_count++] = lastblock - 2;
1727 if (lastblock >= 150)
1728 last[last_count++] = lastblock - 150;
1729 if (lastblock >= 152)
1730 last[last_count++] = lastblock - 152;
1731
1732 for (i = 0; i < last_count; i++) {
1733 if (last[i] >= sb->s_bdev->bd_inode->i_size >>
1734 sb->s_blocksize_bits)
1735 continue;
1736 if (udf_check_anchor_block(sb, last[i], fileset))
1737 return last[i];
1738 if (last[i] < 256)
1739 continue;
1740 if (udf_check_anchor_block(sb, last[i] - 256, fileset))
1741 return last[i];
1742 }
1743
1744 /* Finally try block 512 in case media is open */
1745 if (udf_check_anchor_block(sb, sbi->s_session + 512, fileset))
1746 return last[0];
1747 return 0;
1748}
1749
1750/*
1751 * Find an anchor volume descriptor and load Volume Descriptor Sequence from
1752 * area specified by it. The function expects sbi->s_lastblock to be the last
1753 * block on the media.
1754 *
1755 * Return 1 if ok, 0 if not found.
1756 *
1757 */
1758static int udf_find_anchor(struct super_block *sb,
1759 struct kernel_lb_addr *fileset)
1760{
1761 sector_t lastblock;
1762 struct udf_sb_info *sbi = UDF_SB(sb);
1763
1764 lastblock = udf_scan_anchors(sb, sbi->s_last_block, fileset);
1765 if (lastblock)
1766 goto out;
1767
1768 /* No anchor found? Try VARCONV conversion of block numbers */
1769 UDF_SET_FLAG(sb, UDF_FLAG_VARCONV);
1770 /* Firstly, we try to not convert number of the last block */
1771 lastblock = udf_scan_anchors(sb,
1772 udf_variable_to_fixed(sbi->s_last_block),
1773 fileset);
1774 if (lastblock)
1775 goto out;
1776
1777 /* Secondly, we try with converted number of the last block */
1778 lastblock = udf_scan_anchors(sb, sbi->s_last_block, fileset);
1779 if (!lastblock) {
1780 /* VARCONV didn't help. Clear it. */
1781 UDF_CLEAR_FLAG(sb, UDF_FLAG_VARCONV);
1782 return 0;
1783 }
1784out:
1785 sbi->s_last_block = lastblock;
1786 return 1;
1787}
1788
1789/*
1790 * Check Volume Structure Descriptor, find Anchor block and load Volume
1791 * Descriptor Sequence
1792 */
1793static int udf_load_vrs(struct super_block *sb, struct udf_options *uopt,
1794 int silent, struct kernel_lb_addr *fileset)
Clemens Ladisch1197e4d2009-03-11 15:57:47 +01001795{
1796 struct udf_sb_info *sbi = UDF_SB(sb);
Jan Kara40346002009-03-19 16:21:38 +01001797 loff_t nsr_off;
Clemens Ladisch1197e4d2009-03-11 15:57:47 +01001798
1799 if (!sb_set_blocksize(sb, uopt->blocksize)) {
1800 if (!silent)
Joe Perches78ace702011-10-10 01:08:05 -07001801 udf_warn(sb, "Bad block size\n");
Clemens Ladisch1197e4d2009-03-11 15:57:47 +01001802 return 0;
1803 }
1804 sbi->s_last_block = uopt->lastblock;
Jan Kara40346002009-03-19 16:21:38 +01001805 if (!uopt->novrs) {
1806 /* Check that it is NSR02 compliant */
1807 nsr_off = udf_check_vsd(sb);
1808 if (!nsr_off) {
1809 if (!silent)
Joe Perches78ace702011-10-10 01:08:05 -07001810 udf_warn(sb, "No VRS found\n");
Jan Kara40346002009-03-19 16:21:38 +01001811 return 0;
1812 }
1813 if (nsr_off == -1)
Joe Perchesa983f362011-10-10 01:08:07 -07001814 udf_debug("Failed to read byte 32768. Assuming open disc. Skipping validity check\n");
Jan Kara40346002009-03-19 16:21:38 +01001815 if (!sbi->s_last_block)
1816 sbi->s_last_block = udf_get_last_block(sb);
1817 } else {
1818 udf_debug("Validity check skipped because of novrs option\n");
Clemens Ladisch1197e4d2009-03-11 15:57:47 +01001819 }
Jan Kara40346002009-03-19 16:21:38 +01001820
1821 /* Look for anchor block and load Volume Descriptor Sequence */
1822 sbi->s_anchor = uopt->anchor;
1823 if (!udf_find_anchor(sb, fileset)) {
Clemens Ladisch1197e4d2009-03-11 15:57:47 +01001824 if (!silent)
Joe Perches78ace702011-10-10 01:08:05 -07001825 udf_warn(sb, "No anchor found\n");
Clemens Ladisch1197e4d2009-03-11 15:57:47 +01001826 return 0;
1827 }
1828 return 1;
1829}
1830
Linus Torvalds1da177e2005-04-16 15:20:36 -07001831static void udf_open_lvid(struct super_block *sb)
1832{
Marcin Slusarz6c79e982008-02-08 04:20:30 -08001833 struct udf_sb_info *sbi = UDF_SB(sb);
1834 struct buffer_head *bh = sbi->s_lvid_bh;
Marcin Slusarz165923f2008-02-10 11:33:08 +01001835 struct logicalVolIntegrityDesc *lvid;
1836 struct logicalVolIntegrityDescImpUse *lvidiu;
Jan Kara146bca72009-03-16 18:27:37 +01001837
Marcin Slusarz165923f2008-02-10 11:33:08 +01001838 if (!bh)
1839 return;
Jan Kara949f4a72010-10-20 18:49:20 +02001840
1841 mutex_lock(&sbi->s_alloc_mutex);
Marcin Slusarz165923f2008-02-10 11:33:08 +01001842 lvid = (struct logicalVolIntegrityDesc *)bh->b_data;
1843 lvidiu = udf_sb_lvidiu(sbi);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001844
Marcin Slusarz165923f2008-02-10 11:33:08 +01001845 lvidiu->impIdent.identSuffix[0] = UDF_OS_CLASS_UNIX;
1846 lvidiu->impIdent.identSuffix[1] = UDF_OS_ID_LINUX;
1847 udf_time_to_disk_stamp(&lvid->recordingDateAndTime,
1848 CURRENT_TIME);
Jan Kara146bca72009-03-16 18:27:37 +01001849 lvid->integrityType = cpu_to_le32(LVID_INTEGRITY_TYPE_OPEN);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001850
Marcin Slusarz165923f2008-02-10 11:33:08 +01001851 lvid->descTag.descCRC = cpu_to_le16(
Pekka Enberg5ca4e4b2008-10-15 12:28:03 +02001852 crc_itu_t(0, (char *)lvid + sizeof(struct tag),
Bob Copelandf845fce2008-04-17 09:47:48 +02001853 le16_to_cpu(lvid->descTag.descCRCLength)));
Marcin Slusarz165923f2008-02-10 11:33:08 +01001854
1855 lvid->descTag.tagChecksum = udf_tag_checksum(&lvid->descTag);
1856 mark_buffer_dirty(bh);
Jan Kara146bca72009-03-16 18:27:37 +01001857 sbi->s_lvid_dirty = 0;
Jan Kara949f4a72010-10-20 18:49:20 +02001858 mutex_unlock(&sbi->s_alloc_mutex);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001859}
1860
1861static void udf_close_lvid(struct super_block *sb)
1862{
Marcin Slusarz6c79e982008-02-08 04:20:30 -08001863 struct udf_sb_info *sbi = UDF_SB(sb);
1864 struct buffer_head *bh = sbi->s_lvid_bh;
1865 struct logicalVolIntegrityDesc *lvid;
Marcin Slusarz165923f2008-02-10 11:33:08 +01001866 struct logicalVolIntegrityDescImpUse *lvidiu;
Cyrill Gorcunov28de7942007-07-21 04:37:18 -07001867
Marcin Slusarz6c79e982008-02-08 04:20:30 -08001868 if (!bh)
1869 return;
1870
Jan Kara949f4a72010-10-20 18:49:20 +02001871 mutex_lock(&sbi->s_alloc_mutex);
Marcin Slusarz6c79e982008-02-08 04:20:30 -08001872 lvid = (struct logicalVolIntegrityDesc *)bh->b_data;
Marcin Slusarz165923f2008-02-10 11:33:08 +01001873 lvidiu = udf_sb_lvidiu(sbi);
1874 lvidiu->impIdent.identSuffix[0] = UDF_OS_CLASS_UNIX;
1875 lvidiu->impIdent.identSuffix[1] = UDF_OS_ID_LINUX;
1876 udf_time_to_disk_stamp(&lvid->recordingDateAndTime, CURRENT_TIME);
1877 if (UDF_MAX_WRITE_VERSION > le16_to_cpu(lvidiu->maxUDFWriteRev))
1878 lvidiu->maxUDFWriteRev = cpu_to_le16(UDF_MAX_WRITE_VERSION);
1879 if (sbi->s_udfrev > le16_to_cpu(lvidiu->minUDFReadRev))
1880 lvidiu->minUDFReadRev = cpu_to_le16(sbi->s_udfrev);
1881 if (sbi->s_udfrev > le16_to_cpu(lvidiu->minUDFWriteRev))
1882 lvidiu->minUDFWriteRev = cpu_to_le16(sbi->s_udfrev);
1883 lvid->integrityType = cpu_to_le32(LVID_INTEGRITY_TYPE_CLOSE);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001884
Marcin Slusarz165923f2008-02-10 11:33:08 +01001885 lvid->descTag.descCRC = cpu_to_le16(
Pekka Enberg5ca4e4b2008-10-15 12:28:03 +02001886 crc_itu_t(0, (char *)lvid + sizeof(struct tag),
Bob Copelandf845fce2008-04-17 09:47:48 +02001887 le16_to_cpu(lvid->descTag.descCRCLength)));
Marcin Slusarz165923f2008-02-10 11:33:08 +01001888
1889 lvid->descTag.tagChecksum = udf_tag_checksum(&lvid->descTag);
Jan Kara853a0c22011-12-23 11:53:07 +01001890 /*
1891 * We set buffer uptodate unconditionally here to avoid spurious
1892 * warnings from mark_buffer_dirty() when previous EIO has marked
1893 * the buffer as !uptodate
1894 */
1895 set_buffer_uptodate(bh);
Marcin Slusarz165923f2008-02-10 11:33:08 +01001896 mark_buffer_dirty(bh);
Jan Kara146bca72009-03-16 18:27:37 +01001897 sbi->s_lvid_dirty = 0;
Jan Kara949f4a72010-10-20 18:49:20 +02001898 mutex_unlock(&sbi->s_alloc_mutex);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001899}
1900
Jan Karad664b6a2010-10-20 18:28:46 +02001901u64 lvid_get_unique_id(struct super_block *sb)
1902{
1903 struct buffer_head *bh;
1904 struct udf_sb_info *sbi = UDF_SB(sb);
1905 struct logicalVolIntegrityDesc *lvid;
1906 struct logicalVolHeaderDesc *lvhd;
1907 u64 uniqueID;
1908 u64 ret;
1909
1910 bh = sbi->s_lvid_bh;
1911 if (!bh)
1912 return 0;
1913
1914 lvid = (struct logicalVolIntegrityDesc *)bh->b_data;
1915 lvhd = (struct logicalVolHeaderDesc *)lvid->logicalVolContentsUse;
1916
1917 mutex_lock(&sbi->s_alloc_mutex);
1918 ret = uniqueID = le64_to_cpu(lvhd->uniqueID);
1919 if (!(++uniqueID & 0xFFFFFFFF))
1920 uniqueID += 16;
1921 lvhd->uniqueID = cpu_to_le64(uniqueID);
1922 mutex_unlock(&sbi->s_alloc_mutex);
1923 mark_buffer_dirty(bh);
1924
1925 return ret;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001926}
1927
Linus Torvalds1da177e2005-04-16 15:20:36 -07001928static int udf_fill_super(struct super_block *sb, void *options, int silent)
1929{
Jan Kara40346002009-03-19 16:21:38 +01001930 int ret;
Cyrill Gorcunovcb00ea32007-07-19 01:47:43 -07001931 struct inode *inode = NULL;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001932 struct udf_options uopt;
Pekka Enberg5ca4e4b2008-10-15 12:28:03 +02001933 struct kernel_lb_addr rootdir, fileset;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001934 struct udf_sb_info *sbi;
1935
1936 uopt.flags = (1 << UDF_FLAG_USE_AD_IN_ICB) | (1 << UDF_FLAG_STRICT);
1937 uopt.uid = -1;
1938 uopt.gid = -1;
1939 uopt.umask = 0;
Marcin Slusarz87bc7302008-12-02 13:40:11 +01001940 uopt.fmode = UDF_INVALID_MODE;
1941 uopt.dmode = UDF_INVALID_MODE;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001942
Marcin Slusarz6c79e982008-02-08 04:20:30 -08001943 sbi = kzalloc(sizeof(struct udf_sb_info), GFP_KERNEL);
Alessio Igor Bogani9db9f9e2010-11-16 18:40:49 +01001944 if (!sbi)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001945 return -ENOMEM;
Cyrill Gorcunov28de7942007-07-21 04:37:18 -07001946
Linus Torvalds1da177e2005-04-16 15:20:36 -07001947 sb->s_fs_info = sbi;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001948
Ingo Molnar1e7933d2006-03-23 03:00:44 -08001949 mutex_init(&sbi->s_alloc_mutex);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001950
Miklos Szeredi6da80892008-02-08 04:21:50 -08001951 if (!udf_parse_options((char *)options, &uopt, false))
Linus Torvalds1da177e2005-04-16 15:20:36 -07001952 goto error_out;
1953
1954 if (uopt.flags & (1 << UDF_FLAG_UTF8) &&
Cyrill Gorcunovcb00ea32007-07-19 01:47:43 -07001955 uopt.flags & (1 << UDF_FLAG_NLS_MAP)) {
Joe Perches8076c362011-10-10 01:08:03 -07001956 udf_err(sb, "utf8 cannot be combined with iocharset\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07001957 goto error_out;
1958 }
1959#ifdef CONFIG_UDF_NLS
Cyrill Gorcunovcb00ea32007-07-19 01:47:43 -07001960 if ((uopt.flags & (1 << UDF_FLAG_NLS_MAP)) && !uopt.nls_map) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001961 uopt.nls_map = load_nls_default();
1962 if (!uopt.nls_map)
1963 uopt.flags &= ~(1 << UDF_FLAG_NLS_MAP);
1964 else
1965 udf_debug("Using default NLS map\n");
1966 }
1967#endif
1968 if (!(uopt.flags & (1 << UDF_FLAG_NLS_MAP)))
1969 uopt.flags |= (1 << UDF_FLAG_UTF8);
1970
1971 fileset.logicalBlockNum = 0xFFFFFFFF;
1972 fileset.partitionReferenceNum = 0xFFFF;
1973
Marcin Slusarz6c79e982008-02-08 04:20:30 -08001974 sbi->s_flags = uopt.flags;
1975 sbi->s_uid = uopt.uid;
1976 sbi->s_gid = uopt.gid;
1977 sbi->s_umask = uopt.umask;
Marcin Slusarz7ac9bcd52008-11-16 20:52:19 +01001978 sbi->s_fmode = uopt.fmode;
1979 sbi->s_dmode = uopt.dmode;
Marcin Slusarz6c79e982008-02-08 04:20:30 -08001980 sbi->s_nls_map = uopt.nls_map;
Jan Karac03cad22010-10-20 22:17:28 +02001981 rwlock_init(&sbi->s_cred_lock);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001982
Cyrill Gorcunovcb00ea32007-07-19 01:47:43 -07001983 if (uopt.session == 0xFFFFFFFF)
Marcin Slusarz6c79e982008-02-08 04:20:30 -08001984 sbi->s_session = udf_get_last_session(sb);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001985 else
Marcin Slusarz6c79e982008-02-08 04:20:30 -08001986 sbi->s_session = uopt.session;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001987
Marcin Slusarz6c79e982008-02-08 04:20:30 -08001988 udf_debug("Multi-session=%d\n", sbi->s_session);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001989
Linus Torvalds1da177e2005-04-16 15:20:36 -07001990 /* Fill in the rest of the superblock */
1991 sb->s_op = &udf_sb_ops;
Rasmus Rohde221e5832008-04-30 17:22:06 +02001992 sb->s_export_op = &udf_export_ops;
Christoph Hellwig123e9ca2010-05-19 07:16:44 -04001993
Linus Torvalds1da177e2005-04-16 15:20:36 -07001994 sb->s_magic = UDF_SUPER_MAGIC;
1995 sb->s_time_gran = 1000;
1996
Jan Kara40346002009-03-19 16:21:38 +01001997 if (uopt.flags & (1 << UDF_FLAG_BLOCKSIZE_SET)) {
1998 ret = udf_load_vrs(sb, &uopt, silent, &fileset);
1999 } else {
Martin K. Petersene1defc42009-05-22 17:17:49 -04002000 uopt.blocksize = bdev_logical_block_size(sb->s_bdev);
Jan Kara40346002009-03-19 16:21:38 +01002001 ret = udf_load_vrs(sb, &uopt, silent, &fileset);
2002 if (!ret && uopt.blocksize != UDF_DEFAULT_BLOCKSIZE) {
2003 if (!silent)
Joe Perches78ace702011-10-10 01:08:05 -07002004 pr_notice("Rescanning with blocksize %d\n",
2005 UDF_DEFAULT_BLOCKSIZE);
Ashish Sangwandc141a42012-07-21 16:35:17 +05302006 brelse(sbi->s_lvid_bh);
2007 sbi->s_lvid_bh = NULL;
Jan Kara40346002009-03-19 16:21:38 +01002008 uopt.blocksize = UDF_DEFAULT_BLOCKSIZE;
2009 ret = udf_load_vrs(sb, &uopt, silent, &fileset);
2010 }
2011 }
2012 if (!ret) {
Joe Perches78ace702011-10-10 01:08:05 -07002013 udf_warn(sb, "No partition found (1)\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07002014 goto error_out;
2015 }
2016
Marcin Slusarz6c79e982008-02-08 04:20:30 -08002017 udf_debug("Lastblock=%d\n", sbi->s_last_block);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002018
Marcin Slusarz6c79e982008-02-08 04:20:30 -08002019 if (sbi->s_lvid_bh) {
Marcin Slusarz4b111112008-02-08 04:20:36 -08002020 struct logicalVolIntegrityDescImpUse *lvidiu =
2021 udf_sb_lvidiu(sbi);
Marcin Slusarz6c79e982008-02-08 04:20:30 -08002022 uint16_t minUDFReadRev = le16_to_cpu(lvidiu->minUDFReadRev);
2023 uint16_t minUDFWriteRev = le16_to_cpu(lvidiu->minUDFWriteRev);
Marcin Slusarz4b111112008-02-08 04:20:36 -08002024 /* uint16_t maxUDFWriteRev =
2025 le16_to_cpu(lvidiu->maxUDFWriteRev); */
Linus Torvalds1da177e2005-04-16 15:20:36 -07002026
Cyrill Gorcunovcb00ea32007-07-19 01:47:43 -07002027 if (minUDFReadRev > UDF_MAX_READ_VERSION) {
Joe Perches78ace702011-10-10 01:08:05 -07002028 udf_err(sb, "minUDFReadRev=%x (max is %x)\n",
2029 le16_to_cpu(lvidiu->minUDFReadRev),
2030 UDF_MAX_READ_VERSION);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002031 goto error_out;
Marcin Slusarz4b111112008-02-08 04:20:36 -08002032 } else if (minUDFWriteRev > UDF_MAX_WRITE_VERSION)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002033 sb->s_flags |= MS_RDONLY;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002034
Marcin Slusarz6c79e982008-02-08 04:20:30 -08002035 sbi->s_udfrev = minUDFWriteRev;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002036
2037 if (minUDFReadRev >= UDF_VERS_USE_EXTENDED_FE)
2038 UDF_SET_FLAG(sb, UDF_FLAG_USE_EXTENDED_FE);
2039 if (minUDFReadRev >= UDF_VERS_USE_STREAMS)
2040 UDF_SET_FLAG(sb, UDF_FLAG_USE_STREAMS);
2041 }
2042
Marcin Slusarz6c79e982008-02-08 04:20:30 -08002043 if (!sbi->s_partitions) {
Joe Perches78ace702011-10-10 01:08:05 -07002044 udf_warn(sb, "No partition found (2)\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07002045 goto error_out;
2046 }
2047
Marcin Slusarz4b111112008-02-08 04:20:36 -08002048 if (sbi->s_partmaps[sbi->s_partition].s_partition_flags &
2049 UDF_PART_FLAG_READ_ONLY) {
Joe Perches78ace702011-10-10 01:08:05 -07002050 pr_notice("Partition marked readonly; forcing readonly mount\n");
Eric Sandeen39b3f6d2006-09-29 01:59:41 -07002051 sb->s_flags |= MS_RDONLY;
Peter Osterlundc1a26e72006-10-05 21:17:50 +02002052 }
Eric Sandeen39b3f6d2006-09-29 01:59:41 -07002053
Cyrill Gorcunovcb00ea32007-07-19 01:47:43 -07002054 if (udf_find_fileset(sb, &fileset, &rootdir)) {
Joe Perches78ace702011-10-10 01:08:05 -07002055 udf_warn(sb, "No fileset found\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07002056 goto error_out;
2057 }
2058
Cyrill Gorcunovcb00ea32007-07-19 01:47:43 -07002059 if (!silent) {
Pekka Enberg5ca4e4b2008-10-15 12:28:03 +02002060 struct timestamp ts;
Marcin Slusarz56774802008-02-10 11:25:31 +01002061 udf_time_to_disk_stamp(&ts, sbi->s_record_time);
Joe Perches78ace702011-10-10 01:08:05 -07002062 udf_info("Mounting volume '%s', timestamp %04u/%02u/%02u %02u:%02u (%x)\n",
2063 sbi->s_volume_ident,
2064 le16_to_cpu(ts.year), ts.month, ts.day,
Marcin Slusarz56774802008-02-10 11:25:31 +01002065 ts.hour, ts.minute, le16_to_cpu(ts.typeAndTimezone));
Linus Torvalds1da177e2005-04-16 15:20:36 -07002066 }
2067 if (!(sb->s_flags & MS_RDONLY))
2068 udf_open_lvid(sb);
2069
2070 /* Assign the root inode */
2071 /* assign inodes by physical block number */
2072 /* perhaps it's not extensible enough, but for now ... */
Pekka Enberg97e961f2008-10-15 12:29:03 +02002073 inode = udf_iget(sb, &rootdir);
Cyrill Gorcunovcb00ea32007-07-19 01:47:43 -07002074 if (!inode) {
Joe Perches78ace702011-10-10 01:08:05 -07002075 udf_err(sb, "Error in udf_iget, block=%d, partition=%d\n",
Cyrill Gorcunovcb00ea32007-07-19 01:47:43 -07002076 rootdir.logicalBlockNum, rootdir.partitionReferenceNum);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002077 goto error_out;
2078 }
2079
2080 /* Allocate a dentry for the root inode */
Al Viro48fde702012-01-08 22:15:13 -05002081 sb->s_root = d_make_root(inode);
Cyrill Gorcunovcb00ea32007-07-19 01:47:43 -07002082 if (!sb->s_root) {
Joe Perches78ace702011-10-10 01:08:05 -07002083 udf_err(sb, "Couldn't allocate root dentry\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07002084 goto error_out;
2085 }
Jan Kara31170b62007-05-08 00:35:21 -07002086 sb->s_maxbytes = MAX_LFS_FILESIZE;
Al Viro8de52772012-02-06 12:45:27 -05002087 sb->s_max_links = UDF_MAX_LINKS;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002088 return 0;
2089
Cyrill Gorcunov28de7942007-07-21 04:37:18 -07002090error_out:
Marcin Slusarz6c79e982008-02-08 04:20:30 -08002091 if (sbi->s_vat_inode)
2092 iput(sbi->s_vat_inode);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002093#ifdef CONFIG_UDF_NLS
2094 if (UDF_QUERY_FLAG(sb, UDF_FLAG_NLS_MAP))
Marcin Slusarz6c79e982008-02-08 04:20:30 -08002095 unload_nls(sbi->s_nls_map);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002096#endif
2097 if (!(sb->s_flags & MS_RDONLY))
2098 udf_close_lvid(sb);
Marcin Slusarz6c79e982008-02-08 04:20:30 -08002099 brelse(sbi->s_lvid_bh);
Jan Karabff943a2012-06-27 22:27:05 +02002100 udf_sb_free_partitions(sb);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002101 kfree(sbi);
2102 sb->s_fs_info = NULL;
Cyrill Gorcunov28de7942007-07-21 04:37:18 -07002103
Linus Torvalds1da177e2005-04-16 15:20:36 -07002104 return -EINVAL;
2105}
2106
Joe Perches8076c362011-10-10 01:08:03 -07002107void _udf_err(struct super_block *sb, const char *function,
2108 const char *fmt, ...)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002109{
Joe Perchesc2bff362011-10-10 01:08:06 -07002110 struct va_format vaf;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002111 va_list args;
2112
Linus Torvalds1da177e2005-04-16 15:20:36 -07002113 va_start(args, fmt);
Joe Perchesc2bff362011-10-10 01:08:06 -07002114
2115 vaf.fmt = fmt;
2116 vaf.va = &args;
2117
2118 pr_err("error (device %s): %s: %pV", sb->s_id, function, &vaf);
2119
Linus Torvalds1da177e2005-04-16 15:20:36 -07002120 va_end(args);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002121}
2122
Joe Perchesa40ecd72011-10-10 01:08:04 -07002123void _udf_warn(struct super_block *sb, const char *function,
2124 const char *fmt, ...)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002125{
Joe Perchesc2bff362011-10-10 01:08:06 -07002126 struct va_format vaf;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002127 va_list args;
2128
Cyrill Gorcunovcb00ea32007-07-19 01:47:43 -07002129 va_start(args, fmt);
Joe Perchesc2bff362011-10-10 01:08:06 -07002130
2131 vaf.fmt = fmt;
2132 vaf.va = &args;
2133
2134 pr_warn("warning (device %s): %s: %pV", sb->s_id, function, &vaf);
2135
Linus Torvalds1da177e2005-04-16 15:20:36 -07002136 va_end(args);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002137}
2138
Cyrill Gorcunovcb00ea32007-07-19 01:47:43 -07002139static void udf_put_super(struct super_block *sb)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002140{
Marcin Slusarz6c79e982008-02-08 04:20:30 -08002141 struct udf_sb_info *sbi;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002142
Marcin Slusarz6c79e982008-02-08 04:20:30 -08002143 sbi = UDF_SB(sb);
Christoph Hellwig6cfd0142009-05-05 15:40:36 +02002144
Marcin Slusarz6c79e982008-02-08 04:20:30 -08002145 if (sbi->s_vat_inode)
2146 iput(sbi->s_vat_inode);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002147#ifdef CONFIG_UDF_NLS
2148 if (UDF_QUERY_FLAG(sb, UDF_FLAG_NLS_MAP))
Marcin Slusarz6c79e982008-02-08 04:20:30 -08002149 unload_nls(sbi->s_nls_map);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002150#endif
2151 if (!(sb->s_flags & MS_RDONLY))
2152 udf_close_lvid(sb);
Marcin Slusarz6c79e982008-02-08 04:20:30 -08002153 brelse(sbi->s_lvid_bh);
Jan Karabff943a2012-06-27 22:27:05 +02002154 udf_sb_free_partitions(sb);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002155 kfree(sb->s_fs_info);
2156 sb->s_fs_info = NULL;
2157}
2158
Jan Kara146bca72009-03-16 18:27:37 +01002159static int udf_sync_fs(struct super_block *sb, int wait)
2160{
2161 struct udf_sb_info *sbi = UDF_SB(sb);
2162
2163 mutex_lock(&sbi->s_alloc_mutex);
2164 if (sbi->s_lvid_dirty) {
2165 /*
2166 * Blockdevice will be synced later so we don't have to submit
2167 * the buffer for IO
2168 */
2169 mark_buffer_dirty(sbi->s_lvid_bh);
Jan Kara146bca72009-03-16 18:27:37 +01002170 sbi->s_lvid_dirty = 0;
2171 }
2172 mutex_unlock(&sbi->s_alloc_mutex);
2173
2174 return 0;
2175}
2176
Cyrill Gorcunovcb00ea32007-07-19 01:47:43 -07002177static int udf_statfs(struct dentry *dentry, struct kstatfs *buf)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002178{
David Howells726c3342006-06-23 02:02:58 -07002179 struct super_block *sb = dentry->d_sb;
Marcin Slusarz6c79e982008-02-08 04:20:30 -08002180 struct udf_sb_info *sbi = UDF_SB(sb);
2181 struct logicalVolIntegrityDescImpUse *lvidiu;
Coly Li557f5a12009-01-20 01:36:55 +08002182 u64 id = huge_encode_dev(sb->s_bdev->bd_dev);
Marcin Slusarz6c79e982008-02-08 04:20:30 -08002183
2184 if (sbi->s_lvid_bh != NULL)
2185 lvidiu = udf_sb_lvidiu(sbi);
2186 else
2187 lvidiu = NULL;
David Howells726c3342006-06-23 02:02:58 -07002188
Linus Torvalds1da177e2005-04-16 15:20:36 -07002189 buf->f_type = UDF_SUPER_MAGIC;
2190 buf->f_bsize = sb->s_blocksize;
Marcin Slusarz6c79e982008-02-08 04:20:30 -08002191 buf->f_blocks = sbi->s_partmaps[sbi->s_partition].s_partition_len;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002192 buf->f_bfree = udf_count_free(sb);
2193 buf->f_bavail = buf->f_bfree;
Marcin Slusarz6c79e982008-02-08 04:20:30 -08002194 buf->f_files = (lvidiu != NULL ? (le32_to_cpu(lvidiu->numFiles) +
2195 le32_to_cpu(lvidiu->numDirs)) : 0)
2196 + buf->f_bfree;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002197 buf->f_ffree = buf->f_bfree;
Cyrill Gorcunovcb00ea32007-07-19 01:47:43 -07002198 buf->f_namelen = UDF_NAME_LEN - 2;
Coly Li557f5a12009-01-20 01:36:55 +08002199 buf->f_fsid.val[0] = (u32)id;
2200 buf->f_fsid.val[1] = (u32)(id >> 32);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002201
2202 return 0;
2203}
2204
Marcin Slusarz4b111112008-02-08 04:20:36 -08002205static unsigned int udf_count_free_bitmap(struct super_block *sb,
2206 struct udf_bitmap *bitmap)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002207{
2208 struct buffer_head *bh = NULL;
2209 unsigned int accum = 0;
2210 int index;
2211 int block = 0, newblock;
Pekka Enberg5ca4e4b2008-10-15 12:28:03 +02002212 struct kernel_lb_addr loc;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002213 uint32_t bytes;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002214 uint8_t *ptr;
2215 uint16_t ident;
2216 struct spaceBitmapDesc *bm;
2217
Linus Torvalds1da177e2005-04-16 15:20:36 -07002218 loc.logicalBlockNum = bitmap->s_extPosition;
Marcin Slusarz6c79e982008-02-08 04:20:30 -08002219 loc.partitionReferenceNum = UDF_SB(sb)->s_partition;
Pekka Enberg97e961f2008-10-15 12:29:03 +02002220 bh = udf_read_ptagged(sb, &loc, 0, &ident);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002221
Cyrill Gorcunovcb00ea32007-07-19 01:47:43 -07002222 if (!bh) {
Joe Perches78ace702011-10-10 01:08:05 -07002223 udf_err(sb, "udf_count_free failed\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07002224 goto out;
Cyrill Gorcunovcb00ea32007-07-19 01:47:43 -07002225 } else if (ident != TAG_IDENT_SBD) {
Jan Kara3bf25cb2007-05-08 00:35:16 -07002226 brelse(bh);
Joe Perches78ace702011-10-10 01:08:05 -07002227 udf_err(sb, "udf_count_free failed\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07002228 goto out;
2229 }
2230
2231 bm = (struct spaceBitmapDesc *)bh->b_data;
2232 bytes = le32_to_cpu(bm->numOfBytes);
Cyrill Gorcunov28de7942007-07-21 04:37:18 -07002233 index = sizeof(struct spaceBitmapDesc); /* offset in first block only */
2234 ptr = (uint8_t *)bh->b_data;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002235
Cyrill Gorcunovcb00ea32007-07-19 01:47:43 -07002236 while (bytes > 0) {
Marcin Slusarz01b954a2008-02-02 22:37:07 +01002237 u32 cur_bytes = min_t(u32, bytes, sb->s_blocksize - index);
2238 accum += bitmap_weight((const unsigned long *)(ptr + index),
2239 cur_bytes * 8);
2240 bytes -= cur_bytes;
Cyrill Gorcunovcb00ea32007-07-19 01:47:43 -07002241 if (bytes) {
Jan Kara3bf25cb2007-05-08 00:35:16 -07002242 brelse(bh);
Pekka Enberg97e961f2008-10-15 12:29:03 +02002243 newblock = udf_get_lb_pblock(sb, &loc, ++block);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002244 bh = udf_tread(sb, newblock);
Cyrill Gorcunovcb00ea32007-07-19 01:47:43 -07002245 if (!bh) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002246 udf_debug("read failed\n");
2247 goto out;
2248 }
2249 index = 0;
Cyrill Gorcunov28de7942007-07-21 04:37:18 -07002250 ptr = (uint8_t *)bh->b_data;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002251 }
2252 }
Jan Kara3bf25cb2007-05-08 00:35:16 -07002253 brelse(bh);
Cyrill Gorcunov28de7942007-07-21 04:37:18 -07002254out:
Linus Torvalds1da177e2005-04-16 15:20:36 -07002255 return accum;
2256}
2257
Marcin Slusarz4b111112008-02-08 04:20:36 -08002258static unsigned int udf_count_free_table(struct super_block *sb,
2259 struct inode *table)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002260{
2261 unsigned int accum = 0;
Jan Karaff116fc2007-05-08 00:35:14 -07002262 uint32_t elen;
Pekka Enberg5ca4e4b2008-10-15 12:28:03 +02002263 struct kernel_lb_addr eloc;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002264 int8_t etype;
Jan Karaff116fc2007-05-08 00:35:14 -07002265 struct extent_position epos;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002266
Jan Karad1668fe2010-10-20 23:24:12 +02002267 mutex_lock(&UDF_SB(sb)->s_alloc_mutex);
Marcin Slusarzc0b34432008-02-08 04:20:42 -08002268 epos.block = UDF_I(table)->i_location;
Jan Karaff116fc2007-05-08 00:35:14 -07002269 epos.offset = sizeof(struct unallocSpaceEntry);
2270 epos.bh = NULL;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002271
Marcin Slusarz3a71fc52008-02-08 04:20:28 -08002272 while ((etype = udf_next_aext(table, &epos, &eloc, &elen, 1)) != -1)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002273 accum += (elen >> table->i_sb->s_blocksize_bits);
Marcin Slusarz3a71fc52008-02-08 04:20:28 -08002274
Jan Kara3bf25cb2007-05-08 00:35:16 -07002275 brelse(epos.bh);
Jan Karad1668fe2010-10-20 23:24:12 +02002276 mutex_unlock(&UDF_SB(sb)->s_alloc_mutex);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002277
2278 return accum;
2279}
Cyrill Gorcunovcb00ea32007-07-19 01:47:43 -07002280
2281static unsigned int udf_count_free(struct super_block *sb)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002282{
2283 unsigned int accum = 0;
Marcin Slusarz6c79e982008-02-08 04:20:30 -08002284 struct udf_sb_info *sbi;
2285 struct udf_part_map *map;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002286
Marcin Slusarz6c79e982008-02-08 04:20:30 -08002287 sbi = UDF_SB(sb);
2288 if (sbi->s_lvid_bh) {
Marcin Slusarz4b111112008-02-08 04:20:36 -08002289 struct logicalVolIntegrityDesc *lvid =
2290 (struct logicalVolIntegrityDesc *)
2291 sbi->s_lvid_bh->b_data;
Marcin Slusarz6c79e982008-02-08 04:20:30 -08002292 if (le32_to_cpu(lvid->numOfPartitions) > sbi->s_partition) {
Marcin Slusarz4b111112008-02-08 04:20:36 -08002293 accum = le32_to_cpu(
2294 lvid->freeSpaceTable[sbi->s_partition]);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002295 if (accum == 0xFFFFFFFF)
2296 accum = 0;
2297 }
2298 }
2299
2300 if (accum)
2301 return accum;
2302
Marcin Slusarz6c79e982008-02-08 04:20:30 -08002303 map = &sbi->s_partmaps[sbi->s_partition];
2304 if (map->s_partition_flags & UDF_PART_FLAG_UNALLOC_BITMAP) {
Cyrill Gorcunov28de7942007-07-21 04:37:18 -07002305 accum += udf_count_free_bitmap(sb,
Marcin Slusarz6c79e982008-02-08 04:20:30 -08002306 map->s_uspace.s_bitmap);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002307 }
Marcin Slusarz6c79e982008-02-08 04:20:30 -08002308 if (map->s_partition_flags & UDF_PART_FLAG_FREED_BITMAP) {
Cyrill Gorcunov28de7942007-07-21 04:37:18 -07002309 accum += udf_count_free_bitmap(sb,
Marcin Slusarz6c79e982008-02-08 04:20:30 -08002310 map->s_fspace.s_bitmap);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002311 }
2312 if (accum)
2313 return accum;
2314
Marcin Slusarz6c79e982008-02-08 04:20:30 -08002315 if (map->s_partition_flags & UDF_PART_FLAG_UNALLOC_TABLE) {
Cyrill Gorcunov28de7942007-07-21 04:37:18 -07002316 accum += udf_count_free_table(sb,
Marcin Slusarz6c79e982008-02-08 04:20:30 -08002317 map->s_uspace.s_table);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002318 }
Marcin Slusarz6c79e982008-02-08 04:20:30 -08002319 if (map->s_partition_flags & UDF_PART_FLAG_FREED_TABLE) {
Cyrill Gorcunov28de7942007-07-21 04:37:18 -07002320 accum += udf_count_free_table(sb,
Marcin Slusarz6c79e982008-02-08 04:20:30 -08002321 map->s_fspace.s_table);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002322 }
2323
2324 return accum;
2325}