Skip to content

Commit ac26620

Browse files
committed
Move file set parsing into the udf module.
This just moves more of the parsing where it should be. Signed-off-by: Chris Lalancette <clalancette@openrobotics.org>
1 parent 312f19a commit ac26620

File tree

2 files changed

+45
-24
lines changed

2 files changed

+45
-24
lines changed

pycdlib/pycdlib.py

Lines changed: 3 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,6 @@
2222
import collections
2323
import inspect
2424
import io
25-
import logging
2625
import os
2726
import struct
2827
import sys
@@ -69,7 +68,6 @@
6968
# We allow A-Z, 0-9, and _ as "d1" characters. The below is the fastest way to
7069
# build that list as integers.
7170
_allowed_d1_characters = set(tuple(range(65, 91)) + tuple(range(48, 58)) + tuple((ord(b'_'),)))
72-
_logger = logging.getLogger(__name__)
7371

7472

7573
def _check_d1_characters(name):
@@ -2064,28 +2062,9 @@ def _parse_udf_descriptors(self):
20642062
# Read the data for the File Set and File Terminator together
20652063
file_set_and_term_data = self._cdfp.read(2 * self.logical_block_size)
20662064

2067-
desc_tag = udfmod.UDFTag()
2068-
desc_tag.parse(file_set_and_term_data[:self.logical_block_size], 0)
2069-
if desc_tag.tag_ident != 256:
2070-
raise pycdlibexception.PyCdlibInvalidISO('UDF File Set Tag identifier not 256')
2071-
self.udf_file_set.parse(file_set_and_term_data[:self.logical_block_size],
2072-
current_extent, desc_tag)
2073-
2074-
current_extent += 1
2075-
(tag_ident,) = struct.unpack_from('<H', file_set_and_term_data, self.logical_block_size)
2076-
self.udf_file_set_terminator = udfmod.UDFTerminatingDescriptor()
2077-
if tag_ident == 8:
2078-
desc_tag = udfmod.UDFTag()
2079-
desc_tag.parse(file_set_and_term_data[self.logical_block_size:],
2080-
current_extent - self.udf_main_descs.partitions[0].part_start_location)
2081-
self.udf_file_set_terminator.parse(current_extent, desc_tag)
2082-
else:
2083-
# In this case, the UDF ISO had an invalid File Set Terminator Tag.
2084-
# But this isn't fatal, so log a warning and continue on.
2085-
_logger.warning('Missing UDF File Set Terminator, continuing')
2086-
self.udf_file_set_terminator.new()
2087-
self.udf_file_set_terminator.orig_extent_loc = current_extent
2088-
self.udf_file_set_terminator.desc_tag.tag_location = current_extent - self.udf_main_descs.partitions[0].part_start_location
2065+
self.udf_file_set, self.udf_file_set_terminator = udfmod.parse_file_set(file_set_and_term_data,
2066+
current_extent,
2067+
self.logical_block_size)
20892068

20902069
def _walk_udf_directories(self, extent_to_inode):
20912070
# type: (Dict[int, inode.Inode]) -> None

pycdlib/udf.py

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818

1919
from __future__ import absolute_import
2020

21+
import logging
2122
import random
2223
import struct
2324
import sys
@@ -92,6 +93,9 @@
9293
have_py_3 = False
9394

9495

96+
_logger = logging.getLogger('pycdlib')
97+
98+
9599
def crc_ccitt(data):
96100
# type: (bytes) -> int
97101
"""
@@ -5822,6 +5826,44 @@ def parse_logical_volume_integrity(integrity_data, current_extent, logical_block
58225826
return logical_volume_integrity, logical_volume_integrity_terminator
58235827

58245828

5829+
def parse_file_set(file_set_and_term_data, current_extent, logical_block_size):
5830+
# type: (bytes, int, int) -> Tuple[UDFFileSetDescriptor, UDFTerminatingDescriptor]
5831+
"""
5832+
An internal method to parse File Set data, and the File Set Terminator.
5833+
5834+
Parameters:
5835+
file_set_and_term_data - The data to parse.
5836+
current_extent - The extent location of the data.
5837+
logical_block_size - The logical block size of the ISO.
5838+
Returns:
5839+
A tuple where the first item is a UDFFileSetDescriptor, and the second item
5840+
is a UDFTerminatorDescriptor.
5841+
"""
5842+
desc_tag = UDFTag()
5843+
desc_tag.parse(file_set_and_term_data[:logical_block_size], 0)
5844+
if desc_tag.tag_ident != 256:
5845+
raise pycdlibexception.PyCdlibInvalidISO('UDF File Set Tag identifier not 256')
5846+
file_set = UDFFileSetDescriptor()
5847+
file_set.parse(file_set_and_term_data[:logical_block_size],
5848+
current_extent, desc_tag)
5849+
5850+
(tag_ident,) = struct.unpack_from('<H', file_set_and_term_data, logical_block_size)
5851+
file_set_terminator = UDFTerminatingDescriptor()
5852+
if tag_ident == 8:
5853+
desc_tag = UDFTag()
5854+
desc_tag.parse(file_set_and_term_data[logical_block_size:], 1)
5855+
file_set_terminator.parse(current_extent + 1, desc_tag)
5856+
else:
5857+
# In this case, the UDF ISO had an invalid File Set Terminator Tag.
5858+
# But this isn't fatal, so log a warning and continue on.
5859+
_logger.warning('Missing UDF File Set Terminator, continuing')
5860+
file_set_terminator.new()
5861+
file_set_terminator.orig_extent_loc = current_extent + 1
5862+
file_set_terminator.desc_tag.tag_location = 1
5863+
5864+
return file_set, file_set_terminator
5865+
5866+
58255867
def parse_file_entry(icbdata, abs_file_entry_extent, icb_log_block_num, parent):
58265868
# type: (bytes, int, int, Optional[UDFFileEntry]) -> Optional[UDFFileEntry]
58275869
"""

0 commit comments

Comments
 (0)