aboutsummaryrefslogtreecommitdiffstats
path: root/kernel/power/swap.c
diff options
context:
space:
mode:
Diffstat (limited to 'kernel/power/swap.c')
-rw-r--r--kernel/power/swap.c42
1 files changed, 27 insertions, 15 deletions
diff --git a/kernel/power/swap.c b/kernel/power/swap.c
index 3581f8f86acd..b18c155cbb60 100644
--- a/kernel/power/swap.c
+++ b/kernel/power/swap.c
@@ -33,12 +33,14 @@ extern char resume_file[];
33 33
34#define SWSUSP_SIG "S1SUSPEND" 34#define SWSUSP_SIG "S1SUSPEND"
35 35
36static struct swsusp_header { 36struct swsusp_header {
37 char reserved[PAGE_SIZE - 20 - sizeof(sector_t)]; 37 char reserved[PAGE_SIZE - 20 - sizeof(sector_t)];
38 sector_t image; 38 sector_t image;
39 char orig_sig[10]; 39 char orig_sig[10];
40 char sig[10]; 40 char sig[10];
41} __attribute__((packed, aligned(PAGE_SIZE))) swsusp_header; 41} __attribute__((packed));
42
43static struct swsusp_header *swsusp_header;
42 44
43/* 45/*
44 * General things 46 * General things
@@ -141,14 +143,14 @@ static int mark_swapfiles(sector_t start)
141{ 143{
142 int error; 144 int error;
143 145
144 bio_read_page(swsusp_resume_block, &swsusp_header, NULL); 146 bio_read_page(swsusp_resume_block, swsusp_header, NULL);
145 if (!memcmp("SWAP-SPACE",swsusp_header.sig, 10) || 147 if (!memcmp("SWAP-SPACE",swsusp_header->sig, 10) ||
146 !memcmp("SWAPSPACE2",swsusp_header.sig, 10)) { 148 !memcmp("SWAPSPACE2",swsusp_header->sig, 10)) {
147 memcpy(swsusp_header.orig_sig,swsusp_header.sig, 10); 149 memcpy(swsusp_header->orig_sig,swsusp_header->sig, 10);
148 memcpy(swsusp_header.sig,SWSUSP_SIG, 10); 150 memcpy(swsusp_header->sig,SWSUSP_SIG, 10);
149 swsusp_header.image = start; 151 swsusp_header->image = start;
150 error = bio_write_page(swsusp_resume_block, 152 error = bio_write_page(swsusp_resume_block,
151 &swsusp_header, NULL); 153 swsusp_header, NULL);
152 } else { 154 } else {
153 printk(KERN_ERR "swsusp: Swap header not found!\n"); 155 printk(KERN_ERR "swsusp: Swap header not found!\n");
154 error = -ENODEV; 156 error = -ENODEV;
@@ -564,7 +566,7 @@ int swsusp_read(void)
564 if (error < PAGE_SIZE) 566 if (error < PAGE_SIZE)
565 return error < 0 ? error : -EFAULT; 567 return error < 0 ? error : -EFAULT;
566 header = (struct swsusp_info *)data_of(snapshot); 568 header = (struct swsusp_info *)data_of(snapshot);
567 error = get_swap_reader(&handle, swsusp_header.image); 569 error = get_swap_reader(&handle, swsusp_header->image);
568 if (!error) 570 if (!error)
569 error = swap_read_page(&handle, header, NULL); 571 error = swap_read_page(&handle, header, NULL);
570 if (!error) 572 if (!error)
@@ -591,17 +593,17 @@ int swsusp_check(void)
591 resume_bdev = open_by_devnum(swsusp_resume_device, FMODE_READ); 593 resume_bdev = open_by_devnum(swsusp_resume_device, FMODE_READ);
592 if (!IS_ERR(resume_bdev)) { 594 if (!IS_ERR(resume_bdev)) {
593 set_blocksize(resume_bdev, PAGE_SIZE); 595 set_blocksize(resume_bdev, PAGE_SIZE);
594 memset(&swsusp_header, 0, sizeof(swsusp_header)); 596 memset(swsusp_header, 0, sizeof(PAGE_SIZE));
595 error = bio_read_page(swsusp_resume_block, 597 error = bio_read_page(swsusp_resume_block,
596 &swsusp_header, NULL); 598 swsusp_header, NULL);
597 if (error) 599 if (error)
598 return error; 600 return error;
599 601
600 if (!memcmp(SWSUSP_SIG, swsusp_header.sig, 10)) { 602 if (!memcmp(SWSUSP_SIG, swsusp_header->sig, 10)) {
601 memcpy(swsusp_header.sig, swsusp_header.orig_sig, 10); 603 memcpy(swsusp_header->sig, swsusp_header->orig_sig, 10);
602 /* Reset swap signature now */ 604 /* Reset swap signature now */
603 error = bio_write_page(swsusp_resume_block, 605 error = bio_write_page(swsusp_resume_block,
604 &swsusp_header, NULL); 606 swsusp_header, NULL);
605 } else { 607 } else {
606 return -EINVAL; 608 return -EINVAL;
607 } 609 }
@@ -632,3 +634,13 @@ void swsusp_close(void)
632 634
633 blkdev_put(resume_bdev); 635 blkdev_put(resume_bdev);
634} 636}
637
638static int swsusp_header_init(void)
639{
640 swsusp_header = (struct swsusp_header*) __get_free_page(GFP_KERNEL);
641 if (!swsusp_header)
642 panic("Could not allocate memory for swsusp_header\n");
643 return 0;
644}
645
646core_initcall(swsusp_header_init);