]> git.kernelconcepts.de Git - karo-tx-uboot.git/blobdiff - fs/ext2/ext2fs.c
net: sh-eth: Add support Gigabit of SH7734
[karo-tx-uboot.git] / fs / ext2 / ext2fs.c
index 436f4a4aa92a0f7eaef694743c172b4f8c2482e3..f621741e40555f420e996fe127606901b1d8d671 100644 (file)
@@ -110,7 +110,7 @@ struct ext2_block_group {
        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];
 };
 
@@ -178,18 +178,27 @@ int indir1_blkno = -1;
 uint32_t *indir2_block = NULL;
 int indir2_size = 0;
 int indir2_blkno = -1;
+static unsigned int inode_size;
 
 
 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,34 +212,33 @@ static int ext2fs_read_inode
        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);
+       printf ("ext2fs read inode %d, inode_size %d\n", ino, inode_size);
 #endif
-       status = ext2fs_blockgroup (data,
-                                   ino /
-                                   __le32_to_cpu (sblock->inodes_per_group),
-                                   &blkgrp);
+       /* It is easier to calculate if the first inode is 0.  */
+       ino--;
+       status = ext2fs_blockgroup (data, ino / __le32_to_cpu
+                                   (sblock->inodes_per_group), &blkgrp);
        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) / inode_size;
+
+       blkno = __le32_to_cpu (blkgrp.inode_table_id) +
+               (ino % __le32_to_cpu (sblock->inodes_per_group))
+               / inodes_per_block;
+       blkoff = (ino % inodes_per_block) * inode_size;
 #ifdef DEBUG
        printf ("ext2fs read inode blkno %d blkoff %d\n", blkno, blkoff);
 #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,
+       status = ext2fs_devread (blkno << LOG2_EXT2_BLOCK_SIZE (data), blkoff,
                                 sizeof (struct ext2_inode), (char *) inode);
        if (status == 0) {
                return (0);
        }
+
        return (1);
 }
 
@@ -257,7 +265,8 @@ static int ext2fs_read_block (ext2fs_node_t node, int fileblock) {
        /* Indirect.  */
        else if (fileblock < (INDIRECT_BLOCKS + (blksz / 4))) {
                if (indir1_block == NULL) {
-                       indir1_block = (uint32_t *) malloc (blksz);
+                       indir1_block = (uint32_t *) memalign(ARCH_DMA_MINALIGN,
+                                                            blksz);
                        if (indir1_block == NULL) {
                                printf ("** ext2fs read block (indir 1) malloc failed. **\n");
                                return (-1);
@@ -270,7 +279,8 @@ static int ext2fs_read_block (ext2fs_node_t node, int fileblock) {
                        indir1_block = NULL;
                        indir1_size = 0;
                        indir1_blkno = -1;
-                       indir1_block = (uint32_t *) malloc (blksz);
+                       indir1_block = (uint32_t *) memalign(ARCH_DMA_MINALIGN,
+                                                            blksz);
                        if (indir1_block == NULL) {
                                printf ("** ext2fs read block (indir 1) malloc failed. **\n");
                                return (-1);
@@ -301,7 +311,8 @@ static int ext2fs_read_block (ext2fs_node_t node, int fileblock) {
                                                   + blksz / 4);
 
                if (indir1_block == NULL) {
-                       indir1_block = (uint32_t *) malloc (blksz);
+                       indir1_block = (uint32_t *) memalign(ARCH_DMA_MINALIGN,
+                                                            blksz);
                        if (indir1_block == NULL) {
                                printf ("** ext2fs read block (indir 2 1) malloc failed. **\n");
                                return (-1);
@@ -314,7 +325,8 @@ static int ext2fs_read_block (ext2fs_node_t node, int fileblock) {
                        indir1_block = NULL;
                        indir1_size = 0;
                        indir1_blkno = -1;
-                       indir1_block = (uint32_t *) malloc (blksz);
+                       indir1_block = (uint32_t *) memalign(ARCH_DMA_MINALIGN,
+                                                            blksz);
                        if (indir1_block == NULL) {
                                printf ("** ext2fs read block (indir 2 1) malloc failed. **\n");
                                return (-1);
@@ -335,7 +347,8 @@ static int ext2fs_read_block (ext2fs_node_t node, int fileblock) {
                }
 
                if (indir2_block == NULL) {
-                       indir2_block = (uint32_t *) malloc (blksz);
+                       indir2_block = (uint32_t *) memalign(ARCH_DMA_MINALIGN,
+                                                            blksz);
                        if (indir2_block == NULL) {
                                printf ("** ext2fs read block (indir 2 2) malloc failed. **\n");
                                return (-1);
@@ -348,7 +361,8 @@ static int ext2fs_read_block (ext2fs_node_t node, int fileblock) {
                        indir2_block = NULL;
                        indir2_size = 0;
                        indir2_blkno = -1;
-                       indir2_block = (uint32_t *) malloc (blksz);
+                       indir2_block = (uint32_t *) memalign(ARCH_DMA_MINALIGN,
+                                                            blksz);
                        if (indir2_block == NULL) {
                                printf ("** ext2fs read block (indir 2 2) malloc failed. **\n");
                                return (-1);
@@ -356,7 +370,7 @@ static int ext2fs_read_block (ext2fs_node_t node, int fileblock) {
                        indir2_size = blksz;
                }
                if ((__le32_to_cpu (indir1_block[rblock / perblock]) <<
-                    log2_blksz) != indir1_blkno) {
+                    log2_blksz) != indir2_blkno) {
                        status = ext2fs_devread (__le32_to_cpu(indir1_block[rblock / perblock]) << log2_blksz,
                                                 0, blksz,
                                                 (char *) indir2_block);
@@ -741,7 +755,7 @@ int ext2fs_find_file
 }
 
 
-int ext2fs_ls (char *dirname) {
+int ext2fs_ls (const char *dirname) {
        ext2fs_node_t dirnode;
        int status;
 
@@ -761,7 +775,7 @@ int ext2fs_ls (char *dirname) {
 }
 
 
-int ext2fs_open (char *filename) {
+int ext2fs_open (const char *filename) {
        ext2fs_node_t fdiro = NULL;
        int status;
        int len;
@@ -852,6 +866,15 @@ int ext2fs_mount (unsigned part_length) {
        if (__le16_to_cpu (data->sblock.magic) != EXT2_MAGIC) {
                goto fail;
        }
+       if (__le32_to_cpu(data->sblock.revision_level == 0)) {
+               inode_size = 128;
+       } else {
+               inode_size = __le16_to_cpu(data->sblock.inode_size);
+       }
+#ifdef DEBUG
+       printf("EXT2 rev %d, inode_size %d\n",
+                       __le32_to_cpu(data->sblock.revision_level), inode_size);
+#endif
        data->diropen.data = data;
        data->diropen.ino = 2;
        data->diropen.inode_read = 1;