1 /* $NetBSD: dev-swap.c,v 1.1.1.1 2009/12/02 00:26:34 haad Exp $ */
4 * Copyright (C) 2009 Red Hat, Inc. All rights reserved.
6 * This file is part of LVM2.
8 * This copyrighted material is made available to anyone wishing to use,
9 * modify, copy, or redistribute it subject to the terms and conditions
10 * of the GNU Lesser General Public License v.2.1.
12 * You should have received a copy of the GNU Lesser General Public License
13 * along with this program; if not, write to the Free Software Foundation,
14 * Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
24 #define MAX_PAGESIZE (64 * 1024)
25 #define SIGNATURE_SIZE 10
28 _swap_detect_signature(const char *buf
)
30 if (memcmp(buf
, "SWAP-SPACE", 10) == 0 ||
31 memcmp(buf
, "SWAPSPACE2", 10) == 0)
34 if (memcmp(buf
, "S1SUSPEND", 9) == 0 ||
35 memcmp(buf
, "S2SUSPEND", 9) == 0 ||
36 memcmp(buf
, "ULSUSPEND", 9) == 0 ||
37 memcmp(buf
, "\xed\xc3\x02\xe9\x98\x56\xe5\x0c", 8) == 0)
43 int dev_is_swap(struct device
*dev
, uint64_t *signature
)
49 if (!dev_get_size(dev
, &size
)) {
61 for (page
= 0x1000; page
<= MAX_PAGESIZE
; page
<<= 1) {
63 * skip 32k pagesize since this does not seem to be supported
69 if (!dev_read(dev
, page
- SIGNATURE_SIZE
,
70 SIGNATURE_SIZE
, buf
)) {
74 if (_swap_detect_signature(buf
)) {
75 *signature
= page
- SIGNATURE_SIZE
;
92 int dev_is_swap(struct device
*dev
, uint64_t *signature
)