repo
stringlengths
7
55
path
stringlengths
4
127
func_name
stringlengths
1
88
original_string
stringlengths
75
19.8k
language
stringclasses
1 value
code
stringlengths
75
19.8k
code_tokens
list
docstring
stringlengths
3
17.3k
docstring_tokens
list
sha
stringlengths
40
40
url
stringlengths
87
242
partition
stringclasses
1 value
clalancette/pycdlib
pycdlib/utils.py
file_object_supports_binary
def file_object_supports_binary(fp): # type: (BinaryIO) -> bool ''' A function to check whether a file-like object supports binary mode. Parameters: fp - The file-like object to check for binary mode support. Returns: True if the file-like object supports binary mode, False otherwise. ''' if hasattr(fp, 'mode'): return 'b' in fp.mode # Python 3 if sys.version_info >= (3, 0): return isinstance(fp, (io.RawIOBase, io.BufferedIOBase)) # Python 2 return isinstance(fp, (cStringIO.OutputType, cStringIO.InputType, io.RawIOBase, io.BufferedIOBase))
python
def file_object_supports_binary(fp): # type: (BinaryIO) -> bool ''' A function to check whether a file-like object supports binary mode. Parameters: fp - The file-like object to check for binary mode support. Returns: True if the file-like object supports binary mode, False otherwise. ''' if hasattr(fp, 'mode'): return 'b' in fp.mode # Python 3 if sys.version_info >= (3, 0): return isinstance(fp, (io.RawIOBase, io.BufferedIOBase)) # Python 2 return isinstance(fp, (cStringIO.OutputType, cStringIO.InputType, io.RawIOBase, io.BufferedIOBase))
[ "def", "file_object_supports_binary", "(", "fp", ")", ":", "# type: (BinaryIO) -> bool", "if", "hasattr", "(", "fp", ",", "'mode'", ")", ":", "return", "'b'", "in", "fp", ".", "mode", "# Python 3", "if", "sys", ".", "version_info", ">=", "(", "3", ",", "0", ")", ":", "return", "isinstance", "(", "fp", ",", "(", "io", ".", "RawIOBase", ",", "io", ".", "BufferedIOBase", ")", ")", "# Python 2", "return", "isinstance", "(", "fp", ",", "(", "cStringIO", ".", "OutputType", ",", "cStringIO", ".", "InputType", ",", "io", ".", "RawIOBase", ",", "io", ".", "BufferedIOBase", ")", ")" ]
A function to check whether a file-like object supports binary mode. Parameters: fp - The file-like object to check for binary mode support. Returns: True if the file-like object supports binary mode, False otherwise.
[ "A", "function", "to", "check", "whether", "a", "file", "-", "like", "object", "supports", "binary", "mode", "." ]
1e7b77a809e905d67dc71e12d70e850be26b6233
https://github.com/clalancette/pycdlib/blob/1e7b77a809e905d67dc71e12d70e850be26b6233/pycdlib/utils.py#L304-L322
train
clalancette/pycdlib
pycdlib/isohybrid.py
IsoHybrid.parse
def parse(self, instr): # type: (bytes) -> bool ''' A method to parse ISO hybridization info out of an existing ISO. Parameters: instr - The data for the ISO hybridization. Returns: Nothing. ''' if self._initialized: raise pycdlibexception.PyCdlibInternalError('This IsoHybrid object is already initialized') if len(instr) != 512: raise pycdlibexception.PyCdlibInvalidISO('Invalid size of the instr') if instr[0:32] == self.ORIG_HEADER: self.header = self.ORIG_HEADER elif instr[0:32] == self.MAC_AFP: self.header = self.MAC_AFP else: # If we didn't see anything that we expected, then this is not an # IsoHybrid ISO, so just quietly return False return False (self.mbr, self.rba, unused1, self.mbr_id, unused2) = struct.unpack_from(self.FMT, instr[:32 + struct.calcsize(self.FMT)], 32) if unused1 != 0: raise pycdlibexception.PyCdlibInvalidISO('Invalid IsoHybrid section') if unused2 != 0: raise pycdlibexception.PyCdlibInvalidISO('Invalid IsoHybrid section') offset = 32 + struct.calcsize(self.FMT) for i in range(1, 5): if bytes(bytearray([instr[offset]])) == b'\x80': self.part_entry = i (const_unused, self.bhead, self.bsect, self.bcyle, self.ptype, self.ehead, self.esect, self.ecyle, self.part_offset, self.psize) = struct.unpack_from('=BBBBBBBBLL', instr[:offset + 16], offset) break offset += 16 else: raise pycdlibexception.PyCdlibInvalidISO('No valid partition found in IsoHybrid!') if bytes(bytearray([instr[-2]])) != b'\x55' or bytes(bytearray([instr[-1]])) != b'\xaa': raise pycdlibexception.PyCdlibInvalidISO('Invalid tail on isohybrid section') self.geometry_heads = self.ehead + 1 # FIXME: I can't see any way to compute the number of sectors from the # available information. For now, we just hard-code this at 32 and # hope for the best. self.geometry_sectors = 32 self._initialized = True return True
python
def parse(self, instr): # type: (bytes) -> bool ''' A method to parse ISO hybridization info out of an existing ISO. Parameters: instr - The data for the ISO hybridization. Returns: Nothing. ''' if self._initialized: raise pycdlibexception.PyCdlibInternalError('This IsoHybrid object is already initialized') if len(instr) != 512: raise pycdlibexception.PyCdlibInvalidISO('Invalid size of the instr') if instr[0:32] == self.ORIG_HEADER: self.header = self.ORIG_HEADER elif instr[0:32] == self.MAC_AFP: self.header = self.MAC_AFP else: # If we didn't see anything that we expected, then this is not an # IsoHybrid ISO, so just quietly return False return False (self.mbr, self.rba, unused1, self.mbr_id, unused2) = struct.unpack_from(self.FMT, instr[:32 + struct.calcsize(self.FMT)], 32) if unused1 != 0: raise pycdlibexception.PyCdlibInvalidISO('Invalid IsoHybrid section') if unused2 != 0: raise pycdlibexception.PyCdlibInvalidISO('Invalid IsoHybrid section') offset = 32 + struct.calcsize(self.FMT) for i in range(1, 5): if bytes(bytearray([instr[offset]])) == b'\x80': self.part_entry = i (const_unused, self.bhead, self.bsect, self.bcyle, self.ptype, self.ehead, self.esect, self.ecyle, self.part_offset, self.psize) = struct.unpack_from('=BBBBBBBBLL', instr[:offset + 16], offset) break offset += 16 else: raise pycdlibexception.PyCdlibInvalidISO('No valid partition found in IsoHybrid!') if bytes(bytearray([instr[-2]])) != b'\x55' or bytes(bytearray([instr[-1]])) != b'\xaa': raise pycdlibexception.PyCdlibInvalidISO('Invalid tail on isohybrid section') self.geometry_heads = self.ehead + 1 # FIXME: I can't see any way to compute the number of sectors from the # available information. For now, we just hard-code this at 32 and # hope for the best. self.geometry_sectors = 32 self._initialized = True return True
[ "def", "parse", "(", "self", ",", "instr", ")", ":", "# type: (bytes) -> bool", "if", "self", ".", "_initialized", ":", "raise", "pycdlibexception", ".", "PyCdlibInternalError", "(", "'This IsoHybrid object is already initialized'", ")", "if", "len", "(", "instr", ")", "!=", "512", ":", "raise", "pycdlibexception", ".", "PyCdlibInvalidISO", "(", "'Invalid size of the instr'", ")", "if", "instr", "[", "0", ":", "32", "]", "==", "self", ".", "ORIG_HEADER", ":", "self", ".", "header", "=", "self", ".", "ORIG_HEADER", "elif", "instr", "[", "0", ":", "32", "]", "==", "self", ".", "MAC_AFP", ":", "self", ".", "header", "=", "self", ".", "MAC_AFP", "else", ":", "# If we didn't see anything that we expected, then this is not an", "# IsoHybrid ISO, so just quietly return False", "return", "False", "(", "self", ".", "mbr", ",", "self", ".", "rba", ",", "unused1", ",", "self", ".", "mbr_id", ",", "unused2", ")", "=", "struct", ".", "unpack_from", "(", "self", ".", "FMT", ",", "instr", "[", ":", "32", "+", "struct", ".", "calcsize", "(", "self", ".", "FMT", ")", "]", ",", "32", ")", "if", "unused1", "!=", "0", ":", "raise", "pycdlibexception", ".", "PyCdlibInvalidISO", "(", "'Invalid IsoHybrid section'", ")", "if", "unused2", "!=", "0", ":", "raise", "pycdlibexception", ".", "PyCdlibInvalidISO", "(", "'Invalid IsoHybrid section'", ")", "offset", "=", "32", "+", "struct", ".", "calcsize", "(", "self", ".", "FMT", ")", "for", "i", "in", "range", "(", "1", ",", "5", ")", ":", "if", "bytes", "(", "bytearray", "(", "[", "instr", "[", "offset", "]", "]", ")", ")", "==", "b'\\x80'", ":", "self", ".", "part_entry", "=", "i", "(", "const_unused", ",", "self", ".", "bhead", ",", "self", ".", "bsect", ",", "self", ".", "bcyle", ",", "self", ".", "ptype", ",", "self", ".", "ehead", ",", "self", ".", "esect", ",", "self", ".", "ecyle", ",", "self", ".", "part_offset", ",", "self", ".", "psize", ")", "=", "struct", ".", "unpack_from", "(", "'=BBBBBBBBLL'", ",", "instr", "[", ":", "offset", "+", "16", "]", ",", "offset", ")", "break", "offset", "+=", "16", "else", ":", "raise", "pycdlibexception", ".", "PyCdlibInvalidISO", "(", "'No valid partition found in IsoHybrid!'", ")", "if", "bytes", "(", "bytearray", "(", "[", "instr", "[", "-", "2", "]", "]", ")", ")", "!=", "b'\\x55'", "or", "bytes", "(", "bytearray", "(", "[", "instr", "[", "-", "1", "]", "]", ")", ")", "!=", "b'\\xaa'", ":", "raise", "pycdlibexception", ".", "PyCdlibInvalidISO", "(", "'Invalid tail on isohybrid section'", ")", "self", ".", "geometry_heads", "=", "self", ".", "ehead", "+", "1", "# FIXME: I can't see any way to compute the number of sectors from the", "# available information. For now, we just hard-code this at 32 and", "# hope for the best.", "self", ".", "geometry_sectors", "=", "32", "self", ".", "_initialized", "=", "True", "return", "True" ]
A method to parse ISO hybridization info out of an existing ISO. Parameters: instr - The data for the ISO hybridization. Returns: Nothing.
[ "A", "method", "to", "parse", "ISO", "hybridization", "info", "out", "of", "an", "existing", "ISO", "." ]
1e7b77a809e905d67dc71e12d70e850be26b6233
https://github.com/clalancette/pycdlib/blob/1e7b77a809e905d67dc71e12d70e850be26b6233/pycdlib/isohybrid.py#L50-L107
train
clalancette/pycdlib
pycdlib/isohybrid.py
IsoHybrid.new
def new(self, mac, part_entry, mbr_id, part_offset, geometry_sectors, geometry_heads, part_type): # type: (bool, int, Optional[int], int, int, int, int) -> None ''' A method to add ISO hybridization to an ISO. Parameters: mac - Whether this ISO should be made bootable for the Macintosh. part_entry - The partition entry for the hybridization. mbr_id - The mbr_id to use for the hybridization. part_offset - The partition offset to use for the hybridization. geometry_sectors - The number of sectors to use for the hybridization. geometry_heads - The number of heads to use for the hybridization. part_type - The partition type for the hybridization. Returns: Nothing. ''' if self._initialized: raise pycdlibexception.PyCdlibInternalError('This IsoHybrid object is already initialized') if mac: self.header = self.MAC_AFP else: self.header = self.ORIG_HEADER isohybrid_data_hd0 = b'\x33\xed\xfa\x8e\xd5\xbc\x00\x7c\xfb\xfc\x66\x31\xdb\x66\x31\xc9\x66\x53\x66\x51\x06\x57\x8e\xdd\x8e\xc5\x52\xbe\x00\x7c\xbf\x00\x06\xb9\x00\x01\xf3\xa5\xea\x4b\x06\x00\x00\x52\xb4\x41\xbb\xaa\x55\x31\xc9\x30\xf6\xf9\xcd\x13\x72\x16\x81\xfb\x55\xaa\x75\x10\x83\xe1\x01\x74\x0b\x66\xc7\x06\xf1\x06\xb4\x42\xeb\x15\xeb\x00\x5a\x51\xb4\x08\xcd\x13\x83\xe1\x3f\x5b\x51\x0f\xb6\xc6\x40\x50\xf7\xe1\x53\x52\x50\xbb\x00\x7c\xb9\x04\x00\x66\xa1\xb0\x07\xe8\x44\x00\x0f\x82\x80\x00\x66\x40\x80\xc7\x02\xe2\xf2\x66\x81\x3e\x40\x7c\xfb\xc0\x78\x70\x75\x09\xfa\xbc\xec\x7b\xea\x44\x7c\x00\x00\xe8\x83\x00\x69\x73\x6f\x6c\x69\x6e\x75\x78\x2e\x62\x69\x6e\x20\x6d\x69\x73\x73\x69\x6e\x67\x20\x6f\x72\x20\x63\x6f\x72\x72\x75\x70\x74\x2e\x0d\x0a\x66\x60\x66\x31\xd2\x66\x03\x06\xf8\x7b\x66\x13\x16\xfc\x7b\x66\x52\x66\x50\x06\x53\x6a\x01\x6a\x10\x89\xe6\x66\xf7\x36\xe8\x7b\xc0\xe4\x06\x88\xe1\x88\xc5\x92\xf6\x36\xee\x7b\x88\xc6\x08\xe1\x41\xb8\x01\x02\x8a\x16\xf2\x7b\xcd\x13\x8d\x64\x10\x66\x61\xc3\xe8\x1e\x00\x4f\x70\x65\x72\x61\x74\x69\x6e\x67\x20\x73\x79\x73\x74\x65\x6d\x20\x6c\x6f\x61\x64\x20\x65\x72\x72\x6f\x72\x2e\x0d\x0a\x5e\xac\xb4\x0e\x8a\x3e\x62\x04\xb3\x07\xcd\x10\x3c\x0a\x75\xf1\xcd\x18\xf4\xeb\xfd\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00' self.mbr = isohybrid_data_hd0 self.rba = 0 # This will be set later self.mbr_id = mbr_id if self.mbr_id is None: self.mbr_id = random.getrandbits(32) self.part_entry = part_entry self.bhead = (part_offset // geometry_sectors) % geometry_heads self.bsect = (part_offset % geometry_sectors) + 1 self.bcyle = part_offset // (geometry_heads * geometry_sectors) self.bsect += (self.bcyle & 0x300) >> 2 self.bcyle &= 0xff self.ptype = part_type self.ehead = geometry_heads - 1 self.part_offset = part_offset self.geometry_heads = geometry_heads self.geometry_sectors = geometry_sectors self._initialized = True
python
def new(self, mac, part_entry, mbr_id, part_offset, geometry_sectors, geometry_heads, part_type): # type: (bool, int, Optional[int], int, int, int, int) -> None ''' A method to add ISO hybridization to an ISO. Parameters: mac - Whether this ISO should be made bootable for the Macintosh. part_entry - The partition entry for the hybridization. mbr_id - The mbr_id to use for the hybridization. part_offset - The partition offset to use for the hybridization. geometry_sectors - The number of sectors to use for the hybridization. geometry_heads - The number of heads to use for the hybridization. part_type - The partition type for the hybridization. Returns: Nothing. ''' if self._initialized: raise pycdlibexception.PyCdlibInternalError('This IsoHybrid object is already initialized') if mac: self.header = self.MAC_AFP else: self.header = self.ORIG_HEADER isohybrid_data_hd0 = b'\x33\xed\xfa\x8e\xd5\xbc\x00\x7c\xfb\xfc\x66\x31\xdb\x66\x31\xc9\x66\x53\x66\x51\x06\x57\x8e\xdd\x8e\xc5\x52\xbe\x00\x7c\xbf\x00\x06\xb9\x00\x01\xf3\xa5\xea\x4b\x06\x00\x00\x52\xb4\x41\xbb\xaa\x55\x31\xc9\x30\xf6\xf9\xcd\x13\x72\x16\x81\xfb\x55\xaa\x75\x10\x83\xe1\x01\x74\x0b\x66\xc7\x06\xf1\x06\xb4\x42\xeb\x15\xeb\x00\x5a\x51\xb4\x08\xcd\x13\x83\xe1\x3f\x5b\x51\x0f\xb6\xc6\x40\x50\xf7\xe1\x53\x52\x50\xbb\x00\x7c\xb9\x04\x00\x66\xa1\xb0\x07\xe8\x44\x00\x0f\x82\x80\x00\x66\x40\x80\xc7\x02\xe2\xf2\x66\x81\x3e\x40\x7c\xfb\xc0\x78\x70\x75\x09\xfa\xbc\xec\x7b\xea\x44\x7c\x00\x00\xe8\x83\x00\x69\x73\x6f\x6c\x69\x6e\x75\x78\x2e\x62\x69\x6e\x20\x6d\x69\x73\x73\x69\x6e\x67\x20\x6f\x72\x20\x63\x6f\x72\x72\x75\x70\x74\x2e\x0d\x0a\x66\x60\x66\x31\xd2\x66\x03\x06\xf8\x7b\x66\x13\x16\xfc\x7b\x66\x52\x66\x50\x06\x53\x6a\x01\x6a\x10\x89\xe6\x66\xf7\x36\xe8\x7b\xc0\xe4\x06\x88\xe1\x88\xc5\x92\xf6\x36\xee\x7b\x88\xc6\x08\xe1\x41\xb8\x01\x02\x8a\x16\xf2\x7b\xcd\x13\x8d\x64\x10\x66\x61\xc3\xe8\x1e\x00\x4f\x70\x65\x72\x61\x74\x69\x6e\x67\x20\x73\x79\x73\x74\x65\x6d\x20\x6c\x6f\x61\x64\x20\x65\x72\x72\x6f\x72\x2e\x0d\x0a\x5e\xac\xb4\x0e\x8a\x3e\x62\x04\xb3\x07\xcd\x10\x3c\x0a\x75\xf1\xcd\x18\xf4\xeb\xfd\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00' self.mbr = isohybrid_data_hd0 self.rba = 0 # This will be set later self.mbr_id = mbr_id if self.mbr_id is None: self.mbr_id = random.getrandbits(32) self.part_entry = part_entry self.bhead = (part_offset // geometry_sectors) % geometry_heads self.bsect = (part_offset % geometry_sectors) + 1 self.bcyle = part_offset // (geometry_heads * geometry_sectors) self.bsect += (self.bcyle & 0x300) >> 2 self.bcyle &= 0xff self.ptype = part_type self.ehead = geometry_heads - 1 self.part_offset = part_offset self.geometry_heads = geometry_heads self.geometry_sectors = geometry_sectors self._initialized = True
[ "def", "new", "(", "self", ",", "mac", ",", "part_entry", ",", "mbr_id", ",", "part_offset", ",", "geometry_sectors", ",", "geometry_heads", ",", "part_type", ")", ":", "# type: (bool, int, Optional[int], int, int, int, int) -> None", "if", "self", ".", "_initialized", ":", "raise", "pycdlibexception", ".", "PyCdlibInternalError", "(", "'This IsoHybrid object is already initialized'", ")", "if", "mac", ":", "self", ".", "header", "=", "self", ".", "MAC_AFP", "else", ":", "self", ".", "header", "=", "self", ".", "ORIG_HEADER", "isohybrid_data_hd0", "=", "b'\\x33\\xed\\xfa\\x8e\\xd5\\xbc\\x00\\x7c\\xfb\\xfc\\x66\\x31\\xdb\\x66\\x31\\xc9\\x66\\x53\\x66\\x51\\x06\\x57\\x8e\\xdd\\x8e\\xc5\\x52\\xbe\\x00\\x7c\\xbf\\x00\\x06\\xb9\\x00\\x01\\xf3\\xa5\\xea\\x4b\\x06\\x00\\x00\\x52\\xb4\\x41\\xbb\\xaa\\x55\\x31\\xc9\\x30\\xf6\\xf9\\xcd\\x13\\x72\\x16\\x81\\xfb\\x55\\xaa\\x75\\x10\\x83\\xe1\\x01\\x74\\x0b\\x66\\xc7\\x06\\xf1\\x06\\xb4\\x42\\xeb\\x15\\xeb\\x00\\x5a\\x51\\xb4\\x08\\xcd\\x13\\x83\\xe1\\x3f\\x5b\\x51\\x0f\\xb6\\xc6\\x40\\x50\\xf7\\xe1\\x53\\x52\\x50\\xbb\\x00\\x7c\\xb9\\x04\\x00\\x66\\xa1\\xb0\\x07\\xe8\\x44\\x00\\x0f\\x82\\x80\\x00\\x66\\x40\\x80\\xc7\\x02\\xe2\\xf2\\x66\\x81\\x3e\\x40\\x7c\\xfb\\xc0\\x78\\x70\\x75\\x09\\xfa\\xbc\\xec\\x7b\\xea\\x44\\x7c\\x00\\x00\\xe8\\x83\\x00\\x69\\x73\\x6f\\x6c\\x69\\x6e\\x75\\x78\\x2e\\x62\\x69\\x6e\\x20\\x6d\\x69\\x73\\x73\\x69\\x6e\\x67\\x20\\x6f\\x72\\x20\\x63\\x6f\\x72\\x72\\x75\\x70\\x74\\x2e\\x0d\\x0a\\x66\\x60\\x66\\x31\\xd2\\x66\\x03\\x06\\xf8\\x7b\\x66\\x13\\x16\\xfc\\x7b\\x66\\x52\\x66\\x50\\x06\\x53\\x6a\\x01\\x6a\\x10\\x89\\xe6\\x66\\xf7\\x36\\xe8\\x7b\\xc0\\xe4\\x06\\x88\\xe1\\x88\\xc5\\x92\\xf6\\x36\\xee\\x7b\\x88\\xc6\\x08\\xe1\\x41\\xb8\\x01\\x02\\x8a\\x16\\xf2\\x7b\\xcd\\x13\\x8d\\x64\\x10\\x66\\x61\\xc3\\xe8\\x1e\\x00\\x4f\\x70\\x65\\x72\\x61\\x74\\x69\\x6e\\x67\\x20\\x73\\x79\\x73\\x74\\x65\\x6d\\x20\\x6c\\x6f\\x61\\x64\\x20\\x65\\x72\\x72\\x6f\\x72\\x2e\\x0d\\x0a\\x5e\\xac\\xb4\\x0e\\x8a\\x3e\\x62\\x04\\xb3\\x07\\xcd\\x10\\x3c\\x0a\\x75\\xf1\\xcd\\x18\\xf4\\xeb\\xfd\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00'", "self", ".", "mbr", "=", "isohybrid_data_hd0", "self", ".", "rba", "=", "0", "# This will be set later", "self", ".", "mbr_id", "=", "mbr_id", "if", "self", ".", "mbr_id", "is", "None", ":", "self", ".", "mbr_id", "=", "random", ".", "getrandbits", "(", "32", ")", "self", ".", "part_entry", "=", "part_entry", "self", ".", "bhead", "=", "(", "part_offset", "//", "geometry_sectors", ")", "%", "geometry_heads", "self", ".", "bsect", "=", "(", "part_offset", "%", "geometry_sectors", ")", "+", "1", "self", ".", "bcyle", "=", "part_offset", "//", "(", "geometry_heads", "*", "geometry_sectors", ")", "self", ".", "bsect", "+=", "(", "self", ".", "bcyle", "&", "0x300", ")", ">>", "2", "self", ".", "bcyle", "&=", "0xff", "self", ".", "ptype", "=", "part_type", "self", ".", "ehead", "=", "geometry_heads", "-", "1", "self", ".", "part_offset", "=", "part_offset", "self", ".", "geometry_heads", "=", "geometry_heads", "self", ".", "geometry_sectors", "=", "geometry_sectors", "self", ".", "_initialized", "=", "True" ]
A method to add ISO hybridization to an ISO. Parameters: mac - Whether this ISO should be made bootable for the Macintosh. part_entry - The partition entry for the hybridization. mbr_id - The mbr_id to use for the hybridization. part_offset - The partition offset to use for the hybridization. geometry_sectors - The number of sectors to use for the hybridization. geometry_heads - The number of heads to use for the hybridization. part_type - The partition type for the hybridization. Returns: Nothing.
[ "A", "method", "to", "add", "ISO", "hybridization", "to", "an", "ISO", "." ]
1e7b77a809e905d67dc71e12d70e850be26b6233
https://github.com/clalancette/pycdlib/blob/1e7b77a809e905d67dc71e12d70e850be26b6233/pycdlib/isohybrid.py#L109-L154
train
clalancette/pycdlib
pycdlib/isohybrid.py
IsoHybrid._calc_cc
def _calc_cc(self, iso_size): # type: (int) -> Tuple[int, int] ''' A method to calculate the 'cc' and the 'padding' values for this hybridization. Parameters: iso_size - The size of the ISO, excluding the hybridization. Returns: A tuple containing the cc value and the padding. ''' cylsize = self.geometry_heads * self.geometry_sectors * 512 frac = iso_size % cylsize padding = 0 if frac > 0: padding = cylsize - frac cc = (iso_size + padding) // cylsize if cc > 1024: cc = 1024 return (cc, padding)
python
def _calc_cc(self, iso_size): # type: (int) -> Tuple[int, int] ''' A method to calculate the 'cc' and the 'padding' values for this hybridization. Parameters: iso_size - The size of the ISO, excluding the hybridization. Returns: A tuple containing the cc value and the padding. ''' cylsize = self.geometry_heads * self.geometry_sectors * 512 frac = iso_size % cylsize padding = 0 if frac > 0: padding = cylsize - frac cc = (iso_size + padding) // cylsize if cc > 1024: cc = 1024 return (cc, padding)
[ "def", "_calc_cc", "(", "self", ",", "iso_size", ")", ":", "# type: (int) -> Tuple[int, int]", "cylsize", "=", "self", ".", "geometry_heads", "*", "self", ".", "geometry_sectors", "*", "512", "frac", "=", "iso_size", "%", "cylsize", "padding", "=", "0", "if", "frac", ">", "0", ":", "padding", "=", "cylsize", "-", "frac", "cc", "=", "(", "iso_size", "+", "padding", ")", "//", "cylsize", "if", "cc", ">", "1024", ":", "cc", "=", "1024", "return", "(", "cc", ",", "padding", ")" ]
A method to calculate the 'cc' and the 'padding' values for this hybridization. Parameters: iso_size - The size of the ISO, excluding the hybridization. Returns: A tuple containing the cc value and the padding.
[ "A", "method", "to", "calculate", "the", "cc", "and", "the", "padding", "values", "for", "this", "hybridization", "." ]
1e7b77a809e905d67dc71e12d70e850be26b6233
https://github.com/clalancette/pycdlib/blob/1e7b77a809e905d67dc71e12d70e850be26b6233/pycdlib/isohybrid.py#L156-L176
train
clalancette/pycdlib
pycdlib/isohybrid.py
IsoHybrid.record
def record(self, iso_size): # type: (int) -> bytes ''' A method to generate a string containing the ISO hybridization. Parameters: iso_size - The size of the ISO, excluding the hybridization. Returns: A string containing the ISO hybridization. ''' if not self._initialized: raise pycdlibexception.PyCdlibInternalError('This IsoHybrid object is not yet initialized') outlist = [struct.pack('=32s400sLLLH', self.header, self.mbr, self.rba, 0, self.mbr_id, 0)] for i in range(1, 5): if i == self.part_entry: cc, padding_unused = self._calc_cc(iso_size) esect = self.geometry_sectors + (((cc - 1) & 0x300) >> 2) ecyle = (cc - 1) & 0xff psize = cc * self.geometry_heads * self.geometry_sectors - self.part_offset outlist.append(struct.pack('=BBBBBBBBLL', 0x80, self.bhead, self.bsect, self.bcyle, self.ptype, self.ehead, esect, ecyle, self.part_offset, psize)) else: outlist.append(b'\x00' * 16) outlist.append(b'\x55\xaa') return b''.join(outlist)
python
def record(self, iso_size): # type: (int) -> bytes ''' A method to generate a string containing the ISO hybridization. Parameters: iso_size - The size of the ISO, excluding the hybridization. Returns: A string containing the ISO hybridization. ''' if not self._initialized: raise pycdlibexception.PyCdlibInternalError('This IsoHybrid object is not yet initialized') outlist = [struct.pack('=32s400sLLLH', self.header, self.mbr, self.rba, 0, self.mbr_id, 0)] for i in range(1, 5): if i == self.part_entry: cc, padding_unused = self._calc_cc(iso_size) esect = self.geometry_sectors + (((cc - 1) & 0x300) >> 2) ecyle = (cc - 1) & 0xff psize = cc * self.geometry_heads * self.geometry_sectors - self.part_offset outlist.append(struct.pack('=BBBBBBBBLL', 0x80, self.bhead, self.bsect, self.bcyle, self.ptype, self.ehead, esect, ecyle, self.part_offset, psize)) else: outlist.append(b'\x00' * 16) outlist.append(b'\x55\xaa') return b''.join(outlist)
[ "def", "record", "(", "self", ",", "iso_size", ")", ":", "# type: (int) -> bytes", "if", "not", "self", ".", "_initialized", ":", "raise", "pycdlibexception", ".", "PyCdlibInternalError", "(", "'This IsoHybrid object is not yet initialized'", ")", "outlist", "=", "[", "struct", ".", "pack", "(", "'=32s400sLLLH'", ",", "self", ".", "header", ",", "self", ".", "mbr", ",", "self", ".", "rba", ",", "0", ",", "self", ".", "mbr_id", ",", "0", ")", "]", "for", "i", "in", "range", "(", "1", ",", "5", ")", ":", "if", "i", "==", "self", ".", "part_entry", ":", "cc", ",", "padding_unused", "=", "self", ".", "_calc_cc", "(", "iso_size", ")", "esect", "=", "self", ".", "geometry_sectors", "+", "(", "(", "(", "cc", "-", "1", ")", "&", "0x300", ")", ">>", "2", ")", "ecyle", "=", "(", "cc", "-", "1", ")", "&", "0xff", "psize", "=", "cc", "*", "self", ".", "geometry_heads", "*", "self", ".", "geometry_sectors", "-", "self", ".", "part_offset", "outlist", ".", "append", "(", "struct", ".", "pack", "(", "'=BBBBBBBBLL'", ",", "0x80", ",", "self", ".", "bhead", ",", "self", ".", "bsect", ",", "self", ".", "bcyle", ",", "self", ".", "ptype", ",", "self", ".", "ehead", ",", "esect", ",", "ecyle", ",", "self", ".", "part_offset", ",", "psize", ")", ")", "else", ":", "outlist", ".", "append", "(", "b'\\x00'", "*", "16", ")", "outlist", ".", "append", "(", "b'\\x55\\xaa'", ")", "return", "b''", ".", "join", "(", "outlist", ")" ]
A method to generate a string containing the ISO hybridization. Parameters: iso_size - The size of the ISO, excluding the hybridization. Returns: A string containing the ISO hybridization.
[ "A", "method", "to", "generate", "a", "string", "containing", "the", "ISO", "hybridization", "." ]
1e7b77a809e905d67dc71e12d70e850be26b6233
https://github.com/clalancette/pycdlib/blob/1e7b77a809e905d67dc71e12d70e850be26b6233/pycdlib/isohybrid.py#L178-L208
train
clalancette/pycdlib
pycdlib/isohybrid.py
IsoHybrid.record_padding
def record_padding(self, iso_size): # type: (int) -> bytes ''' A method to record padding for the ISO hybridization. Parameters: iso_size - The size of the ISO, excluding the hybridization. Returns: A string of zeros the right size to pad the ISO. ''' if not self._initialized: raise pycdlibexception.PyCdlibInternalError('This IsoHybrid object is not yet initialized') return b'\x00' * self._calc_cc(iso_size)[1]
python
def record_padding(self, iso_size): # type: (int) -> bytes ''' A method to record padding for the ISO hybridization. Parameters: iso_size - The size of the ISO, excluding the hybridization. Returns: A string of zeros the right size to pad the ISO. ''' if not self._initialized: raise pycdlibexception.PyCdlibInternalError('This IsoHybrid object is not yet initialized') return b'\x00' * self._calc_cc(iso_size)[1]
[ "def", "record_padding", "(", "self", ",", "iso_size", ")", ":", "# type: (int) -> bytes", "if", "not", "self", ".", "_initialized", ":", "raise", "pycdlibexception", ".", "PyCdlibInternalError", "(", "'This IsoHybrid object is not yet initialized'", ")", "return", "b'\\x00'", "*", "self", ".", "_calc_cc", "(", "iso_size", ")", "[", "1", "]" ]
A method to record padding for the ISO hybridization. Parameters: iso_size - The size of the ISO, excluding the hybridization. Returns: A string of zeros the right size to pad the ISO.
[ "A", "method", "to", "record", "padding", "for", "the", "ISO", "hybridization", "." ]
1e7b77a809e905d67dc71e12d70e850be26b6233
https://github.com/clalancette/pycdlib/blob/1e7b77a809e905d67dc71e12d70e850be26b6233/pycdlib/isohybrid.py#L210-L223
train
clalancette/pycdlib
pycdlib/isohybrid.py
IsoHybrid.update_rba
def update_rba(self, current_extent): # type: (int) -> None ''' A method to update the current rba for the ISO hybridization. Parameters: current_extent - The new extent to set the RBA to. Returns: Nothing. ''' if not self._initialized: raise pycdlibexception.PyCdlibInternalError('This IsoHybrid object is not yet initialized') self.rba = current_extent
python
def update_rba(self, current_extent): # type: (int) -> None ''' A method to update the current rba for the ISO hybridization. Parameters: current_extent - The new extent to set the RBA to. Returns: Nothing. ''' if not self._initialized: raise pycdlibexception.PyCdlibInternalError('This IsoHybrid object is not yet initialized') self.rba = current_extent
[ "def", "update_rba", "(", "self", ",", "current_extent", ")", ":", "# type: (int) -> None", "if", "not", "self", ".", "_initialized", ":", "raise", "pycdlibexception", ".", "PyCdlibInternalError", "(", "'This IsoHybrid object is not yet initialized'", ")", "self", ".", "rba", "=", "current_extent" ]
A method to update the current rba for the ISO hybridization. Parameters: current_extent - The new extent to set the RBA to. Returns: Nothing.
[ "A", "method", "to", "update", "the", "current", "rba", "for", "the", "ISO", "hybridization", "." ]
1e7b77a809e905d67dc71e12d70e850be26b6233
https://github.com/clalancette/pycdlib/blob/1e7b77a809e905d67dc71e12d70e850be26b6233/pycdlib/isohybrid.py#L225-L238
train
clalancette/pycdlib
pycdlib/dr.py
XARecord.parse
def parse(self, xastr): # type: (bytes) -> None ''' Parse an Extended Attribute Record out of a string. Parameters: xastr - The string to parse. Returns: Nothing. ''' if self._initialized: raise pycdlibexception.PyCdlibInternalError('This XARecord is already initialized!') (self._group_id, self._user_id, self._attributes, signature, self._filenum, unused) = struct.unpack_from(self.FMT, xastr, 0) if signature != b'XA': raise pycdlibexception.PyCdlibInvalidISO('Invalid signature on the XARecord!') if unused != b'\x00\x00\x00\x00\x00': raise pycdlibexception.PyCdlibInvalidISO('Unused fields should be 0') self._initialized = True
python
def parse(self, xastr): # type: (bytes) -> None ''' Parse an Extended Attribute Record out of a string. Parameters: xastr - The string to parse. Returns: Nothing. ''' if self._initialized: raise pycdlibexception.PyCdlibInternalError('This XARecord is already initialized!') (self._group_id, self._user_id, self._attributes, signature, self._filenum, unused) = struct.unpack_from(self.FMT, xastr, 0) if signature != b'XA': raise pycdlibexception.PyCdlibInvalidISO('Invalid signature on the XARecord!') if unused != b'\x00\x00\x00\x00\x00': raise pycdlibexception.PyCdlibInvalidISO('Unused fields should be 0') self._initialized = True
[ "def", "parse", "(", "self", ",", "xastr", ")", ":", "# type: (bytes) -> None", "if", "self", ".", "_initialized", ":", "raise", "pycdlibexception", ".", "PyCdlibInternalError", "(", "'This XARecord is already initialized!'", ")", "(", "self", ".", "_group_id", ",", "self", ".", "_user_id", ",", "self", ".", "_attributes", ",", "signature", ",", "self", ".", "_filenum", ",", "unused", ")", "=", "struct", ".", "unpack_from", "(", "self", ".", "FMT", ",", "xastr", ",", "0", ")", "if", "signature", "!=", "b'XA'", ":", "raise", "pycdlibexception", ".", "PyCdlibInvalidISO", "(", "'Invalid signature on the XARecord!'", ")", "if", "unused", "!=", "b'\\x00\\x00\\x00\\x00\\x00'", ":", "raise", "pycdlibexception", ".", "PyCdlibInvalidISO", "(", "'Unused fields should be 0'", ")", "self", ".", "_initialized", "=", "True" ]
Parse an Extended Attribute Record out of a string. Parameters: xastr - The string to parse. Returns: Nothing.
[ "Parse", "an", "Extended", "Attribute", "Record", "out", "of", "a", "string", "." ]
1e7b77a809e905d67dc71e12d70e850be26b6233
https://github.com/clalancette/pycdlib/blob/1e7b77a809e905d67dc71e12d70e850be26b6233/pycdlib/dr.py#L54-L76
train
clalancette/pycdlib
pycdlib/dr.py
XARecord.new
def new(self): # type: () -> None ''' Create a new Extended Attribute Record. Parameters: None. Returns: Nothing. ''' if self._initialized: raise pycdlibexception.PyCdlibInternalError('This XARecord is already initialized!') # FIXME: we should allow the user to set these self._group_id = 0 self._user_id = 0 self._attributes = 0 self._filenum = 0 self._initialized = True
python
def new(self): # type: () -> None ''' Create a new Extended Attribute Record. Parameters: None. Returns: Nothing. ''' if self._initialized: raise pycdlibexception.PyCdlibInternalError('This XARecord is already initialized!') # FIXME: we should allow the user to set these self._group_id = 0 self._user_id = 0 self._attributes = 0 self._filenum = 0 self._initialized = True
[ "def", "new", "(", "self", ")", ":", "# type: () -> None", "if", "self", ".", "_initialized", ":", "raise", "pycdlibexception", ".", "PyCdlibInternalError", "(", "'This XARecord is already initialized!'", ")", "# FIXME: we should allow the user to set these", "self", ".", "_group_id", "=", "0", "self", ".", "_user_id", "=", "0", "self", ".", "_attributes", "=", "0", "self", ".", "_filenum", "=", "0", "self", ".", "_initialized", "=", "True" ]
Create a new Extended Attribute Record. Parameters: None. Returns: Nothing.
[ "Create", "a", "new", "Extended", "Attribute", "Record", "." ]
1e7b77a809e905d67dc71e12d70e850be26b6233
https://github.com/clalancette/pycdlib/blob/1e7b77a809e905d67dc71e12d70e850be26b6233/pycdlib/dr.py#L78-L96
train
clalancette/pycdlib
pycdlib/dr.py
XARecord.record
def record(self): # type: () -> bytes ''' Record this Extended Attribute Record. Parameters: None. Returns: A string representing this Extended Attribute Record. ''' if not self._initialized: raise pycdlibexception.PyCdlibInternalError('This XARecord is not yet initialized!') return struct.pack(self.FMT, self._group_id, self._user_id, self._attributes, b'XA', self._filenum, b'\x00' * 5)
python
def record(self): # type: () -> bytes ''' Record this Extended Attribute Record. Parameters: None. Returns: A string representing this Extended Attribute Record. ''' if not self._initialized: raise pycdlibexception.PyCdlibInternalError('This XARecord is not yet initialized!') return struct.pack(self.FMT, self._group_id, self._user_id, self._attributes, b'XA', self._filenum, b'\x00' * 5)
[ "def", "record", "(", "self", ")", ":", "# type: () -> bytes", "if", "not", "self", ".", "_initialized", ":", "raise", "pycdlibexception", ".", "PyCdlibInternalError", "(", "'This XARecord is not yet initialized!'", ")", "return", "struct", ".", "pack", "(", "self", ".", "FMT", ",", "self", ".", "_group_id", ",", "self", ".", "_user_id", ",", "self", ".", "_attributes", ",", "b'XA'", ",", "self", ".", "_filenum", ",", "b'\\x00'", "*", "5", ")" ]
Record this Extended Attribute Record. Parameters: None. Returns: A string representing this Extended Attribute Record.
[ "Record", "this", "Extended", "Attribute", "Record", "." ]
1e7b77a809e905d67dc71e12d70e850be26b6233
https://github.com/clalancette/pycdlib/blob/1e7b77a809e905d67dc71e12d70e850be26b6233/pycdlib/dr.py#L98-L112
train
clalancette/pycdlib
pycdlib/dr.py
DirectoryRecord._new
def _new(self, vd, name, parent, seqnum, isdir, length, xa): # type: (headervd.PrimaryOrSupplementaryVD, bytes, Optional[DirectoryRecord], int, bool, int, bool) -> None ''' Internal method to create a new Directory Record. Parameters: vd - The Volume Descriptor this record is part of. name - The name for this directory record. parent - The parent of this directory record. seqnum - The sequence number to associate with this directory record. isdir - Whether this directory record represents a directory. length - The length of the data for this directory record. xa - True if this is an Extended Attribute record. Returns: Nothing. ''' # Adding a new time should really be done when we are going to write # the ISO (in record()). Ecma-119 9.1.5 says: # # 'This field shall indicate the date and the time of the day at which # the information in the Extent described by the Directory Record was # recorded.' # # We create it here just to have something in the field, but we'll # redo the whole thing when we are mastering. self.date = dates.DirectoryRecordDate() self.date.new() if length > 2**32 - 1: raise pycdlibexception.PyCdlibInvalidInput('Maximum supported file length is 2^32-1') self.data_length = length self.file_ident = name self.isdir = isdir self.seqnum = seqnum # For a new directory record entry, there is no original_extent_loc, # so we leave it at None. self.orig_extent_loc = None self.len_fi = len(self.file_ident) self.dr_len = struct.calcsize(self.FMT) + self.len_fi # From Ecma-119, 9.1.6, the file flag bits are: # # Bit 0 - Existence - 0 for existence known, 1 for hidden # Bit 1 - Directory - 0 for file, 1 for directory # Bit 2 - Associated File - 0 for not associated, 1 for associated # Bit 3 - Record - 0=structure not in xattr, 1=structure in xattr # Bit 4 - Protection - 0=no owner and group, 1=owner and group in xattr # Bit 5 - Reserved # Bit 6 - Reserved # Bit 7 - Multi-extent - 0=final directory record, 1=not final directory record self.file_flags = 0 if self.isdir: self.file_flags |= (1 << self.FILE_FLAG_DIRECTORY_BIT) self.file_unit_size = 0 # FIXME: we don't support setting file unit size for now self.interleave_gap_size = 0 # FIXME: we don't support setting interleave gap size for now self.xattr_len = 0 # FIXME: we don't support xattrs for now self.parent = parent if parent is None: # If no parent, then this is the root self.is_root = True if xa: self.xa_record = XARecord() self.xa_record.new() self.dr_len += XARecord.length() self.dr_len += (self.dr_len % 2) if self.is_root: self._printable_name = b'/' elif self.file_ident == b'\x00': self._printable_name = b'.' elif self.file_ident == b'\x01': self._printable_name = b'..' else: self._printable_name = self.file_ident self.vd = vd self._initialized = True
python
def _new(self, vd, name, parent, seqnum, isdir, length, xa): # type: (headervd.PrimaryOrSupplementaryVD, bytes, Optional[DirectoryRecord], int, bool, int, bool) -> None ''' Internal method to create a new Directory Record. Parameters: vd - The Volume Descriptor this record is part of. name - The name for this directory record. parent - The parent of this directory record. seqnum - The sequence number to associate with this directory record. isdir - Whether this directory record represents a directory. length - The length of the data for this directory record. xa - True if this is an Extended Attribute record. Returns: Nothing. ''' # Adding a new time should really be done when we are going to write # the ISO (in record()). Ecma-119 9.1.5 says: # # 'This field shall indicate the date and the time of the day at which # the information in the Extent described by the Directory Record was # recorded.' # # We create it here just to have something in the field, but we'll # redo the whole thing when we are mastering. self.date = dates.DirectoryRecordDate() self.date.new() if length > 2**32 - 1: raise pycdlibexception.PyCdlibInvalidInput('Maximum supported file length is 2^32-1') self.data_length = length self.file_ident = name self.isdir = isdir self.seqnum = seqnum # For a new directory record entry, there is no original_extent_loc, # so we leave it at None. self.orig_extent_loc = None self.len_fi = len(self.file_ident) self.dr_len = struct.calcsize(self.FMT) + self.len_fi # From Ecma-119, 9.1.6, the file flag bits are: # # Bit 0 - Existence - 0 for existence known, 1 for hidden # Bit 1 - Directory - 0 for file, 1 for directory # Bit 2 - Associated File - 0 for not associated, 1 for associated # Bit 3 - Record - 0=structure not in xattr, 1=structure in xattr # Bit 4 - Protection - 0=no owner and group, 1=owner and group in xattr # Bit 5 - Reserved # Bit 6 - Reserved # Bit 7 - Multi-extent - 0=final directory record, 1=not final directory record self.file_flags = 0 if self.isdir: self.file_flags |= (1 << self.FILE_FLAG_DIRECTORY_BIT) self.file_unit_size = 0 # FIXME: we don't support setting file unit size for now self.interleave_gap_size = 0 # FIXME: we don't support setting interleave gap size for now self.xattr_len = 0 # FIXME: we don't support xattrs for now self.parent = parent if parent is None: # If no parent, then this is the root self.is_root = True if xa: self.xa_record = XARecord() self.xa_record.new() self.dr_len += XARecord.length() self.dr_len += (self.dr_len % 2) if self.is_root: self._printable_name = b'/' elif self.file_ident == b'\x00': self._printable_name = b'.' elif self.file_ident == b'\x01': self._printable_name = b'..' else: self._printable_name = self.file_ident self.vd = vd self._initialized = True
[ "def", "_new", "(", "self", ",", "vd", ",", "name", ",", "parent", ",", "seqnum", ",", "isdir", ",", "length", ",", "xa", ")", ":", "# type: (headervd.PrimaryOrSupplementaryVD, bytes, Optional[DirectoryRecord], int, bool, int, bool) -> None", "# Adding a new time should really be done when we are going to write", "# the ISO (in record()). Ecma-119 9.1.5 says:", "#", "# 'This field shall indicate the date and the time of the day at which", "# the information in the Extent described by the Directory Record was", "# recorded.'", "#", "# We create it here just to have something in the field, but we'll", "# redo the whole thing when we are mastering.", "self", ".", "date", "=", "dates", ".", "DirectoryRecordDate", "(", ")", "self", ".", "date", ".", "new", "(", ")", "if", "length", ">", "2", "**", "32", "-", "1", ":", "raise", "pycdlibexception", ".", "PyCdlibInvalidInput", "(", "'Maximum supported file length is 2^32-1'", ")", "self", ".", "data_length", "=", "length", "self", ".", "file_ident", "=", "name", "self", ".", "isdir", "=", "isdir", "self", ".", "seqnum", "=", "seqnum", "# For a new directory record entry, there is no original_extent_loc,", "# so we leave it at None.", "self", ".", "orig_extent_loc", "=", "None", "self", ".", "len_fi", "=", "len", "(", "self", ".", "file_ident", ")", "self", ".", "dr_len", "=", "struct", ".", "calcsize", "(", "self", ".", "FMT", ")", "+", "self", ".", "len_fi", "# From Ecma-119, 9.1.6, the file flag bits are:", "#", "# Bit 0 - Existence - 0 for existence known, 1 for hidden", "# Bit 1 - Directory - 0 for file, 1 for directory", "# Bit 2 - Associated File - 0 for not associated, 1 for associated", "# Bit 3 - Record - 0=structure not in xattr, 1=structure in xattr", "# Bit 4 - Protection - 0=no owner and group, 1=owner and group in xattr", "# Bit 5 - Reserved", "# Bit 6 - Reserved", "# Bit 7 - Multi-extent - 0=final directory record, 1=not final directory record", "self", ".", "file_flags", "=", "0", "if", "self", ".", "isdir", ":", "self", ".", "file_flags", "|=", "(", "1", "<<", "self", ".", "FILE_FLAG_DIRECTORY_BIT", ")", "self", ".", "file_unit_size", "=", "0", "# FIXME: we don't support setting file unit size for now", "self", ".", "interleave_gap_size", "=", "0", "# FIXME: we don't support setting interleave gap size for now", "self", ".", "xattr_len", "=", "0", "# FIXME: we don't support xattrs for now", "self", ".", "parent", "=", "parent", "if", "parent", "is", "None", ":", "# If no parent, then this is the root", "self", ".", "is_root", "=", "True", "if", "xa", ":", "self", ".", "xa_record", "=", "XARecord", "(", ")", "self", ".", "xa_record", ".", "new", "(", ")", "self", ".", "dr_len", "+=", "XARecord", ".", "length", "(", ")", "self", ".", "dr_len", "+=", "(", "self", ".", "dr_len", "%", "2", ")", "if", "self", ".", "is_root", ":", "self", ".", "_printable_name", "=", "b'/'", "elif", "self", ".", "file_ident", "==", "b'\\x00'", ":", "self", ".", "_printable_name", "=", "b'.'", "elif", "self", ".", "file_ident", "==", "b'\\x01'", ":", "self", ".", "_printable_name", "=", "b'..'", "else", ":", "self", ".", "_printable_name", "=", "self", ".", "file_ident", "self", ".", "vd", "=", "vd", "self", ".", "_initialized", "=", "True" ]
Internal method to create a new Directory Record. Parameters: vd - The Volume Descriptor this record is part of. name - The name for this directory record. parent - The parent of this directory record. seqnum - The sequence number to associate with this directory record. isdir - Whether this directory record represents a directory. length - The length of the data for this directory record. xa - True if this is an Extended Attribute record. Returns: Nothing.
[ "Internal", "method", "to", "create", "a", "new", "Directory", "Record", "." ]
1e7b77a809e905d67dc71e12d70e850be26b6233
https://github.com/clalancette/pycdlib/blob/1e7b77a809e905d67dc71e12d70e850be26b6233/pycdlib/dr.py#L402-L487
train
clalancette/pycdlib
pycdlib/dr.py
DirectoryRecord.new_symlink
def new_symlink(self, vd, name, parent, rr_target, seqnum, rock_ridge, rr_name, xa): # type: (headervd.PrimaryOrSupplementaryVD, bytes, DirectoryRecord, bytes, int, str, bytes, bool) -> None ''' Create a new symlink Directory Record. This implies that the new record will be Rock Ridge. Parameters: vd - The Volume Descriptor this record is part of. name - The name for this directory record. parent - The parent of this directory record. rr_target - The symlink target for this directory record. seqnum - The sequence number for this directory record. rock_ridge - The version of Rock Ridge to use for this directory record. rr_name - The Rock Ridge name for this directory record. xa - True if this is an Extended Attribute record. Returns: Nothing. ''' if self._initialized: raise pycdlibexception.PyCdlibInternalError('Directory Record already initialized') self._new(vd, name, parent, seqnum, False, 0, xa) if rock_ridge: self._rr_new(rock_ridge, rr_name, rr_target, False, False, False, 0o0120555)
python
def new_symlink(self, vd, name, parent, rr_target, seqnum, rock_ridge, rr_name, xa): # type: (headervd.PrimaryOrSupplementaryVD, bytes, DirectoryRecord, bytes, int, str, bytes, bool) -> None ''' Create a new symlink Directory Record. This implies that the new record will be Rock Ridge. Parameters: vd - The Volume Descriptor this record is part of. name - The name for this directory record. parent - The parent of this directory record. rr_target - The symlink target for this directory record. seqnum - The sequence number for this directory record. rock_ridge - The version of Rock Ridge to use for this directory record. rr_name - The Rock Ridge name for this directory record. xa - True if this is an Extended Attribute record. Returns: Nothing. ''' if self._initialized: raise pycdlibexception.PyCdlibInternalError('Directory Record already initialized') self._new(vd, name, parent, seqnum, False, 0, xa) if rock_ridge: self._rr_new(rock_ridge, rr_name, rr_target, False, False, False, 0o0120555)
[ "def", "new_symlink", "(", "self", ",", "vd", ",", "name", ",", "parent", ",", "rr_target", ",", "seqnum", ",", "rock_ridge", ",", "rr_name", ",", "xa", ")", ":", "# type: (headervd.PrimaryOrSupplementaryVD, bytes, DirectoryRecord, bytes, int, str, bytes, bool) -> None", "if", "self", ".", "_initialized", ":", "raise", "pycdlibexception", ".", "PyCdlibInternalError", "(", "'Directory Record already initialized'", ")", "self", ".", "_new", "(", "vd", ",", "name", ",", "parent", ",", "seqnum", ",", "False", ",", "0", ",", "xa", ")", "if", "rock_ridge", ":", "self", ".", "_rr_new", "(", "rock_ridge", ",", "rr_name", ",", "rr_target", ",", "False", ",", "False", ",", "False", ",", "0o0120555", ")" ]
Create a new symlink Directory Record. This implies that the new record will be Rock Ridge. Parameters: vd - The Volume Descriptor this record is part of. name - The name for this directory record. parent - The parent of this directory record. rr_target - The symlink target for this directory record. seqnum - The sequence number for this directory record. rock_ridge - The version of Rock Ridge to use for this directory record. rr_name - The Rock Ridge name for this directory record. xa - True if this is an Extended Attribute record. Returns: Nothing.
[ "Create", "a", "new", "symlink", "Directory", "Record", ".", "This", "implies", "that", "the", "new", "record", "will", "be", "Rock", "Ridge", "." ]
1e7b77a809e905d67dc71e12d70e850be26b6233
https://github.com/clalancette/pycdlib/blob/1e7b77a809e905d67dc71e12d70e850be26b6233/pycdlib/dr.py#L489-L514
train
clalancette/pycdlib
pycdlib/dr.py
DirectoryRecord.new_file
def new_file(self, vd, length, isoname, parent, seqnum, rock_ridge, rr_name, xa, file_mode): # type: (headervd.PrimaryOrSupplementaryVD, int, bytes, DirectoryRecord, int, str, bytes, bool, int) -> None ''' Create a new file Directory Record. Parameters: vd - The Volume Descriptor this record is part of. length - The length of the data. isoname - The name for this directory record. parent - The parent of this directory record. seqnum - The sequence number for this directory record. rock_ridge - Whether to make this a Rock Ridge directory record. rr_name - The Rock Ridge name for this directory record. xa - True if this is an Extended Attribute record. file_mode - The POSIX file mode for this entry. Returns: Nothing. ''' if self._initialized: raise pycdlibexception.PyCdlibInternalError('Directory Record already initialized') self._new(vd, isoname, parent, seqnum, False, length, xa) if rock_ridge: self._rr_new(rock_ridge, rr_name, b'', False, False, False, file_mode)
python
def new_file(self, vd, length, isoname, parent, seqnum, rock_ridge, rr_name, xa, file_mode): # type: (headervd.PrimaryOrSupplementaryVD, int, bytes, DirectoryRecord, int, str, bytes, bool, int) -> None ''' Create a new file Directory Record. Parameters: vd - The Volume Descriptor this record is part of. length - The length of the data. isoname - The name for this directory record. parent - The parent of this directory record. seqnum - The sequence number for this directory record. rock_ridge - Whether to make this a Rock Ridge directory record. rr_name - The Rock Ridge name for this directory record. xa - True if this is an Extended Attribute record. file_mode - The POSIX file mode for this entry. Returns: Nothing. ''' if self._initialized: raise pycdlibexception.PyCdlibInternalError('Directory Record already initialized') self._new(vd, isoname, parent, seqnum, False, length, xa) if rock_ridge: self._rr_new(rock_ridge, rr_name, b'', False, False, False, file_mode)
[ "def", "new_file", "(", "self", ",", "vd", ",", "length", ",", "isoname", ",", "parent", ",", "seqnum", ",", "rock_ridge", ",", "rr_name", ",", "xa", ",", "file_mode", ")", ":", "# type: (headervd.PrimaryOrSupplementaryVD, int, bytes, DirectoryRecord, int, str, bytes, bool, int) -> None", "if", "self", ".", "_initialized", ":", "raise", "pycdlibexception", ".", "PyCdlibInternalError", "(", "'Directory Record already initialized'", ")", "self", ".", "_new", "(", "vd", ",", "isoname", ",", "parent", ",", "seqnum", ",", "False", ",", "length", ",", "xa", ")", "if", "rock_ridge", ":", "self", ".", "_rr_new", "(", "rock_ridge", ",", "rr_name", ",", "b''", ",", "False", ",", "False", ",", "False", ",", "file_mode", ")" ]
Create a new file Directory Record. Parameters: vd - The Volume Descriptor this record is part of. length - The length of the data. isoname - The name for this directory record. parent - The parent of this directory record. seqnum - The sequence number for this directory record. rock_ridge - Whether to make this a Rock Ridge directory record. rr_name - The Rock Ridge name for this directory record. xa - True if this is an Extended Attribute record. file_mode - The POSIX file mode for this entry. Returns: Nothing.
[ "Create", "a", "new", "file", "Directory", "Record", "." ]
1e7b77a809e905d67dc71e12d70e850be26b6233
https://github.com/clalancette/pycdlib/blob/1e7b77a809e905d67dc71e12d70e850be26b6233/pycdlib/dr.py#L516-L541
train
clalancette/pycdlib
pycdlib/dr.py
DirectoryRecord.new_root
def new_root(self, vd, seqnum, log_block_size): # type: (headervd.PrimaryOrSupplementaryVD, int, int) -> None ''' Create a new root Directory Record. Parameters: vd - The Volume Descriptor this record is part of. seqnum - The sequence number for this directory record. log_block_size - The logical block size to use. Returns: Nothing. ''' if self._initialized: raise pycdlibexception.PyCdlibInternalError('Directory Record already initialized') self._new(vd, b'\x00', None, seqnum, True, log_block_size, False)
python
def new_root(self, vd, seqnum, log_block_size): # type: (headervd.PrimaryOrSupplementaryVD, int, int) -> None ''' Create a new root Directory Record. Parameters: vd - The Volume Descriptor this record is part of. seqnum - The sequence number for this directory record. log_block_size - The logical block size to use. Returns: Nothing. ''' if self._initialized: raise pycdlibexception.PyCdlibInternalError('Directory Record already initialized') self._new(vd, b'\x00', None, seqnum, True, log_block_size, False)
[ "def", "new_root", "(", "self", ",", "vd", ",", "seqnum", ",", "log_block_size", ")", ":", "# type: (headervd.PrimaryOrSupplementaryVD, int, int) -> None", "if", "self", ".", "_initialized", ":", "raise", "pycdlibexception", ".", "PyCdlibInternalError", "(", "'Directory Record already initialized'", ")", "self", ".", "_new", "(", "vd", ",", "b'\\x00'", ",", "None", ",", "seqnum", ",", "True", ",", "log_block_size", ",", "False", ")" ]
Create a new root Directory Record. Parameters: vd - The Volume Descriptor this record is part of. seqnum - The sequence number for this directory record. log_block_size - The logical block size to use. Returns: Nothing.
[ "Create", "a", "new", "root", "Directory", "Record", "." ]
1e7b77a809e905d67dc71e12d70e850be26b6233
https://github.com/clalancette/pycdlib/blob/1e7b77a809e905d67dc71e12d70e850be26b6233/pycdlib/dr.py#L543-L558
train
clalancette/pycdlib
pycdlib/dr.py
DirectoryRecord.new_dot
def new_dot(self, vd, parent, seqnum, rock_ridge, log_block_size, xa, file_mode): # type: (headervd.PrimaryOrSupplementaryVD, DirectoryRecord, int, str, int, bool, int) -> None ''' Create a new 'dot' Directory Record. Parameters: vd - The Volume Descriptor this record is part of. parent - The parent of this directory record. seqnum - The sequence number for this directory record. rock_ridge - Whether to make this a Rock Ridge directory record. log_block_size - The logical block size to use. xa - True if this is an Extended Attribute record. file_mode - The POSIX file mode to set for this directory. Returns: Nothing. ''' if self._initialized: raise pycdlibexception.PyCdlibInternalError('Directory Record already initialized') self._new(vd, b'\x00', parent, seqnum, True, log_block_size, xa) if rock_ridge: self._rr_new(rock_ridge, b'', b'', False, False, False, file_mode)
python
def new_dot(self, vd, parent, seqnum, rock_ridge, log_block_size, xa, file_mode): # type: (headervd.PrimaryOrSupplementaryVD, DirectoryRecord, int, str, int, bool, int) -> None ''' Create a new 'dot' Directory Record. Parameters: vd - The Volume Descriptor this record is part of. parent - The parent of this directory record. seqnum - The sequence number for this directory record. rock_ridge - Whether to make this a Rock Ridge directory record. log_block_size - The logical block size to use. xa - True if this is an Extended Attribute record. file_mode - The POSIX file mode to set for this directory. Returns: Nothing. ''' if self._initialized: raise pycdlibexception.PyCdlibInternalError('Directory Record already initialized') self._new(vd, b'\x00', parent, seqnum, True, log_block_size, xa) if rock_ridge: self._rr_new(rock_ridge, b'', b'', False, False, False, file_mode)
[ "def", "new_dot", "(", "self", ",", "vd", ",", "parent", ",", "seqnum", ",", "rock_ridge", ",", "log_block_size", ",", "xa", ",", "file_mode", ")", ":", "# type: (headervd.PrimaryOrSupplementaryVD, DirectoryRecord, int, str, int, bool, int) -> None", "if", "self", ".", "_initialized", ":", "raise", "pycdlibexception", ".", "PyCdlibInternalError", "(", "'Directory Record already initialized'", ")", "self", ".", "_new", "(", "vd", ",", "b'\\x00'", ",", "parent", ",", "seqnum", ",", "True", ",", "log_block_size", ",", "xa", ")", "if", "rock_ridge", ":", "self", ".", "_rr_new", "(", "rock_ridge", ",", "b''", ",", "b''", ",", "False", ",", "False", ",", "False", ",", "file_mode", ")" ]
Create a new 'dot' Directory Record. Parameters: vd - The Volume Descriptor this record is part of. parent - The parent of this directory record. seqnum - The sequence number for this directory record. rock_ridge - Whether to make this a Rock Ridge directory record. log_block_size - The logical block size to use. xa - True if this is an Extended Attribute record. file_mode - The POSIX file mode to set for this directory. Returns: Nothing.
[ "Create", "a", "new", "dot", "Directory", "Record", "." ]
1e7b77a809e905d67dc71e12d70e850be26b6233
https://github.com/clalancette/pycdlib/blob/1e7b77a809e905d67dc71e12d70e850be26b6233/pycdlib/dr.py#L560-L582
train
clalancette/pycdlib
pycdlib/dr.py
DirectoryRecord.new_dotdot
def new_dotdot(self, vd, parent, seqnum, rock_ridge, log_block_size, rr_relocated_parent, xa, file_mode): # type: (headervd.PrimaryOrSupplementaryVD, DirectoryRecord, int, str, int, bool, bool, int) -> None ''' Create a new 'dotdot' Directory Record. Parameters: vd - The Volume Descriptor this record is part of. parent - The parent of this directory record. seqnum - The sequence number for this directory record. rock_ridge - Whether to make this a Rock Ridge directory record. log_block_size - The logical block size to use. rr_relocated_parent - True if this is a Rock Ridge relocated parent. xa - True if this is an Extended Attribute record. file_mode - The POSIX file mode to set for this directory. Returns: Nothing. ''' if self._initialized: raise pycdlibexception.PyCdlibInternalError('Directory Record already initialized') self._new(vd, b'\x01', parent, seqnum, True, log_block_size, xa) if rock_ridge: self._rr_new(rock_ridge, b'', b'', False, False, rr_relocated_parent, file_mode)
python
def new_dotdot(self, vd, parent, seqnum, rock_ridge, log_block_size, rr_relocated_parent, xa, file_mode): # type: (headervd.PrimaryOrSupplementaryVD, DirectoryRecord, int, str, int, bool, bool, int) -> None ''' Create a new 'dotdot' Directory Record. Parameters: vd - The Volume Descriptor this record is part of. parent - The parent of this directory record. seqnum - The sequence number for this directory record. rock_ridge - Whether to make this a Rock Ridge directory record. log_block_size - The logical block size to use. rr_relocated_parent - True if this is a Rock Ridge relocated parent. xa - True if this is an Extended Attribute record. file_mode - The POSIX file mode to set for this directory. Returns: Nothing. ''' if self._initialized: raise pycdlibexception.PyCdlibInternalError('Directory Record already initialized') self._new(vd, b'\x01', parent, seqnum, True, log_block_size, xa) if rock_ridge: self._rr_new(rock_ridge, b'', b'', False, False, rr_relocated_parent, file_mode)
[ "def", "new_dotdot", "(", "self", ",", "vd", ",", "parent", ",", "seqnum", ",", "rock_ridge", ",", "log_block_size", ",", "rr_relocated_parent", ",", "xa", ",", "file_mode", ")", ":", "# type: (headervd.PrimaryOrSupplementaryVD, DirectoryRecord, int, str, int, bool, bool, int) -> None", "if", "self", ".", "_initialized", ":", "raise", "pycdlibexception", ".", "PyCdlibInternalError", "(", "'Directory Record already initialized'", ")", "self", ".", "_new", "(", "vd", ",", "b'\\x01'", ",", "parent", ",", "seqnum", ",", "True", ",", "log_block_size", ",", "xa", ")", "if", "rock_ridge", ":", "self", ".", "_rr_new", "(", "rock_ridge", ",", "b''", ",", "b''", ",", "False", ",", "False", ",", "rr_relocated_parent", ",", "file_mode", ")" ]
Create a new 'dotdot' Directory Record. Parameters: vd - The Volume Descriptor this record is part of. parent - The parent of this directory record. seqnum - The sequence number for this directory record. rock_ridge - Whether to make this a Rock Ridge directory record. log_block_size - The logical block size to use. rr_relocated_parent - True if this is a Rock Ridge relocated parent. xa - True if this is an Extended Attribute record. file_mode - The POSIX file mode to set for this directory. Returns: Nothing.
[ "Create", "a", "new", "dotdot", "Directory", "Record", "." ]
1e7b77a809e905d67dc71e12d70e850be26b6233
https://github.com/clalancette/pycdlib/blob/1e7b77a809e905d67dc71e12d70e850be26b6233/pycdlib/dr.py#L584-L607
train
clalancette/pycdlib
pycdlib/dr.py
DirectoryRecord.new_dir
def new_dir(self, vd, name, parent, seqnum, rock_ridge, rr_name, log_block_size, rr_relocated_child, rr_relocated, xa, file_mode): # type: (headervd.PrimaryOrSupplementaryVD, bytes, DirectoryRecord, int, str, bytes, int, bool, bool, bool, int) -> None ''' Create a new directory Directory Record. Parameters: vd - The Volume Descriptor this record is part of. name - The name for this directory record. parent - The parent of this directory record. seqnum - The sequence number for this directory record. rock_ridge - Whether to make this a Rock Ridge directory record. rr_name - The Rock Ridge name for this directory record. log_block_size - The logical block size to use. rr_relocated_child - True if this is a Rock Ridge relocated child. rr_relocated - True if this is a Rock Ridge relocated entry. xa - True if this is an Extended Attribute record. file_mode - The POSIX file mode to set for this directory. Returns: Nothing. ''' if self._initialized: raise pycdlibexception.PyCdlibInternalError('Directory Record already initialized') self._new(vd, name, parent, seqnum, True, log_block_size, xa) if rock_ridge: self._rr_new(rock_ridge, rr_name, b'', rr_relocated_child, rr_relocated, False, file_mode) if rr_relocated_child and self.rock_ridge: # Relocated Rock Ridge entries are not exactly treated as directories, so # fix things up here. self.isdir = False self.file_flags = 0 self.rock_ridge.add_to_file_links()
python
def new_dir(self, vd, name, parent, seqnum, rock_ridge, rr_name, log_block_size, rr_relocated_child, rr_relocated, xa, file_mode): # type: (headervd.PrimaryOrSupplementaryVD, bytes, DirectoryRecord, int, str, bytes, int, bool, bool, bool, int) -> None ''' Create a new directory Directory Record. Parameters: vd - The Volume Descriptor this record is part of. name - The name for this directory record. parent - The parent of this directory record. seqnum - The sequence number for this directory record. rock_ridge - Whether to make this a Rock Ridge directory record. rr_name - The Rock Ridge name for this directory record. log_block_size - The logical block size to use. rr_relocated_child - True if this is a Rock Ridge relocated child. rr_relocated - True if this is a Rock Ridge relocated entry. xa - True if this is an Extended Attribute record. file_mode - The POSIX file mode to set for this directory. Returns: Nothing. ''' if self._initialized: raise pycdlibexception.PyCdlibInternalError('Directory Record already initialized') self._new(vd, name, parent, seqnum, True, log_block_size, xa) if rock_ridge: self._rr_new(rock_ridge, rr_name, b'', rr_relocated_child, rr_relocated, False, file_mode) if rr_relocated_child and self.rock_ridge: # Relocated Rock Ridge entries are not exactly treated as directories, so # fix things up here. self.isdir = False self.file_flags = 0 self.rock_ridge.add_to_file_links()
[ "def", "new_dir", "(", "self", ",", "vd", ",", "name", ",", "parent", ",", "seqnum", ",", "rock_ridge", ",", "rr_name", ",", "log_block_size", ",", "rr_relocated_child", ",", "rr_relocated", ",", "xa", ",", "file_mode", ")", ":", "# type: (headervd.PrimaryOrSupplementaryVD, bytes, DirectoryRecord, int, str, bytes, int, bool, bool, bool, int) -> None", "if", "self", ".", "_initialized", ":", "raise", "pycdlibexception", ".", "PyCdlibInternalError", "(", "'Directory Record already initialized'", ")", "self", ".", "_new", "(", "vd", ",", "name", ",", "parent", ",", "seqnum", ",", "True", ",", "log_block_size", ",", "xa", ")", "if", "rock_ridge", ":", "self", ".", "_rr_new", "(", "rock_ridge", ",", "rr_name", ",", "b''", ",", "rr_relocated_child", ",", "rr_relocated", ",", "False", ",", "file_mode", ")", "if", "rr_relocated_child", "and", "self", ".", "rock_ridge", ":", "# Relocated Rock Ridge entries are not exactly treated as directories, so", "# fix things up here.", "self", ".", "isdir", "=", "False", "self", ".", "file_flags", "=", "0", "self", ".", "rock_ridge", ".", "add_to_file_links", "(", ")" ]
Create a new directory Directory Record. Parameters: vd - The Volume Descriptor this record is part of. name - The name for this directory record. parent - The parent of this directory record. seqnum - The sequence number for this directory record. rock_ridge - Whether to make this a Rock Ridge directory record. rr_name - The Rock Ridge name for this directory record. log_block_size - The logical block size to use. rr_relocated_child - True if this is a Rock Ridge relocated child. rr_relocated - True if this is a Rock Ridge relocated entry. xa - True if this is an Extended Attribute record. file_mode - The POSIX file mode to set for this directory. Returns: Nothing.
[ "Create", "a", "new", "directory", "Directory", "Record", "." ]
1e7b77a809e905d67dc71e12d70e850be26b6233
https://github.com/clalancette/pycdlib/blob/1e7b77a809e905d67dc71e12d70e850be26b6233/pycdlib/dr.py#L609-L642
train
clalancette/pycdlib
pycdlib/dr.py
DirectoryRecord.change_existence
def change_existence(self, is_hidden): # type: (bool) -> None ''' Change the ISO9660 existence flag of this Directory Record. Parameters: is_hidden - True if this Directory Record should be hidden, False otherwise. Returns: Nothing. ''' if not self._initialized: raise pycdlibexception.PyCdlibInternalError('Directory Record not yet initialized') if is_hidden: self.file_flags |= (1 << self.FILE_FLAG_EXISTENCE_BIT) else: self.file_flags &= ~(1 << self.FILE_FLAG_EXISTENCE_BIT)
python
def change_existence(self, is_hidden): # type: (bool) -> None ''' Change the ISO9660 existence flag of this Directory Record. Parameters: is_hidden - True if this Directory Record should be hidden, False otherwise. Returns: Nothing. ''' if not self._initialized: raise pycdlibexception.PyCdlibInternalError('Directory Record not yet initialized') if is_hidden: self.file_flags |= (1 << self.FILE_FLAG_EXISTENCE_BIT) else: self.file_flags &= ~(1 << self.FILE_FLAG_EXISTENCE_BIT)
[ "def", "change_existence", "(", "self", ",", "is_hidden", ")", ":", "# type: (bool) -> None", "if", "not", "self", ".", "_initialized", ":", "raise", "pycdlibexception", ".", "PyCdlibInternalError", "(", "'Directory Record not yet initialized'", ")", "if", "is_hidden", ":", "self", ".", "file_flags", "|=", "(", "1", "<<", "self", ".", "FILE_FLAG_EXISTENCE_BIT", ")", "else", ":", "self", ".", "file_flags", "&=", "~", "(", "1", "<<", "self", ".", "FILE_FLAG_EXISTENCE_BIT", ")" ]
Change the ISO9660 existence flag of this Directory Record. Parameters: is_hidden - True if this Directory Record should be hidden, False otherwise. Returns: Nothing.
[ "Change", "the", "ISO9660", "existence", "flag", "of", "this", "Directory", "Record", "." ]
1e7b77a809e905d67dc71e12d70e850be26b6233
https://github.com/clalancette/pycdlib/blob/1e7b77a809e905d67dc71e12d70e850be26b6233/pycdlib/dr.py#L644-L660
train
clalancette/pycdlib
pycdlib/dr.py
DirectoryRecord._recalculate_extents_and_offsets
def _recalculate_extents_and_offsets(self, index, logical_block_size): # type: (int, int) -> Tuple[int, int] ''' Internal method to recalculate the extents and offsets associated with children of this directory record. Parameters: index - The index at which to start the recalculation. logical_block_size - The block size to use for comparisons. Returns: A tuple where the first element is the total number of extents required by the children and where the second element is the offset into the last extent currently being used. ''' if index == 0: dirrecord_offset = 0 num_extents = 1 else: dirrecord_offset = self.children[index - 1].offset_to_here num_extents = self.children[index - 1].extents_to_here for i in range(index, len(self.children)): c = self.children[i] dirrecord_len = c.dr_len if (dirrecord_offset + dirrecord_len) > logical_block_size: num_extents += 1 dirrecord_offset = 0 dirrecord_offset += dirrecord_len c.extents_to_here = num_extents c.offset_to_here = dirrecord_offset c.index_in_parent = i return num_extents, dirrecord_offset
python
def _recalculate_extents_and_offsets(self, index, logical_block_size): # type: (int, int) -> Tuple[int, int] ''' Internal method to recalculate the extents and offsets associated with children of this directory record. Parameters: index - The index at which to start the recalculation. logical_block_size - The block size to use for comparisons. Returns: A tuple where the first element is the total number of extents required by the children and where the second element is the offset into the last extent currently being used. ''' if index == 0: dirrecord_offset = 0 num_extents = 1 else: dirrecord_offset = self.children[index - 1].offset_to_here num_extents = self.children[index - 1].extents_to_here for i in range(index, len(self.children)): c = self.children[i] dirrecord_len = c.dr_len if (dirrecord_offset + dirrecord_len) > logical_block_size: num_extents += 1 dirrecord_offset = 0 dirrecord_offset += dirrecord_len c.extents_to_here = num_extents c.offset_to_here = dirrecord_offset c.index_in_parent = i return num_extents, dirrecord_offset
[ "def", "_recalculate_extents_and_offsets", "(", "self", ",", "index", ",", "logical_block_size", ")", ":", "# type: (int, int) -> Tuple[int, int]", "if", "index", "==", "0", ":", "dirrecord_offset", "=", "0", "num_extents", "=", "1", "else", ":", "dirrecord_offset", "=", "self", ".", "children", "[", "index", "-", "1", "]", ".", "offset_to_here", "num_extents", "=", "self", ".", "children", "[", "index", "-", "1", "]", ".", "extents_to_here", "for", "i", "in", "range", "(", "index", ",", "len", "(", "self", ".", "children", ")", ")", ":", "c", "=", "self", ".", "children", "[", "i", "]", "dirrecord_len", "=", "c", ".", "dr_len", "if", "(", "dirrecord_offset", "+", "dirrecord_len", ")", ">", "logical_block_size", ":", "num_extents", "+=", "1", "dirrecord_offset", "=", "0", "dirrecord_offset", "+=", "dirrecord_len", "c", ".", "extents_to_here", "=", "num_extents", "c", ".", "offset_to_here", "=", "dirrecord_offset", "c", ".", "index_in_parent", "=", "i", "return", "num_extents", ",", "dirrecord_offset" ]
Internal method to recalculate the extents and offsets associated with children of this directory record. Parameters: index - The index at which to start the recalculation. logical_block_size - The block size to use for comparisons. Returns: A tuple where the first element is the total number of extents required by the children and where the second element is the offset into the last extent currently being used.
[ "Internal", "method", "to", "recalculate", "the", "extents", "and", "offsets", "associated", "with", "children", "of", "this", "directory", "record", "." ]
1e7b77a809e905d67dc71e12d70e850be26b6233
https://github.com/clalancette/pycdlib/blob/1e7b77a809e905d67dc71e12d70e850be26b6233/pycdlib/dr.py#L662-L694
train
clalancette/pycdlib
pycdlib/dr.py
DirectoryRecord._add_child
def _add_child(self, child, logical_block_size, allow_duplicate, check_overflow): # type: (DirectoryRecord, int, bool, bool) -> bool ''' An internal method to add a child to this object. Note that this is called both during parsing and when adding a new object to the system, so it it shouldn't have any functionality that is not appropriate for both. Parameters: child - The child directory record object to add. logical_block_size - The size of a logical block for this volume descriptor. allow_duplicate - Whether to allow duplicate names, as there are situations where duplicate children are allowed. check_overflow - Whether to check for overflow; if we are parsing, we don't want to do this. Returns: True if adding this child caused the directory to overflow into another extent, False otherwise. ''' if not self.isdir: raise pycdlibexception.PyCdlibInvalidInput('Trying to add a child to a record that is not a directory') # First ensure that this is not a duplicate. For speed purposes, we # recognize that bisect_left will always choose an index to the *left* # of a duplicate child. Thus, to check for duplicates we only need to # see if the child to be added is a duplicate with the entry that # bisect_left returned. index = bisect.bisect_left(self.children, child) if index != len(self.children) and self.children[index].file_ident == child.file_ident: if not self.children[index].is_associated_file() and not child.is_associated_file(): if not (self.rock_ridge is not None and self.file_identifier() == b'RR_MOVED'): if not allow_duplicate: raise pycdlibexception.PyCdlibInvalidInput('Failed adding duplicate name to parent') else: self.children[index].data_continuation = child index += 1 self.children.insert(index, child) if child.rock_ridge is not None and not child.is_dot() and not child.is_dotdot(): lo = 0 hi = len(self.rr_children) while lo < hi: mid = (lo + hi) // 2 rr = self.rr_children[mid].rock_ridge if rr is not None: if rr.name() < child.rock_ridge.name(): lo = mid + 1 else: hi = mid else: raise pycdlibexception.PyCdlibInternalError('Expected all children to have Rock Ridge, but one did not') rr_index = lo self.rr_children.insert(rr_index, child) # We now have to check if we need to add another logical block. # We have to iterate over the entire list again, because where we # placed this last entry may rearrange the empty spaces in the blocks # that we've already allocated. num_extents, offset_unused = self._recalculate_extents_and_offsets(index, logical_block_size) overflowed = False if check_overflow and (num_extents * logical_block_size > self.data_length): overflowed = True # When we overflow our data length, we always add a full block. self.data_length += logical_block_size # We also have to make sure to update the length of the dot child, # as that should always reflect the length. self.children[0].data_length = self.data_length # We also have to update all of the dotdot entries. If this is # the root directory record (no parent), we first update the root # dotdot entry. In all cases, we update the dotdot entry of all # children that are directories. if self.parent is None: self.children[1].data_length = self.data_length for c in self.children: if not c.is_dir(): continue if len(c.children) > 1: c.children[1].data_length = self.data_length return overflowed
python
def _add_child(self, child, logical_block_size, allow_duplicate, check_overflow): # type: (DirectoryRecord, int, bool, bool) -> bool ''' An internal method to add a child to this object. Note that this is called both during parsing and when adding a new object to the system, so it it shouldn't have any functionality that is not appropriate for both. Parameters: child - The child directory record object to add. logical_block_size - The size of a logical block for this volume descriptor. allow_duplicate - Whether to allow duplicate names, as there are situations where duplicate children are allowed. check_overflow - Whether to check for overflow; if we are parsing, we don't want to do this. Returns: True if adding this child caused the directory to overflow into another extent, False otherwise. ''' if not self.isdir: raise pycdlibexception.PyCdlibInvalidInput('Trying to add a child to a record that is not a directory') # First ensure that this is not a duplicate. For speed purposes, we # recognize that bisect_left will always choose an index to the *left* # of a duplicate child. Thus, to check for duplicates we only need to # see if the child to be added is a duplicate with the entry that # bisect_left returned. index = bisect.bisect_left(self.children, child) if index != len(self.children) and self.children[index].file_ident == child.file_ident: if not self.children[index].is_associated_file() and not child.is_associated_file(): if not (self.rock_ridge is not None and self.file_identifier() == b'RR_MOVED'): if not allow_duplicate: raise pycdlibexception.PyCdlibInvalidInput('Failed adding duplicate name to parent') else: self.children[index].data_continuation = child index += 1 self.children.insert(index, child) if child.rock_ridge is not None and not child.is_dot() and not child.is_dotdot(): lo = 0 hi = len(self.rr_children) while lo < hi: mid = (lo + hi) // 2 rr = self.rr_children[mid].rock_ridge if rr is not None: if rr.name() < child.rock_ridge.name(): lo = mid + 1 else: hi = mid else: raise pycdlibexception.PyCdlibInternalError('Expected all children to have Rock Ridge, but one did not') rr_index = lo self.rr_children.insert(rr_index, child) # We now have to check if we need to add another logical block. # We have to iterate over the entire list again, because where we # placed this last entry may rearrange the empty spaces in the blocks # that we've already allocated. num_extents, offset_unused = self._recalculate_extents_and_offsets(index, logical_block_size) overflowed = False if check_overflow and (num_extents * logical_block_size > self.data_length): overflowed = True # When we overflow our data length, we always add a full block. self.data_length += logical_block_size # We also have to make sure to update the length of the dot child, # as that should always reflect the length. self.children[0].data_length = self.data_length # We also have to update all of the dotdot entries. If this is # the root directory record (no parent), we first update the root # dotdot entry. In all cases, we update the dotdot entry of all # children that are directories. if self.parent is None: self.children[1].data_length = self.data_length for c in self.children: if not c.is_dir(): continue if len(c.children) > 1: c.children[1].data_length = self.data_length return overflowed
[ "def", "_add_child", "(", "self", ",", "child", ",", "logical_block_size", ",", "allow_duplicate", ",", "check_overflow", ")", ":", "# type: (DirectoryRecord, int, bool, bool) -> bool", "if", "not", "self", ".", "isdir", ":", "raise", "pycdlibexception", ".", "PyCdlibInvalidInput", "(", "'Trying to add a child to a record that is not a directory'", ")", "# First ensure that this is not a duplicate. For speed purposes, we", "# recognize that bisect_left will always choose an index to the *left*", "# of a duplicate child. Thus, to check for duplicates we only need to", "# see if the child to be added is a duplicate with the entry that", "# bisect_left returned.", "index", "=", "bisect", ".", "bisect_left", "(", "self", ".", "children", ",", "child", ")", "if", "index", "!=", "len", "(", "self", ".", "children", ")", "and", "self", ".", "children", "[", "index", "]", ".", "file_ident", "==", "child", ".", "file_ident", ":", "if", "not", "self", ".", "children", "[", "index", "]", ".", "is_associated_file", "(", ")", "and", "not", "child", ".", "is_associated_file", "(", ")", ":", "if", "not", "(", "self", ".", "rock_ridge", "is", "not", "None", "and", "self", ".", "file_identifier", "(", ")", "==", "b'RR_MOVED'", ")", ":", "if", "not", "allow_duplicate", ":", "raise", "pycdlibexception", ".", "PyCdlibInvalidInput", "(", "'Failed adding duplicate name to parent'", ")", "else", ":", "self", ".", "children", "[", "index", "]", ".", "data_continuation", "=", "child", "index", "+=", "1", "self", ".", "children", ".", "insert", "(", "index", ",", "child", ")", "if", "child", ".", "rock_ridge", "is", "not", "None", "and", "not", "child", ".", "is_dot", "(", ")", "and", "not", "child", ".", "is_dotdot", "(", ")", ":", "lo", "=", "0", "hi", "=", "len", "(", "self", ".", "rr_children", ")", "while", "lo", "<", "hi", ":", "mid", "=", "(", "lo", "+", "hi", ")", "//", "2", "rr", "=", "self", ".", "rr_children", "[", "mid", "]", ".", "rock_ridge", "if", "rr", "is", "not", "None", ":", "if", "rr", ".", "name", "(", ")", "<", "child", ".", "rock_ridge", ".", "name", "(", ")", ":", "lo", "=", "mid", "+", "1", "else", ":", "hi", "=", "mid", "else", ":", "raise", "pycdlibexception", ".", "PyCdlibInternalError", "(", "'Expected all children to have Rock Ridge, but one did not'", ")", "rr_index", "=", "lo", "self", ".", "rr_children", ".", "insert", "(", "rr_index", ",", "child", ")", "# We now have to check if we need to add another logical block.", "# We have to iterate over the entire list again, because where we", "# placed this last entry may rearrange the empty spaces in the blocks", "# that we've already allocated.", "num_extents", ",", "offset_unused", "=", "self", ".", "_recalculate_extents_and_offsets", "(", "index", ",", "logical_block_size", ")", "overflowed", "=", "False", "if", "check_overflow", "and", "(", "num_extents", "*", "logical_block_size", ">", "self", ".", "data_length", ")", ":", "overflowed", "=", "True", "# When we overflow our data length, we always add a full block.", "self", ".", "data_length", "+=", "logical_block_size", "# We also have to make sure to update the length of the dot child,", "# as that should always reflect the length.", "self", ".", "children", "[", "0", "]", ".", "data_length", "=", "self", ".", "data_length", "# We also have to update all of the dotdot entries. If this is", "# the root directory record (no parent), we first update the root", "# dotdot entry. In all cases, we update the dotdot entry of all", "# children that are directories.", "if", "self", ".", "parent", "is", "None", ":", "self", ".", "children", "[", "1", "]", ".", "data_length", "=", "self", ".", "data_length", "for", "c", "in", "self", ".", "children", ":", "if", "not", "c", ".", "is_dir", "(", ")", ":", "continue", "if", "len", "(", "c", ".", "children", ")", ">", "1", ":", "c", ".", "children", "[", "1", "]", ".", "data_length", "=", "self", ".", "data_length", "return", "overflowed" ]
An internal method to add a child to this object. Note that this is called both during parsing and when adding a new object to the system, so it it shouldn't have any functionality that is not appropriate for both. Parameters: child - The child directory record object to add. logical_block_size - The size of a logical block for this volume descriptor. allow_duplicate - Whether to allow duplicate names, as there are situations where duplicate children are allowed. check_overflow - Whether to check for overflow; if we are parsing, we don't want to do this. Returns: True if adding this child caused the directory to overflow into another extent, False otherwise.
[ "An", "internal", "method", "to", "add", "a", "child", "to", "this", "object", ".", "Note", "that", "this", "is", "called", "both", "during", "parsing", "and", "when", "adding", "a", "new", "object", "to", "the", "system", "so", "it", "it", "shouldn", "t", "have", "any", "functionality", "that", "is", "not", "appropriate", "for", "both", "." ]
1e7b77a809e905d67dc71e12d70e850be26b6233
https://github.com/clalancette/pycdlib/blob/1e7b77a809e905d67dc71e12d70e850be26b6233/pycdlib/dr.py#L696-L776
train
clalancette/pycdlib
pycdlib/dr.py
DirectoryRecord.add_child
def add_child(self, child, logical_block_size, allow_duplicate=False): # type: (DirectoryRecord, int, bool) -> bool ''' A method to add a new child to this directory record. Parameters: child - The child directory record object to add. logical_block_size - The size of a logical block for this volume descriptor. allow_duplicate - Whether to allow duplicate names, as there are situations where duplicate children are allowed. Returns: True if adding this child caused the directory to overflow into another extent, False otherwise. ''' if not self._initialized: raise pycdlibexception.PyCdlibInternalError('Directory Record not yet initialized') return self._add_child(child, logical_block_size, allow_duplicate, True)
python
def add_child(self, child, logical_block_size, allow_duplicate=False): # type: (DirectoryRecord, int, bool) -> bool ''' A method to add a new child to this directory record. Parameters: child - The child directory record object to add. logical_block_size - The size of a logical block for this volume descriptor. allow_duplicate - Whether to allow duplicate names, as there are situations where duplicate children are allowed. Returns: True if adding this child caused the directory to overflow into another extent, False otherwise. ''' if not self._initialized: raise pycdlibexception.PyCdlibInternalError('Directory Record not yet initialized') return self._add_child(child, logical_block_size, allow_duplicate, True)
[ "def", "add_child", "(", "self", ",", "child", ",", "logical_block_size", ",", "allow_duplicate", "=", "False", ")", ":", "# type: (DirectoryRecord, int, bool) -> bool", "if", "not", "self", ".", "_initialized", ":", "raise", "pycdlibexception", ".", "PyCdlibInternalError", "(", "'Directory Record not yet initialized'", ")", "return", "self", ".", "_add_child", "(", "child", ",", "logical_block_size", ",", "allow_duplicate", ",", "True", ")" ]
A method to add a new child to this directory record. Parameters: child - The child directory record object to add. logical_block_size - The size of a logical block for this volume descriptor. allow_duplicate - Whether to allow duplicate names, as there are situations where duplicate children are allowed. Returns: True if adding this child caused the directory to overflow into another extent, False otherwise.
[ "A", "method", "to", "add", "a", "new", "child", "to", "this", "directory", "record", "." ]
1e7b77a809e905d67dc71e12d70e850be26b6233
https://github.com/clalancette/pycdlib/blob/1e7b77a809e905d67dc71e12d70e850be26b6233/pycdlib/dr.py#L778-L795
train
clalancette/pycdlib
pycdlib/dr.py
DirectoryRecord.track_child
def track_child(self, child, logical_block_size, allow_duplicate=False): # type: (DirectoryRecord, int, bool) -> None ''' A method to track an existing child of this directory record. Parameters: child - The child directory record object to add. logical_block_size - The size of a logical block for this volume descriptor. allow_duplicate - Whether to allow duplicate names, as there are situations where duplicate children are allowed. Returns: Nothing. ''' if not self._initialized: raise pycdlibexception.PyCdlibInternalError('Directory Record not yet initialized') self._add_child(child, logical_block_size, allow_duplicate, False)
python
def track_child(self, child, logical_block_size, allow_duplicate=False): # type: (DirectoryRecord, int, bool) -> None ''' A method to track an existing child of this directory record. Parameters: child - The child directory record object to add. logical_block_size - The size of a logical block for this volume descriptor. allow_duplicate - Whether to allow duplicate names, as there are situations where duplicate children are allowed. Returns: Nothing. ''' if not self._initialized: raise pycdlibexception.PyCdlibInternalError('Directory Record not yet initialized') self._add_child(child, logical_block_size, allow_duplicate, False)
[ "def", "track_child", "(", "self", ",", "child", ",", "logical_block_size", ",", "allow_duplicate", "=", "False", ")", ":", "# type: (DirectoryRecord, int, bool) -> None", "if", "not", "self", ".", "_initialized", ":", "raise", "pycdlibexception", ".", "PyCdlibInternalError", "(", "'Directory Record not yet initialized'", ")", "self", ".", "_add_child", "(", "child", ",", "logical_block_size", ",", "allow_duplicate", ",", "False", ")" ]
A method to track an existing child of this directory record. Parameters: child - The child directory record object to add. logical_block_size - The size of a logical block for this volume descriptor. allow_duplicate - Whether to allow duplicate names, as there are situations where duplicate children are allowed. Returns: Nothing.
[ "A", "method", "to", "track", "an", "existing", "child", "of", "this", "directory", "record", "." ]
1e7b77a809e905d67dc71e12d70e850be26b6233
https://github.com/clalancette/pycdlib/blob/1e7b77a809e905d67dc71e12d70e850be26b6233/pycdlib/dr.py#L797-L813
train
clalancette/pycdlib
pycdlib/dr.py
DirectoryRecord.remove_child
def remove_child(self, child, index, logical_block_size): # type: (DirectoryRecord, int, int) -> bool ''' A method to remove a child from this Directory Record. Parameters: child - The child DirectoryRecord object to remove. index - The index of the child into this DirectoryRecord children list. logical_block_size - The size of a logical block on this volume descriptor. Returns: True if removing this child caused an underflow, False otherwise. ''' if not self._initialized: raise pycdlibexception.PyCdlibInternalError('Directory Record not yet initialized') if index < 0: # This should never happen raise pycdlibexception.PyCdlibInternalError('Invalid child index to remove') # Unfortunately, Rock Ridge specifies that a CL 'directory' is replaced # by a *file*, not another directory. Thus, we can't just depend on # whether this child is marked as a directory by the file flags during # parse time. Instead, we check if this is either a true directory, # or a Rock Ridge CL entry, and in either case try to manipulate the # file links. if child.rock_ridge is not None: if child.isdir or child.rock_ridge.child_link_record_exists(): if len(self.children) < 2: raise pycdlibexception.PyCdlibInvalidISO('Expected a dot and dotdot entry, but missing; ISO is corrupt') if self.children[0].rock_ridge is None or self.children[1].rock_ridge is None: raise pycdlibexception.PyCdlibInvalidISO('Missing Rock Ridge entry on dot or dotdot; ISO is corrupt') if self.parent is None: self.children[0].rock_ridge.remove_from_file_links() self.children[1].rock_ridge.remove_from_file_links() else: if self.rock_ridge is None: raise pycdlibexception.PyCdlibInvalidISO('Child has Rock Ridge, but parent does not; ISO is corrupt') self.rock_ridge.remove_from_file_links() self.children[0].rock_ridge.remove_from_file_links() del self.children[index] # We now have to check if we need to remove a logical block. # We have to iterate over the entire list again, because where we # removed this last entry may rearrange the empty spaces in the blocks # that we've already allocated. num_extents, dirrecord_offset = self._recalculate_extents_and_offsets(index, logical_block_size) underflow = False total_size = (num_extents - 1) * logical_block_size + dirrecord_offset if (self.data_length - total_size) > logical_block_size: self.data_length -= logical_block_size # We also have to make sure to update the length of the dot child, # as that should always reflect the length. self.children[0].data_length = self.data_length # We also have to update all of the dotdot entries. If this is # the root directory record (no parent), we first update the root # dotdot entry. In all cases, we update the dotdot entry of all # children that are directories. if self.parent is None: self.children[1].data_length = self.data_length for c in self.children: if not c.is_dir(): continue if len(c.children) > 1: c.children[1].data_length = self.data_length underflow = True return underflow
python
def remove_child(self, child, index, logical_block_size): # type: (DirectoryRecord, int, int) -> bool ''' A method to remove a child from this Directory Record. Parameters: child - The child DirectoryRecord object to remove. index - The index of the child into this DirectoryRecord children list. logical_block_size - The size of a logical block on this volume descriptor. Returns: True if removing this child caused an underflow, False otherwise. ''' if not self._initialized: raise pycdlibexception.PyCdlibInternalError('Directory Record not yet initialized') if index < 0: # This should never happen raise pycdlibexception.PyCdlibInternalError('Invalid child index to remove') # Unfortunately, Rock Ridge specifies that a CL 'directory' is replaced # by a *file*, not another directory. Thus, we can't just depend on # whether this child is marked as a directory by the file flags during # parse time. Instead, we check if this is either a true directory, # or a Rock Ridge CL entry, and in either case try to manipulate the # file links. if child.rock_ridge is not None: if child.isdir or child.rock_ridge.child_link_record_exists(): if len(self.children) < 2: raise pycdlibexception.PyCdlibInvalidISO('Expected a dot and dotdot entry, but missing; ISO is corrupt') if self.children[0].rock_ridge is None or self.children[1].rock_ridge is None: raise pycdlibexception.PyCdlibInvalidISO('Missing Rock Ridge entry on dot or dotdot; ISO is corrupt') if self.parent is None: self.children[0].rock_ridge.remove_from_file_links() self.children[1].rock_ridge.remove_from_file_links() else: if self.rock_ridge is None: raise pycdlibexception.PyCdlibInvalidISO('Child has Rock Ridge, but parent does not; ISO is corrupt') self.rock_ridge.remove_from_file_links() self.children[0].rock_ridge.remove_from_file_links() del self.children[index] # We now have to check if we need to remove a logical block. # We have to iterate over the entire list again, because where we # removed this last entry may rearrange the empty spaces in the blocks # that we've already allocated. num_extents, dirrecord_offset = self._recalculate_extents_and_offsets(index, logical_block_size) underflow = False total_size = (num_extents - 1) * logical_block_size + dirrecord_offset if (self.data_length - total_size) > logical_block_size: self.data_length -= logical_block_size # We also have to make sure to update the length of the dot child, # as that should always reflect the length. self.children[0].data_length = self.data_length # We also have to update all of the dotdot entries. If this is # the root directory record (no parent), we first update the root # dotdot entry. In all cases, we update the dotdot entry of all # children that are directories. if self.parent is None: self.children[1].data_length = self.data_length for c in self.children: if not c.is_dir(): continue if len(c.children) > 1: c.children[1].data_length = self.data_length underflow = True return underflow
[ "def", "remove_child", "(", "self", ",", "child", ",", "index", ",", "logical_block_size", ")", ":", "# type: (DirectoryRecord, int, int) -> bool", "if", "not", "self", ".", "_initialized", ":", "raise", "pycdlibexception", ".", "PyCdlibInternalError", "(", "'Directory Record not yet initialized'", ")", "if", "index", "<", "0", ":", "# This should never happen", "raise", "pycdlibexception", ".", "PyCdlibInternalError", "(", "'Invalid child index to remove'", ")", "# Unfortunately, Rock Ridge specifies that a CL 'directory' is replaced", "# by a *file*, not another directory. Thus, we can't just depend on", "# whether this child is marked as a directory by the file flags during", "# parse time. Instead, we check if this is either a true directory,", "# or a Rock Ridge CL entry, and in either case try to manipulate the", "# file links.", "if", "child", ".", "rock_ridge", "is", "not", "None", ":", "if", "child", ".", "isdir", "or", "child", ".", "rock_ridge", ".", "child_link_record_exists", "(", ")", ":", "if", "len", "(", "self", ".", "children", ")", "<", "2", ":", "raise", "pycdlibexception", ".", "PyCdlibInvalidISO", "(", "'Expected a dot and dotdot entry, but missing; ISO is corrupt'", ")", "if", "self", ".", "children", "[", "0", "]", ".", "rock_ridge", "is", "None", "or", "self", ".", "children", "[", "1", "]", ".", "rock_ridge", "is", "None", ":", "raise", "pycdlibexception", ".", "PyCdlibInvalidISO", "(", "'Missing Rock Ridge entry on dot or dotdot; ISO is corrupt'", ")", "if", "self", ".", "parent", "is", "None", ":", "self", ".", "children", "[", "0", "]", ".", "rock_ridge", ".", "remove_from_file_links", "(", ")", "self", ".", "children", "[", "1", "]", ".", "rock_ridge", ".", "remove_from_file_links", "(", ")", "else", ":", "if", "self", ".", "rock_ridge", "is", "None", ":", "raise", "pycdlibexception", ".", "PyCdlibInvalidISO", "(", "'Child has Rock Ridge, but parent does not; ISO is corrupt'", ")", "self", ".", "rock_ridge", ".", "remove_from_file_links", "(", ")", "self", ".", "children", "[", "0", "]", ".", "rock_ridge", ".", "remove_from_file_links", "(", ")", "del", "self", ".", "children", "[", "index", "]", "# We now have to check if we need to remove a logical block.", "# We have to iterate over the entire list again, because where we", "# removed this last entry may rearrange the empty spaces in the blocks", "# that we've already allocated.", "num_extents", ",", "dirrecord_offset", "=", "self", ".", "_recalculate_extents_and_offsets", "(", "index", ",", "logical_block_size", ")", "underflow", "=", "False", "total_size", "=", "(", "num_extents", "-", "1", ")", "*", "logical_block_size", "+", "dirrecord_offset", "if", "(", "self", ".", "data_length", "-", "total_size", ")", ">", "logical_block_size", ":", "self", ".", "data_length", "-=", "logical_block_size", "# We also have to make sure to update the length of the dot child,", "# as that should always reflect the length.", "self", ".", "children", "[", "0", "]", ".", "data_length", "=", "self", ".", "data_length", "# We also have to update all of the dotdot entries. If this is", "# the root directory record (no parent), we first update the root", "# dotdot entry. In all cases, we update the dotdot entry of all", "# children that are directories.", "if", "self", ".", "parent", "is", "None", ":", "self", ".", "children", "[", "1", "]", ".", "data_length", "=", "self", ".", "data_length", "for", "c", "in", "self", ".", "children", ":", "if", "not", "c", ".", "is_dir", "(", ")", ":", "continue", "if", "len", "(", "c", ".", "children", ")", ">", "1", ":", "c", ".", "children", "[", "1", "]", ".", "data_length", "=", "self", ".", "data_length", "underflow", "=", "True", "return", "underflow" ]
A method to remove a child from this Directory Record. Parameters: child - The child DirectoryRecord object to remove. index - The index of the child into this DirectoryRecord children list. logical_block_size - The size of a logical block on this volume descriptor. Returns: True if removing this child caused an underflow, False otherwise.
[ "A", "method", "to", "remove", "a", "child", "from", "this", "Directory", "Record", "." ]
1e7b77a809e905d67dc71e12d70e850be26b6233
https://github.com/clalancette/pycdlib/blob/1e7b77a809e905d67dc71e12d70e850be26b6233/pycdlib/dr.py#L815-L887
train
clalancette/pycdlib
pycdlib/dr.py
DirectoryRecord.record
def record(self): # type: () -> bytes ''' A method to generate the string representing this Directory Record. Parameters: None. Returns: String representing this Directory Record. ''' if not self._initialized: raise pycdlibexception.PyCdlibInternalError('Directory Record not yet initialized') # Ecma-119 9.1.5 says the date should reflect the time when the # record was written, so we make a new date now and use that to # write out the record. self.date = dates.DirectoryRecordDate() self.date.new() padlen = struct.calcsize(self.FMT) + self.len_fi padstr = b'\x00' * (padlen % 2) extent_loc = self._extent_location() xa_rec = b'' if self.xa_record is not None: xa_rec = b'\x00' * self.xa_pad_size + self.xa_record.record() rr_rec = b'' if self.rock_ridge is not None: rr_rec = self.rock_ridge.record_dr_entries() outlist = [struct.pack(self.FMT, self.dr_len, self.xattr_len, extent_loc, utils.swab_32bit(extent_loc), self.data_length, utils.swab_32bit(self.data_length), self.date.record(), self.file_flags, self.file_unit_size, self.interleave_gap_size, self.seqnum, utils.swab_16bit(self.seqnum), self.len_fi) + self.file_ident + padstr + xa_rec + rr_rec] outlist.append(b'\x00' * (len(outlist[0]) % 2)) return b''.join(outlist)
python
def record(self): # type: () -> bytes ''' A method to generate the string representing this Directory Record. Parameters: None. Returns: String representing this Directory Record. ''' if not self._initialized: raise pycdlibexception.PyCdlibInternalError('Directory Record not yet initialized') # Ecma-119 9.1.5 says the date should reflect the time when the # record was written, so we make a new date now and use that to # write out the record. self.date = dates.DirectoryRecordDate() self.date.new() padlen = struct.calcsize(self.FMT) + self.len_fi padstr = b'\x00' * (padlen % 2) extent_loc = self._extent_location() xa_rec = b'' if self.xa_record is not None: xa_rec = b'\x00' * self.xa_pad_size + self.xa_record.record() rr_rec = b'' if self.rock_ridge is not None: rr_rec = self.rock_ridge.record_dr_entries() outlist = [struct.pack(self.FMT, self.dr_len, self.xattr_len, extent_loc, utils.swab_32bit(extent_loc), self.data_length, utils.swab_32bit(self.data_length), self.date.record(), self.file_flags, self.file_unit_size, self.interleave_gap_size, self.seqnum, utils.swab_16bit(self.seqnum), self.len_fi) + self.file_ident + padstr + xa_rec + rr_rec] outlist.append(b'\x00' * (len(outlist[0]) % 2)) return b''.join(outlist)
[ "def", "record", "(", "self", ")", ":", "# type: () -> bytes", "if", "not", "self", ".", "_initialized", ":", "raise", "pycdlibexception", ".", "PyCdlibInternalError", "(", "'Directory Record not yet initialized'", ")", "# Ecma-119 9.1.5 says the date should reflect the time when the", "# record was written, so we make a new date now and use that to", "# write out the record.", "self", ".", "date", "=", "dates", ".", "DirectoryRecordDate", "(", ")", "self", ".", "date", ".", "new", "(", ")", "padlen", "=", "struct", ".", "calcsize", "(", "self", ".", "FMT", ")", "+", "self", ".", "len_fi", "padstr", "=", "b'\\x00'", "*", "(", "padlen", "%", "2", ")", "extent_loc", "=", "self", ".", "_extent_location", "(", ")", "xa_rec", "=", "b''", "if", "self", ".", "xa_record", "is", "not", "None", ":", "xa_rec", "=", "b'\\x00'", "*", "self", ".", "xa_pad_size", "+", "self", ".", "xa_record", ".", "record", "(", ")", "rr_rec", "=", "b''", "if", "self", ".", "rock_ridge", "is", "not", "None", ":", "rr_rec", "=", "self", ".", "rock_ridge", ".", "record_dr_entries", "(", ")", "outlist", "=", "[", "struct", ".", "pack", "(", "self", ".", "FMT", ",", "self", ".", "dr_len", ",", "self", ".", "xattr_len", ",", "extent_loc", ",", "utils", ".", "swab_32bit", "(", "extent_loc", ")", ",", "self", ".", "data_length", ",", "utils", ".", "swab_32bit", "(", "self", ".", "data_length", ")", ",", "self", ".", "date", ".", "record", "(", ")", ",", "self", ".", "file_flags", ",", "self", ".", "file_unit_size", ",", "self", ".", "interleave_gap_size", ",", "self", ".", "seqnum", ",", "utils", ".", "swab_16bit", "(", "self", ".", "seqnum", ")", ",", "self", ".", "len_fi", ")", "+", "self", ".", "file_ident", "+", "padstr", "+", "xa_rec", "+", "rr_rec", "]", "outlist", ".", "append", "(", "b'\\x00'", "*", "(", "len", "(", "outlist", "[", "0", "]", ")", "%", "2", ")", ")", "return", "b''", ".", "join", "(", "outlist", ")" ]
A method to generate the string representing this Directory Record. Parameters: None. Returns: String representing this Directory Record.
[ "A", "method", "to", "generate", "the", "string", "representing", "this", "Directory", "Record", "." ]
1e7b77a809e905d67dc71e12d70e850be26b6233
https://github.com/clalancette/pycdlib/blob/1e7b77a809e905d67dc71e12d70e850be26b6233/pycdlib/dr.py#L1001-L1042
train
clalancette/pycdlib
pycdlib/dr.py
DirectoryRecord.is_associated_file
def is_associated_file(self): # type: () -> bool ''' A method to determine whether this file is 'associated' with another file on the ISO. Parameters: None. Returns: True if this file is associated with another file on the ISO, False otherwise. ''' if not self._initialized: raise pycdlibexception.PyCdlibInternalError('Directory Record not yet initialized') return self.file_flags & (1 << self.FILE_FLAG_ASSOCIATED_FILE_BIT)
python
def is_associated_file(self): # type: () -> bool ''' A method to determine whether this file is 'associated' with another file on the ISO. Parameters: None. Returns: True if this file is associated with another file on the ISO, False otherwise. ''' if not self._initialized: raise pycdlibexception.PyCdlibInternalError('Directory Record not yet initialized') return self.file_flags & (1 << self.FILE_FLAG_ASSOCIATED_FILE_BIT)
[ "def", "is_associated_file", "(", "self", ")", ":", "# type: () -> bool", "if", "not", "self", ".", "_initialized", ":", "raise", "pycdlibexception", ".", "PyCdlibInternalError", "(", "'Directory Record not yet initialized'", ")", "return", "self", ".", "file_flags", "&", "(", "1", "<<", "self", ".", "FILE_FLAG_ASSOCIATED_FILE_BIT", ")" ]
A method to determine whether this file is 'associated' with another file on the ISO. Parameters: None. Returns: True if this file is associated with another file on the ISO, False otherwise.
[ "A", "method", "to", "determine", "whether", "this", "file", "is", "associated", "with", "another", "file", "on", "the", "ISO", "." ]
1e7b77a809e905d67dc71e12d70e850be26b6233
https://github.com/clalancette/pycdlib/blob/1e7b77a809e905d67dc71e12d70e850be26b6233/pycdlib/dr.py#L1044-L1059
train
clalancette/pycdlib
pycdlib/dr.py
DirectoryRecord.set_ptr
def set_ptr(self, ptr): # type: (path_table_record.PathTableRecord) -> None ''' A method to set the Path Table Record associated with this Directory Record. Parameters: ptr - The path table record to associate with this Directory Record. Returns: Nothing. ''' if not self._initialized: raise pycdlibexception.PyCdlibInternalError('Directory Record not yet initialized') self.ptr = ptr
python
def set_ptr(self, ptr): # type: (path_table_record.PathTableRecord) -> None ''' A method to set the Path Table Record associated with this Directory Record. Parameters: ptr - The path table record to associate with this Directory Record. Returns: Nothing. ''' if not self._initialized: raise pycdlibexception.PyCdlibInternalError('Directory Record not yet initialized') self.ptr = ptr
[ "def", "set_ptr", "(", "self", ",", "ptr", ")", ":", "# type: (path_table_record.PathTableRecord) -> None", "if", "not", "self", ".", "_initialized", ":", "raise", "pycdlibexception", ".", "PyCdlibInternalError", "(", "'Directory Record not yet initialized'", ")", "self", ".", "ptr", "=", "ptr" ]
A method to set the Path Table Record associated with this Directory Record. Parameters: ptr - The path table record to associate with this Directory Record. Returns: Nothing.
[ "A", "method", "to", "set", "the", "Path", "Table", "Record", "associated", "with", "this", "Directory", "Record", "." ]
1e7b77a809e905d67dc71e12d70e850be26b6233
https://github.com/clalancette/pycdlib/blob/1e7b77a809e905d67dc71e12d70e850be26b6233/pycdlib/dr.py#L1061-L1075
train
clalancette/pycdlib
pycdlib/dr.py
DirectoryRecord.set_data_location
def set_data_location(self, current_extent, tag_location): # pylint: disable=unused-argument # type: (int, int) -> None ''' A method to set the new extent location that the data for this Directory Record should live at. Parameters: current_extent - The new extent. Returns: Nothing. ''' if not self._initialized: raise pycdlibexception.PyCdlibInternalError('Directory Record not yet initialized') self.new_extent_loc = current_extent if self.ptr is not None: self.ptr.update_extent_location(current_extent)
python
def set_data_location(self, current_extent, tag_location): # pylint: disable=unused-argument # type: (int, int) -> None ''' A method to set the new extent location that the data for this Directory Record should live at. Parameters: current_extent - The new extent. Returns: Nothing. ''' if not self._initialized: raise pycdlibexception.PyCdlibInternalError('Directory Record not yet initialized') self.new_extent_loc = current_extent if self.ptr is not None: self.ptr.update_extent_location(current_extent)
[ "def", "set_data_location", "(", "self", ",", "current_extent", ",", "tag_location", ")", ":", "# pylint: disable=unused-argument", "# type: (int, int) -> None", "if", "not", "self", ".", "_initialized", ":", "raise", "pycdlibexception", ".", "PyCdlibInternalError", "(", "'Directory Record not yet initialized'", ")", "self", ".", "new_extent_loc", "=", "current_extent", "if", "self", ".", "ptr", "is", "not", "None", ":", "self", ".", "ptr", ".", "update_extent_location", "(", "current_extent", ")" ]
A method to set the new extent location that the data for this Directory Record should live at. Parameters: current_extent - The new extent. Returns: Nothing.
[ "A", "method", "to", "set", "the", "new", "extent", "location", "that", "the", "data", "for", "this", "Directory", "Record", "should", "live", "at", "." ]
1e7b77a809e905d67dc71e12d70e850be26b6233
https://github.com/clalancette/pycdlib/blob/1e7b77a809e905d67dc71e12d70e850be26b6233/pycdlib/dr.py#L1077-L1093
train
clalancette/pycdlib
pycdlib/dr.py
DirectoryRecord.get_data_length
def get_data_length(self): # type: () -> int ''' A method to get the length of the data that this Directory Record points to. Parameters: None. Returns: The length of the data that this Directory Record points to. ''' if not self._initialized: raise pycdlibexception.PyCdlibInternalError('Directory Record not yet initialized') if self.inode is not None: return self.inode.get_data_length() return self.data_length
python
def get_data_length(self): # type: () -> int ''' A method to get the length of the data that this Directory Record points to. Parameters: None. Returns: The length of the data that this Directory Record points to. ''' if not self._initialized: raise pycdlibexception.PyCdlibInternalError('Directory Record not yet initialized') if self.inode is not None: return self.inode.get_data_length() return self.data_length
[ "def", "get_data_length", "(", "self", ")", ":", "# type: () -> int", "if", "not", "self", ".", "_initialized", ":", "raise", "pycdlibexception", ".", "PyCdlibInternalError", "(", "'Directory Record not yet initialized'", ")", "if", "self", ".", "inode", "is", "not", "None", ":", "return", "self", ".", "inode", ".", "get_data_length", "(", ")", "return", "self", ".", "data_length" ]
A method to get the length of the data that this Directory Record points to. Parameters: None. Returns: The length of the data that this Directory Record points to.
[ "A", "method", "to", "get", "the", "length", "of", "the", "data", "that", "this", "Directory", "Record", "points", "to", "." ]
1e7b77a809e905d67dc71e12d70e850be26b6233
https://github.com/clalancette/pycdlib/blob/1e7b77a809e905d67dc71e12d70e850be26b6233/pycdlib/dr.py#L1095-L1110
train
clalancette/pycdlib
pycdlib/dr.py
DirectoryRecord.set_data_length
def set_data_length(self, length): # type: (int) -> None ''' A method to set the length of the data that this Directory Record points to. Parameters: length - The new length for the data. Returns: The length of the data that this Directory Record points to. ''' if not self._initialized: raise pycdlibexception.PyCdlibInternalError('Directory Record not yet initialized') self.data_length = length
python
def set_data_length(self, length): # type: (int) -> None ''' A method to set the length of the data that this Directory Record points to. Parameters: length - The new length for the data. Returns: The length of the data that this Directory Record points to. ''' if not self._initialized: raise pycdlibexception.PyCdlibInternalError('Directory Record not yet initialized') self.data_length = length
[ "def", "set_data_length", "(", "self", ",", "length", ")", ":", "# type: (int) -> None", "if", "not", "self", ".", "_initialized", ":", "raise", "pycdlibexception", ".", "PyCdlibInternalError", "(", "'Directory Record not yet initialized'", ")", "self", ".", "data_length", "=", "length" ]
A method to set the length of the data that this Directory Record points to. Parameters: length - The new length for the data. Returns: The length of the data that this Directory Record points to.
[ "A", "method", "to", "set", "the", "length", "of", "the", "data", "that", "this", "Directory", "Record", "points", "to", "." ]
1e7b77a809e905d67dc71e12d70e850be26b6233
https://github.com/clalancette/pycdlib/blob/1e7b77a809e905d67dc71e12d70e850be26b6233/pycdlib/dr.py#L1112-L1125
train
clalancette/pycdlib
pycdlib/inode.py
Inode.new
def new(self, length, fp, manage_fp, offset): # type: (int, BinaryIO, bool, int) -> None ''' Initialize a new Inode. Parameters: None. Returns: Nothing. ''' if self._initialized: raise pycdlibexception.PyCdlibInternalError('Inode is already initialized') self.data_length = length self.data_fp = fp self.manage_fp = manage_fp self.fp_offset = offset self.original_data_location = self.DATA_IN_EXTERNAL_FP self._initialized = True
python
def new(self, length, fp, manage_fp, offset): # type: (int, BinaryIO, bool, int) -> None ''' Initialize a new Inode. Parameters: None. Returns: Nothing. ''' if self._initialized: raise pycdlibexception.PyCdlibInternalError('Inode is already initialized') self.data_length = length self.data_fp = fp self.manage_fp = manage_fp self.fp_offset = offset self.original_data_location = self.DATA_IN_EXTERNAL_FP self._initialized = True
[ "def", "new", "(", "self", ",", "length", ",", "fp", ",", "manage_fp", ",", "offset", ")", ":", "# type: (int, BinaryIO, bool, int) -> None", "if", "self", ".", "_initialized", ":", "raise", "pycdlibexception", ".", "PyCdlibInternalError", "(", "'Inode is already initialized'", ")", "self", ".", "data_length", "=", "length", "self", ".", "data_fp", "=", "fp", "self", ".", "manage_fp", "=", "manage_fp", "self", ".", "fp_offset", "=", "offset", "self", ".", "original_data_location", "=", "self", ".", "DATA_IN_EXTERNAL_FP", "self", ".", "_initialized", "=", "True" ]
Initialize a new Inode. Parameters: None. Returns: Nothing.
[ "Initialize", "a", "new", "Inode", "." ]
1e7b77a809e905d67dc71e12d70e850be26b6233
https://github.com/clalancette/pycdlib/blob/1e7b77a809e905d67dc71e12d70e850be26b6233/pycdlib/inode.py#L56-L76
train
clalancette/pycdlib
pycdlib/inode.py
Inode.parse
def parse(self, extent, length, fp, log_block_size): # type: (int, int, BinaryIO, int) -> None ''' Parse an existing Inode. This just saves off the extent for later use. Parameters: extent - The original extent that the data lives at. Returns: Nothing. ''' if self._initialized: raise pycdlibexception.PyCdlibInternalError('Inode is already initialized') self.orig_extent_loc = extent self.data_length = length self.data_fp = fp self.manage_fp = False self.fp_offset = extent * log_block_size self.original_data_location = self.DATA_ON_ORIGINAL_ISO self._initialized = True
python
def parse(self, extent, length, fp, log_block_size): # type: (int, int, BinaryIO, int) -> None ''' Parse an existing Inode. This just saves off the extent for later use. Parameters: extent - The original extent that the data lives at. Returns: Nothing. ''' if self._initialized: raise pycdlibexception.PyCdlibInternalError('Inode is already initialized') self.orig_extent_loc = extent self.data_length = length self.data_fp = fp self.manage_fp = False self.fp_offset = extent * log_block_size self.original_data_location = self.DATA_ON_ORIGINAL_ISO self._initialized = True
[ "def", "parse", "(", "self", ",", "extent", ",", "length", ",", "fp", ",", "log_block_size", ")", ":", "# type: (int, int, BinaryIO, int) -> None", "if", "self", ".", "_initialized", ":", "raise", "pycdlibexception", ".", "PyCdlibInternalError", "(", "'Inode is already initialized'", ")", "self", ".", "orig_extent_loc", "=", "extent", "self", ".", "data_length", "=", "length", "self", ".", "data_fp", "=", "fp", "self", ".", "manage_fp", "=", "False", "self", ".", "fp_offset", "=", "extent", "*", "log_block_size", "self", ".", "original_data_location", "=", "self", ".", "DATA_ON_ORIGINAL_ISO", "self", ".", "_initialized", "=", "True" ]
Parse an existing Inode. This just saves off the extent for later use. Parameters: extent - The original extent that the data lives at. Returns: Nothing.
[ "Parse", "an", "existing", "Inode", ".", "This", "just", "saves", "off", "the", "extent", "for", "later", "use", "." ]
1e7b77a809e905d67dc71e12d70e850be26b6233
https://github.com/clalancette/pycdlib/blob/1e7b77a809e905d67dc71e12d70e850be26b6233/pycdlib/inode.py#L78-L100
train
clalancette/pycdlib
pycdlib/inode.py
Inode.add_boot_info_table
def add_boot_info_table(self, boot_info_table): # type: (eltorito.EltoritoBootInfoTable) -> None ''' A method to add a boot info table to this Inode. Parameters: boot_info_table - The Boot Info Table object to add to this Inode. Returns: Nothing. ''' if not self._initialized: raise pycdlibexception.PyCdlibInternalError('Inode is not yet initialized') self.boot_info_table = boot_info_table
python
def add_boot_info_table(self, boot_info_table): # type: (eltorito.EltoritoBootInfoTable) -> None ''' A method to add a boot info table to this Inode. Parameters: boot_info_table - The Boot Info Table object to add to this Inode. Returns: Nothing. ''' if not self._initialized: raise pycdlibexception.PyCdlibInternalError('Inode is not yet initialized') self.boot_info_table = boot_info_table
[ "def", "add_boot_info_table", "(", "self", ",", "boot_info_table", ")", ":", "# type: (eltorito.EltoritoBootInfoTable) -> None", "if", "not", "self", ".", "_initialized", ":", "raise", "pycdlibexception", ".", "PyCdlibInternalError", "(", "'Inode is not yet initialized'", ")", "self", ".", "boot_info_table", "=", "boot_info_table" ]
A method to add a boot info table to this Inode. Parameters: boot_info_table - The Boot Info Table object to add to this Inode. Returns: Nothing.
[ "A", "method", "to", "add", "a", "boot", "info", "table", "to", "this", "Inode", "." ]
1e7b77a809e905d67dc71e12d70e850be26b6233
https://github.com/clalancette/pycdlib/blob/1e7b77a809e905d67dc71e12d70e850be26b6233/pycdlib/inode.py#L149-L162
train
clalancette/pycdlib
pycdlib/inode.py
Inode.update_fp
def update_fp(self, fp, length): # type: (BinaryIO, int) -> None ''' Update the Inode to use a different file object and length. Parameters: fp - A file object that contains the data for this Inode. length - The length of the data. Returns: Nothing. ''' if not self._initialized: raise pycdlibexception.PyCdlibInternalError('Inode is not yet initialized') self.original_data_location = self.DATA_IN_EXTERNAL_FP self.data_fp = fp self.data_length = length self.fp_offset = 0
python
def update_fp(self, fp, length): # type: (BinaryIO, int) -> None ''' Update the Inode to use a different file object and length. Parameters: fp - A file object that contains the data for this Inode. length - The length of the data. Returns: Nothing. ''' if not self._initialized: raise pycdlibexception.PyCdlibInternalError('Inode is not yet initialized') self.original_data_location = self.DATA_IN_EXTERNAL_FP self.data_fp = fp self.data_length = length self.fp_offset = 0
[ "def", "update_fp", "(", "self", ",", "fp", ",", "length", ")", ":", "# type: (BinaryIO, int) -> None", "if", "not", "self", ".", "_initialized", ":", "raise", "pycdlibexception", ".", "PyCdlibInternalError", "(", "'Inode is not yet initialized'", ")", "self", ".", "original_data_location", "=", "self", ".", "DATA_IN_EXTERNAL_FP", "self", ".", "data_fp", "=", "fp", "self", ".", "data_length", "=", "length", "self", ".", "fp_offset", "=", "0" ]
Update the Inode to use a different file object and length. Parameters: fp - A file object that contains the data for this Inode. length - The length of the data. Returns: Nothing.
[ "Update", "the", "Inode", "to", "use", "a", "different", "file", "object", "and", "length", "." ]
1e7b77a809e905d67dc71e12d70e850be26b6233
https://github.com/clalancette/pycdlib/blob/1e7b77a809e905d67dc71e12d70e850be26b6233/pycdlib/inode.py#L164-L181
train
clalancette/pycdlib
pycdlib/dates.py
string_to_timestruct
def string_to_timestruct(input_string): # type: (bytes) -> time.struct_time ''' A cacheable function to take an input string and decode it into a time.struct_time from the time module. If the string cannot be decoded because of an illegal value, then the all-zero time.struct_time will be returned instead. Parameters: input_string - The string to attempt to parse. Returns: A time.struct_time object representing the time. ''' try: timestruct = time.strptime(input_string.decode('utf-8'), VolumeDescriptorDate.TIME_FMT) except ValueError: # Ecma-119, 8.4.26.1 specifies that if the string was all the digit # zero, with the last byte 0, the time wasn't specified. In that # case, time.strptime() with our format will raise a ValueError. # In practice we have found that some ISOs specify various wacky # things in this field, so if we see *any* ValueError, we just # assume the date is unspecified and go with that. timestruct = time.struct_time((0, 0, 0, 0, 0, 0, 0, 0, 0)) return timestruct
python
def string_to_timestruct(input_string): # type: (bytes) -> time.struct_time ''' A cacheable function to take an input string and decode it into a time.struct_time from the time module. If the string cannot be decoded because of an illegal value, then the all-zero time.struct_time will be returned instead. Parameters: input_string - The string to attempt to parse. Returns: A time.struct_time object representing the time. ''' try: timestruct = time.strptime(input_string.decode('utf-8'), VolumeDescriptorDate.TIME_FMT) except ValueError: # Ecma-119, 8.4.26.1 specifies that if the string was all the digit # zero, with the last byte 0, the time wasn't specified. In that # case, time.strptime() with our format will raise a ValueError. # In practice we have found that some ISOs specify various wacky # things in this field, so if we see *any* ValueError, we just # assume the date is unspecified and go with that. timestruct = time.struct_time((0, 0, 0, 0, 0, 0, 0, 0, 0)) return timestruct
[ "def", "string_to_timestruct", "(", "input_string", ")", ":", "# type: (bytes) -> time.struct_time", "try", ":", "timestruct", "=", "time", ".", "strptime", "(", "input_string", ".", "decode", "(", "'utf-8'", ")", ",", "VolumeDescriptorDate", ".", "TIME_FMT", ")", "except", "ValueError", ":", "# Ecma-119, 8.4.26.1 specifies that if the string was all the digit", "# zero, with the last byte 0, the time wasn't specified. In that", "# case, time.strptime() with our format will raise a ValueError.", "# In practice we have found that some ISOs specify various wacky", "# things in this field, so if we see *any* ValueError, we just", "# assume the date is unspecified and go with that.", "timestruct", "=", "time", ".", "struct_time", "(", "(", "0", ",", "0", ",", "0", ",", "0", ",", "0", ",", "0", ",", "0", ",", "0", ",", "0", ")", ")", "return", "timestruct" ]
A cacheable function to take an input string and decode it into a time.struct_time from the time module. If the string cannot be decoded because of an illegal value, then the all-zero time.struct_time will be returned instead. Parameters: input_string - The string to attempt to parse. Returns: A time.struct_time object representing the time.
[ "A", "cacheable", "function", "to", "take", "an", "input", "string", "and", "decode", "it", "into", "a", "time", ".", "struct_time", "from", "the", "time", "module", ".", "If", "the", "string", "cannot", "be", "decoded", "because", "of", "an", "illegal", "value", "then", "the", "all", "-", "zero", "time", ".", "struct_time", "will", "be", "returned", "instead", "." ]
1e7b77a809e905d67dc71e12d70e850be26b6233
https://github.com/clalancette/pycdlib/blob/1e7b77a809e905d67dc71e12d70e850be26b6233/pycdlib/dates.py#L35-L59
train
clalancette/pycdlib
pycdlib/dates.py
DirectoryRecordDate.parse
def parse(self, datestr): # type: (bytes) -> None ''' Parse a Directory Record date out of a string. Parameters: datestr - The string to parse the date out of. Returns: Nothing. ''' if self._initialized: raise pycdlibexception.PyCdlibInternalError('Directory Record Date already initialized') (self.years_since_1900, self.month, self.day_of_month, self.hour, self.minute, self.second, self.gmtoffset) = struct.unpack_from(self.FMT, datestr, 0) self._initialized = True
python
def parse(self, datestr): # type: (bytes) -> None ''' Parse a Directory Record date out of a string. Parameters: datestr - The string to parse the date out of. Returns: Nothing. ''' if self._initialized: raise pycdlibexception.PyCdlibInternalError('Directory Record Date already initialized') (self.years_since_1900, self.month, self.day_of_month, self.hour, self.minute, self.second, self.gmtoffset) = struct.unpack_from(self.FMT, datestr, 0) self._initialized = True
[ "def", "parse", "(", "self", ",", "datestr", ")", ":", "# type: (bytes) -> None", "if", "self", ".", "_initialized", ":", "raise", "pycdlibexception", ".", "PyCdlibInternalError", "(", "'Directory Record Date already initialized'", ")", "(", "self", ".", "years_since_1900", ",", "self", ".", "month", ",", "self", ".", "day_of_month", ",", "self", ".", "hour", ",", "self", ".", "minute", ",", "self", ".", "second", ",", "self", ".", "gmtoffset", ")", "=", "struct", ".", "unpack_from", "(", "self", ".", "FMT", ",", "datestr", ",", "0", ")", "self", ".", "_initialized", "=", "True" ]
Parse a Directory Record date out of a string. Parameters: datestr - The string to parse the date out of. Returns: Nothing.
[ "Parse", "a", "Directory", "Record", "date", "out", "of", "a", "string", "." ]
1e7b77a809e905d67dc71e12d70e850be26b6233
https://github.com/clalancette/pycdlib/blob/1e7b77a809e905d67dc71e12d70e850be26b6233/pycdlib/dates.py#L81-L98
train
clalancette/pycdlib
pycdlib/dates.py
DirectoryRecordDate.new
def new(self): # type: () -> None ''' Create a new Directory Record date based on the current time. Parameters: tm - An optional argument that must be None Returns: Nothing. ''' if self._initialized: raise pycdlibexception.PyCdlibInternalError('Directory Record Date already initialized') # This algorithm was ported from cdrkit, genisoimage.c:iso9660_date() tm = time.time() local = time.localtime(tm) self.years_since_1900 = local.tm_year - 1900 self.month = local.tm_mon self.day_of_month = local.tm_mday self.hour = local.tm_hour self.minute = local.tm_min self.second = local.tm_sec self.gmtoffset = utils.gmtoffset_from_tm(tm, local) self._initialized = True
python
def new(self): # type: () -> None ''' Create a new Directory Record date based on the current time. Parameters: tm - An optional argument that must be None Returns: Nothing. ''' if self._initialized: raise pycdlibexception.PyCdlibInternalError('Directory Record Date already initialized') # This algorithm was ported from cdrkit, genisoimage.c:iso9660_date() tm = time.time() local = time.localtime(tm) self.years_since_1900 = local.tm_year - 1900 self.month = local.tm_mon self.day_of_month = local.tm_mday self.hour = local.tm_hour self.minute = local.tm_min self.second = local.tm_sec self.gmtoffset = utils.gmtoffset_from_tm(tm, local) self._initialized = True
[ "def", "new", "(", "self", ")", ":", "# type: () -> None", "if", "self", ".", "_initialized", ":", "raise", "pycdlibexception", ".", "PyCdlibInternalError", "(", "'Directory Record Date already initialized'", ")", "# This algorithm was ported from cdrkit, genisoimage.c:iso9660_date()", "tm", "=", "time", ".", "time", "(", ")", "local", "=", "time", ".", "localtime", "(", "tm", ")", "self", ".", "years_since_1900", "=", "local", ".", "tm_year", "-", "1900", "self", ".", "month", "=", "local", ".", "tm_mon", "self", ".", "day_of_month", "=", "local", ".", "tm_mday", "self", ".", "hour", "=", "local", ".", "tm_hour", "self", ".", "minute", "=", "local", ".", "tm_min", "self", ".", "second", "=", "local", ".", "tm_sec", "self", ".", "gmtoffset", "=", "utils", ".", "gmtoffset_from_tm", "(", "tm", ",", "local", ")", "self", ".", "_initialized", "=", "True" ]
Create a new Directory Record date based on the current time. Parameters: tm - An optional argument that must be None Returns: Nothing.
[ "Create", "a", "new", "Directory", "Record", "date", "based", "on", "the", "current", "time", "." ]
1e7b77a809e905d67dc71e12d70e850be26b6233
https://github.com/clalancette/pycdlib/blob/1e7b77a809e905d67dc71e12d70e850be26b6233/pycdlib/dates.py#L100-L123
train
clalancette/pycdlib
pycdlib/dates.py
DirectoryRecordDate.record
def record(self): # type: () -> bytes ''' Return a string representation of the Directory Record date. Parameters: None. Returns: A string representing this Directory Record Date. ''' if not self._initialized: raise pycdlibexception.PyCdlibInternalError('Directory Record Date not initialized') return struct.pack(self.FMT, self.years_since_1900, self.month, self.day_of_month, self.hour, self.minute, self.second, self.gmtoffset)
python
def record(self): # type: () -> bytes ''' Return a string representation of the Directory Record date. Parameters: None. Returns: A string representing this Directory Record Date. ''' if not self._initialized: raise pycdlibexception.PyCdlibInternalError('Directory Record Date not initialized') return struct.pack(self.FMT, self.years_since_1900, self.month, self.day_of_month, self.hour, self.minute, self.second, self.gmtoffset)
[ "def", "record", "(", "self", ")", ":", "# type: () -> bytes", "if", "not", "self", ".", "_initialized", ":", "raise", "pycdlibexception", ".", "PyCdlibInternalError", "(", "'Directory Record Date not initialized'", ")", "return", "struct", ".", "pack", "(", "self", ".", "FMT", ",", "self", ".", "years_since_1900", ",", "self", ".", "month", ",", "self", ".", "day_of_month", ",", "self", ".", "hour", ",", "self", ".", "minute", ",", "self", ".", "second", ",", "self", ".", "gmtoffset", ")" ]
Return a string representation of the Directory Record date. Parameters: None. Returns: A string representing this Directory Record Date.
[ "Return", "a", "string", "representation", "of", "the", "Directory", "Record", "date", "." ]
1e7b77a809e905d67dc71e12d70e850be26b6233
https://github.com/clalancette/pycdlib/blob/1e7b77a809e905d67dc71e12d70e850be26b6233/pycdlib/dates.py#L125-L140
train
clalancette/pycdlib
pycdlib/dates.py
VolumeDescriptorDate.parse
def parse(self, datestr): # type: (bytes) -> None ''' Parse a Volume Descriptor Date out of a string. A string of all zeros is valid, which means that the date in this field was not specified. Parameters: datestr - string to be parsed Returns: Nothing. ''' if self._initialized: raise pycdlibexception.PyCdlibInternalError('This Volume Descriptor Date object is already initialized') if len(datestr) != 17: raise pycdlibexception.PyCdlibInvalidISO('Invalid ISO9660 date string') timestruct = string_to_timestruct(datestr[:-3]) self.year = timestruct.tm_year self.month = timestruct.tm_mon self.dayofmonth = timestruct.tm_mday self.hour = timestruct.tm_hour self.minute = timestruct.tm_min self.second = timestruct.tm_sec if timestruct.tm_year == 0 and timestruct.tm_mon == 0 and timestruct.tm_mday == 0 and timestruct.tm_hour == 0 and timestruct.tm_min == 0 and timestruct.tm_sec == 0: self.hundredthsofsecond = 0 self.gmtoffset = 0 self.date_str = self.EMPTY_STRING else: self.hundredthsofsecond = int(datestr[14:15]) self.gmtoffset, = struct.unpack_from('=b', datestr, 16) self.date_str = datestr self._initialized = True
python
def parse(self, datestr): # type: (bytes) -> None ''' Parse a Volume Descriptor Date out of a string. A string of all zeros is valid, which means that the date in this field was not specified. Parameters: datestr - string to be parsed Returns: Nothing. ''' if self._initialized: raise pycdlibexception.PyCdlibInternalError('This Volume Descriptor Date object is already initialized') if len(datestr) != 17: raise pycdlibexception.PyCdlibInvalidISO('Invalid ISO9660 date string') timestruct = string_to_timestruct(datestr[:-3]) self.year = timestruct.tm_year self.month = timestruct.tm_mon self.dayofmonth = timestruct.tm_mday self.hour = timestruct.tm_hour self.minute = timestruct.tm_min self.second = timestruct.tm_sec if timestruct.tm_year == 0 and timestruct.tm_mon == 0 and timestruct.tm_mday == 0 and timestruct.tm_hour == 0 and timestruct.tm_min == 0 and timestruct.tm_sec == 0: self.hundredthsofsecond = 0 self.gmtoffset = 0 self.date_str = self.EMPTY_STRING else: self.hundredthsofsecond = int(datestr[14:15]) self.gmtoffset, = struct.unpack_from('=b', datestr, 16) self.date_str = datestr self._initialized = True
[ "def", "parse", "(", "self", ",", "datestr", ")", ":", "# type: (bytes) -> None", "if", "self", ".", "_initialized", ":", "raise", "pycdlibexception", ".", "PyCdlibInternalError", "(", "'This Volume Descriptor Date object is already initialized'", ")", "if", "len", "(", "datestr", ")", "!=", "17", ":", "raise", "pycdlibexception", ".", "PyCdlibInvalidISO", "(", "'Invalid ISO9660 date string'", ")", "timestruct", "=", "string_to_timestruct", "(", "datestr", "[", ":", "-", "3", "]", ")", "self", ".", "year", "=", "timestruct", ".", "tm_year", "self", ".", "month", "=", "timestruct", ".", "tm_mon", "self", ".", "dayofmonth", "=", "timestruct", ".", "tm_mday", "self", ".", "hour", "=", "timestruct", ".", "tm_hour", "self", ".", "minute", "=", "timestruct", ".", "tm_min", "self", ".", "second", "=", "timestruct", ".", "tm_sec", "if", "timestruct", ".", "tm_year", "==", "0", "and", "timestruct", ".", "tm_mon", "==", "0", "and", "timestruct", ".", "tm_mday", "==", "0", "and", "timestruct", ".", "tm_hour", "==", "0", "and", "timestruct", ".", "tm_min", "==", "0", "and", "timestruct", ".", "tm_sec", "==", "0", ":", "self", ".", "hundredthsofsecond", "=", "0", "self", ".", "gmtoffset", "=", "0", "self", ".", "date_str", "=", "self", ".", "EMPTY_STRING", "else", ":", "self", ".", "hundredthsofsecond", "=", "int", "(", "datestr", "[", "14", ":", "15", "]", ")", "self", ".", "gmtoffset", ",", "=", "struct", ".", "unpack_from", "(", "'=b'", ",", "datestr", ",", "16", ")", "self", ".", "date_str", "=", "datestr", "self", ".", "_initialized", "=", "True" ]
Parse a Volume Descriptor Date out of a string. A string of all zeros is valid, which means that the date in this field was not specified. Parameters: datestr - string to be parsed Returns: Nothing.
[ "Parse", "a", "Volume", "Descriptor", "Date", "out", "of", "a", "string", ".", "A", "string", "of", "all", "zeros", "is", "valid", "which", "means", "that", "the", "date", "in", "this", "field", "was", "not", "specified", "." ]
1e7b77a809e905d67dc71e12d70e850be26b6233
https://github.com/clalancette/pycdlib/blob/1e7b77a809e905d67dc71e12d70e850be26b6233/pycdlib/dates.py#L170-L203
train
clalancette/pycdlib
pycdlib/rockridge.py
RRSPRecord.parse
def parse(self, rrstr): # type: (bytes) -> None ''' Parse a Rock Ridge Sharing Protocol record out of a string. Parameters: rrstr - The string to parse the record out of. Returns: Nothing. ''' if self._initialized: raise pycdlibexception.PyCdlibInternalError('SP record already initialized!') (su_len, su_entry_version_unused, check_byte1, check_byte2, self.bytes_to_skip) = struct.unpack_from('=BBBBB', rrstr[:7], 2) # We assume that the caller has already checked the su_entry_version, # so we don't bother. if su_len != RRSPRecord.length(): raise pycdlibexception.PyCdlibInvalidISO('Invalid length on rock ridge extension') if check_byte1 != 0xbe or check_byte2 != 0xef: raise pycdlibexception.PyCdlibInvalidISO('Invalid check bytes on rock ridge extension') self._initialized = True
python
def parse(self, rrstr): # type: (bytes) -> None ''' Parse a Rock Ridge Sharing Protocol record out of a string. Parameters: rrstr - The string to parse the record out of. Returns: Nothing. ''' if self._initialized: raise pycdlibexception.PyCdlibInternalError('SP record already initialized!') (su_len, su_entry_version_unused, check_byte1, check_byte2, self.bytes_to_skip) = struct.unpack_from('=BBBBB', rrstr[:7], 2) # We assume that the caller has already checked the su_entry_version, # so we don't bother. if su_len != RRSPRecord.length(): raise pycdlibexception.PyCdlibInvalidISO('Invalid length on rock ridge extension') if check_byte1 != 0xbe or check_byte2 != 0xef: raise pycdlibexception.PyCdlibInvalidISO('Invalid check bytes on rock ridge extension') self._initialized = True
[ "def", "parse", "(", "self", ",", "rrstr", ")", ":", "# type: (bytes) -> None", "if", "self", ".", "_initialized", ":", "raise", "pycdlibexception", ".", "PyCdlibInternalError", "(", "'SP record already initialized!'", ")", "(", "su_len", ",", "su_entry_version_unused", ",", "check_byte1", ",", "check_byte2", ",", "self", ".", "bytes_to_skip", ")", "=", "struct", ".", "unpack_from", "(", "'=BBBBB'", ",", "rrstr", "[", ":", "7", "]", ",", "2", ")", "# We assume that the caller has already checked the su_entry_version,", "# so we don't bother.", "if", "su_len", "!=", "RRSPRecord", ".", "length", "(", ")", ":", "raise", "pycdlibexception", ".", "PyCdlibInvalidISO", "(", "'Invalid length on rock ridge extension'", ")", "if", "check_byte1", "!=", "0xbe", "or", "check_byte2", "!=", "0xef", ":", "raise", "pycdlibexception", ".", "PyCdlibInvalidISO", "(", "'Invalid check bytes on rock ridge extension'", ")", "self", ".", "_initialized", "=", "True" ]
Parse a Rock Ridge Sharing Protocol record out of a string. Parameters: rrstr - The string to parse the record out of. Returns: Nothing.
[ "Parse", "a", "Rock", "Ridge", "Sharing", "Protocol", "record", "out", "of", "a", "string", "." ]
1e7b77a809e905d67dc71e12d70e850be26b6233
https://github.com/clalancette/pycdlib/blob/1e7b77a809e905d67dc71e12d70e850be26b6233/pycdlib/rockridge.py#L59-L83
train
clalancette/pycdlib
pycdlib/rockridge.py
RRSPRecord.new
def new(self, bytes_to_skip): # type: (int) -> None ''' Create a new Rock Ridge Sharing Protocol record. Parameters: bytes_to_skip - The number of bytes to skip. Returns: Nothing. ''' if self._initialized: raise pycdlibexception.PyCdlibInternalError('SP record already initialized!') self.bytes_to_skip = bytes_to_skip self._initialized = True
python
def new(self, bytes_to_skip): # type: (int) -> None ''' Create a new Rock Ridge Sharing Protocol record. Parameters: bytes_to_skip - The number of bytes to skip. Returns: Nothing. ''' if self._initialized: raise pycdlibexception.PyCdlibInternalError('SP record already initialized!') self.bytes_to_skip = bytes_to_skip self._initialized = True
[ "def", "new", "(", "self", ",", "bytes_to_skip", ")", ":", "# type: (int) -> None", "if", "self", ".", "_initialized", ":", "raise", "pycdlibexception", ".", "PyCdlibInternalError", "(", "'SP record already initialized!'", ")", "self", ".", "bytes_to_skip", "=", "bytes_to_skip", "self", ".", "_initialized", "=", "True" ]
Create a new Rock Ridge Sharing Protocol record. Parameters: bytes_to_skip - The number of bytes to skip. Returns: Nothing.
[ "Create", "a", "new", "Rock", "Ridge", "Sharing", "Protocol", "record", "." ]
1e7b77a809e905d67dc71e12d70e850be26b6233
https://github.com/clalancette/pycdlib/blob/1e7b77a809e905d67dc71e12d70e850be26b6233/pycdlib/rockridge.py#L85-L99
train
clalancette/pycdlib
pycdlib/rockridge.py
RRSPRecord.record
def record(self): # type: () -> bytes ''' Generate a string representing the Rock Ridge Sharing Protocol record. Parameters: None. Returns: String containing the Rock Ridge record. ''' if not self._initialized: raise pycdlibexception.PyCdlibInternalError('SP record not yet initialized!') return b'SP' + struct.pack('=BBBBB', RRSPRecord.length(), SU_ENTRY_VERSION, 0xbe, 0xef, self.bytes_to_skip)
python
def record(self): # type: () -> bytes ''' Generate a string representing the Rock Ridge Sharing Protocol record. Parameters: None. Returns: String containing the Rock Ridge record. ''' if not self._initialized: raise pycdlibexception.PyCdlibInternalError('SP record not yet initialized!') return b'SP' + struct.pack('=BBBBB', RRSPRecord.length(), SU_ENTRY_VERSION, 0xbe, 0xef, self.bytes_to_skip)
[ "def", "record", "(", "self", ")", ":", "# type: () -> bytes", "if", "not", "self", ".", "_initialized", ":", "raise", "pycdlibexception", ".", "PyCdlibInternalError", "(", "'SP record not yet initialized!'", ")", "return", "b'SP'", "+", "struct", ".", "pack", "(", "'=BBBBB'", ",", "RRSPRecord", ".", "length", "(", ")", ",", "SU_ENTRY_VERSION", ",", "0xbe", ",", "0xef", ",", "self", ".", "bytes_to_skip", ")" ]
Generate a string representing the Rock Ridge Sharing Protocol record. Parameters: None. Returns: String containing the Rock Ridge record.
[ "Generate", "a", "string", "representing", "the", "Rock", "Ridge", "Sharing", "Protocol", "record", "." ]
1e7b77a809e905d67dc71e12d70e850be26b6233
https://github.com/clalancette/pycdlib/blob/1e7b77a809e905d67dc71e12d70e850be26b6233/pycdlib/rockridge.py#L101-L114
train
clalancette/pycdlib
pycdlib/rockridge.py
RRRRRecord.new
def new(self): # type: () -> None ''' Create a new Rock Ridge Rock Ridge record. Parameters: None. Returns: Nothing. ''' if self._initialized: raise pycdlibexception.PyCdlibInternalError('RR record already initialized!') self.rr_flags = 0 self._initialized = True
python
def new(self): # type: () -> None ''' Create a new Rock Ridge Rock Ridge record. Parameters: None. Returns: Nothing. ''' if self._initialized: raise pycdlibexception.PyCdlibInternalError('RR record already initialized!') self.rr_flags = 0 self._initialized = True
[ "def", "new", "(", "self", ")", ":", "# type: () -> None", "if", "self", ".", "_initialized", ":", "raise", "pycdlibexception", ".", "PyCdlibInternalError", "(", "'RR record already initialized!'", ")", "self", ".", "rr_flags", "=", "0", "self", ".", "_initialized", "=", "True" ]
Create a new Rock Ridge Rock Ridge record. Parameters: None. Returns: Nothing.
[ "Create", "a", "new", "Rock", "Ridge", "Rock", "Ridge", "record", "." ]
1e7b77a809e905d67dc71e12d70e850be26b6233
https://github.com/clalancette/pycdlib/blob/1e7b77a809e905d67dc71e12d70e850be26b6233/pycdlib/rockridge.py#L167-L181
train
clalancette/pycdlib
pycdlib/rockridge.py
RRRRRecord.append_field
def append_field(self, fieldname): # type: (str) -> None ''' Mark a field as present in the Rock Ridge records. Parameters: fieldname - The name of the field to mark as present; should be one of 'PX', 'PN', 'SL', 'NM', 'CL', 'PL', 'RE', or 'TF'. Returns: Nothing. ''' if not self._initialized: raise pycdlibexception.PyCdlibInternalError('RR record not yet initialized!') if fieldname == 'PX': bit = 0 elif fieldname == 'PN': bit = 1 elif fieldname == 'SL': bit = 2 elif fieldname == 'NM': bit = 3 elif fieldname == 'CL': bit = 4 elif fieldname == 'PL': bit = 5 elif fieldname == 'RE': bit = 6 elif fieldname == 'TF': bit = 7 else: raise pycdlibexception.PyCdlibInternalError('Unknown RR field name %s' % (fieldname)) self.rr_flags |= (1 << bit)
python
def append_field(self, fieldname): # type: (str) -> None ''' Mark a field as present in the Rock Ridge records. Parameters: fieldname - The name of the field to mark as present; should be one of 'PX', 'PN', 'SL', 'NM', 'CL', 'PL', 'RE', or 'TF'. Returns: Nothing. ''' if not self._initialized: raise pycdlibexception.PyCdlibInternalError('RR record not yet initialized!') if fieldname == 'PX': bit = 0 elif fieldname == 'PN': bit = 1 elif fieldname == 'SL': bit = 2 elif fieldname == 'NM': bit = 3 elif fieldname == 'CL': bit = 4 elif fieldname == 'PL': bit = 5 elif fieldname == 'RE': bit = 6 elif fieldname == 'TF': bit = 7 else: raise pycdlibexception.PyCdlibInternalError('Unknown RR field name %s' % (fieldname)) self.rr_flags |= (1 << bit)
[ "def", "append_field", "(", "self", ",", "fieldname", ")", ":", "# type: (str) -> None", "if", "not", "self", ".", "_initialized", ":", "raise", "pycdlibexception", ".", "PyCdlibInternalError", "(", "'RR record not yet initialized!'", ")", "if", "fieldname", "==", "'PX'", ":", "bit", "=", "0", "elif", "fieldname", "==", "'PN'", ":", "bit", "=", "1", "elif", "fieldname", "==", "'SL'", ":", "bit", "=", "2", "elif", "fieldname", "==", "'NM'", ":", "bit", "=", "3", "elif", "fieldname", "==", "'CL'", ":", "bit", "=", "4", "elif", "fieldname", "==", "'PL'", ":", "bit", "=", "5", "elif", "fieldname", "==", "'RE'", ":", "bit", "=", "6", "elif", "fieldname", "==", "'TF'", ":", "bit", "=", "7", "else", ":", "raise", "pycdlibexception", ".", "PyCdlibInternalError", "(", "'Unknown RR field name %s'", "%", "(", "fieldname", ")", ")", "self", ".", "rr_flags", "|=", "(", "1", "<<", "bit", ")" ]
Mark a field as present in the Rock Ridge records. Parameters: fieldname - The name of the field to mark as present; should be one of 'PX', 'PN', 'SL', 'NM', 'CL', 'PL', 'RE', or 'TF'. Returns: Nothing.
[ "Mark", "a", "field", "as", "present", "in", "the", "Rock", "Ridge", "records", "." ]
1e7b77a809e905d67dc71e12d70e850be26b6233
https://github.com/clalancette/pycdlib/blob/1e7b77a809e905d67dc71e12d70e850be26b6233/pycdlib/rockridge.py#L183-L216
train
clalancette/pycdlib
pycdlib/rockridge.py
RRRRRecord.record
def record(self): # type: () -> bytes ''' Generate a string representing the Rock Ridge Rock Ridge record. Parameters: None. Returns: String containing the Rock Ridge record. ''' if not self._initialized: raise pycdlibexception.PyCdlibInternalError('RR record not yet initialized!') return b'RR' + struct.pack('=BBB', RRRRRecord.length(), SU_ENTRY_VERSION, self.rr_flags)
python
def record(self): # type: () -> bytes ''' Generate a string representing the Rock Ridge Rock Ridge record. Parameters: None. Returns: String containing the Rock Ridge record. ''' if not self._initialized: raise pycdlibexception.PyCdlibInternalError('RR record not yet initialized!') return b'RR' + struct.pack('=BBB', RRRRRecord.length(), SU_ENTRY_VERSION, self.rr_flags)
[ "def", "record", "(", "self", ")", ":", "# type: () -> bytes", "if", "not", "self", ".", "_initialized", ":", "raise", "pycdlibexception", ".", "PyCdlibInternalError", "(", "'RR record not yet initialized!'", ")", "return", "b'RR'", "+", "struct", ".", "pack", "(", "'=BBB'", ",", "RRRRRecord", ".", "length", "(", ")", ",", "SU_ENTRY_VERSION", ",", "self", ".", "rr_flags", ")" ]
Generate a string representing the Rock Ridge Rock Ridge record. Parameters: None. Returns: String containing the Rock Ridge record.
[ "Generate", "a", "string", "representing", "the", "Rock", "Ridge", "Rock", "Ridge", "record", "." ]
1e7b77a809e905d67dc71e12d70e850be26b6233
https://github.com/clalancette/pycdlib/blob/1e7b77a809e905d67dc71e12d70e850be26b6233/pycdlib/rockridge.py#L218-L231
train
clalancette/pycdlib
pycdlib/rockridge.py
RRCERecord.parse
def parse(self, rrstr): # type: (bytes) -> None ''' Parse a Rock Ridge Continuation Entry record out of a string. Parameters: rrstr - The string to parse the record out of. Returns: Nothing. ''' if self._initialized: raise pycdlibexception.PyCdlibInternalError('CE record already initialized!') (su_len, su_entry_version_unused, bl_cont_area_le, bl_cont_area_be, offset_cont_area_le, offset_cont_area_be, len_cont_area_le, len_cont_area_be) = struct.unpack_from('=BBLLLLLL', rrstr[:28], 2) # We assume that the caller has already checked the su_entry_version, # so we don't bother. if su_len != RRCERecord.length(): raise pycdlibexception.PyCdlibInvalidISO('Invalid length on rock ridge extension') if bl_cont_area_le != utils.swab_32bit(bl_cont_area_be): raise pycdlibexception.PyCdlibInvalidISO('CE record big and little endian continuation area do not agree') if offset_cont_area_le != utils.swab_32bit(offset_cont_area_be): raise pycdlibexception.PyCdlibInvalidISO('CE record big and little endian continuation area offset do not agree') if len_cont_area_le != utils.swab_32bit(len_cont_area_be): raise pycdlibexception.PyCdlibInvalidISO('CE record big and little endian continuation area length do not agree') self.bl_cont_area = bl_cont_area_le self.offset_cont_area = offset_cont_area_le self.len_cont_area = len_cont_area_le self._initialized = True
python
def parse(self, rrstr): # type: (bytes) -> None ''' Parse a Rock Ridge Continuation Entry record out of a string. Parameters: rrstr - The string to parse the record out of. Returns: Nothing. ''' if self._initialized: raise pycdlibexception.PyCdlibInternalError('CE record already initialized!') (su_len, su_entry_version_unused, bl_cont_area_le, bl_cont_area_be, offset_cont_area_le, offset_cont_area_be, len_cont_area_le, len_cont_area_be) = struct.unpack_from('=BBLLLLLL', rrstr[:28], 2) # We assume that the caller has already checked the su_entry_version, # so we don't bother. if su_len != RRCERecord.length(): raise pycdlibexception.PyCdlibInvalidISO('Invalid length on rock ridge extension') if bl_cont_area_le != utils.swab_32bit(bl_cont_area_be): raise pycdlibexception.PyCdlibInvalidISO('CE record big and little endian continuation area do not agree') if offset_cont_area_le != utils.swab_32bit(offset_cont_area_be): raise pycdlibexception.PyCdlibInvalidISO('CE record big and little endian continuation area offset do not agree') if len_cont_area_le != utils.swab_32bit(len_cont_area_be): raise pycdlibexception.PyCdlibInvalidISO('CE record big and little endian continuation area length do not agree') self.bl_cont_area = bl_cont_area_le self.offset_cont_area = offset_cont_area_le self.len_cont_area = len_cont_area_le self._initialized = True
[ "def", "parse", "(", "self", ",", "rrstr", ")", ":", "# type: (bytes) -> None", "if", "self", ".", "_initialized", ":", "raise", "pycdlibexception", ".", "PyCdlibInternalError", "(", "'CE record already initialized!'", ")", "(", "su_len", ",", "su_entry_version_unused", ",", "bl_cont_area_le", ",", "bl_cont_area_be", ",", "offset_cont_area_le", ",", "offset_cont_area_be", ",", "len_cont_area_le", ",", "len_cont_area_be", ")", "=", "struct", ".", "unpack_from", "(", "'=BBLLLLLL'", ",", "rrstr", "[", ":", "28", "]", ",", "2", ")", "# We assume that the caller has already checked the su_entry_version,", "# so we don't bother.", "if", "su_len", "!=", "RRCERecord", ".", "length", "(", ")", ":", "raise", "pycdlibexception", ".", "PyCdlibInvalidISO", "(", "'Invalid length on rock ridge extension'", ")", "if", "bl_cont_area_le", "!=", "utils", ".", "swab_32bit", "(", "bl_cont_area_be", ")", ":", "raise", "pycdlibexception", ".", "PyCdlibInvalidISO", "(", "'CE record big and little endian continuation area do not agree'", ")", "if", "offset_cont_area_le", "!=", "utils", ".", "swab_32bit", "(", "offset_cont_area_be", ")", ":", "raise", "pycdlibexception", ".", "PyCdlibInvalidISO", "(", "'CE record big and little endian continuation area offset do not agree'", ")", "if", "len_cont_area_le", "!=", "utils", ".", "swab_32bit", "(", "len_cont_area_be", ")", ":", "raise", "pycdlibexception", ".", "PyCdlibInvalidISO", "(", "'CE record big and little endian continuation area length do not agree'", ")", "self", ".", "bl_cont_area", "=", "bl_cont_area_le", "self", ".", "offset_cont_area", "=", "offset_cont_area_le", "self", ".", "len_cont_area", "=", "len_cont_area_le", "self", ".", "_initialized", "=", "True" ]
Parse a Rock Ridge Continuation Entry record out of a string. Parameters: rrstr - The string to parse the record out of. Returns: Nothing.
[ "Parse", "a", "Rock", "Ridge", "Continuation", "Entry", "record", "out", "of", "a", "string", "." ]
1e7b77a809e905d67dc71e12d70e850be26b6233
https://github.com/clalancette/pycdlib/blob/1e7b77a809e905d67dc71e12d70e850be26b6233/pycdlib/rockridge.py#L261-L297
train
clalancette/pycdlib
pycdlib/rockridge.py
RRCERecord.new
def new(self): # type: () -> None ''' Create a new Rock Ridge Continuation Entry record. Parameters: None. Returns: Nothing. ''' if self._initialized: raise pycdlibexception.PyCdlibInternalError('CE record already initialized!') self.bl_cont_area = 0 # This will get set during reshuffle_extents self.offset_cont_area = 0 # This will get set during reshuffle_extents self.len_cont_area = 0 # This will be calculated based on fields put in self._initialized = True
python
def new(self): # type: () -> None ''' Create a new Rock Ridge Continuation Entry record. Parameters: None. Returns: Nothing. ''' if self._initialized: raise pycdlibexception.PyCdlibInternalError('CE record already initialized!') self.bl_cont_area = 0 # This will get set during reshuffle_extents self.offset_cont_area = 0 # This will get set during reshuffle_extents self.len_cont_area = 0 # This will be calculated based on fields put in self._initialized = True
[ "def", "new", "(", "self", ")", ":", "# type: () -> None", "if", "self", ".", "_initialized", ":", "raise", "pycdlibexception", ".", "PyCdlibInternalError", "(", "'CE record already initialized!'", ")", "self", ".", "bl_cont_area", "=", "0", "# This will get set during reshuffle_extents", "self", ".", "offset_cont_area", "=", "0", "# This will get set during reshuffle_extents", "self", ".", "len_cont_area", "=", "0", "# This will be calculated based on fields put in", "self", ".", "_initialized", "=", "True" ]
Create a new Rock Ridge Continuation Entry record. Parameters: None. Returns: Nothing.
[ "Create", "a", "new", "Rock", "Ridge", "Continuation", "Entry", "record", "." ]
1e7b77a809e905d67dc71e12d70e850be26b6233
https://github.com/clalancette/pycdlib/blob/1e7b77a809e905d67dc71e12d70e850be26b6233/pycdlib/rockridge.py#L299-L316
train
clalancette/pycdlib
pycdlib/rockridge.py
RRCERecord.update_extent
def update_extent(self, extent): # type: (int) -> None ''' Update the extent for this CE record. Parameters: extent - The new extent for this CE record. Returns: Nothing. ''' if not self._initialized: raise pycdlibexception.PyCdlibInternalError('CE record not yet initialized!') self.bl_cont_area = extent
python
def update_extent(self, extent): # type: (int) -> None ''' Update the extent for this CE record. Parameters: extent - The new extent for this CE record. Returns: Nothing. ''' if not self._initialized: raise pycdlibexception.PyCdlibInternalError('CE record not yet initialized!') self.bl_cont_area = extent
[ "def", "update_extent", "(", "self", ",", "extent", ")", ":", "# type: (int) -> None", "if", "not", "self", ".", "_initialized", ":", "raise", "pycdlibexception", ".", "PyCdlibInternalError", "(", "'CE record not yet initialized!'", ")", "self", ".", "bl_cont_area", "=", "extent" ]
Update the extent for this CE record. Parameters: extent - The new extent for this CE record. Returns: Nothing.
[ "Update", "the", "extent", "for", "this", "CE", "record", "." ]
1e7b77a809e905d67dc71e12d70e850be26b6233
https://github.com/clalancette/pycdlib/blob/1e7b77a809e905d67dc71e12d70e850be26b6233/pycdlib/rockridge.py#L318-L331
train
clalancette/pycdlib
pycdlib/rockridge.py
RRCERecord.update_offset
def update_offset(self, offset): # type: (int) -> None ''' Update the offset for this CE record. Parameters: extent - The new offset for this CE record. Returns: Nothing. ''' if not self._initialized: raise pycdlibexception.PyCdlibInternalError('CE record not yet initialized!') self.offset_cont_area = offset
python
def update_offset(self, offset): # type: (int) -> None ''' Update the offset for this CE record. Parameters: extent - The new offset for this CE record. Returns: Nothing. ''' if not self._initialized: raise pycdlibexception.PyCdlibInternalError('CE record not yet initialized!') self.offset_cont_area = offset
[ "def", "update_offset", "(", "self", ",", "offset", ")", ":", "# type: (int) -> None", "if", "not", "self", ".", "_initialized", ":", "raise", "pycdlibexception", ".", "PyCdlibInternalError", "(", "'CE record not yet initialized!'", ")", "self", ".", "offset_cont_area", "=", "offset" ]
Update the offset for this CE record. Parameters: extent - The new offset for this CE record. Returns: Nothing.
[ "Update", "the", "offset", "for", "this", "CE", "record", "." ]
1e7b77a809e905d67dc71e12d70e850be26b6233
https://github.com/clalancette/pycdlib/blob/1e7b77a809e905d67dc71e12d70e850be26b6233/pycdlib/rockridge.py#L333-L346
train
clalancette/pycdlib
pycdlib/rockridge.py
RRCERecord.record
def record(self): # type: () -> bytes ''' Generate a string representing the Rock Ridge Continuation Entry record. Parameters: None. Returns: String containing the Rock Ridge record. ''' if not self._initialized: raise pycdlibexception.PyCdlibInternalError('CE record not yet initialized!') return b'CE' + struct.pack('=BBLLLLLL', RRCERecord.length(), SU_ENTRY_VERSION, self.bl_cont_area, utils.swab_32bit(self.bl_cont_area), self.offset_cont_area, utils.swab_32bit(self.offset_cont_area), self.len_cont_area, utils.swab_32bit(self.len_cont_area))
python
def record(self): # type: () -> bytes ''' Generate a string representing the Rock Ridge Continuation Entry record. Parameters: None. Returns: String containing the Rock Ridge record. ''' if not self._initialized: raise pycdlibexception.PyCdlibInternalError('CE record not yet initialized!') return b'CE' + struct.pack('=BBLLLLLL', RRCERecord.length(), SU_ENTRY_VERSION, self.bl_cont_area, utils.swab_32bit(self.bl_cont_area), self.offset_cont_area, utils.swab_32bit(self.offset_cont_area), self.len_cont_area, utils.swab_32bit(self.len_cont_area))
[ "def", "record", "(", "self", ")", ":", "# type: () -> bytes", "if", "not", "self", ".", "_initialized", ":", "raise", "pycdlibexception", ".", "PyCdlibInternalError", "(", "'CE record not yet initialized!'", ")", "return", "b'CE'", "+", "struct", ".", "pack", "(", "'=BBLLLLLL'", ",", "RRCERecord", ".", "length", "(", ")", ",", "SU_ENTRY_VERSION", ",", "self", ".", "bl_cont_area", ",", "utils", ".", "swab_32bit", "(", "self", ".", "bl_cont_area", ")", ",", "self", ".", "offset_cont_area", ",", "utils", ".", "swab_32bit", "(", "self", ".", "offset_cont_area", ")", ",", "self", ".", "len_cont_area", ",", "utils", ".", "swab_32bit", "(", "self", ".", "len_cont_area", ")", ")" ]
Generate a string representing the Rock Ridge Continuation Entry record. Parameters: None. Returns: String containing the Rock Ridge record.
[ "Generate", "a", "string", "representing", "the", "Rock", "Ridge", "Continuation", "Entry", "record", "." ]
1e7b77a809e905d67dc71e12d70e850be26b6233
https://github.com/clalancette/pycdlib/blob/1e7b77a809e905d67dc71e12d70e850be26b6233/pycdlib/rockridge.py#L364-L385
train
clalancette/pycdlib
pycdlib/rockridge.py
RRPXRecord.parse
def parse(self, rrstr): # type: (bytes) -> int ''' Parse a Rock Ridge POSIX File Attributes record out of a string. Parameters: rrstr - The string to parse the record out of. Returns: A string representing the RR version, either 1.09 or 1.12. ''' if self._initialized: raise pycdlibexception.PyCdlibInternalError('PX record already initialized!') (su_len, su_entry_version_unused, posix_file_mode_le, posix_file_mode_be, posix_file_links_le, posix_file_links_be, posix_file_user_id_le, posix_file_user_id_be, posix_file_group_id_le, posix_file_group_id_be) = struct.unpack_from('=BBLLLLLLLL', rrstr[:38], 2) # We assume that the caller has already checked the su_entry_version, # so we don't bother. if posix_file_mode_le != utils.swab_32bit(posix_file_mode_be): raise pycdlibexception.PyCdlibInvalidISO('PX record big and little-endian file mode do not agree') if posix_file_links_le != utils.swab_32bit(posix_file_links_be): raise pycdlibexception.PyCdlibInvalidISO('PX record big and little-endian file links do not agree') if posix_file_user_id_le != utils.swab_32bit(posix_file_user_id_be): raise pycdlibexception.PyCdlibInvalidISO('PX record big and little-endian file user ID do not agree') if posix_file_group_id_le != utils.swab_32bit(posix_file_group_id_be): raise pycdlibexception.PyCdlibInvalidISO('PX record big and little-endian file group ID do not agree') # In Rock Ridge 1.09 and 1.10, there is no serial number so the su_len # is 36, while in Rock Ridge 1.12, there is an 8-byte serial number so # su_len is 44. if su_len == 36: posix_file_serial_number_le = 0 elif su_len == 44: (posix_file_serial_number_le, posix_file_serial_number_be) = struct.unpack_from('=LL', rrstr[:44], 36) if posix_file_serial_number_le != utils.swab_32bit(posix_file_serial_number_be): raise pycdlibexception.PyCdlibInvalidISO('PX record big and little-endian file serial number do not agree') else: raise pycdlibexception.PyCdlibInvalidISO('Invalid length on Rock Ridge PX record') self.posix_file_mode = posix_file_mode_le self.posix_file_links = posix_file_links_le self.posix_user_id = posix_file_user_id_le self.posix_group_id = posix_file_group_id_le self.posix_serial_number = posix_file_serial_number_le self._initialized = True return su_len
python
def parse(self, rrstr): # type: (bytes) -> int ''' Parse a Rock Ridge POSIX File Attributes record out of a string. Parameters: rrstr - The string to parse the record out of. Returns: A string representing the RR version, either 1.09 or 1.12. ''' if self._initialized: raise pycdlibexception.PyCdlibInternalError('PX record already initialized!') (su_len, su_entry_version_unused, posix_file_mode_le, posix_file_mode_be, posix_file_links_le, posix_file_links_be, posix_file_user_id_le, posix_file_user_id_be, posix_file_group_id_le, posix_file_group_id_be) = struct.unpack_from('=BBLLLLLLLL', rrstr[:38], 2) # We assume that the caller has already checked the su_entry_version, # so we don't bother. if posix_file_mode_le != utils.swab_32bit(posix_file_mode_be): raise pycdlibexception.PyCdlibInvalidISO('PX record big and little-endian file mode do not agree') if posix_file_links_le != utils.swab_32bit(posix_file_links_be): raise pycdlibexception.PyCdlibInvalidISO('PX record big and little-endian file links do not agree') if posix_file_user_id_le != utils.swab_32bit(posix_file_user_id_be): raise pycdlibexception.PyCdlibInvalidISO('PX record big and little-endian file user ID do not agree') if posix_file_group_id_le != utils.swab_32bit(posix_file_group_id_be): raise pycdlibexception.PyCdlibInvalidISO('PX record big and little-endian file group ID do not agree') # In Rock Ridge 1.09 and 1.10, there is no serial number so the su_len # is 36, while in Rock Ridge 1.12, there is an 8-byte serial number so # su_len is 44. if su_len == 36: posix_file_serial_number_le = 0 elif su_len == 44: (posix_file_serial_number_le, posix_file_serial_number_be) = struct.unpack_from('=LL', rrstr[:44], 36) if posix_file_serial_number_le != utils.swab_32bit(posix_file_serial_number_be): raise pycdlibexception.PyCdlibInvalidISO('PX record big and little-endian file serial number do not agree') else: raise pycdlibexception.PyCdlibInvalidISO('Invalid length on Rock Ridge PX record') self.posix_file_mode = posix_file_mode_le self.posix_file_links = posix_file_links_le self.posix_user_id = posix_file_user_id_le self.posix_group_id = posix_file_group_id_le self.posix_serial_number = posix_file_serial_number_le self._initialized = True return su_len
[ "def", "parse", "(", "self", ",", "rrstr", ")", ":", "# type: (bytes) -> int", "if", "self", ".", "_initialized", ":", "raise", "pycdlibexception", ".", "PyCdlibInternalError", "(", "'PX record already initialized!'", ")", "(", "su_len", ",", "su_entry_version_unused", ",", "posix_file_mode_le", ",", "posix_file_mode_be", ",", "posix_file_links_le", ",", "posix_file_links_be", ",", "posix_file_user_id_le", ",", "posix_file_user_id_be", ",", "posix_file_group_id_le", ",", "posix_file_group_id_be", ")", "=", "struct", ".", "unpack_from", "(", "'=BBLLLLLLLL'", ",", "rrstr", "[", ":", "38", "]", ",", "2", ")", "# We assume that the caller has already checked the su_entry_version,", "# so we don't bother.", "if", "posix_file_mode_le", "!=", "utils", ".", "swab_32bit", "(", "posix_file_mode_be", ")", ":", "raise", "pycdlibexception", ".", "PyCdlibInvalidISO", "(", "'PX record big and little-endian file mode do not agree'", ")", "if", "posix_file_links_le", "!=", "utils", ".", "swab_32bit", "(", "posix_file_links_be", ")", ":", "raise", "pycdlibexception", ".", "PyCdlibInvalidISO", "(", "'PX record big and little-endian file links do not agree'", ")", "if", "posix_file_user_id_le", "!=", "utils", ".", "swab_32bit", "(", "posix_file_user_id_be", ")", ":", "raise", "pycdlibexception", ".", "PyCdlibInvalidISO", "(", "'PX record big and little-endian file user ID do not agree'", ")", "if", "posix_file_group_id_le", "!=", "utils", ".", "swab_32bit", "(", "posix_file_group_id_be", ")", ":", "raise", "pycdlibexception", ".", "PyCdlibInvalidISO", "(", "'PX record big and little-endian file group ID do not agree'", ")", "# In Rock Ridge 1.09 and 1.10, there is no serial number so the su_len", "# is 36, while in Rock Ridge 1.12, there is an 8-byte serial number so", "# su_len is 44.", "if", "su_len", "==", "36", ":", "posix_file_serial_number_le", "=", "0", "elif", "su_len", "==", "44", ":", "(", "posix_file_serial_number_le", ",", "posix_file_serial_number_be", ")", "=", "struct", ".", "unpack_from", "(", "'=LL'", ",", "rrstr", "[", ":", "44", "]", ",", "36", ")", "if", "posix_file_serial_number_le", "!=", "utils", ".", "swab_32bit", "(", "posix_file_serial_number_be", ")", ":", "raise", "pycdlibexception", ".", "PyCdlibInvalidISO", "(", "'PX record big and little-endian file serial number do not agree'", ")", "else", ":", "raise", "pycdlibexception", ".", "PyCdlibInvalidISO", "(", "'Invalid length on Rock Ridge PX record'", ")", "self", ".", "posix_file_mode", "=", "posix_file_mode_le", "self", ".", "posix_file_links", "=", "posix_file_links_le", "self", ".", "posix_user_id", "=", "posix_file_user_id_le", "self", ".", "posix_group_id", "=", "posix_file_group_id_le", "self", ".", "posix_serial_number", "=", "posix_file_serial_number_le", "self", ".", "_initialized", "=", "True", "return", "su_len" ]
Parse a Rock Ridge POSIX File Attributes record out of a string. Parameters: rrstr - The string to parse the record out of. Returns: A string representing the RR version, either 1.09 or 1.12.
[ "Parse", "a", "Rock", "Ridge", "POSIX", "File", "Attributes", "record", "out", "of", "a", "string", "." ]
1e7b77a809e905d67dc71e12d70e850be26b6233
https://github.com/clalancette/pycdlib/blob/1e7b77a809e905d67dc71e12d70e850be26b6233/pycdlib/rockridge.py#L421-L476
train
clalancette/pycdlib
pycdlib/rockridge.py
RRPXRecord.new
def new(self, mode): # type: (int) -> None ''' Create a new Rock Ridge POSIX File Attributes record. Parameters: mode - The Unix file mode for this record. Returns: Nothing. ''' if self._initialized: raise pycdlibexception.PyCdlibInternalError('PX record already initialized!') self.posix_file_mode = mode self.posix_file_links = 1 self.posix_user_id = 0 self.posix_group_id = 0 self.posix_serial_number = 0 self._initialized = True
python
def new(self, mode): # type: (int) -> None ''' Create a new Rock Ridge POSIX File Attributes record. Parameters: mode - The Unix file mode for this record. Returns: Nothing. ''' if self._initialized: raise pycdlibexception.PyCdlibInternalError('PX record already initialized!') self.posix_file_mode = mode self.posix_file_links = 1 self.posix_user_id = 0 self.posix_group_id = 0 self.posix_serial_number = 0 self._initialized = True
[ "def", "new", "(", "self", ",", "mode", ")", ":", "# type: (int) -> None", "if", "self", ".", "_initialized", ":", "raise", "pycdlibexception", ".", "PyCdlibInternalError", "(", "'PX record already initialized!'", ")", "self", ".", "posix_file_mode", "=", "mode", "self", ".", "posix_file_links", "=", "1", "self", ".", "posix_user_id", "=", "0", "self", ".", "posix_group_id", "=", "0", "self", ".", "posix_serial_number", "=", "0", "self", ".", "_initialized", "=", "True" ]
Create a new Rock Ridge POSIX File Attributes record. Parameters: mode - The Unix file mode for this record. Returns: Nothing.
[ "Create", "a", "new", "Rock", "Ridge", "POSIX", "File", "Attributes", "record", "." ]
1e7b77a809e905d67dc71e12d70e850be26b6233
https://github.com/clalancette/pycdlib/blob/1e7b77a809e905d67dc71e12d70e850be26b6233/pycdlib/rockridge.py#L478-L497
train
clalancette/pycdlib
pycdlib/rockridge.py
RRPXRecord.record
def record(self, rr_version): # type: (str) -> bytes ''' Generate a string representing the Rock Ridge POSIX File Attributes record. Parameters: rr_version - The Rock Ridge version to use. Returns: String containing the Rock Ridge record. ''' if not self._initialized: raise pycdlibexception.PyCdlibInternalError('PX record not yet initialized!') outlist = [b'PX', struct.pack('=BBLLLLLLLL', RRPXRecord.length(rr_version), SU_ENTRY_VERSION, self.posix_file_mode, utils.swab_32bit(self.posix_file_mode), self.posix_file_links, utils.swab_32bit(self.posix_file_links), self.posix_user_id, utils.swab_32bit(self.posix_user_id), self.posix_group_id, utils.swab_32bit(self.posix_group_id))] if rr_version == '1.12': outlist.append(struct.pack('=LL', self.posix_serial_number, utils.swab_32bit(self.posix_serial_number))) # The rr_version can never be "wrong" at this point; if it was, it would # have thrown an exception earlier when calling length(). So just skip # any potential checks here. return b''.join(outlist)
python
def record(self, rr_version): # type: (str) -> bytes ''' Generate a string representing the Rock Ridge POSIX File Attributes record. Parameters: rr_version - The Rock Ridge version to use. Returns: String containing the Rock Ridge record. ''' if not self._initialized: raise pycdlibexception.PyCdlibInternalError('PX record not yet initialized!') outlist = [b'PX', struct.pack('=BBLLLLLLLL', RRPXRecord.length(rr_version), SU_ENTRY_VERSION, self.posix_file_mode, utils.swab_32bit(self.posix_file_mode), self.posix_file_links, utils.swab_32bit(self.posix_file_links), self.posix_user_id, utils.swab_32bit(self.posix_user_id), self.posix_group_id, utils.swab_32bit(self.posix_group_id))] if rr_version == '1.12': outlist.append(struct.pack('=LL', self.posix_serial_number, utils.swab_32bit(self.posix_serial_number))) # The rr_version can never be "wrong" at this point; if it was, it would # have thrown an exception earlier when calling length(). So just skip # any potential checks here. return b''.join(outlist)
[ "def", "record", "(", "self", ",", "rr_version", ")", ":", "# type: (str) -> bytes", "if", "not", "self", ".", "_initialized", ":", "raise", "pycdlibexception", ".", "PyCdlibInternalError", "(", "'PX record not yet initialized!'", ")", "outlist", "=", "[", "b'PX'", ",", "struct", ".", "pack", "(", "'=BBLLLLLLLL'", ",", "RRPXRecord", ".", "length", "(", "rr_version", ")", ",", "SU_ENTRY_VERSION", ",", "self", ".", "posix_file_mode", ",", "utils", ".", "swab_32bit", "(", "self", ".", "posix_file_mode", ")", ",", "self", ".", "posix_file_links", ",", "utils", ".", "swab_32bit", "(", "self", ".", "posix_file_links", ")", ",", "self", ".", "posix_user_id", ",", "utils", ".", "swab_32bit", "(", "self", ".", "posix_user_id", ")", ",", "self", ".", "posix_group_id", ",", "utils", ".", "swab_32bit", "(", "self", ".", "posix_group_id", ")", ")", "]", "if", "rr_version", "==", "'1.12'", ":", "outlist", ".", "append", "(", "struct", ".", "pack", "(", "'=LL'", ",", "self", ".", "posix_serial_number", ",", "utils", ".", "swab_32bit", "(", "self", ".", "posix_serial_number", ")", ")", ")", "# The rr_version can never be \"wrong\" at this point; if it was, it would", "# have thrown an exception earlier when calling length(). So just skip", "# any potential checks here.", "return", "b''", ".", "join", "(", "outlist", ")" ]
Generate a string representing the Rock Ridge POSIX File Attributes record. Parameters: rr_version - The Rock Ridge version to use. Returns: String containing the Rock Ridge record.
[ "Generate", "a", "string", "representing", "the", "Rock", "Ridge", "POSIX", "File", "Attributes", "record", "." ]
1e7b77a809e905d67dc71e12d70e850be26b6233
https://github.com/clalancette/pycdlib/blob/1e7b77a809e905d67dc71e12d70e850be26b6233/pycdlib/rockridge.py#L499-L529
train
clalancette/pycdlib
pycdlib/rockridge.py
RRERRecord.parse
def parse(self, rrstr): # type: (bytes) -> None ''' Parse a Rock Ridge Extensions Reference record out of a string. Parameters: rrstr - The string to parse the record out of. Returns: Nothing. ''' if self._initialized: raise pycdlibexception.PyCdlibInternalError('ER record already initialized!') (su_len, su_entry_version_unused, len_id, len_des, len_src, self.ext_ver) = struct.unpack_from('=BBBBBB', rrstr[:8], 2) # We assume that the caller has already checked the su_entry_version, # so we don't bother. # Ensure that the length isn't crazy if su_len > len(rrstr): raise pycdlibexception.PyCdlibInvalidISO('Length of ER record much too long') # Also ensure that the combination of len_id, len_des, and len_src # doesn't overrun su_len; because of the check above, this means it # can't overrun len(rrstr) either total_length = len_id + len_des + len_src if total_length > su_len: raise pycdlibexception.PyCdlibInvalidISO('Combined length of ER ID, des, and src longer than record') fmtstr = '=%ds%ds%ds' % (len_id, len_des, len_src) (self.ext_id, self.ext_des, self.ext_src) = struct.unpack_from(fmtstr, rrstr, 8) self._initialized = True
python
def parse(self, rrstr): # type: (bytes) -> None ''' Parse a Rock Ridge Extensions Reference record out of a string. Parameters: rrstr - The string to parse the record out of. Returns: Nothing. ''' if self._initialized: raise pycdlibexception.PyCdlibInternalError('ER record already initialized!') (su_len, su_entry_version_unused, len_id, len_des, len_src, self.ext_ver) = struct.unpack_from('=BBBBBB', rrstr[:8], 2) # We assume that the caller has already checked the su_entry_version, # so we don't bother. # Ensure that the length isn't crazy if su_len > len(rrstr): raise pycdlibexception.PyCdlibInvalidISO('Length of ER record much too long') # Also ensure that the combination of len_id, len_des, and len_src # doesn't overrun su_len; because of the check above, this means it # can't overrun len(rrstr) either total_length = len_id + len_des + len_src if total_length > su_len: raise pycdlibexception.PyCdlibInvalidISO('Combined length of ER ID, des, and src longer than record') fmtstr = '=%ds%ds%ds' % (len_id, len_des, len_src) (self.ext_id, self.ext_des, self.ext_src) = struct.unpack_from(fmtstr, rrstr, 8) self._initialized = True
[ "def", "parse", "(", "self", ",", "rrstr", ")", ":", "# type: (bytes) -> None", "if", "self", ".", "_initialized", ":", "raise", "pycdlibexception", ".", "PyCdlibInternalError", "(", "'ER record already initialized!'", ")", "(", "su_len", ",", "su_entry_version_unused", ",", "len_id", ",", "len_des", ",", "len_src", ",", "self", ".", "ext_ver", ")", "=", "struct", ".", "unpack_from", "(", "'=BBBBBB'", ",", "rrstr", "[", ":", "8", "]", ",", "2", ")", "# We assume that the caller has already checked the su_entry_version,", "# so we don't bother.", "# Ensure that the length isn't crazy", "if", "su_len", ">", "len", "(", "rrstr", ")", ":", "raise", "pycdlibexception", ".", "PyCdlibInvalidISO", "(", "'Length of ER record much too long'", ")", "# Also ensure that the combination of len_id, len_des, and len_src", "# doesn't overrun su_len; because of the check above, this means it", "# can't overrun len(rrstr) either", "total_length", "=", "len_id", "+", "len_des", "+", "len_src", "if", "total_length", ">", "su_len", ":", "raise", "pycdlibexception", ".", "PyCdlibInvalidISO", "(", "'Combined length of ER ID, des, and src longer than record'", ")", "fmtstr", "=", "'=%ds%ds%ds'", "%", "(", "len_id", ",", "len_des", ",", "len_src", ")", "(", "self", ".", "ext_id", ",", "self", ".", "ext_des", ",", "self", ".", "ext_src", ")", "=", "struct", ".", "unpack_from", "(", "fmtstr", ",", "rrstr", ",", "8", ")", "self", ".", "_initialized", "=", "True" ]
Parse a Rock Ridge Extensions Reference record out of a string. Parameters: rrstr - The string to parse the record out of. Returns: Nothing.
[ "Parse", "a", "Rock", "Ridge", "Extensions", "Reference", "record", "out", "of", "a", "string", "." ]
1e7b77a809e905d67dc71e12d70e850be26b6233
https://github.com/clalancette/pycdlib/blob/1e7b77a809e905d67dc71e12d70e850be26b6233/pycdlib/rockridge.py#L566-L599
train
clalancette/pycdlib
pycdlib/rockridge.py
RRERRecord.new
def new(self, ext_id, ext_des, ext_src): # type: (bytes, bytes, bytes) -> None ''' Create a new Rock Ridge Extensions Reference record. Parameters: ext_id - The extension identifier to use. ext_des - The extension descriptor to use. ext_src - The extension specification source to use. Returns: Nothing. ''' if self._initialized: raise pycdlibexception.PyCdlibInternalError('ER record already initialized!') self.ext_id = ext_id self.ext_des = ext_des self.ext_src = ext_src self.ext_ver = 1 self._initialized = True
python
def new(self, ext_id, ext_des, ext_src): # type: (bytes, bytes, bytes) -> None ''' Create a new Rock Ridge Extensions Reference record. Parameters: ext_id - The extension identifier to use. ext_des - The extension descriptor to use. ext_src - The extension specification source to use. Returns: Nothing. ''' if self._initialized: raise pycdlibexception.PyCdlibInternalError('ER record already initialized!') self.ext_id = ext_id self.ext_des = ext_des self.ext_src = ext_src self.ext_ver = 1 self._initialized = True
[ "def", "new", "(", "self", ",", "ext_id", ",", "ext_des", ",", "ext_src", ")", ":", "# type: (bytes, bytes, bytes) -> None", "if", "self", ".", "_initialized", ":", "raise", "pycdlibexception", ".", "PyCdlibInternalError", "(", "'ER record already initialized!'", ")", "self", ".", "ext_id", "=", "ext_id", "self", ".", "ext_des", "=", "ext_des", "self", ".", "ext_src", "=", "ext_src", "self", ".", "ext_ver", "=", "1", "self", ".", "_initialized", "=", "True" ]
Create a new Rock Ridge Extensions Reference record. Parameters: ext_id - The extension identifier to use. ext_des - The extension descriptor to use. ext_src - The extension specification source to use. Returns: Nothing.
[ "Create", "a", "new", "Rock", "Ridge", "Extensions", "Reference", "record", "." ]
1e7b77a809e905d67dc71e12d70e850be26b6233
https://github.com/clalancette/pycdlib/blob/1e7b77a809e905d67dc71e12d70e850be26b6233/pycdlib/rockridge.py#L601-L621
train
clalancette/pycdlib
pycdlib/rockridge.py
RRERRecord.record
def record(self): # type: () -> bytes ''' Generate a string representing the Rock Ridge Extensions Reference record. Parameters: None. Returns: String containing the Rock Ridge record. ''' if not self._initialized: raise pycdlibexception.PyCdlibInternalError('ER record not yet initialized!') return b'ER' + struct.pack('=BBBBBB', RRERRecord.length(self.ext_id, self.ext_des, self.ext_src), SU_ENTRY_VERSION, len(self.ext_id), len(self.ext_des), len(self.ext_src), self.ext_ver) + self.ext_id + self.ext_des + self.ext_src
python
def record(self): # type: () -> bytes ''' Generate a string representing the Rock Ridge Extensions Reference record. Parameters: None. Returns: String containing the Rock Ridge record. ''' if not self._initialized: raise pycdlibexception.PyCdlibInternalError('ER record not yet initialized!') return b'ER' + struct.pack('=BBBBBB', RRERRecord.length(self.ext_id, self.ext_des, self.ext_src), SU_ENTRY_VERSION, len(self.ext_id), len(self.ext_des), len(self.ext_src), self.ext_ver) + self.ext_id + self.ext_des + self.ext_src
[ "def", "record", "(", "self", ")", ":", "# type: () -> bytes", "if", "not", "self", ".", "_initialized", ":", "raise", "pycdlibexception", ".", "PyCdlibInternalError", "(", "'ER record not yet initialized!'", ")", "return", "b'ER'", "+", "struct", ".", "pack", "(", "'=BBBBBB'", ",", "RRERRecord", ".", "length", "(", "self", ".", "ext_id", ",", "self", ".", "ext_des", ",", "self", ".", "ext_src", ")", ",", "SU_ENTRY_VERSION", ",", "len", "(", "self", ".", "ext_id", ")", ",", "len", "(", "self", ".", "ext_des", ")", ",", "len", "(", "self", ".", "ext_src", ")", ",", "self", ".", "ext_ver", ")", "+", "self", ".", "ext_id", "+", "self", ".", "ext_des", "+", "self", ".", "ext_src" ]
Generate a string representing the Rock Ridge Extensions Reference record. Parameters: None. Returns: String containing the Rock Ridge record.
[ "Generate", "a", "string", "representing", "the", "Rock", "Ridge", "Extensions", "Reference", "record", "." ]
1e7b77a809e905d67dc71e12d70e850be26b6233
https://github.com/clalancette/pycdlib/blob/1e7b77a809e905d67dc71e12d70e850be26b6233/pycdlib/rockridge.py#L623-L637
train
clalancette/pycdlib
pycdlib/rockridge.py
RRERRecord.length
def length(ext_id, ext_des, ext_src): # type: (bytes, bytes, bytes) -> int ''' Static method to return the length of the Rock Ridge Extensions Reference record. Parameters: ext_id - The extension identifier to use. ext_des - The extension descriptor to use. ext_src - The extension specification source to use. Returns: The length of this record in bytes. ''' return 8 + len(ext_id) + len(ext_des) + len(ext_src)
python
def length(ext_id, ext_des, ext_src): # type: (bytes, bytes, bytes) -> int ''' Static method to return the length of the Rock Ridge Extensions Reference record. Parameters: ext_id - The extension identifier to use. ext_des - The extension descriptor to use. ext_src - The extension specification source to use. Returns: The length of this record in bytes. ''' return 8 + len(ext_id) + len(ext_des) + len(ext_src)
[ "def", "length", "(", "ext_id", ",", "ext_des", ",", "ext_src", ")", ":", "# type: (bytes, bytes, bytes) -> int", "return", "8", "+", "len", "(", "ext_id", ")", "+", "len", "(", "ext_des", ")", "+", "len", "(", "ext_src", ")" ]
Static method to return the length of the Rock Ridge Extensions Reference record. Parameters: ext_id - The extension identifier to use. ext_des - The extension descriptor to use. ext_src - The extension specification source to use. Returns: The length of this record in bytes.
[ "Static", "method", "to", "return", "the", "length", "of", "the", "Rock", "Ridge", "Extensions", "Reference", "record", "." ]
1e7b77a809e905d67dc71e12d70e850be26b6233
https://github.com/clalancette/pycdlib/blob/1e7b77a809e905d67dc71e12d70e850be26b6233/pycdlib/rockridge.py#L640-L653
train
clalancette/pycdlib
pycdlib/rockridge.py
RRESRecord.new
def new(self, extension_sequence): # type: (int) -> None ''' Create a new Rock Ridge Extension Selector record. Parameters: extension_sequence - The sequence number of this extension. Returns: Nothing. ''' if self._initialized: raise pycdlibexception.PyCdlibInternalError('ES record already initialized!') self.extension_sequence = extension_sequence self._initialized = True
python
def new(self, extension_sequence): # type: (int) -> None ''' Create a new Rock Ridge Extension Selector record. Parameters: extension_sequence - The sequence number of this extension. Returns: Nothing. ''' if self._initialized: raise pycdlibexception.PyCdlibInternalError('ES record already initialized!') self.extension_sequence = extension_sequence self._initialized = True
[ "def", "new", "(", "self", ",", "extension_sequence", ")", ":", "# type: (int) -> None", "if", "self", ".", "_initialized", ":", "raise", "pycdlibexception", ".", "PyCdlibInternalError", "(", "'ES record already initialized!'", ")", "self", ".", "extension_sequence", "=", "extension_sequence", "self", ".", "_initialized", "=", "True" ]
Create a new Rock Ridge Extension Selector record. Parameters: extension_sequence - The sequence number of this extension. Returns: Nothing.
[ "Create", "a", "new", "Rock", "Ridge", "Extension", "Selector", "record", "." ]
1e7b77a809e905d67dc71e12d70e850be26b6233
https://github.com/clalancette/pycdlib/blob/1e7b77a809e905d67dc71e12d70e850be26b6233/pycdlib/rockridge.py#L689-L703
train
clalancette/pycdlib
pycdlib/rockridge.py
RRESRecord.record
def record(self): # type: () -> bytes ''' Generate a string representing the Rock Ridge Extension Selector record. Parameters: None. Returns: String containing the Rock Ridge record. ''' if not self._initialized: raise pycdlibexception.PyCdlibInternalError('ES record not yet initialized!') return b'ES' + struct.pack('=BBB', RRESRecord.length(), SU_ENTRY_VERSION, self.extension_sequence)
python
def record(self): # type: () -> bytes ''' Generate a string representing the Rock Ridge Extension Selector record. Parameters: None. Returns: String containing the Rock Ridge record. ''' if not self._initialized: raise pycdlibexception.PyCdlibInternalError('ES record not yet initialized!') return b'ES' + struct.pack('=BBB', RRESRecord.length(), SU_ENTRY_VERSION, self.extension_sequence)
[ "def", "record", "(", "self", ")", ":", "# type: () -> bytes", "if", "not", "self", ".", "_initialized", ":", "raise", "pycdlibexception", ".", "PyCdlibInternalError", "(", "'ES record not yet initialized!'", ")", "return", "b'ES'", "+", "struct", ".", "pack", "(", "'=BBB'", ",", "RRESRecord", ".", "length", "(", ")", ",", "SU_ENTRY_VERSION", ",", "self", ".", "extension_sequence", ")" ]
Generate a string representing the Rock Ridge Extension Selector record. Parameters: None. Returns: String containing the Rock Ridge record.
[ "Generate", "a", "string", "representing", "the", "Rock", "Ridge", "Extension", "Selector", "record", "." ]
1e7b77a809e905d67dc71e12d70e850be26b6233
https://github.com/clalancette/pycdlib/blob/1e7b77a809e905d67dc71e12d70e850be26b6233/pycdlib/rockridge.py#L705-L718
train
clalancette/pycdlib
pycdlib/rockridge.py
RRPNRecord.parse
def parse(self, rrstr): # type: (bytes) -> None ''' Parse a Rock Ridge POSIX Device Number record out of a string. Parameters: rrstr - The string to parse the record out of. Returns: Nothing. ''' if self._initialized: raise pycdlibexception.PyCdlibInternalError('PN record already initialized!') (su_len, su_entry_version_unused, dev_t_high_le, dev_t_high_be, dev_t_low_le, dev_t_low_be) = struct.unpack_from('=BBLLLL', rrstr[:20], 2) # We assume that the caller has already checked the su_entry_version, # so we don't bother. if su_len != RRPNRecord.length(): raise pycdlibexception.PyCdlibInvalidISO('Invalid length on rock ridge extension') if dev_t_high_le != utils.swab_32bit(dev_t_high_be): raise pycdlibexception.PyCdlibInvalidISO('Dev_t high little-endian does not match big-endian') if dev_t_low_le != utils.swab_32bit(dev_t_low_be): raise pycdlibexception.PyCdlibInvalidISO('Dev_t low little-endian does not match big-endian') self.dev_t_high = dev_t_high_le self.dev_t_low = dev_t_low_le self._initialized = True
python
def parse(self, rrstr): # type: (bytes) -> None ''' Parse a Rock Ridge POSIX Device Number record out of a string. Parameters: rrstr - The string to parse the record out of. Returns: Nothing. ''' if self._initialized: raise pycdlibexception.PyCdlibInternalError('PN record already initialized!') (su_len, su_entry_version_unused, dev_t_high_le, dev_t_high_be, dev_t_low_le, dev_t_low_be) = struct.unpack_from('=BBLLLL', rrstr[:20], 2) # We assume that the caller has already checked the su_entry_version, # so we don't bother. if su_len != RRPNRecord.length(): raise pycdlibexception.PyCdlibInvalidISO('Invalid length on rock ridge extension') if dev_t_high_le != utils.swab_32bit(dev_t_high_be): raise pycdlibexception.PyCdlibInvalidISO('Dev_t high little-endian does not match big-endian') if dev_t_low_le != utils.swab_32bit(dev_t_low_be): raise pycdlibexception.PyCdlibInvalidISO('Dev_t low little-endian does not match big-endian') self.dev_t_high = dev_t_high_le self.dev_t_low = dev_t_low_le self._initialized = True
[ "def", "parse", "(", "self", ",", "rrstr", ")", ":", "# type: (bytes) -> None", "if", "self", ".", "_initialized", ":", "raise", "pycdlibexception", ".", "PyCdlibInternalError", "(", "'PN record already initialized!'", ")", "(", "su_len", ",", "su_entry_version_unused", ",", "dev_t_high_le", ",", "dev_t_high_be", ",", "dev_t_low_le", ",", "dev_t_low_be", ")", "=", "struct", ".", "unpack_from", "(", "'=BBLLLL'", ",", "rrstr", "[", ":", "20", "]", ",", "2", ")", "# We assume that the caller has already checked the su_entry_version,", "# so we don't bother.", "if", "su_len", "!=", "RRPNRecord", ".", "length", "(", ")", ":", "raise", "pycdlibexception", ".", "PyCdlibInvalidISO", "(", "'Invalid length on rock ridge extension'", ")", "if", "dev_t_high_le", "!=", "utils", ".", "swab_32bit", "(", "dev_t_high_be", ")", ":", "raise", "pycdlibexception", ".", "PyCdlibInvalidISO", "(", "'Dev_t high little-endian does not match big-endian'", ")", "if", "dev_t_low_le", "!=", "utils", ".", "swab_32bit", "(", "dev_t_low_be", ")", ":", "raise", "pycdlibexception", ".", "PyCdlibInvalidISO", "(", "'Dev_t low little-endian does not match big-endian'", ")", "self", ".", "dev_t_high", "=", "dev_t_high_le", "self", ".", "dev_t_low", "=", "dev_t_low_le", "self", ".", "_initialized", "=", "True" ]
Parse a Rock Ridge POSIX Device Number record out of a string. Parameters: rrstr - The string to parse the record out of. Returns: Nothing.
[ "Parse", "a", "Rock", "Ridge", "POSIX", "Device", "Number", "record", "out", "of", "a", "string", "." ]
1e7b77a809e905d67dc71e12d70e850be26b6233
https://github.com/clalancette/pycdlib/blob/1e7b77a809e905d67dc71e12d70e850be26b6233/pycdlib/rockridge.py#L748-L779
train
clalancette/pycdlib
pycdlib/rockridge.py
RRPNRecord.new
def new(self, dev_t_high, dev_t_low): # type: (int, int) -> None ''' Create a new Rock Ridge POSIX device number record. Parameters: dev_t_high - The high-order 32-bits of the device number. dev_t_low - The low-order 32-bits of the device number. Returns: Nothing. ''' if self._initialized: raise pycdlibexception.PyCdlibInternalError('PN record already initialized!') self.dev_t_high = dev_t_high self.dev_t_low = dev_t_low self._initialized = True
python
def new(self, dev_t_high, dev_t_low): # type: (int, int) -> None ''' Create a new Rock Ridge POSIX device number record. Parameters: dev_t_high - The high-order 32-bits of the device number. dev_t_low - The low-order 32-bits of the device number. Returns: Nothing. ''' if self._initialized: raise pycdlibexception.PyCdlibInternalError('PN record already initialized!') self.dev_t_high = dev_t_high self.dev_t_low = dev_t_low self._initialized = True
[ "def", "new", "(", "self", ",", "dev_t_high", ",", "dev_t_low", ")", ":", "# type: (int, int) -> None", "if", "self", ".", "_initialized", ":", "raise", "pycdlibexception", ".", "PyCdlibInternalError", "(", "'PN record already initialized!'", ")", "self", ".", "dev_t_high", "=", "dev_t_high", "self", ".", "dev_t_low", "=", "dev_t_low", "self", ".", "_initialized", "=", "True" ]
Create a new Rock Ridge POSIX device number record. Parameters: dev_t_high - The high-order 32-bits of the device number. dev_t_low - The low-order 32-bits of the device number. Returns: Nothing.
[ "Create", "a", "new", "Rock", "Ridge", "POSIX", "device", "number", "record", "." ]
1e7b77a809e905d67dc71e12d70e850be26b6233
https://github.com/clalancette/pycdlib/blob/1e7b77a809e905d67dc71e12d70e850be26b6233/pycdlib/rockridge.py#L781-L798
train
clalancette/pycdlib
pycdlib/rockridge.py
RRPNRecord.record
def record(self): # type: () -> bytes ''' Generate a string representing the Rock Ridge POSIX Device Number record. Parameters: None. Returns: String containing the Rock Ridge record. ''' if not self._initialized: raise pycdlibexception.PyCdlibInternalError('PN record not yet initialized!') return b'PN' + struct.pack('=BBLLLL', RRPNRecord.length(), SU_ENTRY_VERSION, self.dev_t_high, utils.swab_32bit(self.dev_t_high), self.dev_t_low, utils.swab_32bit(self.dev_t_low))
python
def record(self): # type: () -> bytes ''' Generate a string representing the Rock Ridge POSIX Device Number record. Parameters: None. Returns: String containing the Rock Ridge record. ''' if not self._initialized: raise pycdlibexception.PyCdlibInternalError('PN record not yet initialized!') return b'PN' + struct.pack('=BBLLLL', RRPNRecord.length(), SU_ENTRY_VERSION, self.dev_t_high, utils.swab_32bit(self.dev_t_high), self.dev_t_low, utils.swab_32bit(self.dev_t_low))
[ "def", "record", "(", "self", ")", ":", "# type: () -> bytes", "if", "not", "self", ".", "_initialized", ":", "raise", "pycdlibexception", ".", "PyCdlibInternalError", "(", "'PN record not yet initialized!'", ")", "return", "b'PN'", "+", "struct", ".", "pack", "(", "'=BBLLLL'", ",", "RRPNRecord", ".", "length", "(", ")", ",", "SU_ENTRY_VERSION", ",", "self", ".", "dev_t_high", ",", "utils", ".", "swab_32bit", "(", "self", ".", "dev_t_high", ")", ",", "self", ".", "dev_t_low", ",", "utils", ".", "swab_32bit", "(", "self", ".", "dev_t_low", ")", ")" ]
Generate a string representing the Rock Ridge POSIX Device Number record. Parameters: None. Returns: String containing the Rock Ridge record.
[ "Generate", "a", "string", "representing", "the", "Rock", "Ridge", "POSIX", "Device", "Number", "record", "." ]
1e7b77a809e905d67dc71e12d70e850be26b6233
https://github.com/clalancette/pycdlib/blob/1e7b77a809e905d67dc71e12d70e850be26b6233/pycdlib/rockridge.py#L800-L814
train
clalancette/pycdlib
pycdlib/rockridge.py
RRSLRecord.parse
def parse(self, rrstr): # type: (bytes) -> None ''' Parse a Rock Ridge Symbolic Link record out of a string. Parameters: rrstr - The string to parse the record out of. Returns: Nothing. ''' if self._initialized: raise pycdlibexception.PyCdlibInternalError('SL record already initialized!') (su_len, su_entry_version_unused, self.flags) = struct.unpack_from('=BBB', rrstr[:5], 2) # We assume that the caller has already checked the su_entry_version, # so we don't bother. cr_offset = 5 data_len = su_len - 5 while data_len > 0: (cr_flags, len_cp) = struct.unpack_from('=BB', rrstr[:cr_offset + 2], cr_offset) data_len -= 2 cr_offset += 2 self.symlink_components.append(self.Component(cr_flags, len_cp, rrstr[cr_offset:cr_offset + len_cp])) # FIXME: if this is the last component in this SL record, # but the component continues on in the next SL record, we will # fail to record this bit. We should fix that. cr_offset += len_cp data_len -= len_cp self._initialized = True
python
def parse(self, rrstr): # type: (bytes) -> None ''' Parse a Rock Ridge Symbolic Link record out of a string. Parameters: rrstr - The string to parse the record out of. Returns: Nothing. ''' if self._initialized: raise pycdlibexception.PyCdlibInternalError('SL record already initialized!') (su_len, su_entry_version_unused, self.flags) = struct.unpack_from('=BBB', rrstr[:5], 2) # We assume that the caller has already checked the su_entry_version, # so we don't bother. cr_offset = 5 data_len = su_len - 5 while data_len > 0: (cr_flags, len_cp) = struct.unpack_from('=BB', rrstr[:cr_offset + 2], cr_offset) data_len -= 2 cr_offset += 2 self.symlink_components.append(self.Component(cr_flags, len_cp, rrstr[cr_offset:cr_offset + len_cp])) # FIXME: if this is the last component in this SL record, # but the component continues on in the next SL record, we will # fail to record this bit. We should fix that. cr_offset += len_cp data_len -= len_cp self._initialized = True
[ "def", "parse", "(", "self", ",", "rrstr", ")", ":", "# type: (bytes) -> None", "if", "self", ".", "_initialized", ":", "raise", "pycdlibexception", ".", "PyCdlibInternalError", "(", "'SL record already initialized!'", ")", "(", "su_len", ",", "su_entry_version_unused", ",", "self", ".", "flags", ")", "=", "struct", ".", "unpack_from", "(", "'=BBB'", ",", "rrstr", "[", ":", "5", "]", ",", "2", ")", "# We assume that the caller has already checked the su_entry_version,", "# so we don't bother.", "cr_offset", "=", "5", "data_len", "=", "su_len", "-", "5", "while", "data_len", ">", "0", ":", "(", "cr_flags", ",", "len_cp", ")", "=", "struct", ".", "unpack_from", "(", "'=BB'", ",", "rrstr", "[", ":", "cr_offset", "+", "2", "]", ",", "cr_offset", ")", "data_len", "-=", "2", "cr_offset", "+=", "2", "self", ".", "symlink_components", ".", "append", "(", "self", ".", "Component", "(", "cr_flags", ",", "len_cp", ",", "rrstr", "[", "cr_offset", ":", "cr_offset", "+", "len_cp", "]", ")", ")", "# FIXME: if this is the last component in this SL record,", "# but the component continues on in the next SL record, we will", "# fail to record this bit. We should fix that.", "cr_offset", "+=", "len_cp", "data_len", "-=", "len_cp", "self", ".", "_initialized", "=", "True" ]
Parse a Rock Ridge Symbolic Link record out of a string. Parameters: rrstr - The string to parse the record out of. Returns: Nothing.
[ "Parse", "a", "Rock", "Ridge", "Symbolic", "Link", "record", "out", "of", "a", "string", "." ]
1e7b77a809e905d67dc71e12d70e850be26b6233
https://github.com/clalancette/pycdlib/blob/1e7b77a809e905d67dc71e12d70e850be26b6233/pycdlib/rockridge.py#L993-L1029
train
clalancette/pycdlib
pycdlib/rockridge.py
RRSLRecord.add_component
def add_component(self, symlink_comp): # type: (bytes) -> None ''' Add a new component to this symlink record. Parameters: symlink_comp - The string to add to this symlink record. Returns: Nothing. ''' if not self._initialized: raise pycdlibexception.PyCdlibInternalError('SL record not yet initialized!') if (self.current_length() + RRSLRecord.Component.length(symlink_comp)) > 255: raise pycdlibexception.PyCdlibInvalidInput('Symlink would be longer than 255') self.symlink_components.append(self.Component.factory(symlink_comp))
python
def add_component(self, symlink_comp): # type: (bytes) -> None ''' Add a new component to this symlink record. Parameters: symlink_comp - The string to add to this symlink record. Returns: Nothing. ''' if not self._initialized: raise pycdlibexception.PyCdlibInternalError('SL record not yet initialized!') if (self.current_length() + RRSLRecord.Component.length(symlink_comp)) > 255: raise pycdlibexception.PyCdlibInvalidInput('Symlink would be longer than 255') self.symlink_components.append(self.Component.factory(symlink_comp))
[ "def", "add_component", "(", "self", ",", "symlink_comp", ")", ":", "# type: (bytes) -> None", "if", "not", "self", ".", "_initialized", ":", "raise", "pycdlibexception", ".", "PyCdlibInternalError", "(", "'SL record not yet initialized!'", ")", "if", "(", "self", ".", "current_length", "(", ")", "+", "RRSLRecord", ".", "Component", ".", "length", "(", "symlink_comp", ")", ")", ">", "255", ":", "raise", "pycdlibexception", ".", "PyCdlibInvalidInput", "(", "'Symlink would be longer than 255'", ")", "self", ".", "symlink_components", ".", "append", "(", "self", ".", "Component", ".", "factory", "(", "symlink_comp", ")", ")" ]
Add a new component to this symlink record. Parameters: symlink_comp - The string to add to this symlink record. Returns: Nothing.
[ "Add", "a", "new", "component", "to", "this", "symlink", "record", "." ]
1e7b77a809e905d67dc71e12d70e850be26b6233
https://github.com/clalancette/pycdlib/blob/1e7b77a809e905d67dc71e12d70e850be26b6233/pycdlib/rockridge.py#L1046-L1062
train
clalancette/pycdlib
pycdlib/rockridge.py
RRSLRecord.current_length
def current_length(self): # type: () -> int ''' Calculate the current length of this symlink record. Parameters: None. Returns: Length of this symlink record. ''' if not self._initialized: raise pycdlibexception.PyCdlibInternalError('SL record not yet initialized!') strlist = [] for comp in self.symlink_components: strlist.append(comp.name()) return RRSLRecord.length(strlist)
python
def current_length(self): # type: () -> int ''' Calculate the current length of this symlink record. Parameters: None. Returns: Length of this symlink record. ''' if not self._initialized: raise pycdlibexception.PyCdlibInternalError('SL record not yet initialized!') strlist = [] for comp in self.symlink_components: strlist.append(comp.name()) return RRSLRecord.length(strlist)
[ "def", "current_length", "(", "self", ")", ":", "# type: () -> int", "if", "not", "self", ".", "_initialized", ":", "raise", "pycdlibexception", ".", "PyCdlibInternalError", "(", "'SL record not yet initialized!'", ")", "strlist", "=", "[", "]", "for", "comp", "in", "self", ".", "symlink_components", ":", "strlist", ".", "append", "(", "comp", ".", "name", "(", ")", ")", "return", "RRSLRecord", ".", "length", "(", "strlist", ")" ]
Calculate the current length of this symlink record. Parameters: None. Returns: Length of this symlink record.
[ "Calculate", "the", "current", "length", "of", "this", "symlink", "record", "." ]
1e7b77a809e905d67dc71e12d70e850be26b6233
https://github.com/clalancette/pycdlib/blob/1e7b77a809e905d67dc71e12d70e850be26b6233/pycdlib/rockridge.py#L1064-L1081
train
clalancette/pycdlib
pycdlib/rockridge.py
RRSLRecord.record
def record(self): # type: () -> bytes ''' Generate a string representing the Rock Ridge Symbolic Link record. Parameters: None. Returns: String containing the Rock Ridge record. ''' if not self._initialized: raise pycdlibexception.PyCdlibInternalError('SL record not yet initialized!') outlist = [b'SL', struct.pack('=BBB', self.current_length(), SU_ENTRY_VERSION, self.flags)] for comp in self.symlink_components: outlist.append(comp.record()) return b''.join(outlist)
python
def record(self): # type: () -> bytes ''' Generate a string representing the Rock Ridge Symbolic Link record. Parameters: None. Returns: String containing the Rock Ridge record. ''' if not self._initialized: raise pycdlibexception.PyCdlibInternalError('SL record not yet initialized!') outlist = [b'SL', struct.pack('=BBB', self.current_length(), SU_ENTRY_VERSION, self.flags)] for comp in self.symlink_components: outlist.append(comp.record()) return b''.join(outlist)
[ "def", "record", "(", "self", ")", ":", "# type: () -> bytes", "if", "not", "self", ".", "_initialized", ":", "raise", "pycdlibexception", ".", "PyCdlibInternalError", "(", "'SL record not yet initialized!'", ")", "outlist", "=", "[", "b'SL'", ",", "struct", ".", "pack", "(", "'=BBB'", ",", "self", ".", "current_length", "(", ")", ",", "SU_ENTRY_VERSION", ",", "self", ".", "flags", ")", "]", "for", "comp", "in", "self", ".", "symlink_components", ":", "outlist", ".", "append", "(", "comp", ".", "record", "(", ")", ")", "return", "b''", ".", "join", "(", "outlist", ")" ]
Generate a string representing the Rock Ridge Symbolic Link record. Parameters: None. Returns: String containing the Rock Ridge record.
[ "Generate", "a", "string", "representing", "the", "Rock", "Ridge", "Symbolic", "Link", "record", "." ]
1e7b77a809e905d67dc71e12d70e850be26b6233
https://github.com/clalancette/pycdlib/blob/1e7b77a809e905d67dc71e12d70e850be26b6233/pycdlib/rockridge.py#L1083-L1100
train
clalancette/pycdlib
pycdlib/rockridge.py
RRSLRecord.name
def name(self): # type: () -> bytes ''' Generate a string that contains all components of the symlink. Parameters: None Returns: String containing all components of the symlink. ''' if not self._initialized: raise pycdlibexception.PyCdlibInternalError('SL record not yet initialized!') outlist = [] # type: List[bytes] continued = False for comp in self.symlink_components: name = comp.name() if name == b'/': outlist = [] continued = False name = b'' if not continued: outlist.append(name) else: outlist[-1] += name continued = comp.is_continued() return b'/'.join(outlist)
python
def name(self): # type: () -> bytes ''' Generate a string that contains all components of the symlink. Parameters: None Returns: String containing all components of the symlink. ''' if not self._initialized: raise pycdlibexception.PyCdlibInternalError('SL record not yet initialized!') outlist = [] # type: List[bytes] continued = False for comp in self.symlink_components: name = comp.name() if name == b'/': outlist = [] continued = False name = b'' if not continued: outlist.append(name) else: outlist[-1] += name continued = comp.is_continued() return b'/'.join(outlist)
[ "def", "name", "(", "self", ")", ":", "# type: () -> bytes", "if", "not", "self", ".", "_initialized", ":", "raise", "pycdlibexception", ".", "PyCdlibInternalError", "(", "'SL record not yet initialized!'", ")", "outlist", "=", "[", "]", "# type: List[bytes]", "continued", "=", "False", "for", "comp", "in", "self", ".", "symlink_components", ":", "name", "=", "comp", ".", "name", "(", ")", "if", "name", "==", "b'/'", ":", "outlist", "=", "[", "]", "continued", "=", "False", "name", "=", "b''", "if", "not", "continued", ":", "outlist", ".", "append", "(", "name", ")", "else", ":", "outlist", "[", "-", "1", "]", "+=", "name", "continued", "=", "comp", ".", "is_continued", "(", ")", "return", "b'/'", ".", "join", "(", "outlist", ")" ]
Generate a string that contains all components of the symlink. Parameters: None Returns: String containing all components of the symlink.
[ "Generate", "a", "string", "that", "contains", "all", "components", "of", "the", "symlink", "." ]
1e7b77a809e905d67dc71e12d70e850be26b6233
https://github.com/clalancette/pycdlib/blob/1e7b77a809e905d67dc71e12d70e850be26b6233/pycdlib/rockridge.py#L1102-L1131
train
clalancette/pycdlib
pycdlib/rockridge.py
RRSLRecord.set_last_component_continued
def set_last_component_continued(self): # type: () -> None ''' Set the previous component of this SL record to continued. Parameters: None. Returns: Nothing. ''' if not self._initialized: raise pycdlibexception.PyCdlibInternalError('SL record not yet initialized!') if not self.symlink_components: raise pycdlibexception.PyCdlibInternalError('Trying to set continued on a non-existent component!') self.symlink_components[-1].set_continued()
python
def set_last_component_continued(self): # type: () -> None ''' Set the previous component of this SL record to continued. Parameters: None. Returns: Nothing. ''' if not self._initialized: raise pycdlibexception.PyCdlibInternalError('SL record not yet initialized!') if not self.symlink_components: raise pycdlibexception.PyCdlibInternalError('Trying to set continued on a non-existent component!') self.symlink_components[-1].set_continued()
[ "def", "set_last_component_continued", "(", "self", ")", ":", "# type: () -> None", "if", "not", "self", ".", "_initialized", ":", "raise", "pycdlibexception", ".", "PyCdlibInternalError", "(", "'SL record not yet initialized!'", ")", "if", "not", "self", ".", "symlink_components", ":", "raise", "pycdlibexception", ".", "PyCdlibInternalError", "(", "'Trying to set continued on a non-existent component!'", ")", "self", ".", "symlink_components", "[", "-", "1", "]", ".", "set_continued", "(", ")" ]
Set the previous component of this SL record to continued. Parameters: None. Returns: Nothing.
[ "Set", "the", "previous", "component", "of", "this", "SL", "record", "to", "continued", "." ]
1e7b77a809e905d67dc71e12d70e850be26b6233
https://github.com/clalancette/pycdlib/blob/1e7b77a809e905d67dc71e12d70e850be26b6233/pycdlib/rockridge.py#L1148-L1164
train
clalancette/pycdlib
pycdlib/rockridge.py
RRSLRecord.last_component_continued
def last_component_continued(self): # type: () -> bool ''' Determines whether the previous component of this SL record is a continued one or not. Parameters: None. Returns: True if the previous component of this SL record is continued, False otherwise. ''' if not self._initialized: raise pycdlibexception.PyCdlibInternalError('SL record not yet initialized!') if not self.symlink_components: raise pycdlibexception.PyCdlibInternalError('Trying to get continued on a non-existent component!') return self.symlink_components[-1].is_continued()
python
def last_component_continued(self): # type: () -> bool ''' Determines whether the previous component of this SL record is a continued one or not. Parameters: None. Returns: True if the previous component of this SL record is continued, False otherwise. ''' if not self._initialized: raise pycdlibexception.PyCdlibInternalError('SL record not yet initialized!') if not self.symlink_components: raise pycdlibexception.PyCdlibInternalError('Trying to get continued on a non-existent component!') return self.symlink_components[-1].is_continued()
[ "def", "last_component_continued", "(", "self", ")", ":", "# type: () -> bool", "if", "not", "self", ".", "_initialized", ":", "raise", "pycdlibexception", ".", "PyCdlibInternalError", "(", "'SL record not yet initialized!'", ")", "if", "not", "self", ".", "symlink_components", ":", "raise", "pycdlibexception", ".", "PyCdlibInternalError", "(", "'Trying to get continued on a non-existent component!'", ")", "return", "self", ".", "symlink_components", "[", "-", "1", "]", ".", "is_continued", "(", ")" ]
Determines whether the previous component of this SL record is a continued one or not. Parameters: None. Returns: True if the previous component of this SL record is continued, False otherwise.
[ "Determines", "whether", "the", "previous", "component", "of", "this", "SL", "record", "is", "a", "continued", "one", "or", "not", "." ]
1e7b77a809e905d67dc71e12d70e850be26b6233
https://github.com/clalancette/pycdlib/blob/1e7b77a809e905d67dc71e12d70e850be26b6233/pycdlib/rockridge.py#L1166-L1183
train
clalancette/pycdlib
pycdlib/rockridge.py
RRSLRecord.length
def length(symlink_components): # type: (List[bytes]) -> int ''' Static method to return the length of the Rock Ridge Symbolic Link record. Parameters: symlink_components - A list containing a string for each of the symbolic link components. Returns: The length of this record in bytes. ''' length = RRSLRecord.header_length() for comp in symlink_components: length += RRSLRecord.Component.length(comp) return length
python
def length(symlink_components): # type: (List[bytes]) -> int ''' Static method to return the length of the Rock Ridge Symbolic Link record. Parameters: symlink_components - A list containing a string for each of the symbolic link components. Returns: The length of this record in bytes. ''' length = RRSLRecord.header_length() for comp in symlink_components: length += RRSLRecord.Component.length(comp) return length
[ "def", "length", "(", "symlink_components", ")", ":", "# type: (List[bytes]) -> int", "length", "=", "RRSLRecord", ".", "header_length", "(", ")", "for", "comp", "in", "symlink_components", ":", "length", "+=", "RRSLRecord", ".", "Component", ".", "length", "(", "comp", ")", "return", "length" ]
Static method to return the length of the Rock Ridge Symbolic Link record. Parameters: symlink_components - A list containing a string for each of the symbolic link components. Returns: The length of this record in bytes.
[ "Static", "method", "to", "return", "the", "length", "of", "the", "Rock", "Ridge", "Symbolic", "Link", "record", "." ]
1e7b77a809e905d67dc71e12d70e850be26b6233
https://github.com/clalancette/pycdlib/blob/1e7b77a809e905d67dc71e12d70e850be26b6233/pycdlib/rockridge.py#L1209-L1224
train
clalancette/pycdlib
pycdlib/rockridge.py
RRNMRecord.parse
def parse(self, rrstr): # type: (bytes) -> None ''' Parse a Rock Ridge Alternate Name record out of a string. Parameters: rrstr - The string to parse the record out of. Returns: Nothing. ''' if self._initialized: raise pycdlibexception.PyCdlibInternalError('NM record already initialized!') (su_len, su_entry_version_unused, self.posix_name_flags) = struct.unpack_from('=BBB', rrstr[:5], 2) # We assume that the caller has already checked the su_entry_version, # so we don't bother. name_len = su_len - 5 if (self.posix_name_flags & 0x7) not in (0, 1, 2, 4): raise pycdlibexception.PyCdlibInvalidISO('Invalid Rock Ridge NM flags') if name_len != 0: if (self.posix_name_flags & (1 << 1)) or (self.posix_name_flags & (1 << 2)) or (self.posix_name_flags & (1 << 5)): raise pycdlibexception.PyCdlibInvalidISO('Invalid name in Rock Ridge NM entry (0x%x %d)' % (self.posix_name_flags, name_len)) self.posix_name += rrstr[5:5 + name_len] self._initialized = True
python
def parse(self, rrstr): # type: (bytes) -> None ''' Parse a Rock Ridge Alternate Name record out of a string. Parameters: rrstr - The string to parse the record out of. Returns: Nothing. ''' if self._initialized: raise pycdlibexception.PyCdlibInternalError('NM record already initialized!') (su_len, su_entry_version_unused, self.posix_name_flags) = struct.unpack_from('=BBB', rrstr[:5], 2) # We assume that the caller has already checked the su_entry_version, # so we don't bother. name_len = su_len - 5 if (self.posix_name_flags & 0x7) not in (0, 1, 2, 4): raise pycdlibexception.PyCdlibInvalidISO('Invalid Rock Ridge NM flags') if name_len != 0: if (self.posix_name_flags & (1 << 1)) or (self.posix_name_flags & (1 << 2)) or (self.posix_name_flags & (1 << 5)): raise pycdlibexception.PyCdlibInvalidISO('Invalid name in Rock Ridge NM entry (0x%x %d)' % (self.posix_name_flags, name_len)) self.posix_name += rrstr[5:5 + name_len] self._initialized = True
[ "def", "parse", "(", "self", ",", "rrstr", ")", ":", "# type: (bytes) -> None", "if", "self", ".", "_initialized", ":", "raise", "pycdlibexception", ".", "PyCdlibInternalError", "(", "'NM record already initialized!'", ")", "(", "su_len", ",", "su_entry_version_unused", ",", "self", ".", "posix_name_flags", ")", "=", "struct", ".", "unpack_from", "(", "'=BBB'", ",", "rrstr", "[", ":", "5", "]", ",", "2", ")", "# We assume that the caller has already checked the su_entry_version,", "# so we don't bother.", "name_len", "=", "su_len", "-", "5", "if", "(", "self", ".", "posix_name_flags", "&", "0x7", ")", "not", "in", "(", "0", ",", "1", ",", "2", ",", "4", ")", ":", "raise", "pycdlibexception", ".", "PyCdlibInvalidISO", "(", "'Invalid Rock Ridge NM flags'", ")", "if", "name_len", "!=", "0", ":", "if", "(", "self", ".", "posix_name_flags", "&", "(", "1", "<<", "1", ")", ")", "or", "(", "self", ".", "posix_name_flags", "&", "(", "1", "<<", "2", ")", ")", "or", "(", "self", ".", "posix_name_flags", "&", "(", "1", "<<", "5", ")", ")", ":", "raise", "pycdlibexception", ".", "PyCdlibInvalidISO", "(", "'Invalid name in Rock Ridge NM entry (0x%x %d)'", "%", "(", "self", ".", "posix_name_flags", ",", "name_len", ")", ")", "self", ".", "posix_name", "+=", "rrstr", "[", "5", ":", "5", "+", "name_len", "]", "self", ".", "_initialized", "=", "True" ]
Parse a Rock Ridge Alternate Name record out of a string. Parameters: rrstr - The string to parse the record out of. Returns: Nothing.
[ "Parse", "a", "Rock", "Ridge", "Alternate", "Name", "record", "out", "of", "a", "string", "." ]
1e7b77a809e905d67dc71e12d70e850be26b6233
https://github.com/clalancette/pycdlib/blob/1e7b77a809e905d67dc71e12d70e850be26b6233/pycdlib/rockridge.py#L1239-L1266
train
clalancette/pycdlib
pycdlib/rockridge.py
RRNMRecord.new
def new(self, rr_name): # type: (bytes) -> None ''' Create a new Rock Ridge Alternate Name record. Parameters: rr_name - The name for the new record. Returns: Nothing. ''' if self._initialized: raise pycdlibexception.PyCdlibInternalError('NM record already initialized!') self.posix_name = rr_name self.posix_name_flags = 0 self._initialized = True
python
def new(self, rr_name): # type: (bytes) -> None ''' Create a new Rock Ridge Alternate Name record. Parameters: rr_name - The name for the new record. Returns: Nothing. ''' if self._initialized: raise pycdlibexception.PyCdlibInternalError('NM record already initialized!') self.posix_name = rr_name self.posix_name_flags = 0 self._initialized = True
[ "def", "new", "(", "self", ",", "rr_name", ")", ":", "# type: (bytes) -> None", "if", "self", ".", "_initialized", ":", "raise", "pycdlibexception", ".", "PyCdlibInternalError", "(", "'NM record already initialized!'", ")", "self", ".", "posix_name", "=", "rr_name", "self", ".", "posix_name_flags", "=", "0", "self", ".", "_initialized", "=", "True" ]
Create a new Rock Ridge Alternate Name record. Parameters: rr_name - The name for the new record. Returns: Nothing.
[ "Create", "a", "new", "Rock", "Ridge", "Alternate", "Name", "record", "." ]
1e7b77a809e905d67dc71e12d70e850be26b6233
https://github.com/clalancette/pycdlib/blob/1e7b77a809e905d67dc71e12d70e850be26b6233/pycdlib/rockridge.py#L1268-L1284
train
clalancette/pycdlib
pycdlib/rockridge.py
RRNMRecord.record
def record(self): # type: () -> bytes ''' Generate a string representing the Rock Ridge Alternate Name record. Parameters: None. Returns: String containing the Rock Ridge record. ''' if not self._initialized: raise pycdlibexception.PyCdlibInternalError('NM record not yet initialized!') return b'NM' + struct.pack(b'=BBB', RRNMRecord.length(self.posix_name), SU_ENTRY_VERSION, self.posix_name_flags) + self.posix_name
python
def record(self): # type: () -> bytes ''' Generate a string representing the Rock Ridge Alternate Name record. Parameters: None. Returns: String containing the Rock Ridge record. ''' if not self._initialized: raise pycdlibexception.PyCdlibInternalError('NM record not yet initialized!') return b'NM' + struct.pack(b'=BBB', RRNMRecord.length(self.posix_name), SU_ENTRY_VERSION, self.posix_name_flags) + self.posix_name
[ "def", "record", "(", "self", ")", ":", "# type: () -> bytes", "if", "not", "self", ".", "_initialized", ":", "raise", "pycdlibexception", ".", "PyCdlibInternalError", "(", "'NM record not yet initialized!'", ")", "return", "b'NM'", "+", "struct", ".", "pack", "(", "b'=BBB'", ",", "RRNMRecord", ".", "length", "(", "self", ".", "posix_name", ")", ",", "SU_ENTRY_VERSION", ",", "self", ".", "posix_name_flags", ")", "+", "self", ".", "posix_name" ]
Generate a string representing the Rock Ridge Alternate Name record. Parameters: None. Returns: String containing the Rock Ridge record.
[ "Generate", "a", "string", "representing", "the", "Rock", "Ridge", "Alternate", "Name", "record", "." ]
1e7b77a809e905d67dc71e12d70e850be26b6233
https://github.com/clalancette/pycdlib/blob/1e7b77a809e905d67dc71e12d70e850be26b6233/pycdlib/rockridge.py#L1286-L1299
train
clalancette/pycdlib
pycdlib/rockridge.py
RRCLRecord.parse
def parse(self, rrstr): # type: (bytes) -> None ''' Parse a Rock Ridge Child Link record out of a string. Parameters: rrstr - The string to parse the record out of. Returns: Nothing. ''' if self._initialized: raise pycdlibexception.PyCdlibInternalError('CL record already initialized!') # We assume that the caller has already checked the su_entry_version, # so we don't bother. (su_len, su_entry_version_unused, child_log_block_num_le, child_log_block_num_be) = struct.unpack_from('=BBLL', rrstr[:12], 2) if su_len != RRCLRecord.length(): raise pycdlibexception.PyCdlibInvalidISO('Invalid length on rock ridge extension') if child_log_block_num_le != utils.swab_32bit(child_log_block_num_be): raise pycdlibexception.PyCdlibInvalidISO('Little endian block num does not equal big endian; corrupt ISO') self.child_log_block_num = child_log_block_num_le self._initialized = True
python
def parse(self, rrstr): # type: (bytes) -> None ''' Parse a Rock Ridge Child Link record out of a string. Parameters: rrstr - The string to parse the record out of. Returns: Nothing. ''' if self._initialized: raise pycdlibexception.PyCdlibInternalError('CL record already initialized!') # We assume that the caller has already checked the su_entry_version, # so we don't bother. (su_len, su_entry_version_unused, child_log_block_num_le, child_log_block_num_be) = struct.unpack_from('=BBLL', rrstr[:12], 2) if su_len != RRCLRecord.length(): raise pycdlibexception.PyCdlibInvalidISO('Invalid length on rock ridge extension') if child_log_block_num_le != utils.swab_32bit(child_log_block_num_be): raise pycdlibexception.PyCdlibInvalidISO('Little endian block num does not equal big endian; corrupt ISO') self.child_log_block_num = child_log_block_num_le self._initialized = True
[ "def", "parse", "(", "self", ",", "rrstr", ")", ":", "# type: (bytes) -> None", "if", "self", ".", "_initialized", ":", "raise", "pycdlibexception", ".", "PyCdlibInternalError", "(", "'CL record already initialized!'", ")", "# We assume that the caller has already checked the su_entry_version,", "# so we don't bother.", "(", "su_len", ",", "su_entry_version_unused", ",", "child_log_block_num_le", ",", "child_log_block_num_be", ")", "=", "struct", ".", "unpack_from", "(", "'=BBLL'", ",", "rrstr", "[", ":", "12", "]", ",", "2", ")", "if", "su_len", "!=", "RRCLRecord", ".", "length", "(", ")", ":", "raise", "pycdlibexception", ".", "PyCdlibInvalidISO", "(", "'Invalid length on rock ridge extension'", ")", "if", "child_log_block_num_le", "!=", "utils", ".", "swab_32bit", "(", "child_log_block_num_be", ")", ":", "raise", "pycdlibexception", ".", "PyCdlibInvalidISO", "(", "'Little endian block num does not equal big endian; corrupt ISO'", ")", "self", ".", "child_log_block_num", "=", "child_log_block_num_le", "self", ".", "_initialized", "=", "True" ]
Parse a Rock Ridge Child Link record out of a string. Parameters: rrstr - The string to parse the record out of. Returns: Nothing.
[ "Parse", "a", "Rock", "Ridge", "Child", "Link", "record", "out", "of", "a", "string", "." ]
1e7b77a809e905d67dc71e12d70e850be26b6233
https://github.com/clalancette/pycdlib/blob/1e7b77a809e905d67dc71e12d70e850be26b6233/pycdlib/rockridge.py#L1344-L1368
train
clalancette/pycdlib
pycdlib/rockridge.py
RRCLRecord.new
def new(self): # type: () -> None ''' Create a new Rock Ridge Child Link record. Parameters: None. Returns: Nothing. ''' if self._initialized: raise pycdlibexception.PyCdlibInternalError('CL record already initialized!') self.child_log_block_num = 0 # This gets set later self._initialized = True
python
def new(self): # type: () -> None ''' Create a new Rock Ridge Child Link record. Parameters: None. Returns: Nothing. ''' if self._initialized: raise pycdlibexception.PyCdlibInternalError('CL record already initialized!') self.child_log_block_num = 0 # This gets set later self._initialized = True
[ "def", "new", "(", "self", ")", ":", "# type: () -> None", "if", "self", ".", "_initialized", ":", "raise", "pycdlibexception", ".", "PyCdlibInternalError", "(", "'CL record already initialized!'", ")", "self", ".", "child_log_block_num", "=", "0", "# This gets set later", "self", ".", "_initialized", "=", "True" ]
Create a new Rock Ridge Child Link record. Parameters: None. Returns: Nothing.
[ "Create", "a", "new", "Rock", "Ridge", "Child", "Link", "record", "." ]
1e7b77a809e905d67dc71e12d70e850be26b6233
https://github.com/clalancette/pycdlib/blob/1e7b77a809e905d67dc71e12d70e850be26b6233/pycdlib/rockridge.py#L1370-L1385
train
clalancette/pycdlib
pycdlib/rockridge.py
RRCLRecord.set_log_block_num
def set_log_block_num(self, bl): # type: (int) -> None ''' Set the logical block number for the child. Parameters: bl - Logical block number of the child. Returns: Nothing. ''' if not self._initialized: raise pycdlibexception.PyCdlibInternalError('CL record not yet initialized!') self.child_log_block_num = bl
python
def set_log_block_num(self, bl): # type: (int) -> None ''' Set the logical block number for the child. Parameters: bl - Logical block number of the child. Returns: Nothing. ''' if not self._initialized: raise pycdlibexception.PyCdlibInternalError('CL record not yet initialized!') self.child_log_block_num = bl
[ "def", "set_log_block_num", "(", "self", ",", "bl", ")", ":", "# type: (int) -> None", "if", "not", "self", ".", "_initialized", ":", "raise", "pycdlibexception", ".", "PyCdlibInternalError", "(", "'CL record not yet initialized!'", ")", "self", ".", "child_log_block_num", "=", "bl" ]
Set the logical block number for the child. Parameters: bl - Logical block number of the child. Returns: Nothing.
[ "Set", "the", "logical", "block", "number", "for", "the", "child", "." ]
1e7b77a809e905d67dc71e12d70e850be26b6233
https://github.com/clalancette/pycdlib/blob/1e7b77a809e905d67dc71e12d70e850be26b6233/pycdlib/rockridge.py#L1402-L1415
train
clalancette/pycdlib
pycdlib/rockridge.py
RRPLRecord.parse
def parse(self, rrstr): # type: (bytes) -> None ''' Parse a Rock Ridge Parent Link record out of a string. Parameters: rrstr - The string to parse the record out of. Returns: Nothing. ''' if self._initialized: raise pycdlibexception.PyCdlibInternalError('PL record already initialized!') # We assume that the caller has already checked the su_entry_version, # so we don't bother. (su_len, su_entry_version_unused, parent_log_block_num_le, parent_log_block_num_be) = struct.unpack_from('=BBLL', rrstr[:12], 2) if su_len != RRPLRecord.length(): raise pycdlibexception.PyCdlibInvalidISO('Invalid length on rock ridge extension') if parent_log_block_num_le != utils.swab_32bit(parent_log_block_num_be): raise pycdlibexception.PyCdlibInvalidISO('Little endian block num does not equal big endian; corrupt ISO') self.parent_log_block_num = parent_log_block_num_le self._initialized = True
python
def parse(self, rrstr): # type: (bytes) -> None ''' Parse a Rock Ridge Parent Link record out of a string. Parameters: rrstr - The string to parse the record out of. Returns: Nothing. ''' if self._initialized: raise pycdlibexception.PyCdlibInternalError('PL record already initialized!') # We assume that the caller has already checked the su_entry_version, # so we don't bother. (su_len, su_entry_version_unused, parent_log_block_num_le, parent_log_block_num_be) = struct.unpack_from('=BBLL', rrstr[:12], 2) if su_len != RRPLRecord.length(): raise pycdlibexception.PyCdlibInvalidISO('Invalid length on rock ridge extension') if parent_log_block_num_le != utils.swab_32bit(parent_log_block_num_be): raise pycdlibexception.PyCdlibInvalidISO('Little endian block num does not equal big endian; corrupt ISO') self.parent_log_block_num = parent_log_block_num_le self._initialized = True
[ "def", "parse", "(", "self", ",", "rrstr", ")", ":", "# type: (bytes) -> None", "if", "self", ".", "_initialized", ":", "raise", "pycdlibexception", ".", "PyCdlibInternalError", "(", "'PL record already initialized!'", ")", "# We assume that the caller has already checked the su_entry_version,", "# so we don't bother.", "(", "su_len", ",", "su_entry_version_unused", ",", "parent_log_block_num_le", ",", "parent_log_block_num_be", ")", "=", "struct", ".", "unpack_from", "(", "'=BBLL'", ",", "rrstr", "[", ":", "12", "]", ",", "2", ")", "if", "su_len", "!=", "RRPLRecord", ".", "length", "(", ")", ":", "raise", "pycdlibexception", ".", "PyCdlibInvalidISO", "(", "'Invalid length on rock ridge extension'", ")", "if", "parent_log_block_num_le", "!=", "utils", ".", "swab_32bit", "(", "parent_log_block_num_be", ")", ":", "raise", "pycdlibexception", ".", "PyCdlibInvalidISO", "(", "'Little endian block num does not equal big endian; corrupt ISO'", ")", "self", ".", "parent_log_block_num", "=", "parent_log_block_num_le", "self", ".", "_initialized", "=", "True" ]
Parse a Rock Ridge Parent Link record out of a string. Parameters: rrstr - The string to parse the record out of. Returns: Nothing.
[ "Parse", "a", "Rock", "Ridge", "Parent", "Link", "record", "out", "of", "a", "string", "." ]
1e7b77a809e905d67dc71e12d70e850be26b6233
https://github.com/clalancette/pycdlib/blob/1e7b77a809e905d67dc71e12d70e850be26b6233/pycdlib/rockridge.py#L1445-L1468
train
clalancette/pycdlib
pycdlib/rockridge.py
RRPLRecord.new
def new(self): # type: () -> None ''' Generate a string representing the Rock Ridge Parent Link record. Parameters: None. Returns: String containing the Rock Ridge record. ''' if self._initialized: raise pycdlibexception.PyCdlibInternalError('PL record already initialized!') self.parent_log_block_num = 0 # This will get set later self._initialized = True
python
def new(self): # type: () -> None ''' Generate a string representing the Rock Ridge Parent Link record. Parameters: None. Returns: String containing the Rock Ridge record. ''' if self._initialized: raise pycdlibexception.PyCdlibInternalError('PL record already initialized!') self.parent_log_block_num = 0 # This will get set later self._initialized = True
[ "def", "new", "(", "self", ")", ":", "# type: () -> None", "if", "self", ".", "_initialized", ":", "raise", "pycdlibexception", ".", "PyCdlibInternalError", "(", "'PL record already initialized!'", ")", "self", ".", "parent_log_block_num", "=", "0", "# This will get set later", "self", ".", "_initialized", "=", "True" ]
Generate a string representing the Rock Ridge Parent Link record. Parameters: None. Returns: String containing the Rock Ridge record.
[ "Generate", "a", "string", "representing", "the", "Rock", "Ridge", "Parent", "Link", "record", "." ]
1e7b77a809e905d67dc71e12d70e850be26b6233
https://github.com/clalancette/pycdlib/blob/1e7b77a809e905d67dc71e12d70e850be26b6233/pycdlib/rockridge.py#L1470-L1485
train
clalancette/pycdlib
pycdlib/rockridge.py
RRPLRecord.set_log_block_num
def set_log_block_num(self, bl): # type: (int) -> None ''' Set the logical block number for the parent. Parameters: bl - Logical block number of the parent. Returns: Nothing. ''' if not self._initialized: raise pycdlibexception.PyCdlibInternalError('PL record not yet initialized!') self.parent_log_block_num = bl
python
def set_log_block_num(self, bl): # type: (int) -> None ''' Set the logical block number for the parent. Parameters: bl - Logical block number of the parent. Returns: Nothing. ''' if not self._initialized: raise pycdlibexception.PyCdlibInternalError('PL record not yet initialized!') self.parent_log_block_num = bl
[ "def", "set_log_block_num", "(", "self", ",", "bl", ")", ":", "# type: (int) -> None", "if", "not", "self", ".", "_initialized", ":", "raise", "pycdlibexception", ".", "PyCdlibInternalError", "(", "'PL record not yet initialized!'", ")", "self", ".", "parent_log_block_num", "=", "bl" ]
Set the logical block number for the parent. Parameters: bl - Logical block number of the parent. Returns: Nothing.
[ "Set", "the", "logical", "block", "number", "for", "the", "parent", "." ]
1e7b77a809e905d67dc71e12d70e850be26b6233
https://github.com/clalancette/pycdlib/blob/1e7b77a809e905d67dc71e12d70e850be26b6233/pycdlib/rockridge.py#L1502-L1515
train
clalancette/pycdlib
pycdlib/rockridge.py
RRTFRecord.parse
def parse(self, rrstr): # type: (bytes) -> None ''' Parse a Rock Ridge Time Stamp record out of a string. Parameters: rrstr - The string to parse the record out of. Returns: Nothing. ''' if self._initialized: raise pycdlibexception.PyCdlibInternalError('TF record already initialized!') # We assume that the caller has already checked the su_entry_version, # so we don't bother. (su_len, su_entry_version_unused, self.time_flags,) = struct.unpack_from('=BBB', rrstr[:5], 2) if su_len < 5: raise pycdlibexception.PyCdlibInvalidISO('Not enough bytes in the TF record') tflen = 7 if self.time_flags & (1 << 7): tflen = 17 offset = 5 for index, fieldname in enumerate(self.FIELDNAMES): if self.time_flags & (1 << index): if tflen == 7: setattr(self, fieldname, dates.DirectoryRecordDate()) elif tflen == 17: setattr(self, fieldname, dates.VolumeDescriptorDate()) getattr(self, fieldname).parse(rrstr[offset:offset + tflen]) offset += tflen self._initialized = True
python
def parse(self, rrstr): # type: (bytes) -> None ''' Parse a Rock Ridge Time Stamp record out of a string. Parameters: rrstr - The string to parse the record out of. Returns: Nothing. ''' if self._initialized: raise pycdlibexception.PyCdlibInternalError('TF record already initialized!') # We assume that the caller has already checked the su_entry_version, # so we don't bother. (su_len, su_entry_version_unused, self.time_flags,) = struct.unpack_from('=BBB', rrstr[:5], 2) if su_len < 5: raise pycdlibexception.PyCdlibInvalidISO('Not enough bytes in the TF record') tflen = 7 if self.time_flags & (1 << 7): tflen = 17 offset = 5 for index, fieldname in enumerate(self.FIELDNAMES): if self.time_flags & (1 << index): if tflen == 7: setattr(self, fieldname, dates.DirectoryRecordDate()) elif tflen == 17: setattr(self, fieldname, dates.VolumeDescriptorDate()) getattr(self, fieldname).parse(rrstr[offset:offset + tflen]) offset += tflen self._initialized = True
[ "def", "parse", "(", "self", ",", "rrstr", ")", ":", "# type: (bytes) -> None", "if", "self", ".", "_initialized", ":", "raise", "pycdlibexception", ".", "PyCdlibInternalError", "(", "'TF record already initialized!'", ")", "# We assume that the caller has already checked the su_entry_version,", "# so we don't bother.", "(", "su_len", ",", "su_entry_version_unused", ",", "self", ".", "time_flags", ",", ")", "=", "struct", ".", "unpack_from", "(", "'=BBB'", ",", "rrstr", "[", ":", "5", "]", ",", "2", ")", "if", "su_len", "<", "5", ":", "raise", "pycdlibexception", ".", "PyCdlibInvalidISO", "(", "'Not enough bytes in the TF record'", ")", "tflen", "=", "7", "if", "self", ".", "time_flags", "&", "(", "1", "<<", "7", ")", ":", "tflen", "=", "17", "offset", "=", "5", "for", "index", ",", "fieldname", "in", "enumerate", "(", "self", ".", "FIELDNAMES", ")", ":", "if", "self", ".", "time_flags", "&", "(", "1", "<<", "index", ")", ":", "if", "tflen", "==", "7", ":", "setattr", "(", "self", ",", "fieldname", ",", "dates", ".", "DirectoryRecordDate", "(", ")", ")", "elif", "tflen", "==", "17", ":", "setattr", "(", "self", ",", "fieldname", ",", "dates", ".", "VolumeDescriptorDate", "(", ")", ")", "getattr", "(", "self", ",", "fieldname", ")", ".", "parse", "(", "rrstr", "[", "offset", ":", "offset", "+", "tflen", "]", ")", "offset", "+=", "tflen", "self", ".", "_initialized", "=", "True" ]
Parse a Rock Ridge Time Stamp record out of a string. Parameters: rrstr - The string to parse the record out of. Returns: Nothing.
[ "Parse", "a", "Rock", "Ridge", "Time", "Stamp", "record", "out", "of", "a", "string", "." ]
1e7b77a809e905d67dc71e12d70e850be26b6233
https://github.com/clalancette/pycdlib/blob/1e7b77a809e905d67dc71e12d70e850be26b6233/pycdlib/rockridge.py#L1558-L1592
train
clalancette/pycdlib
pycdlib/rockridge.py
RRTFRecord.new
def new(self, time_flags): # type: (int) -> None ''' Create a new Rock Ridge Time Stamp record. Parameters: time_flags - The flags to use for this time stamp record. Returns: Nothing. ''' if self._initialized: raise pycdlibexception.PyCdlibInternalError('TF record already initialized!') self.time_flags = time_flags tflen = 7 if self.time_flags & (1 << 7): tflen = 17 for index, fieldname in enumerate(self.FIELDNAMES): if self.time_flags & (1 << index): if tflen == 7: setattr(self, fieldname, dates.DirectoryRecordDate()) elif tflen == 17: setattr(self, fieldname, dates.VolumeDescriptorDate()) getattr(self, fieldname).new() self._initialized = True
python
def new(self, time_flags): # type: (int) -> None ''' Create a new Rock Ridge Time Stamp record. Parameters: time_flags - The flags to use for this time stamp record. Returns: Nothing. ''' if self._initialized: raise pycdlibexception.PyCdlibInternalError('TF record already initialized!') self.time_flags = time_flags tflen = 7 if self.time_flags & (1 << 7): tflen = 17 for index, fieldname in enumerate(self.FIELDNAMES): if self.time_flags & (1 << index): if tflen == 7: setattr(self, fieldname, dates.DirectoryRecordDate()) elif tflen == 17: setattr(self, fieldname, dates.VolumeDescriptorDate()) getattr(self, fieldname).new() self._initialized = True
[ "def", "new", "(", "self", ",", "time_flags", ")", ":", "# type: (int) -> None", "if", "self", ".", "_initialized", ":", "raise", "pycdlibexception", ".", "PyCdlibInternalError", "(", "'TF record already initialized!'", ")", "self", ".", "time_flags", "=", "time_flags", "tflen", "=", "7", "if", "self", ".", "time_flags", "&", "(", "1", "<<", "7", ")", ":", "tflen", "=", "17", "for", "index", ",", "fieldname", "in", "enumerate", "(", "self", ".", "FIELDNAMES", ")", ":", "if", "self", ".", "time_flags", "&", "(", "1", "<<", "index", ")", ":", "if", "tflen", "==", "7", ":", "setattr", "(", "self", ",", "fieldname", ",", "dates", ".", "DirectoryRecordDate", "(", ")", ")", "elif", "tflen", "==", "17", ":", "setattr", "(", "self", ",", "fieldname", ",", "dates", ".", "VolumeDescriptorDate", "(", ")", ")", "getattr", "(", "self", ",", "fieldname", ")", ".", "new", "(", ")", "self", ".", "_initialized", "=", "True" ]
Create a new Rock Ridge Time Stamp record. Parameters: time_flags - The flags to use for this time stamp record. Returns: Nothing.
[ "Create", "a", "new", "Rock", "Ridge", "Time", "Stamp", "record", "." ]
1e7b77a809e905d67dc71e12d70e850be26b6233
https://github.com/clalancette/pycdlib/blob/1e7b77a809e905d67dc71e12d70e850be26b6233/pycdlib/rockridge.py#L1594-L1621
train
clalancette/pycdlib
pycdlib/rockridge.py
RRTFRecord.record
def record(self): # type: () -> bytes ''' Generate a string representing the Rock Ridge Time Stamp record. Parameters: None. Returns: String containing the Rock Ridge record. ''' if not self._initialized: raise pycdlibexception.PyCdlibInternalError('TF record not yet initialized!') outlist = [b'TF', struct.pack('=BBB', RRTFRecord.length(self.time_flags), SU_ENTRY_VERSION, self.time_flags)] for fieldname in self.FIELDNAMES: field = getattr(self, fieldname) if field is not None: outlist.append(field.record()) return b''.join(outlist)
python
def record(self): # type: () -> bytes ''' Generate a string representing the Rock Ridge Time Stamp record. Parameters: None. Returns: String containing the Rock Ridge record. ''' if not self._initialized: raise pycdlibexception.PyCdlibInternalError('TF record not yet initialized!') outlist = [b'TF', struct.pack('=BBB', RRTFRecord.length(self.time_flags), SU_ENTRY_VERSION, self.time_flags)] for fieldname in self.FIELDNAMES: field = getattr(self, fieldname) if field is not None: outlist.append(field.record()) return b''.join(outlist)
[ "def", "record", "(", "self", ")", ":", "# type: () -> bytes", "if", "not", "self", ".", "_initialized", ":", "raise", "pycdlibexception", ".", "PyCdlibInternalError", "(", "'TF record not yet initialized!'", ")", "outlist", "=", "[", "b'TF'", ",", "struct", ".", "pack", "(", "'=BBB'", ",", "RRTFRecord", ".", "length", "(", "self", ".", "time_flags", ")", ",", "SU_ENTRY_VERSION", ",", "self", ".", "time_flags", ")", "]", "for", "fieldname", "in", "self", ".", "FIELDNAMES", ":", "field", "=", "getattr", "(", "self", ",", "fieldname", ")", "if", "field", "is", "not", "None", ":", "outlist", ".", "append", "(", "field", ".", "record", "(", ")", ")", "return", "b''", ".", "join", "(", "outlist", ")" ]
Generate a string representing the Rock Ridge Time Stamp record. Parameters: None. Returns: String containing the Rock Ridge record.
[ "Generate", "a", "string", "representing", "the", "Rock", "Ridge", "Time", "Stamp", "record", "." ]
1e7b77a809e905d67dc71e12d70e850be26b6233
https://github.com/clalancette/pycdlib/blob/1e7b77a809e905d67dc71e12d70e850be26b6233/pycdlib/rockridge.py#L1623-L1642
train
clalancette/pycdlib
pycdlib/rockridge.py
RRTFRecord.length
def length(time_flags): # type: (int) -> int ''' Static method to return the length of the Rock Ridge Time Stamp record. Parameters: time_flags - Integer representing the flags to use. Returns: The length of this record in bytes. ''' tf_each_size = 7 if time_flags & (1 << 7): tf_each_size = 17 time_flags &= 0x7f tf_num = 0 while time_flags: time_flags &= time_flags - 1 tf_num += 1 return 5 + tf_each_size * tf_num
python
def length(time_flags): # type: (int) -> int ''' Static method to return the length of the Rock Ridge Time Stamp record. Parameters: time_flags - Integer representing the flags to use. Returns: The length of this record in bytes. ''' tf_each_size = 7 if time_flags & (1 << 7): tf_each_size = 17 time_flags &= 0x7f tf_num = 0 while time_flags: time_flags &= time_flags - 1 tf_num += 1 return 5 + tf_each_size * tf_num
[ "def", "length", "(", "time_flags", ")", ":", "# type: (int) -> int", "tf_each_size", "=", "7", "if", "time_flags", "&", "(", "1", "<<", "7", ")", ":", "tf_each_size", "=", "17", "time_flags", "&=", "0x7f", "tf_num", "=", "0", "while", "time_flags", ":", "time_flags", "&=", "time_flags", "-", "1", "tf_num", "+=", "1", "return", "5", "+", "tf_each_size", "*", "tf_num" ]
Static method to return the length of the Rock Ridge Time Stamp record. Parameters: time_flags - Integer representing the flags to use. Returns: The length of this record in bytes.
[ "Static", "method", "to", "return", "the", "length", "of", "the", "Rock", "Ridge", "Time", "Stamp", "record", "." ]
1e7b77a809e905d67dc71e12d70e850be26b6233
https://github.com/clalancette/pycdlib/blob/1e7b77a809e905d67dc71e12d70e850be26b6233/pycdlib/rockridge.py#L1645-L1665
train
clalancette/pycdlib
pycdlib/rockridge.py
RRSFRecord.parse
def parse(self, rrstr): # type: (bytes) -> None ''' Parse a Rock Ridge Sparse File record out of a string. Parameters: rrstr - The string to parse the record out of. Returns: Nothing. ''' if self._initialized: raise pycdlibexception.PyCdlibInternalError('SF record already initialized!') # We assume that the caller has already checked the su_entry_version, # so we don't bother. (su_len, su_entry_version_unused,) = struct.unpack_from('=BB', rrstr[:4], 2) if su_len == 12: # This is a Rock Ridge version 1.10 SF Record, which is 12 bytes. (virtual_file_size_le, virtual_file_size_be) = struct.unpack_from('=LL', rrstr[:12], 4) if virtual_file_size_le != utils.swab_32bit(virtual_file_size_be): raise pycdlibexception.PyCdlibInvalidISO('Virtual file size little-endian does not match big-endian') self.virtual_file_size_low = virtual_file_size_le elif su_len == 21: # This is a Rock Ridge version 1.12 SF Record, which is 21 bytes. (virtual_file_size_high_le, virtual_file_size_high_be, virtual_file_size_low_le, virtual_file_size_low_be, self.table_depth) = struct.unpack_from('=LLLLB', rrstr[:21], 4) if virtual_file_size_high_le != utils.swab_32bit(virtual_file_size_high_be): raise pycdlibexception.PyCdlibInvalidISO('Virtual file size high little-endian does not match big-endian') if virtual_file_size_low_le != utils.swab_32bit(virtual_file_size_low_be): raise pycdlibexception.PyCdlibInvalidISO('Virtual file size low little-endian does not match big-endian') self.virtual_file_size_low = virtual_file_size_low_le self.virtual_file_size_high = virtual_file_size_high_le else: raise pycdlibexception.PyCdlibInvalidISO('Invalid length on Rock Ridge SF record (expected 12 or 21)') self._initialized = True
python
def parse(self, rrstr): # type: (bytes) -> None ''' Parse a Rock Ridge Sparse File record out of a string. Parameters: rrstr - The string to parse the record out of. Returns: Nothing. ''' if self._initialized: raise pycdlibexception.PyCdlibInternalError('SF record already initialized!') # We assume that the caller has already checked the su_entry_version, # so we don't bother. (su_len, su_entry_version_unused,) = struct.unpack_from('=BB', rrstr[:4], 2) if su_len == 12: # This is a Rock Ridge version 1.10 SF Record, which is 12 bytes. (virtual_file_size_le, virtual_file_size_be) = struct.unpack_from('=LL', rrstr[:12], 4) if virtual_file_size_le != utils.swab_32bit(virtual_file_size_be): raise pycdlibexception.PyCdlibInvalidISO('Virtual file size little-endian does not match big-endian') self.virtual_file_size_low = virtual_file_size_le elif su_len == 21: # This is a Rock Ridge version 1.12 SF Record, which is 21 bytes. (virtual_file_size_high_le, virtual_file_size_high_be, virtual_file_size_low_le, virtual_file_size_low_be, self.table_depth) = struct.unpack_from('=LLLLB', rrstr[:21], 4) if virtual_file_size_high_le != utils.swab_32bit(virtual_file_size_high_be): raise pycdlibexception.PyCdlibInvalidISO('Virtual file size high little-endian does not match big-endian') if virtual_file_size_low_le != utils.swab_32bit(virtual_file_size_low_be): raise pycdlibexception.PyCdlibInvalidISO('Virtual file size low little-endian does not match big-endian') self.virtual_file_size_low = virtual_file_size_low_le self.virtual_file_size_high = virtual_file_size_high_le else: raise pycdlibexception.PyCdlibInvalidISO('Invalid length on Rock Ridge SF record (expected 12 or 21)') self._initialized = True
[ "def", "parse", "(", "self", ",", "rrstr", ")", ":", "# type: (bytes) -> None", "if", "self", ".", "_initialized", ":", "raise", "pycdlibexception", ".", "PyCdlibInternalError", "(", "'SF record already initialized!'", ")", "# We assume that the caller has already checked the su_entry_version,", "# so we don't bother.", "(", "su_len", ",", "su_entry_version_unused", ",", ")", "=", "struct", ".", "unpack_from", "(", "'=BB'", ",", "rrstr", "[", ":", "4", "]", ",", "2", ")", "if", "su_len", "==", "12", ":", "# This is a Rock Ridge version 1.10 SF Record, which is 12 bytes.", "(", "virtual_file_size_le", ",", "virtual_file_size_be", ")", "=", "struct", ".", "unpack_from", "(", "'=LL'", ",", "rrstr", "[", ":", "12", "]", ",", "4", ")", "if", "virtual_file_size_le", "!=", "utils", ".", "swab_32bit", "(", "virtual_file_size_be", ")", ":", "raise", "pycdlibexception", ".", "PyCdlibInvalidISO", "(", "'Virtual file size little-endian does not match big-endian'", ")", "self", ".", "virtual_file_size_low", "=", "virtual_file_size_le", "elif", "su_len", "==", "21", ":", "# This is a Rock Ridge version 1.12 SF Record, which is 21 bytes.", "(", "virtual_file_size_high_le", ",", "virtual_file_size_high_be", ",", "virtual_file_size_low_le", ",", "virtual_file_size_low_be", ",", "self", ".", "table_depth", ")", "=", "struct", ".", "unpack_from", "(", "'=LLLLB'", ",", "rrstr", "[", ":", "21", "]", ",", "4", ")", "if", "virtual_file_size_high_le", "!=", "utils", ".", "swab_32bit", "(", "virtual_file_size_high_be", ")", ":", "raise", "pycdlibexception", ".", "PyCdlibInvalidISO", "(", "'Virtual file size high little-endian does not match big-endian'", ")", "if", "virtual_file_size_low_le", "!=", "utils", ".", "swab_32bit", "(", "virtual_file_size_low_be", ")", ":", "raise", "pycdlibexception", ".", "PyCdlibInvalidISO", "(", "'Virtual file size low little-endian does not match big-endian'", ")", "self", ".", "virtual_file_size_low", "=", "virtual_file_size_low_le", "self", ".", "virtual_file_size_high", "=", "virtual_file_size_high_le", "else", ":", "raise", "pycdlibexception", ".", "PyCdlibInvalidISO", "(", "'Invalid length on Rock Ridge SF record (expected 12 or 21)'", ")", "self", ".", "_initialized", "=", "True" ]
Parse a Rock Ridge Sparse File record out of a string. Parameters: rrstr - The string to parse the record out of. Returns: Nothing.
[ "Parse", "a", "Rock", "Ridge", "Sparse", "File", "record", "out", "of", "a", "string", "." ]
1e7b77a809e905d67dc71e12d70e850be26b6233
https://github.com/clalancette/pycdlib/blob/1e7b77a809e905d67dc71e12d70e850be26b6233/pycdlib/rockridge.py#L1683-L1721
train
clalancette/pycdlib
pycdlib/rockridge.py
RRSFRecord.new
def new(self, file_size_high, file_size_low, table_depth): # type: (Optional[int], int, Optional[int]) -> None ''' Create a new Rock Ridge Sparse File record. Parameters: file_size_high - The high-order 32-bits of the file size. file_size_low - The low-order 32-bits of the file size. table_depth - The maximum virtual file size. Returns: Nothing. ''' if self._initialized: raise pycdlibexception.PyCdlibInternalError('SF record already initialized!') self.virtual_file_size_high = file_size_high self.virtual_file_size_low = file_size_low self.table_depth = table_depth self._initialized = True
python
def new(self, file_size_high, file_size_low, table_depth): # type: (Optional[int], int, Optional[int]) -> None ''' Create a new Rock Ridge Sparse File record. Parameters: file_size_high - The high-order 32-bits of the file size. file_size_low - The low-order 32-bits of the file size. table_depth - The maximum virtual file size. Returns: Nothing. ''' if self._initialized: raise pycdlibexception.PyCdlibInternalError('SF record already initialized!') self.virtual_file_size_high = file_size_high self.virtual_file_size_low = file_size_low self.table_depth = table_depth self._initialized = True
[ "def", "new", "(", "self", ",", "file_size_high", ",", "file_size_low", ",", "table_depth", ")", ":", "# type: (Optional[int], int, Optional[int]) -> None", "if", "self", ".", "_initialized", ":", "raise", "pycdlibexception", ".", "PyCdlibInternalError", "(", "'SF record already initialized!'", ")", "self", ".", "virtual_file_size_high", "=", "file_size_high", "self", ".", "virtual_file_size_low", "=", "file_size_low", "self", ".", "table_depth", "=", "table_depth", "self", ".", "_initialized", "=", "True" ]
Create a new Rock Ridge Sparse File record. Parameters: file_size_high - The high-order 32-bits of the file size. file_size_low - The low-order 32-bits of the file size. table_depth - The maximum virtual file size. Returns: Nothing.
[ "Create", "a", "new", "Rock", "Ridge", "Sparse", "File", "record", "." ]
1e7b77a809e905d67dc71e12d70e850be26b6233
https://github.com/clalancette/pycdlib/blob/1e7b77a809e905d67dc71e12d70e850be26b6233/pycdlib/rockridge.py#L1723-L1742
train
clalancette/pycdlib
pycdlib/rockridge.py
RRSFRecord.record
def record(self): # type: () -> bytes ''' Generate a string representing the Rock Ridge Sparse File record. Parameters: None. Returns: String containing the Rock Ridge record. ''' if not self._initialized: raise pycdlibexception.PyCdlibInternalError('SF record not yet initialized!') length = 12 if self.virtual_file_size_high is not None: length = 21 ret = b'SF' + struct.pack('=BB', length, SU_ENTRY_VERSION) if self.virtual_file_size_high is not None and self.table_depth is not None: ret += struct.pack('=LLLLB', self.virtual_file_size_high, utils.swab_32bit(self.virtual_file_size_high), self.virtual_file_size_low, utils.swab_32bit(self.virtual_file_size_low), self.table_depth) else: ret += struct.pack('=LL', self.virtual_file_size_low, utils.swab_32bit(self.virtual_file_size_low)) return ret
python
def record(self): # type: () -> bytes ''' Generate a string representing the Rock Ridge Sparse File record. Parameters: None. Returns: String containing the Rock Ridge record. ''' if not self._initialized: raise pycdlibexception.PyCdlibInternalError('SF record not yet initialized!') length = 12 if self.virtual_file_size_high is not None: length = 21 ret = b'SF' + struct.pack('=BB', length, SU_ENTRY_VERSION) if self.virtual_file_size_high is not None and self.table_depth is not None: ret += struct.pack('=LLLLB', self.virtual_file_size_high, utils.swab_32bit(self.virtual_file_size_high), self.virtual_file_size_low, utils.swab_32bit(self.virtual_file_size_low), self.table_depth) else: ret += struct.pack('=LL', self.virtual_file_size_low, utils.swab_32bit(self.virtual_file_size_low)) return ret
[ "def", "record", "(", "self", ")", ":", "# type: () -> bytes", "if", "not", "self", ".", "_initialized", ":", "raise", "pycdlibexception", ".", "PyCdlibInternalError", "(", "'SF record not yet initialized!'", ")", "length", "=", "12", "if", "self", ".", "virtual_file_size_high", "is", "not", "None", ":", "length", "=", "21", "ret", "=", "b'SF'", "+", "struct", ".", "pack", "(", "'=BB'", ",", "length", ",", "SU_ENTRY_VERSION", ")", "if", "self", ".", "virtual_file_size_high", "is", "not", "None", "and", "self", ".", "table_depth", "is", "not", "None", ":", "ret", "+=", "struct", ".", "pack", "(", "'=LLLLB'", ",", "self", ".", "virtual_file_size_high", ",", "utils", ".", "swab_32bit", "(", "self", ".", "virtual_file_size_high", ")", ",", "self", ".", "virtual_file_size_low", ",", "utils", ".", "swab_32bit", "(", "self", ".", "virtual_file_size_low", ")", ",", "self", ".", "table_depth", ")", "else", ":", "ret", "+=", "struct", ".", "pack", "(", "'=LL'", ",", "self", ".", "virtual_file_size_low", ",", "utils", ".", "swab_32bit", "(", "self", ".", "virtual_file_size_low", ")", ")", "return", "ret" ]
Generate a string representing the Rock Ridge Sparse File record. Parameters: None. Returns: String containing the Rock Ridge record.
[ "Generate", "a", "string", "representing", "the", "Rock", "Ridge", "Sparse", "File", "record", "." ]
1e7b77a809e905d67dc71e12d70e850be26b6233
https://github.com/clalancette/pycdlib/blob/1e7b77a809e905d67dc71e12d70e850be26b6233/pycdlib/rockridge.py#L1744-L1766
train
clalancette/pycdlib
pycdlib/rockridge.py
RRRERecord.record
def record(self): # type: () -> bytes ''' Generate a string representing the Rock Ridge Relocated Directory record. Parameters: None. Returns: String containing the Rock Ridge record. ''' if not self._initialized: raise pycdlibexception.PyCdlibInternalError('RE record not yet initialized!') return b'RE' + struct.pack('=BB', RRRERecord.length(), SU_ENTRY_VERSION)
python
def record(self): # type: () -> bytes ''' Generate a string representing the Rock Ridge Relocated Directory record. Parameters: None. Returns: String containing the Rock Ridge record. ''' if not self._initialized: raise pycdlibexception.PyCdlibInternalError('RE record not yet initialized!') return b'RE' + struct.pack('=BB', RRRERecord.length(), SU_ENTRY_VERSION)
[ "def", "record", "(", "self", ")", ":", "# type: () -> bytes", "if", "not", "self", ".", "_initialized", ":", "raise", "pycdlibexception", ".", "PyCdlibInternalError", "(", "'RE record not yet initialized!'", ")", "return", "b'RE'", "+", "struct", ".", "pack", "(", "'=BB'", ",", "RRRERecord", ".", "length", "(", ")", ",", "SU_ENTRY_VERSION", ")" ]
Generate a string representing the Rock Ridge Relocated Directory record. Parameters: None. Returns: String containing the Rock Ridge record.
[ "Generate", "a", "string", "representing", "the", "Rock", "Ridge", "Relocated", "Directory", "record", "." ]
1e7b77a809e905d67dc71e12d70e850be26b6233
https://github.com/clalancette/pycdlib/blob/1e7b77a809e905d67dc71e12d70e850be26b6233/pycdlib/rockridge.py#L1839-L1853
train
clalancette/pycdlib
pycdlib/rockridge.py
RRSTRecord.parse
def parse(self, rrstr): # type: (bytes) -> None ''' Parse a Rock Ridge System Terminator record out of a string. Parameters: rrstr - The string to parse the record out of. Returns: Nothing. ''' if self._initialized: raise pycdlibexception.PyCdlibInternalError('ST record already initialized!') (su_len, su_entry_version_unused) = struct.unpack_from('=BB', rrstr[:4], 2) # We assume that the caller has already checked the su_entry_version, # so we don't bother. if su_len != 4: raise pycdlibexception.PyCdlibInvalidISO('Invalid length on rock ridge extension') self._initialized = True
python
def parse(self, rrstr): # type: (bytes) -> None ''' Parse a Rock Ridge System Terminator record out of a string. Parameters: rrstr - The string to parse the record out of. Returns: Nothing. ''' if self._initialized: raise pycdlibexception.PyCdlibInternalError('ST record already initialized!') (su_len, su_entry_version_unused) = struct.unpack_from('=BB', rrstr[:4], 2) # We assume that the caller has already checked the su_entry_version, # so we don't bother. if su_len != 4: raise pycdlibexception.PyCdlibInvalidISO('Invalid length on rock ridge extension') self._initialized = True
[ "def", "parse", "(", "self", ",", "rrstr", ")", ":", "# type: (bytes) -> None", "if", "self", ".", "_initialized", ":", "raise", "pycdlibexception", ".", "PyCdlibInternalError", "(", "'ST record already initialized!'", ")", "(", "su_len", ",", "su_entry_version_unused", ")", "=", "struct", ".", "unpack_from", "(", "'=BB'", ",", "rrstr", "[", ":", "4", "]", ",", "2", ")", "# We assume that the caller has already checked the su_entry_version,", "# so we don't bother.", "if", "su_len", "!=", "4", ":", "raise", "pycdlibexception", ".", "PyCdlibInvalidISO", "(", "'Invalid length on rock ridge extension'", ")", "self", ".", "_initialized", "=", "True" ]
Parse a Rock Ridge System Terminator record out of a string. Parameters: rrstr - The string to parse the record out of. Returns: Nothing.
[ "Parse", "a", "Rock", "Ridge", "System", "Terminator", "record", "out", "of", "a", "string", "." ]
1e7b77a809e905d67dc71e12d70e850be26b6233
https://github.com/clalancette/pycdlib/blob/1e7b77a809e905d67dc71e12d70e850be26b6233/pycdlib/rockridge.py#L1882-L1903
train
clalancette/pycdlib
pycdlib/rockridge.py
RRSTRecord.record
def record(self): # type: () -> bytes ''' Generate a string representing the Rock Ridge System Terminator record. Parameters: None. Returns: String containing the Rock Ridge record. ''' if not self._initialized: raise pycdlibexception.PyCdlibInternalError('ST record not yet initialized!') return b'ST' + struct.pack('=BB', RRSTRecord.length(), SU_ENTRY_VERSION)
python
def record(self): # type: () -> bytes ''' Generate a string representing the Rock Ridge System Terminator record. Parameters: None. Returns: String containing the Rock Ridge record. ''' if not self._initialized: raise pycdlibexception.PyCdlibInternalError('ST record not yet initialized!') return b'ST' + struct.pack('=BB', RRSTRecord.length(), SU_ENTRY_VERSION)
[ "def", "record", "(", "self", ")", ":", "# type: () -> bytes", "if", "not", "self", ".", "_initialized", ":", "raise", "pycdlibexception", ".", "PyCdlibInternalError", "(", "'ST record not yet initialized!'", ")", "return", "b'ST'", "+", "struct", ".", "pack", "(", "'=BB'", ",", "RRSTRecord", ".", "length", "(", ")", ",", "SU_ENTRY_VERSION", ")" ]
Generate a string representing the Rock Ridge System Terminator record. Parameters: None. Returns: String containing the Rock Ridge record.
[ "Generate", "a", "string", "representing", "the", "Rock", "Ridge", "System", "Terminator", "record", "." ]
1e7b77a809e905d67dc71e12d70e850be26b6233
https://github.com/clalancette/pycdlib/blob/1e7b77a809e905d67dc71e12d70e850be26b6233/pycdlib/rockridge.py#L1920-L1934
train
clalancette/pycdlib
pycdlib/rockridge.py
RRPDRecord.parse
def parse(self, rrstr): # type: (bytes) -> None ''' Parse a Rock Ridge Platform Dependent record out of a string. Parameters: rrstr - The string to parse the record out of. Returns: Nothing. ''' if self._initialized: raise pycdlibexception.PyCdlibInternalError('PD record already initialized!') (su_len_unused, su_entry_version_unused) = struct.unpack_from('=BB', rrstr[:4], 2) self.padding = rrstr[4:] # We assume that the caller has already checked the su_entry_version, # so we don't bother. self._initialized = True
python
def parse(self, rrstr): # type: (bytes) -> None ''' Parse a Rock Ridge Platform Dependent record out of a string. Parameters: rrstr - The string to parse the record out of. Returns: Nothing. ''' if self._initialized: raise pycdlibexception.PyCdlibInternalError('PD record already initialized!') (su_len_unused, su_entry_version_unused) = struct.unpack_from('=BB', rrstr[:4], 2) self.padding = rrstr[4:] # We assume that the caller has already checked the su_entry_version, # so we don't bother. self._initialized = True
[ "def", "parse", "(", "self", ",", "rrstr", ")", ":", "# type: (bytes) -> None", "if", "self", ".", "_initialized", ":", "raise", "pycdlibexception", ".", "PyCdlibInternalError", "(", "'PD record already initialized!'", ")", "(", "su_len_unused", ",", "su_entry_version_unused", ")", "=", "struct", ".", "unpack_from", "(", "'=BB'", ",", "rrstr", "[", ":", "4", "]", ",", "2", ")", "self", ".", "padding", "=", "rrstr", "[", "4", ":", "]", "# We assume that the caller has already checked the su_entry_version,", "# so we don't bother.", "self", ".", "_initialized", "=", "True" ]
Parse a Rock Ridge Platform Dependent record out of a string. Parameters: rrstr - The string to parse the record out of. Returns: Nothing.
[ "Parse", "a", "Rock", "Ridge", "Platform", "Dependent", "record", "out", "of", "a", "string", "." ]
1e7b77a809e905d67dc71e12d70e850be26b6233
https://github.com/clalancette/pycdlib/blob/1e7b77a809e905d67dc71e12d70e850be26b6233/pycdlib/rockridge.py#L1963-L1983
train
clalancette/pycdlib
pycdlib/rockridge.py
RRPDRecord.new
def new(self): # type: () -> None ''' Create a new Rock Ridge Platform Dependent record. Parameters: None. Returns: Nothing. ''' if self._initialized: raise pycdlibexception.PyCdlibInternalError('PD record already initialized!') self._initialized = True self.padding = b''
python
def new(self): # type: () -> None ''' Create a new Rock Ridge Platform Dependent record. Parameters: None. Returns: Nothing. ''' if self._initialized: raise pycdlibexception.PyCdlibInternalError('PD record already initialized!') self._initialized = True self.padding = b''
[ "def", "new", "(", "self", ")", ":", "# type: () -> None", "if", "self", ".", "_initialized", ":", "raise", "pycdlibexception", ".", "PyCdlibInternalError", "(", "'PD record already initialized!'", ")", "self", ".", "_initialized", "=", "True", "self", ".", "padding", "=", "b''" ]
Create a new Rock Ridge Platform Dependent record. Parameters: None. Returns: Nothing.
[ "Create", "a", "new", "Rock", "Ridge", "Platform", "Dependent", "record", "." ]
1e7b77a809e905d67dc71e12d70e850be26b6233
https://github.com/clalancette/pycdlib/blob/1e7b77a809e905d67dc71e12d70e850be26b6233/pycdlib/rockridge.py#L1985-L1999
train
clalancette/pycdlib
pycdlib/rockridge.py
RRPDRecord.record
def record(self): # type: () -> bytes ''' Generate a string representing the Rock Ridge Platform Dependent record. Parameters: None. Returns: String containing the Rock Ridge record. ''' if not self._initialized: raise pycdlibexception.PyCdlibInternalError('PD record not yet initialized!') return b'PD' + struct.pack('=BB', RRPDRecord.length(self.padding), SU_ENTRY_VERSION) + self.padding
python
def record(self): # type: () -> bytes ''' Generate a string representing the Rock Ridge Platform Dependent record. Parameters: None. Returns: String containing the Rock Ridge record. ''' if not self._initialized: raise pycdlibexception.PyCdlibInternalError('PD record not yet initialized!') return b'PD' + struct.pack('=BB', RRPDRecord.length(self.padding), SU_ENTRY_VERSION) + self.padding
[ "def", "record", "(", "self", ")", ":", "# type: () -> bytes", "if", "not", "self", ".", "_initialized", ":", "raise", "pycdlibexception", ".", "PyCdlibInternalError", "(", "'PD record not yet initialized!'", ")", "return", "b'PD'", "+", "struct", ".", "pack", "(", "'=BB'", ",", "RRPDRecord", ".", "length", "(", "self", ".", "padding", ")", ",", "SU_ENTRY_VERSION", ")", "+", "self", ".", "padding" ]
Generate a string representing the Rock Ridge Platform Dependent record. Parameters: None. Returns: String containing the Rock Ridge record.
[ "Generate", "a", "string", "representing", "the", "Rock", "Ridge", "Platform", "Dependent", "record", "." ]
1e7b77a809e905d67dc71e12d70e850be26b6233
https://github.com/clalancette/pycdlib/blob/1e7b77a809e905d67dc71e12d70e850be26b6233/pycdlib/rockridge.py#L2001-L2016
train
clalancette/pycdlib
pycdlib/rockridge.py
RockRidge.has_entry
def has_entry(self, name): # type: (str) -> bool ''' An internal method to tell if we have already parsed an entry of the named type. Parameters: name - The name of the entry to check. Returns: True if we have already parsed an entry of the named type, False otherwise. ''' return getattr(self.dr_entries, name) or getattr(self.ce_entries, name)
python
def has_entry(self, name): # type: (str) -> bool ''' An internal method to tell if we have already parsed an entry of the named type. Parameters: name - The name of the entry to check. Returns: True if we have already parsed an entry of the named type, False otherwise. ''' return getattr(self.dr_entries, name) or getattr(self.ce_entries, name)
[ "def", "has_entry", "(", "self", ",", "name", ")", ":", "# type: (str) -> bool", "return", "getattr", "(", "self", ".", "dr_entries", ",", "name", ")", "or", "getattr", "(", "self", ".", "ce_entries", ",", "name", ")" ]
An internal method to tell if we have already parsed an entry of the named type. Parameters: name - The name of the entry to check. Returns: True if we have already parsed an entry of the named type, False otherwise.
[ "An", "internal", "method", "to", "tell", "if", "we", "have", "already", "parsed", "an", "entry", "of", "the", "named", "type", "." ]
1e7b77a809e905d67dc71e12d70e850be26b6233
https://github.com/clalancette/pycdlib/blob/1e7b77a809e905d67dc71e12d70e850be26b6233/pycdlib/rockridge.py#L2095-L2106
train
clalancette/pycdlib
pycdlib/rockridge.py
RockRidge._record
def _record(self, entries): # type: (RockRidgeEntries) -> bytes ''' Return a string representing the Rock Ridge entry. Parameters: entries - The dr_entries or ce_entries to generate a record for. Returns: A string representing the Rock Ridge entry. ''' outlist = [] if entries.sp_record is not None: outlist.append(entries.sp_record.record()) if entries.rr_record is not None: outlist.append(entries.rr_record.record()) for nm_record in entries.nm_records: outlist.append(nm_record.record()) if entries.px_record is not None: outlist.append(entries.px_record.record(self.rr_version)) for sl_record in entries.sl_records: outlist.append(sl_record.record()) if entries.tf_record is not None: outlist.append(entries.tf_record.record()) if entries.cl_record is not None: outlist.append(entries.cl_record.record()) if entries.pl_record is not None: outlist.append(entries.pl_record.record()) if entries.re_record is not None: outlist.append(entries.re_record.record()) for es_record in entries.es_records: outlist.append(es_record.record()) if entries.er_record is not None: outlist.append(entries.er_record.record()) if entries.ce_record is not None: outlist.append(entries.ce_record.record()) for pd_record in entries.pd_records: outlist.append(pd_record.record()) if entries.st_record is not None: outlist.append(entries.st_record.record()) if entries.sf_record is not None: outlist.append(entries.sf_record.record()) return b''.join(outlist)
python
def _record(self, entries): # type: (RockRidgeEntries) -> bytes ''' Return a string representing the Rock Ridge entry. Parameters: entries - The dr_entries or ce_entries to generate a record for. Returns: A string representing the Rock Ridge entry. ''' outlist = [] if entries.sp_record is not None: outlist.append(entries.sp_record.record()) if entries.rr_record is not None: outlist.append(entries.rr_record.record()) for nm_record in entries.nm_records: outlist.append(nm_record.record()) if entries.px_record is not None: outlist.append(entries.px_record.record(self.rr_version)) for sl_record in entries.sl_records: outlist.append(sl_record.record()) if entries.tf_record is not None: outlist.append(entries.tf_record.record()) if entries.cl_record is not None: outlist.append(entries.cl_record.record()) if entries.pl_record is not None: outlist.append(entries.pl_record.record()) if entries.re_record is not None: outlist.append(entries.re_record.record()) for es_record in entries.es_records: outlist.append(es_record.record()) if entries.er_record is not None: outlist.append(entries.er_record.record()) if entries.ce_record is not None: outlist.append(entries.ce_record.record()) for pd_record in entries.pd_records: outlist.append(pd_record.record()) if entries.st_record is not None: outlist.append(entries.st_record.record()) if entries.sf_record is not None: outlist.append(entries.sf_record.record()) return b''.join(outlist)
[ "def", "_record", "(", "self", ",", "entries", ")", ":", "# type: (RockRidgeEntries) -> bytes", "outlist", "=", "[", "]", "if", "entries", ".", "sp_record", "is", "not", "None", ":", "outlist", ".", "append", "(", "entries", ".", "sp_record", ".", "record", "(", ")", ")", "if", "entries", ".", "rr_record", "is", "not", "None", ":", "outlist", ".", "append", "(", "entries", ".", "rr_record", ".", "record", "(", ")", ")", "for", "nm_record", "in", "entries", ".", "nm_records", ":", "outlist", ".", "append", "(", "nm_record", ".", "record", "(", ")", ")", "if", "entries", ".", "px_record", "is", "not", "None", ":", "outlist", ".", "append", "(", "entries", ".", "px_record", ".", "record", "(", "self", ".", "rr_version", ")", ")", "for", "sl_record", "in", "entries", ".", "sl_records", ":", "outlist", ".", "append", "(", "sl_record", ".", "record", "(", ")", ")", "if", "entries", ".", "tf_record", "is", "not", "None", ":", "outlist", ".", "append", "(", "entries", ".", "tf_record", ".", "record", "(", ")", ")", "if", "entries", ".", "cl_record", "is", "not", "None", ":", "outlist", ".", "append", "(", "entries", ".", "cl_record", ".", "record", "(", ")", ")", "if", "entries", ".", "pl_record", "is", "not", "None", ":", "outlist", ".", "append", "(", "entries", ".", "pl_record", ".", "record", "(", ")", ")", "if", "entries", ".", "re_record", "is", "not", "None", ":", "outlist", ".", "append", "(", "entries", ".", "re_record", ".", "record", "(", ")", ")", "for", "es_record", "in", "entries", ".", "es_records", ":", "outlist", ".", "append", "(", "es_record", ".", "record", "(", ")", ")", "if", "entries", ".", "er_record", "is", "not", "None", ":", "outlist", ".", "append", "(", "entries", ".", "er_record", ".", "record", "(", ")", ")", "if", "entries", ".", "ce_record", "is", "not", "None", ":", "outlist", ".", "append", "(", "entries", ".", "ce_record", ".", "record", "(", ")", ")", "for", "pd_record", "in", "entries", ".", "pd_records", ":", "outlist", ".", "append", "(", "pd_record", ".", "record", "(", ")", ")", "if", "entries", ".", "st_record", "is", "not", "None", ":", "outlist", ".", "append", "(", "entries", ".", "st_record", ".", "record", "(", ")", ")", "if", "entries", ".", "sf_record", "is", "not", "None", ":", "outlist", ".", "append", "(", "entries", ".", "sf_record", ".", "record", "(", ")", ")", "return", "b''", ".", "join", "(", "outlist", ")" ]
Return a string representing the Rock Ridge entry. Parameters: entries - The dr_entries or ce_entries to generate a record for. Returns: A string representing the Rock Ridge entry.
[ "Return", "a", "string", "representing", "the", "Rock", "Ridge", "entry", "." ]
1e7b77a809e905d67dc71e12d70e850be26b6233
https://github.com/clalancette/pycdlib/blob/1e7b77a809e905d67dc71e12d70e850be26b6233/pycdlib/rockridge.py#L2274-L2331
train
clalancette/pycdlib
pycdlib/rockridge.py
RockRidge.record_dr_entries
def record_dr_entries(self): # type: () -> bytes ''' Return a string representing the Rock Ridge entries in the Directory Record. Parameters: None. Returns: A string representing the Rock Ridge entry. ''' if not self._initialized: raise pycdlibexception.PyCdlibInternalError('Rock Ridge extension not yet initialized') return self._record(self.dr_entries)
python
def record_dr_entries(self): # type: () -> bytes ''' Return a string representing the Rock Ridge entries in the Directory Record. Parameters: None. Returns: A string representing the Rock Ridge entry. ''' if not self._initialized: raise pycdlibexception.PyCdlibInternalError('Rock Ridge extension not yet initialized') return self._record(self.dr_entries)
[ "def", "record_dr_entries", "(", "self", ")", ":", "# type: () -> bytes", "if", "not", "self", ".", "_initialized", ":", "raise", "pycdlibexception", ".", "PyCdlibInternalError", "(", "'Rock Ridge extension not yet initialized'", ")", "return", "self", ".", "_record", "(", "self", ".", "dr_entries", ")" ]
Return a string representing the Rock Ridge entries in the Directory Record. Parameters: None. Returns: A string representing the Rock Ridge entry.
[ "Return", "a", "string", "representing", "the", "Rock", "Ridge", "entries", "in", "the", "Directory", "Record", "." ]
1e7b77a809e905d67dc71e12d70e850be26b6233
https://github.com/clalancette/pycdlib/blob/1e7b77a809e905d67dc71e12d70e850be26b6233/pycdlib/rockridge.py#L2333-L2346
train
clalancette/pycdlib
pycdlib/rockridge.py
RockRidge.record_ce_entries
def record_ce_entries(self): # type: () -> bytes ''' Return a string representing the Rock Ridge entries in the Continuation Entry. Parameters: None. Returns: A string representing the Rock Ridge entry. ''' if not self._initialized: raise pycdlibexception.PyCdlibInternalError('Rock Ridge extension not yet initialized') return self._record(self.ce_entries)
python
def record_ce_entries(self): # type: () -> bytes ''' Return a string representing the Rock Ridge entries in the Continuation Entry. Parameters: None. Returns: A string representing the Rock Ridge entry. ''' if not self._initialized: raise pycdlibexception.PyCdlibInternalError('Rock Ridge extension not yet initialized') return self._record(self.ce_entries)
[ "def", "record_ce_entries", "(", "self", ")", ":", "# type: () -> bytes", "if", "not", "self", ".", "_initialized", ":", "raise", "pycdlibexception", ".", "PyCdlibInternalError", "(", "'Rock Ridge extension not yet initialized'", ")", "return", "self", ".", "_record", "(", "self", ".", "ce_entries", ")" ]
Return a string representing the Rock Ridge entries in the Continuation Entry. Parameters: None. Returns: A string representing the Rock Ridge entry.
[ "Return", "a", "string", "representing", "the", "Rock", "Ridge", "entries", "in", "the", "Continuation", "Entry", "." ]
1e7b77a809e905d67dc71e12d70e850be26b6233
https://github.com/clalancette/pycdlib/blob/1e7b77a809e905d67dc71e12d70e850be26b6233/pycdlib/rockridge.py#L2348-L2361
train
clalancette/pycdlib
pycdlib/rockridge.py
RockRidge._add_ce_record
def _add_ce_record(self, curr_dr_len, thislen): # type: (int, int) -> int ''' An internal method to add a new length to a Continuation Entry. If the Continuation Entry does not yet exist, this method creates it. Parameters: curr_dr_len - The current Directory Record length. thislen - The new length to add to the Continuation Entry. Returns: An integer representing the current directory record length after adding the Continuation Entry. ''' if self.dr_entries.ce_record is None: self.dr_entries.ce_record = RRCERecord() self.dr_entries.ce_record.new() curr_dr_len += RRCERecord.length() self.dr_entries.ce_record.add_record(thislen) return curr_dr_len
python
def _add_ce_record(self, curr_dr_len, thislen): # type: (int, int) -> int ''' An internal method to add a new length to a Continuation Entry. If the Continuation Entry does not yet exist, this method creates it. Parameters: curr_dr_len - The current Directory Record length. thislen - The new length to add to the Continuation Entry. Returns: An integer representing the current directory record length after adding the Continuation Entry. ''' if self.dr_entries.ce_record is None: self.dr_entries.ce_record = RRCERecord() self.dr_entries.ce_record.new() curr_dr_len += RRCERecord.length() self.dr_entries.ce_record.add_record(thislen) return curr_dr_len
[ "def", "_add_ce_record", "(", "self", ",", "curr_dr_len", ",", "thislen", ")", ":", "# type: (int, int) -> int", "if", "self", ".", "dr_entries", ".", "ce_record", "is", "None", ":", "self", ".", "dr_entries", ".", "ce_record", "=", "RRCERecord", "(", ")", "self", ".", "dr_entries", ".", "ce_record", ".", "new", "(", ")", "curr_dr_len", "+=", "RRCERecord", ".", "length", "(", ")", "self", ".", "dr_entries", ".", "ce_record", ".", "add_record", "(", "thislen", ")", "return", "curr_dr_len" ]
An internal method to add a new length to a Continuation Entry. If the Continuation Entry does not yet exist, this method creates it. Parameters: curr_dr_len - The current Directory Record length. thislen - The new length to add to the Continuation Entry. Returns: An integer representing the current directory record length after adding the Continuation Entry.
[ "An", "internal", "method", "to", "add", "a", "new", "length", "to", "a", "Continuation", "Entry", ".", "If", "the", "Continuation", "Entry", "does", "not", "yet", "exist", "this", "method", "creates", "it", "." ]
1e7b77a809e905d67dc71e12d70e850be26b6233
https://github.com/clalancette/pycdlib/blob/1e7b77a809e905d67dc71e12d70e850be26b6233/pycdlib/rockridge.py#L2363-L2381
train
clalancette/pycdlib
pycdlib/rockridge.py
RockRidge._add_name
def _add_name(self, rr_name, curr_dr_len): # type: (bytes, int) -> int ''' An internal method to add the appropriate name records to the ISO. Parameters: rr_name - The Rock Ridge name to add to the ISO. curr_dr_len - The current directory record length. Returns: The new directory record length. ''' # The length we are putting in this object (as opposed to the # continuation entry) is the maximum, minus how much is already in the # DR, minus 5 for the NM metadata. We know that at least part of the # NM record will always fit in this DR. That's because the DR is a # maximum size of 255, and the ISO9660 fields uses a maximum of 34 bytes # for metadata and 8+1+3+1+5 (8 for name, 1 for dot, 3 for extension, # 1 for semicolon, and 5 for version number, allowed up to 32767), which # leaves the System Use entry with 255 - 34 - 18 = 203 bytes. Before # this record, the only records we ever put in place could be the SP or # the RR record, and the combination of them is never > 203, so we will # always put some NM data in here. len_here = ALLOWED_DR_SIZE - curr_dr_len - 5 if len_here < len(rr_name): curr_dr_len = self._add_ce_record(curr_dr_len, 0) len_here = ALLOWED_DR_SIZE - curr_dr_len - 5 curr_nm = RRNMRecord() curr_nm.new(rr_name[:len_here]) self.dr_entries.nm_records.append(curr_nm) curr_dr_len += RRNMRecord.length(rr_name[:len_here]) offset = len_here while offset < len(rr_name): curr_nm.set_continued() # We clip the length for this NM entry to 250, as that is # the maximum possible size for an NM entry. length = min(len(rr_name[offset:]), 250) curr_nm = RRNMRecord() curr_nm.new(rr_name[offset:offset + length]) self.ce_entries.nm_records.append(curr_nm) if self.dr_entries.ce_record is not None: self.dr_entries.ce_record.add_record(RRNMRecord.length(rr_name[offset:offset + length])) offset += length return curr_dr_len
python
def _add_name(self, rr_name, curr_dr_len): # type: (bytes, int) -> int ''' An internal method to add the appropriate name records to the ISO. Parameters: rr_name - The Rock Ridge name to add to the ISO. curr_dr_len - The current directory record length. Returns: The new directory record length. ''' # The length we are putting in this object (as opposed to the # continuation entry) is the maximum, minus how much is already in the # DR, minus 5 for the NM metadata. We know that at least part of the # NM record will always fit in this DR. That's because the DR is a # maximum size of 255, and the ISO9660 fields uses a maximum of 34 bytes # for metadata and 8+1+3+1+5 (8 for name, 1 for dot, 3 for extension, # 1 for semicolon, and 5 for version number, allowed up to 32767), which # leaves the System Use entry with 255 - 34 - 18 = 203 bytes. Before # this record, the only records we ever put in place could be the SP or # the RR record, and the combination of them is never > 203, so we will # always put some NM data in here. len_here = ALLOWED_DR_SIZE - curr_dr_len - 5 if len_here < len(rr_name): curr_dr_len = self._add_ce_record(curr_dr_len, 0) len_here = ALLOWED_DR_SIZE - curr_dr_len - 5 curr_nm = RRNMRecord() curr_nm.new(rr_name[:len_here]) self.dr_entries.nm_records.append(curr_nm) curr_dr_len += RRNMRecord.length(rr_name[:len_here]) offset = len_here while offset < len(rr_name): curr_nm.set_continued() # We clip the length for this NM entry to 250, as that is # the maximum possible size for an NM entry. length = min(len(rr_name[offset:]), 250) curr_nm = RRNMRecord() curr_nm.new(rr_name[offset:offset + length]) self.ce_entries.nm_records.append(curr_nm) if self.dr_entries.ce_record is not None: self.dr_entries.ce_record.add_record(RRNMRecord.length(rr_name[offset:offset + length])) offset += length return curr_dr_len
[ "def", "_add_name", "(", "self", ",", "rr_name", ",", "curr_dr_len", ")", ":", "# type: (bytes, int) -> int", "# The length we are putting in this object (as opposed to the", "# continuation entry) is the maximum, minus how much is already in the", "# DR, minus 5 for the NM metadata. We know that at least part of the", "# NM record will always fit in this DR. That's because the DR is a", "# maximum size of 255, and the ISO9660 fields uses a maximum of 34 bytes", "# for metadata and 8+1+3+1+5 (8 for name, 1 for dot, 3 for extension,", "# 1 for semicolon, and 5 for version number, allowed up to 32767), which", "# leaves the System Use entry with 255 - 34 - 18 = 203 bytes. Before", "# this record, the only records we ever put in place could be the SP or", "# the RR record, and the combination of them is never > 203, so we will", "# always put some NM data in here.", "len_here", "=", "ALLOWED_DR_SIZE", "-", "curr_dr_len", "-", "5", "if", "len_here", "<", "len", "(", "rr_name", ")", ":", "curr_dr_len", "=", "self", ".", "_add_ce_record", "(", "curr_dr_len", ",", "0", ")", "len_here", "=", "ALLOWED_DR_SIZE", "-", "curr_dr_len", "-", "5", "curr_nm", "=", "RRNMRecord", "(", ")", "curr_nm", ".", "new", "(", "rr_name", "[", ":", "len_here", "]", ")", "self", ".", "dr_entries", ".", "nm_records", ".", "append", "(", "curr_nm", ")", "curr_dr_len", "+=", "RRNMRecord", ".", "length", "(", "rr_name", "[", ":", "len_here", "]", ")", "offset", "=", "len_here", "while", "offset", "<", "len", "(", "rr_name", ")", ":", "curr_nm", ".", "set_continued", "(", ")", "# We clip the length for this NM entry to 250, as that is", "# the maximum possible size for an NM entry.", "length", "=", "min", "(", "len", "(", "rr_name", "[", "offset", ":", "]", ")", ",", "250", ")", "curr_nm", "=", "RRNMRecord", "(", ")", "curr_nm", ".", "new", "(", "rr_name", "[", "offset", ":", "offset", "+", "length", "]", ")", "self", ".", "ce_entries", ".", "nm_records", ".", "append", "(", "curr_nm", ")", "if", "self", ".", "dr_entries", ".", "ce_record", "is", "not", "None", ":", "self", ".", "dr_entries", ".", "ce_record", ".", "add_record", "(", "RRNMRecord", ".", "length", "(", "rr_name", "[", "offset", ":", "offset", "+", "length", "]", ")", ")", "offset", "+=", "length", "return", "curr_dr_len" ]
An internal method to add the appropriate name records to the ISO. Parameters: rr_name - The Rock Ridge name to add to the ISO. curr_dr_len - The current directory record length. Returns: The new directory record length.
[ "An", "internal", "method", "to", "add", "the", "appropriate", "name", "records", "to", "the", "ISO", "." ]
1e7b77a809e905d67dc71e12d70e850be26b6233
https://github.com/clalancette/pycdlib/blob/1e7b77a809e905d67dc71e12d70e850be26b6233/pycdlib/rockridge.py#L2502-L2549
train
clalancette/pycdlib
pycdlib/rockridge.py
RockRidge.add_to_file_links
def add_to_file_links(self): # type: () -> None ''' Increment the number of POSIX file links on this entry by one. Parameters: None. Returns: Nothing. ''' if not self._initialized: raise pycdlibexception.PyCdlibInternalError('Rock Ridge extension not yet initialized') if self.dr_entries.px_record is None: if self.ce_entries.px_record is None: raise pycdlibexception.PyCdlibInvalidInput('No Rock Ridge file links') self.ce_entries.px_record.posix_file_links += 1 else: self.dr_entries.px_record.posix_file_links += 1
python
def add_to_file_links(self): # type: () -> None ''' Increment the number of POSIX file links on this entry by one. Parameters: None. Returns: Nothing. ''' if not self._initialized: raise pycdlibexception.PyCdlibInternalError('Rock Ridge extension not yet initialized') if self.dr_entries.px_record is None: if self.ce_entries.px_record is None: raise pycdlibexception.PyCdlibInvalidInput('No Rock Ridge file links') self.ce_entries.px_record.posix_file_links += 1 else: self.dr_entries.px_record.posix_file_links += 1
[ "def", "add_to_file_links", "(", "self", ")", ":", "# type: () -> None", "if", "not", "self", ".", "_initialized", ":", "raise", "pycdlibexception", ".", "PyCdlibInternalError", "(", "'Rock Ridge extension not yet initialized'", ")", "if", "self", ".", "dr_entries", ".", "px_record", "is", "None", ":", "if", "self", ".", "ce_entries", ".", "px_record", "is", "None", ":", "raise", "pycdlibexception", ".", "PyCdlibInvalidInput", "(", "'No Rock Ridge file links'", ")", "self", ".", "ce_entries", ".", "px_record", ".", "posix_file_links", "+=", "1", "else", ":", "self", ".", "dr_entries", ".", "px_record", ".", "posix_file_links", "+=", "1" ]
Increment the number of POSIX file links on this entry by one. Parameters: None. Returns: Nothing.
[ "Increment", "the", "number", "of", "POSIX", "file", "links", "on", "this", "entry", "by", "one", "." ]
1e7b77a809e905d67dc71e12d70e850be26b6233
https://github.com/clalancette/pycdlib/blob/1e7b77a809e905d67dc71e12d70e850be26b6233/pycdlib/rockridge.py#L2728-L2746
train
clalancette/pycdlib
pycdlib/rockridge.py
RockRidge.copy_file_links
def copy_file_links(self, src): # type: (RockRidge) -> None ''' Copy the number of file links from the source Rock Ridge entry into this Rock Ridge entry. Parameters: src - The source Rock Ridge entry to copy from. Returns: Nothing. ''' if not self._initialized: raise pycdlibexception.PyCdlibInternalError('Rock Ridge extension not yet initialized') # First, get the src data if src.dr_entries.px_record is None: if src.ce_entries.px_record is None: raise pycdlibexception.PyCdlibInvalidInput('No Rock Ridge file links') num_links = src.ce_entries.px_record.posix_file_links else: num_links = src.dr_entries.px_record.posix_file_links # Now apply it to this record. if self.dr_entries.px_record is None: if self.ce_entries.px_record is None: raise pycdlibexception.PyCdlibInvalidInput('No Rock Ridge file links') self.ce_entries.px_record.posix_file_links = num_links else: self.dr_entries.px_record.posix_file_links = num_links
python
def copy_file_links(self, src): # type: (RockRidge) -> None ''' Copy the number of file links from the source Rock Ridge entry into this Rock Ridge entry. Parameters: src - The source Rock Ridge entry to copy from. Returns: Nothing. ''' if not self._initialized: raise pycdlibexception.PyCdlibInternalError('Rock Ridge extension not yet initialized') # First, get the src data if src.dr_entries.px_record is None: if src.ce_entries.px_record is None: raise pycdlibexception.PyCdlibInvalidInput('No Rock Ridge file links') num_links = src.ce_entries.px_record.posix_file_links else: num_links = src.dr_entries.px_record.posix_file_links # Now apply it to this record. if self.dr_entries.px_record is None: if self.ce_entries.px_record is None: raise pycdlibexception.PyCdlibInvalidInput('No Rock Ridge file links') self.ce_entries.px_record.posix_file_links = num_links else: self.dr_entries.px_record.posix_file_links = num_links
[ "def", "copy_file_links", "(", "self", ",", "src", ")", ":", "# type: (RockRidge) -> None", "if", "not", "self", ".", "_initialized", ":", "raise", "pycdlibexception", ".", "PyCdlibInternalError", "(", "'Rock Ridge extension not yet initialized'", ")", "# First, get the src data", "if", "src", ".", "dr_entries", ".", "px_record", "is", "None", ":", "if", "src", ".", "ce_entries", ".", "px_record", "is", "None", ":", "raise", "pycdlibexception", ".", "PyCdlibInvalidInput", "(", "'No Rock Ridge file links'", ")", "num_links", "=", "src", ".", "ce_entries", ".", "px_record", ".", "posix_file_links", "else", ":", "num_links", "=", "src", ".", "dr_entries", ".", "px_record", ".", "posix_file_links", "# Now apply it to this record.", "if", "self", ".", "dr_entries", ".", "px_record", "is", "None", ":", "if", "self", ".", "ce_entries", ".", "px_record", "is", "None", ":", "raise", "pycdlibexception", ".", "PyCdlibInvalidInput", "(", "'No Rock Ridge file links'", ")", "self", ".", "ce_entries", ".", "px_record", ".", "posix_file_links", "=", "num_links", "else", ":", "self", ".", "dr_entries", ".", "px_record", ".", "posix_file_links", "=", "num_links" ]
Copy the number of file links from the source Rock Ridge entry into this Rock Ridge entry. Parameters: src - The source Rock Ridge entry to copy from. Returns: Nothing.
[ "Copy", "the", "number", "of", "file", "links", "from", "the", "source", "Rock", "Ridge", "entry", "into", "this", "Rock", "Ridge", "entry", "." ]
1e7b77a809e905d67dc71e12d70e850be26b6233
https://github.com/clalancette/pycdlib/blob/1e7b77a809e905d67dc71e12d70e850be26b6233/pycdlib/rockridge.py#L2768-L2796
train
clalancette/pycdlib
pycdlib/rockridge.py
RockRidge.get_file_mode
def get_file_mode(self): # type: () -> int ''' Get the POSIX file mode bits for this Rock Ridge entry. Parameters: None. Returns: The POSIX file mode bits for this Rock Ridge entry. ''' if not self._initialized: raise pycdlibexception.PyCdlibInternalError('Rock Ridge extension not yet initialized') if self.dr_entries.px_record is None: if self.ce_entries.px_record is None: raise pycdlibexception.PyCdlibInvalidInput('No Rock Ridge file mode') return self.ce_entries.px_record.posix_file_mode return self.dr_entries.px_record.posix_file_mode
python
def get_file_mode(self): # type: () -> int ''' Get the POSIX file mode bits for this Rock Ridge entry. Parameters: None. Returns: The POSIX file mode bits for this Rock Ridge entry. ''' if not self._initialized: raise pycdlibexception.PyCdlibInternalError('Rock Ridge extension not yet initialized') if self.dr_entries.px_record is None: if self.ce_entries.px_record is None: raise pycdlibexception.PyCdlibInvalidInput('No Rock Ridge file mode') return self.ce_entries.px_record.posix_file_mode return self.dr_entries.px_record.posix_file_mode
[ "def", "get_file_mode", "(", "self", ")", ":", "# type: () -> int", "if", "not", "self", ".", "_initialized", ":", "raise", "pycdlibexception", ".", "PyCdlibInternalError", "(", "'Rock Ridge extension not yet initialized'", ")", "if", "self", ".", "dr_entries", ".", "px_record", "is", "None", ":", "if", "self", ".", "ce_entries", ".", "px_record", "is", "None", ":", "raise", "pycdlibexception", ".", "PyCdlibInvalidInput", "(", "'No Rock Ridge file mode'", ")", "return", "self", ".", "ce_entries", ".", "px_record", ".", "posix_file_mode", "return", "self", ".", "dr_entries", ".", "px_record", ".", "posix_file_mode" ]
Get the POSIX file mode bits for this Rock Ridge entry. Parameters: None. Returns: The POSIX file mode bits for this Rock Ridge entry.
[ "Get", "the", "POSIX", "file", "mode", "bits", "for", "this", "Rock", "Ridge", "entry", "." ]
1e7b77a809e905d67dc71e12d70e850be26b6233
https://github.com/clalancette/pycdlib/blob/1e7b77a809e905d67dc71e12d70e850be26b6233/pycdlib/rockridge.py#L2798-L2816
train