summaryrefslogtreecommitdiff
path: root/src/libs/uio/fstypes.h
blob: 3ff01a2c4abb29606b5fb8b9e1888c79b14bfe90 (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
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
/*
 * Copyright (C) 2003  Serge van den Boom
 *
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of version 2 of the GNU General Public License as
 * published by the Free Software Foundation.
 * Nota bene: later versions of the GNU General Public License do not apply
 * to this program.
 *
 * 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.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
 *
 */

#ifndef LIBS_UIO_FSTYPES_H_
#define LIBS_UIO_FSTYPES_H_

typedef int uio_FileSystemID;
#define uio_FSTYPE_STDIO 1
#define uio_FSTYPE_ZIP   2


#ifdef uio_INTERNAL

#define uio_FS_FIRST_CUSTOM_ID 0x10

#ifndef uio_INTERNAL_PHYSICAL
typedef void *uio_NativeHandle;
#endif

// 'forward' declarations
typedef struct uio_FileSystemHandler uio_FileSystemHandler;
typedef struct uio_FileSystemInfo uio_FileSystemInfo;

#include <sys/stat.h>
#include <sys/types.h>
#include "physical.h"
#include "uioport.h"


/* Structure describing how to access files _in_ a directory of a certain
 * type (not files _of_ a certain type.) Except for mount().
 * in open(), the first arg points to the dir where the file should be
 * in, and the second arg is the name of that file (no path)
 */
struct uio_FileSystemHandler {
	int               (*init)     (void);
	int               (*unInit)   (void);
	void              (*cleanup)  (uio_PRoot *, int);
			// Called to cleanup memory. The second argument specifies
			// how thoroughly.

	struct uio_PRoot * (*mount)    (uio_Handle *, int);
	int               (*umount)   (uio_PRoot *);

	int               (*access)   (uio_PDirHandle *, const char *, int mode);
	void              (*close)    (uio_Handle *);
			// called when the last reference is closed, not
			// necessarilly each time when uio_close() is called
	int               (*fstat)    (uio_Handle *, struct stat *);
	int               (*stat)     (uio_PDirHandle *, const char *,
			struct stat *);
	uio_PDirHandle *  (*mkdir)    (uio_PDirHandle *, const char *, mode_t);
	uio_Handle *      (*open)     (uio_PDirHandle *, const char *, int,
			mode_t);
	ssize_t           (*read)     (uio_Handle *, void *, size_t);
	int               (*rename)   (uio_PDirHandle *, const char *,
			uio_PDirHandle *, const char *);
	int               (*rmdir)    (uio_PDirHandle *, const char *);
	off_t             (*seek)     (uio_Handle *, off_t, int);
	ssize_t           (*write)    (uio_Handle *, const void *, size_t);
	int               (*unlink)   (uio_PDirHandle *, const char *);

	uio_NativeEntriesContext (*openEntries) (uio_PDirHandle *);
	int               (*readEntries) (uio_NativeEntriesContext *, char *,
			size_t);
	void              (*closeEntries) (uio_NativeEntriesContext);

	uio_PDirEntryHandle * (*getPDirEntryHandle) (
			const uio_PDirHandle *, const char *);
	void              (*deletePRootExtra) (uio_PRootExtra pRootExtra);
	void              (*deletePDirHandleExtra) (
			uio_PDirHandleExtra pDirHandleExtra);
	void              (*deletePFileHandleExtra) (
			uio_PFileHandleExtra pFileHandleExtra);
};

struct uio_FileSystemInfo {
	int ref;
	uio_FileSystemID id;
	char *name;  // name of the file system
	uio_FileSystemHandler *handler;
	struct uio_FileSystemInfo *next;
};

void uio_registerDefaultFileSystems(void);
void uio_unRegisterDefaultFileSystems(void);
uio_FileSystemID uio_registerFileSystem(uio_FileSystemID wantedID,
		 const char *name, uio_FileSystemHandler *handler);
int uio_unRegisterFileSystem(uio_FileSystemID id);
uio_FileSystemHandler *uio_getFileSystemHandler(uio_FileSystemID id);
uio_FileSystemInfo *uio_getFileSystemInfo(uio_FileSystemID id);

#endif  /* uio_INTERNAL */

#endif  /* LIBS_UIO_FSTYPES_H_ */