virtfs 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (91) hide show
  1. checksums.yaml +7 -0
  2. data/.gitignore +18 -0
  3. data/.rspec +2 -0
  4. data/.travis.yml +8 -0
  5. data/Gemfile +4 -0
  6. data/LICENSE.txt +22 -0
  7. data/README.md +154 -0
  8. data/Rakefile +5 -0
  9. data/lib/virtfs-nativefs-thick.rb +1 -0
  10. data/lib/virtfs-nativefs-thin.rb +1 -0
  11. data/lib/virtfs.rb +38 -0
  12. data/lib/virtfs/activation.rb +97 -0
  13. data/lib/virtfs/block_io.rb +140 -0
  14. data/lib/virtfs/byte_range.rb +71 -0
  15. data/lib/virtfs/context.rb +300 -0
  16. data/lib/virtfs/context_manager.rb +175 -0
  17. data/lib/virtfs/context_switch_class_methods.rb +96 -0
  18. data/lib/virtfs/delegate_module.rb +40 -0
  19. data/lib/virtfs/dir_instance_delegate.rb +3 -0
  20. data/lib/virtfs/exception.rb +13 -0
  21. data/lib/virtfs/file_instance_delegate.rb +3 -0
  22. data/lib/virtfs/file_modes_and_options.rb +293 -0
  23. data/lib/virtfs/find_class_methods.rb +106 -0
  24. data/lib/virtfs/io_buffer.rb +133 -0
  25. data/lib/virtfs/io_instance_delegate.rb +3 -0
  26. data/lib/virtfs/kernel.rb +146 -0
  27. data/lib/virtfs/nativefs/thick.rb +30 -0
  28. data/lib/virtfs/nativefs/thick/dir_class_methods.rb +38 -0
  29. data/lib/virtfs/nativefs/thick/file_class_methods.rb +178 -0
  30. data/lib/virtfs/nativefs/thin.rb +32 -0
  31. data/lib/virtfs/nativefs/thin/dir.rb +30 -0
  32. data/lib/virtfs/nativefs/thin/dir_class_methods.rb +41 -0
  33. data/lib/virtfs/nativefs/thin/file.rb +112 -0
  34. data/lib/virtfs/nativefs/thin/file_class_methods.rb +181 -0
  35. data/lib/virtfs/protofs/protofs.rb +7 -0
  36. data/lib/virtfs/protofs/protofs_base.rb +12 -0
  37. data/lib/virtfs/protofs/protofs_dir.rb +13 -0
  38. data/lib/virtfs/protofs/protofs_dir_class.rb +31 -0
  39. data/lib/virtfs/protofs/protofs_file.rb +27 -0
  40. data/lib/virtfs/protofs/protofs_file_class.rb +136 -0
  41. data/lib/virtfs/stat.rb +100 -0
  42. data/lib/virtfs/thin_dir_delegator.rb +79 -0
  43. data/lib/virtfs/thin_file_delegator.rb +77 -0
  44. data/lib/virtfs/thin_io_delegator_methods.rb +301 -0
  45. data/lib/virtfs/thin_io_delegator_methods_bufferio.rb +337 -0
  46. data/lib/virtfs/v_dir.rb +238 -0
  47. data/lib/virtfs/v_file.rb +480 -0
  48. data/lib/virtfs/v_io.rb +243 -0
  49. data/lib/virtfs/v_pathname.rb +128 -0
  50. data/lib/virtfs/version.rb +3 -0
  51. data/spec/activate_spec.rb +202 -0
  52. data/spec/chroot_spec.rb +120 -0
  53. data/spec/context_manager_class_spec.rb +246 -0
  54. data/spec/context_manager_instance_spec.rb +255 -0
  55. data/spec/context_spec.rb +335 -0
  56. data/spec/data/UTF-16LE-data.txt +0 -0
  57. data/spec/data/UTF-8-data.txt +212 -0
  58. data/spec/dir_class_spec.rb +506 -0
  59. data/spec/dir_instance_spec.rb +208 -0
  60. data/spec/file_class_spec.rb +2106 -0
  61. data/spec/file_instance_spec.rb +154 -0
  62. data/spec/file_modes_and_options_spec.rb +1556 -0
  63. data/spec/find_spec.rb +142 -0
  64. data/spec/io_bufferio_size_shared_examples.rb +371 -0
  65. data/spec/io_bufferio_size_spec.rb +861 -0
  66. data/spec/io_bufferio_spec.rb +801 -0
  67. data/spec/io_class_spec.rb +145 -0
  68. data/spec/io_instance_spec.rb +516 -0
  69. data/spec/kernel_spec.rb +285 -0
  70. data/spec/mount_spec.rb +186 -0
  71. data/spec/nativefs_local_root_spec.rb +132 -0
  72. data/spec/path_spec.rb +39 -0
  73. data/spec/spec_helper.rb +126 -0
  74. data/tasks/rspec.rake +3 -0
  75. data/tasks/yard.rake +7 -0
  76. data/test/UTF-8-demo.txt +212 -0
  77. data/test/bench.rb +18 -0
  78. data/test/bio_internal_test.rb +45 -0
  79. data/test/delegate_io.rb +31 -0
  80. data/test/delegate_module.rb +62 -0
  81. data/test/encode_test.rb +42 -0
  82. data/test/enoent_test.rb +30 -0
  83. data/test/namespace_test.rb +42 -0
  84. data/test/read_block_valid_encoding.rb +44 -0
  85. data/test/read_test.rb +78 -0
  86. data/test/stream_readers.rb +46 -0
  87. data/test/utf-16-demo.txt +0 -0
  88. data/test/utf8_to_utf16.rb +77 -0
  89. data/test/wrapper_test.rb +34 -0
  90. data/virtfs.gemspec +29 -0
  91. metadata +230 -0
