test: partit.c File Reference

Main Page | Class Hierarchy | Class List | File List | Class Members | File Members

# partit.c File Reference

`#include "precomp.h"`

Go to the source code of this file.

## Defines

#define | STATUS_ROW_TOP 13
#define | STATUS_ROW_BOTTOM 17
#define | MsgNoMem() AlStatusMsg(STATUS_ROW_TOP,STATUS_ROW_BOTTOM,TRUE,NOMEMMSG);
#define | SYSPARTMENU_CREATE 0
#define | SYSPARTMENU_DELETE 1
#define | SYSPARTMENU_ADD 2
#define | SYSPARTMENU_EXIT 3
#define | MENU_ROW 4

## Functions

PCHAR | AlGetNextArcNamToken (IN PCHAR TokenString, OUT PCHAR OutputToken, OUT PULONG UnitNumber)
BOOLEAN | Confirm (PCHAR Warning)
VOID | PrintErrorMsg (PCHAR FormatString,...)
VOID | PrintMsg (PCHAR FormatString,...)
BOOLEAN | IsBootSelectionPartition (PCHAR Variable, ULONG Disk, ULONG Partition, PULONG MatchNumber OPTIONAL)
LONG | ChooseDisk (VOID)
BOOLEAN | DoPartitionCreate (OUT PULONG DiskNo, OUT PULONG PartitionNo)
VOID | DoPartitionDelete (VOID)
VOID | DoSystemPartitionCreate (VOID)
VOID | DoMakePartitionSystemPartition (VOID)
VOID | ConfigureSystemPartitions (VOID)

## Variables

char | NOMEMMSG [] = "Insufficient memory"
char | NOCNFMSG [] = "Unable to determine disk configuration (ARC status = %u)"
char | NOFMTMSG [] = "Format failed (ARC status = %u)"
char | DSKFLMSG [] = "Disk is full"
char | NOCREMSG [] = "Could not create partition (ARC status = %u)"
char | NODELMSG [] = "Could not delete partition (ARC status = %u)"
char | ALREAMSG [] = "Partition is already a system partition"
char | NOFILMSG [] = "Unable to determine filesystem on partition (ARC status = %u)"
char | NOENVMSG [] = "Error (ARC status = %u) determining environment"
char | NOEVAMSG [] = "Could not add partition to environment (ARC status = %u)"
char | NOEVDMSG [] = "Could not remove partition from environment (ARC status = %u)"
char | NOSYSMSG [] = "No system partitions defined"
char | NOPARMSG [] = "No partitions on this disk"
char | SYSPARTVAR [] = "SYSTEMPARTITION"
char | OSLOADERVAR [] = "OSLOADER"
char | OSLOADPARTVAR [] = "OSLOADPARTITION"
PCHAR | SysPartMenu []
char | sprintfBuffer [256]

## Define Documentation

#define MENU_ROW 4

| Definition at line 69 of file partit.c. Referenced by ChooseDisk(), ConfigureSystemPartitions(), DoMakePartitionSystemPartition(), DoPartitionCreate(), and DoPartitionDelete().

#define MsgNoMem | (

)

AlStatusMsg(STATUS_ROW_TOP,STATUS_ROW_BOTTOM,TRUE,NOMEMMSG);

| Definition at line 56 of file partit.c. Referenced by ChooseDisk(), ConfigureSystemPartitions(), DoMakePartitionSystemPartition(), DoPartitionCreate(), and DoPartitionDelete().

#define STATUS_ROW_BOTTOM 17

| Definition at line 36 of file partit.c. Referenced by Confirm(), DoPartitionCreate(), DoSystemPartitionCreate(), PrintErrorMsg(), and PrintMsg().

#define STATUS_ROW_TOP 13

| Definition at line 35 of file partit.c. Referenced by Confirm(), DoPartitionCreate(), DoSystemPartitionCreate(), PrintErrorMsg(), and PrintMsg().

#define SYSPARTMENU_ADD 2

| Definition at line 66 of file partit.c. Referenced by ConfigureSystemPartitions().

#define SYSPARTMENU_CREATE 0

| Definition at line 64 of file partit.c. Referenced by ConfigureSystemPartitions().

#define SYSPARTMENU_DELETE 1

| Definition at line 65 of file partit.c. Referenced by ConfigureSystemPartitions().

#define SYSPARTMENU_EXIT 3

| Definition at line 67 of file partit.c. Referenced by ConfigureSystemPartitions().

## Function Documentation

PCHAR AlGetNextArcNamToken | ( | IN PCHAR | TokenString,
|  | OUT PCHAR | OutputToken,
|  | OUT PULONG | UnitNumber
| ) |

Definition at line 1318 of file almisc.c.

References NULL.

