2 * Copyright (C) 2009 Red Hat, Inc. All rights reserved.
4 * This file is part of LVM2.
6 * This copyrighted material is made available to anyone wishing to use,
7 * modify, copy, or redistribute it subject to the terms and conditions
8 * of the GNU Lesser General Public License v.2.1.
10 * You should have received a copy of the GNU Lesser General Public License
11 * along with this program; if not, write to the Free Software Foundation,
12 * Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
22 #define MAX_PAGESIZE (64 * 1024)
23 #define SIGNATURE_SIZE 10
26 _swap_detect_signature(const char *buf)
28 if (memcmp(buf, "SWAP-SPACE", 10) == 0 ||
29 memcmp(buf, "SWAPSPACE2", 10) == 0)
32 if (memcmp(buf, "S1SUSPEND", 9) == 0 ||
33 memcmp(buf, "S2SUSPEND", 9) == 0 ||
34 memcmp(buf, "ULSUSPEND", 9) == 0 ||
35 memcmp(buf, "\xed\xc3\x02\xe9\x98\x56\xe5\x0c", 8) == 0)
41 int dev_is_swap(struct device *dev, uint64_t *signature)
47 if (!dev_get_size(dev, &size)) {
59 for (page = 0x1000; page <= MAX_PAGESIZE; page <<= 1) {
61 * skip 32k pagesize since this does not seem to be supported
67 if (!dev_read(dev, page - SIGNATURE_SIZE,
68 SIGNATURE_SIZE, buf)) {
72 if (_swap_detect_signature(buf)) {
73 *signature = page - SIGNATURE_SIZE;