[Suspend2][ 10/16] [Suspend2] Image exists proc entry.

From: Nigel Cunningham
Date: Mon Jun 26 2006 - 18:33:39 EST


Routines for the image_exists proc entry. Read to determine whether an
image exists at the place resume2= points to (-1 equals can't determine, 0
for no image, 1 for there is).

If an image exists, we also print the kernel version and suspend version
used to create the image on additional lines.

Echoing to the file invalidates any image that exists.

Signed-off-by: Nigel Cunningham <nigel@xxxxxxxxxxxx>

kernel/power/suspend.c | 51 ++++++++++++++++++++++++++++++++++++++++++++++++
1 files changed, 51 insertions(+), 0 deletions(-)

diff --git a/kernel/power/suspend.c b/kernel/power/suspend.c
index 40f54f7..4eabb21 100644
--- a/kernel/power/suspend.c
+++ b/kernel/power/suspend.c
@@ -640,3 +640,54 @@ cleanup:
suspend_deactivate_storage(0);
}

+/* image_exists_read
+ *
+ * Return 0 or 1, depending on whether an image is found.
+ */
+static int image_exists_read(char *page, char **start, off_t off, int count,
+ int *eof, void *data)
+{
+ int len = 0;
+ char *result;
+
+ if (suspend_activate_storage(0))
+ return count;
+
+ if (!test_suspend_state(SUSPEND_RESUME_DEVICE_OK))
+ suspend_attempt_to_parse_resume_device();
+
+ if (!suspend_active_writer) {
+ len = sprintf(page, "-1\n");
+ } else {
+ result = get_have_image_data();
+ if (result) {
+ len = sprintf(page, "%s", result);
+ free_page((unsigned long) result);
+ }
+ }
+
+ *eof = 1;
+
+ suspend_deactivate_storage(0);
+
+ return len;
+}
+
+/* image_exists_write
+ *
+ * Invalidate an image if one exists.
+ */
+static int image_exists_write(struct file *file, const char *buffer,
+ unsigned long count, void *data)
+{
+ if (suspend_activate_storage(0))
+ return count;
+
+ if (suspend_active_writer && suspend_active_writer->image_exists())
+ suspend_active_writer->invalidate_image();
+
+ suspend_deactivate_storage(0);
+
+ return count;
+}
+

--
Nigel Cunningham nigel at suspend2 dot net
-
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/