Referenced by ChooseDisk().

    01326                    :
    01327
    01328     This routine scans the specified token string for the next token and
    01329     unit number. The token format is:
    01330
    01331         name[(unit)]
    01332
    01333 Arguments:
    01334
    01335     TokenString - Supplies a pointer to a zero terminated token string.
    01336
    01337     OutputToken - Supplies a pointer to a variable that receives the next
    01338         token.
    01339
    01340     UnitNumber - Supplies a pointer to a variable that receives the unit
    01341         number.
    01342
    01343 Return Value:
    01344
    01345     If another token exists in the token string, then a pointer to the
    01346     start of the next token is returned. Otherwise, a value of NULL is
    01347     returned.
    01348
    01349 --*/
    01350
    01351 {
    01352
    01353     //
    01354     // If there are more characters in the token string, then parse the
    01355     // next token. Otherwise, return a value of NULL.
    01356     //
    01357
    01358     if (*TokenString == '\0') {
    01359         return NULL;
    01360
    01361     } else {
    01362         while ((*TokenString != '\0') && (*TokenString != '(')) {
    01363             *OutputToken++ = *TokenString++;
    01364         }
    01365
    01366         *OutputToken = '\0';
    01367
    01368         //
    01369         // If a unit number is specified, then convert it to binary.
    01370         // Otherwise, default the unit number to zero.
    01371         //
    01372
    01373         *UnitNumber = 0;
    01374         if (*TokenString == '(') {
    01375             TokenString += 1;
    01376             while ((*TokenString != '\0') && (*TokenString != ')')) {
    01377                 *UnitNumber = (*UnitNumber * 10) + (*TokenString++ - '0');
    01378             }
    01379
    01380             if (*TokenString == ')') {
    01381                 TokenString += 1;
    01382             }
    01383         }
    01384     }
    01385
    01386     return TokenString;
    01387 }

LONG ChooseDisk | ( | VOID |  | ) |

Definition at line 149 of file partit.c.

References AlAddMenuItem(), AlDisplayMenu(), AlGetNextArcNamToken(), AlNewMenu(), CHAR, FALSE, GetDiskCount(), GetDiskName(), MENU_ROW, MsgNoMem, NULL, sprintf(), sprintfBuffer, and Token.

Referenced by DoMakePartitionSystemPartition(), DoPartitionCreate(), and DoPartitionDelete().

    00152 {
    00153     ULONG DiskCount = GetDiskCount();
    00154     PVOID MenuID;
    00155     LONG Disk;
    00156     ULONG ChosenDisk;
    00157     PCHAR DiskName,TempDiskName;
    00158     ULONG UnitNumber,ScsiNumber,ScsiId,DiskNumber;
    00159     CHAR Token[32];
    00160
    00161     if (DiskCount == 1) {
    00162         return(0);
    00163     }
    00164
    00165     if (!AlNewMenu(&MenuID)) {
    00166         MsgNoMem();
    00167         return(-1);
    00168     }
    00169
    00170     for(Disk = DiskCount - 1; Disk >= 0; Disk--) {
    00171
    00172         DiskName = GetDiskName(Disk);
    00173
    00174         if ((strstr(DiskName, "scsi") != NULL) &&
    00175             (strstr(DiskName, "disk") != NULL) ) {
    00176
    00177             ScsiNumber = ScsiId = DiskNumber = 0;
    00178             TempDiskName = DiskName;
    00179
    00180             while (TempDiskName != NULL) {
    00181                 TempDiskName = AlGetNextArcNamToken(TempDiskName,
    00182                                                     Token,
    00183                                                     &UnitNumber);
    00184
    00185                 if (strcmp(Token,"scsi") == 0) {
    00186                     ScsiNumber = UnitNumber;
    00187                 }
    00188
    00189                 if (strcmp(Token,"disk") == 0) {
    00190                     ScsiId = UnitNumber;
    00191                 }
    00192
    00193                 if (strcmp(Token,"rdisk") == 0) {
    00194                     DiskNumber = UnitNumber;
    00195                 }
    00196             }
    00197
    00198             sprintf(sprintfBuffer,
    00199                     "Scsi bus %d, Identifier %d, Disk %d (%s)",
    00200                     ScsiNumber,
    00201                     ScsiId,
    00202                     DiskNumber,
    00203                     GetDiskName(Disk));
    00204         } else {
    00205             sprintf(sprintfBuffer,"Disk %d (%s)",Disk,GetDiskName(Disk));
    00206         }
    00207
    00208
    00209         if (!AlAddMenuItem(MenuID,sprintfBuffer,Disk,0)) {
    00210             MsgNoMem();
    00211             return(-1);
    00212         }
    00213     }
    00214
    00215     if (!AlDisplayMenu(MenuID,FALSE,0,&ChosenDisk,MENU_ROW,"Select Disk")) {
    00216         return(-1);
    00217     } else {
    00218         return(ChosenDisk);
    00219     }
    00220 }

VOID ConfigureSystemPartitions | ( | VOID |  | ) |

Definition at line 681 of file partit.c.

References AlAddMenuItems(), AlDisplayMenu(), AlFreeMenu(), AlNewMenu(), DoMakePartitionSystemPartition(), DoPartitionDelete(), DoSystemPartitionCreate(), FALSE, GetDiskCount(), MENU_ROW, MsgNoMem, SysPartMenu, SYSPARTMENU_ADD, SYSPARTMENU_CREATE, SYSPARTMENU_DELETE, and SYSPARTMENU_EXIT.

Referenced by main().

    00684 {
    00685     ULONG Choice=0,DiskCount=GetDiskCount();
    00686     PVOID MenuID;
    00687
    00688     if (!AlNewMenu(&MenuID)) {
    00689         MsgNoMem();
    00690         return;
    00691     }
    00692
    00693     if (!AlAddMenuItems(MenuID,SysPartMenu,sizeof(SysPartMenu)/sizeof(PCHAR))) {
    00694         MsgNoMem();
    00695         AlFreeMenu(MenuID);
    00696         return;
    00697     }
    00698
    00699     while(1) {
    00700
    00701         if ((!AlDisplayMenu(MenuID,FALSE,Choice,&Choice,MENU_ROW,"Configure System Partitions"))
    00702             || (Choice == SYSPARTMENU_EXIT))
    00703         {
    00704             break;
    00705         }
    00706
    00707         switch(Choice) {
    00708
    00709         case SYSPARTMENU_CREATE:
    00710             // create system partition.
    00711             DoSystemPartitionCreate();
    00712             break;
    00713
    00714         case SYSPARTMENU_DELETE:
    00715             // delete partition
    00716             DoPartitionDelete();
    00717             break;
    00718
    00719         case SYSPARTMENU_ADD:
    00720             // make existing into a system partition
    00721             DoMakePartitionSystemPartition();
    00722             break;
    00723         }
    00724     }
    00725
    00726     AlFreeMenu(MenuID);
    00727 }

BOOLEAN Confirm | ( | PCHAR | Warning | ) |

Definition at line 74 of file partit.c.

References AlClearStatusArea(), AlPrint(), ARC_CONSOLE_INPUT, ArcRead, ASCI_ESC, c, Count, MSGMARGIN, STATUS_ROW_BOTTOM, and STATUS_ROW_TOP.

Referenced by DoMakePartitionSystemPartition(), DoPartitionCreate(), and DoPartitionDelete().

    00077 {
    00078     char  c;
    00079     ULONG Count;
    00080
    00081     AlClearStatusArea(STATUS_ROW_TOP,STATUS_ROW_BOTTOM);
    00082     AlPrint("%s%s (y/n)?",MSGMARGIN,Warning);
    00083     ArcRead(ARC_CONSOLE_INPUT,&c,1,&Count);
    00084     while((c != 'y') && (c != 'Y') && (c != 'n') && (c != 'N') && (c != ASCI_ESC)) {
    00085         ArcRead(ARC_CONSOLE_INPUT,&c,1,&Count);
    00086     }
    00087     AlClearStatusArea(STATUS_ROW_TOP,STATUS_ROW_BOTTOM);
    00088     return((BOOLEAN)((c == 'y') || (c == 'Y')));
    00089 }

VOID DoMakePartitionSystemPartition | ( | VOID |  | ) |

Definition at line 573 of file partit.c.

References AlAddMenuItem(), AlAddSystemPartition(), AlDisplayMenu(), AlFreeMenu(), AlNewMenu(), ALREAMSG, ARC_STATUS, ChooseDisk(), Confirm(), ESUCCESS, FALSE, FmtFatFormat(), FmtIsFat(), FreeRegionArray(), GetDiskName(), GetHiddenSectorCount(), GetSysIDName(), GetUsedDiskRegions, IsBootSelectionPartition(), IsExtended(), MENU_ROW, MsgNoMem, NOCNFMSG, NOEVAMSG, NOFILMSG, NOFMTMSG, NOPARMSG, NULL, _tagREGION_DESCRIPTOR::PartitionNumber, PrintErrorMsg(), PrintMsg(), SetSysID(), sprintf(), sprintfBuffer, SYSID_BIGFAT, and SYSPARTVAR.

