virtfs-camcorderfs 0.0.1
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.
- checksums.yaml +7 -0
- data/.gitignore +9 -0
- data/.rspec +2 -0
- data/.travis.yml +4 -0
- data/Gemfile +6 -0
- data/LICENSE.txt +21 -0
- data/README.md +78 -0
- data/Rakefile +6 -0
- data/bin/console +14 -0
- data/bin/setup +7 -0
- data/lib/virtfs-camcorderfs.rb +1 -0
- data/lib/virtfs/camcorderfs.rb +13 -0
- data/lib/virtfs/camcorderfs/cc_delegate.rb +18 -0
- data/lib/virtfs/camcorderfs/cc_delegate/dir_class_methods.rb +51 -0
- data/lib/virtfs/camcorderfs/cc_delegate/dir_instance_methods.rb +20 -0
- data/lib/virtfs/camcorderfs/cc_delegate/file_class_methods.rb +188 -0
- data/lib/virtfs/camcorderfs/cc_delegate/file_instance_methods.rb +145 -0
- data/lib/virtfs/camcorderfs/dir.rb +37 -0
- data/lib/virtfs/camcorderfs/file.rb +157 -0
- data/lib/virtfs/camcorderfs/fs.rb +106 -0
- data/lib/virtfs/camcorderfs/fs/dir_class_methods.rb +38 -0
- data/lib/virtfs/camcorderfs/fs/dir_instance_methods.rb +20 -0
- data/lib/virtfs/camcorderfs/fs/file_class_methods.rb +179 -0
- data/lib/virtfs/camcorderfs/fs/file_instance_methods.rb +144 -0
- data/lib/virtfs/camcorderfs/real_dir.rb +27 -0
- data/lib/virtfs/camcorderfs/real_file.rb +27 -0
- data/lib/virtfs/camcorderfs/version.rb +5 -0
- data/virtfs-camcorderfs.gemspec +32 -0
- metadata +143 -0
@@ -0,0 +1,145 @@
|
|
1
|
+
module VirtFS::CamcorderFS # rubocop:disable Style/ClassAndModuleChildren
|
2
|
+
#
|
3
|
+
# File instance methods - called by CamcorderFS::File instances.
|
4
|
+
# Methods are wraped in delegate class for camcorder interposition.
|
5
|
+
#
|
6
|
+
class CcDelegate
|
7
|
+
module FileInstanceMethods
|
8
|
+
#
|
9
|
+
# File instance methods - implementation.
|
10
|
+
#
|
11
|
+
def file_i_atime(instance_handle)
|
12
|
+
instance_call(:atime, instance_handle)
|
13
|
+
end
|
14
|
+
|
15
|
+
def file_i_chmod(instance_handle, permission)
|
16
|
+
instance_call(:chmod, instance_handle, permission)
|
17
|
+
end
|
18
|
+
|
19
|
+
def file_i_chown(instance_handle, owner, group)
|
20
|
+
instance_call(:chown, instance_handle, owner, group)
|
21
|
+
end
|
22
|
+
|
23
|
+
def file_i_ctime(instance_handle)
|
24
|
+
instance_call(:ctime, instance_handle)
|
25
|
+
end
|
26
|
+
|
27
|
+
def file_i_flock(instance_handle, locking_constant)
|
28
|
+
instance_call(:flock, instance_handle, locking_constant)
|
29
|
+
end
|
30
|
+
|
31
|
+
def file_i_lstat(instance_handle)
|
32
|
+
VirtFS::Stat.new(instance_call(:lstat, instance_handle))
|
33
|
+
end
|
34
|
+
|
35
|
+
def file_i_mtime(instance_handle)
|
36
|
+
instance_call(:mtime, instance_handle)
|
37
|
+
end
|
38
|
+
|
39
|
+
def file_i_size(instance_handle)
|
40
|
+
instance_call(:size, instance_handle)
|
41
|
+
end
|
42
|
+
|
43
|
+
def file_i_truncate(instance_handle, to_size)
|
44
|
+
instance_call(:truncate, instance_handle, to_size)
|
45
|
+
end
|
46
|
+
|
47
|
+
#
|
48
|
+
# IO instance methods.
|
49
|
+
#
|
50
|
+
def file_i_close(instance_handle)
|
51
|
+
instance_call(:close, instance_handle)
|
52
|
+
end
|
53
|
+
|
54
|
+
def file_i_close_on_exec?(instance_handle)
|
55
|
+
instance_call(:close_on_exec?, instance_handle)
|
56
|
+
end
|
57
|
+
|
58
|
+
def file_i_close_on_exec=(instance_handle, bool_val)
|
59
|
+
instance_call(:close_on_exec=, instance_handle, bool_val)
|
60
|
+
end
|
61
|
+
|
62
|
+
def file_i_close_read(instance_handle)
|
63
|
+
instance_call(:close_read, instance_handle)
|
64
|
+
end
|
65
|
+
|
66
|
+
def file_i_close_write(instance_handle)
|
67
|
+
instance_call(:close_write, instance_handle)
|
68
|
+
end
|
69
|
+
|
70
|
+
def file_i_fcntl(instance_handle, cmd, arg)
|
71
|
+
instance_call(:fcntl, instance_handle, cmd, arg)
|
72
|
+
end
|
73
|
+
|
74
|
+
def file_i_fdatasync(instance_handle)
|
75
|
+
instance_call(:fdatasync, instance_handle)
|
76
|
+
end
|
77
|
+
|
78
|
+
def file_i_fileno(instance_handle)
|
79
|
+
instance_call(:fileno, instance_handle)
|
80
|
+
end
|
81
|
+
|
82
|
+
def file_i_flush(instance_handle)
|
83
|
+
instance_call(:flush, instance_handle)
|
84
|
+
end
|
85
|
+
|
86
|
+
def file_i_fsync(instance_handle)
|
87
|
+
instance_call(:fsync, instance_handle)
|
88
|
+
end
|
89
|
+
|
90
|
+
def file_i_ioctl(instance_handle, cms, arg)
|
91
|
+
instance_call(:ioctl, instance_handle, cms, arg)
|
92
|
+
end
|
93
|
+
|
94
|
+
def file_i_isatty(instance_handle)
|
95
|
+
instance_call(:isatty, instance_handle)
|
96
|
+
end
|
97
|
+
|
98
|
+
def file_i_pid(instance_handle)
|
99
|
+
instance_call(:pid, instance_handle)
|
100
|
+
end
|
101
|
+
|
102
|
+
def file_i_raw_read(instance_handle, start_byte, num_bytes)
|
103
|
+
instance_handle.sysseek(start_byte, IO::SEEK_SET)
|
104
|
+
instance_handle.sysread(num_bytes)
|
105
|
+
end
|
106
|
+
|
107
|
+
def file_i_raw_write(instance_handle, start_byte, buf)
|
108
|
+
instance_handle.sysseek(start_byte, IO::SEEK_SET)
|
109
|
+
instance_handle.syswrite(buf)
|
110
|
+
end
|
111
|
+
|
112
|
+
def file_i_readpartial(instance_handle, limit, result)
|
113
|
+
instance_call(:readpartial, instance_handle, limit, result)
|
114
|
+
end
|
115
|
+
|
116
|
+
def file_i_read_nonblock(instance_handle, limit, result)
|
117
|
+
instance_call(:read_nonblock, instance_handle, limit, result)
|
118
|
+
end
|
119
|
+
|
120
|
+
def file_i_stat(instance_handle)
|
121
|
+
VirtFS::Stat.new(instance_call(:stat, instance_handle))
|
122
|
+
end
|
123
|
+
|
124
|
+
def file_i_sync(instance_handle)
|
125
|
+
instance_call(:sync, instance_handle)
|
126
|
+
end
|
127
|
+
|
128
|
+
def file_i_sync=(instance_handle, bool_val)
|
129
|
+
instance_call(:sync=, instance_handle, bool_val)
|
130
|
+
end
|
131
|
+
|
132
|
+
def file_i_to_i(instance_handle)
|
133
|
+
instance_call(:to_i, instance_handle)
|
134
|
+
end
|
135
|
+
|
136
|
+
def file_i_tty?(instance_handle)
|
137
|
+
instance_call(:tty?, instance_handle)
|
138
|
+
end
|
139
|
+
|
140
|
+
def file_i_write_nonblock(instance_handle, buf)
|
141
|
+
instance_call(:write_nonblock, instance_handle, buf)
|
142
|
+
end
|
143
|
+
end
|
144
|
+
end
|
145
|
+
end
|
@@ -0,0 +1,37 @@
|
|
1
|
+
module VirtFS::CamcorderFS # rubocop:disable Style/ClassAndModuleChildren
|
2
|
+
#
|
3
|
+
# CamcorderFS::Dir class.
|
4
|
+
# Instance methods call into CamcorderFS::FS instance.
|
5
|
+
#
|
6
|
+
class Dir
|
7
|
+
attr_reader :fs
|
8
|
+
|
9
|
+
NS_PFX = "dir_i_"
|
10
|
+
|
11
|
+
def initialize(fs, instance_handle, hash_args)
|
12
|
+
@fs = fs
|
13
|
+
@instance_handle = instance_handle
|
14
|
+
@hash_args = hash_args
|
15
|
+
@cache = nil
|
16
|
+
end
|
17
|
+
|
18
|
+
def close
|
19
|
+
fs_call(__method__)
|
20
|
+
end
|
21
|
+
|
22
|
+
# returns file_name and new position.
|
23
|
+
def read(pos)
|
24
|
+
return cache[pos], pos + 1
|
25
|
+
end
|
26
|
+
|
27
|
+
private
|
28
|
+
|
29
|
+
def cache
|
30
|
+
@cache ||= fs_call(:each, nil, nil).to_a
|
31
|
+
end
|
32
|
+
|
33
|
+
def fs_call(method, *args)
|
34
|
+
@fs.send("#{NS_PFX}#{method}", @instance_handle, *args)
|
35
|
+
end
|
36
|
+
end
|
37
|
+
end
|
@@ -0,0 +1,157 @@
|
|
1
|
+
module VirtFS::CamcorderFS # rubocop:disable Style/ClassAndModuleChildren
|
2
|
+
#
|
3
|
+
# CamcorderFS::File class.
|
4
|
+
# Instance methods call into CamcorderFS::FS instance.
|
5
|
+
#
|
6
|
+
class File
|
7
|
+
attr_reader :fs
|
8
|
+
|
9
|
+
NS_PFX = "file_i_"
|
10
|
+
|
11
|
+
def initialize(fs, instance_handle, parsed_args)
|
12
|
+
@fs = fs
|
13
|
+
@instance_handle = instance_handle
|
14
|
+
@parsed_args = parsed_args
|
15
|
+
end
|
16
|
+
|
17
|
+
#
|
18
|
+
# File instance methods.
|
19
|
+
#
|
20
|
+
def atime
|
21
|
+
fs_call(__method__)
|
22
|
+
end
|
23
|
+
|
24
|
+
def chmod(permission)
|
25
|
+
fs_call(__method__, permission)
|
26
|
+
end
|
27
|
+
|
28
|
+
def chown(owner, group)
|
29
|
+
fs_call(__method__, owner, group)
|
30
|
+
end
|
31
|
+
|
32
|
+
def ctime
|
33
|
+
fs_call(__method__)
|
34
|
+
end
|
35
|
+
|
36
|
+
def flock(locking_constant)
|
37
|
+
fs_call(__method__, locking_constant)
|
38
|
+
end
|
39
|
+
|
40
|
+
def lstat
|
41
|
+
fs_call(__method__)
|
42
|
+
end
|
43
|
+
|
44
|
+
def mtime
|
45
|
+
fs_call(__method__)
|
46
|
+
end
|
47
|
+
|
48
|
+
def size
|
49
|
+
fs_call(__method__)
|
50
|
+
end
|
51
|
+
|
52
|
+
def truncate(to_size)
|
53
|
+
fs_call(__method__, to_size)
|
54
|
+
end
|
55
|
+
|
56
|
+
#
|
57
|
+
# IO instance methods.
|
58
|
+
#
|
59
|
+
def close
|
60
|
+
fs_call(__method__)
|
61
|
+
end
|
62
|
+
|
63
|
+
def close_on_exec?
|
64
|
+
fs_call(__method__)
|
65
|
+
end
|
66
|
+
|
67
|
+
def close_on_exec=(bool_val)
|
68
|
+
fs_call(__method__, bool_val)
|
69
|
+
end
|
70
|
+
|
71
|
+
def close_read
|
72
|
+
fs_call(__method__)
|
73
|
+
end
|
74
|
+
|
75
|
+
def close_write
|
76
|
+
fs_call(__method__)
|
77
|
+
end
|
78
|
+
|
79
|
+
def fcntl(cmd, arg)
|
80
|
+
fs_call(__method__, cmd, arg)
|
81
|
+
end
|
82
|
+
|
83
|
+
def fdatasync
|
84
|
+
fs_call(__method__)
|
85
|
+
end
|
86
|
+
|
87
|
+
def fileno
|
88
|
+
fs_call(__method__)
|
89
|
+
end
|
90
|
+
|
91
|
+
def flush
|
92
|
+
fs_call(__method__)
|
93
|
+
end
|
94
|
+
|
95
|
+
def fsync
|
96
|
+
fs_call(__method__)
|
97
|
+
end
|
98
|
+
|
99
|
+
def ioctl(cms, arg)
|
100
|
+
fs_call(__method__, cms, arg)
|
101
|
+
end
|
102
|
+
|
103
|
+
def isatty
|
104
|
+
fs_call(__method__)
|
105
|
+
end
|
106
|
+
|
107
|
+
def pid
|
108
|
+
fs_call(__method__)
|
109
|
+
end
|
110
|
+
|
111
|
+
def raw_read(start_byte, num_bytes)
|
112
|
+
fs_call(__method__, start_byte, num_bytes)
|
113
|
+
end
|
114
|
+
|
115
|
+
def raw_write(start_byte, buf)
|
116
|
+
fs_call(__method__, start_byte, buf)
|
117
|
+
end
|
118
|
+
|
119
|
+
def readpartial(limit, result = "")
|
120
|
+
fs_call(__method__, limit, result)
|
121
|
+
end
|
122
|
+
|
123
|
+
def read_nonblock(limit, result = "")
|
124
|
+
fs_call(__method__, limit, result)
|
125
|
+
end
|
126
|
+
|
127
|
+
def stat
|
128
|
+
fs_call(__method__)
|
129
|
+
end
|
130
|
+
|
131
|
+
def sync
|
132
|
+
fs_call(__method__)
|
133
|
+
end
|
134
|
+
|
135
|
+
def sync=(bool_val)
|
136
|
+
fs_call(__method__, bool_val)
|
137
|
+
end
|
138
|
+
|
139
|
+
def to_i
|
140
|
+
fs_call(__method__)
|
141
|
+
end
|
142
|
+
|
143
|
+
def tty?
|
144
|
+
fs_call(__method__)
|
145
|
+
end
|
146
|
+
|
147
|
+
def write_nonblock(buf)
|
148
|
+
fs_call(__method__, buf)
|
149
|
+
end
|
150
|
+
|
151
|
+
private
|
152
|
+
|
153
|
+
def fs_call(method, *args)
|
154
|
+
@fs.send("#{NS_PFX}#{method}", @instance_handle, *args)
|
155
|
+
end
|
156
|
+
end
|
157
|
+
end
|
@@ -0,0 +1,106 @@
|
|
1
|
+
require_relative 'fs/dir_class_methods'
|
2
|
+
require_relative 'fs/dir_instance_methods'
|
3
|
+
require_relative 'fs/file_class_methods'
|
4
|
+
require_relative 'fs/file_instance_methods'
|
5
|
+
|
6
|
+
module VirtFS::CamcorderFS # rubocop:disable Style/ClassAndModuleChildren
|
7
|
+
class FS
|
8
|
+
attr_accessor :mount_point, :name, :root
|
9
|
+
attr_reader :recording_path
|
10
|
+
|
11
|
+
include DirClassMethods
|
12
|
+
include DirInstanceMethods
|
13
|
+
include FileClassMethods
|
14
|
+
include FileInstanceMethods
|
15
|
+
|
16
|
+
def initialize(recording_path = nil, root = VfsRealFile::SEPARATOR)
|
17
|
+
@mount_point = nil
|
18
|
+
@name = self.class.name
|
19
|
+
@root = root
|
20
|
+
|
21
|
+
if recording_path.nil?
|
22
|
+
@cc_delegate = CcDelegate.new
|
23
|
+
else
|
24
|
+
start_recorder(recording_path)
|
25
|
+
end
|
26
|
+
end
|
27
|
+
|
28
|
+
def start_recorder(recording_path)
|
29
|
+
@recording_path = recording_path
|
30
|
+
@recorder = Camcorder::Recorder.new(@recording_path)
|
31
|
+
|
32
|
+
@cc_delegate = Camcorder.proxy_class(CcDelegate, @recorder) do
|
33
|
+
#
|
34
|
+
# Dir class methods.
|
35
|
+
#
|
36
|
+
methods_with_side_effects :dir_chdir, :dir_delete, :dir_mkdir, :dir_new
|
37
|
+
|
38
|
+
#
|
39
|
+
# Dir instance methods.
|
40
|
+
#
|
41
|
+
methods_with_side_effects :dir_i_close, :dir_i_each
|
42
|
+
|
43
|
+
#
|
44
|
+
# File class methods.
|
45
|
+
#
|
46
|
+
methods_with_side_effects :file_atime, :file_chmod, :file_chown, :file_ctime,
|
47
|
+
:file_delete, :file_lchmod, :file_lchown, :file_link,
|
48
|
+
:file_lstat, :file_mtime, :file_new, :file_rename,
|
49
|
+
:file_stat, :file_symlink?, :file_symlink, :file_truncate,
|
50
|
+
:file_utime
|
51
|
+
|
52
|
+
#
|
53
|
+
# File instance methods.
|
54
|
+
#
|
55
|
+
methods_with_side_effects :file_i_atime, :file_i_chmod, :file_i_chown,
|
56
|
+
:file_i_ctime, :file_i_flock, :file_i_lstat,
|
57
|
+
:file_i_mtime, :file_i_truncate, :file_i_close,
|
58
|
+
:file_i_close_on_exec=, :file_i_close_read, :file_i_close_write,
|
59
|
+
:file_i_fcntl, :file_i_ioctl, :file_i_raw_read,
|
60
|
+
:file_i_raw_write, :file_i_readpartial, :file_i_read_nonblock,
|
61
|
+
:file_i_write_nonblock
|
62
|
+
end.new
|
63
|
+
|
64
|
+
@recorder.start
|
65
|
+
end
|
66
|
+
|
67
|
+
def thin_interface?
|
68
|
+
true
|
69
|
+
end
|
70
|
+
|
71
|
+
def umount
|
72
|
+
@recorder.commit unless @recorder.nil?
|
73
|
+
@mount_point = nil
|
74
|
+
end
|
75
|
+
|
76
|
+
def apply_root(path)
|
77
|
+
VfsRealFile.join(@root, path)
|
78
|
+
end
|
79
|
+
private :apply_root
|
80
|
+
|
81
|
+
def ccd_call(method, *args)
|
82
|
+
@cc_delegate.send(method, *args)
|
83
|
+
rescue SystemCallError => scerr
|
84
|
+
#
|
85
|
+
# The errno is lost when the exception is YAML.dump'd but the
|
86
|
+
# sub-class is correct. We get the errno from the sub-class
|
87
|
+
# and instantiate a new exception to raise.
|
88
|
+
#
|
89
|
+
# Passing the whole message from the original exception isn't
|
90
|
+
# the right thing to do. We need to find a way to extract the
|
91
|
+
# target name from the original message.
|
92
|
+
#
|
93
|
+
raise SystemCallError.new(scerr.message, scerr.class::Errno)
|
94
|
+
rescue
|
95
|
+
raise
|
96
|
+
end
|
97
|
+
private :ccd_call
|
98
|
+
|
99
|
+
def return_enum(array, block, rv = nil)
|
100
|
+
return array.each if block.nil? # return Enumerator.
|
101
|
+
array.each(&block)
|
102
|
+
rv
|
103
|
+
end
|
104
|
+
private :return_enum
|
105
|
+
end
|
106
|
+
end
|