Branch data Line data Source code
1 : : /*
2 : : * Copyright (C) 2009 Red Hat, Inc. All rights reserved.
3 : : *
4 : : * This file is part of LVM2.
5 : : *
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.
9 : : *
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
13 : : */
14 : :
15 : : #include "lib.h"
16 : : #include "metadata.h"
17 : : #include "xlate.h"
18 : : #include "filter.h"
19 : :
20 : : #ifdef linux
21 : :
22 : : #define MAX_PAGESIZE (64 * 1024)
23 : : #define SIGNATURE_SIZE 10
24 : :
25 : : static int
26 : 0 : _swap_detect_signature(const char *buf)
27 : : {
28 [ # # ][ # # ]: 0 : if (memcmp(buf, "SWAP-SPACE", 10) == 0 ||
29 : 0 : memcmp(buf, "SWAPSPACE2", 10) == 0)
30 : 0 : return 1;
31 : :
32 [ # # ][ # # ]: 0 : if (memcmp(buf, "S1SUSPEND", 9) == 0 ||
[ # # ][ # # ]
33 : 0 : memcmp(buf, "S2SUSPEND", 9) == 0 ||
34 : 0 : memcmp(buf, "ULSUSPEND", 9) == 0 ||
35 : 0 : memcmp(buf, "\xed\xc3\x02\xe9\x98\x56\xe5\x0c", 8) == 0)
36 : 0 : return 1;
37 : :
38 : 0 : return 0;
39 : : }
40 : :
41 : 0 : int dev_is_swap(struct device *dev, uint64_t *signature)
42 : : {
43 : : char buf[10];
44 : : uint64_t size;
45 : : int page;
46 : :
47 [ # # ]: 0 : if (!dev_get_size(dev, &size)) {
48 : 0 : stack;
49 : 0 : return -1;
50 : : }
51 : :
52 [ # # ]: 0 : if (!dev_open(dev)) {
53 : 0 : stack;
54 : 0 : return -1;
55 : : }
56 : :
57 : 0 : *signature = 0;
58 : :
59 [ # # ]: 0 : for (page = 0x1000; page <= MAX_PAGESIZE; page <<= 1) {
60 : : /*
61 : : * skip 32k pagesize since this does not seem to be supported
62 : : */
63 [ # # ]: 0 : if (page == 0x8000)
64 : 0 : continue;
65 [ # # ]: 0 : if (size < page)
66 : 0 : break;
67 [ # # ]: 0 : if (!dev_read(dev, page - SIGNATURE_SIZE,
68 : : SIGNATURE_SIZE, buf)) {
69 : 0 : stack;
70 : 0 : return -1;
71 : : }
72 [ # # ]: 0 : if (_swap_detect_signature(buf)) {
73 : 0 : *signature = page - SIGNATURE_SIZE;
74 : 0 : break;
75 : : }
76 : : }
77 : :
78 [ # # ]: 0 : if (!dev_close(dev))
79 : 0 : stack;
80 : :
81 [ # # ]: 0 : if (*signature)
82 : 0 : return 1;
83 : :
84 : 0 : return 0;
85 : : }
86 : :
87 : : #endif
|