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