2 * SPDX-License-Identifier: BSD-3-Clause
14 * Definitions and structure taken from
15 * https://github.com/util-linux/util-linux/blob/master/include/swapheader.h
18 #define SWAP_VERSION 1
19 #define SWAP_UUID_LENGTH 16
20 #define SWAP_LABEL_LENGTH 16
21 #define SWAP_SIGNATURE "SWAPSPACE2"
22 #define SWAP_SIGNATURE_SZ (sizeof(SWAP_SIGNATURE) - 1)
24 struct swap_header_v1_2 {
25 char bootbits[1024]; /* Space for disklabel etc. */
29 unsigned char uuid[SWAP_UUID_LENGTH];
30 char volume_name[SWAP_LABEL_LENGTH];
31 uint32_t padding[117];
36 struct swap_header_v1_2 header;
38 uint8_t reserved[4096 - SWAP_SIGNATURE_SZ];
39 char signature[SWAP_SIGNATURE_SZ];
43 #define sw_version header.version
44 #define sw_volume_name header.volume_name
45 #define sw_signature tail.signature
48 is_linux_swap(const char *name)
51 swhdr_t *hdr = (swhdr_t *) buf;
54 fd = open(name, O_RDONLY);
58 if (read(fd, buf, 4096) != 4096) {
64 return (hdr->sw_version == SWAP_VERSION &&
65 !memcmp(hdr->sw_signature, SWAP_SIGNATURE, SWAP_SIGNATURE_SZ));