Referenced by ConfigureSystemPartitions().

    00576 {
    00577     BOOLEAN            f,IsFAT;
    00578     ULONG              Disk,i,Choice;
    00579     PVOID              MenuID;
    00580     PREGION_DESCRIPTOR Regions;
    00581     ULONG              RegionCount;
    00582     ARC_STATUS         status;
    00583     char               PartitionPath[256];
    00584     ULONG              PartitionNumber;
    00585
    00586
    00587     // take an existing partition and add it to the
    00588     // list of system partitions.  Also make sure it's
    00589     // formatted as FAT.
    00590
    00591     if ((Disk = ChooseDisk()) == -1) {
    00592         return;
    00593     }
    00594
    00595     status = GetUsedDiskRegions(Disk,&Regions,&RegionCount);
    00596     if (status != ESUCCESS) {
    00597         PrintErrorMsg(NOCNFMSG,status);
    00598         return;
    00599     }
    00600
    00601     if (!RegionCount) {
    00602         FreeRegionArray(Regions,RegionCount);
    00603         PrintErrorMsg(NOPARMSG);
    00604         return;
    00605     }
    00606
    00607     if (!AlNewMenu(&MenuID)) {
    00608         FreeRegionArray(Regions,RegionCount);
    00609         MsgNoMem();
    00610         return;
    00611     }
    00612
    00613     for(i=0; i<RegionCount; i++) {
    00614         if (!IsExtended(Regions[i].SysID)) {
    00615             sprintf(sprintfBuffer,
    00616                     "Partition %u (%u MB %s)",
    00617                     Regions[i].PartitionNumber,
    00618                     Regions[i].SizeMB,
    00619                     GetSysIDName(Regions[i].SysID)
    00620                    );
    00621             if (!AlAddMenuItem(MenuID,sprintfBuffer,i,0)) {
    00622                 MsgNoMem();
    00623                 AlFreeMenu(MenuID);
    00624                 FreeRegionArray(Regions,RegionCount);
    00625                 return;
    00626             }
    00627         }
    00628     }
    00629
    00630     f = AlDisplayMenu(MenuID,FALSE,0,&Choice,MENU_ROW,"Choose Partition");
    00631     AlFreeMenu(MenuID);
    00632     if (!f) {            // user escaped
    00633         FreeRegionArray(Regions,RegionCount);
    00634         return;
    00635     }
    00636
    00637     PartitionNumber = Regions[Choice].PartitionNumber;
    00638     sprintf(PartitionPath,"%spartition(%u)",GetDiskName(Disk),PartitionNumber);
    00639
    00640     FreeRegionArray(Regions,RegionCount);
    00641
    00642     if(IsBootSelectionPartition(SYSPARTVAR,Disk,PartitionNumber,NULL)) {
    00643         PrintErrorMsg(ALREAMSG);
    00644         return;
    00645     }
    00646
    00647     status = FmtIsFat(PartitionPath,&IsFAT);
    00648     if (status != ESUCCESS) {
    00649         PrintErrorMsg(NOFILMSG,status);
    00650         return;
    00651     }
    00652
    00653     if (!IsFAT) {
    00654         if (Confirm("System partitions must be formatted with the FAT filesystem.\r\n Do you wish to format the chosen partition")
    00655             && Confirm("All existing data will be lost.  Are you sure"))
    00656         {
    00657             status = FmtFatFormat(PartitionPath,GetHiddenSectorCount(Disk,PartitionNumber));
    00658             if (status != ESUCCESS) {
    00659                 PrintErrorMsg(NOFMTMSG,status);
    00660                 return;
    00661             }
    00662             SetSysID(Disk,PartitionNumber,SYSID_BIGFAT);
    00663         } else {
    00664             return;
    00665         }
    00666     }
    00667
    00668     //
    00669     // Add to list of system partitions.
    00670     //
    00671     if ((status = AlAddSystemPartition(PartitionPath)) == ESUCCESS) {
    00672         PrintMsg("Partition added successfully.");
    00673     } else {
    00674         PrintErrorMsg(NOEVAMSG,status);
    00675     }
    00676 }

BOOLEAN DoPartitionCreate | ( | OUT PULONG | DiskNo,
|  | OUT PULONG | PartitionNo
| ) |

Definition at line 224 of file partit.c.

References AlAddMenuItem(), AlClearStatusArea(), AlDisplayMenu(), AlFreeMenu(), AlGetString(), AlNewMenu(), AlPrint(), ARC_STATUS, ArcGetEnvironmentVariable, ArcSetEnvironmentVariable, ChooseDisk(), CommitPartitionChanges(), Confirm(), CreatePartition(), DoesAnyPrimaryExist(), DSKFLMSG, ESUCCESS, FALSE, FreeRegionArray(), GetDiskName(), GetFreeDiskRegions, GetFreeLogicalDiskRegions, IsAnyCreationAllowed(), MENU_ROW, MSGMARGIN, MsgNoMem, NOCNFMSG, NOCREMSG, NOEVAMSG, NULL, _tagREGION_DESCRIPTOR::PartitionNumber, PREGION_DESCRIPTOR, PrintErrorMsg(), PrintMsg(), REGION_EXTENDED, REGION_LOGICAL, REGION_PRIMARY, _tagREGION_DESCRIPTOR::RegionType, _tagREGION_DESCRIPTOR::SizeMB, sprintf(), sprintfBuffer, STATUS_ROW_BOTTOM, STATUS_ROW_TOP, SYSPARTVAR, and TRUE.

