No empty .Rs/.Re
[netbsd-mini2440.git] / sys / arch / hpc / stand / hpcboot / file.h
blob6de180212f2fca8299e96ef7822d6ecae3287201
1 /* -*-C++-*- $NetBSD: file.h,v 1.5 2006/03/05 04:05:39 uwe Exp $ */
3 /*-
4 * Copyright (c) 1996, 2001 The NetBSD Foundation, Inc.
5 * All rights reserved.
7 * This code is derived from software contributed to The NetBSD Foundation
8 * by Matthias Drochner. and UCHIYAMA Yasushi.
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.
19 * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
20 * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
21 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
22 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
23 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
24 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
25 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
26 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
27 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
28 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
29 * POSSIBILITY OF SUCH DAMAGE.
32 #ifndef _HPCBOOT_FILE_H_
33 #define _HPCBOOT_FILE_H_
35 #include <hpcboot.h>
37 class Console;
38 struct z_stream_s;
40 class File {
41 protected:
42 Console *&_cons;
43 BOOL _debug;
44 BOOL _to_ascii(char *, const TCHAR *, size_t);
45 char _ascii_filename[MAX_PATH];
47 public:
48 File(Console *&cons) : _cons(cons) { /* NO-OP */ }
49 virtual ~File() { /* NO-OP */ }
50 BOOL &setDebug(void) { return _debug; }
52 virtual BOOL setRoot(TCHAR *) = 0;
53 virtual BOOL open(const TCHAR *, uint32_t = OPEN_EXISTING) = 0;
54 virtual size_t size(void) = 0;
55 virtual size_t realsize(void) { return size(); };
56 virtual BOOL close(void) = 0;
57 virtual size_t read(void *, size_t, off_t = -1) = 0;
58 virtual size_t write(const void *, size_t, off_t = -1) = 0;
59 virtual BOOL seek(off_t) = 0;
62 class FileManager : public File {
63 // GZIP staff
64 #define Z_BUFSIZE 1024
65 private:
66 enum flags {
67 ASCII_FLAG = 0x01, /* bit 0 set: file probably ascii text */
68 HEAD_CRC = 0x02, /* bit 1 set: header CRC present */
69 EXTRA_FIELD = 0x04, /* bit 2 set: extra field present */
70 ORIG_NAME = 0x08, /* bit 3 set: original file name present */
71 COMMENT = 0x10, /* bit 4 set: file comment present */
72 RESERVED = 0xE0 /* bits 5..7: reserved */
75 struct z_stream_s *_stream;
76 int _gz_magic[2];
77 int _z_err; /* error code for last stream operation */
78 int _z_eof; /* set if end of input file */
79 uint8_t _inbuf[Z_BUFSIZE]; /* input buffer */
80 uint32_t _crc; /* crc32 of uncompressed data */
81 BOOL _compressed;
83 void _reset(void);
84 int _get_byte(void);
85 uint32_t _get_long(void);
86 void _check_header(void);
87 size_t _skip_compressed(off_t);
89 off_t _cur_ofs;
91 private:
92 File *_file;
94 public:
95 FileManager(Console *&, enum FileOps);
96 virtual ~FileManager(void);
98 BOOL setRoot(TCHAR *);
99 BOOL open(const TCHAR *, uint32_t);
100 size_t size(void);
101 size_t realsize(void);
102 BOOL close(void);
103 size_t read(void *, size_t, off_t = -1);
104 size_t write(const void *, size_t, off_t = -1);
105 BOOL seek(off_t);
106 size_t _read(void *, size_t);
109 #endif //_HPCBOOT_FILE_H_