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.
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) */
37 static int swap_set_info(blkid_probe pr, const char *version)
39 struct swap_header_v1_2 *hdr;
41 /* Swap header always located at offset of 1024 bytes */
42 hdr = (struct swap_header_v1_2 *) blkid_probe_get_buffer(pr, 1024,
43 sizeof(struct swap_header_v1_2));
47 /* SWAPSPACE2 - check for wrong version or zeroed pagecount */
48 if (strcmp(version, "2") == 0 &&
49 (hdr->version != 1 || hdr->lastpage == 0))
52 /* arbitrary sanity check.. is there any garbage down there? */
53 if (hdr->padding[32] == 0 && hdr->padding[33] == 0) {
54 if (hdr->volume[0] && blkid_probe_set_label(pr, hdr->volume,
55 sizeof(hdr->volume)) < 0)
57 if (hdr->uuid[0] && blkid_probe_set_uuid(pr, hdr->uuid) < 0)
61 blkid_probe_set_version(pr, version);
65 static int probe_swap(blkid_probe pr, const struct blkid_idmag *mag)
70 if (!memcmp(mag->magic, "SWAP-SPACE", mag->len)) {
71 /* swap v0 doesn't support LABEL or UUID */
72 blkid_probe_set_version(pr, "1");
75 } else if (!memcmp(mag->magic, "SWAPSPACE2", mag->len))
76 return swap_set_info(pr, "2");
81 static int probe_swsuspend(blkid_probe pr, const struct blkid_idmag *mag)
85 if (!memcmp(mag->magic, "S1SUSPEND", mag->len))
86 return swap_set_info(pr, "s1suspend");
87 if (!memcmp(mag->magic, "S2SUSPEND", mag->len))
88 return swap_set_info(pr, "s2suspend");
89 if (!memcmp(mag->magic, "ULSUSPEND", mag->len))
90 return swap_set_info(pr, "ulsuspend");
91 if (!memcmp(mag->magic, "\xed\xc3\x02\xe9\x98\x56\xe5\x0c", mag->len))
92 return swap_set_info(pr, "tuxonice");
94 return -1; /* no signature detected */
97 const struct blkid_idinfo swap_idinfo =
100 .usage = BLKID_USAGE_OTHER,
101 .probefunc = probe_swap,
104 { "SWAP-SPACE", 10, 0, 0xff6 },
105 { "SWAPSPACE2", 10, 0, 0xff6 },
106 { "SWAP-SPACE", 10, 0, 0x1ff6 },
107 { "SWAPSPACE2", 10, 0, 0x1ff6 },
108 { "SWAP-SPACE", 10, 0, 0x3ff6 },
109 { "SWAPSPACE2", 10, 0, 0x3ff6 },
110 { "SWAP-SPACE", 10, 0, 0x7ff6 },
111 { "SWAPSPACE2", 10, 0, 0x7ff6 },
112 { "SWAP-SPACE", 10, 0, 0xfff6 },
113 { "SWAPSPACE2", 10, 0, 0xfff6 },
119 const struct blkid_idinfo swsuspend_idinfo =
122 .usage = BLKID_USAGE_OTHER,
123 .probefunc = probe_swsuspend,
126 { "S1SUSPEND", 9, 0, 0xff6 },
127 { "S2SUSPEND", 9, 0, 0xff6 },
128 { "ULSUSPEND", 9, 0, 0xff6 },
129 { "\xed\xc3\x02\xe9\x98\x56\xe5\x0c", 8, 0, 0xff6 },
130 { "S1SUSPEND", 9, 0, 0x1ff6 },
131 { "S2SUSPEND", 9, 0, 0x1ff6 },
132 { "ULSUSPEND", 9, 0, 0x1ff6 },
133 { "\xed\xc3\x02\xe9\x98\x56\xe5\x0c", 8, 0, 0x1ff6 },
134 { "S1SUSPEND", 9, 0, 0x3ff6 },
135 { "S2SUSPEND", 9, 0, 0x3ff6 },
136 { "ULSUSPEND", 9, 0, 0x3ff6 },
137 { "\xed\xc3\x02\xe9\x98\x56\xe5\x0c", 8, 0, 0x3ff6 },
138 { "S1SUSPEND", 9, 0, 0x7ff6 },
139 { "S2SUSPEND", 9, 0, 0x7ff6 },
140 { "ULSUSPEND", 9, 0, 0x7ff6 },
141 { "\xed\xc3\x02\xe9\x98\x56\xe5\x0c", 8, 0, 0x7ff6 },
142 { "S1SUSPEND", 9, 0, 0xfff6 },
143 { "S2SUSPEND", 9, 0, 0xfff6 },
144 { "ULSUSPEND", 9, 0, 0xfff6 },
145 { "\xed\xc3\x02\xe9\x98\x56\xe5\x0c", 8, 0, 0xfff6 },