@@ -0,0 +1,178 @@
1
+ #
2
+ # File class methods - are instance methods of filesystem instance.
3
+ #
4
+ module VirtFS::NativeFS # rubocop:disable Style/ClassAndModuleChildren
5
+ class Thick
6
+ module FileClassMethods # rubocop:disable ModuleLength
7
+ def file_atime(p)
8
+ VfsRealFile.atime(p)
9
+ end
10
+
11
+ def file_blockdev?(p)
12
+ VfsRealFile.blockdev?(apply_root(p))
13
+ end
14
+
15
+ def file_chardev?(p)
16
+ VfsRealFile.chardev?(apply_root(p))
17
+ end
18
+
19
+ def file_chmod(permission, p)
20
+ VfsRealFile.chmod(permission, apply_root(p))
21
+ end
22
+
23
+ def file_chown(owner, group, p)
24
+ VfsRealFile.chown(owner, group, apply_root(p))
25
+ end
26
+
27
+ def file_ctime(p)
28
+ VfsRealFile.ctime(apply_root(p))
29
+ end
30
+
31
+ def file_delete(p)
32
+ VfsRealFile.delete(apply_root(p))
33
+ end
34
+
35
+ def file_directory?(p)
36
+ VfsRealFile.directory?(apply_root(p))
37
+ end
38
+
39
+ def file_executable?(p)
40
+ VfsRealFile.executable?(apply_root(p))
41
+ end
42
+
43
+ def file_executable_real?(p)
44
+ VfsRealFile.executable_real?(apply_root(p))
45
+ end
46
+
47
+ def file_exist?(p)
48
+ VfsRealFile.exist?(apply_root(p))
49
+ end
50
+
51
+ def file_file?(p)
52
+ VfsRealFile.file?(apply_root(p))
53
+ end
54
+
55
+ def file_ftype(p)
56
+ VfsRealFile.ftype(apply_root(p))
57
+ end
58
+
59
+ def file_grpowned?(p)
60
+ VfsRealFile.grpowned?(apply_root(p))
61
+ end
62
+
63
+ def file_identical?(p1, p2)
64
+ VfsRealFile.identical?(apply_root(p1), apply_root(p2))
65
+ end
66
+
67
+ def file_lchmod(permission, p)
68
+ VfsRealFile.lchmod(permission, apply_root(p))
69
+ end
70
+
71
+ def file_lchown(owner, group, p)
72
+ VfsRealFile.lchown(owner, group, apply_root(p))
73
+ end
74
+
75
+ def file_link(p1, p2)
76
+ VfsRealFile.link(apply_root(p1), apply_root(p2))
77
+ end
78
+
79
+ def file_lstat(p)
80
+ VfsRealFile.lstat(apply_root(p))
81
+ end
82
+
83
+ def file_mtime(p)
84
+ VfsRealFile.mtime(apply_root(p))
85
+ end
86
+
87
+ def file_owned?(p)
88
+ VfsRealFile.owned?(apply_root(p))
89
+ end
90
+
91
+ def file_pipe?(p)
92
+ VfsRealFile.pipe?(apply_root(p))
93
+ end
94
+
95
+ def file_readable?(p)
96
+ VfsRealFile.readable?(apply_root(p))
97
+ end
98
+
99
+ def file_readable_real?(p)
100
+ VfsRealFile.readable_real?(apply_root(p))
101
+ end
102
+
103
+ def file_readlink(p)
104
+ VfsRealFile.readlink(apply_root(p))
105
+ end
106
+
107
+ def file_rename(p1, p2)
108
+ VfsRealFile.rename(apply_root(p1), apply_root(p2))
109
+ end
110
+
111
+ def file_setgid?(p)
112
+ VfsRealFile.setgid?(apply_root(p))
113
+ end
114
+
115
+ def file_setuid?(p)
116
+ VfsRealFile.setuid?(apply_root(p))
117
+ end
118
+
119
+ def file_size(p)
120
+ VfsRealFile.size(apply_root(p))
121
+ end
122
+
123
+ def file_socket?(p)
124
+ VfsRealFile.socket?(apply_root(p))
125
+ end
126
+
127
+ def file_stat(p)
128
+ VfsRealFile.stat(apply_root(p))
129
+ end
130
+
131
+ def file_sticky?(p)
132
+ VfsRealFile.sticky?(apply_root(p))
133
+ end
134
+
135
+ def file_symlink(oname, p)
136
+ VfsRealFile.symlink(oname, apply_root(p))
137
+ end
138
+
139
+ def file_symlink?(p)
140
+ VfsRealFile.symlink?(apply_root(p))
141
+ end
142
+
143
+ def file_truncate(p, len)
144
+ VfsRealFile.truncate(apply_root(p), len)
145
+ end
146
+
147
+ def file_utime(atime, mtime, p)
148
+ VfsRealFile.utime(atime, mtime, apply_root(p))
149
+ end
150
+
151
+ def file_world_readable?(p)
152
+ VfsRealFile.world_readable?(apply_root(p))
153
+ end
154
+
155
+ def file_world_writable?(p)
156
+ VfsRealFile.world_writable?(apply_root(p))
157
+ end
158
+
159
+ def file_writable?(p)
160
+ VfsRealFile.writable?(apply_root(p))
161
+ end
162
+
163
+ def file_writable_real?(p)
164
+ VfsRealFile.writable_real?(apply_root(p))
165
+ end
166
+
167
+ def file_new(f, parsed_args, _open_path, cwd)
168
+ owd = VfsRealDir.getwd
169
+ begin
170
+ VfsRealDir.chdir(cwd)
171
+ return VfsRealFile.new(apply_root(f), *parsed_args.args)
172
+ ensure
173
+ VfsRealDir.chdir(owd)
174
+ end
175
+ end
176
+ end
177
+ end
178
+ end
@@ -0,0 +1,32 @@
1
+ require_relative 'thin/file'
2
+ require_relative 'thin/dir'
3
+ require_relative 'thin/file_class_methods'
4
+ require_relative 'thin/dir_class_methods'
5
+
6
+ module VirtFS::NativeFS # rubocop:disable Style/ClassAndModuleChildren
7
+ class Thin
8
+ attr_accessor :mount_point, :name
9
+
10
+ include FileClassMethods
11
+ include DirClassMethods
12
+
13
+ def initialize(root = VfsRealFile::SEPARATOR)
14
+ @mount_point = nil
15
+ @name = self.class.name
16
+ @root = root
17
+ end
18
+
19
+ def thin_interface?
20
+ true
21
+ end
22
+
23
+ def umount
24
+ @mount_point = nil
25
+ end
26
+
27
+ def apply_root(path)
28
+ VfsRealFile.join(@root, path)
29
+ end
30
+ private :apply_root
31
+ end
32
+ end
@@ -0,0 +1,30 @@
1
+ module VirtFS::NativeFS # rubocop:disable Style/ClassAndModuleChildren
2
+ class Thin
3
+ class Dir
4
+ attr_reader :fs, :dir_obj
5
+
6
+ def initialize(fs, instance_handle, hash_args)
7
+ @fs = fs
8
+ @dir_obj = instance_handle
9
+ @hash_args = hash_args
10
+
11
+ @cache = nil
12
+ end
13
+
14
+ def close
15
+ @dir_obj.close
16
+ end
17
+
18
+ # returns file_name and new position.
19
+ def read(pos)
20
+ return cache[pos], pos + 1
21
+ end
22
+
23
+ private
24
+
25
+ def cache
26
+ @cache ||= @dir_obj.each.to_a
27
+ end
28
+ end
29
+ end
30
+ end
@@ -0,0 +1,41 @@
1
+ #
2
+ # Dir class methods - are instance methods of filesystem instance.
3
+ #
4
+ module VirtFS::NativeFS # rubocop:disable Style/ClassAndModuleChildren
5
+ class Thin
6
+ module DirClassMethods
7
+ def dir_delete(p)
8
+ VfsRealDir.delete(apply_root(p))
9
+ end
10
+
11
+ def dir_entries(p)
12
+ VfsRealDir.entries(apply_root(p))
13
+ end
14
+
15
+ def dir_exist?(p)
16
+ VfsRealDir.exist?(apply_root(p))
17
+ end
18
+
19
+ def dir_foreach(p, &block)
20
+ VfsRealDir.foreach(apply_root(p), &block)
21
+ end
22
+
23
+ def dir_mkdir(p, permissions)
24
+ VfsRealDir.mkdir(apply_root(p), permissions)
25
+ end
26
+
27
+ def dir_new(fs_rel_path, hash_args, _open_path, _cwd)
28
+ Dir.new(self, lookup_dir(apply_root(fs_rel_path), hash_args), hash_args)
29
+ end
30
+
31
+ private
32
+
33
+ def lookup_dir(fs_rel_path, hash_args)
34
+ #
35
+ # Get filesystem-specific handle for directory instance.
36
+ #
37
+ VfsRealDir.new(fs_rel_path, hash_args)
38
+ end
39
+ end
40
+ end
41
+ end
@@ -0,0 +1,112 @@
1
+ module VirtFS::NativeFS # rubocop:disable Style/ClassAndModuleChildren
2
+ class Thin
3
+ class File
4
+ attr_reader :fs, :file_obj, :block_size
5
+
6
+ def initialize(fs, instance_handle, parsed_args)
7
+ @fs = fs
8
+ @file_obj = instance_handle
9
+ @parsed_args = parsed_args
10
+ @block_size = 512
11
+ end
12
+
13
+ def atime
14
+ @file_obj.atime
15
+ end
16
+
17
+ def chmod(permission)
18
+ @file_obj.chmod(permission)
19
+ end
20
+
21
+ def chown(owner, group)
22
+ @file_obj.chown(owner, group)
23
+ end
24
+
25
+ def close
26
+ @file_obj.close unless @file_obj.closed?
27
+ end
28
+
29
+ def close_on_exec?
30
+ @file_obj.close_on_exec?
31
+ end
32
+
33
+ def close_on_exec=(bool)
34
+ @file_obj.close_on_exec = bool
35
+ end
36
+
37
+ def close_read
38
+ @file_obj.close_read
39
+ end
40
+
41
+ def close_write
42
+ @file_obj.close_write
43
+ end
44
+
45
+ def ctime
46
+ @file_obj.ctime
47
+ end
48
+
49
+ def fcntl(cmd, arg)
50
+ @file_obj.fcntl(cmd, arg)
51
+ end
52
+
53
+ def fdatasync
54
+ @file_obj.fdatasync
55
+ end
56
+
57
+ def flush
58
+ @file_obj.flush
59
+ end
60
+
61
+ def fileno
62
+ @file_obj.fileno
63
+ end
64
+
65
+ def flock(locking_constant)
66
+ @file_obj.flock(locking_constant)
67
+ end
68
+
69
+ def fsync
70
+ @file_obj.fsync
71
+ end
72
+
73
+ def isatty
74
+ @file_obj.isatty
75
+ end
76
+
77
+ def lstat
78
+ @file_obj.lstat
79
+ end
80
+
81
+ def mtime
82
+ @file_obj.mtime
83
+ end
84
+
85
+ def pid
86
+ @file_obj.pid
87
+ end
88
+
89
+ def raw_read(start_byte, num_bytes)
90
+ @file_obj.sysseek(start_byte, IO::SEEK_SET)
91
+ @file_obj.sysread(num_bytes)
92
+ end
93
+
94
+ def raw_write(start_byte, buf)
95
+ @file_obj.sysseek(start_byte, IO::SEEK_SET)
96
+ @file_obj.syswrite(buf)
97
+ end
98
+
99
+ def size
100
+ @file_obj.size
101
+ end
102
+
103
+ def stat
104
+ @file_obj.stat
105
+ end
106
+
107
+ def truncate(len)
108
+ @file_obj.truncate(len)
109
+ end
110
+ end
111
+ end
112
+ end
@@ -0,0 +1,181 @@
1
+ #
2
+ # File class methods - are instance methods of filesystem instance.
3
+ #
4
+ module VirtFS::NativeFS # rubocop:disable Style/ClassAndModuleChildren
5
+ class Thin
6
+ module FileClassMethods # rubocop:disable ModuleLength
7
+ def file_atime(p)
8
+ VfsRealFile.atime(p)
9
+ end
10
+
11
+ def file_blockdev?(p)
12
+ VfsRealFile.blockdev?(apply_root(p))
13
+ end
14
+
15
+ def file_chardev?(p)
16
+ VfsRealFile.chardev?(apply_root(p))
17
+ end
18
+
19
+ def file_chmod(permission, p)
20
+ VfsRealFile.chmod(permission, apply_root(p))
21
+ end
22
+
23
+ def file_chown(owner, group, p)
24
+ VfsRealFile.chown(owner, group, apply_root(p))
25
+ end
26
+
27
+ def file_ctime(p)
28
+ VfsRealFile.ctime(apply_root(p))
29
+ end
30
+
31
+ def file_delete(p)
32
+ VfsRealFile.delete(apply_root(p))
33
+ end
34
+
35
+ def file_directory?(p)
36
+ VfsRealFile.directory?(apply_root(p))
37
+ end
38
+
39
+ def file_executable?(p)
40
+ VfsRealFile.executable?(apply_root(p))
41
+ end
42
+
43
+ def file_executable_real?(p)
44
+ VfsRealFile.executable_real?(apply_root(p))
45
+ end
46
+
47
+ def file_exist?(p)
48
+ VfsRealFile.exist?(apply_root(p))
49
+ end
50
+
51
+ def file_file?(p)
52
+ VfsRealFile.file?(apply_root(p))
53
+ end
54
+
55
+ def file_ftype(p)
56
+ VfsRealFile.ftype(apply_root(p))
57
+ end
58
+
59
+ def file_grpowned?(p)
60
+ VfsRealFile.grpowned?(apply_root(p))
61
+ end
62
+
63
+ def file_identical?(p1, p2)
64
+ VfsRealFile.identical?(apply_root(p1), apply_root(p2))
65
+ end
66
+
67
+ def file_lchmod(permission, p)
68
+ VfsRealFile.lchmod(permission, apply_root(p))
69
+ end
70
+
71
+ def file_lchown(owner, group, p)
72
+ VfsRealFile.lchown(owner, group, apply_root(p))
73
+ end
74
+
75
+ def file_link(p1, p2)
76
+ VfsRealFile.link(apply_root(p1), apply_root(p2))
77
+ end
78
+
79
+ def file_lstat(p)
80
+ VfsRealFile.lstat(apply_root(p))
81
+ end
82
+
83
+ def file_mtime(p)
84
+ VfsRealFile.mtime(apply_root(p))
85
+ end
86
+
87
+ def file_owned?(p)
88
+ VfsRealFile.owned?(apply_root(p))
89
+ end
90
+
91
+ def file_pipe?(p)
92
+ VfsRealFile.pipe?(apply_root(p))
93
+ end
94
+
95
+ def file_readable?(p)
96
+ VfsRealFile.readable?(apply_root(p))
97
+ end
98
+
99
+ def file_readable_real?(p)
100
+ VfsRealFile.readable_real?(apply_root(p))
101
+ end
102
+
103
+ def file_readlink(p)
104
+ VfsRealFile.readlink(apply_root(p))
105
+ end
106
+
107
+ def file_rename(p1, p2)
108
+ VfsRealFile.rename(apply_root(p1), apply_root(p2))
109
+ end
110
+
111
+ def file_setgid?(p)
112
+ VfsRealFile.setgid?(apply_root(p))
113
+ end
114
+
115
+ def file_setuid?(p)
116
+ VfsRealFile.setuid?(apply_root(p))
117
+ end
118
+
119
+ def file_size(p)
120
+ VfsRealFile.size(apply_root(p))
121
+ end
122
+
123
+ def file_socket?(p)
124
+ VfsRealFile.socket?(apply_root(p))
125
+ end
126
+
127
+ def file_stat(p)
128
+ VfsRealFile.stat(apply_root(p))
129
+ end
130
+
131
+ def file_sticky?(p)
132
+ VfsRealFile.sticky?(apply_root(p))
133
+ end
134
+
135
+ def file_symlink(oname, p)
136
+ VfsRealFile.symlink(oname, apply_root(p))
137
+ end
138
+
139
+ def file_symlink?(p)
140
+ VfsRealFile.symlink?(apply_root(p))
141
+ end
142
+
143
+ def file_truncate(p, len)
144
+ VfsRealFile.truncate(apply_root(p), len)
145
+ end
146
+
147
+ def file_utime(atime, mtime, p)
148
+ VfsRealFile.utime(atime, mtime, apply_root(p))
149
+ end
150
+
151
+ def file_world_readable?(p)
152
+ VfsRealFile.world_readable?(apply_root(p))
153
+ end
154
+
155
+ def file_world_writable?(p)
156
+ VfsRealFile.world_writable?(apply_root(p))
157
+ end
158
+
159
+ def file_writable?(p)
160
+ VfsRealFile.writable?(apply_root(p))
161
+ end
162
+
163
+ def file_writable_real?(p)
164
+ VfsRealFile.writable_real?(apply_root(p))
165
+ end
166
+
167
+ def file_new(f, parsed_args, _open_path, _cwd)
168
+ File.new(self, lookup_file(apply_root(f), parsed_args), parsed_args)
169
+ end
170
+
171
+ private
172
+
173
+ def lookup_file(f, parsed_args)
174
+ #
175
+ # Get filesystem-specific handle for file instance.
176
+ #
177
+ VfsRealFile.new(f, parsed_args.mode_bits & ~VfsRealFile::APPEND, :binmode => true)
178
+ end
179
+ end
180
+ end
181
+ end