From 109ccc774dd58205c3eba6e589da38879d95a401 Mon Sep 17 00:00:00 2001 From: Gregory Nutt Date: Mon, 22 Sep 2014 09:33:58 -0600 Subject: [PATCH] SMART FS update from Ken Pettit --- fs/smartfs/smartfs_smart.c | 54 +++++++++++++++++++++----------------- 1 file changed, 30 insertions(+), 24 deletions(-) diff --git a/fs/smartfs/smartfs_smart.c b/fs/smartfs/smartfs_smart.c index d58c0f0e5e..f221b49f67 100644 --- a/fs/smartfs/smartfs_smart.c +++ b/fs/smartfs/smartfs_smart.c @@ -710,20 +710,23 @@ static ssize_t smartfs_write(FAR struct file *filep, const char *buffer, /* Now perform the write. */ - ret = FS_IOCTL(fs, BIOC_WRITESECT, (unsigned long) &readwrite); - if (ret < 0) + if (readwrite.count > 0) { - fdbg("Error %d writing sector %d data\n", ret, sf->currsector); - goto errout_with_semaphore; + ret = FS_IOCTL(fs, BIOC_WRITESECT, (unsigned long) &readwrite); + if (ret < 0) + { + fdbg("Error %d writing sector %d data\n", ret, sf->currsector); + goto errout_with_semaphore; + } + + /* Update our control variables */ + + sf->filepos += readwrite.count; + sf->curroffset += readwrite.count; + buflen -= readwrite.count; + byteswritten += readwrite.count; } - /* Update our control variables */ - - sf->filepos += readwrite.count; - sf->curroffset += readwrite.count; - buflen -= readwrite.count; - byteswritten += readwrite.count; - /* Test if we wrote to the end of the current sector */ if (sf->curroffset == fs->fs_llformat.availbytes) @@ -771,22 +774,25 @@ static ssize_t smartfs_write(FAR struct file *filep, const char *buffer, /* Perform the write */ - ret = FS_IOCTL(fs, BIOC_WRITESECT, (unsigned long) &readwrite); - if (ret < 0) + if (readwrite.count > 0) { - fdbg("Error %d writing sector %d data\n", ret, sf->currsector); - goto errout_with_semaphore; + ret = FS_IOCTL(fs, BIOC_WRITESECT, (unsigned long) &readwrite); + if (ret < 0) + { + fdbg("Error %d writing sector %d data\n", ret, sf->currsector); + goto errout_with_semaphore; + } + + /* Update our control variables */ + + sf->entry.datlen += readwrite.count; + sf->byteswritten += readwrite.count; + sf->filepos += readwrite.count; + sf->curroffset += readwrite.count; + buflen -= readwrite.count; + byteswritten += readwrite.count; } - /* Update our control variables */ - - sf->entry.datlen += readwrite.count; - sf->byteswritten += readwrite.count; - sf->filepos += readwrite.count; - sf->curroffset += readwrite.count; - buflen -= readwrite.count; - byteswritten += readwrite.count; - /* Test if we wrote a full sector of data */ if (sf->curroffset == fs->fs_llformat.availbytes)