blob: f5b9f430e04b1933747eba80587f9d88726c56a8 [file] [log] [blame]
Paolo Bonzini701a8f72012-01-13 17:07:20 +01001/*
2 * QEMU System Emulator
3 *
4 * Copyright (c) 2003-2008 Fabrice Bellard
5 *
6 * Permission is hereby granted, free of charge, to any person obtaining a copy
7 * of this software and associated documentation files (the "Software"), to deal
8 * in the Software without restriction, including without limitation the rights
9 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10 * copies of the Software, and to permit persons to whom the Software is
11 * furnished to do so, subject to the following conditions:
12 *
13 * The above copyright notice and this permission notice shall be included in
14 * all copies or substantial portions of the Software.
15 *
16 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
19 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
22 * THE SOFTWARE.
23 */
Markus Armbruster175de522016-06-29 15:29:06 +020024
Juan Quintela08a0aee2017-04-20 18:52:18 +020025#ifndef MIGRATION_QEMU_FILE_H
26#define MIGRATION_QEMU_FILE_H
Dr. David Alan Gilbertdeb22f92014-10-10 12:39:04 +010027
Xiao Guangrongdcaf4462018-03-30 15:51:20 +080028#include <zlib.h>
Markus Armbruster6a0acff2019-08-12 07:23:43 +020029#include "exec/cpu-common.h"
Peter Xuc6ad5be2021-07-22 13:58:40 -040030#include "io/channel.h"
Xiao Guangrongdcaf4462018-03-30 15:51:20 +080031
Daniel P. Berrangé77ef2dc2022-06-20 12:02:05 +010032QEMUFile *qemu_file_new_input(QIOChannel *ioc);
33QEMUFile *qemu_file_new_output(QIOChannel *ioc);
Paolo Bonzini701a8f72012-01-13 17:07:20 +010034int qemu_fclose(QEMUFile *f);
Daniel P. Berrangéfbfa6402022-06-20 12:01:50 +010035
Maciej S. Szmigierofda70ed2025-03-04 23:03:55 +010036G_DEFINE_AUTOPTR_CLEANUP_FUNC(QEMUFile, qemu_fclose)
37
Daniel P. Berrangéfbfa6402022-06-20 12:01:50 +010038/*
Juan Quintelae9c0eed2023-10-25 11:11:11 +020039 * qemu_file_transferred:
Daniel P. Berrangéfbfa6402022-06-20 12:01:50 +010040 *
Juan Quintelae9c0eed2023-10-25 11:11:11 +020041 * No flush is performed and the reported amount will include the size
42 * of any queued buffers, on top of the amount actually transferred.
Daniel P. Berrangéfbfa6402022-06-20 12:01:50 +010043 *
44 * Returns: the total bytes transferred and queued
45 */
Juan Quintelae9c0eed2023-10-25 11:11:11 +020046uint64_t qemu_file_transferred(QEMUFile *f);
Daniel P. Berrangéfbfa6402022-06-20 12:01:50 +010047
Orit Wasserman6181ec22013-03-22 16:48:02 +020048/*
49 * put_buffer without copying the buffer.
50 * The buffer should be available till it is sent asynchronously.
51 */
Pavel Butsykin53f09a12017-02-03 18:23:20 +030052void qemu_put_buffer_async(QEMUFile *f, const uint8_t *buf, size_t size,
53 bool may_free);
Paolo Bonzini701a8f72012-01-13 17:07:20 +010054
Juan Quintela08a0aee2017-04-20 18:52:18 +020055#include "migration/qemu-file-types.h"
Dr. David Alan Gilbertdeb22f92014-10-10 12:39:04 +010056
Paolo Bonzini394b9402022-12-16 12:48:16 +010057size_t coroutine_mixed_fn qemu_peek_buffer(QEMUFile *f, uint8_t **buf, size_t size, size_t offset);
58size_t coroutine_mixed_fn qemu_get_buffer_in_place(QEMUFile *f, uint8_t **buf, size_t size);
Dr. David Alan Gilbert9504fb52015-11-05 18:10:35 +000059
Dr. David Alan Gilbert548f52e2014-04-08 15:29:37 +010060/*
61 * Note that you can only peek continuous bytes from where the current pointer
62 * is; you aren't guaranteed to be able to peak to +n bytes unless you've
63 * previously peeked +n-1.
64 */
Paolo Bonzini394b9402022-12-16 12:48:16 +010065int coroutine_mixed_fn qemu_peek_byte(QEMUFile *f, int offset);
Eduardo Habkostc9615142013-11-28 12:01:10 -020066void qemu_file_skip(QEMUFile *f, int size);
Peter Xu60bb3c52022-07-07 14:55:06 -040067int qemu_file_get_error_obj_any(QEMUFile *f1, QEMUFile *f2, Error **errp);
Yury Kotov3d661c82019-04-22 13:34:20 +030068void qemu_file_set_error_obj(QEMUFile *f, int ret, Error *err);
Peter Xu7aa60702023-10-17 16:26:29 -040069int qemu_file_get_error_obj(QEMUFile *f, Error **errp);
Eduardo Habkostc9615142013-11-28 12:01:10 -020070void qemu_file_set_error(QEMUFile *f, int ret);
Dr. David Alan Gilberte1a8c9b2015-01-08 11:11:30 +000071int qemu_file_shutdown(QEMUFile *f);
Dr. David Alan Gilbertadc468e2015-11-05 18:10:43 +000072QEMUFile *qemu_file_get_return_path(QEMUFile *f);
Juan Quintelabe07a0e2023-10-25 11:11:17 +020073int qemu_fflush(QEMUFile *f);
Dr. David Alan Gilberta800cd52015-11-05 18:10:36 +000074void qemu_file_set_blocking(QEMUFile *f, bool block);
Avihai Horonc7a7db42023-02-09 21:20:35 +020075int qemu_file_get_to_fd(QEMUFile *f, int fd, size_t size);
Fabiano Rosas7f5b50a2024-02-29 12:30:00 -030076void qemu_set_offset(QEMUFile *f, off_t off, int whence);
77off_t qemu_get_offset(QEMUFile *f);
78void qemu_put_buffer_at(QEMUFile *f, const uint8_t *buf, size_t buflen,
79 off_t pos);
80size_t qemu_get_buffer_at(QEMUFile *f, const uint8_t *buf, size_t buflen,
81 off_t pos);
Paolo Bonzini701a8f72012-01-13 17:07:20 +010082
Peter Xuc6ad5be2021-07-22 13:58:40 -040083QIOChannel *qemu_file_get_ioc(QEMUFile *file);
Steve Sistareb5779dc2025-01-15 11:00:39 -080084int qemu_file_put_fd(QEMUFile *f, int fd);
85int qemu_file_get_fd(QEMUFile *f);
Juan Quintela08a0aee2017-04-20 18:52:18 +020086
Paolo Bonzini701a8f72012-01-13 17:07:20 +010087#endif