From 915aa03c77e7478d59b229df894685c304b9aaab Mon Sep 17 00:00:00 2001 From: Sascha Hauer Date: Thu, 30 Jul 2009 16:10:20 +0200 Subject: 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 --- fs/fs.c | 12 +++++++++--- 1 file 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); -- cgit v1.2.3