aboutsummaryrefslogtreecommitdiffstats
path: root/src/gfile/gfile_fs.h
blob: 5b1f4fdc3cd5e2c39b11b3809054df2d91dbc26d (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
/*
 * This file is subject to the terms of the GFX License. If a copy of
 * the license was not distributed with this file, you can obtain one at:
 *
 *              http://ugfx.org/license.html
 */

/**
 * @file    src/gfile/gfile_fs.h
 * @brief   GFILE file system header.
 *
 */

#ifndef _GFILE_FS_H
#define _GFILE_FS_H

struct GFILE {
	const struct GFILEVMT *	vmt;
	uint16_t				flags;
		#define	GFILEFLG_OPEN			0x0001		// File is open
		#define	GFILEFLG_READ			0x0002		// Read the file
		#define	GFILEFLG_WRITE			0x0004		// Write the file
		#define	GFILEFLG_APPEND			0x0008		// Append on each write
		#define GFILEFLG_BINARY			0x0010		// Treat as a binary file
		#define	GFILEFLG_DELONCLOSE		0x0020		// Delete on close
		#define	GFILEFLG_CANSEEK		0x0040		// Seek operations are valid
		#define GFILEFLG_FAILONBLOCK	0x0080		// Fail on a blocking call
		#define GFILEFLG_MUSTEXIST		0x0100		// On open file must exist
		#define GFILEFLG_MUSTNOTEXIST	0x0200		// On open file must not exist
		#define GFILEFLG_TRUNC			0x0400		// On open truncate the file
	void *					obj;
	long int				pos;
};

struct gfileList {
	const struct GFILEVMT *	vmt;
	gBool					dirs;
};

typedef struct GFILEVMT {
	uint8_t					flags;
		#define GFSFLG_WRITEABLE		0x0001
		#define GFSFLG_CASESENSITIVE	0x0002
		#define GFSFLG_SEEKABLE			0x0004
		#define GFSFLG_FAST				0x0010
		#define GFSFLG_SMALL			0x0020
		#define GFSFLG_TEXTMODES		0x0040
	char					prefix;
	gBool		(*del)		(const char *fname);
	gBool		(*exists)	(const char *fname);
	long int	(*filesize)	(const char *fname);
	gBool		(*ren)		(const char *oldname, const char *newname);
	gBool		(*open)		(GFILE *f, const char *fname);
	void		(*close)	(GFILE *f);
	int			(*read)		(GFILE *f, void *buf, int size);
	int			(*write)	(GFILE *f, const void *buf, int size);
	gBool		(*setpos)	(GFILE *f, long int pos);
	long int	(*getsize)	(GFILE *f);
	gBool		(*eof)		(GFILE *f);
	gBool		(*mount)	(const char *drive);
	gBool		(*unmount)	(const char *drive);
	gBool		(*sync)		(GFILE *f);
	#if GFILE_NEED_FILELISTS
		gfileList *	(*flopen)	(const char *path, gBool dirs);
		const char *(*flread)	(gfileList *pfl);
		void		(*flclose)	(gfileList *pfl);
	#endif
} GFILEVMT;

GFILE *_gfileFindSlot(const char *mode);

#endif //_GFILE_FS_H