The Pedigree Project  0.1
RamFs.h
Go to the documentation of this file.
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 RAMFS_H
21 #define RAMFS_H
22 
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/compiler.h"
32 #include "pedigree/kernel/processor/types.h"
33 #include "pedigree/kernel/utilities/Cache.h"
34 #include "pedigree/kernel/utilities/String.h"
35 
36 class Disk;
37 
39 {
40  public:
41  RamFile(
42  const String &name, uintptr_t inode, Filesystem *pParentFS,
43  File *pParent);
44 
45  virtual ~RamFile();
46 
47  virtual void truncate();
48 
49  bool canWrite();
50 
51  protected:
52  virtual uintptr_t readBlock(uint64_t location);
53 
54  virtual void pinBlock(uint64_t location);
55 
56  virtual void unpinBlock(uint64_t location);
57 
58  private:
59  Cache m_FileBlocks;
60 
61  size_t m_nOwnerPid;
62 };
63 
66 {
67  private:
68  RamDir(const RamDir &);
69  RamDir &operator=(const RamDir &);
70 
71  public:
72  RamDir(
73  const String &name, size_t inode, class Filesystem *pFs, File *pParent);
74  virtual ~RamDir();
75 
76  virtual void cacheDirectoryContents()
77  {
78  }
79 
80  virtual bool addEntry(String filename, File *pFile);
81 
82  virtual bool removeEntry(File *pFile);
83 };
84 
87 {
88  public:
89  RamFs();
90  virtual ~RamFs();
91 
92  virtual bool initialise(Disk *pDisk);
93 
94  void setProcessOwnership(bool bEnable)
95  {
96  m_bProcessOwners = bEnable;
97  }
98 
99  bool getProcessOwnership() const
100  {
101  return m_bProcessOwners;
102  }
103 
104  virtual File *getRoot() const
105  {
106  return m_pRoot;
107  }
108  virtual String getVolumeLabel() const
109  {
110  return m_VolumeLabel;
111  }
112 
113  protected:
114  virtual bool
115  createFile(File *parent, const String &filename, uint32_t mask);
116  virtual bool
117  createDirectory(File *parent, const String &filename, uint32_t mask);
118  virtual bool
119  createSymlink(File *parent, const String &filename, const String &value);
120  virtual bool remove(File *parent, File *file);
121 
122  RamFs(const RamFs &);
123  void operator=(const RamFs &);
124 
125  static String m_VolumeLabel;
126 
129 
130  bool m_bProcessOwners;
131 };
132 
133 #endif
virtual void pinBlock(uint64_t location)
Definition: File.cc:626
virtual void cacheDirectoryContents()
Definition: RamFs.h:76
void operator=(const Filesystem &)
bool createFile(const StringView &path, uint32_t mask, File *pStartNode=0)
Definition: Filesystem.cc:75
Definition: String.h:49
Definition: Disk.h:32
Definition: Cache.h:118
virtual File * getRoot() const
Definition: RamFs.h:104
virtual void unpinBlock(uint64_t location)
Definition: File.cc:630
bool createDirectory(const StringView &path, uint32_t mask, File *pStartNode=0)
Definition: Filesystem.cc:112
File * m_pRoot
Definition: RamFs.h:128
Definition: RamFs.h:65
virtual void truncate()
Definition: File.cc:568
Definition: RamFs.h:38
Definition: RamFs.h:86
virtual uintptr_t readBlock(uint64_t location)
Definition: File.cc:602
virtual bool initialise(Disk *pDisk)=0
virtual String getVolumeLabel() const
Definition: RamFs.h:108
Definition: File.h:66
bool createSymlink(const StringView &path, const String &value, File *pStartNode=0)
Definition: Filesystem.cc:149