2004-03-03 00:56:51 +01:00
|
|
|
// Zip archiving on top of ZLib.
|
|
|
|
//
|
|
|
|
// Copyright (c) 2003 Jan Wassenberg
|
|
|
|
//
|
|
|
|
// This program is free software; you can redistribute it and/or
|
|
|
|
// modify it under the terms of the GNU General Public License as
|
|
|
|
// published by the Free Software Foundation; either version 2 of the
|
|
|
|
// License, or (at your option) any later version.
|
|
|
|
//
|
|
|
|
// This program is distributed in the hope that it will be useful, but
|
|
|
|
// WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
|
// General Public License for more details.
|
|
|
|
//
|
|
|
|
// Contact info:
|
|
|
|
// Jan.Wassenberg@stud.uni-karlsruhe.de
|
|
|
|
// http://www.stud.uni-karlsruhe.de/~urkt/
|
|
|
|
|
2004-07-31 13:03:17 +02:00
|
|
|
#ifndef ZIP_H__
|
|
|
|
#define ZIP_H__
|
2004-03-03 00:56:51 +01:00
|
|
|
|
|
|
|
#include "h_mgr.h"
|
2004-08-11 22:21:42 +02:00
|
|
|
#include "file.h" // FileCB for zip_enum
|
2004-03-03 00:56:51 +01:00
|
|
|
|
|
|
|
|
2004-08-11 22:21:42 +02:00
|
|
|
// note: filenames are case-insensitive.
|
2004-03-03 00:56:51 +01:00
|
|
|
|
|
|
|
|
|
|
|
//
|
|
|
|
// archive
|
|
|
|
//
|
|
|
|
|
|
|
|
// open and return a handle to the zip archive indicated by <fn>
|
|
|
|
extern Handle zip_archive_open(const char* fn);
|
|
|
|
|
|
|
|
// close the archive <ha> and set ha to 0
|
|
|
|
extern int zip_archive_close(Handle& ha);
|
|
|
|
|
2004-08-11 22:21:42 +02:00
|
|
|
// for all files in archive <ha>: call <cb>, passing <user>
|
|
|
|
// and the entries's complete path.
|
|
|
|
extern int zip_enum(const Handle ha, const FileCB cb, const uintptr_t user);
|
2004-03-03 00:56:51 +01:00
|
|
|
|
2004-05-06 19:14:30 +02:00
|
|
|
|
2004-03-03 00:56:51 +01:00
|
|
|
//
|
|
|
|
// file
|
|
|
|
//
|
|
|
|
|
|
|
|
struct ZFile
|
|
|
|
{
|
|
|
|
#ifdef PARANOIA
|
|
|
|
u32 magic;
|
|
|
|
#endif
|
|
|
|
|
2004-08-11 22:21:42 +02:00
|
|
|
// keep offset of flags and size members in sync with struct File!
|
2004-03-05 17:23:31 +01:00
|
|
|
// it is accessed by VFS and must be the same for both (union).
|
|
|
|
// dirty, but necessary because VFile is pushing the HDATA size limit.
|
2004-06-03 02:17:24 +02:00
|
|
|
uint flags;
|
2004-03-03 00:56:51 +01:00
|
|
|
size_t ucsize;
|
2004-03-05 17:23:31 +01:00
|
|
|
// size of logical file
|
2004-03-03 00:56:51 +01:00
|
|
|
|
2004-06-02 22:41:05 +02:00
|
|
|
off_t ofs;
|
|
|
|
off_t csize;
|
|
|
|
off_t last_raw_ofs;
|
2004-03-03 00:56:51 +01:00
|
|
|
|
|
|
|
Handle ha;
|
2004-08-11 22:21:42 +02:00
|
|
|
uintptr_t inf_ctx;
|
2004-03-03 00:56:51 +01:00
|
|
|
};
|
|
|
|
|
2004-08-11 22:21:42 +02:00
|
|
|
// return file information for <fn> in archive <ha>
|
2004-03-03 00:56:51 +01:00
|
|
|
extern int zip_stat(Handle ha, const char* fn, struct stat* s);
|
|
|
|
|
|
|
|
// open the file <fn> in archive <ha>, and fill *zf with information about it.
|
|
|
|
extern int zip_open(Handle ha, const char* fn, ZFile* zf);
|
|
|
|
|
|
|
|
// close the file <zf>
|
|
|
|
extern int zip_close(ZFile* zf);
|
|
|
|
|
|
|
|
|
2004-06-03 02:17:24 +02:00
|
|
|
//
|
|
|
|
// memory mapping
|
|
|
|
//
|
|
|
|
|
|
|
|
// map the entire file <zf> into memory. mapping compressed files
|
|
|
|
// isn't allowed, since the compression algorithm is unspecified.
|
|
|
|
// output parameters are zeroed on failure.
|
|
|
|
//
|
|
|
|
// the mapping will be removed (if still open) when its archive is closed.
|
|
|
|
// however, map/unmap calls should still be paired so that the archive mapping
|
|
|
|
// may be removed when no longer needed.
|
2004-03-03 00:56:51 +01:00
|
|
|
extern int zip_map(ZFile* zf, void*& p, size_t& size);
|
2004-06-03 02:17:24 +02:00
|
|
|
|
|
|
|
// remove the mapping of file <zf>; fail if not mapped.
|
|
|
|
//
|
|
|
|
// the mapping will be removed (if still open) when its archive is closed.
|
|
|
|
// however, map/unmap calls should be paired so that the archive mapping
|
|
|
|
// may be removed when no longer needed.
|
2004-06-02 22:41:05 +02:00
|
|
|
extern int zip_unmap(ZFile* zf);
|
2004-03-03 00:56:51 +01:00
|
|
|
|
2004-07-31 13:03:17 +02:00
|
|
|
|
|
|
|
//
|
|
|
|
// asynchronous read
|
|
|
|
//
|
|
|
|
|
|
|
|
// currently only supported for compressed files to keep things simple.
|
|
|
|
// see rationale in source.
|
|
|
|
|
|
|
|
// begin transferring <size> bytes, starting at <ofs>. get result
|
|
|
|
// with zip_wait_io; when no longer needed, free via zip_discard_io.
|
|
|
|
extern Handle zip_start_io(ZFile* const zf, off_t ofs, size_t size, void* buf);
|
|
|
|
|
|
|
|
// wait until the transfer <hio> completes, and return its buffer.
|
|
|
|
// output parameters are zeroed on error.
|
|
|
|
extern int zip_wait_io(Handle hio, void*& p, size_t& size);
|
|
|
|
|
|
|
|
// finished with transfer <hio> - free its buffer (returned by vfs_wait_io)
|
|
|
|
extern int zip_discard_io(Handle& hio);
|
|
|
|
|
|
|
|
|
|
|
|
//
|
|
|
|
// synchronous read
|
|
|
|
//
|
|
|
|
|
2004-06-03 02:17:24 +02:00
|
|
|
// read from file <zf>, starting at offset <ofs> in the compressed data.
|
2004-07-09 04:14:21 +02:00
|
|
|
extern ssize_t zip_read(ZFile* zf, off_t ofs, size_t size, void** p);
|
2004-03-03 00:56:51 +01:00
|
|
|
|
|
|
|
|
2004-07-31 13:03:17 +02:00
|
|
|
#endif // #ifndef ZIP_H__
|