diff options
author | Sascha Hauer <s.hauer@pengutronix.de> | 2014-02-26 09:02:15 +0100 |
---|---|---|
committer | Sascha Hauer <s.hauer@pengutronix.de> | 2014-02-26 09:36:18 +0100 |
commit | 0b1d85af1889652cecba0588bf69c4df447258e0 (patch) | |
tree | 9bc8cab2c14b72bdb6da2e4b29723f7c8c63408f /fs | |
parent | 3df00bd62dc7534aea831ca6b417388728b3383d (diff) | |
download | barebox-0b1d85af1889652cecba0588bf69c4df447258e0.tar.gz barebox-0b1d85af1889652cecba0588bf69c4df447258e0.tar.xz |
fs: tftp: Fix writing files to tftp
Copying files to tftp is broken since:
| commit d4f5bb1e011ac653a167031554f0ac9e028e9e36
| Author: Sascha Hauer <s.hauer@pengutronix.de>
| Date: Sat Sep 28 13:12:50 2013 +0200
|
| copy_file: Add missing O_TRUNC
|
| Without it, when copying a smaller file over a larger file the
| resulting file still has the remaining space from the larger file.
|
| Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
Since this commit copy_file passes O_TRUNC to open(). This results in the
fs layer calling fsdrv->truncate. tftp returns -ENOSYS here and open returns
with an error. To fix this return 0 for the truncate callback in tftp. Also
enforce the O_TRUNC flag when opening a file for writing on tftp as the files
are always truncated on tftp anyway.
Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
Reported-by: andreas.willig@rafi.de
Diffstat (limited to 'fs')
-rw-r--r-- | fs/tftp.c | 10 |
1 files changed, 9 insertions, 1 deletions
@@ -110,7 +110,7 @@ static int tftp_rmdir(struct device_d *dev, const char *pathname) static int tftp_truncate(struct device_d *dev, FILE *f, ulong size) { - return -ENOSYS; + return 0; } static int tftp_send(struct file_priv *priv) @@ -393,6 +393,14 @@ static struct file_priv *tftp_do_open(struct device_d *dev, case O_WRONLY: priv->push = 1; priv->state = STATE_WRQ; + if (!(accmode & O_TRUNC)) { + /* + * TFTP always truncates the existing file, so this + * flag is mandatory when opening a file for writing. + */ + ret = -ENOSYS; + goto out; + } break; case O_RDWR: ret = -ENOSYS; |