xref: /src/sys/contrib/openzfs/cmd/zstream/zstream_util.h (revision 80aae8a3f8aa70712930664572be9e6885dc0be7)
1 // SPDX-License-Identifier: CDDL-1.0
2 /*
3  * CDDL HEADER START
4  *
5  * This file and its contents are supplied under the terms of the
6  * Common Development and Distribution License ("CDDL"), version 1.0.
7  * You may only use this file in accordance with the terms of version
8  * 1.0 of the CDDL.
9  *
10  * A full copy of the text of the CDDL should have accompanied this
11  * source.  A copy of the CDDL is also available via the Internet at
12  * http://www.illumos.org/license/CDDL.
13  *
14  * CDDL HEADER END
15  */
16 
17 /*
18  * Copyright (c) 2026 by Garth Snyder. All rights reserved.
19  */
20 
21 #ifndef	_ZSTREAM_UTIL_H
22 #define	_ZSTREAM_UTIL_H
23 
24 #ifdef	__cplusplus
25 extern "C" {
26 #endif
27 
28 #include <stddef.h>
29 #include <sys/zfs_ioctl.h>
30 #include <sys/zio_checksum.h>
31 
32 /*
33  * The safe_ versions of the functions below terminate the process if the
34  * operation doesn't succeed instead of returning an error.
35  */
36 extern void *
37 safe_malloc(size_t size);
38 
39 extern void *
40 safe_calloc(size_t n);
41 
42 extern int
43 sfread(void *buf, size_t size, FILE *fp);
44 
45 /*
46  * 1) Update checksum with the record header up to drr_checksum.
47  * 2) Update checksum field in the record header.
48  * 3) Update checksum with the checksum field in the record header.
49  * 4) Update checksum with the contents of the payload.
50  * 5) Write header and payload to fd.
51  */
52 extern int
53 dump_record(dmu_replay_record_t *drr, void *payload, size_t payload_len,
54 	zio_cksum_t *zc, int outfd);
55 
56 #ifdef __cplusplus
57 }
58 #endif
59 
60 #endif  /* _ZSTREAM_UTIL_H */
61