1 - swsusp swaps should be reinitialized
3 --- util-linux-2.13-pre2/mount/swapon.c.swsuspend 2005-09-02 14:32:53.000000000 +0200
4 +++ util-linux-2.13-pre2/mount/swapon.c 2005-09-02 16:29:43.000000000 +0200
9 +#include <sys/types.h>
10 +#include <sys/wait.h>
13 #include "swap_constants.h"
17 #define _PATH_FSTAB "/etc/fstab"
18 #define PROC_SWAPS "/proc/swaps"
19 +#define PATH_MKSWAP "/sbin/mkswap"
21 #define SWAPON_NEEDS_TWO_ARGS
28 + * It's better do swsuspend detection by follow routine than
29 + * include huge mount_guess_fstype.o to swapon. We need only
30 + * swsuspend and no the others filesystems.
34 +swap_is_swsuspend(const char *device) {
35 + const char *type = blkid_get_tag_value(blkid, "TYPE", device);
37 + if (type && strcmp(type, "swsuspend")==0)
43 +swap_is_swsuspend(const char *device) {
44 + int fd, re = 1, n = getpagesize() - 10;
47 + fd = open(device, O_RDONLY);
51 + if (lseek(fd, n, SEEK_SET) >= 0 &&
52 + read(fd, buf, sizeof buf) == sizeof buf &&
53 + (memcmp("S1SUSPEND", buf, 9)==0 ||
54 + memcmp("S2SUSPEND", buf, 9)==0))
64 +swap_reinitialize(const char *device) {
65 + const char *label = mount_get_volume_label_by_spec(device);
68 + switch((pid=fork())) {
69 + case -1: /* fork error */
70 + fprintf(stderr, _("%s: cannot fork: %s\n"),
71 + progname, strerror(errno));
75 + if (label && *label)
76 + execl(PATH_MKSWAP, PATH_MKSWAP, "-L", label, device, NULL);
78 + execl(PATH_MKSWAP, PATH_MKSWAP, device, NULL);
79 + exit(1); /* error */
81 + default: /* parent */
87 + if ((ret = waitpid(pid, &status, 0)) < 0
91 + fprintf(stderr, _("%s: waitpid: %s\n"),
92 + progname, strerror(errno));
97 + /* mkswap returns: 0=suss, 1=error */
98 + if (WIFEXITED(status) && WEXITSTATUS(status)==0)
102 + return -1; /* error */
106 do_swapon(const char *orig_special, int prio) {
112 + /* We have to reinitialize swap with old (=useless) software suspend
113 + * data. The problem is that if we don't do it, then we get data
114 + * corruption the next time with suspended on.
116 + if (swap_is_swsuspend(special)==0) {
117 + fprintf(stdout, _("%s: %s: software suspend data detected. "
118 + "Reinitializing the swap.\n"),
119 + progname, special);
120 + if (swap_reinitialize(special) < 0)
124 /* people generally dislike this warning - now it is printed
125 only when `verbose' is set */
127 --- util-linux-2.13-pre2/mount/get_label_uuid.c.swsuspend 2005-09-02 14:32:53.000000000 +0200
128 +++ util-linux-2.13-pre2/mount/get_label_uuid.c 2005-09-02 16:21:20.000000000 +0200
136 +is_swsuspend_partition(int fd, char **label, char *uuid) {
137 + int n = getpagesize();
138 + char *buf = xmalloc(n);
139 + struct swap_header_v1_2 *p = (struct swap_header_v1_2 *) buf;
141 + if (lseek(fd, 0, SEEK_SET) == 0
142 + && read(fd, buf, n) == n
143 + && (strncmp(buf+n-10, "S1SUSPEND", 9)==0 ||
144 + strncmp(buf+n-10, "S2SUSPEND", 9)==0)
145 + && p->version == 1) {
146 + store_uuid(uuid, p->uuid);
147 + store_label(label, p->volume_name, 16);
154 * Get both label and uuid.
157 if (is_v1_swap_partition(fd, label, uuid))
159 + if (is_swsuspend_partition(fd, label, uuid))
162 if (lseek(fd, 1024, SEEK_SET) == 1024
163 && read(fd, (char *) &e2sb, sizeof(e2sb)) == sizeof(e2sb)