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