The 'len' parameter passed to fs_read() actually denotes the maximum
number of bytes that fit into the callers buffer, not an expected
amount of data to be read.
Rename the parameter accordingly and honor the maxlen requested by the
caller appropriately.
Also remove the bogus warning message printed when the number of bytes
read is smaller than maxlen.
} else if (partnum == 0) {
loff_t len_read;
} else if (partnum == 0) {
loff_t len_read;
- debug("Reading file %s from mmc partition %d\n", part,
- partnum);
+ debug("Trying to read (%u) byte from file '%s' in mmc partition %d\n",
+ len, part, partnum);
ret = fs_read(part, (ulong)addr, 0, len, &len_read);
if (ret < 0) {
ret = fs_read(part, (ulong)addr, 0, len, &len_read);
if (ret < 0) {
- printf("Failed to read %u byte from mmc partition %d\n",
- len, partnum);
+ printf("Failed to read %u byte from %s in mmc partition %d; err: %d\n",
+ len, part, partnum, ret);
- if (len_read < len) {
- printf("Read only %llu of %u bytes\n", (u64)len_read, len);
- }
+ debug("Read %llu bytes from %s\n", len_read, part);
} else {
ret = partnum;
goto out;
} else {
ret = partnum;
goto out;
-int fs_read(const char *filename, ulong addr, loff_t offset, loff_t len,
+int fs_read(const char *filename, ulong addr, loff_t offset, loff_t maxlen,
loff_t *actread)
{
struct fstype_info *info = fs_get_info(fs_type);
void *buf;
int ret;
loff_t *actread)
{
struct fstype_info *info = fs_get_info(fs_type);
void *buf;
int ret;
- /*
- * We don't actually know how many bytes are being read, since len==0
- * means read the whole file.
- */
+ ret = info->size(filename, &len);
+ if (ret) {
+ printf("Failed to determine size of file %s: %d\n",
+ filename, ret);
+ goto err;
+ }
+ if (maxlen == 0)
+ maxlen = len;
+ else if (len > maxlen)
+ printf("** File %s larger than buffer size; truncating to %llu of %llu bytes\n",
+ filename, maxlen, len);
+ len = min(len, maxlen);
buf = map_sysmem(addr, len);
ret = info->read(filename, buf, offset, len, actread);
buf = map_sysmem(addr, len);
ret = info->read(filename, buf, offset, len, actread);
-
- /* If we requested a specific number of bytes, check we got it */
- if (ret == 0 && len && *actread != len)
- printf("** %s shorter than offset + len **\n", filename);