The Pedigree Project  0.1
Ext2Filesystem.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 EXT2FILESYSTEM_H
21 #define EXT2FILESYSTEM_H
22 
23 #include "modules/system/vfs/Filesystem.h"
24 #include "pedigree/kernel/process/Mutex.h"
25 #include "pedigree/kernel/processor/types.h"
26 #include "pedigree/kernel/utilities/String.h"
27 
28 class Disk;
29 class File;
30 struct GroupDesc;
31 struct Inode;
32 struct Superblock;
33 template <class T>
34 class Vector;
35 
37 class Ext2Filesystem : public Filesystem
38 {
39  friend class Ext2File;
40  friend class Ext2Node;
41  friend class Ext2Directory;
42  friend class Ext2Symlink;
43 
44  public:
46 
47  virtual ~Ext2Filesystem();
48 
49  //
50  // Filesystem interface.
51  //
52  virtual bool initialise(Disk *pDisk);
53  static Filesystem *probe(Disk *pDisk);
54  virtual File *getRoot() const;
55  virtual String getVolumeLabel() const;
56 
57  protected:
58  virtual bool
59  createFile(File *parent, const String &filename, uint32_t mask);
60  virtual bool
61  createDirectory(File *parent, const String &filename, uint32_t mask);
62  virtual bool
63  createSymlink(File *parent, const String &filename, const String &value);
64  virtual bool createLink(File *parent, const String &filename, File *target);
65  virtual bool remove(File *parent, File *file);
66 
67  private:
68  virtual bool createNode(
69  File *parent, const String &filename, uint32_t mask,
70  const String &value, size_t type, uint32_t inodeOverride = 0);
71 
74  void operator=(const Ext2Filesystem &);
75 
77  uintptr_t readBlock(uint32_t block);
79  void writeBlock(uint32_t block);
80 
81  void pinBlock(uint64_t location);
82  void unpinBlock(uint64_t location);
83 
84  void sync(size_t offset, bool async);
85 
86  uint32_t findFreeBlock(uint32_t inode);
87  bool findFreeBlocks(uint32_t inode, size_t count, Vector<uint32_t> &blocks);
88  size_t findFreeBlocksInGroup(
89  uint32_t group, size_t maxCount, Vector<uint32_t> &blocks);
90  uint32_t findFreeInode();
91 
92  void releaseBlock(uint32_t block);
95  bool releaseInode(uint32_t inode);
96 
97  Inode *getInode(uint32_t num);
98  void writeInode(uint32_t num);
99 
100  void ensureFreeBlockBitmapLoaded(size_t group);
101  void ensureFreeInodeBitmapLoaded(size_t group);
102  void ensureInodeTableLoaded(size_t group);
103 
104  bool checkOptionalFeature(size_t feature);
105  bool checkRequiredFeature(size_t feature);
106  bool checkReadOnlyFeature(size_t feature);
107 
108  void increaseInodeRefcount(uint32_t inode);
109  bool decreaseInodeRefcount(uint32_t inode);
110 
113 
117 
124 
126  uint32_t m_BlockSize;
127 
129  uint32_t m_InodeSize;
130 
133 
134 #ifdef THREADS
135 
138 #endif
139 
142 
145 };
146 
147 #endif
virtual bool createFile(File *parent, const String &filename, uint32_t mask)
Vector< size_t > * m_pInodeBitmaps
virtual bool createNode(File *parent, const String &filename, uint32_t mask, const String &value, size_t type, uint32_t inodeOverride=0)
Vector< size_t > * m_pBlockBitmaps
size_t m_nGroupDescriptors
A vector / dynamic array.
Vector< size_t > * m_pInodeTables
size_t findFreeBlocksInGroup(uint32_t group, size_t maxCount, Vector< uint32_t > &blocks)
Definition: Mutex.h:58
Definition: String.h:49
virtual String getVolumeLabel() const
Definition: Disk.h:32
Superblock * m_pSuperblock
Definition: ext2.h:152
virtual File * getRoot() const
uint32_t m_BlockSize
virtual bool createDirectory(File *parent, const String &filename, uint32_t mask)
void releaseBlock(uint32_t block)
virtual bool initialise(Disk *pDisk)
virtual bool createLink(File *parent, const String &filename, File *target)
bool releaseInode(uint32_t inode)
uint32_t m_InodeSize
GroupDesc ** m_pGroupDescriptors
bool findFreeBlocks(uint32_t inode, size_t count, Vector< uint32_t > &blocks)
uintptr_t readBlock(uint32_t block)
uint32_t findFreeInode()
virtual void sync()
Definition: File.cc:351
Definition: File.h:66
void writeBlock(uint32_t block)
virtual bool createSymlink(File *parent, const String &filename, const String &value)