From 572804f988b73481286d300ad693a0d5f7d2e417 Mon Sep 17 00:00:00 2001 From: Alexander Viro Date: Sat, 4 Sep 2004 06:42:46 -0700 Subject: [PATCH] [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: Al Viro Signed-off-by: Linus Torvalds --- fs/udf/inode.c | 12 ++++++------ fs/udf/namei.c | 2 +- fs/udf/partition.c | 10 +++++----- fs/udf/super.c | 7 ++++--- 4 files changed, 16 insertions(+), 15 deletions(-) diff --git a/fs/udf/inode.c b/fs/udf/inode.c index f4724459a1a97..6ddc6a06d86ad 100644 --- a/fs/udf/inode.c +++ b/fs/udf/inode.c @@ -268,12 +268,12 @@ struct buffer_head * udf_expand_dir_adinicb(struct inode *inode, int *block, int return NULL; } UDF_I_ALLOCTYPE(inode) = alloctype; - sfi->descTag.tagLocation = *block; + sfi->descTag.tagLocation = cpu_to_le32(*block); dfibh.soffset = dfibh.eoffset; dfibh.eoffset += (sfibh.eoffset - sfibh.soffset); dfi = (struct fileIdentDesc *)(dbh->b_data + dfibh.soffset); 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_release_data(dbh); @@ -1411,11 +1411,11 @@ udf_update_inode(struct inode *inode, int do_sync) udf_add_extendedattr(inode, sizeof(struct deviceSpec) + sizeof(regid), 12, 0x3); - dsea->attrType = 12; + dsea->attrType = cpu_to_le32(12); dsea->attrSubtype = 1; - dsea->attrLength = sizeof(struct deviceSpec) + - sizeof(regid); - dsea->impUseLength = sizeof(regid); + dsea->attrLength = cpu_to_le32(sizeof(struct deviceSpec) + + sizeof(regid)); + dsea->impUseLength = cpu_to_le32(sizeof(regid)); } eid = (regid *)dsea->impUse; memset(eid, 0, sizeof(regid)); diff --git a/fs/udf/namei.c b/fs/udf/namei.c index 86cf34e77ebf2..0c5615ae4f05b 100644 --- a/fs/udf/namei.c +++ b/fs/udf/namei.c @@ -119,7 +119,7 @@ int udf_write_fi(struct inode *inode, struct fileIdentDesc *cfi, 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); for (i=0; i<16; i++) diff --git a/fs/udf/partition.c b/fs/udf/partition.c index e182fb8a82313..92e8cbf02d126 100644 --- a/fs/udf/partition.c +++ b/fs/udf/partition.c @@ -119,7 +119,7 @@ uint32_t udf_get_pblock_spar15(struct super_block *sb, uint32_t block, uint16_t if (st) { - for (i=0; ireallocationTableLen; i++) + for (i=0; ireallocationTableLen); i++) { if (le32_to_cpu(st->mapEntry[i].origLocation) >= 0xFFFFFFF0) break; @@ -163,7 +163,7 @@ int udf_relocate_blocks(struct super_block *sb, long old_block, long *new_block) if (!st) return 1; - for (k=0; kreallocationTableLen; k++) + for (k=0; kreallocationTableLen); k++) { 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) { 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) + 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]); } } @@ -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) break; } - for (l=k; lreallocationTableLen; l++) + for (l=k; lreallocationTableLen); l++) { 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) 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) + 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]); } } diff --git a/fs/udf/super.c b/fs/udf/super.c index c132a95052f76..7b5484a5ba1fd 100644 --- a/fs/udf/super.c +++ b/fs/udf/super.c @@ -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)); 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_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 = 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) if (minUDFReadRev > UDF_MAX_READ_VERSION) { 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; } else if (minUDFWriteRev > UDF_MAX_WRITE_VERSION) @@ -1824,7 +1825,7 @@ udf_count_free_bitmap(struct super_block *sb, struct udf_bitmap *bitmap) } bm = (struct spaceBitmapDesc *)bh->b_data; - bytes = bm->numOfBytes; + bytes = le32_to_cpu(bm->numOfBytes); index = sizeof(struct spaceBitmapDesc); /* offset in first block only */ ptr = (uint8_t *)bh->b_data; -- 2.53.0