Fixed two endianness problems with old patch from 2009-01-30.

From: unsik Kim <donar...@gmail.com>
Signed-off-by: Bernhard Weirich <bernhard.weir...@riedel.net>

--- fs/ext2/ext2fs.c    2009-06-09 18:03:20.000000000 +0200
+++ fs/ext2/ext2fs.c    2009-06-09 18:04:26.000000000 +0200
@@ -110,7 +110,7 @@
        uint32_t inode_table_id;
        uint16_t free_blocks;
        uint16_t free_inodes;
-       uint16_t pad;
+    uint16_t used_dir_cnt;
        uint32_t reserved[3];
 };
 
@@ -182,14 +182,23 @@
 
 static int ext2fs_blockgroup
        (struct ext2_data *data, int group, struct ext2_block_group *blkgrp) {
+    unsigned int blkno;
+    unsigned int blkoff;
+    unsigned int desc_per_blk;
+
+    desc_per_blk = EXT2_BLOCK_SIZE(data) / sizeof(struct ext2_block_group);
+
+    blkno = __le32_to_cpu(data->sblock.first_data_block) + 1 +
+    group / desc_per_blk;
+    blkoff = (group % desc_per_blk) * sizeof(struct ext2_block_group);
 #ifdef DEBUG
-       printf ("ext2fs read blockgroup\n");
+    printf ("ext2fs read %d group descriptor (blkno %d blkoff %d)\n",
+        group, blkno, blkoff);
 #endif
-       return (ext2fs_devread
-               (((__le32_to_cpu (data->sblock.first_data_block) +
-                  1) << LOG2_EXT2_BLOCK_SIZE (data)),
-                group * sizeof (struct ext2_block_group),
-                sizeof (struct ext2_block_group), (char *) blkgrp));
+    return (ext2fs_devread
+        (blkno << LOG2_EXT2_BLOCK_SIZE(data),
+         blkoff, sizeof(struct ext2_block_group), (char *)blkgrp));
+
 }
 
 
@@ -203,11 +212,11 @@
        unsigned int blkno;
        unsigned int blkoff;
 
-       /* It is easier to calculate if the first inode is 0.  */
-       ino--;
 #ifdef DEBUG
        printf ("ext2fs read inode %d\n", ino);
 #endif
+       /* It is easier to calculate if the first inode is 0.  */
+       ino--;
        status = ext2fs_blockgroup (data,
                                    ino /
                                    __le32_to_cpu (sblock->inodes_per_group),
@@ -215,22 +224,26 @@
        if (status == 0) {
                return (0);
        }
-       inodes_per_block = EXT2_BLOCK_SIZE (data) / 128;
-       blkno = (ino % __le32_to_cpu (sblock->inodes_per_group)) /
-               inodes_per_block;
-       blkoff = (ino % __le32_to_cpu (sblock->inodes_per_group)) %
-               inodes_per_block;
+
+    inodes_per_block = EXT2_BLOCK_SIZE(data) / 
__le16_to_cpu(sblock->inode_size);
+
 #ifdef DEBUG
-       printf ("ext2fs read inode blkno %d blkoff %d\n", blkno, blkoff);
+    printf("id: %d, ino: %d, ipg: %d, ipb: %d, ins: %d\n", 
__le32_to_cpu(blkgrp.inode_table_id), ino, inodes_per_block, 
__le32_to_cpu(sblock->inodes_per_group), __le16_to_cpu(sblock->inode_size));
 #endif
-       /* Read the inode.  */
-       status = ext2fs_devread (((__le32_to_cpu (blkgrp.inode_table_id) +
-                                  blkno) << LOG2_EXT2_BLOCK_SIZE (data)),
-                                sizeof (struct ext2_inode) * blkoff,
-                                sizeof (struct ext2_inode), (char *) inode);
-       if (status == 0) {
-               return (0);
-       }
+
+    blkno = __le32_to_cpu(blkgrp.inode_table_id) +
+        (ino % __le32_to_cpu(sblock->inodes_per_group)) / inodes_per_block;
+         blkoff = (ino % inodes_per_block) * __le16_to_cpu(sblock->inode_size);
+#ifdef DEBUG
+          printf ("ext2fs read inode blkno %d blkoff %d\n", blkno, blkoff);
+#endif
+          /* Read the inode.  */
+    status = ext2fs_devread (blkno << LOG2_EXT2_BLOCK_SIZE (data), blkoff,
+                             sizeof (struct ext2_inode), (char *) inode);
+    if (status == 0) {
+        return (0);
+    }
+
        return (1);
 }
 

Bernhard WEIRICH
_______________________________________________
U-Boot mailing list
U-Boot@lists.denx.de
http://lists.denx.de/mailman/listinfo/u-boot

Reply via email to