The Pedigree Project  0.1
DevFs.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 DEVFS_H
21 #define DEVFS_H
22 
23 #include "pedigree/kernel/Log.h"
24 
25 #include "modules/system/vfs/Directory.h"
26 #include "modules/system/vfs/File.h"
27 #include "modules/system/vfs/Filesystem.h"
28 #include "pedigree/kernel/machine/InputManager.h"
29 #include "pedigree/kernel/utilities/ExtensibleBitmap.h"
30 
31 #include "modules/system/console/TextIO.h"
32 
33 #include "pedigree/kernel/graphics/Graphics.h"
34 #include "pedigree/kernel/graphics/GraphicsService.h"
35 
36 #include "modules/subsys/posix/PsAuxFile.h"
37 #include "modules/subsys/posix/VirtualTerminal.h"
38 
39 #define DEVFS_NUMTTYS 7
40 
41 class DevFs;
42 class DevFsDirectory;
43 
44 extern DevFs *g_pDevFs;
45 
46 class RandomFile : public File
47 {
48  public:
49  RandomFile(String str, size_t inode, Filesystem *pParentFS, File *pParent)
50  : File(str, 0, 0, 0, inode, pParentFS, 0, pParent)
51  {
53  FILE_UR | FILE_UW | FILE_GR | FILE_GW | FILE_OR | FILE_OW);
54  setUidOnly(0);
55  setGidOnly(0);
56  }
57  ~RandomFile()
58  {
59  }
60 
61  virtual uint64_t readBytewise(
62  uint64_t location, uint64_t size, uintptr_t buffer,
63  bool bCanBlock = true);
64  virtual uint64_t writeBytewise(
65  uint64_t location, uint64_t size, uintptr_t buffer,
66  bool bCanBlock = true);
67 
68  private:
69  virtual bool isBytewise() const
70  {
71  return true;
72  }
73 };
74 
75 class NullFile : public File
76 {
77  public:
78  NullFile(String str, size_t inode, Filesystem *pParentFS, File *pParentNode)
79  : File(str, 0, 0, 0, inode, pParentFS, 0, pParentNode)
80  {
82  FILE_UR | FILE_UW | FILE_GR | FILE_GW | FILE_OR | FILE_OW);
83  setUidOnly(0);
84  setGidOnly(0);
85  }
86  ~NullFile()
87  {
88  }
89 
90  virtual uint64_t readBytewise(
91  uint64_t location, uint64_t size, uintptr_t buffer,
92  bool bCanBlock = true);
93  virtual uint64_t writeBytewise(
94  uint64_t location, uint64_t size, uintptr_t buffer,
95  bool bCanBlock = true);
96 
97  private:
98  virtual bool isBytewise() const
99  {
100  return true;
101  }
102 };
103 
104 class ZeroFile : public File
105 {
106  public:
107  ZeroFile(String str, size_t inode, Filesystem *pParentFS, File *pParentNode)
108  : File(str, 0, 0, 0, inode, pParentFS, 0, pParentNode)
109  {
111  FILE_UR | FILE_UW | FILE_GR | FILE_GW | FILE_OR | FILE_OW);
112  setUidOnly(0);
113  setGidOnly(0);
114  }
115  ~ZeroFile()
116  {
117  }
118 
119  virtual uint64_t readBytewise(
120  uint64_t location, uint64_t size, uintptr_t buffer,
121  bool bCanBlock = true);
122  virtual uint64_t writeBytewise(
123  uint64_t location, uint64_t size, uintptr_t buffer,
124  bool bCanBlock = true);
125 
126  private:
127  virtual bool isBytewise() const
128  {
129  return true;
130  }
131 };
132 
133 class PtmxFile : public File
134 {
135  public:
136  PtmxFile(
137  String str, size_t inode, Filesystem *pParentFS, File *pParent,
138  DevFsDirectory *m_pPtsDirectory);
139  ~PtmxFile();
140 
141  virtual uint64_t readBytewise(
142  uint64_t location, uint64_t size, uintptr_t buffer,
143  bool bCanBlock = true);
144  virtual uint64_t writeBytewise(
145  uint64_t location, uint64_t size, uintptr_t buffer,
146  bool bCanBlock = true);
147 
148  // override open() to correctly handle returning a master and creating
149  // the associated slave.
150  virtual File *open();
151 
152  private:
153  ExtensibleBitmap m_Terminals;
154  DevFsDirectory *m_pPtsDirectory;
155 
156  virtual bool isBytewise() const
157  {
158  return true;
159  }
160 };
161 
162 class RtcFile : public File
163 {
164  public:
165  RtcFile(size_t inode, Filesystem *pParentFS, File *pParentNode)
166  : File(String("rtc"), 0, 0, 0, inode, pParentFS, 0, pParentNode)
167  {
168  setPermissionsOnly(FILE_UR | FILE_UW | FILE_GR | FILE_GW | FILE_OR);
169  setUidOnly(0);
170  setGidOnly(0);
171  }
172  ~RtcFile()
173  {
174  }
175 
176  virtual uint64_t readBytewise(
177  uint64_t location, uint64_t size, uintptr_t buffer,
178  bool bCanBlock = true);
179  virtual uint64_t writeBytewise(
180  uint64_t location, uint64_t size, uintptr_t buffer,
181  bool bCanBlock = true);
182 
183  virtual bool supports(const size_t command) const;
184  virtual int command(const size_t command, void *buffer);
185 
186  private:
187  virtual bool isBytewise() const
188  {
189  return true;
190  }
191 };
192 
193 class FramebufferFile : public File
194 {
195  public:
197  String str, size_t inode, Filesystem *pParentFS, File *pParentNode);
198  ~FramebufferFile();
199 
200  bool initialise();
201 
202  virtual uintptr_t readBlock(uint64_t location);
203 
204  virtual bool supports(const size_t command) const;
205  virtual int command(const size_t command, void *buffer);
206 
208 
209  private:
211 
212  bool m_bTextMode;
213  size_t m_nDepth;
214 };
215 
216 class Tty0File : public File
217 {
218  public:
219  Tty0File(
220  String str, size_t inode, Filesystem *pParentFS, File *pParent,
221  DevFs *devfs);
222  ~Tty0File();
223 
224  virtual uint64_t readBytewise(
225  uint64_t location, uint64_t size, uintptr_t buffer,
226  bool bCanBlock = true);
227  virtual uint64_t writeBytewise(
228  uint64_t location, uint64_t size, uintptr_t buffer,
229  bool bCanBlock = true);
230 
231  // override open() to correctly handle returning a master and creating
232  // the associated slave.
233  virtual File *open();
234 
235  private:
236  DevFs *m_pDevFs;
237 
238  virtual bool isBytewise() const
239  {
240  return true;
241  }
242 };
243 
244 class MemFile : public File
245 {
246  public:
247  MemFile(String name, size_t inode, Filesystem *pParentFS, File *pParentNode)
248  : File(name, 0, 0, 0, inode, pParentFS, 0, pParentNode)
249  {
251  FILE_UR | FILE_UW | FILE_GR | FILE_GW | FILE_OR | FILE_OW);
252  setUidOnly(0);
253  setGidOnly(0);
254  }
255  ~MemFile()
256  {
257  }
258 
259  virtual physical_uintptr_t getPhysicalPage(size_t offset);
260  virtual void returnPhysicalPage(size_t offset);
261 };
262 
265 class DevFsDirectory : public Directory
266 {
267  public:
269  String name, Time::Timestamp accessedTime, Time::Timestamp modifiedTime,
270  Time::Timestamp creationTime, uintptr_t inode, class Filesystem *pFs,
271  size_t size, File *pParent)
272  : Directory(
273  name, accessedTime, modifiedTime, creationTime, inode, pFs, size,
274  pParent)
275  {
276  }
277 
278  virtual ~DevFsDirectory();
279 
280  void addEntry(String name, File *pFile)
281  {
282  addDirectoryEntry(name, pFile);
283  }
284 };
285 
287 class DevFs : public Filesystem
288 {
289  public:
290  DevFs() : m_pRoot(0), m_pTty(0), m_VtManager(0), m_pPsAuxFile(0)
291  {
292  }
293 
294  virtual ~DevFs();
295 
296  virtual bool initialise(Disk *pDisk);
297 
298  virtual File *getRoot() const
299  {
300  return m_pRoot;
301  }
302  virtual String getVolumeLabel() const
303  {
304  return String("dev");
305  }
306 
307  virtual size_t getNextInode();
308  virtual void revertInode();
309 
310  void handleInput(InputManager::InputNotification &in);
311 
312  VirtualTerminalManager &getTerminalManager()
313  {
314  return *m_VtManager;
315  }
316 
317  protected:
318  virtual bool createFile(File *parent, const String &filename, uint32_t mask)
319  {
320  return false;
321  }
322  virtual bool
323  createDirectory(File *parent, const String &filename, uint32_t mask)
324  {
325  return false;
326  }
327  virtual bool
328  createSymlink(File *parent, const String &filename, const String &value)
329  {
330  return false;
331  }
332  virtual bool remove(File *parent, File *file)
333  {
334  return false;
335  }
336 
337  private:
338  DevFs(const DevFs &);
339  DevFs &operator=(const DevFs &);
340 
341  DevFsDirectory *m_pRoot;
342 
343  TextIO *m_pTty;
344 
345  size_t m_NextInode;
346 
347  TextIO *m_pTtys[DEVFS_NUMTTYS];
348  File *m_pTtyFiles[DEVFS_NUMTTYS];
349  size_t m_CurrentTty;
350 
351  VirtualTerminalManager *m_VtManager;
352 
353  PsAuxFile *m_pPsAuxFile;
354 };
355 
356 #endif
Definition: DevFs.h:75
virtual String getVolumeLabel() const
Definition: DevFs.h:302
virtual File * getRoot() const
Definition: DevFs.h:298
virtual int command(const size_t command, void *buffer)
Definition: File.cc:544
virtual bool isBytewise() const
Definition: DevFs.h:156
void setUidOnly(size_t uid)
Definition: File.cc:644
virtual physical_uintptr_t getPhysicalPage(size_t offset)
Definition: File.cc:242
Definition: DevFs.h:244
virtual void returnPhysicalPage(size_t offset)
Definition: File.cc:315
GraphicsService::GraphicsParameters * m_pGraphicsParameters
Definition: DevFs.h:210
virtual bool createDirectory(File *parent, const String &filename, uint32_t mask)
Definition: DevFs.h:323
virtual bool supports(const size_t command) const
Definition: File.cc:539
virtual bool isBytewise() const
Definition: DevFs.h:187
Definition: String.h:49
virtual bool createFile(File *parent, const String &filename, uint32_t mask)
Definition: DevFs.h:318
Definition: Disk.h:32
Definition: TextIO.h:48
Definition: DevFs.h:162
virtual bool isBytewise() const
Definition: DevFs.h:127
void setPermissionsOnly(uint32_t perms)
Definition: File.cc:639
virtual bool createSymlink(File *parent, const String &filename, const String &value)
Definition: DevFs.h:328
File()
Definition: File.cc:68
virtual uint64_t writeBytewise(uint64_t location, uint64_t size, uintptr_t buffer, bool bCanBlock=true)
Definition: DevFs.cc:102
void setGidOnly(size_t gid)
Definition: File.cc:649
virtual uintptr_t readBlock(uint64_t location)
Definition: File.cc:602
Definition: DevFs.h:287
virtual bool isBytewise() const
Definition: DevFs.h:98
virtual bool isBytewise() const
Definition: DevFs.h:238
virtual uint64_t readBytewise(uint64_t location, uint64_t size, uintptr_t buffer, bool bCanBlock=true)
Definition: DevFs.cc:59
virtual File * open()
Definition: File.cc:572
Definition: File.h:66
virtual bool isBytewise() const
Definition: DevFs.h:69