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