xref: /netbsd/sys/arch/hpc/stand/hpcboot/file.h (revision bf9ec67e)
1 /* -*-C++-*-	$NetBSD: file.h,v 1.1 2001/02/09 18:34:36 uch Exp $	*/
2 
3 /*-
4  * Copyright (c) 1996, 2001 The NetBSD Foundation, Inc.
5  * All rights reserved.
6  *
7  * This code is derived from software contributed to The NetBSD Foundation
8  * by Matthias Drochner. and UCHIYAMA Yasushi.
9  *
10  * Redistribution and use in source and binary forms, with or without
11  * modification, are permitted provided that the following conditions
12  * are met:
13  * 1. Redistributions of source code must retain the above copyright
14  *    notice, this list of conditions and the following disclaimer.
15  * 2. Redistributions in binary form must reproduce the above copyright
16  *    notice, this list of conditions and the following disclaimer in the
17  *    documentation and/or other materials provided with the distribution.
18  * 3. All advertising materials mentioning features or use of this software
19  *    must display the following acknowledgement:
20  *        This product includes software developed by the NetBSD
21  *        Foundation, Inc. and its contributors.
22  * 4. Neither the name of The NetBSD Foundation nor the names of its
23  *    contributors may be used to endorse or promote products derived
24  *    from this software without specific prior written permission.
25  *
26  * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
27  * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
28  * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
29  * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
30  * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
31  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
32  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
33  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
34  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
35  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
36  * POSSIBILITY OF SUCH DAMAGE.
37  */
38 
39 #ifndef _HPCBOOT_FILE_H_
40 #define _HPCBOOT_FILE_H_
41 
42 #include <hpcboot.h>
43 
44 class Console;
45 struct z_stream_s;
46 
47 class File {
48 protected:
49 	Console *&_cons;
50 	BOOL _debug;
51 	BOOL _to_ascii(char *, const TCHAR *, size_t);
52 	char _ascii_filename[MAX_PATH];
53 
54 public:
55 	File(Console *&cons) : _cons(cons) { /* NO-OP */ }
56 	virtual ~File() { /* NO-OP */ }
57 	BOOL &setDebug(void) { return _debug; }
58 
59 	virtual BOOL setRoot(TCHAR *) = 0;
60 	virtual BOOL open(const TCHAR *, u_int32_t = OPEN_EXISTING) = 0;
61 	virtual size_t size(void) = 0;
62 	virtual BOOL close(void) = 0;
63 	virtual size_t read(void *, size_t, off_t = -1) = 0;
64 	virtual size_t write(const void *, size_t, off_t = -1) = 0;
65 	virtual BOOL seek(off_t) = 0;
66 };
67 
68 class FileManager : public File {
69 	// GZIP staff
70 #define Z_BUFSIZE	1024
71 private:
72 	enum flags {
73 		ASCII_FLAG  = 0x01, /* bit 0 set: file probably ascii text */
74 		HEAD_CRC    = 0x02, /* bit 1 set: header CRC present */
75 		EXTRA_FIELD = 0x04, /* bit 2 set: extra field present */
76 		ORIG_NAME   = 0x08, /* bit 3 set: original file name present */
77 		COMMENT	    = 0x10, /* bit 4 set: file comment present */
78 		RESERVED    = 0xE0  /* bits 5..7: reserved */
79 	};
80 
81 	struct z_stream_s *_stream;
82 	int _gz_magic[2];
83 	int _z_err;		/* error code for last stream operation */
84 	int _z_eof;		/* set if end of input file */
85 	u_int8_t _inbuf[Z_BUFSIZE];	/* input buffer */
86 	u_int32_t _crc;		/* crc32 of uncompressed data */
87 	BOOL _compressed;
88 
89 	void _reset(void);
90 	int _get_byte(void);
91 	u_int32_t _get_long(void);
92 	void _check_header(void);
93 
94 	off_t _cur_ofs;
95 
96 private:
97 	File *_file;
98 
99 public:
100 	FileManager(Console *&, enum FileOps);
101 	virtual ~FileManager(void);
102 
103 	BOOL setRoot(TCHAR *);
104 	BOOL open(const TCHAR *, u_int32_t);
105 	size_t size(void);
106 	BOOL close(void);
107 	size_t read(void *, size_t, off_t = -1);
108 	size_t write(const void *, size_t, off_t = -1);
109 	BOOL seek(off_t);
110 	size_t _read(void *, size_t);
111 };
112 
113 #endif //_HPCBOOT_FILE_H_
114