📄 bootlib.c
字号:
** This routine displays the current value of each boot parameter and prompts* the user for a new value. Typing a RETURN leaves the parameter unchanged.* Typing a period (.) clears the parameter.** The parameter <string> holds the initial values. The new boot line is* copied over <string>. If there are no initial values, <string> is* empty on entry.** RETURNS: N/A*/void bootParamsPrompt ( char *string /* default boot line */ ) { BOOT_PARAMS bp; FAST int n = 0; FAST int i; /* interpret the boot parameters */ (void) bootStringToStruct (string, &bp); printf ("\n'.' = clear field; '-' = go to previous field; ^D = quit\n\n"); /* prompt the user for each item; * i: 0 = same field, 1 = next field, -1 = previous field, * -98 = error, -99 = quit */ FOREVER { switch (n) { case 0: i = promptParamBootDevice (strBootDevice, bp.bootDev, &bp.unitNum, sizeof (bp.bootDev)); break; case 1: i = promptParamNum (strProcNum, &bp.procNum, FALSE);break; case 2: i = promptParamString (strHostName, bp.hostName, sizeof (bp.hostName)); break; case 3: i = promptParamString (strFileName, bp.bootFile, sizeof (bp.bootFile)); break; case 4: i = promptParamString (strInetOnEthernet, bp.ead, sizeof (bp.ead)); break; case 5: i = promptParamString (strInetOnBackplane, bp.bad, sizeof (bp.bad));break; case 6: i = promptParamString (strHostInet, bp.had, sizeof (bp.had)); break; case 7: i = promptParamString (strGatewayInet, bp.gad, sizeof (bp.gad)); break; case 8: i = promptParamString (strUser, bp.usr, sizeof (bp.usr)); break; case 9: i = promptParamString (strFtpPwLong, bp.passwd, sizeof (bp.passwd)); break; case 10: i = promptParamNum (strFlags, &bp.flags, TRUE); break; case 11: i = promptParamString (strTargetName, bp.targetName, sizeof (bp.targetName));break; case 12: i = promptParamString (strStartup, bp.startupScript, sizeof (bp.startupScript));break; case 13: i = promptParamString (strOther, bp.other, sizeof (bp.other)); break; default: i = -99; break; } /* check for QUIT */ if (i == -99) { printf ("\n"); break; } /* move to new field */ if (i != -98) n += i; } (void) bootStructToString (string, &bp); }/******************************************************************************** bootParamsErrorPrint - print boot string error indicator** print error msg with '^' where parse failed** NOMANUAL*/void bootParamsErrorPrint ( char *bootString, char *pError ) { printf ("Error in boot line:\n%s\n%*c\n", bootString, (int) (pError - bootString + 1), '^'); }/********************************************************************************* bootLeaseExtract - extract the lease information from an Internet address** This routine extracts the optional lease duration and lease origin fields * from an Internet address field for use with DHCP. The lease duration can be * specified by appending a colon and the lease duration to the netmask field.* For example, the "inet on ethernet" field of the boot parameters could be * specified as:* .CS* inet on ethernet: 90.1.0.1:ffff0000:1000* .CE** If no netmask is specified, the contents of the field could be:* .CS* inet on ethernet: 90.1.0.1::ffffffff* .CE** In the first case, the lease duration for the address is 1000 seconds. The * second case indicates an infinite lease, and does not specify a netmask for* the address. At the beginning of the boot process, the value of the lease* duration field is used to specify the requested lease duration. If the field * not included, the value of DHCP_DEFAULT_LEASE is used* instead.* * The lease origin is specified with the same format as the lease duration,* but is added during the boot process. The presence of the lease origin* field distinguishes addresses assigned by a DHCP server from addresses* entered manually. Addresses assigned by a DHCP server may be replaced* if the bootstrap loader uses DHCP to obtain configuration parameters.* The value of the lease origin field at the beginning of the boot process* is ignored.** This routine extracts the optional lease duration by replacing the preceding * colon in the specified string with an EOS and then scanning the remainder as * a number. The lease duration and lease origin values are returned via* the <pLeaseLen> and <pLeaseStart> pointers, if those parameters are not NULL.** RETURNS:* 2 if both lease values are specified correctly in <string>, or * -2 if one of the two values is specified incorrectly.* If only the lease duration is found, it returns:* 1 if the lease duration in <string> is specified correctly,* 0 if the lease duration is not specified in <string>, or* -1 if an invalid lease duration is specified in <string>.*/int bootLeaseExtract ( char *string, /* string containing addr field */ u_long *pLeaseLen, /* pointer to storage for lease duration */ u_long *pLeaseStart /* pointer to storage for lease origin */ ) { FAST char *pDelim; FAST char *offset; int result; int status = 0; int start; int length; /* find delimeter for netmask */ offset = index (string, ':'); if (offset == NULL) return (0); /* no subfield specified */ /* Start search after netmask field. */ pDelim = offset + 1; /* Search for lease duration field. */ offset = index (pDelim, ':'); if (offset == NULL) /* No lease duration tag. */ return (0); /* Start search after duration. */ pDelim = offset + 1; status = bootSubfieldExtract (pDelim, &start, ':'); if (status == 1 && pLeaseStart != NULL) *pLeaseStart = start; /* Reset search pointer to obtain lease duration. */ offset = index (string, ':'); if (offset == NULL) /* Sanity check - should not occur. */ return (0); /* Lease duration follows netmask. */ pDelim = offset + 1; /* Store lease duration if found. */ result = bootSubfieldExtract (pDelim, &length, ':'); if (result == 1 && pLeaseLen != NULL) *pLeaseLen = length; if (status != 0) /* Both lease values were present. */ { if (status < 0 || result < 0) /* Error reading one of the values. */ return (-2); else return (2); /* Both lease values read successfully. */ } return (result); }/********************************************************************************* bootNetmaskExtract - extract the net mask field from an Internet address** This routine extracts the optional subnet mask field from an Internet address* field. Subnet masks can be specified for an Internet interface by appending* to the Internet address a colon and the net mask in hexadecimal. * For example, the "inet on ethernet" field of the boot parameters could * be specified as:* .CS* inet on ethernet: 90.1.0.1:ffff0000* .CE* In this case, the network portion of the address (normally just 90)* is extended by the subnet mask (to 90.1). This routine extracts the* optional trailing subnet mask by replacing the colon in the specified* string with an EOS and then scanning the remainder as a hex number.* This number, the net mask, is returned via the <pNetmask> pointer.* * This routine also handles an empty netmask field used as a placeholder* for the lease duration field (see bootLeaseExtract() ). In that case,* the colon separator is replaced with an EOS and the value of netmask is* set to 0. ** RETURNS:* 1 if the subnet mask in <string> is specified correctly,* 0 if the subnet mask in <string> is not specified, or* -1 if an invalid subnet mask is specified in <string>.*/STATUS bootNetmaskExtract ( char *string, /* string containing addr field */ int *pNetmask /* pointer where to return net mask */ ) { FAST char *pDelim; char *offset; /* find delimeter */ pDelim = index (string, ':'); if (pDelim == NULL) return (0); /* no subfield specified */ /* Check if netmask field precedes timeout field. */ offset = pDelim + 1; skipSpace(&offset); if (*offset == ':' || *offset == EOS) /* Netmask field is placeholder. */ { *pDelim = EOS; *pNetmask = 0; return (1); } return (bootSubfieldExtract (string, pNetmask, ':')); }/******************************************************************************** bootBpAnchorExtract - extract a backplane address from a device field** This routine extracts the optional backplane anchor address field from a* boot device field. The anchor can be specified for the backplane* driver by appending to the device name (i.e., "bp") an equal sign (=) and the* address in hexadecimal. For example, the "boot device" field of the boot* parameters could be specified as:* .CS* boot device: bp=800000* .CE* In this case, the backplane anchor address would be at address 0x800000,* instead of the default specified in config.h.** This routine picks off the optional trailing anchor address by replacing* the equal sign (=) in the specified string with an EOS and then scanning the* remainder as a hex number.* This number, the anchor address, is returned via the <pAnchorAdrs> pointer.** RETURNS:* 1 if the anchor address in <string> is specified correctly,* 0 if the anchor address in <string> is not specified, or* -1 if an invalid anchor address is specified in <string>.*/STATUS bootBpAnchorExtract ( char *string, /* string containing adrs field */ char **pAnchorAdrs /* pointer where to return anchor address */ ) { return (bootSubfieldExtract (string, (int *) pAnchorAdrs, '=')); }/******************************************************************************** bootSubfieldExtract - extract a numeric subfield from a boot field** Extracts subfields in fields of the form "<field><delimeter><subfield>".* i.e. <inet>:<netmask> and bp=<anchor>*/LOCAL STATUS bootSubfieldExtract ( char *string, /* string containing field to be extracted */ int *pValue, /* pointer where to return value */ char delimeter /* character delimeter */ ) { FAST char *pDelim; int value; /* find delimeter */ pDelim = index (string, delimeter); if (pDelim == NULL) return (0); /* no subfield specified */ /* scan remainder for numeric subfield */ string = pDelim + 1; if (bootScanNum (&string, &value, TRUE) != OK) return (-1); /* invalid subfield specified */ *pDelim = EOS; /* terminate string at the delimeter */ *pValue = value; /* return value */ return (1); /* valid subfield specified */ }/********************************************************************************* addAssignNum - add a numeric value assignment to a string*/LOCAL void addAssignNum ( FAST char *string, char *code, int value ) { if (value != 0) { string += strlen (string); sprintf (string, (value <= 7) ? " %s=%d" : " %s=0x%x", code, value); } }/********************************************************************************* addAssignString - add a string assignment to a string*/LOCAL void addAssignString ( FAST char *string, char *code, char *value ) { if (value[0] != EOS) { string += strlen (string); sprintf (string, " %s=%s", code, value); } }/********************************************************************************* getWord - get a word out of a string** Words longer than the specified max length are truncated.** RETURNS: TRUE if word is successfully extracted from string, FALSE otherwise;* Also updates ppString to point to next character following extracted word.*/LOCAL BOOL getWord ( char **ppString, /* ptr to ptr to string from which to get word */ FAST char *pWord, /* where to return word */ int length, /* max length of word to get including EOS */ char *delim /* string of delimiters that can terminate word */ ) { FAST char *pStr; skipSpace (ppString); /* copy up to any specified delimeter, EOS, or max length */ pStr = *ppString; while ((--length > 0) && (*pStr != EOS) && (index (delim, *pStr) == 0)) *(pWord++) = *(pStr++); *pWord = EOS; /* if we copied anything at all, update pointer and return TRUE */ if (pStr != *ppString) { *ppString = pStr; return (TRUE); } /* no word to get */ return (FALSE); }/********************************************************************************* getConst - get a constant string out of a string** case insensitive compare for identical strings*/LOCAL BOOL getConst ( char **ppString, FAST char *pConst ) { FAST int ch1; FAST int ch2; FAST char *pString; skipSpace (ppString); for (pString = *ppString; *pConst != EOS; ++pString, ++pConst) { ch1 = *pString; ch1 = (isascii (ch1) && isupper (ch1)) ? tolower (ch1) : ch1; ch2 = *pConst; ch2 = (isascii (ch2) && isupper (ch2)) ? tolower (ch2) : ch2; if (ch1 != ch2) return (FALSE); } /* strings match */
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -