diff --git a/src/main/java/dev/dokan/dokan_java/DokanyUtils.java b/src/main/java/dev/dokan/dokan_java/DokanyUtils.java index bab5139..2c605c9 100644 --- a/src/main/java/dev/dokan/dokan_java/DokanyUtils.java +++ b/src/main/java/dev/dokan/dokan_java/DokanyUtils.java @@ -1,10 +1,15 @@ package dev.dokan.dokan_java; +import com.sun.jna.Pointer; +import com.sun.jna.Structure; import com.sun.jna.platform.win32.WinBase.FILETIME; +import dev.dokan.dokan_java.structure.DokanControl; import org.slf4j.Logger; import org.slf4j.LoggerFactory; +import java.util.ArrayList; import java.util.Date; +import java.util.List; import static com.sun.jna.platform.win32.WinError.*; import static dev.dokan.dokan_java.constants.microsoft.NtStatuses.*; @@ -55,6 +60,22 @@ public static boolean canHandleShutdownHooks() { } } + public static List getDokanControlList(Pointer start, long length) { + List list = new ArrayList<>(); + if(length == 0){ + return list; + }else if(length<0) { + //TODO length is actually an unsigned long! -> java always treats them as signed + return list; + }else { + list.add(new DokanControl(start)); + for(int i=1; i + * Used by {@link dev.dokan.dokan_java.NativeMethods#DokanGetMountPointList(boolean, LongByReference)} and {@link dev.dokan.dokan_java.NativeMethods#DokanReleaseMountPointList(Pointer)}. + */ +public class DokanControl extends Structure implements Structure.ByReference { + + /** + * File System Type + */ + public long Type; + + /** + * Mount point. Can be "M:\" (drive letter) or "C:\mount\dokan" (path in NTFS) + */ + public char[] MountPoint = new char[256]; + + /** + * UNC name used for network volume + */ + public char[] UNCName = new char[64]; + + /** + * Disk Device Name + */ + public char[] DeviceName = new char[64]; + + /** + * Volume Device Object + */ + public Pointer DeviceObject; + + /** + * Session ID of calling process + */ + public long SessionId; + + public DokanControl(Pointer p) { + this(p, 0); + } + + public DokanControl(Pointer p, long offset) { + super(p); + long currentOffset = offset; + this.Type = p.getLong(currentOffset); + currentOffset += NativeLong.SIZE; + this.MountPoint = p.getCharArray(currentOffset, WinNT.MAX_PATH); + currentOffset += WinNT.MAX_PATH * 2; + this.UNCName = p.getCharArray(currentOffset, 64); + currentOffset += 64 * 2; + this.DeviceName = p.getCharArray(currentOffset, 64); + currentOffset += 64 * 2; + this.DeviceObject = new Pointer(p.getLong(currentOffset)); + currentOffset += NativeLong.SIZE; + this.SessionId = p.getLong(currentOffset); + } + + + @Override + protected List getFieldOrder() { + return Arrays.asList("Type", "MountPoint", "UNCName", "DeviceName", "DeviceObject", "SessionId"); + } +}