| 1 | // AiR-BOOT (c) Copyright 1998-2008 M. Kiewitz
|
|---|
| 2 | //
|
|---|
| 3 | // This file is part of AiR-BOOT
|
|---|
| 4 | //
|
|---|
| 5 | // AiR-BOOT is free software: you can redistribute it and/or modify it under
|
|---|
| 6 | // the terms of the GNU General Public License as published by the Free
|
|---|
| 7 | // Software Foundation, either version 3 of the License, or (at your option)
|
|---|
| 8 | // any later version.
|
|---|
| 9 | //
|
|---|
| 10 | // AiR-BOOT is distributed in the hope that it will be useful, but WITHOUT ANY
|
|---|
| 11 | // WARRANTY: without even the implied warranty of MERCHANTABILITY or FITNESS
|
|---|
| 12 | // FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
|
|---|
| 13 | // details.
|
|---|
| 14 | //
|
|---|
| 15 | // You should have received a copy of the GNU General Public License along with
|
|---|
| 16 | // AiR-BOOT. If not, see <http://www.gnu.org/licenses/>.
|
|---|
| 17 | //
|
|---|
| 18 |
|
|---|
| 19 | /*
|
|---|
| 20 | // Rousseau: 2011-02-05
|
|---|
| 21 | // - Made volumes compare case insensitive so fs-label matches volume-name on command-line. (around line 510)
|
|---|
| 22 | // This means bootable volumes cannot not have the same and only differ in case.
|
|---|
| 23 | */
|
|---|
| 24 |
|
|---|
| 25 |
|
|---|
| 26 | #define INCL_BASE
|
|---|
| 27 | #define INCL_WINSHELLDATA
|
|---|
| 28 | #define INCL_DOS
|
|---|
| 29 | #define INCL_DOSDEVIOCTL
|
|---|
| 30 | #include <os2.h>
|
|---|
| 31 | #include <malloc.h>
|
|---|
| 32 |
|
|---|
| 33 | #include <stdlib.h>
|
|---|
| 34 | #include <stdio.h>
|
|---|
| 35 | #include <ctype.h>
|
|---|
| 36 | #include <conio.h>
|
|---|
| 37 | #include <string.h>
|
|---|
| 38 |
|
|---|
| 39 | #include "msghelp.c"
|
|---|
| 40 |
|
|---|
| 41 | // Msg-IDs from OSO001.msg
|
|---|
| 42 | #define TXT_QUERY_TimeLimit_None 860
|
|---|
| 43 | #define TXT_QUERY_TimeLimit_Show 861
|
|---|
| 44 | #define TXT_QUERY_Mode_Extended 863
|
|---|
| 45 | #define TXT_QUERY_Mode_Normal 864
|
|---|
| 46 | #define TXT_SYNTAX_Show 867
|
|---|
| 47 | #define TXT_ERROR_DuringAccessHDD 868
|
|---|
| 48 | #define TXT_ERROR_NoValueFor 870
|
|---|
| 49 | #define TXT_ERROR_NeedsValueFor 871
|
|---|
| 50 | #define TXT_ERROR_BadParameter 872
|
|---|
| 51 | #define TXT_ERROR_BadValueFor 873
|
|---|
| 52 | #define TXT_ERROR_NoBootManager 874
|
|---|
| 53 |
|
|---|
| 54 | #pragma pack(1)
|
|---|
| 55 |
|
|---|
| 56 | // This structure needs NOT to get optimized, otherwise it will screw up...
|
|---|
| 57 | typedef struct _AiRBOOTCODESIG {
|
|---|
| 58 | CHAR Identifier[7];
|
|---|
| 59 | UCHAR DayOfRelease;
|
|---|
| 60 | UCHAR MonthOfRelease;
|
|---|
| 61 | USHORT YearOfRelease;
|
|---|
| 62 | UCHAR MajorVersion;
|
|---|
| 63 | UCHAR MinorVersion;
|
|---|
| 64 | CHAR ReleaseLanguage;
|
|---|
| 65 | UCHAR TotalCodeSectors;
|
|---|
| 66 | USHORT CheckSumOfCode;
|
|---|
| 67 | } AiRBOOTCODESIG;
|
|---|
| 68 | typedef AiRBOOTCODESIG *PAiRBOOTCODESIG;
|
|---|
| 69 |
|
|---|
| 70 | typedef struct _AiRBOOTCONFIG {
|
|---|
| 71 | CHAR Identifier[13]; // Rousseau: INVISIBLE CHAR AT END !
|
|---|
| 72 | UCHAR MajorVersion;
|
|---|
| 73 | UCHAR MinorVersion;
|
|---|
| 74 | CHAR ReleaseLanguage;
|
|---|
| 75 | ULONG EditCounter;
|
|---|
| 76 | USHORT CheckSumOfConfig;
|
|---|
| 77 | UCHAR Partitions;
|
|---|
| 78 | UCHAR Meaningless1;
|
|---|
| 79 | UCHAR DefaultPartition;
|
|---|
| 80 | UCHAR LastPartition;
|
|---|
| 81 | UCHAR TimedBoot;
|
|---|
| 82 | UCHAR TimedSeconds;
|
|---|
| 83 | USHORT Meaningless2;
|
|---|
| 84 | UCHAR TimedBootLast;
|
|---|
| 85 | UCHAR RememberBoot;
|
|---|
| 86 | UCHAR RememberTimed;
|
|---|
| 87 | UCHAR IncludeFloppy;
|
|---|
| 88 | UCHAR BootMenuActive;
|
|---|
| 89 | UCHAR PartitionsDetect;
|
|---|
| 90 | UCHAR PasswordedSetup;
|
|---|
| 91 | UCHAR PasswordedSystem;
|
|---|
| 92 | UCHAR PasswordedChangeBoot;
|
|---|
| 93 | UCHAR ProtectMBRTSR;
|
|---|
| 94 | UCHAR ProtectMBRignore;
|
|---|
| 95 | UCHAR FloppyGetName;
|
|---|
| 96 | UCHAR DetectVirus;
|
|---|
| 97 | UCHAR DetectStealth;
|
|---|
| 98 | UCHAR DetectVIBR;
|
|---|
| 99 | UCHAR AutoEnterSetup;
|
|---|
| 100 | UCHAR MasterPassword[8];
|
|---|
| 101 | UCHAR BootPassword[8];
|
|---|
| 102 | UCHAR Meaningless3;
|
|---|
| 103 | UCHAR LinuxPartition;
|
|---|
| 104 | UCHAR TimedKeyHandling;
|
|---|
| 105 | UCHAR MakeSound;
|
|---|
| 106 | UCHAR FloppyGetTimer;
|
|---|
| 107 | UCHAR ResumeBIOSbootSeq;
|
|---|
| 108 | UCHAR CooperBars;
|
|---|
| 109 | CHAR LinuxCommandLine[75];
|
|---|
| 110 | UCHAR LinuxKernelPartition;
|
|---|
| 111 | CHAR LinuxDefaultKernel[11];
|
|---|
| 112 | UCHAR LinuxKernelNameEnd;
|
|---|
| 113 | CHAR LinuxLastKernel[11];
|
|---|
| 114 | UCHAR LinuxKernelNameEnd2;
|
|---|
| 115 | UCHAR ExtPartitionMShack;
|
|---|
| 116 | UCHAR AutomaticBoot;
|
|---|
| 117 | UCHAR AutomaticPartition;
|
|---|
| 118 | UCHAR ForceLBAUsage;
|
|---|
| 119 | UCHAR IgnoreLVM;
|
|---|
| 120 | UCHAR Reserved[82];
|
|---|
| 121 | CHAR InstallVolume[12];
|
|---|
| 122 | } AiRBOOTCONFIG;
|
|---|
| 123 | typedef AiRBOOTCONFIG *PAiRBOOTCONFIG;
|
|---|
| 124 |
|
|---|
| 125 |
|
|---|
| 126 |
|
|---|
| 127 | typedef struct _AiRBOOTIPENTRY {
|
|---|
| 128 | ULONG SerialNumber;
|
|---|
| 129 | CHAR PartitionName[11];
|
|---|
| 130 | UCHAR Drive;
|
|---|
| 131 | UCHAR PartitionID;
|
|---|
| 132 | UCHAR Flags;
|
|---|
| 133 | USHORT CheckSum;
|
|---|
| 134 | UCHAR LocationBegin[3];
|
|---|
| 135 | UCHAR LocationPartTab[3];
|
|---|
| 136 | ULONG AbsoluteBegin;
|
|---|
| 137 | ULONG AbsolutePartTab;
|
|---|
| 138 | } AiRBOOTIPENTRY;
|
|---|
| 139 | typedef AiRBOOTIPENTRY *PAiRBOOTIPENTRY;
|
|---|
| 140 |
|
|---|
| 141 | #pragma pack()
|
|---|
| 142 |
|
|---|
| 143 | #define AiRBOOTIPENTRY_Flags_BootAble 0x01
|
|---|
| 144 |
|
|---|
| 145 | CHAR Track0[60*512]; // Space for Track-0
|
|---|
| 146 | PAiRBOOTCODESIG AiRBOOT_CodeSig = 0;
|
|---|
| 147 | PAiRBOOTCONFIG AiRBOOT_Config = 0;
|
|---|
| 148 | PAiRBOOTIPENTRY AiRBOOT_IPT = 0;
|
|---|
| 149 | USHORT AiRBOOT_ConfigCheckSum = 0;
|
|---|
| 150 | UCHAR AiRBOOT_IPTCount = 0;
|
|---|
| 151 |
|
|---|
| 152 |
|
|---|
| 153 | /* Executables to search for */
|
|---|
| 154 | PCHAR classic_setboots[] = {
|
|---|
| 155 | "SETBM.EXE",
|
|---|
| 156 | NULL
|
|---|
| 157 | };
|
|---|
| 158 |
|
|---|
| 159 |
|
|---|
| 160 | /*
|
|---|
| 161 | // ProtoTypes.
|
|---|
| 162 | */
|
|---|
| 163 | BOOL Track0DetectAirBoot (BOOL* ab_bad);
|
|---|
| 164 | BOOL Track0WriteAiRBOOTConfig (void);
|
|---|
| 165 |
|
|---|
| 166 |
|
|---|
| 167 |
|
|---|
| 168 | USHORT CountHarddrives (void) {
|
|---|
| 169 | USHORT NumDrives = 0;
|
|---|
| 170 |
|
|---|
| 171 | if (DosPhysicalDisk(INFO_COUNT_PARTITIONABLE_DISKS, &NumDrives, sizeof(NumDrives),NULL, 0) != 0)
|
|---|
| 172 | return 0;
|
|---|
| 173 | return NumDrives;
|
|---|
| 174 | }
|
|---|
| 175 |
|
|---|
| 176 | USHORT OS2_GetIOCTLHandle () {
|
|---|
| 177 | USHORT IOCTLHandle = 0;
|
|---|
| 178 |
|
|---|
| 179 | if (DosPhysicalDisk(INFO_GETIOCTLHANDLE, &IOCTLHandle, sizeof(IOCTLHandle),"1:" , 3) != 0)
|
|---|
| 180 | return 0;
|
|---|
| 181 | return IOCTLHandle;
|
|---|
| 182 | }
|
|---|
| 183 |
|
|---|
| 184 | void OS2_FreeIOCTLHandle (USHORT IOCTLHandle) {
|
|---|
| 185 | DosPhysicalDisk(INFO_FREEIOCTLHANDLE, NULL, 0, &IOCTLHandle, sizeof(IOCTLHandle));
|
|---|
| 186 | return;
|
|---|
| 187 | }
|
|---|
| 188 |
|
|---|
| 189 | BOOL Track0Load (void) {
|
|---|
| 190 | USHORT IOCTLHandle;
|
|---|
| 191 | ULONG TrackLayoutLen = sizeof(TRACKLAYOUT)+sizeof(ULONG)*(60-1);
|
|---|
| 192 | TRACKLAYOUT *TrackLayoutPtr = malloc(TrackLayoutLen);
|
|---|
| 193 | ULONG cbParms = sizeof(TrackLayoutPtr);
|
|---|
| 194 | ULONG cbData = 512;
|
|---|
| 195 | int i;
|
|---|
| 196 | BOOL Success = FALSE;
|
|---|
| 197 |
|
|---|
| 198 | IOCTLHandle = OS2_GetIOCTLHandle();
|
|---|
| 199 |
|
|---|
| 200 | TrackLayoutPtr->bCommand = 0x01;
|
|---|
| 201 | TrackLayoutPtr->usHead = 0;
|
|---|
| 202 | TrackLayoutPtr->usCylinder = 0;
|
|---|
| 203 | TrackLayoutPtr->usFirstSector = 0;
|
|---|
| 204 | TrackLayoutPtr->cSectors = 60;
|
|---|
| 205 |
|
|---|
| 206 | for (i=0; i<60; i++) {
|
|---|
| 207 | TrackLayoutPtr->TrackTable[i].usSectorNumber = i+1;
|
|---|
| 208 | TrackLayoutPtr->TrackTable[i].usSectorSize = 512;
|
|---|
| 209 | }
|
|---|
| 210 |
|
|---|
| 211 | if (!DosDevIOCtl(IOCTLHandle, IOCTL_PHYSICALDISK, PDSK_READPHYSTRACK,
|
|---|
| 212 | TrackLayoutPtr, cbParms, &cbParms, &Track0, cbData, &cbData))
|
|---|
| 213 | Success = TRUE;
|
|---|
| 214 | OS2_FreeIOCTLHandle (IOCTLHandle);
|
|---|
| 215 | free (TrackLayoutPtr);
|
|---|
| 216 | return Success;
|
|---|
| 217 | }
|
|---|
| 218 |
|
|---|
| 219 | BOOL Track0Write (void) {
|
|---|
| 220 | USHORT IOCTLHandle;
|
|---|
| 221 | ULONG TrackLayoutLen = sizeof(TRACKLAYOUT)+sizeof(ULONG)*(60-1);
|
|---|
| 222 | TRACKLAYOUT *TrackLayoutPtr = malloc(TrackLayoutLen);
|
|---|
| 223 | ULONG cbParms = sizeof(TrackLayoutPtr);
|
|---|
| 224 | ULONG cbData = 512;
|
|---|
| 225 | INT i;
|
|---|
| 226 | BOOL Success = FALSE;
|
|---|
| 227 |
|
|---|
| 228 | IOCTLHandle = OS2_GetIOCTLHandle();
|
|---|
| 229 |
|
|---|
| 230 |
|
|---|
| 231 | TrackLayoutPtr->bCommand = 0x01;
|
|---|
| 232 | TrackLayoutPtr->usHead = 0;
|
|---|
| 233 | TrackLayoutPtr->usCylinder = 0;
|
|---|
| 234 | TrackLayoutPtr->usFirstSector = 0;
|
|---|
| 235 | TrackLayoutPtr->cSectors = 60;
|
|---|
| 236 |
|
|---|
| 237 | for (i=0; i<60; i++) {
|
|---|
| 238 | TrackLayoutPtr->TrackTable[i].usSectorNumber = i+1;
|
|---|
| 239 | TrackLayoutPtr->TrackTable[i].usSectorSize = 512;
|
|---|
| 240 | }
|
|---|
| 241 |
|
|---|
| 242 | if (!DosDevIOCtl(IOCTLHandle, IOCTL_PHYSICALDISK, PDSK_WRITEPHYSTRACK,
|
|---|
| 243 | TrackLayoutPtr, cbParms, &cbParms, &Track0, cbData, &cbData))
|
|---|
| 244 | Success = TRUE;
|
|---|
| 245 | OS2_FreeIOCTLHandle (IOCTLHandle);
|
|---|
| 246 | free (TrackLayoutPtr);
|
|---|
| 247 | return Success;
|
|---|
| 248 | }
|
|---|
| 249 |
|
|---|
| 250 | #define CATEGORY_DOSSYS 0xD5
|
|---|
| 251 | #define FUNCTION_REBOOT 0xAB
|
|---|
| 252 |
|
|---|
| 253 | void RebootSystem (void) {
|
|---|
| 254 | HFILE DosHandle;
|
|---|
| 255 | ULONG DosOpenAction;
|
|---|
| 256 |
|
|---|
| 257 | DosSleep (2000);
|
|---|
| 258 | if (!DosOpen("DOS$", &DosHandle, &DosOpenAction, 0, FILE_NORMAL, FILE_OPEN, OPEN_ACCESS_READWRITE|OPEN_SHARE_DENYNONE, NULL)) {
|
|---|
| 259 | DosDevIOCtl(DosHandle, CATEGORY_DOSSYS, FUNCTION_REBOOT, NULL, 0, NULL, NULL, 0, NULL);
|
|---|
| 260 | DosSleep (60000);
|
|---|
| 261 | }
|
|---|
| 262 | DosClose(DosHandle);
|
|---|
| 263 | }
|
|---|
| 264 |
|
|---|
| 265 |
|
|---|
| 266 | APIRET QueryBootDrive(char *bootdrv)
|
|---|
| 267 | {
|
|---|
| 268 | ULONG aulSysInfo[QSV_MAX] = {0}; // System Information Data Buffer
|
|---|
| 269 | APIRET rc = NO_ERROR; // Return code
|
|---|
| 270 |
|
|---|
| 271 | if(bootdrv==0) return 1;
|
|---|
| 272 |
|
|---|
| 273 | rc = DosQuerySysInfo(1L, // Request all available system
|
|---|
| 274 | QSV_MAX , // information
|
|---|
| 275 | (PVOID)aulSysInfo, // Pointer to buffer
|
|---|
| 276 | sizeof(ULONG)*QSV_MAX); // Size of the buffer
|
|---|
| 277 |
|
|---|
| 278 | if (rc != NO_ERROR) {
|
|---|
| 279 | return 1;
|
|---|
| 280 | }
|
|---|
| 281 | else {
|
|---|
| 282 | //printf("Bootable drive: %c:\n",
|
|---|
| 283 | // aulSysInfo[QSV_BOOT_DRIVE-1]+'A'-1); /* Max length of path name */
|
|---|
| 284 | bootdrv[0]=aulSysInfo[QSV_BOOT_DRIVE-1]+'A'-1;
|
|---|
| 285 |
|
|---|
| 286 | /*
|
|---|
| 287 | printf("Total physical memory is %u bytes.\n",
|
|---|
| 288 | aulSysInfo[QSV_TOTPHYSMEM-1]);
|
|---|
| 289 | */
|
|---|
| 290 |
|
|---|
| 291 | return 0;
|
|---|
| 292 | }
|
|---|
| 293 |
|
|---|
| 294 |
|
|---|
| 295 | }
|
|---|
| 296 |
|
|---|
| 297 | USHORT GetChecksumOfSector (USHORT BaseCheck, USHORT SectorNo) {
|
|---|
| 298 | PUSHORT CurPos = (PUSHORT)((ULONG)&Track0+(SectorNo-1)*512);
|
|---|
| 299 | USHORT LengthLeft = 256;
|
|---|
| 300 |
|
|---|
| 301 | while (LengthLeft-->0)
|
|---|
| 302 | BaseCheck ^= (*CurPos++ ^ 0x0BABE);
|
|---|
| 303 | if (BaseCheck==0) BaseCheck = 1;
|
|---|
| 304 | return BaseCheck;
|
|---|
| 305 | }
|
|---|
| 306 |
|
|---|
| 307 |
|
|---|
| 308 |
|
|---|
| 309 |
|
|---|
| 310 | /*
|
|---|
| 311 | // If AiR-BOOT is not installed, the user probably meant to control OS/2 BM with this utility.
|
|---|
| 312 | // Since the functionality of this utility is for AiR-BOOT only, we will pass the request to
|
|---|
| 313 | // the OS/2 BM SETBOOT utility which is called SETBM.EXE as of eCS 2.01.
|
|---|
| 314 | // Since the objective here is to supply OS/2 BM SETBOOT compatibility, if SETBM.EXE is not found,
|
|---|
| 315 | // some other system locations are searched for the OS/2 version of SETBOOT.EXE.
|
|---|
| 316 | // Any SETBOOT.EXE that is found and that does not have a module-name of "setaboot" is invoked,
|
|---|
| 317 | // and passed along the command-line the user issued.
|
|---|
| 318 | // In this case also the return-value of the OS/2 version of SETBOOT.EXE is returned.
|
|---|
| 319 | */
|
|---|
| 320 | int DoClassicActions(int argc, char **argv) {
|
|---|
| 321 | APIRET rc = -1;
|
|---|
| 322 | RESULTCODES crc = {-1,-1};
|
|---|
| 323 | PTIB ptib = NULL;
|
|---|
| 324 | PPIB ppib = NULL;
|
|---|
| 325 | char buffer[256] = "\0";
|
|---|
| 326 | char cmdline[256] = "\0";
|
|---|
| 327 | PSZ path = NULL;
|
|---|
| 328 | char sresult[256] = "\0";
|
|---|
| 329 | char bootdrive = '?';
|
|---|
| 330 | char* p = NULL;
|
|---|
| 331 | int i = 0;
|
|---|
| 332 |
|
|---|
| 333 | //printf("\nCLASSIC ACTIONS !! (%d)\n", argc);
|
|---|
| 334 |
|
|---|
| 335 | rc = QueryBootDrive(&bootdrive);
|
|---|
| 336 |
|
|---|
| 337 | rc = DosScanEnv("PATH", &path);
|
|---|
| 338 | rc = DosSearchPath(SEARCH_CUR_DIRECTORY | SEARCH_IGNORENETERRS,
|
|---|
| 339 | path,
|
|---|
| 340 | classic_setboots[0],
|
|---|
| 341 | sresult,
|
|---|
| 342 | sizeof(sresult));
|
|---|
| 343 |
|
|---|
| 344 | //printf("SRESULT: rc=%d, %s\n", rc, sresult);
|
|---|
| 345 |
|
|---|
| 346 | if (rc) {
|
|---|
| 347 | printf("\n");
|
|---|
| 348 | printf("ERROR: SETBOOT (AiR-BOOT version)\n");
|
|---|
| 349 | printf("Since the AiR-BOOT Boot Manager is not installed, this program (SETBOOT.EXE), funcions as a wrapper\n");
|
|---|
| 350 | printf("to %s that should be used to control IBM Boot Manager.\n", classic_setboots[0]);
|
|---|
| 351 | printf("However, %s could not be found in the PATH, the error-code is: %d\n", classic_setboots[0], rc);
|
|---|
| 352 | printf("You can resolve this situation by renaming a valid SETBOOT.EXE to %s\n", classic_setboots[0]);
|
|---|
| 353 | printf("and put it in your %c:\\OS2 directory.", bootdrive);
|
|---|
| 354 | printf("\n");
|
|---|
| 355 | exit(rc);
|
|---|
| 356 | }
|
|---|
| 357 |
|
|---|
| 358 |
|
|---|
| 359 |
|
|---|
| 360 |
|
|---|
| 361 | memset(cmdline, 0, sizeof(cmdline)); // Clear the command-line buffer.
|
|---|
| 362 | p = cmdline; // Temporary pointer to insert arguments.
|
|---|
| 363 | strcpy(p, sresult); // Copy the program-name.
|
|---|
| 364 | p += strlen(sresult)+1; // Advance to point for space separated parameters.
|
|---|
| 365 |
|
|---|
| 366 | /*
|
|---|
| 367 | // Process all the arguments,
|
|---|
| 368 | // inserting the separated by a space.
|
|---|
| 369 | */
|
|---|
| 370 | for (i=1; i<argc; i++) {
|
|---|
| 371 | strcpy(p, argv[i]); // Copy the argument.
|
|---|
| 372 | p += strlen(argv[i]); // Advance pointer past argument.
|
|---|
| 373 | *p++ = ' '; // Space separation.
|
|---|
| 374 | }
|
|---|
| 375 |
|
|---|
| 376 | /*
|
|---|
| 377 | for (i=0; i<100; i++) {
|
|---|
| 378 | printf("%c", cmdline[i] ? cmdline[i] : '#');
|
|---|
| 379 | }
|
|---|
| 380 | printf("\n");
|
|---|
| 381 | */
|
|---|
| 382 |
|
|---|
| 383 | //printf("CMDLINE: %s\n", cmdline);
|
|---|
| 384 | //printf("CMDLINE+: %s\n", cmdline+strlen(sresult)+1);
|
|---|
| 385 |
|
|---|
| 386 | rc = DosExecPgm(buffer,
|
|---|
| 387 | sizeof(buffer),
|
|---|
| 388 | EXEC_SYNC,
|
|---|
| 389 | cmdline,
|
|---|
| 390 | NULL,
|
|---|
| 391 | &crc,
|
|---|
| 392 | sresult);
|
|---|
| 393 |
|
|---|
| 394 | //rc = 3;
|
|---|
| 395 | if (rc) {
|
|---|
| 396 | printf("\n");
|
|---|
| 397 | printf("ERROR: SETBOOT (AiR-BOOT version)\n");
|
|---|
| 398 | printf("Since the AiR-BOOT Boot Manager is not installed, this program (SETBOOT.EXE), funcions as a wrapper\n");
|
|---|
| 399 | printf("to %s that should be used to control IBM Boot Manager.\n", classic_setboots[0]);
|
|---|
| 400 | printf("However, something went wrong when executing %s.\n", classic_setboots[0]);
|
|---|
| 401 | printf("The error-code is: %d and the termination-code is: %d\n", rc, crc.codeTerminate);
|
|---|
| 402 | printf("\n");
|
|---|
| 403 | exit(rc);
|
|---|
| 404 | }
|
|---|
| 405 |
|
|---|
| 406 |
|
|---|
| 407 | //printf("DosExecPgm: rc=%08X, codeterminate=%08X, coderesult=%08X\n", rc, crc.codeTerminate, crc.codeResult);
|
|---|
| 408 |
|
|---|
| 409 | /*
|
|---|
| 410 | rc = DosGetInfoBlocks(&ptib, &ppib);
|
|---|
| 411 |
|
|---|
| 412 | rc = DosQueryModuleName(ppib->pib_hmte, sizeof(buffer), buffer);
|
|---|
| 413 | printf("MODULE: %s\n", buffer);
|
|---|
| 414 | printf("CMDLINE: %s\n", ppib->pib_pchcmd);
|
|---|
| 415 | */
|
|---|
| 416 |
|
|---|
| 417 | return crc.codeResult;
|
|---|
| 418 | }
|
|---|
| 419 |
|
|---|
| 420 |
|
|---|
| 421 | int DoAirBootActions(int argc, char **argv, BOOL ab_detected, BOOL ab_bad) {
|
|---|
| 422 | ULONG CurArgument = 0;
|
|---|
| 423 | ULONG ArgumentLen = 0;
|
|---|
| 424 | PCHAR StartPos = 0;
|
|---|
| 425 | PCHAR EndPos = 0;
|
|---|
| 426 | PCHAR CurPos = 0;
|
|---|
| 427 | CHAR CurChar = 0;
|
|---|
| 428 | BOOL DoXWPSupport = FALSE;
|
|---|
| 429 | BOOL DoQuery = FALSE;
|
|---|
| 430 | BOOL DoSetTimer = FALSE;
|
|---|
| 431 | SHORT SetTimerValue = 0;
|
|---|
| 432 | BOOL DoSetBootMenu = FALSE;
|
|---|
| 433 | BOOL BootMenuDetailed = FALSE;
|
|---|
| 434 | BOOL DoDirectBoot = FALSE;
|
|---|
| 435 | BOOL DisableDirectBoot= FALSE;
|
|---|
| 436 | UCHAR DirectBootPart = 0;
|
|---|
| 437 | BOOL DoReboot = FALSE;
|
|---|
| 438 | BOOL AiRBOOTDetected = FALSE;
|
|---|
| 439 | BOOL AiRBOOTChanged = FALSE;
|
|---|
| 440 | BOOL BadParm = FALSE;
|
|---|
| 441 | BOOL BadValue = FALSE;
|
|---|
| 442 | UCHAR CurPartitionNo = 0;
|
|---|
| 443 | PAiRBOOTIPENTRY CurIPTEntry = 0;
|
|---|
| 444 | CHAR TempBuffer[10];
|
|---|
| 445 | ULONG XWPStringSize = 0;
|
|---|
| 446 | PCHAR XWPOrgStringPtr = 0;
|
|---|
| 447 | ULONG WriteLeft = 0;
|
|---|
| 448 | ULONG TmpLength = 0;
|
|---|
| 449 | ULONG TmpLength2 = 0;
|
|---|
| 450 | ULONG XWPBootCount = 0;
|
|---|
| 451 | CHAR XWPBootName[30][12];
|
|---|
| 452 | CHAR XWPBootCommand[30][28]; // 'setaboot /IBA:""' (16 chars)
|
|---|
| 453 | BOOL XWPEntryFound = FALSE;
|
|---|
| 454 | BOOL CDBoot = FALSE; // TRUE if booted from CD; New System will be added when using /4:"LABEL"
|
|---|
| 455 | BOOL Track0Loaded = FALSE; // Assume track0 did not load correctly.
|
|---|
| 456 | BOOL AiRBOOTBad = FALSE;
|
|---|
| 457 |
|
|---|
| 458 | //printf("\nAiR-BOOT ACTIONS !!\n");
|
|---|
| 459 |
|
|---|
| 460 | AiRBOOTDetected = ab_detected;
|
|---|
| 461 | AiRBOOTBad = ab_bad;
|
|---|
| 462 |
|
|---|
| 463 | if (AiRBOOTBad)
|
|---|
| 464 | return 1;
|
|---|
| 465 |
|
|---|
| 466 | // Use OSO001.MSG, so we safe us the trouble of translating :)
|
|---|
| 467 | if (!MSG_Init("OSO001.MSG"))
|
|---|
| 468 | return 1;
|
|---|
| 469 |
|
|---|
| 470 | /*
|
|---|
| 471 | // Rousseau: changed version to be the same as the AiR-BOOT is accompanies.
|
|---|
| 472 | */
|
|---|
| 473 | //puts ("SETABOOT - AiR-BOOT Configuration Utility (OS/2) - (c) 2004-2009 by M. Kiewitz");
|
|---|
| 474 | puts ("SETABOOT v1.07 - AiR-BOOT Configuration Utility - (c) 2004-2011 by M. Kiewitz");
|
|---|
| 475 |
|
|---|
| 476 |
|
|---|
| 477 | //return 0;
|
|---|
| 478 |
|
|---|
| 479 | /*
|
|---|
| 480 | // Rousseau:
|
|---|
| 481 | // Log some debug stuff to (virtual) flop.
|
|---|
| 482 | */
|
|---|
| 483 | /*
|
|---|
| 484 | {
|
|---|
| 485 | char buf[512]="\0";
|
|---|
| 486 | FILE* fp = NULL;
|
|---|
| 487 | int i = 0;
|
|---|
| 488 |
|
|---|
| 489 | fp = fopen("A:\\SETBOOT.TXT", "a");
|
|---|
| 490 | sprintf(buf, "Bliep");
|
|---|
| 491 | fprintf(fp,"Program: %s\n", argv[0]);
|
|---|
| 492 | fprintf(fp,"Arguments: %d\n", argc);
|
|---|
| 493 | for (i=0; i<argc-1; i++) {
|
|---|
| 494 | fprintf(fp, "Arg %d: %s\n", i+1, argv[i+1]);
|
|---|
| 495 | }
|
|---|
| 496 | fprintf(fp, "\n");
|
|---|
| 497 | fclose(fp);
|
|---|
| 498 | }
|
|---|
| 499 | */
|
|---|
| 500 |
|
|---|
| 501 |
|
|---|
| 502 |
|
|---|
| 503 | /*
|
|---|
| 504 | // Rousseau: ## Enable boot-through when installing new system ##
|
|---|
| 505 | // In the install-environment, the MEMDRIVE env-var is defined.
|
|---|
| 506 | // This modifies the behavior after phase 1.
|
|---|
| 507 | */
|
|---|
| 508 | if (getenv("MEMDRIVE")) {
|
|---|
| 509 | printf("CDBoot Environment.\n");
|
|---|
| 510 | CDBoot = TRUE;
|
|---|
| 511 | }
|
|---|
| 512 |
|
|---|
| 513 |
|
|---|
| 514 | if (argc==1) {
|
|---|
| 515 | MSG_Print (TXT_SYNTAX_Show);
|
|---|
| 516 | return 1;
|
|---|
| 517 | }
|
|---|
| 518 |
|
|---|
| 519 |
|
|---|
| 520 |
|
|---|
| 521 |
|
|---|
| 522 | // Now we check for AiR-BOOT existance...
|
|---|
| 523 | /*
|
|---|
| 524 | if (CountHarddrives()>0) {
|
|---|
| 525 | if (Track0Load()) {
|
|---|
| 526 | // Rousseau: Track0DetectAirBoot() will init globals.
|
|---|
| 527 | if (Track0DetectAirBoot()) // REPLACE WITH BOOL
|
|---|
| 528 | AiRBOOTDetected = TRUE;
|
|---|
| 529 | }
|
|---|
| 530 | else {
|
|---|
| 531 | MSG_Print (TXT_ERROR_DuringAccessHDD);
|
|---|
| 532 | }
|
|---|
| 533 | }
|
|---|
| 534 | else {
|
|---|
| 535 | MSG_Print (TXT_ERROR_DuringAccessHDD);
|
|---|
| 536 | }
|
|---|
| 537 | */
|
|---|
| 538 |
|
|---|
| 539 | CurArgument = 1;
|
|---|
| 540 | while (CurArgument<argc) {
|
|---|
| 541 | StartPos = argv[CurArgument];
|
|---|
| 542 | ArgumentLen = strlen(StartPos);
|
|---|
| 543 |
|
|---|
| 544 | if ((*StartPos=='/') && (ArgumentLen>1)) {
|
|---|
| 545 | StartPos++; ArgumentLen--;
|
|---|
| 546 | CurChar = toupper(*StartPos++);
|
|---|
| 547 |
|
|---|
| 548 | switch (CurChar) {
|
|---|
| 549 | case '?':
|
|---|
| 550 | MSG_Print (TXT_SYNTAX_Show);
|
|---|
| 551 | return 1;
|
|---|
| 552 | case 'B':
|
|---|
| 553 | if (ArgumentLen==1) DoReboot = TRUE;
|
|---|
| 554 | else BadParm = TRUE;
|
|---|
| 555 | break;
|
|---|
| 556 | case 'Q':
|
|---|
| 557 | if (ArgumentLen==1) DoQuery = TRUE;
|
|---|
| 558 | else BadParm = TRUE;
|
|---|
| 559 | break;
|
|---|
| 560 | case 'T':
|
|---|
| 561 | DoSetTimer = TRUE;
|
|---|
| 562 | if ((ArgumentLen>2) && (*StartPos==':')) {
|
|---|
| 563 | *StartPos = 0; StartPos++;
|
|---|
| 564 | CurPos = StartPos;
|
|---|
| 565 | while (*CurPos!=0) {
|
|---|
| 566 | if ((*CurPos<'0') || (*CurPos>'9')) {
|
|---|
| 567 | BadValue = TRUE;
|
|---|
| 568 | break;
|
|---|
| 569 | }
|
|---|
| 570 | CurPos++;
|
|---|
| 571 | }
|
|---|
| 572 | if (!BadValue) {
|
|---|
| 573 | SetTimerValue = atoi(StartPos);
|
|---|
| 574 | if ((SetTimerValue<0) || (SetTimerValue>255))
|
|---|
| 575 | BadValue = TRUE;
|
|---|
| 576 | } else {
|
|---|
| 577 | if ((ArgumentLen==4) && (toupper(*CurPos)=='N') && (toupper(*(CurPos+1))=='O')) {
|
|---|
| 578 | BadValue = FALSE;
|
|---|
| 579 | SetTimerValue = -1; // Disable Timer
|
|---|
| 580 | }
|
|---|
| 581 | }
|
|---|
| 582 | } else BadParm = TRUE;
|
|---|
| 583 | break;
|
|---|
| 584 | case 'M':
|
|---|
| 585 | DoSetBootMenu = TRUE;
|
|---|
| 586 | if ((ArgumentLen>2) && (*StartPos==':')) {
|
|---|
| 587 | *StartPos = 0; StartPos++;
|
|---|
| 588 | CurChar = toupper(*StartPos);
|
|---|
| 589 | switch (CurChar) {
|
|---|
| 590 | case 'N':
|
|---|
| 591 | BootMenuDetailed = FALSE;
|
|---|
| 592 | break;
|
|---|
| 593 | case 'A':
|
|---|
| 594 | BootMenuDetailed = TRUE;
|
|---|
| 595 | break;
|
|---|
| 596 | default:
|
|---|
| 597 | BadValue = TRUE;
|
|---|
| 598 | break;
|
|---|
| 599 | }
|
|---|
| 600 | if ((AiRBOOT_CodeSig->MajorVersion==0x00) && (AiRBOOT_CodeSig->MinorVersion<0x91)) {
|
|---|
| 601 | puts ("SETABOOT: AiR-BOOT v0.91 required for this feature.");
|
|---|
| 602 | BadValue = TRUE;
|
|---|
| 603 | }
|
|---|
| 604 | } else BadParm = TRUE;
|
|---|
| 605 | break;
|
|---|
| 606 | case 'I':
|
|---|
| 607 | case '4':
|
|---|
| 608 | DoDirectBoot = TRUE;
|
|---|
| 609 | if (CurChar=='I') {
|
|---|
| 610 | if ((ArgumentLen>4) && (ArgumentLen<16) && (toupper(*StartPos++)=='B') && (toupper(*StartPos++)=='A') && (*StartPos==':')) {
|
|---|
| 611 | DoReboot = TRUE; // IBA: requires us to reboot
|
|---|
| 612 | ArgumentLen -= 4;
|
|---|
| 613 | } else {
|
|---|
| 614 | BadParm = TRUE;
|
|---|
| 615 | break;
|
|---|
| 616 | }
|
|---|
| 617 | } else {
|
|---|
| 618 | if ((ArgumentLen>1) && (ArgumentLen<33) && (*StartPos==':')) {
|
|---|
| 619 | ArgumentLen -= 2;
|
|---|
| 620 | } else {
|
|---|
| 621 | BadParm = TRUE;
|
|---|
| 622 | break;
|
|---|
| 623 | }
|
|---|
| 624 | }
|
|---|
| 625 |
|
|---|
| 626 | *StartPos = 0; StartPos++;
|
|---|
| 627 |
|
|---|
| 628 | // Search that partition in IPT of AiR-BOOT...
|
|---|
| 629 | if ((CurChar=='4') && (ArgumentLen==0)) {
|
|---|
| 630 | // '4:' and no partition name means disable automatic boot
|
|---|
| 631 | DoDirectBoot = FALSE;
|
|---|
| 632 | DisableDirectBoot = TRUE;
|
|---|
| 633 | break;
|
|---|
| 634 | }
|
|---|
| 635 | if (ArgumentLen>11)
|
|---|
| 636 | ArgumentLen = 11;
|
|---|
| 637 |
|
|---|
| 638 | if (!AiRBOOTDetected) {
|
|---|
| 639 | MSG_Print (TXT_ERROR_NoBootManager);
|
|---|
| 640 | return 1;
|
|---|
| 641 | }
|
|---|
| 642 |
|
|---|
| 643 |
|
|---|
| 644 | /*
|
|---|
| 645 | // Rousseau:
|
|---|
| 646 | // Insert label of newly installed system in AiR-BOOT configuration.
|
|---|
| 647 | // Note that it is changed to uppercase because AiR-BOOT uses the FS-label when
|
|---|
| 648 | // scanning partitions and LVM-info is not found. (Otherwise PART-label)
|
|---|
| 649 | // The auto-boot flag is not set in this case as this is handled by the AiR-BOOT loader.
|
|---|
| 650 | */
|
|---|
| 651 | if (CDBoot) {
|
|---|
| 652 | strncpy(AiRBOOT_Config->InstallVolume, _strupr(StartPos), ArgumentLen);
|
|---|
| 653 | AiRBOOT_Config->InstallVolume[ArgumentLen] = '\0';
|
|---|
| 654 | printf("Writing Install Volume: %s to AiR-BOOT configuration.\n", AiRBOOT_Config->InstallVolume);
|
|---|
| 655 | Track0WriteAiRBOOTConfig();
|
|---|
| 656 | return 0;
|
|---|
| 657 | }
|
|---|
| 658 |
|
|---|
| 659 |
|
|---|
| 660 |
|
|---|
| 661 |
|
|---|
| 662 | BadValue = TRUE;
|
|---|
| 663 | CurPartitionNo = 0; CurIPTEntry = AiRBOOT_IPT;
|
|---|
| 664 | while (CurPartitionNo<AiRBOOT_Config->Partitions) {
|
|---|
| 665 | /*
|
|---|
| 666 | // Rousseau: Changed below to case-insensitive compare.
|
|---|
| 667 | // This solves the part/vol-label (mixed-case) v.s. fs-label (upper-case) issue.
|
|---|
| 668 | */
|
|---|
| 669 | /*if (strncmp(CurIPTEntry->PartitionName, StartPos, ArgumentLen)==0) {*/
|
|---|
| 670 | if (strnicmp(CurIPTEntry->PartitionName, StartPos, ArgumentLen)==0) {
|
|---|
| 671 | if (ArgumentLen==11) {
|
|---|
| 672 | BadValue = FALSE;
|
|---|
| 673 | break;
|
|---|
| 674 | } else {
|
|---|
| 675 | CurPos = CurIPTEntry->PartitionName+ArgumentLen;
|
|---|
| 676 | EndPos = CurIPTEntry->PartitionName+11;
|
|---|
| 677 | while ((CurPos<EndPos) && ((*CurPos==0x00) || (*CurPos==0x20)))
|
|---|
| 678 | CurPos++;
|
|---|
| 679 | if (CurPos==EndPos) {
|
|---|
| 680 | BadValue = FALSE;
|
|---|
| 681 | break;
|
|---|
| 682 | }
|
|---|
| 683 | }
|
|---|
| 684 | }
|
|---|
| 685 | CurPartitionNo++; CurIPTEntry++;
|
|---|
| 686 | }
|
|---|
| 687 |
|
|---|
| 688 |
|
|---|
| 689 | if (BadValue) {
|
|---|
| 690 | puts ("SETABOOT: Partition not found in IPT.");
|
|---|
| 691 | } else {
|
|---|
| 692 | if (CurIPTEntry->Flags & AiRBOOTIPENTRY_Flags_BootAble) {
|
|---|
| 693 | DirectBootPart = CurPartitionNo;
|
|---|
| 694 | if ((AiRBOOT_CodeSig->MajorVersion==0x00) && (AiRBOOT_CodeSig->MinorVersion<0x94)) {
|
|---|
| 695 | puts ("SETABOOT: AiR-BOOT v0.94 required for this feature.");
|
|---|
| 696 | BadValue = TRUE;
|
|---|
| 697 | } else if ((AiRBOOT_Config->PasswordedSystem) || (AiRBOOT_Config->PasswordedChangeBoot)) {
|
|---|
| 698 | puts ("SETABOOT: This feature needs password protection to be off.");
|
|---|
| 699 | BadValue = TRUE;
|
|---|
| 700 | }
|
|---|
| 701 | } else {
|
|---|
| 702 | BadValue = TRUE;
|
|---|
| 703 | puts ("SETABOOT: Partition not set bootable.");
|
|---|
| 704 | }
|
|---|
| 705 | }
|
|---|
| 706 | break;
|
|---|
| 707 | case 'X':
|
|---|
| 708 | if ((ArgumentLen==3) && (toupper(*StartPos++)=='W') && (toupper(*StartPos++)=='P')) {
|
|---|
| 709 | if (!AiRBOOTDetected) {
|
|---|
| 710 | MSG_Print (TXT_ERROR_NoBootManager);
|
|---|
| 711 | return 1;
|
|---|
| 712 | }
|
|---|
| 713 | if ((AiRBOOT_CodeSig->MajorVersion==0x00) && (AiRBOOT_CodeSig->MinorVersion<0x94)) {
|
|---|
| 714 | puts ("SETABOOT: AiR-BOOT v0.94 required for this feature.");
|
|---|
| 715 | BadValue = TRUE;
|
|---|
| 716 | } else DoXWPSupport = TRUE;
|
|---|
| 717 | break;
|
|---|
| 718 | }
|
|---|
| 719 | case 'N':
|
|---|
| 720 | puts ("SETABOOT: No support for this option.");
|
|---|
| 721 | default:
|
|---|
| 722 | BadParm = TRUE;
|
|---|
| 723 | }
|
|---|
| 724 | } else BadParm = TRUE;
|
|---|
| 725 |
|
|---|
| 726 | if (BadParm) {
|
|---|
| 727 | MSG_SetInsertViaPSZ (1, argv[CurArgument]);
|
|---|
| 728 | MSG_Print (TXT_ERROR_BadParameter);
|
|---|
| 729 | return 1;
|
|---|
| 730 | }
|
|---|
| 731 | if (BadValue) {
|
|---|
| 732 | MSG_SetInsertViaPSZ (1, StartPos);
|
|---|
| 733 | MSG_SetInsertViaPSZ (2, argv[CurArgument]);
|
|---|
| 734 | MSG_Print (TXT_ERROR_BadValueFor);
|
|---|
| 735 | return 1;
|
|---|
| 736 | }
|
|---|
| 737 |
|
|---|
| 738 | CurArgument++;
|
|---|
| 739 | }
|
|---|
| 740 |
|
|---|
| 741 | if (DoXWPSupport) {
|
|---|
| 742 | if ((!PrfQueryProfileSize(HINI_USERPROFILE, "XWorkplace", "XShutdown", &XWPStringSize))) {
|
|---|
| 743 | puts ("SETABOOT: /XWP needs XWorkPlace.");
|
|---|
| 744 | return 1;
|
|---|
| 745 | }
|
|---|
| 746 | // First, get the current string...
|
|---|
| 747 | CurPos = XWPOrgStringPtr = malloc(65536);
|
|---|
| 748 | WriteLeft = XWPStringSize = 65536;
|
|---|
| 749 | if (!PrfQueryProfileData (HINI_USERPROFILE, "XWorkplace", "RebootTo", XWPOrgStringPtr, &XWPStringSize))
|
|---|
| 750 | XWPStringSize = 0;
|
|---|
| 751 | EndPos = CurPos+XWPStringSize;
|
|---|
| 752 |
|
|---|
| 753 | CurPartitionNo = 0; CurIPTEntry = AiRBOOT_IPT;
|
|---|
| 754 | while (CurPartitionNo<AiRBOOT_Config->Partitions) {
|
|---|
| 755 | if (CurIPTEntry->Flags & AiRBOOTIPENTRY_Flags_BootAble) {
|
|---|
| 756 | strncpy (XWPBootName[XWPBootCount], CurIPTEntry->PartitionName, 11);
|
|---|
| 757 | XWPBootName[XWPBootCount][11] = 0;
|
|---|
| 758 | sprintf (XWPBootCommand[XWPBootCount], "setaboot /IBA:\"%s\"", XWPBootName[XWPBootCount]);
|
|---|
| 759 | XWPBootCount++;
|
|---|
| 760 | }
|
|---|
| 761 | CurPartitionNo++; CurIPTEntry++;
|
|---|
| 762 | }
|
|---|
| 763 |
|
|---|
| 764 | while ((CurPos<EndPos) && (*CurPos!=0)) {
|
|---|
| 765 | StartPos = CurPos; TmpLength = strlen(CurPos)+1;
|
|---|
| 766 | CurPos += TmpLength; TmpLength2 = strlen(CurPos)+1;
|
|---|
| 767 |
|
|---|
| 768 | XWPEntryFound = FALSE;
|
|---|
| 769 | for (CurPartitionNo=0; CurPartitionNo<XWPBootCount; CurPartitionNo++) {
|
|---|
| 770 | if ((strcmp(StartPos, XWPBootName[CurPartitionNo])==0) && (strcmp(CurPos, XWPBootCommand[CurPartitionNo])==0))
|
|---|
| 771 | XWPBootCommand[CurPartitionNo][0] = 0;
|
|---|
| 772 | }
|
|---|
| 773 | CurPos += TmpLength2;
|
|---|
| 774 | WriteLeft -= TmpLength+TmpLength2;
|
|---|
| 775 | }
|
|---|
| 776 |
|
|---|
| 777 | for (CurPartitionNo=0; CurPartitionNo<XWPBootCount; CurPartitionNo++) {
|
|---|
| 778 | if (XWPBootCommand[CurPartitionNo][0]!=0) {
|
|---|
| 779 | if (WriteLeft>11+27) {
|
|---|
| 780 | TmpLength = strlen(XWPBootName[CurPartitionNo])+1;
|
|---|
| 781 | TmpLength2 = strlen(XWPBootCommand[CurPartitionNo])+1;
|
|---|
| 782 | strcpy (CurPos, XWPBootName[CurPartitionNo]);
|
|---|
| 783 | CurPos += TmpLength;
|
|---|
| 784 | strcpy (CurPos, XWPBootCommand[CurPartitionNo]);
|
|---|
| 785 | CurPos += TmpLength2;
|
|---|
| 786 | WriteLeft += TmpLength+TmpLength2;
|
|---|
| 787 | }
|
|---|
| 788 | }
|
|---|
| 789 | }
|
|---|
| 790 | *CurPos = 0; CurPos++;
|
|---|
| 791 | XWPStringSize = CurPos-XWPOrgStringPtr;
|
|---|
| 792 |
|
|---|
| 793 | PrfWriteProfileData (HINI_USERPROFILE, "XWorkplace", "RebootTo", XWPOrgStringPtr, XWPStringSize);
|
|---|
| 794 | free(XWPOrgStringPtr);
|
|---|
| 795 |
|
|---|
| 796 | puts ("SETABOOT: XWorkPlace updated.");
|
|---|
| 797 | return 0;
|
|---|
| 798 | }
|
|---|
| 799 | if (DoQuery) {
|
|---|
| 800 | if (!AiRBOOTDetected) {
|
|---|
| 801 | MSG_Print (TXT_ERROR_NoBootManager);
|
|---|
| 802 | return 1;
|
|---|
| 803 | }
|
|---|
| 804 | printf("SETABOOT: AiR-BOOT %X.%02X detected.\n\n", AiRBOOT_CodeSig->MajorVersion, AiRBOOT_CodeSig->MinorVersion);
|
|---|
| 805 | //printf("DEBUG: InstallVolume: %s\n", AiRBOOT_Config->InstallVolume);
|
|---|
| 806 | if (AiRBOOT_Config->BootMenuActive) {
|
|---|
| 807 | if (AiRBOOT_Config->TimedBoot) {
|
|---|
| 808 | itoa (AiRBOOT_Config->TimedSeconds, (PCHAR)&TempBuffer, 10);
|
|---|
| 809 | MSG_SetInsertViaPSZ (1, TempBuffer);
|
|---|
| 810 | MSG_Print (TXT_QUERY_TimeLimit_Show);
|
|---|
| 811 | } else {
|
|---|
| 812 | MSG_Print (TXT_QUERY_TimeLimit_None);
|
|---|
| 813 | }
|
|---|
| 814 | if (AiRBOOT_Config->BootMenuActive>1)
|
|---|
| 815 | MSG_Print (TXT_QUERY_Mode_Extended);
|
|---|
| 816 | else
|
|---|
| 817 | MSG_Print (TXT_QUERY_Mode_Normal);
|
|---|
| 818 | } else {
|
|---|
| 819 | MSG_SetInsertViaPSZ (1, "0");
|
|---|
| 820 | MSG_Print (TXT_QUERY_TimeLimit_Show);
|
|---|
| 821 | MSG_Print (TXT_QUERY_Mode_Normal);
|
|---|
| 822 | }
|
|---|
| 823 | return 0;
|
|---|
| 824 | }
|
|---|
| 825 | if (DoSetTimer) {
|
|---|
| 826 | if (!AiRBOOTDetected) {
|
|---|
| 827 | MSG_Print (TXT_ERROR_NoBootManager);
|
|---|
| 828 | return 1;
|
|---|
| 829 | }
|
|---|
| 830 | // Set Timer to "SetTimerValue" (1-255 -> seconds, -1 -> disable)
|
|---|
| 831 | // 0 is a special case, which will disable the BootMenu
|
|---|
| 832 | if (SetTimerValue==0) {
|
|---|
| 833 | // 0 is a special case, that will disable the bootmenu
|
|---|
| 834 | AiRBOOT_Config->BootMenuActive = 0; // Switches off Boot-Menu
|
|---|
| 835 | } else if (SetTimerValue==-1) {
|
|---|
| 836 | // -1 will disable Timed-Boot
|
|---|
| 837 | if (AiRBOOT_Config->BootMenuActive==0)
|
|---|
| 838 | AiRBOOT_Config->BootMenuActive = 1;
|
|---|
| 839 | AiRBOOT_Config->TimedBoot = 0; // Switches off Timed-Boot
|
|---|
| 840 | } else {
|
|---|
| 841 | if (AiRBOOT_Config->BootMenuActive==0)
|
|---|
| 842 | AiRBOOT_Config->BootMenuActive = 1;
|
|---|
| 843 | AiRBOOT_Config->TimedBoot = 1; // Switches on Timed-Boot
|
|---|
| 844 | AiRBOOT_Config->TimedSeconds = SetTimerValue;
|
|---|
| 845 | }
|
|---|
| 846 | AiRBOOTChanged = TRUE;
|
|---|
| 847 | }
|
|---|
| 848 | if (DoSetBootMenu) {
|
|---|
| 849 | if (!AiRBOOTDetected) {
|
|---|
| 850 | MSG_Print (TXT_ERROR_NoBootManager);
|
|---|
| 851 | return 1;
|
|---|
| 852 | }
|
|---|
| 853 | // Sets type of Boot-menu
|
|---|
| 854 | // Switches BootMenu between Enabled and Detailed state...
|
|---|
| 855 | if (BootMenuDetailed)
|
|---|
| 856 | AiRBOOT_Config->BootMenuActive = 2; // Switch to Detailed mode
|
|---|
| 857 | else
|
|---|
| 858 | AiRBOOT_Config->BootMenuActive = 1; // Switch to Enabled (Normal)
|
|---|
| 859 | AiRBOOTChanged = TRUE;
|
|---|
| 860 | }
|
|---|
| 861 | if (DoDirectBoot) {
|
|---|
| 862 | if (!AiRBOOTDetected) {
|
|---|
| 863 | MSG_Print (TXT_ERROR_NoBootManager);
|
|---|
| 864 | return 1;
|
|---|
| 865 | }
|
|---|
| 866 | // Sets Automatic-Booting to "DirectBootPart" (IPT-Entry)
|
|---|
| 867 | AiRBOOT_Config->AutomaticBoot = 1; // Switches on Automatic-Boot
|
|---|
| 868 | AiRBOOT_Config->AutomaticPartition = DirectBootPart;
|
|---|
| 869 | AiRBOOTChanged = TRUE;
|
|---|
| 870 | puts ("SETABOOT: Automatic boot enabled.");
|
|---|
| 871 | }
|
|---|
| 872 | if (DisableDirectBoot) {
|
|---|
| 873 | if (!AiRBOOTDetected) {
|
|---|
| 874 | MSG_Print (TXT_ERROR_NoBootManager);
|
|---|
| 875 | return 1;
|
|---|
| 876 | }
|
|---|
| 877 | AiRBOOT_Config->AutomaticBoot = 0; // Switches off Automatic-Boot
|
|---|
| 878 | AiRBOOT_Config->AutomaticPartition = 0;
|
|---|
| 879 | AiRBOOTChanged = TRUE;
|
|---|
| 880 | puts ("SETABOOT: Automatic boot disabled.");
|
|---|
| 881 | }
|
|---|
| 882 | if (AiRBOOTChanged) {
|
|---|
| 883 | if (!Track0WriteAiRBOOTConfig())
|
|---|
| 884 | return 1;
|
|---|
| 885 | }
|
|---|
| 886 | if (DoReboot) {
|
|---|
| 887 | puts ("SETABOOT: Now rebooting system...");
|
|---|
| 888 | RebootSystem();
|
|---|
| 889 | }
|
|---|
| 890 | return 0;
|
|---|
| 891 |
|
|---|
| 892 |
|
|---|
| 893 |
|
|---|
| 894 | }
|
|---|
| 895 |
|
|---|
| 896 |
|
|---|
| 897 | /*
|
|---|
| 898 | // Rousseau:
|
|---|
| 899 | // Global pointers will be initialized here !
|
|---|
| 900 | */
|
|---|
| 901 | BOOL Track0DetectAirBoot (BOOL* ab_bad) {
|
|---|
| 902 | USHORT ResultCheck;
|
|---|
| 903 | USHORT CurSectorNo = 0;
|
|---|
| 904 |
|
|---|
| 905 | /* Globals that get initialized */
|
|---|
| 906 | AiRBOOT_CodeSig = (PAiRBOOTCODESIG)&Track0[2];
|
|---|
| 907 | AiRBOOT_Config = (PAiRBOOTCONFIG)&Track0[(55-1)*512];
|
|---|
| 908 | AiRBOOT_IPT = (PAiRBOOTIPENTRY)&Track0[(56-1)*512];
|
|---|
| 909 |
|
|---|
| 910 | if (strncmp(AiRBOOT_CodeSig->Identifier, "AiRBOOT", 7)!=0) {
|
|---|
| 911 | *ab_bad = FALSE;
|
|---|
| 912 | return FALSE;
|
|---|
| 913 | }
|
|---|
| 914 |
|
|---|
| 915 | if ((AiRBOOT_CodeSig->TotalCodeSectors)>53) {
|
|---|
| 916 | puts ("SETABOOT: AiR-BOOT Code damaged!");
|
|---|
| 917 | *ab_bad = TRUE;
|
|---|
| 918 | return TRUE;
|
|---|
| 919 | }
|
|---|
| 920 |
|
|---|
| 921 | ResultCheck = 0; CurSectorNo = 0;
|
|---|
| 922 | while (CurSectorNo<AiRBOOT_CodeSig->TotalCodeSectors) {
|
|---|
| 923 | ResultCheck = GetChecksumOfSector(ResultCheck, CurSectorNo+2);
|
|---|
| 924 | CurSectorNo++;
|
|---|
| 925 | }
|
|---|
| 926 | if (ResultCheck!=AiRBOOT_CodeSig->CheckSumOfCode) {
|
|---|
| 927 | puts ("SETABOOT: AiR-BOOT Code damaged!");
|
|---|
| 928 | *ab_bad = TRUE;
|
|---|
| 929 | return TRUE;
|
|---|
| 930 | }
|
|---|
| 931 |
|
|---|
| 932 | if (strncmp(AiRBOOT_Config->Identifier, "AiRCFG-TABLE", 13)!=0) { // Rousseau: INVISIBLE CHAR HERE !
|
|---|
| 933 | puts ("SETABOOT: AiR-BOOT Config damaged!");
|
|---|
| 934 | *ab_bad = TRUE;
|
|---|
| 935 | return TRUE;
|
|---|
| 936 | }
|
|---|
| 937 |
|
|---|
| 938 | // Set Config-CheckSum to 0
|
|---|
| 939 | AiRBOOT_ConfigCheckSum = AiRBOOT_Config->CheckSumOfConfig;
|
|---|
| 940 | AiRBOOT_Config->CheckSumOfConfig = 0;
|
|---|
| 941 |
|
|---|
| 942 | // Calculate CheckSum...
|
|---|
| 943 | ResultCheck = 0; CurSectorNo = 55;
|
|---|
| 944 | while (CurSectorNo<60) {
|
|---|
| 945 | ResultCheck = GetChecksumOfSector(ResultCheck, CurSectorNo);
|
|---|
| 946 | CurSectorNo++;
|
|---|
| 947 | }
|
|---|
| 948 | if (ResultCheck!=AiRBOOT_ConfigCheckSum) {
|
|---|
| 949 | puts ("SETABOOT: AiR-BOOT Config damaged!");
|
|---|
| 950 | *ab_bad = TRUE;
|
|---|
| 951 | return TRUE;
|
|---|
| 952 | }
|
|---|
| 953 | *ab_bad = FALSE;
|
|---|
| 954 | return TRUE;
|
|---|
| 955 | }
|
|---|
| 956 |
|
|---|
| 957 | BOOL Track0WriteAiRBOOTConfig (void) {
|
|---|
| 958 | USHORT ResultCheck;
|
|---|
| 959 | USHORT CurSectorNo = 0;
|
|---|
| 960 |
|
|---|
| 961 | // Update Edit-Counter...
|
|---|
| 962 | AiRBOOT_Config->EditCounter++;
|
|---|
| 963 | AiRBOOT_Config->CheckSumOfConfig = 0;
|
|---|
| 964 |
|
|---|
| 965 | // Calculate CheckSum...
|
|---|
| 966 | ResultCheck = 0; CurSectorNo = 55;
|
|---|
| 967 | while (CurSectorNo<60) {
|
|---|
| 968 | ResultCheck = GetChecksumOfSector(ResultCheck, CurSectorNo);
|
|---|
| 969 | CurSectorNo++;
|
|---|
| 970 | }
|
|---|
| 971 | AiRBOOT_Config->CheckSumOfConfig = ResultCheck;
|
|---|
| 972 |
|
|---|
| 973 | if (!Track0Write())
|
|---|
| 974 | return FALSE;
|
|---|
| 975 | return TRUE;
|
|---|
| 976 | }
|
|---|
| 977 |
|
|---|
| 978 |
|
|---|
| 979 | /*
|
|---|
| 980 | // Rousseau: # This is the main entry-point #
|
|---|
| 981 | // Special behavior if eCS is booted from CDROM and phase 1 called this program.
|
|---|
| 982 | // In that case, the name of the newly installed system is put in the AiR-BOOT configuration.
|
|---|
| 983 | // This will cause AiR-BOOT to boot through after phase 1.
|
|---|
| 984 | */
|
|---|
| 985 | int main (int argc, char **argv) {
|
|---|
| 986 | BOOL AiRBOOTDetected = FALSE;
|
|---|
| 987 | BOOL Track0Loaded = FALSE; // Assume track0 did not load correctly.
|
|---|
| 988 | BOOL AiRBOOTBad = FALSE;
|
|---|
| 989 | int rc = -1;
|
|---|
| 990 |
|
|---|
| 991 |
|
|---|
| 992 | /*
|
|---|
| 993 | // Rousseau: ## Changed order to first check for AiR-BOOT existance ##
|
|---|
| 994 | // If AiR-BOOT is not installed, all action is passed-thru to IBM SETBOOT (SETBM.EXE).
|
|---|
| 995 | */
|
|---|
| 996 |
|
|---|
| 997 |
|
|---|
| 998 | /*
|
|---|
| 999 | // Try to load track zero.
|
|---|
| 1000 | // We don't care if no harddisk is present, since we first want to know if AiR-BOOT is
|
|---|
| 1001 | // installed to adjust our behaviour.
|
|---|
| 1002 | // If it's not installed, or a loading error occurs, all actions will be deferred to
|
|---|
| 1003 | // IBM SETBOOT (SETBM.EXE).
|
|---|
| 1004 | // This means we also let IBM SETBOOT handle the situation in which no HD's are present.
|
|---|
| 1005 | */
|
|---|
| 1006 | Track0Loaded = Track0Load();
|
|---|
| 1007 |
|
|---|
| 1008 | /*
|
|---|
| 1009 | // Now see if AiR-BOOT is present.
|
|---|
| 1010 | // If there was a loading error, no AiR-BOOT signature will be present, so
|
|---|
| 1011 | // we pass-thru to IBM SETBOOT.
|
|---|
| 1012 | */
|
|---|
| 1013 | AiRBOOTDetected = Track0DetectAirBoot(&AiRBOOTBad);
|
|---|
| 1014 |
|
|---|
| 1015 | if (AiRBOOTDetected) {
|
|---|
| 1016 | rc = DoAirBootActions(argc, argv, AiRBOOTDetected, AiRBOOTBad);
|
|---|
| 1017 | }
|
|---|
| 1018 | else {
|
|---|
| 1019 | rc = DoClassicActions(argc, argv);
|
|---|
| 1020 | }
|
|---|
| 1021 |
|
|---|
| 1022 |
|
|---|
| 1023 | return rc;
|
|---|
| 1024 | }
|
|---|