-/*
- * Saving part...
- */
-
-static __inline__ int fill_suspend_header(struct suspend_header *sh)
-{
- memset((char *)sh, 0, sizeof(*sh));
-
- sh->version_code = LINUX_VERSION_CODE;
- sh->num_physpages = num_physpages;
- strncpy(sh->machine, system_utsname.machine, 8);
- strncpy(sh->version, system_utsname.version, 20);
- /* FIXME: Is this bogus? --RR */
- sh->num_cpus = num_online_cpus();
- sh->page_size = PAGE_SIZE;
- sh->suspend_pagedir = pagedir_nosave;
- BUG_ON (pagedir_save != pagedir_nosave);
- sh->num_pbes = nr_copy_pages;
- /* TODO: needed? mounted fs' last mounted date comparison
- * [so they haven't been mounted since last suspend.
- * Maybe it isn't.] [we'd need to do this for _all_ fs-es]
- */
- return 0;
-}
-
-/* We memorize in swapfile_used what swap devices are used for suspension */
-#define SWAPFILE_UNUSED 0
-#define SWAPFILE_SUSPEND 1 /* This is the suspending device */
-#define SWAPFILE_IGNORED 2 /* Those are other swap devices ignored for suspension */
-
-static unsigned short swapfile_used[MAX_SWAPFILES];
-static unsigned short root_swap;
-#define MARK_SWAP_SUSPEND 0
-#define MARK_SWAP_RESUME 2
-
-static void mark_swapfiles(swp_entry_t prev, int mode)
-{
- swp_entry_t entry;
- union diskpage *cur;
- struct page *page;
-
- if (root_swap == 0xFFFF) /* ignored */
- return;
-
- page = alloc_page(GFP_ATOMIC);
- if (!page)
- panic("Out of memory in mark_swapfiles");
- cur = page_address(page);
- /* XXX: this is dirty hack to get first page of swap file */
- entry = swp_entry(root_swap, 0);
- rw_swap_page_sync(READ, entry, page);
-
- if (mode == MARK_SWAP_RESUME) {
- if (!memcmp("S1",cur->swh.magic.magic,2))
- memcpy(cur->swh.magic.magic,"SWAP-SPACE",10);
- else if (!memcmp("S2",cur->swh.magic.magic,2))
- memcpy(cur->swh.magic.magic,"SWAPSPACE2",10);
- else printk("%sUnable to find suspended-data signature (%.10s - misspelled?\n",
- name_resume, cur->swh.magic.magic);
- } else {
- if ((!memcmp("SWAP-SPACE",cur->swh.magic.magic,10)))
- memcpy(cur->swh.magic.magic,"S1SUSP....",10);
- else if ((!memcmp("SWAPSPACE2",cur->swh.magic.magic,10)))
- memcpy(cur->swh.magic.magic,"S2SUSP....",10);
- else panic("\nSwapspace is not swapspace (%.10s)\n", cur->swh.magic.magic);
- cur->link.next = prev; /* prev is the first/last swap page of the resume area */
- /* link.next lies *no more* in last 4/8 bytes of magic */
- }
- rw_swap_page_sync(WRITE, entry, page);
- __free_page(page);
-}
-
-static void read_swapfiles(void) /* This is called before saving image */
-{
- int i, len;
- static char buff[sizeof(resume_file)], *sname;
-
- len=strlen(resume_file);
- root_swap = 0xFFFF;
-
- swap_list_lock();
- for(i=0; i<MAX_SWAPFILES; i++) {
- if (swap_info[i].flags == 0) {
- swapfile_used[i]=SWAPFILE_UNUSED;
- } else {
- if(!len) {
- printk(KERN_WARNING "resume= option should be used to set suspend device" );
- if(root_swap == 0xFFFF) {
- swapfile_used[i] = SWAPFILE_SUSPEND;
- root_swap = i;
- } else
- swapfile_used[i] = SWAPFILE_IGNORED;
- } else {
- /* we ignore all swap devices that are not the resume_file */
- sname = d_path(swap_info[i].swap_file->f_dentry,
- swap_info[i].swap_file->f_vfsmnt,
- buff,
- sizeof(buff));
- if (!strcmp(sname, resume_file)) {
- swapfile_used[i] = SWAPFILE_SUSPEND;
- root_swap = i;
- } else {
-#if 0
- printk( "Resume: device %s (%x != %x) ignored\n", swap_info[i].swap_file->d_name.name, swap_info[i].swap_device, resume_device );
-#endif
- swapfile_used[i] = SWAPFILE_IGNORED;
- }
- }
- }
- }
- swap_list_unlock();
-}
-
-static void lock_swapdevices(void) /* This is called after saving image so modification
- will be lost after resume... and that's what we want. */
-{
- int i;
-
- swap_list_lock();
- for(i = 0; i< MAX_SWAPFILES; i++)
- if(swapfile_used[i] == SWAPFILE_IGNORED) {
- swap_info[i].flags ^= 0xFF; /* we make the device unusable. A new call to
- lock_swapdevices can unlock the devices. */
- }
- swap_list_unlock();
-}
-