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