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 "pedigree/kernel/LockGuard.h"
22#include "pedigree/kernel/Log.h"
23#include "pedigree/kernel/processor/types.h"
24#include "pedigree/kernel/syscallError.h"
25#include "pedigree/kernel/utilities/utility.h"
26
27#include "Ext2Filesystem.h"
28#include "ext2.h"
29
30class File;
31class Filesystem;
32
33Ext2Symlink::Ext2Symlink(const String& name, uintptr_t inode_num, Inode* inode, Ext2Filesystem* pFs,
34 File* pParent)
35 : Symlink(name, LITTLE_TO_HOST32(inode->i_atime), LITTLE_TO_HOST32(inode->i_mtime),
36 LITTLE_TO_HOST32(inode->i_ctime), inode_num, static_cast<Filesystem*>(pFs),
37 LITTLE_TO_HOST32(inode->i_size),
38 pParent),
39 Ext2Node(inode_num, inode, pFs) {
40 uint32_t mode = LITTLE_TO_HOST32(inode->i_mode);
41 setPermissionsOnly(modeToPermissions(mode));
42 setUidOnly(Ext2Owner::uid(*inode));
43 setGidOnly(Ext2Owner::gid(*inode));
44}
45
47
48uint64_t Ext2Symlink::readBytewise(uint64_t location, uint64_t size, uintptr_t buffer,
49 bool canBlock) {
50 if (!m_State->allocationValid || !size || location >= getSize())
51 return 0;
52 const uint64_t remaining = getSize() - location;
53 if (size > remaining)
54 size = remaining;
55
56 if (isInlineSymlink()) {
57 MemoryCopy(reinterpret_cast<void*>(buffer), adjust_pointer(m_pInode->i_block, location), size);
58 return size;
59 }
60
61 if (getSize() > m_pExt2Fs->m_BlockSize) {
62 WARNING("Ext2: rather large symlink found, not handled yet");
63 return 0;
64 }
65
66 uintptr_t block = Ext2Node::readBlock(location);
67 if (!block) {
68 return 0;
69 }
70 MemoryCopy(reinterpret_cast<void*>(buffer), reinterpret_cast<void*>(block), size);
71 Ext2Node::unpinBlock(location);
72 m_Size = m_nSize;
73 return size;
74}
75
76uint64_t Ext2Symlink::writeBytewise(uint64_t location, uint64_t size, uintptr_t buffer,
77 bool canBlock) {
78 LockGuard<Mutex> inode(m_State->writebackLock);
79 if (location > m_pExt2Fs->m_BlockSize || size > m_pExt2Fs->m_BlockSize - location) {
80 SYSCALL_ERROR(FileTooLarge);
81 return 0;
82 }
83 if (!ensureLargeEnough(location + size, location, size))
84 return 0;
85 m_Size = m_nSize;
86
87 uintptr_t block = Ext2Node::readBlock(location);
88 if (!block) {
89 SYSCALL_ERROR(IoError);
90 return 0;
91 }
92 MemoryCopy(reinterpret_cast<void*>(block), reinterpret_cast<void*>(buffer), size);
93 Ext2Node::writeBlock(location);
94 Ext2Node::unpinBlock(location);
95 return size;
96}
97
100 m_Size = m_nSize;
101}
102
104 LockGuard<Mutex> guard(m_State->writebackLock);
105 Ext2Node::fileAttributeChanged(m_Size, LITTLE_TO_HOST32(m_pInode->i_atime),
106 LITTLE_TO_HOST32(m_pInode->i_mtime),
107 LITTLE_TO_HOST32(m_pInode->i_ctime));
108}
109
110File::Attributes Ext2Symlink::getAttributes() const {
111 return inodeAttributes();
112}
113
114void Ext2Symlink::updateAttributes(const Attributes& attributes, uint32_t mask) {
115 updateInodeAttributes(attributes, mask);
116}
bool wipe(bool allocationLockHeld=false)
Definition Ext2Node.cc:217
bool ensureLargeEnough(size_t size, uint64_t location, uint64_t opsize, bool onlyBlocks=false, bool nozeroblocks=false)
Definition Ext2Node.cc:258
void fileAttributeChanged(size_t size, size_t atime, size_t mtime, size_t ctime)
Definition Ext2Node.cc:567
Definition File.h:75
void setGidOnly(size_t gid)
Definition File.cc:1448
void setPermissionsOnly(uint32_t perms)
Definition File.cc:1440
void setUidOnly(size_t uid)
Definition File.cc:1444
Definition ext2.h:152