1 /* identify.c - Translate label names to kernel paths */
4 Copyright 1992-1998 Werner Almesberger.
5 Copyright 1999-2004 John Coffman.
8 Licensed under the terms contained in the file 'COPYING' in the
26 static char *first, *dflt;
30 static void do_identify(char *var,char type)
32 char *label,*path,*alias,*initrd,*keytab,*appstr,*dtem,*addappstr;
34 int root,image, ramdisk, kt, append;
37 image = !!strchr(opt,'i');
38 ramdisk = !!strchr(opt,'r');
39 kt = !!strchr(opt,'k');
40 append = !!strchr(opt,'a');
41 root = !!strchr(opt,'R');
42 if (opt && !image && !ramdisk && !kt && !append
43 && !idefault && !root) exit(1);
44 /* if (!opt) image = 1; */
47 printf("do_identify: opt=\"%s\"\n", opt);
50 label = strrchr(path = cfg_get_strg(cf_identify,var),'/');
52 if (cfg_get_strg(cf_all,"label")) label = cfg_get_strg(cf_all,"label");
53 else if (!label) label = path;
55 if (!first) first = stralloc(label);
57 alias = cfg_get_strg(cf_all,"alias");
58 dtem = cfg_get_strg(cf_options,"default");
60 if (verbose>=2) printf("identify: dtem=%s label=%s\n", dtem, label);
62 if (dtem && (!strcasecmp(label,dtem) || (alias && !strcasecmp(alias,dtem)))) {
64 if (dtem && (!strcmp(label,dtem) || (alias && !strcmp(alias,dtem)))) {
66 if (verbose>=2) printf("setting dflt\n");
70 initrd = cfg_get_strg(cf_kernel,"initrd");
71 if (!initrd) initrd = cfg_get_strg(cf_options,"initrd");
72 keytab = cfg_get_strg(cf_options,"keytable");
73 if (!keytab) keytab="us.ktl";
74 appstr = cfg_get_strg(cf_kernel,"append");
75 if (!appstr) appstr = cfg_get_strg(cf_options,"append");
76 addappstr = cfg_get_strg(cf_kernel,"addappend");
77 rootstr = cfg_get_strg(cf_kernel,"root");
78 if (!rootstr) rootstr = cfg_get_strg(cf_options,"root");
81 if (!strcasecmp(label,identify) || (alias && !strcasecmp(alias,identify))) {
83 if (!strcmp(label,identify) || (alias && !strcmp(alias,identify))) {
85 if (image) printf("%s\n",path);
86 if (ramdisk) printf("%s\n",initrd?initrd:"No initial ramdisk specified");
87 if (kt) printf("%s\n",keytab);
89 if (!appstr && !addappstr)
90 printf("No append= was specified\n");
91 else if ((appstr && !addappstr) || (!appstr && addappstr))
92 printf("%s\n", appstr?appstr:addappstr);
93 else printf("%s %s\n", appstr, addappstr);
95 if (root) printf("%s\n",rootstr?rootstr:"No root specified");
96 if (idefault) printf("%s\n", dflt ? dflt : first);
105 (void) cfg_parse(cf_image);
106 do_identify("image",'i');
107 cfg_init(cf_identify);
115 curr_drv_map = curr_prt_map = 0;
116 (void) cfg_parse(cf_other);
117 cfg_init(cf_identify);
121 void identify_image(char *label,char *options)
125 if (verbose>=2) printf("identify_image: id='%s' opt='%s'\n", label, options);
126 idefault = !!strchr(opt,'D');
127 if (idefault) identify = "";
128 cfg_init(cf_identify);
129 if (cfg_parse(cf_identify)) cfg_error("Syntax error");
130 if (idefault && first) {
131 printf("%s\n", dflt ? dflt : first);
134 die("No image found for \"%s\"",label);