diff options
author | Mike Larkin <mlarkin@cvs.openbsd.org> | 2011-05-09 00:08:29 +0000 |
---|---|---|
committer | Mike Larkin <mlarkin@cvs.openbsd.org> | 2011-05-09 00:08:29 +0000 |
commit | 9e98fa48614e64d893e77e0f7386143b1a3904ff (patch) | |
tree | abd885d9676b5d1baf1080b68eeba1033f140b2a /sys | |
parent | 0f48b8da1be41c9d51bae8163c8e75c5a4a95577 (diff) |
Add signature read/write functions for i386 hibernate.
Also fix a missing parenthesis in the previous commit.
Diffstat (limited to 'sys')
-rw-r--r-- | sys/arch/i386/i386/hibernate_machdep.c | 63 |
1 files changed, 56 insertions, 7 deletions
diff --git a/sys/arch/i386/i386/hibernate_machdep.c b/sys/arch/i386/i386/hibernate_machdep.c index c94fdf9985b..f69a9e6ded2 100644 --- a/sys/arch/i386/i386/hibernate_machdep.c +++ b/sys/arch/i386/i386/hibernate_machdep.c @@ -48,6 +48,8 @@ void *get_hibernate_io_function(void); int get_hibernate_info(struct hibernate_info *); void hibernate_enter_resume_pte(vaddr_t, paddr_t); void hibernate_populate_resume_pt(paddr_t *, paddr_t *); +int hibernate_write_signature(void); +int hibernate_clear_signature(void); struct hibernate_info *global_hiber_info; paddr_t global_image_start; @@ -129,9 +131,9 @@ get_hibernate_info(struct hibernate_info *hiber_info) } /* Calculate signature block offset in swap */ - hiber_info->sig_offset = DL_BLKTOSEC(&dl, - dl.d_partitions[1].p_size - 1)) * - DL_BLKSPERSEC(&dl); + hiber_info->sig_offset = DL_BLKTOSEC(&dl, + (dl.d_partitions[1].p_size - 1)) * + DL_BLKSPERSEC(&dl); /* Calculate memory image offset in swap */ hiber_info->image_offset = dl.d_partitions[1].p_offset + @@ -251,8 +253,9 @@ hibernate_write_image() (void *)HIBERNATE_ALLOC_PAGE); } } - - return (1); + + /* Image write complete, write the signature and return */ + return hibernate_write_signature(); } int @@ -293,8 +296,9 @@ hibernate_read_image() } } - - return (1); + + /* Read complete, clear the signature and return */ + return hibernate_clear_signature(); } int @@ -415,4 +419,49 @@ hibernate_resume() */ hibernate_resume_machine(); } + +int +hibernate_write_signature() +{ + struct hibernate_info hiber_info; + u_int8_t *io_page; + + /* Get current running machine's hibernate info */ + if (!get_hibernate_info(&hiber_info)) + return (0); + + io_page = malloc(PAGE_SIZE, M_DEVBUF, M_NOWAIT); + if (!io_page) + return (0); + + /* Write hibernate info to disk */ + hiber_info.io_func(hiber_info.device, hiber_info.sig_offset, + (vaddr_t)&hiber_info, 512, 1, io_page); + + free(io_page, M_DEVBUF); + + return (1); +} + +int +hibernate_clear_signature() +{ + struct hibernate_info hiber_info; + u_int8_t *io_page; + + /* Zero out a blank hiber_info */ + bzero(&hiber_info, sizeof(hiber_info)); + + io_page = malloc(PAGE_SIZE, M_DEVBUF, M_NOWAIT); + if (!io_page) + return (0); + + /* Write (zeroed) hibernate info to disk */ + hiber_info.io_func(hiber_info.device, hiber_info.sig_offset, + (vaddr_t)&hiber_info, 512, 1, io_page); + + free(io_page, M_DEVBUF); + + return (1); +} #endif /* !SMALL_KERNEL */ |