Lines Matching +full:os +full:- +full:data +full:- +full:offset

11 # SPDX-License-Identifier: GPL-2.0-or-later
15 # - qcow2 header
16 # - refcount table
17 # - refcount blocks
18 # - L1 table
19 # - L2 tables
20 # - Data clusters
30 import os
47 QEMU_STORAGE_DAEMON = "qemu-storage-daemon"
70 # are known to contain data. Those are the ones that we need to read.
75 data_from = os.lseek(fd, data_to, os.SEEK_DATA)
76 data_to = align_up(os.lseek(fd, data_from, os.SEEK_HOLE), cluster_size)
86 # format we can use qemu-storage-daemon to make it appear as raw.
94 pid_file = os.path.join(temp_dir, "pid")
95 raw_file = os.path.join(temp_dir, "raw")
100 "--daemonize",
101 "--pidfile", pid_file,
102 … "--blockdev", f"driver=file,node-name=file0,driver=file,filename={input_file},read-only=on",
103 "--blockdev", f"driver={input_format},node-name=disk0,file=file0,read-only=on",
104 … "--export", f"type=fuse,id=export0,node-name=disk0,mountpoint={raw_file},writable=off",
109 sys.exit("[Error] Could not start the qemu-storage-daemon:\n" +
115 if os.path.exists(pid_file):
118 os.kill(pid, signal.SIGTERM)
119 while os.path.exists(pid_file):
121 os.unlink(raw_file)
122 os.rmdir(temp_dir)
125 def write_features(cluster, offset, data_file_name): argument
127 encoded_name = data_file_name.encode("utf-8")
129 struct.pack_into(f">II{padded_name_len}s", cluster, offset,
133 offset += 8 + padded_name_len
139 (0, 2, "external data file"),
146 (2, 1, "raw external data"),
148 struct.pack_into(">I", cluster, offset, QCOW2_FEATURE_NAME_TABLE)
149 struct.pack_into(">I", cluster, offset + 4, len(qcow2_features) * 48)
150 offset += 8
152 struct.pack_into(">BB46s", cluster, offset,
154 offset += 48
164 # Virtual disk size, number of data clusters and L1 entries
165 disk_size = align_up(os.path.getsize(input_file), 512)
190 fd = os.open(input_file, os.O_RDONLY)
192 # Read all the clusters that contain data
194 cluster = os.pread(fd, cluster_size, cluster_size * idx)
197 cluster += bytes(cluster_size - len(cluster))
198 # If a cluster has non-zero data then it must be allocated
203 # Allocated data clusters also need their corresponding L1 entry and L2 table
271 0, # backing file offset
281 0, # snapshot table offset
299 remaining_refcount_table_entries -= to_write
310 remaining_refcount_block_entries -= to_write
358 ### Write data clusters
361 cluster = os.pread(fd, cluster_size, cluster_size * idx)
364 cluster += bytes(cluster_size - len(cluster))
368 os.close(fd)
372 # Command-line arguments
379 "-f",
386 "-c",
395 "-r",
404 "-d",
406 help="create an image with input_file as an external data file",
410 "-R",
412 help="enable data_file_raw on the generated image (implies -d)",
420 if not os.path.isfile(args.input_file):
424 sys.exit("[Error] External data files can only be used with raw input images")
426 # A 512 byte header is too small for the data file name extension
428 sys.exit("[Error] External data files require a larger cluster size")