bigbiff | 7b4c7a6 | 2015-01-01 19:44:14 -0500 | [diff] [blame] | 1 | |
| 2 | #include "c.h" |
| 3 | #include "nls.h" |
| 4 | |
| 5 | #include "swapheader.h" |
| 6 | #include "swapprober.h" |
| 7 | |
| 8 | blkid_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) |
| 32 | warnx(_("%s: ambiguous probing result; use wipefs(8)"), devname); |
| 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 | } |