18 #ifndef __XEMU_COMMON_EMUTOOLS_SNAPSHOT_H_INCLUDED
19 #define __XEMU_COMMON_EMUTOOLS_SNAPSHOT_H_INCLUDED
21 #ifdef XEMU_SNAPSHOT_SUPPORT
23 #define XEMUSNAP_MAX_IDENT_LENGTH 64
24 #define XEMUSNAP_ERROR_BUFFER_SIZE 256
25 #define XEMUSNAP_FIXED_HEADER_SIZE 21
26 #define XEMUSNAP_FRAMING_VERSION 0
28 #define XSNAPERR_NODATA 1
29 #define XSNAPERR_TRUNCATED 2
30 #define XSNAPERR_FORMAT 3
32 #define XSNAPERR_CALLBACK 5
34 #define RETURN_XSNAPERR_USER(...) \
36 snprintf(xemusnap_user_error_buffer, XEMUSNAP_ERROR_BUFFER_SIZE, __VA_ARGS__); \
37 return XSNAPERR_CALLBACK; \
40 struct xemu_snapshot_block_st {
47 char idstr[XEMUSNAP_MAX_IDENT_LENGTH + 1];
53 struct xemu_snapshot_definition_st;
55 typedef int (*xemu_snapshot_load_callback_t)(
const struct xemu_snapshot_definition_st * ,
struct xemu_snapshot_block_st * );
56 typedef int (*xemu_snapshot_save_callback_t)(
const struct xemu_snapshot_definition_st * );
58 struct xemu_snapshot_definition_st {
61 xemu_snapshot_load_callback_t
load;
62 xemu_snapshot_save_callback_t save;
66 extern char xemusnap_error_buffer[];
67 extern char xemusnap_user_error_buffer[];
70 static inline Uint64 P_AS_BE64 (
const Uint8 *p ) {
71 return ((Uint64)p[0] << 56) | ((Uint64)p[1] << 48) | ((Uint64)p[2] << 40) | ((Uint64)p[3] << 32) | ((Uint64)p[4] << 24) | ((Uint64)p[5] << 16) | ((Uint64)p[6] << 8) | (Uint64)p[7];
79 static inline void U64_AS_BE (
Uint8 *p, Uint64 n ) {
80 p[0] = n >> 56; p[1] = n >> 48; p[2] = n >> 40; p[3] = n >> 32; p[4] = n >> 24; p[5] = n >> 16; p[6] = n >> 8; p[7] = n;
82 static inline void U32_AS_BE (
Uint8 *p,
Uint32 n ) {
83 p[0] = n >> 24; p[1] = n >> 16; p[2] = n >> 8; p[3] = n;
85 static inline void U16_AS_BE (
Uint8 *p,
Uint16 n ) {
86 p[0] = n >> 8; p[1] = n;
89 extern void xemusnap_init (
const struct xemu_snapshot_definition_st *def );
90 extern int xemusnap_read_file (
void *buffer,
size_t size );
91 extern int xemusnap_skip_file_bytes ( off_t
size );
92 extern int xemusnap_write_file (
const void *buffer,
size_t size );
93 extern int xemusnap_read_block_header (
struct xemu_snapshot_block_st *
block );
94 extern int xemusnap_write_block_header (
const char *ident,
Uint32 version );
95 extern int xemusnap_read_be32 (
Uint32 *result );
96 extern int xemusnap_skip_sub_blocks (
int num );
97 extern int xemusnap_write_sub_block (
const Uint8 *buffer,
Uint32 size );
98 extern int xemusnap_load (
const char *filename );
99 extern int xemusnap_save (
const char *filename );