Commit 66a47ff2d8f037e1e9d641623257894a9975c325
Committed by
Tom Rini
1 parent
f81db56f2f
Exists in
v2017.01-smarct4x
and in
25 other branches
ext4: Allow reading files with non-zero offset, clamp read len
Support was already implemented, but not hooked up. This fixes several fails in the test cases. Signed-off-by: Stefan Brüns <stefan.bruens@rwth-aachen.de> Acked-by: Stephen Warren <swarren@wwwdotorg.org>
Showing 3 changed files with 11 additions and 16 deletions Side-by-side Diff
common/spl/spl_ext.c
... | ... | @@ -42,7 +42,7 @@ |
42 | 42 | puts("spl: ext4fs_open failed\n"); |
43 | 43 | goto end; |
44 | 44 | } |
45 | - err = ext4fs_read((char *)header, sizeof(struct image_header), &actlen); | |
45 | + err = ext4fs_read((char *)header, 0, sizeof(struct image_header), &actlen); | |
46 | 46 | if (err < 0) { |
47 | 47 | puts("spl: ext4fs_read failed\n"); |
48 | 48 | goto end; |
... | ... | @@ -54,7 +54,7 @@ |
54 | 54 | goto end; |
55 | 55 | } |
56 | 56 | |
57 | - err = ext4fs_read((char *)spl_image->load_addr, filelen, &actlen); | |
57 | + err = ext4fs_read((char *)spl_image->load_addr, 0, filelen, &actlen); | |
58 | 58 | |
59 | 59 | end: |
60 | 60 | #ifdef CONFIG_SPL_LIBCOMMON_SUPPORT |
... | ... | @@ -97,7 +97,7 @@ |
97 | 97 | puts("spl: ext4fs_open failed\n"); |
98 | 98 | goto defaults; |
99 | 99 | } |
100 | - err = ext4fs_read((void *)CONFIG_SYS_SPL_ARGS_ADDR, filelen, &actlen); | |
100 | + err = ext4fs_read((void *)CONFIG_SYS_SPL_ARGS_ADDR, 0, filelen, &actlen); | |
101 | 101 | if (err < 0) { |
102 | 102 | printf("spl: error reading image %s, err - %d, falling back to default\n", |
103 | 103 | file, err); |
... | ... | @@ -127,7 +127,7 @@ |
127 | 127 | if (err < 0) |
128 | 128 | puts("spl: ext4fs_open failed\n"); |
129 | 129 | |
130 | - err = ext4fs_read((void *)CONFIG_SYS_SPL_ARGS_ADDR, filelen, &actlen); | |
130 | + err = ext4fs_read((void *)CONFIG_SYS_SPL_ARGS_ADDR, 0, filelen, &actlen); | |
131 | 131 | if (err < 0) { |
132 | 132 | #ifdef CONFIG_SPL_LIBCOMMON_SUPPORT |
133 | 133 | printf("%s: error reading image %s, err - %d\n", |
fs/ext4/ext4fs.c
... | ... | @@ -65,8 +65,8 @@ |
65 | 65 | short status; |
66 | 66 | |
67 | 67 | /* Adjust len so it we can't read past the end of the file. */ |
68 | - if (len > filesize) | |
69 | - len = filesize; | |
68 | + if (len + pos > filesize) | |
69 | + len = (filesize - pos); | |
70 | 70 | |
71 | 71 | blockcnt = lldiv(((len + pos) + blocksize - 1), blocksize); |
72 | 72 | |
73 | 73 | |
74 | 74 | |
... | ... | @@ -190,12 +190,12 @@ |
190 | 190 | return ext4fs_open(filename, size); |
191 | 191 | } |
192 | 192 | |
193 | -int ext4fs_read(char *buf, loff_t len, loff_t *actread) | |
193 | +int ext4fs_read(char *buf, loff_t offset, loff_t len, loff_t *actread) | |
194 | 194 | { |
195 | 195 | if (ext4fs_root == NULL || ext4fs_file == NULL) |
196 | - return 0; | |
196 | + return -1; | |
197 | 197 | |
198 | - return ext4fs_read_file(ext4fs_file, 0, len, buf, actread); | |
198 | + return ext4fs_read_file(ext4fs_file, offset, len, buf, actread); | |
199 | 199 | } |
200 | 200 | |
201 | 201 | int ext4fs_probe(struct blk_desc *fs_dev_desc, |
... | ... | @@ -217,11 +217,6 @@ |
217 | 217 | loff_t file_len; |
218 | 218 | int ret; |
219 | 219 | |
220 | - if (offset != 0) { | |
221 | - printf("** Cannot support non-zero offset **\n"); | |
222 | - return -1; | |
223 | - } | |
224 | - | |
225 | 220 | ret = ext4fs_open(filename, &file_len); |
226 | 221 | if (ret < 0) { |
227 | 222 | printf("** File not found %s **\n", filename); |
... | ... | @@ -231,7 +226,7 @@ |
231 | 226 | if (len == 0) |
232 | 227 | len = file_len; |
233 | 228 | |
234 | - return ext4fs_read(buf, len, len_read); | |
229 | + return ext4fs_read(buf, offset, len, len_read); | |
235 | 230 | } |
236 | 231 | |
237 | 232 | int ext4fs_uuid(char *uuid_str) |
include/ext4fs.h
... | ... | @@ -135,7 +135,7 @@ |
135 | 135 | |
136 | 136 | struct ext_filesystem *get_fs(void); |
137 | 137 | int ext4fs_open(const char *filename, loff_t *len); |
138 | -int ext4fs_read(char *buf, loff_t len, loff_t *actread); | |
138 | +int ext4fs_read(char *buf, loff_t offset, loff_t len, loff_t *actread); | |
139 | 139 | int ext4fs_mount(unsigned part_length); |
140 | 140 | void ext4fs_close(void); |
141 | 141 | void ext4fs_reinit_global(void); |