From a7ab34ebbce60f2af159f9010a2e3629756af3d1 Mon Sep 17 00:00:00 2001 From: human Date: Thu, 7 Jan 2021 16:31:52 +0200 Subject: fix truncating in defineFile() - in the C part: enable FUSE_CAP_ATOMIC_O_TRUNC so that open() will get called with O_TRUNC in flags instead of truncate() being called separately - this also prevents truncate() from calling setData() with an empty string when a file is opened with O_TRUNC - in defineFile()->open(): if O_TRUNC is used, don't call getData() but start with an empty file as if it had just been truncated - in defineFile()->write()/truncate(): correct buffer resizing/copying --- fs/tabfs.c | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) (limited to 'fs') diff --git a/fs/tabfs.c b/fs/tabfs.c index 8c28dab..0eab91c 100644 --- a/fs/tabfs.c +++ b/fs/tabfs.c @@ -423,6 +423,20 @@ static int tabfs_create(const char *path, mode_t mode, struct fuse_file_info *fi return 0; } +#define want_capability(conn, flag) \ + do { \ + if (conn->capable & flag) { \ + conn->want |= flag; \ + } else { \ + eprintln("warning: " #flag " not supported"); \ + } \ + } while (0) + +static void *tabfs_init(struct fuse_conn_info *conn) { + want_capability(conn, FUSE_CAP_ATOMIC_O_TRUNC); + return NULL; +} + static const struct fuse_operations tabfs_oper = { .getattr = tabfs_getattr, .readlink = tabfs_readlink, @@ -441,6 +455,8 @@ static const struct fuse_operations tabfs_oper = { .mkdir = tabfs_mkdir, .create = tabfs_create, + + .init = tabfs_init, }; int main(int argc, char **argv) { -- cgit v1.2.3