fs/fat: Fix a bug in the FAT ftruncate logic.

This commit is contained in:
Gregory Nutt 2018-01-05 11:56:39 -06:00
parent 376e30dab4
commit 49775ea801
2 changed files with 14 additions and 2 deletions

View File

@ -303,7 +303,7 @@ static ssize_t rd_write(FAR struct inode *inode, const unsigned char *buffer,
else if (start_sector < dev->rd_nsectors &&
start_sector + nsectors <= dev->rd_nsectors)
{
finfo("Transfer %d bytes from %p\n",
finfo("Transfer %d bytes to %p\n",
nsectors * dev->rd_sectsize,
&dev->rd_buffer[start_sector * dev->rd_sectsize]);

View File

@ -1786,6 +1786,16 @@ static int fat_truncate(FAR struct file *filep, off_t length)
ret = fat_dirshrink(fs, direntry, length);
}
if (ret >= 0)
{
/* The truncation has completed without error. Update the file
* size.
*/
ff->ff_size = length;
ret = OK;
}
}
else
{
@ -1797,7 +1807,9 @@ static int fat_truncate(FAR struct file *filep, off_t length)
ret = fat_dirextend(fs, ff, length);
if (ret >= 0)
{
/* The truncation has completed without error. Update the file size */
/* The truncation has completed without error. Update the file
* size.
*/
ff->ff_size = length;
ret = OK;