1 /* identify.c - Translate label names to kernel paths
3 * Copyright 1992-1998 Werner Almesberger
4 * Copyright 1999-2004 John Coffman
5 * Copyright 2009-2011 Joachim Wiedorn
8 * Licensed under the terms contained in the file 'COPYING'
9 * in the source directory.
24 static char *first, *dflt;
28 static void do_identify(char *var,char type)
30 char *label,*path,*alias,*initrd,*keytab,*appstr,*dtem,*addappstr;
32 int root,image, ramdisk, kt, append;
35 image = !!strchr(opt,'i');
36 ramdisk = !!strchr(opt,'r');
37 kt = !!strchr(opt,'k');
38 append = !!strchr(opt,'a');
39 root = !!strchr(opt,'R');
40 if (opt && !image && !ramdisk && !kt && !append
41 && !idefault && !root) exit(1);
42 /* if (!opt) image = 1; */
45 printf("do_identify: opt=\"%s\"\n", opt);
48 label = strrchr(path = cfg_get_strg(cf_identify,var),'/');
50 if (cfg_get_strg(cf_all,"label")) label = cfg_get_strg(cf_all,"label");
51 else if (!label) label = path;
53 if (!first) first = stralloc(label);
55 alias = cfg_get_strg(cf_all,"alias");
56 dtem = cfg_get_strg(cf_options,"default");
58 if (verbose>=2) printf("identify: dtem=%s label=%s\n", dtem, label);
60 if (dtem && (!strcasecmp(label,dtem) || (alias && !strcasecmp(alias,dtem)))) {
62 if (dtem && (!strcmp(label,dtem) || (alias && !strcmp(alias,dtem)))) {
64 if (verbose>=2) printf("setting dflt\n");
68 initrd = cfg_get_strg(cf_kernel,"initrd");
69 if (!initrd) initrd = cfg_get_strg(cf_options,"initrd");
70 keytab = cfg_get_strg(cf_options,"keytable");
71 if (!keytab) keytab="us.ktl";
72 appstr = cfg_get_strg(cf_kernel,"append");
73 if (!appstr) appstr = cfg_get_strg(cf_options,"append");
74 addappstr = cfg_get_strg(cf_kernel,"addappend");
75 rootstr = cfg_get_strg(cf_kernel,"root");
76 if (!rootstr) rootstr = cfg_get_strg(cf_options,"root");
79 if (!strcasecmp(label,identify) || (alias && !strcasecmp(alias,identify))) {
81 if (!strcmp(label,identify) || (alias && !strcmp(alias,identify))) {
83 if (image) printf("%s\n",path);
84 if (ramdisk) printf("%s\n",initrd?initrd:"No initial ramdisk specified");
85 if (kt) printf("%s\n",keytab);
87 if (!appstr && !addappstr)
88 printf("No append= was specified\n");
89 else if ((appstr && !addappstr) || (!appstr && addappstr))
90 printf("%s\n", appstr?appstr:addappstr);
91 else printf("%s %s\n", appstr, addappstr);
93 if (root) printf("%s\n",rootstr?rootstr:"No root specified");
94 if (idefault) printf("%s\n", dflt ? dflt : first);
103 (void) cfg_parse(cf_image);
104 do_identify("image",'i');
105 cfg_init(cf_identify);
113 curr_drv_map = curr_prt_map = 0;
114 (void) cfg_parse(cf_other);
115 cfg_init(cf_identify);
119 void identify_image(char *label,char *options)
123 if (verbose>=2) printf("identify_image: id='%s' opt='%s'\n", label, options);
124 idefault = !!strchr(opt,'D');
125 if (idefault) identify = "";
126 cfg_init(cf_identify);
127 if (cfg_parse(cf_identify)) cfg_error("Syntax error");
128 if (idefault && first) {
129 printf("%s\n", dflt ? dflt : first);
132 die("No image found for \"%s\"",label);