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

📄 lilo.c

📁 linux 的引导程序源码The Microsoft&reg Windows&reg Software Development Kit (SDK) provides the documentation
💻 C
📖 第 1 页 / 共 3 页
字号:
		}	    }			    if ((do_md_install == MD_PARALLEL && is_accessible(raid_device[pass]))		|| (do_md_install == MD_MIXED && pri_offset == raid_offset[pass]		        && is_primary(raid_device[pass]))		)    		raid_bios[pass] |= IS_COVERED;	}	   		nlist = 0;	if (extra==X_SPEC) {	    char *next, *scan;	    	    scan = next = extrap;	    while (next && *next) {		scan = next;		while (isspace(*scan)) scan++;	/* deblank the line */		next = strchr(scan, ',');	/* find the separator */		if (next) *next++ = 0;		/* NUL terminate  scan */		    		if ((md_fd=open(scan,O_NOACCESS)) < 0)		    die("Unable to open %s", scan);		if (fstat(md_fd,&st) < 0)		    die("Unable to stat %s",scan);		if (!S_ISBLK(st.st_mode))		    die("%s is not a block device",scan);	    	mask = has_partitions(st.st_rdev);	    	if (!mask) die("%s (%04X) not a block device", scan, (int)st.st_rdev);		if (verbose>=2) printf("RAID list: %s is device 0x%04X\n",				scan, (int)st.st_rdev);	    			close(md_fd);				list_index[nlist] = ndisk;  /* raid_bios==0 here */		for (pass=0; pass < ndisk; pass++) {		    if (master(st.st_rdev) == master(raid_device[pass])) {		    	list_index[nlist] = pass;		    	if (st.st_rdev == raid_device[pass])			    die("Cannot write to a partition within a RAID set:  %s", scan);		    	else if (is_accessible(st.st_rdev))		    	    raid_bios[pass] |= IS_COVERED;		    	break;		    }		}		if (list_index[nlist] == ndisk) {#if 0		    raid_flags |= FLAG_RAID_NOWRITE;  /* disk is outside RAID set */#endif		    if (!nowarn) printf("Warning: device outside of RAID set  %s  0x%04X\n", 		    				scan, (int)st.st_rdev);		}		raid_list[nlist++] = stralloc(scan);	    }	    	}		   	    /* if the install is to MBRs, then change the boot= name */	if (extra == X_MBR_ONLY) {	    if (cfg_get_strg(cf_options,"boot")) cfg_unset(cf_options,"boot");	    cfg_set(cf_options, "boot", (boot=raid_mbr[0]), NULL);	}	else {	/* if skewed install, disable mdX boot records as 							source of writeback info */	    if (do_md_install == MD_SKEWED) raid_flags |= FLAG_RAID_DEFEAT | 	    	(extra == X_NONE ? FLAG_RAID_NOWRITE : 0);	}	mask = 1;	for (pass=0; pass < ndisk; pass++) {	    mask &= !!(raid_bios[pass] & COVERED);	}	if (!mask) {	    raid_flags |= FLAG_RAID_NOWRITE;	}	if (raid_flags & FLAG_RAID_NOWRITE) {	    if (!nowarn) {		fprintf(errstd, "\nWarning: FLAG_RAID_NOWRITE has been set.\n");#if 0		if (verbose >= 1)		fprintf(errstd,   "  The boot loader will be unable to update the stored command line;\n"		                  "  'lock' and 'fallback' are not operable; the 'lilo -R' boot command\n"		                  "  line will be locked.\n\n");#endif	    }	}    /* if the disk= bios= did not specify the bios, then this is the default */	if (md_disk->bios < 0) {	    md_disk->bios = md_bios;	}	if (md_disk->bios < 0x80 || md_disk->bios > DEV_MASK)	   die("Unusual RAID bios device code: 0x%02X", md_disk->bios);	disk = disktab;	for (pass=0; pass < ndisk; pass++) {	    disk->bios = md_disk->bios;	  /* all disks in the array are */	    disk = disk->next;		  /*  assigned the same bios code */	}	if (!nowarn) {	    fprintf(errstd,	       "Warning: using BIOS device code 0x%02X for RAID boot blocks\n",	    	                            md_disk->bios);	}	return raid_offset[pri_index];    }	/* IF (test for a raid installation */    else {	/* not raid at all */	if (cfg_get_strg(cf_options, RAID_EXTRA_BOOT))	    die("Not a RAID install, '" RAID_EXTRA_BOOT "=' not allowed");	return 0L;    }}  /* void raid_setup(void) */#undef COVEREDstatic void show_other(int fd){    BOOT_SECTOR buf[SETUPSECS-1];    const unsigned char *drvmap;    const unsigned char *prtmap;    if (read(fd,buf,sizeof(buf)) != sizeof(buf))	die("Read on map file failed (access conflict ?)");    if (!strncmp(buf[0].par_c.signature-4,"LILO",4)) {	printf("    Pre-21 signature (0x%02x,0x%02x,0x%02x,0x%02x)\n",	  buf[0].par_c.signature[0],buf[0].par_c.signature[1],	  buf[0].par_c.signature[2],buf[0].par_c.signature[3]);	return;    }    if (strncmp(buf[0].par_c.signature,"LILO",4)) {	printf("    Bad signature (0x%02x,0x%02x,0x%02x,0x%02x)\n",	  buf[0].par_c.signature[0],buf[0].par_c.signature[1],	  buf[0].par_c.signature[2],buf[0].par_c.signature[3]);	return;    }    drvmap = ((unsigned char *) buf+buf[0].par_c.drvmap);    prtmap = drvmap+2*(DRVMAP_SIZE+1);    while (drvmap[0] && drvmap[1]) {	printf("    BIOS drive 0x%02x is mapped to 0x%02x\n",drvmap[0],	  drvmap[1]);	drvmap += 2;    }    /* fix VERY old bug -- offset of 0 in PT is okay */    while (prtmap[0] /*** && prtmap[1] ***/ ) {	printf("    BIOS drive 0x%02x, offset 0x%x: 0x%02x -> 0x%02x\n",	  prtmap[0],prtmap[1]+PART_TABLE_OFFSET,prtmap[2],prtmap[3]);	prtmap += 4;    }}static void show_images(char *map_file){    DESCR_SECTORS descrs;    BOOT_SECTOR boot;    GEOMETRY geo;    SECTOR_ADDR addr[4];    char buffer[SECTOR_SIZE];    char *name;    int fd,image;    int tsecs;    int tlinear, tlba32;    unsigned short flags;    fd = geo_open(&geo,map_file,O_RDONLY);    if (read(fd,buffer,SECTOR_SIZE) != SECTOR_SIZE)	die("read %s: %s",map_file,strerror(errno));    if (read(fd,(char *) &descrs,sizeof(descrs)) != sizeof(descrs))	die("read %s: %s",map_file,strerror(errno));    tlba32  = (descrs.d.descr[0].start.device & LBA32_FLAG) != 0;    tlinear = !tlba32 && (descrs.d.descr[0].start.device & LINEAR_FLAG);    if (tlinear != linear  ||  tlba32 != lba32) {        printf("Warning: mapfile created with %s option\n",	       tlinear?"linear":tlba32?"lba32":"no linear/lba32");        linear = tlinear;  lba32 = tlba32;    }    if (verbose > 0) {	bsect_read(cfg_get_strg(cf_options,"boot"),&boot);#if 1	if (boot.par_1.cli != 0xFA) {	/* relocation happened */	    int len, offset=0;	    if (boot.sector[0] == 0xEB)		/* jmp short */		offset = boot.sector[1]+2;	    else if (boot.sector[0] == 0xE9)	/* jmp near */		offset = *(short*)&boot.sector[1] + 3;	    else die("Cannot undo boot sector relocation.");	    len = SECTOR_SIZE - offset;	    memmove(&boot, &boot.sector[offset], len);	    if (boot.par_1.cli != 0xFA)		die("Cannot recognize boot sector.");	}#endif	printf("Global settings:\n");	tsecs = (boot.par_1.delay*2197+3999)/4000;	printf("  Delay before booting: %d.%d seconds\n",tsecs/10,tsecs % 10);	if (boot.par_1.timeout == 0xffff) printf("  No command-line timeout\n");	else {	    tsecs = (boot.par_1.timeout*2197+3999)/4000;	    printf("  Command-line timeout: %d.%d seconds\n",tsecs/10,	      tsecs % 10);	}	if (boot.par_1.prompt & FLAG_PROMPT) printf("  Always enter boot prompt\n");	else printf("  Enter boot prompt only on demand\n");	printf("  Boot-time BIOS data%s saved\n",		boot.par_1.prompt & FLAG_NOBD ? " NOT" : "");	printf("  Large memory (>15M) is%s used to load initial ramdisk\n", 		boot.par_1.prompt & FLAG_LARGEMEM ? "" : " NOT");	printf("  %sRAID installation\n",		boot.par_1.prompt & FLAG_RAID ? "" : "Non-");	if (!boot.par_1.port) printf("  Serial line access is disabled\n");	else printf("  Boot prompt can be accessed from COM%d\n",	      boot.par_1.port);	if (!boot.par_1.msg_len) printf("  No message for boot prompt\n");	else if (!cfg_get_strg(cf_options,"bitmap"))	    printf("  Boot prompt message is %d bytes\n",boot.par_1.msg_len);	else printf("  Bitmap file is %d paragraphs (%d bytes)\n",			boot.par_1.msg_len, 16*boot.par_1.msg_len);	if (*(unsigned short *) buffer != DC_MAGIC || !buffer[2])	    printf("  No default boot command line\n");	else printf("  Default boot command line: \"%s\"\n",buffer+2);	printf("Images:\n");    }    for (image = 0; image < MAX_IMAGES; image++)	if (*(name = descrs.d.descr[image].name)) {	    printf("%s%-" S(MAX_IMAGE_NAME) "s %s%s",verbose > 0 ? "  " : "",name,	      image ? "" : "*",#ifdef LCF_VIRTUAL	      descrs.d.descr[image].flags & FLAG_VMDEFAULT ? "@" :#endif	      ""	      );	    if (verbose >= 2) {	        if (descrs.d.descr[image].start.device & (LINEAR_FLAG|LBA32_FLAG)) {		   unsigned int sector;		   sector = (descrs.d.descr[image].start.device & LBA32_FLAG)		      && (descrs.d.descr[image].start.device & LBA32_NOCOUNT)		        ? descrs.d.descr[image].start.num_sect : 0;		   sector = (sector<<8)+descrs.d.descr[image].start.head;	           sector = (sector<<8)+descrs.d.descr[image].start.track;		   sector = (sector<<8)+descrs.d.descr[image].start.sector;		   printf(" <dev=0x%02x,linear=%d>",		     descrs.d.descr[image].start.device,		     sector);		}	        else { /*  CHS addressing */		    printf(" <dev=0x%02x,hd=%d,cyl=%d,sct=%d>",		      descrs.d.descr[image].start.device,		      descrs.d.descr[image].start.head,		      descrs.d.descr[image].start.track,		      descrs.d.descr[image].start.sector);		}	    }	    printf("\n");	    if (verbose >= 1) {		flags = descrs.d.descr[image].flags;#ifdef LCF_VIRTUAL		if (flags & FLAG_VMDISABLE)		    printf("    Virtual Boot is disabled\n");		if (flags & FLAG_VMWARN)		    printf("    Warn on Virtual boot\n");#endif				if ( !(flags & FLAG_PASSWORD) )		    printf("    No password\n");		else printf("    Password is required for %s\n",flags &		      FLAG_RESTR ? "specifying options" : "booting this image");		printf("    Boot command-line %s be locked\n",flags &		  FLAG_LOCK ? "WILL" : "won't");		printf("    %single-key activation\n",flags & FLAG_SINGLE ?		  "S" : "No s");		if (flags & FLAG_KERNEL) {#ifdef NORMAL_VGA		    if (!(flags & FLAG_VGA))		       printf("    VGA mode is taken from boot image\n");		    else {			printf("    VGA mode: ");			switch (descrs.d.descr[image].vga_mode) {			    case NORMAL_VGA:				printf("NORMAL\n");				break;			    case EXTENDED_VGA:				printf("EXTENDED\n");				break;			    case ASK_VGA:				printf("ASK\n");				break;			    default:				printf("%d (0x%04x)\n",				  descrs.d.descr[image].vga_mode,				  descrs.d.descr[image].vga_mode);			}		    }#endif#if 0		    if (!descrs.d.descr[image].start_page)			printf("    Kernel is loaded \"low\"\n");		    else printf("    Kernel is loaded \"high\", at 0x%08lx\n",			  (unsigned long) descrs.d.descr[image].start_page*			  PAGE_SIZE);#else		    if (!(flags & FLAG_LOADHI))			printf("    Kernel is loaded \"low\"\n");		    else printf("    Kernel is loaded \"high\"\n");#endif#if 1		    if (!*(unsigned long *) descrs.d.descr[image].rd_size)			printf("    No initial RAM disk\n");		    else printf("    Initial RAM disk is %ld bytes\n",			  *(unsigned long *) descrs.d.descr[image].rd_size);#else		    if (!descrs.d.descr[image].rd_size)			printf("    No initial RAM disk\n");		    else printf("    Initial RAM disk is %d sectors\n",			  (int)descrs.d.descr[image].rd_size);#endif		}		if (!geo_find(&geo,descrs.d.descr[image].start)) {		    printf("    Map sector not found\n");		    continue;		}		if (read(fd,addr,4*sizeof(SECTOR_ADDR)) !=		  4*sizeof(SECTOR_ADDR))			die("Read on map file failed (access conflict ?)");		if (!geo_find(&geo,addr[0]))		    printf("    Fallback sector not found\n");		else {		    if (read(fd,buffer,SECTOR_SIZE) != SECTOR_SIZE)			die("Read on map file failed (access conflict ?)");		    if (*(unsigned short *) buffer != DC_MAGIC)			printf("    No fallback\n");		    else printf("    Fallback: \"%s\"\n",buffer+2);		}#define OTHER 0#if OTHER		if (flags & FLAG_KERNEL)#endif		    if (!geo_find(&geo,addr[1]))			printf("    Options sector not found\n");		    else {			if (read(fd,buffer,SECTOR_SIZE) != SECTOR_SIZE)			    die("Read on map file failed (access conflict ?)");			if (*buffer) printf("    Options: \"%s\"\n",buffer);			else printf("    No options\n");		    }#if OTHER		else {#else		if (!(flags & FLAG_KERNEL)) {#endif		    if (geo_find(&geo,addr[3])) show_other(fd);		    else printf("    Image data not found\n");		}	    }	}#undef OTHER    (void) close(fd);#if 0    checksum = INIT_CKS;    for (i = 0; i < sizeof(descrs)/sizeof(unsigned short); i++)	checksum ^= ((unsigned short *) &descrs)[i];    if (!checksum) exit(0);#else    if (descrs.l.checksum ==    	  crc32(descrs.sector, sizeof(descrs.l.sector), CRC_POLY1) )  exit(0);#endif    fflush(stdout);    fprintf(errstd,"Checksum error\n");    exit(1);}static void usage(char *name){    char *here;    here = strrchr(name,'/');    if (here) name = here+1;    fprintf(errstd,"usage: %s [ -C config_file ] -q [ -m map_file ] "      "[ -v N | -v ... ]\n",name);    fprintf(errstd,"%7s%s [ -C config_file ] [ -b boot_device ] [ -c ] "      "[ -g | -l | -L ]\n","",name);    fprintf(errstd,"%12s[ -F ] [ -i boot_loader ] [ -m map_file ] [ -d delay ]\n","");    fprintf(errstd,"%12s[ -v N | -v ... ] [ -t ] [ -s save_file | -S save_file ]\n",      "");    fprintf(errstd,"%12s[ -p ][ -P fix | -P ignore ] [ -r root_dir ] [ -w ]\n","");    fprintf(errstd,"%7s%s [ -C config_file ] [ -m map_file ] "      "-R [ word ... ]\n","",name);    fprintf(errstd,"%7s%s [ -C config_file ] -I name [ options ]\n","",name);    fprintf(errstd,"%7s%s [ -C config_file ] [ -s save_file ] "      "-u | -U [ boot_device ]\n","",name);    fprintf(errstd,"%7s%s -A /dev/XXX [ N ]\t\tactivate a partition\n","",name);    fprintf(errstd,"%7s%s -M /dev/XXX [ mbr_file ]\tinstall master boot record\n","",name);    fprintf(errstd,"%7s%s -T help \t\t\tlist additional options\n", "", name);    fprintf(errstd,"%7s%s -X\t\t\t\tinternal compile-time options\n", "", name);    fprintf(errstd,"%7s%s -V [ -v ]\t\t\tversion information\n\n","",name);    exit(1);}int main(int argc,char **argv){    char *name,*reboot_arg,*identify,*ident_opt,*new_root;    char *tell_param, *uninst_dev, *param, *act1, *act2, ch;

⌨️ 快捷键说明

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