The Pedigree Project 0.1
DiskImage.h
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#ifndef DISKIMAGE_H
21#define DISKIMAGE_H
22
23#include "pedigree/kernel/machine/Disk.h"
24#include "pedigree/kernel/process/Mutex.h"
25#include "pedigree/kernel/utilities/Cache.h"
26
28class DiskImage : public Disk {
29 public:
30 DiskImage() : Disk(), m_pBase(0), m_nSize(0), m_Cache(), m_CacheLock(), m_nAlignPoints(0) {}
31
32 virtual ~DiskImage();
33
34 bool initialise();
35
36 virtual void getName(String& str) {
37 str.assign("Hosted disk image");
38 }
39
40 virtual void dump(String& str) {
41 str.assign("Hosted disk image");
42 }
43
44 virtual BufferView read(uint64_t location);
45
46 virtual size_t getSize() const;
47
48 virtual size_t getBlockSize() const {
49 return 0x10000;
50 }
51
52 virtual void align(uint64_t location);
53
54 virtual bool pin(uint64_t location);
55
56 virtual void unpin(uint64_t location);
57
58 private:
59 uint64_t getAlignmentPoint(uint64_t location) const;
60 uint64_t getPageLocation(uint64_t location) const;
61
62 void* m_pBase;
63 size_t m_nSize;
64
65 Cache m_Cache;
66 Mutex m_CacheLock;
67 uint64_t m_AlignPoints[8];
68 size_t m_nAlignPoints;
69};
70
71#endif
Definition Cache.h:207
virtual BufferView read(uint64_t location)
Definition DiskImage.cc:62
virtual void getName(String &str)
Definition DiskImage.h:36
virtual void align(uint64_t location)
Sets the page boundary alignment after a specific location on the disk.
Definition DiskImage.cc:105
virtual size_t getBlockSize() const
Gets the preferred I/O extent of the disk.
Definition DiskImage.h:48
virtual size_t getSize() const
Gets the size of the disk.
Definition DiskImage.cc:101
virtual bool pin(uint64_t location)
Pins a cache page.
Definition DiskImage.cc:117
virtual void dump(String &str)
Definition DiskImage.h:40
virtual void unpin(uint64_t location)
Definition DiskImage.cc:125
Definition Disk.h:35
Definition Mutex.h:56