Esempio n. 1
0
    def directory_record_length(self):
        '''
        A method to determine the length of this Directory Record.

        Parameters:
         None.
        Returns:
         The length of this Directory Record.
        '''
        if not self._initialized:
            raise pycdlibexception.PyCdlibInternalError(
                "Directory Record not yet initialized")
        return self.dr_len
Esempio n. 2
0
    def is_file(self):
        '''
        A method to determine whether this Directory Record is a file.

        Parameters:
         None.
        Returns:
         True if this DirectoryRecord object is a file, False otherwise.
        '''
        if not self._initialized:
            raise pycdlibexception.PyCdlibInternalError(
                "Directory Record not yet initialized")
        return not self.isdir
Esempio n. 3
0
    def is_dotdot(self):
        '''
        A method to determine whether this Directory Record is a "dotdot" entry.

        Parameters:
         None.
        Returns:
         True if this DirectoryRecord object is a "dotdot" entry, False otherwise.
        '''
        if not self._initialized:
            raise pycdlibexception.PyCdlibInternalError(
                "Directory Record not yet initialized")
        return self.file_ident == b'\x01'
Esempio n. 4
0
    def update_extent_location(self, extent_loc):
        '''
        A method to update the extent location for this Path Table Record.

        Parameters:
         extent_loc - The new extent location.
        Returns:
         Nothing.
        '''
        if not self._initialized:
            raise pycdlibexception.PyCdlibInternalError("Path Table Record not yet initialized")

        self.extent_location = extent_loc
Esempio n. 5
0
    def update_parent_directory_number(self, parent_dir_num):
        '''
        A method to update the parent directory number for this Path Table
        Record from the directory record.

        Parameters:
         parent_dir_num - The new parent directory number to assign to this PTR.
        Returns:
         Nothing.
        '''
        if not self._initialized:
            raise pycdlibexception.PyCdlibInternalError("Path Table Record not yet initialized")
        self.parent_directory_num = parent_dir_num
Esempio n. 6
0
    def update_vd_extent(self):
        '''
        A method to update the internal volume descriptor extent from the volume descriptor
        extent.

        Parameters:
         None.
        Returns:
         Nothing.
        '''
        if not self._initialized:
            raise pycdlibexception.PyCdlibInternalError("This Eltorito Boot Info Table not yet initialized")
        self.pvd_extent = self.vd.extent_location()
Esempio n. 7
0
    def new_root(self):
        '''
        A method to create a new root Path Table Record.

        Parameters:
         None.
        Returns:
         Nothing.
        '''
        if self._initialized:
            raise pycdlibexception.PyCdlibInternalError("Path Table Record already initialized")

        self._new(b"\x00", None)
Esempio n. 8
0
    def extent_location(self):
        '''
        A method to get the extent location of this El Torito Boot Catalog.

        Parameters:
         None.
        Returns:
         Integer extent location of this El Torito Boot Catalog.
        '''
        if not self._initialized:
            raise pycdlibexception.PyCdlibInternalError("El Torito Boot Catalog not yet initialized")

        return self._extent_location()
Esempio n. 9
0
    def set_dirrecord(self, rec):
        '''
        A method to set the Directory Record associated with this Boot Catalog.

        Parameters:
         rec - The DirectoryRecord object to associate with this Boot Catalog.
        Returns:
         Nothing.
        '''
        if not self._initialized:
            raise pycdlibexception.PyCdlibInternalError("El Torito Boot Catalog not yet initialized")

        self.dirrecord = rec
Esempio n. 10
0
    def set_dirrecord(self, rec):
        '''
        A method to set the directory record associated with this El Torito
        Entry.

        Parameters:
         rec - The DirectoryRecord object corresponding to this entry.
        Returns:
         Nothing.
        '''
        if not self._initialized:
            raise pycdlibexception.PyCdlibInternalError("El Torito Entry not yet initialized")
        self.dirrecord = rec
Esempio n. 11
0
    def extent_location(self):
        '''
        A method to get the location of this Directory Record on the ISO.

        Parameters:
         None.
        Returns:
         Extent location of this Directory Record on the ISO.
        '''
        if not self._initialized:
            raise pycdlibexception.PyCdlibInternalError(
                "Directory Record not yet initialized")
        return self._extent_location()
