void udf_new_tag(char *data, uint16_t ident, uint16_t version, uint16_t snum, uint32_t loc, int length) { tag *tptr = (tag *)data; tptr->tagIdent = cpu_to_le16(ident); tptr->descVersion = cpu_to_le16(version); tptr->tagSerialNum = cpu_to_le16(snum); tptr->tagLocation = cpu_to_le32(loc); udf_update_tag(data, length); }
int udf_relocate_blocks(struct super_block *sb, long old_block, long *new_block) { struct udf_sparing_data *sdata; struct sparingTable *st = NULL; struct sparingEntry mapEntry; uint32_t packet; int i, j, k, l; for (i = 0; i < UDF_SB_NUMPARTS(sb); i++) { if (old_block > UDF_SB_PARTROOT(sb,i) && old_block < UDF_SB_PARTROOT(sb,i) + UDF_SB_PARTLEN(sb,i)) { sdata = &UDF_SB_TYPESPAR(sb,i); packet = (old_block - UDF_SB_PARTROOT(sb,i)) & ~(sdata->s_packet_len - 1); for (j = 0; j < 4; j++) { if (UDF_SB_TYPESPAR(sb,i).s_spar_map[j] != NULL) { st = (struct sparingTable *)sdata->s_spar_map[j]->b_data; break; } } if (!st) return 1; for (k = 0; k < le16_to_cpu(st->reallocationTableLen); k++) { if (le32_to_cpu(st->mapEntry[k].origLocation) == 0xFFFFFFFF) { for (; j < 4; j++) { if (sdata->s_spar_map[j]) { st = (struct sparingTable *)sdata->s_spar_map[j]->b_data; st->mapEntry[k].origLocation = cpu_to_le32(packet); udf_update_tag((char *)st, sizeof(struct sparingTable) + le16_to_cpu(st->reallocationTableLen) * sizeof(struct sparingEntry)); mark_buffer_dirty(sdata->s_spar_map[j]); } } *new_block = le32_to_cpu(st->mapEntry[k].mappedLocation) + ((old_block - UDF_SB_PARTROOT(sb,i)) & (sdata->s_packet_len - 1)); return 0; } else if (le32_to_cpu(st->mapEntry[k].origLocation) == packet) { *new_block = le32_to_cpu(st->mapEntry[k].mappedLocation) + ((old_block - UDF_SB_PARTROOT(sb,i)) & (sdata->s_packet_len - 1)); return 0; } else if (le32_to_cpu(st->mapEntry[k].origLocation) > packet) { break; } } for (l = k; l < le16_to_cpu(st->reallocationTableLen); l++) { if (le32_to_cpu(st->mapEntry[l].origLocation) == 0xFFFFFFFF) { for (; j < 4; j++) { if (sdata->s_spar_map[j]) { st = (struct sparingTable *)sdata->s_spar_map[j]->b_data; mapEntry = st->mapEntry[l]; mapEntry.origLocation = cpu_to_le32(packet); memmove(&st->mapEntry[k + 1], &st->mapEntry[k], (l - k) * sizeof(struct sparingEntry)); st->mapEntry[k] = mapEntry; udf_update_tag((char *)st, sizeof(struct sparingTable) + le16_to_cpu(st->reallocationTableLen) * sizeof(struct sparingEntry)); mark_buffer_dirty(sdata->s_spar_map[j]); } } *new_block = le32_to_cpu(st->mapEntry[k].mappedLocation) + ((old_block - UDF_SB_PARTROOT(sb,i)) & (sdata->s_packet_len - 1)); return 0; } } return 1; } /* if old_block */ } if (i == UDF_SB_NUMPARTS(sb)) { /* outside of partitions */ /* for now, fail =) */ return 1; } return 0; }