From 8caea461a7a78cb4709b47eaa8283628208139ea Mon Sep 17 00:00:00 2001 From: Ben RUBSON Date: Sat, 17 Mar 2018 16:18:03 +0100 Subject: [PATCH] Do not count usage on root path (#471) --- encfs/Context.cpp | 11 ++++++++++- encfs/Context.h | 1 + encfs/encfs.cpp | 6 +++++- 3 files changed, 16 insertions(+), 2 deletions(-) diff --git a/encfs/Context.cpp b/encfs/Context.cpp index 60606bd..7ebebaa 100644 --- a/encfs/Context.cpp +++ b/encfs/Context.cpp @@ -47,7 +47,12 @@ EncFS_Context::~EncFS_Context() { // release all entries from map openFiles.clear(); } + std::shared_ptr EncFS_Context::getRoot(int *errCode) { + return getRoot(errCode, false); +} + +std::shared_ptr EncFS_Context::getRoot(int *errCode, bool skipUsageCount) { std::shared_ptr ret = nullptr; do { { @@ -57,7 +62,11 @@ std::shared_ptr EncFS_Context::getRoot(int *errCode) { break; } ret = root; - ++usageCount; + // On some system, stat of "/" is allowed even if the calling user is + // not allowed to list / to go deeper. Do not then count this call. + if (!skipUsageCount) { + ++usageCount; + } } if (!ret) { diff --git a/encfs/Context.h b/encfs/Context.h index 3d84d37..8d48d16 100644 --- a/encfs/Context.h +++ b/encfs/Context.h @@ -56,6 +56,7 @@ class EncFS_Context { void setRoot(const std::shared_ptr &root); std::shared_ptr getRoot(int *err); + std::shared_ptr getRoot(int *err, bool skipUsageCount); std::shared_ptr args; std::shared_ptr opts; diff --git a/encfs/encfs.cpp b/encfs/encfs.cpp index ccbc752..38eec09 100644 --- a/encfs/encfs.cpp +++ b/encfs/encfs.cpp @@ -139,7 +139,11 @@ static int withFileNode(const char *opName, const char *path, EncFS_Context *ctx = context(); int res = -EIO; - std::shared_ptr FSRoot = ctx->getRoot(&res); + bool skipUsageCount = false; + if (strlen(path) == 1) { + skipUsageCount = true; + } + std::shared_ptr FSRoot = ctx->getRoot(&res, skipUsageCount); if (!FSRoot) { return res; }