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; }