xref: /freebsd/sys/contrib/openzfs/cmd/zstream/zstream_byteswap.h (revision d0b3ecdc274930e190ea233b6b69ff03782eaf8d)
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 Common
6  * Development and Distribution License ("CDDL"), version 1.0. You may only use
7  * this file in accordance with the terms of version 1.0 of the CDDL.
8  *
9  * A full copy of the text of the CDDL should have accompanied this source. A
10  * copy of the CDDL is also available via the Internet at
11  * http://www.illumos.org/license/CDDL.
12  *
13  * CDDL HEADER END
14  */
15 
16 /*
17  * Copyright (c) 2026 by Garth Snyder. All rights reserved.
18  */
19 
20 #ifndef _ZSTREAM_BYTESWAP_H
21 #define	_ZSTREAM_BYTESWAP_H
22 
23 #ifdef __cplusplus
24 extern "C" {
25 #endif
26 
27 #include "zstream_io.h"
28 
29 #define	MAX_BYTESWAP 4  /* Most swapping ops in a chain */
30 
31 /*
32  * Byteswapping is generally done both on input and on output. By default,
33  * the stream's endianness is preserved. That is, opposite-endian streams
34  * are byteswapped for processing by other modules, then ultimately
35  * de-byteswapped for output.
36  */
37 typedef enum { BS_INCOMING, BS_OUTGOING } byteswap_stage_t;
38 
39 chain_step_t
40 serial_byteswap(byteswap_stage_t stage);
41 
42 /*
43  * Unconditionally swap a record. drr_type is passed in separately because
44  * we don't know whether we're doing input or output swapping. We need
45  * that value in native byte order to know how to swap the rest of the
46  * record.
47  */
48 extern void
49 byteswap_record(dmu_replay_record_t *drr, uint32_t drr_type);
50 
51 #ifdef __cplusplus
52 }
53 #endif
54 
55 #endif  /* _ZSTREAM_BYTESWAP_H */
56