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