Esempio n. 1
0
File: edit.c Progetto: OPSF/uClinux
static void transfer_params(char *config_file)
{
    int n;
    char *bitmap_file, *opt;
    char *cp;
    int cfd;

    cfg_bitmap_only();		/* disable everything but cf_bitmap */
    
    cfd = cfg_open(config_file);
    if (verbose >= 3) printf("cfg_open returns: %d\n", cfd);
    n = cfg_parse(cf_bitmap);
    if (verbose >= 3) printf("cfg_parse returns: %d\n", n);
    if (n != 0) {
	die("Illegal token in '%s'", config_file);
    }
    if ((bitmap_file = cfg_get_strg(cf_bitmap, "bitmap")) != NULL) {
	opt = "Using";
	cp = strrchr(config_file, '/');
	if (cp && bitmap_file[0] != '/') {
	    *++cp = 0;
	    bitmap_file = strcat(strcpy(alloc(strlen(config_file) + strlen(bitmap_file) + 1),
					config_file),
				 bitmap_file);
	    *cp = '/';
	}
    } else {
	opt = "Assuming";
	cp = strrchr(config_file, '.');
	if (cp) *cp = 0;
	bitmap_file = alloc(strlen(config_file) + strlen(BMP_BMP) + 1);
	strcpy(bitmap_file, config_file);
	strcat(bitmap_file, BMP_BMP);
	if (cp) *cp = '.';
    }

    printf("Transfer parameters from '%s' to '%s'", config_file, bitmap_file);
    if (yesno("?", 0)==0) exit(0);

    if (verbose > 0) printf("%s bitmap file:  %s\n", opt, bitmap_file);
    
    bmp_file_open(bitmap_file);
    
    bmp_do_table(cfg_get_strg(cf_bitmap, "bmp-table"), menu);
    bmp_do_colors(cfg_get_strg(cf_bitmap, "bmp-colors"), menu);
    bmp_do_timer(cfg_get_strg(cf_bitmap, "bmp-timer"), menu);
    
    bmp_file_close(1);  /* update */
    
    exit(0);
}
Esempio n. 2
0
char *
gen_tmpparm( char *pfile )
{
	char *append = cfg_get_strg(cf_options, "append");
	char *root = cfg_get_strg(cf_options, "root");
	int ro = cfg_get_flag(cf_options, "readonly");
	FILE *f,*of;
	char *fn;
	char c;
	char *tmpdir=NULL,*save=NULL;

	if (!append && !root && !ro)
		return pfile;
	of = fopen(pfile, "r");
	if ( of ) {
		NTRY( fn = tempnam(NULL,"parm."));
	} else {
		fn = pfile;
	}
	NTRY( f = fopen(fn, "a+"));
	if ( of ) {
		while ( ! feof (of) ) {
		  c=fgetc(of);
	  	fputc(c,f);
		}
	}
	if (root)
		fprintf(f, " root=%s", root);
	if (ro)
		fprintf(f, " ro");
	if (append)
		fprintf(f, " %s", append);
	fprintf(f, "\n");
	fclose(f);
	fclose(of);
	printf ("tempfile is %s\n",fn);
	return strdup(fn);
}
Esempio n. 3
0
int
read_cfg(struct silo_options *o)
{
	char *tmp;
	if (access(o->conffile, R_OK) && (errno == ENOENT))
		return 0;
	/* If errno != ENOENT, let cfg_open report an error */
	cfg_open(o->conffile);
	cfg_parse(cf_options);
	tmp = cfg_get_strg(cf_options, "ipldevice");
	if ( ! o->ipldevice  && tmp ) 
		o->ipldevice = tmp;
	tmp = cfg_get_strg(cf_options, "image");
	if ( ! strncmp(o-> image,SILO_IMAGE,strlen(SILO_IMAGE)) && tmp ) 
		o->image = tmp;
	tmp = cfg_get_strg(cf_options, "parmfile");
	if ( !strncmp(o->parmfile,SILO_PARMFILE,strlen(SILO_PARMFILE)) && tmp) 
		o->parmfile = tmp;
	if ( ! o -> ramdisk ) 
		o->ramdisk = cfg_get_strg(cf_options, "ramdisk");
	tmp = cfg_get_strg(cf_options, "bootsect");
	if ( !strncmp(o -> bootsect,SILO_BOOTSECT,strlen(SILO_BOOTSECT))&&tmp)
		o->bootsect = tmp;
	tmp = cfg_get_strg(cf_options, "map") ;
	if ( !strncmp(o -> bootmap,SILO_BOOTMAP,strlen(SILO_BOOTMAP)) && tmp) 
		o->bootmap = tmp; 
	tmp = cfg_get_strg(cf_options, "verbose");
	if ( tmp ) {
		unsigned short v;
		sscanf (tmp, "%hu", &v);
		o->verbosity = v;
	}
	tmp = cfg_get_strg(cf_options, "testlevel");
	if ( tmp ) {
		unsigned short t;
		sscanf (tmp, "%hu", &t);
		o->testlevel += t;
	}
	return 1;
}
Esempio n. 4
0
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,i;
    int tsecs;
    unsigned short checksum,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));
    if (verbose > 0) {
	bsect_read(cfg_get_strg(cf_options,"boot"),&boot);
	printf("Global settings:\n");
	tsecs = (boot.par_1.delay*55+50)/100;
	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*55+50)/100;
	    printf("  Command-line timeout: %d.%d seconds\n",tsecs/10,
	      tsecs % 10);
	}
	if (boot.par_1.prompt) printf("  Always enter boot prompt\n");
	else printf("  Enter boot prompt only on demand\n");
	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 printf("  Boot prompt message is %d bytes\n",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",verbose > 0 ? "  " : "",name,
	      image ? "  " : " *");
	    if (verbose > 1) {
		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 > 0) {
		flags = descrs.d.descr[image].flags;
		if (!*descrs.d.descr[image].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 (!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*
			  getpagesize());
		    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);
		}
		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);
		}
		if (flags & FLAG_KERNEL)
		    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 ?)");
			printf("    Options: \"%s\"\n",buffer);
		    }
		else if (geo_find(&geo,addr[3])) show_other(fd);
		   else printf("    Image data not found\n");
	    }
	}
    (void) close(fd);
    checksum = INIT_CKS;
    for (i = 0; i < sizeof(descrs)/sizeof(unsigned short); i++)
	checksum ^= ((unsigned short *) &descrs)[i];
    if (!checksum) exit(0);
    fflush(stdout);
    fprintf(stderr,"Checksum error\n");
    exit(1);
}
Esempio n. 5
0
int main(int argc,char **argv)
{
    char *name,*config_file,*reboot_arg,*identify,*ident_opt,*new_root;
    char *uninst_dev;
    int query,more,version,uninstall,validate,do_md_install,pass;
    BOOT_SECTOR dummy;
    IMAGE_DESCR dummy2;
    struct stat st;
    int fd, md_fd;
    md_array_info_t md_array_info;
    md_disk_info_t md_disk_info;
    char md_boot_name[MAX_TOKEN+1];
    char md_boot_map[MAX_TOKEN+1];
    DT_ENTRY md_disk;
    DT_ENTRY *disk;

    config_file = DFL_CONFIG;
    reboot_arg = identify = ident_opt = new_root = uninst_dev = NULL;
    pass = do_md_install = query = version = uninstall = validate = 0;
    name = *argv++;
    argc--;
    cfg_init(cf_options);
    while (argc && **argv == '-') {
	argc--;
	if (argv[0][2]) usage(name);
	switch ((*argv++)[1]) {
	    case 'b':
		if (!argc) usage(name);
		cfg_set(cf_options,"boot",*argv++,NULL);
		argc--;
		break;
	    case 'c':
		cfg_set(cf_options,"compact",NULL,NULL);
		compact = 1;
		break;
	    case 'd':
		if (!argc) usage(name);
		cfg_set(cf_options,"delay",*argv++,NULL);
		argc--;
		break;
	    case 'D':
		if (!argc) usage(name);
		cfg_set(cf_options,"default",*argv++,NULL);
		argc--;
		break;
	    case 'f':
		if (!argc) usage(name);
		cfg_set(cf_options,"disktab",*argv++,NULL);
		argc--;
		break;
	    case 'l':
		cfg_set(cf_options,"linear",NULL,NULL);
		linear = 1;
		break;
	    case 'm':
		if (!argc) usage(name);
		cfg_set(cf_options,"map",*argv++,NULL);
		argc--;
		break;
	    case 'i':
		if (!argc) usage(name);
		cfg_set(cf_options,"install",*argv++,NULL);
		argc--;
		break;
	    case 'I':
		if (!argc) usage(name);
		identify = *argv++;
		if (--argc) {
		    ident_opt = *argv++;
		    argc--;
		}
		break;
	    case 'X':
		printf("-DIMAGES=%d -DCODE_START_1=%d -DCODE_START_2=%d "
		  "-DDESCR_SIZE=%d -DDSC_OFF=%d -DDSC_OFF2=%d -DDFCMD_OFF=%d "
		  "-DMSG_OFF=%d -DFLAGS_OFF=%d\n",MAX_IMAGES,
		  sizeof(BOOT_PARAMS_1),sizeof(BOOT_PARAMS_2),
		  sizeof(IMAGE_DESCR),
		  (void *) &dummy.par_1.descr[0]-(void *) &dummy,
		  (void *) &dummy.par_1.descr[1]-(void *) &dummy,
		  (void *) &dummy.par_1.descr[2]-(void *) &dummy,
		  (void *) &dummy.par_1.msg_len-(void *) &dummy,
		  (void *) &dummy2.flags-(void *) &dummy2);
		exit(0);
	    case 'C':
		if (!argc) usage(name);
		config_file = *argv++;
		argc--;
		break;
	    case 'S':
		if (!argc) usage(name);
		cfg_set(cf_options,"force-backup",*argv++,NULL);
		argc--;
		break;
	    case 's':
		if (!argc) usage(name);
		cfg_set(cf_options,"backup",*argv++,NULL);
		argc--;
		break;
	    case 'P':
		if (!argc) usage(name);
		if (!strcmp(*argv,"fix"))
		    cfg_set(cf_options,"fix-table",NULL,NULL);
		else if (!strcmp(*argv,"ignore"))
			cfg_set(cf_options,"ignore-table",NULL,NULL);
		    else usage(name);
		argv++;
		argc--;
		break;
	    case 'q':
		query = 1;
		break;
	    case 'r':
		if (!argc) usage(name);
		new_root = *argv++;
		argc--;
		break;
	    case 'R':
		if (!argc) reboot_arg = "";
		else while (argc) {
			if (!reboot_arg)
			    *(reboot_arg = alloc(strlen(*argv)+1)) = 0;
			else strcat(reboot_arg = ralloc(reboot_arg,
			      strlen(reboot_arg)+strlen(*argv)+2)," ");
			strcat(reboot_arg,*argv++);
			argc--;
		    }
		break;
	    case 't':
		test = 1;
		break;
	    case 'u':
		validate = 1;
		/* fall through */
	    case 'U':
		uninstall = 1;
		if (argc) {
		    if (argc-- > 1) usage(name);
		    uninst_dev = *argv;
		}
		break;
	    case 'v':
		verbose++;
		break;
	    case 'V':
		version = 1;
		break;
	    case 'w':
		cfg_set(cf_options,"nowarn",NULL,NULL);
		nowarn = 1;
		break;
	    default:
		usage(name);
	}
    }
    if (!new_root) new_root = getenv("ROOT");
    if (new_root && *new_root) {
	if (chroot(new_root) < 0) die("chroot %s: %s",new_root,strerror(errno));
	if (chdir("/") < 0) die("chdir /: %s",strerror(errno));
    }
    if (atexit(temp_remove)) die("atexit() failed");
    if (verbose > 0 || version) {
	printf("LILO version 21%s",version ? "\n" : "");
	if (version) return 0;
	printf(", Copyright 1992-1998 Werner Almesberger\n\n");
    }
#if 0
    if (((install || test || boot_device || disktab_file || compact) && !argc)
      || (compact && linear && 0)) usage(name);
#endif
    if (!nowarn && compact && linear)
	fprintf(stderr,"Warning: COMPACT may conflict with LINEAR on some "
	  "systems\n");
    preload_types();
    fd = cfg_open(config_file);
    more = cfg_parse(cf_options);
    if (!nowarn) {
	if (fstat(fd,&st) < 0) {
	    fprintf(stderr,"fstat %s: %s\n",config_file,strerror(errno));
	    exit(1);
	}
	if (S_ISREG(st.st_mode)) {
	    if (st.st_uid)
		fprintf(stderr,"Warning: %s should be owned by root\n",
		  config_file);
	    else if (st.st_mode & (S_IWGRP | S_IWOTH))
		    fprintf(stderr,"Warning: %s should be writable only for "
		      "root\n",config_file);
		else if ((cfg_get_strg(cf_all,"password") || cfg_get_strg(
		      cf_options,"password")) && (st.st_mode & (S_IRGRP |
		      S_IROTH)))
			fprintf(stderr,"Warning: %s should be readable only "
			  "for root if using PASSWORD\n",config_file);
	}
    }
    preload_dev_cache();
    if (identify) identify_image(identify,ident_opt);
    if (strncmp("/dev/md",cfg_get_strg(cf_options,"boot"),7) == 0) {
	if ((md_fd=open(cfg_get_strg(cf_options,"boot"),O_NOACCESS)) < 0)
	    die("Unable to open %s",cfg_get_strg(cf_options,"boot"));
	if (fstat(md_fd,&st) < 0)
	    die("Unable to stat %s",cfg_get_strg(cf_options,"boot"));
	if (!S_ISBLK(st.st_mode))
	    die("%s is not a block device",cfg_get_strg(cf_options,"boot"));
	if (ioctl(md_fd,GET_ARRAY_INFO,&md_array_info) < 0)
	    die("Unable to get RAID info on %s",cfg_get_strg(cf_options,"boot"));
	if ((md_array_info.major_version == 0) && (md_array_info.minor_version < 90))
	    die("Raid versions < 0.90 are not supported");
	if (md_array_info.level != 1)
	    die("Only RAID1 devices are supported as boot devices");
	do_md_install = 1;
	strcpy(md_boot_name,cfg_get_strg(cf_options,"boot"));
	if (cfg_get_strg(cf_options,"map"))
	    strcpy(md_boot_map,cfg_get_strg(cf_options,"map"));
	else
	    strcpy(md_boot_map,MAP_FILE);
	md_disk.device = (MD_MAJOR << 8) | md_array_info.md_minor;
	md_disk.bios = 0x80;
	md_disk.next = disktab;
	disktab = &md_disk;
    }
    while( (pass == 0) || (do_md_install && (pass < md_array_info.nr_disks)) ) {
	if(do_md_install) {
	    GEOMETRY geo;
	    DEVICE dev;
	    int device,disk_fd;
	    char new_name[MAX_TOKEN+1];

	    if(pass > 0) {
		close(fd);
		cfg_init(cf_options);
		fd = cfg_open(config_file);
		more = cfg_parse(cf_options);
	    }
	    md_disk_info.number = pass;
	    if (ioctl(md_fd,GET_DISK_INFO,&md_disk_info) < 0)
		die("main: GET_DISK_INFO: %s", strerror(errno));
	    device = (md_disk_info.major << 8) | md_disk_info.minor;
	    disk_fd = dev_open(&dev,device,O_NOACCESS);
	    if (md_disk_info.state == MD_DISK_FAULTY) {
		printf("disk %s marked as faulty, skipping\n",dev.name);
		pass++;
		continue;
	    }
	    geo_query_dev(&geo,device,1);
	    disk = alloc_t(DT_ENTRY);
	    disk->bios = 0x80;
	    disk->device = device & 0xfff0;
	    disk->sectors = geo.sectors;
	    disk->heads = geo.heads;
	    disk->cylinders = geo.cylinders;
	    disk->start = geo.start;
	    disk->next = disktab;
	    disktab = disk;
	    if (cfg_get_strg(cf_options,"boot")) cfg_unset(cf_options,"boot");
	    if (cfg_get_strg(cf_options,"map")) cfg_unset(cf_options,"map");
	    strncpy(new_name,dev.name,8);
	    new_name[8] = '\0';
	    cfg_set(cf_options,"boot",new_name,NULL);
	    snprintf(new_name,MAX_TOKEN,"%s.%04x",md_boot_map,device);
	    cfg_set(cf_options,"map",new_name,NULL);
	    printf("boot = %s, map = %s\n", cfg_get_strg(cf_options,"boot"),
		cfg_get_strg(cf_options,"map"));
	    md_disk.sectors = geo.sectors;
	    md_disk.heads = geo.heads;
	    md_disk.cylinders = geo.cylinders;
	    md_disk.start = geo.start;
	}
	    
	pass++;
	if (uninstall)
	    bsect_uninstall(uninst_dev ? uninst_dev : cfg_get_strg(cf_options,
	      "boot"),cfg_get_strg(cf_options,"backup"),validate);
	compact = cfg_get_flag(cf_options,"compact");
	linear = cfg_get_flag(cf_options,"linear");
	nowarn = cfg_get_flag(cf_options,"nowarn");
	if (cfg_get_strg(cf_options,"verbose"))
	    verbose += to_number(cfg_get_strg(cf_options,"verbose"));
	if (reboot_arg) {
	    map_patch_first(cfg_get_strg(cf_options,"map") ? cfg_get_strg(
	      cf_options,"map") : MAP_FILE,reboot_arg);
	    exit(0);
	}
	if (argc) usage(name);
	geo_init(cfg_get_strg(cf_options,"disktab"));
	if (query)
	    show_images(!cfg_get_strg(cf_options,"map") ? MAP_FILE :
	      cfg_get_strg(cf_options,"map"));
	bsect_open(cfg_get_strg(cf_options,"boot"),cfg_get_strg(cf_options,"map") ?
	  cfg_get_strg(cf_options,"map") : MAP_FILE,cfg_get_strg(cf_options,
	  "install"),cfg_get_strg(cf_options,"delay") ? to_number(cfg_get_strg(
	  cf_options,"delay")) : 0,cfg_get_strg(cf_options,"timeout") ?
	  to_number(cfg_get_strg(cf_options,"timeout")) : -1);
	if (more) {
            cfg_init(cf_top);
            if (cfg_parse(cf_top)) cfg_error("Syntax error");
	}
	if (!bsect_number()) die("No images have been defined.");
	check_fallback();
	if (!test)
	    if (cfg_get_strg(cf_options,"force-backup"))
		bsect_update(cfg_get_strg(cf_options,"force-backup"),1);
	    else bsect_update(cfg_get_strg(cf_options,"backup"),0);
	else {
	    bsect_cancel();
	    fprintf(stderr,"The boot sector and the map file have *NOT* been "
	      "altered.\n");
	}
    }
    return 0;
}
Esempio n. 6
0
File: lilo.c Progetto: x86-8/lilo232
	int main(int argc,char **argv)
	{
		char *name,*reboot_arg,*ident_opt,*new_root;
		char *tell_param, *uninst_dev, *param, *act1, *act2, ch;
		static char *bitmap_file;
		int more,version,uninstall,validate,activate,instmbr,geom;
		int fd, temp=0, tell_early=0;
		int raid_offset;
#if !__MSDOS__
		struct stat st;
#endif /* !__MSDOS__ */

		errstd = stderr;
#if VERSION_MINOR>=50
		if (sizeof(MENUTABLE)!=256) die("MENUTABLE is not 256 bytes (common.h)");
#if !__MSDOS__
		cfg_alpha_check();
#endif /* !__MSDOS__ */
#endif
		config_file = DFL_CONFIG;
		act1 = act2 = tell_param = 
			reboot_arg = identify = ident_opt = new_root = uninst_dev = NULL;
		do_md_install = zflag =
			version = uninstall = validate = activate = instmbr = 0;
		verbose = -1;
#if !__MSDOS__
		name = *argv;
#else  /* __MSDOS__ */
		name = "lilo";
#endif /* __MSDOS__ */
		argc--;

#if !__MSDOS__    
		if (atexit( (void(*)(void)) sync)) die("atexit(sync)");
		if (atexit( (void(*)(void)) purge)) die("atexit(purge)");
#endif /* !__MSDOS__ */

		cfg_init(cf_options);
		while (argc && **++argv == '-') {
			argc--;
			/* first those options with a mandatory parameter */
			/* Notably absent are "RuUvw" */
			if (strchr("AbBCdDEfiImMPrsSTxZ", ch=(*argv)[1])) {
				if ((*argv)[2]) param = (*argv)+2;
				else {
					param = *++argv;
					if(argc-- <= 0) usage(name);
				}
			} else { 
				param = NULL;
				if (strchr("cFglLpqtVXz", ch)	/* those with no args */
						&& (*argv)[2]) usage(name);
			}
#if 0
			fprintf(errstd,"argc=%d, *argv=%s, ch=%c param=%s\n", argc, *argv, ch, param);
#endif
			switch (ch) {
#if !__MSDOS__
				case 'A':
					activate = 1;
					act1 = param;
					if (argc && argv[1][0] != '-') {
						act2 = *++argv;
						argc--;
					}
					break;
				case 'b':
					cfg_set(cf_options,"boot",param,NULL);
					break;
				case 'B':
					cfg_set(cf_options,"bitmap",param,NULL);
					break;
				case 'c':
					cfg_set(cf_options,"compact",NULL,NULL);
					compact = 1;
					break;
#endif /* !__MSDOS */
				case 'C':
					config_file = param;
					break;
#if !__MSDOS__
				case 'd':
					cfg_set(cf_options,"delay",param,NULL);
					break;
				case 'D':
					cfg_set(cf_options,"default",param,NULL);
					break;
				case 'E':
					eflag=1;
					bitmap_file = param;
					break;
				case 'f':
					cfg_set(cf_options,"disktab",param,NULL);
					break;
				case 'F':
					force_fs=1;
					break;
				case 'g':
					geometric |= AD_GEOMETRIC;
					break;
				case 'H':
					force_raid=1;
					break;
				case 'i':
					cfg_set(cf_options,"install",param,NULL);
					break;
				case 'I':
					identify = param;
					if (argc && *argv[1] != '-') {
						ident_opt = *++argv;
						argc--;
					} else {
						ident_opt = "i";
					}
					break;
				case 'l':
					geometric |= AD_LINEAR;
					break;
				case 'L':
					geometric |= AD_LBA32;
					break;
#endif /* !__MSDOS__ */
				case 'm':
					cfg_set(cf_options,"map",param,NULL);
					break;
#if !__MSDOS__
				case 'M':
					instmbr = 1;
					act1 = param;
#if !defined LCF_BUILTIN	|| 1
					if (argc && argv[1][0] != '-') {
						act2 = *++argv;
						argc--;
					}
#endif
					break;
				case 'p':
					passw = 1;	/* force re-gen of password file */
					break;
				case 'P':
					if ((act1=strchr(param,'='))) {
						*act1++ = 0;	/* null terminate */
						cfg_set(cf_options,param,act1,NULL);
					}
					else if (!strcasecmp(param,"fix"))
						cfg_set(cf_options,"fix-table",NULL,NULL);
					else if (!strcasecmp(param,"ignore"))
						cfg_set(cf_options,"ignore-table",NULL,NULL);
					else if (!strcasecmp(param,"x"))
						extended_pt = 1;
					else
						cfg_set(cf_options,param,NULL,NULL);
					break;
#endif /* !__MSDOS__ */
				case 'q':
					query = 1;
					break;
#if !__MSDOS__
				case 'r':
					new_root = param;
					break;
#endif /* !__MSDOS__ */
				case 'R':
					if (*(param = (*argv)+2)) argc++;
					else if (argc) param = *++argv;
					else reboot_arg = "";

					while (argc) {
						if (!reboot_arg)
							*(reboot_arg = alloc(strlen(param)+1)) = 0;
						else {
							param = *++argv;
							strcat(reboot_arg = ralloc(reboot_arg,
										strlen(reboot_arg)+strlen(param)+2)," ");
						}
						strcat(reboot_arg, param);
						argc--;
					}
#if 0
					fprintf(errstd,"REBOOT=\"%s\"\n", reboot_arg);		    
#endif
					break;
#if !__MSDOS__
				case 's':
					cfg_set(cf_options,"backup",param,NULL);
					break;
				case 'S':
					cfg_set(cf_options,"force-backup",param,NULL);
					break;
				case 't':
					test = 1;
					break;
				case 'T':
					tell_param = param;
					break;
				case 'u':
					validate = 1;
					/* fall through */
				case 'U':	/* argument to -u or -U is optional */
					uninstall = 1;
					if ((*argv)[2]) param = (*argv)+2;
					else if (argc && argv[1][0] != '-') {
						param = *++argv;
						argc--;
					}
					uninst_dev = param;
					break;
#endif /* !__MSDOS__ */
				case 'v':
					if ((*argv)[2]) param = (*argv)+2;
					else if (argc && argv[1][0]>='0' && argv[1][0]<='9') {
						param = *++argv;
						argc--;
					}
					if (param) 
						verbose = to_number(param);
					else
						if (verbose<0) verbose = 1;
						else verbose++;
					if (verbose) errstd = stdout;
					break;
				case 'V':
					version = 1;
					break;
#if !__MSDOS__
				case 'w':
					cfg_set(cf_options,"nowarn",NULL,NULL);
					nowarn = 1;
					if ( (*argv)[2] == '+' ) nowarn = -1;
					break;
				case 'x':
					cfg_set(cf_options,RAID_EXTRA_BOOT,param,NULL);
					break;
#endif /* !__MSDOS__ */
				case 'X':
					configuration();
					exit(0);
#if !__MSDOS__
				case 'z':
					zflag++;	/* force zero of MBR 8-byte area */
					break;
				case 'Z':
					cfg_set(cf_options,"bios-passes-dl",param,NULL);
					break;
#endif /* !__MSDOS__ */
				default:
					usage(name);
			}
		}
		if (argc) usage(name);
#if !__MSDOS__
		if (!new_root) new_root = getenv("ROOT");
		if (new_root && *new_root) {
			pp_fd = fopen(PARTITIONS, "r");
			if (chroot(new_root) < 0) die("chroot %s: %s",new_root,strerror(errno));
			if (chdir("/dev") < 0)
				warn("root at %s has no /dev directory", new_root);
			if (chdir("/") < 0) die("chdir /: %s",strerror(errno));
		}
		if (atexit(temp_remove)) die("atexit() failed");
		if (version+activate+instmbr+(tell_param!=NULL) > 1) usage(name);
		if (activate) do_activate(act1, act2);
#endif /* !__MSDOS__ */

		if (verbose > 0 || version) {
			printf("LILO version %d.%d%s", VERSION_MAJOR, VERSION_MINOR, VERSION_EDIT);
			if (test)
				printf(" (test mode)\n");
			else
				printf(" (released %s)\n", VERSION_DATE);
			if (version && verbose<=0) {
				/* exit if user asks for version and no verbose */
				return 0;
			}
			printf("  * Copyright (C) 1992-1998 Werner Almesberger  (until v20)\n"
					"  * Copyright (C) 1999-2007 John Coffman  (until v22)\n"
					"  * Copyright (C) 2009-2011 Joachim Wiedorn  (since v23)\n"
					"This program comes with ABSOLUTELY NO WARRANTY. This is free software \n"
					"distributed under the BSD License (3-clause). Details can be found in \n"
					"the file COPYING, which is distributed with this software.\n"
				  );
			if (verbose>0) {
#if !__MSDOS__
#include <sys/utsname.h>
				struct utsname buf;
#endif
				printf("Compiled at %s on %s%s\n", __TIME__, __DATE__, semi);
#if !__MSDOS__
				if (verbose>=2 && uname(&buf)==0) {
					printf("Running %s kernel %s on %s\n",
							buf.sysname, buf.release, buf.machine);
				}
#endif
			}
			printf("\n");
			if (version) {
				if (verbose>=2) configuration();
				return 0;
			}
		}

		if (verbose > 0) errstd = stdout;
#if !__MSDOS__
		preload_types();
		if (geometric & (geometric-1))
			die ("Only one of '-g', '-l', or '-L' may be specified");

		if (tell_param) tell_early = strcasecmp(tell_param, "chrul")
			&& strcasecmp(tell_param, "ebda");
		if (eflag) do_bitmap_edit(bitmap_file);
		if (tell_param && tell_early) probe_tell(tell_param);
		if (instmbr) do_install_mbr(act1, act2);
#endif /* !__MSDOS__ */    

		fd = cfg_open(config_file);
		more = fd<0 ? 0 : cfg_parse(cf_options);

#if !__MSDOS__
		temp = cfg_get_flag(cf_options,"nowarn");
		if (nowarn < 0) nowarn = 0;
		else nowarn = temp;
		/* All warnings appear if very verbose modes used */
		if (verbose>=3) nowarn = 0;
#endif /* !__MSDOS__ */

		if (verbose>=6) printf("main: cfg_parse returns %d\n", more);

#if !__MSDOS__
		if (tell_param && !tell_early) probe_tell(tell_param);

		if (fstat(fd,&st) < 0)
			die("fstat %s: %s", config_file, strerror(errno) );

		if (S_ISREG(st.st_mode)) {
			if (st.st_uid)
				warn("%s should be owned by root", config_file);
			else if (st.st_mode & (S_IWGRP | S_IWOTH))
				warn("%s should be writable only for root", config_file);
			config_read = !!(st.st_mode & (S_IRGRP | S_IROTH));
		}

		if (!cfg_get_flag(cf_options,"nodevcache"))  preload_dev_cache();

		if (verbose<0 && cfg_get_strg(cf_options,"verbose"))
			verbose = to_number(cfg_get_strg(cf_options,"verbose"));
		if (verbose<0) verbose = 0;
		if (verbose) errstd = stdout;

		compact = cfg_get_flag(cf_options,"compact");
		geom = cfg_get_flag(cf_options,"geometric");
		linear = cfg_get_flag(cf_options,"linear");
		lba32  = cfg_get_flag(cf_options,"lba32");

		if (geom+linear+lba32 > 1)
			die("May specify only one of GEOMETRIC, LINEAR or LBA32");
		if (geometric) {
			if (geom+linear+lba32 > 0)  
				warn("Ignoring entry '%s'", geom ? "geometric" :
						linear ? "linear" : "lba32");
			geom = linear = lba32 = 0;
			if (geometric==AD_LBA32) lba32 = 1;
			else if (geometric==AD_LINEAR) linear = 1;
			else if (geometric==AD_GEOMETRIC) geom = 1;
		}    
		if (geom+linear+lba32 == 0) {
			warn("LBA32 addressing assumed");
			lba32 = 1;
		}
		if (linear) warn(
				"LINEAR is deprecated in favor of LBA32:  LINEAR specifies 24-bit\n"
				"  disk addresses below the 1024 cylinder limit; LBA32 specifies 32-bit disk\n"
				"  addresses not subject to cylinder limits on systems with EDD-BIOS extensions;\n"
				"  use LINEAR only if you are aware of its limitations.");

		if (identify) identify_image(identify,ident_opt);

		if (uninstall)
			bsect_uninstall(uninst_dev ? uninst_dev : cfg_get_strg(cf_options,
						"boot"),cfg_get_strg(cf_options,"backup"),validate);
#endif /* !__MSDOS__ */

		if (reboot_arg) {
			map_patch_first(cfg_get_strg(cf_options,"map") ? cfg_get_strg(
						cf_options,"map") : MAP_FILE, reboot_arg);
			exit(0);
		}

#if !__MSDOS__
		if ( (param = cfg_get_strg(cf_options,"bios-passes-dl")) ) {
			if (strchr("YyTt1", *param)) bios_passes_dl = DL_GOOD;
			if (strchr("NnFf0", *param)) bios_passes_dl = DL_BAD;
		}
		if (bios_passes_dl == DL_NOT_SET) 	check_bios();	/* in probe.c */

		if (compact && (linear || lba32) && verbose>=4)
			warn("COMPACT may conflict with %s on some "
					"systems", lba32 ? "LBA32" : "LINEAR");

		geo_init(cfg_get_strg(cf_options,"disktab"));
#endif /* !__MSDOS__ */
		if (query)
			show_images(!cfg_get_strg(cf_options,"map") ? MAP_FILE :
					cfg_get_strg(cf_options,"map"));

#if !__MSDOS__
		/*************************************************/
		/*  Doing a real install (may be test mode)      */
		/*************************************************/

		/* test for a RAID installation */
		raid_offset = raid_setup();
		if (verbose >= 2) {
			printf("raid_setup returns offset = %08X  ndisk = %d\n", raid_offset, ndisk);
			dump_serial_nos();    
		}

		if (verbose >=2 && do_md_install)
			printf("raid flags: at bsect_open  0x%02X\n", raid_flags);

		bsect_open(
				cfg_get_strg(cf_options,"boot"),
				cfg_get_strg(cf_options,"map") ?
				cfg_get_strg(cf_options,"map") : MAP_FILE,
				cfg_get_strg(cf_options,"install"),
				cfg_get_strg(cf_options,"delay") ?
				timer_number(cfg_get_strg(cf_options,"delay")) : 0,
				cfg_get_strg(cf_options,"timeout") ?
				timer_number(cfg_get_strg(cf_options,"timeout")) : -1,
				raid_offset );
		if (more) {
			cfg_init(cf_top);
			if (cfg_parse(cf_top)) cfg_error("Syntax error");
		}

		temp = bsect_number();
		if (temp==0) die("No images have been defined.");
		else if (temp<0) die("Default image doesn't exist.");

#ifdef LCF_VIRTUAL
		check_vmdefault();
#endif
#ifdef LCF_NOKEYBOARD
		check_nokbdefault();
#endif
		check_fallback();
		check_unattended();

		if (verbose>=2) dump_serial_nos();
		if (do_md_install) raid_final();
		else if (!test) {
			char *cp;

			if (verbose) printf("Writing boot sector.\n");

			cp = cfg_get_strg(cf_options,"force-backup");
			if (cp) bsect_update(cp,1,0);
			else bsect_update(cfg_get_strg(cf_options,"backup"),0,0);

		} 
		else {
			bsect_cancel();
			if (passw)
				printf("The password crc file has *NOT* been updated.\n");

			printf("The boot sector and the map file have *NOT* been "
					"altered.\n");
		}
		if (verbose>=4) dump_serial_nos();
		if (warnings) {
			if (warnings>1)
				printf("%d warnings were ", warnings);
			else printf("One warning was ");
			printf("%sed.\n", nowarn ? "suppress" : "issu");
		}
#else  /* __MSDOS__ */
		die("No option switches specified:  -q, -R, or -V");
#endif /* __MSDOS__ */

		return 0;
	}
