From 9c0e3a7b4e97d30844ab8efbadd9ad7e9fefc82b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jean-Pierre=20Andr=C3=A9?= Date: Tue, 26 Oct 2010 08:59:51 +0200 Subject: [PATCH] Enabled use of fuse cacheing in lowntfs-3g under conditions --- include/ntfs-3g/param.h | 9 +++++++-- src/lowntfs-3g.c | 36 ++++++++++++++++++++++++++++++------ 2 files changed, 37 insertions(+), 8 deletions(-) diff --git a/include/ntfs-3g/param.h b/include/ntfs-3g/param.h index f21bd653..9edb9642 100644 --- a/include/ntfs-3g/param.h +++ b/include/ntfs-3g/param.h @@ -58,7 +58,8 @@ enum { * * Stick to the recommended values unless you understand the consequences * on protection and performances. Use of cacheing is good for - * performances, but bad on security. + * performances, but bad on security with internal fuse or external + * fuse older than 2.8 * * Possible values for high level : * 1 : no cache, kernel control (recommended) @@ -67,7 +68,7 @@ enum { * * Possible values for low level : * 2 : no cache, kernel control - * 3 : use kernel/fuse cache, kernel control + * 3 : use kernel/fuse cache, kernel control (external fuse >= 2.8) * 5 : no cache, file system control (recommended) * 8 : no cache, kernel control for ACLs * @@ -77,6 +78,10 @@ enum { */ #define HPERMSCONFIG 1 +#if defined(FUSE_INTERNAL) || !defined(FUSE_VERSION) || (FUSE_VERSION < 28) #define LPERMSCONFIG 5 +#else +#define LPERMSCONFIG 3 +#endif #endif /* defined _NTFS_PARAM_H */ diff --git a/src/lowntfs-3g.c b/src/lowntfs-3g.c index 17105c73..6c580421 100644 --- a/src/lowntfs-3g.c +++ b/src/lowntfs-3g.c @@ -122,18 +122,17 @@ #endif #if CACHEING & (KERNELACLS | !KERNELPERMS) -#warning "Fuse cacheing is broken unless basic permissions checked by kernel" +#warning "Fuse cacheing is only usable with basic permissions checked by kernel" #endif #if !CACHEING - /* - * FUSE cacheing is broken except for basic permissions - * checked by the kernel - * So do not use cacheing until this is fixed - */ #define ATTR_TIMEOUT 0.0 #define ENTRY_TIMEOUT 0.0 #else + /* + * FUSE cacheing is only usable with basic permissions + * checked by the kernel with external fuse >= 2.8 + */ #define ATTR_TIMEOUT (ctx->vol->secure_flags & (1 << SECURITY_DEFAULT) ? 1.0 : 0.0) #define ENTRY_TIMEOUT (ctx->vol->secure_flags & (1 << SECURITY_DEFAULT) ? 1.0 : 0.0) #endif @@ -3028,6 +3027,18 @@ static void ntfs_fuse_setxattr(fuse_req_t req, fuse_ino_t ino, const char *name, set_fuse_error(&res); } else res = -errno; +#endif +#if CACHEING && !defined(FUSE_INTERNAL) + /* + * Most of system xattr settings cause changes to some + * file attribute (st_mode, st_nlink, st_mtime, etc.), + * so we must invalidate cached data when cacheing is + * in use (not possible with internal fuse or external + * fuse before 2.8) + */ + if ((res >= 0) + && fuse_lowlevel_notify_inval_inode(ctx->fc, ino, -1, 0)) + res = -errno; #endif if (res < 0) fuse_reply_err(req, -res); @@ -3231,6 +3242,19 @@ static void ntfs_fuse_removexattr(fuse_req_t req, fuse_ino_t ino, const char *na set_fuse_error(&res); } else res = -errno; +#endif +#if CACHEING && !defined(FUSE_INTERNAL) + /* + * Some allowed system xattr removals cause changes to + * some file attribute (st_mode, st_nlink, etc.), + * so we must invalidate cached data when cacheing is + * in use (not possible with internal fuse or external + * fuse before 2.8) + */ + if ((res >= 0) + && fuse_lowlevel_notify_inval_inode(ctx->fc, + ino, -1, 0)) + res = -errno; #endif break; }