Skip to content

Commit

Permalink
Merge pull request #41 from JaniruTEC/improved-enumintegers
Browse files Browse the repository at this point in the history
Merge pull request #41 from JaniruTEC/improved-enumintegers: Improve EnumInteger-System

Added new package conv (conversion)
Added convenience methods
Added missing static methods
Added IntegerConvertible as base interface of EnumInteger
Added MaskValue as special case of EnumInteger that is used to express masks
Renamed EnumIntegerSet to MaskValueSet and changed it to only accept MaskValues
Made EnumIntegerSet an interface and added EnumIntegerSetImpl as implementation
Renamed enumSetFromInt to maskValueSet
  • Loading branch information
JaniruTEC authored Jun 2, 2020
2 parents e0cbff1 + 7975114 commit 43b8d13
Show file tree
Hide file tree
Showing 33 changed files with 372 additions and 306 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
import dev.dokan.dokan_java.constants.dokany.MountOption;
import dev.dokan.dokan_java.structure.DokanControl;
import dev.dokan.dokan_java.structure.DokanOptions;
import dev.dokan.dokan_java.structure.EnumIntegerSet;
import dev.dokan.dokan_java.masking.MaskValueSet;

import java.lang.reflect.Method;
import java.nio.file.Path;
Expand Down Expand Up @@ -173,10 +173,10 @@ private boolean isImplemented(String funcName) {
* @param sectorSize the sector size
* @param UNCName
* @param threadCount the number of threads spawned for processing filesystem calls
* @param options an {@link EnumIntegerSet} containing {@link MountOption}s
* @param options an {@link MaskValueSet} containing {@link MountOption}s
*/
@Override
public final synchronized void mount(Path mountPoint, String volumeName, int volumeSerialnumber, boolean blocking, long timeout, long allocationUnitSize, long sectorSize, String UNCName, short threadCount, EnumIntegerSet<MountOption> options) {
public final synchronized void mount(Path mountPoint, String volumeName, int volumeSerialnumber, boolean blocking, long timeout, long allocationUnitSize, long sectorSize, String UNCName, short threadCount, MaskValueSet<MountOption> options) {
this.dokanOptions = new DokanOptions(mountPoint.toString(), threadCount, options, UNCName, timeout, allocationUnitSize, sectorSize);
this.mountPoint = mountPoint;
this.volumeName = volumeName;
Expand Down Expand Up @@ -216,7 +216,7 @@ public final synchronized void mount(Path mountPoint, String volumeName, int vol
* @param mountPoint
* @param mountOptions
*/
public void mount(Path mountPoint, EnumIntegerSet<MountOption> mountOptions) {
public void mount(Path mountPoint, MaskValueSet<MountOption> mountOptions) {
String uncName = null;
short threadCount = 5;
long timeout = 3000;
Expand Down
10 changes: 5 additions & 5 deletions src/main/java/dev/dokan/dokan_java/DokanUtils.java
Original file line number Diff line number Diff line change
Expand Up @@ -140,19 +140,19 @@ public static int mapFileGenericAccessToGenericAccess(int fileAccess) {
public static int convertCreateDispositionToCreationDispostion(int createDisposition) {
switch (createDisposition) {
case FILE_CREATE:
return CREATE_NEW.getMask();
return CREATE_NEW.intValue();
case FILE_OPEN:
return OPEN_EXISTING.getMask();
return OPEN_EXISTING.intValue();
case FILE_OPEN_IF:
return OPEN_ALWAYS.getMask();
return OPEN_ALWAYS.intValue();
case FILE_OVERWRITE:
return TRUNCATE_EXISTING.getMask();
return TRUNCATE_EXISTING.intValue();
case FILE_SUPERSEDE:
// The documentation isn't clear on the difference between replacing a file
// and truncating it.
// For now we just map it to create/truncate
case FILE_OVERWRITE_IF:
return CREATE_ALWAYS.getMask();
return CREATE_ALWAYS.intValue();
default:
//TODO: maybe throw an exception
return 0;
Expand Down
12 changes: 6 additions & 6 deletions src/main/java/dev/dokan/dokan_java/FileSystemInformation.java
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package dev.dokan.dokan_java;

import dev.dokan.dokan_java.constants.microsoft.FileSystemFlag;
import dev.dokan.dokan_java.structure.EnumIntegerSet;
import dev.dokan.dokan_java.masking.MaskValueSet;

/**
* Supplementary class to bundle information of the filesystem.
Expand All @@ -14,18 +14,18 @@ public final class FileSystemInformation {

private final int maxComponentLength;
private final String fileSystemName;
private final EnumIntegerSet<FileSystemFlag> fileSystemFeatures;
private final MaskValueSet<FileSystemFlag> fileSystemFeatures;

/**
* Provides default values for maxComponentLength and Filesystem name.
*
* @param fileSystemFlags An {@link EnumIntegerSet} of features the file system supports. For possible values, see the {@link FileSystemFlag} enum.
* @param fileSystemFlags An {@link MaskValueSet} of features the file system supports. For possible values, see the {@link FileSystemFlag} enum.
*/
public FileSystemInformation(EnumIntegerSet<FileSystemFlag> fileSystemFlags) {
public FileSystemInformation(MaskValueSet<FileSystemFlag> fileSystemFlags) {
this(DEFAULT_MAX_COMPONENT_LENGTH, DEFAULT_FS_NAME, fileSystemFlags);
}

public FileSystemInformation(final int maxComponentLength, final String fileSystemName, final EnumIntegerSet<FileSystemFlag> fileSystemFeatures) {
public FileSystemInformation(final int maxComponentLength, final String fileSystemName, final MaskValueSet<FileSystemFlag> fileSystemFeatures) {
this.maxComponentLength = maxComponentLength;
this.fileSystemName = fileSystemName;
this.fileSystemFeatures = fileSystemFeatures;
Expand All @@ -39,7 +39,7 @@ public String getFileSystemName() {
return this.fileSystemName;
}

public EnumIntegerSet<FileSystemFlag> getFileSystemFeatures() {
public MaskValueSet<FileSystemFlag> getFileSystemFeatures() {
return this.fileSystemFeatures;
}

Expand Down
6 changes: 3 additions & 3 deletions src/main/java/dev/dokan/dokan_java/Mountable.java
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package dev.dokan.dokan_java;

import dev.dokan.dokan_java.constants.dokany.MountOption;
import dev.dokan.dokan_java.structure.EnumIntegerSet;
import dev.dokan.dokan_java.masking.MaskValueSet;

import java.nio.file.Path;

Expand All @@ -25,9 +25,9 @@ public interface Mountable extends AutoCloseable {
* @param sectorSize the sector size
* @param UNCName
* @param threadCount the number of threads spawned for processing filesystem calls
* @param options an {@link EnumIntegerSet} containing {@link MountOption}s
* @param options an {@link MaskValueSet} containing {@link MountOption}s
*/
void mount(Path mountPoint, String volumeName, int volumeSerialnumber, boolean blocking, long timeout, long allocationUnitSize, long sectorSize, String UNCName, short threadCount, EnumIntegerSet<MountOption> options);
void mount(Path mountPoint, String volumeName, int volumeSerialnumber, boolean blocking, long timeout, long allocationUnitSize, long sectorSize, String UNCName, short threadCount, MaskValueSet<MountOption> options);

/**
* Unmount this object.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package dev.dokan.dokan_java.constants.dokany;

import dev.dokan.dokan_java.constants.EnumInteger;
import dev.dokan.dokan_java.masking.EnumInteger;

/**
* Return values of com.dokan.java.NativeMethods#DokanMain(DokanOptions, DokanOperations)
Expand All @@ -17,20 +17,21 @@ public enum MountError implements EnumInteger {
MOUNT_POINT_ERROR(-6, "Mount failed: Mount point is invalid."),
VERSION_ERROR(-7, "Mount failed: Requested an incompatible version.");

private final int mask;
private final int intValue;
private final String description;

public static MountError fromInt(final int value) {
return EnumInteger.enumFromInt(value, values());
}

MountError(final int mask, final String description) {
this.mask = mask;
MountError(final int intValue, final String description) {
this.intValue = intValue;
this.description = description;
}

public int getMask() {
return this.mask;
@Override
public int intValue() {
return this.intValue;
}

public String getDescription() {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
package dev.dokan.dokan_java.constants.dokany;

import dev.dokan.dokan_java.constants.EnumInteger;
import dev.dokan.dokan_java.structure.EnumIntegerSet;
import dev.dokan.dokan_java.masking.MaskValueSet;
import dev.dokan.dokan_java.masking.MaskValueEnum;
import dev.dokan.dokan_java.structure.DokanOptions;

/**
* Enumeration of features that can be enabled for a mount. Part of {@link DokanOptions}
*
* @see <a href="https://dokan-dev.github.io/dokany-doc/html/group___d_o_k_a_n___o_p_t_i_o_n.html">Dokany documentation</a>
*/
public enum MountOption implements EnumInteger {
public enum MountOption implements MaskValueEnum {
DEBUG_MODE(1, "Enable output debug message."),
STD_ERR_OUTPUT(2, "Enable output debug message to stderr."),
ALT_STREAM(4, "Use alternate stream."),
Expand All @@ -20,20 +20,21 @@ public enum MountOption implements EnumInteger {
CURRENT_SESSION(128, "Mount the drive on current session only."),
FILELOCK_USER_MODE(256, "Enable Lockfile/Unlockfile operations. Otherwise Dokan will take care of it.");

private final int mask;
private final int maskingValue;
private final String description;

MountOption(final int i, final String desc) {
this.mask = i;
MountOption(final int maskingValue, final String desc) {
this.maskingValue = maskingValue;
this.description = desc;
}

public static EnumIntegerSet<MountOption> fromInt(final int value) {
return EnumIntegerSet.enumSetFromInt(value, values());
public static MaskValueSet<MountOption> maskValueSet(final int mask) {
return MaskValueSet.maskValueSet(mask, values());
}

public int getMask() {
return this.mask;
@Override
public int intValue() {
return this.maskingValue;
}

public String getDescription() {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
package dev.dokan.dokan_java.constants.microsoft;

import dev.dokan.dokan_java.constants.EnumInteger;
import com.sun.jna.platform.win32.WinNT;
import dev.dokan.dokan_java.masking.MaskValueEnum;
import dev.dokan.dokan_java.masking.MaskValueSet;

/**
* Enumeration of the possible AccesMask options.
* For more info see the <a href="https://msdn.microsoft.com/en-us/library/cc230294.aspx"> Microsoft Developer Documentation</a> or <a href="https://docs.microsoft.com/en-us/windows/desktop/SecAuthZ/access-mask">the normal documentation.</a>
*/
public enum AccessMask implements EnumInteger {
public enum AccessMask implements MaskValueEnum {
/**
* GENERIC_READ
* When used in an Access Request operation: When read access to an object is requested, this bit is translated to a combination of bits. These are most often set in the lower 16 bits of the ACCESS_MASK. (Individual protocol specifications MAY specify a different configuration.) The bits that are set are implementation dependent. During this translation, the GENERIC_READ bit is cleared. The resulting ACCESS_MASK bits are the actual permissions that are checked against the ACE structures in the security descriptor that attached to the object.
Expand Down Expand Up @@ -97,15 +98,18 @@ public enum AccessMask implements EnumInteger {
*/
DELETE(WinNT.DELETE);

private int mask;
private int maskingValue;

AccessMask(long mask) {
this.mask = (int) mask;
AccessMask(long maskingValue) {
this.maskingValue = (int) maskingValue;
}

public static MaskValueSet<AccessMask> maskValueSet(final int mask) {
return MaskValueSet.maskValueSet(mask, values());
}

@Override
public int getMask() {
return mask;
public int intValue() {
return this.maskingValue;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

import dev.dokan.dokan_java.DokanNativeMethods;
import dev.dokan.dokan_java.DokanOperations;
import dev.dokan.dokan_java.constants.EnumInteger;
import dev.dokan.dokan_java.masking.EnumInteger;
import com.sun.jna.ptr.IntByReference;

/**
Expand Down Expand Up @@ -74,14 +74,18 @@ public enum CreateDisposition implements EnumInteger {
FILE_OVERWRITE(CreateDispositions.FILE_OVERWRITE),
FILE_OVERWRITE_IF(CreateDispositions.FILE_OVERWRITE_IF);

private final int mask;
private final int intValue;

CreateDisposition(int mask) {
this.mask = mask;
CreateDisposition(int intValue) {
this.intValue = intValue;
}

public static CreateDisposition fromInt(final int value) {
return EnumInteger.enumFromInt(value, values());
}

@Override
public int getMask() {
return mask;
public int intValue() {
return this.intValue;
}
}
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
package dev.dokan.dokan_java.constants.microsoft;

import dev.dokan.dokan_java.constants.EnumInteger;
import dev.dokan.dokan_java.structure.EnumIntegerSet;
import dev.dokan.dokan_java.masking.MaskValueSet;
import dev.dokan.dokan_java.masking.MaskValueEnum;

/**
* Enum of flags specifying the options to apply when the driver creates or opens the file.
*
* @see <a href="https://docs.microsoft.com/en-us/windows-hardware/drivers/ddi/content/wdm/nf-wdm-zwcreatefile">Microsofts documentation of ZwCreateFile</a>
* @see <a href="https://dokan-dev.github.io/dokany-doc/html/struct_d_o_k_a_n___o_p_e_r_a_t_i_o_n_s.html#a40c2f61e1287237f5fd5c2690e795183">Dokany documentation of ZwCreateFile</a>
*/
public enum CreateOption implements EnumInteger {
public enum CreateOption implements MaskValueEnum {
FILE_DIRECTORY_FILE(CreateOptions.FILE_DIRECTORY_FILE),
FILE_WRITE_THROUGH(CreateOptions.FILE_WRITE_THROUGH),
FILE_SEQUENTIAL_ONLY(CreateOptions.FILE_SEQUENTIAL_ONLY),
Expand All @@ -29,19 +29,19 @@ public enum CreateOption implements EnumInteger {
FILE_NO_COMPRESSION(CreateOptions.FILE_NO_COMPRESSION),
FILE_SESSION_AWARE(CreateOptions.FILE_SESSION_AWARE);

private final int mask;
private final int maskingValue;

CreateOption(final int i) {
mask = i;
CreateOption(final int maskingValue) {
this.maskingValue = maskingValue;
}

public static EnumIntegerSet<CreateOption> fromInt(final int value) {
return EnumIntegerSet.enumSetFromInt(value, values());
public static MaskValueSet<CreateOption> maskValueSet(final int mask) {
return MaskValueSet.maskValueSet(mask, values());
}

@Override
public int getMask() {
return mask;
public int intValue() {
return this.maskingValue;
}

}
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
package dev.dokan.dokan_java.constants.microsoft;

import dev.dokan.dokan_java.DokanNativeMethods;
import dev.dokan.dokan_java.constants.EnumInteger;
import com.sun.jna.platform.win32.WinNT;
import com.sun.jna.ptr.IntByReference;
import dev.dokan.dokan_java.DokanNativeMethods;
import dev.dokan.dokan_java.masking.EnumInteger;

/**
* Enum of actions to take on a not-necessarily existing file or device.
Expand Down Expand Up @@ -64,18 +63,19 @@ public enum CreationDisposition implements EnumInteger {
OPEN_ALWAYS(WinNT.OPEN_ALWAYS),
TRUNCATE_EXISTING(WinNT.TRUNCATE_EXISTING);

private final int mask;
private final int intValue;

CreationDisposition(final int i) {
mask = i;
CreationDisposition(final int intValue) {
this.intValue = intValue;
}

public static CreationDisposition fromInt(final int value) {
return EnumInteger.enumFromInt(value, values());
}

public int getMask() {
return this.mask;
@Override
public int intValue() {
return this.intValue;
}

}
Original file line number Diff line number Diff line change
@@ -1,25 +1,30 @@
package dev.dokan.dokan_java.constants.microsoft;

import dev.dokan.dokan_java.constants.EnumInteger;
import com.sun.jna.platform.win32.WinNT;
import dev.dokan.dokan_java.masking.MaskValueEnum;
import dev.dokan.dokan_java.masking.MaskValueSet;

/**
* Additional {@link AccessMask} values specific to directories.
*
* @see <a href="https://docs.microsoft.com/en-us/windows-hardware/drivers/ddi/content/wdm/nf-wdm-zwcreatefile">Microsoft documentation of ZwCreateFile</a>, Section Parameters, Parameter {@code DesiredAccess}
*/
public enum DirectoryAccessMask implements EnumInteger {
public enum DirectoryAccessMask implements MaskValueEnum {
LIST_DIRECTORY(WinNT.FILE_LIST_DIRECTORY),
TRAVERSE(WinNT.FILE_TRAVERSE);

private final int mask;
private final int maskingValue;

DirectoryAccessMask(int mask) {
this.mask = mask;
}
DirectoryAccessMask(int maskingValue) {
this.maskingValue = maskingValue;
}

@Override
public int getMask() {
return mask;
}
public static MaskValueSet<DirectoryAccessMask> maskValueSet(final int mask) {
return MaskValueSet.maskValueSet(mask, values());
}

@Override
public int intValue() {
return this.maskingValue;
}
}
Loading

0 comments on commit 43b8d13

Please sign in to comment.