The Pedigree Project 0.1
FatSymlink.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 "FatSymlink.h"
21#include "pedigree/kernel/LockGuard.h"
22
23#include "FatFilesystem.h"
24#include "modules/system/vfs/File.h"
25
26FatSymlink::FatSymlink(String name, Time::Timestamp accessedTime, Time::Timestamp modifiedTime,
27 Time::Timestamp creationTime, uintptr_t inode, class Filesystem* pFs,
28 size_t size, uint32_t dirClus, uint32_t dirOffset, File* pParent)
29 : Symlink(name, accessedTime, modifiedTime, creationTime, inode, pFs, size, pParent),
30 m_DirClus(dirClus),
31 m_DirOffset(dirOffset) {
32 // No permissions on FAT - set all to RWX.
33 setPermissionsOnly(FILE_UR | FILE_UW | FILE_UX | FILE_GR | FILE_GW | FILE_GX | FILE_OR | FILE_OW |
34 FILE_OX);
35 static_cast<FatFilesystem*>(pFs)->registerNode(this);
36}
37
38uint64_t FatSymlink::readBytewise(uint64_t location, uint64_t size, uintptr_t buffer,
39 bool bCanBlock) {
40 FatFilesystem* pFs = static_cast<FatFilesystem*>(m_pFilesystem);
41 return pFs->read(this, location, size, buffer);
42}
43
44File::Attributes FatSymlink::getAttributes() const {
45 FatSymlink* file = const_cast<FatSymlink*>(this);
46 LockGuard<Mutex> dataGuard(file->dataMutationLock());
47 FatFilesystem* filesystem = static_cast<FatFilesystem*>(m_pFilesystem);
48 LockGuard<Mutex> guard(filesystem->m_FileMutationLock);
49 Attributes attributes = File::getAttributes();
50 attributes.blocks = filesystem->allocatedBlocks(file);
51 return attributes;
52}
53
54uint64_t FatSymlink::writeBytewise(uint64_t location, uint64_t size, uintptr_t buffer,
55 bool bCanBlock) {
57 FatFilesystem* pFs = static_cast<FatFilesystem*>(m_pFilesystem);
58 uint64_t ret = pFs->write(this, location, size, buffer);
59
60 // Reset the symlink target.
61 initialise(true);
62
63 return ret;
64}
65
66FatSymlink::~FatSymlink() {
67 static_cast<FatFilesystem*>(m_pFilesystem)->releaseNode(this);
68}
Mutex m_FileMutationLock
Definition File.h:75