The Pedigree Project  0.1
ProcFs.h
1 /*
2  * Copyright (c) 2008-2014, Pedigree Developers
3  *
4  * Please see the CONTRIB file in the root of the source tree for a full
5  * list of contributors.
6  *
7  * Permission to use, copy, modify, and distribute this software for any
8  * purpose with or without fee is hereby granted, provided that the above
9  * copyright notice and this permission notice appear in all copies.
10  *
11  * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
12  * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
13  * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
14  * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
15  * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
16  * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
17  * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
18  */
19 
20 #ifndef PROCFS_H
21 #define PROCFS_H
22 
23 #include "pedigree/kernel/machine/Machine.h"
24 #include "pedigree/kernel/machine/Timer.h"
25 
26 #include "pedigree/kernel/Log.h"
27 
28 #include "modules/system/vfs/Directory.h"
29 #include "modules/system/vfs/File.h"
30 #include "modules/system/vfs/Filesystem.h"
31 #include "pedigree/kernel/utilities/ExtensibleBitmap.h"
32 
33 class ProcFs;
34 class ProcFsDirectory;
35 class Thread;
36 class PosixProcess;
37 
38 class MeminfoFile : public File
39 {
40  public:
41  MeminfoFile(size_t inode, Filesystem *pParentFS, File *pParent);
42  ~MeminfoFile();
43 
44  virtual uint64_t readBytewise(
45  uint64_t location, uint64_t size, uintptr_t buffer,
46  bool bCanBlock = true);
47  virtual uint64_t writeBytewise(
48  uint64_t location, uint64_t size, uintptr_t buffer,
49  bool bCanBlock = true);
50 
51  virtual size_t getSize();
52 
53  static int run(void *p);
54 
55  void updateThread();
56 
57  private:
58  Thread *m_pUpdateThread;
59  bool m_bRunning;
60  String m_Contents;
61  Mutex m_Lock;
62 
63  virtual bool isBytewise() const
64  {
65  return true;
66  }
67 };
68 
69 class PciDevicesFile : public File
70 {
71  public:
72  PciDevicesFile(size_t inode, Filesystem *pParentFS, File *pParent);
73  ~PciDevicesFile();
74 
75  virtual uint64_t readBytewise(
76  uint64_t location, uint64_t size, uintptr_t buffer,
77  bool bCanBlock = true);
78  virtual uint64_t writeBytewise(
79  uint64_t location, uint64_t size, uintptr_t buffer,
80  bool bCanBlock = true);
81 
82  virtual size_t getSize();
83 
84  private:
85  void resync();
86 
87  String m_Contents;
88 
89  virtual bool isBytewise() const
90  {
91  return true;
92  }
93 };
94 
95 class MountFile : public File
96 {
97  public:
98  MountFile(size_t inode, Filesystem *pParentFS, File *pParent);
99  ~MountFile();
100 
101  virtual uint64_t readBytewise(
102  uint64_t location, uint64_t size, uintptr_t buffer,
103  bool bCanBlock = true);
104  virtual uint64_t writeBytewise(
105  uint64_t location, uint64_t size, uintptr_t buffer,
106  bool bCanBlock = true);
107 
108  virtual size_t getSize();
109 
110  private:
111  virtual bool isBytewise() const
112  {
113  return true;
114  }
115 };
116 
117 class UptimeFile : public File
118 {
119  public:
120  UptimeFile(size_t inode, Filesystem *pParentFS, File *pParent);
121  ~UptimeFile();
122 
123  virtual uint64_t readBytewise(
124  uint64_t location, uint64_t size, uintptr_t buffer,
125  bool bCanBlock = true);
126  virtual uint64_t writeBytewise(
127  uint64_t location, uint64_t size, uintptr_t buffer,
128  bool bCanBlock = true);
129 
130  virtual size_t getSize();
131 
132  private:
133  String generateString();
134 
135  virtual bool isBytewise() const
136  {
137  return true;
138  }
139 };
140 
141 class ConstantFile : public File
142 {
143  public:
144  ConstantFile(
145  String name, const char *value, size_t size, size_t inode,
146  Filesystem *pParentFS, File *pParent);
147  ~ConstantFile();
148 
149  virtual uint64_t readBytewise(
150  uint64_t location, uint64_t size, uintptr_t buffer,
151  bool bCanBlock = true);
152  virtual uint64_t writeBytewise(
153  uint64_t location, uint64_t size, uintptr_t buffer,
154  bool bCanBlock = true);
155 
156  virtual size_t getSize();
157 
158  private:
159  char *m_Contents;
160  size_t m_Size;
161 
162  virtual bool isBytewise() const
163  {
164  return true;
165  }
166 };
167 
171 {
172  public:
174  String name, Time::Timestamp accessedTime, Time::Timestamp modifiedTime,
175  Time::Timestamp creationTime, uintptr_t inode, class Filesystem *pFs,
176  size_t size, File *pParent)
177  : Directory(
178  name, accessedTime, modifiedTime, creationTime, inode, pFs, size,
179  pParent)
180  {
181  }
182 
183  virtual ~ProcFsDirectory();
184 
185  void addEntry(String name, File *pFile)
186  {
187  addDirectoryEntry(name, pFile);
188  }
189 };
190 
192 class ProcFs : public Filesystem
193 {
194  public:
195  ProcFs() : m_pRoot(0)
196  {
197  }
198 
199  virtual ~ProcFs();
200 
201  virtual bool initialise(Disk *pDisk);
202 
203  virtual File *getRoot() const
204  {
205  return m_pRoot;
206  }
207  virtual String getVolumeLabel() const
208  {
209  return String("proc");
210  }
211 
212  virtual size_t getNextInode();
213  virtual void revertInode();
214 
215  void addProcess(PosixProcess *proc);
216  void removeProcess(PosixProcess *proc);
217 
218  protected:
219  virtual bool createFile(File *parent, const String &filename, uint32_t mask)
220  {
221  return false;
222  }
223  virtual bool
224  createDirectory(File *parent, const String &filename, uint32_t mask)
225  {
226  return false;
227  }
228  virtual bool
229  createSymlink(File *parent, const String &filename, const String &value)
230  {
231  return false;
232  }
233  virtual bool remove(File *parent, File *file)
234  {
235  return false;
236  }
237 
238  private:
239  ProcFs(const ProcFs &);
240  ProcFs &operator=(const ProcFs &);
241 
242  ProcFsDirectory *m_pRoot;
243 
244  Tree<size_t, ProcFsDirectory *> m_pProcessDirectories;
245 
246  size_t m_NextInode;
247 
248  String m_PciDevices;
249 };
250 
251 #endif // PROCFS_H
virtual bool isBytewise() const
Definition: ProcFs.h:135
virtual bool createFile(File *parent, const String &filename, uint32_t mask)
Definition: ProcFs.h:219
virtual String getVolumeLabel() const
Definition: ProcFs.h:207
Definition: ProcFs.h:192
Definition: Mutex.h:58
Definition: String.h:49
Definition: Disk.h:32
virtual uint64_t writeBytewise(uint64_t location, uint64_t size, uintptr_t buffer, bool bCanBlock=true)
Definition: ProcFs.cc:109
virtual bool createSymlink(File *parent, const String &filename, const String &value)
Definition: ProcFs.h:229
virtual bool isBytewise() const
Definition: ProcFs.h:63
virtual bool isBytewise() const
Definition: ProcFs.h:89
virtual uint64_t readBytewise(uint64_t location, uint64_t size, uintptr_t buffer, bool bCanBlock=true)
Definition: ProcFs.cc:87
virtual bool createDirectory(File *parent, const String &filename, uint32_t mask)
Definition: ProcFs.h:224
virtual bool isBytewise() const
Definition: ProcFs.h:162
Definition: Thread.h:54
Definition: File.h:66
virtual bool isBytewise() const
Definition: ProcFs.h:111
virtual File * getRoot() const
Definition: ProcFs.h:203