From: Michael A Cassaniti Date: Fri, 7 Oct 2022 06:14:39 +0000 (+1100) Subject: Chunk partition insert using sendfile because sendfile has a maximum transfer size X-Git-Tag: v14~14 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=022bbd35e0f40482478fd5ad2748c86aab699bb1;p=thirdparty%2Fmkosi.git Chunk partition insert using sendfile because sendfile has a maximum transfer size --- diff --git a/mkosi/__init__.py b/mkosi/__init__.py index 1b468f398..9418aad17 100644 --- a/mkosi/__init__.py +++ b/mkosi/__init__.py @@ -3661,7 +3661,15 @@ def insert_partition( # Without this the entire blob will be read into memory which could exceed system memory with open(path, mode='wb') as path_fp: - os.sendfile(path_fp.fileno(), blob.fileno(), offset=0, count=blob_size) + # Chunk size for 32/64-bit systems + # Chunking required because sendfile under Linux has a maximum copy size + chunksize = 2 ** 30 if sys.maxsize < 2 ** 32 else 0x7ffff000 + offset = 0 + while True: + sent = os.sendfile(path_fp.fileno(), blob.fileno(), offset=offset, count=chunksize) + if not sent: + break + offset += sent return part