The Pedigree Project 0.1
LoDisk.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 LODISK_H
21#define LODISK_H
22
23#include "pedigree/kernel/compiler.h"
24#include "pedigree/kernel/machine/Disk.h"
25#include "pedigree/kernel/process/Mutex.h"
26#include "pedigree/kernel/processor/MemoryRegion.h"
27#include "pedigree/kernel/processor/types.h"
28#include "pedigree/kernel/utilities/Cache.h"
29#include "pedigree/kernel/utilities/String.h"
30
31#include "modules/system/vfs/File.h"
32
35
43class EXPORTED_PUBLIC FileDisk : public Disk {
44 public:
49 RamOnly = 0,
50
52 Standard
53 };
54
55 FileDisk() = delete;
56 FileDisk(String file, AccessType mode = Standard);
57 virtual ~FileDisk();
58
59 virtual void getName(String& str) {
60 if (m_pFile)
61 str = m_pFile->getName();
62 else
63 str = String("FileDisk");
64 }
65
66 bool initialise();
67
68 virtual BufferView read(uint64_t location);
69 virtual void write(uint64_t location);
70 virtual void align(uint64_t location);
71 virtual size_t getSize() const;
72 virtual bool pin(uint64_t location);
73 virtual void unpin(uint64_t location);
74
80 virtual bool cacheIsCritical() {
81 return true;
82 }
83
84 private:
85 FileDisk(const FileDisk&);
86 FileDisk& operator=(const FileDisk&);
87
90
93
96
97 Cache m_Cache;
98
99 // Our region of memory
100 MemoryRegion m_MemRegion;
101
102 // Mutex to ensure only one request runs at a time
103 Mutex m_ReqMutex;
104
105 uint64_t m_AlignPoints[8];
106 size_t m_nAlignPoints;
107};
108
109#endif
Definition Cache.h:207
Definition Disk.h:35
virtual void align(uint64_t location)
Sets the page boundary alignment after a specific location on the disk.
Definition Disk.cc:342
virtual BufferView read(uint64_t location)
Definition Disk.cc:163
virtual size_t getSize() const
Gets the size of the disk.
Definition Disk.cc:344
virtual void unpin(uint64_t location)=0
virtual void write(uint64_t location)
Definition Disk.cc:340
virtual MUST_USE_RESULT bool pin(uint64_t location)=0
Pins a cache page.
virtual bool cacheIsCritical()
Definition LoDisk.h:80
virtual void getName(String &str)
Definition LoDisk.h:59
bool m_bVfsReference
Whether this disk owns a persistent VFS reference to m_pFile.
Definition LoDisk.h:92
AccessType
Definition LoDisk.h:45
AccessType m_Mode
Access mode.
Definition LoDisk.h:95
File * m_pFile
File we're using as a disk.
Definition LoDisk.h:89
Definition File.h:75
Special memory entity in the kernel's virtual address space.
Definition Mutex.h:56