]> err.no Git - util-linux/commitdiff
libblkid: set correct offsets for TuxOnIce signature
authorChow Loong Jin <hyperair@ubuntu.com>
Fri, 30 Apr 2010 23:55:41 +0000 (07:55 +0800)
committerKarel Zak <kzak@redhat.com>
Thu, 6 May 2010 09:50:30 +0000 (11:50 +0200)
TuxOnIce stores its signature at the beginning of the swap, rather than
at the end of the first page like swsusp does.

[kzak@redhat.com: - use macro for TOI magic string,
                  - check for TOI in swap probing function to avoid
                    collision between swap and TOI]

Signed-off-by: Chow Loong Jin <hyperair@ubuntu.com>
Signed-off-by: Karel Zak <kzak@redhat.com>
shlibs/blkid/src/superblocks/swap.c

index 8aaa6f31428a10d5034cc0c69bab14990505d994..e2b0db9f1fe653035013ff360bc00d05f8d5ff7a 100644 (file)
@@ -33,6 +33,8 @@ struct swap_header_v1_2 {
 #define PAGESIZE_MIN   0xff6   /* 4086 (arm, i386, ...) */
 #define PAGESIZE_MAX   0xfff6  /* 65526 (ia64) */
 
+#define TOI_MAGIC_STRING       "\xed\xc3\x02\xe9\x98\x56\xe5\x0c"
+#define TOI_MAGIC_STRLEN       (sizeof(TOI_MAGIC_STRING) - 1)
 
 static int swap_set_info(blkid_probe pr, const char *version)
 {
@@ -64,9 +66,19 @@ static int swap_set_info(blkid_probe pr, const char *version)
 
 static int probe_swap(blkid_probe pr, const struct blkid_idmag *mag)
 {
+       unsigned char *buf;
+
        if (!mag)
                return -1;
 
+       /* TuxOnIce keeps valid swap header at the end of the 1st page */
+       buf = blkid_probe_get_buffer(pr, 0, TOI_MAGIC_STRLEN);
+       if (!buf)
+               return -1;
+
+       if (memcmp(buf, TOI_MAGIC_STRING, TOI_MAGIC_STRLEN) == 0)
+               return 1;       /* Ignore swap signature, it's TuxOnIce */
+
        if (!memcmp(mag->magic, "SWAP-SPACE", mag->len)) {
                /* swap v0 doesn't support LABEL or UUID */
                blkid_probe_set_version(pr, "1");
@@ -88,7 +100,7 @@ static int probe_swsuspend(blkid_probe pr, const struct blkid_idmag *mag)
                return swap_set_info(pr, "s2suspend");
        if (!memcmp(mag->magic, "ULSUSPEND", mag->len))
                return swap_set_info(pr, "ulsuspend");
-       if (!memcmp(mag->magic, "\xed\xc3\x02\xe9\x98\x56\xe5\x0c", mag->len))
+       if (!memcmp(mag->magic, TOI_MAGIC_STRING, mag->len))
                return swap_set_info(pr, "tuxonice");
 
        return -1;      /* no signature detected */
@@ -125,26 +137,22 @@ const struct blkid_idinfo swsuspend_idinfo =
        .minsz          = 10 * 4096,    /* 10 pages */
        .magics         =
        {
+               { TOI_MAGIC_STRING, TOI_MAGIC_STRLEN, 0, 0 },
                { "S1SUSPEND", 9, 0, 0xff6 },
                { "S2SUSPEND", 9, 0, 0xff6 },
                { "ULSUSPEND", 9, 0, 0xff6 },
-               { "\xed\xc3\x02\xe9\x98\x56\xe5\x0c", 8, 0, 0xff6 },
                { "S1SUSPEND", 9, 0, 0x1ff6 },
                { "S2SUSPEND", 9, 0, 0x1ff6 },
                { "ULSUSPEND", 9, 0, 0x1ff6 },
-               { "\xed\xc3\x02\xe9\x98\x56\xe5\x0c", 8, 0, 0x1ff6 },
                { "S1SUSPEND", 9, 0, 0x3ff6 },
                { "S2SUSPEND", 9, 0, 0x3ff6 },
                { "ULSUSPEND", 9, 0, 0x3ff6 },
-               { "\xed\xc3\x02\xe9\x98\x56\xe5\x0c", 8, 0, 0x3ff6 },
                { "S1SUSPEND", 9, 0, 0x7ff6 },
                { "S2SUSPEND", 9, 0, 0x7ff6 },
                { "ULSUSPEND", 9, 0, 0x7ff6 },
-               { "\xed\xc3\x02\xe9\x98\x56\xe5\x0c", 8, 0, 0x7ff6 },
                { "S1SUSPEND", 9, 0, 0xfff6 },
                { "S2SUSPEND", 9, 0, 0xfff6 },
                { "ULSUSPEND", 9, 0, 0xfff6 },
-               { "\xed\xc3\x02\xe9\x98\x56\xe5\x0c", 8, 0, 0xfff6 },
                { NULL }
        }
 };