diff options
author | Sascha Hauer <s.hauer@pengutronix.de> | 2009-07-30 16:10:20 +0200 |
---|---|---|
committer | Sascha Hauer <s.hauer@pengutronix.de> | 2009-07-30 16:10:20 +0200 |
commit | 915aa03c77e7478d59b229df894685c304b9aaab (patch) | |
tree | ad19e06e762e9e9b207397d48bcb0fc89ed8c410 | |
parent | 6437a0156ad8001fb5f115e4ff5c29865acba6ed (diff) | |
download | barebox-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.c | 12 |
1 files changed, 9 insertions, 3 deletions
@@ -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); |