From e600a8f83f72329d95098dd970d976e02843fd33 Mon Sep 17 00:00:00 2001 From: JaniruTEC Date: Thu, 28 May 2020 16:17:28 +0200 Subject: [PATCH] Added MountInfo-API Added MountInfo-API to wrap the class DokanOptions for the respective field in DokanFileHandle (wrapper for DokanFileInfo). Added Interfaces ROMountInfo and RWMountInfo Added ImmutableMountInfo and MountInfo as implementations This commit is part of my effort to fix dokan-java's issue https://github.com/dokan-dev/dokan-java/issues/32 --- .../mountinfo/ImmutableMountInfo.java | 145 +++++++++++++ .../wrappers/mountinfo/MountInfo.java | 203 ++++++++++++++++++ .../wrappers/mountinfo/ROMountInfo.java | 42 ++++ .../wrappers/mountinfo/RWMountInfo.java | 31 +++ 4 files changed, 421 insertions(+) create mode 100644 src/main/java/dev/dokan/dokan_java/wrappers/mountinfo/ImmutableMountInfo.java create mode 100644 src/main/java/dev/dokan/dokan_java/wrappers/mountinfo/MountInfo.java create mode 100644 src/main/java/dev/dokan/dokan_java/wrappers/mountinfo/ROMountInfo.java create mode 100644 src/main/java/dev/dokan/dokan_java/wrappers/mountinfo/RWMountInfo.java diff --git a/src/main/java/dev/dokan/dokan_java/wrappers/mountinfo/ImmutableMountInfo.java b/src/main/java/dev/dokan/dokan_java/wrappers/mountinfo/ImmutableMountInfo.java new file mode 100644 index 0000000..39a765a --- /dev/null +++ b/src/main/java/dev/dokan/dokan_java/wrappers/mountinfo/ImmutableMountInfo.java @@ -0,0 +1,145 @@ +package dev.dokan.dokan_java.wrappers.mountinfo; + + +import com.sun.jna.WString; +import dev.dokan.dokan_java.DokanNativeMethods; +import dev.dokan.dokan_java.constants.dokany.MountOption; +import dev.dokan.dokan_java.structure.DokanOptions; +import dev.dokan.dokan_java.structure.EnumIntegerSet; + + +public class ImmutableMountInfo implements ROMountInfo { + +// private final long globalContext; + + private final short threadCount; + private final int mountOptions; + private final String mountPoint; + private final String uncName; + private final long timeout; + private final long allocationUnitSize; + private final long sectorSize; + + public ImmutableMountInfo(DokanOptions dokanOptions) { + this.threadCount = dokanOptions.ThreadCount; + this.mountOptions = dokanOptions.Options; +// this.globalContext = dokanOptions.GlobalContext; + this.mountPoint = dokanOptions.MountPoint.toString(); + this.uncName = dokanOptions.UNCName.toString(); + this.timeout = dokanOptions.Timeout; + this.allocationUnitSize = dokanOptions.AllocationUnitSize; + this.sectorSize = dokanOptions.SectorSize; + } + + ImmutableMountInfo(ImmutableMountInfo info) { + this.threadCount = info.threadCount; + this.mountOptions = info.mountOptions; +// this.globalContext = info.globalContext; + this.mountPoint = info.mountPoint; + this.uncName = info.uncName; + this.timeout = info.timeout; + this.allocationUnitSize = info.allocationUnitSize; + this.sectorSize = info.sectorSize; + } + + ImmutableMountInfo(MountInfo info) { + this.threadCount = info.getThreadCount(); + this.mountOptions = info.getFlags(); +// this.globalContext = info.getGlobalContext(); + this.mountPoint = info.getMountPoint(); + this.uncName = info.getUNCName(); + this.timeout = info.getTimeout(); + this.allocationUnitSize = info.getAllocationUnitSize(); + this.sectorSize = info.getSectorSize(); + } + + @Override + public short getDokanVersion() { + return DokanNativeMethods.getMinimumRequiredDokanVersion(); + } + + @Override + public short getThreadCount() { + return this.threadCount; + } + + @Override + public EnumIntegerSet getMountOptions() { + return MountOption.fromInt(this.mountOptions); + } + + @Override + public int getFlags() { + return this.mountOptions; + } + + @Override + public boolean getFlag(MountOption flag) { + return (this.mountOptions & flag.getMask()) != 0; + } + +// @Override +// public long getGlobalContext() { +// return this.globalContext; +// } + + @Override + public String getMountPoint() { + return this.mountPoint; + } + + @Override + public String getUNCName() { + return this.uncName; + } + + @Override + public long getTimeout() { + return this.timeout; + } + + @Override + public long getAllocationUnitSize() { + return this.allocationUnitSize; + } + + @Override + public long getSectorSize() { + return this.sectorSize; + } + + @Override + public boolean isMutable() { + return false; + } + + @Override + public ROMountInfo immutableCopy() { + return new ImmutableMountInfo(this); + } + + @Override + public RWMountInfo mutableCopy() { + return new MountInfo(this); + } + + @Override + public DokanOptions nativeCopy() { + DokanOptions options = new DokanOptions(this.mountPoint, this.threadCount, this.mountOptions, this.uncName, this.timeout, this.allocationUnitSize, this.sectorSize); +// options.GlobalContext = this.globalContext; + + return options; + } + + @Override + public void nativeCopy(DokanOptions options) { + options.ThreadCount = this.threadCount; + options.Options = this.mountOptions; +// options.GlobalContext = this.globalContext; + options.MountPoint = new WString(this.mountPoint); + options.UNCName = new WString(this.uncName); + options.Timeout = this.timeout; + options.AllocationUnitSize = this.allocationUnitSize; + options.SectorSize = this.sectorSize; + } +} \ No newline at end of file diff --git a/src/main/java/dev/dokan/dokan_java/wrappers/mountinfo/MountInfo.java b/src/main/java/dev/dokan/dokan_java/wrappers/mountinfo/MountInfo.java new file mode 100644 index 0000000..7720721 --- /dev/null +++ b/src/main/java/dev/dokan/dokan_java/wrappers/mountinfo/MountInfo.java @@ -0,0 +1,203 @@ +package dev.dokan.dokan_java.wrappers.mountinfo; + + +import com.sun.jna.WString; +import dev.dokan.dokan_java.DokanNativeMethods; +import dev.dokan.dokan_java.constants.dokany.MountOption; +import dev.dokan.dokan_java.structure.DokanOptions; +import dev.dokan.dokan_java.structure.EnumIntegerSet; + + +public class MountInfo implements RWMountInfo { + +// private long globalContext; + + private short threadCount; + private int mountOptions; + private String mountPoint; + private String uncName; + private long timeout; + private long allocationUnitSize; + private long sectorSize; + + public MountInfo(DokanOptions dokanOptions) { + this.threadCount = dokanOptions.ThreadCount; + this.mountOptions = dokanOptions.Options; +// this.globalContext = dokanOptions.GlobalContext; + this.mountPoint = dokanOptions.MountPoint.toString(); + this.uncName = dokanOptions.UNCName.toString(); + this.timeout = dokanOptions.Timeout; + this.allocationUnitSize = dokanOptions.AllocationUnitSize; + this.sectorSize = dokanOptions.SectorSize; + } + + MountInfo(MountInfo info) { + this.threadCount = info.threadCount; + this.mountOptions = info.mountOptions; +// this.globalContext = info.globalContext; + this.mountPoint = info.mountPoint; + this.uncName = info.uncName; + this.timeout = info.timeout; + this.allocationUnitSize = info.allocationUnitSize; + this.sectorSize = info.sectorSize; + } + + MountInfo(ImmutableMountInfo info) { + this.threadCount = info.getThreadCount(); + this.mountOptions = info.getFlags(); +// this.globalContext = info.getGlobalContext(); + this.mountPoint = info.getMountPoint(); + this.uncName = info.getUNCName(); + this.timeout = info.getTimeout(); + this.allocationUnitSize = info.getAllocationUnitSize(); + this.sectorSize = info.getSectorSize(); + } + + @Override + public short getDokanVersion() { + return DokanNativeMethods.getMinimumRequiredDokanVersion(); + } + + @Override + public short getThreadCount() { + return this.threadCount; + } + + @Override + public void setThreadCount(short threadCount) { + this.threadCount = threadCount; + } + + @Override + public EnumIntegerSet getMountOptions() { + return MountOption.fromInt(this.mountOptions); + } + + @Override + public void setMountOptions(EnumIntegerSet mountOptions) { + this.mountOptions = mountOptions.toInt(); + } + + @Override + public int getFlags() { + return this.mountOptions; + } + + @Override + public void setFlags(int flags) { + this.mountOptions = flags; + } + + @Override + public boolean getFlag(MountOption flag) { + return (this.mountOptions & flag.getMask()) != 0; + } + + @Override + public boolean setFlag(MountOption flag) { + return updateFlag(flag, true); + } + + @Override + public boolean unsetFlag(MountOption flag) { + return updateFlag(flag, false); + } + + @Override + public boolean updateFlag(MountOption flag, boolean value) { + boolean prev = getFlag(flag); + this.mountOptions &= value ? flag.getMask() : ~flag.getMask(); + + return prev; + } + +// @Override +// public long getGlobalContext() { +// return this.globalContext; +// } + + @Override + public String getMountPoint() { + return this.mountPoint; + } + + @Override + public void setMountPoint(String mountPoint) { + this.mountPoint = mountPoint; + } + + @Override + public String getUNCName() { + return this.uncName; + } + + @Override + public void setUNCName(String uncName) { + this.uncName = uncName; + } + + @Override + public long getTimeout() { + return this.timeout; + } + + @Override + public void setTimeout(long timeout) { + this.timeout = timeout; + } + + @Override + public long getAllocationUnitSize() { + return this.allocationUnitSize; + } + + @Override + public void setAllocationUnitSize(long allocationUnitSize) { + this.allocationUnitSize = allocationUnitSize; + } + + @Override + public long getSectorSize() { + return this.sectorSize; + } + + @Override + public void setSectorSize(long sectorSize) { + this.sectorSize = sectorSize; + } + + @Override + public boolean isMutable() { + return true; + } + + @Override + public ROMountInfo immutableCopy() { + return new ImmutableMountInfo(this); + } + + @Override + public RWMountInfo mutableCopy() { + return new MountInfo(this); + } + + @Override + public DokanOptions nativeCopy() { + DokanOptions options = new DokanOptions(this.mountPoint, this.threadCount, this.mountOptions, this.uncName, this.timeout, this.allocationUnitSize, this.sectorSize); +// options.GlobalContext = this.globalContext; + + return options; + } + + @Override + public void nativeCopy(DokanOptions options) { + options.ThreadCount = this.threadCount; + options.Options = this.mountOptions; +// options.GlobalContext = this.globalContext; + options.MountPoint = new WString(this.mountPoint); + options.UNCName = new WString(this.uncName); + options.Timeout = this.timeout; + options.AllocationUnitSize = this.allocationUnitSize; + options.SectorSize = this.sectorSize; + } +} \ No newline at end of file diff --git a/src/main/java/dev/dokan/dokan_java/wrappers/mountinfo/ROMountInfo.java b/src/main/java/dev/dokan/dokan_java/wrappers/mountinfo/ROMountInfo.java new file mode 100644 index 0000000..3323e26 --- /dev/null +++ b/src/main/java/dev/dokan/dokan_java/wrappers/mountinfo/ROMountInfo.java @@ -0,0 +1,42 @@ +package dev.dokan.dokan_java.wrappers.mountinfo; + + +import dev.dokan.dokan_java.constants.dokany.MountOption; +import dev.dokan.dokan_java.structure.DokanOptions; +import dev.dokan.dokan_java.structure.EnumIntegerSet; + + +public interface ROMountInfo { + + short getDokanVersion(); + + short getThreadCount(); + + EnumIntegerSet getMountOptions(); + + int getFlags(); + + boolean getFlag(MountOption flag); + +// long getGlobalContext(); + + String getMountPoint(); + + String getUNCName(); + + long getTimeout(); + + long getAllocationUnitSize(); + + long getSectorSize(); + + boolean isMutable(); + + ROMountInfo immutableCopy(); + + RWMountInfo mutableCopy(); + + DokanOptions nativeCopy(); + + void nativeCopy(DokanOptions options); +} \ No newline at end of file diff --git a/src/main/java/dev/dokan/dokan_java/wrappers/mountinfo/RWMountInfo.java b/src/main/java/dev/dokan/dokan_java/wrappers/mountinfo/RWMountInfo.java new file mode 100644 index 0000000..aee5093 --- /dev/null +++ b/src/main/java/dev/dokan/dokan_java/wrappers/mountinfo/RWMountInfo.java @@ -0,0 +1,31 @@ +package dev.dokan.dokan_java.wrappers.mountinfo; + + +import dev.dokan.dokan_java.constants.dokany.MountOption; +import dev.dokan.dokan_java.structure.EnumIntegerSet; + + +public interface RWMountInfo extends ROMountInfo { + + void setThreadCount(short threadCount); + + void setMountOptions(EnumIntegerSet mountOptions); + + void setFlags(int flags); + + boolean setFlag(MountOption flag); + + boolean unsetFlag(MountOption flag); + + boolean updateFlag(MountOption flag, boolean value); + + void setMountPoint(String mountPoint); + + void setUNCName(String uncName); + + void setTimeout(long timeout); + + void setAllocationUnitSize(long allocationUnitSize); + + void setSectorSize(long sectorSize); +} \ No newline at end of file