Referenced by DoSystemPartitionCreate().

    00228 {
    00229     ULONG              Disk,i;
    00230     PREGION_DESCRIPTOR Regions;
    00231     ULONG              RegionCount,Choice;
    00232     ULONG              ChosenSize;
    00233     ARC_STATUS         status;
    00234     BOOLEAN            xAny,xP,xE,xL,PrimaryExists;
    00235     PVOID              MenuID;
    00236     ULONG              PartitionNumber;
    00237     char               PartitionPath[256];
    00238
    00239
    00240     if ((Disk = ChooseDisk()) == -1) {
    00241         return(FALSE);
    00242     }
    00243
    00244     if ((status = DoesAnyPrimaryExist(Disk,&PrimaryExists)) != ESUCCESS) {
    00245         PrintErrorMsg(NOCNFMSG,status);
    00246         return(FALSE);
    00247     }
    00248
    00249     if ((status = IsAnyCreationAllowed(Disk,
    00250                                       TRUE,
    00251                                       &xAny,
    00252                                       &xP,
    00253                                       &xE,
    00254                                       &xL
    00255                                      )
    00256        )
    00257       != ESUCCESS)
    00258     {
    00259         PrintErrorMsg(NOCNFMSG,status);
    00260         return(FALSE);
    00261     }
    00262
    00263     // in order for a creation to be allowed there must be
    00264     // - free space on the disk and a free mbr entry OR
    00265     // - free space in an existing extended partition.
    00266
    00267     if (!xAny) {
    00268         PrintErrorMsg(DSKFLMSG);
    00269         return(FALSE);
    00270     }
    00271
    00272     if ((status = GetFreeDiskRegions(Disk,&Regions,&RegionCount)) != ESUCCESS) {
    00273         PrintErrorMsg(NOCNFMSG,status);
    00274         return(FALSE);
    00275     }
    00276
    00277     if (!AlNewMenu(&MenuID)) {
    00278         MsgNoMem();
    00279         FreeRegionArray(Regions,RegionCount);
    00280         return(FALSE);
    00281     }
    00282
    00283     // Present the user with a list of the free spaces
    00284     // on the disk (and within the extended partition, if it
    00285     // exists).
    00286
    00287     if (RegionCount > 1) {
    00288
    00289         for(i=0; i<RegionCount; i++) {
    00290
    00291             sprintf(sprintfBuffer,"%u MB space",Regions[i].SizeMB);
    00292             if (Regions[i].RegionType == REGION_LOGICAL) {
    00293                 strcat(sprintfBuffer," (in extended partition)");
    00294             }
    00295             if (!AlAddMenuItem(MenuID,sprintfBuffer,i,0)) {
    00296                 MsgNoMem();
    00297                 AlFreeMenu(MenuID);
    00298                 FreeRegionArray(Regions,RegionCount);
    00299                 return(FALSE);
    00300             }
    00301         }
    00302
    00303         if (!AlDisplayMenu(MenuID,FALSE,0,&Choice,MENU_ROW,"Available Free Spaces")) {
    00304             // user escaped
    00305             AlClearStatusArea(STATUS_ROW_TOP,STATUS_ROW_BOTTOM);
    00306             AlFreeMenu(MenuID);
    00307             FreeRegionArray(Regions,RegionCount);
    00308             return(FALSE);
    00309         }
    00310     } else {
    00311         Choice = 0;
    00312     }
    00313
    00314     AlFreeMenu(MenuID);
    00315
    00316     // now ask the user for the size of the partition to create in the chosen space.
    00317
    00318     do {
    00319         AlClearStatusArea(STATUS_ROW_TOP,STATUS_ROW_BOTTOM);
    00320         AlPrint("%sEnter size in MB (1-%u): ",MSGMARGIN,Regions[Choice].SizeMB);
    00321         if (!AlGetString(sprintfBuffer,sizeof(sprintfBuffer))) {
    00322             FreeRegionArray(Regions,RegionCount);
    00323             return(FALSE);
    00324         }
    00325         ChosenSize = atoi(sprintfBuffer);
    00326         if (!ChosenSize || (ChosenSize > Regions[Choice].SizeMB)) {
    00327             PrintErrorMsg("Invalid size.");
    00328         } else {
    00329             break;
    00330         }
    00331     } while(1);
    00332
    00333     // The chosen space is either in the extended partition or not.
    00334     // If it is, just create the requested partition.
    00335
    00336     if (Regions[Choice].RegionType == REGION_LOGICAL) {
    00337
    00338         status = CreatePartition(&Regions[Choice],ChosenSize,REGION_LOGICAL);
    00339         PartitionNumber = Regions[Choice].PartitionNumber;
    00340
    00341     } else {
    00342
    00343         // The chosen space is not in an extended partition.
    00344         // If there's already a primary and we can create
    00345         // an extended partition, then first create an
    00346         // extended partition spanning the entire space chosen
    00347         // by the user, and then a logical volume within it of
    00348         // size entered by the user.  Otherwise [ie, there's no primary
    00349         // or we're not allowed to create an extended partition]
    00350         // create a primary of the size entered by the user.
    00351
    00352
    00353         if (PrimaryExists && xE) {
    00354
    00355             // create extended partition first.
    00356             status = CreatePartition(&Regions[Choice],Regions[Choice].SizeMB,REGION_EXTENDED);
    00357             FreeRegionArray(Regions,RegionCount);
    00358
    00359             if ((status = GetFreeLogicalDiskRegions(Disk,&Regions,&RegionCount)) != ESUCCESS) {
    00360                 PrintErrorMsg(NOCNFMSG,status);
    00361                 return(FALSE);
    00362             }
    00363             // since we just created the extended partition, there will be one free
    00364             // region in it.
    00365
    00366             status = CreatePartition(Regions,ChosenSize,REGION_LOGICAL);
    00367             PartitionNumber = Regions[0].PartitionNumber;
    00368
    00369         } else {
    00370
    00371             status = CreatePartition(&Regions[Choice],ChosenSize,REGION_PRIMARY);
    00372             PartitionNumber = Regions[Choice].PartitionNumber;
    00373         }
    00374     }
    00375     FreeRegionArray(Regions,RegionCount);
    00376
    00377     if ( (status                                 == ESUCCESS)
    00378     && ((status = CommitPartitionChanges(Disk)) == ESUCCESS))
    00379     {
    00380         PrintMsg("Partition successfully created.");
    00381
    00382 #if 0
    00383         //
    00384         // This is bogus since this routine is called in the code path where
    00385         // the user is creating a system partition.
    00386         //
    00387         if (ArcGetEnvironmentVariable(SYSPARTVAR) == NULL) {
    00388             if (Confirm("Do you want to make this the system partition")) {
    00389                 sprintf(PartitionPath,"%spartition(%u)",GetDiskName(Disk),PartitionNumber);
    00390                 if ((status = ArcSetEnvironmentVariable(SYSPARTVAR,PartitionPath)) != ESUCCESS) {
    00391                     PrintErrorMsg(NOEVAMSG,status);
    00392                 }
    00393             }
    00394         }
    00395 #endif
    00396
    00397         *DiskNo      = Disk;
    00398         *PartitionNo = PartitionNumber;
    00399         return(TRUE);
    00400
    00401     } else {
    00402         PrintErrorMsg(NOCREMSG,status);
    00403         return(FALSE);
    00404     }
    00405 }

