2929
3030#define SWSUSP_SIG "S1SUSPEND"
3131
32+ /*
33+ * The swap map is a data structure used for keeping track of each page
34+ * written to a swap partition. It consists of many swap_map_page
35+ * structures that contain each an array of MAP_PAGE_SIZE swap entries.
36+ * These structures are stored on the swap and linked together with the
37+ * help of the .next_swap member.
38+ *
39+ * The swap map is created during suspend. The swap map pages are
40+ * allocated and populated one at a time, so we only need one memory
41+ * page to set up the entire structure.
42+ *
43+ * During resume we also only need to use one swap_map_page structure
44+ * at a time.
45+ */
46+
47+ #define MAP_PAGE_ENTRIES (PAGE_SIZE / sizeof(sector_t) - 1)
48+
49+ struct swap_map_page {
50+ sector_t entries [MAP_PAGE_ENTRIES ];
51+ sector_t next_swap ;
52+ };
53+
54+ /**
55+ * The swap_map_handle structure is used for handling swap in
56+ * a file-alike way
57+ */
58+
59+ struct swap_map_handle {
60+ struct swap_map_page * cur ;
61+ sector_t cur_swap ;
62+ sector_t first_sector ;
63+ unsigned int k ;
64+ };
65+
3266struct swsusp_header {
3367 char reserved [PAGE_SIZE - 20 - sizeof (sector_t ) - sizeof (int )];
3468 sector_t image ;
@@ -151,7 +185,7 @@ struct block_device *hib_resume_bdev;
151185 * Saving part
152186 */
153187
154- static int mark_swapfiles (sector_t start , unsigned int flags )
188+ static int mark_swapfiles (struct swap_map_handle * handle , unsigned int flags )
155189{
156190 int error ;
157191
@@ -160,7 +194,7 @@ static int mark_swapfiles(sector_t start, unsigned int flags)
160194 !memcmp ("SWAPSPACE2" ,swsusp_header -> sig , 10 )) {
161195 memcpy (swsusp_header -> orig_sig ,swsusp_header -> sig , 10 );
162196 memcpy (swsusp_header -> sig ,SWSUSP_SIG , 10 );
163- swsusp_header -> image = start ;
197+ swsusp_header -> image = handle -> first_sector ;
164198 swsusp_header -> flags = flags ;
165199 error = hib_bio_write_page (swsusp_resume_block ,
166200 swsusp_header , NULL );
@@ -226,39 +260,6 @@ static int write_page(void *buf, sector_t offset, struct bio **bio_chain)
226260 return hib_bio_write_page (offset , src , bio_chain );
227261}
228262
229- /*
230- * The swap map is a data structure used for keeping track of each page
231- * written to a swap partition. It consists of many swap_map_page
232- * structures that contain each an array of MAP_PAGE_SIZE swap entries.
233- * These structures are stored on the swap and linked together with the
234- * help of the .next_swap member.
235- *
236- * The swap map is created during suspend. The swap map pages are
237- * allocated and populated one at a time, so we only need one memory
238- * page to set up the entire structure.
239- *
240- * During resume we also only need to use one swap_map_page structure
241- * at a time.
242- */
243-
244- #define MAP_PAGE_ENTRIES (PAGE_SIZE / sizeof(sector_t) - 1)
245-
246- struct swap_map_page {
247- sector_t entries [MAP_PAGE_ENTRIES ];
248- sector_t next_swap ;
249- };
250-
251- /**
252- * The swap_map_handle structure is used for handling swap in
253- * a file-alike way
254- */
255-
256- struct swap_map_handle {
257- struct swap_map_page * cur ;
258- sector_t cur_swap ;
259- unsigned int k ;
260- };
261-
262263static void release_swap_writer (struct swap_map_handle * handle )
263264{
264265 if (handle -> cur )
@@ -277,6 +278,7 @@ static int get_swap_writer(struct swap_map_handle *handle)
277278 return - ENOSPC ;
278279 }
279280 handle -> k = 0 ;
281+ handle -> first_sector = handle -> cur_swap ;
280282 return 0 ;
281283}
282284
@@ -421,8 +423,6 @@ int swsusp_write(unsigned int flags)
421423 }
422424 error = get_swap_writer (& handle );
423425 if (!error ) {
424- sector_t start = handle .cur_swap ;
425-
426426 error = swap_write_page (& handle , header , NULL );
427427 if (!error )
428428 error = save_image (& handle , & snapshot ,
@@ -431,7 +431,7 @@ int swsusp_write(unsigned int flags)
431431 if (!error ) {
432432 flush_swap_writer (& handle );
433433 printk (KERN_INFO "PM: S" );
434- error = mark_swapfiles (start , flags );
434+ error = mark_swapfiles (& handle , flags );
435435 printk ("|\n" );
436436 }
437437 }
0 commit comments