The Pedigree Project 0.1
Iso9660File.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 "Iso9660File.h"
21#include "pedigree/kernel/machine/Disk.h"
22#include "pedigree/kernel/processor/types.h"
23#include "pedigree/kernel/syscallError.h"
24#include "pedigree/kernel/utilities/utility.h"
25
26bool Iso9660File::readPage(uint64_t location, uintptr_t destination) {
27 const size_t pageSize = TargetInfo::getPageSize();
28 if (!destination || location % pageSize || !m_pFs || !m_pFs->m_pDisk)
29 return false;
30 const size_t size = getSize();
31 if (location >= size) {
32 ByteSet(reinterpret_cast<void*>(destination), 0, pageSize);
33 return true;
34 }
35 const size_t remaining = size - location;
36 const size_t amount = remaining < pageSize ? remaining : pageSize;
37 const uint64_t extent = static_cast<uint64_t>(LITTLE_TO_HOST32(m_Dir.ExtentLocation_LE)) * 2048;
38 if (location > ~uint64_t(0) - extent ||
39 !m_pFs->m_pDisk->readInto(extent + location, reinterpret_cast<void*>(destination), amount))
40 return false;
41 ByteSet(reinterpret_cast<void*>(destination + amount), 0, pageSize - amount);
42 return true;
43}
44
45bool Iso9660File::prepareWrite(uint64_t, uint64_t) {
46 SYSCALL_ERROR(ReadOnlyFilesystem);
47 return false;
48}
49
51 SYSCALL_ERROR(ReadOnlyFilesystem);
52 return false;
53}
54
55uintptr_t Iso9660File::readBlock(uint64_t location) {
56 return reinterpret_cast<Iso9660Filesystem*>(m_pFilesystem)->readBlock(this, location);
57}
58
59bool Iso9660File::pinBlock(uint64_t location) {
60 const uint64_t diskLocation =
61 (static_cast<uint64_t>(LITTLE_TO_HOST32(m_Dir.ExtentLocation_LE)) * 2048) + location;
62 return m_pFs->m_pDisk->pin(diskLocation);
63}
64
65void Iso9660File::unpinBlock(uint64_t location) {
66 const uint64_t diskLocation =
67 (static_cast<uint64_t>(LITTLE_TO_HOST32(m_Dir.ExtentLocation_LE)) * 2048) + location;
68 m_pFs->m_pDisk->unpin(diskLocation);
69}
virtual void unpin(uint64_t location)=0
virtual MUST_USE_RESULT bool readInto(uint64_t location, void *buffer, size_t length)
Definition Disk.cc:219
virtual MUST_USE_RESULT bool pin(uint64_t location)=0
Pins a cache page.
uintptr_t readBlock(uint64_t location) override
void unpinBlock(uint64_t location) override
bool pinBlock(uint64_t location) override
bool readPage(uint64_t location, uintptr_t destination) override
bool prepareSharedMapping(size_t offset, size_t length) override
static constexpr size_t getPageSize() noexcept
Definition TargetInfo.h:40