OLD | NEW |
---|---|
1 /* Copyright (c) 2012 The Chromium Authors. All rights reserved. | 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 | 2 * Use of this source code is governed by a BSD-style license that can be |
3 * found in the LICENSE file. | 3 * found in the LICENSE file. |
4 */ | 4 */ |
5 #ifndef LIBRARIES_NACL_MOUNTS_MOUNT_MEM_H_ | 5 #ifndef LIBRARIES_NACL_MOUNTS_MOUNT_MEM_H_ |
6 #define LIBRARIES_NACL_MOUNTS_MOUNT_MEM_H_ | 6 #define LIBRARIES_NACL_MOUNTS_MOUNT_MEM_H_ |
7 | 7 |
8 #include <stdint.h> | 8 #include <stdint.h> |
9 #include <map> | 9 #include <map> |
10 #include <string> | 10 #include <string> |
11 | 11 |
12 #include "mount.h" | 12 #include "mount.h" |
13 #include "util/macros.h" | |
14 #include "util/SlotAllocator.h" | |
15 | 13 |
16 struct dirent; | |
17 struct stat; | |
18 | |
19 class MountMemNode; | |
20 | |
21 // Mount serves as the base mounting class that will be used by | |
22 // the mount manager (class MountManager). The mount manager | |
23 // relies heavily on the GetNode method as a way of directing | |
24 // system calls that take a path as an argument. The methods | |
25 // of this class are pure virtual. BaseMount class contains | |
26 // stub implementations for these methods. Feel free to use | |
27 // BaseMount if your mount does not implement all of these | |
28 // operations. | |
29 class MountMem : public Mount { | 14 class MountMem : public Mount { |
30 protected: | 15 protected: |
31 MountMem(); | 16 MountMem(int dev); |
binji
2012/04/16 22:43:05
explicit
noelallen1
2012/04/21 18:09:53
Done globally
| |
32 virtual ~MountMem(); | |
33 | 17 |
34 // Init must be called by the factory before | 18 virtual bool Init(const std::string& args); |
35 void Init(); | 19 virtual void Destroy(); |
36 | 20 |
37 int MountMem::AddDirEntry(MountNode* node, MountNode* node, const char *name); | 21 // Allocata a node assigning it's first reference to the passed in |
binji
2012/04/16 22:43:05
Spelling: "Allocate" "its"
noelallen1
2012/04/21 18:09:53
Done.
| |
22 // MountNodePtr_t object returnning true, or return false if the node | |
23 // failes to initialize. | |
24 virtual MountNode *AllocateData(int mode); | |
25 virtual MountNode *AllocatePath(int mode); | |
26 virtual void ReleaseNode(MountNode *node); | |
27 | |
28 // Allocate or free an INODE number. | |
29 int AllocateINO(); | |
30 void FreeINO(int ino); | |
31 | |
32 // Find a Node specified node optionally failing if type does not match. | |
33 virtual MountNode* FindNode(const Path& path, int type = 0); | |
38 | 34 |
39 public: | 35 public: |
40 // System calls that can be overridden by a mount implementation | 36 typedef std::vector<ino_t> INOList_t; |
41 virtual int Creat(const std::string& path, int mode, struct stat *st); | |
42 virtual int Mkdir(const std::string& path, int mode, struct stat *st); | |
43 virtual int Unlink(const std::string& path); | |
44 | 37 |
45 virtual int Rmdir(int node); | 38 virtual MountNode *Open(const Path& path, int mode); |
46 virtual int Chmod(int node, int mode); | 39 virtual int Close(MountNode* node); |
47 virtual int Stat(int node, struct stat *buf); | 40 virtual int Unlink(const Path& path); |
48 virtual int Fsync(int node); | 41 virtual int Mkdir(const Path& path, int perm); |
42 virtual int Rmdir(const Path& path); | |
49 | 43 |
50 virtual int Getdents(int node, off_t offset, struct dirent *dirp, | 44 private: |
51 unsigned int count); | 45 MountNode* root_; |
46 INOList_t inos_; | |
47 size_t max_ino_; | |
52 | 48 |
53 virtual ssize_t Read(int node, off_t offset, | |
54 void *buf, size_t count); | |
55 virtual ssize_t Write(int node, off_t offset, | |
56 const void *buf, size_t count); | |
57 virtual int Isatty(int node); | |
58 | |
59 private: | |
60 pthread_mutex_t lock_; | |
61 SlotAllocator<MountMemNode> inodes_; | |
62 DISALLOW_COPY_AND_ASSIGN(MountMem); | 49 DISALLOW_COPY_AND_ASSIGN(MountMem); |
63 }; | 50 }; |
64 | 51 |
65 #endif // LIBRARIES_NACL_MOUNTS_MOUNT_MEM_H_ | 52 #endif // LIBRARIES_NACL_MOUNTS_MOUNT_MEM_H_ |
66 | 53 |
OLD | NEW |