2005-03-27 19:27:49 +02:00
|
|
|
// virtual file system: tree of files and directories
|
|
|
|
//
|
|
|
|
// Copyright (c) 2005 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/
|
|
|
|
|
|
|
|
#ifndef VFS_TREE_H__
|
|
|
|
#define VFS_TREE_H__
|
|
|
|
|
|
|
|
#include "vfs.h" // vfsDirEnt
|
|
|
|
|
2005-03-27 03:46:54 +02:00
|
|
|
struct TMountPoint;
|
|
|
|
|
|
|
|
class TDir;
|
|
|
|
|
|
|
|
struct TFile
|
|
|
|
{
|
|
|
|
// required:
|
|
|
|
const TMountPoint* mount_point;
|
|
|
|
// allocated and owned by caller (mount code)
|
|
|
|
|
|
|
|
time_t mtime;
|
|
|
|
off_t size;
|
|
|
|
|
|
|
|
// these can also be extracted from TMountPoint,
|
|
|
|
// but better cache coherency when accessing them here.
|
|
|
|
u32 pri : 16;
|
|
|
|
u32 in_archive : 1;
|
|
|
|
|
|
|
|
// note: this is basically the constructor (C++ can't call it directly
|
|
|
|
// since this object is stored in a union)
|
|
|
|
void init()
|
|
|
|
{
|
|
|
|
mount_point = 0;
|
|
|
|
mtime = 0;
|
|
|
|
size = 0;
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
enum TreeLookupFlags
|
|
|
|
{
|
|
|
|
LF_CREATE_MISSING = 1,
|
|
|
|
LF_START_DIR = 2
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
extern void tree_init();
|
|
|
|
extern void tree_clear();
|
|
|
|
extern void tree_display();
|
|
|
|
|
|
|
|
extern TFile* tree_add_file(TDir* dir, const char* name);
|
2005-03-27 19:27:49 +02:00
|
|
|
extern TDir * tree_add_dir (TDir* dir, const char* name);
|
|
|
|
|
|
|
|
extern int tree_mount(TDir* dir, const char* path, const TMountPoint*, bool watch = true);
|
2005-03-27 03:46:54 +02:00
|
|
|
|
|
|
|
|
|
|
|
// starting at VFS root, traverse <path> and pass back information
|
|
|
|
// for its last directory component.
|
|
|
|
//
|
|
|
|
// if <flags> & LF_CREATE_MISSING, all missing subdirectory components are
|
|
|
|
// added to the VFS.
|
|
|
|
// if <flags> & LF_START_DIR, traversal starts at *pdir
|
|
|
|
// (used when looking up paths relative to a mount point).
|
|
|
|
// if <exact_path> != 0, it receives a copy of <path> with the exact
|
|
|
|
// case of each component as returned by the OS (useful for calling
|
|
|
|
// external case-sensitive code). must hold at least VFS_MAX_PATH chars.
|
|
|
|
//
|
|
|
|
// <path> can be to a file or dir (in which case it must end in '/',
|
|
|
|
// to make sure the last component is treated as a directory).
|
|
|
|
//
|
|
|
|
// return 0 on success, or a negative error code
|
|
|
|
// (in which case output params are undefined).
|
|
|
|
extern int tree_lookup_dir(const char* path, TDir** pdir, uint flags = 0, char* exact_path = 0);
|
|
|
|
|
|
|
|
|
|
|
|
// pass back file information for <path> (relative to VFS root).
|
|
|
|
//
|
|
|
|
// if <flags> & LF_CREATE_MISSING, the file is added to VFS unless
|
|
|
|
// a higher-priority file of the same name already exists
|
|
|
|
// (used by VFile_reload when opening for writing).
|
|
|
|
// if <exact_path> != 0, it receives a copy of <path> with the exact
|
|
|
|
// case of each component as returned by the OS (useful for calling
|
|
|
|
// external case-sensitive code). must hold at least VFS_MAX_PATH chars.
|
|
|
|
//
|
|
|
|
// return 0 on success, or a negative error code
|
|
|
|
// (in which case output params are undefined).
|
|
|
|
extern int tree_lookup(const char* path, TFile** pfile, uint flags = 0, char* exact_path = 0);
|
|
|
|
|
|
|
|
extern int tree_open_dir(const char* path_slash, void** latch);
|
2005-03-27 19:27:49 +02:00
|
|
|
extern int tree_next_dirent(void* latch_, const char* filter, vfsDirEnt* dirent);
|
2005-03-27 03:46:54 +02:00
|
|
|
extern int tree_close_dir(void* latch_);
|
2005-03-27 19:27:49 +02:00
|
|
|
|
|
|
|
#endif // #ifndef VFS_TREE_H__
|