forked from winfsp/winfsp
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathFileSystemBase.cs
1488 lines (1479 loc) · 56.6 KB
/
FileSystemBase.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/FileSystemBase.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 the base class that user mode file systems must inherit from.
/// </summary>
public partial class FileSystemBase
{
/* types */
public class DirectoryBuffer : IDisposable
{
~DirectoryBuffer()
{
Dispose(false);
}
public void Dispose()
{
lock (this)
Dispose(true);
GC.SuppressFinalize(true);
}
protected virtual void Dispose(bool disposing)
{
Api.FspFileSystemDeleteDirectoryBuffer(ref DirBuffer);
}
internal IntPtr DirBuffer;
}
/* operations */
/// <summary>
/// Provides a means to customize the returned status code when an exception happens.
/// </summary>
/// <param name="ex"></param>
/// <returns>STATUS_SUCCESS or error code.</returns>
public virtual Int32 ExceptionHandler(Exception ex)
{
Api.FspDebugLog("%s\n", ex.ToString());
return STATUS_UNEXPECTED_IO_ERROR;
}
/// <summary>
/// Occurs just before the file system is mounted.
/// File systems may override this method to configure the file system host.
/// </summary>
/// <param name="Host">
/// The file system host that is mounting this file system.
/// </param>
/// <returns>STATUS_SUCCESS or error code.</returns>
public virtual Int32 Init(Object Host)
{
return STATUS_SUCCESS;
}
/// <summary>
/// Occurs just after the file system is mounted,
/// but prior to receiving any file system operation.
/// </summary>
/// <param name="Host">
/// The file system host that is mounting this file system.
/// </param>
/// <returns>STATUS_SUCCESS or error code.</returns>
public virtual Int32 Mounted(Object Host)
{
return STATUS_SUCCESS;
}
/// <summary>
/// Occurs just after the file system is unmounted.
/// No other file system operations will be received on this file system.
/// </summary>
/// <param name="Host">
/// The file system host that is mounting this file system.
/// </param>
public virtual void Unmounted(Object Host)
{
}
/// <summary>
/// Gets the volume information.
/// </summary>
/// <param name="VolumeInfo">
/// Receives the volume information.
/// </param>
/// <returns>STATUS_SUCCESS or error code.</returns>
public virtual Int32 GetVolumeInfo(
out VolumeInfo VolumeInfo)
{
VolumeInfo = default(VolumeInfo);
return STATUS_INVALID_DEVICE_REQUEST;
}
/// <summary>
/// Sets the volume label.
/// </summary>
/// <param name="VolumeLabel">
/// The new label for the volume.
/// </param>
/// <param name="VolumeInfo">
/// Receives the updated volume information.
/// </param>
/// <returns>STATUS_SUCCESS or error code.</returns>
public virtual Int32 SetVolumeLabel(
String VolumeLabel,
out VolumeInfo VolumeInfo)
{
VolumeInfo = default(VolumeInfo);
return STATUS_INVALID_DEVICE_REQUEST;
}
/// <summary>
/// Gets file or directory attributes and security descriptor given a file name.
/// </summary>
/// <param name="FileName">
/// The name of the file or directory to get the attributes and security descriptor for.
/// </param>
/// <param name="FileAttributes">
/// Receives the file attributes on successful return.
/// If this call returns STATUS_REPARSE, the file system may place here the index of the
/// first reparse point within FileName.
/// </param>
/// <param name="SecurityDescriptor">
/// Receives the file security descriptor. If the SecurityDescriptor parameter is null
/// on input the file system should not fill this value.
/// </param>
/// <returns>
/// STATUS_SUCCESS, STATUS_REPARSE or error code.
/// STATUS_REPARSE should be returned by file systems that support reparse points when
/// they encounter a FileName that contains reparse points anywhere but the final path
/// component.
/// </returns>
public virtual Int32 GetSecurityByName(
String FileName,
out UInt32 FileAttributes/* or ReparsePointIndex */,
ref Byte[] SecurityDescriptor)
{
FileAttributes = default(UInt32);
return STATUS_INVALID_DEVICE_REQUEST;
}
/// <summary>
/// Creates a new file or directory.
/// </summary>
/// <param name="FileName">
/// The name of the file or directory to be created.
/// </param>
/// <param name="CreateOptions">
/// Create options for this request.
/// </param>
/// <param name="GrantedAccess">
/// Determines the specific access rights that have been granted for this request.
/// </param>
/// <param name="FileAttributes">
/// File attributes to apply to the newly created file or directory.
/// </param>
/// <param name="SecurityDescriptor">
/// Security descriptor to apply to the newly created file or directory.
/// </param>
/// <param name="AllocationSize">
/// Allocation size for the newly created file.
/// </param>
/// <param name="FileNode">
/// Receives the file node for the newly created file.
/// </param>
/// <param name="FileDesc">
/// Receives the file descriptor for the newly created file.
/// </param>
/// <param name="FileInfo">
/// Receives the file information for the newly created file.
/// </param>
/// <param name="NormalizedName">
/// Receives the normalized name for the newly created file.
/// </param>
/// <returns>STATUS_SUCCESS or error code.</returns>
public virtual Int32 Create(
String FileName,
UInt32 CreateOptions,
UInt32 GrantedAccess,
UInt32 FileAttributes,
Byte[] SecurityDescriptor,
UInt64 AllocationSize,
out Object FileNode,
out Object FileDesc,
out FileInfo FileInfo,
out String NormalizedName)
{
FileNode = default(Object);
FileDesc = default(Object);
FileInfo = default(FileInfo);
NormalizedName = default(String);
return STATUS_INVALID_DEVICE_REQUEST;
}
/// <summary>
/// Opens a file or directory.
/// </summary>
/// <param name="FileName">
/// The name of the file or directory to be opened.
/// </param>
/// <param name="CreateOptions">
/// Create options for this request.
/// </param>
/// <param name="GrantedAccess">
/// Determines the specific access rights that have been granted for this request.
/// </param>
/// <param name="FileNode">
/// Receives the file node for the newly opened file.
/// </param>
/// <param name="FileDesc">
/// Receives the file descriptor for the newly opened file.
/// </param>
/// <param name="FileInfo">
/// Receives the file information for the newly opened file.
/// </param>
/// <param name="NormalizedName">
/// Receives the normalized name for the newly opened file.
/// </param>
/// <returns>STATUS_SUCCESS or error code.</returns>
public virtual Int32 Open(
String FileName,
UInt32 CreateOptions,
UInt32 GrantedAccess,
out Object FileNode,
out Object FileDesc,
out FileInfo FileInfo,
out String NormalizedName)
{
FileNode = default(Object);
FileDesc = default(Object);
FileInfo = default(FileInfo);
NormalizedName = default(String);
return STATUS_INVALID_DEVICE_REQUEST;
}
/// <summary>
/// Overwrites a file.
/// </summary>
/// <param name="FileNode">
/// The file node for the file to be overwritten.
/// </param>
/// <param name="FileDesc">
/// The file descriptor for the file to be overwritten.
/// </param>
/// <param name="FileAttributes">
/// File attributes to apply to the overwritten file.
/// </param>
/// <param name="ReplaceFileAttributes">
/// When true the existing file attributes should be replaced with the new ones.
/// When false the existing file attributes should be merged (or'ed) with the new ones.
/// </param>
/// <param name="AllocationSize">
/// Allocation size for the overwritten file.
/// </param>
/// <param name="FileInfo">
/// Receives the updated file information.
/// </param>
/// <returns>STATUS_SUCCESS or error code.</returns>
public virtual Int32 Overwrite(
Object FileNode,
Object FileDesc,
UInt32 FileAttributes,
Boolean ReplaceFileAttributes,
UInt64 AllocationSize,
out FileInfo FileInfo)
{
FileInfo = default(FileInfo);
return STATUS_INVALID_DEVICE_REQUEST;
}
/// <summary>
/// Cleans up a file or directory.
/// </summary>
/// <remarks>
/// <para>
/// When CreateFile is used to open or create a file the kernel creates a kernel mode file
/// object (type FILE_OBJECT) and a handle for it, which it returns to user-mode. The handle may
/// be duplicated (using DuplicateHandle), but all duplicate handles always refer to the same
/// file object. When all handles for a particular file object get closed (using CloseHandle)
/// the system sends a Cleanup request to the file system.
/// </para><para>
/// There will be a Cleanup operation for every Create or Open operation posted to the user mode
/// file system. However the Cleanup operation is not the final close operation on a file.
/// The file system must be ready to receive additional operations until close time. This is true
/// even when the file is being deleted!
/// </para><para>
/// The Flags parameter contains information about the cleanup operation:
/// <list>
/// <item>CleanupDelete -
/// An important function of the Cleanup operation is to complete a delete operation. Deleting
/// a file or directory in Windows is a three-stage process where the file is first opened, then
/// tested to see if the delete can proceed and if the answer is positive the file is then
/// deleted during Cleanup.
/// When this flag is set, this is the last outstanding cleanup for this particular file node.
/// </item>
/// <item>CleanupSetAllocationSize -
/// The NTFS and FAT file systems reset a file's allocation size when they receive the last
/// outstanding cleanup for a particular file node. User mode file systems that implement
/// allocation size and wish to duplicate the NTFS and FAT behavior can use this flag.
/// </item>
/// <item>CleanupSetArchiveBit -
/// File systems that support the archive bit should set the file node's archive bit when this
/// flag is set.
/// </item>
/// <item>CleanupSetLastAccessTime, CleanupSetLastWriteTime, CleanupSetChangeTime -
/// File systems should set the corresponding file time when each one of these flags is set.
/// Note that updating the last access time is expensive and a file system may choose to not
/// implement it.
/// </item>
/// </list>
/// </para><para>
/// There is no way to report failure of this operation. This is a Windows limitation.
/// </para>
/// </remarks>
/// <param name="FileNode">
/// The file node of the file or directory to cleanup.
/// </param>
/// <param name="FileDesc">
/// The file descriptor of the file or directory to cleanup.
/// </param>
/// <param name="FileName">
/// The name of the file or directory to cleanup. Sent only when a Delete is requested.
/// </param>
/// <param name="Flags">
/// These flags determine whether the file was modified and whether to delete the file.
/// </param>
/// <seealso cref="CanDelete"/>
/// <seealso cref="SetDelete"/>
/// <seealso cref="Close"/>
public virtual void Cleanup(
Object FileNode,
Object FileDesc,
String FileName,
UInt32 Flags)
{
}
/// <summary>
/// Closes a file or directory.
/// </summary>
/// <param name="FileNode">
/// The file node of the file or directory to close.
/// </param>
/// <param name="FileDesc">
/// The file descriptor of the file or directory to close.
/// </param>
public virtual void Close(
Object FileNode,
Object FileDesc)
{
}
/// <summary>
/// Reads a file.
/// </summary>
/// <param name="FileNode">
/// The file node of the file to read.
/// </param>
/// <param name="FileDesc">
/// The file descriptor of the file to read.
/// </param>
/// <param name="Buffer">
/// Pointer to a buffer that receives the results of the read operation.
/// </param>
/// <param name="Offset">
/// Offset within the file to read from.
/// </param>
/// <param name="Length">
/// Length of data to read.
/// </param>
/// <param name="BytesTransferred">
/// Receives the actual number of bytes read.
/// </param>
/// <returns>STATUS_SUCCESS or error code.</returns>
public virtual Int32 Read(
Object FileNode,
Object FileDesc,
IntPtr Buffer,
UInt64 Offset,
UInt32 Length,
out UInt32 BytesTransferred)
{
BytesTransferred = default(UInt32);
return STATUS_INVALID_DEVICE_REQUEST;
}
/// <summary>
/// Writes a file.
/// </summary>
/// <param name="FileNode">
/// The file node of the file to write.
/// </param>
/// <param name="FileDesc">
/// The file descriptor of the file to write.
/// </param>
/// <param name="Buffer">
/// Pointer to a buffer that receives the results of the write operation.
/// </param>
/// <param name="Offset">
/// Offset within the file to write to.
/// </param>
/// <param name="Length">
/// Length of data to write.
/// </param>
/// <param name="WriteToEndOfFile">
/// When true the file system must write to the current end of file. In this case the Offset
/// parameter will contain the value -1.
/// </param>
/// <param name="ConstrainedIo">
/// When true the file system must not extend the file (i.e. change the file size).
/// </param>
/// <param name="BytesTransferred">
/// Receives the actual number of bytes written.
/// </param>
/// <param name="FileInfo">
/// Receives the updated file information.
/// </param>
/// <returns>STATUS_SUCCESS or error code.</returns>
public virtual Int32 Write(
Object FileNode,
Object FileDesc,
IntPtr Buffer,
UInt64 Offset,
UInt32 Length,
Boolean WriteToEndOfFile,
Boolean ConstrainedIo,
out UInt32 BytesTransferred,
out FileInfo FileInfo)
{
BytesTransferred = default(UInt32);
FileInfo = default(FileInfo);
return STATUS_INVALID_DEVICE_REQUEST;
}
/// <summary>
/// Flushes a file or volume.
/// </summary>
/// <remarks>
/// Note that the FSD will also flush all file/volume caches prior to invoking this operation.
/// </remarks>
/// <param name="FileNode">
/// The file node of the file to flush.
/// When this and the FileDesc parameter are null the whole volume is being flushed.
/// </param>
/// <param name="FileDesc">
/// The file descriptor of the file to flush.
/// When this and the FileNode parameter are null the whole volume is being flushed.
/// </param>
/// <param name="FileInfo">
/// Receives the updated file information.
/// </param>
/// <returns>STATUS_SUCCESS or error code.</returns>
public virtual Int32 Flush(
Object FileNode,
Object FileDesc,
out FileInfo FileInfo)
{
FileInfo = default(FileInfo);
return STATUS_INVALID_DEVICE_REQUEST;
}
/// <summary>
/// Gets file or directory information.
/// </summary>
/// <param name="FileNode">
/// The file node of the file to get information for.
/// </param>
/// <param name="FileDesc">
/// The file descriptor of the file to get information for.
/// </param>
/// <param name="FileInfo">
/// Receives the file information.
/// </param>
/// <returns>STATUS_SUCCESS or error code.</returns>
public virtual Int32 GetFileInfo(
Object FileNode,
Object FileDesc,
out FileInfo FileInfo)
{
FileInfo = default(FileInfo);
return STATUS_INVALID_DEVICE_REQUEST;
}
/// <summary>
/// Sets file or directory basic information.
/// </summary>
/// <param name="FileNode">
/// The file node of the file to set information for.
/// </param>
/// <param name="FileDesc">
/// The file descriptor of the file to set information for.
/// </param>
/// <param name="FileAttributes">
/// File attributes to apply to the file or directory.
/// If the value -1 is sent, the file attributes should not be changed.
/// </param>
/// <param name="CreationTime">
/// Creation time to apply to the file or directory.
/// If the value 0 is sent, the creation time should not be changed.
/// </param>
/// <param name="LastAccessTime">
/// Last access time to apply to the file or directory.
/// If the value 0 is sent, the last access time should not be changed.
/// </param>
/// <param name="LastWriteTime">
/// Last write time to apply to the file or directory.
/// If the value 0 is sent, the last write time should not be changed.
/// </param>
/// <param name="ChangeTime">
/// Change time to apply to the file or directory.
/// If the value 0 is sent, the change time should not be changed.
/// </param>
/// <param name="FileInfo">
/// Receives the updated file information.
/// </param>
/// <returns>STATUS_SUCCESS or error code.</returns>
public virtual Int32 SetBasicInfo(
Object FileNode,
Object FileDesc,
UInt32 FileAttributes,
UInt64 CreationTime,
UInt64 LastAccessTime,
UInt64 LastWriteTime,
UInt64 ChangeTime,
out FileInfo FileInfo)
{
FileInfo = default(FileInfo);
return STATUS_INVALID_DEVICE_REQUEST;
}
/// <summary>
/// Sets file/allocation size.
/// </summary>
/// <remarks>
/// <para>
/// This function is used to change a file's sizes. Windows file systems maintain two kinds
/// of sizes: the file size is where the End Of File (EOF) is, and the allocation size is the
/// actual size that a file takes up on the "disk".
/// </para><para>
/// The rules regarding file/allocation size are:
/// <list>
/// <item>
/// Allocation size must always be aligned to the allocation unit boundary. The allocation
/// unit is the product SectorSize * SectorsPerAllocationUnit. The FSD will always send
/// properly aligned allocation sizes when setting the allocation size.
/// </item>
/// <item>
/// Allocation size is always greater or equal to the file size.
/// </item>
/// <item>
/// A file size of more than the current allocation size will also extend the allocation
/// size to the next allocation unit boundary.
/// </item>
/// <item>
/// An allocation size of less than the current file size should also truncate the current
/// file size.
/// </item>
/// </list>
/// </para>
/// </remarks>
/// <param name="FileNode">
/// The file node of the file to set the file/allocation size for.
/// </param>
/// <param name="FileDesc">
/// The file descriptor of the file to set the file/allocation size for.
/// </param>
/// <param name="NewSize">
/// New file/allocation size to apply to the file.
/// </param>
/// <param name="SetAllocationSize">
/// If true, then the allocation size is being set. if false, then the file size is being set.
/// </param>
/// <param name="FileInfo">
/// Receives the updated file information.
/// </param>
/// <returns>STATUS_SUCCESS or error code.</returns>
public virtual Int32 SetFileSize(
Object FileNode,
Object FileDesc,
UInt64 NewSize,
Boolean SetAllocationSize,
out FileInfo FileInfo)
{
FileInfo = default(FileInfo);
return STATUS_INVALID_DEVICE_REQUEST;
}
/// <summary>
/// Determines whether a file or directory can be deleted.
/// </summary>
/// <remarks>
/// <para>
/// This function tests whether a file or directory can be safely deleted. This function does
/// not need to perform access checks, but may performs tasks such as check for empty
/// directories, etc.
/// </para><para>
/// This function should <b>NEVER</b> delete the file or directory in question. Deletion should
/// happen during Cleanup with the FspCleanupDelete flag set.
/// </para><para>
/// This function gets called when Win32 API's such as DeleteFile or RemoveDirectory are used.
/// It does not get called when a file or directory is opened with FILE_DELETE_ON_CLOSE.
/// </para><para>
/// NOTE: If both CanDelete and SetDelete are defined, SetDelete takes precedence. However
/// most file systems need only implement the CanDelete operation.
/// </para>
/// </remarks>
/// <param name="FileNode">
/// The file node of the file or directory to test for deletion.
/// </param>
/// <param name="FileDesc">
/// The file descriptor of the file or directory to test for deletion.
/// </param>
/// <param name="FileName">
/// The name of the file or directory to test for deletion.
/// </param>
/// <returns>STATUS_SUCCESS or error code.</returns>
/// <seealso cref="Cleanup"/>
/// <seealso cref="SetDelete"/>
public virtual Int32 CanDelete(
Object FileNode,
Object FileDesc,
String FileName)
{
return STATUS_INVALID_DEVICE_REQUEST;
}
/// <summary>
/// Renames a file or directory.
/// </summary>
/// <remarks>
/// The kernel mode FSD provides certain guarantees prior to posting a rename operation:
/// <list>
/// <item>
/// A file cannot be renamed if a file with the same name exists and has open handles.
/// </item>
/// <item>
/// A directory cannot be renamed if it or any of its subdirectories contains a file that
/// has open handles.
/// </item>
/// </list>
/// </remarks>
/// <param name="FileNode">
/// The file node of the file or directory to be renamed.
/// </param>
/// <param name="FileDesc">
/// The file descriptor of the file or directory to be renamed.
/// </param>
/// <param name="FileName">
/// The current name of the file or directory to rename.
/// </param>
/// <param name="NewFileName">
/// The new name for the file or directory.
/// </param>
/// <param name="ReplaceIfExists">
/// Whether to replace a file that already exists at NewFileName.
/// </param>
/// <returns>STATUS_SUCCESS or error code.</returns>
public virtual Int32 Rename(
Object FileNode,
Object FileDesc,
String FileName,
String NewFileName,
Boolean ReplaceIfExists)
{
return STATUS_INVALID_DEVICE_REQUEST;
}
/// <summary>
/// Gets file or directory security descriptor.
/// </summary>
/// <param name="FileNode">
/// The file node of the file or directory to get the security descriptor for.
/// </param>
/// <param name="FileDesc">
/// The file descriptor of the file or directory to get the security descriptor for.
/// </param>
/// <param name="SecurityDescriptor">
/// Receives the file security descriptor.
/// </param>
/// <returns>STATUS_SUCCESS or error code.</returns>
public virtual Int32 GetSecurity(
Object FileNode,
Object FileDesc,
ref Byte[] SecurityDescriptor)
{
return STATUS_INVALID_DEVICE_REQUEST;
}
/// <summary>
/// Sets file or directory security descriptor.
/// </summary>
/// <param name="FileNode">
/// The file node of the file or directory to set the security descriptor for.
/// </param>
/// <param name="FileDesc">
/// The file descriptor of the file or directory to set the security descriptor for.
/// </param>
/// <param name="Sections">
/// Describes what parts of the file or directory security descriptor should be modified.
/// </param>
/// <param name="SecurityDescriptor">
/// Describes the modifications to apply to the file or directory security descriptor.
/// </param>
/// <returns>STATUS_SUCCESS or error code.</returns>
/// <seealso cref="ModifySecurityDescriptorEx"/>
public virtual Int32 SetSecurity(
Object FileNode,
Object FileDesc,
AccessControlSections Sections,
Byte[] SecurityDescriptor)
{
return STATUS_INVALID_DEVICE_REQUEST;
}
/// <summary>
/// Reads a directory.
/// </summary>
/// <seealso cref="ReadDirectoryEntry"/>
public virtual Int32 ReadDirectory(
Object FileNode,
Object FileDesc,
String Pattern,
String Marker,
IntPtr Buffer,
UInt32 Length,
out UInt32 BytesTransferred)
{
return SeekableReadDirectory(FileNode, FileDesc, Pattern, Marker, Buffer, Length,
out BytesTransferred);
}
/// <summary>
/// Reads a directory entry.
/// </summary>
/// <param name="FileNode">
/// The file node of the directory to be read.
/// </param>
/// <param name="FileDesc">
/// The file descriptor of the directory to be read.
/// </param>
/// <param name="Pattern">
/// The pattern to match against files in this directory. Can be null. The file system
/// can choose to ignore this parameter as the FSD will always perform its own pattern
/// matching on the returned results.
/// </param>
/// <param name="Marker">
/// A file name that marks where in the directory to start reading. Files with names
/// that are greater than (not equal to) this marker (in the directory order determined
/// by the file system) should be returned. Can be null.
/// </param>
/// <param name="Context">
/// Can be used by the file system to track the ReadDirectory operation.
/// </param>
/// <param name="FileName">
/// Receives the file name for the directory entry.
/// </param>
/// <param name="FileInfo">
/// Receives the file information for the directory entry.
/// </param>
/// <returns>True if there are additional directory entries to return. False otherwise.</returns>
/// <seealso cref="ReadDirectory"/>
public virtual Boolean ReadDirectoryEntry(
Object FileNode,
Object FileDesc,
String Pattern,
String Marker,
ref Object Context,
out String FileName,
out FileInfo FileInfo)
{
FileName = default(String);
FileInfo = default(FileInfo);
return false;
}
/// <summary>
/// Resolves reparse points.
/// </summary>
public virtual Int32 ResolveReparsePoints(
String FileName,
UInt32 ReparsePointIndex,
Boolean ResolveLastPathComponent,
out IoStatusBlock IoStatus,
IntPtr Buffer,
IntPtr PSize)
{
GCHandle Handle = GCHandle.Alloc(this, GCHandleType.Normal);
try
{
return Api.FspFileSystemResolveReparsePoints(
IntPtr.Zero,
GetReparsePointByName,
(IntPtr)Handle,
FileName,
ReparsePointIndex,
ResolveLastPathComponent,
out IoStatus,
Buffer,
PSize);
}
finally
{
Handle.Free();
}
}
/// <summary>
/// Gets a reparse point given a file name.
/// </summary>
/// <param name="FileName">
/// The name of the file or directory to get the reparse point for.
/// </param>
/// <param name="IsDirectory">
/// Determines whether the passed file name is assumed to be a directory.
/// </param>
/// <param name="ReparseData">
/// Receives the reparse data for the file or directory.
/// </param>
/// <returns>STATUS_SUCCESS or error code.</returns>
public virtual Int32 GetReparsePointByName(
String FileName,
Boolean IsDirectory,
ref Byte[] ReparseData)
{
return STATUS_INVALID_DEVICE_REQUEST;
}
/// <summary>
/// Gets a reparse point.
/// </summary>
/// <param name="FileNode">
/// The file node of the reparse point.
/// </param>
/// <param name="FileDesc">
/// The file descriptor of the reparse point.
/// </param>
/// <param name="FileName">
/// The file name of the reparse point.
/// </param>
/// <param name="ReparseData">
/// Receives the reparse data for the reparse point.
/// </param>
/// <returns>STATUS_SUCCESS or error code.</returns>
public virtual Int32 GetReparsePoint(
Object FileNode,
Object FileDesc,
String FileName,
ref Byte[] ReparseData)
{
return STATUS_INVALID_DEVICE_REQUEST;
}
/// <summary>
/// Sets a reparse point.
/// </summary>
/// <param name="FileNode">
/// The file node of the reparse point.
/// </param>
/// <param name="FileDesc">
/// The file descriptor of the reparse point.
/// </param>
/// <param name="FileName">
/// The file name of the reparse point.
/// </param>
/// <param name="ReparseData">
/// The new reparse data for the reparse point.
/// </param>
/// <returns>STATUS_SUCCESS or error code.</returns>
public virtual Int32 SetReparsePoint(
Object FileNode,
Object FileDesc,
String FileName,
Byte[] ReparseData)
{
return STATUS_INVALID_DEVICE_REQUEST;
}
/// <summary>
/// Deletes a reparse point.
/// </summary>
/// <param name="FileNode">
/// The file node of the reparse point.
/// </param>
/// <param name="FileDesc">
/// The file descriptor of the reparse point.
/// </param>
/// <param name="FileName">
/// The file name of the reparse point.
/// </param>
/// <param name="ReparseData">
/// The reparse data for the reparse point.
/// </param>
/// <returns>STATUS_SUCCESS or error code.</returns>
public virtual Int32 DeleteReparsePoint(
Object FileNode,
Object FileDesc,
String FileName,
Byte[] ReparseData)
{
return STATUS_INVALID_DEVICE_REQUEST;
}
/// <summary>
/// Gets named streams information.
/// </summary>
public virtual Int32 GetStreamInfo(
Object FileNode,
Object FileDesc,
IntPtr Buffer,
UInt32 Length,
out UInt32 BytesTransferred)
{
Object Context = null;
String StreamName;
StreamInfo StreamInfo = default(StreamInfo);
BytesTransferred = default(UInt32);
while (GetStreamEntry(FileNode, FileDesc, ref Context,
out StreamName, out StreamInfo.StreamSize, out StreamInfo.StreamAllocationSize))
{
StreamInfo.SetStreamNameBuf(StreamName);
if (!Api.FspFileSystemAddStreamInfo(ref StreamInfo, Buffer, Length,
out BytesTransferred))
return STATUS_SUCCESS;
}
Api.FspFileSystemEndStreamInfo(Buffer, Length, out BytesTransferred);
return STATUS_SUCCESS;
}
/// <summary>
/// Gets named streams information entry.
/// </summary>
/// <param name="FileNode">
/// The file node of the file or directory to get stream information for.
/// </param>
/// <param name="FileDesc">
/// The file descriptor of the file or directory to get stream information for.
/// </param>
/// <param name="Context">
/// Can be used by the file system to track the GetStreamInfo operation.
/// </param>
/// <param name="StreamName">
/// Receives the stream name for the stream entry.
/// </param>
/// <param name="StreamSize">
/// Receives the stream size for the stream entry.
/// </param>
/// <param name="StreamAllocationSize">
/// Receives the stream allocation size for the stream entry.
/// </param>
/// <returns>True if there are additional stream entries to return. False otherwise.</returns>
public virtual Boolean GetStreamEntry(
Object FileNode,
Object FileDesc,
ref Object Context,
out String StreamName,
out UInt64 StreamSize,
out UInt64 StreamAllocationSize)
{
StreamName = default(String);
StreamSize = default(UInt64);
StreamAllocationSize = default(UInt64);
return false;
}
/// <summary>
/// Gets directory information for a single file or directory within a parent directory.
/// </summary>
/// <param name="FileNode">
/// The file node of the parent directory.
/// </param>
/// <param name="FileDesc">
/// The file descriptor of the parent directory.
/// </param>
/// <param name="FileName">
/// The name of the file or directory to get information for. This name is relative
/// to the parent directory and is a single path component.
/// </param>
/// <param name="NormalizedName">
/// Receives the normalized name from the directory entry.
/// </param>
/// <param name="FileInfo">
/// Receives the file information.
/// </param>
/// <returns>STATUS_SUCCESS or error code.</returns>
public virtual Int32 GetDirInfoByName(
Object FileNode,
Object FileDesc,
String FileName,
out String NormalizedName,
out FileInfo FileInfo)
{
NormalizedName = default(String);
FileInfo = default(FileInfo);
return STATUS_INVALID_DEVICE_REQUEST;
}
/// <summary>
/// Processes a control code.
/// </summary>
/// <remarks>
/// This function is called when a program uses the DeviceIoControl API.
/// </remarks>
/// <param name="FileNode">
/// The file node of the file or directory to be controled.
/// </param>
/// <param name="FileDesc">