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