Beispiel #1
0
void md_run(int argc, char *argv[])
{
	char **pp, *p;

	for (pp = argv; (p = *pp); pp++) {
		if (!strncmp(p, "raid=", 5))
			raid_setup(p + 5);
		else if (!strncmp(p, "md=", 3))
			md_setup(p + 3);
	}

	md_run_setup();
}
Beispiel #2
0
	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;
	}