Esempio n. 7
0
File: lilo.c Progetto: x86-8/lilo232
static void show_images(char *map_file)
{
#if !__MSDOS__
	DESCR_SECTORS descrs;
	BOOT_SECTOR boot;
	MENUTABLE menu;
	BOOT_PARAMS_2 param2;
	GEOMETRY geo;
	SECTOR_ADDR addr[4];
	char buffer[SECTOR_SIZE];
#else /* __MSDOS */
	static DESCR_SECTORS descrs;
	static char buffer[SECTOR_SIZE];
#endif /*__MSDOS__ */
	char *name;
	int fd,image;
	int tsecs;
	int tlinear, tlba32;
	unsigned short flags;
	time_t Time;

#if !__MSDOS__
	fd = geo_open(&geo,map_file,O_RDONLY);
#else  /* __MSDOS__ */
	if ((fd = open(map_file,O_RDONLY))<=0)
		die("Cannot open map file: %s", map_file);
#endif /* __MSDOS__ */
	if (read(fd,buffer,SECTOR_SIZE) != SECTOR_SIZE)
		die("read cmdline %s: %s",map_file,strerror(errno));
	if (read(fd,(char*)&descrs,sizeof(descrs)) != sizeof(descrs))
		die("read descrs %s: %s",map_file,strerror(errno));
#if !__MSDOS__
	if (lseek(fd, SECTOR_SIZE, SEEK_CUR) <= 0)	/* skip zero sector */
		die("lseek over zero sector %s: %s",map_file,strerror(errno));
	if (read(fd,(char*)&param2,sizeof(param2)) != sizeof(param2))
		die("read second params %s: %s",map_file,strerror(errno));
	if (lseek(fd, - sizeof(menu), SEEK_END) <= 0)
		die("lseek keytable %s: %s",map_file,strerror(errno));
	if (read(fd,(char*)&menu,sizeof(menu)) != sizeof(menu))
		die("read keytable %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) {
		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
#if 1
		Time = boot.par_1.map_stamp;
		printf("Installed:  %s\n", ctime(&Time));
#else
		printf("Installed:  %s\n", ctime((time_t*)&boot.par_1.map_stamp));
#endif
		printf("Global settings:\n");
		tsecs = (param2.delay*2197+3999)/4000;
		printf("  Delay before booting: %d.%d seconds\n",tsecs/10,tsecs % 10);
		if (param2.timeout == 0xffff) printf("  No command-line timeout\n");
		else {
			tsecs = (param2.timeout*2197+3999)/4000;
			printf("  Command-line timeout: %d.%d seconds\n",tsecs/10,
					tsecs % 10);
		}
		printf("  %snattended booting\n", param2.flag2&FLAG2_UNATTENDED ? "U" : "No u");
		printf("  %sPC/AT keyboard hardware prescence check\n", param2.flag2&FLAG2_NOKBD ? "" : "No ");
		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("  Boot-time BIOS data auto-suppress write%s bypassed\n",
				boot.par_1.prompt & FLAG_BD_OKAY ? "" : " 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-");
		printf("  Boot device %s be used for the Map file\n",
				boot.par_1.prompt & FLAG_MAP_ON_BOOT ? "WILL" : "will not");
		if (!param2.port) printf("  Serial line access is disabled\n");
		else printf("  Boot prompt can be accessed from COM%d\n",
				param2.port);
		if (!param2.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",param2.msg_len);
		else printf("  Bitmap file is %d paragraphs (%d bytes)\n",
				param2.msg_len, 16*param2.msg_len);
		/* 22.6.2 begin */
		if (*(unsigned short *) buffer != DC_MAGIC /* || !buffer[2] */)
			/* 22.6.2 end */
			printf("  No default boot command line\n");
		else printf("  Default boot command line: \"%s\"\n",buffer+2);
		if (verbose>=3) {
			printf("Serial numbers %08X\n", menu.serial_no[0]);
		}
		printf("Images:\n");
	}
	/* 22.7 begin */
	else	/* verbose==0 */
#endif /* !__MSDOS__ */
	{
		if (*(unsigned short *) buffer == DC_MAGIC)
			printf("Default boot command line: \"%s\"\n",buffer+2);
	}
	/* 22.7 end */
	for (image = 0; image < MAX_IMAGES; image++) {
		if (*(name = descrs.d.descr[image].name)) {
#if __MSDOS__
			printf("%s\n", name
#else /* !__MSDOS__ */
					printf("%s%-" SA(MAX_IMAGE_NAME) "s %s%s%s",verbose > 0 ? "  " : "",name,
						image ? "" : "*",
#ifdef LCF_VIRTUAL
						descrs.d.descr[image].flags & FLAG_VMDEFAULT ? "@" :
#endif
						"",
#ifdef LCF_NOKEYBOARD
						descrs.d.descr[image].flags & FLAG_NOKBDEFAULT ? "&" :
#endif
						""
#endif /* !__MSDOS__ */
						);
#if !__MSDOS__
					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,%s=%d>",
							descrs.d.descr[image].start.device&DEV_MASK,
							descrs.d.descr[image].start.device&LBA32_FLAG ? "lba32" : "linear",
							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		
#ifdef LCF_NOKEYBOARD
						if (flags & FLAG_NOKBDISABLE)
							printf("    NoKeyboard Boot is disabled\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 (!(flags & FLAG_LOADHI))
								printf("    Kernel is loaded \"low\"\n");
							else printf("    Kernel is loaded \"high\"\n");
							if (!*(unsigned int *) descrs.d.descr[image].rd_size)
								printf("    No initial RAM disk\n");
							else printf("    Initial RAM disk is %d bytes\n",
									*(unsigned int *) descrs.d.descr[image].rd_size);
							if (flags & FLAG_TOOBIG)
								printf("       and is too big to fit between 4M-15M\n");
						}
						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 ?) 2");
						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 ?) 3");
							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 ?) 4");
								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");
							}
						}
