[PATCH 1/7] fs: implement ftruncate
Sascha Hauer
s.hauer at pengutronix.de
Wed Jan 10 23:50:06 PST 2018
Signed-off-by: Sascha Hauer <s.hauer at pengutronix.de>
---
fs/fs.c | 22 ++++++++++++++++++++++
include/unistd.h | 1 +
2 files changed, 23 insertions(+)
diff --git a/fs/fs.c b/fs/fs.c
index f61ee091b5..051af8d19f 100644
--- a/fs/fs.c
+++ b/fs/fs.c
@@ -742,6 +742,28 @@ int creat(const char *pathname, mode_t mode)
}
EXPORT_SYMBOL(creat);
+int ftruncate(int fd, loff_t length)
+{
+ struct fs_driver_d *fsdrv;
+ FILE *f;
+ int ret;
+
+ if (check_fd(fd))
+ return -errno;
+
+ f = &files[fd];
+
+ fsdrv = f->fsdev->driver;
+
+ ret = fsdrv->truncate(&f->fsdev->dev, f, length);
+ if (ret)
+ return ret;
+
+ f->size = length;
+
+ return 0;
+}
+
int ioctl(int fd, int request, void *buf)
{
struct fs_driver_d *fsdrv;
diff --git a/include/unistd.h b/include/unistd.h
index 31f430a5b6..f392e6dd6c 100644
--- a/include/unistd.h
+++ b/include/unistd.h
@@ -20,5 +20,6 @@ int symlink(const char *pathname, const char *newpath);
int readlink(const char *path, char *buf, size_t bufsiz);
int chdir(const char *pathname);
const char *getcwd(void);
+int ftruncate(int fd, loff_t length);
#endif /* __UNISTD_H */
--
2.11.0
More information about the barebox
mailing list