int swsusp_write(unsigned int flags) { struct swap_map_handle handle; struct snapshot_handle snapshot; struct swsusp_info *header; int error; error = swsusp_swap_check(); if (error) { printk(KERN_ERR "PM: Cannot find swap device, try " "swapon -a.\n"); return error; } memset(&snapshot, 0, sizeof(struct snapshot_handle)); error = snapshot_read_next(&snapshot, PAGE_SIZE); if (error < PAGE_SIZE) { if (error >= 0) error = -EFAULT; goto out; } header = (struct swsusp_info *)data_of(snapshot); if (!enough_swap(header->pages)) { printk(KERN_ERR "PM: Not enough free swap\n"); error = -ENOSPC; goto out; } error = get_swap_writer(&handle); if (!error) { sector_t start = handle.cur_swap; error = swap_write_page(&handle, header, NULL); if (!error) error = save_image(&handle, &snapshot, header->pages - 1); if (!error) { flush_swap_writer(&handle); printk(KERN_INFO "PM: S"); error = mark_swapfiles(start, flags); printk("|\n"); } } if (error) free_all_swap_pages(root_swap); release_swap_writer(&handle); out: swsusp_close(FMODE_WRITE); return error; }
int swsusp_write(void) { struct swap_map_handle handle; struct snapshot_handle snapshot; struct swsusp_info *header; int error; if ((error = swsusp_swap_check())) { printk(KERN_ERR "swsusp: Cannot find swap device, try swapon -a.\n"); return error; } memset(&snapshot, 0, sizeof(struct snapshot_handle)); error = snapshot_read_next(&snapshot, PAGE_SIZE); if (error < PAGE_SIZE) return error < 0 ? error : -EFAULT; header = (struct swsusp_info *)data_of(snapshot); if (!enough_swap(header->pages)) { printk(KERN_ERR "swsusp: Not enough free swap\n"); return -ENOSPC; } error = get_swap_writer(&handle); if (!error) { unsigned long start = handle.cur_swap; error = swap_write_page(&handle, header); if (!error) error = save_image(&handle, &snapshot, header->pages - 1); if (!error) { flush_swap_writer(&handle); printk("S"); error = mark_swapfiles(swp_entry(root_swap, start)); printk("|\n"); } } if (error) free_all_swap_pages(root_swap, handle.bitmap); release_swap_writer(&handle); return error; }