xref: /aosp_15_r20/external/gptfdisk/bsd.cc (revision 57696d54d05c64fd1b1787f8371dbcf104911cfb)
1*57696d54SAkhilesh Sanikop /* bsd.cc -- Functions for loading and manipulating legacy BSD disklabel
2*57696d54SAkhilesh Sanikop    data. */
3*57696d54SAkhilesh Sanikop 
4*57696d54SAkhilesh Sanikop /* By Rod Smith, initial coding August, 2009 */
5*57696d54SAkhilesh Sanikop 
6*57696d54SAkhilesh Sanikop /* This program is copyright (c) 2009 by Roderick W. Smith. It is distributed
7*57696d54SAkhilesh Sanikop   under the terms of the GNU GPL version 2, as detailed in the COPYING file. */
8*57696d54SAkhilesh Sanikop 
9*57696d54SAkhilesh Sanikop #define __STDC_LIMIT_MACROS
10*57696d54SAkhilesh Sanikop #define __STDC_CONSTANT_MACROS
11*57696d54SAkhilesh Sanikop 
12*57696d54SAkhilesh Sanikop #include <stdio.h>
13*57696d54SAkhilesh Sanikop //#include <unistd.h>
14*57696d54SAkhilesh Sanikop #include <stdlib.h>
15*57696d54SAkhilesh Sanikop #include <stdint.h>
16*57696d54SAkhilesh Sanikop #include <fcntl.h>
17*57696d54SAkhilesh Sanikop #include <sys/stat.h>
18*57696d54SAkhilesh Sanikop #include <errno.h>
19*57696d54SAkhilesh Sanikop #include <iostream>
20*57696d54SAkhilesh Sanikop #include <string>
21*57696d54SAkhilesh Sanikop #include "support.h"
22*57696d54SAkhilesh Sanikop #include "bsd.h"
23*57696d54SAkhilesh Sanikop 
24*57696d54SAkhilesh Sanikop using namespace std;
25*57696d54SAkhilesh Sanikop 
26*57696d54SAkhilesh Sanikop 
BSDData(void)27*57696d54SAkhilesh Sanikop BSDData::BSDData(void) {
28*57696d54SAkhilesh Sanikop    state = unknown;
29*57696d54SAkhilesh Sanikop    signature = UINT32_C(0);
30*57696d54SAkhilesh Sanikop    signature2 = UINT32_C(0);
31*57696d54SAkhilesh Sanikop    sectorSize = 512;
32*57696d54SAkhilesh Sanikop    numParts = 0;
33*57696d54SAkhilesh Sanikop    labelFirstLBA = 0;
34*57696d54SAkhilesh Sanikop    labelLastLBA = 0;
35*57696d54SAkhilesh Sanikop    labelStart = LABEL_OFFSET1; // assume raw disk format
36*57696d54SAkhilesh Sanikop    partitions = NULL;
37*57696d54SAkhilesh Sanikop } // default constructor
38*57696d54SAkhilesh Sanikop 
~BSDData(void)39*57696d54SAkhilesh Sanikop BSDData::~BSDData(void) {
40*57696d54SAkhilesh Sanikop    delete[] partitions;
41*57696d54SAkhilesh Sanikop } // destructor
42*57696d54SAkhilesh Sanikop 
43*57696d54SAkhilesh Sanikop // Read BSD disklabel data from the specified device filename. This function
44*57696d54SAkhilesh Sanikop // just opens the device file and then calls an overloaded function to do
45*57696d54SAkhilesh Sanikop // the bulk of the work. Returns 1 on success, 0 on failure.
ReadBSDData(const string & device,uint64_t startSector,uint64_t endSector)46*57696d54SAkhilesh Sanikop int BSDData::ReadBSDData(const string & device, uint64_t startSector, uint64_t endSector) {
47*57696d54SAkhilesh Sanikop    int allOK;
48*57696d54SAkhilesh Sanikop    DiskIO myDisk;
49*57696d54SAkhilesh Sanikop 
50*57696d54SAkhilesh Sanikop    if (device != "") {
51*57696d54SAkhilesh Sanikop       if (myDisk.OpenForRead(device)) {
52*57696d54SAkhilesh Sanikop          allOK = ReadBSDData(&myDisk, startSector, endSector);
53*57696d54SAkhilesh Sanikop       } else {
54*57696d54SAkhilesh Sanikop          allOK = 0;
55*57696d54SAkhilesh Sanikop       } // if/else
56*57696d54SAkhilesh Sanikop 
57*57696d54SAkhilesh Sanikop       myDisk.Close();
58*57696d54SAkhilesh Sanikop    } else {
59*57696d54SAkhilesh Sanikop       allOK = 0;
60*57696d54SAkhilesh Sanikop    } // if/else
61*57696d54SAkhilesh Sanikop    return allOK;
62*57696d54SAkhilesh Sanikop } // BSDData::ReadBSDData() (device filename version)
63*57696d54SAkhilesh Sanikop 
64*57696d54SAkhilesh Sanikop // Load the BSD disklabel data from an already-opened disk
65*57696d54SAkhilesh Sanikop // file, starting with the specified sector number.
ReadBSDData(DiskIO * theDisk,uint64_t startSector,uint64_t endSector)66*57696d54SAkhilesh Sanikop int BSDData::ReadBSDData(DiskIO *theDisk, uint64_t startSector, uint64_t endSector) {
67*57696d54SAkhilesh Sanikop    int allOK;
68*57696d54SAkhilesh Sanikop    int i, foundSig = 0, bigEnd = 0;
69*57696d54SAkhilesh Sanikop    int relative = 0; // assume absolute partition sector numbering
70*57696d54SAkhilesh Sanikop    uint8_t buffer[4096]; // I/O buffer
71*57696d54SAkhilesh Sanikop    uint32_t realSig;
72*57696d54SAkhilesh Sanikop    uint32_t* temp32;
73*57696d54SAkhilesh Sanikop    uint16_t* temp16;
74*57696d54SAkhilesh Sanikop    BSDRecord* tempRecords;
75*57696d54SAkhilesh Sanikop    int offset[NUM_OFFSETS] = { LABEL_OFFSET1, LABEL_OFFSET2 };
76*57696d54SAkhilesh Sanikop 
77*57696d54SAkhilesh Sanikop    labelFirstLBA = startSector;
78*57696d54SAkhilesh Sanikop    labelLastLBA = endSector;
79*57696d54SAkhilesh Sanikop    offset[1] = theDisk->GetBlockSize();
80*57696d54SAkhilesh Sanikop 
81*57696d54SAkhilesh Sanikop    // Read 4096 bytes (eight 512-byte sectors or equivalent)
82*57696d54SAkhilesh Sanikop    // into memory; we'll extract data from this buffer.
83*57696d54SAkhilesh Sanikop    // (Done to work around FreeBSD limitation on size of reads
84*57696d54SAkhilesh Sanikop    // from block devices.)
85*57696d54SAkhilesh Sanikop    allOK = theDisk->Seek(startSector);
86*57696d54SAkhilesh Sanikop    if (allOK) allOK = theDisk->Read(buffer, 4096);
87*57696d54SAkhilesh Sanikop 
88*57696d54SAkhilesh Sanikop    // Do some strangeness to support big-endian architectures...
89*57696d54SAkhilesh Sanikop    bigEnd = (IsLittleEndian() == 0);
90*57696d54SAkhilesh Sanikop    realSig = BSD_SIGNATURE;
91*57696d54SAkhilesh Sanikop    if (bigEnd && allOK)
92*57696d54SAkhilesh Sanikop       ReverseBytes(&realSig, 4);
93*57696d54SAkhilesh Sanikop 
94*57696d54SAkhilesh Sanikop    // Look for the signature at any of two locations.
95*57696d54SAkhilesh Sanikop    // Note that the signature is repeated at both the original
96*57696d54SAkhilesh Sanikop    // offset and 132 bytes later, so we need two checks....
97*57696d54SAkhilesh Sanikop    if (allOK) {
98*57696d54SAkhilesh Sanikop       i = 0;
99*57696d54SAkhilesh Sanikop       do {
100*57696d54SAkhilesh Sanikop          temp32 = (uint32_t*) &buffer[offset[i]];
101*57696d54SAkhilesh Sanikop          signature = *temp32;
102*57696d54SAkhilesh Sanikop          if (signature == realSig) { // found first, look for second
103*57696d54SAkhilesh Sanikop             temp32 = (uint32_t*) &buffer[offset[i] + 132];
104*57696d54SAkhilesh Sanikop             signature2 = *temp32;
105*57696d54SAkhilesh Sanikop             if (signature2 == realSig) {
106*57696d54SAkhilesh Sanikop                foundSig = 1;
107*57696d54SAkhilesh Sanikop                labelStart = offset[i];
108*57696d54SAkhilesh Sanikop             } // if found signature
109*57696d54SAkhilesh Sanikop          } // if/else
110*57696d54SAkhilesh Sanikop          i++;
111*57696d54SAkhilesh Sanikop       } while ((!foundSig) && (i < NUM_OFFSETS));
112*57696d54SAkhilesh Sanikop       allOK = foundSig;
113*57696d54SAkhilesh Sanikop    } // if
114*57696d54SAkhilesh Sanikop 
115*57696d54SAkhilesh Sanikop    // Load partition metadata from the buffer....
116*57696d54SAkhilesh Sanikop    if (allOK) {
117*57696d54SAkhilesh Sanikop       temp32 = (uint32_t*) &buffer[labelStart + 40];
118*57696d54SAkhilesh Sanikop       sectorSize = *temp32;
119*57696d54SAkhilesh Sanikop       temp16 = (uint16_t*) &buffer[labelStart + 138];
120*57696d54SAkhilesh Sanikop       numParts = *temp16;
121*57696d54SAkhilesh Sanikop    } // if
122*57696d54SAkhilesh Sanikop 
123*57696d54SAkhilesh Sanikop    // Make it big-endian-aware....
124*57696d54SAkhilesh Sanikop    if ((IsLittleEndian() == 0) && allOK)
125*57696d54SAkhilesh Sanikop       ReverseMetaBytes();
126*57696d54SAkhilesh Sanikop 
127*57696d54SAkhilesh Sanikop    // Check validity of the data and flag it appropriately....
128*57696d54SAkhilesh Sanikop    if (foundSig && (numParts <= MAX_BSD_PARTS) && allOK) {
129*57696d54SAkhilesh Sanikop       state = bsd;
130*57696d54SAkhilesh Sanikop    } else {
131*57696d54SAkhilesh Sanikop       state = bsd_invalid;
132*57696d54SAkhilesh Sanikop    } // if/else
133*57696d54SAkhilesh Sanikop 
134*57696d54SAkhilesh Sanikop    // If the state is good, go ahead and load the main partition data....
135*57696d54SAkhilesh Sanikop    if (state == bsd) {
136*57696d54SAkhilesh Sanikop       partitions = new struct BSDRecord[numParts * sizeof(struct BSDRecord)];
137*57696d54SAkhilesh Sanikop       if (partitions == NULL) {
138*57696d54SAkhilesh Sanikop          cerr << "Unable to allocate memory in BSDData::ReadBSDData()! Terminating!\n";
139*57696d54SAkhilesh Sanikop          exit(1);
140*57696d54SAkhilesh Sanikop       } // if
141*57696d54SAkhilesh Sanikop       for (i = 0; i < numParts; i++) {
142*57696d54SAkhilesh Sanikop          // Once again, we use the buffer, but index it using a BSDRecord
143*57696d54SAkhilesh Sanikop          // pointer (dangerous, but effective)....
144*57696d54SAkhilesh Sanikop          tempRecords = (BSDRecord*) &buffer[labelStart + 148];
145*57696d54SAkhilesh Sanikop          partitions[i].lengthLBA = tempRecords[i].lengthLBA;
146*57696d54SAkhilesh Sanikop          partitions[i].firstLBA = tempRecords[i].firstLBA;
147*57696d54SAkhilesh Sanikop          partitions[i].fsType = tempRecords[i].fsType;
148*57696d54SAkhilesh Sanikop          if (bigEnd) { // reverse data (fsType is a single byte)
149*57696d54SAkhilesh Sanikop             ReverseBytes(&partitions[i].lengthLBA, 4);
150*57696d54SAkhilesh Sanikop             ReverseBytes(&partitions[i].firstLBA, 4);
151*57696d54SAkhilesh Sanikop          } // if big-endian
152*57696d54SAkhilesh Sanikop          // Check for signs of relative sector numbering: A "0" first sector
153*57696d54SAkhilesh Sanikop          // number on a partition with a non-zero length -- but ONLY if the
154*57696d54SAkhilesh Sanikop          // length is less than the disk size, since NetBSD has a habit of
155*57696d54SAkhilesh Sanikop          // creating a disk-sized partition within a carrier MBR partition
156*57696d54SAkhilesh Sanikop          // that's too small to house it, and this throws off everything....
157*57696d54SAkhilesh Sanikop          if ((partitions[i].firstLBA == 0) && (partitions[i].lengthLBA > 0)
158*57696d54SAkhilesh Sanikop              && (partitions[i].lengthLBA < labelLastLBA))
159*57696d54SAkhilesh Sanikop             relative = 1;
160*57696d54SAkhilesh Sanikop       } // for
161*57696d54SAkhilesh Sanikop       // Some disklabels use sector numbers relative to the enclosing partition's
162*57696d54SAkhilesh Sanikop       // start, others use absolute sector numbers. If relative numbering was
163*57696d54SAkhilesh Sanikop       // detected above, apply a correction to all partition start sectors....
164*57696d54SAkhilesh Sanikop       if (relative) {
165*57696d54SAkhilesh Sanikop          for (i = 0; i < numParts; i++) {
166*57696d54SAkhilesh Sanikop             partitions[i].firstLBA += (uint32_t) startSector;
167*57696d54SAkhilesh Sanikop          } // for
168*57696d54SAkhilesh Sanikop       } // if
169*57696d54SAkhilesh Sanikop    } // if signatures OK
170*57696d54SAkhilesh Sanikop //   DisplayBSDData();
171*57696d54SAkhilesh Sanikop    return allOK;
172*57696d54SAkhilesh Sanikop } // BSDData::ReadBSDData(DiskIO* theDisk, uint64_t startSector)
173*57696d54SAkhilesh Sanikop 
174*57696d54SAkhilesh Sanikop // Reverse metadata's byte order; called only on big-endian systems
ReverseMetaBytes(void)175*57696d54SAkhilesh Sanikop void BSDData::ReverseMetaBytes(void) {
176*57696d54SAkhilesh Sanikop    ReverseBytes(&signature, 4);
177*57696d54SAkhilesh Sanikop    ReverseBytes(&sectorSize, 4);
178*57696d54SAkhilesh Sanikop    ReverseBytes(&signature2, 4);
179*57696d54SAkhilesh Sanikop    ReverseBytes(&numParts, 2);
180*57696d54SAkhilesh Sanikop } // BSDData::ReverseMetaByteOrder()
181*57696d54SAkhilesh Sanikop 
182*57696d54SAkhilesh Sanikop // Display basic BSD partition data. Used for debugging.
DisplayBSDData(void)183*57696d54SAkhilesh Sanikop void BSDData::DisplayBSDData(void) {
184*57696d54SAkhilesh Sanikop    int i;
185*57696d54SAkhilesh Sanikop 
186*57696d54SAkhilesh Sanikop    if (state == bsd) {
187*57696d54SAkhilesh Sanikop       cout << "BSD partitions:\n";
188*57696d54SAkhilesh Sanikop       for (i = 0; i < numParts; i++) {
189*57696d54SAkhilesh Sanikop          cout.width(4);
190*57696d54SAkhilesh Sanikop          cout << i + 1 << "\t";
191*57696d54SAkhilesh Sanikop          cout.width(13);
192*57696d54SAkhilesh Sanikop          cout << partitions[i].firstLBA << "\t";
193*57696d54SAkhilesh Sanikop          cout.width(15);
194*57696d54SAkhilesh Sanikop          cout << partitions[i].lengthLBA << " \t0x";
195*57696d54SAkhilesh Sanikop          cout.width(2);
196*57696d54SAkhilesh Sanikop          cout.fill('0');
197*57696d54SAkhilesh Sanikop          cout.setf(ios::uppercase);
198*57696d54SAkhilesh Sanikop          cout << hex << (int) partitions[i].fsType << "\n" << dec;
199*57696d54SAkhilesh Sanikop          cout.fill(' ');
200*57696d54SAkhilesh Sanikop       } // for
201*57696d54SAkhilesh Sanikop    } // if
202*57696d54SAkhilesh Sanikop } // BSDData::DisplayBSDData()
203*57696d54SAkhilesh Sanikop 
204*57696d54SAkhilesh Sanikop // Displays the BSD disklabel state. Called during program launch to inform
205*57696d54SAkhilesh Sanikop // the user about the partition table(s) status
ShowState(void)206*57696d54SAkhilesh Sanikop int BSDData::ShowState(void) {
207*57696d54SAkhilesh Sanikop    int retval = 0;
208*57696d54SAkhilesh Sanikop 
209*57696d54SAkhilesh Sanikop    switch (state) {
210*57696d54SAkhilesh Sanikop       case bsd_invalid:
211*57696d54SAkhilesh Sanikop          cout << "  BSD: not present\n";
212*57696d54SAkhilesh Sanikop          break;
213*57696d54SAkhilesh Sanikop       case bsd:
214*57696d54SAkhilesh Sanikop          cout << "  BSD: present\n";
215*57696d54SAkhilesh Sanikop          retval = 1;
216*57696d54SAkhilesh Sanikop          break;
217*57696d54SAkhilesh Sanikop       default:
218*57696d54SAkhilesh Sanikop          cout << "\a  BSD: unknown -- bug!\n";
219*57696d54SAkhilesh Sanikop          break;
220*57696d54SAkhilesh Sanikop    } // switch
221*57696d54SAkhilesh Sanikop    return retval;
222*57696d54SAkhilesh Sanikop } // BSDData::ShowState()
223*57696d54SAkhilesh Sanikop 
224*57696d54SAkhilesh Sanikop // Weirdly, this function has stopped working when defined inline,
225*57696d54SAkhilesh Sanikop // but it's OK here....
IsDisklabel(void)226*57696d54SAkhilesh Sanikop int BSDData::IsDisklabel(void) {
227*57696d54SAkhilesh Sanikop    return (state == bsd);
228*57696d54SAkhilesh Sanikop } // BSDData::IsDiskLabel()
229*57696d54SAkhilesh Sanikop 
230*57696d54SAkhilesh Sanikop // Returns the BSD table's partition type code
GetType(int i)231*57696d54SAkhilesh Sanikop uint8_t BSDData::GetType(int i) {
232*57696d54SAkhilesh Sanikop    uint8_t retval = 0; // 0 = "unused"
233*57696d54SAkhilesh Sanikop 
234*57696d54SAkhilesh Sanikop    if ((i < numParts) && (i >= 0) && (state == bsd) && (partitions != 0))
235*57696d54SAkhilesh Sanikop       retval = partitions[i].fsType;
236*57696d54SAkhilesh Sanikop 
237*57696d54SAkhilesh Sanikop    return(retval);
238*57696d54SAkhilesh Sanikop } // BSDData::GetType()
239*57696d54SAkhilesh Sanikop 
240*57696d54SAkhilesh Sanikop // Returns the number of the first sector of the specified partition
GetFirstSector(int i)241*57696d54SAkhilesh Sanikop uint64_t BSDData::GetFirstSector(int i) {
242*57696d54SAkhilesh Sanikop    uint64_t retval = UINT64_C(0);
243*57696d54SAkhilesh Sanikop 
244*57696d54SAkhilesh Sanikop    if ((i < numParts) && (i >= 0) && (state == bsd) && (partitions != 0))
245*57696d54SAkhilesh Sanikop       retval = (uint64_t) partitions[i].firstLBA;
246*57696d54SAkhilesh Sanikop 
247*57696d54SAkhilesh Sanikop    return retval;
248*57696d54SAkhilesh Sanikop } // BSDData::GetFirstSector
249*57696d54SAkhilesh Sanikop 
250*57696d54SAkhilesh Sanikop // Returns the length (in sectors) of the specified partition
GetLength(int i)251*57696d54SAkhilesh Sanikop uint64_t BSDData::GetLength(int i) {
252*57696d54SAkhilesh Sanikop    uint64_t retval = UINT64_C(0);
253*57696d54SAkhilesh Sanikop 
254*57696d54SAkhilesh Sanikop    if ((i < numParts) && (i >= 0) && (state == bsd) && (partitions != 0))
255*57696d54SAkhilesh Sanikop       retval = (uint64_t) partitions[i].lengthLBA;
256*57696d54SAkhilesh Sanikop 
257*57696d54SAkhilesh Sanikop    return retval;
258*57696d54SAkhilesh Sanikop } // BSDData::GetLength()
259*57696d54SAkhilesh Sanikop 
260*57696d54SAkhilesh Sanikop // Returns the number of partitions defined in the current table
GetNumParts(void)261*57696d54SAkhilesh Sanikop int BSDData::GetNumParts(void) {
262*57696d54SAkhilesh Sanikop    return numParts;
263*57696d54SAkhilesh Sanikop } // BSDData::GetNumParts()
264*57696d54SAkhilesh Sanikop 
265*57696d54SAkhilesh Sanikop // Returns the specified partition as a GPT partition. Used in BSD-to-GPT
266*57696d54SAkhilesh Sanikop // conversion process
AsGPT(int i)267*57696d54SAkhilesh Sanikop GPTPart BSDData::AsGPT(int i) {
268*57696d54SAkhilesh Sanikop    GPTPart guid;                  // dump data in here, then return it
269*57696d54SAkhilesh Sanikop    uint64_t sectorOne, sectorEnd; // first & last sectors of partition
270*57696d54SAkhilesh Sanikop    int passItOn = 1;              // Set to 0 if partition is empty or invalid
271*57696d54SAkhilesh Sanikop 
272*57696d54SAkhilesh Sanikop    guid.BlankPartition();
273*57696d54SAkhilesh Sanikop    sectorOne = (uint64_t) partitions[i].firstLBA;
274*57696d54SAkhilesh Sanikop    sectorEnd = sectorOne + (uint64_t) partitions[i].lengthLBA;
275*57696d54SAkhilesh Sanikop    if (sectorEnd > 0) sectorEnd--;
276*57696d54SAkhilesh Sanikop    // Note on above: BSD partitions sometimes have a length of 0 and a start
277*57696d54SAkhilesh Sanikop    // sector of 0. With unsigned ints, the usual way (start + length - 1) to
278*57696d54SAkhilesh Sanikop    // find the end will result in a huge number, which will be confusing.
279*57696d54SAkhilesh Sanikop    // Thus, apply the "-1" part only if it's reasonable to do so.
280*57696d54SAkhilesh Sanikop 
281*57696d54SAkhilesh Sanikop    // Do a few sanity checks on the partition before we pass it on....
282*57696d54SAkhilesh Sanikop    // First, check that it falls within the bounds of its container
283*57696d54SAkhilesh Sanikop    // and that it starts before it ends....
284*57696d54SAkhilesh Sanikop    if ((sectorOne < labelFirstLBA) || (sectorEnd > labelLastLBA) || (sectorOne > sectorEnd))
285*57696d54SAkhilesh Sanikop       passItOn = 0;
286*57696d54SAkhilesh Sanikop    // Some disklabels include a pseudo-partition that's the size of the entire
287*57696d54SAkhilesh Sanikop    // disk or containing partition. Don't return it.
288*57696d54SAkhilesh Sanikop    if ((sectorOne <= labelFirstLBA) && (sectorEnd >= labelLastLBA) &&
289*57696d54SAkhilesh Sanikop        (GetType(i) == 0))
290*57696d54SAkhilesh Sanikop       passItOn = 0;
291*57696d54SAkhilesh Sanikop    // If the end point is 0, it's not a valid partition.
292*57696d54SAkhilesh Sanikop    if ((sectorEnd == 0) || (sectorEnd == labelFirstLBA))
293*57696d54SAkhilesh Sanikop       passItOn = 0;
294*57696d54SAkhilesh Sanikop 
295*57696d54SAkhilesh Sanikop    if (passItOn) {
296*57696d54SAkhilesh Sanikop       guid.SetFirstLBA(sectorOne);
297*57696d54SAkhilesh Sanikop       guid.SetLastLBA(sectorEnd);
298*57696d54SAkhilesh Sanikop       // Now set a random unique GUID for the partition....
299*57696d54SAkhilesh Sanikop       guid.RandomizeUniqueGUID();
300*57696d54SAkhilesh Sanikop       // ... zero out the attributes and name fields....
301*57696d54SAkhilesh Sanikop       guid.SetAttributes(UINT64_C(0));
302*57696d54SAkhilesh Sanikop       // Most BSD disklabel type codes seem to be archaic or rare.
303*57696d54SAkhilesh Sanikop       // They're also ambiguous; a FreeBSD filesystem is impossible
304*57696d54SAkhilesh Sanikop       // to distinguish from a NetBSD one. Thus, these code assignment
305*57696d54SAkhilesh Sanikop       // are going to be rough to begin with. For a list of meanings,
306*57696d54SAkhilesh Sanikop       // see http://fxr.watson.org/fxr/source/sys/dtype.h?v=DFBSD,
307*57696d54SAkhilesh Sanikop       // or Google it.
308*57696d54SAkhilesh Sanikop       switch (GetType(i)) {
309*57696d54SAkhilesh Sanikop          case 1: // BSD swap
310*57696d54SAkhilesh Sanikop             guid.SetType(0xa502); break;
311*57696d54SAkhilesh Sanikop          case 7: // BSD FFS
312*57696d54SAkhilesh Sanikop             guid.SetType(0xa503); break;
313*57696d54SAkhilesh Sanikop          case 8: case 11: // MS-DOS or HPFS
314*57696d54SAkhilesh Sanikop             guid.SetType(0x0700); break;
315*57696d54SAkhilesh Sanikop          case 9: // log-structured fs
316*57696d54SAkhilesh Sanikop             guid.SetType(0xa903); break;
317*57696d54SAkhilesh Sanikop          case 13: // bootstrap
318*57696d54SAkhilesh Sanikop             guid.SetType(0xa501); break;
319*57696d54SAkhilesh Sanikop          case 14: // vinum
320*57696d54SAkhilesh Sanikop             guid.SetType(0xa505); break;
321*57696d54SAkhilesh Sanikop          case 15: // RAID
322*57696d54SAkhilesh Sanikop             guid.SetType(0xa903); break;
323*57696d54SAkhilesh Sanikop          case 27: // FreeBSD ZFS
324*57696d54SAkhilesh Sanikop             guid.SetType(0xa504); break;
325*57696d54SAkhilesh Sanikop          default:
326*57696d54SAkhilesh Sanikop             guid.SetType(0xa503); break;
327*57696d54SAkhilesh Sanikop       } // switch
328*57696d54SAkhilesh Sanikop       // Set the partition name to the name of the type code....
329*57696d54SAkhilesh Sanikop       guid.SetName(guid.GetTypeName());
330*57696d54SAkhilesh Sanikop    } // if
331*57696d54SAkhilesh Sanikop    return guid;
332*57696d54SAkhilesh Sanikop } // BSDData::AsGPT()
333