All of lore.kernel.org
 help / color / mirror / Atom feed
From: Pavel Machek <pavel@suse.cz>
To: "Rafael J. Wysocki" <rjw@sisk.pl>
Cc: Nigel Cunningham <nigel@suspend2.net>,
	linux-pm@osdl.org, linux-pm@lists.osdl.org, "Victor Porton, , ,
	" <porton@ex-code.com>
Subject: Re: Re: standby to disk transition
Date: Tue, 14 Mar 2006 22:59:19 +0100	[thread overview]
Message-ID: <20060314215919.GP1782@elf.ucw.cz> (raw)
In-Reply-To: <200603142213.03000.rjw@sisk.pl>

[-- Attachment #1: Type: text/plain, Size: 4997 bytes --]

Hi!

Just a preview of what I'm working on: suspend-to-both
implementation. Be *very* careful with it.


===================================================================
RCS file: /cvsroot/suspend/suspend/Makefile,v
retrieving revision 1.21
diff -u -u -r1.21 Makefile
--- Makefile	12 Mar 2006 16:17:19 -0000	1.21
+++ Makefile	14 Mar 2006 21:55:40 -0000
@@ -1,5 +1,5 @@
 #CONFIG_COMPRESS=yes
-#CONFIG_ENCRYPT=yes
+CONFIG_ENCRYPT=yes
 
 CC_FLAGS=-I/usr/local/include
 LD_FLAGS=-L/usr/local/lib
@@ -69,8 +69,8 @@
 vt.o:	vt.c vt.h
 	gcc -Wall -c vt.c
 
-suspend:	md5.o encrypt.o config.o suspend.c swsusp.h config.h encrypt.h md5.h
-	gcc -Wall $(CC_FLAGS) md5.o encrypt.o config.o suspend.c -o suspend $(LD_FLAGS)
+suspend:	md5.o encrypt.o config.o suspend.c swsusp.h config.h encrypt.h md5.h s2ram.c dmidecode.c whitelist.c radeontool.c $(S2RAMOBJ)
+	gcc -g -O2 -DCONFIG_BOTH -Wall $(CC_FLAGS) md5.o encrypt.o config.o suspend.c s2ram.c -o suspend $(S2RAMOBJ) $(LD_FLAGS) -lpci 
 
 resume:	md5.o encrypt.o config.o resume.c swsusp.h config.h encrypt.h md5.h
 	gcc -Wall $(CC_FLAGS) md5.o encrypt.o config.o resume.c -static -o resume $(LD_FLAGS)
Index: s2ram.c
===================================================================
RCS file: /cvsroot/suspend/suspend/s2ram.c,v
retrieving revision 1.29
diff -u -u -r1.29 s2ram.c
--- s2ram.c	7 Mar 2006 23:54:21 -0000	1.29
+++ s2ram.c	14 Mar 2006 21:55:44 -0000
@@ -162,9 +162,11 @@
 		vbe_buffer = __save_state(&size);
 	}
 	if (flags & RADEON_OFF) {
+#if 0
 		map_radeon_cntl_mem();
 		printf("Calling radeon_cmd_light");
 		radeon_cmd_light("off");
+#endif
 	}
 }
 
@@ -237,6 +239,7 @@
 	exit(1);
 }
 
+#ifndef CONFIG_BOTH
 int main(int argc, char *argv[])
 {
 	int i;
@@ -299,3 +302,4 @@
 	s2ram_resume();
 	return i;
 }
+#endif
Index: suspend.c
===================================================================
RCS file: /cvsroot/suspend/suspend/suspend.c,v
retrieving revision 1.22
diff -u -u -r1.22 suspend.c
--- suspend.c	12 Mar 2006 16:17:19 -0000	1.22
+++ suspend.c	14 Mar 2006 21:55:58 -0000
@@ -53,6 +53,7 @@
 #define encrypt 0
 #define key_name NULL
 #endif
