summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorSuren A. Chilingaryan <csa@dside.dyndns.org>2012-03-26 15:00:45 +0200
committerSuren A. Chilingaryan <csa@dside.dyndns.org>2012-03-26 15:00:45 +0200
commit0af5dbbe4edec6a25cc4a66248bee38f570d131e (patch)
treef4ac495eff92fb47f0cf3795e497b668015486b7
parent4fdf54d4690fdf33c94b27bcf44094bb933e11fd (diff)
downloadfastwriter-0af5dbbe4edec6a25cc4a66248bee38f570d131e.tar.gz
fastwriter-0af5dbbe4edec6a25cc4a66248bee38f570d131e.tar.bz2
fastwriter-0af5dbbe4edec6a25cc4a66248bee38f570d131e.tar.xz
fastwriter-0af5dbbe4edec6a25cc4a66248bee38f570d131e.zip
Try without O_DIRECT if run under normal user
-rw-r--r--default.c14
1 files changed, 13 insertions, 1 deletions
diff --git a/default.c b/default.c
index 97baec1..5109608 100644
--- a/default.c
+++ b/default.c
@@ -117,7 +117,19 @@ int fastwriter_default_open(fastwriter_t *fw, const char *name, fastwriter_flags
open_flags |= O_TRUNC;
ctx->fd = open(name, open_flags, open_mode);
- if (ctx->fd < 0) return errno;
+#ifdef SYNC_MODE
+ if (ctx->fd < 0) {
+ // Running as normal user, try to disable direct mode
+ if ((errno == EINVAL)&&(ctx->sync_mode)) {
+ ctx->sync_mode = 0;
+ open_flags &= ~O_DIRECT;
+ ctx->fd = open(name, open_flags, open_mode);
+ }
+#endif /* SYNC_MODE */
+ if (ctx->fd < 0) return errno;
+#ifdef SYNC_MODE
+ }
+#endif /* SYNC_MODE */
if (((open_flags&FASTWRITER_FLAGS_OVERWRITE)==0)&&(strcmp(fs, "raw"))) {
ctx->prior_size = lseek(ctx->fd, 0, SEEK_END);