Paolo Bonzini | 701a8f7 | 2012-01-13 17:07:20 +0100 | [diff] [blame] | 1 | /* |
| 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 Armbruster | 175de52 | 2016-06-29 15:29:06 +0200 | [diff] [blame] | 24 | |
Juan Quintela | 08a0aee | 2017-04-20 18:52:18 +0200 | [diff] [blame] | 25 | #ifndef MIGRATION_QEMU_FILE_H |
| 26 | #define MIGRATION_QEMU_FILE_H |
Dr. David Alan Gilbert | deb22f9 | 2014-10-10 12:39:04 +0100 | [diff] [blame] | 27 | |
Xiao Guangrong | dcaf446 | 2018-03-30 15:51:20 +0800 | [diff] [blame] | 28 | #include <zlib.h> |
Markus Armbruster | 6a0acff | 2019-08-12 07:23:43 +0200 | [diff] [blame] | 29 | #include "exec/cpu-common.h" |
Peter Xu | c6ad5be | 2021-07-22 13:58:40 -0400 | [diff] [blame] | 30 | #include "io/channel.h" |
Xiao Guangrong | dcaf446 | 2018-03-30 15:51:20 +0800 | [diff] [blame] | 31 | |
Daniel P. Berrangé | 77ef2dc | 2022-06-20 12:02:05 +0100 | [diff] [blame] | 32 | QEMUFile *qemu_file_new_input(QIOChannel *ioc); |
| 33 | QEMUFile *qemu_file_new_output(QIOChannel *ioc); |
Paolo Bonzini | 701a8f7 | 2012-01-13 17:07:20 +0100 | [diff] [blame] | 34 | int qemu_fclose(QEMUFile *f); |
Daniel P. Berrangé | fbfa640 | 2022-06-20 12:01:50 +0100 | [diff] [blame] | 35 | |
Maciej S. Szmigiero | fda70ed | 2025-03-04 23:03:55 +0100 | [diff] [blame] | 36 | G_DEFINE_AUTOPTR_CLEANUP_FUNC(QEMUFile, qemu_fclose) |
| 37 | |
Daniel P. Berrangé | fbfa640 | 2022-06-20 12:01:50 +0100 | [diff] [blame] | 38 | /* |
Juan Quintela | e9c0eed | 2023-10-25 11:11:11 +0200 | [diff] [blame] | 39 | * qemu_file_transferred: |
Daniel P. Berrangé | fbfa640 | 2022-06-20 12:01:50 +0100 | [diff] [blame] | 40 | * |
Juan Quintela | e9c0eed | 2023-10-25 11:11:11 +0200 | [diff] [blame] | 41 | * 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é | fbfa640 | 2022-06-20 12:01:50 +0100 | [diff] [blame] | 43 | * |
| 44 | * Returns: the total bytes transferred and queued |
| 45 | */ |
Juan Quintela | e9c0eed | 2023-10-25 11:11:11 +0200 | [diff] [blame] | 46 | uint64_t qemu_file_transferred(QEMUFile *f); |
Daniel P. Berrangé | fbfa640 | 2022-06-20 12:01:50 +0100 | [diff] [blame] | 47 | |
Orit Wasserman | 6181ec2 | 2013-03-22 16:48:02 +0200 | [diff] [blame] | 48 | /* |
| 49 | * put_buffer without copying the buffer. |
| 50 | * The buffer should be available till it is sent asynchronously. |
| 51 | */ |
Pavel Butsykin | 53f09a1 | 2017-02-03 18:23:20 +0300 | [diff] [blame] | 52 | void qemu_put_buffer_async(QEMUFile *f, const uint8_t *buf, size_t size, |
| 53 | bool may_free); |
Paolo Bonzini | 701a8f7 | 2012-01-13 17:07:20 +0100 | [diff] [blame] | 54 | |
Juan Quintela | 08a0aee | 2017-04-20 18:52:18 +0200 | [diff] [blame] | 55 | #include "migration/qemu-file-types.h" |
Dr. David Alan Gilbert | deb22f9 | 2014-10-10 12:39:04 +0100 | [diff] [blame] | 56 | |
Paolo Bonzini | 394b940 | 2022-12-16 12:48:16 +0100 | [diff] [blame] | 57 | size_t coroutine_mixed_fn qemu_peek_buffer(QEMUFile *f, uint8_t **buf, size_t size, size_t offset); |
| 58 | size_t coroutine_mixed_fn qemu_get_buffer_in_place(QEMUFile *f, uint8_t **buf, size_t size); |
Dr. David Alan Gilbert | 9504fb5 | 2015-11-05 18:10:35 +0000 | [diff] [blame] | 59 | |
Dr. David Alan Gilbert | 548f52e | 2014-04-08 15:29:37 +0100 | [diff] [blame] | 60 | /* |
| 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 Bonzini | 394b940 | 2022-12-16 12:48:16 +0100 | [diff] [blame] | 65 | int coroutine_mixed_fn qemu_peek_byte(QEMUFile *f, int offset); |
Eduardo Habkost | c961514 | 2013-11-28 12:01:10 -0200 | [diff] [blame] | 66 | void qemu_file_skip(QEMUFile *f, int size); |
Peter Xu | 60bb3c5 | 2022-07-07 14:55:06 -0400 | [diff] [blame] | 67 | int qemu_file_get_error_obj_any(QEMUFile *f1, QEMUFile *f2, Error **errp); |
Yury Kotov | 3d661c8 | 2019-04-22 13:34:20 +0300 | [diff] [blame] | 68 | void qemu_file_set_error_obj(QEMUFile *f, int ret, Error *err); |
Peter Xu | 7aa6070 | 2023-10-17 16:26:29 -0400 | [diff] [blame] | 69 | int qemu_file_get_error_obj(QEMUFile *f, Error **errp); |
Eduardo Habkost | c961514 | 2013-11-28 12:01:10 -0200 | [diff] [blame] | 70 | void qemu_file_set_error(QEMUFile *f, int ret); |
Dr. David Alan Gilbert | e1a8c9b | 2015-01-08 11:11:30 +0000 | [diff] [blame] | 71 | int qemu_file_shutdown(QEMUFile *f); |
Dr. David Alan Gilbert | adc468e | 2015-11-05 18:10:43 +0000 | [diff] [blame] | 72 | QEMUFile *qemu_file_get_return_path(QEMUFile *f); |
Juan Quintela | be07a0e | 2023-10-25 11:11:17 +0200 | [diff] [blame] | 73 | int qemu_fflush(QEMUFile *f); |
Dr. David Alan Gilbert | a800cd5 | 2015-11-05 18:10:36 +0000 | [diff] [blame] | 74 | void qemu_file_set_blocking(QEMUFile *f, bool block); |
Avihai Horon | c7a7db4 | 2023-02-09 21:20:35 +0200 | [diff] [blame] | 75 | int qemu_file_get_to_fd(QEMUFile *f, int fd, size_t size); |
Fabiano Rosas | 7f5b50a | 2024-02-29 12:30:00 -0300 | [diff] [blame] | 76 | void qemu_set_offset(QEMUFile *f, off_t off, int whence); |
| 77 | off_t qemu_get_offset(QEMUFile *f); |
| 78 | void qemu_put_buffer_at(QEMUFile *f, const uint8_t *buf, size_t buflen, |
| 79 | off_t pos); |
| 80 | size_t qemu_get_buffer_at(QEMUFile *f, const uint8_t *buf, size_t buflen, |
| 81 | off_t pos); |
Paolo Bonzini | 701a8f7 | 2012-01-13 17:07:20 +0100 | [diff] [blame] | 82 | |
Peter Xu | c6ad5be | 2021-07-22 13:58:40 -0400 | [diff] [blame] | 83 | QIOChannel *qemu_file_get_ioc(QEMUFile *file); |
Steve Sistare | b5779dc | 2025-01-15 11:00:39 -0800 | [diff] [blame] | 84 | int qemu_file_put_fd(QEMUFile *f, int fd); |
| 85 | int qemu_file_get_fd(QEMUFile *f); |
Juan Quintela | 08a0aee | 2017-04-20 18:52:18 +0200 | [diff] [blame] | 86 | |
Paolo Bonzini | 701a8f7 | 2012-01-13 17:07:20 +0100 | [diff] [blame] | 87 | #endif |