2014-12-03 08:39:06 +00:00
|
|
|
/* Copyright (c) 2013-2014 Jeffrey Pfau
|
|
|
|
*
|
|
|
|
* This Source Code Form is subject to the terms of the Mozilla Public
|
|
|
|
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
|
|
|
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
2014-07-17 06:55:09 +00:00
|
|
|
#ifndef VFS_H
|
|
|
|
#define VFS_H
|
2014-07-16 08:31:10 +00:00
|
|
|
|
2016-12-31 01:00:22 +00:00
|
|
|
#include <mgba-util/common.h>
|
2014-07-16 08:31:10 +00:00
|
|
|
|
2016-12-27 05:01:55 +00:00
|
|
|
CXX_GUARD_START
|
|
|
|
|
2015-06-10 04:22:11 +00:00
|
|
|
#ifdef _WIN32
|
2015-04-02 04:13:16 +00:00
|
|
|
#include <io.h>
|
|
|
|
#include <windows.h>
|
2016-01-07 05:05:05 +00:00
|
|
|
#define PATH_SEP "/" // Windows can handle slashes, and backslashes confuse some libraries
|
2015-06-10 04:22:11 +00:00
|
|
|
#else
|
|
|
|
#define PATH_SEP "/"
|
2015-04-02 04:13:16 +00:00
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifndef PATH_MAX
|
|
|
|
#ifdef MAX_PATH
|
|
|
|
#define PATH_MAX MAX_PATH
|
|
|
|
#else
|
|
|
|
#define PATH_MAX 128
|
|
|
|
#endif
|
|
|
|
#endif
|
|
|
|
|
2014-07-20 08:36:18 +00:00
|
|
|
enum {
|
|
|
|
MAP_READ = 1,
|
|
|
|
MAP_WRITE = 2
|
|
|
|
};
|
2014-07-16 09:08:54 +00:00
|
|
|
|
2015-08-26 05:41:47 +00:00
|
|
|
enum VFSType {
|
|
|
|
VFS_UNKNOWN = 0,
|
|
|
|
VFS_FILE,
|
|
|
|
VFS_DIRECTORY
|
|
|
|
};
|
|
|
|
|
2014-07-16 08:31:10 +00:00
|
|
|
struct VFile {
|
|
|
|
bool (*close)(struct VFile* vf);
|
2014-07-16 10:02:16 +00:00
|
|
|
off_t (*seek)(struct VFile* vf, off_t offset, int whence);
|
|
|
|
ssize_t (*read)(struct VFile* vf, void* buffer, size_t size);
|
|
|
|
ssize_t (*readline)(struct VFile* vf, char* buffer, size_t size);
|
2014-10-14 10:08:39 +00:00
|
|
|
ssize_t (*write)(struct VFile* vf, const void* buffer, size_t size);
|
2014-07-16 09:08:54 +00:00
|
|
|
void* (*map)(struct VFile* vf, size_t size, int flags);
|
|
|
|
void (*unmap)(struct VFile* vf, void* memory, size_t size);
|
|
|
|
void (*truncate)(struct VFile* vf, size_t size);
|
2015-01-11 08:35:22 +00:00
|
|
|
ssize_t (*size)(struct VFile* vf);
|
2015-07-07 07:26:31 +00:00
|
|
|
bool (*sync)(struct VFile* vf, const void* buffer, size_t size);
|
2014-07-16 08:31:10 +00:00
|
|
|
};
|
|
|
|
|
2014-07-17 06:55:09 +00:00
|
|
|
struct VDirEntry {
|
|
|
|
const char* (*name)(struct VDirEntry* vde);
|
2015-08-26 05:41:47 +00:00
|
|
|
enum VFSType (*type)(struct VDirEntry* vde);
|
2014-07-17 06:55:09 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
struct VDir {
|
|
|
|
bool (*close)(struct VDir* vd);
|
2014-07-17 07:53:17 +00:00
|
|
|
void (*rewind)(struct VDir* vd);
|
2014-07-17 06:55:09 +00:00
|
|
|
struct VDirEntry* (*listNext)(struct VDir* vd);
|
|
|
|
struct VFile* (*openFile)(struct VDir* vd, const char* name, int mode);
|
2015-09-23 04:19:55 +00:00
|
|
|
struct VDir* (*openDir)(struct VDir* vd, const char* name);
|
2016-02-01 05:59:16 +00:00
|
|
|
bool (*deleteFile)(struct VDir* vd, const char* name);
|
2014-07-17 06:55:09 +00:00
|
|
|
};
|
|
|
|
|
2014-07-16 08:31:10 +00:00
|
|
|
struct VFile* VFileOpen(const char* path, int flags);
|
2015-06-20 10:11:11 +00:00
|
|
|
|
|
|
|
struct VFile* VFileOpenFD(const char* path, int flags);
|
2014-07-16 08:31:10 +00:00
|
|
|
struct VFile* VFileFromFD(int fd);
|
2016-10-14 22:30:40 +00:00
|
|
|
|
2015-03-06 02:44:28 +00:00
|
|
|
struct VFile* VFileFromMemory(void* mem, size_t size);
|
2016-01-03 01:07:44 +00:00
|
|
|
struct VFile* VFileFromConstMemory(const void* mem, size_t size);
|
|
|
|
struct VFile* VFileMemChunk(const void* mem, size_t size);
|
2014-07-16 08:31:10 +00:00
|
|
|
|
2014-07-17 06:55:09 +00:00
|
|
|
struct VDir* VDirOpen(const char* path);
|
2015-09-23 04:18:46 +00:00
|
|
|
struct VDir* VDirOpenArchive(const char* path);
|
2014-07-17 06:55:09 +00:00
|
|
|
|
2015-12-29 09:32:25 +00:00
|
|
|
#if defined(USE_LIBZIP) || defined(USE_ZLIB)
|
2014-07-17 09:45:17 +00:00
|
|
|
struct VDir* VDirOpenZip(const char* path, int flags);
|
|
|
|
#endif
|
|
|
|
|
2015-03-11 09:17:45 +00:00
|
|
|
#ifdef USE_LZMA
|
2015-01-25 08:11:05 +00:00
|
|
|
struct VDir* VDirOpen7z(const char* path, int flags);
|
|
|
|
#endif
|
|
|
|
|
2016-12-31 01:00:22 +00:00
|
|
|
#if defined(__wii__) || defined(_3DS)
|
2017-01-12 06:22:44 +00:00
|
|
|
struct VDir* VDeviceList(void);
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifdef USE_VFS_FILE
|
2016-10-14 22:30:40 +00:00
|
|
|
struct VFile* VFileFOpen(const char* path, const char* mode);
|
|
|
|
struct VFile* VFileFromFILE(FILE* file);
|
|
|
|
#endif
|
2015-12-19 06:18:52 +00:00
|
|
|
|
2015-12-31 05:21:02 +00:00
|
|
|
void separatePath(const char* path, char* dirname, char* basename, char* extension);
|
|
|
|
|
|
|
|
struct VFile* VDirFindFirst(struct VDir* dir, bool (*filter)(struct VFile*));
|
|
|
|
struct VFile* VDirFindNextAvailable(struct VDir*, const char* basename, const char* infix, const char* suffix, int mode);
|
2014-10-10 06:55:02 +00:00
|
|
|
|
2015-03-06 02:40:33 +00:00
|
|
|
ssize_t VFileReadline(struct VFile* vf, char* buffer, size_t size);
|
|
|
|
|
2015-05-29 05:57:01 +00:00
|
|
|
ssize_t VFileWrite32LE(struct VFile* vf, int32_t word);
|
|
|
|
ssize_t VFileWrite16LE(struct VFile* vf, int16_t hword);
|
|
|
|
ssize_t VFileRead32LE(struct VFile* vf, void* word);
|
|
|
|
ssize_t VFileRead16LE(struct VFile* vf, void* hword);
|
|
|
|
|
2016-12-27 05:01:55 +00:00
|
|
|
CXX_GUARD_END
|
|
|
|
|
2014-07-16 08:31:10 +00:00
|
|
|
#endif
|