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