From 09baf99aa4b72ba757b4e109dd3ca2b4f3c2e32e Mon Sep 17 00:00:00 2001 From: "Ryan C. Gordon" Date: Wed, 21 Aug 2013 23:30:33 -0400 Subject: [PATCH] Don't fsync() read-only filehandles (thanks, Andreas!). This sounds harmless, but it actually forces a write of the inode's atime, which means a lot of painful and unnecessary disk i/o on some filesystems. Should be a good speedup on games that read a lot of small files on Unix. --- docs/CREDITS.txt | 3 +++ src/platform_posix.c | 3 ++- 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/docs/CREDITS.txt b/docs/CREDITS.txt index b961e72..aa5d023 100644 --- a/docs/CREDITS.txt +++ b/docs/CREDITS.txt @@ -136,6 +136,9 @@ SLB archiver: Bug fixes: Dmitry Marakasov +Bug fixes: + Andreas Karlsson + Other stuff: Your name here! Patches go to icculus@icculus.org ... diff --git a/src/platform_posix.c b/src/platform_posix.c index 71f8ba0..018ae76 100644 --- a/src/platform_posix.c +++ b/src/platform_posix.c @@ -279,7 +279,8 @@ PHYSFS_sint64 __PHYSFS_platformFileLength(void *opaque) int __PHYSFS_platformFlush(void *opaque) { const int fd = *((int *) opaque); - BAIL_IF_MACRO(fsync(fd) == -1, errcodeFromErrno(), 0); + if ((fcntl(fd, F_GETFL) & O_ACCMODE) != O_RDONLY) + BAIL_IF_MACRO(fsync(fd) == -1, errcodeFromErrno(), 0); return 1; } /* __PHYSFS_platformFlush */