Annotation of /trunk/mkinitrd-magellan/klibc/usr/kinit/resume/resumelib.c
Parent Directory | Revision Log
Revision 1122 -
(hide annotations)
(download)
Wed Aug 18 21:11:40 2010 UTC (13 years, 9 months ago) by niro
File MIME type: text/plain
File size: 2080 byte(s)
Wed Aug 18 21:11:40 2010 UTC (13 years, 9 months ago) by niro
File MIME type: text/plain
File size: 2080 byte(s)
-updated to klibc-1.5.19
1 | niro | 532 | /* |
2 | * Handle resume from suspend-to-disk | ||
3 | */ | ||
4 | |||
5 | #include <errno.h> | ||
6 | #include <fcntl.h> | ||
7 | #include <stdio.h> | ||
8 | #include <stdlib.h> | ||
9 | #include <string.h> | ||
10 | #include <limits.h> | ||
11 | #include <sys/stat.h> | ||
12 | #include <sys/sysmacros.h> | ||
13 | |||
14 | #include "kinit.h" | ||
15 | #include "do_mounts.h" | ||
16 | #include "resume.h" | ||
17 | |||
18 | #ifndef CONFIG_PM_STD_PARTITION | ||
19 | # define CONFIG_PM_STD_PARTITION "" | ||
20 | #endif | ||
21 | |||
22 | int do_resume(int argc, char *argv[]) | ||
23 | { | ||
24 | const char *resume_file = CONFIG_PM_STD_PARTITION; | ||
25 | const char *resume_arg; | ||
26 | unsigned long long resume_offset; | ||
27 | |||
28 | resume_arg = get_arg(argc, argv, "resume="); | ||
29 | resume_file = resume_arg ? resume_arg : resume_file; | ||
30 | /* No resume device specified */ | ||
31 | if (!resume_file[0]) | ||
32 | return 0; | ||
33 | |||
34 | resume_arg = get_arg(argc, argv, "resume_offset="); | ||
35 | resume_offset = resume_arg ? strtoull(resume_arg, NULL, 0) : 0ULL; | ||
36 | |||
37 | /* Fix: we either should consider reverting the device back to | ||
38 | ordinary swap, or (better) put that code into swapon */ | ||
39 | /* Noresume requested */ | ||
40 | if (get_flag(argc, argv, "noresume")) | ||
41 | return 0; | ||
42 | return resume(resume_file, resume_offset); | ||
43 | } | ||
44 | |||
45 | int resume(const char *resume_file, unsigned long long resume_offset) | ||
46 | { | ||
47 | dev_t resume_device; | ||
48 | int powerfd = -1; | ||
49 | char device_string[64]; | ||
50 | int len; | ||
51 | |||
52 | resume_device = name_to_dev_t(resume_file); | ||
53 | |||
54 | if (major(resume_device) == 0) { | ||
55 | fprintf(stderr, "Invalid resume device: %s\n", resume_file); | ||
56 | goto failure; | ||
57 | } | ||
58 | |||
59 | if ((powerfd = open("/sys/power/resume", O_WRONLY)) < 0) | ||
60 | goto fail_r; | ||
61 | |||
62 | len = snprintf(device_string, sizeof device_string, | ||
63 | "%u:%u:%llu", | ||
64 | major(resume_device), minor(resume_device), | ||
65 | resume_offset); | ||
66 | |||
67 | /* This should never happen */ | ||
68 | if (len >= sizeof device_string) | ||
69 | goto fail_r; | ||
70 | |||
71 | niro | 1122 | dprintf("kinit: trying to resume from %s\n", resume_file); |
72 | niro | 532 | |
73 | if (write(powerfd, device_string, len) != len) | ||
74 | goto fail_r; | ||
75 | |||
76 | /* Okay, what are we still doing alive... */ | ||
77 | failure: | ||
78 | if (powerfd >= 0) | ||
79 | close(powerfd); | ||
80 | niro | 1122 | dprintf("kinit: No resume image, doing normal boot...\n"); |
81 | niro | 532 | return -1; |
82 | |||
83 | fail_r: | ||
84 | fprintf(stderr, "Cannot write /sys/power/resume " | ||
85 | "(no software suspend kernel support?)\n"); | ||
86 | goto failure; | ||
87 | } |