+static int s2ram = 1;
 
 static struct config_par parameters[PARAM_NO] = {
 	{
@@ -518,6 +519,50 @@
 						ioctl(fd, VT_WAITACTIVE, vt); \
 						ioctl(fd, KDSKBMODE, ioc2);
 
+
+static int reset_signature(int fd)
+{
+	static struct swap_map_handle handle;
+	int ret, error = 0;
+	struct swsusp_info *header;
+	char c;
+
+	ret = lseek(fd, 0, SEEK_SET);
+	if (!ret)
+		return -errno;
+	memset(&swsusp_header, 0, sizeof(swsusp_header));
+	ret = read(fd, &swsusp_header, PAGE_SIZE);
+	if (ret == PAGE_SIZE) {
+		if (memcmp(SWSUSP_SIG, swsusp_header.sig, 10))
+			/* Impossible? We wrote signature and it is not there?! */
+			return -EINVAL;
+	} else {
+		error = ret < 0 ? ret : -EIO;
+	}
+
+	if (!error || !ret) {
+		/* Reset swap signature now */
+		memcpy(swsusp_header.sig, swsusp_header.orig_sig, 10);
+		ret = lseek(fd, 0, SEEK_SET);
+		if (!ret)
+			ret = write(fd, &swsusp_header, PAGE_SIZE);
+		if (ret < (int)PAGE_SIZE) {
+			fprintf(stderr, "resume: Could not restore the partition header\n");
+			error = ret < 0 ? -errno : -EIO;
+		}
+	}
+	fsync(fd);
+	close(fd);
+	if (!error) {
+		printf("reset_signature: Signature reset ok\n");
+	} else {
+		printf("reset_signature: Error %d resetting the image. Something went very wrong please reboot machine manually, destroy saved image, and force fsck.\n"
+			"\n", error);
+		while(1);
+	}
+	return error;
+}
+
 int suspend_system(int snapshot_fd, int resume_fd, int vt_fd, int vt_no)
 {
 	loff_t avail_swap;
@@ -552,7 +597,15 @@
 				break;
 			error = write_image(snapshot_fd, resume_fd);
 			if (!error) {
-				power_off();
+				if (!s2ram)
+					power_off();
+				else {
+					s2ram_do();
+					s2ram_resume();
+					error = EDOM;
+					reset_signature(snapshot_fd);
+					break;
+				}
 			} else {
 				free_swap_pages(snapshot_fd);
 				free_snapshot(snapshot_fd);
@@ -569,6 +622,7 @@
 
 Unfreeze:
 	unfreeze(snapshot_fd);
+	/* FIXME: We have to kill the signature here */
 
 	return error;
 }
@@ -779,7 +833,6 @@
 	if (stat(resume_dev_name, &stat_buf)) {
 		fprintf(stderr, "suspend: Could not stat the resume device file\n");
 		return ENODEV;
-	} else {
 	}
 	if (!S_ISBLK(stat_buf.st_mode)) {
 		fprintf(stderr, "suspend: Invalid resume device\n");
@@ -797,6 +850,10 @@
 		ret = ENODEV;
 		goto Close_resume_fd;
 	}
+
+	if (s2ram)
+		s2ram_prepare();
+
 	if (!S_ISCHR(stat_buf.st_mode)) {
 		fprintf(stderr, "suspend: Invalid snapshot device\n");
 		ret = EINVAL;
@@ -823,6 +880,7 @@
 		goto Close_snapshot_fd;
 	}
 
+#if 0
 	sprintf(chroot_path, "/proc/%d", getpid());
 	if (chroot(chroot_path)) {
 		fprintf(stderr, "suspend: Could not chroot to %s\n", chroot_path);
@@ -830,6 +888,7 @@
 		goto Restore_console;
 	}
 	chdir("/");
+#endif
 
 	orig_loglevel = get_kernel_console_loglevel();
 	set_kernel_console_loglevel(suspend_loglevel);

-- 
53:        Decrypt( adPRIV, 0, adPRIV.Length, UserKey, MD5.Hash );

[-- Attachment #2: Type: text/plain, Size: 0 bytes --]



  parent reply	other threads:[~2006-03-14 21:59 UTC|newest]

Thread overview: 31+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2006-03-13  2:34 standby to disk transition Victor Porton,,,
2006-03-13  8:30 ` Pavel Machek
2006-03-13  8:48   ` Adam Belay
2006-03-13  8:50     ` Pavel Machek
2006-03-13  9:07       ` Adam Belay
2006-03-13  9:13         ` Pavel Machek
2006-03-13 18:33           ` Dave Jones
2006-03-13 21:24             ` Pavel Machek
2006-03-13 21:28               ` Dave Jones
2006-03-13 21:46                 ` Pavel Machek
2006-03-13 22:06                   ` Rafael J. Wysocki
2006-03-13 21:59                 ` Nigel Cunningham
2006-03-13 22:08                   ` Pavel Machek
2006-03-13 22:42                     ` Rafael J. Wysocki
2006-03-13 23:11                       ` Nigel Cunningham
2006-03-13 23:36                         ` Rafael J. Wysocki
2006-03-14  0:18                           ` Nigel Cunningham
2006-03-14 18:12                             ` Rafael J. Wysocki
2006-03-14 20:33                           ` Pavel Machek
2006-03-14 21:13                             ` Rafael J. Wysocki
2006-03-14 21:22                               ` Pavel Machek
2006-03-14 21:42                                 ` Alan Stern
2006-03-14 22:07                                   ` Rafael J. Wysocki
2006-03-15 15:14                                     ` Alan Stern
2006-03-14 21:57                                 ` Rafael J. Wysocki
2006-03-14 21:59                               ` Pavel Machek [this message]
2006-03-15  0:22                                 ` suspend-to-both [was Re: Re: standby to disk transition] Pavel Machek
2006-03-14 20:29                         ` Re: standby to disk transition Pavel Machek
2006-03-14  0:21               ` Nigel Cunningham
2006-03-14  9:50                 ` Pavel Machek
2006-03-13 13:55     ` Nigel Cunningham

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20060314215919.GP1782@elf.ucw.cz \
    --to=pavel@suse.cz \
    --cc=linux-pm@lists.osdl.org \
    --cc=linux-pm@osdl.org \
    --cc=nigel@suspend2.net \
    --cc=porton@ex-code.com \
    --cc=rjw@sisk.pl \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.