Esempio n. 12
0
    def file_identifier(self):
        '''
        A method to get the identifier of this Directory Record.

        Parameters:
         None.
        Returns:
         String representing the identifier of this Directory Record.
        '''
        if not self._initialized:
            raise pycdlibexception.PyCdlibInternalError(
                "Directory Record not yet initialized")
        return self._printable_name
Esempio n. 13
0
    def record(self):
        '''
        A method to generate a string representing this boot info table.

        Parameters:
         None.
        Returns:
         A string representing this boot info table.
        '''
        if not self._initialized:
            raise pycdlibexception.PyCdlibInternalError("This Eltorito Boot Info Table not yet initialized")

        return struct.pack("=LLLL", self.vd.extent_location(), self.dirrecord.extent_location(), self.orig_len, self.csum) + b'\x00' * 40
Esempio n. 14
0
    def get_rba(self):
        '''
        A method to get the load_rba for this El Torito Entry.

        Parameters:
         None.
        Returns:
         The load RBA for this El Torito Entry.
        '''
        if not self._initialized:
            raise pycdlibexception.PyCdlibInternalError("El Torito Entry not yet initialized")

        return self.load_rba
Esempio n. 15
0
def copy_data(data_length, blocksize, infp, outfp):
    '''
    A utility function to copy data from the input file object to the output
    file object.  This function will use the most efficient copy method available,
    which is often sendfile.

    Parameters:
     data_length - The amount of data to copy.
     blocksize - How much data to copy per iteration.
     infp - The file object to copy data from.
     outfp - The file object to copy data to.
    Returns:
     Nothing.
    '''
    use_sendfile = False
    if have_sendfile:
        # Python 3 implements the fileno method for all file-like objects, so
        # we can't just use the existence of the method to tell whether it is
        # available.  Instead, we try to assign it, and if we fail, then we
        # assume it is not available.
        try:
            x_unused = infp.fileno()  # NOQA
            y_unused = outfp.fileno()  # NOQA
            use_sendfile = True
        except (AttributeError, io.UnsupportedOperation):
            pass

    if use_sendfile:
        # This is one of those instances where using the file object and the
        # file descriptor causes problems.  The sendfile() call actually updates
        # the underlying file descriptor, but the file object does not know
        # about it.  To get around this, we instead get the offset, allow
        # sendfile() to update the offset, then manually seek the file object
        # to the right location.  This ensures that the file object gets updated
        # properly.
        in_offset = infp.tell()
        out_offset = outfp.tell()
        sendfile(outfp.fileno(), infp.fileno(), in_offset, data_length)
        infp.seek(in_offset + data_length)
        outfp.seek(out_offset + data_length)
    else:
        left = data_length
        readsize = blocksize
        while left > 0:
            if left < readsize:
                readsize = left
            data = infp.read(readsize)
            if len(data) != readsize:
                raise pycdlibexception.PyCdlibInternalError("Failed to read expected bytes")
            outfp.write(data)
            left -= readsize
Esempio n. 16
0
    def record(self):
        '''
        A method to generate a string representing this El Torito Validation
        Entry.

        Parameters:
         None.
        Returns:
         String representing this El Torito Validation Entry.
        '''
        if not self._initialized:
            raise pycdlibexception.PyCdlibInternalError('El Torito Validation Entry not yet initialized')

        return self._record()
    def update_rba(self, 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.
        '''
        if not self._initialized:
            raise pycdlibexception.PyCdlibInternalError(
                'This IsoHybrid object is not yet initialized')

        self.rba = current_extent
    def record_padding(self, iso_size):
        '''
        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]
