⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 bsect.c

📁 LINUX lilo-22.7 源代码。
💻 C
📖 第 1 页 / 共 4 页
字号:
    	    die("Serial line not supported by boot loader");	if (!*serial || !(this = strchr(coms,*serial)))	    die("Invalid serial port in \"%s\" (should be 0-3)",serial);	else param2.port = (this-coms)+1;	param2.ser_param = SER_DFL_PRM;	if (serial[1]) {	    if (serial[1] != ',')		die("Serial syntax is <port>[,<bps>[<parity>[<bits>]]]");	    walk = bps;	    speed = 0;	    while (*walk && strncmp(serial+2,walk,(i=strlen(walk)))) {		speed++;		walk += i+1;	    }	    if (!*walk) die("Unsupported baud rate");	    param2.ser_param &= ~0xE4;	    if (speed==16) speed -= 6;  /* convert 56000 to 57600 */	    param2.ser_param |= ((speed<<5) | (speed>>1)) & 0xE4;	    serial += i+2;	/* check for parity specified */	    if (*serial) {		if (!(this = strchr(parity,*serial)))		    die("Serial speed = %s; valid parity values are N, O and E", walk);		i = (int)(this-parity)>>1;		if (i==2) i++; /* N=00, O=01, E=11 */		param2.ser_param &= ~(i&1); /* 7 bits if parity specified */		param2.ser_param |= i<<3;   /* specify parity */	/* check if number of bits is there */		if (serial[1]) {		    if (serial[1] != '7' && serial[1] != '8')			die("Only 7 or 8 bits supported");		    if (serial[1]=='7')	param2.ser_param &= 0xFE;		    else param2.ser_param |= 0x01;		    		    if (serial[2]) die("Synax error in SERIAL");		}	    }	    if (verbose>=4) printf("Serial Param = 0x%02X\n", 						(int)param2.ser_param);	}	if (delay < 20 && !cfg_get_flag(cf_options,"prompt")) {	    fprintf(errstd,"Warning: no PROMPT with SERIAL; setting DELAY to 20 (2 seconds)\n");	    delay = 20;	}    }    bsect.par_1.prompt |= cfg_get_flag(cf_options,"prompt") ? FLAG_PROMPT : 0;    if (cfg_get_flag(cf_options,"suppress-boot-time-BIOS-data")) {    	fprintf(errstd,"CAUTION:  boot-time BIOS data will not be saved\n");    	bsect.par_1.prompt |= FLAG_NOBD;    }    if (!fetch() && (bios_map &#if VERSION_MINOR>=50    			bios_boot &	/* if 'boot=/dev/fd0', force write */#endif    				0x80)) {	bsect.par_1.prompt |= FLAG_BD_OKAY;	if (verbose>=2) printf("BIOS data check was okay on the last boot\n");    }    else {	if (verbose>=2) printf("BIOS data check will include auto-suppress check\n");    }    if (cfg_get_flag(cf_options,"large-memory")) {#ifndef LCF_INITRDLOW	bsect.par_1.prompt |= FLAG_LARGEMEM;#else	if (!nowarn) fprintf(errstd, "Warning: This LILO compiled with INITRDLOW option, 'large-memory' ignored\n");#endif    }    bsect.par_1.prompt |= raid_flags;    bsect.par_1.raid_offset = raid_offset;  /* to be modified in bsect_raid_update *//* convert timeout in tenths of a second to clock ticks    *//* tick interval is 54.925 ms  *//*   54.925 * 40 -> 2197       *//*  100 * 40 -> 4000	       */#if 0#define	tick(x) ((x)*100/55)#else#define tick(x) ((x)*4000/2197)#endif    delay =  delay==36000 ? 0xffff : tick(delay);    if (delay > 0xffff) die("Maximum delay is 59:59 (3599.5secs).");	else param2.delay = delay;    timeout =  timeout==36000 ? 0xfffe : tick(timeout);	/* -1 -> -1 ticks */    if (timeout == -1) param2.timeout = 0xffff;    else if (timeout >= 0xffff) die("Maximum timeout is 59:59 (3599.5secs).");	else param2.timeout = timeout;/* keytable & parameter area setup */    if (!(keytable = cfg_get_strg(cf_options,"keytable"))) {	for (i = 0; i < 256; i++) table[i] = i;    }    else {	if ((kt_fd = open(keytable,O_RDONLY)) < 0)	    die("open %s: %s",keytable,strerror(errno));	if (read(kt_fd,table,256) != 256)	    die("%s: bad keyboard translation table",keytable);	(void) close(kt_fd);    }#if 0    menu = (MENUTABLE*)&table[256];    memset(menu, 0, 256);#else    menu = &menuparams;#endif    memcpy(&(menu->row), &(lhv.row), sizeof(lhv) - sizeof(lhv.size) - sizeof(lhv.magic));    if ((scheme = cfg_get_strg(cf_options,"menu-scheme"))) {	if (!(stage_flags & STAGE_FLAG_MENU) && !nowarn)	    fprintf(errstd,"Warning: 'menu-scheme' not supported by boot loader\n");    	menu_do_scheme(scheme, menu);    }    if ((scheme = cfg_get_strg(cf_options,"menu-title"))) {	if (!(stage_flags & STAGE_FLAG_MENU) && !nowarn)	    fprintf(errstd,"Warning: 'menu-title' not supported by boot loader\n");	if (strlen(scheme) > MAX_MENU_TITLE && !nowarn)	    fprintf(errstd,"Warning: menu-title is > %d characters\n", MAX_MENU_TITLE);    	strncpy(menu->title, scheme, MAX_MENU_TITLE);    	menu->len_title = strlen(menu->title);    }    if ((scheme = cfg_get_strg(cf_options,"bmp-table"))) {	if (!(stage_flags & STAGE_FLAG_BMP4) && !nowarn)	    fprintf(errstd,"Warning: 'bmp-table' not supported by boot loader\n");    }    bmp_do_table(scheme, menu);    if (bitmap) {	image_menu_space = menu->ncol * menu->maxcol;	if (verbose>=3) printf("image_menu_space = %d\n", image_menu_space);    }    if ((scheme = cfg_get_strg(cf_options,"bmp-colors"))) {	if (!(stage_flags & STAGE_FLAG_BMP4) && !nowarn)	    fprintf(errstd,"Warning: 'bmp-colors' not supported by boot loader\n");    }    bmp_do_colors(scheme, menu);    if ((scheme = cfg_get_strg(cf_options,"bmp-timer"))) {	if (!(stage_flags & STAGE_FLAG_BMP4) && !nowarn)	    fprintf(errstd,"Warning: 'bmp-timer' not supported by boot loader\n");    }    bmp_do_timer(scheme, menu);#if 0    map_begin_section();    map_add_sector(table);    (void) map_write(&param2.keytab,1,0);#endif    memset(&descrs,0,SECTOR_SIZE*MAX_DESCR_SECS);    if (cfg_get_strg(cf_options,"default")) image = image_base = 1;    if (verbose > 0) printf("\n");}static int dev_number(char *dev){    struct stat st;    if (stat(dev,&st) >= 0) return st.st_rdev;    if (!isdigit(*dev)) die("Illegal 'root=' specification: %s", dev);    if (verbose >= 1) 	printf("Warning: cannot 'stat' device \"%s\"; trying numerical conversion\n", dev);    return to_number(dev);}static int get_image(char *name,char *label,IMAGE_DESCR *descr){    char *here,*deflt;    int this_image,other;    unsigned char *uch;    if (!label) {	here = strrchr(label = name,'/');	if (here) label = here+1;    }    if (strchr(label,' ')) die("Image name, label, or alias contains a blank character: '%s'", label);    if (strlen(label) > MAX_IMAGE_NAME) die("Image name, label, or alias is too long: '%s'",label);    for (uch=label; *uch; uch++) {	if (*uch<' ')  die("Image name, label, or alias contains an illegal character: '%s'", label);    }    for (other = image_base; other <= image; other++) {#ifdef LCF_IGNORECASE	if (!strcasecmp(label,descrs.d.descr[other].name))#else	if (!strcmp(label,descrs.d.descr[other].name))#endif	    die("Duplicate label \"%s\"",label);	if ((((descr->flags & FLAG_SINGLE) && strlen(label) == 1) ||	  (((descrs.d.descr[other].flags) & FLAG_SINGLE) &&	  strlen(descrs.d.descr[other].name) == 1)) &&#ifdef LCF_IGNORECASE	  toupper(*label) == toupper(*descrs.d.descr[other].name))#else	  *label == *descrs.d.descr[other].name)#endif	    die("Single-key clash: \"%s\" vs. \"%s\"",label,	      descrs.d.descr[other].name);    }    if (image_base && (deflt = cfg_get_strg(cf_options,"default")) &&#ifdef LCF_IGNORECASE      !strcasecmp(deflt,label))#else      !strcmp(deflt,label))#endif	this_image = image_base = 0;    else {	if (image == MAX_IMAGES)	    die("Only %d image names can be defined",MAX_IMAGES);	if (image >= image_menu_space)	    die("Bitmap table has space for only %d images",	    			image_menu_space);	this_image = image++;    }    descrs.d.descr[this_image] = *descr;    strcpy(descrs.d.descr[this_image].name,label);#ifdef LCF_VIRTUAL    if ( (deflt = cfg_get_strg(cf_options,"vmdefault")) &&#ifdef LCF_IGNORECASE		!strcasecmp(deflt,label))#else		!strcmp(deflt,label))#endif	descrs.d.descr[this_image].flags |= FLAG_VMDEFAULT;#endif    return this_image;}static char options[SECTOR_SIZE]; /* this is ugly */static void bsect_common(IMAGE_DESCR *descr, int image){    struct stat st;    char *here,*root,*ram_disk,*vga,*password;    char *literal,*append,*fback;    char fallback_buf[SECTOR_SIZE];    memset(descr, 0, sizeof(IMAGE_DESCR));	/* allocated on stack by caller */    memset(fallback_buf,0,SECTOR_SIZE);    memset(options,0,SECTOR_SIZE);    if (image) { /* long section specific to 'image=' */    char *append_local;        if ((cfg_get_flag(cf_kernel,"read-only") && cfg_get_flag(cf_kernel,      "read-write")) || (cfg_get_flag(cf_options,"read-only") && cfg_get_flag(      cf_options,"read-write")))	die("Conflicting READONLY and READ_WRITE settings.");    if (cfg_get_flag(cf_kernel,"read-only") || cfg_get_flag(cf_options,      "read-only")) strcat(options,"ro ");    if (cfg_get_flag(cf_kernel,"read-write") || cfg_get_flag(cf_options,      "read-write")) strcat(options,"rw ");    if ((root = cfg_get_strg(cf_kernel,"root")) || (root = cfg_get_strg(      cf_options,"root")))  {	if (!strcasecmp(root,"current")) {	    if (stat("/",&st) < 0) pdie("stat /");	    sprintf(strchr(options,0),"root=%x ",(unsigned int) st.st_dev);	}	else if (strlen(root)>6 && !strncmp(root,"LABEL=",6)) {	    sprintf(strchr(options,0),"root=%s ", root);	}	else {	    sprintf(strchr(options,0),"root=%x ",dev_number(root));	}      }	    if ((ram_disk = cfg_get_strg(cf_kernel,"ramdisk")) || (ram_disk =      cfg_get_strg(cf_options,"ramdisk")))	sprintf(strchr(options,0),"ramdisk=%d ",to_number(ram_disk));    if ((vga = cfg_get_strg(cf_kernel,"vga")) || (vga = cfg_get_strg(cf_options,      "vga"))) {#ifndef NORMAL_VGA	if (!nowarn)	    fprintf(errstd,"Warning: VGA mode presetting is not supported; ignoring 'vga='\n");#else	descr->flags |= FLAG_VGA;	     if (!strcasecmp(vga,"normal")) descr->vga_mode = NORMAL_VGA;	else if (!strcasecmp(vga,"ext") || !strcasecmp(vga,"extended"))		descr->vga_mode = EXTENDED_VGA;	else if (!strcasecmp(vga,"ask")) descr->vga_mode = ASK_VGA;	else descr->vga_mode = to_number(vga);#endif    }#ifdef LCF_BOOT_FILE    if ((append = cfg_get_strg(cf_top, "image"))) {	strcat(options, "BOOT_FILE=");	strcat(options, append);	strcat(options, " ");    }#endif    append_local = cfg_get_strg(cf_options,"append");	/* global, actually */    if ((append = cfg_get_strg(cf_kernel,"append")) ||	(append = append_local)  ) {		if (strlen(append) > COMMAND_LINE_SIZE-1) die("Command line options > %d", COMMAND_LINE_SIZE-1);		strcat(strcat(options,append)," ");    }#if 1    append = append_local;	/* append == global append */    if ((append_local = cfg_get_strg(cf_kernel,"addappend"))) {	if (!append && !nowarn)	    fprintf(errstd, "Warning: ADDAPPEND used without global APPEND\n");	if (strlen(options)+strlen(append_local) > SECTOR_SIZE-1) die("Command line options > %d", COMMAND_LINE_SIZE-1);	strcat(options,append_local);    }#endif} /* end of section specific to 'image=' */    literal = cfg_get_strg(cf_kernel,"literal");    if (literal) strcpy(options,literal);    if (*options) {	here = strchr(options,0);	if (here[-1] == ' ') here[-1] = 0;    }    check_options(options);    if (cfg_get_flag(cf_kernel,"lock") || cfg_get_flag(cf_options,"lock")) {#ifdef LCF_READONLY	die("This LILO is compiled READONLY and doesn't support the LOCK "	  "option");#else	descr->flags |= FLAG_LOCK;#endif    }    if ((cfg_get_flag(cf_options,"restricted") && 	     cfg_get_flag(cf_options,"mandatory")) ||	(cfg_get_flag(cf_all,"restricted") && 	     cfg_get_flag(cf_all,"mandatory")))	 die("MANDATORY and RESTRICTED are mutually exclusive");    if (cfg_get_flag(cf_all,"bypass")) {	if (cfg_get_flag(cf_all,"mandatory"))	     die("MANDATORY and BYPASS are mutually exclusive");	if (cfg_get_flag(cf_all,"restricted"))	     die("RESTRICTED and BYPASS are mutually exclusive");	if (!cfg_get_strg(cf_options,"password"))	     die("BYPASS only valid if global PASSWORD is set");    }    if ((password = cfg_get_strg(cf_all,"password")) && cfg_get_flag(cf_all,"bypass"))	die("PASSWORD and BYPASS not valid together");    if (password || 	( (password = cfg_get_strg(cf_options,"password")) &&	  !cfg_get_flag(cf_all,"bypass")  ) ) {	if (!*password) {	/* null password triggers interaction */	    retrieve_crc((int*)descr->password_crc);	} else {	    hash_password(password, (int*)descr->password_crc );	}	descr->flags |= FLAG_PASSWORD;    }#ifdef LCF_VIRTUAL    if (cfg_get_flag(cf_all,"vmwarn")) descr->flags |= FLAG_VMWARN;    if (cfg_get_flag(cf_all,"vmdisable")) descr->flags |= FLAG_VMDISABLE;    if ( (descr->flags & FLAG_VMWARN) && (descr->flags & FLAG_VMDISABLE) )	die ("VMWARN and VMDISABLE are not valid together");#endif#if 1    if (cfg_get_flag(cf_all,"mandatory") || cfg_get_flag(cf_options,      "mandatory")) {	if (!password) die("MANDATORY is only valid if PASSWORD is set.");    }    if (cfg_get_flag(cf_all,"restricted") || cfg_get_flag(cf_options,      "restricted")) {	if (!password) die("RESTRICTED is only valid if PASSWORD is set.");	if ((descr->flags & FLAG_PASSWORD) && !cfg_get_flag(cf_all,"mandatory"))	    descr->flags |= FLAG_RESTR;    }    if (password && *password && config_read) {	fprintf(errstd,"Warning: %s should be readable only "	  "for root if using PASSWORD\n",config_file);	config_read = 0;	/* suppress further warnings */    }#else    if (cfg_get_flag(cf_all,"restricted") || cfg_get_flag(cf_options,      "restricted")) {	if (!password) die("RESTRICTED is only valid if PASSWORD is set.");	descr->flags |= FLAG_RESTR;    }#endif    if (cfg_get_flag(cf_all,"bmp-retain") ||      cfg_get_flag(cf_options,"bmp-retain")) descr->flags |= FLAG_RETAIN;    if (cfg_get_flag(cf_all,"single-key") ||      cfg_get_flag(cf_options,"single-key")) descr->flags |= FLAG_SINGLE;    fback = cfg_get_strg(cf_kernel,"fallback");    if (fback) {#ifdef LCF_READONLY	die("This LILO is compiled READONLY and doesn't support the FALLBACK "	  "option");#else	if (descr->flags & FLAG_LOCK)	    die("LOCK and FALLBACK are mutually exclusive");	else descr->flags |= FLAG_FALLBACK;

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -