virt_disk 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/.rspec +2 -0
- data/.travis.yml +5 -0
- data/Gemfile +4 -0
- data/LICENSE.txt +21 -0
- data/README.md +1 -0
- data/Rakefile +6 -0
- data/lib/virt_disk.rb +9 -0
- data/lib/virt_disk/block_file.rb +32 -0
- data/lib/virt_disk/client_head.rb +56 -0
- data/lib/virt_disk/disk.rb +21 -0
- data/lib/virt_disk/disk_unicode.rb +43 -0
- data/lib/virt_disk/disk_uuid.rb +22 -0
- data/lib/virt_disk/export_methods.rb +74 -0
- data/lib/virt_disk/file_io.rb +42 -0
- data/lib/virt_disk/partition.rb +39 -0
- data/lib/virt_disk/partition_type.rb +16 -0
- data/lib/virt_disk/partition_type/dos_partition.rb +113 -0
- data/lib/virt_disk/partition_type/gpt_partition.rb +71 -0
- data/lib/virt_disk/version.rb +3 -0
- data/spec/data/dos_partition.img +0 -0
- data/spec/data/gpt_partition.img +0 -0
- data/spec/data/no_partition.img +0 -0
- data/spec/dos_partition_spec.rb +49 -0
- data/spec/export_methods_spec.rb +257 -0
- data/spec/gpt_partition_spec.rb +58 -0
- data/spec/partition_shared_examples.rb +55 -0
- data/spec/partition_type_spec.rb +74 -0
- data/spec/spec_helper.rb +20 -0
- data/tasks/rspec.rake +3 -0
- data/tasks/yard.rake +7 -0
- data/virt_disk.gemspec +31 -0
- metadata +182 -0
@@ -0,0 +1,55 @@
|
|
1
|
+
shared_examples_for "common_partition" do
|
2
|
+
it "should be of expected data type" do
|
3
|
+
expect(@partition).to be_kind_of(expected_partition_class)
|
4
|
+
end
|
5
|
+
|
6
|
+
it "should have the expected 'ptype' value" do
|
7
|
+
pvalues = per_partition_values[@partition.pnum - 1]
|
8
|
+
expect(@partition.ptype).to eq(pvalues[:ptype])
|
9
|
+
end
|
10
|
+
|
11
|
+
it "should have the expected 'block_size' value" do
|
12
|
+
pvalues = per_partition_values[@partition.pnum - 1]
|
13
|
+
expect(@partition.block_size).to eq(pvalues[:block_size])
|
14
|
+
end
|
15
|
+
|
16
|
+
it "should have the expected 'start_lba' value" do
|
17
|
+
pvalues = per_partition_values[@partition.pnum - 1]
|
18
|
+
expect(@partition.start_lba).to eq(pvalues[:start_lba])
|
19
|
+
end
|
20
|
+
|
21
|
+
it "should have the expected 'end_lba' value" do
|
22
|
+
pvalues = per_partition_values[@partition.pnum - 1]
|
23
|
+
expect(@partition.end_lba).to eq(pvalues[:end_lba])
|
24
|
+
end
|
25
|
+
|
26
|
+
it "should have the expected 'start_byte_addr' value" do
|
27
|
+
pvalues = per_partition_values[@partition.pnum - 1]
|
28
|
+
expect(@partition.start_byte_addr).to eq(pvalues[:start_byte_addr])
|
29
|
+
end
|
30
|
+
|
31
|
+
it "should have the expected 'end_byte_addr' value" do
|
32
|
+
pvalues = per_partition_values[@partition.pnum - 1]
|
33
|
+
expect(@partition.end_byte_addr).to eq(pvalues[:end_byte_addr])
|
34
|
+
end
|
35
|
+
|
36
|
+
it "should have the expected 'size' value" do
|
37
|
+
pvalues = per_partition_values[@partition.pnum - 1]
|
38
|
+
expect(@partition.size).to eq(pvalues[:size])
|
39
|
+
end
|
40
|
+
|
41
|
+
it "'start_byte_addr' should be consistent with 'start_lba' and 'block_size'" do
|
42
|
+
pvalues = per_partition_values[@partition.pnum - 1]
|
43
|
+
expect(@partition.start_byte_addr).to eq(@partition.start_lba * @partition.block_size)
|
44
|
+
end
|
45
|
+
|
46
|
+
it "'end_byte_addr' should be consistent with 'end_lba' and 'block_size'" do
|
47
|
+
pvalues = per_partition_values[@partition.pnum - 1]
|
48
|
+
expect(@partition.end_byte_addr).to eq(@partition.end_lba * @partition.block_size)
|
49
|
+
end
|
50
|
+
|
51
|
+
it "'size' should be consistent with 'start_byte_addr' and 'end_byte_addr'" do
|
52
|
+
pvalues = per_partition_values[@partition.pnum - 1]
|
53
|
+
expect(@partition.size).to eq(@partition.end_byte_addr - @partition.start_byte_addr)
|
54
|
+
end
|
55
|
+
end
|
@@ -0,0 +1,74 @@
|
|
1
|
+
require "spec_helper"
|
2
|
+
|
3
|
+
describe VirtDisk::PartitionType do
|
4
|
+
let(:data_dir) do
|
5
|
+
File.join(__dir__, "data")
|
6
|
+
end
|
7
|
+
|
8
|
+
let(:dos_partition_file) do
|
9
|
+
File.join(data_dir, "dos_partition.img")
|
10
|
+
end
|
11
|
+
|
12
|
+
let(:no_partition_file) do
|
13
|
+
File.join(data_dir, "no_partition.img")
|
14
|
+
end
|
15
|
+
|
16
|
+
describe "partition_types" do
|
17
|
+
it "should return an array" do
|
18
|
+
expect(VirtDisk::PartitionType.partition_types).to be_kind_of(Array)
|
19
|
+
end
|
20
|
+
|
21
|
+
it "should return an array of the expected length" do
|
22
|
+
expect(VirtDisk::PartitionType.partition_types.length).to eq(2)
|
23
|
+
end
|
24
|
+
|
25
|
+
it "should return an array with the expected data" do
|
26
|
+
expect(VirtDisk::PartitionType.partition_types)
|
27
|
+
.to match_array([VirtDisk::PartitionType::DosPartition, VirtDisk::PartitionType::GptPartition])
|
28
|
+
end
|
29
|
+
end
|
30
|
+
|
31
|
+
describe "partition_probe" do
|
32
|
+
describe "unpartitioned disk" do
|
33
|
+
before(:each) do
|
34
|
+
file_mod = VirtDisk::FileIo.new(no_partition_file)
|
35
|
+
@disk = VirtDisk::Disk.new(file_mod)
|
36
|
+
end
|
37
|
+
|
38
|
+
after(:each) do
|
39
|
+
@disk.close
|
40
|
+
end
|
41
|
+
|
42
|
+
it "should return an array" do
|
43
|
+
expect(VirtDisk::PartitionType.partition_probe(@disk)).to be_kind_of(Array)
|
44
|
+
end
|
45
|
+
|
46
|
+
it "should return an empty array" do
|
47
|
+
expect(VirtDisk::PartitionType.partition_probe(@disk).length).to eq(0)
|
48
|
+
end
|
49
|
+
end
|
50
|
+
|
51
|
+
describe "partitioned disk" do
|
52
|
+
before(:each) do
|
53
|
+
file_mod = VirtDisk::FileIo.new(dos_partition_file)
|
54
|
+
@disk = VirtDisk::Disk.new(file_mod)
|
55
|
+
end
|
56
|
+
|
57
|
+
after(:each) do
|
58
|
+
@disk.close
|
59
|
+
end
|
60
|
+
|
61
|
+
it "should return an array" do
|
62
|
+
expect(VirtDisk::PartitionType.partition_probe(@disk)).to be_kind_of(Array)
|
63
|
+
end
|
64
|
+
|
65
|
+
it "should return an array of the expected length" do
|
66
|
+
expect(VirtDisk::PartitionType.partition_probe(@disk).length).to eq(2)
|
67
|
+
end
|
68
|
+
|
69
|
+
it "should return an array with the expected data" do
|
70
|
+
expect(VirtDisk::PartitionType.partition_probe(@disk).first).to be_kind_of(VirtDisk::PartitionType::DosPartition)
|
71
|
+
end
|
72
|
+
end
|
73
|
+
end
|
74
|
+
end
|
data/spec/spec_helper.rb
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
require "log_decorator"
|
2
|
+
|
3
|
+
def log_init
|
4
|
+
require "logger"
|
5
|
+
|
6
|
+
log = Logger.new(STDERR)
|
7
|
+
log.formatter = lambda { |_severity, _datetime, _progname, msg| "#{msg}\n" }
|
8
|
+
log.level = case ENV['LOG_LEVEL']
|
9
|
+
when 'ERROR' then Logger::ERROR
|
10
|
+
when 'WARN' then Logger::WARN
|
11
|
+
when 'INFO' then Logger::INFO
|
12
|
+
when 'DEBUG' then Logger::DEBUG
|
13
|
+
else Logger::ERROR
|
14
|
+
end
|
15
|
+
LogDecorator.logger = log
|
16
|
+
end
|
17
|
+
|
18
|
+
log_init
|
19
|
+
|
20
|
+
require "virt_disk"
|
data/tasks/rspec.rake
ADDED
data/tasks/yard.rake
ADDED
data/virt_disk.gemspec
ADDED
@@ -0,0 +1,31 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'virt_disk/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = "virt_disk"
|
8
|
+
spec.version = VirtDisk::VERSION
|
9
|
+
spec.authors = ["Mo Morsi"]
|
10
|
+
spec.email = ["mmorsi@redhat.com"]
|
11
|
+
|
12
|
+
spec.summary = "Virtual Block Device Implementation"
|
13
|
+
spec.description = %q{
|
14
|
+
}
|
15
|
+
spec.homepage = ""
|
16
|
+
spec.license = "MIT"
|
17
|
+
|
18
|
+
spec.files = `git ls-files`.split($/)
|
19
|
+
spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
|
20
|
+
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
|
21
|
+
spec.require_paths = ["lib"]
|
22
|
+
|
23
|
+
spec.add_dependency "binary_struct"
|
24
|
+
spec.add_dependency "uuidtools"
|
25
|
+
spec.add_dependency "log_decorator"
|
26
|
+
|
27
|
+
spec.add_development_dependency "bundler", "~> 1.3"
|
28
|
+
spec.add_development_dependency "rake"
|
29
|
+
spec.add_development_dependency "rspec"
|
30
|
+
spec.add_development_dependency "yard"
|
31
|
+
end
|
metadata
ADDED
@@ -0,0 +1,182 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: virt_disk
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Mo Morsi
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2017-09-12 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: binary_struct
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - ">="
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '0'
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - ">="
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '0'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: uuidtools
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - ">="
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '0'
|
34
|
+
type: :runtime
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - ">="
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '0'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: log_decorator
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - ">="
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '0'
|
48
|
+
type: :runtime
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - ">="
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '0'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: bundler
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - "~>"
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '1.3'
|
62
|
+
type: :development
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - "~>"
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '1.3'
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
name: rake
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - ">="
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: '0'
|
76
|
+
type: :development
|
77
|
+
prerelease: false
|
78
|
+
version_requirements: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - ">="
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: '0'
|
83
|
+
- !ruby/object:Gem::Dependency
|
84
|
+
name: rspec
|
85
|
+
requirement: !ruby/object:Gem::Requirement
|
86
|
+
requirements:
|
87
|
+
- - ">="
|
88
|
+
- !ruby/object:Gem::Version
|
89
|
+
version: '0'
|
90
|
+
type: :development
|
91
|
+
prerelease: false
|
92
|
+
version_requirements: !ruby/object:Gem::Requirement
|
93
|
+
requirements:
|
94
|
+
- - ">="
|
95
|
+
- !ruby/object:Gem::Version
|
96
|
+
version: '0'
|
97
|
+
- !ruby/object:Gem::Dependency
|
98
|
+
name: yard
|
99
|
+
requirement: !ruby/object:Gem::Requirement
|
100
|
+
requirements:
|
101
|
+
- - ">="
|
102
|
+
- !ruby/object:Gem::Version
|
103
|
+
version: '0'
|
104
|
+
type: :development
|
105
|
+
prerelease: false
|
106
|
+
version_requirements: !ruby/object:Gem::Requirement
|
107
|
+
requirements:
|
108
|
+
- - ">="
|
109
|
+
- !ruby/object:Gem::Version
|
110
|
+
version: '0'
|
111
|
+
description: "\n "
|
112
|
+
email:
|
113
|
+
- mmorsi@redhat.com
|
114
|
+
executables: []
|
115
|
+
extensions: []
|
116
|
+
extra_rdoc_files: []
|
117
|
+
files:
|
118
|
+
- ".rspec"
|
119
|
+
- ".travis.yml"
|
120
|
+
- Gemfile
|
121
|
+
- LICENSE.txt
|
122
|
+
- README.md
|
123
|
+
- Rakefile
|
124
|
+
- lib/virt_disk.rb
|
125
|
+
- lib/virt_disk/block_file.rb
|
126
|
+
- lib/virt_disk/client_head.rb
|
127
|
+
- lib/virt_disk/disk.rb
|
128
|
+
- lib/virt_disk/disk_unicode.rb
|
129
|
+
- lib/virt_disk/disk_uuid.rb
|
130
|
+
- lib/virt_disk/export_methods.rb
|
131
|
+
- lib/virt_disk/file_io.rb
|
132
|
+
- lib/virt_disk/partition.rb
|
133
|
+
- lib/virt_disk/partition_type.rb
|
134
|
+
- lib/virt_disk/partition_type/dos_partition.rb
|
135
|
+
- lib/virt_disk/partition_type/gpt_partition.rb
|
136
|
+
- lib/virt_disk/version.rb
|
137
|
+
- spec/data/dos_partition.img
|
138
|
+
- spec/data/gpt_partition.img
|
139
|
+
- spec/data/no_partition.img
|
140
|
+
- spec/dos_partition_spec.rb
|
141
|
+
- spec/export_methods_spec.rb
|
142
|
+
- spec/gpt_partition_spec.rb
|
143
|
+
- spec/partition_shared_examples.rb
|
144
|
+
- spec/partition_type_spec.rb
|
145
|
+
- spec/spec_helper.rb
|
146
|
+
- tasks/rspec.rake
|
147
|
+
- tasks/yard.rake
|
148
|
+
- virt_disk.gemspec
|
149
|
+
homepage: ''
|
150
|
+
licenses:
|
151
|
+
- MIT
|
152
|
+
metadata: {}
|
153
|
+
post_install_message:
|
154
|
+
rdoc_options: []
|
155
|
+
require_paths:
|
156
|
+
- lib
|
157
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
158
|
+
requirements:
|
159
|
+
- - ">="
|
160
|
+
- !ruby/object:Gem::Version
|
161
|
+
version: '0'
|
162
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
163
|
+
requirements:
|
164
|
+
- - ">="
|
165
|
+
- !ruby/object:Gem::Version
|
166
|
+
version: '0'
|
167
|
+
requirements: []
|
168
|
+
rubyforge_project:
|
169
|
+
rubygems_version: 2.6.12
|
170
|
+
signing_key:
|
171
|
+
specification_version: 4
|
172
|
+
summary: Virtual Block Device Implementation
|
173
|
+
test_files:
|
174
|
+
- spec/data/dos_partition.img
|
175
|
+
- spec/data/gpt_partition.img
|
176
|
+
- spec/data/no_partition.img
|
177
|
+
- spec/dos_partition_spec.rb
|
178
|
+
- spec/export_methods_spec.rb
|
179
|
+
- spec/gpt_partition_spec.rb
|
180
|
+
- spec/partition_shared_examples.rb
|
181
|
+
- spec/partition_type_spec.rb
|
182
|
+
- spec/spec_helper.rb
|