Esempio n. 19
0
    def add_boot_info_table(self, 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.
        '''
        if not self._initialized:
            raise pycdlibexception.PyCdlibInternalError(
                'Inode is not yet initialized')

        self.boot_info_table = boot_info_table
Esempio n. 20
0
    def get_data_length(self):
        '''
        Get the length of the data pointed to by this Inode.

        Parameters:
         None.
        Returns:
         The length of the data pointed to by this Inode.
        '''
        if not self._initialized:
            raise pycdlibexception.PyCdlibInternalError(
                'Inode is not yet initialized')

        return self.data_length
Esempio n. 21
0
    def set_location(self, extent):
        '''
        Set the current location of this Inode on the ISO.

        Parameters:
         extent - The new extent location for this Inode.
        Returns:
         Nothing.
        '''
        if not self._initialized:
            raise pycdlibexception.PyCdlibInternalError(
                'Inode is not yet initialized')

        self.new_extent_loc = extent
Esempio n. 22
0
    def update_catalog_extent(self, current_extent):
        # type: (int) -> None
        '''
        Update the extent associated with this Boot Catalog.

        Parameters:
         current_extent - New extent to associate with this Boot Catalog
        Returns:
         Nothing.
        '''
        if not self._initialized:
            raise pycdlibexception.PyCdlibInternalError('El Torito Boot Catalog not yet initialized')

        self.br.update_boot_system_use(struct.pack('<L', current_extent))
Esempio n. 23
0
    def extent_location(self):
        # type: () -> int
        '''
        Get the extent location of this El Torito Boot Catalog.

        Parameters:
         None.
        Returns:
         Integer extent location of this El Torito Boot Catalog.
        '''
        if not self._initialized:
            raise pycdlibexception.PyCdlibInternalError('El Torito Boot Catalog not yet initialized')

        return self._extent_location()
Esempio n. 24
0
    def add_dirrecord(self, rec):
        # type: (Union[dr.DirectoryRecord, udfmod.UDFFileEntry]) -> None
        '''
        Set the Directory Record associated with this Boot Catalog.

        Parameters:
         rec - The DirectoryRecord object to associate with this Boot Catalog.
        Returns:
         Nothing.
        '''
        if not self._initialized:
            raise pycdlibexception.PyCdlibInternalError('El Torito Boot Catalog not yet initialized')

        self.dirrecords.append(rec)
Esempio n. 25
0
    def set_inode(self, ino):
        # type: (inode.Inode) -> None
        '''
        A method to set the Inode associated with this El Torito Entry.

        Parameters:
         ino - The Inode object corresponding to this entry.
        Returns:
         Nothing.
        '''
        if not self._initialized:
            raise pycdlibexception.PyCdlibInternalError(
                'El Torito Entry not yet initialized')
        self.inode = ino
Esempio n. 26
0
    def length(self):
        '''
        A method to get the length, in bytes, of this El Torito Entry.

        Parameters:
         None.
        Returns:
         An integer representing the length in bytes of this El Torito Entry.
        '''
        if not self._initialized:
            raise pycdlibexception.PyCdlibInternalError('El Torito Entry not initialized')
        # According to El Torito, the sector count is in virtual sectors, which
        # are defined to be 512 bytes.
        return self.sector_count * 512
Esempio n. 27
0
    def set_record_not_last(self):
        '''
        A method to set this Section Header so that it is *not* the last one in
        the Boot Catalog; this is used when a new header is added.

        Parameters:
         None.
        Returns:
         Nothing.
        '''
        if not self._initialized:
            raise pycdlibexception.PyCdlibInternalError('El Torito Section Header not yet initialized')

        self.header_indicator = 0x90
Esempio n. 28
0
    def get_rba(self):
        # type: () -> int
        '''
        Get the load_rba for this El Torito Entry.

        Parameters:
         None.
        Returns:
         The load RBA for this El Torito Entry.
        '''
        if not self._initialized:
            raise pycdlibexception.PyCdlibInternalError('El Torito Entry not yet initialized')

        return self.load_rba
Esempio n. 29
0
    def set_data_length(self, length):
        # type: (int) -> None
        '''
        A method to set the length of data for this El Torito Entry.

        Parameters:
         length - The new length for the El Torito Entry.
        Returns:
         Nothing.
        '''
        if not self._initialized:
            raise pycdlibexception.PyCdlibInternalError(
                'El Torito Entry not initialized')
        self.sector_count = utils.ceiling_div(length, 512)
Esempio n. 30
0
    def set_data_location(self, current_extent, tag_location):  # pylint: disable=unused-argument
        # type: (int, int) -> None
        '''
        Update the extent (and RBA) for this entry.

        Parameters:
         current_extent - The new extent to set for this entry.
        Returns:
         Nothing.
        '''
        if not self._initialized:
            raise pycdlibexception.PyCdlibInternalError('El Torito Entry not yet initialized')

        self.load_rba = current_extent