Lines Matching +full:class +full:- +full:d

4 # SPDX-License-Identifier: GPL-2.0-only
9 are supported - the FIEMAP ioctl and the 'SEEK_HOLE / SEEK_DATA' features of
10 the file seek syscall. The former is implemented by the 'FilemapFiemap' class,
11 the latter is implemented by the 'FilemapSeek' class. Both classes provide the
12 same API. The 'filemap' function automatically selects which class can be used
13 and returns an instance of the class.
33 # Get the block size of the host file-system for the image file by calling
51 class ErrorNotSupp(Exception):
54 is not supported either by the kernel or the file-system.
58 class Error(Exception):
59 """A class for all the other exceptions raised by this module."""
63 class _FilemapBase(object):
65 This is a base class for a couple of other classes in this module. This
66 class simply performs the common parts of the initialization process: opens
73 Initialize a class instance. The 'image' argument is full path to the
102 self.blocks_cnt = self.image_size + self.block_size - 1
118 self._log.debug("block size %d, blocks count %d, image size %d"
122 """The class destructor which just closes the image file."""
168 returns '-1'. Otherwise the data or hole position is returned."""
176 return -1
178 raise ErrorNotSupp("the kernel or file-system does not support "
183 class FilemapSeek(_FilemapBase):
185 This class uses the 'SEEK_HOLE' and 'SEEK_DATA' to find file block mapping.
191 """Refer the '_FilemapBase' class for the documentation."""
193 # Call the base class constructor first
231 self._log.debug("lseek(0, SEEK_HOLE) returned %d" % offs)
232 raise ErrorNotSupp("the file-system does not support "
239 """Refer the '_FilemapBase' class for the documentation."""
241 if offs == -1:
246 self._log.debug("FilemapSeek: block_is_mapped(%d) returns %s"
262 if start == -1 or start >= limit or start == self.image_size:
266 if end == -1 or end == self.image_size:
272 end_blk = end // self.block_size - 1
273 self._log.debug("FilemapSeek: yielding range (%d, %d)"
278 """Refer the '_FilemapBase' class for the documentation."""
279 self._log.debug("FilemapSeek: get_mapped_ranges(%d, %d(%d))"
280 % (start, count, start + count - 1))
307 class FilemapFiemap(_FilemapBase):
309 This class provides API to the FIEMAP ioctl. Namely, it allows to iterate
312 This class synchronizes the image file every time it invokes the FIEMAP
313 ioctl in order to work-around early FIEMAP implementation kernel bugs.
318 Initialize a class instance. The 'image' argument is full the file
322 # Call the base class constructor first
329 self._buf_size -= _FIEMAP_SIZE
352 raise Error("bad block number %d, should be within [0, %d]"
359 # synchronizing the file is a necessary work-around.
371 "by the file-system"
385 """Refer the '_FilemapBase' class for the documentation."""
392 self._log.debug("FilemapFiemap: block_is_mapped(%d) returns %s"
437 # Extent length and offset have to be block-aligned
441 if extent_block > start + count - 1:
445 last = min(extent_block + extent_count, start + count) - 1
453 """Refer the '_FilemapBase' class for the documentation."""
454 self._log.debug("FilemapFiemap: get_mapped_ranges(%d, %d(%d))"
455 % (start, count, start + count - 1))
460 if last_prev == first - 1:
463 self._log.debug("FilemapFiemap: yielding range (%d, %d)"
468 self._log.debug("FilemapFiemap: yielding range (%d, %d)"
472 class FilemapNobmap(_FilemapBase):
474 This class is used when both the 'SEEK_DATA/HOLE' and FIEMAP are not
479 """Refer the '_FilemapBase' class for the documentation."""
481 # Call the base class constructor first
486 """Refer the '_FilemapBase' class for the documentation."""
490 """Refer the '_FilemapBase' class for the documentation."""
491 self._log.debug("FilemapNobmap: get_mapped_ranges(%d, %d(%d))"
492 % (start, count, start + count - 1))
493 yield (start, start + count -1)
497 Create and return an instance of a Filemap class - 'FilemapFiemap' or
499 FIEMAP ioctl is supported, an instance of the 'FilemapFiemap' class is
501 'FilemapSeek' class is returned. If none of these are supported, the
535 dst_size = os.path.getsize(src_fname) + seek - skip
551 written += start - skip - written
557 dst_file.seek(seek + start - skip, os.SEEK_SET)
560 to_read = end - start
565 chunk_size = to_read - read
568 size = length - written