]> Git Repo - J-u-boot.git/blobdiff - fs/ext4/ext4fs.c
dm: core: Create a new header file for 'compat' features
[J-u-boot.git] / fs / ext4 / ext4fs.c
index 26db677a1f172bde1f10ac5297bf7226b6f6ba15..1c616a26a272ba7c15736b317bbd9f50a2524dbe 100644 (file)
@@ -25,6 +25,7 @@
 #include <ext4fs.h>
 #include "ext4_common.h"
 #include <div64.h>
 #include <ext4fs.h>
 #include "ext4_common.h"
 #include <div64.h>
+#include <malloc.h>
 
 int ext4fs_symlinknest;
 struct ext_filesystem ext_fs;
 
 int ext4fs_symlinknest;
 struct ext_filesystem ext_fs;
@@ -61,18 +62,21 @@ int ext4fs_read_file(struct ext2fs_node *node, loff_t pos,
        lbaint_t delayed_skipfirst = 0;
        lbaint_t delayed_next = 0;
        char *delayed_buf = NULL;
        lbaint_t delayed_skipfirst = 0;
        lbaint_t delayed_next = 0;
        char *delayed_buf = NULL;
+       char *start_buf = buf;
        short status;
        struct ext_block_cache cache;
 
        ext_cache_init(&cache);
 
        short status;
        struct ext_block_cache cache;
 
        ext_cache_init(&cache);
 
-       if (blocksize <= 0)
-               return -1;
-
        /* Adjust len so it we can't read past the end of the file. */
        if (len + pos > filesize)
                len = (filesize - pos);
 
        /* Adjust len so it we can't read past the end of the file. */
        if (len + pos > filesize)
                len = (filesize - pos);
 
+       if (blocksize <= 0 || len <= 0) {
+               ext_cache_fini(&cache);
+               return -1;
+       }
+
        blockcnt = lldiv(((len + pos) + blocksize - 1), blocksize);
 
        for (i = lldiv(pos, blocksize); i < blockcnt; i++) {
        blockcnt = lldiv(((len + pos) + blocksize - 1), blocksize);
 
        for (i = lldiv(pos, blocksize); i < blockcnt; i++) {
@@ -137,6 +141,7 @@ int ext4fs_read_file(struct ext2fs_node *node, loff_t pos,
                        }
                } else {
                        int n;
                        }
                } else {
                        int n;
+                       int n_left;
                        if (previous_block_number != -1) {
                                /* spill */
                                status = ext4fs_devread(delayed_start,
                        if (previous_block_number != -1) {
                                /* spill */
                                status = ext4fs_devread(delayed_start,
@@ -151,8 +156,9 @@ int ext4fs_read_file(struct ext2fs_node *node, loff_t pos,
                        }
                        /* Zero no more than `len' bytes. */
                        n = blocksize - skipfirst;
                        }
                        /* Zero no more than `len' bytes. */
                        n = blocksize - skipfirst;
-                       if (n > len)
-                               n = len;
+                       n_left = len - ( buf - start_buf );
+                       if (n > n_left)
+                               n = n_left;
                        memset(buf, 0, n);
                }
                buf += blocksize - skipfirst;
                        memset(buf, 0, n);
                }
                buf += blocksize - skipfirst;
@@ -286,7 +292,7 @@ int ext_cache_read(struct ext_block_cache *cache, lbaint_t block, int size)
        if (!cache->buf)
                return 0;
        if (!ext4fs_devread(block, 0, size, cache->buf)) {
        if (!cache->buf)
                return 0;
        if (!ext4fs_devread(block, 0, size, cache->buf)) {
-               free(cache->buf);
+               ext_cache_fini(cache);
                return 0;
        }
        cache->block = block;
                return 0;
        }
        cache->block = block;
This page took 0.027044 seconds and 4 git commands to generate.