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