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

Implementing the "Easy"-Dokan-API #35

Draft
wants to merge 35 commits into
base: develop
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
35 commits
Select commit Hold shift + click to select a range
665adea
Made isImplemented()-method public
JaniruTEC May 2, 2020
97bb432
Re-added API for conversion from FileTime to FILETIME
JaniruTEC May 2, 2020
670147d
Merge pull request #1 from JaniruTEC/jt-develop
JaniruTEC May 2, 2020
ecda6a6
Updated README.md with info about versioning
JaniruTEC May 4, 2020
64f66e4
Added multiple Enums to wrap native bitmasks
JaniruTEC May 5, 2020
caf890c
Added FileInfo-API
JaniruTEC May 7, 2020
495e9cd
Readded VolumeInformation
JaniruTEC May 7, 2020
c07a563
Moved VolumeInformation
JaniruTEC May 7, 2020
a11aa0e
Removed misplaced license templates
JaniruTEC May 8, 2020
fb4489b
Added DesiredAccessMask and DiskSpaceInfo
JaniruTEC May 9, 2020
08b9e89
Added Filesystem and Handle
JaniruTEC May 14, 2020
0b9450c
Fixed typos/unfinished renaming of classes in EasyDokanyFileSystem
JaniruTEC May 14, 2020
74ff4eb
Merge branch 'develop'
JaniruTEC May 21, 2020
5204c3b
Unified naming-scheme of wrapper-classes
JaniruTEC May 22, 2020
45fe7a3
Unified naming scheme
JaniruTEC May 22, 2020
01e50b1
Renamed DokanyFileHandle to DokanFileHandle
JaniruTEC May 23, 2020
ff1d27e
Renamed EasyDokanyFileSystem to EasyDokanFileSystem
JaniruTEC May 23, 2020
9646e1a
Renamed SecurityContext to EasyDokanIOSecurityContext
JaniruTEC May 23, 2020
562e0b4
Merge remote-tracking branch 'upstream/develop'
JaniruTEC May 24, 2020
817b87f
Merge remote-tracking branch 'upstream/develop'
JaniruTEC May 26, 2020
317ad69
Added overloaded constructor to DokanOptions to allow an int as Options
JaniruTEC May 28, 2020
e600a8f
Added MountInfo-API
JaniruTEC May 28, 2020
461777d
Merge remote-tracking branch 'upstream/develop'
JaniruTEC May 28, 2020
98e1497
Added last basic API-Classes
JaniruTEC May 28, 2020
13a5054
Merge remote-tracking branch 'upstream/develop'
JaniruTEC Jun 2, 2020
bbc2004
Fixed issues that arose from merging
JaniruTEC Jun 2, 2020
bffbce0
Improved support for generic/non-MS ReparsePointTags
JaniruTEC Jun 3, 2020
8ba91fd
Updated DokanFileHandle to use ROMountInfo and added missing method
JaniruTEC Jun 8, 2020
37eb216
Added check if only a single bit (flag) is set
JaniruTEC Jun 9, 2020
31330ab
Added check if only a single bit (flag) is set to updateFlag
JaniruTEC Jun 9, 2020
2ef3c1e
Merge remote-tracking branch 'upstream/develop'
JaniruTEC Jun 18, 2020
5736a1a
Merge branch 'develop'
JaniruTEC Jun 18, 2020
72296c4
Adopted changes of AccessMaskFlags to DesiredAccessMask
JaniruTEC Jun 18, 2020
05c1c39
Moved support for Basic Rights to a new base class
JaniruTEC Jun 18, 2020
a163954
Merge remote-tracking branch 'upstream/develop'
JaniruTEC Jul 2, 2020
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
9 changes: 9 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,15 @@ To publish to your local Maven repository, execute as the third step `./gradlew.
## Examples
An example user filesystems using this library can be found in the examples package [dev.dokan.dokan_java.examples](https://github.com/dokan-dev/dokan-java/tree/develop/src/main/java/dev/dokan/dokan_java/examples).

## Versioning
Dokan-Java uses it's own versioning system and therefore doesn't match the versions of Dokany.
For Dokan-Java to work you need to have a suitable version of Dokany installed on your machine. The following table helps you choose the correct Dokany-version.

| Dokan-Java Version | Minimum Version of Dokany |
|--------------------|---------------------------|
| 1.0.0 - 1.1.X | 1.2.0.1000 |
| 1.2.0+ | 1.3.0.1000 |

## Contributing
You're encouraged to contribute.
Fork the code and then submit a pull request.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,7 @@ private void init(DokanOperations dokanOperations) {
}
}

private boolean isImplemented(String funcName) {
public boolean isImplemented(String funcName) {
return !notImplementedMethods.contains(funcName);
}

Expand Down
5 changes: 5 additions & 0 deletions src/main/java/dev/dokan/dokan_java/DokanUtils.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import com.sun.jna.platform.win32.WinNT;
import dev.dokan.dokan_java.constants.microsoft.CreationDisposition;

import java.nio.file.attribute.FileTime;
import java.util.Date;

import static dev.dokan.dokan_java.constants.microsoft.CreateDispositions.*;
Expand Down Expand Up @@ -38,6 +39,10 @@ public static String trimStrToSize(final String str, final int len) {
return str.substring(0, Math.min(str.length(), len));
}

public static FILETIME toFILETIME(final FileTime time) {
return getTime(time.toMillis());
}

public static FILETIME getTime(final Date date) {
return new FILETIME(date);
}
Expand Down
15 changes: 15 additions & 0 deletions src/main/java/dev/dokan/dokan_java/NativeName.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
package dev.dokan.dokan_java;

import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;

import static java.lang.annotation.ElementType.METHOD;

@Retention(RetentionPolicy.RUNTIME)
@Target(value = METHOD)
public @interface NativeName {

String value();

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
package dev.dokan.dokan_java.constants.dokan_java;

public enum DefaultFileTimePolicy {

STATIC_YEAR_1601,
STATIC_YEAR_1970,
INHERIT_ELSE_1601,
INHERIT_ELSE_1970

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


import dev.dokan.dokan_java.masking.MaskValueEnum;
import dev.dokan.dokan_java.masking.MaskValueSet;

public enum DokanFileInfoFlag implements MaskValueEnum {

DELETE_ON_CLOSE(1),
IS_DIRECTORY(2),
NO_CACHE(4),
PAGING_IO(8),
SYNCHRONOUS_IO(16),
WRITE_TO_END_OF_FILE(32);

private final int maskingValue;

DokanFileInfoFlag(int maskingValue) {
this.maskingValue = maskingValue;
}

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

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


import dev.dokan.dokan_java.masking.MaskValueEnum;
import dev.dokan.dokan_java.masking.MaskValueSet;

public enum FileShareAccess implements MaskValueEnum {

FILE_SHARE_READ(1),
FILE_SHARE_WRITE(2),
FILE_SHARE_DELETE(4);

private final int maskingValue;

FileShareAccess(int maskingValue) {
this.maskingValue = maskingValue;
}

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

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


import dev.dokan.dokan_java.masking.EnumInteger;
import dev.dokan.dokan_java.structure.ReparsePointTag;


public enum MicrosoftReparsePointTag implements ReparsePointTag {

IO_REPARSE_TAG_CSV(0x80000009),
IO_REPARSE_TAG_DEDUP(0x80000013),
IO_REPARSE_TAG_DFS(0x8000000A),
IO_REPARSE_TAG_DFSR(0x80000012),
IO_REPARSE_TAG_HSM(0xC0000004),
IO_REPARSE_TAG_HSM2(0x80000006),
IO_REPARSE_TAG_MOUNT_POINT(0xA0000003),
IO_REPARSE_TAG_NFS(0x80000014),
IO_REPARSE_TAG_SIS(0x80000007),
IO_REPARSE_TAG_SYMLINK(0xA000000C),
IO_REPARSE_TAG_WIM(0x80000008);

private static final String SOURCE = "WinNT.h";
private static final String DEFINED_BY = "Microsoft";

private final int intValue;

MicrosoftReparsePointTag(int intValue) {
this.intValue = intValue;
}

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

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

@Override
public String getSource() {
return SOURCE;
}

@Override
public String getDefinedBy() {
return DEFINED_BY;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -79,9 +79,13 @@ public DokanOptions() {
}

public DokanOptions(String mountPoint, @Unsigned short threadCount, MaskValueSet<MountOption> mountOptions, String uncName, @Unsigned int timeout, @Unsigned int allocationUnitSize, @Unsigned int sectorSize) {
this(mountPoint, threadCount, mountOptions.intValue(), uncName, timeout, allocationUnitSize, sectorSize);
}

public DokanOptions(String mountPoint, @Unsigned short threadCount, @Unsigned int mountOptions, String uncName, @Unsigned int timeout, @Unsigned int allocationUnitSize, @Unsigned int sectorSize) {
MountPoint = new WString(mountPoint);
ThreadCount = threadCount;
Options = mountOptions.intValue();
Options = mountOptions;
if (uncName != null) {
UNCName = new WString(uncName);
} else {
Expand Down
13 changes: 13 additions & 0 deletions src/main/java/dev/dokan/dokan_java/structure/ReparsePointTag.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
package dev.dokan.dokan_java.structure;


import dev.dokan.dokan_java.masking.EnumInteger;


public interface ReparsePointTag extends EnumInteger {

String getSource();

String getDefinedBy();

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
package dev.dokan.dokan_java.wrappers;

import dev.dokan.dokan_java.NativeName;
import dev.dokan.dokan_java.FileSystemInformation;
import dev.dokan.dokan_java.NotImplemented;

import java.lang.annotation.Annotation;
import java.lang.reflect.Method;
import java.util.Arrays;
import java.util.Set;
import java.util.stream.Collectors;

public abstract class AbstractEasyDokanFileSystem implements EasyDokanFileSystem {

private final Set<String> notImplementedMethods;
private final ForwardingFileSystem lowLevelFS;

public AbstractEasyDokanFileSystem(FileSystemInformation fileSystemInformation) {
this.notImplementedMethods = Arrays.stream(getClass().getMethods())
.filter(method -> method.getAnnotation(NotImplemented.class) != null)
.map((method) -> getNativeName(method))
.collect(Collectors.toSet());

this.lowLevelFS = new ForwardingFileSystem(fileSystemInformation, this.notImplementedMethods, this);
}

private String getNativeName(Method method) {
Method annotated = getAnnotatedMethod(NativeName.class, method);

if(annotated == null) {
return method.getName();
}
return annotated.getAnnotation(NativeName.class).value();
}

private Method getAnnotatedMethod(Class<? extends Annotation> annotation, Method method) {
return getAnnotatedMethod(annotation, method.getDeclaringClass(), method.getName(), method.getParameterTypes());
}

private Method getAnnotatedMethod(Class<? extends Annotation> annotation,
Class<?> inClass,
String methodName,
Class<?>... parameterTypes) {

Method result;
try {
result = inClass.getMethod(methodName, parameterTypes);
} catch(NoSuchMethodException e) {
return null;
}

if(result.isAnnotationPresent(annotation)) {
return result;
}

Class<?> superClass = inClass.getSuperclass();
if(superClass != null) {
result = getAnnotatedMethod(annotation, superClass, methodName, parameterTypes);
}

if(result != null) {
return result;
}

return Arrays.stream(inClass.getInterfaces())
.map((cInterface) -> getAnnotatedMethod(annotation, cInterface, methodName, parameterTypes))
.findFirst().orElse(null);
}
}
Loading