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