-
Notifications
You must be signed in to change notification settings - Fork 0
/
MirrorFsOperation.cs
180 lines (153 loc) · 4.49 KB
/
MirrorFsOperation.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
using System;
using System.IO;
using System.Collections;
using Dokan;
namespace DokaNetMirror{
class Mirror:DokanOperations{
private string root_;
private int count_;
public Mirror(string root){
root_=root;
count_=1;
}
private string GetPath(string filename){
string path=root_+filename;
Console.Error.WriteLine("GetPath : {0}",path);
return path;
}
public int CreateFile(String filename,FileAccess access,FileShare share,
FileMode mode,FileOptions options,DokanFileInfo info){
string path=GetPath(filename);
info.Context=count_++;
if (File.Exists(path)){
return 0;
}else if(Directory.Exists(path)){
info.IsDirectory=true;
return 0;
}else{
return -DokanNet.ERROR_FILE_NOT_FOUND;
}
}
public int OpenDirectory(String filename,DokanFileInfo info){
info.Context=count_++;
if (Directory.Exists(GetPath(filename)))
return 0;
else
return -DokanNet.ERROR_PATH_NOT_FOUND;
}
public int CreateDirectory(String filename,DokanFileInfo info){
return -1;
}
public int Cleanup(String filename,DokanFileInfo info){
//Console.WriteLine("%%%%%% count={0}",info.Context);
return 0;
}
public int CloseFile(String filename,DokanFileInfo info){
return 0;
}
public int ReadFile(String filename,Byte[] buffer,ref uint readBytes,
long offset,DokanFileInfo info){
try{
FileStream fs=File.OpenRead(GetPath(filename));
fs.Seek(offset,SeekOrigin.Begin);
readBytes=(uint)fs.Read(buffer,0,buffer.Length);
return 0;
}catch(Exception){
return -1;
}
}
public int WriteFile(String filename,Byte[] buffer,ref uint writtenBytes,long offset,DokanFileInfo info){
return -1;
}
public int FlushFileBuffers(String filename,DokanFileInfo info){
return -1;
}
public int GetFileInformation(String filename,FileInformation fileinfo,DokanFileInfo info){
string path=GetPath(filename);
if (File.Exists(path)){
FileInfo f=new FileInfo(path);
fileinfo.Attributes=f.Attributes;
fileinfo.CreationTime=f.CreationTime;
fileinfo.LastAccessTime=f.LastAccessTime;
fileinfo.LastWriteTime=f.LastWriteTime;
fileinfo.Length=f.Length;
return 0;
}else if (Directory.Exists(path)){
DirectoryInfo f=new DirectoryInfo(path);
fileinfo.Attributes=f.Attributes;
fileinfo.CreationTime=f.CreationTime;
fileinfo.LastAccessTime=f.LastAccessTime;
fileinfo.LastWriteTime=f.LastWriteTime;
fileinfo.Length=0;// f.Length;
return 0;
}else{
return -1;
}
}
public int FindFiles(String filename,ArrayList files,DokanFileInfo info){
string path=GetPath(filename);
if (Directory.Exists(path)){
DirectoryInfo d=new DirectoryInfo(path);
FileSystemInfo[] entries=d.GetFileSystemInfos();
foreach (FileSystemInfo f in entries){
FileInformation fi=new FileInformation();
fi.Attributes=f.Attributes;
fi.CreationTime=f.CreationTime;
fi.LastAccessTime=f.LastAccessTime;
fi.LastWriteTime=f.LastWriteTime;
fi.Length=(f is DirectoryInfo) ? 0 : ((FileInfo)f).Length;
fi.FileName=f.Name;
files.Add(fi);
}
return 0;
}else{
return -1;
}
}
public int SetFileAttributes(String filename,FileAttributes attr,DokanFileInfo info){
return -1;
}
public int SetFileTime(String filename,DateTime ctime,
DateTime atime,DateTime mtime,DokanFileInfo info){
return -1;
}
public int DeleteFile(String filename,DokanFileInfo info){
return -1;
}
public int DeleteDirectory(String filename,DokanFileInfo info){
return -1;
}
public int MoveFile(String filename,String newname,bool replace,DokanFileInfo info){
return -1;
}
public int SetEndOfFile(String filename,long length,DokanFileInfo info){
return -1;
}
public int SetAllocationSize(String filename,long length,DokanFileInfo info){
return -1;
}
public int LockFile(String filename,long offset,long length,DokanFileInfo info){
return 0;
}
public int UnlockFile(String filename,long offset,long length,DokanFileInfo info){
return 0;
}
public int GetDiskFreeSpace(ref ulong freeBytesAvailable,ref ulong totalBytes,
ref ulong totalFreeBytes,DokanFileInfo info){
freeBytesAvailable=512 * 1024 * 1024;
totalBytes=1024 * 1024 * 1024;
totalFreeBytes=512 * 1024 * 1024;
return 0;
}
public int Unmount(DokanFileInfo info){
return 0;
}
static void Main(string[] args){
DokanOptions opt=new DokanOptions();
opt.DebugMode=true;
opt.DriveLetter='n';
opt.ThreadCount=5;
DokanNet.DokanMain(opt,new Mirror("C:"));
}
}
}