Home | History | Annotate | Download | only in nacl_io
      1 // Copyright (c) 2012 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_MOUNT_FUSE_H_
      6 #define LIBRARIES_NACL_IO_MOUNT_FUSE_H_
      7 
      8 #include <map>
      9 
     10 #include "nacl_io/fuse.h"
     11 #include "nacl_io/mount.h"
     12 #include "nacl_io/mount_node.h"
     13 #include "nacl_io/typed_mount_factory.h"
     14 
     15 namespace nacl_io {
     16 
     17 class MountFuse : public Mount {
     18  protected:
     19   MountFuse();
     20 
     21   virtual Error Init(const MountInitArgs& args);
     22   virtual void Destroy();
     23 
     24  public:
     25   virtual Error Access(const Path& path, int a_mode);
     26   virtual Error Open(const Path& path, int mode, ScopedMountNode* out_node);
     27   virtual Error Unlink(const Path& path);
     28   virtual Error Mkdir(const Path& path, int perm);
     29   virtual Error Rmdir(const Path& path);
     30   virtual Error Remove(const Path& path);
     31   virtual Error Rename(const Path& path, const Path& newpath);
     32 
     33 private:
     34   struct fuse_operations* fuse_ops_;
     35   void* fuse_user_data_;
     36 
     37   friend class MountNodeFuse;
     38   friend class FuseMountFactory;
     39   DISALLOW_COPY_AND_ASSIGN(MountFuse);
     40 };
     41 
     42 class MountNodeFuse : public MountNode {
     43  protected:
     44   MountNodeFuse(Mount* mount,
     45                 struct fuse_operations* fuse_ops,
     46                 struct fuse_file_info& info,
     47                 const std::string& path);
     48 
     49  public:
     50   virtual bool CanOpen(int open_flags);
     51   virtual Error GetStat(struct stat* stat);
     52   virtual Error VIoctl(int request, va_list args);
     53   virtual Error Tcflush(int queue_selector);
     54   virtual Error Tcgetattr(struct termios* termios_p);
     55   virtual Error Tcsetattr(int optional_actions,
     56                           const struct termios *termios_p);
     57   virtual Error GetSize(size_t* out_size);
     58 
     59  protected:
     60   struct fuse_operations* fuse_ops_;
     61   struct fuse_file_info info_;
     62   std::string path_;
     63 };
     64 
     65 class MountNodeFuseFile : public MountNodeFuse {
     66  public:
     67   MountNodeFuseFile(Mount* mount,
     68                     struct fuse_operations* fuse_ops,
     69                     struct fuse_file_info& info,
     70                     const std::string& path);
     71 
     72  protected:
     73   virtual void Destroy();
     74 
     75  public:
     76   virtual Error FSync();
     77   virtual Error FTruncate(off_t length);
     78   virtual Error Read(const HandleAttr& attr,
     79                      void* buf,
     80                      size_t count,
     81                      int* out_bytes);
     82   virtual Error Write(const HandleAttr& attr,
     83                       const void* buf,
     84                       size_t count,
     85                       int* out_bytes);
     86 
     87  private:
     88   friend class MountFuse;
     89   DISALLOW_COPY_AND_ASSIGN(MountNodeFuseFile);
     90 };
     91 
     92 class MountNodeFuseDir : public MountNodeFuse {
     93  public:
     94   MountNodeFuseDir(Mount* mount,
     95                    struct fuse_operations* fuse_ops,
     96                    struct fuse_file_info& info,
     97                    const std::string& path);
     98 
     99  protected:
    100   virtual void Destroy();
    101 
    102  public:
    103   virtual Error FSync();
    104   virtual Error GetDents(size_t offs,
    105                          struct dirent* pdir,
    106                          size_t count,
    107                          int* out_bytes);
    108 
    109  private:
    110   static int FillDirCallback(void* buf,
    111                              const char* name,
    112                              const struct stat* stbuf,
    113                              off_t off);
    114 
    115  private:
    116   friend class MountFuse;
    117   DISALLOW_COPY_AND_ASSIGN(MountNodeFuseDir);
    118 };
    119 
    120 }  // namespace nacl_io
    121 
    122 #endif  // LIBRARIES_NACL_IO_MOUNT_FUSE_H_
    123