The Pedigree Project  0.1
Ext2File.cc
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 #include "Ext2File.h"
21 #include "Ext2Filesystem.h"
22 #include "ext2.h"
23 #include "pedigree/kernel/utilities/utility.h"
24 
25 class Filesystem;
26 
28  const String &name, uintptr_t inode_num, Inode *inode, Ext2Filesystem *pFs,
29  File *pParent)
30  : File(
31  name, LITTLE_TO_HOST32(inode->i_atime),
32  LITTLE_TO_HOST32(inode->i_mtime), LITTLE_TO_HOST32(inode->i_ctime),
33  inode_num, static_cast<Filesystem *>(pFs),
34  LITTLE_TO_HOST32(inode->i_size),
35  pParent),
36  Ext2Node(inode_num, inode, pFs)
37 {
38  uint32_t mode = LITTLE_TO_HOST32(inode->i_mode);
39  setPermissionsOnly(modeToPermissions(mode));
40  setUidOnly(LITTLE_TO_HOST16(inode->i_uid));
41  setGidOnly(LITTLE_TO_HOST16(inode->i_gid));
42 }
43 
45 {
46 }
47 
48 void Ext2File::preallocate(size_t expectedSize, bool zero)
49 {
50  // No need to change the actual file size, just allocate the blocks.
51  Ext2Node::ensureLargeEnough(expectedSize, 0, 0, true, !zero);
52 }
53 
54 void Ext2File::extend(size_t newSize)
55 {
56  Ext2Node::extend(newSize, 0, 0);
57  m_Size = m_nSize;
58 }
59 
60 void Ext2File::extend(size_t newSize, uint64_t location, uint64_t size)
61 {
62  Ext2Node::extend(newSize, location, size);
63  m_Size = m_nSize;
64 }
65 
67 {
68  // Wipe all our blocks. (Ext2Node).
70  m_Size = m_nSize;
71 }
72 
74 {
75  static_cast<Ext2Node *>(this)->fileAttributeChanged(
76  m_Size, m_AccessedTime, m_ModifiedTime, m_CreationTime);
77  static_cast<Ext2Node *>(this)->updateMetadata(
78  getUid(), getGid(), permissionsToMode(getPermissions()));
79 }
80 
81 uintptr_t Ext2File::readBlock(uint64_t location)
82 {
83  return Ext2Node::readBlock(location);
84 }
85 
86 void Ext2File::writeBlock(uint64_t location, uintptr_t addr)
87 {
88  Ext2Node::writeBlock(location);
89 }
90 
91 void Ext2File::pinBlock(uint64_t location)
92 {
93  Ext2Node::pinBlock(location);
94 }
95 
96 void Ext2File::unpinBlock(uint64_t location)
97 {
98  Ext2Node::unpinBlock(location);
99 }
100 
101 void Ext2File::sync(size_t offset, bool async)
102 {
103  Ext2Node::sync(offset, async);
104 }
105 
107 {
108  return m_pExt2Fs->m_BlockSize;
109 }
virtual void pinBlock(uint64_t location)
Definition: Ext2File.cc:91
Ext2File(const Ext2File &file)
virtual void preallocate(size_t expectedSize, bool zero=true)
Definition: Ext2File.cc:48
void setUidOnly(size_t uid)
Definition: File.cc:644
void fileAttributeChanged()
Definition: Ext2File.cc:73
virtual void writeBlock(uint64_t location, uintptr_t addr)
Definition: Ext2File.cc:86
Definition: String.h:49
virtual void truncate()
Definition: Ext2File.cc:66
Definition: ext2.h:152
virtual void extend(size_t newSize)
Definition: Ext2File.cc:54
void setPermissionsOnly(uint32_t perms)
Definition: File.cc:639
uint32_t m_BlockSize
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
virtual ~Ext2File()
Definition: Ext2File.cc:44
void setGidOnly(size_t gid)
Definition: File.cc:649
void wipe()
Definition: Ext2Node.cc:115
virtual size_t getBlockSize() const
Definition: Ext2File.cc:106
virtual uintptr_t readBlock(uint64_t location)
Definition: Ext2File.cc:81
virtual void sync()
Definition: File.cc:351
virtual void unpinBlock(uint64_t location)
Definition: Ext2File.cc:96
Definition: File.h:66