The Pedigree Project  0.1
Ext2Symlink.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 "Ext2Symlink.h"
21 #include "Ext2Filesystem.h"
22 #include "ext2.h"
23 #include "pedigree/kernel/Log.h"
24 #include "pedigree/kernel/processor/types.h"
25 #include "pedigree/kernel/utilities/utility.h"
26 
27 class File;
28 class Filesystem;
29 
31  const String &name, uintptr_t inode_num, Inode *inode, Ext2Filesystem *pFs,
32  File *pParent)
33  : Symlink(
34  name, LITTLE_TO_HOST32(inode->i_atime),
35  LITTLE_TO_HOST32(inode->i_mtime), LITTLE_TO_HOST32(inode->i_ctime),
36  inode_num, static_cast<Filesystem *>(pFs),
37  LITTLE_TO_HOST32(inode->i_size),
38  pParent),
39  Ext2Node(inode_num, inode, pFs)
40 {
41  uint32_t mode = LITTLE_TO_HOST32(inode->i_mode);
42  setPermissionsOnly(modeToPermissions(mode));
43  setUidOnly(LITTLE_TO_HOST16(inode->i_uid));
44  setGidOnly(LITTLE_TO_HOST16(inode->i_gid));
45 }
46 
48 {
49 }
50 
52  uint64_t location, uint64_t size, uintptr_t buffer, bool canBlock)
53 {
54  if (location >= getSize())
55  return 0;
56  if ((location + size) >= getSize())
57  size = getSize() - location;
58  if (!size)
59  return 0;
60 
61  if (getSize() && Ext2Node::getInode()->i_blocks == 0)
62  {
63  MemoryCopy(
64  reinterpret_cast<void *>(buffer),
65  adjust_pointer(m_pInode->i_block, location), size);
66  return size;
67  }
68 
69  if (getSize() > m_pExt2Fs->m_BlockSize)
70  {
71  WARNING("Ext2: rather large symlink found, not handled yet");
72  return 0;
73  }
74 
75  uintptr_t block = Ext2Node::readBlock(location);
76  size_t offset = location % m_pExt2Fs->m_BlockSize;
77  MemoryCopy(
78  reinterpret_cast<void *>(buffer),
79  reinterpret_cast<void *>(block + offset), size);
80  m_Size = m_nSize;
81  return size;
82 }
83 
85  uint64_t location, uint64_t size, uintptr_t buffer, bool canBlock)
86 {
87  Ext2Node::extend(size);
88  m_Size = m_nSize;
89 
90  if (getSize() > m_pExt2Fs->m_BlockSize)
91  {
92  WARNING("Ext2: rather large symlink found, not handled yet");
93  return 0;
94  }
95 
96  uintptr_t block = Ext2Node::readBlock(location);
97  size_t offset = location % m_pExt2Fs->m_BlockSize;
98  MemoryCopy(
99  adjust_pointer(reinterpret_cast<void *>(block), offset),
100  reinterpret_cast<void *>(buffer), size);
101  Ext2Node::writeBlock(location);
102  return size;
103 }
104 
106 {
107  Ext2Node::wipe();
108  m_Size = m_nSize;
109 }
110 
112 {
113  static_cast<Ext2Node *>(this)->fileAttributeChanged(
114  m_Size, m_AccessedTime, m_ModifiedTime, m_CreationTime);
115  static_cast<Ext2Node *>(this)->updateMetadata(
116  getUid(), getGid(), permissionsToMode(getPermissions()));
117 }
void setUidOnly(size_t uid)
Definition: File.cc:644
Definition: String.h:49
Definition: ext2.h:152
void setPermissionsOnly(uint32_t perms)
Definition: File.cc:639
uint32_t m_BlockSize
#define WARNING(text)
Definition: Log.h:78
void updateMetadata(uint16_t uid, uint16_t gid, uint32_t perms)
Definition: Ext2Node.cc:497
void setGidOnly(size_t gid)
Definition: File.cc:649
void wipe()
Definition: Ext2Node.cc:115
Definition: File.h:66