108a0aee1SJuan Quintela /* 208a0aee1SJuan Quintela * QEMU System Emulator 308a0aee1SJuan Quintela * 408a0aee1SJuan Quintela * Copyright (c) 2003-2008 Fabrice Bellard 508a0aee1SJuan Quintela * 608a0aee1SJuan Quintela * Permission is hereby granted, free of charge, to any person obtaining a copy 708a0aee1SJuan Quintela * of this software and associated documentation files (the "Software"), to deal 808a0aee1SJuan Quintela * in the Software without restriction, including without limitation the rights 908a0aee1SJuan Quintela * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 1008a0aee1SJuan Quintela * copies of the Software, and to permit persons to whom the Software is 1108a0aee1SJuan Quintela * furnished to do so, subject to the following conditions: 1208a0aee1SJuan Quintela * 1308a0aee1SJuan Quintela * The above copyright notice and this permission notice shall be included in 1408a0aee1SJuan Quintela * all copies or substantial portions of the Software. 1508a0aee1SJuan Quintela * 1608a0aee1SJuan Quintela * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 1708a0aee1SJuan Quintela * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 1808a0aee1SJuan Quintela * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL 1908a0aee1SJuan Quintela * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 2008a0aee1SJuan Quintela * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 2108a0aee1SJuan Quintela * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 2208a0aee1SJuan Quintela * THE SOFTWARE. 2308a0aee1SJuan Quintela */ 2408a0aee1SJuan Quintela 2508a0aee1SJuan Quintela #ifndef MIGRATION_QEMU_FILE_H 2608a0aee1SJuan Quintela #define MIGRATION_QEMU_FILE_H 2708a0aee1SJuan Quintela 28dcaf446eSXiao Guangrong #include <zlib.h> 296a0acfffSMarkus Armbruster #include "exec/cpu-common.h" 30c6ad5be7SPeter Xu #include "io/channel.h" 31dcaf446eSXiao Guangrong 3277ef2dc1SDaniel P. Berrangé QEMUFile *qemu_file_new_input(QIOChannel *ioc); 3377ef2dc1SDaniel P. Berrangé QEMUFile *qemu_file_new_output(QIOChannel *ioc); 3408a0aee1SJuan Quintela int qemu_fclose(QEMUFile *f); 35fbfa6404SDaniel P. Berrangé 36fbfa6404SDaniel P. Berrangé /* 37e9c0eed7SJuan Quintela * qemu_file_transferred: 38fbfa6404SDaniel P. Berrangé * 39e9c0eed7SJuan Quintela * No flush is performed and the reported amount will include the size 40e9c0eed7SJuan Quintela * of any queued buffers, on top of the amount actually transferred. 41fbfa6404SDaniel P. Berrangé * 42fbfa6404SDaniel P. Berrangé * Returns: the total bytes transferred and queued 43fbfa6404SDaniel P. Berrangé */ 44e9c0eed7SJuan Quintela uint64_t qemu_file_transferred(QEMUFile *f); 45fbfa6404SDaniel P. Berrangé 4608a0aee1SJuan Quintela /* 4708a0aee1SJuan Quintela * put_buffer without copying the buffer. 4808a0aee1SJuan Quintela * The buffer should be available till it is sent asynchronously. 4908a0aee1SJuan Quintela */ 5008a0aee1SJuan Quintela void qemu_put_buffer_async(QEMUFile *f, const uint8_t *buf, size_t size, 5108a0aee1SJuan Quintela bool may_free); 5208a0aee1SJuan Quintela 5308a0aee1SJuan Quintela #include "migration/qemu-file-types.h" 5408a0aee1SJuan Quintela 55394b9407SPaolo Bonzini size_t coroutine_mixed_fn qemu_peek_buffer(QEMUFile *f, uint8_t **buf, size_t size, size_t offset); 56394b9407SPaolo Bonzini size_t coroutine_mixed_fn qemu_get_buffer_in_place(QEMUFile *f, uint8_t **buf, size_t size); 5708a0aee1SJuan Quintela 5808a0aee1SJuan Quintela /* 5908a0aee1SJuan Quintela * Note that you can only peek continuous bytes from where the current pointer 6008a0aee1SJuan Quintela * is; you aren't guaranteed to be able to peak to +n bytes unless you've 6108a0aee1SJuan Quintela * previously peeked +n-1. 6208a0aee1SJuan Quintela */ 63394b9407SPaolo Bonzini int coroutine_mixed_fn qemu_peek_byte(QEMUFile *f, int offset); 6408a0aee1SJuan Quintela void qemu_file_skip(QEMUFile *f, int size); 6560bb3c58SPeter Xu int qemu_file_get_error_obj_any(QEMUFile *f1, QEMUFile *f2, Error **errp); 663d661c8aSYury Kotov void qemu_file_set_error_obj(QEMUFile *f, int ret, Error *err); 677aa6070dSPeter Xu int qemu_file_get_error_obj(QEMUFile *f, Error **errp); 6808a0aee1SJuan Quintela void qemu_file_set_error(QEMUFile *f, int ret); 6908a0aee1SJuan Quintela int qemu_file_shutdown(QEMUFile *f); 7008a0aee1SJuan Quintela QEMUFile *qemu_file_get_return_path(QEMUFile *f); 71be07a0edSJuan Quintela int qemu_fflush(QEMUFile *f); 7208a0aee1SJuan Quintela void qemu_file_set_blocking(QEMUFile *f, bool block); 73c7a7db4bSAvihai Horon int qemu_file_get_to_fd(QEMUFile *f, int fd, size_t size); 74*7f5b50a4SFabiano Rosas void qemu_set_offset(QEMUFile *f, off_t off, int whence); 75*7f5b50a4SFabiano Rosas off_t qemu_get_offset(QEMUFile *f); 76*7f5b50a4SFabiano Rosas void qemu_put_buffer_at(QEMUFile *f, const uint8_t *buf, size_t buflen, 77*7f5b50a4SFabiano Rosas off_t pos); 78*7f5b50a4SFabiano Rosas size_t qemu_get_buffer_at(QEMUFile *f, const uint8_t *buf, size_t buflen, 79*7f5b50a4SFabiano Rosas off_t pos); 8008a0aee1SJuan Quintela 81c6ad5be7SPeter Xu QIOChannel *qemu_file_get_ioc(QEMUFile *file); 8208a0aee1SJuan Quintela 8308a0aee1SJuan Quintela #endif 84