Home | History | Annotate | Download | only in fusefs
      1 // Copyright 2013 The Chromium Authors. All rights reserved.
      2 // Use of this source code is governed by a BSD-style license that can be
      3 // found in the LICENSE file.
      4 
      5 #ifndef LIBRARIES_NACL_IO_FUSEFS_FUSE_FS_H_
      6 #define LIBRARIES_NACL_IO_FUSEFS_FUSE_FS_H_
      7 
      8 #include <map>
      9 
     10 #include "nacl_io/filesystem.h"
     11 #include "nacl_io/fuse.h"
     12 #include "nacl_io/node.h"
     13 
     14 namespace nacl_io {
     15 
     16 class FuseFs : public Filesystem {
     17  protected:
     18   FuseFs();
     19 
     20   virtual Error Init(const FsInitArgs& args);
     21   virtual void Destroy();
     22 
     23  public:
     24   virtual Error Access(const Path& path, int a_mode);
     25   virtual Error Open(const Path& path, int mode, ScopedNode* out_node);
     26   virtual Error Unlink(const Path& path);
     27   virtual Error Mkdir(const Path& path, int perm);
     28   virtual Error Rmdir(const Path& path);
     29   virtual Error Remove(const Path& path);
     30   virtual Error Rename(const Path& path, const Path& newpath);
     31 
     32  private:
     33   struct fuse_operations* fuse_ops_;
     34   void* fuse_user_data_;
     35 
     36   friend class FuseFsNode;
     37   friend class FuseFsFactory;
     38   DISALLOW_COPY_AND_ASSIGN(FuseFs);
     39 };
     40 
     41 class FuseFsNode : public Node {
     42  protected:
     43   FuseFsNode(Filesystem* filesystem,
     44              struct fuse_operations* fuse_ops,
     45              struct fuse_file_info& info,
     46              const std::string& path);
     47 
     48  public:
     49   virtual bool CanOpen(int open_flags);
     50   virtual Error GetStat(struct stat* stat);
     51   virtual Error VIoctl(int request, va_list args);
     52   virtual Error Tcflush(int queue_selector);
     53   virtual Error Tcgetattr(struct termios* termios_p);
     54   virtual Error Tcsetattr(int optional_actions,
     55                           const struct termios* termios_p);
     56   virtual Error GetSize(off_t* out_size);
     57 
     58  protected:
     59   struct fuse_operations* fuse_ops_;
     60   struct fuse_file_info info_;
     61   std::string path_;
     62 };
     63 
     64 class FileFuseFsNode : public FuseFsNode {
     65  public:
     66   FileFuseFsNode(Filesystem* filesystem,
     67                  struct fuse_operations* fuse_ops,
     68                  struct fuse_file_info& info,
     69                  const std::string& path);
     70 
     71  protected:
     72   virtual void Destroy();
     73 
     74  public:
     75   virtual Error FSync();
     76   virtual Error FTruncate(off_t length);
     77   virtual Error Read(const HandleAttr& attr,
     78                      void* buf,
     79                      size_t count,
     80                      int* out_bytes);
     81   virtual Error Write(const HandleAttr& attr,
     82                       const void* buf,
     83                       size_t count,
     84                       int* out_bytes);
     85 
     86  private:
     87   friend class FuseFs;
     88   DISALLOW_COPY_AND_ASSIGN(FileFuseFsNode);
     89 };
     90 
     91 class DirFuseFsNode : public FuseFsNode {
     92  public:
     93   DirFuseFsNode(Filesystem* filesystem,
     94                 struct fuse_operations* fuse_ops,
     95                 struct fuse_file_info& info,
     96                 const std::string& path);
     97 
     98  protected:
     99   virtual void Destroy();
    100 
    101  public:
    102   virtual Error FSync();
    103   virtual Error GetDents(size_t offs,
    104                          struct dirent* pdir,
    105                          size_t count,
    106                          int* out_bytes);
    107 
    108  private:
    109   static int FillDirCallback(void* buf,
    110                              const char* name,
    111                              const struct stat* stbuf,
    112                              off_t off);
    113 
    114  private:
    115   friend class FuseFs;
    116   DISALLOW_COPY_AND_ASSIGN(DirFuseFsNode);
    117 };
    118 
    119 }  // namespace nacl_io
    120 
    121 #endif  // LIBRARIES_NACL_IO_FUSEFS_FUSE_FS_H_
    122