Skip to content

Commit e67b7af

Browse files
committed
Fix #384
This commit brings DokanOptions flags up to date and in sync with changes in native library. * The EnableNotificationAPI is no longer necessary and has been removed, just like in native library. * Several DokanOptions flag values have changed, rebuilt implementations to get the correct values! * Added missing DokanOptions.AllowIpcBatching
1 parent 048824d commit e67b7af

File tree

5 files changed

+71
-68
lines changed

5 files changed

+71
-68
lines changed

DokanNet/Dokan.cs

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -66,8 +66,7 @@ public bool RemoveMountPoint(string mountPoint)
6666
/// <summary>
6767
/// Dokan User FS file-change notifications
6868
/// </summary>
69-
/// <remarks> If <see cref="DokanOptions.EnableNotificationAPI"/> is passed to <see cref="DOKAN_OPTIONS.Options"/>,
70-
/// the application implementing the user file system can notify
69+
/// <remarks>The application implementing the user file system can notify
7170
/// the Dokan kernel driver of external file- and directory-changes.
7271
///
7372
/// For example, the mirror application can notify the driver about
@@ -102,7 +101,6 @@ public static bool Create(DokanInstance dokanInstance, string filePath, bool isD
102101
/// <param name="filePath">Absolute path to the file or directory, including the mount-point of the file system.</param>
103102
/// <param name="isDirectory">Indicates if the path is a directory.</param>
104103
/// <returns>true if notification succeeded.</returns>
105-
/// <remarks><see cref="DokanOptions.EnableNotificationAPI"/> must be set in the mount options for this to succeed.</remarks>
106104
public static bool Delete(DokanInstance dokanInstance, string filePath, bool isDirectory)
107105
{
108106
return dokanInstance.NotifyDelete(filePath, isDirectory);
@@ -114,7 +112,6 @@ public static bool Delete(DokanInstance dokanInstance, string filePath, bool isD
114112
/// <param name="dokanInstance">The dokan mount context created by <see cref="DokanInstance.DokanInstance"/></param>
115113
/// <param name="filePath">Absolute path to the file or directory, including the mount-point of the file system.</param>
116114
/// <returns>true if notification succeeded.</returns>
117-
/// <remarks><see cref="DokanOptions.EnableNotificationAPI"/> must be set in the mount options for this to succeed.</remarks>
118115
public static bool Update(DokanInstance dokanInstance, string filePath)
119116
{
120117
return dokanInstance.NotifyUpdate(filePath);
@@ -126,7 +123,6 @@ public static bool Update(DokanInstance dokanInstance, string filePath)
126123
/// <param name="dokanInstance">The dokan mount context created by <see cref="DokanInstance.DokanInstance"/></param>
127124
/// <param name="filePath">Absolute path to the file or directory, including the mount-point of the file system.</param>
128125
/// <returns>true if notification succeeded.</returns>
129-
/// <remarks><see cref="DokanOptions.EnableNotificationAPI"/> must be set in the mount options for this to succeed.</remarks>
130126
public static bool XAttrUpdate(DokanInstance dokanInstance, string filePath)
131127
{
132128
return dokanInstance.NotifyXAttrUpdate(filePath);
@@ -142,7 +138,6 @@ public static bool XAttrUpdate(DokanInstance dokanInstance, string filePath)
142138
/// <param name="isDirectory">Indicates if the path is a directory.</param>
143139
/// <param name="isInSameDirectory">Indicates if the file or directory have the same parent directory.</param>
144140
/// <returns>true if notification succeeded.</returns>
145-
/// <remarks><see cref="DokanOptions.EnableNotificationAPI"/> must be set in the mount options for this to succeed.</remarks>
146141
public static bool Rename(DokanInstance dokanInstance, string oldPath, string newPath, bool isDirectory, bool isInSameDirectory)
147142
{
148143
return dokanInstance.NotifyRename(oldPath,

DokanNet/DokanInstance.cs

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -166,7 +166,6 @@ public bool NotifyCreate(string filePath, bool isDirectory)
166166
/// <param name="filePath">Absolute path to the file or directory, including the mount-point of the file system.</param>
167167
/// <param name="isDirectory">Indicates if the path is a directory.</param>
168168
/// <returns>true if notification succeeded.</returns>
169-
/// <remarks><see cref="DokanOptions.EnableNotificationAPI"/> must be set in the mount options for this to succeed.</remarks>
170169
public bool NotifyDelete(string filePath, bool isDirectory)
171170
{
172171
return NativeMethods.DokanNotifyDelete(DokanHandle, filePath, isDirectory);
@@ -177,7 +176,6 @@ public bool NotifyDelete(string filePath, bool isDirectory)
177176
/// </summary>
178177
/// <param name="filePath">Absolute path to the file or directory, including the mount-point of the file system.</param>
179178
/// <returns>true if notification succeeded.</returns>
180-
/// <remarks><see cref="DokanOptions.EnableNotificationAPI"/> must be set in the mount options for this to succeed.</remarks>
181179
public bool NotifyUpdate(string filePath)
182180
{
183181
return NativeMethods.DokanNotifyUpdate(DokanHandle, filePath);
@@ -188,7 +186,6 @@ public bool NotifyUpdate(string filePath)
188186
/// </summary>
189187
/// <param name="filePath">Absolute path to the file or directory, including the mount-point of the file system.</param>
190188
/// <returns>true if notification succeeded.</returns>
191-
/// <remarks><see cref="DokanOptions.EnableNotificationAPI"/> must be set in the mount options for this to succeed.</remarks>
192189
public bool NotifyXAttrUpdate(string filePath)
193190
{
194191
return NativeMethods.DokanNotifyXAttrUpdate(DokanHandle, filePath);
@@ -203,7 +200,6 @@ public bool NotifyXAttrUpdate(string filePath)
203200
/// <param name="isDirectory">Indicates if the path is a directory.</param>
204201
/// <param name="isInSameDirectory">Indicates if the file or directory have the same parent directory.</param>
205202
/// <returns>true if notification succeeded.</returns>
206-
/// <remarks><see cref="DokanOptions.EnableNotificationAPI"/> must be set in the mount options for this to succeed.</remarks>
207203
public bool NotifyRename(string oldPath, string newPath, bool isDirectory, bool isInSameDirectory)
208204
{
209205
return NativeMethods.DokanNotifyRename(DokanHandle, oldPath,

DokanNet/DokanOptions.cs

Lines changed: 64 additions & 52 deletions
Original file line numberDiff line numberDiff line change
@@ -1,70 +1,82 @@
11
using System;
2+
using System.Drawing;
23
using DokanNet.Native;
34

4-
namespace DokanNet
5+
namespace DokanNet;
6+
7+
/// <summary>
8+
/// Dokan mount options used to describe dokan device behavior.
9+
/// </summary>
10+
/// \if PRIVATE
11+
/// <seealso cref="DOKAN_OPTIONS.Options"/>
12+
/// \endif
13+
[Flags]
14+
public enum DokanOptions : uint
515
{
6-
/// <summary>
7-
/// Dokan mount options used to describe dokan device behavior.
8-
/// </summary>
9-
/// \if PRIVATE
10-
/// <seealso cref="DOKAN_OPTIONS.Options"/>
11-
/// \endif
12-
[Flags]
13-
public enum DokanOptions : uint
14-
{
15-
/// <summary>Fixed Drive.</summary>
16-
FixedDrive = 0,
16+
/// <summary>Fixed Drive.</summary>
17+
FixedDrive = 0,
1718

18-
/// <summary>Enable output debug message.</summary>
19-
DebugMode = 1,
19+
/// <summary>Enable output debug message.</summary>
20+
DebugMode = 1,
2021

21-
/// <summary>Enable output debug message to stderr.</summary>
22-
StderrOutput = 2,
22+
/// <summary>Enable output debug message to stderr.</summary>
23+
StderrOutput = (1 << 1),
2324

24-
/// <summary>Use alternate stream.</summary>
25-
AltStream = 4,
25+
/// <summary>Enable the use of alternate stream paths in the form
26+
/// [file-name]:[stream-name]. If this is not specified then the driver will
27+
/// fail any attempt to access a path with a colon.</summary>
28+
AltStream = (1 << 2),
2629

27-
/// <summary>Enable mount drive as write-protected.</summary>
28-
WriteProtection = 8,
30+
/// <summary>Enable mount drive as write-protected.</summary>
31+
WriteProtection = (1 << 3),
2932

30-
/// <summary>Use network drive - Dokan network provider need to be installed.</summary>
31-
NetworkDrive = 16,
33+
/// <summary>Use network drive - Dokan network provider needs to be installed and a \ref DOKAN_OPTIONS.UNCName provided.</summary>
34+
NetworkDrive = (1 << 4),
3235

33-
/// <summary>Use removable drive.</summary>
34-
RemovableDrive = 32,
36+
/// <summary>Use removable drive
37+
/// Be aware that on some environments, the userland application will be denied
38+
/// to communicate with the drive which will result in a unwanted unmount.
39+
/// <a href="https://github.com/dokan-dev/dokany/issues/843">Issue #843</a>.</summary>
40+
RemovableDrive = (1 << 5),
3541

36-
/// <summary>Use mount manager.</summary>
37-
MountManager = 64,
42+
/// <summary>Use Windows Mount Manager.
43+
/// This option is highly recommended to use for better system integration
44+
/// If a drive letter is used but is busy, Mount manager will assign one for us and
45+
/// <see cref="IDokanOperations2.Mounted" /> parameters will contain the new mount point.</summary>
46+
MountManager = (1 << 6),
3847

39-
/// <summary>Mount the drive on current session only.</summary>
40-
CurrentSession = 128,
48+
/// <summary>Mount the drive on current session only
49+
/// Note: As Windows process only have on sessionID which is here used to define what is the current session,
50+
/// impersonation will not work if someone attend to mount for a user from another one (like system service).
51+
/// <a href="https://github.com/dokan-dev/dokany/issues/1196">Issue #1196</a>.</summary>
52+
CurrentSession = (1 << 7),
4153

42-
/// <summary>Enable Lockfile/Unlockfile operations.</summary>
43-
UserModeLock = 256,
54+
/// <summary>Enable Lockfile/Unlockfile operations. Otherwise Dokan will take care of it.</summary>
55+
UserModeLock = (1 << 8),
4456

45-
/// <summary>
46-
/// Enable methods in <see cref="Dokan.Notify"/>, which require this library to maintain a special
47-
/// handle while the file system is mounted.
48-
/// Without this flag, the methods in that inner class always return false if invoked.
49-
/// </summary>
50-
EnableNotificationAPI = 512,
57+
/// <summary>
58+
/// Enable Case sensitive path.
59+
/// By default all path are case insensitive.
60+
/// For case sensitive: \\dir\\File and \\diR\\file are different files
61+
/// but for case insensitive they are the same.
62+
/// </summary>
63+
CaseSensitive = (1 << 9),
5164

52-
/// <summary>
53-
/// Enable Case sensitive path.
54-
/// By default all path are case insensitive.
55-
/// For case sensitive: \\dir\\File and \\diR\\file are different files
56-
/// but for case insensitive they are the same.
57-
/// </summary>
58-
CaseSensitive = 1024,
65+
/// <summary>
66+
/// Allows unmounting of network drive via explorer
67+
/// </summary>
68+
EnableNetworkUnmount = (1 << 10),
5969

60-
/// <summary>
61-
/// Enables unmounting of network drives via file explorer
62-
/// </summary>
63-
EnableNetworkUnmount = 2048,
70+
/// <summary>
71+
/// Forward the kernel driver global and volume logs to the userland.
72+
/// Can be very slow if single thread is enabled.
73+
/// </summary>
74+
DispatchDriverLogs = (1 << 11),
6475

65-
/// <summary>
66-
/// Forward the kernel driver global and volume logs to the userland
67-
/// </summary>
68-
DispatchDriverLogs = 4096,
69-
}
76+
/// <summary>
77+
/// Pull batches of events from the driver instead of a single one and execute them parallelly.
78+
/// This option should only be used on computers with low cpu count
79+
/// and userland filesystem taking time to process requests (like remote storage).
80+
/// </summary>
81+
AllowIpcBatching = (1 << 12),
7082
}

sample/DokanNetMirror/Program.cs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -51,15 +51,15 @@ private static async Task Main(string[] args)
5151
.ConfigureLogger(() => dokanLogger)
5252
.ConfigureOptions(options =>
5353
{
54-
options.Options = DokanNet.DokanOptions.DebugMode | DokanNet.DokanOptions.EnableNotificationAPI;
54+
options.Options = DokanNet.DokanOptions.DebugMode;
5555
options.MountPoint = mountPath;
5656
});
5757

5858
using var dokanInstance = dokanBuilder.Build(mirror);
59-
59+
6060
using var notify = new Notify(mirrorPath, mountPath, dokanInstance);
61-
62-
Console.CancelKeyPress += (object? sender, ConsoleCancelEventArgs e) =>
61+
62+
Console.CancelKeyPress += (sender, e) =>
6363
{
6464
e.Cancel = true;
6565

sample/DokanNetMirrorLegacy/Program.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -48,12 +48,12 @@ private static async Task Main(string[] args)
4848
.ConfigureLogger(() => dokanLogger)
4949
.ConfigureOptions(options =>
5050
{
51-
options.Options = DokanOptions.DebugMode | DokanOptions.EnableNotificationAPI;
51+
options.Options = DokanOptions.DebugMode;
5252
options.MountPoint = mountPath;
5353
});
5454
using var dokanInstance = dokanBuilder.Build(mirror);
5555
using var notify = new Notify(mirrorPath, mountPath, dokanInstance);
56-
Console.CancelKeyPress += (object? sender, ConsoleCancelEventArgs e) =>
56+
Console.CancelKeyPress += (sender, e) =>
5757
{
5858
e.Cancel = true;
5959
dokan.RemoveMountPoint(mountPath);

0 commit comments

Comments
 (0)