Commit e8183c2452041326c95258ecc7865b6fcd91c730

Authored by Tomas Janousek
Committed by Jan Kara
1 parent e4f3ec0634

udf: Fix regression in UDF anchor block detection

In some cases it could happen that some block passed test in
udf_check_anchor_block() even though udf_read_tagged() refused to read it later
(e.g. because checksum was not correct).  This patch makes
udf_check_anchor_block() use udf_read_tagged() so that the checking is
stricter.

This fixes the regression (certain disks unmountable) caused by commit
423cf6dc04eb79d441bfda2b127bc4b57134b41d.

Signed-off-by: Tomas Janousek <tomi@nomi.cz>
Signed-off-by: Jan Kara <jack@suse.cz>

Showing 1 changed file with 23 additions and 34 deletions Inline Diff

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