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