don't double patch!
[debian/elilo] / x86_64 / gzip_loader.c
1 /*
2  *  Copyright (C) 2001-2002 Hewlett-Packard Co.
3  *      Contributed by Stephane Eranian <eranian@hpl.hp.com>
4  *  Copyright (C) 2006-2009 Intel Corporation
5  *      Contributed by Fenghua Yu <fenghua.yu@intel.com>
6  *      Contributed by Bibo Mao <bibo.mao@intel.com>
7  *      Contributed by Chandramouli Narayanan <mouli@linux.intel.com>
8  *
9  * This file is part of the ELILO, the EFI Linux boot loader.
10  *
11  *  ELILO is free software; you can redistribute it and/or modify
12  *  it under the terms of the GNU General Public License as published by
13  *  the Free Software Foundation; either version 2, or (at your option)
14  *  any later version.
15  *
16  *  ELILO is distributed in the hope that it will be useful,
17  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
18  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
19  *  GNU General Public License for more details.
20  *
21  *  You should have received a copy of the GNU General Public License
22  *  along with ELILO; see the file COPYING.  If not, write to the Free
23  *  Software Foundation, 59 Temple Place - Suite 330, Boston, MA
24  *  02111-1307, USA.
25  *
26  * Please check out the elilo.txt for complete documentation on how
27  * to use this program.
28  */
29
30 #include <efi.h>
31 #include <efilib.h>
32
33 #include "elilo.h"
34 #include "loader.h"
35 #include "gzip.h"
36
37 static INTN
38 gzip_probe_format(CHAR16 *kname)
39 {
40         UINT8 buf[4];
41         EFI_STATUS status;
42         INTN ret = -1;
43         UINTN size;
44         fops_fd_t fd;
45
46         status = fops_open(kname, &fd);
47         if (EFI_ERROR(status)) return -1;
48
49         size = sizeof(buf);
50         status = fops_read(fd, buf, &size);
51
52         if (EFI_ERROR(status) || size != sizeof(buf)) goto error;
53
54         ret = gzip_probe(buf, sizeof(buf));
55 error:
56         fops_close(fd);
57         return ret;
58 }
59
60
61 static INTN
62 gzip_load_kernel(CHAR16 *kname, kdesc_t *kd)
63 {
64         EFI_STATUS status;
65         INT32 ret;
66         fops_fd_t fd;
67
68         status = fops_open(kname, &fd);
69         if (EFI_ERROR(status)) return ELILO_LOAD_ERROR;
70
71         ret = gunzip_kernel(fd, kd);
72        
73         fops_close(fd);
74
75         return ret; /* could be success, error, or abort */
76 }
77
78 loader_ops_t gzip_loader={
79         NULL,
80         LD_NAME,
81         gzip_probe_format,
82         gzip_load_kernel
83 };