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