The Pedigree Project  0.1
Partition.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 PARTITION_H
21 #define PARTITION_H
22 
23 #include "pedigree/kernel/machine/Disk.h"
24 #include "pedigree/kernel/processor/types.h"
25 #include "pedigree/kernel/utilities/StaticString.h"
26 #include "pedigree/kernel/utilities/String.h"
27 
31 class Partition : public Disk
32 {
33  public:
34  Partition(String type, uint64_t start, uint64_t length);
35  virtual ~Partition();
36 
37  virtual void getName(String &str)
38  {
39  NormalStaticString str2;
40  str2 += m_Type;
41  str2 += " partition";
42  str = str2;
43  }
44 
45  virtual void dump(String &str)
46  {
47  LargeStaticString str2;
48  str2 += m_Type;
49  str2 += " partition at 0x";
50  str2.append(m_Start, 16);
51  str2 += "-";
52  str2.append(m_Start + m_Length, 16);
53  str = str2;
54  }
55 
56  virtual uintptr_t read(uint64_t location)
57  {
58  // Ensure the read does not begin past the end of our partition
59  if (location > m_Length)
60  return 0;
61  else if ((location + 0x1000) > m_Length)
62  return 0;
63 
64  Disk *pParent = static_cast<Disk *>(getParent());
65 
66  if (!m_bAligned)
67  {
68  m_bAligned = true;
69  // Ensure that we get blocks aligned on our start position (which is
70  // quite likely to not be on a 4096-byte boundary).
71  pParent->align(m_Start);
72  }
73 
74  return pParent->read(location + m_Start);
75  }
76 
77  virtual void write(uint64_t location)
78  {
79  // Ensure the read does not begin past the end of our partition
80  if (location > m_Length)
81  return;
82  else if ((location + 0x1000) > m_Length)
83  return;
84 
85  Disk *pParent = static_cast<Disk *>(getParent());
86 
87  if (!m_bAligned)
88  {
89  m_bAligned = true;
90  // Ensure that we get blocks aligned on our start position (which is
91  // quite likely to not be on a 4096-byte boundary).
92  pParent->align(m_Start);
93  }
94 
95  pParent->write(location + m_Start);
96  }
97 
98  virtual size_t getSize() const
99  {
100  return getLength();
101  }
102 
103  virtual size_t getBlockSize() const
104  {
105  const Disk *pParent = static_cast<const Disk *>(getParent());
106  return pParent->getBlockSize();
107  }
108 
110  uint64_t getStart();
111 
113  uint64_t getLength() const
114  {
115  return m_Length;
116  }
117 
120  {
121  return m_Type;
122  }
123 
124  private:
125  String m_Type;
126  uint64_t m_Start;
127  uint64_t m_Length;
128  bool m_bAligned;
129 };
130 
131 #endif
uint64_t getLength() const
Definition: Partition.h:113
Definition: String.h:49
virtual size_t getBlockSize() const
Gets the block size of the disk.
Definition: Partition.h:103
virtual void getName(String &str)
Definition: Partition.h:37
Definition: Disk.h:32
String getPartitionType()
Definition: Partition.h:119
virtual uintptr_t read(uint64_t location)
Definition: Disk.cc:56
virtual uintptr_t read(uint64_t location)
Definition: Partition.h:56
virtual size_t getBlockSize() const
Gets the block size of the disk.
Definition: Disk.cc:74
virtual void write(uint64_t location)
Definition: Disk.cc:61
virtual void write(uint64_t location)
Definition: Partition.h:77
uint64_t getStart()
Definition: Partition.cc:32
virtual void dump(String &str)
Definition: Partition.h:45
virtual size_t getSize() const
Gets the size of the disk.
Definition: Partition.h:98
virtual void align(uint64_t location)
Sets the page boundary alignment after a specific location on the disk.
Definition: Disk.cc:65
Device * getParent() const
Definition: Device.h:149