#endif /*  !__MSDOS__ */
					} /* if */
		} /* for */
#undef OTHER
		(void) close(fd);
#if !__MSDOS__
		if (descrs.l.checksum ==
				crc32(descrs.sector, sizeof(descrs.l.sector), CRC_POLY1) )
#endif /* !__MSDOS__ */
			exit(0);
#if !__MSDOS__
		fflush(stdout);
		fprintf(errstd,"Checksum error\n");
		exit(1);
#endif /* !__MSDOS__ */
	}
Esempio n. 8
0
static void do_identify(char *var,char type)
{
    char *label,*path,*alias,*initrd,*keytab,*appstr,*dtem,*addappstr;
    char *rootstr;
    int root,image, ramdisk, kt, append;

#if 1
    image = !!strchr(opt,'i');
    ramdisk = !!strchr(opt,'r');
    kt = !!strchr(opt,'k');
    append = !!strchr(opt,'a');
    root = !!strchr(opt,'R');
    if (opt && !image && !ramdisk && !kt && !append
    	&& !idefault && !root) exit(1);
/*    if (!opt) image = 1; */
#else
    image = ramdisk = 1;
    printf("do_identify:  opt=\"%s\"\n", opt);
#endif
    
    label = strrchr(path = cfg_get_strg(cf_identify,var),'/');
    if (label) label++;
    if (cfg_get_strg(cf_all,"label")) label = cfg_get_strg(cf_all,"label");
    else if (!label) label = path;

    if (!first) first = stralloc(label);
    
    alias = cfg_get_strg(cf_all,"alias");
    dtem = cfg_get_strg(cf_options,"default");

    if (verbose>=2) printf("identify: dtem=%s  label=%s\n", dtem, label);
#ifdef LCF_IGNORECASE
    if (dtem && (!strcasecmp(label,dtem) || (alias && !strcasecmp(alias,dtem)))) {
#else
    if (dtem && (!strcmp(label,dtem) || (alias && !strcmp(alias,dtem)))) {
#endif
	if (verbose>=2) printf("setting  dflt\n");
	dflt = dtem;
    }

    initrd = cfg_get_strg(cf_kernel,"initrd");
    if (!initrd) initrd = cfg_get_strg(cf_options,"initrd");
    keytab = cfg_get_strg(cf_options,"keytable");
    if (!keytab) keytab="us.ktl";
    appstr = cfg_get_strg(cf_kernel,"append");
    if (!appstr) appstr = cfg_get_strg(cf_options,"append");
    addappstr = cfg_get_strg(cf_kernel,"addappend");
    rootstr = cfg_get_strg(cf_kernel,"root");
    if (!rootstr) rootstr = cfg_get_strg(cf_options,"root");

#ifdef LCF_IGNORECASE
    if (!strcasecmp(label,identify) || (alias && !strcasecmp(alias,identify))) {
#else
    if (!strcmp(label,identify) || (alias && !strcmp(alias,identify))) {
#endif
	if (image) printf("%s\n",path);
	if (ramdisk) printf("%s\n",initrd?initrd:"No initial ramdisk specified");
	if (kt) printf("%s\n",keytab);
	if (append) {
	    if (!appstr && !addappstr)
		printf("No append= was specified\n");
	    else if ((appstr && !addappstr) || (!appstr && addappstr))
		printf("%s\n", appstr?appstr:addappstr);
	    else printf("%s %s\n", appstr, addappstr);
	}
	if (root) printf("%s\n",rootstr?rootstr:"No root specified");
	if (idefault) printf("%s\n", dflt ? dflt : first);
	exit(0);
    }
}


void id_image(void)
{
    cfg_init(cf_image);
    (void) cfg_parse(cf_image);
    do_identify("image",'i');
    cfg_init(cf_identify);
}


void id_other(void)
{
    cfg_init(cf_other);
    cfg_init(cf_kernel);
    curr_drv_map = curr_prt_map = 0;
    (void) cfg_parse(cf_other);
    cfg_init(cf_identify);
}
Esempio n. 9
0
File: cfg.c Progetto: arnew/yaboot
int cfg_get_flag (char *image, char *item)
{
     return !!cfg_get_strg (image, item);
}
Esempio n. 10
0
File: main.c Progetto: andreiw/iQUIK
static char *
make_params(char *label,
            char *params)
{
   char *p, *q;
   static char *buffer = NULL;

   /*
    * AndreiW: fix me. This is mildly
    * better than putting it on the heap.
    */
   if (buffer == NULL) {
      buffer = malloc(2048);
      if (buffer == NULL) {
         return NULL;
      }
   }

   q = buffer;
   *q = 0;

   p = cfg_get_strg(label, "literal");
   if (p) {
      strcpy(q, p);
      q = strchr(q, 0);
      if (*params) {
         if (*p)
            *q++ = ' ';
         strcpy(q, params);
      }
      return buffer;
   }

   p = cfg_get_strg(label, "root");
   if (p) {
      strcpy (q, "root=");
      strcpy (q + 5, p);
      q = strchr (q, 0);
      *q++ = ' ';
   }
   if (cfg_get_flag(label, "read-only")) {
      strcpy (q, "ro ");
      q += 3;
   }
   if (cfg_get_flag(label, "read-write")) {
      strcpy (q, "rw ");
      q += 3;
   }
   p = cfg_get_strg(label, "ramdisk");
   if (p) {
      strcpy (q, "ramdisk=");
      strcpy (q + 8, p);
      q = strchr (q, 0);
      *q++ = ' ';
   }
   p = cfg_get_strg (label, "append");
   if (p) {
      strcpy (q, p);
      q = strchr (q, 0);
      *q++ = ' ';
   }
   *q = 0;

   if (cfg_get_flag (label, "pause-after")) {
      bi->flags |= PAUSE_BEFORE_BOOT;
   }

   p = cfg_get_strg(label, "pause-message");
   if (p) {
      bi->pause_message = p;
   }

   if (*params) {
      strcpy(q, params);
   }

   return buffer;
}
Esempio n. 11
0
File: main.c Progetto: andreiw/iQUIK
static quik_err_t
get_params(char **kernel,
           char **initrd,
           char **params,
           env_dev_t *cur_dev)
{
   char *p;
   char *q;
   int n;
   char *buf;
   char *endp;
   key_t lastkey;
   char *label = NULL;
   int timeout = DEFAULT_TIMEOUT;

   if ((bi->flags & TRIED_AUTO) == 0) {
      bi->flags ^= TRIED_AUTO;
      *params = bi->bootargs;
      *kernel = *params;

      word_split(kernel, params);
      if (!*kernel) {
         *kernel = cfg_get_default();

         /*
          * Timeout only makes sense
          * if we don't have an image name already
          * passed.
          */
         if ((bi->flags & CONFIG_VALID) &&
             (q = cfg_get_strg(0, "timeout")) != 0 && *q != 0) {
           timeout = strtol(q, NULL, 0);
         }
      } else {

         /*
          * We have something, boot immediately.
          */
         timeout = 0;
      }
   }

   printk(PROMPT);
   lastkey = KEY_NONE;
   if (timeout != -1) {
      lastkey = wait_for_key(timeout, '\n');
   }

   if (lastkey == '\n') {
      printk("%s", *kernel);
      if (*params) {
         printk(" %s", *params);
      }

      printk("\n");
   } else {
      *kernel = NULL;

      buf = cmd_edit(maintabfunc, lastkey);
      if (buf == NULL) {
         return ERR_NOT_READY;
      }

      *kernel = buf;
      word_split(kernel, params);
   }

   if (bi->flags & CONFIG_VALID) {
      *initrd = cfg_get_strg(0, "initrd");
      p = cfg_get_strg(*kernel, "image");
      if (p && *p) {
         label = *kernel;
         *kernel = p;

         p = cfg_get_strg(label, "device");
         if (p) {
            cur_dev->device = p;
         }

         p = cfg_get_strg(label, "partition");
         if (p) {
            n = strtol(p, &endp, 10);
            if (endp != p && *endp == 0) {
               env_dev_set_part(cur_dev, n);
            }
         }

         p = cfg_get_strg(label, "initrd");
         if (p) {
            *initrd = p;
         }

         if (cfg_get_strg(label, "old-kernel")) {
            bi->flags |= BOOT_PRE_2_4;
         } else {
            bi->flags &= ~BOOT_PRE_2_4;
         }

         *params = make_params(label, *params);
         if (*params == NULL) {
            return ERR_NO_MEM;
         }
      }
   }

   if (*kernel == NULL) {
      printk("<TAB> for list of bootable images, or !help\n");
      return ERR_NOT_READY;
   }

   /*
    * If we manually entered kernel path, the initrd could
    * be following in the param list...
    */
   if (label == NULL) {
      *params = chomp(*params);

      if (memcmp(*params, "-- ", 3) != 0) {
         *initrd = *params;
         word_split(initrd, params);
      } else {

         /*
          * No initrd, just kernel args.
          */
         *params = *params + 3;
      }
   }

   return ERR_NONE;
}
Esempio n. 12
0
File: main.c Progetto: andreiw/iQUIK
static quik_err_t
load_config(void)
{
   length_t len;
   char *buf;
   char *endp;
   char *p;
   path_t path;
   unsigned n = 0;
   quik_err_t err = ERR_NONE;
   char *attempts[] = {
      bi->config_file,
      "/boot/iquik.conf",
      "/boot/quik.conf",
      "/boot/iquik.conf",
      "/quik.conf",
      NULL
   };

   err = env_dev_is_valid(&bi->default_dev);
   if (err != ERR_NONE) {
      if (err == ERR_ENV_CURRENT_BAD) {
         err = ERR_ENV_DEFAULT_BAD;
      }

      return err;
   }

   path.device = bi->default_dev.device;
   path.part = bi->default_dev.part;
   while (attempts[n] != NULL) {
      path.path = attempts[n];

      printk("Trying configuration file @ '%P'\n", &path);
      err = file_len(&path, &len);
      if (err == ERR_NONE) {
         break;
      }

      n++;
   }

   /* Set by file_len. */
   if (err != ERR_NONE) {
      return ERR_CONFIG_NOT_FOUND;
   }

   buf = malloc(len);
   if (buf == NULL) {
      return ERR_NO_MEM;
   }

   err = file_load(&path, buf);
   if (err != ERR_NONE) {
      printk("\nCouldn't load '%P': %r\n", &path, err);
      free(buf);
      return err;
   }

   if (cfg_parse(bi->config_file, buf, len) < 0) {
      printk ("Syntax error or read error in '%P'\n", &path);
   }

   free(buf);
   bi->flags |= CONFIG_VALID;
   p = cfg_get_strg(0, "init-code");
   if (p) {
      prom_interpret(p);
   }

   p = cfg_get_strg(0, "init-message");
   if (p) {
      printk("%s\n", p);
   }

   if(cfg_get_strg(0, "device") != NULL) {
      bi->default_dev.device = cfg_get_strg(0, "device");
   }

   p = cfg_get_strg(0, "partition");
   if (p) {
      n = strtol(p, &endp, 10);
      if (endp != p && *endp == 0) {
         env_dev_set_part(&bi->default_dev, n);
      }
   }

   p = cfg_get_strg(0, "pause-message");
   if (p) {
      bi->pause_message = p;
   }

   p = cfg_get_strg(0, "message");
   if (p) {
      file_cmd_cat(p);
   }

   return ERR_NONE;
}