VOID DoPartitionDelete | ( | VOID |  | ) |

Definition at line 409 of file partit.c.

References AlAddMenuItem(), AlDisplayMenu(), AlFreeMenu(), AlNewMenu(), ARC_STATUS, ArcGetEnvironmentVariable, BootString, ChooseDisk(), CommitPartitionChanges(), Confirm(), DeletePartition(), DoesAnyPartitionExist(), ESUCCESS, FALSE, FreeRegionArray(), GetDiskName(), GetSysIDName(), GetUsedDiskRegions, Index, IsBootSelectionPartition(), IsExtended(), JzDeleteVariableSegment(), MaximumBootVariable, MENU_ROW, MsgNoMem, NOCNFMSG, NODELMSG, NULL, OSLOADPARTVAR, PrintErrorMsg(), PrintMsg(), REGION_LOGICAL, sprintf(), sprintfBuffer, SYSPARTVAR, SystemPartitionVariable, and TRUE.

Referenced by ConfigureSystemPartitions().

    00412 {
    00413     BOOLEAN            xAny,xPrimary,xExtended,xLogical;
    00414     ARC_STATUS         status;
    00415     PVOID              MenuID;
    00416     ULONG              i,RegionCount,Choice;
    00417     ULONG              MatchNumber,Index;
    00418     LONG               Disk;
    00419     PREGION_DESCRIPTOR Regions;
    00420     BOOLEAN            err,Confirmation;
    00421
    00422
    00423     if ((Disk = ChooseDisk()) == -1) {
    00424         return;
    00425     }
    00426
    00427     if ((status = DoesAnyPartitionExist(Disk,&xAny,&xPrimary,&xExtended,&xLogical)) != ESUCCESS) {
    00428         PrintErrorMsg(NOCNFMSG,status);
    00429         return;
    00430     }
    00431
    00432     if (xAny) {
    00433
    00434         if (!AlNewMenu(&MenuID)) {
    00435             MsgNoMem();
    00436             return;
    00437         }
    00438
    00439         if ((status = GetUsedDiskRegions(Disk,&Regions,&RegionCount)) != ESUCCESS) {
    00440
    00441             PrintErrorMsg(NOCNFMSG,status);
    00442
    00443         } else {
    00444
    00445             err = FALSE;
    00446
    00447             for(i=0; i<RegionCount; i++) {
    00448
    00449                 sprintf(sprintfBuffer,"%s%u MB ",Regions[i].RegionType == REGION_LOGICAL ? "    " : "",Regions[i].SizeMB);
    00450                 strcat(sprintfBuffer,GetSysIDName(Regions[i].SysID));
    00451                 strcat(sprintfBuffer,Regions[i].RegionType == REGION_LOGICAL ? " Logical Volume" : " Partition");
    00452                 if (IsExtended(Regions[i].SysID) && xLogical) {
    00453                     strcat(sprintfBuffer,", also resulting in the deletion of:");
    00454                 }
    00455
    00456                 if (!AlAddMenuItem(MenuID,sprintfBuffer,i,0)) {
    00457                     MsgNoMem();
    00458                     err = TRUE;
    00459                     break;
    00460                 }
    00461             }
    00462
    00463             if (!err) {
    00464
    00465                 if (AlDisplayMenu(MenuID,FALSE,0,&Choice,MENU_ROW,"Select Partition to Delete")) {
    00466
    00467                     if (IsBootSelectionPartition(SYSPARTVAR,Disk,Regions[Choice].PartitionNumber,NULL)) {
    00468                         Confirmation = Confirm("The selected partition is (or contains) a system partition.\r\n Are you sure you want to delete it");
    00469                     } else {
    00470                         if (IsBootSelectionPartition(OSLOADPARTVAR,Disk,Regions[Choice].PartitionNumber,NULL)) {
    00471                             Confirmation = Confirm("The selected partition contains an operating system.\r\n Are you sure you want to delete it");
    00472                         } else {
    00473                             Confirmation = Confirm("Are you sure");
    00474                         }
    00475                     }
    00476                     if (Confirmation) {
    00477                         if (((status = DeletePartition(&Regions[Choice])) != ESUCCESS)
    00478                         || ((status = CommitPartitionChanges(Disk)) != ESUCCESS))
    00479                         {
    00480                             PrintErrorMsg(NODELMSG,status);
    00481                         } else {
    00482                             PrintMsg("Partition deleted successfully.");
    00483
    00484                             sprintf(sprintfBuffer,
    00485                                     "%spartition(%u)",
    00486                                     GetDiskName(Disk),
    00487                                     Regions[Choice].PartitionNumber
    00488                                    );
    00489
    00490                             //
    00491                             // If there are any boot selections and the deleted partition
    00492                             // was used, ask if the associated boot selections should be
    00493                             // deleted.
    00494                             //
    00495
    00496                             if (ArcGetEnvironmentVariable(OSLOADPARTVAR) != NULL) {
    00497                                 if ((IsBootSelectionPartition(SYSPARTVAR,Disk,Regions[Choice].PartitionNumber,NULL) ||
    00498                                      IsBootSelectionPartition(OSLOADPARTVAR,Disk,Regions[Choice].PartitionNumber,NULL)) &&
    00499                                      Confirm("Do you want to delete the boot selection(s) associated\r\n with the deleted partition?")) {
    00500
    00501                                     while (IsBootSelectionPartition(SYSPARTVAR,Disk,Regions[Choice].PartitionNumber,&MatchNumber)) {
    00502                                         for ( Index = 0 ; Index < MaximumBootVariable ; Index++ ) {
    00503                                             JzDeleteVariableSegment(BootString[Index],MatchNumber);
    00504                                         }
    00505                                     }
    00506
    00507                                     while (IsBootSelectionPartition(OSLOADPARTVAR,Disk,Regions[Choice].PartitionNumber,&MatchNumber)) {
    00508                                         for ( Index = 0 ; Index < MaximumBootVariable ; Index++ ) {
    00509                                             JzDeleteVariableSegment(BootString[Index],MatchNumber);
    00510                                         }
    00511                                     }
    00512                                 }
    00513
    00514                             } else {
    00515
    00516                                 //
    00517                                 // There are no boot selections but delete all segments
    00518                                 // of the SystemPartition variable that pointed to the
    00519                                 // deleted partition.
    00520                                 //
    00521
    00522                                 while (IsBootSelectionPartition(SYSPARTVAR,Disk,Regions[Choice].PartitionNumber,&MatchNumber)) {
    00523                                     JzDeleteVariableSegment(BootString[SystemPartitionVariable],MatchNumber);
    00524                                 }
    00525                             }
    00526                         }
    00527                     }
    00528                 }
    00529             }
    00530
    00531             FreeRegionArray(Regions,RegionCount);
    00532         }
    00533         AlFreeMenu(MenuID);
    00534
    00535     } else {
    00536         PrintErrorMsg("No partitions on this disk");
    00537     }
    00538 }

VOID DoSystemPartitionCreate | ( | VOID |  | ) |

Definition at line 542 of file partit.c.

References AlAddSystemPartition(), AlStatusMsgNoWait(), ARC_STATUS, DoPartitionCreate(), ESUCCESS, FALSE, FmtFatFormat(), GetDiskName(), GetHiddenSectorCount(), NOEVAMSG, NOFMTMSG, PrintErrorMsg(), PrintMsg(), SetSysID(), sprintf(), sprintfBuffer, STATUS_ROW_BOTTOM, STATUS_ROW_TOP, and SYSID_BIGFAT.

Referenced by ConfigureSystemPartitions().

    00545 {
    00546     ULONG      DiskNo,PartitionNo;
    00547     ARC_STATUS status;
    00548
    00549     if (DoPartitionCreate(&DiskNo,&PartitionNo)) {
    00550
    00551         sprintf(sprintfBuffer,"%spartition(%u)",GetDiskName(DiskNo),PartitionNo);
    00552
    00553         // add the partition to the SYSTEMPARTITION NVRAM environment variable
    00554
    00555         if ((status = AlAddSystemPartition(sprintfBuffer)) != ESUCCESS) {
    00556             PrintErrorMsg(NOEVAMSG,status);
    00557             return;
    00558         }
    00559
    00560         AlStatusMsgNoWait(STATUS_ROW_TOP,STATUS_ROW_BOTTOM,FALSE,"Formatting %s",sprintfBuffer);
    00561         status = FmtFatFormat(sprintfBuffer,GetHiddenSectorCount(DiskNo,PartitionNo));
    00562         if (status == ESUCCESS) {
    00563             SetSysID(DiskNo,PartitionNo,SYSID_BIGFAT);
    00564             PrintMsg("Partition formatted successfully.");
    00565         } else {
    00566             PrintErrorMsg(NOFMTMSG,status);
    00567         }
    00568     }
    00569 }

BOOLEAN IsBootSelectionPartition | ( | PCHAR | Variable,
|  | ULONG | Disk,
|  | ULONG | Partition,
|  | PULONG MatchNumber | OPTIONAL
| ) |

Definition at line 129 of file partit.c.

References AlFindNextMatchComponent(), ArcGetEnvironmentVariable, FALSE, GetDiskName(), NULL, sprintf(), and text.

Referenced by DoMakePartitionSystemPartition(), and DoPartitionDelete().

    00135 {
    00136     char  text[256];
    00137     PCHAR Var = ArcGetEnvironmentVariable(Variable);
    00138
    00139     if (Var == NULL) {
    00140         return(FALSE);
    00141     }
    00142
    00143     sprintf(text,"%spartition(%u)",GetDiskName(Disk),Partition);
    00144     return(AlFindNextMatchComponent(Var,text,0,MatchNumber));
    00145 }

