virtfs 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +18 -0
- data/.rspec +2 -0
- data/.travis.yml +8 -0
- data/Gemfile +4 -0
- data/LICENSE.txt +22 -0
- data/README.md +154 -0
- data/Rakefile +5 -0
- data/lib/virtfs-nativefs-thick.rb +1 -0
- data/lib/virtfs-nativefs-thin.rb +1 -0
- data/lib/virtfs.rb +38 -0
- data/lib/virtfs/activation.rb +97 -0
- data/lib/virtfs/block_io.rb +140 -0
- data/lib/virtfs/byte_range.rb +71 -0
- data/lib/virtfs/context.rb +300 -0
- data/lib/virtfs/context_manager.rb +175 -0
- data/lib/virtfs/context_switch_class_methods.rb +96 -0
- data/lib/virtfs/delegate_module.rb +40 -0
- data/lib/virtfs/dir_instance_delegate.rb +3 -0
- data/lib/virtfs/exception.rb +13 -0
- data/lib/virtfs/file_instance_delegate.rb +3 -0
- data/lib/virtfs/file_modes_and_options.rb +293 -0
- data/lib/virtfs/find_class_methods.rb +106 -0
- data/lib/virtfs/io_buffer.rb +133 -0
- data/lib/virtfs/io_instance_delegate.rb +3 -0
- data/lib/virtfs/kernel.rb +146 -0
- data/lib/virtfs/nativefs/thick.rb +30 -0
- data/lib/virtfs/nativefs/thick/dir_class_methods.rb +38 -0
- data/lib/virtfs/nativefs/thick/file_class_methods.rb +178 -0
- data/lib/virtfs/nativefs/thin.rb +32 -0
- data/lib/virtfs/nativefs/thin/dir.rb +30 -0
- data/lib/virtfs/nativefs/thin/dir_class_methods.rb +41 -0
- data/lib/virtfs/nativefs/thin/file.rb +112 -0
- data/lib/virtfs/nativefs/thin/file_class_methods.rb +181 -0
- data/lib/virtfs/protofs/protofs.rb +7 -0
- data/lib/virtfs/protofs/protofs_base.rb +12 -0
- data/lib/virtfs/protofs/protofs_dir.rb +13 -0
- data/lib/virtfs/protofs/protofs_dir_class.rb +31 -0
- data/lib/virtfs/protofs/protofs_file.rb +27 -0
- data/lib/virtfs/protofs/protofs_file_class.rb +136 -0
- data/lib/virtfs/stat.rb +100 -0
- data/lib/virtfs/thin_dir_delegator.rb +79 -0
- data/lib/virtfs/thin_file_delegator.rb +77 -0
- data/lib/virtfs/thin_io_delegator_methods.rb +301 -0
- data/lib/virtfs/thin_io_delegator_methods_bufferio.rb +337 -0
- data/lib/virtfs/v_dir.rb +238 -0
- data/lib/virtfs/v_file.rb +480 -0
- data/lib/virtfs/v_io.rb +243 -0
- data/lib/virtfs/v_pathname.rb +128 -0
- data/lib/virtfs/version.rb +3 -0
- data/spec/activate_spec.rb +202 -0
- data/spec/chroot_spec.rb +120 -0
- data/spec/context_manager_class_spec.rb +246 -0
- data/spec/context_manager_instance_spec.rb +255 -0
- data/spec/context_spec.rb +335 -0
- data/spec/data/UTF-16LE-data.txt +0 -0
- data/spec/data/UTF-8-data.txt +212 -0
- data/spec/dir_class_spec.rb +506 -0
- data/spec/dir_instance_spec.rb +208 -0
- data/spec/file_class_spec.rb +2106 -0
- data/spec/file_instance_spec.rb +154 -0
- data/spec/file_modes_and_options_spec.rb +1556 -0
- data/spec/find_spec.rb +142 -0
- data/spec/io_bufferio_size_shared_examples.rb +371 -0
- data/spec/io_bufferio_size_spec.rb +861 -0
- data/spec/io_bufferio_spec.rb +801 -0
- data/spec/io_class_spec.rb +145 -0
- data/spec/io_instance_spec.rb +516 -0
- data/spec/kernel_spec.rb +285 -0
- data/spec/mount_spec.rb +186 -0
- data/spec/nativefs_local_root_spec.rb +132 -0
- data/spec/path_spec.rb +39 -0
- data/spec/spec_helper.rb +126 -0
- data/tasks/rspec.rake +3 -0
- data/tasks/yard.rake +7 -0
- data/test/UTF-8-demo.txt +212 -0
- data/test/bench.rb +18 -0
- data/test/bio_internal_test.rb +45 -0
- data/test/delegate_io.rb +31 -0
- data/test/delegate_module.rb +62 -0
- data/test/encode_test.rb +42 -0
- data/test/enoent_test.rb +30 -0
- data/test/namespace_test.rb +42 -0
- data/test/read_block_valid_encoding.rb +44 -0
- data/test/read_test.rb +78 -0
- data/test/stream_readers.rb +46 -0
- data/test/utf-16-demo.txt +0 -0
- data/test/utf8_to_utf16.rb +77 -0
- data/test/wrapper_test.rb +34 -0
- data/virtfs.gemspec +29 -0
- metadata +230 -0
@@ -0,0 +1,31 @@
|
|
1
|
+
#
|
2
|
+
# Dir class methods - are instance methods of filesystem instance.
|
3
|
+
#
|
4
|
+
class ProtoFS
|
5
|
+
def dir_delete(p)
|
6
|
+
end
|
7
|
+
|
8
|
+
def dir_entries(p)
|
9
|
+
end
|
10
|
+
|
11
|
+
def dir_exist?(p)
|
12
|
+
end
|
13
|
+
|
14
|
+
def dir_foreach(p, &block)
|
15
|
+
end
|
16
|
+
|
17
|
+
def dir_mkdir(p, permissions)
|
18
|
+
end
|
19
|
+
|
20
|
+
def dir_new(dir, hash_args={})
|
21
|
+
Dir.new(self, lookup_dir(dir), hash_args)
|
22
|
+
end
|
23
|
+
|
24
|
+
private
|
25
|
+
|
26
|
+
def lookup_dir(dir)
|
27
|
+
#
|
28
|
+
# Get filesystem-specific handel for directory instance.
|
29
|
+
#
|
30
|
+
end
|
31
|
+
end
|
@@ -0,0 +1,27 @@
|
|
1
|
+
class ProtoFS
|
2
|
+
class File
|
3
|
+
def initialize(fs, instance_handle, parsed_args)
|
4
|
+
end
|
5
|
+
|
6
|
+
def atime
|
7
|
+
end
|
8
|
+
|
9
|
+
def chmod(permission)
|
10
|
+
end
|
11
|
+
|
12
|
+
def chown(owner, group)
|
13
|
+
end
|
14
|
+
|
15
|
+
def ctime
|
16
|
+
end
|
17
|
+
|
18
|
+
def flock(locking_constant)
|
19
|
+
end
|
20
|
+
|
21
|
+
def lstat
|
22
|
+
end
|
23
|
+
|
24
|
+
def truncate(len)
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
@@ -0,0 +1,136 @@
|
|
1
|
+
#
|
2
|
+
# File class methods - are instance methods of filesystem instance.
|
3
|
+
#
|
4
|
+
class ProtoFS
|
5
|
+
def file_atime(p)
|
6
|
+
end
|
7
|
+
|
8
|
+
def file_blockdev?(p)
|
9
|
+
end
|
10
|
+
|
11
|
+
def file_chardev?(p)
|
12
|
+
end
|
13
|
+
|
14
|
+
def file_chmod(permission, p)
|
15
|
+
end
|
16
|
+
|
17
|
+
def file_chown(owner, group, p)
|
18
|
+
end
|
19
|
+
|
20
|
+
def file_fileCtime(p)
|
21
|
+
end
|
22
|
+
|
23
|
+
def file_delete(p)
|
24
|
+
end
|
25
|
+
|
26
|
+
def file_directory?(p)
|
27
|
+
end
|
28
|
+
|
29
|
+
def file_executable?(p)
|
30
|
+
end
|
31
|
+
|
32
|
+
def file_executable_real?(p)
|
33
|
+
end
|
34
|
+
|
35
|
+
def file_exist?(p)
|
36
|
+
end
|
37
|
+
|
38
|
+
def file_file?(p)
|
39
|
+
end
|
40
|
+
|
41
|
+
def file_ftype(p)
|
42
|
+
end
|
43
|
+
|
44
|
+
def file_grpowned?(p)
|
45
|
+
end
|
46
|
+
|
47
|
+
def file_identical?(p1, p2)
|
48
|
+
end
|
49
|
+
|
50
|
+
def file_lchmod(permission, p)
|
51
|
+
end
|
52
|
+
|
53
|
+
def file_lchown(owner, group, p)
|
54
|
+
end
|
55
|
+
|
56
|
+
def file_link(p1, p2)
|
57
|
+
end
|
58
|
+
|
59
|
+
def file_lstat(p)
|
60
|
+
end
|
61
|
+
|
62
|
+
def file_mtime(p)
|
63
|
+
end
|
64
|
+
|
65
|
+
def file_owned?(p)
|
66
|
+
end
|
67
|
+
|
68
|
+
def file_pipe?(p)
|
69
|
+
end
|
70
|
+
|
71
|
+
def file_readable?(p)
|
72
|
+
end
|
73
|
+
|
74
|
+
def file_readable_real?(p)
|
75
|
+
end
|
76
|
+
|
77
|
+
def file_readlink(p)
|
78
|
+
end
|
79
|
+
|
80
|
+
def file_rename(p1, p2)
|
81
|
+
end
|
82
|
+
|
83
|
+
def file_setgid?(p)
|
84
|
+
end
|
85
|
+
|
86
|
+
def file_setuid?(p)
|
87
|
+
end
|
88
|
+
|
89
|
+
def file_size(p)
|
90
|
+
end
|
91
|
+
|
92
|
+
def file_socket?(p)
|
93
|
+
end
|
94
|
+
|
95
|
+
def file_stat(p)
|
96
|
+
end
|
97
|
+
|
98
|
+
def file_sticky?(p)
|
99
|
+
end
|
100
|
+
|
101
|
+
def file_symlink(oname, p)
|
102
|
+
end
|
103
|
+
|
104
|
+
def file_symlink?(p)
|
105
|
+
end
|
106
|
+
|
107
|
+
def file_truncate(p, len)
|
108
|
+
end
|
109
|
+
|
110
|
+
def file_utime(atime, mtime, p)
|
111
|
+
end
|
112
|
+
|
113
|
+
def file_world_readable?(p, len)
|
114
|
+
end
|
115
|
+
|
116
|
+
def file_world_writable?(p, len)
|
117
|
+
end
|
118
|
+
|
119
|
+
def file_writable?(p, len)
|
120
|
+
end
|
121
|
+
|
122
|
+
def file_writable_real?(p, len)
|
123
|
+
end
|
124
|
+
|
125
|
+
def file_new(f, parsed_args)
|
126
|
+
File.new(self, lookup_file(f), parsed_args)
|
127
|
+
end
|
128
|
+
|
129
|
+
private
|
130
|
+
|
131
|
+
def lookup_file(f)
|
132
|
+
#
|
133
|
+
# Get filesystem-specific handel for file instance.
|
134
|
+
#
|
135
|
+
end
|
136
|
+
end
|
data/lib/virtfs/stat.rb
ADDED
@@ -0,0 +1,100 @@
|
|
1
|
+
module VirtFS
|
2
|
+
# File Stat, contains attributes common to files on all files systems
|
3
|
+
class Stat
|
4
|
+
include Comparable
|
5
|
+
|
6
|
+
# Specified File Attributes supported by VirtFS (auto converted to symbols)
|
7
|
+
ATTR_ACCESSORS = %i(
|
8
|
+
atime
|
9
|
+
blksize
|
10
|
+
blockdev?
|
11
|
+
blocks
|
12
|
+
chardev?
|
13
|
+
ctime
|
14
|
+
dev
|
15
|
+
dev_major
|
16
|
+
dev_minor
|
17
|
+
directory?
|
18
|
+
executable?
|
19
|
+
executable_real?
|
20
|
+
file?
|
21
|
+
ftype
|
22
|
+
gid
|
23
|
+
grpowned?
|
24
|
+
ino
|
25
|
+
inspect
|
26
|
+
mode
|
27
|
+
mtime
|
28
|
+
nlink
|
29
|
+
owned?
|
30
|
+
pipe?
|
31
|
+
rdev
|
32
|
+
rdev_major
|
33
|
+
rdev_minor
|
34
|
+
readable?
|
35
|
+
readable_real?
|
36
|
+
setgid?
|
37
|
+
setuid?
|
38
|
+
size
|
39
|
+
size?
|
40
|
+
socket?
|
41
|
+
sticky?
|
42
|
+
symlink?
|
43
|
+
uid
|
44
|
+
world_readable?
|
45
|
+
world_writable?
|
46
|
+
writable?
|
47
|
+
writable_real?
|
48
|
+
zero?
|
49
|
+
)
|
50
|
+
|
51
|
+
# Helper to convert attribute name to instance variable name
|
52
|
+
#
|
53
|
+
# @param name [String] string name
|
54
|
+
# @return [String] string instance variable name
|
55
|
+
def self.iv_name(name)
|
56
|
+
name = name.to_s.chomp('?') if name.to_s.end_with?('?')
|
57
|
+
"@#{name}"
|
58
|
+
end
|
59
|
+
|
60
|
+
ATTR_ACCESSORS.each { |aa| class_eval("def #{aa}; #{iv_name(aa)}; end") }
|
61
|
+
|
62
|
+
# Attribute intializer, accepts Stat or Hash containing attributes
|
63
|
+
#
|
64
|
+
# @param obj [Stat,Hash] instance of object containing stat info to initialize
|
65
|
+
def initialize(obj)
|
66
|
+
if obj.is_a?(VfsRealFile::Stat)
|
67
|
+
stat_init(obj)
|
68
|
+
else
|
69
|
+
hash_init(obj)
|
70
|
+
end
|
71
|
+
end
|
72
|
+
|
73
|
+
# Sort file stats by modify time
|
74
|
+
def <=>(other)
|
75
|
+
return -1 if mtime < other.mtime
|
76
|
+
return 1 if mtime > other.mtime
|
77
|
+
0
|
78
|
+
end
|
79
|
+
|
80
|
+
private
|
81
|
+
|
82
|
+
def stat_init(obj)
|
83
|
+
ATTR_ACCESSORS.each do |aa|
|
84
|
+
next unless obj.respond_to?(aa)
|
85
|
+
instance_variable_set(iv_name(aa), obj.send(aa))
|
86
|
+
end
|
87
|
+
end
|
88
|
+
|
89
|
+
def hash_init(obj)
|
90
|
+
ATTR_ACCESSORS.each do |aa|
|
91
|
+
next unless obj.key?(aa)
|
92
|
+
instance_variable_set(iv_name(aa), obj[aa])
|
93
|
+
end
|
94
|
+
end
|
95
|
+
|
96
|
+
def iv_name(name)
|
97
|
+
self.class.iv_name(name)
|
98
|
+
end
|
99
|
+
end
|
100
|
+
end
|
@@ -0,0 +1,79 @@
|
|
1
|
+
module VirtFS
|
2
|
+
# Dispatches Dir calls to/from VirtFS and the 'Thin' subsystem
|
3
|
+
#
|
4
|
+
class ThinDirDelegator
|
5
|
+
# Instance methods
|
6
|
+
def initialize(fs_dir_obj, creation_path, fs_path, _hash_args)
|
7
|
+
@fs_dir_obj = fs_dir_obj
|
8
|
+
@creation_path = creation_path
|
9
|
+
@full_path = VfsRealFile.join(fs_dir_obj.fs.mount_point, fs_path)
|
10
|
+
@fs_path = fs_path
|
11
|
+
@dir_closed = false
|
12
|
+
@raw_pos = 0 # FS-specific position
|
13
|
+
@cur_tell = -1
|
14
|
+
@next_tell = 0
|
15
|
+
@tells = []
|
16
|
+
@raw_pos_to_tell = {}
|
17
|
+
end
|
18
|
+
|
19
|
+
def close
|
20
|
+
raise IOError, "closed directory" if @dir_closed
|
21
|
+
@fs_dir_obj.close
|
22
|
+
@dir_closed = true
|
23
|
+
nil
|
24
|
+
end
|
25
|
+
|
26
|
+
def each
|
27
|
+
return to_enum(__method__) unless block_given?
|
28
|
+
raise IOError, "closed directory" if @dir_closed
|
29
|
+
while (file_name = read)
|
30
|
+
yield(file_name)
|
31
|
+
end
|
32
|
+
self
|
33
|
+
end
|
34
|
+
|
35
|
+
def path
|
36
|
+
@creation_path
|
37
|
+
end
|
38
|
+
alias_method :to_path, :path
|
39
|
+
|
40
|
+
def pos=(tell_val)
|
41
|
+
raise IOError, "closed directory" if @dir_closed
|
42
|
+
seek(tell_val)
|
43
|
+
tell_val
|
44
|
+
end
|
45
|
+
|
46
|
+
def read
|
47
|
+
raise IOError, "closed directory" if @dir_closed
|
48
|
+
file_name, @raw_pos = @fs_dir_obj.read(@raw_pos)
|
49
|
+
file_name
|
50
|
+
end
|
51
|
+
|
52
|
+
def rewind
|
53
|
+
raise IOError, "closed directory" if @dir_closed
|
54
|
+
@raw_pos = 0
|
55
|
+
self
|
56
|
+
end
|
57
|
+
|
58
|
+
def seek(tell_val)
|
59
|
+
raise IOError, "closed directory" if @dir_closed
|
60
|
+
return self unless (new_pos = @tells[tell_val])
|
61
|
+
@cur_tell = tell_val
|
62
|
+
@raw_pos = new_pos
|
63
|
+
self
|
64
|
+
end
|
65
|
+
|
66
|
+
def tell
|
67
|
+
raise IOError, "closed directory" if @dir_closed
|
68
|
+
if (tell_val = @raw_pos_to_tell[@raw_pos])
|
69
|
+
return @cur_tell = tell_val
|
70
|
+
end
|
71
|
+
@cur_tell = @next_tell
|
72
|
+
@tells[@cur_tell] = @raw_pos
|
73
|
+
@raw_pos_to_tell[@raw_pos] = @cur_tell
|
74
|
+
@next_tell += 1
|
75
|
+
@cur_tell
|
76
|
+
end
|
77
|
+
alias_method :pos, :tell
|
78
|
+
end
|
79
|
+
end
|
@@ -0,0 +1,77 @@
|
|
1
|
+
require_relative 'thin_io_delegator_methods.rb'
|
2
|
+
|
3
|
+
module VirtFS
|
4
|
+
# Dispatches File calls to/from VirtFS and the 'Thin' subsystem
|
5
|
+
#
|
6
|
+
class ThinFileDelegator
|
7
|
+
attr_reader :fs_file_obj
|
8
|
+
|
9
|
+
include ThinIODelegatorMethods
|
10
|
+
|
11
|
+
# Instance methods
|
12
|
+
def initialize(fs_file_obj, creation_path, fs_path, parsed_args)
|
13
|
+
super(fs_file_obj, parsed_args) # Initialize IO instance.
|
14
|
+
# @size = @fs_io_obj.size
|
15
|
+
@creation_path = creation_path
|
16
|
+
@full_path = VfsRealFile.join(@fs_io_obj.fs.mount_point, fs_path)
|
17
|
+
@fs_path = fs_path
|
18
|
+
end
|
19
|
+
|
20
|
+
def re_initialize(io_obj)
|
21
|
+
super(io_obj) # re-initialize IO
|
22
|
+
@creation_path = io_obj.instance_variable_get(:@creation_path)
|
23
|
+
@full_path = io_obj.instance_variable_get(:@full_path)
|
24
|
+
@fs_path = io_obj.instance_variable_get(:@fs_path)
|
25
|
+
end
|
26
|
+
|
27
|
+
def atime
|
28
|
+
file_open
|
29
|
+
@fs_io_obj.atime
|
30
|
+
end
|
31
|
+
|
32
|
+
def chmod(permission)
|
33
|
+
file_open
|
34
|
+
@fs_io_obj.chmod(permission)
|
35
|
+
end
|
36
|
+
|
37
|
+
def chown(owner, group)
|
38
|
+
file_open
|
39
|
+
@fs_io_obj.chown(owner, group)
|
40
|
+
end
|
41
|
+
|
42
|
+
def ctime
|
43
|
+
file_open
|
44
|
+
@fs_io_obj.ctime
|
45
|
+
end
|
46
|
+
|
47
|
+
def flock(locking_constant)
|
48
|
+
file_open
|
49
|
+
@fs_io_obj.flock(locking_constant)
|
50
|
+
end
|
51
|
+
|
52
|
+
def lstat
|
53
|
+
file_open
|
54
|
+
@fs_io_obj.lstat
|
55
|
+
end
|
56
|
+
|
57
|
+
def mtime
|
58
|
+
file_open
|
59
|
+
@fs_io_obj.mtime
|
60
|
+
end
|
61
|
+
|
62
|
+
def path
|
63
|
+
@creation_path
|
64
|
+
end
|
65
|
+
alias_method :to_path, :path
|
66
|
+
|
67
|
+
def size
|
68
|
+
file_open
|
69
|
+
@size
|
70
|
+
end
|
71
|
+
|
72
|
+
def truncate(len)
|
73
|
+
file_open
|
74
|
+
@fs_io_obj.truncate(len)
|
75
|
+
end
|
76
|
+
end
|
77
|
+
end
|