Home | History | Annotate | Download | only in gptfdisk

Lines Matching refs:partitions

99       partitions[i] = orig.partitions[i];
138 // in the partitions[] array; these partitions must be re-created when
152 // Empty existing MBR data, including the logical partitions...
166 partitions[i] = tempMBR.partitions[i];
167 if (partitions[i].GetLengthLBA() > 0)
168 partitions[i].SetInclusion(PRIMARY);
169 } // for i... (reading all four partitions)
179 partitions[i].ReverseByteOrder();
199 if ((partitions[i].GetType() == 0x05) || (partitions[i].GetType() == 0x0f)
200 || (partitions[i].GetType() == 0x85)) {
202 logicalNum = ReadLogicalParts(partitions[i].GetStartLBA(), abs(logicalNum) + 1);
204 cerr << "Error reading logical partitions! List may be truncated!\n";
219 if (partitions[i].GetType() == UINT8_C(0xEE)) {
229 if ((partitions[i].GetType() != UINT8_C(0xEE)) &&
230 (partitions[i].GetType() != UINT8_C(0x00)))
233 cerr << "Warning! MBR Logical partitions found on a hybrid MBR disk! This is an\n"
241 // This is a function to read all the logical partitions, following the
243 // partitions[] array. Returns last index to partitions[] used, or -1 times the
273 << "!\nSome logical partitions may be missing!\n";
277 ReverseBytes(&ebr.partitions[0].firstLBA, 4);
278 ReverseBytes(&ebr.partitions[0].lengthLBA, 4);
279 ReverseBytes(&ebr.partitions[1].firstLBA, 4);
280 ReverseBytes(&ebr.partitions[1].lengthLBA, 4);
299 ebrType = ebr.partitions[0].partitionType;
302 offset = extendedStart + ebr.partitions[0].firstLBA;
305 partitions[partNum] = ebr.partitions[0];
307 partitions[partNum].SetStartLBA(ebr.partitions[0].firstLBA + offset);
308 partitions[partNum].SetInclusion(LOGICAL);
311 if ((ebr.partitions[1].firstLBA != UINT32_C(0)) && (partNum < (MAX_MBR_PARTS - 1))) {
312 offset = extendedStart + ebr.partitions[1].firstLBA;
324 // MBR itself and any defined logical partitions, provided there's an
342 // MBR itself and any defined logical partitions.
357 partitions[i].StoreInStruct(&tempMBR.partitions[i]);
358 if (partitions[i].GetType() == 0x0f) {
359 extFirstLBA = partitions[i].GetStartLBA();
366 // Set up tempMBR with some constant data for logical partitions...
369 tempMBR.partitions[i].firstLBA = tempMBR.partitions[i].lengthLBA = 0;
370 tempMBR.partitions[i].partitionType = 0x00;
372 tempMBR.partitions[i].firstSector[j] = 0;
373 tempMBR.partitions[i].lastSector[j] = 0;
381 partitions[partNum].StoreInStruct(&tempMBR.partitions[0]);
382 tempMBR.partitions[0].firstLBA = 1;
383 // tempMBR.partitions[1] points to next EBR or terminates EBR linked list...
385 if ((next < MAX_MBR_PARTS) && (next > 0) && (partitions[next].GetStartLBA() > 0)) {
386 tempMBR.partitions[1].partitionType = 0x0f;
387 tempMBR.partitions[1].firstLBA = (uint32_t) (partitions[next].GetStartLBA() - extFirstLBA - 1);
388 tempMBR.partitions[1].lengthLBA = (uint32_t) (partitions[next].GetLengthLBA() + 1);
389 LBAtoCHS((uint64_t) tempMBR.partitions[1].firstLBA,
390 (uint8_t *) &tempMBR.partitions[1].firstSector);
391 LBAtoCHS(tempMBR.partitions[1].lengthLBA - extFirstLBA,
392 (uint8_t *) &tempMBR.partitions[1].lastSector);
394 tempMBR.partitions[1].partitionType = 0x00;
395 tempMBR.partitions[1].firstLBA = 0;
396 tempMBR.partitions[1].lengthLBA = 0;
400 writeEbrTo = (uint64_t) tempMBR.partitions[1].firstLBA + (uint64_t) extFirstLBA;
425 ReverseBytes(&mbr.partitions[i].firstLBA, 4);
426 ReverseBytes(&mbr.partitions[i].lengthLBA, 4);
449 ReverseBytes(&mbr.partitions[i].firstLBA, 4);
450 ReverseBytes(&mbr.partitions[i].lengthLBA, 4);
474 // of partitions....
485 cout << "MBR partitions:\n\n";
494 if (partitions[i].GetLengthLBA() != 0) {
498 partitions[i].ShowData((state == gpt) || (state == hybrid));
627 partitions[0].SetGeometry(numHeads, numSecspTrack, diskSize, blockSize);
631 // Return value is the number of partitions found. Note that the
632 // *low and *high values are both set to 0 when no partitions
635 // tell when no partitions exist.
643 if (partitions[i].GetStartLBA() != UINT32_C(0)) { // it exists
652 // Above will leave *low pointing to its "not found" value if no partitions
706 // Look for overlapping partitions. Also looks for a couple of non-error
714 if ((partitions[i].GetInclusion() != NONE) && (partitions[j].GetInclusion() != NONE) &&
715 (partitions[i].DoTheyOverlap(partitions[j]))) {
717 cout << "\nProblem: MBR partitions " << i + 1 << " and " << j + 1
721 if (partitions[i].GetType() == 0xEE) {
723 if (partitions[i].GetStartLBA() == 1)
738 // Returns the number of primary partitions, including the extended partition
739 // required to hold any logical partitions found.
744 if (partitions[i].GetLengthLBA() > 0) {
745 if (partitions[i].GetInclusion() == PRIMARY)
747 if (partitions[i].GetInclusion() == LOGICAL)
754 // Returns the number of logical partitions.
759 if (partitions[i].GetInclusion() == LOGICAL)
765 // Returns the number of partitions (primaries plus logicals), NOT including
771 if ((partitions[i].GetInclusion() == LOGICAL) ||
772 (partitions[i].GetInclusion() == PRIMARY))
778 // Updates the canBeLogical and canBePrimary flags for all the partitions.
788 usedAsEBR = (SectorUsedAs(partitions[i].GetLastLBA()) == EBR);
790 partitions[i].SetCanBeLogical(0);
791 partitions[i].SetCanBePrimary(0);
792 } else if (partitions[i].GetLengthLBA() > 0) {
794 sectorBefore = SectorUsedAs(partitions[i].GetStartLBA() - 1);
795 lStart = partitions[i].GetStartLBA(); // start of potential logical part.
800 partitions[i].SetCanBeLogical(1);
802 if ((i != j) && (partitions[j].GetInclusion() == PRIMARY)) {
803 pStart = partitions[j].GetStartLBA();
806 partitions[i].SetCanBeLogical(0);
812 partitions[i].SetCanBeLogical(0);
814 partitions[i].SetCanBeLogical(lastLogical == 0); // can be logical only if no logicals already
817 partitions[i].SetCanBePrimary(1);
818 if ((numPrimaries >= 4) && (partitions[i].GetInclusion() != PRIMARY)) {
819 partitions[i].SetCanBePrimary(0);
820 if ((partitions[i].GetInclusion() == LOGICAL) && (numLogicals == 1) &&
822 partitions[i].SetCanBePrimary(1);
824 if ((partitions[i].GetStartLBA() > (firstLogical + 1)) &&
825 (partitions[i].GetLastLBA() < lastLogical))
826 partitions[i].SetCanBePrimary(0);
833 // if there are no logical partitions defined.
839 if ((partitions[i].GetInclusion() == LOGICAL) &&
840 (partitions[i].GetStartLBA() < firstFound)) {
841 firstFound = partitions[i].GetStartLBA();
848 // there are no logical partitions defined.
854 if ((partitions[i].GetInclusion() == LOGICAL) &&
855 (partitions[i].GetLastLBA() > lastFound))
856 lastFound = partitions[i].GetLastLBA();
861 // Returns 1 if logical partitions are contiguous (have no primaries
872 if ((partitions[i].GetInclusion() == PRIMARY) &&
873 (partitions[i].GetStartLBA() >= firstLogical) &&
874 (partitions[i].GetStartLBA() <= lastLogical)) {
883 // Returns 1 if all partitions fit on the disk, given its size; 0 if any
889 if ((partitions[i].GetStartLBA() > diskSize) || (partitions[i].GetLastLBA() > diskSize)) {
897 // all partitions flagged as logical; 0 if any logical partition lacks
903 if ((partitions[i].GetStartLBA() > 0) && (partitions[i].GetInclusion() == LOGICAL)) {
904 allOK = allOK && (SectorUsedAs(partitions[i].GetStartLBA() - 1) == EBR);
911 // Returns 1 if the partitions describe a legal layout -- all logicals
914 // logicals), there are no overlapping partitions, etc.
936 if ((partitions[i].GetStatus() & 0x80) && (partitions[i].GetType() == 0xEE))
947 while ((start < MAX_MBR_PARTS) && (start >= 0) && (partitions[start].GetInclusion() == NONE))
956 * Functions to create, delete, or change partitions *
972 // Blank out the partitions
974 partitions[i].Empty();
1000 partitions[num] = newPart;
1013 partitions[num].Empty();
1014 partitions[num].SetType(type);
1015 partitions[num].SetLocation(start, length);
1017 partitions[num].SetInclusion(PRIMARY);
1019 partitions[num].SetInclusion(LOGICAL);
1030 if (partitions[num].GetLengthLBA() != UINT32_C(0)) {
1031 allOK = partitions[num].SetType(type);
1044 if (partitions[num].GetLengthLBA() != UINT32_C(0)) {
1046 partitions[num].SetStatus(UINT8_C(0x00));
1048 partitions[num].SetStatus(UINT8_C(0x80));
1090 partitions[i].Empty();
1101 origValue = partitions[num].GetInclusion();
1102 partitions[num].SetInclusion(inclStatus);
1104 partitions[num].SetInclusion(origValue);
1119 // protective partitions, but this is required by some buggy BIOSes, so I'm
1123 partitions[partNum].RecomputeCHS();
1126 // Sorts the partitions starting with partition #start. This function
1128 // critical when writing the partitions.
1131 sort(partitions + start, partitions + MAX_MBR_PARTS);
1134 // Delete any partitions that are too big to fit on the disk
1136 // This deletes the partitions by setting values to 0, not just
1138 // Returns the number of partitions deleted in this way.
1143 if ((partitions[i].GetStartLBA() > diskSize) || (partitions[i].GetLastLBA() > diskSize) ||
1144 (partitions[i].GetStartLBA() > UINT32_MAX) || (partitions[i].GetLengthLBA() > UINT32_MAX)) {
1146 << partitions[i].GetStartLBA() << ", length = " << partitions[i].GetLengthLBA() << "\n";
1147 partitions[i].Empty();
1154 // Search for and delete extended partitions.
1155 // Returns the number of partitions deleted.
1161 type = partitions[i].GetType();
1163 (partitions[i].GetLengthLBA() > 0)) {
1164 partitions[i].Empty();
1171 // Finds any overlapping partitions and omits the smaller of the two.
1177 if ((partitions[i].GetInclusion() != NONE) &&
1178 partitions[i].DoTheyOverlap(partitions[j])) {
1179 if (partitions[i].GetLengthLBA() < partitions[j].GetLengthLBA())
1180 partitions[i].SetInclusion(NONE);
1182 partitions[j].SetInclusion(NONE);
1188 // Convert as many partitions into logicals as possible, except for
1196 if (partitions[i].CanBeLogical()) {
1197 partitions[i].SetInclusion(LOGICAL);
1198 } else if (partitions[i].CanBePrimary()) {
1199 partitions[i].SetInclusion(PRIMARY);
1201 partitions[i].SetInclusion(NONE);
1206 if ((NumPrimaries() < 4) && (partitions[earliestPart].GetInclusion() == LOGICAL))
1207 partitions[earliestPart].SetInclusion(earliestPartWas);
1216 if ((partitions[i].GetInclusion() == NONE) && (partitions[i].CanBePrimary())) {
1217 partitions[i].SetInclusion(PRIMARY);
1225 // Remove primary partitions in excess of 4, starting with the later ones,
1232 if (partitions[i].GetInclusion() == PRIMARY) {
1233 partitions[i].SetInclusion(NONE);
1240 // Locates primary partitions located between logical partitions and
1250 if ((partitions[i].GetInclusion() == PRIMARY) &&
1251 (partitions[i].GetStartLBA() >= firstLogicalLBA) &&
1252 (partitions[i].GetLastLBA() <= lastLogicalLBA)) {
1253 if (SectorUsedAs(partitions[i].GetStartLBA() - 1) == NONE)
1254 partitions[i].SetInclusion(LOGICAL);
1256 partitions[i].SetInclusion(NONE);
1262 // if necessary, drop partitions, to make the data legal.
1276 // Removes logical partitions and deactivated partitions from first four
1278 // Returns the number of partitions moved.
1284 if ((partitions[i].GetInclusion() != PRIMARY) && (partitions[i].GetLengthLBA() > 0)) {
1288 if ((partitions[j].GetInclusion() == NONE) && (partitions[j].GetLengthLBA() == 0)) {
1289 temp = partitions[j];
1290 partitions[j] = partitions[i];
1291 partitions[i] = temp;
1298 cerr << "Warning! Too many partitions in BasicMBRData::RemoveLogicalsFromFirstFour()!\n";
1305 // Returns the number of partitions moved.
1311 if (partitions[i].GetInclusion() == PRIMARY) {
1315 if (partitions[j].GetInclusion() != PRIMARY) {
1316 temp = partitions[j];
1317 partitions[j] = partitions[i];
1318 partitions[i] = temp;
1329 // Create an extended partition, if necessary, to hold the logical partitions.
1352 if ((partitions[i].GetInclusion() == NONE) || (partitions[i].GetLengthLBA() == 0)) {
1353 partitions[i] = temp;
1364 // Do a final check for EFI GPT (0xEE) partitions & flag as a problem if found
1367 if (swapped && partitions[i].GetType() == 0xEE)
1390 // ...now search through all partitions; if first is within an
1394 // cases where partitions are out of sequential order....
1399 if ((first >= partitions[i].GetStartLBA()) &&
1400 (first < (partitions[i].GetStartLBA() + partitions[i].GetLengthLBA()))) {
1401 first = partitions[i].GetStartLBA() + partitions[i].GetLengthLBA();
1422 if ((nearestStart > partitions[i].GetStartLBA()) &&
1423 (partitions[i].GetStartLBA() > start)) {
1424 nearestStart = partitions[i].GetStartLBA() - 1;
1437 thisLastLBA = partitions[i].GetLastLBA() + 1;
1454 if ((partitions[i].GetStartLBA() <= sector) && (partitions[i].GetLastLBA() >= sector))
1455 usedAs = partitions[i].GetInclusion();
1456 if ((partitions[i].GetStartLBA() == (sector + 1)) && (partitions[i].GetInclusion() == LOGICAL))
1469 * Functions that extract data on specific partitions *
1533 thePart = &partitions[i];
1545 // Returns the number of partitions defined on exit, or -1 if the
1561 if (partitions[num].GetInclusion() != NONE)
1562 partitions[num].SetStatus(partitions[num].GetStatus() ^ 0x80);
1580 cout << "\n** Extended partitions are not displayed, but will be generated "
1603 if (partitions[num].GetLengthLBA() > 0) {
1610 partitions[num].SetType(hexCode);
1636 cout << "s\tsort MBR partitions\n";