VOID PrintErrorMsg | ( | PCHAR | FormatString,
|  |  | ...
| ) |

Definition at line 93 of file partit.c.

References AlClearStatusArea(), AlWaitKey(), NULL, STATUS_ROW_BOTTOM, STATUS_ROW_TOP, TRUE, and vAlStatusMsg().

Referenced by DoMakePartitionSystemPartition(), DoPartitionCreate(), DoPartitionDelete(), and DoSystemPartitionCreate().

    00097 {
    00098     va_list ArgList;
    00099
    00100     va_start(ArgList,FormatString);
    00101
    00102     AlClearStatusArea(STATUS_ROW_TOP,STATUS_ROW_BOTTOM);
    00103     vAlStatusMsg(STATUS_ROW_TOP,TRUE,FormatString,ArgList);
    00104
    00105     AlWaitKey(NULL);
    00106     AlClearStatusArea(STATUS_ROW_TOP,STATUS_ROW_BOTTOM);
    00107 }

VOID PrintMsg | ( | PCHAR | FormatString,
|  |  | ...
| ) |

Definition at line 111 of file partit.c.

References AlClearStatusArea(), AlWaitKey(), FALSE, NULL, STATUS_ROW_BOTTOM, STATUS_ROW_TOP, and vAlStatusMsg().

Referenced by DoMakePartitionSystemPartition(), DoPartitionCreate(), DoPartitionDelete(), and DoSystemPartitionCreate().

    00115 {
    00116     va_list ArgList;
    00117
    00118     va_start(ArgList,FormatString);
    00119
    00120     AlClearStatusArea(STATUS_ROW_TOP,STATUS_ROW_BOTTOM);
    00121     vAlStatusMsg(STATUS_ROW_TOP,FALSE,FormatString,ArgList);
    00122
    00123     AlWaitKey(NULL);
    00124     AlClearStatusArea(STATUS_ROW_TOP,STATUS_ROW_BOTTOM);
    00125 }

## Variable Documentation

char ALREAMSG[] = "Partition is already a system partition"

| Definition at line 44 of file partit.c. Referenced by DoMakePartitionSystemPartition().

char DSKFLMSG[] = "Disk is full"

| Definition at line 41 of file partit.c. Referenced by DoPartitionCreate().

char NOCNFMSG[] = "Unable to determine disk configuration (ARC status = %u)"

| Definition at line 39 of file partit.c. Referenced by DoMakePartitionSystemPartition(), DoPartitionCreate(), and DoPartitionDelete().

char NOCREMSG[] = "Could not create partition (ARC status = %u)"

| Definition at line 42 of file partit.c. Referenced by DoPartitionCreate().

char NODELMSG[] = "Could not delete partition (ARC status = %u)"

| Definition at line 43 of file partit.c. Referenced by DoPartitionDelete().

char NOENVMSG[] = "Error (ARC status = %u) determining environment"

| Definition at line 46 of file partit.c.

char NOEVAMSG[] = "Could not add partition to environment (ARC status = %u)"

| Definition at line 47 of file partit.c. Referenced by DoMakePartitionSystemPartition(), DoPartitionCreate(), and DoSystemPartitionCreate().

char NOEVDMSG[] = "Could not remove partition from environment (ARC status = %u)"

| Definition at line 48 of file partit.c.

char NOFILMSG[] = "Unable to determine filesystem on partition (ARC status = %u)"

| Definition at line 45 of file partit.c. Referenced by DoMakePartitionSystemPartition().

char NOFMTMSG[] = "Format failed (ARC status = %u)"

| Definition at line 40 of file partit.c. Referenced by DoMakePartitionSystemPartition(), and DoSystemPartitionCreate().

char NOMEMMSG[] = "Insufficient memory"

| Definition at line 38 of file partit.c.

char NOPARMSG[] = "No partitions on this disk"

| Definition at line 50 of file partit.c. Referenced by DoMakePartitionSystemPartition().

char NOSYSMSG[] = "No system partitions defined"

| Definition at line 49 of file partit.c.

char OSLOADERVAR[] = "OSLOADER"

| Definition at line 53 of file partit.c.

char OSLOADPARTVAR[] = "OSLOADPARTITION"

| Definition at line 54 of file partit.c. Referenced by DoPartitionDelete().

char sprintfBuffer[256]

| Definition at line 71 of file partit.c. Referenced by ChooseDisk(), DoMakePartitionSystemPartition(), DoPartitionCreate(), DoPartitionDelete(), and DoSystemPartitionCreate().

PCHAR SysPartMenu[]

Initial value:

     {   "Create System Partition",
                              "Delete Partition",
                              "Make Existing Partition into System Partition",
                              "Exit"
                          }

Definition at line 58 of file partit.c.

Referenced by ConfigureSystemPartitions().

char SYSPARTVAR[] = "SYSTEMPARTITION"

| Definition at line 52 of file partit.c. Referenced by DoMakePartitionSystemPartition(), DoPartitionCreate(), and DoPartitionDelete().