2008-01-07 09:09:04 +01:00
|
|
|
/*****************************************************************************
|
|
|
|
* Author: Valient Gough <vgough@pobox.com>
|
|
|
|
*
|
|
|
|
*****************************************************************************
|
|
|
|
* Copyright (c) 2007, Valient Gough
|
2012-10-03 07:12:17 +02:00
|
|
|
*
|
|
|
|
* This program is free software: you can redistribute it and/or modify it
|
|
|
|
* under the terms of the GNU Lesser General Public License as published by the
|
|
|
|
* Free Software Foundation, either version 3 of the License, or (at your
|
|
|
|
* option) any later version.
|
2008-01-07 09:09:04 +01:00
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful, but WITHOUT
|
|
|
|
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
2012-10-03 07:12:17 +02:00
|
|
|
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License
|
|
|
|
* for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU Lesser General Public License
|
|
|
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
2008-01-07 09:09:04 +01:00
|
|
|
*/
|
|
|
|
|
|
|
|
#ifndef _Context_incl_
|
|
|
|
#define _Context_incl_
|
|
|
|
|
2013-01-29 04:07:54 +01:00
|
|
|
#include "base/shared_ptr.h"
|
|
|
|
#include "fs/encfs.h"
|
2008-01-07 09:09:04 +01:00
|
|
|
#include <set>
|
|
|
|
|
2013-01-29 04:07:54 +01:00
|
|
|
#ifdef HAVE_TR1_UNORDERED_MAP
|
2012-08-22 06:46:36 +02:00
|
|
|
#include <tr1/unordered_map>
|
|
|
|
using std::tr1::unordered_map;
|
2008-01-07 09:09:04 +01:00
|
|
|
#else
|
2012-08-22 06:46:36 +02:00
|
|
|
#include <unordered_map>
|
|
|
|
using std::unordered_map;
|
2008-01-07 09:09:04 +01:00
|
|
|
#endif
|
|
|
|
|
|
|
|
struct EncFS_Args;
|
|
|
|
struct EncFS_Opts;
|
2010-08-30 08:32:05 +02:00
|
|
|
class FileNode;
|
|
|
|
class DirNode;
|
2008-01-07 09:09:04 +01:00
|
|
|
|
|
|
|
class EncFS_Context
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
EncFS_Context();
|
|
|
|
~EncFS_Context();
|
|
|
|
|
|
|
|
shared_ptr<FileNode> getNode(void *ptr);
|
|
|
|
shared_ptr<FileNode> lookupNode(const char *path);
|
|
|
|
|
|
|
|
int getAndResetUsageCounter();
|
|
|
|
int openFileCount() const;
|
|
|
|
|
|
|
|
void *putNode(const char *path, const shared_ptr<FileNode> &node);
|
|
|
|
|
|
|
|
void eraseNode(const char *path, void *placeholder);
|
|
|
|
|
|
|
|
void renameNode(const char *oldName, const char *newName);
|
|
|
|
|
|
|
|
void setRoot(const shared_ptr<DirNode> &root);
|
|
|
|
shared_ptr<DirNode> getRoot(int *err);
|
|
|
|
bool isMounted();
|
|
|
|
|
|
|
|
shared_ptr<EncFS_Args> args;
|
|
|
|
shared_ptr<EncFS_Opts> opts;
|
|
|
|
bool publicFilesystem;
|
|
|
|
|
|
|
|
// root path to cipher dir
|
|
|
|
std::string rootCipherDir;
|
|
|
|
|
|
|
|
// for idle monitor
|
|
|
|
bool running;
|
|
|
|
pthread_t monitorThread;
|
|
|
|
pthread_cond_t wakeupCond;
|
|
|
|
pthread_mutex_t wakeupMutex;
|
|
|
|
|
|
|
|
private:
|
|
|
|
/* This placeholder is what is referenced in FUSE context (passed to
|
|
|
|
* callbacks).
|
|
|
|
*
|
|
|
|
* A FileNode may be opened many times, but only one FileNode instance per
|
|
|
|
* file is kept. Rather then doing reference counting in FileNode, we
|
|
|
|
* store a unique Placeholder for each open() until the corresponding
|
|
|
|
* release() is called. shared_ptr then does our reference counting for
|
|
|
|
* us.
|
|
|
|
*/
|
|
|
|
struct Placeholder
|
|
|
|
{
|
|
|
|
shared_ptr<FileNode> node;
|
|
|
|
|
|
|
|
Placeholder( const shared_ptr<FileNode> &ptr ) : node(ptr) {}
|
|
|
|
};
|
|
|
|
|
|
|
|
// set of open files, indexed by path
|
2012-08-22 06:46:36 +02:00
|
|
|
typedef unordered_map<std::string, std::set<Placeholder*> > FileMap;
|
2008-01-07 09:09:04 +01:00
|
|
|
mutable pthread_mutex_t contextMutex;
|
2012-08-22 06:46:36 +02:00
|
|
|
|
2008-01-07 09:09:04 +01:00
|
|
|
FileMap openFiles;
|
|
|
|
|
|
|
|
int usageCount;
|
|
|
|
shared_ptr<DirNode> root;
|
|
|
|
};
|
|
|
|
|
|
|
|
int remountFS( EncFS_Context *ctx );
|
|
|
|
|
|
|
|
#endif
|
|
|
|
|