"Fossies" - the Fresh Open Source Software Archive

Member "encfs-1.9.5/encfs/Context.h" (27 Apr 2018, 3032 Bytes) of package /linux/misc/encfs-1.9.5.tar.gz:


As a special service "Fossies" has tried to format the requested source page into HTML format using (guessed) C and C++ source code syntax highlighting (style: standard) with prefixed line numbers and code folding option. Alternatively you can here view or download the uninterpreted source code file. For more information about "Context.h" see the Fossies "Dox" file reference documentation and the latest Fossies "Diffs" side-by-side code changes report: 1.9.4_vs_1.9.5.

    1 /*****************************************************************************
    2  * Author:   Valient Gough <vgough@pobox.com>
    3  *
    4  *****************************************************************************
    5  * Copyright (c) 2007, Valient Gough
    6  *
    7  * This program is free software: you can redistribute it and/or modify it
    8  * under the terms of the GNU Lesser General Public License as published by the
    9  * Free Software Foundation, either version 3 of the License, or (at your
   10  * option) any later version.
   11  *
   12  * This program is distributed in the hope that it will be useful, but WITHOUT
   13  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
   14  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU Lesser General Public License
   15  * for more details.
   16  *
   17  * You should have received a copy of the GNU Lesser General Public License
   18  * along with this program.  If not, see <http://www.gnu.org/licenses/>.
   19  */
   20 
   21 #ifndef _Context_incl_
   22 #define _Context_incl_
   23 
   24 #include <algorithm>
   25 #include <atomic>
   26 #include <list>
   27 #include <memory>
   28 #include <pthread.h>
   29 #include <set>
   30 #include <string>
   31 #include <unordered_map>
   32 
   33 #include "encfs.h"
   34 
   35 namespace encfs {
   36 
   37 class DirNode;
   38 class FileNode;
   39 struct EncFS_Args;
   40 struct EncFS_Opts;
   41 
   42 class EncFS_Context {
   43  public:
   44   EncFS_Context();
   45   ~EncFS_Context();
   46 
   47   std::shared_ptr<FileNode> lookupNode(const char *path);
   48 
   49   bool usageAndUnmount(int timeoutCycles);
   50 
   51   void putNode(const char *path, const std::shared_ptr<FileNode> &node);
   52 
   53   void eraseNode(const char *path, const std::shared_ptr<FileNode> &fnode);
   54 
   55   void renameNode(const char *oldName, const char *newName);
   56 
   57   void setRoot(const std::shared_ptr<DirNode> &root);
   58   std::shared_ptr<DirNode> getRoot(int *err);
   59   std::shared_ptr<DirNode> getRoot(int *err, bool skipUsageCount);
   60 
   61   std::shared_ptr<EncFS_Args> args;
   62   std::shared_ptr<EncFS_Opts> opts;
   63   bool publicFilesystem;
   64 
   65   // root path to cipher dir
   66   std::string rootCipherDir;
   67 
   68   // for idle monitor
   69   bool running;
   70   pthread_t monitorThread;
   71   pthread_cond_t wakeupCond;
   72   pthread_mutex_t wakeupMutex;
   73 
   74   uint64_t nextFuseFh();
   75   std::shared_ptr<FileNode> lookupFuseFh(uint64_t);
   76 
   77  private:
   78   /* This placeholder is what is referenced in FUSE context (passed to
   79    * callbacks).
   80    *
   81    * A FileNode may be opened many times, but only one FileNode instance per
   82    * file is kept.  Rather then doing reference counting in FileNode, we
   83    * store a unique Placeholder for each open() until the corresponding
   84    * release() is called.  std::shared_ptr then does our reference counting for
   85    * us.
   86    */
   87 
   88   using FileMap =
   89       std::unordered_map<std::string, std::list<std::shared_ptr<FileNode>>>;
   90 
   91   mutable pthread_mutex_t contextMutex;
   92   FileMap openFiles;
   93 
   94   int usageCount;
   95   int idleCount;
   96   bool isUnmounting;
   97   std::shared_ptr<DirNode> root;
   98 
   99   std::atomic<std::uint64_t> currentFuseFh;
  100   std::unordered_map<uint64_t, std::shared_ptr<FileNode>> fuseFhMap;
  101 };
  102 
  103 int remountFS(EncFS_Context *ctx);
  104 bool unmountFS(EncFS_Context *ctx);
  105 
  106 }  // namespace encfs
  107 
  108 #endif