Commit 572804f9 authored by Alexander Viro's avatar Alexander Viro Committed by Linus Torvalds

[PATCH] UDF endianness fixes

Lots of crap.  It looks like the thing had never been really tested on
big-endian boxen...  Aside of usual "forgot to convert" bugs there's a cute
one - foo->le16field = cpu_to_le32(bar) does not work on big-endian...
Signed-off-by: default avatarAl Viro <viro@parcelfarce.linux.org.uk>
Signed-off-by: default avatarLinus Torvalds <torvalds@osdl.org>
parent ec5995e8
...@@ -268,12 +268,12 @@ struct buffer_head * udf_expand_dir_adinicb(struct inode *inode, int *block, int ...@@ -268,12 +268,12 @@ struct buffer_head * udf_expand_dir_adinicb(struct inode *inode, int *block, int
return NULL; return NULL;
} }
UDF_I_ALLOCTYPE(inode) = alloctype; UDF_I_ALLOCTYPE(inode) = alloctype;
sfi->descTag.tagLocation = *block; sfi->descTag.tagLocation = cpu_to_le32(*block);
dfibh.soffset = dfibh.eoffset; dfibh.soffset = dfibh.eoffset;
dfibh.eoffset += (sfibh.eoffset - sfibh.soffset); dfibh.eoffset += (sfibh.eoffset - sfibh.soffset);
dfi = (struct fileIdentDesc *)(dbh->b_data + dfibh.soffset); dfi = (struct fileIdentDesc *)(dbh->b_data + dfibh.soffset);
if (udf_write_fi(inode, sfi, dfi, &dfibh, sfi->impUse, if (udf_write_fi(inode, sfi, dfi, &dfibh, sfi->impUse,
sfi->fileIdent + sfi->lengthOfImpUse)) sfi->fileIdent + le16_to_cpu(sfi->lengthOfImpUse)))
{ {
UDF_I_ALLOCTYPE(inode) = ICBTAG_FLAG_AD_IN_ICB; UDF_I_ALLOCTYPE(inode) = ICBTAG_FLAG_AD_IN_ICB;
udf_release_data(dbh); udf_release_data(dbh);
...@@ -1411,11 +1411,11 @@ udf_update_inode(struct inode *inode, int do_sync) ...@@ -1411,11 +1411,11 @@ udf_update_inode(struct inode *inode, int do_sync)
udf_add_extendedattr(inode, udf_add_extendedattr(inode,
sizeof(struct deviceSpec) + sizeof(struct deviceSpec) +
sizeof(regid), 12, 0x3); sizeof(regid), 12, 0x3);
dsea->attrType = 12; dsea->attrType = cpu_to_le32(12);
dsea->attrSubtype = 1; dsea->attrSubtype = 1;
dsea->attrLength = sizeof(struct deviceSpec) + dsea->attrLength = cpu_to_le32(sizeof(struct deviceSpec) +
sizeof(regid); sizeof(regid));
dsea->impUseLength = sizeof(regid); dsea->impUseLength = cpu_to_le32(sizeof(regid));
} }
eid = (regid *)dsea->impUse; eid = (regid *)dsea->impUse;
memset(eid, 0, sizeof(regid)); memset(eid, 0, sizeof(regid));
......
...@@ -119,7 +119,7 @@ int udf_write_fi(struct inode *inode, struct fileIdentDesc *cfi, ...@@ -119,7 +119,7 @@ int udf_write_fi(struct inode *inode, struct fileIdentDesc *cfi,
crc = udf_crc(fibh->ebh->b_data, fibh->eoffset, crc); crc = udf_crc(fibh->ebh->b_data, fibh->eoffset, crc);
} }
cfi->descTag.descCRC = cpu_to_le32(crc); cfi->descTag.descCRC = cpu_to_le16(crc);
cfi->descTag.descCRCLength = cpu_to_le16(crclen); cfi->descTag.descCRCLength = cpu_to_le16(crclen);
for (i=0; i<16; i++) for (i=0; i<16; i++)
......
...@@ -119,7 +119,7 @@ uint32_t udf_get_pblock_spar15(struct super_block *sb, uint32_t block, uint16_t ...@@ -119,7 +119,7 @@ uint32_t udf_get_pblock_spar15(struct super_block *sb, uint32_t block, uint16_t
if (st) if (st)
{ {
for (i=0; i<st->reallocationTableLen; i++) for (i=0; i<le16_to_cpu(st->reallocationTableLen); i++)
{ {
if (le32_to_cpu(st->mapEntry[i].origLocation) >= 0xFFFFFFF0) if (le32_to_cpu(st->mapEntry[i].origLocation) >= 0xFFFFFFF0)
break; break;
...@@ -163,7 +163,7 @@ int udf_relocate_blocks(struct super_block *sb, long old_block, long *new_block) ...@@ -163,7 +163,7 @@ int udf_relocate_blocks(struct super_block *sb, long old_block, long *new_block)
if (!st) if (!st)
return 1; return 1;
for (k=0; k<st->reallocationTableLen; k++) for (k=0; k<le16_to_cpu(st->reallocationTableLen); k++)
{ {
if (le32_to_cpu(st->mapEntry[k].origLocation) == 0xFFFFFFFF) if (le32_to_cpu(st->mapEntry[k].origLocation) == 0xFFFFFFFF)
{ {
...@@ -173,7 +173,7 @@ int udf_relocate_blocks(struct super_block *sb, long old_block, long *new_block) ...@@ -173,7 +173,7 @@ int udf_relocate_blocks(struct super_block *sb, long old_block, long *new_block)
{ {
st = (struct sparingTable *)sdata->s_spar_map[j]->b_data; st = (struct sparingTable *)sdata->s_spar_map[j]->b_data;
st->mapEntry[k].origLocation = cpu_to_le32(packet); st->mapEntry[k].origLocation = cpu_to_le32(packet);
udf_update_tag((char *)st, sizeof(struct sparingTable) + st->reallocationTableLen * sizeof(struct sparingEntry)); udf_update_tag((char *)st, sizeof(struct sparingTable) + le16_to_cpu(st->reallocationTableLen) * sizeof(struct sparingEntry));
mark_buffer_dirty(sdata->s_spar_map[j]); mark_buffer_dirty(sdata->s_spar_map[j]);
} }
} }
...@@ -190,7 +190,7 @@ int udf_relocate_blocks(struct super_block *sb, long old_block, long *new_block) ...@@ -190,7 +190,7 @@ int udf_relocate_blocks(struct super_block *sb, long old_block, long *new_block)
else if (le32_to_cpu(st->mapEntry[k].origLocation) > packet) else if (le32_to_cpu(st->mapEntry[k].origLocation) > packet)
break; break;
} }
for (l=k; l<st->reallocationTableLen; l++) for (l=k; l<le16_to_cpu(st->reallocationTableLen); l++)
{ {
if (le32_to_cpu(st->mapEntry[l].origLocation) == 0xFFFFFFFF) if (le32_to_cpu(st->mapEntry[l].origLocation) == 0xFFFFFFFF)
{ {
...@@ -203,7 +203,7 @@ int udf_relocate_blocks(struct super_block *sb, long old_block, long *new_block) ...@@ -203,7 +203,7 @@ int udf_relocate_blocks(struct super_block *sb, long old_block, long *new_block)
mapEntry.origLocation = cpu_to_le32(packet); mapEntry.origLocation = cpu_to_le32(packet);
memmove(&st->mapEntry[k+1], &st->mapEntry[k], (l-k)*sizeof(struct sparingEntry)); memmove(&st->mapEntry[k+1], &st->mapEntry[k], (l-k)*sizeof(struct sparingEntry));
st->mapEntry[k] = mapEntry; st->mapEntry[k] = mapEntry;
udf_update_tag((char *)st, sizeof(struct sparingTable) + st->reallocationTableLen * sizeof(struct sparingEntry)); udf_update_tag((char *)st, sizeof(struct sparingTable) + le16_to_cpu(st->reallocationTableLen) * sizeof(struct sparingEntry));
mark_buffer_dirty(sdata->s_spar_map[j]); mark_buffer_dirty(sdata->s_spar_map[j]);
} }
} }
......
...@@ -1455,7 +1455,7 @@ static void udf_close_lvid(struct super_block *sb) ...@@ -1455,7 +1455,7 @@ static void udf_close_lvid(struct super_block *sb)
UDF_SB_LVIDIU(sb)->minUDFReadRev = cpu_to_le16(UDF_SB_UDFREV(sb)); UDF_SB_LVIDIU(sb)->minUDFReadRev = cpu_to_le16(UDF_SB_UDFREV(sb));
if (UDF_SB_UDFREV(sb) > le16_to_cpu(UDF_SB_LVIDIU(sb)->minUDFWriteRev)) if (UDF_SB_UDFREV(sb) > le16_to_cpu(UDF_SB_LVIDIU(sb)->minUDFWriteRev))
UDF_SB_LVIDIU(sb)->minUDFWriteRev = cpu_to_le16(UDF_SB_UDFREV(sb)); UDF_SB_LVIDIU(sb)->minUDFWriteRev = cpu_to_le16(UDF_SB_UDFREV(sb));
UDF_SB_LVID(sb)->integrityType = LVID_INTEGRITY_TYPE_CLOSE; UDF_SB_LVID(sb)->integrityType = cpu_to_le32(LVID_INTEGRITY_TYPE_CLOSE);
UDF_SB_LVID(sb)->descTag.descCRC = UDF_SB_LVID(sb)->descTag.descCRC =
cpu_to_le16(udf_crc((char *)UDF_SB_LVID(sb) + sizeof(tag), cpu_to_le16(udf_crc((char *)UDF_SB_LVID(sb) + sizeof(tag),
...@@ -1585,7 +1585,8 @@ static int udf_fill_super(struct super_block *sb, void *options, int silent) ...@@ -1585,7 +1585,8 @@ static int udf_fill_super(struct super_block *sb, void *options, int silent)
if (minUDFReadRev > UDF_MAX_READ_VERSION) if (minUDFReadRev > UDF_MAX_READ_VERSION)
{ {
printk("UDF-fs: minUDFReadRev=%x (max is %x)\n", printk("UDF-fs: minUDFReadRev=%x (max is %x)\n",
UDF_SB_LVIDIU(sb)->minUDFReadRev, UDF_MAX_READ_VERSION); le16_to_cpu(UDF_SB_LVIDIU(sb)->minUDFReadRev),
UDF_MAX_READ_VERSION);
goto error_out; goto error_out;
} }
else if (minUDFWriteRev > UDF_MAX_WRITE_VERSION) else if (minUDFWriteRev > UDF_MAX_WRITE_VERSION)
...@@ -1824,7 +1825,7 @@ udf_count_free_bitmap(struct super_block *sb, struct udf_bitmap *bitmap) ...@@ -1824,7 +1825,7 @@ udf_count_free_bitmap(struct super_block *sb, struct udf_bitmap *bitmap)
} }
bm = (struct spaceBitmapDesc *)bh->b_data; bm = (struct spaceBitmapDesc *)bh->b_data;
bytes = bm->numOfBytes; bytes = le32_to_cpu(bm->numOfBytes);
index = sizeof(struct spaceBitmapDesc); /* offset in first block only */ index = sizeof(struct spaceBitmapDesc); /* offset in first block only */
ptr = (uint8_t *)bh->b_data; ptr = (uint8_t *)bh->b_data;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment