Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1 | /* |
| 2 | * partition.c |
| 3 | * |
| 4 | * PURPOSE |
| 5 | * Partition handling routines for the OSTA-UDF(tm) filesystem. |
| 6 | * |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7 | * COPYRIGHT |
| 8 | * This file is distributed under the terms of the GNU General Public |
| 9 | * License (GPL). Copies of the GPL can be obtained from: |
| 10 | * ftp://prep.ai.mit.edu/pub/gnu/GPL |
| 11 | * Each contributing author retains all rights to their own work. |
| 12 | * |
| 13 | * (C) 1998-2001 Ben Fennema |
| 14 | * |
| 15 | * HISTORY |
| 16 | * |
Cyrill Gorcunov | 28de794 | 2007-07-21 04:37:18 -0700 | [diff] [blame] | 17 | * 12/06/98 blf Created file. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 18 | * |
| 19 | */ |
| 20 | |
| 21 | #include "udfdecl.h" |
| 22 | #include "udf_sb.h" |
| 23 | #include "udf_i.h" |
| 24 | |
| 25 | #include <linux/fs.h> |
| 26 | #include <linux/string.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 27 | #include <linux/buffer_head.h> |
Alessio Igor Bogani | 7db09be | 2010-11-16 18:40:48 +0100 | [diff] [blame] | 28 | #include <linux/mutex.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 29 | |
Adrian Bunk | 22ba031 | 2008-04-28 18:38:49 +0300 | [diff] [blame] | 30 | uint32_t udf_get_pblock(struct super_block *sb, uint32_t block, |
| 31 | uint16_t partition, uint32_t offset) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 32 | { |
Marcin Slusarz | 6c79e98 | 2008-02-08 04:20:30 -0800 | [diff] [blame] | 33 | struct udf_sb_info *sbi = UDF_SB(sb); |
| 34 | struct udf_part_map *map; |
| 35 | if (partition >= sbi->s_partitions) { |
Joe Perches | a983f36 | 2011-10-10 01:08:07 -0700 | [diff] [blame] | 36 | udf_debug("block=%d, partition=%d, offset=%d: invalid partition\n", |
| 37 | block, partition, offset); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 38 | return 0xFFFFFFFF; |
| 39 | } |
Marcin Slusarz | 6c79e98 | 2008-02-08 04:20:30 -0800 | [diff] [blame] | 40 | map = &sbi->s_partmaps[partition]; |
| 41 | if (map->s_partition_func) |
| 42 | return map->s_partition_func(sb, block, partition, offset); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 43 | else |
Marcin Slusarz | 6c79e98 | 2008-02-08 04:20:30 -0800 | [diff] [blame] | 44 | return map->s_partition_root + block + offset; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 45 | } |
| 46 | |
Cyrill Gorcunov | 28de794 | 2007-07-21 04:37:18 -0700 | [diff] [blame] | 47 | uint32_t udf_get_pblock_virt15(struct super_block *sb, uint32_t block, |
Cyrill Gorcunov | cb00ea3 | 2007-07-19 01:47:43 -0700 | [diff] [blame] | 48 | uint16_t partition, uint32_t offset) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 49 | { |
| 50 | struct buffer_head *bh = NULL; |
| 51 | uint32_t newblock; |
| 52 | uint32_t index; |
| 53 | uint32_t loc; |
Marcin Slusarz | 6c79e98 | 2008-02-08 04:20:30 -0800 | [diff] [blame] | 54 | struct udf_sb_info *sbi = UDF_SB(sb); |
| 55 | struct udf_part_map *map; |
Marcin Slusarz | 4b11111 | 2008-02-08 04:20:36 -0800 | [diff] [blame] | 56 | struct udf_virtual_data *vdata; |
Jan Kara | fa5e081 | 2008-04-08 02:08:53 +0200 | [diff] [blame] | 57 | struct udf_inode_info *iinfo = UDF_I(sbi->s_vat_inode); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 58 | |
Marcin Slusarz | 6c79e98 | 2008-02-08 04:20:30 -0800 | [diff] [blame] | 59 | map = &sbi->s_partmaps[partition]; |
Marcin Slusarz | 4b11111 | 2008-02-08 04:20:36 -0800 | [diff] [blame] | 60 | vdata = &map->s_type_specific.s_virtual; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 61 | |
Marcin Slusarz | 4b11111 | 2008-02-08 04:20:36 -0800 | [diff] [blame] | 62 | if (block > vdata->s_num_entries) { |
Joe Perches | a983f36 | 2011-10-10 01:08:07 -0700 | [diff] [blame] | 63 | udf_debug("Trying to access block beyond end of VAT (%d max %d)\n", |
| 64 | block, vdata->s_num_entries); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 65 | return 0xFFFFFFFF; |
| 66 | } |
| 67 | |
Jan Kara | fa5e081 | 2008-04-08 02:08:53 +0200 | [diff] [blame] | 68 | if (iinfo->i_alloc_type == ICBTAG_FLAG_AD_IN_ICB) { |
Sebastian Manciulea | 47c9358 | 2008-04-14 17:06:36 +0200 | [diff] [blame] | 69 | loc = le32_to_cpu(((__le32 *)(iinfo->i_ext.i_data + |
| 70 | vdata->s_start_offset))[block]); |
Jan Kara | fa5e081 | 2008-04-08 02:08:53 +0200 | [diff] [blame] | 71 | goto translate; |
| 72 | } |
| 73 | index = (sb->s_blocksize - vdata->s_start_offset) / sizeof(uint32_t); |
Cyrill Gorcunov | cb00ea3 | 2007-07-19 01:47:43 -0700 | [diff] [blame] | 74 | if (block >= index) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 75 | block -= index; |
| 76 | newblock = 1 + (block / (sb->s_blocksize / sizeof(uint32_t))); |
| 77 | index = block % (sb->s_blocksize / sizeof(uint32_t)); |
Cyrill Gorcunov | cb00ea3 | 2007-07-19 01:47:43 -0700 | [diff] [blame] | 78 | } else { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 79 | newblock = 0; |
Marcin Slusarz | 4b11111 | 2008-02-08 04:20:36 -0800 | [diff] [blame] | 80 | index = vdata->s_start_offset / sizeof(uint32_t) + block; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 81 | } |
| 82 | |
Marcin Slusarz | 6c79e98 | 2008-02-08 04:20:30 -0800 | [diff] [blame] | 83 | loc = udf_block_map(sbi->s_vat_inode, newblock); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 84 | |
Marcin Slusarz | 4b11111 | 2008-02-08 04:20:36 -0800 | [diff] [blame] | 85 | bh = sb_bread(sb, loc); |
| 86 | if (!bh) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 87 | udf_debug("get_pblock(UDF_VIRTUAL_MAP:%p,%d,%d) VAT: %d[%d]\n", |
Cyrill Gorcunov | cb00ea3 | 2007-07-19 01:47:43 -0700 | [diff] [blame] | 88 | sb, block, partition, loc, index); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 89 | return 0xFFFFFFFF; |
| 90 | } |
| 91 | |
Cyrill Gorcunov | 28de794 | 2007-07-21 04:37:18 -0700 | [diff] [blame] | 92 | loc = le32_to_cpu(((__le32 *)bh->b_data)[index]); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 93 | |
Jan Kara | 3bf25cb | 2007-05-08 00:35:16 -0700 | [diff] [blame] | 94 | brelse(bh); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 95 | |
Jan Kara | fa5e081 | 2008-04-08 02:08:53 +0200 | [diff] [blame] | 96 | translate: |
Marcin Slusarz | 48d6d8f | 2008-02-08 04:20:44 -0800 | [diff] [blame] | 97 | if (iinfo->i_location.partitionReferenceNum == partition) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 98 | udf_debug("recursive call to udf_get_pblock!\n"); |
| 99 | return 0xFFFFFFFF; |
| 100 | } |
| 101 | |
Cyrill Gorcunov | cb00ea3 | 2007-07-19 01:47:43 -0700 | [diff] [blame] | 102 | return udf_get_pblock(sb, loc, |
Marcin Slusarz | 48d6d8f | 2008-02-08 04:20:44 -0800 | [diff] [blame] | 103 | iinfo->i_location.partitionReferenceNum, |
Cyrill Gorcunov | 28de794 | 2007-07-21 04:37:18 -0700 | [diff] [blame] | 104 | offset); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 105 | } |
| 106 | |
Marcin Slusarz | 4b11111 | 2008-02-08 04:20:36 -0800 | [diff] [blame] | 107 | inline uint32_t udf_get_pblock_virt20(struct super_block *sb, uint32_t block, |
Cyrill Gorcunov | cb00ea3 | 2007-07-19 01:47:43 -0700 | [diff] [blame] | 108 | uint16_t partition, uint32_t offset) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 109 | { |
| 110 | return udf_get_pblock_virt15(sb, block, partition, offset); |
| 111 | } |
| 112 | |
Marcin Slusarz | 6c79e98 | 2008-02-08 04:20:30 -0800 | [diff] [blame] | 113 | uint32_t udf_get_pblock_spar15(struct super_block *sb, uint32_t block, |
Cyrill Gorcunov | cb00ea3 | 2007-07-19 01:47:43 -0700 | [diff] [blame] | 114 | uint16_t partition, uint32_t offset) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 115 | { |
| 116 | int i; |
| 117 | struct sparingTable *st = NULL; |
Marcin Slusarz | 6c79e98 | 2008-02-08 04:20:30 -0800 | [diff] [blame] | 118 | struct udf_sb_info *sbi = UDF_SB(sb); |
| 119 | struct udf_part_map *map; |
| 120 | uint32_t packet; |
Marcin Slusarz | 4b11111 | 2008-02-08 04:20:36 -0800 | [diff] [blame] | 121 | struct udf_sparing_data *sdata; |
Marcin Slusarz | 6c79e98 | 2008-02-08 04:20:30 -0800 | [diff] [blame] | 122 | |
| 123 | map = &sbi->s_partmaps[partition]; |
Marcin Slusarz | 4b11111 | 2008-02-08 04:20:36 -0800 | [diff] [blame] | 124 | sdata = &map->s_type_specific.s_sparing; |
| 125 | packet = (block + offset) & ~(sdata->s_packet_len - 1); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 126 | |
Cyrill Gorcunov | cb00ea3 | 2007-07-19 01:47:43 -0700 | [diff] [blame] | 127 | for (i = 0; i < 4; i++) { |
Marcin Slusarz | 4b11111 | 2008-02-08 04:20:36 -0800 | [diff] [blame] | 128 | if (sdata->s_spar_map[i] != NULL) { |
| 129 | st = (struct sparingTable *) |
| 130 | sdata->s_spar_map[i]->b_data; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 131 | break; |
| 132 | } |
| 133 | } |
| 134 | |
Cyrill Gorcunov | cb00ea3 | 2007-07-19 01:47:43 -0700 | [diff] [blame] | 135 | if (st) { |
| 136 | for (i = 0; i < le16_to_cpu(st->reallocationTableLen); i++) { |
Marcin Slusarz | 4b11111 | 2008-02-08 04:20:36 -0800 | [diff] [blame] | 137 | struct sparingEntry *entry = &st->mapEntry[i]; |
| 138 | u32 origLoc = le32_to_cpu(entry->origLocation); |
| 139 | if (origLoc >= 0xFFFFFFF0) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 140 | break; |
Marcin Slusarz | 4b11111 | 2008-02-08 04:20:36 -0800 | [diff] [blame] | 141 | else if (origLoc == packet) |
| 142 | return le32_to_cpu(entry->mappedLocation) + |
| 143 | ((block + offset) & |
| 144 | (sdata->s_packet_len - 1)); |
| 145 | else if (origLoc > packet) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 146 | break; |
| 147 | } |
| 148 | } |
Cyrill Gorcunov | 28de794 | 2007-07-21 04:37:18 -0700 | [diff] [blame] | 149 | |
Marcin Slusarz | 6c79e98 | 2008-02-08 04:20:30 -0800 | [diff] [blame] | 150 | return map->s_partition_root + block + offset; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 151 | } |
| 152 | |
| 153 | int udf_relocate_blocks(struct super_block *sb, long old_block, long *new_block) |
| 154 | { |
| 155 | struct udf_sparing_data *sdata; |
| 156 | struct sparingTable *st = NULL; |
| 157 | struct sparingEntry mapEntry; |
| 158 | uint32_t packet; |
| 159 | int i, j, k, l; |
Marcin Slusarz | 6c79e98 | 2008-02-08 04:20:30 -0800 | [diff] [blame] | 160 | struct udf_sb_info *sbi = UDF_SB(sb); |
Marcin Slusarz | 4b11111 | 2008-02-08 04:20:36 -0800 | [diff] [blame] | 161 | u16 reallocationTableLen; |
| 162 | struct buffer_head *bh; |
Alessio Igor Bogani | 7db09be | 2010-11-16 18:40:48 +0100 | [diff] [blame] | 163 | int ret = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 164 | |
Alessio Igor Bogani | 7db09be | 2010-11-16 18:40:48 +0100 | [diff] [blame] | 165 | mutex_lock(&sbi->s_alloc_mutex); |
Marcin Slusarz | 6c79e98 | 2008-02-08 04:20:30 -0800 | [diff] [blame] | 166 | for (i = 0; i < sbi->s_partitions; i++) { |
| 167 | struct udf_part_map *map = &sbi->s_partmaps[i]; |
| 168 | if (old_block > map->s_partition_root && |
| 169 | old_block < map->s_partition_root + map->s_partition_len) { |
| 170 | sdata = &map->s_type_specific.s_sparing; |
Marcin Slusarz | 4b11111 | 2008-02-08 04:20:36 -0800 | [diff] [blame] | 171 | packet = (old_block - map->s_partition_root) & |
| 172 | ~(sdata->s_packet_len - 1); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 173 | |
Marcin Slusarz | 4b11111 | 2008-02-08 04:20:36 -0800 | [diff] [blame] | 174 | for (j = 0; j < 4; j++) |
| 175 | if (sdata->s_spar_map[j] != NULL) { |
| 176 | st = (struct sparingTable *) |
| 177 | sdata->s_spar_map[j]->b_data; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 178 | break; |
| 179 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 180 | |
Alessio Igor Bogani | 7db09be | 2010-11-16 18:40:48 +0100 | [diff] [blame] | 181 | if (!st) { |
| 182 | ret = 1; |
| 183 | goto out; |
| 184 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 185 | |
Marcin Slusarz | 4b11111 | 2008-02-08 04:20:36 -0800 | [diff] [blame] | 186 | reallocationTableLen = |
| 187 | le16_to_cpu(st->reallocationTableLen); |
| 188 | for (k = 0; k < reallocationTableLen; k++) { |
| 189 | struct sparingEntry *entry = &st->mapEntry[k]; |
| 190 | u32 origLoc = le32_to_cpu(entry->origLocation); |
| 191 | |
| 192 | if (origLoc == 0xFFFFFFFF) { |
Cyrill Gorcunov | cb00ea3 | 2007-07-19 01:47:43 -0700 | [diff] [blame] | 193 | for (; j < 4; j++) { |
Marcin Slusarz | 4b11111 | 2008-02-08 04:20:36 -0800 | [diff] [blame] | 194 | int len; |
| 195 | bh = sdata->s_spar_map[j]; |
| 196 | if (!bh) |
| 197 | continue; |
| 198 | |
| 199 | st = (struct sparingTable *) |
| 200 | bh->b_data; |
| 201 | entry->origLocation = |
| 202 | cpu_to_le32(packet); |
| 203 | len = |
| 204 | sizeof(struct sparingTable) + |
| 205 | reallocationTableLen * |
| 206 | sizeof(struct sparingEntry); |
| 207 | udf_update_tag((char *)st, len); |
| 208 | mark_buffer_dirty(bh); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 209 | } |
Marcin Slusarz | 4b11111 | 2008-02-08 04:20:36 -0800 | [diff] [blame] | 210 | *new_block = le32_to_cpu( |
| 211 | entry->mappedLocation) + |
| 212 | ((old_block - |
| 213 | map->s_partition_root) & |
| 214 | (sdata->s_packet_len - 1)); |
Alessio Igor Bogani | 7db09be | 2010-11-16 18:40:48 +0100 | [diff] [blame] | 215 | ret = 0; |
| 216 | goto out; |
Marcin Slusarz | 4b11111 | 2008-02-08 04:20:36 -0800 | [diff] [blame] | 217 | } else if (origLoc == packet) { |
| 218 | *new_block = le32_to_cpu( |
| 219 | entry->mappedLocation) + |
| 220 | ((old_block - |
| 221 | map->s_partition_root) & |
| 222 | (sdata->s_packet_len - 1)); |
Alessio Igor Bogani | 7db09be | 2010-11-16 18:40:48 +0100 | [diff] [blame] | 223 | ret = 0; |
| 224 | goto out; |
Marcin Slusarz | 4b11111 | 2008-02-08 04:20:36 -0800 | [diff] [blame] | 225 | } else if (origLoc > packet) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 226 | break; |
| 227 | } |
Cyrill Gorcunov | 28de794 | 2007-07-21 04:37:18 -0700 | [diff] [blame] | 228 | |
Marcin Slusarz | 4b11111 | 2008-02-08 04:20:36 -0800 | [diff] [blame] | 229 | for (l = k; l < reallocationTableLen; l++) { |
| 230 | struct sparingEntry *entry = &st->mapEntry[l]; |
| 231 | u32 origLoc = le32_to_cpu(entry->origLocation); |
| 232 | |
| 233 | if (origLoc != 0xFFFFFFFF) |
| 234 | continue; |
| 235 | |
| 236 | for (; j < 4; j++) { |
| 237 | bh = sdata->s_spar_map[j]; |
| 238 | if (!bh) |
| 239 | continue; |
| 240 | |
| 241 | st = (struct sparingTable *)bh->b_data; |
| 242 | mapEntry = st->mapEntry[l]; |
| 243 | mapEntry.origLocation = |
| 244 | cpu_to_le32(packet); |
| 245 | memmove(&st->mapEntry[k + 1], |
| 246 | &st->mapEntry[k], |
| 247 | (l - k) * |
| 248 | sizeof(struct sparingEntry)); |
| 249 | st->mapEntry[k] = mapEntry; |
| 250 | udf_update_tag((char *)st, |
| 251 | sizeof(struct sparingTable) + |
| 252 | reallocationTableLen * |
| 253 | sizeof(struct sparingEntry)); |
| 254 | mark_buffer_dirty(bh); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 255 | } |
Marcin Slusarz | 4b11111 | 2008-02-08 04:20:36 -0800 | [diff] [blame] | 256 | *new_block = |
| 257 | le32_to_cpu( |
| 258 | st->mapEntry[k].mappedLocation) + |
| 259 | ((old_block - map->s_partition_root) & |
| 260 | (sdata->s_packet_len - 1)); |
Alessio Igor Bogani | 7db09be | 2010-11-16 18:40:48 +0100 | [diff] [blame] | 261 | ret = 0; |
| 262 | goto out; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 263 | } |
Cyrill Gorcunov | 28de794 | 2007-07-21 04:37:18 -0700 | [diff] [blame] | 264 | |
Alessio Igor Bogani | 7db09be | 2010-11-16 18:40:48 +0100 | [diff] [blame] | 265 | ret = 1; |
| 266 | goto out; |
Cyrill Gorcunov | 28de794 | 2007-07-21 04:37:18 -0700 | [diff] [blame] | 267 | } /* if old_block */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 268 | } |
Cyrill Gorcunov | 28de794 | 2007-07-21 04:37:18 -0700 | [diff] [blame] | 269 | |
Marcin Slusarz | 6c79e98 | 2008-02-08 04:20:30 -0800 | [diff] [blame] | 270 | if (i == sbi->s_partitions) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 271 | /* outside of partitions */ |
| 272 | /* for now, fail =) */ |
Alessio Igor Bogani | 7db09be | 2010-11-16 18:40:48 +0100 | [diff] [blame] | 273 | ret = 1; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 274 | } |
| 275 | |
Alessio Igor Bogani | 7db09be | 2010-11-16 18:40:48 +0100 | [diff] [blame] | 276 | out: |
| 277 | mutex_unlock(&sbi->s_alloc_mutex); |
| 278 | return ret; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 279 | } |
Jan Kara | bfb257a | 2008-04-08 20:37:21 +0200 | [diff] [blame] | 280 | |
| 281 | static uint32_t udf_try_read_meta(struct inode *inode, uint32_t block, |
| 282 | uint16_t partition, uint32_t offset) |
| 283 | { |
| 284 | struct super_block *sb = inode->i_sb; |
| 285 | struct udf_part_map *map; |
Pekka Enberg | 5ca4e4b | 2008-10-15 12:28:03 +0200 | [diff] [blame] | 286 | struct kernel_lb_addr eloc; |
Jan Kara | bfb257a | 2008-04-08 20:37:21 +0200 | [diff] [blame] | 287 | uint32_t elen; |
| 288 | sector_t ext_offset; |
| 289 | struct extent_position epos = {}; |
| 290 | uint32_t phyblock; |
| 291 | |
| 292 | if (inode_bmap(inode, block, &epos, &eloc, &elen, &ext_offset) != |
| 293 | (EXT_RECORDED_ALLOCATED >> 30)) |
| 294 | phyblock = 0xFFFFFFFF; |
| 295 | else { |
| 296 | map = &UDF_SB(sb)->s_partmaps[partition]; |
| 297 | /* map to sparable/physical partition desc */ |
| 298 | phyblock = udf_get_pblock(sb, eloc.logicalBlockNum, |
| 299 | map->s_partition_num, ext_offset + offset); |
| 300 | } |
| 301 | |
| 302 | brelse(epos.bh); |
| 303 | return phyblock; |
| 304 | } |
| 305 | |
| 306 | uint32_t udf_get_pblock_meta25(struct super_block *sb, uint32_t block, |
| 307 | uint16_t partition, uint32_t offset) |
| 308 | { |
| 309 | struct udf_sb_info *sbi = UDF_SB(sb); |
| 310 | struct udf_part_map *map; |
| 311 | struct udf_meta_data *mdata; |
| 312 | uint32_t retblk; |
| 313 | struct inode *inode; |
| 314 | |
| 315 | udf_debug("READING from METADATA\n"); |
| 316 | |
| 317 | map = &sbi->s_partmaps[partition]; |
| 318 | mdata = &map->s_type_specific.s_metadata; |
| 319 | inode = mdata->s_metadata_fe ? : mdata->s_mirror_fe; |
| 320 | |
| 321 | /* We shouldn't mount such media... */ |
| 322 | BUG_ON(!inode); |
| 323 | retblk = udf_try_read_meta(inode, block, partition, offset); |
Namjae Jeon | 3080a74 | 2011-10-23 19:28:32 +0900 | [diff] [blame^] | 324 | if (retblk == 0xFFFFFFFF && mdata->s_metadata_fe) { |
Joe Perches | a40ecd7 | 2011-10-10 01:08:04 -0700 | [diff] [blame] | 325 | udf_warn(sb, "error reading from METADATA, trying to read from MIRROR\n"); |
Namjae Jeon | 3080a74 | 2011-10-23 19:28:32 +0900 | [diff] [blame^] | 326 | if (!mdata->s_mirror_loaded_flag) { |
| 327 | mdata->s_mirror_fe = udf_find_metadata_inode_efe(sb, |
| 328 | mdata->s_mirror_file_loc, map->s_partition_num); |
| 329 | mdata->s_mirror_loaded_flag = 1; |
| 330 | } |
| 331 | |
Jan Kara | bfb257a | 2008-04-08 20:37:21 +0200 | [diff] [blame] | 332 | inode = mdata->s_mirror_fe; |
| 333 | if (!inode) |
| 334 | return 0xFFFFFFFF; |
| 335 | retblk = udf_try_read_meta(inode, block, partition, offset); |
| 336 | } |
| 337 | |
| 338 | return retblk; |
| 339 | } |