qemu-file.h 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  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. */
  24. #ifndef MIGRATION_QEMU_FILE_H
  25. #define MIGRATION_QEMU_FILE_H
  26. #include <zlib.h>
  27. #include "exec/cpu-common.h"
  28. #include "io/channel.h"
  29. QEMUFile *qemu_file_new_input(QIOChannel *ioc);
  30. QEMUFile *qemu_file_new_output(QIOChannel *ioc);
  31. int qemu_fclose(QEMUFile *f);
  32. G_DEFINE_AUTOPTR_CLEANUP_FUNC(QEMUFile, qemu_fclose)
  33. /*
  34. * qemu_file_transferred:
  35. *
  36. * No flush is performed and the reported amount will include the size
  37. * of any queued buffers, on top of the amount actually transferred.
  38. *
  39. * Returns: the total bytes transferred and queued
  40. */
  41. uint64_t qemu_file_transferred(QEMUFile *f);
  42. /*
  43. * put_buffer without copying the buffer.
  44. * The buffer should be available till it is sent asynchronously.
  45. */
  46. void qemu_put_buffer_async(QEMUFile *f, const uint8_t *buf, size_t size,
  47. bool may_free);
  48. #include "migration/qemu-file-types.h"
  49. size_t coroutine_mixed_fn qemu_peek_buffer(QEMUFile *f, uint8_t **buf, size_t size, size_t offset);
  50. size_t coroutine_mixed_fn qemu_get_buffer_in_place(QEMUFile *f, uint8_t **buf, size_t size);
  51. /*
  52. * Note that you can only peek continuous bytes from where the current pointer
  53. * is; you aren't guaranteed to be able to peak to +n bytes unless you've
  54. * previously peeked +n-1.
  55. */
  56. int coroutine_mixed_fn qemu_peek_byte(QEMUFile *f, int offset);
  57. void qemu_file_skip(QEMUFile *f, int size);
  58. int qemu_file_get_error_obj_any(QEMUFile *f1, QEMUFile *f2, Error **errp);
  59. void qemu_file_set_error_obj(QEMUFile *f, int ret, Error *err);
  60. int qemu_file_get_error_obj(QEMUFile *f, Error **errp);
  61. void qemu_file_set_error(QEMUFile *f, int ret);
  62. int qemu_file_shutdown(QEMUFile *f);
  63. QEMUFile *qemu_file_get_return_path(QEMUFile *f);
  64. int qemu_fflush(QEMUFile *f);
  65. void qemu_file_set_blocking(QEMUFile *f, bool block);
  66. int qemu_file_get_to_fd(QEMUFile *f, int fd, size_t size);
  67. void qemu_set_offset(QEMUFile *f, off_t off, int whence);
  68. off_t qemu_get_offset(QEMUFile *f);
  69. void qemu_put_buffer_at(QEMUFile *f, const uint8_t *buf, size_t buflen,
  70. off_t pos);
  71. size_t qemu_get_buffer_at(QEMUFile *f, const uint8_t *buf, size_t buflen,
  72. off_t pos);
  73. QIOChannel *qemu_file_get_ioc(QEMUFile *file);
  74. int qemu_file_put_fd(QEMUFile *f, int fd);
  75. int qemu_file_get_fd(QEMUFile *f);
  76. #endif