1 /* This example shows how to use qemu-nbd
2 * to open a local qcow2 file.
12 main (int argc
, const char *argv
[])
15 struct nbd_handle
*nbd
;
20 fprintf (stderr
, "open-qcow2 file.qcow2\n");
25 /* Create the libnbd handle. */
28 fprintf (stderr
, "%s\n", nbd_get_error ());
32 /* Run qemu-nbd as a subprocess using
33 * systemd socket activation.
36 "qemu-nbd", "-f", "qcow2",
40 if (nbd_connect_systemd_socket_activation (nbd
,
42 fprintf (stderr
, "%s\n", nbd_get_error ());
46 /* Read the first sector and print it. */
47 if (nbd_pread (nbd
, buf
, sizeof buf
, 0, 0) == -1) {
48 fprintf (stderr
, "%s\n", nbd_get_error ());
52 fp
= popen ("hexdump -C", "w");
54 perror ("popen: hexdump");
57 fwrite (buf
, sizeof buf
, 1, fp
);
60 /* Close the libnbd handle. */