• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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_MEMFS_MEM_FS_H_
6 #define LIBRARIES_NACL_IO_MEMFS_MEM_FS_H_
7 
8 #include "nacl_io/filesystem.h"
9 #include "nacl_io/typed_fs_factory.h"
10 
11 namespace nacl_io {
12 
13 class MemFs : public Filesystem {
14  protected:
15   MemFs();
16 
17   using Filesystem::Init;
18   virtual Error Init(const FsInitArgs& args);
19 
20   // The protected functions are only used internally and will not
21   // acquire or release the filesystem's lock themselves.  The caller is
22   // required to use correct locking as needed.
23 
24   // Allocate or free an INODE number.
25   int AllocateINO();
26   void FreeINO(int ino);
27 
28   // Find a Node specified node optionally failing if type does not match.
29   virtual Error FindNode(const Path& path, int type, ScopedNode* out_node);
30 
31  public:
32   virtual Error Access(const Path& path, int a_mode);
33   virtual Error Open(const Path& path, int mode, ScopedNode* out_node);
34   virtual Error Unlink(const Path& path);
35   virtual Error Mkdir(const Path& path, int perm);
36   virtual Error Rmdir(const Path& path);
37   virtual Error Remove(const Path& path);
38   virtual Error Rename(const Path& path, const Path& newpath);
39 
40  private:
41   static const int REMOVE_DIR = 1;
42   static const int REMOVE_FILE = 2;
43   static const int REMOVE_ALL = REMOVE_DIR | REMOVE_FILE;
44 
45   Error RemoveInternal(const Path& path, int remove_type);
46 
47   ScopedNode root_;
48 
49   friend class TypedFsFactory<MemFs>;
50   DISALLOW_COPY_AND_ASSIGN(MemFs);
51 };
52 
53 }  // namespace nacl_io
54 
55 #endif  // LIBRARIES_NACL_IO_MEMFS_MEM_FS_H_
56