unsigned int wanted, unsigned int *got)
{
ext2_filsys fs;
- errcode_t retval;
+ errcode_t retval = 0;
unsigned int count = 0;
+ uint64_t isize = EXT2_I_SIZE(&file->inode);
size_t size;
+ if (file->pos >= isize)
+ goto out;
+
fs = file->fs;
retval = ext2fs_inline_data_get(fs, file->ino, &file->inode,
file->buf, &size);
if (retval)
return retval;
- if (file->pos >= size)
- goto out;
+ /*
+ * size is the number of bytes available for inline data storage, which
+ * means it can exceed isize.
+ */
+ if (size > isize)
+ size = isize;
count = size - file->pos;
if (count > wanted)
file->pos += count;
buf = (char *) buf + count;
+ /* zero-fill the rest of the buffer */
+ wanted -= count;
+ if (wanted > 0) {
+ memset(buf, 0, wanted);
+ file->pos += wanted;
+ count += wanted;
+ }
+
out:
if (got)
*got = count;