From 2ac050e2567701fafd30038be47941fb898bde17 Mon Sep 17 00:00:00 2001 From: kzak Date: Fri, 2 Sep 2005 14:38:19 +0000 Subject: [PATCH] - fix swapon on swsuspend --- util-linux-2.13-swapon-suspend.patch | 161 +++++++++++++++++++++++++++ util-linux.spec | 8 +- 2 files changed, 167 insertions(+), 2 deletions(-) create mode 100644 util-linux-2.13-swapon-suspend.patch diff --git a/util-linux-2.13-swapon-suspend.patch b/util-linux-2.13-swapon-suspend.patch new file mode 100644 index 0000000..6c716d2 --- /dev/null +++ b/util-linux-2.13-swapon-suspend.patch @@ -0,0 +1,161 @@ +--- util-linux-2.13-pre2/mount/swapon.c.swsuspend 2005-09-02 14:32:53.000000000 +0200 ++++ util-linux-2.13-pre2/mount/swapon.c 2005-09-02 16:29:43.000000000 +0200 +@@ -11,6 +11,9 @@ + #include + #include + #include ++#include ++#include ++#include + #include "xmalloc.h" + #include "swap_constants.h" + #include "swapargs.h" +@@ -22,6 +25,7 @@ + + #define _PATH_FSTAB "/etc/fstab" + #define PROC_SWAPS "/proc/swaps" ++#define PATH_MKSWAP "/sbin/mkswap" + + #define SWAPON_NEEDS_TWO_ARGS + +@@ -173,6 +177,84 @@ + return 0 ; + } + ++/* ++ * It's better do swsuspend detection by follow routine than ++ * include huge mount_guess_fstype.o to swapon. We need only ++ * swsuspend and no the others filesystems. ++ */ ++#ifdef HAVE_LIBBLKID ++static int ++swap_is_swsuspend(const char *device) { ++ const char *type = blkid_get_tag_value(blkid, "TYPE", device); ++ ++ if (type && strcmp(type, "swsuspend")==0) ++ return 0; ++ return 1; ++} ++#else ++static int ++swap_is_swsuspend(const char *device) { ++ int fd, re = 1, n = getpagesize() - 10; ++ char buf[10]; ++ ++ fd = open(device, O_RDONLY); ++ if (fd < 0) ++ return -1; ++ ++ if (lseek(fd, n, SEEK_SET) >= 0 && ++ read(fd, buf, sizeof buf) == sizeof buf && ++ (memcmp("S1SUSPEND", buf, 9)==0 || ++ memcmp("S2SUSPEND", buf, 9)==0)) ++ re = 0; ++ ++ close(fd); ++ return re; ++} ++#endif ++ ++/* calls mkswap */ ++static int ++swap_reinitialize(const char *device) { ++ const char *label = mount_get_volume_label_by_spec(device); ++ pid_t pid; ++ ++ switch((pid=fork())) { ++ case -1: /* fork error */ ++ fprintf(stderr, _("%s: cannot fork: %s\n"), ++ progname, strerror(errno)); ++ return -1; ++ ++ case 0: /* child */ ++ if (label && *label) ++ execl(PATH_MKSWAP, PATH_MKSWAP, "-L", label, device, NULL); ++ else ++ execl(PATH_MKSWAP, PATH_MKSWAP, device, NULL); ++ exit(1); /* error */ ++ ++ default: /* parent */ ++ { ++ int status; ++ int ret; ++ ++ do { ++ if ((ret = waitpid(pid, &status, 0)) < 0 ++ && errno == EINTR) ++ continue; ++ else if (ret < 0) { ++ fprintf(stderr, _("%s: waitpid: %s\n"), ++ progname, strerror(errno)); ++ return -1; ++ } ++ } while (0); ++ ++ /* mkswap returns: 0=suss, 1=error */ ++ if (WIFEXITED(status) && WEXITSTATUS(status)==0) ++ return 0; /* ok */ ++ } ++ } ++ return -1; /* error */ ++} ++ + static int + do_swapon(const char *orig_special, int prio) { + int status; +@@ -196,6 +278,18 @@ + return -1; + } + ++ /* We have to reinitialize swap with old (=useless) software suspend ++ * data. The problem is that if we don't do it, then we get data ++ * corruption the next time with suspended on. ++ */ ++ if (swap_is_swsuspend(special)==0) { ++ fprintf(stdout, _("%s: %s: software suspend data detected. " ++ "Reinitializing the swap.\n"), ++ progname, special); ++ if (swap_reinitialize(special) < 0) ++ return -1; ++ } ++ + /* people generally dislike this warning - now it is printed + only when `verbose' is set */ + if (verbose) { +--- util-linux-2.13-pre2/mount/get_label_uuid.c.swsuspend 2005-09-02 14:32:53.000000000 +0200 ++++ util-linux-2.13-pre2/mount/get_label_uuid.c 2005-09-02 16:21:20.000000000 +0200 +@@ -129,7 +129,24 @@ + } + return 0; + } +- ++ ++static int ++is_swsuspend_partition(int fd, char **label, char *uuid) { ++ int n = getpagesize(); ++ char *buf = xmalloc(n); ++ struct swap_header_v1_2 *p = (struct swap_header_v1_2 *) buf; ++ ++ if (lseek(fd, 0, SEEK_SET) == 0 ++ && read(fd, buf, n) == n ++ && (strncmp(buf+n-10, "S1SUSPEND", 9)==0 || ++ strncmp(buf+n-10, "S2SUSPEND", 9)==0) ++ && p->version == 1) { ++ store_uuid(uuid, p->uuid); ++ store_label(label, p->volume_name, 16); ++ return 1; ++ } ++ return 0; ++} + + /* + * Get both label and uuid. +@@ -162,6 +179,8 @@ + + if (is_v1_swap_partition(fd, label, uuid)) + goto done; ++ if (is_swsuspend_partition(fd, label, uuid)) ++ goto done; + + if (lseek(fd, 1024, SEEK_SET) == 1024 + && read(fd, (char *) &e2sb, sizeof(e2sb)) == sizeof(e2sb) diff --git a/util-linux.spec b/util-linux.spec index 1784985..39bec0b 100644 --- a/util-linux.spec +++ b/util-linux.spec @@ -28,7 +28,7 @@ BuildRoot: %{_tmppath}/%{name}-root Summary: A collection of basic system utilities. Name: util-linux Version: 2.13 -Release: 0.2.pre2 +Release: 0.3.pre2 License: distributable Group: System Environment/Base @@ -157,6 +157,8 @@ Patch208: util-linux-2.13-usrsbin.patch #159410 - mkswap(8) claims max swap area size is 2 GB Patch209: util-linux-2.12p-mkswap-man.patch +#165863 - swsusp swaps should be reinitialized +Patch210: util-linux-2.13-swapon-suspend.patch # When adding patches, please make sure that it is easy to find out what bug # the # patch fixes. @@ -225,6 +227,7 @@ cp %{SOURCE8} %{SOURCE9} . %patch207 -p1 %patch208 -p1 %patch209 -p1 +%patch210 -p1 -b .swsuspend %build unset LINGUAS || : @@ -646,9 +649,10 @@ fi /sbin/losetup %changelog -* Tue Aug 30 2005 Karel Zak 2.13-0.3.pre2 +* Fri Sep 2 2005 Karel Zak 2.13-0.3.pre2 - fix #166923 - hwclock will not run on a non audit-enabled kernel - fix #159410 - mkswap(8) claims max swap area size is 2 GB +- fix #165863 - swsusp swaps should be reinitialized * Tue Aug 16 2005 Karel Zak 2.13-0.2.pre2 - /usr/share/misc/getopt/* -move-> /usr/share/doc/util-linux-2.13/getopt-*