fileops.c 3.17 KB
Newer Older
1
2
3
4
5
6
7
8
9
10
/**
 * Implemention of the epicardium epic_file_ api that operates on
 * the global EpicFileSystem instance
 *
 * All functions lock & unlock the global FS object
 *
 */

#include "fs/internal.h"

11
12
13
14
15
16
17
18
19
20
#if defined(__GNUC__) &&                                                       \
	((__GNUC__ > 4) || (__GNUC__ == 4 && __GNUC_MINOR__ >= 6))
#define HAVE_STATIC_ASSERT 1
#elif defined(__clang__)
#define HAVE_STATIC_ASSERT 1
#endif
#if HAVE_STATIC_ASSERT
_Static_assert(sizeof(struct epic_stat) == 276, "");
#endif

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
int epic_file_open(const char *filename, const char *mode)
{
	EpicFileSystem *fs;
	int res = efs_lock_global(&fs);
	if (res == 0) {
		res = efs_open(fs, filename, mode);
		efs_unlock_global(fs);
	}
	return res;
}

int epic_file_close(int fd)
{
	EpicFileSystem *fs;
	int res = efs_lock_global(&fs);
	if (res == 0) {
		res = efs_close(fs, fd);
		efs_unlock_global(fs);
	}
	return res;
}

int epic_file_read(int fd, void *buf, size_t nbytes)
{
	EpicFileSystem *fs;
	int res = efs_lock_global(&fs);
	if (res == 0) {
		res = efs_read(fs, fd, buf, nbytes);
		efs_unlock_global(fs);
	}
	return res;
}

int epic_file_write(int fd, const void *buf, size_t nbytes)
{
	EpicFileSystem *fs;
	int res = efs_lock_global(&fs);
	if (res == 0) {
		res = efs_write(fs, fd, buf, nbytes);
		efs_unlock_global(fs);
	}
	return res;
}

int epic_file_flush(int fd)
{
	EpicFileSystem *fs;
	int res = efs_lock_global(&fs);
	if (res == 0) {
		res = efs_flush(fs, fd);
		efs_unlock_global(fs);
	}
	return res;
}

int epic_file_seek(int fd, long offset, int whence)
{
	EpicFileSystem *fs;
	int res = efs_lock_global(&fs);
	if (res == 0) {
		res = efs_seek(fs, fd, offset, whence);
		efs_unlock_global(fs);
	}
	return res;
}

int epic_file_tell(int fd)
{
	EpicFileSystem *fs;
	int res = efs_lock_global(&fs);
	if (res == 0) {
		res = efs_tell(fs, fd);
		efs_unlock_global(fs);
	}
	return res;
}

int epic_file_stat(const char *filename, struct epic_stat *stat)
{
	EpicFileSystem *fs;
	int res = efs_lock_global(&fs);
	if (res == 0) {
		res = efs_stat(fs, filename, stat);
		efs_unlock_global(fs);
	}
	return res;
}
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140

int epic_file_opendir(const char *path)
{
	EpicFileSystem *fs;
	int res = efs_lock_global(&fs);
	if (res == 0) {
		res = efs_opendir(fs, path);
		efs_unlock_global(fs);
	}
	return res;
}

int epic_file_readdir(int fd, struct epic_stat *stat)
{
	EpicFileSystem *fs;
	int res = efs_lock_global(&fs);
	if (res == 0) {
		res = efs_readdir(fs, fd, stat);
		efs_unlock_global(fs);
	}
	return res;
}

int epic_file_unlink(const char *path)
{
	EpicFileSystem *fs;
	int res = efs_lock_global(&fs);
	if (res == 0) {
		res = efs_unlink(fs, path);
		efs_unlock_global(fs);
	}
	return res;
}
swym's avatar
swym committed
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162

int epic_file_rename(const char *oldp, const char *newp)
{
	EpicFileSystem *fs;
	int res = efs_lock_global(&fs);
	if (res == 0) {
		res = efs_rename(fs, oldp, newp);
		efs_unlock_global(fs);
	}
	return res;
}

int epic_file_mkdir(const char *dirname)
{
	EpicFileSystem *fs;
	int res = efs_lock_global(&fs);
	if (res == 0) {
		res = efs_mkdir(fs, dirname);
		efs_unlock_global(fs);
	}
	return res;
}
163
164
165
166
167
168
169
170
171
172
173

int epic_file_fs_status(void)
{
	EpicFileSystem *fs;
	int res = efs_lock_global(&fs);
	if (res == 0) {
		efs_dump_status(fs);
		efs_unlock_global(fs);
	}
	return res;
}