1*57696d54SAkhilesh Sanikop /*
2*57696d54SAkhilesh Sanikop MBRPart class, part of GPT fdisk program family.
3*57696d54SAkhilesh Sanikop Copyright (C) 2011 Roderick W. Smith
4*57696d54SAkhilesh Sanikop
5*57696d54SAkhilesh Sanikop This program is free software; you can redistribute it and/or modify
6*57696d54SAkhilesh Sanikop it under the terms of the GNU General Public License as published by
7*57696d54SAkhilesh Sanikop the Free Software Foundation; either version 2 of the License, or
8*57696d54SAkhilesh Sanikop (at your option) any later version.
9*57696d54SAkhilesh Sanikop
10*57696d54SAkhilesh Sanikop This program is distributed in the hope that it will be useful,
11*57696d54SAkhilesh Sanikop but WITHOUT ANY WARRANTY; without even the implied warranty of
12*57696d54SAkhilesh Sanikop MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13*57696d54SAkhilesh Sanikop GNU General Public License for more details.
14*57696d54SAkhilesh Sanikop
15*57696d54SAkhilesh Sanikop You should have received a copy of the GNU General Public License along
16*57696d54SAkhilesh Sanikop with this program; if not, write to the Free Software Foundation, Inc.,
17*57696d54SAkhilesh Sanikop 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
18*57696d54SAkhilesh Sanikop */
19*57696d54SAkhilesh Sanikop
20*57696d54SAkhilesh Sanikop #define __STDC_LIMIT_MACROS
21*57696d54SAkhilesh Sanikop #define __STDC_CONSTANT_MACROS
22*57696d54SAkhilesh Sanikop
23*57696d54SAkhilesh Sanikop #include <stddef.h>
24*57696d54SAkhilesh Sanikop #include <stdint.h>
25*57696d54SAkhilesh Sanikop #include <iostream>
26*57696d54SAkhilesh Sanikop #include "support.h"
27*57696d54SAkhilesh Sanikop #include "mbrpart.h"
28*57696d54SAkhilesh Sanikop
29*57696d54SAkhilesh Sanikop using namespace std;
30*57696d54SAkhilesh Sanikop
31*57696d54SAkhilesh Sanikop uint32_t MBRPart::numHeads = MAX_HEADS;
32*57696d54SAkhilesh Sanikop uint32_t MBRPart::numSecspTrack = MAX_SECSPERTRACK;
33*57696d54SAkhilesh Sanikop uint64_t MBRPart::diskSize = 0;
34*57696d54SAkhilesh Sanikop uint32_t MBRPart::blockSize = 512;
35*57696d54SAkhilesh Sanikop int MBRPart::numInstances = 0;
36*57696d54SAkhilesh Sanikop
MBRPart()37*57696d54SAkhilesh Sanikop MBRPart::MBRPart() {
38*57696d54SAkhilesh Sanikop int i;
39*57696d54SAkhilesh Sanikop
40*57696d54SAkhilesh Sanikop status = 0;
41*57696d54SAkhilesh Sanikop for (i = 0; i < 3; i++) {
42*57696d54SAkhilesh Sanikop firstSector[i] = 0;
43*57696d54SAkhilesh Sanikop lastSector[i] = 0;
44*57696d54SAkhilesh Sanikop } // for
45*57696d54SAkhilesh Sanikop partitionType = 0x00;
46*57696d54SAkhilesh Sanikop firstLBA = 0;
47*57696d54SAkhilesh Sanikop lengthLBA = 0;
48*57696d54SAkhilesh Sanikop includeAs = NONE;
49*57696d54SAkhilesh Sanikop canBePrimary = 0;
50*57696d54SAkhilesh Sanikop canBeLogical = 0;
51*57696d54SAkhilesh Sanikop if (numInstances == 0) {
52*57696d54SAkhilesh Sanikop numHeads = MAX_HEADS;
53*57696d54SAkhilesh Sanikop numSecspTrack = MAX_SECSPERTRACK;
54*57696d54SAkhilesh Sanikop diskSize = 0;
55*57696d54SAkhilesh Sanikop blockSize = 512;
56*57696d54SAkhilesh Sanikop } // if
57*57696d54SAkhilesh Sanikop numInstances++;
58*57696d54SAkhilesh Sanikop }
59*57696d54SAkhilesh Sanikop
MBRPart(const MBRPart & orig)60*57696d54SAkhilesh Sanikop MBRPart::MBRPart(const MBRPart& orig) {
61*57696d54SAkhilesh Sanikop numInstances++;
62*57696d54SAkhilesh Sanikop operator=(orig);
63*57696d54SAkhilesh Sanikop }
64*57696d54SAkhilesh Sanikop
~MBRPart()65*57696d54SAkhilesh Sanikop MBRPart::~MBRPart() {
66*57696d54SAkhilesh Sanikop numInstances--;
67*57696d54SAkhilesh Sanikop }
68*57696d54SAkhilesh Sanikop
operator =(const MBRPart & orig)69*57696d54SAkhilesh Sanikop MBRPart& MBRPart::operator=(const MBRPart& orig) {
70*57696d54SAkhilesh Sanikop int i;
71*57696d54SAkhilesh Sanikop
72*57696d54SAkhilesh Sanikop status = orig.status;
73*57696d54SAkhilesh Sanikop for (i = 0; i < 3; i++) {
74*57696d54SAkhilesh Sanikop firstSector[i] = orig.firstSector[i];
75*57696d54SAkhilesh Sanikop lastSector[i] = orig.lastSector[i];
76*57696d54SAkhilesh Sanikop } // for
77*57696d54SAkhilesh Sanikop partitionType = orig.partitionType;
78*57696d54SAkhilesh Sanikop firstLBA = orig.firstLBA;
79*57696d54SAkhilesh Sanikop lengthLBA = orig.lengthLBA;
80*57696d54SAkhilesh Sanikop includeAs = orig.includeAs;
81*57696d54SAkhilesh Sanikop canBePrimary = orig.canBePrimary;
82*57696d54SAkhilesh Sanikop canBeLogical = orig.canBeLogical;
83*57696d54SAkhilesh Sanikop return *this;
84*57696d54SAkhilesh Sanikop } // MBRPart::operator=(const MBRPart& orig)
85*57696d54SAkhilesh Sanikop
86*57696d54SAkhilesh Sanikop // Set partition data from packed MBRRecord structure.
operator =(const struct MBRRecord & orig)87*57696d54SAkhilesh Sanikop MBRPart& MBRPart::operator=(const struct MBRRecord& orig) {
88*57696d54SAkhilesh Sanikop int i;
89*57696d54SAkhilesh Sanikop
90*57696d54SAkhilesh Sanikop status = orig.status;
91*57696d54SAkhilesh Sanikop for (i = 0; i < 3; i++) {
92*57696d54SAkhilesh Sanikop firstSector[i] = orig.firstSector[i];
93*57696d54SAkhilesh Sanikop lastSector[i] = orig.lastSector[i];
94*57696d54SAkhilesh Sanikop } // for
95*57696d54SAkhilesh Sanikop partitionType = orig.partitionType;
96*57696d54SAkhilesh Sanikop firstLBA = orig.firstLBA;
97*57696d54SAkhilesh Sanikop lengthLBA = orig.lengthLBA;
98*57696d54SAkhilesh Sanikop if (lengthLBA > 0)
99*57696d54SAkhilesh Sanikop includeAs = PRIMARY;
100*57696d54SAkhilesh Sanikop else
101*57696d54SAkhilesh Sanikop includeAs = NONE;
102*57696d54SAkhilesh Sanikop return *this;
103*57696d54SAkhilesh Sanikop } // MBRPart::operator=(const struct MBRRecord& orig)
104*57696d54SAkhilesh Sanikop
105*57696d54SAkhilesh Sanikop // Compare the values, and return a bool result.
106*57696d54SAkhilesh Sanikop // Because this is intended for sorting and a lengthLBA value of 0 denotes
107*57696d54SAkhilesh Sanikop // a partition that's not in use and so that should be sorted upwards,
108*57696d54SAkhilesh Sanikop // we return the opposite of the usual arithmetic result when either
109*57696d54SAkhilesh Sanikop // lengthLBA value is 0.
operator <(const MBRPart & other) const110*57696d54SAkhilesh Sanikop bool MBRPart::operator<(const MBRPart &other) const {
111*57696d54SAkhilesh Sanikop if (lengthLBA && other.lengthLBA)
112*57696d54SAkhilesh Sanikop return (firstLBA < other.firstLBA);
113*57696d54SAkhilesh Sanikop else
114*57696d54SAkhilesh Sanikop return (other.firstLBA < firstLBA);
115*57696d54SAkhilesh Sanikop } // operator<()
116*57696d54SAkhilesh Sanikop
117*57696d54SAkhilesh Sanikop /**************************************************
118*57696d54SAkhilesh Sanikop * *
119*57696d54SAkhilesh Sanikop * Set information on partitions or disks without *
120*57696d54SAkhilesh Sanikop * interacting with the user.... *
121*57696d54SAkhilesh Sanikop * *
122*57696d54SAkhilesh Sanikop **************************************************/
123*57696d54SAkhilesh Sanikop
SetGeometry(uint32_t heads,uint32_t sectors,uint64_t ds,uint32_t bs)124*57696d54SAkhilesh Sanikop void MBRPart::SetGeometry(uint32_t heads, uint32_t sectors, uint64_t ds, uint32_t bs) {
125*57696d54SAkhilesh Sanikop numHeads = heads;
126*57696d54SAkhilesh Sanikop numSecspTrack = sectors;
127*57696d54SAkhilesh Sanikop diskSize = ds;
128*57696d54SAkhilesh Sanikop blockSize = bs;
129*57696d54SAkhilesh Sanikop } // MBRPart::SetGeometry
130*57696d54SAkhilesh Sanikop
131*57696d54SAkhilesh Sanikop // Empty the partition (zero out all values).
Empty(void)132*57696d54SAkhilesh Sanikop void MBRPart::Empty(void) {
133*57696d54SAkhilesh Sanikop status = UINT8_C(0);
134*57696d54SAkhilesh Sanikop firstSector[0] = UINT8_C(0);
135*57696d54SAkhilesh Sanikop firstSector[1] = UINT8_C(0);
136*57696d54SAkhilesh Sanikop firstSector[2] = UINT8_C(0);
137*57696d54SAkhilesh Sanikop partitionType = UINT8_C(0);
138*57696d54SAkhilesh Sanikop lastSector[0] = UINT8_C(0);
139*57696d54SAkhilesh Sanikop lastSector[1] = UINT8_C(0);
140*57696d54SAkhilesh Sanikop lastSector[2] = UINT8_C(0);
141*57696d54SAkhilesh Sanikop firstLBA = UINT32_C(0);
142*57696d54SAkhilesh Sanikop lengthLBA = UINT32_C(0);
143*57696d54SAkhilesh Sanikop includeAs = NONE;
144*57696d54SAkhilesh Sanikop } // MBRPart::Empty()
145*57696d54SAkhilesh Sanikop
146*57696d54SAkhilesh Sanikop // Sets the type code, but silently refuses to change it to an extended type
147*57696d54SAkhilesh Sanikop // code.
148*57696d54SAkhilesh Sanikop // Returns 1 on success, 0 on failure (extended type code)
SetType(uint8_t typeCode,int isExtended)149*57696d54SAkhilesh Sanikop int MBRPart::SetType(uint8_t typeCode, int isExtended) {
150*57696d54SAkhilesh Sanikop int allOK = 0;
151*57696d54SAkhilesh Sanikop
152*57696d54SAkhilesh Sanikop if ((isExtended == 1) || ((typeCode != 0x05) && (typeCode != 0x0f) && (typeCode != 0x85))) {
153*57696d54SAkhilesh Sanikop partitionType = typeCode;
154*57696d54SAkhilesh Sanikop allOK = 1;
155*57696d54SAkhilesh Sanikop } // if
156*57696d54SAkhilesh Sanikop return allOK;
157*57696d54SAkhilesh Sanikop } // MBRPart::SetType()
158*57696d54SAkhilesh Sanikop
SetStartLBA(uint64_t start)159*57696d54SAkhilesh Sanikop void MBRPart::SetStartLBA(uint64_t start) {
160*57696d54SAkhilesh Sanikop if (start > UINT32_MAX)
161*57696d54SAkhilesh Sanikop cerr << "Partition start out of range! Continuing, but problems now likely!\n";
162*57696d54SAkhilesh Sanikop firstLBA = (uint32_t) start;
163*57696d54SAkhilesh Sanikop RecomputeCHS();
164*57696d54SAkhilesh Sanikop } // MBRPart::SetStartLBA()
165*57696d54SAkhilesh Sanikop
SetLengthLBA(uint64_t length)166*57696d54SAkhilesh Sanikop void MBRPart::SetLengthLBA(uint64_t length) {
167*57696d54SAkhilesh Sanikop if (length > UINT32_MAX)
168*57696d54SAkhilesh Sanikop cerr << "Partition length out of range! Continuing, but problems now likely!\n";
169*57696d54SAkhilesh Sanikop lengthLBA = (uint32_t) length;
170*57696d54SAkhilesh Sanikop RecomputeCHS();
171*57696d54SAkhilesh Sanikop } // MBRPart::SetLengthLBA()
172*57696d54SAkhilesh Sanikop
173*57696d54SAkhilesh Sanikop // Set the start point and length of the partition. This function takes LBA
174*57696d54SAkhilesh Sanikop // values, sets them directly, and sets the CHS values based on the LBA
175*57696d54SAkhilesh Sanikop // values and the current geometry settings.
SetLocation(uint64_t start,uint64_t length)176*57696d54SAkhilesh Sanikop void MBRPart::SetLocation(uint64_t start, uint64_t length) {
177*57696d54SAkhilesh Sanikop int validCHS;
178*57696d54SAkhilesh Sanikop
179*57696d54SAkhilesh Sanikop if ((start > UINT32_MAX) || (length > UINT32_MAX)) {
180*57696d54SAkhilesh Sanikop cerr << "Partition values out of range in MBRPart::SetLocation()!\n"
181*57696d54SAkhilesh Sanikop << "Continuing, but strange problems are now likely!\n";
182*57696d54SAkhilesh Sanikop } // if
183*57696d54SAkhilesh Sanikop firstLBA = (uint32_t) start;
184*57696d54SAkhilesh Sanikop lengthLBA = (uint32_t) length;
185*57696d54SAkhilesh Sanikop validCHS = RecomputeCHS();
186*57696d54SAkhilesh Sanikop
187*57696d54SAkhilesh Sanikop // If this is a complete 0xEE protective MBR partition, max out its
188*57696d54SAkhilesh Sanikop // CHS last sector value, as per the GPT spec. (Set to 0xffffff,
189*57696d54SAkhilesh Sanikop // although the maximum legal MBR value is 0xfeffff, which is
190*57696d54SAkhilesh Sanikop // actually what GNU Parted and Apple's Disk Utility use, in
191*57696d54SAkhilesh Sanikop // violation of the GPT spec.)
192*57696d54SAkhilesh Sanikop if ((partitionType == 0xEE) && (!validCHS) && (firstLBA == 1) &&
193*57696d54SAkhilesh Sanikop ((lengthLBA == diskSize - 1) || (lengthLBA == UINT32_MAX))) {
194*57696d54SAkhilesh Sanikop lastSector[0] = lastSector[1] = lastSector[2] = 0xFF;
195*57696d54SAkhilesh Sanikop } // if
196*57696d54SAkhilesh Sanikop } // MBRPart::SetLocation()
197*57696d54SAkhilesh Sanikop
198*57696d54SAkhilesh Sanikop // Store the MBR data in the packed structure used for disk I/O...
StoreInStruct(MBRRecord * theStruct)199*57696d54SAkhilesh Sanikop void MBRPart::StoreInStruct(MBRRecord* theStruct) {
200*57696d54SAkhilesh Sanikop int i;
201*57696d54SAkhilesh Sanikop
202*57696d54SAkhilesh Sanikop theStruct->firstLBA = firstLBA;
203*57696d54SAkhilesh Sanikop theStruct->lengthLBA = lengthLBA;
204*57696d54SAkhilesh Sanikop theStruct->partitionType = partitionType;
205*57696d54SAkhilesh Sanikop theStruct->status = status;
206*57696d54SAkhilesh Sanikop for (i = 0; i < 3; i++) {
207*57696d54SAkhilesh Sanikop theStruct->firstSector[i] = firstSector[i];
208*57696d54SAkhilesh Sanikop theStruct->lastSector[i] = lastSector[i];
209*57696d54SAkhilesh Sanikop } // for
210*57696d54SAkhilesh Sanikop } // MBRPart::StoreInStruct()
211*57696d54SAkhilesh Sanikop
212*57696d54SAkhilesh Sanikop /**********************************************
213*57696d54SAkhilesh Sanikop * *
214*57696d54SAkhilesh Sanikop * Get information on partitions or disks.... *
215*57696d54SAkhilesh Sanikop * *
216*57696d54SAkhilesh Sanikop **********************************************/
217*57696d54SAkhilesh Sanikop
218*57696d54SAkhilesh Sanikop // Returns the last LBA value. Note that this can theoretically be a 33-bit
219*57696d54SAkhilesh Sanikop // value, so we return a 64-bit value. If lengthLBA == 0, returns 0, even if
220*57696d54SAkhilesh Sanikop // firstLBA is non-0.
GetLastLBA(void) const221*57696d54SAkhilesh Sanikop uint64_t MBRPart::GetLastLBA(void) const {
222*57696d54SAkhilesh Sanikop if (lengthLBA > 0)
223*57696d54SAkhilesh Sanikop return (uint64_t) firstLBA + (uint64_t) lengthLBA - UINT64_C(1);
224*57696d54SAkhilesh Sanikop else
225*57696d54SAkhilesh Sanikop return 0;
226*57696d54SAkhilesh Sanikop } // MBRPart::GetLastLBA()
227*57696d54SAkhilesh Sanikop
228*57696d54SAkhilesh Sanikop // Returns 1 if other overlaps with the current partition, 0 if they don't
229*57696d54SAkhilesh Sanikop // overlap
DoTheyOverlap(const MBRPart & other)230*57696d54SAkhilesh Sanikop int MBRPart::DoTheyOverlap (const MBRPart& other) {
231*57696d54SAkhilesh Sanikop return lengthLBA && other.lengthLBA &&
232*57696d54SAkhilesh Sanikop (firstLBA <= other.GetLastLBA()) != (GetLastLBA() < other.firstLBA);
233*57696d54SAkhilesh Sanikop } // MBRPart::DoTheyOverlap()
234*57696d54SAkhilesh Sanikop
235*57696d54SAkhilesh Sanikop /*************************************************
236*57696d54SAkhilesh Sanikop * *
237*57696d54SAkhilesh Sanikop * Adjust information on partitions or disks.... *
238*57696d54SAkhilesh Sanikop * *
239*57696d54SAkhilesh Sanikop *************************************************/
240*57696d54SAkhilesh Sanikop
241*57696d54SAkhilesh Sanikop // Recompute the CHS values for the start and end points.
242*57696d54SAkhilesh Sanikop // Returns 1 if both computed values are within the range
243*57696d54SAkhilesh Sanikop // that can be expressed by that CHS, 0 otherwise.
RecomputeCHS(void)244*57696d54SAkhilesh Sanikop int MBRPart::RecomputeCHS(void) {
245*57696d54SAkhilesh Sanikop int retval = 1;
246*57696d54SAkhilesh Sanikop
247*57696d54SAkhilesh Sanikop if (lengthLBA > 0) {
248*57696d54SAkhilesh Sanikop retval = LBAtoCHS(firstLBA, firstSector);
249*57696d54SAkhilesh Sanikop retval *= LBAtoCHS(firstLBA + lengthLBA - 1, lastSector);
250*57696d54SAkhilesh Sanikop } // if
251*57696d54SAkhilesh Sanikop return retval;
252*57696d54SAkhilesh Sanikop } // MBRPart::RecomputeCHS()
253*57696d54SAkhilesh Sanikop
254*57696d54SAkhilesh Sanikop // Converts 32-bit LBA value to MBR-style CHS value. Returns 1 if conversion
255*57696d54SAkhilesh Sanikop // was within the range that can be expressed by CHS (including 0, for an
256*57696d54SAkhilesh Sanikop // empty partition), 0 if the value is outside that range, and -1 if chs is
257*57696d54SAkhilesh Sanikop // invalid.
LBAtoCHS(uint32_t lba,uint8_t * chs)258*57696d54SAkhilesh Sanikop int MBRPart::LBAtoCHS(uint32_t lba, uint8_t * chs) {
259*57696d54SAkhilesh Sanikop uint64_t cylinder, head, sector; // all numbered from 0
260*57696d54SAkhilesh Sanikop uint64_t remainder;
261*57696d54SAkhilesh Sanikop int retval = 1;
262*57696d54SAkhilesh Sanikop int done = 0;
263*57696d54SAkhilesh Sanikop
264*57696d54SAkhilesh Sanikop if (chs != NULL) {
265*57696d54SAkhilesh Sanikop // Special case: In case of 0 LBA value, zero out CHS values....
266*57696d54SAkhilesh Sanikop if (lba == 0) {
267*57696d54SAkhilesh Sanikop chs[0] = chs[1] = chs[2] = UINT8_C(0);
268*57696d54SAkhilesh Sanikop done = 1;
269*57696d54SAkhilesh Sanikop } // if
270*57696d54SAkhilesh Sanikop // If LBA value is too large for CHS, max out CHS values....
271*57696d54SAkhilesh Sanikop if ((!done) && (lba >= (numHeads * numSecspTrack * MAX_CYLINDERS))) {
272*57696d54SAkhilesh Sanikop chs[0] = 254;
273*57696d54SAkhilesh Sanikop chs[1] = chs[2] = 255;
274*57696d54SAkhilesh Sanikop done = 1;
275*57696d54SAkhilesh Sanikop retval = 0;
276*57696d54SAkhilesh Sanikop } // if
277*57696d54SAkhilesh Sanikop // If neither of the above applies, compute CHS values....
278*57696d54SAkhilesh Sanikop if (!done) {
279*57696d54SAkhilesh Sanikop cylinder = lba / (numHeads * numSecspTrack);
280*57696d54SAkhilesh Sanikop remainder = lba - (cylinder * numHeads * numSecspTrack);
281*57696d54SAkhilesh Sanikop head = remainder / numSecspTrack;
282*57696d54SAkhilesh Sanikop remainder -= head * numSecspTrack;
283*57696d54SAkhilesh Sanikop sector = remainder;
284*57696d54SAkhilesh Sanikop if (head < numHeads)
285*57696d54SAkhilesh Sanikop chs[0] = (uint8_t) head;
286*57696d54SAkhilesh Sanikop else
287*57696d54SAkhilesh Sanikop retval = 0;
288*57696d54SAkhilesh Sanikop if (sector < numSecspTrack) {
289*57696d54SAkhilesh Sanikop chs[1] = (uint8_t) ((sector + 1) + (cylinder >> 8) * 64);
290*57696d54SAkhilesh Sanikop chs[2] = (uint8_t) (cylinder & UINT32_C(0xFF));
291*57696d54SAkhilesh Sanikop } else {
292*57696d54SAkhilesh Sanikop retval = 0;
293*57696d54SAkhilesh Sanikop } // if/else
294*57696d54SAkhilesh Sanikop } // if value is expressible and non-0
295*57696d54SAkhilesh Sanikop } else { // Invalid (NULL) chs pointer
296*57696d54SAkhilesh Sanikop retval = -1;
297*57696d54SAkhilesh Sanikop } // if CHS pointer valid
298*57696d54SAkhilesh Sanikop return (retval);
299*57696d54SAkhilesh Sanikop } // MBRPart::LBAtoCHS()
300*57696d54SAkhilesh Sanikop
301*57696d54SAkhilesh Sanikop // Reverses the byte order, but only if we're on a big-endian platform.
302*57696d54SAkhilesh Sanikop // Note that most data come in 8-bit structures, so don't need reversing;
303*57696d54SAkhilesh Sanikop // only the LBA data needs to be reversed....
ReverseByteOrder(void)304*57696d54SAkhilesh Sanikop void MBRPart::ReverseByteOrder(void) {
305*57696d54SAkhilesh Sanikop if (IsLittleEndian() == 0) {
306*57696d54SAkhilesh Sanikop ReverseBytes(&firstLBA, 4);
307*57696d54SAkhilesh Sanikop ReverseBytes(&lengthLBA, 4);
308*57696d54SAkhilesh Sanikop } // if
309*57696d54SAkhilesh Sanikop } // MBRPart::ReverseByteOrder()
310*57696d54SAkhilesh Sanikop
311*57696d54SAkhilesh Sanikop /**************************
312*57696d54SAkhilesh Sanikop * *
313*57696d54SAkhilesh Sanikop * User I/O functions.... *
314*57696d54SAkhilesh Sanikop * *
315*57696d54SAkhilesh Sanikop **************************/
316*57696d54SAkhilesh Sanikop
317*57696d54SAkhilesh Sanikop // Show MBR data. Should update canBeLogical flags before calling.
318*57696d54SAkhilesh Sanikop // If isGpt == 1, omits the "can be logical" and "can be primary" columns.
ShowData(int isGpt)319*57696d54SAkhilesh Sanikop void MBRPart::ShowData(int isGpt) {
320*57696d54SAkhilesh Sanikop char bootCode = ' ';
321*57696d54SAkhilesh Sanikop
322*57696d54SAkhilesh Sanikop if (status & 0x80) // it's bootable
323*57696d54SAkhilesh Sanikop bootCode = '*';
324*57696d54SAkhilesh Sanikop cout.fill(' ');
325*57696d54SAkhilesh Sanikop cout << bootCode << " ";
326*57696d54SAkhilesh Sanikop cout.width(13);
327*57696d54SAkhilesh Sanikop cout << firstLBA;
328*57696d54SAkhilesh Sanikop cout.width(13);
329*57696d54SAkhilesh Sanikop cout << GetLastLBA() << " ";
330*57696d54SAkhilesh Sanikop switch (includeAs) {
331*57696d54SAkhilesh Sanikop case PRIMARY:
332*57696d54SAkhilesh Sanikop cout << "primary";
333*57696d54SAkhilesh Sanikop break;
334*57696d54SAkhilesh Sanikop case LOGICAL:
335*57696d54SAkhilesh Sanikop cout << "logical";
336*57696d54SAkhilesh Sanikop break;
337*57696d54SAkhilesh Sanikop case NONE:
338*57696d54SAkhilesh Sanikop cout << "omitted";
339*57696d54SAkhilesh Sanikop break;
340*57696d54SAkhilesh Sanikop default:
341*57696d54SAkhilesh Sanikop cout << "error ";
342*57696d54SAkhilesh Sanikop break;
343*57696d54SAkhilesh Sanikop } // switch
344*57696d54SAkhilesh Sanikop cout.width(7);
345*57696d54SAkhilesh Sanikop if (!isGpt) {
346*57696d54SAkhilesh Sanikop if (canBeLogical)
347*57696d54SAkhilesh Sanikop cout << " Y ";
348*57696d54SAkhilesh Sanikop else
349*57696d54SAkhilesh Sanikop cout << " ";
350*57696d54SAkhilesh Sanikop if (canBePrimary)
351*57696d54SAkhilesh Sanikop cout << " Y ";
352*57696d54SAkhilesh Sanikop else
353*57696d54SAkhilesh Sanikop cout << " ";
354*57696d54SAkhilesh Sanikop } // if
355*57696d54SAkhilesh Sanikop cout << "0x";
356*57696d54SAkhilesh Sanikop cout.width(2);
357*57696d54SAkhilesh Sanikop cout.fill('0');
358*57696d54SAkhilesh Sanikop cout << hex << (int) partitionType << dec << "\n";
359*57696d54SAkhilesh Sanikop } // MBRPart::ShowData()
360