2005-08-09 18:32:23 +02:00
|
|
|
#ifndef VFS_MOUNT_H__
|
|
|
|
#define VFS_MOUNT_H__
|
|
|
|
|
2006-01-23 21:05:09 +01:00
|
|
|
struct Mount; // must come before vfs_tree.h
|
|
|
|
|
2005-09-27 17:20:56 +02:00
|
|
|
#include "file.h"
|
|
|
|
#include "zip.h"
|
2006-01-23 21:05:09 +01:00
|
|
|
#include "vfs_tree.h"
|
2005-09-27 17:20:56 +02:00
|
|
|
|
2005-08-09 18:32:23 +02:00
|
|
|
extern void mount_init();
|
|
|
|
extern void mount_shutdown();
|
|
|
|
|
|
|
|
|
2005-09-13 01:37:52 +02:00
|
|
|
// If it was possible to forward-declare enums in gcc, this one wouldn't be in
|
|
|
|
// the header. Don't use.
|
|
|
|
enum MountType
|
|
|
|
{
|
|
|
|
// the relative ordering of values expresses efficiency of the sources
|
|
|
|
// (e.g. archives are faster than loose files). mount_should_replace
|
|
|
|
// makes use of this.
|
|
|
|
|
|
|
|
MT_NONE = 0,
|
|
|
|
MT_FILE = 1,
|
|
|
|
MT_ARCHIVE = 2
|
|
|
|
};
|
2005-08-09 18:32:23 +02:00
|
|
|
|
|
|
|
|
|
|
|
struct XIo
|
|
|
|
{
|
|
|
|
enum MountType type; // internal use only
|
|
|
|
union XIoUnion
|
|
|
|
{
|
|
|
|
FileIo fio;
|
2006-01-23 21:05:09 +01:00
|
|
|
AFileIo zio;
|
2005-08-09 18:32:23 +02:00
|
|
|
}
|
|
|
|
u;
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
struct XFile
|
|
|
|
{
|
|
|
|
enum MountType type; // internal use only
|
|
|
|
|
|
|
|
// pointer to VFS file info storage; used to update size/mtime
|
|
|
|
// after a newly written file is closed.
|
|
|
|
TFile* tf;
|
|
|
|
|
|
|
|
union XFileUnion
|
|
|
|
{
|
2006-01-23 21:05:09 +01:00
|
|
|
FileCommon fc;
|
2005-08-09 18:32:23 +02:00
|
|
|
File f;
|
2006-01-23 21:05:09 +01:00
|
|
|
AFile zf;
|
2005-08-09 18:32:23 +02:00
|
|
|
}
|
|
|
|
u;
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
// given a Mount, return the actual location (portable path) of
|
|
|
|
// <V_path>. used by vfs_realpath and VFile_reopen.
|
2006-01-23 21:05:09 +01:00
|
|
|
extern LibError x_realpath(const Mount* m, const char* V_path, char* P_real_path);
|
2005-08-09 18:32:23 +02:00
|
|
|
|
2006-01-23 21:05:09 +01:00
|
|
|
extern LibError x_open(const Mount* m, const char* V_path, int flags, TFile* tf, XFile* xf);
|
2005-12-11 23:23:55 +01:00
|
|
|
extern LibError x_close(XFile* xf);
|
2005-08-09 18:32:23 +02:00
|
|
|
|
2005-12-11 23:23:55 +01:00
|
|
|
extern LibError x_validate(const XFile* xf);
|
2005-10-12 06:35:01 +02:00
|
|
|
|
2005-08-09 18:32:23 +02:00
|
|
|
extern bool x_is_open(const XFile* xf);
|
|
|
|
extern off_t x_size(const XFile* xf);
|
|
|
|
extern uint x_flags(const XFile* xf);
|
|
|
|
extern void x_set_flags(XFile* xf, uint flags);
|
|
|
|
|
2005-12-11 23:23:55 +01:00
|
|
|
extern LibError x_io_issue(XFile* xf, off_t ofs, size_t size, void* buf, XIo* xio);
|
2005-10-12 06:35:01 +02:00
|
|
|
extern int x_io_has_completed(XIo* xio);
|
2005-12-11 23:23:55 +01:00
|
|
|
extern LibError x_io_wait(XIo* xio, void*& p, size_t& size);
|
|
|
|
extern LibError x_io_discard(XIo* xio);
|
|
|
|
extern LibError x_io_validate(const XIo* xio);
|
2005-08-09 18:32:23 +02:00
|
|
|
|
2006-01-23 21:05:09 +01:00
|
|
|
extern ssize_t x_io(XFile* xf, off_t ofs, size_t size, FileIOBuf* pbuf, FileIOCB cb, uintptr_t ctx);
|
|
|
|
|
|
|
|
extern LibError x_map(XFile* xf, void*& p, size_t& size);
|
|
|
|
extern LibError x_unmap(XFile* xf);
|
|
|
|
|
|
|
|
|
2005-08-09 18:32:23 +02:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//
|
|
|
|
// accessor routines that obviate the need to access Mount fields directly:
|
|
|
|
//
|
|
|
|
|
2006-02-25 20:26:00 +01:00
|
|
|
bool mount_should_replace(const Mount* m_old, const Mount* m_new,
|
|
|
|
size_t size_old, size_t size_new, time_t mtime_old, time_t mtime_new);
|
2005-08-09 18:32:23 +02:00
|
|
|
|
|
|
|
extern char mount_get_type(const Mount* m);
|
|
|
|
|
2005-08-13 19:09:57 +02:00
|
|
|
|
|
|
|
|
|
|
|
// stored by vfs_tree in TDir
|
|
|
|
struct RealDir
|
|
|
|
{
|
|
|
|
// if exactly one real directory is mounted into this virtual dir,
|
|
|
|
// this points to its location. used to add files to VFS when writing.
|
|
|
|
//
|
|
|
|
// the Mount is actually in the mount info and is invalid when
|
|
|
|
// that's unmounted, but the VFS would then be rebuilt anyway.
|
|
|
|
//
|
|
|
|
// = 0 if no real dir mounted here; = -1 if more than one.
|
|
|
|
const Mount* m;
|
|
|
|
#ifndef NO_DIR_WATCH
|
|
|
|
intptr_t watch;
|
|
|
|
#endif
|
|
|
|
};
|
|
|
|
|
2005-12-11 23:23:55 +01:00
|
|
|
extern LibError mount_attach_real_dir(RealDir* rd, const char* P_path, const Mount* m, int flags);
|
2005-08-13 19:09:57 +02:00
|
|
|
extern void mount_detach_real_dir(RealDir* rd);
|
|
|
|
|
2005-12-11 23:23:55 +01:00
|
|
|
extern LibError mount_populate(TDir* td, RealDir* rd);
|
2005-08-13 19:09:57 +02:00
|
|
|
|
|
|
|
|
2006-03-07 06:44:34 +01:00
|
|
|
extern void mount_unmount_all(void);
|
|
|
|
|
2005-10-21 20:01:21 +02:00
|
|
|
// rebuild the VFS, i.e. re-mount everything. open files are not affected.
|
|
|
|
// necessary after loose files or directories change, so that the VFS
|
|
|
|
// "notices" the changes and updates file locations. res calls this after
|
|
|
|
// dir_watch reports changes; can also be called from the console after a
|
|
|
|
// rebuild command. there is no provision for updating single VFS dirs -
|
|
|
|
// it's not worth the trouble.
|
2005-12-11 23:23:55 +01:00
|
|
|
extern LibError mount_rebuild();
|
2005-10-21 20:01:21 +02:00
|
|
|
|
|
|
|
// if <path> or its ancestors are mounted,
|
|
|
|
// return a VFS path that accesses it.
|
|
|
|
// used when receiving paths from external code.
|
2005-12-11 23:23:55 +01:00
|
|
|
extern LibError mount_make_vfs_path(const char* P_path, char* V_path);
|
2005-10-21 20:01:21 +02:00
|
|
|
|
2005-08-09 18:32:23 +02:00
|
|
|
#endif // #ifndef VFS_MOUNT_H__
|