Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1 | /* |
| 2 | * super.c |
| 3 | * |
| 4 | * PURPOSE |
| 5 | * Super block routines for the OSTA-UDF(tm) filesystem. |
| 6 | * |
| 7 | * DESCRIPTION |
| 8 | * OSTA-UDF(tm) = Optical Storage Technology Association |
| 9 | * Universal Disk Format. |
| 10 | * |
| 11 | * This code is based on version 2.00 of the UDF specification, |
| 12 | * and revision 3 of the ECMA 167 standard [equivalent to ISO 13346]. |
| 13 | * http://www.osta.org/ |
| 14 | * http://www.ecma.ch/ |
| 15 | * http://www.iso.org/ |
| 16 | * |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 17 | * COPYRIGHT |
| 18 | * This file is distributed under the terms of the GNU General Public |
| 19 | * License (GPL). Copies of the GPL can be obtained from: |
| 20 | * ftp://prep.ai.mit.edu/pub/gnu/GPL |
| 21 | * Each contributing author retains all rights to their own work. |
| 22 | * |
| 23 | * (C) 1998 Dave Boynton |
| 24 | * (C) 1998-2004 Ben Fennema |
| 25 | * (C) 2000 Stelias Computing Inc |
| 26 | * |
| 27 | * HISTORY |
| 28 | * |
| 29 | * 09/24/98 dgb changed to allow compiling outside of kernel, and |
| 30 | * added some debugging. |
| 31 | * 10/01/98 dgb updated to allow (some) possibility of compiling w/2.0.34 |
| 32 | * 10/16/98 attempting some multi-session support |
| 33 | * 10/17/98 added freespace count for "df" |
| 34 | * 11/11/98 gr added novrs option |
| 35 | * 11/26/98 dgb added fileset,anchor mount options |
Marcin Slusarz | 3a71fc5 | 2008-02-08 04:20:28 -0800 | [diff] [blame] | 36 | * 12/06/98 blf really hosed things royally. vat/sparing support. sequenced |
| 37 | * vol descs. rewrote option handling based on isofs |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 38 | * 12/20/98 find the free space bitmap (if it exists) |
| 39 | */ |
| 40 | |
Cyrill Gorcunov | cb00ea3 | 2007-07-19 01:47:43 -0700 | [diff] [blame] | 41 | #include "udfdecl.h" |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 42 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 43 | #include <linux/blkdev.h> |
| 44 | #include <linux/slab.h> |
| 45 | #include <linux/kernel.h> |
| 46 | #include <linux/module.h> |
| 47 | #include <linux/parser.h> |
| 48 | #include <linux/stat.h> |
| 49 | #include <linux/cdrom.h> |
| 50 | #include <linux/nls.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 51 | #include <linux/vfs.h> |
| 52 | #include <linux/vmalloc.h> |
Marcin Slusarz | dc5d39b | 2008-02-08 04:20:32 -0800 | [diff] [blame] | 53 | #include <linux/errno.h> |
Miklos Szeredi | 6da8089 | 2008-02-08 04:21:50 -0800 | [diff] [blame] | 54 | #include <linux/mount.h> |
| 55 | #include <linux/seq_file.h> |
Marcin Slusarz | 01b954a | 2008-02-02 22:37:07 +0100 | [diff] [blame] | 56 | #include <linux/bitmap.h> |
Bob Copeland | f845fce | 2008-04-17 09:47:48 +0200 | [diff] [blame] | 57 | #include <linux/crc-itu-t.h> |
Jan Kara | 1df2ae3 | 2012-06-27 21:23:07 +0200 | [diff] [blame] | 58 | #include <linux/log2.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 59 | #include <asm/byteorder.h> |
| 60 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 61 | #include "udf_sb.h" |
| 62 | #include "udf_i.h" |
| 63 | |
| 64 | #include <linux/init.h> |
Fabian Frederick | e973606 | 2014-06-18 19:38:24 +0200 | [diff] [blame] | 65 | #include <linux/uaccess.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 66 | |
Jan Kara | 4b8d425 | 2018-02-09 12:52:28 +0100 | [diff] [blame] | 67 | enum { |
| 68 | VDS_POS_PRIMARY_VOL_DESC, |
| 69 | VDS_POS_UNALLOC_SPACE_DESC, |
| 70 | VDS_POS_LOGICAL_VOL_DESC, |
Jan Kara | 4b8d425 | 2018-02-09 12:52:28 +0100 | [diff] [blame] | 71 | VDS_POS_IMP_USE_VOL_DESC, |
Jan Kara | 4b8d425 | 2018-02-09 12:52:28 +0100 | [diff] [blame] | 72 | VDS_POS_LENGTH |
| 73 | }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 74 | |
Peter A. Felvegi | 4449960 | 2013-10-18 20:07:44 +0200 | [diff] [blame] | 75 | #define VSD_FIRST_SECTOR_OFFSET 32768 |
| 76 | #define VSD_MAX_SECTOR_OFFSET 0x800000 |
| 77 | |
Alden Tondettar | a47241c | 2016-04-25 19:27:56 -0700 | [diff] [blame] | 78 | /* |
| 79 | * Maximum number of Terminating Descriptor / Logical Volume Integrity |
| 80 | * Descriptor redirections. The chosen numbers are arbitrary - just that we |
| 81 | * hopefully don't limit any real use of rewritten inode on write-once media |
| 82 | * but avoid looping for too long on corrupted media. |
| 83 | */ |
| 84 | #define UDF_MAX_TD_NESTING 64 |
| 85 | #define UDF_MAX_LVID_NESTING 1000 |
| 86 | |
Al Viro | 8de5277 | 2012-02-06 12:45:27 -0500 | [diff] [blame] | 87 | enum { UDF_MAX_LINKS = 0xffff }; |
| 88 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 89 | /* These are the "meat" - everything else is stuffing */ |
| 90 | static int udf_fill_super(struct super_block *, void *, int); |
| 91 | static void udf_put_super(struct super_block *); |
Jan Kara | 146bca7 | 2009-03-16 18:27:37 +0100 | [diff] [blame] | 92 | static int udf_sync_fs(struct super_block *, int); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 93 | static int udf_remount_fs(struct super_block *, int *, char *); |
Pekka Enberg | 5ca4e4b | 2008-10-15 12:28:03 +0200 | [diff] [blame] | 94 | static void udf_load_logicalvolint(struct super_block *, struct kernel_extent_ad); |
Pekka Enberg | 5ca4e4b | 2008-10-15 12:28:03 +0200 | [diff] [blame] | 95 | static int udf_find_fileset(struct super_block *, struct kernel_lb_addr *, |
| 96 | struct kernel_lb_addr *); |
Cyrill Gorcunov | cb00ea3 | 2007-07-19 01:47:43 -0700 | [diff] [blame] | 97 | static void udf_load_fileset(struct super_block *, struct buffer_head *, |
Pekka Enberg | 5ca4e4b | 2008-10-15 12:28:03 +0200 | [diff] [blame] | 98 | struct kernel_lb_addr *); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 99 | static void udf_open_lvid(struct super_block *); |
| 100 | static void udf_close_lvid(struct super_block *); |
| 101 | static unsigned int udf_count_free(struct super_block *); |
David Howells | 726c334 | 2006-06-23 02:02:58 -0700 | [diff] [blame] | 102 | static int udf_statfs(struct dentry *, struct kstatfs *); |
Al Viro | 34c80b1 | 2011-12-08 21:32:45 -0500 | [diff] [blame] | 103 | static int udf_show_options(struct seq_file *, struct dentry *); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 104 | |
Jan Kara | 69d7567 | 2013-09-12 22:00:15 +0200 | [diff] [blame] | 105 | struct logicalVolIntegrityDescImpUse *udf_sb_lvidiu(struct super_block *sb) |
Marcin Slusarz | 6c79e98 | 2008-02-08 04:20:30 -0800 | [diff] [blame] | 106 | { |
Jan Kara | 69d7567 | 2013-09-12 22:00:15 +0200 | [diff] [blame] | 107 | struct logicalVolIntegrityDesc *lvid; |
| 108 | unsigned int partnum; |
| 109 | unsigned int offset; |
| 110 | |
| 111 | if (!UDF_SB(sb)->s_lvid_bh) |
| 112 | return NULL; |
| 113 | lvid = (struct logicalVolIntegrityDesc *)UDF_SB(sb)->s_lvid_bh->b_data; |
| 114 | partnum = le32_to_cpu(lvid->numOfPartitions); |
| 115 | if ((sb->s_blocksize - sizeof(struct logicalVolIntegrityDescImpUse) - |
| 116 | offsetof(struct logicalVolIntegrityDesc, impUse)) / |
| 117 | (2 * sizeof(uint32_t)) < partnum) { |
| 118 | udf_err(sb, "Logical volume integrity descriptor corrupted " |
| 119 | "(numOfPartitions = %u)!\n", partnum); |
| 120 | return NULL; |
| 121 | } |
| 122 | /* The offset is to skip freeSpaceTable and sizeTable arrays */ |
| 123 | offset = partnum * 2 * sizeof(uint32_t); |
Marcin Slusarz | 6c79e98 | 2008-02-08 04:20:30 -0800 | [diff] [blame] | 124 | return (struct logicalVolIntegrityDescImpUse *)&(lvid->impUse[offset]); |
| 125 | } |
| 126 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 127 | /* UDF filesystem type */ |
Al Viro | 152a083 | 2010-07-25 00:46:55 +0400 | [diff] [blame] | 128 | static struct dentry *udf_mount(struct file_system_type *fs_type, |
| 129 | int flags, const char *dev_name, void *data) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 130 | { |
Al Viro | 152a083 | 2010-07-25 00:46:55 +0400 | [diff] [blame] | 131 | return mount_bdev(fs_type, flags, dev_name, data, udf_fill_super); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 132 | } |
| 133 | |
| 134 | static struct file_system_type udf_fstype = { |
Cyrill Gorcunov | 28de794 | 2007-07-21 04:37:18 -0700 | [diff] [blame] | 135 | .owner = THIS_MODULE, |
| 136 | .name = "udf", |
Al Viro | 152a083 | 2010-07-25 00:46:55 +0400 | [diff] [blame] | 137 | .mount = udf_mount, |
Cyrill Gorcunov | 28de794 | 2007-07-21 04:37:18 -0700 | [diff] [blame] | 138 | .kill_sb = kill_block_super, |
| 139 | .fs_flags = FS_REQUIRES_DEV, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 140 | }; |
Eric W. Biederman | 3e64fe5 | 2013-03-11 07:05:42 -0700 | [diff] [blame] | 141 | MODULE_ALIAS_FS("udf"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 142 | |
Cyrill Gorcunov | cb00ea3 | 2007-07-19 01:47:43 -0700 | [diff] [blame] | 143 | static struct kmem_cache *udf_inode_cachep; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 144 | |
| 145 | static struct inode *udf_alloc_inode(struct super_block *sb) |
| 146 | { |
| 147 | struct udf_inode_info *ei; |
Marcin Slusarz | 3a71fc5 | 2008-02-08 04:20:28 -0800 | [diff] [blame] | 148 | ei = kmem_cache_alloc(udf_inode_cachep, GFP_KERNEL); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 149 | if (!ei) |
| 150 | return NULL; |
Dan Bastone | 95f8797 | 2006-08-13 23:24:18 -0700 | [diff] [blame] | 151 | |
| 152 | ei->i_unique = 0; |
| 153 | ei->i_lenExtents = 0; |
| 154 | ei->i_next_alloc_block = 0; |
| 155 | ei->i_next_alloc_goal = 0; |
| 156 | ei->i_strat4096 = 0; |
Alessio Igor Bogani | 4d0fb62 | 2010-11-16 18:40:47 +0100 | [diff] [blame] | 157 | init_rwsem(&ei->i_data_sem); |
Namjae Jeon | 9960005 | 2013-01-19 11:17:14 +0900 | [diff] [blame] | 158 | ei->cached_extent.lstart = -1; |
| 159 | spin_lock_init(&ei->i_extent_cache_lock); |
Dan Bastone | 95f8797 | 2006-08-13 23:24:18 -0700 | [diff] [blame] | 160 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 161 | return &ei->vfs_inode; |
| 162 | } |
| 163 | |
Nick Piggin | fa0d7e3d | 2011-01-07 17:49:49 +1100 | [diff] [blame] | 164 | static void udf_i_callback(struct rcu_head *head) |
| 165 | { |
| 166 | struct inode *inode = container_of(head, struct inode, i_rcu); |
Nick Piggin | fa0d7e3d | 2011-01-07 17:49:49 +1100 | [diff] [blame] | 167 | kmem_cache_free(udf_inode_cachep, UDF_I(inode)); |
| 168 | } |
| 169 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 170 | static void udf_destroy_inode(struct inode *inode) |
| 171 | { |
Nick Piggin | fa0d7e3d | 2011-01-07 17:49:49 +1100 | [diff] [blame] | 172 | call_rcu(&inode->i_rcu, udf_i_callback); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 173 | } |
| 174 | |
Alexey Dobriyan | 51cc506 | 2008-07-25 19:45:34 -0700 | [diff] [blame] | 175 | static void init_once(void *foo) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 176 | { |
Cyrill Gorcunov | cb00ea3 | 2007-07-19 01:47:43 -0700 | [diff] [blame] | 177 | struct udf_inode_info *ei = (struct udf_inode_info *)foo; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 178 | |
Christoph Lameter | a35afb8 | 2007-05-16 22:10:57 -0700 | [diff] [blame] | 179 | ei->i_ext.i_data = NULL; |
| 180 | inode_init_once(&ei->vfs_inode); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 181 | } |
| 182 | |
Fabian Frederick | 53ea18d | 2014-02-01 15:45:18 +0800 | [diff] [blame] | 183 | static int __init init_inodecache(void) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 184 | { |
| 185 | udf_inode_cachep = kmem_cache_create("udf_inode_cache", |
| 186 | sizeof(struct udf_inode_info), |
Cyrill Gorcunov | cb00ea3 | 2007-07-19 01:47:43 -0700 | [diff] [blame] | 187 | 0, (SLAB_RECLAIM_ACCOUNT | |
Vladimir Davydov | 5d09705 | 2016-01-14 15:18:21 -0800 | [diff] [blame] | 188 | SLAB_MEM_SPREAD | |
| 189 | SLAB_ACCOUNT), |
Paul Mundt | 20c2df8 | 2007-07-20 10:11:58 +0900 | [diff] [blame] | 190 | init_once); |
Cyrill Gorcunov | 28de794 | 2007-07-21 04:37:18 -0700 | [diff] [blame] | 191 | if (!udf_inode_cachep) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 192 | return -ENOMEM; |
| 193 | return 0; |
| 194 | } |
| 195 | |
| 196 | static void destroy_inodecache(void) |
| 197 | { |
Kirill A. Shutemov | 8c0a853 | 2012-09-26 11:33:07 +1000 | [diff] [blame] | 198 | /* |
| 199 | * Make sure all delayed rcu free inodes are flushed before we |
| 200 | * destroy cache. |
| 201 | */ |
| 202 | rcu_barrier(); |
Alexey Dobriyan | 1a1d92c | 2006-09-27 01:49:40 -0700 | [diff] [blame] | 203 | kmem_cache_destroy(udf_inode_cachep); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 204 | } |
| 205 | |
| 206 | /* Superblock operations */ |
Josef 'Jeff' Sipek | ee9b6d6 | 2007-02-12 00:55:41 -0800 | [diff] [blame] | 207 | static const struct super_operations udf_sb_ops = { |
Cyrill Gorcunov | 28de794 | 2007-07-21 04:37:18 -0700 | [diff] [blame] | 208 | .alloc_inode = udf_alloc_inode, |
| 209 | .destroy_inode = udf_destroy_inode, |
| 210 | .write_inode = udf_write_inode, |
Al Viro | 3aac2b62 | 2010-06-07 00:43:39 -0400 | [diff] [blame] | 211 | .evict_inode = udf_evict_inode, |
Cyrill Gorcunov | 28de794 | 2007-07-21 04:37:18 -0700 | [diff] [blame] | 212 | .put_super = udf_put_super, |
Jan Kara | 146bca7 | 2009-03-16 18:27:37 +0100 | [diff] [blame] | 213 | .sync_fs = udf_sync_fs, |
Cyrill Gorcunov | 28de794 | 2007-07-21 04:37:18 -0700 | [diff] [blame] | 214 | .statfs = udf_statfs, |
| 215 | .remount_fs = udf_remount_fs, |
Miklos Szeredi | 6da8089 | 2008-02-08 04:21:50 -0800 | [diff] [blame] | 216 | .show_options = udf_show_options, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 217 | }; |
| 218 | |
Cyrill Gorcunov | cb00ea3 | 2007-07-19 01:47:43 -0700 | [diff] [blame] | 219 | struct udf_options { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 220 | unsigned char novrs; |
| 221 | unsigned int blocksize; |
| 222 | unsigned int session; |
| 223 | unsigned int lastblock; |
| 224 | unsigned int anchor; |
| 225 | unsigned int volume; |
| 226 | unsigned short partition; |
| 227 | unsigned int fileset; |
| 228 | unsigned int rootdir; |
| 229 | unsigned int flags; |
Al Viro | faa1729 | 2011-07-26 03:18:29 -0400 | [diff] [blame] | 230 | umode_t umask; |
Eric W. Biederman | c2ba138 | 2012-02-10 12:20:35 -0800 | [diff] [blame] | 231 | kgid_t gid; |
| 232 | kuid_t uid; |
Al Viro | faa1729 | 2011-07-26 03:18:29 -0400 | [diff] [blame] | 233 | umode_t fmode; |
| 234 | umode_t dmode; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 235 | struct nls_table *nls_map; |
| 236 | }; |
| 237 | |
| 238 | static int __init init_udf_fs(void) |
| 239 | { |
| 240 | int err; |
Cyrill Gorcunov | 28de794 | 2007-07-21 04:37:18 -0700 | [diff] [blame] | 241 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 242 | err = init_inodecache(); |
| 243 | if (err) |
| 244 | goto out1; |
| 245 | err = register_filesystem(&udf_fstype); |
| 246 | if (err) |
| 247 | goto out; |
Cyrill Gorcunov | 28de794 | 2007-07-21 04:37:18 -0700 | [diff] [blame] | 248 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 249 | return 0; |
Cyrill Gorcunov | 28de794 | 2007-07-21 04:37:18 -0700 | [diff] [blame] | 250 | |
| 251 | out: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 252 | destroy_inodecache(); |
Cyrill Gorcunov | 28de794 | 2007-07-21 04:37:18 -0700 | [diff] [blame] | 253 | |
| 254 | out1: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 255 | return err; |
| 256 | } |
| 257 | |
| 258 | static void __exit exit_udf_fs(void) |
| 259 | { |
| 260 | unregister_filesystem(&udf_fstype); |
| 261 | destroy_inodecache(); |
| 262 | } |
| 263 | |
Marcin Slusarz | dc5d39b | 2008-02-08 04:20:32 -0800 | [diff] [blame] | 264 | static int udf_sb_alloc_partition_maps(struct super_block *sb, u32 count) |
| 265 | { |
| 266 | struct udf_sb_info *sbi = UDF_SB(sb); |
| 267 | |
Markus Elfring | 033c9da | 2017-08-15 16:45:44 +0200 | [diff] [blame] | 268 | sbi->s_partmaps = kcalloc(count, sizeof(*sbi->s_partmaps), GFP_KERNEL); |
Marcin Slusarz | dc5d39b | 2008-02-08 04:20:32 -0800 | [diff] [blame] | 269 | if (!sbi->s_partmaps) { |
Marcin Slusarz | dc5d39b | 2008-02-08 04:20:32 -0800 | [diff] [blame] | 270 | sbi->s_partitions = 0; |
| 271 | return -ENOMEM; |
| 272 | } |
| 273 | |
| 274 | sbi->s_partitions = count; |
| 275 | return 0; |
| 276 | } |
| 277 | |
Jan Kara | bff943a | 2012-06-27 22:27:05 +0200 | [diff] [blame] | 278 | static void udf_sb_free_bitmap(struct udf_bitmap *bitmap) |
| 279 | { |
| 280 | int i; |
| 281 | int nr_groups = bitmap->s_nr_groups; |
Jan Kara | bff943a | 2012-06-27 22:27:05 +0200 | [diff] [blame] | 282 | |
| 283 | for (i = 0; i < nr_groups; i++) |
| 284 | if (bitmap->s_block_bitmap[i]) |
| 285 | brelse(bitmap->s_block_bitmap[i]); |
| 286 | |
Tetsuo Handa | 1d5cfdb | 2016-01-22 15:11:02 -0800 | [diff] [blame] | 287 | kvfree(bitmap); |
Jan Kara | bff943a | 2012-06-27 22:27:05 +0200 | [diff] [blame] | 288 | } |
| 289 | |
| 290 | static void udf_free_partition(struct udf_part_map *map) |
| 291 | { |
| 292 | int i; |
| 293 | struct udf_meta_data *mdata; |
| 294 | |
| 295 | if (map->s_partition_flags & UDF_PART_FLAG_UNALLOC_TABLE) |
| 296 | iput(map->s_uspace.s_table); |
| 297 | if (map->s_partition_flags & UDF_PART_FLAG_FREED_TABLE) |
| 298 | iput(map->s_fspace.s_table); |
| 299 | if (map->s_partition_flags & UDF_PART_FLAG_UNALLOC_BITMAP) |
| 300 | udf_sb_free_bitmap(map->s_uspace.s_bitmap); |
| 301 | if (map->s_partition_flags & UDF_PART_FLAG_FREED_BITMAP) |
| 302 | udf_sb_free_bitmap(map->s_fspace.s_bitmap); |
| 303 | if (map->s_partition_type == UDF_SPARABLE_MAP15) |
| 304 | for (i = 0; i < 4; i++) |
| 305 | brelse(map->s_type_specific.s_sparing.s_spar_map[i]); |
| 306 | else if (map->s_partition_type == UDF_METADATA_MAP25) { |
| 307 | mdata = &map->s_type_specific.s_metadata; |
| 308 | iput(mdata->s_metadata_fe); |
| 309 | mdata->s_metadata_fe = NULL; |
| 310 | |
| 311 | iput(mdata->s_mirror_fe); |
| 312 | mdata->s_mirror_fe = NULL; |
| 313 | |
| 314 | iput(mdata->s_bitmap_fe); |
| 315 | mdata->s_bitmap_fe = NULL; |
| 316 | } |
| 317 | } |
| 318 | |
| 319 | static void udf_sb_free_partitions(struct super_block *sb) |
| 320 | { |
| 321 | struct udf_sb_info *sbi = UDF_SB(sb); |
| 322 | int i; |
Markus Elfring | ba2eb86 | 2017-08-15 17:03:06 +0200 | [diff] [blame] | 323 | |
| 324 | if (!sbi->s_partmaps) |
Namjae Jeon | 1b1baff | 2013-01-14 22:53:47 +0100 | [diff] [blame] | 325 | return; |
Jan Kara | bff943a | 2012-06-27 22:27:05 +0200 | [diff] [blame] | 326 | for (i = 0; i < sbi->s_partitions; i++) |
| 327 | udf_free_partition(&sbi->s_partmaps[i]); |
| 328 | kfree(sbi->s_partmaps); |
| 329 | sbi->s_partmaps = NULL; |
| 330 | } |
| 331 | |
Al Viro | 34c80b1 | 2011-12-08 21:32:45 -0500 | [diff] [blame] | 332 | static int udf_show_options(struct seq_file *seq, struct dentry *root) |
Miklos Szeredi | 6da8089 | 2008-02-08 04:21:50 -0800 | [diff] [blame] | 333 | { |
Al Viro | 34c80b1 | 2011-12-08 21:32:45 -0500 | [diff] [blame] | 334 | struct super_block *sb = root->d_sb; |
Miklos Szeredi | 6da8089 | 2008-02-08 04:21:50 -0800 | [diff] [blame] | 335 | struct udf_sb_info *sbi = UDF_SB(sb); |
| 336 | |
| 337 | if (!UDF_QUERY_FLAG(sb, UDF_FLAG_STRICT)) |
| 338 | seq_puts(seq, ",nostrict"); |
Clemens Ladisch | 1197e4d | 2009-03-11 15:57:47 +0100 | [diff] [blame] | 339 | if (UDF_QUERY_FLAG(sb, UDF_FLAG_BLOCKSIZE_SET)) |
Miklos Szeredi | 6da8089 | 2008-02-08 04:21:50 -0800 | [diff] [blame] | 340 | seq_printf(seq, ",bs=%lu", sb->s_blocksize); |
| 341 | if (UDF_QUERY_FLAG(sb, UDF_FLAG_UNHIDE)) |
| 342 | seq_puts(seq, ",unhide"); |
| 343 | if (UDF_QUERY_FLAG(sb, UDF_FLAG_UNDELETE)) |
| 344 | seq_puts(seq, ",undelete"); |
| 345 | if (!UDF_QUERY_FLAG(sb, UDF_FLAG_USE_AD_IN_ICB)) |
| 346 | seq_puts(seq, ",noadinicb"); |
| 347 | if (UDF_QUERY_FLAG(sb, UDF_FLAG_USE_SHORT_AD)) |
| 348 | seq_puts(seq, ",shortad"); |
| 349 | if (UDF_QUERY_FLAG(sb, UDF_FLAG_UID_FORGET)) |
| 350 | seq_puts(seq, ",uid=forget"); |
Miklos Szeredi | 6da8089 | 2008-02-08 04:21:50 -0800 | [diff] [blame] | 351 | if (UDF_QUERY_FLAG(sb, UDF_FLAG_GID_FORGET)) |
| 352 | seq_puts(seq, ",gid=forget"); |
Miklos Szeredi | 6da8089 | 2008-02-08 04:21:50 -0800 | [diff] [blame] | 353 | if (UDF_QUERY_FLAG(sb, UDF_FLAG_UID_SET)) |
Eric W. Biederman | c2ba138 | 2012-02-10 12:20:35 -0800 | [diff] [blame] | 354 | seq_printf(seq, ",uid=%u", from_kuid(&init_user_ns, sbi->s_uid)); |
Miklos Szeredi | 6da8089 | 2008-02-08 04:21:50 -0800 | [diff] [blame] | 355 | if (UDF_QUERY_FLAG(sb, UDF_FLAG_GID_SET)) |
Eric W. Biederman | c2ba138 | 2012-02-10 12:20:35 -0800 | [diff] [blame] | 356 | seq_printf(seq, ",gid=%u", from_kgid(&init_user_ns, sbi->s_gid)); |
Miklos Szeredi | 6da8089 | 2008-02-08 04:21:50 -0800 | [diff] [blame] | 357 | if (sbi->s_umask != 0) |
Al Viro | faa1729 | 2011-07-26 03:18:29 -0400 | [diff] [blame] | 358 | seq_printf(seq, ",umask=%ho", sbi->s_umask); |
Marcin Slusarz | 87bc730 | 2008-12-02 13:40:11 +0100 | [diff] [blame] | 359 | if (sbi->s_fmode != UDF_INVALID_MODE) |
Al Viro | faa1729 | 2011-07-26 03:18:29 -0400 | [diff] [blame] | 360 | seq_printf(seq, ",mode=%ho", sbi->s_fmode); |
Marcin Slusarz | 87bc730 | 2008-12-02 13:40:11 +0100 | [diff] [blame] | 361 | if (sbi->s_dmode != UDF_INVALID_MODE) |
Al Viro | faa1729 | 2011-07-26 03:18:29 -0400 | [diff] [blame] | 362 | seq_printf(seq, ",dmode=%ho", sbi->s_dmode); |
Miklos Szeredi | 6da8089 | 2008-02-08 04:21:50 -0800 | [diff] [blame] | 363 | if (UDF_QUERY_FLAG(sb, UDF_FLAG_SESSION_SET)) |
Steve Magnani | fcbf763 | 2017-10-12 08:48:41 -0500 | [diff] [blame] | 364 | seq_printf(seq, ",session=%d", sbi->s_session); |
Miklos Szeredi | 6da8089 | 2008-02-08 04:21:50 -0800 | [diff] [blame] | 365 | if (UDF_QUERY_FLAG(sb, UDF_FLAG_LASTBLOCK_SET)) |
| 366 | seq_printf(seq, ",lastblock=%u", sbi->s_last_block); |
Jan Kara | 40346005 | 2009-03-19 16:21:38 +0100 | [diff] [blame] | 367 | if (sbi->s_anchor != 0) |
| 368 | seq_printf(seq, ",anchor=%u", sbi->s_anchor); |
Miklos Szeredi | 6da8089 | 2008-02-08 04:21:50 -0800 | [diff] [blame] | 369 | /* |
| 370 | * volume, partition, fileset and rootdir seem to be ignored |
| 371 | * currently |
| 372 | */ |
| 373 | if (UDF_QUERY_FLAG(sb, UDF_FLAG_UTF8)) |
| 374 | seq_puts(seq, ",utf8"); |
| 375 | if (UDF_QUERY_FLAG(sb, UDF_FLAG_NLS_MAP) && sbi->s_nls_map) |
| 376 | seq_printf(seq, ",iocharset=%s", sbi->s_nls_map->charset); |
| 377 | |
| 378 | return 0; |
| 379 | } |
| 380 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 381 | /* |
| 382 | * udf_parse_options |
| 383 | * |
| 384 | * PURPOSE |
| 385 | * Parse mount options. |
| 386 | * |
| 387 | * DESCRIPTION |
| 388 | * The following mount options are supported: |
| 389 | * |
| 390 | * gid= Set the default group. |
| 391 | * umask= Set the default umask. |
Marcin Slusarz | 7ac9bcd5 | 2008-11-16 20:52:19 +0100 | [diff] [blame] | 392 | * mode= Set the default file permissions. |
| 393 | * dmode= Set the default directory permissions. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 394 | * uid= Set the default user. |
| 395 | * bs= Set the block size. |
| 396 | * unhide Show otherwise hidden files. |
| 397 | * undelete Show deleted files in lists. |
| 398 | * adinicb Embed data in the inode (default) |
| 399 | * noadinicb Don't embed data in the inode |
| 400 | * shortad Use short ad's |
| 401 | * longad Use long ad's (default) |
| 402 | * nostrict Unset strict conformance |
| 403 | * iocharset= Set the NLS character set |
| 404 | * |
| 405 | * The remaining are for debugging and disaster recovery: |
| 406 | * |
Cyrill Gorcunov | 28de794 | 2007-07-21 04:37:18 -0700 | [diff] [blame] | 407 | * novrs Skip volume sequence recognition |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 408 | * |
| 409 | * The following expect a offset from 0. |
| 410 | * |
| 411 | * session= Set the CDROM session (default= last session) |
| 412 | * anchor= Override standard anchor location. (default= 256) |
| 413 | * volume= Override the VolumeDesc location. (unused) |
| 414 | * partition= Override the PartitionDesc location. (unused) |
| 415 | * lastblock= Set the last block of the filesystem/ |
| 416 | * |
| 417 | * The following expect a offset from the partition root. |
| 418 | * |
| 419 | * fileset= Override the fileset block location. (unused) |
| 420 | * rootdir= Override the root directory location. (unused) |
| 421 | * WARNING: overriding the rootdir to a non-directory may |
| 422 | * yield highly unpredictable results. |
| 423 | * |
| 424 | * PRE-CONDITIONS |
| 425 | * options Pointer to mount options string. |
| 426 | * uopts Pointer to mount options variable. |
| 427 | * |
| 428 | * POST-CONDITIONS |
| 429 | * <return> 1 Mount options parsed okay. |
| 430 | * <return> 0 Error parsing mount options. |
| 431 | * |
| 432 | * HISTORY |
| 433 | * July 1, 1997 - Andrew E. Mileski |
| 434 | * Written, tested, and released. |
| 435 | */ |
Cyrill Gorcunov | 28de794 | 2007-07-21 04:37:18 -0700 | [diff] [blame] | 436 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 437 | enum { |
| 438 | Opt_novrs, Opt_nostrict, Opt_bs, Opt_unhide, Opt_undelete, |
| 439 | Opt_noadinicb, Opt_adinicb, Opt_shortad, Opt_longad, |
| 440 | Opt_gid, Opt_uid, Opt_umask, Opt_session, Opt_lastblock, |
| 441 | Opt_anchor, Opt_volume, Opt_partition, Opt_fileset, |
| 442 | Opt_rootdir, Opt_utf8, Opt_iocharset, |
Marcin Slusarz | 7ac9bcd5 | 2008-11-16 20:52:19 +0100 | [diff] [blame] | 443 | Opt_err, Opt_uforget, Opt_uignore, Opt_gforget, Opt_gignore, |
| 444 | Opt_fmode, Opt_dmode |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 445 | }; |
| 446 | |
Steven Whitehouse | a447c09 | 2008-10-13 10:46:57 +0100 | [diff] [blame] | 447 | static const match_table_t tokens = { |
Cyrill Gorcunov | 28de794 | 2007-07-21 04:37:18 -0700 | [diff] [blame] | 448 | {Opt_novrs, "novrs"}, |
| 449 | {Opt_nostrict, "nostrict"}, |
| 450 | {Opt_bs, "bs=%u"}, |
| 451 | {Opt_unhide, "unhide"}, |
| 452 | {Opt_undelete, "undelete"}, |
| 453 | {Opt_noadinicb, "noadinicb"}, |
| 454 | {Opt_adinicb, "adinicb"}, |
| 455 | {Opt_shortad, "shortad"}, |
| 456 | {Opt_longad, "longad"}, |
| 457 | {Opt_uforget, "uid=forget"}, |
| 458 | {Opt_uignore, "uid=ignore"}, |
| 459 | {Opt_gforget, "gid=forget"}, |
| 460 | {Opt_gignore, "gid=ignore"}, |
| 461 | {Opt_gid, "gid=%u"}, |
| 462 | {Opt_uid, "uid=%u"}, |
| 463 | {Opt_umask, "umask=%o"}, |
| 464 | {Opt_session, "session=%u"}, |
| 465 | {Opt_lastblock, "lastblock=%u"}, |
| 466 | {Opt_anchor, "anchor=%u"}, |
| 467 | {Opt_volume, "volume=%u"}, |
| 468 | {Opt_partition, "partition=%u"}, |
| 469 | {Opt_fileset, "fileset=%u"}, |
| 470 | {Opt_rootdir, "rootdir=%u"}, |
| 471 | {Opt_utf8, "utf8"}, |
| 472 | {Opt_iocharset, "iocharset=%s"}, |
Marcin Slusarz | 7ac9bcd5 | 2008-11-16 20:52:19 +0100 | [diff] [blame] | 473 | {Opt_fmode, "mode=%o"}, |
| 474 | {Opt_dmode, "dmode=%o"}, |
Cyrill Gorcunov | 28de794 | 2007-07-21 04:37:18 -0700 | [diff] [blame] | 475 | {Opt_err, NULL} |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 476 | }; |
| 477 | |
Miklos Szeredi | 6da8089 | 2008-02-08 04:21:50 -0800 | [diff] [blame] | 478 | static int udf_parse_options(char *options, struct udf_options *uopt, |
| 479 | bool remount) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 480 | { |
| 481 | char *p; |
| 482 | int option; |
| 483 | |
| 484 | uopt->novrs = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 485 | uopt->partition = 0xFFFF; |
| 486 | uopt->session = 0xFFFFFFFF; |
| 487 | uopt->lastblock = 0; |
| 488 | uopt->anchor = 0; |
| 489 | uopt->volume = 0xFFFFFFFF; |
| 490 | uopt->rootdir = 0xFFFFFFFF; |
| 491 | uopt->fileset = 0xFFFFFFFF; |
| 492 | uopt->nls_map = NULL; |
| 493 | |
| 494 | if (!options) |
| 495 | return 1; |
| 496 | |
Cyrill Gorcunov | cb00ea3 | 2007-07-19 01:47:43 -0700 | [diff] [blame] | 497 | while ((p = strsep(&options, ",")) != NULL) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 498 | substring_t args[MAX_OPT_ARGS]; |
| 499 | int token; |
Fabian Frederick | 8c6915a | 2014-01-29 17:13:16 +0800 | [diff] [blame] | 500 | unsigned n; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 501 | if (!*p) |
| 502 | continue; |
| 503 | |
| 504 | token = match_token(p, tokens, args); |
Cyrill Gorcunov | cb00ea3 | 2007-07-19 01:47:43 -0700 | [diff] [blame] | 505 | switch (token) { |
| 506 | case Opt_novrs: |
| 507 | uopt->novrs = 1; |
Clemens Ladisch | 4136801 | 2009-03-06 09:16:49 +0100 | [diff] [blame] | 508 | break; |
Cyrill Gorcunov | cb00ea3 | 2007-07-19 01:47:43 -0700 | [diff] [blame] | 509 | case Opt_bs: |
| 510 | if (match_int(&args[0], &option)) |
| 511 | return 0; |
Fabian Frederick | 8c6915a | 2014-01-29 17:13:16 +0800 | [diff] [blame] | 512 | n = option; |
| 513 | if (n != 512 && n != 1024 && n != 2048 && n != 4096) |
| 514 | return 0; |
| 515 | uopt->blocksize = n; |
Clemens Ladisch | 1197e4d | 2009-03-11 15:57:47 +0100 | [diff] [blame] | 516 | uopt->flags |= (1 << UDF_FLAG_BLOCKSIZE_SET); |
Cyrill Gorcunov | cb00ea3 | 2007-07-19 01:47:43 -0700 | [diff] [blame] | 517 | break; |
| 518 | case Opt_unhide: |
| 519 | uopt->flags |= (1 << UDF_FLAG_UNHIDE); |
| 520 | break; |
| 521 | case Opt_undelete: |
| 522 | uopt->flags |= (1 << UDF_FLAG_UNDELETE); |
| 523 | break; |
| 524 | case Opt_noadinicb: |
| 525 | uopt->flags &= ~(1 << UDF_FLAG_USE_AD_IN_ICB); |
| 526 | break; |
| 527 | case Opt_adinicb: |
| 528 | uopt->flags |= (1 << UDF_FLAG_USE_AD_IN_ICB); |
| 529 | break; |
| 530 | case Opt_shortad: |
| 531 | uopt->flags |= (1 << UDF_FLAG_USE_SHORT_AD); |
| 532 | break; |
| 533 | case Opt_longad: |
| 534 | uopt->flags &= ~(1 << UDF_FLAG_USE_SHORT_AD); |
| 535 | break; |
| 536 | case Opt_gid: |
| 537 | if (match_int(args, &option)) |
| 538 | return 0; |
Eric W. Biederman | c2ba138 | 2012-02-10 12:20:35 -0800 | [diff] [blame] | 539 | uopt->gid = make_kgid(current_user_ns(), option); |
| 540 | if (!gid_valid(uopt->gid)) |
| 541 | return 0; |
Cyrill Gorcunov | ca76d2d | 2007-07-31 00:39:40 -0700 | [diff] [blame] | 542 | uopt->flags |= (1 << UDF_FLAG_GID_SET); |
Cyrill Gorcunov | cb00ea3 | 2007-07-19 01:47:43 -0700 | [diff] [blame] | 543 | break; |
| 544 | case Opt_uid: |
| 545 | if (match_int(args, &option)) |
| 546 | return 0; |
Eric W. Biederman | c2ba138 | 2012-02-10 12:20:35 -0800 | [diff] [blame] | 547 | uopt->uid = make_kuid(current_user_ns(), option); |
| 548 | if (!uid_valid(uopt->uid)) |
| 549 | return 0; |
Cyrill Gorcunov | ca76d2d | 2007-07-31 00:39:40 -0700 | [diff] [blame] | 550 | uopt->flags |= (1 << UDF_FLAG_UID_SET); |
Cyrill Gorcunov | cb00ea3 | 2007-07-19 01:47:43 -0700 | [diff] [blame] | 551 | break; |
| 552 | case Opt_umask: |
| 553 | if (match_octal(args, &option)) |
| 554 | return 0; |
| 555 | uopt->umask = option; |
| 556 | break; |
| 557 | case Opt_nostrict: |
| 558 | uopt->flags &= ~(1 << UDF_FLAG_STRICT); |
| 559 | break; |
| 560 | case Opt_session: |
| 561 | if (match_int(args, &option)) |
| 562 | return 0; |
| 563 | uopt->session = option; |
Miklos Szeredi | 6da8089 | 2008-02-08 04:21:50 -0800 | [diff] [blame] | 564 | if (!remount) |
| 565 | uopt->flags |= (1 << UDF_FLAG_SESSION_SET); |
Cyrill Gorcunov | cb00ea3 | 2007-07-19 01:47:43 -0700 | [diff] [blame] | 566 | break; |
| 567 | case Opt_lastblock: |
| 568 | if (match_int(args, &option)) |
| 569 | return 0; |
| 570 | uopt->lastblock = option; |
Miklos Szeredi | 6da8089 | 2008-02-08 04:21:50 -0800 | [diff] [blame] | 571 | if (!remount) |
| 572 | uopt->flags |= (1 << UDF_FLAG_LASTBLOCK_SET); |
Cyrill Gorcunov | cb00ea3 | 2007-07-19 01:47:43 -0700 | [diff] [blame] | 573 | break; |
| 574 | case Opt_anchor: |
| 575 | if (match_int(args, &option)) |
| 576 | return 0; |
| 577 | uopt->anchor = option; |
| 578 | break; |
| 579 | case Opt_volume: |
| 580 | if (match_int(args, &option)) |
| 581 | return 0; |
| 582 | uopt->volume = option; |
| 583 | break; |
| 584 | case Opt_partition: |
| 585 | if (match_int(args, &option)) |
| 586 | return 0; |
| 587 | uopt->partition = option; |
| 588 | break; |
| 589 | case Opt_fileset: |
| 590 | if (match_int(args, &option)) |
| 591 | return 0; |
| 592 | uopt->fileset = option; |
| 593 | break; |
| 594 | case Opt_rootdir: |
| 595 | if (match_int(args, &option)) |
| 596 | return 0; |
| 597 | uopt->rootdir = option; |
| 598 | break; |
| 599 | case Opt_utf8: |
| 600 | uopt->flags |= (1 << UDF_FLAG_UTF8); |
| 601 | break; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 602 | #ifdef CONFIG_UDF_NLS |
Cyrill Gorcunov | cb00ea3 | 2007-07-19 01:47:43 -0700 | [diff] [blame] | 603 | case Opt_iocharset: |
| 604 | uopt->nls_map = load_nls(args[0].from); |
| 605 | uopt->flags |= (1 << UDF_FLAG_NLS_MAP); |
| 606 | break; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 607 | #endif |
Cyrill Gorcunov | cb00ea3 | 2007-07-19 01:47:43 -0700 | [diff] [blame] | 608 | case Opt_uforget: |
| 609 | uopt->flags |= (1 << UDF_FLAG_UID_FORGET); |
| 610 | break; |
Jan Kara | 70260e4 | 2018-02-21 17:27:44 +0100 | [diff] [blame] | 611 | case Opt_uignore: |
Cyrill Gorcunov | cb00ea3 | 2007-07-19 01:47:43 -0700 | [diff] [blame] | 612 | case Opt_gignore: |
Jan Kara | 70260e4 | 2018-02-21 17:27:44 +0100 | [diff] [blame] | 613 | /* These options are superseeded by uid=<number> */ |
Cyrill Gorcunov | cb00ea3 | 2007-07-19 01:47:43 -0700 | [diff] [blame] | 614 | break; |
| 615 | case Opt_gforget: |
| 616 | uopt->flags |= (1 << UDF_FLAG_GID_FORGET); |
| 617 | break; |
Marcin Slusarz | 7ac9bcd5 | 2008-11-16 20:52:19 +0100 | [diff] [blame] | 618 | case Opt_fmode: |
| 619 | if (match_octal(args, &option)) |
| 620 | return 0; |
| 621 | uopt->fmode = option & 0777; |
| 622 | break; |
| 623 | case Opt_dmode: |
| 624 | if (match_octal(args, &option)) |
| 625 | return 0; |
| 626 | uopt->dmode = option & 0777; |
| 627 | break; |
Cyrill Gorcunov | cb00ea3 | 2007-07-19 01:47:43 -0700 | [diff] [blame] | 628 | default: |
Joe Perches | 78ace70 | 2011-10-10 01:08:05 -0700 | [diff] [blame] | 629 | pr_err("bad mount option \"%s\" or missing value\n", p); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 630 | return 0; |
| 631 | } |
| 632 | } |
| 633 | return 1; |
| 634 | } |
| 635 | |
Cyrill Gorcunov | cb00ea3 | 2007-07-19 01:47:43 -0700 | [diff] [blame] | 636 | 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] | 637 | { |
| 638 | struct udf_options uopt; |
Marcin Slusarz | 6c79e98 | 2008-02-08 04:20:30 -0800 | [diff] [blame] | 639 | struct udf_sb_info *sbi = UDF_SB(sb); |
Christoph Hellwig | c79d967 | 2010-05-19 07:16:40 -0400 | [diff] [blame] | 640 | int error = 0; |
Jan Kara | 69d7567 | 2013-09-12 22:00:15 +0200 | [diff] [blame] | 641 | struct logicalVolIntegrityDescImpUse *lvidiu = udf_sb_lvidiu(sb); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 642 | |
Theodore Ts'o | 02b9984 | 2014-03-13 10:14:33 -0400 | [diff] [blame] | 643 | sync_filesystem(sb); |
Jan Kara | 69d7567 | 2013-09-12 22:00:15 +0200 | [diff] [blame] | 644 | if (lvidiu) { |
| 645 | int write_rev = le16_to_cpu(lvidiu->minUDFWriteRev); |
Linus Torvalds | 1751e8a | 2017-11-27 13:05:09 -0800 | [diff] [blame] | 646 | if (write_rev > UDF_MAX_WRITE_VERSION && !(*flags & SB_RDONLY)) |
Jan Kara | e729eac | 2013-07-25 16:15:16 +0200 | [diff] [blame] | 647 | return -EACCES; |
| 648 | } |
| 649 | |
Marcin Slusarz | 6c79e98 | 2008-02-08 04:20:30 -0800 | [diff] [blame] | 650 | uopt.flags = sbi->s_flags; |
| 651 | uopt.uid = sbi->s_uid; |
| 652 | uopt.gid = sbi->s_gid; |
| 653 | uopt.umask = sbi->s_umask; |
Marcin Slusarz | 7ac9bcd5 | 2008-11-16 20:52:19 +0100 | [diff] [blame] | 654 | uopt.fmode = sbi->s_fmode; |
| 655 | uopt.dmode = sbi->s_dmode; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 656 | |
Miklos Szeredi | 6da8089 | 2008-02-08 04:21:50 -0800 | [diff] [blame] | 657 | if (!udf_parse_options(options, &uopt, true)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 658 | return -EINVAL; |
| 659 | |
Jan Kara | c03cad2 | 2010-10-20 22:17:28 +0200 | [diff] [blame] | 660 | write_lock(&sbi->s_cred_lock); |
Marcin Slusarz | 6c79e98 | 2008-02-08 04:20:30 -0800 | [diff] [blame] | 661 | sbi->s_flags = uopt.flags; |
| 662 | sbi->s_uid = uopt.uid; |
| 663 | sbi->s_gid = uopt.gid; |
| 664 | sbi->s_umask = uopt.umask; |
Marcin Slusarz | 7ac9bcd5 | 2008-11-16 20:52:19 +0100 | [diff] [blame] | 665 | sbi->s_fmode = uopt.fmode; |
| 666 | sbi->s_dmode = uopt.dmode; |
Jan Kara | c03cad2 | 2010-10-20 22:17:28 +0200 | [diff] [blame] | 667 | write_unlock(&sbi->s_cred_lock); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 668 | |
Linus Torvalds | 1751e8a | 2017-11-27 13:05:09 -0800 | [diff] [blame] | 669 | if ((bool)(*flags & SB_RDONLY) == sb_rdonly(sb)) |
Christoph Hellwig | c79d967 | 2010-05-19 07:16:40 -0400 | [diff] [blame] | 670 | goto out_unlock; |
| 671 | |
Linus Torvalds | 1751e8a | 2017-11-27 13:05:09 -0800 | [diff] [blame] | 672 | if (*flags & SB_RDONLY) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 673 | udf_close_lvid(sb); |
Jan Kara | 3635046 | 2010-05-19 16:28:56 +0200 | [diff] [blame] | 674 | else |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 675 | udf_open_lvid(sb); |
| 676 | |
Christoph Hellwig | c79d967 | 2010-05-19 07:16:40 -0400 | [diff] [blame] | 677 | out_unlock: |
Christoph Hellwig | c79d967 | 2010-05-19 07:16:40 -0400 | [diff] [blame] | 678 | return error; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 679 | } |
| 680 | |
Jan Kara | 40346005 | 2009-03-19 16:21:38 +0100 | [diff] [blame] | 681 | /* Check Volume Structure Descriptors (ECMA 167 2/9.1) */ |
| 682 | /* We also check any "CD-ROM Volume Descriptor Set" (ECMA 167 2/8.3.1) */ |
| 683 | static loff_t udf_check_vsd(struct super_block *sb) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 684 | { |
| 685 | struct volStructDesc *vsd = NULL; |
Peter A. Felvegi | 4449960 | 2013-10-18 20:07:44 +0200 | [diff] [blame] | 686 | loff_t sector = VSD_FIRST_SECTOR_OFFSET; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 687 | int sectorsize; |
| 688 | struct buffer_head *bh = NULL; |
Cyrill Gorcunov | cb00ea3 | 2007-07-19 01:47:43 -0700 | [diff] [blame] | 689 | int nsr02 = 0; |
| 690 | int nsr03 = 0; |
Marcin Slusarz | 6c79e98 | 2008-02-08 04:20:30 -0800 | [diff] [blame] | 691 | struct udf_sb_info *sbi; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 692 | |
Marcin Slusarz | 6c79e98 | 2008-02-08 04:20:30 -0800 | [diff] [blame] | 693 | sbi = UDF_SB(sb); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 694 | if (sb->s_blocksize < sizeof(struct volStructDesc)) |
| 695 | sectorsize = sizeof(struct volStructDesc); |
| 696 | else |
| 697 | sectorsize = sb->s_blocksize; |
| 698 | |
Jan Kara | abdc0eb | 2017-10-16 11:38:11 +0200 | [diff] [blame] | 699 | sector += (((loff_t)sbi->s_session) << sb->s_blocksize_bits); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 700 | |
Steve Magnani | fcbf763 | 2017-10-12 08:48:41 -0500 | [diff] [blame] | 701 | udf_debug("Starting at sector %u (%lu byte sectors)\n", |
Sebastian Manciulea | 706047a | 2008-04-14 17:13:01 +0200 | [diff] [blame] | 702 | (unsigned int)(sector >> sb->s_blocksize_bits), |
| 703 | sb->s_blocksize); |
Peter A. Felvegi | 4449960 | 2013-10-18 20:07:44 +0200 | [diff] [blame] | 704 | /* Process the sequence (if applicable). The hard limit on the sector |
| 705 | * offset is arbitrary, hopefully large enough so that all valid UDF |
| 706 | * filesystems will be recognised. There is no mention of an upper |
| 707 | * bound to the size of the volume recognition area in the standard. |
| 708 | * The limit will prevent the code to read all the sectors of a |
| 709 | * specially crafted image (like a bluray disc full of CD001 sectors), |
| 710 | * potentially causing minutes or even hours of uninterruptible I/O |
| 711 | * activity. This actually happened with uninitialised SSD partitions |
| 712 | * (all 0xFF) before the check for the limit and all valid IDs were |
| 713 | * added */ |
| 714 | for (; !nsr02 && !nsr03 && sector < VSD_MAX_SECTOR_OFFSET; |
| 715 | sector += sectorsize) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 716 | /* Read a block */ |
| 717 | bh = udf_tread(sb, sector >> sb->s_blocksize_bits); |
| 718 | if (!bh) |
| 719 | break; |
| 720 | |
| 721 | /* Look for ISO descriptors */ |
| 722 | vsd = (struct volStructDesc *)(bh->b_data + |
Marcin Slusarz | 3a71fc5 | 2008-02-08 04:20:28 -0800 | [diff] [blame] | 723 | (sector & (sb->s_blocksize - 1))); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 724 | |
Peter A. Felvegi | 4449960 | 2013-10-18 20:07:44 +0200 | [diff] [blame] | 725 | if (!strncmp(vsd->stdIdent, VSD_STD_ID_CD001, |
Marcin Slusarz | 3a71fc5 | 2008-02-08 04:20:28 -0800 | [diff] [blame] | 726 | VSD_STD_ID_LEN)) { |
Cyrill Gorcunov | cb00ea3 | 2007-07-19 01:47:43 -0700 | [diff] [blame] | 727 | switch (vsd->structType) { |
| 728 | case 0: |
| 729 | udf_debug("ISO9660 Boot Record found\n"); |
| 730 | break; |
| 731 | case 1: |
Joe Perches | a983f36 | 2011-10-10 01:08:07 -0700 | [diff] [blame] | 732 | udf_debug("ISO9660 Primary Volume Descriptor found\n"); |
Cyrill Gorcunov | cb00ea3 | 2007-07-19 01:47:43 -0700 | [diff] [blame] | 733 | break; |
| 734 | case 2: |
Joe Perches | a983f36 | 2011-10-10 01:08:07 -0700 | [diff] [blame] | 735 | udf_debug("ISO9660 Supplementary Volume Descriptor found\n"); |
Cyrill Gorcunov | cb00ea3 | 2007-07-19 01:47:43 -0700 | [diff] [blame] | 736 | break; |
| 737 | case 3: |
Joe Perches | a983f36 | 2011-10-10 01:08:07 -0700 | [diff] [blame] | 738 | udf_debug("ISO9660 Volume Partition Descriptor found\n"); |
Cyrill Gorcunov | cb00ea3 | 2007-07-19 01:47:43 -0700 | [diff] [blame] | 739 | break; |
| 740 | case 255: |
Joe Perches | a983f36 | 2011-10-10 01:08:07 -0700 | [diff] [blame] | 741 | udf_debug("ISO9660 Volume Descriptor Set Terminator found\n"); |
Cyrill Gorcunov | cb00ea3 | 2007-07-19 01:47:43 -0700 | [diff] [blame] | 742 | break; |
| 743 | default: |
| 744 | udf_debug("ISO9660 VRS (%u) found\n", |
| 745 | vsd->structType); |
| 746 | break; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 747 | } |
Marcin Slusarz | 3a71fc5 | 2008-02-08 04:20:28 -0800 | [diff] [blame] | 748 | } else if (!strncmp(vsd->stdIdent, VSD_STD_ID_BEA01, |
| 749 | VSD_STD_ID_LEN)) |
| 750 | ; /* nothing */ |
| 751 | else if (!strncmp(vsd->stdIdent, VSD_STD_ID_TEA01, |
| 752 | VSD_STD_ID_LEN)) { |
Jan Kara | 3bf25cb | 2007-05-08 00:35:16 -0700 | [diff] [blame] | 753 | brelse(bh); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 754 | break; |
Marcin Slusarz | 3a71fc5 | 2008-02-08 04:20:28 -0800 | [diff] [blame] | 755 | } else if (!strncmp(vsd->stdIdent, VSD_STD_ID_NSR02, |
| 756 | VSD_STD_ID_LEN)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 757 | nsr02 = sector; |
Marcin Slusarz | 3a71fc5 | 2008-02-08 04:20:28 -0800 | [diff] [blame] | 758 | else if (!strncmp(vsd->stdIdent, VSD_STD_ID_NSR03, |
| 759 | VSD_STD_ID_LEN)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 760 | nsr03 = sector; |
Peter A. Felvegi | 4449960 | 2013-10-18 20:07:44 +0200 | [diff] [blame] | 761 | else if (!strncmp(vsd->stdIdent, VSD_STD_ID_BOOT2, |
| 762 | VSD_STD_ID_LEN)) |
| 763 | ; /* nothing */ |
| 764 | else if (!strncmp(vsd->stdIdent, VSD_STD_ID_CDW02, |
| 765 | VSD_STD_ID_LEN)) |
| 766 | ; /* nothing */ |
| 767 | else { |
| 768 | /* invalid id : end of volume recognition area */ |
| 769 | brelse(bh); |
| 770 | break; |
| 771 | } |
Jan Kara | 3bf25cb | 2007-05-08 00:35:16 -0700 | [diff] [blame] | 772 | brelse(bh); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 773 | } |
| 774 | |
| 775 | if (nsr03) |
| 776 | return nsr03; |
| 777 | else if (nsr02) |
| 778 | return nsr02; |
Peter A. Felvegi | 4449960 | 2013-10-18 20:07:44 +0200 | [diff] [blame] | 779 | else if (!bh && sector - (sbi->s_session << sb->s_blocksize_bits) == |
| 780 | VSD_FIRST_SECTOR_OFFSET) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 781 | return -1; |
| 782 | else |
| 783 | return 0; |
| 784 | } |
| 785 | |
Marcin Slusarz | 3a71fc5 | 2008-02-08 04:20:28 -0800 | [diff] [blame] | 786 | static int udf_find_fileset(struct super_block *sb, |
Pekka Enberg | 5ca4e4b | 2008-10-15 12:28:03 +0200 | [diff] [blame] | 787 | struct kernel_lb_addr *fileset, |
| 788 | struct kernel_lb_addr *root) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 789 | { |
| 790 | struct buffer_head *bh = NULL; |
| 791 | long lastblock; |
| 792 | uint16_t ident; |
Marcin Slusarz | 6c79e98 | 2008-02-08 04:20:30 -0800 | [diff] [blame] | 793 | struct udf_sb_info *sbi; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 794 | |
| 795 | if (fileset->logicalBlockNum != 0xFFFFFFFF || |
Cyrill Gorcunov | cb00ea3 | 2007-07-19 01:47:43 -0700 | [diff] [blame] | 796 | fileset->partitionReferenceNum != 0xFFFF) { |
Pekka Enberg | 97e961f | 2008-10-15 12:29:03 +0200 | [diff] [blame] | 797 | bh = udf_read_ptagged(sb, fileset, 0, &ident); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 798 | |
Cyrill Gorcunov | 28de794 | 2007-07-21 04:37:18 -0700 | [diff] [blame] | 799 | if (!bh) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 800 | return 1; |
Cyrill Gorcunov | 28de794 | 2007-07-21 04:37:18 -0700 | [diff] [blame] | 801 | } else if (ident != TAG_IDENT_FSD) { |
Jan Kara | 3bf25cb | 2007-05-08 00:35:16 -0700 | [diff] [blame] | 802 | brelse(bh); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 803 | return 1; |
| 804 | } |
Cyrill Gorcunov | cb00ea3 | 2007-07-19 01:47:43 -0700 | [diff] [blame] | 805 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 806 | } |
| 807 | |
Marcin Slusarz | 6c79e98 | 2008-02-08 04:20:30 -0800 | [diff] [blame] | 808 | sbi = UDF_SB(sb); |
Marcin Slusarz | 3a71fc5 | 2008-02-08 04:20:28 -0800 | [diff] [blame] | 809 | if (!bh) { |
| 810 | /* Search backwards through the partitions */ |
Pekka Enberg | 5ca4e4b | 2008-10-15 12:28:03 +0200 | [diff] [blame] | 811 | struct kernel_lb_addr newfileset; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 812 | |
Cyrill Gorcunov | 28de794 | 2007-07-21 04:37:18 -0700 | [diff] [blame] | 813 | /* --> cvg: FIXME - is it reasonable? */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 814 | return 1; |
Cyrill Gorcunov | cb00ea3 | 2007-07-19 01:47:43 -0700 | [diff] [blame] | 815 | |
Marcin Slusarz | 6c79e98 | 2008-02-08 04:20:30 -0800 | [diff] [blame] | 816 | for (newfileset.partitionReferenceNum = sbi->s_partitions - 1; |
Cyrill Gorcunov | cb00ea3 | 2007-07-19 01:47:43 -0700 | [diff] [blame] | 817 | (newfileset.partitionReferenceNum != 0xFFFF && |
| 818 | fileset->logicalBlockNum == 0xFFFFFFFF && |
| 819 | fileset->partitionReferenceNum == 0xFFFF); |
| 820 | newfileset.partitionReferenceNum--) { |
Marcin Slusarz | 6c79e98 | 2008-02-08 04:20:30 -0800 | [diff] [blame] | 821 | lastblock = sbi->s_partmaps |
| 822 | [newfileset.partitionReferenceNum] |
| 823 | .s_partition_len; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 824 | newfileset.logicalBlockNum = 0; |
| 825 | |
Cyrill Gorcunov | cb00ea3 | 2007-07-19 01:47:43 -0700 | [diff] [blame] | 826 | do { |
Pekka Enberg | 97e961f | 2008-10-15 12:29:03 +0200 | [diff] [blame] | 827 | bh = udf_read_ptagged(sb, &newfileset, 0, |
Marcin Slusarz | 3a71fc5 | 2008-02-08 04:20:28 -0800 | [diff] [blame] | 828 | &ident); |
Cyrill Gorcunov | cb00ea3 | 2007-07-19 01:47:43 -0700 | [diff] [blame] | 829 | if (!bh) { |
| 830 | newfileset.logicalBlockNum++; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 831 | continue; |
| 832 | } |
| 833 | |
Cyrill Gorcunov | cb00ea3 | 2007-07-19 01:47:43 -0700 | [diff] [blame] | 834 | switch (ident) { |
| 835 | case TAG_IDENT_SBD: |
Cyrill Gorcunov | 28de794 | 2007-07-21 04:37:18 -0700 | [diff] [blame] | 836 | { |
| 837 | struct spaceBitmapDesc *sp; |
Marcin Slusarz | 4b11111 | 2008-02-08 04:20:36 -0800 | [diff] [blame] | 838 | sp = (struct spaceBitmapDesc *) |
| 839 | bh->b_data; |
Cyrill Gorcunov | 28de794 | 2007-07-21 04:37:18 -0700 | [diff] [blame] | 840 | newfileset.logicalBlockNum += 1 + |
| 841 | ((le32_to_cpu(sp->numOfBytes) + |
Marcin Slusarz | 4b11111 | 2008-02-08 04:20:36 -0800 | [diff] [blame] | 842 | sizeof(struct spaceBitmapDesc) |
| 843 | - 1) >> sb->s_blocksize_bits); |
Cyrill Gorcunov | 28de794 | 2007-07-21 04:37:18 -0700 | [diff] [blame] | 844 | brelse(bh); |
| 845 | break; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 846 | } |
Cyrill Gorcunov | 28de794 | 2007-07-21 04:37:18 -0700 | [diff] [blame] | 847 | case TAG_IDENT_FSD: |
| 848 | *fileset = newfileset; |
| 849 | break; |
| 850 | default: |
| 851 | newfileset.logicalBlockNum++; |
| 852 | brelse(bh); |
| 853 | bh = NULL; |
| 854 | break; |
| 855 | } |
| 856 | } while (newfileset.logicalBlockNum < lastblock && |
| 857 | fileset->logicalBlockNum == 0xFFFFFFFF && |
| 858 | fileset->partitionReferenceNum == 0xFFFF); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 859 | } |
| 860 | } |
| 861 | |
| 862 | if ((fileset->logicalBlockNum != 0xFFFFFFFF || |
Cyrill Gorcunov | cb00ea3 | 2007-07-19 01:47:43 -0700 | [diff] [blame] | 863 | fileset->partitionReferenceNum != 0xFFFF) && bh) { |
Steve Magnani | fcbf763 | 2017-10-12 08:48:41 -0500 | [diff] [blame] | 864 | udf_debug("Fileset at block=%u, partition=%u\n", |
Cyrill Gorcunov | cb00ea3 | 2007-07-19 01:47:43 -0700 | [diff] [blame] | 865 | fileset->logicalBlockNum, |
| 866 | fileset->partitionReferenceNum); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 867 | |
Marcin Slusarz | 6c79e98 | 2008-02-08 04:20:30 -0800 | [diff] [blame] | 868 | sbi->s_partition = fileset->partitionReferenceNum; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 869 | udf_load_fileset(sb, bh, root); |
Jan Kara | 3bf25cb | 2007-05-08 00:35:16 -0700 | [diff] [blame] | 870 | brelse(bh); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 871 | return 0; |
| 872 | } |
| 873 | return 1; |
| 874 | } |
| 875 | |
Jan Kara | d759bfa4 | 2013-07-25 19:10:59 +0200 | [diff] [blame] | 876 | /* |
| 877 | * Load primary Volume Descriptor Sequence |
| 878 | * |
| 879 | * Return <0 on error, 0 on success. -EAGAIN is special meaning next sequence |
| 880 | * should be tried. |
| 881 | */ |
Jan Kara | c0eb31e | 2008-04-01 16:50:35 +0200 | [diff] [blame] | 882 | static int udf_load_pvoldesc(struct super_block *sb, sector_t block) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 883 | { |
| 884 | struct primaryVolDesc *pvoldesc; |
Andrew Gabbasov | 9293fcf | 2016-01-15 02:44:22 -0600 | [diff] [blame] | 885 | uint8_t *outstr; |
Jan Kara | c0eb31e | 2008-04-01 16:50:35 +0200 | [diff] [blame] | 886 | struct buffer_head *bh; |
| 887 | uint16_t ident; |
Jan Kara | d759bfa4 | 2013-07-25 19:10:59 +0200 | [diff] [blame] | 888 | int ret = -ENOMEM; |
Marcin Slusarz | ba9aadd | 2008-11-16 19:01:44 +0100 | [diff] [blame] | 889 | |
Andrew Gabbasov | 9293fcf | 2016-01-15 02:44:22 -0600 | [diff] [blame] | 890 | outstr = kmalloc(128, GFP_NOFS); |
Marcin Slusarz | ba9aadd | 2008-11-16 19:01:44 +0100 | [diff] [blame] | 891 | if (!outstr) |
Andrew Gabbasov | 9293fcf | 2016-01-15 02:44:22 -0600 | [diff] [blame] | 892 | return -ENOMEM; |
Jan Kara | c0eb31e | 2008-04-01 16:50:35 +0200 | [diff] [blame] | 893 | |
| 894 | bh = udf_read_tagged(sb, block, block, &ident); |
Jan Kara | d759bfa4 | 2013-07-25 19:10:59 +0200 | [diff] [blame] | 895 | if (!bh) { |
| 896 | ret = -EAGAIN; |
Marcin Slusarz | ba9aadd | 2008-11-16 19:01:44 +0100 | [diff] [blame] | 897 | goto out2; |
Jan Kara | d759bfa4 | 2013-07-25 19:10:59 +0200 | [diff] [blame] | 898 | } |
Marcin Slusarz | ba9aadd | 2008-11-16 19:01:44 +0100 | [diff] [blame] | 899 | |
Jan Kara | d759bfa4 | 2013-07-25 19:10:59 +0200 | [diff] [blame] | 900 | if (ident != TAG_IDENT_PVD) { |
| 901 | ret = -EIO; |
| 902 | goto out_bh; |
| 903 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 904 | |
| 905 | pvoldesc = (struct primaryVolDesc *)bh->b_data; |
| 906 | |
Marcin Slusarz | 5677480 | 2008-02-10 11:25:31 +0100 | [diff] [blame] | 907 | if (udf_disk_stamp_to_time(&UDF_SB(sb)->s_record_time, |
| 908 | pvoldesc->recordingDateAndTime)) { |
Marcin Slusarz | af15a29 | 2008-02-10 11:29:10 +0100 | [diff] [blame] | 909 | #ifdef UDFFS_DEBUG |
Pekka Enberg | 5ca4e4b | 2008-10-15 12:28:03 +0200 | [diff] [blame] | 910 | struct timestamp *ts = &pvoldesc->recordingDateAndTime; |
Joe Perches | a983f36 | 2011-10-10 01:08:07 -0700 | [diff] [blame] | 911 | udf_debug("recording time %04u/%02u/%02u %02u:%02u (%x)\n", |
Marcin Slusarz | af15a29 | 2008-02-10 11:29:10 +0100 | [diff] [blame] | 912 | le16_to_cpu(ts->year), ts->month, ts->day, ts->hour, |
| 913 | ts->minute, le16_to_cpu(ts->typeAndTimezone)); |
| 914 | #endif |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 915 | } |
| 916 | |
Andrew Gabbasov | c26f6c6 | 2016-04-25 06:19:38 -0500 | [diff] [blame] | 917 | ret = udf_dstrCS0toUTF8(outstr, 31, pvoldesc->volIdent, 32); |
Andrew Gabbasov | 9293fcf | 2016-01-15 02:44:22 -0600 | [diff] [blame] | 918 | if (ret < 0) |
| 919 | goto out_bh; |
Fabian Frederick | e9d4cf41 | 2015-04-08 21:23:54 +0200 | [diff] [blame] | 920 | |
Andrew Gabbasov | 9293fcf | 2016-01-15 02:44:22 -0600 | [diff] [blame] | 921 | strncpy(UDF_SB(sb)->s_volume_ident, outstr, ret); |
| 922 | udf_debug("volIdent[] = '%s'\n", UDF_SB(sb)->s_volume_ident); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 923 | |
Andrew Gabbasov | c26f6c6 | 2016-04-25 06:19:38 -0500 | [diff] [blame] | 924 | ret = udf_dstrCS0toUTF8(outstr, 127, pvoldesc->volSetIdent, 128); |
Andrew Gabbasov | 9293fcf | 2016-01-15 02:44:22 -0600 | [diff] [blame] | 925 | if (ret < 0) |
| 926 | goto out_bh; |
Fabian Frederick | e9d4cf41 | 2015-04-08 21:23:54 +0200 | [diff] [blame] | 927 | |
Andrew Gabbasov | 9293fcf | 2016-01-15 02:44:22 -0600 | [diff] [blame] | 928 | outstr[ret] = 0; |
| 929 | udf_debug("volSetIdent[] = '%s'\n", outstr); |
Jan Kara | c0eb31e | 2008-04-01 16:50:35 +0200 | [diff] [blame] | 930 | |
Marcin Slusarz | ba9aadd | 2008-11-16 19:01:44 +0100 | [diff] [blame] | 931 | ret = 0; |
Jan Kara | d759bfa4 | 2013-07-25 19:10:59 +0200 | [diff] [blame] | 932 | out_bh: |
| 933 | brelse(bh); |
Marcin Slusarz | ba9aadd | 2008-11-16 19:01:44 +0100 | [diff] [blame] | 934 | out2: |
| 935 | kfree(outstr); |
Marcin Slusarz | ba9aadd | 2008-11-16 19:01:44 +0100 | [diff] [blame] | 936 | return ret; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 937 | } |
| 938 | |
Namjae Jeon | 3080a74 | 2011-10-23 19:28:32 +0900 | [diff] [blame] | 939 | struct inode *udf_find_metadata_inode_efe(struct super_block *sb, |
Alden Tondettar | 7888824 | 2016-05-18 14:09:19 -0700 | [diff] [blame] | 940 | u32 meta_file_loc, u32 partition_ref) |
Namjae Jeon | 3080a74 | 2011-10-23 19:28:32 +0900 | [diff] [blame] | 941 | { |
| 942 | struct kernel_lb_addr addr; |
| 943 | struct inode *metadata_fe; |
| 944 | |
| 945 | addr.logicalBlockNum = meta_file_loc; |
Alden Tondettar | 7888824 | 2016-05-18 14:09:19 -0700 | [diff] [blame] | 946 | addr.partitionReferenceNum = partition_ref; |
Namjae Jeon | 3080a74 | 2011-10-23 19:28:32 +0900 | [diff] [blame] | 947 | |
Jan Kara | 6174c2e | 2014-10-09 12:52:16 +0200 | [diff] [blame] | 948 | metadata_fe = udf_iget_special(sb, &addr); |
Namjae Jeon | 3080a74 | 2011-10-23 19:28:32 +0900 | [diff] [blame] | 949 | |
Jan Kara | 6d3d5e8 | 2014-09-04 16:15:51 +0200 | [diff] [blame] | 950 | if (IS_ERR(metadata_fe)) { |
Namjae Jeon | 3080a74 | 2011-10-23 19:28:32 +0900 | [diff] [blame] | 951 | udf_warn(sb, "metadata inode efe not found\n"); |
Jan Kara | 6d3d5e8 | 2014-09-04 16:15:51 +0200 | [diff] [blame] | 952 | return metadata_fe; |
| 953 | } |
| 954 | if (UDF_I(metadata_fe)->i_alloc_type != ICBTAG_FLAG_AD_SHORT) { |
Namjae Jeon | 3080a74 | 2011-10-23 19:28:32 +0900 | [diff] [blame] | 955 | udf_warn(sb, "metadata inode efe does not have short allocation descriptors!\n"); |
| 956 | iput(metadata_fe); |
Jan Kara | 6d3d5e8 | 2014-09-04 16:15:51 +0200 | [diff] [blame] | 957 | return ERR_PTR(-EIO); |
Namjae Jeon | 3080a74 | 2011-10-23 19:28:32 +0900 | [diff] [blame] | 958 | } |
| 959 | |
| 960 | return metadata_fe; |
| 961 | } |
| 962 | |
Alden Tondettar | 7888824 | 2016-05-18 14:09:19 -0700 | [diff] [blame] | 963 | static int udf_load_metadata_files(struct super_block *sb, int partition, |
| 964 | int type1_index) |
Jan Kara | bfb257a | 2008-04-08 20:37:21 +0200 | [diff] [blame] | 965 | { |
| 966 | struct udf_sb_info *sbi = UDF_SB(sb); |
| 967 | struct udf_part_map *map; |
| 968 | struct udf_meta_data *mdata; |
Pekka Enberg | 5ca4e4b | 2008-10-15 12:28:03 +0200 | [diff] [blame] | 969 | struct kernel_lb_addr addr; |
Jan Kara | 6d3d5e8 | 2014-09-04 16:15:51 +0200 | [diff] [blame] | 970 | struct inode *fe; |
Jan Kara | bfb257a | 2008-04-08 20:37:21 +0200 | [diff] [blame] | 971 | |
| 972 | map = &sbi->s_partmaps[partition]; |
| 973 | mdata = &map->s_type_specific.s_metadata; |
Alden Tondettar | 7888824 | 2016-05-18 14:09:19 -0700 | [diff] [blame] | 974 | mdata->s_phys_partition_ref = type1_index; |
Jan Kara | bfb257a | 2008-04-08 20:37:21 +0200 | [diff] [blame] | 975 | |
| 976 | /* metadata address */ |
Steve Magnani | fcbf763 | 2017-10-12 08:48:41 -0500 | [diff] [blame] | 977 | udf_debug("Metadata file location: block = %u part = %u\n", |
Alden Tondettar | 7888824 | 2016-05-18 14:09:19 -0700 | [diff] [blame] | 978 | mdata->s_meta_file_loc, mdata->s_phys_partition_ref); |
Jan Kara | bfb257a | 2008-04-08 20:37:21 +0200 | [diff] [blame] | 979 | |
Jan Kara | 6d3d5e8 | 2014-09-04 16:15:51 +0200 | [diff] [blame] | 980 | fe = udf_find_metadata_inode_efe(sb, mdata->s_meta_file_loc, |
Alden Tondettar | 7888824 | 2016-05-18 14:09:19 -0700 | [diff] [blame] | 981 | mdata->s_phys_partition_ref); |
Jan Kara | 6d3d5e8 | 2014-09-04 16:15:51 +0200 | [diff] [blame] | 982 | if (IS_ERR(fe)) { |
Namjae Jeon | 3080a74 | 2011-10-23 19:28:32 +0900 | [diff] [blame] | 983 | /* mirror file entry */ |
Steve Magnani | fcbf763 | 2017-10-12 08:48:41 -0500 | [diff] [blame] | 984 | udf_debug("Mirror metadata file location: block = %u part = %u\n", |
Alden Tondettar | 7888824 | 2016-05-18 14:09:19 -0700 | [diff] [blame] | 985 | mdata->s_mirror_file_loc, mdata->s_phys_partition_ref); |
Jan Kara | bfb257a | 2008-04-08 20:37:21 +0200 | [diff] [blame] | 986 | |
Jan Kara | 6d3d5e8 | 2014-09-04 16:15:51 +0200 | [diff] [blame] | 987 | fe = udf_find_metadata_inode_efe(sb, mdata->s_mirror_file_loc, |
Alden Tondettar | 7888824 | 2016-05-18 14:09:19 -0700 | [diff] [blame] | 988 | mdata->s_phys_partition_ref); |
Jan Kara | bfb257a | 2008-04-08 20:37:21 +0200 | [diff] [blame] | 989 | |
Jan Kara | 6d3d5e8 | 2014-09-04 16:15:51 +0200 | [diff] [blame] | 990 | if (IS_ERR(fe)) { |
Namjae Jeon | 3080a74 | 2011-10-23 19:28:32 +0900 | [diff] [blame] | 991 | udf_err(sb, "Both metadata and mirror metadata inode efe can not found\n"); |
Jan Kara | 6d3d5e8 | 2014-09-04 16:15:51 +0200 | [diff] [blame] | 992 | return PTR_ERR(fe); |
Namjae Jeon | 3080a74 | 2011-10-23 19:28:32 +0900 | [diff] [blame] | 993 | } |
Jan Kara | 6d3d5e8 | 2014-09-04 16:15:51 +0200 | [diff] [blame] | 994 | mdata->s_mirror_fe = fe; |
| 995 | } else |
| 996 | mdata->s_metadata_fe = fe; |
| 997 | |
Jan Kara | bfb257a | 2008-04-08 20:37:21 +0200 | [diff] [blame] | 998 | |
| 999 | /* |
| 1000 | * bitmap file entry |
| 1001 | * Note: |
| 1002 | * Load only if bitmap file location differs from 0xFFFFFFFF (DCN-5102) |
| 1003 | */ |
| 1004 | if (mdata->s_bitmap_file_loc != 0xFFFFFFFF) { |
| 1005 | addr.logicalBlockNum = mdata->s_bitmap_file_loc; |
Alden Tondettar | 7888824 | 2016-05-18 14:09:19 -0700 | [diff] [blame] | 1006 | addr.partitionReferenceNum = mdata->s_phys_partition_ref; |
Jan Kara | bfb257a | 2008-04-08 20:37:21 +0200 | [diff] [blame] | 1007 | |
Steve Magnani | fcbf763 | 2017-10-12 08:48:41 -0500 | [diff] [blame] | 1008 | udf_debug("Bitmap file location: block = %u part = %u\n", |
Joe Perches | a983f36 | 2011-10-10 01:08:07 -0700 | [diff] [blame] | 1009 | addr.logicalBlockNum, addr.partitionReferenceNum); |
Jan Kara | bfb257a | 2008-04-08 20:37:21 +0200 | [diff] [blame] | 1010 | |
Jan Kara | 6174c2e | 2014-10-09 12:52:16 +0200 | [diff] [blame] | 1011 | fe = udf_iget_special(sb, &addr); |
Jan Kara | 6d3d5e8 | 2014-09-04 16:15:51 +0200 | [diff] [blame] | 1012 | if (IS_ERR(fe)) { |
David Howells | bc98a42 | 2017-07-17 08:45:34 +0100 | [diff] [blame] | 1013 | if (sb_rdonly(sb)) |
Joe Perches | a40ecd7 | 2011-10-10 01:08:04 -0700 | [diff] [blame] | 1014 | udf_warn(sb, "bitmap inode efe not found but it's ok since the disc is mounted read-only\n"); |
Jan Kara | bfb257a | 2008-04-08 20:37:21 +0200 | [diff] [blame] | 1015 | else { |
Joe Perches | 8076c36 | 2011-10-10 01:08:03 -0700 | [diff] [blame] | 1016 | udf_err(sb, "bitmap inode efe not found and attempted read-write mount\n"); |
Jan Kara | 6d3d5e8 | 2014-09-04 16:15:51 +0200 | [diff] [blame] | 1017 | return PTR_ERR(fe); |
Jan Kara | bfb257a | 2008-04-08 20:37:21 +0200 | [diff] [blame] | 1018 | } |
Jan Kara | 6d3d5e8 | 2014-09-04 16:15:51 +0200 | [diff] [blame] | 1019 | } else |
| 1020 | mdata->s_bitmap_fe = fe; |
Jan Kara | bfb257a | 2008-04-08 20:37:21 +0200 | [diff] [blame] | 1021 | } |
| 1022 | |
| 1023 | udf_debug("udf_load_metadata_files Ok\n"); |
Jan Kara | bfb257a | 2008-04-08 20:37:21 +0200 | [diff] [blame] | 1024 | return 0; |
Jan Kara | bfb257a | 2008-04-08 20:37:21 +0200 | [diff] [blame] | 1025 | } |
| 1026 | |
Cyrill Gorcunov | 28de794 | 2007-07-21 04:37:18 -0700 | [diff] [blame] | 1027 | static void udf_load_fileset(struct super_block *sb, struct buffer_head *bh, |
Pekka Enberg | 5ca4e4b | 2008-10-15 12:28:03 +0200 | [diff] [blame] | 1028 | struct kernel_lb_addr *root) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1029 | { |
| 1030 | struct fileSetDesc *fset; |
| 1031 | |
| 1032 | fset = (struct fileSetDesc *)bh->b_data; |
| 1033 | |
| 1034 | *root = lelb_to_cpu(fset->rootDirectoryICB.extLocation); |
| 1035 | |
Marcin Slusarz | 6c79e98 | 2008-02-08 04:20:30 -0800 | [diff] [blame] | 1036 | UDF_SB(sb)->s_serial_number = le16_to_cpu(fset->descTag.tagSerialNum); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1037 | |
Steve Magnani | fcbf763 | 2017-10-12 08:48:41 -0500 | [diff] [blame] | 1038 | udf_debug("Rootdir at block=%u, partition=%u\n", |
Cyrill Gorcunov | cb00ea3 | 2007-07-19 01:47:43 -0700 | [diff] [blame] | 1039 | root->logicalBlockNum, root->partitionReferenceNum); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1040 | } |
| 1041 | |
Marcin Slusarz | 883cb9d | 2008-02-08 04:20:34 -0800 | [diff] [blame] | 1042 | int udf_compute_nr_groups(struct super_block *sb, u32 partition) |
| 1043 | { |
| 1044 | struct udf_part_map *map = &UDF_SB(sb)->s_partmaps[partition]; |
Julia Lawall | 8dee00b | 2008-02-14 16:15:45 +0100 | [diff] [blame] | 1045 | return DIV_ROUND_UP(map->s_partition_len + |
| 1046 | (sizeof(struct spaceBitmapDesc) << 3), |
| 1047 | sb->s_blocksize * 8); |
Marcin Slusarz | 883cb9d | 2008-02-08 04:20:34 -0800 | [diff] [blame] | 1048 | } |
| 1049 | |
Marcin Slusarz | 66e1da3 | 2008-02-08 04:20:33 -0800 | [diff] [blame] | 1050 | static struct udf_bitmap *udf_sb_alloc_bitmap(struct super_block *sb, u32 index) |
| 1051 | { |
Marcin Slusarz | 66e1da3 | 2008-02-08 04:20:33 -0800 | [diff] [blame] | 1052 | struct udf_bitmap *bitmap; |
| 1053 | int nr_groups; |
| 1054 | int size; |
| 1055 | |
Marcin Slusarz | 883cb9d | 2008-02-08 04:20:34 -0800 | [diff] [blame] | 1056 | nr_groups = udf_compute_nr_groups(sb, index); |
Marcin Slusarz | 66e1da3 | 2008-02-08 04:20:33 -0800 | [diff] [blame] | 1057 | size = sizeof(struct udf_bitmap) + |
| 1058 | (sizeof(struct buffer_head *) * nr_groups); |
| 1059 | |
| 1060 | if (size <= PAGE_SIZE) |
Joe Perches | ed2ae6f | 2010-11-04 20:08:04 -0700 | [diff] [blame] | 1061 | bitmap = kzalloc(size, GFP_KERNEL); |
Marcin Slusarz | 66e1da3 | 2008-02-08 04:20:33 -0800 | [diff] [blame] | 1062 | else |
Joe Perches | ed2ae6f | 2010-11-04 20:08:04 -0700 | [diff] [blame] | 1063 | bitmap = vzalloc(size); /* TODO: get rid of vzalloc */ |
Marcin Slusarz | 66e1da3 | 2008-02-08 04:20:33 -0800 | [diff] [blame] | 1064 | |
Markus Elfring | ba2eb86 | 2017-08-15 17:03:06 +0200 | [diff] [blame] | 1065 | if (!bitmap) |
Marcin Slusarz | 66e1da3 | 2008-02-08 04:20:33 -0800 | [diff] [blame] | 1066 | return NULL; |
Marcin Slusarz | 66e1da3 | 2008-02-08 04:20:33 -0800 | [diff] [blame] | 1067 | |
Marcin Slusarz | 66e1da3 | 2008-02-08 04:20:33 -0800 | [diff] [blame] | 1068 | bitmap->s_nr_groups = nr_groups; |
| 1069 | return bitmap; |
| 1070 | } |
| 1071 | |
Jan Kara | 3fb38df | 2008-04-02 12:26:36 +0200 | [diff] [blame] | 1072 | static int udf_fill_partdesc_info(struct super_block *sb, |
| 1073 | struct partitionDesc *p, int p_index) |
| 1074 | { |
| 1075 | struct udf_part_map *map; |
| 1076 | struct udf_sb_info *sbi = UDF_SB(sb); |
| 1077 | struct partitionHeaderDesc *phd; |
| 1078 | |
| 1079 | map = &sbi->s_partmaps[p_index]; |
| 1080 | |
| 1081 | map->s_partition_len = le32_to_cpu(p->partitionLength); /* blocks */ |
| 1082 | map->s_partition_root = le32_to_cpu(p->partitionStartingLocation); |
| 1083 | |
| 1084 | if (p->accessType == cpu_to_le32(PD_ACCESS_TYPE_READ_ONLY)) |
| 1085 | map->s_partition_flags |= UDF_PART_FLAG_READ_ONLY; |
| 1086 | if (p->accessType == cpu_to_le32(PD_ACCESS_TYPE_WRITE_ONCE)) |
| 1087 | map->s_partition_flags |= UDF_PART_FLAG_WRITE_ONCE; |
| 1088 | if (p->accessType == cpu_to_le32(PD_ACCESS_TYPE_REWRITABLE)) |
| 1089 | map->s_partition_flags |= UDF_PART_FLAG_REWRITABLE; |
| 1090 | if (p->accessType == cpu_to_le32(PD_ACCESS_TYPE_OVERWRITABLE)) |
| 1091 | map->s_partition_flags |= UDF_PART_FLAG_OVERWRITABLE; |
| 1092 | |
Steve Magnani | fcbf763 | 2017-10-12 08:48:41 -0500 | [diff] [blame] | 1093 | udf_debug("Partition (%d type %x) starts at physical %u, block length %u\n", |
Joe Perches | a983f36 | 2011-10-10 01:08:07 -0700 | [diff] [blame] | 1094 | p_index, map->s_partition_type, |
| 1095 | map->s_partition_root, map->s_partition_len); |
Jan Kara | 3fb38df | 2008-04-02 12:26:36 +0200 | [diff] [blame] | 1096 | |
| 1097 | if (strcmp(p->partitionContents.ident, PD_PARTITION_CONTENTS_NSR02) && |
| 1098 | strcmp(p->partitionContents.ident, PD_PARTITION_CONTENTS_NSR03)) |
| 1099 | return 0; |
| 1100 | |
| 1101 | phd = (struct partitionHeaderDesc *)p->partitionContentsUse; |
| 1102 | if (phd->unallocSpaceTable.extLength) { |
Pekka Enberg | 5ca4e4b | 2008-10-15 12:28:03 +0200 | [diff] [blame] | 1103 | struct kernel_lb_addr loc = { |
Jan Kara | 3fb38df | 2008-04-02 12:26:36 +0200 | [diff] [blame] | 1104 | .logicalBlockNum = le32_to_cpu( |
| 1105 | phd->unallocSpaceTable.extPosition), |
| 1106 | .partitionReferenceNum = p_index, |
| 1107 | }; |
Jan Kara | 6d3d5e8 | 2014-09-04 16:15:51 +0200 | [diff] [blame] | 1108 | struct inode *inode; |
Jan Kara | 3fb38df | 2008-04-02 12:26:36 +0200 | [diff] [blame] | 1109 | |
Jan Kara | 6174c2e | 2014-10-09 12:52:16 +0200 | [diff] [blame] | 1110 | inode = udf_iget_special(sb, &loc); |
Jan Kara | 6d3d5e8 | 2014-09-04 16:15:51 +0200 | [diff] [blame] | 1111 | if (IS_ERR(inode)) { |
Jan Kara | 3fb38df | 2008-04-02 12:26:36 +0200 | [diff] [blame] | 1112 | udf_debug("cannot load unallocSpaceTable (part %d)\n", |
Joe Perches | a983f36 | 2011-10-10 01:08:07 -0700 | [diff] [blame] | 1113 | p_index); |
Jan Kara | 6d3d5e8 | 2014-09-04 16:15:51 +0200 | [diff] [blame] | 1114 | return PTR_ERR(inode); |
Jan Kara | 3fb38df | 2008-04-02 12:26:36 +0200 | [diff] [blame] | 1115 | } |
Jan Kara | 6d3d5e8 | 2014-09-04 16:15:51 +0200 | [diff] [blame] | 1116 | map->s_uspace.s_table = inode; |
Jan Kara | 3fb38df | 2008-04-02 12:26:36 +0200 | [diff] [blame] | 1117 | map->s_partition_flags |= UDF_PART_FLAG_UNALLOC_TABLE; |
Steve Magnani | fcbf763 | 2017-10-12 08:48:41 -0500 | [diff] [blame] | 1118 | udf_debug("unallocSpaceTable (part %d) @ %lu\n", |
Joe Perches | a983f36 | 2011-10-10 01:08:07 -0700 | [diff] [blame] | 1119 | p_index, map->s_uspace.s_table->i_ino); |
Jan Kara | 3fb38df | 2008-04-02 12:26:36 +0200 | [diff] [blame] | 1120 | } |
| 1121 | |
| 1122 | if (phd->unallocSpaceBitmap.extLength) { |
| 1123 | struct udf_bitmap *bitmap = udf_sb_alloc_bitmap(sb, p_index); |
| 1124 | if (!bitmap) |
Jan Kara | d759bfa4 | 2013-07-25 19:10:59 +0200 | [diff] [blame] | 1125 | return -ENOMEM; |
Jan Kara | 3fb38df | 2008-04-02 12:26:36 +0200 | [diff] [blame] | 1126 | map->s_uspace.s_bitmap = bitmap; |
Jan Kara | 3fb38df | 2008-04-02 12:26:36 +0200 | [diff] [blame] | 1127 | bitmap->s_extPosition = le32_to_cpu( |
| 1128 | phd->unallocSpaceBitmap.extPosition); |
| 1129 | map->s_partition_flags |= UDF_PART_FLAG_UNALLOC_BITMAP; |
Steve Magnani | fcbf763 | 2017-10-12 08:48:41 -0500 | [diff] [blame] | 1130 | udf_debug("unallocSpaceBitmap (part %d) @ %u\n", |
Joe Perches | a983f36 | 2011-10-10 01:08:07 -0700 | [diff] [blame] | 1131 | p_index, bitmap->s_extPosition); |
Jan Kara | 3fb38df | 2008-04-02 12:26:36 +0200 | [diff] [blame] | 1132 | } |
| 1133 | |
| 1134 | if (phd->partitionIntegrityTable.extLength) |
| 1135 | udf_debug("partitionIntegrityTable (part %d)\n", p_index); |
| 1136 | |
| 1137 | if (phd->freedSpaceTable.extLength) { |
Pekka Enberg | 5ca4e4b | 2008-10-15 12:28:03 +0200 | [diff] [blame] | 1138 | struct kernel_lb_addr loc = { |
Jan Kara | 3fb38df | 2008-04-02 12:26:36 +0200 | [diff] [blame] | 1139 | .logicalBlockNum = le32_to_cpu( |
| 1140 | phd->freedSpaceTable.extPosition), |
| 1141 | .partitionReferenceNum = p_index, |
| 1142 | }; |
Jan Kara | 6d3d5e8 | 2014-09-04 16:15:51 +0200 | [diff] [blame] | 1143 | struct inode *inode; |
Jan Kara | 3fb38df | 2008-04-02 12:26:36 +0200 | [diff] [blame] | 1144 | |
Jan Kara | 6174c2e | 2014-10-09 12:52:16 +0200 | [diff] [blame] | 1145 | inode = udf_iget_special(sb, &loc); |
Jan Kara | 6d3d5e8 | 2014-09-04 16:15:51 +0200 | [diff] [blame] | 1146 | if (IS_ERR(inode)) { |
Jan Kara | 3fb38df | 2008-04-02 12:26:36 +0200 | [diff] [blame] | 1147 | udf_debug("cannot load freedSpaceTable (part %d)\n", |
Joe Perches | a983f36 | 2011-10-10 01:08:07 -0700 | [diff] [blame] | 1148 | p_index); |
Jan Kara | 6d3d5e8 | 2014-09-04 16:15:51 +0200 | [diff] [blame] | 1149 | return PTR_ERR(inode); |
Jan Kara | 3fb38df | 2008-04-02 12:26:36 +0200 | [diff] [blame] | 1150 | } |
Jan Kara | 6d3d5e8 | 2014-09-04 16:15:51 +0200 | [diff] [blame] | 1151 | map->s_fspace.s_table = inode; |
Jan Kara | 3fb38df | 2008-04-02 12:26:36 +0200 | [diff] [blame] | 1152 | map->s_partition_flags |= UDF_PART_FLAG_FREED_TABLE; |
Steve Magnani | fcbf763 | 2017-10-12 08:48:41 -0500 | [diff] [blame] | 1153 | udf_debug("freedSpaceTable (part %d) @ %lu\n", |
Joe Perches | a983f36 | 2011-10-10 01:08:07 -0700 | [diff] [blame] | 1154 | p_index, map->s_fspace.s_table->i_ino); |
Jan Kara | 3fb38df | 2008-04-02 12:26:36 +0200 | [diff] [blame] | 1155 | } |
| 1156 | |
| 1157 | if (phd->freedSpaceBitmap.extLength) { |
| 1158 | struct udf_bitmap *bitmap = udf_sb_alloc_bitmap(sb, p_index); |
| 1159 | if (!bitmap) |
Jan Kara | d759bfa4 | 2013-07-25 19:10:59 +0200 | [diff] [blame] | 1160 | return -ENOMEM; |
Jan Kara | 3fb38df | 2008-04-02 12:26:36 +0200 | [diff] [blame] | 1161 | map->s_fspace.s_bitmap = bitmap; |
Jan Kara | 3fb38df | 2008-04-02 12:26:36 +0200 | [diff] [blame] | 1162 | bitmap->s_extPosition = le32_to_cpu( |
| 1163 | phd->freedSpaceBitmap.extPosition); |
| 1164 | map->s_partition_flags |= UDF_PART_FLAG_FREED_BITMAP; |
Steve Magnani | fcbf763 | 2017-10-12 08:48:41 -0500 | [diff] [blame] | 1165 | udf_debug("freedSpaceBitmap (part %d) @ %u\n", |
Joe Perches | a983f36 | 2011-10-10 01:08:07 -0700 | [diff] [blame] | 1166 | p_index, bitmap->s_extPosition); |
Jan Kara | 3fb38df | 2008-04-02 12:26:36 +0200 | [diff] [blame] | 1167 | } |
| 1168 | return 0; |
| 1169 | } |
| 1170 | |
Jan Kara | e971b0b | 2009-11-30 19:47:55 +0100 | [diff] [blame] | 1171 | static void udf_find_vat_block(struct super_block *sb, int p_index, |
| 1172 | int type1_index, sector_t start_block) |
| 1173 | { |
| 1174 | struct udf_sb_info *sbi = UDF_SB(sb); |
| 1175 | struct udf_part_map *map = &sbi->s_partmaps[p_index]; |
| 1176 | sector_t vat_block; |
| 1177 | struct kernel_lb_addr ino; |
Jan Kara | 6d3d5e8 | 2014-09-04 16:15:51 +0200 | [diff] [blame] | 1178 | struct inode *inode; |
Jan Kara | e971b0b | 2009-11-30 19:47:55 +0100 | [diff] [blame] | 1179 | |
| 1180 | /* |
| 1181 | * VAT file entry is in the last recorded block. Some broken disks have |
| 1182 | * it a few blocks before so try a bit harder... |
| 1183 | */ |
| 1184 | ino.partitionReferenceNum = type1_index; |
| 1185 | for (vat_block = start_block; |
| 1186 | vat_block >= map->s_partition_root && |
Jan Kara | 6d3d5e8 | 2014-09-04 16:15:51 +0200 | [diff] [blame] | 1187 | vat_block >= start_block - 3; vat_block--) { |
Jan Kara | e971b0b | 2009-11-30 19:47:55 +0100 | [diff] [blame] | 1188 | ino.logicalBlockNum = vat_block - map->s_partition_root; |
Jan Kara | 6174c2e | 2014-10-09 12:52:16 +0200 | [diff] [blame] | 1189 | inode = udf_iget_special(sb, &ino); |
Jan Kara | 6d3d5e8 | 2014-09-04 16:15:51 +0200 | [diff] [blame] | 1190 | if (!IS_ERR(inode)) { |
| 1191 | sbi->s_vat_inode = inode; |
| 1192 | break; |
| 1193 | } |
Jan Kara | e971b0b | 2009-11-30 19:47:55 +0100 | [diff] [blame] | 1194 | } |
| 1195 | } |
| 1196 | |
Jan Kara | 38b74a5 | 2008-04-02 16:01:35 +0200 | [diff] [blame] | 1197 | static int udf_load_vat(struct super_block *sb, int p_index, int type1_index) |
| 1198 | { |
| 1199 | struct udf_sb_info *sbi = UDF_SB(sb); |
| 1200 | struct udf_part_map *map = &sbi->s_partmaps[p_index]; |
Jan Kara | fa5e081 | 2008-04-08 02:08:53 +0200 | [diff] [blame] | 1201 | struct buffer_head *bh = NULL; |
| 1202 | struct udf_inode_info *vati; |
| 1203 | uint32_t pos; |
| 1204 | struct virtualAllocationTable20 *vat20; |
Fabian Frederick | 23bcda1 | 2017-01-06 21:54:41 +0100 | [diff] [blame] | 1205 | sector_t blocks = i_size_read(sb->s_bdev->bd_inode) >> |
| 1206 | sb->s_blocksize_bits; |
Jan Kara | 38b74a5 | 2008-04-02 16:01:35 +0200 | [diff] [blame] | 1207 | |
Jan Kara | e971b0b | 2009-11-30 19:47:55 +0100 | [diff] [blame] | 1208 | udf_find_vat_block(sb, p_index, type1_index, sbi->s_last_block); |
Jan Kara | 4bf17af | 2009-07-14 19:30:23 +0200 | [diff] [blame] | 1209 | if (!sbi->s_vat_inode && |
| 1210 | sbi->s_last_block != blocks - 1) { |
Joe Perches | 78ace70 | 2011-10-10 01:08:05 -0700 | [diff] [blame] | 1211 | pr_notice("Failed to read VAT inode from the last recorded block (%lu), retrying with the last block of the device (%lu).\n", |
| 1212 | (unsigned long)sbi->s_last_block, |
| 1213 | (unsigned long)blocks - 1); |
Jan Kara | e971b0b | 2009-11-30 19:47:55 +0100 | [diff] [blame] | 1214 | udf_find_vat_block(sb, p_index, type1_index, blocks - 1); |
Jan Kara | 4bf17af | 2009-07-14 19:30:23 +0200 | [diff] [blame] | 1215 | } |
Jan Kara | 38b74a5 | 2008-04-02 16:01:35 +0200 | [diff] [blame] | 1216 | if (!sbi->s_vat_inode) |
Jan Kara | d759bfa4 | 2013-07-25 19:10:59 +0200 | [diff] [blame] | 1217 | return -EIO; |
Jan Kara | 38b74a5 | 2008-04-02 16:01:35 +0200 | [diff] [blame] | 1218 | |
| 1219 | if (map->s_partition_type == UDF_VIRTUAL_MAP15) { |
Sebastian Manciulea | 47c9358 | 2008-04-14 17:06:36 +0200 | [diff] [blame] | 1220 | map->s_type_specific.s_virtual.s_start_offset = 0; |
Jan Kara | 38b74a5 | 2008-04-02 16:01:35 +0200 | [diff] [blame] | 1221 | map->s_type_specific.s_virtual.s_num_entries = |
| 1222 | (sbi->s_vat_inode->i_size - 36) >> 2; |
| 1223 | } else if (map->s_partition_type == UDF_VIRTUAL_MAP20) { |
Jan Kara | fa5e081 | 2008-04-08 02:08:53 +0200 | [diff] [blame] | 1224 | vati = UDF_I(sbi->s_vat_inode); |
| 1225 | if (vati->i_alloc_type != ICBTAG_FLAG_AD_IN_ICB) { |
| 1226 | pos = udf_block_map(sbi->s_vat_inode, 0); |
| 1227 | bh = sb_bread(sb, pos); |
| 1228 | if (!bh) |
Jan Kara | d759bfa4 | 2013-07-25 19:10:59 +0200 | [diff] [blame] | 1229 | return -EIO; |
Jan Kara | fa5e081 | 2008-04-08 02:08:53 +0200 | [diff] [blame] | 1230 | vat20 = (struct virtualAllocationTable20 *)bh->b_data; |
| 1231 | } else { |
| 1232 | vat20 = (struct virtualAllocationTable20 *) |
| 1233 | vati->i_ext.i_data; |
| 1234 | } |
Jan Kara | 38b74a5 | 2008-04-02 16:01:35 +0200 | [diff] [blame] | 1235 | |
Jan Kara | 38b74a5 | 2008-04-02 16:01:35 +0200 | [diff] [blame] | 1236 | map->s_type_specific.s_virtual.s_start_offset = |
Sebastian Manciulea | 47c9358 | 2008-04-14 17:06:36 +0200 | [diff] [blame] | 1237 | le16_to_cpu(vat20->lengthHeader); |
Jan Kara | 38b74a5 | 2008-04-02 16:01:35 +0200 | [diff] [blame] | 1238 | map->s_type_specific.s_virtual.s_num_entries = |
| 1239 | (sbi->s_vat_inode->i_size - |
| 1240 | map->s_type_specific.s_virtual. |
| 1241 | s_start_offset) >> 2; |
| 1242 | brelse(bh); |
| 1243 | } |
| 1244 | return 0; |
| 1245 | } |
| 1246 | |
Jan Kara | d759bfa4 | 2013-07-25 19:10:59 +0200 | [diff] [blame] | 1247 | /* |
| 1248 | * Load partition descriptor block |
| 1249 | * |
| 1250 | * Returns <0 on error, 0 on success, -EAGAIN is special - try next descriptor |
| 1251 | * sequence. |
| 1252 | */ |
Jan Kara | c0eb31e | 2008-04-01 16:50:35 +0200 | [diff] [blame] | 1253 | static int udf_load_partdesc(struct super_block *sb, sector_t block) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1254 | { |
Jan Kara | c0eb31e | 2008-04-01 16:50:35 +0200 | [diff] [blame] | 1255 | struct buffer_head *bh; |
Jan Kara | c0eb31e | 2008-04-01 16:50:35 +0200 | [diff] [blame] | 1256 | struct partitionDesc *p; |
Marcin Slusarz | 6c79e98 | 2008-02-08 04:20:30 -0800 | [diff] [blame] | 1257 | struct udf_part_map *map; |
Marcin Slusarz | 165923f | 2008-02-10 11:33:08 +0100 | [diff] [blame] | 1258 | struct udf_sb_info *sbi = UDF_SB(sb); |
Jan Kara | 38b74a5 | 2008-04-02 16:01:35 +0200 | [diff] [blame] | 1259 | int i, type1_idx; |
Jan Kara | c0eb31e | 2008-04-01 16:50:35 +0200 | [diff] [blame] | 1260 | uint16_t partitionNumber; |
| 1261 | uint16_t ident; |
Jan Kara | d759bfa4 | 2013-07-25 19:10:59 +0200 | [diff] [blame] | 1262 | int ret; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1263 | |
Jan Kara | c0eb31e | 2008-04-01 16:50:35 +0200 | [diff] [blame] | 1264 | bh = udf_read_tagged(sb, block, block, &ident); |
| 1265 | if (!bh) |
Jan Kara | d759bfa4 | 2013-07-25 19:10:59 +0200 | [diff] [blame] | 1266 | return -EAGAIN; |
| 1267 | if (ident != TAG_IDENT_PD) { |
| 1268 | ret = 0; |
Jan Kara | c0eb31e | 2008-04-01 16:50:35 +0200 | [diff] [blame] | 1269 | goto out_bh; |
Jan Kara | d759bfa4 | 2013-07-25 19:10:59 +0200 | [diff] [blame] | 1270 | } |
Jan Kara | c0eb31e | 2008-04-01 16:50:35 +0200 | [diff] [blame] | 1271 | |
| 1272 | p = (struct partitionDesc *)bh->b_data; |
| 1273 | partitionNumber = le16_to_cpu(p->partitionNumber); |
Jan Kara | 38b74a5 | 2008-04-02 16:01:35 +0200 | [diff] [blame] | 1274 | |
Alden Tondettar | 7888824 | 2016-05-18 14:09:19 -0700 | [diff] [blame] | 1275 | /* First scan for TYPE1 and SPARABLE partitions */ |
Marcin Slusarz | 6c79e98 | 2008-02-08 04:20:30 -0800 | [diff] [blame] | 1276 | for (i = 0; i < sbi->s_partitions; i++) { |
| 1277 | map = &sbi->s_partmaps[i]; |
Steve Magnani | fcbf763 | 2017-10-12 08:48:41 -0500 | [diff] [blame] | 1278 | udf_debug("Searching map: (%u == %u)\n", |
Marcin Slusarz | 165923f | 2008-02-10 11:33:08 +0100 | [diff] [blame] | 1279 | map->s_partition_num, partitionNumber); |
Jan Kara | 38b74a5 | 2008-04-02 16:01:35 +0200 | [diff] [blame] | 1280 | if (map->s_partition_num == partitionNumber && |
| 1281 | (map->s_partition_type == UDF_TYPE1_MAP15 || |
| 1282 | map->s_partition_type == UDF_SPARABLE_MAP15)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1283 | break; |
Marcin Slusarz | 165923f | 2008-02-10 11:33:08 +0100 | [diff] [blame] | 1284 | } |
| 1285 | |
Jan Kara | 38b74a5 | 2008-04-02 16:01:35 +0200 | [diff] [blame] | 1286 | if (i >= sbi->s_partitions) { |
Steve Magnani | fcbf763 | 2017-10-12 08:48:41 -0500 | [diff] [blame] | 1287 | udf_debug("Partition (%u) not found in partition map\n", |
Marcin Slusarz | 165923f | 2008-02-10 11:33:08 +0100 | [diff] [blame] | 1288 | partitionNumber); |
Jan Kara | d759bfa4 | 2013-07-25 19:10:59 +0200 | [diff] [blame] | 1289 | ret = 0; |
Jan Kara | c0eb31e | 2008-04-01 16:50:35 +0200 | [diff] [blame] | 1290 | goto out_bh; |
Marcin Slusarz | 165923f | 2008-02-10 11:33:08 +0100 | [diff] [blame] | 1291 | } |
| 1292 | |
Jan Kara | 3fb38df | 2008-04-02 12:26:36 +0200 | [diff] [blame] | 1293 | ret = udf_fill_partdesc_info(sb, p, i); |
Jan Kara | d759bfa4 | 2013-07-25 19:10:59 +0200 | [diff] [blame] | 1294 | if (ret < 0) |
| 1295 | goto out_bh; |
Jan Kara | 38b74a5 | 2008-04-02 16:01:35 +0200 | [diff] [blame] | 1296 | |
| 1297 | /* |
Jan Kara | bfb257a | 2008-04-08 20:37:21 +0200 | [diff] [blame] | 1298 | * Now rescan for VIRTUAL or METADATA partitions when SPARABLE and |
| 1299 | * PHYSICAL partitions are already set up |
Jan Kara | 38b74a5 | 2008-04-02 16:01:35 +0200 | [diff] [blame] | 1300 | */ |
| 1301 | type1_idx = i; |
Peter A. Felvegi | 4449960 | 2013-10-18 20:07:44 +0200 | [diff] [blame] | 1302 | #ifdef UDFFS_DEBUG |
| 1303 | map = NULL; /* supress 'maybe used uninitialized' warning */ |
| 1304 | #endif |
Jan Kara | 38b74a5 | 2008-04-02 16:01:35 +0200 | [diff] [blame] | 1305 | for (i = 0; i < sbi->s_partitions; i++) { |
| 1306 | map = &sbi->s_partmaps[i]; |
| 1307 | |
| 1308 | if (map->s_partition_num == partitionNumber && |
| 1309 | (map->s_partition_type == UDF_VIRTUAL_MAP15 || |
Jan Kara | bfb257a | 2008-04-08 20:37:21 +0200 | [diff] [blame] | 1310 | map->s_partition_type == UDF_VIRTUAL_MAP20 || |
| 1311 | map->s_partition_type == UDF_METADATA_MAP25)) |
Jan Kara | 38b74a5 | 2008-04-02 16:01:35 +0200 | [diff] [blame] | 1312 | break; |
| 1313 | } |
| 1314 | |
Jan Kara | d759bfa4 | 2013-07-25 19:10:59 +0200 | [diff] [blame] | 1315 | if (i >= sbi->s_partitions) { |
| 1316 | ret = 0; |
Jan Kara | 38b74a5 | 2008-04-02 16:01:35 +0200 | [diff] [blame] | 1317 | goto out_bh; |
Jan Kara | d759bfa4 | 2013-07-25 19:10:59 +0200 | [diff] [blame] | 1318 | } |
Jan Kara | 38b74a5 | 2008-04-02 16:01:35 +0200 | [diff] [blame] | 1319 | |
| 1320 | ret = udf_fill_partdesc_info(sb, p, i); |
Jan Kara | d759bfa4 | 2013-07-25 19:10:59 +0200 | [diff] [blame] | 1321 | if (ret < 0) |
Jan Kara | 38b74a5 | 2008-04-02 16:01:35 +0200 | [diff] [blame] | 1322 | goto out_bh; |
| 1323 | |
Jan Kara | bfb257a | 2008-04-08 20:37:21 +0200 | [diff] [blame] | 1324 | if (map->s_partition_type == UDF_METADATA_MAP25) { |
Alden Tondettar | 7888824 | 2016-05-18 14:09:19 -0700 | [diff] [blame] | 1325 | ret = udf_load_metadata_files(sb, i, type1_idx); |
Jan Kara | d759bfa4 | 2013-07-25 19:10:59 +0200 | [diff] [blame] | 1326 | if (ret < 0) { |
Joe Perches | 78ace70 | 2011-10-10 01:08:05 -0700 | [diff] [blame] | 1327 | udf_err(sb, "error loading MetaData partition map %d\n", |
| 1328 | i); |
Jan Kara | bfb257a | 2008-04-08 20:37:21 +0200 | [diff] [blame] | 1329 | goto out_bh; |
| 1330 | } |
| 1331 | } else { |
Jan Kara | e729eac | 2013-07-25 16:15:16 +0200 | [diff] [blame] | 1332 | /* |
| 1333 | * If we have a partition with virtual map, we don't handle |
| 1334 | * writing to it (we overwrite blocks instead of relocating |
| 1335 | * them). |
| 1336 | */ |
David Howells | bc98a42 | 2017-07-17 08:45:34 +0100 | [diff] [blame] | 1337 | if (!sb_rdonly(sb)) { |
Jan Kara | e729eac | 2013-07-25 16:15:16 +0200 | [diff] [blame] | 1338 | ret = -EACCES; |
| 1339 | goto out_bh; |
| 1340 | } |
Jan Kara | bfb257a | 2008-04-08 20:37:21 +0200 | [diff] [blame] | 1341 | ret = udf_load_vat(sb, i, type1_idx); |
Jan Kara | d759bfa4 | 2013-07-25 19:10:59 +0200 | [diff] [blame] | 1342 | if (ret < 0) |
Jan Kara | bfb257a | 2008-04-08 20:37:21 +0200 | [diff] [blame] | 1343 | goto out_bh; |
Jan Kara | bfb257a | 2008-04-08 20:37:21 +0200 | [diff] [blame] | 1344 | } |
Jan Kara | d759bfa4 | 2013-07-25 19:10:59 +0200 | [diff] [blame] | 1345 | ret = 0; |
Jan Kara | c0eb31e | 2008-04-01 16:50:35 +0200 | [diff] [blame] | 1346 | out_bh: |
Jan Kara | 2e0838f | 2008-04-01 18:08:51 +0200 | [diff] [blame] | 1347 | /* In case loading failed, we handle cleanup in udf_fill_super */ |
Jan Kara | c0eb31e | 2008-04-01 16:50:35 +0200 | [diff] [blame] | 1348 | brelse(bh); |
| 1349 | return ret; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1350 | } |
| 1351 | |
Jan Kara | 1df2ae3 | 2012-06-27 21:23:07 +0200 | [diff] [blame] | 1352 | static int udf_load_sparable_map(struct super_block *sb, |
| 1353 | struct udf_part_map *map, |
| 1354 | struct sparablePartitionMap *spm) |
| 1355 | { |
| 1356 | uint32_t loc; |
| 1357 | uint16_t ident; |
| 1358 | struct sparingTable *st; |
| 1359 | struct udf_sparing_data *sdata = &map->s_type_specific.s_sparing; |
| 1360 | int i; |
| 1361 | struct buffer_head *bh; |
| 1362 | |
| 1363 | map->s_partition_type = UDF_SPARABLE_MAP15; |
| 1364 | sdata->s_packet_len = le16_to_cpu(spm->packetLength); |
| 1365 | if (!is_power_of_2(sdata->s_packet_len)) { |
| 1366 | udf_err(sb, "error loading logical volume descriptor: " |
| 1367 | "Invalid packet length %u\n", |
| 1368 | (unsigned)sdata->s_packet_len); |
| 1369 | return -EIO; |
| 1370 | } |
| 1371 | if (spm->numSparingTables > 4) { |
| 1372 | udf_err(sb, "error loading logical volume descriptor: " |
| 1373 | "Too many sparing tables (%d)\n", |
| 1374 | (int)spm->numSparingTables); |
| 1375 | return -EIO; |
| 1376 | } |
| 1377 | |
| 1378 | for (i = 0; i < spm->numSparingTables; i++) { |
| 1379 | loc = le32_to_cpu(spm->locSparingTable[i]); |
| 1380 | bh = udf_read_tagged(sb, loc, loc, &ident); |
| 1381 | if (!bh) |
| 1382 | continue; |
| 1383 | |
| 1384 | st = (struct sparingTable *)bh->b_data; |
| 1385 | if (ident != 0 || |
| 1386 | strncmp(st->sparingIdent.ident, UDF_ID_SPARING, |
| 1387 | strlen(UDF_ID_SPARING)) || |
| 1388 | sizeof(*st) + le16_to_cpu(st->reallocationTableLen) > |
| 1389 | sb->s_blocksize) { |
| 1390 | brelse(bh); |
| 1391 | continue; |
| 1392 | } |
| 1393 | |
| 1394 | sdata->s_spar_map[i] = bh; |
| 1395 | } |
| 1396 | map->s_partition_func = udf_get_pblock_spar15; |
| 1397 | return 0; |
| 1398 | } |
| 1399 | |
Jan Kara | c0eb31e | 2008-04-01 16:50:35 +0200 | [diff] [blame] | 1400 | static int udf_load_logicalvol(struct super_block *sb, sector_t block, |
Pekka Enberg | 5ca4e4b | 2008-10-15 12:28:03 +0200 | [diff] [blame] | 1401 | struct kernel_lb_addr *fileset) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1402 | { |
| 1403 | struct logicalVolDesc *lvd; |
Jan Kara | 1df2ae3 | 2012-06-27 21:23:07 +0200 | [diff] [blame] | 1404 | int i, offset; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1405 | uint8_t type; |
Marcin Slusarz | 6c79e98 | 2008-02-08 04:20:30 -0800 | [diff] [blame] | 1406 | struct udf_sb_info *sbi = UDF_SB(sb); |
Marcin Slusarz | 4b11111 | 2008-02-08 04:20:36 -0800 | [diff] [blame] | 1407 | struct genericPartitionMap *gpm; |
Jan Kara | c0eb31e | 2008-04-01 16:50:35 +0200 | [diff] [blame] | 1408 | uint16_t ident; |
| 1409 | struct buffer_head *bh; |
Jan Kara | adee11b | 2012-06-27 20:20:22 +0200 | [diff] [blame] | 1410 | unsigned int table_len; |
Jan Kara | d759bfa4 | 2013-07-25 19:10:59 +0200 | [diff] [blame] | 1411 | int ret; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1412 | |
Jan Kara | c0eb31e | 2008-04-01 16:50:35 +0200 | [diff] [blame] | 1413 | bh = udf_read_tagged(sb, block, block, &ident); |
| 1414 | if (!bh) |
Jan Kara | d759bfa4 | 2013-07-25 19:10:59 +0200 | [diff] [blame] | 1415 | return -EAGAIN; |
Jan Kara | c0eb31e | 2008-04-01 16:50:35 +0200 | [diff] [blame] | 1416 | BUG_ON(ident != TAG_IDENT_LVD); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1417 | lvd = (struct logicalVolDesc *)bh->b_data; |
Jan Kara | adee11b | 2012-06-27 20:20:22 +0200 | [diff] [blame] | 1418 | table_len = le32_to_cpu(lvd->mapTableLength); |
Jan Kara | 57b9655 | 2012-07-10 17:58:04 +0200 | [diff] [blame] | 1419 | if (table_len > sb->s_blocksize - sizeof(*lvd)) { |
Jan Kara | adee11b | 2012-06-27 20:20:22 +0200 | [diff] [blame] | 1420 | udf_err(sb, "error loading logical volume descriptor: " |
| 1421 | "Partition table too long (%u > %lu)\n", table_len, |
| 1422 | sb->s_blocksize - sizeof(*lvd)); |
Jan Kara | d759bfa4 | 2013-07-25 19:10:59 +0200 | [diff] [blame] | 1423 | ret = -EIO; |
Jan Kara | adee11b | 2012-06-27 20:20:22 +0200 | [diff] [blame] | 1424 | goto out_bh; |
| 1425 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1426 | |
Jan Kara | cb14d34 | 2012-06-27 20:08:44 +0200 | [diff] [blame] | 1427 | ret = udf_sb_alloc_partition_maps(sb, le32_to_cpu(lvd->numPartitionMaps)); |
| 1428 | if (ret) |
Jan Kara | c0eb31e | 2008-04-01 16:50:35 +0200 | [diff] [blame] | 1429 | goto out_bh; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1430 | |
Cyrill Gorcunov | cb00ea3 | 2007-07-19 01:47:43 -0700 | [diff] [blame] | 1431 | for (i = 0, offset = 0; |
Jan Kara | adee11b | 2012-06-27 20:20:22 +0200 | [diff] [blame] | 1432 | i < sbi->s_partitions && offset < table_len; |
Marcin Slusarz | 4b11111 | 2008-02-08 04:20:36 -0800 | [diff] [blame] | 1433 | i++, offset += gpm->partitionMapLength) { |
| 1434 | struct udf_part_map *map = &sbi->s_partmaps[i]; |
| 1435 | gpm = (struct genericPartitionMap *) |
| 1436 | &(lvd->partitionMaps[offset]); |
| 1437 | type = gpm->partitionMapType; |
Cyrill Gorcunov | cb00ea3 | 2007-07-19 01:47:43 -0700 | [diff] [blame] | 1438 | if (type == 1) { |
Marcin Slusarz | 4b11111 | 2008-02-08 04:20:36 -0800 | [diff] [blame] | 1439 | struct genericPartitionMap1 *gpm1 = |
| 1440 | (struct genericPartitionMap1 *)gpm; |
Marcin Slusarz | 6c79e98 | 2008-02-08 04:20:30 -0800 | [diff] [blame] | 1441 | map->s_partition_type = UDF_TYPE1_MAP15; |
| 1442 | map->s_volumeseqnum = le16_to_cpu(gpm1->volSeqNum); |
| 1443 | map->s_partition_num = le16_to_cpu(gpm1->partitionNum); |
| 1444 | map->s_partition_func = NULL; |
Cyrill Gorcunov | cb00ea3 | 2007-07-19 01:47:43 -0700 | [diff] [blame] | 1445 | } else if (type == 2) { |
Marcin Slusarz | 4b11111 | 2008-02-08 04:20:36 -0800 | [diff] [blame] | 1446 | struct udfPartitionMap2 *upm2 = |
| 1447 | (struct udfPartitionMap2 *)gpm; |
| 1448 | if (!strncmp(upm2->partIdent.ident, UDF_ID_VIRTUAL, |
| 1449 | strlen(UDF_ID_VIRTUAL))) { |
| 1450 | u16 suf = |
| 1451 | le16_to_cpu(((__le16 *)upm2->partIdent. |
| 1452 | identSuffix)[0]); |
Jan Kara | c82a127 | 2008-04-08 01:16:32 +0200 | [diff] [blame] | 1453 | if (suf < 0x0200) { |
Marcin Slusarz | 4b11111 | 2008-02-08 04:20:36 -0800 | [diff] [blame] | 1454 | map->s_partition_type = |
| 1455 | UDF_VIRTUAL_MAP15; |
| 1456 | map->s_partition_func = |
| 1457 | udf_get_pblock_virt15; |
Jan Kara | c82a127 | 2008-04-08 01:16:32 +0200 | [diff] [blame] | 1458 | } else { |
Marcin Slusarz | 4b11111 | 2008-02-08 04:20:36 -0800 | [diff] [blame] | 1459 | map->s_partition_type = |
| 1460 | UDF_VIRTUAL_MAP20; |
| 1461 | map->s_partition_func = |
| 1462 | udf_get_pblock_virt20; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1463 | } |
Marcin Slusarz | 4b11111 | 2008-02-08 04:20:36 -0800 | [diff] [blame] | 1464 | } else if (!strncmp(upm2->partIdent.ident, |
| 1465 | UDF_ID_SPARABLE, |
| 1466 | strlen(UDF_ID_SPARABLE))) { |
Jan Kara | d759bfa4 | 2013-07-25 19:10:59 +0200 | [diff] [blame] | 1467 | ret = udf_load_sparable_map(sb, map, |
| 1468 | (struct sparablePartitionMap *)gpm); |
| 1469 | if (ret < 0) |
Jan Kara | 1df2ae3 | 2012-06-27 21:23:07 +0200 | [diff] [blame] | 1470 | goto out_bh; |
Jan Kara | bfb257a | 2008-04-08 20:37:21 +0200 | [diff] [blame] | 1471 | } else if (!strncmp(upm2->partIdent.ident, |
| 1472 | UDF_ID_METADATA, |
| 1473 | strlen(UDF_ID_METADATA))) { |
| 1474 | struct udf_meta_data *mdata = |
| 1475 | &map->s_type_specific.s_metadata; |
| 1476 | struct metadataPartitionMap *mdm = |
| 1477 | (struct metadataPartitionMap *) |
| 1478 | &(lvd->partitionMaps[offset]); |
Steve Magnani | fcbf763 | 2017-10-12 08:48:41 -0500 | [diff] [blame] | 1479 | udf_debug("Parsing Logical vol part %d type %u id=%s\n", |
Joe Perches | a983f36 | 2011-10-10 01:08:07 -0700 | [diff] [blame] | 1480 | i, type, UDF_ID_METADATA); |
Jan Kara | bfb257a | 2008-04-08 20:37:21 +0200 | [diff] [blame] | 1481 | |
| 1482 | map->s_partition_type = UDF_METADATA_MAP25; |
| 1483 | map->s_partition_func = udf_get_pblock_meta25; |
| 1484 | |
| 1485 | mdata->s_meta_file_loc = |
| 1486 | le32_to_cpu(mdm->metadataFileLoc); |
| 1487 | mdata->s_mirror_file_loc = |
| 1488 | le32_to_cpu(mdm->metadataMirrorFileLoc); |
| 1489 | mdata->s_bitmap_file_loc = |
| 1490 | le32_to_cpu(mdm->metadataBitmapFileLoc); |
| 1491 | mdata->s_alloc_unit_size = |
| 1492 | le32_to_cpu(mdm->allocUnitSize); |
| 1493 | mdata->s_align_unit_size = |
| 1494 | le16_to_cpu(mdm->alignUnitSize); |
Jan Kara | ed47a7d | 2011-10-24 16:47:48 +0200 | [diff] [blame] | 1495 | if (mdm->flags & 0x01) |
| 1496 | mdata->s_flags |= MF_DUPLICATE_MD; |
Jan Kara | bfb257a | 2008-04-08 20:37:21 +0200 | [diff] [blame] | 1497 | |
| 1498 | udf_debug("Metadata Ident suffix=0x%x\n", |
Joe Perches | a983f36 | 2011-10-10 01:08:07 -0700 | [diff] [blame] | 1499 | le16_to_cpu(*(__le16 *) |
| 1500 | mdm->partIdent.identSuffix)); |
Steve Magnani | fcbf763 | 2017-10-12 08:48:41 -0500 | [diff] [blame] | 1501 | udf_debug("Metadata part num=%u\n", |
Joe Perches | a983f36 | 2011-10-10 01:08:07 -0700 | [diff] [blame] | 1502 | le16_to_cpu(mdm->partitionNum)); |
Steve Magnani | fcbf763 | 2017-10-12 08:48:41 -0500 | [diff] [blame] | 1503 | udf_debug("Metadata part alloc unit size=%u\n", |
Joe Perches | a983f36 | 2011-10-10 01:08:07 -0700 | [diff] [blame] | 1504 | le32_to_cpu(mdm->allocUnitSize)); |
Steve Magnani | fcbf763 | 2017-10-12 08:48:41 -0500 | [diff] [blame] | 1505 | udf_debug("Metadata file loc=%u\n", |
Joe Perches | a983f36 | 2011-10-10 01:08:07 -0700 | [diff] [blame] | 1506 | le32_to_cpu(mdm->metadataFileLoc)); |
Steve Magnani | fcbf763 | 2017-10-12 08:48:41 -0500 | [diff] [blame] | 1507 | udf_debug("Mirror file loc=%u\n", |
Joe Perches | a983f36 | 2011-10-10 01:08:07 -0700 | [diff] [blame] | 1508 | le32_to_cpu(mdm->metadataMirrorFileLoc)); |
Steve Magnani | fcbf763 | 2017-10-12 08:48:41 -0500 | [diff] [blame] | 1509 | udf_debug("Bitmap file loc=%u\n", |
Joe Perches | a983f36 | 2011-10-10 01:08:07 -0700 | [diff] [blame] | 1510 | le32_to_cpu(mdm->metadataBitmapFileLoc)); |
Steve Magnani | fcbf763 | 2017-10-12 08:48:41 -0500 | [diff] [blame] | 1511 | udf_debug("Flags: %d %u\n", |
Jan Kara | ed47a7d | 2011-10-24 16:47:48 +0200 | [diff] [blame] | 1512 | mdata->s_flags, mdm->flags); |
Cyrill Gorcunov | cb00ea3 | 2007-07-19 01:47:43 -0700 | [diff] [blame] | 1513 | } else { |
Marcin Slusarz | 3a71fc5 | 2008-02-08 04:20:28 -0800 | [diff] [blame] | 1514 | udf_debug("Unknown ident: %s\n", |
| 1515 | upm2->partIdent.ident); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1516 | continue; |
| 1517 | } |
Marcin Slusarz | 6c79e98 | 2008-02-08 04:20:30 -0800 | [diff] [blame] | 1518 | map->s_volumeseqnum = le16_to_cpu(upm2->volSeqNum); |
| 1519 | map->s_partition_num = le16_to_cpu(upm2->partitionNum); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1520 | } |
Steve Magnani | fcbf763 | 2017-10-12 08:48:41 -0500 | [diff] [blame] | 1521 | udf_debug("Partition (%d:%u) type %u on volume %u\n", |
Joe Perches | a983f36 | 2011-10-10 01:08:07 -0700 | [diff] [blame] | 1522 | i, map->s_partition_num, type, map->s_volumeseqnum); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1523 | } |
| 1524 | |
Cyrill Gorcunov | cb00ea3 | 2007-07-19 01:47:43 -0700 | [diff] [blame] | 1525 | if (fileset) { |
Pekka Enberg | 5ca4e4b | 2008-10-15 12:28:03 +0200 | [diff] [blame] | 1526 | struct long_ad *la = (struct long_ad *)&(lvd->logicalVolContentsUse[0]); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1527 | |
| 1528 | *fileset = lelb_to_cpu(la->extLocation); |
Steve Magnani | fcbf763 | 2017-10-12 08:48:41 -0500 | [diff] [blame] | 1529 | udf_debug("FileSet found in LogicalVolDesc at block=%u, partition=%u\n", |
Joe Perches | a983f36 | 2011-10-10 01:08:07 -0700 | [diff] [blame] | 1530 | fileset->logicalBlockNum, |
Cyrill Gorcunov | 28de794 | 2007-07-21 04:37:18 -0700 | [diff] [blame] | 1531 | fileset->partitionReferenceNum); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1532 | } |
| 1533 | if (lvd->integritySeqExt.extLength) |
| 1534 | udf_load_logicalvolint(sb, leea_to_cpu(lvd->integritySeqExt)); |
Jan Kara | d759bfa4 | 2013-07-25 19:10:59 +0200 | [diff] [blame] | 1535 | ret = 0; |
Jan Kara | c0eb31e | 2008-04-01 16:50:35 +0200 | [diff] [blame] | 1536 | out_bh: |
| 1537 | brelse(bh); |
| 1538 | return ret; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1539 | } |
| 1540 | |
| 1541 | /* |
Alden Tondettar | a47241c | 2016-04-25 19:27:56 -0700 | [diff] [blame] | 1542 | * Find the prevailing Logical Volume Integrity Descriptor. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1543 | */ |
Pekka Enberg | 5ca4e4b | 2008-10-15 12:28:03 +0200 | [diff] [blame] | 1544 | static void udf_load_logicalvolint(struct super_block *sb, struct kernel_extent_ad loc) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1545 | { |
Alden Tondettar | a47241c | 2016-04-25 19:27:56 -0700 | [diff] [blame] | 1546 | struct buffer_head *bh, *final_bh; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1547 | uint16_t ident; |
Marcin Slusarz | 6c79e98 | 2008-02-08 04:20:30 -0800 | [diff] [blame] | 1548 | struct udf_sb_info *sbi = UDF_SB(sb); |
| 1549 | struct logicalVolIntegrityDesc *lvid; |
Alden Tondettar | a47241c | 2016-04-25 19:27:56 -0700 | [diff] [blame] | 1550 | int indirections = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1551 | |
Alden Tondettar | a47241c | 2016-04-25 19:27:56 -0700 | [diff] [blame] | 1552 | while (++indirections <= UDF_MAX_LVID_NESTING) { |
| 1553 | final_bh = NULL; |
| 1554 | while (loc.extLength > 0 && |
| 1555 | (bh = udf_read_tagged(sb, loc.extLocation, |
| 1556 | loc.extLocation, &ident))) { |
| 1557 | if (ident != TAG_IDENT_LVID) { |
| 1558 | brelse(bh); |
| 1559 | break; |
| 1560 | } |
Cyrill Gorcunov | cb00ea3 | 2007-07-19 01:47:43 -0700 | [diff] [blame] | 1561 | |
Alden Tondettar | a47241c | 2016-04-25 19:27:56 -0700 | [diff] [blame] | 1562 | brelse(final_bh); |
| 1563 | final_bh = bh; |
Cyrill Gorcunov | cb00ea3 | 2007-07-19 01:47:43 -0700 | [diff] [blame] | 1564 | |
Alden Tondettar | a47241c | 2016-04-25 19:27:56 -0700 | [diff] [blame] | 1565 | loc.extLength -= sb->s_blocksize; |
| 1566 | loc.extLocation++; |
| 1567 | } |
| 1568 | |
| 1569 | if (!final_bh) |
| 1570 | return; |
| 1571 | |
| 1572 | brelse(sbi->s_lvid_bh); |
| 1573 | sbi->s_lvid_bh = final_bh; |
| 1574 | |
| 1575 | lvid = (struct logicalVolIntegrityDesc *)final_bh->b_data; |
| 1576 | if (lvid->nextIntegrityExt.extLength == 0) |
| 1577 | return; |
| 1578 | |
| 1579 | loc = leea_to_cpu(lvid->nextIntegrityExt); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1580 | } |
Alden Tondettar | a47241c | 2016-04-25 19:27:56 -0700 | [diff] [blame] | 1581 | |
| 1582 | udf_warn(sb, "Too many LVID indirections (max %u), ignoring.\n", |
| 1583 | UDF_MAX_LVID_NESTING); |
| 1584 | brelse(sbi->s_lvid_bh); |
| 1585 | sbi->s_lvid_bh = NULL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1586 | } |
| 1587 | |
Jan Kara | 7b78fd0 | 2018-02-09 15:56:34 +0100 | [diff] [blame] | 1588 | /* |
| 1589 | * Step for reallocation of table of partition descriptor sequence numbers. |
| 1590 | * Must be power of 2. |
| 1591 | */ |
| 1592 | #define PART_DESC_ALLOC_STEP 32 |
| 1593 | |
| 1594 | struct desc_seq_scan_data { |
| 1595 | struct udf_vds_record vds[VDS_POS_LENGTH]; |
| 1596 | unsigned int size_part_descs; |
| 1597 | struct udf_vds_record *part_descs_loc; |
| 1598 | }; |
| 1599 | |
| 1600 | static struct udf_vds_record *handle_partition_descriptor( |
| 1601 | struct buffer_head *bh, |
| 1602 | struct desc_seq_scan_data *data) |
| 1603 | { |
| 1604 | struct partitionDesc *desc = (struct partitionDesc *)bh->b_data; |
| 1605 | int partnum; |
| 1606 | |
| 1607 | partnum = le16_to_cpu(desc->partitionNumber); |
| 1608 | if (partnum >= data->size_part_descs) { |
| 1609 | struct udf_vds_record *new_loc; |
| 1610 | unsigned int new_size = ALIGN(partnum, PART_DESC_ALLOC_STEP); |
| 1611 | |
| 1612 | new_loc = kzalloc(sizeof(*new_loc) * new_size, GFP_KERNEL); |
| 1613 | if (!new_loc) |
| 1614 | return ERR_PTR(-ENOMEM); |
| 1615 | memcpy(new_loc, data->part_descs_loc, |
| 1616 | data->size_part_descs * sizeof(*new_loc)); |
| 1617 | kfree(data->part_descs_loc); |
| 1618 | data->part_descs_loc = new_loc; |
| 1619 | data->size_part_descs = new_size; |
| 1620 | } |
| 1621 | return &(data->part_descs_loc[partnum]); |
| 1622 | } |
| 1623 | |
| 1624 | |
| 1625 | static struct udf_vds_record *get_volume_descriptor_record(uint16_t ident, |
| 1626 | struct buffer_head *bh, struct desc_seq_scan_data *data) |
Jan Kara | 18cf4781 | 2018-02-09 15:15:39 +0100 | [diff] [blame] | 1627 | { |
| 1628 | switch (ident) { |
| 1629 | case TAG_IDENT_PVD: /* ISO 13346 3/10.1 */ |
Jan Kara | 7b78fd0 | 2018-02-09 15:56:34 +0100 | [diff] [blame] | 1630 | return &(data->vds[VDS_POS_PRIMARY_VOL_DESC]); |
Jan Kara | 18cf4781 | 2018-02-09 15:15:39 +0100 | [diff] [blame] | 1631 | case TAG_IDENT_IUVD: /* ISO 13346 3/10.4 */ |
Jan Kara | 7b78fd0 | 2018-02-09 15:56:34 +0100 | [diff] [blame] | 1632 | return &(data->vds[VDS_POS_IMP_USE_VOL_DESC]); |
Jan Kara | 18cf4781 | 2018-02-09 15:15:39 +0100 | [diff] [blame] | 1633 | case TAG_IDENT_LVD: /* ISO 13346 3/10.6 */ |
Jan Kara | 7b78fd0 | 2018-02-09 15:56:34 +0100 | [diff] [blame] | 1634 | return &(data->vds[VDS_POS_LOGICAL_VOL_DESC]); |
Jan Kara | 18cf4781 | 2018-02-09 15:15:39 +0100 | [diff] [blame] | 1635 | case TAG_IDENT_USD: /* ISO 13346 3/10.8 */ |
Jan Kara | 7b78fd0 | 2018-02-09 15:56:34 +0100 | [diff] [blame] | 1636 | return &(data->vds[VDS_POS_UNALLOC_SPACE_DESC]); |
| 1637 | case TAG_IDENT_PD: /* ISO 13346 3/10.5 */ |
| 1638 | return handle_partition_descriptor(bh, data); |
Jan Kara | 18cf4781 | 2018-02-09 15:15:39 +0100 | [diff] [blame] | 1639 | } |
| 1640 | return NULL; |
| 1641 | } |
Vegard Nossum | e7a4eb8 | 2015-12-10 17:13:41 +0100 | [diff] [blame] | 1642 | |
| 1643 | /* |
Jan Kara | d759bfa4 | 2013-07-25 19:10:59 +0200 | [diff] [blame] | 1644 | * Process a main/reserve volume descriptor sequence. |
| 1645 | * @block First block of first extent of the sequence. |
| 1646 | * @lastblock Lastblock of first extent of the sequence. |
| 1647 | * @fileset There we store extent containing root fileset |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1648 | * |
Jan Kara | d759bfa4 | 2013-07-25 19:10:59 +0200 | [diff] [blame] | 1649 | * Returns <0 on error, 0 on success. -EAGAIN is special - try next descriptor |
| 1650 | * sequence |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1651 | */ |
Jan Kara | d759bfa4 | 2013-07-25 19:10:59 +0200 | [diff] [blame] | 1652 | static noinline int udf_process_sequence( |
| 1653 | struct super_block *sb, |
| 1654 | sector_t block, sector_t lastblock, |
| 1655 | struct kernel_lb_addr *fileset) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1656 | { |
| 1657 | struct buffer_head *bh = NULL; |
Marcin Slusarz | 4b11111 | 2008-02-08 04:20:36 -0800 | [diff] [blame] | 1658 | struct udf_vds_record *curr; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1659 | struct generic_desc *gd; |
| 1660 | struct volDescPtr *vdp; |
Fabian Frederick | 2b8f942 | 2015-02-04 18:15:04 +0100 | [diff] [blame] | 1661 | bool done = false; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1662 | uint32_t vdsn; |
| 1663 | uint16_t ident; |
Jan Kara | d759bfa4 | 2013-07-25 19:10:59 +0200 | [diff] [blame] | 1664 | int ret; |
Vegard Nossum | e7a4eb8 | 2015-12-10 17:13:41 +0100 | [diff] [blame] | 1665 | unsigned int indirections = 0; |
Jan Kara | 7b78fd0 | 2018-02-09 15:56:34 +0100 | [diff] [blame] | 1666 | struct desc_seq_scan_data data; |
| 1667 | unsigned int i; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1668 | |
Jan Kara | 7b78fd0 | 2018-02-09 15:56:34 +0100 | [diff] [blame] | 1669 | memset(data.vds, 0, sizeof(struct udf_vds_record) * VDS_POS_LENGTH); |
| 1670 | data.size_part_descs = PART_DESC_ALLOC_STEP; |
| 1671 | data.part_descs_loc = kzalloc(sizeof(*data.part_descs_loc) * |
| 1672 | data.size_part_descs, GFP_KERNEL); |
| 1673 | if (!data.part_descs_loc) |
| 1674 | return -ENOMEM; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1675 | |
Jan Kara | c0eb31e | 2008-04-01 16:50:35 +0200 | [diff] [blame] | 1676 | /* |
| 1677 | * Read the main descriptor sequence and find which descriptors |
| 1678 | * are in it. |
| 1679 | */ |
Cyrill Gorcunov | cb00ea3 | 2007-07-19 01:47:43 -0700 | [diff] [blame] | 1680 | for (; (!done && block <= lastblock); block++) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1681 | |
| 1682 | bh = udf_read_tagged(sb, block, block, &ident); |
Jan Kara | 6762167 | 2018-02-08 18:10:54 +0100 | [diff] [blame] | 1683 | if (!bh) |
| 1684 | break; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1685 | |
| 1686 | /* Process each descriptor (ISO 13346 3/8.3-8.4) */ |
| 1687 | gd = (struct generic_desc *)bh->b_data; |
| 1688 | vdsn = le32_to_cpu(gd->volDescSeqNum); |
Cyrill Gorcunov | cb00ea3 | 2007-07-19 01:47:43 -0700 | [diff] [blame] | 1689 | switch (ident) { |
Cyrill Gorcunov | 28de794 | 2007-07-21 04:37:18 -0700 | [diff] [blame] | 1690 | case TAG_IDENT_VDP: /* ISO 13346 3/10.3 */ |
Jan Kara | 7b568cb | 2018-02-09 13:28:41 +0100 | [diff] [blame] | 1691 | if (++indirections > UDF_MAX_TD_NESTING) { |
| 1692 | udf_err(sb, "too many Volume Descriptor " |
| 1693 | "Pointers (max %u supported)\n", |
| 1694 | UDF_MAX_TD_NESTING); |
| 1695 | brelse(bh); |
| 1696 | return -EIO; |
Cyrill Gorcunov | cb00ea3 | 2007-07-19 01:47:43 -0700 | [diff] [blame] | 1697 | } |
Jan Kara | 7b568cb | 2018-02-09 13:28:41 +0100 | [diff] [blame] | 1698 | |
| 1699 | vdp = (struct volDescPtr *)bh->b_data; |
| 1700 | block = le32_to_cpu(vdp->nextVolDescSeqExt.extLocation); |
| 1701 | lastblock = le32_to_cpu( |
| 1702 | vdp->nextVolDescSeqExt.extLength) >> |
| 1703 | sb->s_blocksize_bits; |
| 1704 | lastblock += block - 1; |
| 1705 | /* For loop is going to increment 'block' again */ |
| 1706 | block--; |
Cyrill Gorcunov | cb00ea3 | 2007-07-19 01:47:43 -0700 | [diff] [blame] | 1707 | break; |
Jan Kara | 18cf4781 | 2018-02-09 15:15:39 +0100 | [diff] [blame] | 1708 | case TAG_IDENT_PVD: /* ISO 13346 3/10.1 */ |
Cyrill Gorcunov | 28de794 | 2007-07-21 04:37:18 -0700 | [diff] [blame] | 1709 | case TAG_IDENT_IUVD: /* ISO 13346 3/10.4 */ |
Jan Kara | 18cf4781 | 2018-02-09 15:15:39 +0100 | [diff] [blame] | 1710 | case TAG_IDENT_LVD: /* ISO 13346 3/10.6 */ |
| 1711 | case TAG_IDENT_USD: /* ISO 13346 3/10.8 */ |
Jan Kara | 7b78fd0 | 2018-02-09 15:56:34 +0100 | [diff] [blame] | 1712 | case TAG_IDENT_PD: /* ISO 13346 3/10.5 */ |
| 1713 | curr = get_volume_descriptor_record(ident, bh, &data); |
| 1714 | if (IS_ERR(curr)) { |
| 1715 | brelse(bh); |
| 1716 | return PTR_ERR(curr); |
| 1717 | } |
| 1718 | /* Descriptor we don't care about? */ |
| 1719 | if (!curr) |
| 1720 | break; |
Marcin Slusarz | 4b11111 | 2008-02-08 04:20:36 -0800 | [diff] [blame] | 1721 | if (vdsn >= curr->volDescSeqNum) { |
| 1722 | curr->volDescSeqNum = vdsn; |
| 1723 | curr->block = block; |
Cyrill Gorcunov | cb00ea3 | 2007-07-19 01:47:43 -0700 | [diff] [blame] | 1724 | } |
| 1725 | break; |
Cyrill Gorcunov | 28de794 | 2007-07-21 04:37:18 -0700 | [diff] [blame] | 1726 | case TAG_IDENT_TD: /* ISO 13346 3/10.9 */ |
Jan Kara | 7b568cb | 2018-02-09 13:28:41 +0100 | [diff] [blame] | 1727 | done = true; |
Cyrill Gorcunov | cb00ea3 | 2007-07-19 01:47:43 -0700 | [diff] [blame] | 1728 | break; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1729 | } |
Jan Kara | 3bf25cb | 2007-05-08 00:35:16 -0700 | [diff] [blame] | 1730 | brelse(bh); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1731 | } |
Jan Kara | c0eb31e | 2008-04-01 16:50:35 +0200 | [diff] [blame] | 1732 | /* |
| 1733 | * Now read interesting descriptors again and process them |
| 1734 | * in a suitable order |
| 1735 | */ |
Jan Kara | 7b78fd0 | 2018-02-09 15:56:34 +0100 | [diff] [blame] | 1736 | if (!data.vds[VDS_POS_PRIMARY_VOL_DESC].block) { |
Joe Perches | 78ace70 | 2011-10-10 01:08:05 -0700 | [diff] [blame] | 1737 | udf_err(sb, "Primary Volume Descriptor not found!\n"); |
Jan Kara | d759bfa4 | 2013-07-25 19:10:59 +0200 | [diff] [blame] | 1738 | return -EAGAIN; |
Jan Kara | c0eb31e | 2008-04-01 16:50:35 +0200 | [diff] [blame] | 1739 | } |
Jan Kara | 7b78fd0 | 2018-02-09 15:56:34 +0100 | [diff] [blame] | 1740 | ret = udf_load_pvoldesc(sb, data.vds[VDS_POS_PRIMARY_VOL_DESC].block); |
Jan Kara | d759bfa4 | 2013-07-25 19:10:59 +0200 | [diff] [blame] | 1741 | if (ret < 0) |
| 1742 | return ret; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1743 | |
Jan Kara | 7b78fd0 | 2018-02-09 15:56:34 +0100 | [diff] [blame] | 1744 | if (data.vds[VDS_POS_LOGICAL_VOL_DESC].block) { |
Jan Kara | d759bfa4 | 2013-07-25 19:10:59 +0200 | [diff] [blame] | 1745 | ret = udf_load_logicalvol(sb, |
Jan Kara | 7b78fd0 | 2018-02-09 15:56:34 +0100 | [diff] [blame] | 1746 | data.vds[VDS_POS_LOGICAL_VOL_DESC].block, |
| 1747 | fileset); |
Jan Kara | d759bfa4 | 2013-07-25 19:10:59 +0200 | [diff] [blame] | 1748 | if (ret < 0) |
| 1749 | return ret; |
| 1750 | } |
Marcin Slusarz | 165923f | 2008-02-10 11:33:08 +0100 | [diff] [blame] | 1751 | |
Jan Kara | 7b78fd0 | 2018-02-09 15:56:34 +0100 | [diff] [blame] | 1752 | /* Now handle prevailing Partition Descriptors */ |
| 1753 | for (i = 0; i < data.size_part_descs; i++) { |
| 1754 | if (data.part_descs_loc[i].block) { |
| 1755 | ret = udf_load_partdesc(sb, |
| 1756 | data.part_descs_loc[i].block); |
Jan Kara | d759bfa4 | 2013-07-25 19:10:59 +0200 | [diff] [blame] | 1757 | if (ret < 0) |
| 1758 | return ret; |
| 1759 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1760 | } |
| 1761 | |
| 1762 | return 0; |
| 1763 | } |
| 1764 | |
Jan Kara | d759bfa4 | 2013-07-25 19:10:59 +0200 | [diff] [blame] | 1765 | /* |
| 1766 | * Load Volume Descriptor Sequence described by anchor in bh |
| 1767 | * |
| 1768 | * Returns <0 on error, 0 on success |
| 1769 | */ |
Jan Kara | 40346005 | 2009-03-19 16:21:38 +0100 | [diff] [blame] | 1770 | static int udf_load_sequence(struct super_block *sb, struct buffer_head *bh, |
| 1771 | struct kernel_lb_addr *fileset) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1772 | { |
Jan Kara | 40346005 | 2009-03-19 16:21:38 +0100 | [diff] [blame] | 1773 | struct anchorVolDescPtr *anchor; |
Jan Kara | d759bfa4 | 2013-07-25 19:10:59 +0200 | [diff] [blame] | 1774 | sector_t main_s, main_e, reserve_s, reserve_e; |
| 1775 | int ret; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1776 | |
Jan Kara | 40346005 | 2009-03-19 16:21:38 +0100 | [diff] [blame] | 1777 | anchor = (struct anchorVolDescPtr *)bh->b_data; |
| 1778 | |
| 1779 | /* Locate the main sequence */ |
| 1780 | main_s = le32_to_cpu(anchor->mainVolDescSeqExt.extLocation); |
| 1781 | main_e = le32_to_cpu(anchor->mainVolDescSeqExt.extLength); |
| 1782 | main_e = main_e >> sb->s_blocksize_bits; |
Jan Kara | 91c9c9e | 2018-02-08 17:39:01 +0100 | [diff] [blame] | 1783 | main_e += main_s - 1; |
Jan Kara | 40346005 | 2009-03-19 16:21:38 +0100 | [diff] [blame] | 1784 | |
| 1785 | /* Locate the reserve sequence */ |
| 1786 | reserve_s = le32_to_cpu(anchor->reserveVolDescSeqExt.extLocation); |
| 1787 | reserve_e = le32_to_cpu(anchor->reserveVolDescSeqExt.extLength); |
| 1788 | reserve_e = reserve_e >> sb->s_blocksize_bits; |
Jan Kara | 91c9c9e | 2018-02-08 17:39:01 +0100 | [diff] [blame] | 1789 | reserve_e += reserve_s - 1; |
Jan Kara | 40346005 | 2009-03-19 16:21:38 +0100 | [diff] [blame] | 1790 | |
| 1791 | /* Process the main & reserve sequences */ |
| 1792 | /* responsible for finding the PartitionDesc(s) */ |
Jan Kara | d759bfa4 | 2013-07-25 19:10:59 +0200 | [diff] [blame] | 1793 | ret = udf_process_sequence(sb, main_s, main_e, fileset); |
| 1794 | if (ret != -EAGAIN) |
| 1795 | return ret; |
Jan Kara | bff943a | 2012-06-27 22:27:05 +0200 | [diff] [blame] | 1796 | udf_sb_free_partitions(sb); |
Jan Kara | d759bfa4 | 2013-07-25 19:10:59 +0200 | [diff] [blame] | 1797 | ret = udf_process_sequence(sb, reserve_s, reserve_e, fileset); |
| 1798 | if (ret < 0) { |
| 1799 | udf_sb_free_partitions(sb); |
| 1800 | /* No sequence was OK, return -EIO */ |
| 1801 | if (ret == -EAGAIN) |
| 1802 | ret = -EIO; |
| 1803 | } |
| 1804 | return ret; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1805 | } |
| 1806 | |
Jan Kara | 40346005 | 2009-03-19 16:21:38 +0100 | [diff] [blame] | 1807 | /* |
| 1808 | * Check whether there is an anchor block in the given block and |
| 1809 | * load Volume Descriptor Sequence if so. |
Jan Kara | d759bfa4 | 2013-07-25 19:10:59 +0200 | [diff] [blame] | 1810 | * |
| 1811 | * Returns <0 on error, 0 on success, -EAGAIN is special - try next anchor |
| 1812 | * block |
Jan Kara | 40346005 | 2009-03-19 16:21:38 +0100 | [diff] [blame] | 1813 | */ |
| 1814 | static int udf_check_anchor_block(struct super_block *sb, sector_t block, |
| 1815 | struct kernel_lb_addr *fileset) |
| 1816 | { |
| 1817 | struct buffer_head *bh; |
| 1818 | uint16_t ident; |
| 1819 | int ret; |
| 1820 | |
| 1821 | if (UDF_QUERY_FLAG(sb, UDF_FLAG_VARCONV) && |
| 1822 | udf_fixed_to_variable(block) >= |
Fabian Frederick | 23bcda1 | 2017-01-06 21:54:41 +0100 | [diff] [blame] | 1823 | i_size_read(sb->s_bdev->bd_inode) >> sb->s_blocksize_bits) |
Jan Kara | d759bfa4 | 2013-07-25 19:10:59 +0200 | [diff] [blame] | 1824 | return -EAGAIN; |
Jan Kara | 40346005 | 2009-03-19 16:21:38 +0100 | [diff] [blame] | 1825 | |
| 1826 | bh = udf_read_tagged(sb, block, block, &ident); |
| 1827 | if (!bh) |
Jan Kara | d759bfa4 | 2013-07-25 19:10:59 +0200 | [diff] [blame] | 1828 | return -EAGAIN; |
Jan Kara | 40346005 | 2009-03-19 16:21:38 +0100 | [diff] [blame] | 1829 | if (ident != TAG_IDENT_AVDP) { |
| 1830 | brelse(bh); |
Jan Kara | d759bfa4 | 2013-07-25 19:10:59 +0200 | [diff] [blame] | 1831 | return -EAGAIN; |
Jan Kara | 40346005 | 2009-03-19 16:21:38 +0100 | [diff] [blame] | 1832 | } |
| 1833 | ret = udf_load_sequence(sb, bh, fileset); |
| 1834 | brelse(bh); |
| 1835 | return ret; |
| 1836 | } |
| 1837 | |
Jan Kara | d759bfa4 | 2013-07-25 19:10:59 +0200 | [diff] [blame] | 1838 | /* |
| 1839 | * Search for an anchor volume descriptor pointer. |
| 1840 | * |
| 1841 | * Returns < 0 on error, 0 on success. -EAGAIN is special - try next set |
| 1842 | * of anchors. |
| 1843 | */ |
| 1844 | static int udf_scan_anchors(struct super_block *sb, sector_t *lastblock, |
| 1845 | struct kernel_lb_addr *fileset) |
Jan Kara | 40346005 | 2009-03-19 16:21:38 +0100 | [diff] [blame] | 1846 | { |
| 1847 | sector_t last[6]; |
| 1848 | int i; |
| 1849 | struct udf_sb_info *sbi = UDF_SB(sb); |
| 1850 | int last_count = 0; |
Jan Kara | d759bfa4 | 2013-07-25 19:10:59 +0200 | [diff] [blame] | 1851 | int ret; |
Jan Kara | 40346005 | 2009-03-19 16:21:38 +0100 | [diff] [blame] | 1852 | |
| 1853 | /* First try user provided anchor */ |
| 1854 | if (sbi->s_anchor) { |
Jan Kara | d759bfa4 | 2013-07-25 19:10:59 +0200 | [diff] [blame] | 1855 | ret = udf_check_anchor_block(sb, sbi->s_anchor, fileset); |
| 1856 | if (ret != -EAGAIN) |
| 1857 | return ret; |
Jan Kara | 40346005 | 2009-03-19 16:21:38 +0100 | [diff] [blame] | 1858 | } |
| 1859 | /* |
| 1860 | * according to spec, anchor is in either: |
| 1861 | * block 256 |
| 1862 | * lastblock-256 |
| 1863 | * lastblock |
| 1864 | * however, if the disc isn't closed, it could be 512. |
| 1865 | */ |
Jan Kara | d759bfa4 | 2013-07-25 19:10:59 +0200 | [diff] [blame] | 1866 | ret = udf_check_anchor_block(sb, sbi->s_session + 256, fileset); |
| 1867 | if (ret != -EAGAIN) |
| 1868 | return ret; |
Jan Kara | 40346005 | 2009-03-19 16:21:38 +0100 | [diff] [blame] | 1869 | /* |
| 1870 | * The trouble is which block is the last one. Drives often misreport |
| 1871 | * this so we try various possibilities. |
| 1872 | */ |
Jan Kara | d759bfa4 | 2013-07-25 19:10:59 +0200 | [diff] [blame] | 1873 | last[last_count++] = *lastblock; |
| 1874 | if (*lastblock >= 1) |
| 1875 | last[last_count++] = *lastblock - 1; |
| 1876 | last[last_count++] = *lastblock + 1; |
| 1877 | if (*lastblock >= 2) |
| 1878 | last[last_count++] = *lastblock - 2; |
| 1879 | if (*lastblock >= 150) |
| 1880 | last[last_count++] = *lastblock - 150; |
| 1881 | if (*lastblock >= 152) |
| 1882 | last[last_count++] = *lastblock - 152; |
Jan Kara | 40346005 | 2009-03-19 16:21:38 +0100 | [diff] [blame] | 1883 | |
| 1884 | for (i = 0; i < last_count; i++) { |
Fabian Frederick | 23bcda1 | 2017-01-06 21:54:41 +0100 | [diff] [blame] | 1885 | if (last[i] >= i_size_read(sb->s_bdev->bd_inode) >> |
Jan Kara | 40346005 | 2009-03-19 16:21:38 +0100 | [diff] [blame] | 1886 | sb->s_blocksize_bits) |
| 1887 | continue; |
Jan Kara | d759bfa4 | 2013-07-25 19:10:59 +0200 | [diff] [blame] | 1888 | ret = udf_check_anchor_block(sb, last[i], fileset); |
| 1889 | if (ret != -EAGAIN) { |
| 1890 | if (!ret) |
| 1891 | *lastblock = last[i]; |
| 1892 | return ret; |
| 1893 | } |
Jan Kara | 40346005 | 2009-03-19 16:21:38 +0100 | [diff] [blame] | 1894 | if (last[i] < 256) |
| 1895 | continue; |
Jan Kara | d759bfa4 | 2013-07-25 19:10:59 +0200 | [diff] [blame] | 1896 | ret = udf_check_anchor_block(sb, last[i] - 256, fileset); |
| 1897 | if (ret != -EAGAIN) { |
| 1898 | if (!ret) |
| 1899 | *lastblock = last[i]; |
| 1900 | return ret; |
| 1901 | } |
Jan Kara | 40346005 | 2009-03-19 16:21:38 +0100 | [diff] [blame] | 1902 | } |
| 1903 | |
| 1904 | /* Finally try block 512 in case media is open */ |
Jan Kara | d759bfa4 | 2013-07-25 19:10:59 +0200 | [diff] [blame] | 1905 | return udf_check_anchor_block(sb, sbi->s_session + 512, fileset); |
Jan Kara | 40346005 | 2009-03-19 16:21:38 +0100 | [diff] [blame] | 1906 | } |
| 1907 | |
| 1908 | /* |
| 1909 | * Find an anchor volume descriptor and load Volume Descriptor Sequence from |
| 1910 | * area specified by it. The function expects sbi->s_lastblock to be the last |
| 1911 | * block on the media. |
| 1912 | * |
Jan Kara | d759bfa4 | 2013-07-25 19:10:59 +0200 | [diff] [blame] | 1913 | * Return <0 on error, 0 if anchor found. -EAGAIN is special meaning anchor |
| 1914 | * was not found. |
Jan Kara | 40346005 | 2009-03-19 16:21:38 +0100 | [diff] [blame] | 1915 | */ |
| 1916 | static int udf_find_anchor(struct super_block *sb, |
| 1917 | struct kernel_lb_addr *fileset) |
| 1918 | { |
Jan Kara | 40346005 | 2009-03-19 16:21:38 +0100 | [diff] [blame] | 1919 | struct udf_sb_info *sbi = UDF_SB(sb); |
Jan Kara | d759bfa4 | 2013-07-25 19:10:59 +0200 | [diff] [blame] | 1920 | sector_t lastblock = sbi->s_last_block; |
| 1921 | int ret; |
Jan Kara | 40346005 | 2009-03-19 16:21:38 +0100 | [diff] [blame] | 1922 | |
Jan Kara | d759bfa4 | 2013-07-25 19:10:59 +0200 | [diff] [blame] | 1923 | ret = udf_scan_anchors(sb, &lastblock, fileset); |
| 1924 | if (ret != -EAGAIN) |
Jan Kara | 40346005 | 2009-03-19 16:21:38 +0100 | [diff] [blame] | 1925 | goto out; |
| 1926 | |
| 1927 | /* No anchor found? Try VARCONV conversion of block numbers */ |
| 1928 | UDF_SET_FLAG(sb, UDF_FLAG_VARCONV); |
Jan Kara | d759bfa4 | 2013-07-25 19:10:59 +0200 | [diff] [blame] | 1929 | lastblock = udf_variable_to_fixed(sbi->s_last_block); |
Jan Kara | 40346005 | 2009-03-19 16:21:38 +0100 | [diff] [blame] | 1930 | /* Firstly, we try to not convert number of the last block */ |
Jan Kara | d759bfa4 | 2013-07-25 19:10:59 +0200 | [diff] [blame] | 1931 | ret = udf_scan_anchors(sb, &lastblock, fileset); |
| 1932 | if (ret != -EAGAIN) |
Jan Kara | 40346005 | 2009-03-19 16:21:38 +0100 | [diff] [blame] | 1933 | goto out; |
| 1934 | |
Jan Kara | d759bfa4 | 2013-07-25 19:10:59 +0200 | [diff] [blame] | 1935 | lastblock = sbi->s_last_block; |
Jan Kara | 40346005 | 2009-03-19 16:21:38 +0100 | [diff] [blame] | 1936 | /* Secondly, we try with converted number of the last block */ |
Jan Kara | d759bfa4 | 2013-07-25 19:10:59 +0200 | [diff] [blame] | 1937 | ret = udf_scan_anchors(sb, &lastblock, fileset); |
| 1938 | if (ret < 0) { |
Jan Kara | 40346005 | 2009-03-19 16:21:38 +0100 | [diff] [blame] | 1939 | /* VARCONV didn't help. Clear it. */ |
| 1940 | UDF_CLEAR_FLAG(sb, UDF_FLAG_VARCONV); |
Jan Kara | 40346005 | 2009-03-19 16:21:38 +0100 | [diff] [blame] | 1941 | } |
| 1942 | out: |
Jan Kara | d759bfa4 | 2013-07-25 19:10:59 +0200 | [diff] [blame] | 1943 | if (ret == 0) |
| 1944 | sbi->s_last_block = lastblock; |
| 1945 | return ret; |
Jan Kara | 40346005 | 2009-03-19 16:21:38 +0100 | [diff] [blame] | 1946 | } |
| 1947 | |
| 1948 | /* |
| 1949 | * Check Volume Structure Descriptor, find Anchor block and load Volume |
Jan Kara | d759bfa4 | 2013-07-25 19:10:59 +0200 | [diff] [blame] | 1950 | * Descriptor Sequence. |
| 1951 | * |
| 1952 | * Returns < 0 on error, 0 on success. -EAGAIN is special meaning anchor |
| 1953 | * block was not found. |
Jan Kara | 40346005 | 2009-03-19 16:21:38 +0100 | [diff] [blame] | 1954 | */ |
| 1955 | static int udf_load_vrs(struct super_block *sb, struct udf_options *uopt, |
| 1956 | int silent, struct kernel_lb_addr *fileset) |
Clemens Ladisch | 1197e4d | 2009-03-11 15:57:47 +0100 | [diff] [blame] | 1957 | { |
| 1958 | struct udf_sb_info *sbi = UDF_SB(sb); |
Jan Kara | 40346005 | 2009-03-19 16:21:38 +0100 | [diff] [blame] | 1959 | loff_t nsr_off; |
Jan Kara | d759bfa4 | 2013-07-25 19:10:59 +0200 | [diff] [blame] | 1960 | int ret; |
Clemens Ladisch | 1197e4d | 2009-03-11 15:57:47 +0100 | [diff] [blame] | 1961 | |
| 1962 | if (!sb_set_blocksize(sb, uopt->blocksize)) { |
| 1963 | if (!silent) |
Joe Perches | 78ace70 | 2011-10-10 01:08:05 -0700 | [diff] [blame] | 1964 | udf_warn(sb, "Bad block size\n"); |
Jan Kara | d759bfa4 | 2013-07-25 19:10:59 +0200 | [diff] [blame] | 1965 | return -EINVAL; |
Clemens Ladisch | 1197e4d | 2009-03-11 15:57:47 +0100 | [diff] [blame] | 1966 | } |
| 1967 | sbi->s_last_block = uopt->lastblock; |
Jan Kara | 40346005 | 2009-03-19 16:21:38 +0100 | [diff] [blame] | 1968 | if (!uopt->novrs) { |
| 1969 | /* Check that it is NSR02 compliant */ |
| 1970 | nsr_off = udf_check_vsd(sb); |
| 1971 | if (!nsr_off) { |
| 1972 | if (!silent) |
Joe Perches | 78ace70 | 2011-10-10 01:08:05 -0700 | [diff] [blame] | 1973 | udf_warn(sb, "No VRS found\n"); |
Fabian Frederick | 70f16ce | 2017-01-18 19:39:35 +0100 | [diff] [blame] | 1974 | return -EINVAL; |
Jan Kara | 40346005 | 2009-03-19 16:21:38 +0100 | [diff] [blame] | 1975 | } |
| 1976 | if (nsr_off == -1) |
Peter A. Felvegi | 4449960 | 2013-10-18 20:07:44 +0200 | [diff] [blame] | 1977 | udf_debug("Failed to read sector at offset %d. " |
| 1978 | "Assuming open disc. Skipping validity " |
| 1979 | "check\n", VSD_FIRST_SECTOR_OFFSET); |
Jan Kara | 40346005 | 2009-03-19 16:21:38 +0100 | [diff] [blame] | 1980 | if (!sbi->s_last_block) |
| 1981 | sbi->s_last_block = udf_get_last_block(sb); |
| 1982 | } else { |
| 1983 | udf_debug("Validity check skipped because of novrs option\n"); |
Clemens Ladisch | 1197e4d | 2009-03-11 15:57:47 +0100 | [diff] [blame] | 1984 | } |
Jan Kara | 40346005 | 2009-03-19 16:21:38 +0100 | [diff] [blame] | 1985 | |
| 1986 | /* Look for anchor block and load Volume Descriptor Sequence */ |
| 1987 | sbi->s_anchor = uopt->anchor; |
Jan Kara | d759bfa4 | 2013-07-25 19:10:59 +0200 | [diff] [blame] | 1988 | ret = udf_find_anchor(sb, fileset); |
| 1989 | if (ret < 0) { |
| 1990 | if (!silent && ret == -EAGAIN) |
Joe Perches | 78ace70 | 2011-10-10 01:08:05 -0700 | [diff] [blame] | 1991 | udf_warn(sb, "No anchor found\n"); |
Jan Kara | d759bfa4 | 2013-07-25 19:10:59 +0200 | [diff] [blame] | 1992 | return ret; |
Clemens Ladisch | 1197e4d | 2009-03-11 15:57:47 +0100 | [diff] [blame] | 1993 | } |
Jan Kara | d759bfa4 | 2013-07-25 19:10:59 +0200 | [diff] [blame] | 1994 | return 0; |
Clemens Ladisch | 1197e4d | 2009-03-11 15:57:47 +0100 | [diff] [blame] | 1995 | } |
| 1996 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1997 | static void udf_open_lvid(struct super_block *sb) |
| 1998 | { |
Marcin Slusarz | 6c79e98 | 2008-02-08 04:20:30 -0800 | [diff] [blame] | 1999 | struct udf_sb_info *sbi = UDF_SB(sb); |
| 2000 | struct buffer_head *bh = sbi->s_lvid_bh; |
Marcin Slusarz | 165923f | 2008-02-10 11:33:08 +0100 | [diff] [blame] | 2001 | struct logicalVolIntegrityDesc *lvid; |
| 2002 | struct logicalVolIntegrityDescImpUse *lvidiu; |
Deepa Dinamani | 88b50ce | 2017-01-02 19:20:55 -0800 | [diff] [blame] | 2003 | struct timespec ts; |
Jan Kara | 146bca7 | 2009-03-16 18:27:37 +0100 | [diff] [blame] | 2004 | |
Marcin Slusarz | 165923f | 2008-02-10 11:33:08 +0100 | [diff] [blame] | 2005 | if (!bh) |
| 2006 | return; |
Jan Kara | 69d7567 | 2013-09-12 22:00:15 +0200 | [diff] [blame] | 2007 | lvid = (struct logicalVolIntegrityDesc *)bh->b_data; |
| 2008 | lvidiu = udf_sb_lvidiu(sb); |
| 2009 | if (!lvidiu) |
| 2010 | return; |
Jan Kara | 949f4a7 | 2010-10-20 18:49:20 +0200 | [diff] [blame] | 2011 | |
| 2012 | mutex_lock(&sbi->s_alloc_mutex); |
Marcin Slusarz | 165923f | 2008-02-10 11:33:08 +0100 | [diff] [blame] | 2013 | lvidiu->impIdent.identSuffix[0] = UDF_OS_CLASS_UNIX; |
| 2014 | lvidiu->impIdent.identSuffix[1] = UDF_OS_ID_LINUX; |
Deepa Dinamani | 88b50ce | 2017-01-02 19:20:55 -0800 | [diff] [blame] | 2015 | ktime_get_real_ts(&ts); |
| 2016 | udf_time_to_disk_stamp(&lvid->recordingDateAndTime, ts); |
Jan Kara | 146bca7 | 2009-03-16 18:27:37 +0100 | [diff] [blame] | 2017 | lvid->integrityType = cpu_to_le32(LVID_INTEGRITY_TYPE_OPEN); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2018 | |
Marcin Slusarz | 165923f | 2008-02-10 11:33:08 +0100 | [diff] [blame] | 2019 | lvid->descTag.descCRC = cpu_to_le16( |
Pekka Enberg | 5ca4e4b | 2008-10-15 12:28:03 +0200 | [diff] [blame] | 2020 | crc_itu_t(0, (char *)lvid + sizeof(struct tag), |
Bob Copeland | f845fce | 2008-04-17 09:47:48 +0200 | [diff] [blame] | 2021 | le16_to_cpu(lvid->descTag.descCRCLength))); |
Marcin Slusarz | 165923f | 2008-02-10 11:33:08 +0100 | [diff] [blame] | 2022 | |
| 2023 | lvid->descTag.tagChecksum = udf_tag_checksum(&lvid->descTag); |
| 2024 | mark_buffer_dirty(bh); |
Jan Kara | 146bca7 | 2009-03-16 18:27:37 +0100 | [diff] [blame] | 2025 | sbi->s_lvid_dirty = 0; |
Jan Kara | 949f4a7 | 2010-10-20 18:49:20 +0200 | [diff] [blame] | 2026 | mutex_unlock(&sbi->s_alloc_mutex); |
Jan Kara | 9734c97 | 2013-01-17 22:11:38 +0100 | [diff] [blame] | 2027 | /* Make opening of filesystem visible on the media immediately */ |
| 2028 | sync_dirty_buffer(bh); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2029 | } |
| 2030 | |
| 2031 | static void udf_close_lvid(struct super_block *sb) |
| 2032 | { |
Marcin Slusarz | 6c79e98 | 2008-02-08 04:20:30 -0800 | [diff] [blame] | 2033 | struct udf_sb_info *sbi = UDF_SB(sb); |
| 2034 | struct buffer_head *bh = sbi->s_lvid_bh; |
| 2035 | struct logicalVolIntegrityDesc *lvid; |
Marcin Slusarz | 165923f | 2008-02-10 11:33:08 +0100 | [diff] [blame] | 2036 | struct logicalVolIntegrityDescImpUse *lvidiu; |
Deepa Dinamani | 88b50ce | 2017-01-02 19:20:55 -0800 | [diff] [blame] | 2037 | struct timespec ts; |
Cyrill Gorcunov | 28de794 | 2007-07-21 04:37:18 -0700 | [diff] [blame] | 2038 | |
Marcin Slusarz | 6c79e98 | 2008-02-08 04:20:30 -0800 | [diff] [blame] | 2039 | if (!bh) |
| 2040 | return; |
Jan Kara | 69d7567 | 2013-09-12 22:00:15 +0200 | [diff] [blame] | 2041 | lvid = (struct logicalVolIntegrityDesc *)bh->b_data; |
| 2042 | lvidiu = udf_sb_lvidiu(sb); |
| 2043 | if (!lvidiu) |
| 2044 | return; |
Marcin Slusarz | 6c79e98 | 2008-02-08 04:20:30 -0800 | [diff] [blame] | 2045 | |
Jan Kara | 949f4a7 | 2010-10-20 18:49:20 +0200 | [diff] [blame] | 2046 | mutex_lock(&sbi->s_alloc_mutex); |
Marcin Slusarz | 165923f | 2008-02-10 11:33:08 +0100 | [diff] [blame] | 2047 | lvidiu->impIdent.identSuffix[0] = UDF_OS_CLASS_UNIX; |
| 2048 | lvidiu->impIdent.identSuffix[1] = UDF_OS_ID_LINUX; |
Deepa Dinamani | 88b50ce | 2017-01-02 19:20:55 -0800 | [diff] [blame] | 2049 | ktime_get_real_ts(&ts); |
| 2050 | udf_time_to_disk_stamp(&lvid->recordingDateAndTime, ts); |
Marcin Slusarz | 165923f | 2008-02-10 11:33:08 +0100 | [diff] [blame] | 2051 | if (UDF_MAX_WRITE_VERSION > le16_to_cpu(lvidiu->maxUDFWriteRev)) |
| 2052 | lvidiu->maxUDFWriteRev = cpu_to_le16(UDF_MAX_WRITE_VERSION); |
| 2053 | if (sbi->s_udfrev > le16_to_cpu(lvidiu->minUDFReadRev)) |
| 2054 | lvidiu->minUDFReadRev = cpu_to_le16(sbi->s_udfrev); |
| 2055 | if (sbi->s_udfrev > le16_to_cpu(lvidiu->minUDFWriteRev)) |
| 2056 | lvidiu->minUDFWriteRev = cpu_to_le16(sbi->s_udfrev); |
| 2057 | lvid->integrityType = cpu_to_le32(LVID_INTEGRITY_TYPE_CLOSE); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2058 | |
Marcin Slusarz | 165923f | 2008-02-10 11:33:08 +0100 | [diff] [blame] | 2059 | lvid->descTag.descCRC = cpu_to_le16( |
Pekka Enberg | 5ca4e4b | 2008-10-15 12:28:03 +0200 | [diff] [blame] | 2060 | crc_itu_t(0, (char *)lvid + sizeof(struct tag), |
Bob Copeland | f845fce | 2008-04-17 09:47:48 +0200 | [diff] [blame] | 2061 | le16_to_cpu(lvid->descTag.descCRCLength))); |
Marcin Slusarz | 165923f | 2008-02-10 11:33:08 +0100 | [diff] [blame] | 2062 | |
| 2063 | lvid->descTag.tagChecksum = udf_tag_checksum(&lvid->descTag); |
Jan Kara | 853a0c2 | 2011-12-23 11:53:07 +0100 | [diff] [blame] | 2064 | /* |
| 2065 | * We set buffer uptodate unconditionally here to avoid spurious |
| 2066 | * warnings from mark_buffer_dirty() when previous EIO has marked |
| 2067 | * the buffer as !uptodate |
| 2068 | */ |
| 2069 | set_buffer_uptodate(bh); |
Marcin Slusarz | 165923f | 2008-02-10 11:33:08 +0100 | [diff] [blame] | 2070 | mark_buffer_dirty(bh); |
Jan Kara | 146bca7 | 2009-03-16 18:27:37 +0100 | [diff] [blame] | 2071 | sbi->s_lvid_dirty = 0; |
Jan Kara | 949f4a7 | 2010-10-20 18:49:20 +0200 | [diff] [blame] | 2072 | mutex_unlock(&sbi->s_alloc_mutex); |
Jan Kara | 9734c97 | 2013-01-17 22:11:38 +0100 | [diff] [blame] | 2073 | /* Make closing of filesystem visible on the media immediately */ |
| 2074 | sync_dirty_buffer(bh); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2075 | } |
| 2076 | |
Jan Kara | d664b6a | 2010-10-20 18:28:46 +0200 | [diff] [blame] | 2077 | u64 lvid_get_unique_id(struct super_block *sb) |
| 2078 | { |
| 2079 | struct buffer_head *bh; |
| 2080 | struct udf_sb_info *sbi = UDF_SB(sb); |
| 2081 | struct logicalVolIntegrityDesc *lvid; |
| 2082 | struct logicalVolHeaderDesc *lvhd; |
| 2083 | u64 uniqueID; |
| 2084 | u64 ret; |
| 2085 | |
| 2086 | bh = sbi->s_lvid_bh; |
| 2087 | if (!bh) |
| 2088 | return 0; |
| 2089 | |
| 2090 | lvid = (struct logicalVolIntegrityDesc *)bh->b_data; |
| 2091 | lvhd = (struct logicalVolHeaderDesc *)lvid->logicalVolContentsUse; |
| 2092 | |
| 2093 | mutex_lock(&sbi->s_alloc_mutex); |
| 2094 | ret = uniqueID = le64_to_cpu(lvhd->uniqueID); |
| 2095 | if (!(++uniqueID & 0xFFFFFFFF)) |
| 2096 | uniqueID += 16; |
| 2097 | lvhd->uniqueID = cpu_to_le64(uniqueID); |
| 2098 | mutex_unlock(&sbi->s_alloc_mutex); |
| 2099 | mark_buffer_dirty(bh); |
| 2100 | |
| 2101 | return ret; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2102 | } |
| 2103 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2104 | static int udf_fill_super(struct super_block *sb, void *options, int silent) |
| 2105 | { |
Jan Kara | d759bfa4 | 2013-07-25 19:10:59 +0200 | [diff] [blame] | 2106 | int ret = -EINVAL; |
Cyrill Gorcunov | cb00ea3 | 2007-07-19 01:47:43 -0700 | [diff] [blame] | 2107 | struct inode *inode = NULL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2108 | struct udf_options uopt; |
Pekka Enberg | 5ca4e4b | 2008-10-15 12:28:03 +0200 | [diff] [blame] | 2109 | struct kernel_lb_addr rootdir, fileset; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2110 | struct udf_sb_info *sbi; |
Jan Kara | 9181f8b | 2015-08-20 14:50:07 +0200 | [diff] [blame] | 2111 | bool lvid_open = false; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2112 | |
| 2113 | uopt.flags = (1 << UDF_FLAG_USE_AD_IN_ICB) | (1 << UDF_FLAG_STRICT); |
Jan Kara | 116e525 | 2018-02-22 10:39:52 +0100 | [diff] [blame^] | 2114 | /* By default we'll use overflow[ug]id when UDF inode [ug]id == -1 */ |
| 2115 | uopt.uid = make_kuid(current_user_ns(), overflowuid); |
| 2116 | uopt.gid = make_kgid(current_user_ns(), overflowgid); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2117 | uopt.umask = 0; |
Marcin Slusarz | 87bc730 | 2008-12-02 13:40:11 +0100 | [diff] [blame] | 2118 | uopt.fmode = UDF_INVALID_MODE; |
| 2119 | uopt.dmode = UDF_INVALID_MODE; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2120 | |
Markus Elfring | 033c9da | 2017-08-15 16:45:44 +0200 | [diff] [blame] | 2121 | sbi = kzalloc(sizeof(*sbi), GFP_KERNEL); |
Alessio Igor Bogani | 9db9f9e | 2010-11-16 18:40:49 +0100 | [diff] [blame] | 2122 | if (!sbi) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2123 | return -ENOMEM; |
Cyrill Gorcunov | 28de794 | 2007-07-21 04:37:18 -0700 | [diff] [blame] | 2124 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2125 | sb->s_fs_info = sbi; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2126 | |
Ingo Molnar | 1e7933d | 2006-03-23 03:00:44 -0800 | [diff] [blame] | 2127 | mutex_init(&sbi->s_alloc_mutex); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2128 | |
Miklos Szeredi | 6da8089 | 2008-02-08 04:21:50 -0800 | [diff] [blame] | 2129 | if (!udf_parse_options((char *)options, &uopt, false)) |
Markus Elfring | fdf2657 | 2014-11-18 18:29:10 +0100 | [diff] [blame] | 2130 | goto parse_options_failure; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2131 | |
| 2132 | if (uopt.flags & (1 << UDF_FLAG_UTF8) && |
Cyrill Gorcunov | cb00ea3 | 2007-07-19 01:47:43 -0700 | [diff] [blame] | 2133 | uopt.flags & (1 << UDF_FLAG_NLS_MAP)) { |
Joe Perches | 8076c36 | 2011-10-10 01:08:03 -0700 | [diff] [blame] | 2134 | udf_err(sb, "utf8 cannot be combined with iocharset\n"); |
Markus Elfring | fdf2657 | 2014-11-18 18:29:10 +0100 | [diff] [blame] | 2135 | goto parse_options_failure; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2136 | } |
| 2137 | #ifdef CONFIG_UDF_NLS |
Cyrill Gorcunov | cb00ea3 | 2007-07-19 01:47:43 -0700 | [diff] [blame] | 2138 | if ((uopt.flags & (1 << UDF_FLAG_NLS_MAP)) && !uopt.nls_map) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2139 | uopt.nls_map = load_nls_default(); |
| 2140 | if (!uopt.nls_map) |
| 2141 | uopt.flags &= ~(1 << UDF_FLAG_NLS_MAP); |
| 2142 | else |
| 2143 | udf_debug("Using default NLS map\n"); |
| 2144 | } |
| 2145 | #endif |
| 2146 | if (!(uopt.flags & (1 << UDF_FLAG_NLS_MAP))) |
| 2147 | uopt.flags |= (1 << UDF_FLAG_UTF8); |
| 2148 | |
| 2149 | fileset.logicalBlockNum = 0xFFFFFFFF; |
| 2150 | fileset.partitionReferenceNum = 0xFFFF; |
| 2151 | |
Marcin Slusarz | 6c79e98 | 2008-02-08 04:20:30 -0800 | [diff] [blame] | 2152 | sbi->s_flags = uopt.flags; |
| 2153 | sbi->s_uid = uopt.uid; |
| 2154 | sbi->s_gid = uopt.gid; |
| 2155 | sbi->s_umask = uopt.umask; |
Marcin Slusarz | 7ac9bcd5 | 2008-11-16 20:52:19 +0100 | [diff] [blame] | 2156 | sbi->s_fmode = uopt.fmode; |
| 2157 | sbi->s_dmode = uopt.dmode; |
Marcin Slusarz | 6c79e98 | 2008-02-08 04:20:30 -0800 | [diff] [blame] | 2158 | sbi->s_nls_map = uopt.nls_map; |
Jan Kara | c03cad2 | 2010-10-20 22:17:28 +0200 | [diff] [blame] | 2159 | rwlock_init(&sbi->s_cred_lock); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2160 | |
Cyrill Gorcunov | cb00ea3 | 2007-07-19 01:47:43 -0700 | [diff] [blame] | 2161 | if (uopt.session == 0xFFFFFFFF) |
Marcin Slusarz | 6c79e98 | 2008-02-08 04:20:30 -0800 | [diff] [blame] | 2162 | sbi->s_session = udf_get_last_session(sb); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2163 | else |
Marcin Slusarz | 6c79e98 | 2008-02-08 04:20:30 -0800 | [diff] [blame] | 2164 | sbi->s_session = uopt.session; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2165 | |
Marcin Slusarz | 6c79e98 | 2008-02-08 04:20:30 -0800 | [diff] [blame] | 2166 | udf_debug("Multi-session=%d\n", sbi->s_session); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2167 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2168 | /* Fill in the rest of the superblock */ |
| 2169 | sb->s_op = &udf_sb_ops; |
Rasmus Rohde | 221e583 | 2008-04-30 17:22:06 +0200 | [diff] [blame] | 2170 | sb->s_export_op = &udf_export_ops; |
Christoph Hellwig | 123e9ca | 2010-05-19 07:16:44 -0400 | [diff] [blame] | 2171 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2172 | sb->s_magic = UDF_SUPER_MAGIC; |
| 2173 | sb->s_time_gran = 1000; |
| 2174 | |
Jan Kara | 40346005 | 2009-03-19 16:21:38 +0100 | [diff] [blame] | 2175 | if (uopt.flags & (1 << UDF_FLAG_BLOCKSIZE_SET)) { |
| 2176 | ret = udf_load_vrs(sb, &uopt, silent, &fileset); |
| 2177 | } else { |
Martin K. Petersen | e1defc4 | 2009-05-22 17:17:49 -0400 | [diff] [blame] | 2178 | uopt.blocksize = bdev_logical_block_size(sb->s_bdev); |
Fabian Frederick | 70f16ce | 2017-01-18 19:39:35 +0100 | [diff] [blame] | 2179 | while (uopt.blocksize <= 4096) { |
Jan Kara | 40346005 | 2009-03-19 16:21:38 +0100 | [diff] [blame] | 2180 | ret = udf_load_vrs(sb, &uopt, silent, &fileset); |
Fabian Frederick | 70f16ce | 2017-01-18 19:39:35 +0100 | [diff] [blame] | 2181 | if (ret < 0) { |
| 2182 | if (!silent && ret != -EACCES) { |
Steve Magnani | fcbf763 | 2017-10-12 08:48:41 -0500 | [diff] [blame] | 2183 | pr_notice("Scanning with blocksize %u failed\n", |
Fabian Frederick | 70f16ce | 2017-01-18 19:39:35 +0100 | [diff] [blame] | 2184 | uopt.blocksize); |
| 2185 | } |
| 2186 | brelse(sbi->s_lvid_bh); |
| 2187 | sbi->s_lvid_bh = NULL; |
| 2188 | /* |
| 2189 | * EACCES is special - we want to propagate to |
| 2190 | * upper layers that we cannot handle RW mount. |
| 2191 | */ |
| 2192 | if (ret == -EACCES) |
| 2193 | break; |
| 2194 | } else |
| 2195 | break; |
| 2196 | |
| 2197 | uopt.blocksize <<= 1; |
Jan Kara | 40346005 | 2009-03-19 16:21:38 +0100 | [diff] [blame] | 2198 | } |
| 2199 | } |
Jan Kara | d759bfa4 | 2013-07-25 19:10:59 +0200 | [diff] [blame] | 2200 | if (ret < 0) { |
| 2201 | if (ret == -EAGAIN) { |
| 2202 | udf_warn(sb, "No partition found (1)\n"); |
| 2203 | ret = -EINVAL; |
| 2204 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2205 | goto error_out; |
| 2206 | } |
| 2207 | |
Steve Magnani | fcbf763 | 2017-10-12 08:48:41 -0500 | [diff] [blame] | 2208 | udf_debug("Lastblock=%u\n", sbi->s_last_block); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2209 | |
Marcin Slusarz | 6c79e98 | 2008-02-08 04:20:30 -0800 | [diff] [blame] | 2210 | if (sbi->s_lvid_bh) { |
Marcin Slusarz | 4b11111 | 2008-02-08 04:20:36 -0800 | [diff] [blame] | 2211 | struct logicalVolIntegrityDescImpUse *lvidiu = |
Jan Kara | 69d7567 | 2013-09-12 22:00:15 +0200 | [diff] [blame] | 2212 | udf_sb_lvidiu(sb); |
| 2213 | uint16_t minUDFReadRev; |
| 2214 | uint16_t minUDFWriteRev; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2215 | |
Jan Kara | 69d7567 | 2013-09-12 22:00:15 +0200 | [diff] [blame] | 2216 | if (!lvidiu) { |
| 2217 | ret = -EINVAL; |
| 2218 | goto error_out; |
| 2219 | } |
| 2220 | minUDFReadRev = le16_to_cpu(lvidiu->minUDFReadRev); |
| 2221 | minUDFWriteRev = le16_to_cpu(lvidiu->minUDFWriteRev); |
Cyrill Gorcunov | cb00ea3 | 2007-07-19 01:47:43 -0700 | [diff] [blame] | 2222 | if (minUDFReadRev > UDF_MAX_READ_VERSION) { |
Joe Perches | 78ace70 | 2011-10-10 01:08:05 -0700 | [diff] [blame] | 2223 | udf_err(sb, "minUDFReadRev=%x (max is %x)\n", |
Jan Kara | 69d7567 | 2013-09-12 22:00:15 +0200 | [diff] [blame] | 2224 | minUDFReadRev, |
Joe Perches | 78ace70 | 2011-10-10 01:08:05 -0700 | [diff] [blame] | 2225 | UDF_MAX_READ_VERSION); |
Jan Kara | d759bfa4 | 2013-07-25 19:10:59 +0200 | [diff] [blame] | 2226 | ret = -EINVAL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2227 | goto error_out; |
Jan Kara | e729eac | 2013-07-25 16:15:16 +0200 | [diff] [blame] | 2228 | } else if (minUDFWriteRev > UDF_MAX_WRITE_VERSION && |
David Howells | bc98a42 | 2017-07-17 08:45:34 +0100 | [diff] [blame] | 2229 | !sb_rdonly(sb)) { |
Jan Kara | e729eac | 2013-07-25 16:15:16 +0200 | [diff] [blame] | 2230 | ret = -EACCES; |
| 2231 | goto error_out; |
| 2232 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2233 | |
Marcin Slusarz | 6c79e98 | 2008-02-08 04:20:30 -0800 | [diff] [blame] | 2234 | sbi->s_udfrev = minUDFWriteRev; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2235 | |
| 2236 | if (minUDFReadRev >= UDF_VERS_USE_EXTENDED_FE) |
| 2237 | UDF_SET_FLAG(sb, UDF_FLAG_USE_EXTENDED_FE); |
| 2238 | if (minUDFReadRev >= UDF_VERS_USE_STREAMS) |
| 2239 | UDF_SET_FLAG(sb, UDF_FLAG_USE_STREAMS); |
| 2240 | } |
| 2241 | |
Marcin Slusarz | 6c79e98 | 2008-02-08 04:20:30 -0800 | [diff] [blame] | 2242 | if (!sbi->s_partitions) { |
Joe Perches | 78ace70 | 2011-10-10 01:08:05 -0700 | [diff] [blame] | 2243 | udf_warn(sb, "No partition found (2)\n"); |
Jan Kara | d759bfa4 | 2013-07-25 19:10:59 +0200 | [diff] [blame] | 2244 | ret = -EINVAL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2245 | goto error_out; |
| 2246 | } |
| 2247 | |
Marcin Slusarz | 4b11111 | 2008-02-08 04:20:36 -0800 | [diff] [blame] | 2248 | if (sbi->s_partmaps[sbi->s_partition].s_partition_flags & |
Jan Kara | e729eac | 2013-07-25 16:15:16 +0200 | [diff] [blame] | 2249 | UDF_PART_FLAG_READ_ONLY && |
David Howells | bc98a42 | 2017-07-17 08:45:34 +0100 | [diff] [blame] | 2250 | !sb_rdonly(sb)) { |
Jan Kara | e729eac | 2013-07-25 16:15:16 +0200 | [diff] [blame] | 2251 | ret = -EACCES; |
| 2252 | goto error_out; |
Peter Osterlund | c1a26e7 | 2006-10-05 21:17:50 +0200 | [diff] [blame] | 2253 | } |
Eric Sandeen | 39b3f6d | 2006-09-29 01:59:41 -0700 | [diff] [blame] | 2254 | |
Cyrill Gorcunov | cb00ea3 | 2007-07-19 01:47:43 -0700 | [diff] [blame] | 2255 | if (udf_find_fileset(sb, &fileset, &rootdir)) { |
Joe Perches | 78ace70 | 2011-10-10 01:08:05 -0700 | [diff] [blame] | 2256 | udf_warn(sb, "No fileset found\n"); |
Jan Kara | d759bfa4 | 2013-07-25 19:10:59 +0200 | [diff] [blame] | 2257 | ret = -EINVAL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2258 | goto error_out; |
| 2259 | } |
| 2260 | |
Cyrill Gorcunov | cb00ea3 | 2007-07-19 01:47:43 -0700 | [diff] [blame] | 2261 | if (!silent) { |
Pekka Enberg | 5ca4e4b | 2008-10-15 12:28:03 +0200 | [diff] [blame] | 2262 | struct timestamp ts; |
Marcin Slusarz | 5677480 | 2008-02-10 11:25:31 +0100 | [diff] [blame] | 2263 | udf_time_to_disk_stamp(&ts, sbi->s_record_time); |
Joe Perches | 78ace70 | 2011-10-10 01:08:05 -0700 | [diff] [blame] | 2264 | udf_info("Mounting volume '%s', timestamp %04u/%02u/%02u %02u:%02u (%x)\n", |
| 2265 | sbi->s_volume_ident, |
| 2266 | le16_to_cpu(ts.year), ts.month, ts.day, |
Marcin Slusarz | 5677480 | 2008-02-10 11:25:31 +0100 | [diff] [blame] | 2267 | ts.hour, ts.minute, le16_to_cpu(ts.typeAndTimezone)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2268 | } |
David Howells | bc98a42 | 2017-07-17 08:45:34 +0100 | [diff] [blame] | 2269 | if (!sb_rdonly(sb)) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2270 | udf_open_lvid(sb); |
Jan Kara | 9181f8b | 2015-08-20 14:50:07 +0200 | [diff] [blame] | 2271 | lvid_open = true; |
| 2272 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2273 | |
| 2274 | /* Assign the root inode */ |
| 2275 | /* assign inodes by physical block number */ |
| 2276 | /* perhaps it's not extensible enough, but for now ... */ |
Pekka Enberg | 97e961f | 2008-10-15 12:29:03 +0200 | [diff] [blame] | 2277 | inode = udf_iget(sb, &rootdir); |
Jan Kara | 6d3d5e8 | 2014-09-04 16:15:51 +0200 | [diff] [blame] | 2278 | if (IS_ERR(inode)) { |
Steve Magnani | fcbf763 | 2017-10-12 08:48:41 -0500 | [diff] [blame] | 2279 | udf_err(sb, "Error in udf_iget, block=%u, partition=%u\n", |
Cyrill Gorcunov | cb00ea3 | 2007-07-19 01:47:43 -0700 | [diff] [blame] | 2280 | rootdir.logicalBlockNum, rootdir.partitionReferenceNum); |
Jan Kara | 6d3d5e8 | 2014-09-04 16:15:51 +0200 | [diff] [blame] | 2281 | ret = PTR_ERR(inode); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2282 | goto error_out; |
| 2283 | } |
| 2284 | |
| 2285 | /* Allocate a dentry for the root inode */ |
Al Viro | 48fde70 | 2012-01-08 22:15:13 -0500 | [diff] [blame] | 2286 | sb->s_root = d_make_root(inode); |
Cyrill Gorcunov | cb00ea3 | 2007-07-19 01:47:43 -0700 | [diff] [blame] | 2287 | if (!sb->s_root) { |
Joe Perches | 78ace70 | 2011-10-10 01:08:05 -0700 | [diff] [blame] | 2288 | udf_err(sb, "Couldn't allocate root dentry\n"); |
Jan Kara | d759bfa4 | 2013-07-25 19:10:59 +0200 | [diff] [blame] | 2289 | ret = -ENOMEM; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2290 | goto error_out; |
| 2291 | } |
Jan Kara | 31170b6 | 2007-05-08 00:35:21 -0700 | [diff] [blame] | 2292 | sb->s_maxbytes = MAX_LFS_FILESIZE; |
Al Viro | 8de5277 | 2012-02-06 12:45:27 -0500 | [diff] [blame] | 2293 | sb->s_max_links = UDF_MAX_LINKS; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2294 | return 0; |
| 2295 | |
Cyrill Gorcunov | 28de794 | 2007-07-21 04:37:18 -0700 | [diff] [blame] | 2296 | error_out: |
Markus Elfring | 0d454e4 | 2014-11-18 17:17:46 +0100 | [diff] [blame] | 2297 | iput(sbi->s_vat_inode); |
Markus Elfring | fdf2657 | 2014-11-18 18:29:10 +0100 | [diff] [blame] | 2298 | parse_options_failure: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2299 | #ifdef CONFIG_UDF_NLS |
| 2300 | if (UDF_QUERY_FLAG(sb, UDF_FLAG_NLS_MAP)) |
Marcin Slusarz | 6c79e98 | 2008-02-08 04:20:30 -0800 | [diff] [blame] | 2301 | unload_nls(sbi->s_nls_map); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2302 | #endif |
Jan Kara | 9181f8b | 2015-08-20 14:50:07 +0200 | [diff] [blame] | 2303 | if (lvid_open) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2304 | udf_close_lvid(sb); |
Marcin Slusarz | 6c79e98 | 2008-02-08 04:20:30 -0800 | [diff] [blame] | 2305 | brelse(sbi->s_lvid_bh); |
Jan Kara | bff943a | 2012-06-27 22:27:05 +0200 | [diff] [blame] | 2306 | udf_sb_free_partitions(sb); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2307 | kfree(sbi); |
| 2308 | sb->s_fs_info = NULL; |
Cyrill Gorcunov | 28de794 | 2007-07-21 04:37:18 -0700 | [diff] [blame] | 2309 | |
Jan Kara | d759bfa4 | 2013-07-25 19:10:59 +0200 | [diff] [blame] | 2310 | return ret; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2311 | } |
| 2312 | |
Joe Perches | 8076c36 | 2011-10-10 01:08:03 -0700 | [diff] [blame] | 2313 | void _udf_err(struct super_block *sb, const char *function, |
| 2314 | const char *fmt, ...) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2315 | { |
Joe Perches | c2bff36 | 2011-10-10 01:08:06 -0700 | [diff] [blame] | 2316 | struct va_format vaf; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2317 | va_list args; |
| 2318 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2319 | va_start(args, fmt); |
Joe Perches | c2bff36 | 2011-10-10 01:08:06 -0700 | [diff] [blame] | 2320 | |
| 2321 | vaf.fmt = fmt; |
| 2322 | vaf.va = &args; |
| 2323 | |
| 2324 | pr_err("error (device %s): %s: %pV", sb->s_id, function, &vaf); |
| 2325 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2326 | va_end(args); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2327 | } |
| 2328 | |
Joe Perches | a40ecd7 | 2011-10-10 01:08:04 -0700 | [diff] [blame] | 2329 | void _udf_warn(struct super_block *sb, const char *function, |
| 2330 | const char *fmt, ...) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2331 | { |
Joe Perches | c2bff36 | 2011-10-10 01:08:06 -0700 | [diff] [blame] | 2332 | struct va_format vaf; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2333 | va_list args; |
| 2334 | |
Cyrill Gorcunov | cb00ea3 | 2007-07-19 01:47:43 -0700 | [diff] [blame] | 2335 | va_start(args, fmt); |
Joe Perches | c2bff36 | 2011-10-10 01:08:06 -0700 | [diff] [blame] | 2336 | |
| 2337 | vaf.fmt = fmt; |
| 2338 | vaf.va = &args; |
| 2339 | |
| 2340 | pr_warn("warning (device %s): %s: %pV", sb->s_id, function, &vaf); |
| 2341 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2342 | va_end(args); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2343 | } |
| 2344 | |
Cyrill Gorcunov | cb00ea3 | 2007-07-19 01:47:43 -0700 | [diff] [blame] | 2345 | static void udf_put_super(struct super_block *sb) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2346 | { |
Marcin Slusarz | 6c79e98 | 2008-02-08 04:20:30 -0800 | [diff] [blame] | 2347 | struct udf_sb_info *sbi; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2348 | |
Marcin Slusarz | 6c79e98 | 2008-02-08 04:20:30 -0800 | [diff] [blame] | 2349 | sbi = UDF_SB(sb); |
Christoph Hellwig | 6cfd014 | 2009-05-05 15:40:36 +0200 | [diff] [blame] | 2350 | |
Markus Elfring | 0d454e4 | 2014-11-18 17:17:46 +0100 | [diff] [blame] | 2351 | iput(sbi->s_vat_inode); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2352 | #ifdef CONFIG_UDF_NLS |
| 2353 | if (UDF_QUERY_FLAG(sb, UDF_FLAG_NLS_MAP)) |
Marcin Slusarz | 6c79e98 | 2008-02-08 04:20:30 -0800 | [diff] [blame] | 2354 | unload_nls(sbi->s_nls_map); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2355 | #endif |
David Howells | bc98a42 | 2017-07-17 08:45:34 +0100 | [diff] [blame] | 2356 | if (!sb_rdonly(sb)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2357 | udf_close_lvid(sb); |
Marcin Slusarz | 6c79e98 | 2008-02-08 04:20:30 -0800 | [diff] [blame] | 2358 | brelse(sbi->s_lvid_bh); |
Jan Kara | bff943a | 2012-06-27 22:27:05 +0200 | [diff] [blame] | 2359 | udf_sb_free_partitions(sb); |
Fabian Frederick | bbe48dd | 2015-01-10 19:13:32 +0100 | [diff] [blame] | 2360 | mutex_destroy(&sbi->s_alloc_mutex); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2361 | kfree(sb->s_fs_info); |
| 2362 | sb->s_fs_info = NULL; |
| 2363 | } |
| 2364 | |
Jan Kara | 146bca7 | 2009-03-16 18:27:37 +0100 | [diff] [blame] | 2365 | static int udf_sync_fs(struct super_block *sb, int wait) |
| 2366 | { |
| 2367 | struct udf_sb_info *sbi = UDF_SB(sb); |
| 2368 | |
| 2369 | mutex_lock(&sbi->s_alloc_mutex); |
| 2370 | if (sbi->s_lvid_dirty) { |
| 2371 | /* |
| 2372 | * Blockdevice will be synced later so we don't have to submit |
| 2373 | * the buffer for IO |
| 2374 | */ |
| 2375 | mark_buffer_dirty(sbi->s_lvid_bh); |
Jan Kara | 146bca7 | 2009-03-16 18:27:37 +0100 | [diff] [blame] | 2376 | sbi->s_lvid_dirty = 0; |
| 2377 | } |
| 2378 | mutex_unlock(&sbi->s_alloc_mutex); |
| 2379 | |
| 2380 | return 0; |
| 2381 | } |
| 2382 | |
Cyrill Gorcunov | cb00ea3 | 2007-07-19 01:47:43 -0700 | [diff] [blame] | 2383 | static int udf_statfs(struct dentry *dentry, struct kstatfs *buf) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2384 | { |
David Howells | 726c334 | 2006-06-23 02:02:58 -0700 | [diff] [blame] | 2385 | struct super_block *sb = dentry->d_sb; |
Marcin Slusarz | 6c79e98 | 2008-02-08 04:20:30 -0800 | [diff] [blame] | 2386 | struct udf_sb_info *sbi = UDF_SB(sb); |
| 2387 | struct logicalVolIntegrityDescImpUse *lvidiu; |
Coly Li | 557f5a1 | 2009-01-20 01:36:55 +0800 | [diff] [blame] | 2388 | u64 id = huge_encode_dev(sb->s_bdev->bd_dev); |
Marcin Slusarz | 6c79e98 | 2008-02-08 04:20:30 -0800 | [diff] [blame] | 2389 | |
Jan Kara | 69d7567 | 2013-09-12 22:00:15 +0200 | [diff] [blame] | 2390 | lvidiu = udf_sb_lvidiu(sb); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2391 | buf->f_type = UDF_SUPER_MAGIC; |
| 2392 | buf->f_bsize = sb->s_blocksize; |
Marcin Slusarz | 6c79e98 | 2008-02-08 04:20:30 -0800 | [diff] [blame] | 2393 | buf->f_blocks = sbi->s_partmaps[sbi->s_partition].s_partition_len; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2394 | buf->f_bfree = udf_count_free(sb); |
| 2395 | buf->f_bavail = buf->f_bfree; |
Marcin Slusarz | 6c79e98 | 2008-02-08 04:20:30 -0800 | [diff] [blame] | 2396 | buf->f_files = (lvidiu != NULL ? (le32_to_cpu(lvidiu->numFiles) + |
| 2397 | le32_to_cpu(lvidiu->numDirs)) : 0) |
| 2398 | + buf->f_bfree; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2399 | buf->f_ffree = buf->f_bfree; |
Andrew Gabbasov | 9fba705 | 2016-01-15 02:44:21 -0600 | [diff] [blame] | 2400 | buf->f_namelen = UDF_NAME_LEN; |
Coly Li | 557f5a1 | 2009-01-20 01:36:55 +0800 | [diff] [blame] | 2401 | buf->f_fsid.val[0] = (u32)id; |
| 2402 | buf->f_fsid.val[1] = (u32)(id >> 32); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2403 | |
| 2404 | return 0; |
| 2405 | } |
| 2406 | |
Marcin Slusarz | 4b11111 | 2008-02-08 04:20:36 -0800 | [diff] [blame] | 2407 | static unsigned int udf_count_free_bitmap(struct super_block *sb, |
| 2408 | struct udf_bitmap *bitmap) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2409 | { |
| 2410 | struct buffer_head *bh = NULL; |
| 2411 | unsigned int accum = 0; |
| 2412 | int index; |
Steve Magnani | b490bdd | 2017-10-12 08:48:40 -0500 | [diff] [blame] | 2413 | udf_pblk_t block = 0, newblock; |
Pekka Enberg | 5ca4e4b | 2008-10-15 12:28:03 +0200 | [diff] [blame] | 2414 | struct kernel_lb_addr loc; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2415 | uint32_t bytes; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2416 | uint8_t *ptr; |
| 2417 | uint16_t ident; |
| 2418 | struct spaceBitmapDesc *bm; |
| 2419 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2420 | loc.logicalBlockNum = bitmap->s_extPosition; |
Marcin Slusarz | 6c79e98 | 2008-02-08 04:20:30 -0800 | [diff] [blame] | 2421 | loc.partitionReferenceNum = UDF_SB(sb)->s_partition; |
Pekka Enberg | 97e961f | 2008-10-15 12:29:03 +0200 | [diff] [blame] | 2422 | bh = udf_read_ptagged(sb, &loc, 0, &ident); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2423 | |
Cyrill Gorcunov | cb00ea3 | 2007-07-19 01:47:43 -0700 | [diff] [blame] | 2424 | if (!bh) { |
Joe Perches | 78ace70 | 2011-10-10 01:08:05 -0700 | [diff] [blame] | 2425 | udf_err(sb, "udf_count_free failed\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2426 | goto out; |
Cyrill Gorcunov | cb00ea3 | 2007-07-19 01:47:43 -0700 | [diff] [blame] | 2427 | } else if (ident != TAG_IDENT_SBD) { |
Jan Kara | 3bf25cb | 2007-05-08 00:35:16 -0700 | [diff] [blame] | 2428 | brelse(bh); |
Joe Perches | 78ace70 | 2011-10-10 01:08:05 -0700 | [diff] [blame] | 2429 | udf_err(sb, "udf_count_free failed\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2430 | goto out; |
| 2431 | } |
| 2432 | |
| 2433 | bm = (struct spaceBitmapDesc *)bh->b_data; |
| 2434 | bytes = le32_to_cpu(bm->numOfBytes); |
Cyrill Gorcunov | 28de794 | 2007-07-21 04:37:18 -0700 | [diff] [blame] | 2435 | index = sizeof(struct spaceBitmapDesc); /* offset in first block only */ |
| 2436 | ptr = (uint8_t *)bh->b_data; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2437 | |
Cyrill Gorcunov | cb00ea3 | 2007-07-19 01:47:43 -0700 | [diff] [blame] | 2438 | while (bytes > 0) { |
Marcin Slusarz | 01b954a | 2008-02-02 22:37:07 +0100 | [diff] [blame] | 2439 | u32 cur_bytes = min_t(u32, bytes, sb->s_blocksize - index); |
| 2440 | accum += bitmap_weight((const unsigned long *)(ptr + index), |
| 2441 | cur_bytes * 8); |
| 2442 | bytes -= cur_bytes; |
Cyrill Gorcunov | cb00ea3 | 2007-07-19 01:47:43 -0700 | [diff] [blame] | 2443 | if (bytes) { |
Jan Kara | 3bf25cb | 2007-05-08 00:35:16 -0700 | [diff] [blame] | 2444 | brelse(bh); |
Pekka Enberg | 97e961f | 2008-10-15 12:29:03 +0200 | [diff] [blame] | 2445 | newblock = udf_get_lb_pblock(sb, &loc, ++block); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2446 | bh = udf_tread(sb, newblock); |
Cyrill Gorcunov | cb00ea3 | 2007-07-19 01:47:43 -0700 | [diff] [blame] | 2447 | if (!bh) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2448 | udf_debug("read failed\n"); |
| 2449 | goto out; |
| 2450 | } |
| 2451 | index = 0; |
Cyrill Gorcunov | 28de794 | 2007-07-21 04:37:18 -0700 | [diff] [blame] | 2452 | ptr = (uint8_t *)bh->b_data; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2453 | } |
| 2454 | } |
Jan Kara | 3bf25cb | 2007-05-08 00:35:16 -0700 | [diff] [blame] | 2455 | brelse(bh); |
Cyrill Gorcunov | 28de794 | 2007-07-21 04:37:18 -0700 | [diff] [blame] | 2456 | out: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2457 | return accum; |
| 2458 | } |
| 2459 | |
Marcin Slusarz | 4b11111 | 2008-02-08 04:20:36 -0800 | [diff] [blame] | 2460 | static unsigned int udf_count_free_table(struct super_block *sb, |
| 2461 | struct inode *table) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2462 | { |
| 2463 | unsigned int accum = 0; |
Jan Kara | ff116fc | 2007-05-08 00:35:14 -0700 | [diff] [blame] | 2464 | uint32_t elen; |
Pekka Enberg | 5ca4e4b | 2008-10-15 12:28:03 +0200 | [diff] [blame] | 2465 | struct kernel_lb_addr eloc; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2466 | int8_t etype; |
Jan Kara | ff116fc | 2007-05-08 00:35:14 -0700 | [diff] [blame] | 2467 | struct extent_position epos; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2468 | |
Jan Kara | d1668fe | 2010-10-20 23:24:12 +0200 | [diff] [blame] | 2469 | mutex_lock(&UDF_SB(sb)->s_alloc_mutex); |
Marcin Slusarz | c0b3443 | 2008-02-08 04:20:42 -0800 | [diff] [blame] | 2470 | epos.block = UDF_I(table)->i_location; |
Jan Kara | ff116fc | 2007-05-08 00:35:14 -0700 | [diff] [blame] | 2471 | epos.offset = sizeof(struct unallocSpaceEntry); |
| 2472 | epos.bh = NULL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2473 | |
Marcin Slusarz | 3a71fc5 | 2008-02-08 04:20:28 -0800 | [diff] [blame] | 2474 | while ((etype = udf_next_aext(table, &epos, &eloc, &elen, 1)) != -1) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2475 | accum += (elen >> table->i_sb->s_blocksize_bits); |
Marcin Slusarz | 3a71fc5 | 2008-02-08 04:20:28 -0800 | [diff] [blame] | 2476 | |
Jan Kara | 3bf25cb | 2007-05-08 00:35:16 -0700 | [diff] [blame] | 2477 | brelse(epos.bh); |
Jan Kara | d1668fe | 2010-10-20 23:24:12 +0200 | [diff] [blame] | 2478 | mutex_unlock(&UDF_SB(sb)->s_alloc_mutex); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2479 | |
| 2480 | return accum; |
| 2481 | } |
Cyrill Gorcunov | cb00ea3 | 2007-07-19 01:47:43 -0700 | [diff] [blame] | 2482 | |
| 2483 | static unsigned int udf_count_free(struct super_block *sb) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2484 | { |
| 2485 | unsigned int accum = 0; |
Marcin Slusarz | 6c79e98 | 2008-02-08 04:20:30 -0800 | [diff] [blame] | 2486 | struct udf_sb_info *sbi; |
| 2487 | struct udf_part_map *map; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2488 | |
Marcin Slusarz | 6c79e98 | 2008-02-08 04:20:30 -0800 | [diff] [blame] | 2489 | sbi = UDF_SB(sb); |
| 2490 | if (sbi->s_lvid_bh) { |
Marcin Slusarz | 4b11111 | 2008-02-08 04:20:36 -0800 | [diff] [blame] | 2491 | struct logicalVolIntegrityDesc *lvid = |
| 2492 | (struct logicalVolIntegrityDesc *) |
| 2493 | sbi->s_lvid_bh->b_data; |
Marcin Slusarz | 6c79e98 | 2008-02-08 04:20:30 -0800 | [diff] [blame] | 2494 | if (le32_to_cpu(lvid->numOfPartitions) > sbi->s_partition) { |
Marcin Slusarz | 4b11111 | 2008-02-08 04:20:36 -0800 | [diff] [blame] | 2495 | accum = le32_to_cpu( |
| 2496 | lvid->freeSpaceTable[sbi->s_partition]); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2497 | if (accum == 0xFFFFFFFF) |
| 2498 | accum = 0; |
| 2499 | } |
| 2500 | } |
| 2501 | |
| 2502 | if (accum) |
| 2503 | return accum; |
| 2504 | |
Marcin Slusarz | 6c79e98 | 2008-02-08 04:20:30 -0800 | [diff] [blame] | 2505 | map = &sbi->s_partmaps[sbi->s_partition]; |
| 2506 | if (map->s_partition_flags & UDF_PART_FLAG_UNALLOC_BITMAP) { |
Cyrill Gorcunov | 28de794 | 2007-07-21 04:37:18 -0700 | [diff] [blame] | 2507 | accum += udf_count_free_bitmap(sb, |
Marcin Slusarz | 6c79e98 | 2008-02-08 04:20:30 -0800 | [diff] [blame] | 2508 | map->s_uspace.s_bitmap); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2509 | } |
Marcin Slusarz | 6c79e98 | 2008-02-08 04:20:30 -0800 | [diff] [blame] | 2510 | if (map->s_partition_flags & UDF_PART_FLAG_FREED_BITMAP) { |
Cyrill Gorcunov | 28de794 | 2007-07-21 04:37:18 -0700 | [diff] [blame] | 2511 | accum += udf_count_free_bitmap(sb, |
Marcin Slusarz | 6c79e98 | 2008-02-08 04:20:30 -0800 | [diff] [blame] | 2512 | map->s_fspace.s_bitmap); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2513 | } |
| 2514 | if (accum) |
| 2515 | return accum; |
| 2516 | |
Marcin Slusarz | 6c79e98 | 2008-02-08 04:20:30 -0800 | [diff] [blame] | 2517 | if (map->s_partition_flags & UDF_PART_FLAG_UNALLOC_TABLE) { |
Cyrill Gorcunov | 28de794 | 2007-07-21 04:37:18 -0700 | [diff] [blame] | 2518 | accum += udf_count_free_table(sb, |
Marcin Slusarz | 6c79e98 | 2008-02-08 04:20:30 -0800 | [diff] [blame] | 2519 | map->s_uspace.s_table); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2520 | } |
Marcin Slusarz | 6c79e98 | 2008-02-08 04:20:30 -0800 | [diff] [blame] | 2521 | if (map->s_partition_flags & UDF_PART_FLAG_FREED_TABLE) { |
Cyrill Gorcunov | 28de794 | 2007-07-21 04:37:18 -0700 | [diff] [blame] | 2522 | accum += udf_count_free_table(sb, |
Marcin Slusarz | 6c79e98 | 2008-02-08 04:20:30 -0800 | [diff] [blame] | 2523 | map->s_fspace.s_table); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2524 | } |
| 2525 | |
| 2526 | return accum; |
| 2527 | } |
Fabian Frederick | 54bb60d | 2017-01-06 21:53:57 +0100 | [diff] [blame] | 2528 | |
| 2529 | MODULE_AUTHOR("Ben Fennema"); |
| 2530 | MODULE_DESCRIPTION("Universal Disk Format Filesystem"); |
| 2531 | MODULE_LICENSE("GPL"); |
| 2532 | module_init(init_udf_fs) |
| 2533 | module_exit(exit_udf_fs) |