VFS: Add sync method to force syncing with backing

This commit is contained in:
Jeffrey Pfau 2015-07-07 00:26:31 -07:00
parent b4c3440bc4
commit 250d3b940d
6 changed files with 42 additions and 0 deletions

View File

@ -98,6 +98,7 @@ Misc:
- GBA Hardware: Backport generic RTC source into core
- All: Proper handling of Unicode file paths
- GBA Video: Slightly optimize mode 0 mosaic rendering
- VFS: Add sync method to force syncing with backing
0.2.1: (2015-05-13)
Bugfixes:

View File

@ -39,6 +39,7 @@ struct VFile {
void (*unmap)(struct VFile* vf, void* memory, size_t size);
void (*truncate)(struct VFile* vf, size_t size);
ssize_t (*size)(struct VFile* vf);
bool (*sync)(struct VFile* vf, const void* buffer, size_t size);
};
struct VDirEntry {

View File

@ -30,6 +30,7 @@ static void* _vfdMap(struct VFile* vf, size_t size, int flags);
static void _vfdUnmap(struct VFile* vf, void* memory, size_t size);
static void _vfdTruncate(struct VFile* vf, size_t size);
static ssize_t _vfdSize(struct VFile* vf);
static bool _vfdSync(struct VFile* vf, const void* buffer, size_t size);
struct VFile* VFileOpenFD(const char* path, int flags) {
if (!path) {
@ -66,6 +67,7 @@ struct VFile* VFileFromFD(int fd) {
vfd->d.unmap = _vfdUnmap;
vfd->d.truncate = _vfdTruncate;
vfd->d.size = _vfdSize;
vfd->d.sync = _vfdSync;
return &vfd->d;
}
@ -166,3 +168,10 @@ static ssize_t _vfdSize(struct VFile* vf) {
}
return stat.st_size;
}
static bool _vfdSync(struct VFile* vf, const void* buffer, size_t size) {
UNUSED(buffer);
UNUSED(size);
struct VFileFD* vfd = (struct VFileFD*) vf;
return fsync(vfd->fd) == 0;
}

View File

@ -24,6 +24,7 @@ static void* _vffMap(struct VFile* vf, size_t size, int flags);
static void _vffUnmap(struct VFile* vf, void* memory, size_t size);
static void _vffTruncate(struct VFile* vf, size_t size);
static ssize_t _vffSize(struct VFile* vf);
static bool _vffSync(struct VFile* vf, const void* buffer, size_t size);
struct VFile* VFileFOpen(const char* path, const char* mode) {
if (!path && !mode) {
@ -57,6 +58,7 @@ struct VFile* VFileFromFILE(FILE* file) {
vff->d.unmap = _vffUnmap;
vff->d.truncate = _vffTruncate;
vff->d.size = _vffSize;
vff->d.sync = _vffSync;
return &vff->d;
}
@ -140,3 +142,14 @@ static ssize_t _vffSize(struct VFile* vf) {
fseek(vff->file, pos, SEEK_SET);
return size;
}
static bool _vffSync(struct VFile* vf, const void* buffer, size_t size) {
struct VFileFILE* vff = (struct VFileFILE*) vf;
if (buffer && size) {
long pos = ftell(vff->file);
fseek(vff->file, 0, SEEK_SET);
fwrite(buffer, size, 1, vff->file);
fseek(vff->file, pos, SEEK_SET);
}
return fflush(vff->file) == 0;
}

View File

@ -56,6 +56,7 @@ static void* _vf7zMap(struct VFile* vf, size_t size, int flags);
static void _vf7zUnmap(struct VFile* vf, void* memory, size_t size);
static void _vf7zTruncate(struct VFile* vf, size_t size);
static ssize_t _vf7zSize(struct VFile* vf);
static bool _vf7zSync(struct VFile* vf, const void* buffer, size_t size);
static bool _vd7zClose(struct VDir* vd);
static void _vd7zRewind(struct VDir* vd);
@ -291,6 +292,7 @@ struct VFile* _vd7zOpenFile(struct VDir* vd, const char* path, int mode) {
vf->d.unmap = _vf7zUnmap;
vf->d.truncate = _vf7zTruncate;
vf->d.size = _vf7zSize;
vf->d.sync = _vf7zSync;
return &vf->d;
}
@ -308,4 +310,11 @@ const char* _vde7zName(struct VDirEntry* vde) {
return vde7z->utf8;
}
bool _vf7zSync(struct VFile* vf, const void* memory, size_t size) {
UNUSED(vf);
UNUSED(memory);
UNUSED(size);
return false;
}
#endif

View File

@ -43,6 +43,7 @@ static void* _vfzMap(struct VFile* vf, size_t size, int flags);
static void _vfzUnmap(struct VFile* vf, void* memory, size_t size);
static void _vfzTruncate(struct VFile* vf, size_t size);
static ssize_t _vfzSize(struct VFile* vf);
static bool _vfzSync(struct VFile* vf, const void* buffer, size_t size);
static bool _vdzClose(struct VDir* vd);
static void _vdzRewind(struct VDir* vd);
@ -289,6 +290,7 @@ struct VFile* _vdzOpenFile(struct VDir* vd, const char* path, int mode) {
vfz->d.unmap = _vfzUnmap;
vfz->d.truncate = _vfzTruncate;
vfz->d.size = _vfzSize;
vfz->d.sync = _vfzSync;
return &vfz->d;
}
@ -302,4 +304,11 @@ const char* _vdezName(struct VDirEntry* vde) {
return s.name;
}
bool _vfzSync(struct VFile* vf, const void* memory, size_t size) {
UNUSED(vf);
UNUSED(memory);
UNUSED(size);
return false;
}
#endif