qemu.py 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122
  1. # Copyright 2017 Cloudbase Solutions Srl
  2. # All Rights Reserved.
  3. import ctypes
  4. _libqemu = ctypes.CDLL('libqemu.so')
  5. MODULE_INIT_BLOCK = 0
  6. MODULE_INIT_OPTS = 1
  7. MODULE_INIT_QOM = 2
  8. MODULE_INIT_TRACE = 3
  9. MODULE_INIT_MAX = 4
  10. BDRV_BLOCK_DATA = 1
  11. BDRV_BLOCK_ZERO = 2
  12. BDRV_BLOCK_OFFSET_VALID = 4
  13. BDRV_BLOCK_RAW = 8
  14. BDRV_BLOCK_ALLOCATED = 0x10
  15. BDRV_BLOCK_EOF = 0x20
  16. BDRV_SECTOR_BITS = 9
  17. class QObject(ctypes.Structure):
  18. _fields_ = [("type", ctypes.c_void_p),
  19. ("refcnt", ctypes.c_size_t)]
  20. class QString(ctypes.Structure):
  21. _fields_ = [("base", QObject),
  22. ("string", ctypes.c_char_p),
  23. ("length", ctypes.c_size_t),
  24. ("capacity", ctypes.c_size_t)]
  25. class Error(ctypes.Structure):
  26. _fields_ = [("msg", ctypes.c_char_p),
  27. ("err_class", ctypes.c_int),
  28. ("src", ctypes.c_char_p),
  29. ("func", ctypes.c_char_p),
  30. ("line", ctypes.c_int),
  31. ("hint", ctypes.c_void_p)]
  32. _libqemu.qemu_vfree.argtypes = [ctypes.c_void_p]
  33. _libqemu.qemu_vfree.restype = None
  34. qemu_vfree = _libqemu.qemu_vfree
  35. _libqemu.module_call_init.argtypes = [ctypes.c_int]
  36. _libqemu.module_call_init.restype = None
  37. module_call_init = _libqemu.module_call_init
  38. _libqemu.qemu_init_exec_dir.argtypes = [ctypes.c_char_p]
  39. _libqemu.qemu_init_exec_dir.restype = None
  40. qemu_init_exec_dir = _libqemu.qemu_init_exec_dir
  41. _libqemu.qemu_init_main_loop.argtypes = [
  42. ctypes.POINTER(ctypes.POINTER(Error))]
  43. _libqemu.qemu_init_main_loop.res_type = ctypes.c_int
  44. qemu_init_main_loop = _libqemu.qemu_init_main_loop
  45. _libqemu.qcrypto_init.argtypes = [ctypes.POINTER(ctypes.POINTER(Error))]
  46. _libqemu.qcrypto_init.res_type = ctypes.c_int
  47. qcrypto_init = _libqemu.qcrypto_init
  48. _libqemu.error_set_progname.argtypes = [ctypes.c_char_p]
  49. _libqemu.error_set_progname.restype = None
  50. error_set_progname = _libqemu.error_set_progname
  51. _libqemu.error_reportf_err.argtypes = [ctypes.POINTER(Error), ctypes.c_char_p]
  52. _libqemu.error_reportf_err.res_type = None
  53. error_reportf_err = _libqemu.error_reportf_err
  54. _libqemu.qstring_from_str.argtypes = [ctypes.c_char_p]
  55. _libqemu.qstring_from_str.restype = ctypes.POINTER(QString)
  56. qstring_from_str = _libqemu.qstring_from_str
  57. _libqemu.qdict_new.argtypes = []
  58. _libqemu.qdict_new.res_type = ctypes.c_void_p
  59. qdict_new = _libqemu.qdict_new
  60. _libqemu.qdict_put_obj.argtypes = [
  61. ctypes.c_void_p, ctypes.c_char_p, ctypes.POINTER(QObject)]
  62. _libqemu.qdict_put_obj.restype = None
  63. qdict_put_obj = _libqemu.qdict_put_obj
  64. _libqemu.bdrv_init.argtypes = []
  65. _libqemu.bdrv_init.restype = None
  66. bdrv_init = _libqemu.bdrv_init
  67. _libqemu.blk_new_open.argtypes = [
  68. ctypes.c_char_p, ctypes.c_char_p, ctypes.c_void_p, ctypes.c_int,
  69. ctypes.POINTER(ctypes.POINTER(Error))]
  70. _libqemu.blk_new_open.restype = ctypes.c_void_p
  71. blk_new_open = _libqemu.blk_new_open
  72. _libqemu.blk_blockalign.argtypes = [ctypes.c_void_p, ctypes.c_size_t]
  73. _libqemu.blk_blockalign.restype = ctypes.c_void_p
  74. blk_blockalign = _libqemu.blk_blockalign
  75. _libqemu.blk_bs.argtypes = [ctypes.c_void_p]
  76. _libqemu.blk_bs.restype = ctypes.c_void_p
  77. blk_bs = _libqemu.blk_bs
  78. _libqemu.blk_nb_sectors.argtypes = [ctypes.c_void_p]
  79. _libqemu.blk_nb_sectors.restype = ctypes.c_int64
  80. blk_nb_sectors = _libqemu.blk_nb_sectors
  81. _libqemu.blk_pread.argtypes = [
  82. ctypes.c_void_p, ctypes.c_int64, ctypes.c_void_p, ctypes.c_int]
  83. _libqemu.blk_pread.res_type = ctypes.c_int
  84. blk_pread = _libqemu.blk_pread
  85. _libqemu.blk_unref.argtypes = [ctypes.c_void_p]
  86. _libqemu.blk_unref.restype = None
  87. blk_unref = _libqemu.blk_unref
  88. _libqemu.bdrv_get_block_status_above.argtypes = [
  89. ctypes.c_void_p, ctypes.c_void_p, ctypes.c_int64, ctypes.c_int,
  90. ctypes.POINTER(ctypes.c_int), ctypes.POINTER(ctypes.c_void_p)]
  91. _libqemu.bdrv_get_block_status_above.restype = ctypes.c_int64
  92. bdrv_get_block_status_above = _libqemu.bdrv_get_block_status_above