2
* Copyright (C) 1999 by Andries Brouwer
3
* Copyright (C) 1999, 2000, 2003 by Theodore Ts'o
4
* Copyright (C) 2001 by Andreas Dilger
5
* Copyright (C) 2004 Kay Sievers <kay.sievers@vrfy.org>
6
* Copyright (C) 2008 Karel Zak <kzak@redhat.com>
8
* This file may be redistributed under the terms of the
9
* GNU Lesser General Public License.
19
#include "superblocks.h"
21
/* linux-2.6/include/linux/swap.h */
22
struct swap_header_v1_2 {
23
/* char bootbits[1024]; */ /* Space for disklabel etc. */
27
unsigned char uuid[16];
28
unsigned char volume[16];
29
uint32_t padding[117];
31
} __attribute__((packed));
33
#define PAGESIZE_MIN 0xff6 /* 4086 (arm, i386, ...) */
34
#define PAGESIZE_MAX 0xfff6 /* 65526 (ia64) */
36
#define TOI_MAGIC_STRING "\xed\xc3\x02\xe9\x98\x56\xe5\x0c"
37
#define TOI_MAGIC_STRLEN (sizeof(TOI_MAGIC_STRING) - 1)
39
static int swap_set_info(blkid_probe pr, const char *version)
41
struct swap_header_v1_2 *hdr;
43
/* Swap header always located at offset of 1024 bytes */
44
hdr = (struct swap_header_v1_2 *) blkid_probe_get_buffer(pr, 1024,
45
sizeof(struct swap_header_v1_2));
49
/* SWAPSPACE2 - check for wrong version or zeroed pagecount */
50
if (strcmp(version, "2") == 0 &&
51
(hdr->version != 1 || hdr->lastpage == 0))
54
/* arbitrary sanity check.. is there any garbage down there? */
55
if (hdr->padding[32] == 0 && hdr->padding[33] == 0) {
56
if (hdr->volume[0] && blkid_probe_set_label(pr, hdr->volume,
57
sizeof(hdr->volume)) < 0)
59
if (hdr->uuid[0] && blkid_probe_set_uuid(pr, hdr->uuid) < 0)
63
blkid_probe_set_version(pr, version);
67
static int probe_swap(blkid_probe pr, const struct blkid_idmag *mag)
74
/* TuxOnIce keeps valid swap header at the end of the 1st page */
75
buf = blkid_probe_get_buffer(pr, 0, TOI_MAGIC_STRLEN);
79
if (memcmp(buf, TOI_MAGIC_STRING, TOI_MAGIC_STRLEN) == 0)
80
return 1; /* Ignore swap signature, it's TuxOnIce */
82
if (!memcmp(mag->magic, "SWAP-SPACE", mag->len)) {
83
/* swap v0 doesn't support LABEL or UUID */
84
blkid_probe_set_version(pr, "1");
87
} else if (!memcmp(mag->magic, "SWAPSPACE2", mag->len))
88
return swap_set_info(pr, "2");
93
static int probe_swsuspend(blkid_probe pr, const struct blkid_idmag *mag)
97
if (!memcmp(mag->magic, "S1SUSPEND", mag->len))
98
return swap_set_info(pr, "s1suspend");
99
if (!memcmp(mag->magic, "S2SUSPEND", mag->len))
100
return swap_set_info(pr, "s2suspend");
101
if (!memcmp(mag->magic, "ULSUSPEND", mag->len))
102
return swap_set_info(pr, "ulsuspend");
103
if (!memcmp(mag->magic, TOI_MAGIC_STRING, mag->len))
104
return swap_set_info(pr, "tuxonice");
105
if (!memcmp(mag->magic, "LINHIB0001", mag->len))
106
return swap_set_info(pr, "linhib0001");
108
return -1; /* no signature detected */
111
const struct blkid_idinfo swap_idinfo =
114
.usage = BLKID_USAGE_OTHER,
115
.probefunc = probe_swap,
116
.minsz = 10 * 4096, /* 10 pages */
119
{ "SWAP-SPACE", 10, 0, 0xff6 },
120
{ "SWAPSPACE2", 10, 0, 0xff6 },
121
{ "SWAP-SPACE", 10, 0, 0x1ff6 },
122
{ "SWAPSPACE2", 10, 0, 0x1ff6 },
123
{ "SWAP-SPACE", 10, 0, 0x3ff6 },
124
{ "SWAPSPACE2", 10, 0, 0x3ff6 },
125
{ "SWAP-SPACE", 10, 0, 0x7ff6 },
126
{ "SWAPSPACE2", 10, 0, 0x7ff6 },
127
{ "SWAP-SPACE", 10, 0, 0xfff6 },
128
{ "SWAPSPACE2", 10, 0, 0xfff6 },
134
const struct blkid_idinfo swsuspend_idinfo =
137
.usage = BLKID_USAGE_OTHER,
138
.probefunc = probe_swsuspend,
139
.minsz = 10 * 4096, /* 10 pages */
142
{ TOI_MAGIC_STRING, TOI_MAGIC_STRLEN, 0, 0 },
143
{ "S1SUSPEND", 9, 0, 0xff6 },
144
{ "S2SUSPEND", 9, 0, 0xff6 },
145
{ "ULSUSPEND", 9, 0, 0xff6 },
146
{ "LINHIB0001",10,0, 0xff6 },
148
{ "S1SUSPEND", 9, 0, 0x1ff6 },
149
{ "S2SUSPEND", 9, 0, 0x1ff6 },
150
{ "ULSUSPEND", 9, 0, 0x1ff6 },
151
{ "LINHIB0001",10,0, 0x1ff6 },
153
{ "S1SUSPEND", 9, 0, 0x3ff6 },
154
{ "S2SUSPEND", 9, 0, 0x3ff6 },
155
{ "ULSUSPEND", 9, 0, 0x3ff6 },
156
{ "LINHIB0001",10,0, 0x3ff6 },
158
{ "S1SUSPEND", 9, 0, 0x7ff6 },
159
{ "S2SUSPEND", 9, 0, 0x7ff6 },
160
{ "ULSUSPEND", 9, 0, 0x7ff6 },
161
{ "LINHIB0001",10,0, 0x7ff6 },
163
{ "S1SUSPEND", 9, 0, 0xfff6 },
164
{ "S2SUSPEND", 9, 0, 0xfff6 },
165
{ "ULSUSPEND", 9, 0, 0xfff6 },
166
{ "LINHIB0001",10,0, 0xfff6 },