Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(OpenFlags): correct the O_DIRECT flag on aarch64 #2

Merged
merged 1 commit into from
Mar 17, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 3 additions & 4 deletions src/main/java/moe/cnkirito/kdio/DirectIOLib.java
Original file line number Diff line number Diff line change
Expand Up @@ -244,11 +244,11 @@ public int pwrite(int fd, ByteBuffer buf, long offset) throws IOException {
*
*/
public int oDirectOpen(String pathname, boolean readOnly) throws IOException {
int flags = OpenFlags.O_DIRECT;
int flags = OpenFlags.INSTANCE.oDIRECT();
if (readOnly) {
flags |= OpenFlags.O_RDONLY;
flags |= OpenFlags.INSTANCE.oRDONLY();
} else {
flags |= OpenFlags.O_RDWR | OpenFlags.O_CREAT;
flags |= OpenFlags.INSTANCE.oWRONLY() | OpenFlags.INSTANCE.oCREAT();
}
int fd = open(pathname, flags, 00644);
if (fd < 0) {
Expand Down Expand Up @@ -413,4 +413,3 @@ public static int lcm(long x, long y) {
private static native String strerror(int errnum);

}

52 changes: 43 additions & 9 deletions src/main/java/moe/cnkirito/kdio/OpenFlags.java
Original file line number Diff line number Diff line change
Expand Up @@ -18,14 +18,48 @@
/**
* Constants for {@link DirectIOLib#oDirectOpen(String, boolean)}.
*/
public final class OpenFlags {
public static final int O_RDONLY = 00;
public static final int O_WRONLY = 01;
public static final int O_RDWR = 02;
public static final int O_CREAT = 0100;
public static final int O_TRUNC = 01000;
public static final int O_DIRECT = 040000;
public static final int O_SYNC = 04000000;
public interface OpenFlags {
OpenFlags INSTANCE = instance();

private OpenFlags() {}
static OpenFlags instance() {
String arch = System.getProperty("os.arch");
switch (arch) {
case "aarch64":
return new Aarch64OpenFlags();
default:
return new DefaultOpenFlags();
}
}

default int oRDONLY() {
return 00;
}
default int oWRONLY() {
return 01;
}
default int oRDWR() {
return 02;
}
default int oCREAT() {
return 0100;
}
default int oTRUNC() {
return 01000;
}
default int oDIRECT() {
return 040000;
}
default int oSYNC() {
return 04010000;
}

class DefaultOpenFlags implements OpenFlags {
}

class Aarch64OpenFlags implements OpenFlags {
@Override
public int oDIRECT() {
return 0200000;
}
}
}