]> git.ipfire.org Git - thirdparty/util-linux.git/blame - lib/swapprober.c
script: document SIGUSR1
[thirdparty/util-linux.git] / lib / swapprober.c
CommitLineData
18b3e549
KZ
1
2#include "c.h"
3#include "nls.h"
4
05dd1d1d 5#include "swapheader.h"
18b3e549
KZ
6#include "swapprober.h"
7
8blkid_probe get_swap_prober(const char *devname)
9{
10 blkid_probe pr;
11 int rc;
12 const char *version = NULL;
13 char *swap_filter[] = { "swap", NULL };
14
15 pr = blkid_new_probe_from_filename(devname);
16 if (!pr) {
17 warn(_("%s: unable to probe device"), devname);
18 return NULL;
19 }
20
21 blkid_probe_enable_superblocks(pr, TRUE);
22 blkid_probe_set_superblocks_flags(pr,
23 BLKID_SUBLKS_LABEL | BLKID_SUBLKS_UUID |
24 BLKID_SUBLKS_VERSION);
25
26 blkid_probe_filter_superblocks_type(pr, BLKID_FLTR_ONLYIN, swap_filter);
27
28 rc = blkid_do_safeprobe(pr);
29 if (rc == -1)
30 warn(_("%s: unable to probe device"), devname);
31 else if (rc == -2)
1c75610f 32 warnx(_("%s: ambiguous probing result; use wipefs(8)"), devname);
18b3e549
KZ
33 else if (rc == 1)
34 warnx(_("%s: not a valid swap partition"), devname);
35
36 if (rc == 0) {
37 /* Only the SWAPSPACE2 is supported. */
38 if (blkid_probe_lookup_value(pr, "VERSION", &version, NULL) == 0
39 && version
40 && strcmp(version, stringify_value(SWAP_VERSION)))
41 warnx(_("%s: unsupported swap version '%s'"),
42 devname, version);
43 else
44 return pr;
45 }
46
47 blkid_free_probe(pr);
48 return NULL;
49}