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