am adcee61e: Merge "Use O_DSYNC instead of O_SYNC when opening a file with mode="rwd"."
* commit 'adcee61e90099981a01306d3d12afdc232b741b1':
Use O_DSYNC instead of O_SYNC when opening a file with mode="rwd".
diff --git a/luni/src/main/java/android/system/OsConstants.java b/luni/src/main/java/android/system/OsConstants.java
index 0908b88..08a0ba8 100644
--- a/luni/src/main/java/android/system/OsConstants.java
+++ b/luni/src/main/java/android/system/OsConstants.java
@@ -350,6 +350,7 @@
public static final int O_RDONLY = placeholder();
public static final int O_RDWR = placeholder();
public static final int O_SYNC = placeholder();
+ /** @hide */ public static final int O_DSYNC = placeholder();
public static final int O_TRUNC = placeholder();
public static final int O_WRONLY = placeholder();
public static final int POLLERR = placeholder();
diff --git a/luni/src/main/java/java/io/RandomAccessFile.java b/luni/src/main/java/java/io/RandomAccessFile.java
index 0e4fa4f..42c30c4 100644
--- a/luni/src/main/java/java/io/RandomAccessFile.java
+++ b/luni/src/main/java/java/io/RandomAccessFile.java
@@ -44,8 +44,6 @@
*/
private FileDescriptor fd;
- private boolean syncMetadata = false;
-
// The unique file channel associated with this FileInputStream (lazily
// initialized).
private FileChannel channel;
@@ -104,11 +102,11 @@
} else if (mode.equals("rw") || mode.equals("rws") || mode.equals("rwd")) {
flags = O_RDWR | O_CREAT;
if (mode.equals("rws")) {
- // Sync file and metadata with every write
- syncMetadata = true;
- } else if (mode.equals("rwd")) {
- // Sync file, but not necessarily metadata
+ // Sync data and metadata with every write
flags |= O_SYNC;
+ } else if (mode.equals("rwd")) {
+ // Sync data, but not necessarily metadata
+ flags |= O_DSYNC;
}
} else {
throw new IllegalArgumentException("Invalid mode: " + mode);
@@ -116,14 +114,6 @@
this.mode = flags;
this.fd = IoBridge.open(file.getPath(), flags);
- // if we are in "rws" mode, attempt to sync file+metadata
- if (syncMetadata) {
- try {
- fd.sync();
- } catch (IOException e) {
- // Ignored
- }
- }
guard.open("close");
}
@@ -635,10 +625,6 @@
seek(newLength);
}
- // if we are in "rws" mode, attempt to sync file+metadata
- if (syncMetadata) {
- fd.sync();
- }
}
/**
@@ -689,10 +675,6 @@
*/
public void write(byte[] buffer, int byteOffset, int byteCount) throws IOException {
IoBridge.write(fd, buffer, byteOffset, byteCount);
- // if we are in "rws" mode, attempt to sync file+metadata
- if (syncMetadata) {
- fd.sync();
- }
}
/**
diff --git a/luni/src/main/native/android_system_OsConstants.cpp b/luni/src/main/native/android_system_OsConstants.cpp
index 3cc9b06..c064130 100644
--- a/luni/src/main/native/android_system_OsConstants.cpp
+++ b/luni/src/main/native/android_system_OsConstants.cpp
@@ -386,6 +386,7 @@
initConstant(env, c, "O_RDONLY", O_RDONLY);
initConstant(env, c, "O_RDWR", O_RDWR);
initConstant(env, c, "O_SYNC", O_SYNC);
+ initConstant(env, c, "O_DSYNC", O_DSYNC);
initConstant(env, c, "O_TRUNC", O_TRUNC);
initConstant(env, c, "O_WRONLY", O_WRONLY);
initConstant(env, c, "POLLERR", POLLERR);