diff --git a/src/main/java/moe/cnkirito/kdio/DirectIOLib.java b/src/main/java/moe/cnkirito/kdio/DirectIOLib.java index 95ef3bc..8340fbc 100755 --- a/src/main/java/moe/cnkirito/kdio/DirectIOLib.java +++ b/src/main/java/moe/cnkirito/kdio/DirectIOLib.java @@ -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) { @@ -413,4 +413,3 @@ public static int lcm(long x, long y) { private static native String strerror(int errnum); } - diff --git a/src/main/java/moe/cnkirito/kdio/OpenFlags.java b/src/main/java/moe/cnkirito/kdio/OpenFlags.java index 552d111..bda3a4e 100755 --- a/src/main/java/moe/cnkirito/kdio/OpenFlags.java +++ b/src/main/java/moe/cnkirito/kdio/OpenFlags.java @@ -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; + } + } }