From 49775ea801da737dc811c46d4fd09727ba68ca82 Mon Sep 17 00:00:00 2001 From: Gregory Nutt Date: Fri, 5 Jan 2018 11:56:39 -0600 Subject: [PATCH] fs/fat: Fix a bug in the FAT ftruncate logic. --- drivers/ramdisk.c | 2 +- fs/fat/fs_fat32.c | 14 +++++++++++++- 2 files changed, 14 insertions(+), 2 deletions(-) diff --git a/drivers/ramdisk.c b/drivers/ramdisk.c index 4473a41ad1d..b31e1f0dd9d 100644 --- a/drivers/ramdisk.c +++ b/drivers/ramdisk.c @@ -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]); diff --git a/fs/fat/fs_fat32.c b/fs/fat/fs_fat32.c index aa165accfa6..e3ad8b166c0 100644 --- a/fs/fat/fs_fat32.c +++ b/fs/fat/fs_fat32.c @@ -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;