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