The Pedigree Project 0.1
Disk.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 MACHINE_DISK_H
21#define MACHINE_DISK_H
22
23#include "pedigree/kernel/compiler.h"
24#include "pedigree/kernel/machine/Device.h"
25#include "pedigree/kernel/machine/DiskPaging.h"
26#include "pedigree/kernel/machine/DiskView.h"
27#include "pedigree/kernel/processor/types.h"
28#include "pedigree/kernel/utilities/BufferView.h"
29
30class String;
31
35class EXPORTED_PUBLIC Disk : public Device {
36 public:
37 enum SubType { ATA = 0, ATAPI };
38
39 Disk();
40 Disk(Device* p);
41 virtual ~Disk();
42
43 virtual Disk* physicalDisk();
44 bool acquireUse(DiskUse& use);
45 uint32_t endpointId();
46
48 virtual bool getPartitionUuid(String& uuid) const;
49 virtual bool getPartitionLabel(String& label) const;
50
52 virtual PagingStatus preparePagingTransport(PagingTransport*& transport);
53
55 void retireEndpoint();
56 bool tryCloseEndpoint();
57 void reopenEndpoint();
58
59 protected:
60 void reserveEndpoint();
61 void publishEndpoint();
62
63 private:
64 DiskEndpoint* m_Endpoint;
65
66 public:
67 virtual Type getType();
68
69 virtual SubType getSubType();
70
71 virtual void getName(String& str);
72
73 virtual void dump(String& str);
74
94 virtual BufferView read(uint64_t location);
95
99 virtual DiskReadView readView(uint64_t location);
100 virtual DiskWriteView writeView(uint64_t location);
101
102 protected:
103 friend class DiskReadView;
104 // Acquisition runs inside the caller's endpoint admission and I/O termination scope.
105 virtual BufferView acquireView(uint64_t location, bool writable, uint64_t& token);
106 virtual void releaseView(uint64_t token, bool writable);
107
108 public:
116 MUST_USE_RESULT virtual bool readInto(uint64_t location, void* buffer, size_t length);
117 MUST_USE_RESULT virtual bool writeFrom(uint64_t location, const void* buffer, size_t length);
118
119 struct ReadBuffer {
120 uint64_t location;
121 void* buffer;
122 size_t length;
123 bool complete;
124 };
125 static constexpr size_t MaxReadBuffers = 32;
126 struct WriteBuffer {
127 uint64_t location;
128 const void* buffer;
129 size_t length;
130 bool complete;
132 physical_uintptr_t dmaPhysical = 0;
133 };
134 static constexpr size_t MaxWriteBuffers = 32;
140 MUST_USE_RESULT virtual bool writeFromBatch(WriteBuffer* buffers, size_t count);
141
149 MUST_USE_RESULT virtual bool readIntoBatch(ReadBuffer* buffers, size_t count);
150
157 MUST_USE_RESULT virtual bool syncData();
158
167 MUST_USE_RESULT bool readViews(uint64_t location, size_t length, BufferViewSequence& views);
168
170 void unpinViews(uint64_t location, BufferViewSequence& views);
171
179 virtual void write(uint64_t location);
180
192 virtual void align(uint64_t location);
193
200 virtual size_t getSize() const;
201
209 virtual size_t getBlockSize() const;
210
212 virtual size_t getNativeBlockSize() const;
213
227 MUST_USE_RESULT virtual bool pin(uint64_t location) = 0;
228
232 virtual void unpin(uint64_t location) = 0;
233
254 virtual bool cacheIsCritical();
255
266 virtual void flush(uint64_t location);
267
273 virtual bool sync(uint64_t location, bool async);
274
275 static constexpr size_t MaxSyncPages = 64;
276
278 MUST_USE_RESULT virtual bool syncPages(const uint64_t* locations, size_t count);
279
281 MUST_USE_RESULT virtual bool syncAll();
282
296 MUST_USE_RESULT virtual bool retireCachePage(uint64_t location);
297
300 MUST_USE_RESULT virtual bool zero(uint64_t location, size_t length);
301};
302
303#endif
virtual void dump(String &str)
Definition Device.h:261
@ Disk
A disk device - a block device in UNIX terms.
Definition Device.h:75
virtual void getName(String &str)
Definition Device.cc:130
virtual Type getType()
Definition Device.h:178
Definition Disk.h:35
virtual void unpin(uint64_t location)=0
virtual MUST_USE_RESULT bool pin(uint64_t location)=0
Pins a cache page.