orphan
[debian/elilo] / loader.c
1 /*
2  *  Copyright (C) 2001-2003 Hewlett-Packard Co.
3  *      Contributed by Stephane Eranian <eranian@hpl.hp.com>
4  *
5  * This file is part of the ELILO, the EFI Linux boot loader.
6  *
7  *  ELILO is free software; you can redistribute it and/or modify
8  *  it under the terms of the GNU General Public License as published by
9  *  the Free Software Foundation; either version 2, or (at your option)
10  *  any later version.
11  *
12  *  ELILO is distributed in the hope that it will be useful,
13  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
14  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15  *  GNU General Public License for more details.
16  *
17  *  You should have received a copy of the GNU General Public License
18  *  along with ELILO; see the file COPYING.  If not, write to the Free
19  *  Software Foundation, 59 Temple Place - Suite 330, Boston, MA
20  *  02111-1307, USA.
21  *
22  * Please check out the elilo.txt for complete documentation on how
23  * to use this program.
24  */
25
26 #include <efi.h>
27 #include <efilib.h>
28
29 #include "elilo.h"
30 #include "loader.h"
31
32 extern loader_ops_t plain_loader;
33 extern loader_ops_t gzip_loader;
34
35 static loader_ops_t *ldops_list;
36
37 loader_ops_t *
38 loader_probe(CHAR16 *kname)
39 {
40         loader_ops_t *ops;
41         UINTN n = 0;
42
43         for (ops= ldops_list; ops; ops = ops->next) {
44                 n++;
45                 VERB_PRT(3, Print(L"Probing loader: %s\n", ops->ld_name));
46                 if (ops->ld_probe(kname) == 0) {
47                         return ops;
48                 }
49         }
50         if (!n) {
51                 ERR_PRT((L"No loaders registered"));
52         }
53         return NULL;
54 }
55
56 INTN
57 loader_register(loader_ops_t *ldops)
58 {
59         if (ldops == NULL) return -1;
60
61         /* cheap sanity check */
62         if (ldops->next) {
63                 ERR_PRT((L"loader %s is already registered", ldops->ld_name));
64                 return -1;
65         }
66
67         ldops->next = ldops_list;
68         ldops_list  = ldops;
69
70         VERB_PRT(3, Print(L"New loader registered: %s\n", ldops->ld_name));
71
72         return 0;
73 }
74