summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorSascha Hauer <s.hauer@pengutronix.de>2009-07-30 16:10:20 +0200
committerSascha Hauer <s.hauer@pengutronix.de>2009-07-30 16:10:20 +0200
commit915aa03c77e7478d59b229df894685c304b9aaab (patch)
treead19e06e762e9e9b207397d48bcb0fc89ed8c410
parent6437a0156ad8001fb5f115e4ff5c29865acba6ed (diff)
downloadbarebox-915aa03c77e7478d59b229df894685c304b9aaab.tar.gz
barebox-915aa03c77e7478d59b229df894685c304b9aaab.tar.xz
fs: write: fix writing on devices
We can't truncate device files. Make sure that if we want to write beyond the device that the bytes that still fit into the device get written. Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
-rw-r--r--fs/fs.c12
1 files changed, 9 insertions, 3 deletions
diff --git a/fs/fs.c b/fs/fs.c
index 148e3a35cb..7c1f18ebae 100644
--- a/fs/fs.c
+++ b/fs/fs.c
@@ -499,9 +499,15 @@ ssize_t write(int fd, const void *buf, size_t count)
fsdrv = (struct fs_driver_d *)dev->driver->type_data;
if (f->pos + count > f->size) {
errno = fsdrv->truncate(dev, f, f->pos + count);
- if (errno)
- return errno;
- f->size = f->pos + count;
+ if (errno) {
+ if (errno != -ENOSPC)
+ return errno;
+ count = f->size - f->pos;
+ if (!count)
+ return errno;
+ } else {
+ f->size = f->pos + count;
+ }
}
errno = fsdrv->write(dev, f, buf, count);