forked from winfsp/winfsp
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathFileSystemHost.cs
1461 lines (1450 loc) · 54.3 KB
/
FileSystemHost.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
/*
* dotnet/FileSystemHost.cs
*
* Copyright 2015-2020 Bill Zissimopoulos
*/
/*
* This file is part of WinFsp.
*
* You can redistribute it and/or modify it under the terms of the GNU
* General Public License version 3 as published by the Free Software
* Foundation.
*
* Licensees holding a valid commercial license may use this software
* in accordance with the commercial license agreement provided in
* conjunction with the software. The terms and conditions of any such
* commercial license agreement shall govern, supersede, and render
* ineffective any application of the GPLv3 license to this software,
* notwithstanding of any reference thereto in the software or
* associated repository.
*/
using System;
using System.Runtime.InteropServices;
using System.Security.AccessControl;
using Fsp.Interop;
namespace Fsp
{
/// <summary>
/// Provides a means to host (mount) a file system.
/// </summary>
public class FileSystemHost : IDisposable
{
/* ctor/dtor */
/// <summary>
/// Creates an instance of the FileSystemHost class.
/// </summary>
/// <param name="FileSystem">The file system to host.</param>
public FileSystemHost(FileSystemBase FileSystem)
{
_VolumeParams.Version = (UInt16)Marshal.SizeOf(_VolumeParams);
_VolumeParams.Flags = VolumeParams.UmFileContextIsFullContext;
_FileSystem = FileSystem;
}
~FileSystemHost()
{
Dispose(false);
}
/// <summary>
/// Unmounts the file system and releases all associated resources.
/// </summary>
public void Dispose()
{
lock (this)
Dispose(true);
GC.SuppressFinalize(true);
}
protected virtual void Dispose(bool disposing)
{
if (IntPtr.Zero != _FileSystemPtr)
{
Api.FspFileSystemStopDispatcher(_FileSystemPtr);
if (disposing)
try
{
_FileSystem.Unmounted(this);
}
catch (Exception ex)
{
ExceptionHandler(_FileSystem, ex);
}
Api.DisposeUserContext(_FileSystemPtr);
Api.FspFileSystemDelete(_FileSystemPtr);
_FileSystemPtr = IntPtr.Zero;
}
}
/* properties */
/// <summary>
/// Gets or sets the sector size used by the file system.
/// </summary>
public UInt16 SectorSize
{
get { return _VolumeParams.SectorSize; }
set { _VolumeParams.SectorSize = value; }
}
/// <summary>
/// Gets or sets the sectors per allocation unit used by the file system.
/// </summary>
public UInt16 SectorsPerAllocationUnit
{
get { return _VolumeParams.SectorsPerAllocationUnit; }
set { _VolumeParams.SectorsPerAllocationUnit = value; }
}
/// <summary>
/// Gets or sets the maximum path component length used by the file system.
/// </summary>
public UInt16 MaxComponentLength
{
get { return _VolumeParams.MaxComponentLength; }
set { _VolumeParams.MaxComponentLength = value; }
}
/// <summary>
/// Gets or sets the volume creation time.
/// </summary>
public UInt64 VolumeCreationTime
{
get { return _VolumeParams.VolumeCreationTime; }
set { _VolumeParams.VolumeCreationTime = value; }
}
/// <summary>
/// Gets or sets the volume serial number.
/// </summary>
public UInt32 VolumeSerialNumber
{
get { return _VolumeParams.VolumeSerialNumber; }
set { _VolumeParams.VolumeSerialNumber = value; }
}
/// <summary>
/// Gets or sets the file information timeout.
/// </summary>
public UInt32 FileInfoTimeout
{
get { return _VolumeParams.FileInfoTimeout; }
set { _VolumeParams.FileInfoTimeout = value; }
}
/// <summary>
/// Gets or sets the volume information timeout.
/// </summary>
public UInt32 VolumeInfoTimeout
{
get
{
return 0 != (_VolumeParams.AdditionalFlags & VolumeParams.VolumeInfoTimeoutValid) ?
_VolumeParams.VolumeInfoTimeout : _VolumeParams.FileInfoTimeout;
}
set
{
_VolumeParams.AdditionalFlags |= VolumeParams.VolumeInfoTimeoutValid;
_VolumeParams.VolumeInfoTimeout = value;
}
}
/// <summary>
/// Gets or sets the directory information timeout.
/// </summary>
public UInt32 DirInfoTimeout
{
get
{
return 0 != (_VolumeParams.AdditionalFlags & VolumeParams.DirInfoTimeoutValid) ?
_VolumeParams.DirInfoTimeout : _VolumeParams.FileInfoTimeout;
}
set
{
_VolumeParams.AdditionalFlags |= VolumeParams.DirInfoTimeoutValid;
_VolumeParams.DirInfoTimeout = value;
}
}
/// <summary>
/// Gets or sets the security information timeout.
/// </summary>
public UInt32 SecurityTimeout
{
get
{
return 0 != (_VolumeParams.AdditionalFlags & VolumeParams.SecurityTimeoutValid) ?
_VolumeParams.SecurityTimeout : _VolumeParams.FileInfoTimeout;
}
set
{
_VolumeParams.AdditionalFlags |= VolumeParams.SecurityTimeoutValid;
_VolumeParams.SecurityTimeout = value;
}
}
/// <summary>
/// Gets or sets the stream information timeout.
/// </summary>
public UInt32 StreamInfoTimeout
{
get
{
return 0 != (_VolumeParams.AdditionalFlags & VolumeParams.StreamInfoTimeoutValid) ?
_VolumeParams.StreamInfoTimeout : _VolumeParams.FileInfoTimeout;
}
set
{
_VolumeParams.AdditionalFlags |= VolumeParams.StreamInfoTimeoutValid;
_VolumeParams.StreamInfoTimeout = value;
}
}
/// <summary>
/// Gets or sets the EA information timeout.
/// </summary>
public UInt32 EaTimeout
{
get
{
return 0 != (_VolumeParams.AdditionalFlags & VolumeParams.EaTimeoutValid) ?
_VolumeParams.EaTimeout : _VolumeParams.FileInfoTimeout;
}
set
{
_VolumeParams.AdditionalFlags |= VolumeParams.EaTimeoutValid;
_VolumeParams.EaTimeout = value;
}
}
/// <summary>
/// Gets or sets a value that determines whether the file system is case sensitive.
/// </summary>
public Boolean CaseSensitiveSearch
{
get { return 0 != (_VolumeParams.Flags & VolumeParams.CaseSensitiveSearch); }
set { _VolumeParams.Flags |= (value ? VolumeParams.CaseSensitiveSearch : 0); }
}
/// <summary>
/// Gets or sets a value that determines whether a case insensitive file system
/// preserves case in file names.
/// </summary>
public Boolean CasePreservedNames
{
get { return 0 != (_VolumeParams.Flags & VolumeParams.CasePreservedNames); }
set { _VolumeParams.Flags |= (value ? VolumeParams.CasePreservedNames : 0); }
}
/// <summary>
/// Gets or sets a value that determines whether file names support unicode characters.
/// </summary>
public Boolean UnicodeOnDisk
{
get { return 0 != (_VolumeParams.Flags & VolumeParams.UnicodeOnDisk); }
set { _VolumeParams.Flags |= (value ? VolumeParams.UnicodeOnDisk : 0); }
}
/// <summary>
/// Gets or sets a value that determines whether the file system supports ACL security.
/// </summary>
public Boolean PersistentAcls
{
get { return 0 != (_VolumeParams.Flags & VolumeParams.PersistentAcls); }
set { _VolumeParams.Flags |= (value ? VolumeParams.PersistentAcls : 0); }
}
/// <summary>
/// Gets or sets a value that determines whether the file system supports reparse points.
/// </summary>
public Boolean ReparsePoints
{
get { return 0 != (_VolumeParams.Flags & VolumeParams.ReparsePoints); }
set { _VolumeParams.Flags |= (value ? VolumeParams.ReparsePoints : 0); }
}
/// <summary>
/// Gets or sets a value that determines whether the file system allows creation of
/// symbolic links without additional privileges.
/// </summary>
public Boolean ReparsePointsAccessCheck
{
get { return 0 != (_VolumeParams.Flags & VolumeParams.ReparsePointsAccessCheck); }
set { _VolumeParams.Flags |= (value ? VolumeParams.ReparsePointsAccessCheck : 0); }
}
/// <summary>
/// Gets or sets a value that determines whether the file system supports named streams.
/// </summary>
public Boolean NamedStreams
{
get { return 0 != (_VolumeParams.Flags & VolumeParams.NamedStreams); }
set { _VolumeParams.Flags |= (value ? VolumeParams.NamedStreams : 0); }
}
/// <summary>
/// Gets or sets a value that determines whether the file system supports extended attributes.
/// </summary>
public Boolean ExtendedAttributes
{
get { return 0 != (_VolumeParams.Flags & VolumeParams.ExtendedAttributes); }
set { _VolumeParams.Flags |= (value ? VolumeParams.ExtendedAttributes : 0); }
}
public Boolean PostCleanupWhenModifiedOnly
{
get { return 0 != (_VolumeParams.Flags & VolumeParams.PostCleanupWhenModifiedOnly); }
set { _VolumeParams.Flags |= (value ? VolumeParams.PostCleanupWhenModifiedOnly : 0); }
}
public Boolean PassQueryDirectoryPattern
{
get { return 0 != (_VolumeParams.Flags & VolumeParams.PassQueryDirectoryPattern); }
set { _VolumeParams.Flags |= (value ? VolumeParams.PassQueryDirectoryPattern : 0); }
}
public Boolean PassQueryDirectoryFileName
{
get { return 0 != (_VolumeParams.Flags & VolumeParams.PassQueryDirectoryFileName); }
set { _VolumeParams.Flags |= (value ? VolumeParams.PassQueryDirectoryFileName : 0); }
}
public Boolean FlushAndPurgeOnCleanup
{
get { return 0 != (_VolumeParams.Flags & VolumeParams.FlushAndPurgeOnCleanup); }
set { _VolumeParams.Flags |= (value ? VolumeParams.FlushAndPurgeOnCleanup : 0); }
}
public Boolean DeviceControl
{
get { return 0 != (_VolumeParams.Flags & VolumeParams.DeviceControl); }
set { _VolumeParams.Flags |= (value ? VolumeParams.DeviceControl : 0); }
}
public Boolean AllowOpenInKernelMode
{
get { return 0 != (_VolumeParams.Flags & VolumeParams.AllowOpenInKernelMode); }
set { _VolumeParams.Flags |= (value ? VolumeParams.AllowOpenInKernelMode : 0); }
}
public Boolean WslFeatures
{
get { return 0 != (_VolumeParams.Flags & VolumeParams.WslFeatures); }
set { _VolumeParams.Flags |= (value ? VolumeParams.WslFeatures : 0); }
}
public Boolean RejectIrpPriorToTransact0
{
get { return 0 != (_VolumeParams.Flags & VolumeParams.RejectIrpPriorToTransact0); }
set { _VolumeParams.Flags |= (value ? VolumeParams.RejectIrpPriorToTransact0 : 0); }
}
/// <summary>
/// Gets or sets the prefix for a network file system.
/// </summary>
public String Prefix
{
get { return _VolumeParams.GetPrefix(); }
set { _VolumeParams.SetPrefix(value); }
}
/// <summary>
/// Gets or sets the file system name.
/// </summary>
public String FileSystemName
{
get { return _VolumeParams.GetFileSystemName(); }
set { _VolumeParams.SetFileSystemName(value); }
}
/* control */
/// <summary>
/// Checks whether mounting a file system is possible.
/// </summary>
/// <param name="MountPoint">
/// The mount point for the new file system. A value of null means that
/// the file system should use the next available drive letter counting
/// downwards from Z: as its mount point.
/// </param>
/// <returns>STATUS_SUCCESS or error code.</returns>
public Int32 Preflight(String MountPoint)
{
return Api.FspFileSystemPreflight(
_VolumeParams.IsPrefixEmpty() ? "WinFsp.Disk" : "WinFsp.Net",
MountPoint);
}
/// <summary>
/// Mounts a file system.
/// </summary>
/// <param name="MountPoint">
/// The mount point for the new file system. A value of null means that
/// the file system should use the next available drive letter counting
/// downwards from Z: as its mount point.
/// </param>
/// <param name="SecurityDescriptor">
/// Security descriptor to use if mounting on (newly created) directory.
/// A value of null means the directory should be created with default
/// security.
/// </param>
/// <param name="Synchronized">
/// If true file system operations are synchronized using an exclusive lock.
/// </param>
/// <param name="DebugLog">
/// A value of 0 disables all debug logging.
/// A value of -1 enables all debug logging.
/// </param>
/// <returns>STATUS_SUCCESS or error code.</returns>
public Int32 Mount(String MountPoint,
Byte[] SecurityDescriptor = null,
Boolean Synchronized = false,
UInt32 DebugLog = 0)
{
return MountEx(MountPoint, 0, SecurityDescriptor, Synchronized, DebugLog);
}
/// <summary>
/// Mounts a file system.
/// </summary>
/// <param name="MountPoint">
/// The mount point for the new file system. A value of null means that
/// the file system should use the next available drive letter counting
/// downwards from Z: as its mount point.
/// </param>
/// <param name="ThreadCount">
/// Number of threads to use to service file system requests. A value
/// of 0 means that the default number of threads should be used.
/// </param>
/// <param name="SecurityDescriptor">
/// Security descriptor to use if mounting on (newly created) directory.
/// A value of null means the directory should be created with default
/// security.
/// </param>
/// <param name="Synchronized">
/// If true file system operations are synchronized using an exclusive lock.
/// </param>
/// <param name="DebugLog">
/// A value of 0 disables all debug logging.
/// A value of -1 enables all debug logging.
/// </param>
/// <returns>STATUS_SUCCESS or error code.</returns>
public Int32 MountEx(String MountPoint,
UInt32 ThreadCount,
Byte[] SecurityDescriptor = null,
Boolean Synchronized = false,
UInt32 DebugLog = 0)
{
Int32 Result;
try
{
Result = _FileSystem.Init(this);
}
catch (Exception ex)
{
Result = ExceptionHandler(_FileSystem, ex);
}
if (0 > Result)
return Result;
Result = Api.FspFileSystemCreate(
_VolumeParams.IsPrefixEmpty() ? "WinFsp.Disk" : "WinFsp.Net",
ref _VolumeParams, _FileSystemInterfacePtr, out _FileSystemPtr);
if (0 > Result)
return Result;
Api.SetUserContext(_FileSystemPtr, _FileSystem);
Api.FspFileSystemSetOperationGuardStrategy(_FileSystemPtr, Synchronized ?
1/*FSP_FILE_SYSTEM_OPERATION_GUARD_STRATEGY_COARSE*/ :
0/*FSP_FILE_SYSTEM_OPERATION_GUARD_STRATEGY_FINE*/);
Api.FspFileSystemSetDebugLog(_FileSystemPtr, DebugLog);
Result = Api.FspFileSystemSetMountPointEx(_FileSystemPtr, MountPoint,
SecurityDescriptor);
if (0 <= Result)
{
try
{
Result = _FileSystem.Mounted(this);
}
catch (Exception ex)
{
Result = ExceptionHandler(_FileSystem, ex);
}
if (0 <= Result)
{
Result = Api.FspFileSystemStartDispatcher(_FileSystemPtr, ThreadCount);
if (0 > Result)
try
{
_FileSystem.Unmounted(this);
}
catch (Exception ex)
{
ExceptionHandler(_FileSystem, ex);
}
}
}
if (0 > Result)
{
Api.DisposeUserContext(_FileSystemPtr);
Api.FspFileSystemDelete(_FileSystemPtr);
_FileSystemPtr = IntPtr.Zero;
}
return Result;
}
/// <summary>
/// Unmounts the file system and releases all associated resources.
/// </summary>
public void Unmount()
{
Dispose();
}
/// <summary>
/// Gets the file system mount point.
/// </summary>
/// <returns>The file system mount point.</returns>
public String MountPoint()
{
return IntPtr.Zero != _FileSystemPtr ?
Marshal.PtrToStringUni(Api.FspFileSystemMountPoint(_FileSystemPtr)) : null;
}
public IntPtr FileSystemHandle()
{
return _FileSystemPtr;
}
/// <summary>
/// Gets the hosted file system.
/// </summary>
/// <returns>The hosted file system.</returns>
public FileSystemBase FileSystem()
{
return _FileSystem;
}
/// <summary>
/// Sets the debug log file to use when debug logging is enabled.
/// </summary>
/// <param name="FileName">
/// The debug log file name. A value of "-" means standard error output.
/// </param>
/// <returns>STATUS_SUCCESS or error code.</returns>
public static Int32 SetDebugLogFile(String FileName)
{
return Api.SetDebugLogFile(FileName);
}
/// <summary>
/// Return the installed version of WinFsp.
/// </summary>
public static Version Version()
{
return Api.GetVersion();
}
/// <summary>
/// Returns a RequestHint to reference the current operation asynchronously.
/// </summary>
public UInt64 GetOperationRequestHint()
{
return Api.FspFileSystemGetOperationRequestHint();
}
/// <summary>
/// Asynchronously complete a Read operation.
/// </summary>
/// <param name="RequestHint">
/// A reference to the operation to complete.
/// </param>
/// <param name="Status">
/// STATUS_SUCCESS or error code.
/// </param>
/// <param name="BytesTransferred">
/// Number of bytes read.
/// </param>
public void SendReadResponse(UInt64 RequestHint, Int32 Status, UInt32 BytesTransferred)
{
FspFsctlTransactRsp Response = default(FspFsctlTransactRsp);
Response.Size = 128;
Response.Kind = (UInt32)FspFsctlTransact.ReadKind;
Response.Hint = RequestHint;
Response.IoStatus.Information = BytesTransferred;
Response.IoStatus.Status = (UInt32)Status;
Api.FspFileSystemSendResponse(_FileSystemPtr, ref Response);
}
/// <summary>
/// Asynchronously complete a Write operation.
/// </summary>
/// <param name="RequestHint">
/// A reference to the operation to complete.
/// </param>
/// <param name="Status">
/// STATUS_SUCCESS or error code.
/// </param>
/// <param name="BytesTransferred">
/// The number of bytes written.
/// </param>
/// <param name="FileInfo">
/// Updated file information.
/// </param>
public void SendWriteResponse(UInt64 RequestHint, Int32 Status, UInt32 BytesTransferred, ref FileInfo FileInfo)
{
FspFsctlTransactRsp Response = default(FspFsctlTransactRsp);
Response.Size = 128;
Response.Kind = (UInt32)FspFsctlTransact.WriteKind;
Response.Hint = RequestHint;
Response.IoStatus.Information = BytesTransferred;
Response.IoStatus.Status = (UInt32)Status;
Response.WriteFileInfo = FileInfo;
Api.FspFileSystemSendResponse(_FileSystemPtr, ref Response);
}
/// <summary>
/// Asynchronously complete a ReadDirectory operation.
/// </summary>
/// <param name="RequestHint">
/// A reference to the operation to complete.
/// </param>
/// <param name="Status">
/// STATUS_SUCCESS or error code.
/// </param>
/// <param name="BytesTransferred">
/// Number of bytes read.
/// </param>
public void SendReadDirectoryResponse(UInt64 RequestHint, Int32 Status, UInt32 BytesTransferred)
{
FspFsctlTransactRsp Response = default(FspFsctlTransactRsp);
Response.Size = 128;
Response.Kind = (UInt32)FspFsctlTransact.QueryDirectoryKind;
Response.Hint = RequestHint;
Response.IoStatus.Information = BytesTransferred;
Response.IoStatus.Status = (UInt32)Status;
Api.FspFileSystemSendResponse(_FileSystemPtr, ref Response);
}
/// <summary>
/// Begin notifying Windows that the file system has file changes.
/// </summary>
/// <remarks>
/// <para>
/// A file system that wishes to notify Windows about file changes must
/// first issue an FspFileSystemBegin call, followed by 0 or more
/// FspFileSystemNotify calls, followed by an FspFileSystemNotifyEnd call.
/// </para><para>
/// This operation blocks concurrent file rename operations. File rename
/// operations may interfere with file notification, because a file being
/// notified may also be concurrently renamed. After all file change
/// notifications have been issued, you must make sure to call
/// FspFileSystemNotifyEnd to allow file rename operations to proceed.
/// </para>
/// </remarks>
/// <returns>
/// STATUS_SUCCESS or error code. The error code STATUS_CANT_WAIT means that
/// a file rename operation is currently in progress and the operation must be
/// retried at a later time.
/// </returns>
public Int32 NotifyBegin(UInt32 Timeout)
{
return Api.FspFileSystemNotifyBegin(_FileSystemPtr, Timeout);
}
/// <summary>
/// End notifying Windows that the file system has file changes.
/// </summary>
/// <remarks>
/// <para>
/// A file system that wishes to notify Windows about file changes must
/// first issue an FspFileSystemBegin call, followed by 0 or more
/// FspFileSystemNotify calls, followed by an FspFileSystemNotifyEnd call.
/// </para><para>
/// This operation allows any blocked file rename operations to proceed.
/// </para>
/// </remarks>
/// <returns>STATUS_SUCCESS or error code.</returns>
public Int32 NotifyEnd()
{
return Api.FspFileSystemNotifyEnd(_FileSystemPtr);
}
/// <summary>
/// Notify Windows that the file system has file changes.
/// </summary>
/// <remarks>
/// <para>
/// A file system that wishes to notify Windows about file changes must
/// first issue an FspFileSystemBegin call, followed by 0 or more
/// FspFileSystemNotify calls, followed by an FspFileSystemNotifyEnd call.
/// </para><para>
/// Note that FspFileSystemNotify requires file names to be normalized. A
/// normalized file name is one that contains the correct case of all characters
/// in the file name.
/// </para><para>
/// For case-sensitive file systems all file names are normalized by definition.
/// For case-insensitive file systems that implement file name normalization,
/// a normalized file name is the one that the file system specifies in the
/// response to Create or Open (see also FspFileSystemGetOpenFileInfo). For
/// case-insensitive file systems that do not implement file name normalization
/// a normalized file name is the upper case version of the file name used
/// to open the file.
/// </para>
/// </remarks>
/// <returns>STATUS_SUCCESS or error code.</returns>
public Int32 Notify(NotifyInfo[] NotifyInfoArray)
{
return Api.FspFileSystemNotify(_FileSystemPtr, NotifyInfoArray);
}
/* FSP_FILE_SYSTEM_INTERFACE */
private static Byte[] ByteBufferNotNull = new Byte[0];
private static Int32 ExceptionHandler(
FileSystemBase FileSystem,
Exception ex)
{
try
{
return FileSystem.ExceptionHandler(ex);
}
catch
{
return unchecked((Int32)0xc00000e9)/*STATUS_UNEXPECTED_IO_ERROR*/;
}
}
private static Int32 GetVolumeInfo(
IntPtr FileSystemPtr,
out VolumeInfo VolumeInfo)
{
FileSystemBase FileSystem = (FileSystemBase)Api.GetUserContext(FileSystemPtr);
try
{
return FileSystem.GetVolumeInfo(
out VolumeInfo);
}
catch (Exception ex)
{
VolumeInfo = default(VolumeInfo);
return ExceptionHandler(FileSystem, ex);
}
}
private static Int32 SetVolumeLabel(
IntPtr FileSystemPtr,
String VolumeLabel,
out VolumeInfo VolumeInfo)
{
FileSystemBase FileSystem = (FileSystemBase)Api.GetUserContext(FileSystemPtr);
try
{
return FileSystem.SetVolumeLabel(
VolumeLabel,
out VolumeInfo);
}
catch (Exception ex)
{
VolumeInfo = default(VolumeInfo);
return ExceptionHandler(FileSystem, ex);
}
}
private static Int32 GetSecurityByName(
IntPtr FileSystemPtr,
String FileName,
IntPtr PFileAttributes/* or ReparsePointIndex */,
IntPtr SecurityDescriptor,
IntPtr PSecurityDescriptorSize)
{
FileSystemBase FileSystem = (FileSystemBase)Api.GetUserContext(FileSystemPtr);
try
{
UInt32 FileAttributes;
Byte[] SecurityDescriptorBytes = null;
Int32 Result;
if (IntPtr.Zero != PSecurityDescriptorSize)
SecurityDescriptorBytes = ByteBufferNotNull;
Result = FileSystem.GetSecurityByName(
FileName,
out FileAttributes,
ref SecurityDescriptorBytes);
if (0 <= Result && 260/*STATUS_REPARSE*/ != Result)
{
if (IntPtr.Zero != PFileAttributes)
Marshal.WriteInt32(PFileAttributes, (Int32)FileAttributes);
Result = Api.CopySecurityDescriptor(SecurityDescriptorBytes,
SecurityDescriptor, PSecurityDescriptorSize);
}
return Result;
}
catch (Exception ex)
{
return ExceptionHandler(FileSystem, ex);
}
}
private static Int32 Create(
IntPtr FileSystemPtr,
String FileName,
UInt32 CreateOptions,
UInt32 GrantedAccess,
UInt32 FileAttributes,
IntPtr SecurityDescriptor,
UInt64 AllocationSize,
IntPtr ExtraBuffer,
UInt32 ExtraLength,
Boolean ExtraBufferIsReparsePoint,
ref FullContext FullContext,
ref OpenFileInfo OpenFileInfo)
{
FileSystemBase FileSystem = (FileSystemBase)Api.GetUserContext(FileSystemPtr);
try
{
Object FileNode, FileDesc;
String NormalizedName;
Int32 Result;
Result = FileSystem.CreateEx(
FileName,
CreateOptions,
GrantedAccess,
FileAttributes,
Api.MakeSecurityDescriptor(SecurityDescriptor),
AllocationSize,
ExtraBuffer,
ExtraLength,
ExtraBufferIsReparsePoint,
out FileNode,
out FileDesc,
out OpenFileInfo.FileInfo,
out NormalizedName);
if (0 <= Result)
{
if (null != NormalizedName)
OpenFileInfo.SetNormalizedName(NormalizedName);
Api.SetFullContext(ref FullContext, FileNode, FileDesc);
}
return Result;
}
catch (Exception ex)
{
return ExceptionHandler(FileSystem, ex);
}
}
private static Int32 Open(
IntPtr FileSystemPtr,
String FileName,
UInt32 CreateOptions,
UInt32 GrantedAccess,
ref FullContext FullContext,
ref OpenFileInfo OpenFileInfo)
{
FileSystemBase FileSystem = (FileSystemBase)Api.GetUserContext(FileSystemPtr);
try
{
Object FileNode, FileDesc;
String NormalizedName;
Int32 Result;
Result = FileSystem.Open(
FileName,
CreateOptions,
GrantedAccess,
out FileNode,
out FileDesc,
out OpenFileInfo.FileInfo,
out NormalizedName);
if (0 <= Result)
{
if (null != NormalizedName)
OpenFileInfo.SetNormalizedName(NormalizedName);
Api.SetFullContext(ref FullContext, FileNode, FileDesc);
}
return Result;
}
catch (Exception ex)
{
return ExceptionHandler(FileSystem, ex);
}
}
private static Int32 Overwrite(
IntPtr FileSystemPtr,
ref FullContext FullContext,
UInt32 FileAttributes,
Boolean ReplaceFileAttributes,
UInt64 AllocationSize,
IntPtr Ea,
UInt32 EaLength,
out FileInfo FileInfo)
{
FileSystemBase FileSystem = (FileSystemBase)Api.GetUserContext(FileSystemPtr);
try
{
Object FileNode, FileDesc;
Api.GetFullContext(ref FullContext, out FileNode, out FileDesc);
return FileSystem.OverwriteEx(
FileNode,
FileDesc,
FileAttributes,
ReplaceFileAttributes,
AllocationSize,
Ea,
EaLength,
out FileInfo);
}
catch (Exception ex)
{
FileInfo = default(FileInfo);
return ExceptionHandler(FileSystem, ex);
}
}
private static void Cleanup(
IntPtr FileSystemPtr,
ref FullContext FullContext,
String FileName,
UInt32 Flags)
{
FileSystemBase FileSystem = (FileSystemBase)Api.GetUserContext(FileSystemPtr);
try
{
Object FileNode, FileDesc;
Api.GetFullContext(ref FullContext, out FileNode, out FileDesc);
FileSystem.Cleanup(
FileNode,
FileDesc,
FileName,
Flags);
}
catch (Exception ex)
{
ExceptionHandler(FileSystem, ex);
}
}
private static void Close(
IntPtr FileSystemPtr,
ref FullContext FullContext)
{
FileSystemBase FileSystem = (FileSystemBase)Api.GetUserContext(FileSystemPtr);
try
{
Object FileNode, FileDesc;
Api.GetFullContext(ref FullContext, out FileNode, out FileDesc);
FileSystem.Close(
FileNode,
FileDesc);
Api.DisposeFullContext(ref FullContext);
}
catch (Exception ex)
{
ExceptionHandler(FileSystem, ex);
}
}
private static Int32 Read(
IntPtr FileSystemPtr,
ref FullContext FullContext,
IntPtr Buffer,
UInt64 Offset,
UInt32 Length,
out UInt32 PBytesTransferred)
{
FileSystemBase FileSystem = (FileSystemBase)Api.GetUserContext(FileSystemPtr);
try
{
Object FileNode, FileDesc;
Api.GetFullContext(ref FullContext, out FileNode, out FileDesc);
return FileSystem.Read(
FileNode,
FileDesc,
Buffer,
Offset,
Length,
out PBytesTransferred);
}
catch (Exception ex)
{
PBytesTransferred = default(UInt32);
return ExceptionHandler(FileSystem, ex);
}
}
private static Int32 Write(
IntPtr FileSystemPtr,
ref FullContext FullContext,
IntPtr Buffer,
UInt64 Offset,
UInt32 Length,
Boolean WriteToEndOfFile,
Boolean ConstrainedIo,
out UInt32 PBytesTransferred,
out FileInfo FileInfo)
{
FileSystemBase FileSystem = (FileSystemBase)Api.GetUserContext(FileSystemPtr);
try
{
Object FileNode, FileDesc;
Api.GetFullContext(ref FullContext, out FileNode, out FileDesc);
return FileSystem.Write(
FileNode,
FileDesc,
Buffer,
Offset,
Length,
WriteToEndOfFile,
ConstrainedIo,
out PBytesTransferred,
out FileInfo);
}
catch (Exception ex)
{
PBytesTransferred = default(UInt32);
FileInfo = default(FileInfo);
return ExceptionHandler(FileSystem, ex);
}
}
private static Int32 Flush(
IntPtr FileSystemPtr,
ref FullContext FullContext,
out FileInfo FileInfo)
{
FileSystemBase FileSystem = (FileSystemBase)Api.GetUserContext(FileSystemPtr);
try
{
Object FileNode, FileDesc;
Api.GetFullContext(ref FullContext, out FileNode, out FileDesc);
return FileSystem.Flush(
FileNode,
FileDesc,
out FileInfo);
}
catch (Exception ex)
{
FileInfo = default(FileInfo);
return ExceptionHandler(FileSystem, ex);
}
}
private static Int32 GetFileInfo(
IntPtr FileSystemPtr,
ref FullContext FullContext,
out FileInfo FileInfo)
{
FileSystemBase FileSystem = (FileSystemBase)Api.GetUserContext(FileSystemPtr);
try
{
Object FileNode, FileDesc;
Api.GetFullContext(ref FullContext, out FileNode, out FileDesc);
return FileSystem.GetFileInfo(
FileNode,
FileDesc,
out FileInfo);
}
catch (Exception ex)
{
FileInfo = default(FileInfo);
return ExceptionHandler(FileSystem, ex);
}
}
private static Int32 SetBasicInfo(
IntPtr FileSystemPtr,
ref FullContext FullContext,
UInt32 FileAttributes,
UInt64 CreationTime,
UInt64 LastAccessTime,
UInt64 LastWriteTime,