The Pedigree Project  0.1
Ext2Node.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 EXT2_NODE_H
21 #define EXT2_NODE_H
22 
23 #include "pedigree/kernel/processor/types.h"
24 #include "pedigree/kernel/utilities/Vector.h"
25 
26 struct Inode;
27 
29 class Ext2Node
30 {
31  friend class Ext2Filesystem;
32 
33  private:
35  Ext2Node(const Ext2Node &file);
36  Ext2Node &operator=(const Ext2Node &);
37 
38  public:
40  Ext2Node(uintptr_t inode_num, Inode *pInode, class Ext2Filesystem *pFs);
42  virtual ~Ext2Node();
43 
44  Inode *getInode()
45  {
46  return m_pInode;
47  }
48 
49  uint32_t getInodeNumber()
50  {
51  return m_InodeNumber;
52  }
53 
55  void
56  fileAttributeChanged(size_t size, size_t atime, size_t mtime, size_t ctime);
57 
59  void updateMetadata(uint16_t uid, uint16_t gid, uint32_t perms);
60 
62  void wipe();
63 
64  void extend(size_t newSize);
65  void extend(size_t newSize, uint64_t location, uint64_t size);
66 
67  uintptr_t readBlock(uint64_t location);
68  void writeBlock(uint64_t location);
69 
70  void trackBlock(uint32_t block);
71 
72  void pinBlock(uint64_t location);
73  void unpinBlock(uint64_t location);
74 
75  void sync(size_t offset, bool async);
76 
77  protected:
83  bool ensureLargeEnough(size_t size, uint64_t location, uint64_t opsize, bool onlyBlocks = false, bool nozeroblocks = false);
84 
85  bool addBlock(uint32_t blockValue);
86 
87  bool ensureBlockLoaded(size_t nBlock);
88  bool getBlockNumber(size_t nBlock);
89  bool
90  getBlockNumberIndirect(uint32_t inode_block, size_t nBlocks, size_t nBlock);
91  bool getBlockNumberBiindirect(
92  uint32_t inode_block, size_t nBlocks, size_t nBlock);
93  bool getBlockNumberTriindirect(
94  uint32_t inode_block, size_t nBlocks, size_t nBlock);
95 
96  bool setBlockNumber(size_t blockNum, uint32_t blockValue);
97 
98  uint32_t modeToPermissions(uint32_t mode) const;
99  uint32_t permissionsToMode(uint32_t permissions) const;
100 
101  Inode *m_pInode;
102  uint32_t m_InodeNumber;
103  class Ext2Filesystem *m_pExt2Fs;
104 
105  Vector<uint32_t> m_Blocks;
106  uint32_t m_nMetadataBlocks;
107 
108  size_t m_nSize;
109 };
110 
111 #endif
Ext2Node(const Ext2Node &file)
Definition: ext2.h:152
void updateMetadata(uint16_t uid, uint16_t gid, uint32_t perms)
Definition: Ext2Node.cc:497
bool ensureLargeEnough(size_t size, uint64_t location, uint64_t opsize, bool onlyBlocks=false, bool nozeroblocks=false)
Definition: Ext2Node.cc:144
void fileAttributeChanged(size_t size, size_t atime, size_t mtime, size_t ctime)
Definition: Ext2Node.cc:478
void wipe()
Definition: Ext2Node.cc:115
uintptr_t readBlock(uint32_t block)
virtual ~Ext2Node()
Definition: Ext2Node.cc:57
void writeBlock(uint32_t block)