Skip to content

Commit d8b96a7

Browse files
committed
Move the UDF File Entry parsing into udf.py.
That's where it belongs. Signed-off-by: Chris Lalancette <clalancette@openrobotics.org>
1 parent d07710b commit d8b96a7

File tree

2 files changed

+46
-39
lines changed

2 files changed

+46
-39
lines changed

pycdlib/pycdlib.py

Lines changed: 14 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -2087,39 +2087,6 @@ def _parse_udf_descriptors(self):
20872087
self.udf_file_set_terminator.orig_extent_loc = current_extent
20882088
self.udf_file_set_terminator.desc_tag.tag_location = current_extent - self.udf_main_descs.partitions[0].part_start_location
20892089

2090-
def _parse_udf_file_entry(self, abs_file_entry_extent, icb, parent):
2091-
# type: (int, udfmod.UDFLongAD, Optional[udfmod.UDFFileEntry]) -> Optional[udfmod.UDFFileEntry]
2092-
"""
2093-
An internal method to parse a single UDF File Entry and return the
2094-
corresponding object.
2095-
2096-
Parameters:
2097-
abs_file_entry_extent - The extent number the file entry starts at.
2098-
icb - The ICB object for the data.
2099-
parent - The parent of the UDF File Entry.
2100-
Returns:
2101-
A UDF File Entry object corresponding to the on-disk File Entry.
2102-
"""
2103-
self._seek_to_extent(abs_file_entry_extent)
2104-
icbdata = self._cdfp.read(icb.extent_length)
2105-
2106-
if all(v == 0 for v in bytearray(icbdata)):
2107-
# We have seen ISOs in the wild (Windows 2008 Datacenter Enterprise
2108-
# Standard SP2 x86 DVD) where the UDF File Identifier points to a
2109-
# UDF File Entry of all zeros. In those cases, we just keep the
2110-
# File Identifier, and keep the UDF File Entry blank.
2111-
return None
2112-
2113-
desc_tag = udfmod.UDFTag()
2114-
desc_tag.parse(icbdata, icb.log_block_num)
2115-
if desc_tag.tag_ident != 261:
2116-
raise pycdlibexception.PyCdlibInvalidISO('UDF File Entry Tag identifier not 261')
2117-
2118-
file_entry = udfmod.UDFFileEntry()
2119-
file_entry.parse(icbdata, abs_file_entry_extent, parent, desc_tag)
2120-
2121-
return file_entry
2122-
21232090
def _walk_udf_directories(self, extent_to_inode):
21242091
# type: (Dict[int, inode.Inode]) -> None
21252092
"""
@@ -2132,9 +2099,14 @@ def _walk_udf_directories(self, extent_to_inode):
21322099
Nothing.
21332100
"""
21342101
part_start = self.udf_main_descs.partitions[0].part_start_location
2135-
self.udf_root = self._parse_udf_file_entry(part_start + self.udf_file_set.root_dir_icb.log_block_num,
2136-
self.udf_file_set.root_dir_icb,
2137-
None)
2102+
2103+
abs_file_entry_extent = part_start + self.udf_file_set.root_dir_icb.log_block_num
2104+
self._seek_to_extent(abs_file_entry_extent)
2105+
icbdata = self._cdfp.read(self.udf_file_set.root_dir_icb.extent_length)
2106+
self.udf_root = udfmod.parse_file_entry(icbdata,
2107+
abs_file_entry_extent,
2108+
self.udf_file_set.root_dir_icb.log_block_num,
2109+
None)
21382110

21392111
udf_file_entries = collections.deque([self.udf_root])
21402112
while udf_file_entries:
@@ -2167,9 +2139,12 @@ def _walk_udf_directories(self, extent_to_inode):
21672139
continue
21682140

21692141
abs_file_entry_extent = part_start + file_ident.icb.log_block_num
2170-
next_entry = self._parse_udf_file_entry(abs_file_entry_extent,
2171-
file_ident.icb,
2172-
udf_file_entry)
2142+
self._seek_to_extent(abs_file_entry_extent)
2143+
icbdata = self._cdfp.read(file_ident.icb.extent_length)
2144+
next_entry = udfmod.parse_file_entry(icbdata,
2145+
abs_file_entry_extent,
2146+
file_ident.icb.log_block_num,
2147+
udf_file_entry)
21732148

21742149
# For a non-parent, we delay adding this to the list of
21752150
# fi_descs until after we check whether this is a valid

pycdlib/udf.py

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5820,3 +5820,35 @@ def parse_logical_volume_integrity(integrity_data, current_extent, logical_block
58205820
logical_volume_integrity_terminator.parse(current_extent + 1, desc_tag)
58215821

58225822
return logical_volume_integrity, logical_volume_integrity_terminator
5823+
5824+
5825+
def parse_file_entry(icbdata, abs_file_entry_extent, icb_log_block_num, parent):
5826+
# type: (bytes, int, int, Optional[UDFFileEntry]) -> Optional[UDFFileEntry]
5827+
"""
5828+
An internal method to parse a single UDF File Entry and return the
5829+
corresponding object.
5830+
5831+
Parameters:
5832+
icbdata - The data to parse.
5833+
abs_file_entry_extent - The extent number the file entry starts at.
5834+
icb_log_block_num - The ICB logical block number.
5835+
parent - The parent of the UDF File Entry.
5836+
Returns:
5837+
A UDF File Entry object corresponding to the on-disk File Entry.
5838+
"""
5839+
if all(v == 0 for v in bytearray(icbdata)):
5840+
# We have seen ISOs in the wild (Windows 2008 Datacenter Enterprise
5841+
# Standard SP2 x86 DVD) where the UDF File Identifier points to a
5842+
# UDF File Entry of all zeros. In those cases, we just keep the
5843+
# File Identifier, and keep the UDF File Entry blank.
5844+
return None
5845+
5846+
desc_tag = UDFTag()
5847+
desc_tag.parse(icbdata, icb_log_block_num)
5848+
if desc_tag.tag_ident != 261:
5849+
raise pycdlibexception.PyCdlibInvalidISO('UDF File Entry Tag identifier not 261')
5850+
5851+
file_entry = UDFFileEntry()
5852+
file_entry.parse(icbdata, abs_file_entry_extent, parent, desc_tag)
5853+
5854+
return file_entry

0 commit comments

Comments
 (0)