dokan-ruby 0.0.1-mswin32
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/LICENSE +20 -0
- data/README.rdoc +39 -0
- data/Rakefile +63 -0
- data/VERSION +1 -0
- data/dokan-ruby.gemspec +66 -0
- data/ext/dokan-ruby-0.1.5.1229/API.txt +45 -0
- data/ext/dokan-ruby-0.1.5.1229/dokan_lib.c +1987 -0
- data/ext/dokan-ruby-0.1.5.1229/dokan_lib.so +0 -0
- data/ext/dokan-ruby-0.1.5.1229/extconf.rb +11 -0
- data/ext/dokan-ruby-0.1.5.1229/lib/dokanfs.rb +390 -0
- data/ext/dokan-ruby-0.1.5.1229/license.txt +19 -0
- data/ext/dokan-ruby-0.1.5.1229/list.h +144 -0
- data/ext/dokan-ruby-0.1.5.1229/readme.ja.txt +66 -0
- data/ext/dokan-ruby-0.1.5.1229/readme.txt +70 -0
- data/ext/dokan-ruby-0.1.5.1229/sample/hello.rb +39 -0
- data/ext/dokan-ruby-0.1.5.1229/sample/mirror.rb +178 -0
- data/ext/dokan-ruby-0.1.5.1229/sample/rssfs.rb +52 -0
- data/ext/dokan-ruby-0.1.5.1229/sample/sshfs.rb +163 -0
- data/ext/dokan-ruby-0.1.5.1229/sample/test.rb +115 -0
- data/lib/dokan-ruby.rb +1 -0
- data/test/dokan-ruby_test.rb +29 -0
- data/test/test_helper.rb +11 -0
- metadata +90 -0
Binary file
|
@@ -0,0 +1,390 @@
|
|
1
|
+
|
2
|
+
require 'dokan_lib'
|
3
|
+
|
4
|
+
class DokanProxy
|
5
|
+
|
6
|
+
|
7
|
+
def initialize
|
8
|
+
@root = nil
|
9
|
+
end
|
10
|
+
|
11
|
+
def set_root(root)
|
12
|
+
@root = root
|
13
|
+
def @root.method_missing(name, *arg)
|
14
|
+
puts "#method_missing " + name.to_s
|
15
|
+
false
|
16
|
+
end
|
17
|
+
end
|
18
|
+
|
19
|
+
def open(path, fileinfo)
|
20
|
+
puts "#open " + path
|
21
|
+
if path == "/"
|
22
|
+
true
|
23
|
+
else
|
24
|
+
@root.file?(path) or @root.directory?(path)
|
25
|
+
end
|
26
|
+
end
|
27
|
+
|
28
|
+
def create(path, fileinfo)
|
29
|
+
puts "#create " + path
|
30
|
+
if @root.can_write?(path)
|
31
|
+
@root.write_to(path, "")
|
32
|
+
true
|
33
|
+
else
|
34
|
+
false
|
35
|
+
end
|
36
|
+
end
|
37
|
+
|
38
|
+
def truncate(path, fileinfo)
|
39
|
+
puts "#truncate " + path
|
40
|
+
@root.can_write?(path) and @root.write_to(path, "")
|
41
|
+
end
|
42
|
+
|
43
|
+
def opendir(path, fileinfo)
|
44
|
+
puts "#opendir " + path
|
45
|
+
if path == "/"
|
46
|
+
true
|
47
|
+
else
|
48
|
+
@root.directory?(path)
|
49
|
+
end
|
50
|
+
end
|
51
|
+
|
52
|
+
def mkdir(path, fileinfo)
|
53
|
+
puts "#mkdir " + path
|
54
|
+
@root.can_mkdir?(path) and @root.mkdir(path)
|
55
|
+
end
|
56
|
+
|
57
|
+
def cleanup(path, fileinfo)
|
58
|
+
puts "#cleanup " + path
|
59
|
+
if fileinfo.context
|
60
|
+
@root.can_write?(path) and @root.write_to(path, fileinfo.context)
|
61
|
+
end
|
62
|
+
true
|
63
|
+
end
|
64
|
+
|
65
|
+
def close(path, fileinfo)
|
66
|
+
puts "#close " + path
|
67
|
+
true
|
68
|
+
end
|
69
|
+
|
70
|
+
def read(path, offset, length, fileinfo)
|
71
|
+
puts "#read " + path
|
72
|
+
return "" unless @root.file?(path)
|
73
|
+
str = @root.read_file(path)
|
74
|
+
if offset < str.length
|
75
|
+
str[offset, length]
|
76
|
+
else
|
77
|
+
false
|
78
|
+
end
|
79
|
+
end
|
80
|
+
|
81
|
+
def write(path, offset, data, fileinfo)
|
82
|
+
puts "#write " + path
|
83
|
+
fileinfo.context = "" unless fileinfo.context
|
84
|
+
fileinfo.context[offset, data.length] = data
|
85
|
+
true
|
86
|
+
end
|
87
|
+
|
88
|
+
def flush(path, fileinfo)
|
89
|
+
puts "#flush " + path
|
90
|
+
true
|
91
|
+
end
|
92
|
+
|
93
|
+
def stat(path, fileinfo)
|
94
|
+
puts "#stat " + path
|
95
|
+
#[size, attr, ctime, atime, mtime]
|
96
|
+
|
97
|
+
size = @root.size(path)
|
98
|
+
size = 0 unless size
|
99
|
+
|
100
|
+
if path == "/" or @root.directory?(path)
|
101
|
+
[size, Dokan::DIRECTORY, 0, 0, 0]
|
102
|
+
else
|
103
|
+
[size, Dokan::NORMAL, 0, 0, 0]
|
104
|
+
end
|
105
|
+
end
|
106
|
+
|
107
|
+
# def readdira(path, fileinfo)
|
108
|
+
# end
|
109
|
+
|
110
|
+
def readdir(path, fileinfo)
|
111
|
+
puts "#readdir " + path
|
112
|
+
path == "/" or @root.directory?(path) and @root.contents(path)
|
113
|
+
end
|
114
|
+
|
115
|
+
def setattr(path, attr, fileinfo)
|
116
|
+
puts "#setattr " + path
|
117
|
+
false
|
118
|
+
end
|
119
|
+
|
120
|
+
def utime(path, ctime, atime, mtime, fileinfo)
|
121
|
+
puts "#utime " + path
|
122
|
+
false
|
123
|
+
end
|
124
|
+
|
125
|
+
def remove(path, fileinfo)
|
126
|
+
puts "#remove " + path
|
127
|
+
@root.can_delete?(path) and @root.delete(path)
|
128
|
+
end
|
129
|
+
|
130
|
+
def rename(path, newpath, fileinfo)
|
131
|
+
puts "#rename " + path
|
132
|
+
if @root.file?(path) and @root.can_delete?(path) and @root.can_write?(path)
|
133
|
+
str = @root.read_file(path)
|
134
|
+
@root.write_to(newpath, str)
|
135
|
+
@root.delete(path)
|
136
|
+
else
|
137
|
+
false
|
138
|
+
end
|
139
|
+
end
|
140
|
+
|
141
|
+
def rmdir(path, fileinfo)
|
142
|
+
puts "#rmdir " + path
|
143
|
+
@root.can_rmdir(path) and @root.rmdir(path)
|
144
|
+
end
|
145
|
+
|
146
|
+
def lock(path, fileinfo)
|
147
|
+
true
|
148
|
+
end
|
149
|
+
|
150
|
+
def unlock(path, fileinfo)
|
151
|
+
true
|
152
|
+
end
|
153
|
+
|
154
|
+
def unmount(fileinfo)
|
155
|
+
puts "#unmount"
|
156
|
+
@root.unmount
|
157
|
+
end
|
158
|
+
|
159
|
+
|
160
|
+
end
|
161
|
+
|
162
|
+
|
163
|
+
#
|
164
|
+
# from fusefs.rb
|
165
|
+
# Author: Greg Millam <walker@deafcode.com>.
|
166
|
+
#
|
167
|
+
module DokanFS
|
168
|
+
|
169
|
+
|
170
|
+
def DokanFS.set_root(root)
|
171
|
+
@proxy = DokanProxy.new
|
172
|
+
@proxy.set_root(root)
|
173
|
+
end
|
174
|
+
|
175
|
+
def DokanFS.mount_under(letter)
|
176
|
+
@letter = letter
|
177
|
+
end
|
178
|
+
|
179
|
+
def DokanFS.run
|
180
|
+
Dokan.mount(@letter, @proxy)
|
181
|
+
end
|
182
|
+
|
183
|
+
|
184
|
+
class DokanDir
|
185
|
+
def split_path(path)
|
186
|
+
cur, *rest = path.scan(/[^\/]+/)
|
187
|
+
if rest.empty?
|
188
|
+
[ cur, nil ]
|
189
|
+
else
|
190
|
+
[ cur, File.join(rest) ]
|
191
|
+
end
|
192
|
+
end
|
193
|
+
def scan_path(path)
|
194
|
+
path.scan(/[^\/]+/)
|
195
|
+
end
|
196
|
+
end
|
197
|
+
|
198
|
+
FuseDir = DokanDir
|
199
|
+
|
200
|
+
class MetaDir < DokanDir
|
201
|
+
def initialize
|
202
|
+
@subdirs = Hash.new(nil)
|
203
|
+
@files = Hash.new(nil)
|
204
|
+
end
|
205
|
+
|
206
|
+
# Contents of directory.
|
207
|
+
def contents(path)
|
208
|
+
base, rest = split_path(path)
|
209
|
+
case
|
210
|
+
when base.nil?
|
211
|
+
(@files.keys + @subdirs.keys).sort.uniq
|
212
|
+
when ! @subdirs.has_key?(base)
|
213
|
+
nil
|
214
|
+
when rest.nil?
|
215
|
+
@subdirs[base].contents('/')
|
216
|
+
else
|
217
|
+
@subdirs[base].contents(rest)
|
218
|
+
end
|
219
|
+
end
|
220
|
+
|
221
|
+
# File types
|
222
|
+
def directory?(path)
|
223
|
+
base, rest = split_path(path)
|
224
|
+
case
|
225
|
+
when base.nil?
|
226
|
+
true
|
227
|
+
when ! @subdirs.has_key?(base)
|
228
|
+
false
|
229
|
+
when rest.nil?
|
230
|
+
true
|
231
|
+
else
|
232
|
+
@subdirs[base].directory?(rest)
|
233
|
+
end
|
234
|
+
end
|
235
|
+
def file?(path)
|
236
|
+
base, rest = split_path(path)
|
237
|
+
case
|
238
|
+
when base.nil?
|
239
|
+
false
|
240
|
+
when rest.nil?
|
241
|
+
@files.has_key?(base)
|
242
|
+
when ! @subdirs.has_key?(base)
|
243
|
+
false
|
244
|
+
else
|
245
|
+
@subdirs[base].file?(rest)
|
246
|
+
end
|
247
|
+
end
|
248
|
+
|
249
|
+
# File Reading
|
250
|
+
def read_file(path)
|
251
|
+
base, rest = split_path(path)
|
252
|
+
case
|
253
|
+
when base.nil?
|
254
|
+
nil
|
255
|
+
when rest.nil?
|
256
|
+
@files[base].to_s
|
257
|
+
when ! @subdirs.has_key?(base)
|
258
|
+
nil
|
259
|
+
else
|
260
|
+
@subdirs[base].read_file(rest)
|
261
|
+
end
|
262
|
+
end
|
263
|
+
|
264
|
+
# Write to a file
|
265
|
+
def can_write?(path)
|
266
|
+
#return false unless Process.uid == FuseFS.reader_uid
|
267
|
+
base, rest = split_path(path)
|
268
|
+
case
|
269
|
+
when base.nil?
|
270
|
+
true
|
271
|
+
when rest.nil?
|
272
|
+
true
|
273
|
+
when ! @subdirs.has_key?(base)
|
274
|
+
false
|
275
|
+
else
|
276
|
+
@subdirs[base].can_write?(rest)
|
277
|
+
end
|
278
|
+
end
|
279
|
+
def write_to(path,file)
|
280
|
+
base, rest = split_path(path)
|
281
|
+
case
|
282
|
+
when base.nil?
|
283
|
+
false
|
284
|
+
when rest.nil?
|
285
|
+
@files[base] = file
|
286
|
+
when ! @subdirs.has_key?(base)
|
287
|
+
false
|
288
|
+
else
|
289
|
+
@subdirs[base].write_to(rest,file)
|
290
|
+
end
|
291
|
+
end
|
292
|
+
|
293
|
+
# Delete a file
|
294
|
+
def can_delete?(path)
|
295
|
+
#return false unless Process.uid == FuseFS.reader_uid
|
296
|
+
base, rest = split_path(path)
|
297
|
+
case
|
298
|
+
when base.nil?
|
299
|
+
false
|
300
|
+
when rest.nil?
|
301
|
+
@files.has_key?(base)
|
302
|
+
when ! @subdirs.has_key?(base)
|
303
|
+
false
|
304
|
+
else
|
305
|
+
@subdirs[base].can_delete?(rest)
|
306
|
+
end
|
307
|
+
end
|
308
|
+
def delete(path)
|
309
|
+
base, rest = split_path(path)
|
310
|
+
case
|
311
|
+
when base.nil?
|
312
|
+
nil
|
313
|
+
when rest.nil?
|
314
|
+
# Delete it.
|
315
|
+
@files.delete(base)
|
316
|
+
when ! @subdirs.has_key?(base)
|
317
|
+
nil
|
318
|
+
else
|
319
|
+
@subdirs[base].delete(rest)
|
320
|
+
end
|
321
|
+
end
|
322
|
+
|
323
|
+
# Make a new directory
|
324
|
+
def can_mkdir?(path)
|
325
|
+
#return false unless Process.uid == FuseFS.reader_uid
|
326
|
+
base, rest = split_path(path)
|
327
|
+
case
|
328
|
+
when base.nil?
|
329
|
+
false
|
330
|
+
when rest.nil?
|
331
|
+
! (@subdirs.has_key?(base) || @files.has_key?(base))
|
332
|
+
when ! @subdirs.has_key?(base)
|
333
|
+
false
|
334
|
+
else
|
335
|
+
@subdirs[base].can_mkdir?(rest)
|
336
|
+
end
|
337
|
+
end
|
338
|
+
def mkdir(path,dir=nil)
|
339
|
+
base, rest = split_path(path)
|
340
|
+
case
|
341
|
+
when base.nil?
|
342
|
+
false
|
343
|
+
when rest.nil?
|
344
|
+
dir ||= MetaDir.new
|
345
|
+
@subdirs[base] = dir
|
346
|
+
true
|
347
|
+
when ! @subdirs.has_key?(base)
|
348
|
+
false
|
349
|
+
else
|
350
|
+
@subdirs[base].mkdir(rest,dir)
|
351
|
+
end
|
352
|
+
end
|
353
|
+
|
354
|
+
# Delete an existing directory.
|
355
|
+
def can_rmdir?(path)
|
356
|
+
#return false unless Process.uid == FuseFS.reader_uid
|
357
|
+
base, rest = split_path(path)
|
358
|
+
case
|
359
|
+
when base.nil?
|
360
|
+
false
|
361
|
+
when rest.nil?
|
362
|
+
@subdirs.has_key?(base)
|
363
|
+
when ! @subdirs.has_key?(base)
|
364
|
+
false
|
365
|
+
else
|
366
|
+
@subdirs[base].can_rmdir?(rest)
|
367
|
+
end
|
368
|
+
end
|
369
|
+
def rmdir(path)
|
370
|
+
base, rest = split_path(path)
|
371
|
+
dir ||= MetaDir.new
|
372
|
+
case
|
373
|
+
when base.nil?
|
374
|
+
false
|
375
|
+
when rest.nil?
|
376
|
+
@subdirs.delete(base)
|
377
|
+
true
|
378
|
+
when ! @subdirs.has_key?(base)
|
379
|
+
false
|
380
|
+
else
|
381
|
+
@subdirs[base].rmdir(rest,dir)
|
382
|
+
end
|
383
|
+
end
|
384
|
+
end
|
385
|
+
end
|
386
|
+
|
387
|
+
|
388
|
+
FuseFS = DokanFS
|
389
|
+
|
390
|
+
|
@@ -0,0 +1,19 @@
|
|
1
|
+
Copyright (c) 2007 Hiroki Asakawa
|
2
|
+
|
3
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
4
|
+
of this software and associated documentation files (the "Software"), to deal
|
5
|
+
in the Software without restriction, including without limitation the rights
|
6
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
7
|
+
copies of the Software, and to permit persons to whom the Software is
|
8
|
+
furnished to do so, subject to the following conditions:
|
9
|
+
|
10
|
+
The above copyright notice and this permission notice shall be included in
|
11
|
+
all copies or substantial portions of the Software.
|
12
|
+
|
13
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
14
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
15
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
16
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
17
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
18
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
19
|
+
THE SOFTWARE.
|
@@ -0,0 +1,144 @@
|
|
1
|
+
#ifndef _LIST_H_
|
2
|
+
#define _LIST_H_
|
3
|
+
|
4
|
+
#include <windows.h>
|
5
|
+
|
6
|
+
#if _MSC_VER < 1300
|
7
|
+
#define FORCEINLINE __inline
|
8
|
+
#endif
|
9
|
+
|
10
|
+
FORCEINLINE
|
11
|
+
VOID
|
12
|
+
InitializeListHead(
|
13
|
+
PLIST_ENTRY ListHead)
|
14
|
+
{
|
15
|
+
ListHead->Flink = ListHead->Blink = ListHead;
|
16
|
+
}
|
17
|
+
|
18
|
+
FORCEINLINE
|
19
|
+
BOOLEAN
|
20
|
+
IsListEmpty(
|
21
|
+
const LIST_ENTRY * ListHead)
|
22
|
+
{
|
23
|
+
return (BOOLEAN)(ListHead->Flink == ListHead);
|
24
|
+
}
|
25
|
+
|
26
|
+
FORCEINLINE
|
27
|
+
BOOLEAN
|
28
|
+
RemoveEntryList(
|
29
|
+
PLIST_ENTRY Entry)
|
30
|
+
{
|
31
|
+
PLIST_ENTRY Blink;
|
32
|
+
PLIST_ENTRY Flink;
|
33
|
+
|
34
|
+
Flink = Entry->Flink;
|
35
|
+
Blink = Entry->Blink;
|
36
|
+
Blink->Flink = Flink;
|
37
|
+
Flink->Blink = Blink;
|
38
|
+
return (BOOLEAN)(Flink == Blink);
|
39
|
+
}
|
40
|
+
|
41
|
+
FORCEINLINE
|
42
|
+
PLIST_ENTRY
|
43
|
+
RemoveHeadList(
|
44
|
+
PLIST_ENTRY ListHead)
|
45
|
+
{
|
46
|
+
PLIST_ENTRY Flink;
|
47
|
+
PLIST_ENTRY Entry;
|
48
|
+
|
49
|
+
Entry = ListHead->Flink;
|
50
|
+
Flink = Entry->Flink;
|
51
|
+
ListHead->Flink = Flink;
|
52
|
+
Flink->Blink = ListHead;
|
53
|
+
return Entry;
|
54
|
+
}
|
55
|
+
|
56
|
+
|
57
|
+
|
58
|
+
FORCEINLINE
|
59
|
+
PLIST_ENTRY
|
60
|
+
RemoveTailList(
|
61
|
+
PLIST_ENTRY ListHead)
|
62
|
+
{
|
63
|
+
PLIST_ENTRY Blink;
|
64
|
+
PLIST_ENTRY Entry;
|
65
|
+
|
66
|
+
Entry = ListHead->Blink;
|
67
|
+
Blink = Entry->Blink;
|
68
|
+
ListHead->Blink = Blink;
|
69
|
+
Blink->Flink = ListHead;
|
70
|
+
return Entry;
|
71
|
+
}
|
72
|
+
|
73
|
+
|
74
|
+
FORCEINLINE
|
75
|
+
VOID
|
76
|
+
InsertTailList(
|
77
|
+
PLIST_ENTRY ListHead,
|
78
|
+
PLIST_ENTRY Entry)
|
79
|
+
{
|
80
|
+
PLIST_ENTRY Blink;
|
81
|
+
|
82
|
+
Blink = ListHead->Blink;
|
83
|
+
Entry->Flink = ListHead;
|
84
|
+
Entry->Blink = Blink;
|
85
|
+
Blink->Flink = Entry;
|
86
|
+
ListHead->Blink = Entry;
|
87
|
+
}
|
88
|
+
|
89
|
+
|
90
|
+
FORCEINLINE
|
91
|
+
VOID
|
92
|
+
InsertHeadList(
|
93
|
+
PLIST_ENTRY ListHead,
|
94
|
+
PLIST_ENTRY Entry)
|
95
|
+
{
|
96
|
+
PLIST_ENTRY Flink;
|
97
|
+
|
98
|
+
Flink = ListHead->Flink;
|
99
|
+
Entry->Flink = Flink;
|
100
|
+
Entry->Blink = ListHead;
|
101
|
+
Flink->Blink = Entry;
|
102
|
+
ListHead->Flink = Entry;
|
103
|
+
}
|
104
|
+
|
105
|
+
FORCEINLINE
|
106
|
+
VOID
|
107
|
+
AppendTailList(
|
108
|
+
PLIST_ENTRY ListHead,
|
109
|
+
PLIST_ENTRY ListToAppend)
|
110
|
+
{
|
111
|
+
PLIST_ENTRY ListEnd = ListHead->Blink;
|
112
|
+
|
113
|
+
ListHead->Blink->Flink = ListToAppend;
|
114
|
+
ListHead->Blink = ListToAppend->Blink;
|
115
|
+
ListToAppend->Blink->Flink = ListHead;
|
116
|
+
ListToAppend->Blink = ListEnd;
|
117
|
+
}
|
118
|
+
|
119
|
+
FORCEINLINE
|
120
|
+
PSINGLE_LIST_ENTRY
|
121
|
+
PopEntryList(
|
122
|
+
PSINGLE_LIST_ENTRY ListHead)
|
123
|
+
{
|
124
|
+
PSINGLE_LIST_ENTRY FirstEntry;
|
125
|
+
FirstEntry = ListHead->Next;
|
126
|
+
if (FirstEntry != NULL) {
|
127
|
+
ListHead->Next = FirstEntry->Next;
|
128
|
+
}
|
129
|
+
|
130
|
+
return FirstEntry;
|
131
|
+
}
|
132
|
+
|
133
|
+
|
134
|
+
FORCEINLINE
|
135
|
+
VOID
|
136
|
+
PushEntryList(
|
137
|
+
PSINGLE_LIST_ENTRY ListHead,
|
138
|
+
PSINGLE_LIST_ENTRY Entry)
|
139
|
+
{
|
140
|
+
Entry->Next = ListHead->Next;
|
141
|
+
ListHead->Next = Entry;
|
142
|
+
}
|
143
|
+
|
144
|
+
#endif
|