all repos — mgba @ 250d3b940dc06961a320811678dac67e5a77484f

mGBA Game Boy Advance Emulator

VFS: Add sync method to force syncing with backing
Jeffrey Pfau jeffrey@endrift.com
Tue, 07 Jul 2015 00:26:31 -0700
commit

250d3b940dc06961a320811678dac67e5a77484f

parent

b4c3440bc4b8bf85cd91f3571c91f4a6a958c7aa

M CHANGESCHANGES

@@ -98,6 +98,7 @@ - GBA Audio: Implement audio reset for channels A/B

- 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:
M src/util/vfs.hsrc/util/vfs.h

@@ -39,6 +39,7 @@ void* (*map)(struct VFile* vf, size_t size, int flags);

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 {
M src/util/vfs/vfs-fd.csrc/util/vfs/vfs-fd.c

@@ -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 @@ vfd->d.map = _vfdMap;

vfd->d.unmap = _vfdUnmap; vfd->d.truncate = _vfdTruncate; vfd->d.size = _vfdSize; + vfd->d.sync = _vfdSync; return &vfd->d; }

@@ -166,3 +168,10 @@ return -1;

} 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; +}
M src/util/vfs/vfs-file.csrc/util/vfs/vfs-file.c

@@ -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 @@ vff->d.map = _vffMap;

vff->d.unmap = _vffUnmap; vff->d.truncate = _vffTruncate; vff->d.size = _vffSize; + vff->d.sync = _vffSync; return &vff->d; }

@@ -140,3 +142,14 @@ ssize_t size = ftell(vff->file);

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; +}
M src/util/vfs/vfs-lzma.csrc/util/vfs/vfs-lzma.c

@@ -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 @@ vf->d.map = _vf7zMap;

vf->d.unmap = _vf7zUnmap; vf->d.truncate = _vf7zTruncate; vf->d.size = _vf7zSize; + vf->d.sync = _vf7zSync; return &vf->d; }

@@ -306,6 +308,13 @@ free(name);

} return vde7z->utf8; +} + +bool _vf7zSync(struct VFile* vf, const void* memory, size_t size) { + UNUSED(vf); + UNUSED(memory); + UNUSED(size); + return false; } #endif
M src/util/vfs/vfs-zip.csrc/util/vfs/vfs-zip.c

@@ -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 @@ vfz->d.map = _vfzMap;

vfz->d.unmap = _vfzUnmap; vfz->d.truncate = _vfzTruncate; vfz->d.size = _vfzSize; + vfz->d.sync = _vfzSync; return &vfz->d; }

@@ -300,6 +302,13 @@ if (zip_stat_index(vdez->z, vdez->index, 0, &s) < 0) {

return 0; } return s.name; +} + +bool _vfzSync(struct VFile* vf, const void* memory, size_t size) { + UNUSED(vf); + UNUSED(memory); + UNUSED(size); + return false; } #endif