orphan
[debian/elilo] / gzip.h
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 #ifndef __GZIP_H__
27 #define __GZIP_H__
28
29 int gunzip_image(memdesc_t *);
30 int gunzip_kernel(fops_fd_t, kdesc_t *);
31
32 /* gzip flag byte */
33 #define ASCII_FLAG   0x01 /* bit 0 set: file probably ASCII text */
34 #define CONTINUATION 0x02 /* bit 1 set: continuation of multi-part gzip file */
35 #define EXTRA_FIELD  0x04 /* bit 2 set: extra field present */
36 #define ORIG_NAME    0x08 /* bit 3 set: original file name present */
37 #define COMMENT      0x10 /* bit 4 set: file comment present */
38 #define ENCRYPTED    0x20 /* bit 5 set: file is encrypted */
39 #define RESERVED     0xC0 /* bit 6,7:   reserved */
40
41 /*
42  * check for valid gzip signature
43  * return:
44  *      0 : valid gzip archive
45  *      -1: invalid gzip archive
46  */
47 static inline int
48 gzip_probe(unsigned char *buf, unsigned long size)
49 {
50     if (size < 4) return -1;
51
52     if (buf[0] != 037 ||
53         ((buf[1] != 0213) && (buf[1] != 0236))) return -1;
54
55     /* We only support method #8, DEFLATED */
56     if (buf[2] != 8) return -1;
57     
58     if ((buf[3] & ENCRYPTED) != 0) return -1;
59
60     if ((buf[3] & CONTINUATION) != 0) return -1;
61
62     if ((buf[3] & RESERVED) != 0) return -1;
63
64     return 0;
65 }
66
67 #endif /* __GZIP_H__ */