manageiq-smartstate 0.6.2 → 0.7.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.codeclimate.yml +34 -35
- data/.rubocop.yml +3 -3
- data/.rubocop_cc.yml +3 -4
- data/.rubocop_local.yml +1 -1
- data/.travis.yml +0 -1
- data/lib/disk/modules/MSCommon.rb +3 -1
- data/lib/disk/modules/VhdxDisk.rb +3 -1
- data/lib/fs/MiqMountManager.rb +2 -29
- data/lib/fs/VimDatastoreFS/VimDatastoreFS.rb +1 -6
- data/lib/fs/fat32/directory_entry.rb +60 -60
- data/lib/fs/iso9660/boot_sector.rb +3 -2
- data/lib/fs/iso9660/directory_entry.rb +3 -2
- data/lib/fs/iso9660/rock_ridge.rb +3 -1
- data/lib/fs/ntfs/attrib_attribute_list.rb +3 -1
- data/lib/fs/ntfs/attrib_file_name.rb +3 -1
- data/lib/fs/ntfs/attrib_header.rb +3 -1
- data/lib/fs/ntfs/attrib_index_root.rb +3 -1
- data/lib/fs/ntfs/attrib_volume_name.rb +3 -1
- data/lib/manageiq/smartstate/util.rb +18 -0
- data/lib/manageiq/smartstate/version.rb +1 -1
- data/lib/metadata/VmConfig/GetNativeCfg.rb +2 -4
- data/lib/metadata/VmConfig/VmConfig.rb +3 -1
- data/lib/metadata/VmConfig/cfgConfig.rb +4 -0
- data/lib/metadata/VmConfig/xmlConfig.rb +3 -3
- data/lib/metadata/linux/MiqRpmPackages.rb +3 -1
- data/lib/metadata/util/win32/Win32Accounts.rb +3 -0
- data/lib/metadata/util/win32/Win32EventLog.rb +3 -1
- data/lib/metadata/util/win32/Win32Software.rb +5 -3
- data/lib/metadata/util/win32/decode.rb +0 -0
- data/lib/metadata/util/win32/fleece_hives.rb +0 -8
- data/lib/metadata/util/win32/ms-registry.rb +3 -1
- data/lib/metadata/util/win32/peheader.rb +3 -2
- data/lib/miq_unicode.rb +45 -0
- data/manageiq-smartstate.gemspec +5 -5
- metadata +39 -24
- data/lib/fs/MetakitFS/MetakitFS.rb +0 -530
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 2eed9833b4418d9405995117c01ae36ec8d9dbd8f59c2a71a3b1695fd1845eca
|
4
|
+
data.tar.gz: 014abce3c3c7a22594ffe9877046b1a390b0941e58e4052b3eb29525c80bd6fb
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 417c6b7efe6f1ebdf11f037beb537f9fd48f1654e5985699a6b6c2d29342ea7fd22b59df97b48ae4ba09e1d6c75624c198add8d988b6387d071084ae48b0aafb
|
7
|
+
data.tar.gz: 35335b08093b49f9fb4e57aeba97b2c89d6c01ead9de3cb854086f84b0a70b59f90a178f1aaa44230dd1feea24c70acefa0546f43e2b65a279b8bcd59b0d1146
|
data/.codeclimate.yml
CHANGED
@@ -1,17 +1,23 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
-
|
9
|
-
|
10
|
-
-
|
11
|
-
|
12
|
-
-
|
13
|
-
|
14
|
-
|
1
|
+
checks:
|
2
|
+
method-complexity:
|
3
|
+
enabled: true
|
4
|
+
config:
|
5
|
+
threshold: 8
|
6
|
+
prepare:
|
7
|
+
fetch:
|
8
|
+
- url: https://raw.githubusercontent.com/ManageIQ/manageiq-style/master/.rubocop_base.yml
|
9
|
+
path: ".rubocop_base.yml"
|
10
|
+
- url: https://raw.githubusercontent.com/ManageIQ/manageiq-style/master/.rubocop_cc_base.yml
|
11
|
+
path: ".rubocop_cc_base.yml"
|
12
|
+
- url: https://raw.githubusercontent.com/ManageIQ/manageiq-style/master/styles/base.yml
|
13
|
+
path: styles/base.yml
|
14
|
+
- url: https://raw.githubusercontent.com/ManageIQ/manageiq-style/master/styles/cc_base.yml
|
15
|
+
path: styles/cc_base.yml
|
16
|
+
plugins:
|
17
|
+
rubocop:
|
18
|
+
enabled: true
|
19
|
+
config: ".rubocop_cc.yml"
|
20
|
+
channel: rubocop-0-82
|
15
21
|
brakeman:
|
16
22
|
enabled: false
|
17
23
|
bundler-audit:
|
@@ -25,7 +31,7 @@ engines:
|
|
25
31
|
ruby:
|
26
32
|
mass_threshold: 25
|
27
33
|
count_threshold: 5
|
28
|
-
javascript:
|
34
|
+
javascript:
|
29
35
|
eslint:
|
30
36
|
enabled: false
|
31
37
|
channel: eslint-3
|
@@ -33,23 +39,16 @@ engines:
|
|
33
39
|
enabled: false
|
34
40
|
markdownlint:
|
35
41
|
enabled: false
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
- url: https://raw.githubusercontent.com/ManageIQ/guides/master/.rubocop_cc_base.yml
|
50
|
-
path: ".rubocop_cc_base.yml"
|
51
|
-
ratings:
|
52
|
-
paths:
|
53
|
-
- Gemfile.lock
|
54
|
-
- "**.rake"
|
55
|
-
- "**.rb"
|
42
|
+
exclude_patterns:
|
43
|
+
- ".git/"
|
44
|
+
- "**.xml"
|
45
|
+
- "**.yaml"
|
46
|
+
- "**.yml"
|
47
|
+
- lib/metadata/linux/test/Packages
|
48
|
+
- lib/metadata/linux/test/tc_LinuxUtils.rb
|
49
|
+
- locale/
|
50
|
+
- spec/
|
51
|
+
- test/
|
52
|
+
- tools/
|
53
|
+
- tmp/
|
54
|
+
version: '2'
|
data/.rubocop.yml
CHANGED
@@ -1,4 +1,4 @@
|
|
1
1
|
inherit_from:
|
2
|
-
-
|
3
|
-
|
4
|
-
- .
|
2
|
+
- ".rubocop_local.yml"
|
3
|
+
inherit_gem:
|
4
|
+
manageiq-style: ".rubocop_base.yml"
|
data/.rubocop_cc.yml
CHANGED
data/.rubocop_local.yml
CHANGED
data/.travis.yml
CHANGED
@@ -1,10 +1,12 @@
|
|
1
1
|
require 'disk/modules/MiqLargeFile'
|
2
|
-
require '
|
2
|
+
require 'miq_unicode'
|
3
3
|
require 'binary_struct'
|
4
4
|
require 'memory_buffer'
|
5
5
|
require 'Scvmm/miq_hyperv_disk'
|
6
6
|
|
7
7
|
module MSCommon
|
8
|
+
using ManageIQ::UnicodeString
|
9
|
+
|
8
10
|
# NOTE: All values are stored in network byte order.
|
9
11
|
|
10
12
|
FOOTER = BinaryStruct.new([
|
@@ -1,6 +1,6 @@
|
|
1
1
|
# encoding: US-ASCII
|
2
2
|
|
3
|
-
require '
|
3
|
+
require 'miq_unicode'
|
4
4
|
require 'binary_struct'
|
5
5
|
require 'disk/MiqDisk'
|
6
6
|
require 'memory_buffer'
|
@@ -8,6 +8,8 @@ require 'disk/modules/MiqLargeFile'
|
|
8
8
|
require 'disk/modules/vhdx_bat_entry'
|
9
9
|
|
10
10
|
module VhdxDisk
|
11
|
+
using ManageIQ::UnicodeString
|
12
|
+
|
11
13
|
# NOTE: All values are stored in network byte order.
|
12
14
|
|
13
15
|
VHDX_FILE_IDENTIFIER = BinaryStruct.new([
|
data/lib/fs/MiqMountManager.rb
CHANGED
@@ -8,6 +8,7 @@ class MiqMountManager < MiqFS
|
|
8
8
|
def self.mountVolumes(volMgr, vmCfg, ost = nil)
|
9
9
|
rootTrees = []
|
10
10
|
noFsVolumes = []
|
11
|
+
|
11
12
|
volMgr.visibleVolumes.each do |dobj|
|
12
13
|
$log.debug("MiqMountManager.mountVolumes >> fileName=#{dobj.dInfo.fileName}, partition=#{dobj.partNum}") if $log
|
13
14
|
fs = MiqFS.getFS(dobj)
|
@@ -20,10 +21,7 @@ class MiqMountManager < MiqFS
|
|
20
21
|
rootTrees << new(rsm, dobj, volMgr, vmCfg, ost)
|
21
22
|
end
|
22
23
|
end
|
23
|
-
|
24
|
-
require 'MetakitFS'
|
25
|
-
rootTrees.each { |rt| rt.findPayload(noFsVolumes) } unless noFsVolumes.empty?
|
26
|
-
end
|
24
|
+
|
27
25
|
rootTrees
|
28
26
|
end # def self.mountVolumes
|
29
27
|
|
@@ -41,31 +39,6 @@ class MiqMountManager < MiqFS
|
|
41
39
|
super(rootModule, rootVolume)
|
42
40
|
end # def initialize
|
43
41
|
|
44
|
-
def findPayload(noFsVolumes)
|
45
|
-
$log.debug "MiqMountManager.findPayload: searching for payloads:" if $log
|
46
|
-
noFsVolumes.each do |v|
|
47
|
-
next unless v.respond_to?(:devFile)
|
48
|
-
if v.devFile
|
49
|
-
$log.debug "\tMiqMountManager.findPayload: devFile = #{v.devFile}" if $log
|
50
|
-
v.mkfile = v.devFile
|
51
|
-
unless MetakitFS.supported?(v)
|
52
|
-
$log.debug "\tMiqMountManager.findPayload: devFile = #{v.devFile} not mkfs, skipping" if $log
|
53
|
-
v.mkfile = nil
|
54
|
-
next
|
55
|
-
end
|
56
|
-
mkFs = MiqFS.new(MetakitFS, v)
|
57
|
-
if mkFs.fsId == "MIQPAYLOAD"
|
58
|
-
$log.debug "\tMiqMountManager.findPayload: payload found devFile = #{v.devFile}" if $log
|
59
|
-
@payloads << mkFs
|
60
|
-
else
|
61
|
-
$log.debug "\tMiqMountManager.findPayload: devFile = #{v.devFile} not payload, fsId = #{mkFs.fsId}" if $log
|
62
|
-
end
|
63
|
-
else
|
64
|
-
$log.debug "\tMiqMountManager.findPayload: devFile not set, fileName = #{v.dInfo.fileName}" if $log
|
65
|
-
end
|
66
|
-
end
|
67
|
-
end
|
68
|
-
|
69
42
|
#
|
70
43
|
# Override standard MiqFS methods to account for mount indirection.
|
71
44
|
# The getFsPath method is defined by the OS-specific mount modules.
|
@@ -105,12 +105,7 @@ module VimDatastoreFS
|
|
105
105
|
#
|
106
106
|
# fpos = 0
|
107
107
|
# fsize = @pSize.get(fileRow)
|
108
|
-
#
|
109
|
-
# @pSize.set fileRow, 0
|
110
|
-
# @pData.set fileRow, Metakit::Bytes.new("", 0)
|
111
|
-
# elsif fappend
|
112
|
-
# fpos = fsize
|
113
|
-
# end
|
108
|
+
# fpos = fsize if fappend
|
114
109
|
#
|
115
110
|
# return(MkFile.new(p, fileRow, fpos, fread, fwrite))
|
116
111
|
# end # def fs_fileOpen
|
@@ -1,9 +1,8 @@
|
|
1
1
|
# encoding: US-ASCII
|
2
2
|
|
3
3
|
require 'stringio'
|
4
|
-
|
5
4
|
require 'binary_struct'
|
6
|
-
require '
|
5
|
+
require 'miq_unicode'
|
7
6
|
|
8
7
|
# ////////////////////////////////////////////////////////////////////////////
|
9
8
|
# // Data definitions.
|
@@ -13,6 +12,7 @@ require 'util/miq-unicode'
|
|
13
12
|
# (which yields uppercase names on XP).
|
14
13
|
|
15
14
|
module Fat32
|
15
|
+
using ManageIQ::UnicodeString
|
16
16
|
|
17
17
|
DIR_ENT_SFN = BinaryStruct.new([
|
18
18
|
'a11', 'name', # If name[0] = 0, unallocated; if name[0] = 0xe5, deleted. DOES NOT INCLUDE DOT.
|
@@ -39,17 +39,17 @@ module Fat32
|
|
39
39
|
'S', 'reserved2', # Reserved.
|
40
40
|
'a4', 'name3' # UNICODE chars 12-13 of name.
|
41
41
|
])
|
42
|
-
|
42
|
+
|
43
43
|
CHARS_PER_LFN = 13
|
44
44
|
LFN_NAME_MAXLEN = 260
|
45
45
|
DIR_ENT_SIZE = 32
|
46
46
|
ATTRIB_OFFSET = 11
|
47
|
-
|
47
|
+
|
48
48
|
# ////////////////////////////////////////////////////////////////////////////
|
49
49
|
# // Class.
|
50
50
|
|
51
51
|
class DirectoryEntry
|
52
|
-
|
52
|
+
|
53
53
|
# From the UTF-8 perspective.
|
54
54
|
# LFN name components: entry hash name, char offset, length.
|
55
55
|
LFN_NAME_COMPONENTS = [
|
@@ -61,19 +61,19 @@ module Fat32
|
|
61
61
|
LFN_NC_HASHNAME = 0
|
62
62
|
LFN_NC_OFFSET = 1
|
63
63
|
LFN_NC_LENGTH = 2
|
64
|
-
|
64
|
+
|
65
65
|
# SFN failure cases.
|
66
66
|
SFN_NAME_LENGTH = 1
|
67
67
|
SFN_EXT_LENGTH = 2
|
68
68
|
SFN_NAME_NULL = 3
|
69
69
|
SFN_NAME_DEVICE = 4
|
70
70
|
SFN_ILLEGAL_CHARS = 5
|
71
|
-
|
71
|
+
|
72
72
|
# LFN failure cases.
|
73
73
|
LFN_NAME_LENGTH = 1
|
74
74
|
LFN_NAME_DEVICE = 2
|
75
75
|
LFN_ILLEGAL_CHARS = 3
|
76
|
-
|
76
|
+
|
77
77
|
# FileAttributes
|
78
78
|
FA_READONLY = 0x01
|
79
79
|
FA_HIDDEN = 0x02
|
@@ -82,7 +82,7 @@ module Fat32
|
|
82
82
|
FA_DIRECTORY = 0x10
|
83
83
|
FA_ARCHIVE = 0x20
|
84
84
|
FA_LFN = 0x0f
|
85
|
-
|
85
|
+
|
86
86
|
# DOS time masks.
|
87
87
|
MSK_DAY = 0x001f # Range: 1 - 31
|
88
88
|
MSK_MONTH = 0x01e0 # Right shift 5, Range: 1 - 12
|
@@ -90,18 +90,18 @@ module Fat32
|
|
90
90
|
MSK_SEC = 0x001f # Range: 0 - 29 WARNING: 2 second granularity on this.
|
91
91
|
MSK_MIN = 0x07e0 # Right shift 5, Range: 0 - 59
|
92
92
|
MSK_HOUR = 0xf800 # Right shift 11, Range: 0 - 23
|
93
|
-
|
93
|
+
|
94
94
|
# AllocationFlags
|
95
95
|
AF_NOT_ALLOCATED = 0x00
|
96
96
|
AF_DELETED = 0xe5
|
97
97
|
AF_LFN_LAST = 0x40
|
98
|
-
|
98
|
+
|
99
99
|
# Members.
|
100
100
|
attr_reader :unused, :name, :dirty
|
101
101
|
attr_accessor :parentCluster, :parentOffset
|
102
102
|
# NOTE: Directory is responsible for setting parent.
|
103
103
|
# These describe the cluster & offset of the START of the directory entry.
|
104
|
-
|
104
|
+
|
105
105
|
# Initialization
|
106
106
|
def initialize(buf = nil)
|
107
107
|
# Create for write.
|
@@ -109,7 +109,7 @@ module Fat32
|
|
109
109
|
self.create
|
110
110
|
return
|
111
111
|
end
|
112
|
-
|
112
|
+
|
113
113
|
# Handle possibly multiple LFN records.
|
114
114
|
data = StringIO.new(buf); @lfn_ents = []
|
115
115
|
checksum = 0; @name = ""
|
@@ -119,12 +119,12 @@ module Fat32
|
|
119
119
|
@unused = ""
|
120
120
|
return
|
121
121
|
end
|
122
|
-
|
122
|
+
|
123
123
|
# If attribute contains 0x0f then LFN entry.
|
124
124
|
isLfn = buf[ATTRIB_OFFSET] == FA_LFN
|
125
125
|
@dir_ent = isLfn ? DIR_ENT_LFN.decode(buf) : DIR_ENT_SFN.decode(buf)
|
126
126
|
break if !isLfn
|
127
|
-
|
127
|
+
|
128
128
|
# Ignore this entry if deleted or not allocated.
|
129
129
|
af = @dir_ent['seq_num']
|
130
130
|
if af == AF_DELETED || af == AF_NOT_ALLOCATED
|
@@ -132,19 +132,19 @@ module Fat32
|
|
132
132
|
@unused = data.read()
|
133
133
|
return
|
134
134
|
end
|
135
|
-
|
135
|
+
|
136
136
|
# Set checksum or make sure it's the same
|
137
137
|
checksum = @dir_ent['checksum'] if checksum == 0
|
138
138
|
raise "Directory entry LFN checksum mismatch." if @dir_ent['checksum'] != checksum
|
139
|
-
|
139
|
+
|
140
140
|
# Track LFN entry, gather names & prepend to name.
|
141
141
|
@lfn_ents << @dir_ent
|
142
142
|
@name = getLongNameFromEntry(@dir_ent) + @name
|
143
143
|
end #LFN loop
|
144
|
-
|
144
|
+
|
145
145
|
# Push the rest of the data back.
|
146
146
|
@unused = data.read()
|
147
|
-
|
147
|
+
|
148
148
|
# If this is the last record of an LFN chain, check the checksum.
|
149
149
|
if checksum != 0
|
150
150
|
csum = calcChecksum
|
@@ -156,7 +156,7 @@ module Fat32
|
|
156
156
|
raise "Checksum error"
|
157
157
|
end
|
158
158
|
end
|
159
|
-
|
159
|
+
|
160
160
|
# Populate name if not LFN.
|
161
161
|
if @name == "" && !@dir_ent['name'].empty?
|
162
162
|
@name = @dir_ent['name'][0, 8].strip
|
@@ -167,21 +167,21 @@ module Fat32
|
|
167
167
|
|
168
168
|
# ////////////////////////////////////////////////////////////////////////////
|
169
169
|
# // Class helpers & accessors.
|
170
|
-
|
170
|
+
|
171
171
|
# Return this entry as a raw string.
|
172
172
|
def raw
|
173
173
|
out = ""
|
174
174
|
@lfn_ents.each {|ent| out += BinaryStruct.encode(ent, DIR_ENT_LFN)} if @lfn_ents
|
175
175
|
out += BinaryStruct.encode(@dir_ent, DIR_ENT_SFN)
|
176
176
|
end
|
177
|
-
|
177
|
+
|
178
178
|
# Number of dir ent structures (both sfn and lfn).
|
179
179
|
def numEnts
|
180
180
|
num = 1
|
181
181
|
num += @lfn_ents.size if @lfn_ents
|
182
182
|
return num
|
183
183
|
end
|
184
|
-
|
184
|
+
|
185
185
|
# Return normalized 8.3 name.
|
186
186
|
def shortName
|
187
187
|
name = @dir_ent['name'][0, 8].strip
|
@@ -189,7 +189,7 @@ module Fat32
|
|
189
189
|
name += "." + ext if ext != ""
|
190
190
|
return name
|
191
191
|
end
|
192
|
-
|
192
|
+
|
193
193
|
# Construct & return long name from lfn entries.
|
194
194
|
def longName
|
195
195
|
return nil if @lfn_ents == nil
|
@@ -197,7 +197,7 @@ module Fat32
|
|
197
197
|
@lfn_ents.reverse.each {|ent| name += getLongNameFromEntry(ent)}
|
198
198
|
return name
|
199
199
|
end
|
200
|
-
|
200
|
+
|
201
201
|
# WRITE: change filename.
|
202
202
|
def name=(filename)
|
203
203
|
@dirty = true
|
@@ -215,17 +215,17 @@ module Fat32
|
|
215
215
|
@name = filename
|
216
216
|
end
|
217
217
|
end
|
218
|
-
|
218
|
+
|
219
219
|
# WRITE: change magic number.
|
220
220
|
def magic=(magic)
|
221
221
|
@dirty = true
|
222
222
|
@dir_ent['reserved1'] = magic
|
223
223
|
end
|
224
|
-
|
224
|
+
|
225
225
|
def magic
|
226
226
|
return @dir_ent['reserved1']
|
227
227
|
end
|
228
|
-
|
228
|
+
|
229
229
|
# WRITE: change attribs.
|
230
230
|
def setAttribute(attrib, set = true)
|
231
231
|
@dirty = true
|
@@ -235,27 +235,27 @@ module Fat32
|
|
235
235
|
@dir_ent['attributes'] &= (~attrib)
|
236
236
|
end
|
237
237
|
end
|
238
|
-
|
238
|
+
|
239
239
|
# WRITE: change length.
|
240
240
|
def length=(len)
|
241
241
|
@dirty = true
|
242
242
|
@dir_ent['file_size'] = len
|
243
243
|
end
|
244
|
-
|
244
|
+
|
245
245
|
# WRITE: change first cluster.
|
246
246
|
def firstCluster=(first_clus)
|
247
247
|
@dirty = true
|
248
248
|
@dir_ent['first_clus_hi'] = (first_clus >> 16)
|
249
249
|
@dir_ent['first_clus_lo'] = (first_clus & 0xffff)
|
250
250
|
end
|
251
|
-
|
251
|
+
|
252
252
|
# WRITE: change access time.
|
253
253
|
def aTime=(tim)
|
254
254
|
@dirty = true
|
255
255
|
time, day = rubyToDosTime(tim)
|
256
256
|
@dir_ent['atime_day'] = day
|
257
257
|
end
|
258
|
-
|
258
|
+
|
259
259
|
# To support root dir times (all zero).
|
260
260
|
def zeroTime
|
261
261
|
@dirty = true
|
@@ -263,13 +263,13 @@ module Fat32
|
|
263
263
|
@dir_ent['ctime_tos'] = 0; @dir_ent['ctime_hms'] = 0; @dir_ent['ctime_day'] = 0
|
264
264
|
@dir_ent['mtime_hms'] = 0; @dir_ent['mtime_day'] = 0
|
265
265
|
end
|
266
|
-
|
266
|
+
|
267
267
|
# WRITE: change modified (written) time.
|
268
268
|
def mTime=(tim)
|
269
269
|
@dirty = true
|
270
270
|
@dir_ent['mtime_hms'], @dir_ent['mtime_day'] = rubyToDosTime(tim)
|
271
271
|
end
|
272
|
-
|
272
|
+
|
273
273
|
# WRITE: write or rewrite directory entry.
|
274
274
|
def writeEntry(bs)
|
275
275
|
return if not @dirty
|
@@ -290,7 +290,7 @@ module Fat32
|
|
290
290
|
bs.putCluster(cluster, buf)
|
291
291
|
@dirty = false
|
292
292
|
end
|
293
|
-
|
293
|
+
|
294
294
|
# WRITE: delete file.
|
295
295
|
def delete(bs)
|
296
296
|
# Deallocate data chain.
|
@@ -301,43 +301,43 @@ module Fat32
|
|
301
301
|
@dirty = true
|
302
302
|
self.writeEntry(bs)
|
303
303
|
end
|
304
|
-
|
304
|
+
|
305
305
|
def close(bs)
|
306
306
|
writeEntry(bs) if @dirty
|
307
307
|
end
|
308
|
-
|
308
|
+
|
309
309
|
def attributes
|
310
310
|
return @dir_ent['attributes']
|
311
311
|
end
|
312
|
-
|
312
|
+
|
313
313
|
def length
|
314
314
|
return @dir_ent['file_size']
|
315
315
|
end
|
316
|
-
|
316
|
+
|
317
317
|
def firstCluster
|
318
318
|
return (@dir_ent['first_clus_hi'] << 16) + @dir_ent['first_clus_lo']
|
319
319
|
end
|
320
|
-
|
320
|
+
|
321
321
|
def isDir?
|
322
322
|
return true if @dir_ent['attributes'] & FA_DIRECTORY == FA_DIRECTORY
|
323
323
|
return false
|
324
324
|
end
|
325
|
-
|
325
|
+
|
326
326
|
def mTime
|
327
327
|
return dosToRubyTime(@dir_ent['mtime_day'], @dir_ent['mtime_hms'])
|
328
328
|
end
|
329
|
-
|
329
|
+
|
330
330
|
def aTime
|
331
331
|
return dosToRubyTime(@dir_ent['atime_day'], 0)
|
332
332
|
end
|
333
|
-
|
333
|
+
|
334
334
|
def cTime
|
335
335
|
return dosToRubyTime(@dir_ent['ctime_day'], @dir_ent['ctime_hms'])
|
336
336
|
end
|
337
|
-
|
337
|
+
|
338
338
|
# ////////////////////////////////////////////////////////////////////////////
|
339
339
|
# // Utility functions.
|
340
|
-
|
340
|
+
|
341
341
|
def getLongNameFromEntry(ent)
|
342
342
|
pre_name = ""; hashNames = %w(name name2 name3)
|
343
343
|
hashNames.each {|name|
|
@@ -351,7 +351,7 @@ module Fat32
|
|
351
351
|
}
|
352
352
|
return pre_name
|
353
353
|
end
|
354
|
-
|
354
|
+
|
355
355
|
def incShortName
|
356
356
|
@dirty = true
|
357
357
|
num = @dir_ent['name'][7].to_i
|
@@ -363,7 +363,7 @@ module Fat32
|
|
363
363
|
@lfn_ents.each {|ent| ent['checksum'] = csum}
|
364
364
|
end
|
365
365
|
end
|
366
|
-
|
366
|
+
|
367
367
|
def create
|
368
368
|
@dirty = true
|
369
369
|
@dir_ent = Hash.new
|
@@ -377,7 +377,7 @@ module Fat32
|
|
377
377
|
# Must fill all members or BinaryStruct.encode fails.
|
378
378
|
self.magic = 0x00; self.length = 0; self.firstCluster = 0 #magic used to be 0x18
|
379
379
|
end
|
380
|
-
|
380
|
+
|
381
381
|
def mkLongName(name)
|
382
382
|
@lfn_ents = mkLfn(name)
|
383
383
|
@dir_ent['name'] = mkSfn(name)
|
@@ -387,7 +387,7 @@ module Fat32
|
|
387
387
|
csum = calcChecksum()
|
388
388
|
@lfn_ents.each {|ent| ent['checksum'] = csum}
|
389
389
|
end
|
390
|
-
|
390
|
+
|
391
391
|
def mkLfn(name)
|
392
392
|
name = mkLegalLfn(name)
|
393
393
|
lfn_ents = []
|
@@ -420,11 +420,11 @@ module Fat32
|
|
420
420
|
lfn_ents[0]['seq_num'] |= AF_LFN_LAST
|
421
421
|
return lfn_ents
|
422
422
|
end
|
423
|
-
|
423
|
+
|
424
424
|
def mkSfn(name)
|
425
425
|
return mkLegalSfn(name)
|
426
426
|
end
|
427
|
-
|
427
|
+
|
428
428
|
def isIllegalSfn(name)
|
429
429
|
# Check: name length, extension length, NULL file name,
|
430
430
|
# device names as file names & illegal chars.
|
@@ -437,14 +437,14 @@ module Fat32
|
|
437
437
|
return SFN_ILLEGAL_CHARS if name.index(/[;+=\[\]',\"*\\<>\/?\:|]/) != nil
|
438
438
|
return false
|
439
439
|
end
|
440
|
-
|
440
|
+
|
441
441
|
def checkForDeviceName(fn)
|
442
442
|
%w[aux com1 com2 com3 com4 lpt lpt1 lpt2 lpt3 lpt4 mailslot nul pipe prn].each {|bad|
|
443
443
|
return true if fn == bad
|
444
444
|
}
|
445
445
|
return false
|
446
446
|
end
|
447
|
-
|
447
|
+
|
448
448
|
def mkLegalSfn(name)
|
449
449
|
name = name.upcase; name = name.delete(" ")
|
450
450
|
name = name + "." if not name.include?(".")
|
@@ -454,18 +454,18 @@ module Fat32
|
|
454
454
|
fn = fn[0, 6] + "~1" if fn.length > 8
|
455
455
|
return (fn.ljust(8) + ext.ljust(3)).gsub(/[;+=\[\]',\"*\\<>\/?\:|]/, "_")
|
456
456
|
end
|
457
|
-
|
457
|
+
|
458
458
|
def isIllegalLfn(name)
|
459
459
|
return LFN_NAME_LENGTH if name.length > LFN_NAME_MAXLEN
|
460
460
|
return LFN_ILLEGAL_CHARS if name.index(/\/\\:><?/) != nil
|
461
461
|
return false
|
462
462
|
end
|
463
|
-
|
463
|
+
|
464
464
|
def mkLegalLfn(name)
|
465
465
|
name = name[0...LFN_NAME_MAXLEN] if name.length > LFN_NAME_MAXLEN
|
466
466
|
return name.gsub(/\/\\:><?/, "_")
|
467
467
|
end
|
468
|
-
|
468
|
+
|
469
469
|
def calcChecksum
|
470
470
|
name = @dir_ent['name']; csum = 0
|
471
471
|
0.upto(10) {|i|
|
@@ -473,7 +473,7 @@ module Fat32
|
|
473
473
|
}
|
474
474
|
return csum
|
475
475
|
end
|
476
|
-
|
476
|
+
|
477
477
|
def dosToRubyTime(dos_day, dos_time)
|
478
478
|
# Extract d,m,y,s,m,h & range check.
|
479
479
|
day = dos_day & MSK_DAY; day = 1 if day == 0
|
@@ -487,7 +487,7 @@ module Fat32
|
|
487
487
|
# Make a Ruby time.
|
488
488
|
return Time.mktime(year, month, day, hour, min, sec)
|
489
489
|
end
|
490
|
-
|
490
|
+
|
491
491
|
def rubyToDosTime(tim)
|
492
492
|
# Time
|
493
493
|
sec = tim.sec; sec -= 1 if sec == 60 #correction for possible leap second.
|
@@ -501,7 +501,7 @@ module Fat32
|
|
501
501
|
dos_day = (year << 9) + (month << 5) + day
|
502
502
|
return dos_time, dos_day
|
503
503
|
end
|
504
|
-
|
504
|
+
|
505
505
|
# Dump object.
|
506
506
|
def dump
|
507
507
|
out = "\#<#{self.class}:0x#{'%08x' % self.object_id}>\n"
|
@@ -535,6 +535,6 @@ module Fat32
|
|
535
535
|
out += "First clus lo: 0x#{'%04x' % @dir_ent['first_clus_lo']}\n"
|
536
536
|
out += "File size : 0x#{'%08x' % @dir_ent['file_size']}\n"
|
537
537
|
end
|
538
|
-
|
538
|
+
|
539
539
|
end
|
540
540
|
end # module Fat32
|