File: DtaEndianFixup.h

package info (click to toggle)
sedutil 1.20.0-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 1,744 kB
  • sloc: cpp: 8,386; xml: 1,433; sh: 810; ansic: 721; makefile: 110
file content (49 lines) | stat: -rw-r--r-- 2,030 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
/* C:B**************************************************************************
This software is Copyright 2014-2017 Bright Plaza Inc. <drivetrust@drivetrust.com>

This file is part of sedutil.

sedutil is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.

sedutil is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
GNU General Public License for more details.

You should have received a copy of the GNU General Public License
along with sedutil.  If not, see <http://www.gnu.org/licenses/>.

* C:E********************************************************************** */
/* These are a few macros to fixup the endianess of the data
 * returned by the drive as specified in the TCG OPAL SSC standards
 * Since this is a low use utility program it shouldn't be to
 * ugly that these are macros
 */

/*
 * Windows provides system call in the network stack to do this but
 * I've never had much luck when the winsock headers get in the mix
 */
//
//TODO: add a test on the endianess of the system and define
//  empty macros if the system is big endian
#pragma once
#ifdef __gnu_linux__
#include <endian.h>
#if __BYTE_ORDER != __LITTLE_ENDIAN
#error This code does not support big endian architectures
#endif
#endif
/** change the "endianess" of a 16bit field */
#define SWAP16(x) ((uint16_t) ((x & 0x00ff) << 8) | ((x & 0xff00) >> 8))
/** change the "endianess" of a 32bit field */
#define SWAP32(x) ((uint32_t) (((x) & 0x000000ff) << 24) | (((x) & 0x0000ff00) << 8) \
	                        | (((x) & 0x00ff0000) >> 8) | (((x) & 0xff000000) >> 24))
/** change the "endianess" of a 64bit field */
#define SWAP64(x) (uint64_t) \
	((uint64_t) (SWAP32((x & 0x00000000ffffffff)) << 32) | \
	((uint64_t) (SWAP32((x >> 32))) )    \
	)