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