int allocate_checksum_pages(void) { int pages_needed = checksum_pages_needed(); if (!toi_checksum_ops.enabled) return 0; while (pages_allocated < pages_needed) { unsigned long *new_page = (unsigned long *) toi_get_zeroed_page(15, TOI_ATOMIC_GFP); if (!new_page) { printk(KERN_ERR "Unable to allocate checksum pages.\n"); return -ENOMEM; } SetPageNosave(virt_to_page(new_page)); (*new_page) = page_list; page_list = (unsigned long) new_page; pages_allocated++; } next_page = (unsigned long) page_list; checksum_index = 0; return 0; }
int get_signature_page(void) { if (!toi_cur_sig_page) { toi_message(TOI_IO, TOI_VERBOSE, 0, "Allocating current signature page."); toi_cur_sig_page = (char *)toi_get_zeroed_page(38, TOI_ATOMIC_GFP); if (!toi_cur_sig_page) { pr_err("Failed to allocate memory for the current image signature.\n"); return -ENOMEM; } toi_sig_data = (struct sig_data *)toi_cur_sig_page; } toi_message(TOI_IO, TOI_VERBOSE, 0, "Reading signature from dev %x, sector %lu.", (unsigned int) resume_block_device->bd_dev, resume_firstblock); return toi_bio_ops.bdev_page_io(READ, resume_block_device, resume_firstblock, virt_to_page(toi_cur_sig_page)); }
int remove_old_signature(void) { union p_diskpage swap_header_page = (union p_diskpage) toi_cur_sig_page; char *orig_sig, *no_image_signature_contents; char *header_start = (char *) toi_get_zeroed_page(38, TOI_ATOMIC_GFP); int result; struct block_device *header_bdev; struct old_sig_data *old_sig_data = &swap_header_page.pointer->old_sig_data; header_bdev = toi_open_bdev(NULL, old_sig_data->device, 1); result = toi_bio_ops.bdev_page_io(READ, header_bdev, old_sig_data->sector, virt_to_page(header_start)); if (result) goto out; /* * TODO: Get the original contents of the first bytes of the swap * header page. */ if (!old_sig_data->orig_sig_type) orig_sig = "SWAP-SPACE"; else orig_sig = "SWAPSPACE2"; memcpy(swap_header_page.pointer->swh.magic.magic, orig_sig, 10); memcpy(swap_header_page.ptr, header_start, sizeof(no_image_signature_contents)); result = toi_bio_ops.bdev_page_io(WRITE, resume_block_device, resume_firstblock, virt_to_page(swap_header_page.ptr)); out: toi_close_bdev(header_bdev); have_old_image = 0; toi_free_page(38, (unsigned long) header_start); return result; }