// file layer on top of POSIX. // provides streaming support and caching. // // Copyright (c) 2004 Jan Wassenberg // // This file 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 file 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/ #ifndef FILE_H #define FILE_H #include "h_mgr.h" #include "lib.h" struct File { #ifdef PARANOIA u32 magic; #endif // keep offset of flags and size members in sync with struct ZFile! // it is accessed by VFS and must be the same for both (union). // dirty, but necessary because VFile is pushing the HDATA size limit. uint flags; off_t size; u32 fn_hash; void* mapping; uint map_refs; int fd; }; enum { // write-only access; otherwise, read only FILE_WRITE = 0x01, // buffers returned may be read-only (allows some caching optimizations) FILE_MEM_READONLY = 0x02, // don't cache the whole file, e.g. if kept in memory elsewhere anyway. FILE_NO_CACHE = 0x04, // random access hint FILE_RANDOM = 0x08, FILE_NO_AIO = 0x10 }; // keep in sync with zip.cpp and vfs.cpp *_CB_FLAGS! enum FILE_CB_FLAGS { // location LOC_DIR = BIT(0) }; extern int file_make_native_path(const char* path, char* n_path); extern int file_make_portable_path(const char* n_path, char* path); // set current directory to rel_path, relative to the path to the executable, // which is taken from argv0. // // example: executable in "$install_dir/system"; desired root dir is // "$install_dir/data" => rel_path = "../data". // // this is necessary because the current directory is unknown at startup // (e.g. it isn't set when invoked via batch file), and this is the // easiest portable way to find our install directory. // // can only be called once, by design (see source). rel_path is trusted. extern int file_rel_chdir(const char* argv0, const char* rel_path); typedef int(*FileCB)(const char* const name, const uint flags, const ssize_t size, const uintptr_t user); // not recursive - only the files in