122 lines
2.4 KiB
C
122 lines
2.4 KiB
C
// vfs.h
|
|
// Virtual file system subsystem for HOS
|
|
// Author: Josh Holtrop
|
|
// Date: 05/10/05
|
|
// Modified: 12/26/05
|
|
|
|
#ifndef __HOS_VFS_H__
|
|
#define __HOS_VFS_H__ __HOS_VFS_H__
|
|
|
|
#define VFS_FT_UNKNOWN 0
|
|
#define VFS_FT_FILE 1
|
|
#define VFS_FT_DIR 2
|
|
#define VFS_FT_CHAR 3
|
|
#define VFS_FT_BLOCK 4
|
|
#define VFS_FT_FIFO 5
|
|
#define VFS_FT_SOCK 6
|
|
#define VFS_FT_SYMLINK 7
|
|
|
|
#define VFS_PERMS_OX 0x0001
|
|
#define VFS_PERMS_OW 0x0002
|
|
#define VFS_PERMS_OR 0x0004
|
|
#define VFS_PERMS_GX 0x0008
|
|
#define VFS_PERMS_GW 0x0010
|
|
#define VFS_PERMS_GR 0x0020
|
|
#define VFS_PERMS_UX 0x0040
|
|
#define VFS_PERMS_UW 0x0080
|
|
#define VFS_PERMS_UR 0x0100
|
|
#define VFS_PERMS_STICKY 0x0200
|
|
#define VFS_PERMS_SGID 0x0400
|
|
#define VFS_PERMS_SUID 0x0800
|
|
|
|
#define EOF 0x100
|
|
|
|
#define VFS_MAX_FILENAME 255
|
|
|
|
#define SEEK_ABSOLUTE 0
|
|
#define SEEK_RELATIVE 1
|
|
#define SEEK_END 2
|
|
|
|
#include "hos_defines.h"
|
|
#include "devices.h"
|
|
|
|
|
|
typedef struct
|
|
{
|
|
u16_t type; // file type, of VFS_FT_*
|
|
u32_t size;
|
|
u32_t inode;
|
|
u16_t permissions;
|
|
u16_t uid;
|
|
u16_t gid;
|
|
u32_t atime;
|
|
u32_t mtime;
|
|
u32_t ctime;
|
|
u16_t links;
|
|
u32_t dev;
|
|
} vfs_stat_t;
|
|
|
|
typedef struct
|
|
{
|
|
char name[VFS_MAX_FILENAME + 1];
|
|
u32_t inum;
|
|
} vfs_dir_entry_t;
|
|
|
|
typedef struct
|
|
{
|
|
char fs[16];
|
|
char mountPoint[256];
|
|
u32_t totalBlocks;
|
|
u32_t freeBlocks;
|
|
u32_t totalInodes;
|
|
u32_t freeInodes;
|
|
} vfs_mount_info_t;
|
|
|
|
typedef u64_t inode_num_t;
|
|
|
|
#ifdef _HOS_CPP_
|
|
extern "C" {
|
|
#endif
|
|
|
|
int vfs_init();
|
|
int vfs_mount(device_t device, char *fsType, char *mountPoint);
|
|
int vfs_umount(device_t dev);
|
|
int vfs_stat(char *name, vfs_stat_t *buff);
|
|
int vfs_get_mount_info(unsigned int mountNum, vfs_mount_info_t *infoptr);
|
|
void *vfs_open_dir(char *name);
|
|
void *vfs_open_file(char *name);
|
|
void vfs_close_dir(void *o);
|
|
void vfs_close_file(void *o);
|
|
int vfs_read_dir(void *o, vfs_dir_entry_t *dirent);
|
|
int vfs_write_dir(void *o, vfs_dir_entry_t *dirent);
|
|
int vfs_seek_dir(void *o, int pos, int mode);
|
|
int vfs_read_file(void *o);
|
|
int vfs_read_file_block(void *o, void *buf, u32_t num);
|
|
int vfs_write_file(void *o, int chr);
|
|
int vfs_write_file_block(void *o, void *buf, u32_t num);
|
|
int vfs_seek_file(void *o, int pos, int mode);
|
|
|
|
|
|
#ifdef _HOS_CPP_
|
|
}
|
|
|
|
#include "lang/string.h"
|
|
#include "lang/vector.h"
|
|
#include "fs/FileSystem.h"
|
|
#include "fs/VFSMount.h"
|
|
|
|
typedef FileSystem *(*mount_func_t)(device_t);
|
|
|
|
typedef struct
|
|
{
|
|
string name;
|
|
mount_func_t mount_func;
|
|
} FSHandle;
|
|
|
|
int vfs_register(char *fs, mount_func_t mount_func);
|
|
|
|
#endif
|
|
|
|
#endif
|
|
|