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