1 | /*␊ |
2 | * HibernateEnabler.c␊ |
3 | * Chameleon␊ |
4 | *␊ |
5 | * Created by cparm.␊ |
6 | */␊ |
7 | ␊ |
8 | #include "bootstruct.h"␊ |
9 | #include "modules.h"␊ |
10 | #include "resume.h"␊ |
11 | #include "sl.h"␊ |
12 | #include "graphic_utils.h"␊ |
13 | ␊ |
14 | #define kWake␉␉␉␉"Wake"␉␉␉␉/* boot.c */␊ |
15 | #define kForceWake␉␉␉"ForceWake"␉␉␉/* boot.c */␊ |
16 | #define kWakeImage␉␉␉"WakeImage"␉␉␉/* boot.c */␊ |
17 | #define kEnableHibernate␉"EnableHibernateModule"␊ |
18 | ␊ |
19 | void HibernateEnabler_hook(void* arg1, void* arg2, void* arg3, void* arg4, void* arg5, void* arg6)␊ |
20 | {␊ |
21 | ␉bool tryresume,tryresumedefault, forceresume;␊ |
22 | ␉␊ |
23 | ␉if (!getBoolForKey (kWake, &tryresume, &bootInfo->bootConfig))␊ |
24 | ␉{␊ |
25 | ␉␉tryresume = true;␊ |
26 | ␉␉tryresumedefault = true;␊ |
27 | ␉}␊ |
28 | ␉else␊ |
29 | ␉{␊ |
30 | ␉␉tryresumedefault = false;␊ |
31 | ␉}␊ |
32 | ␉␊ |
33 | ␉if (!getBoolForKey (kForceWake, &forceresume, &bootInfo->bootConfig))␊ |
34 | ␉{␊ |
35 | ␉␉forceresume = false;␊ |
36 | ␉}␊ |
37 | ␉␊ |
38 | ␉if (forceresume)␊ |
39 | ␉{␊ |
40 | ␉␉tryresume = true;␊ |
41 | ␉␉tryresumedefault = false;␊ |
42 | ␉}␊ |
43 | ␉␊ |
44 | ␉while (tryresume) {␊ |
45 | ␉␉const char *tmp, *val;␊ |
46 | ␉␉int len, ret = -1;␊ |
47 | ␉␉long flags, sleeptime;␊ |
48 | ␉␉BVRef bvr;␊ |
49 | ␉␉if (!getValueForKey(kWakeImage, &val, &len, &bootInfo->bootConfig))␊ |
50 | ␉␉␉val="/private/var/vm/sleepimage";␊ |
51 | ␉␉␊ |
52 | ␉␉// Do this first to be sure that root volume is mounted␊ |
53 | ␉␉ret = GetFileInfo(0, val, &flags, &sleeptime);␊ |
54 | ␉␉␊ |
55 | ␉␉if ((bvr = getBootVolumeRef(val, &tmp)) == NULL)␊ |
56 | ␉␉␉break;␊ |
57 | ␉␉␊ |
58 | ␉␉// Can't check if it was hibernation Wake=y is required␊ |
59 | ␉␉if (bvr->modTime == 0 && tryresumedefault)␊ |
60 | ␉␉␉break;␊ |
61 | ␉␉␊ |
62 | ␉␉if ((ret != 0) || ((flags & kFileTypeMask) != kFileTypeFlat))␊ |
63 | ␉␉␉break;␊ |
64 | ␉␉␊ |
65 | ␉␉if (!forceresume && ((sleeptime+3)<bvr->modTime))␊ |
66 | ␉␉{␊ |
67 | ␉␉␉printf ("Hibernate image is too old by %d seconds. Use ForceWake=y to override\n",bvr->modTime-sleeptime);␊ |
68 | ␉␉␉break;␊ |
69 | ␉␉}␊ |
70 | ␉␉␊ |
71 | ␉␉HibernateBoot((char *)val);␊ |
72 | ␉␉break;␊ |
73 | ␉}␊ |
74 | ␉␊ |
75 | }␊ |
76 | ␊ |
77 | void HibernateEnabler_start()␊ |
78 | {␊ |
79 | ␉bool enable = true;␊ |
80 | ␉getBoolForKey(kEnableHibernate, &enable, &bootInfo->bootConfig) ;␊ |
81 | ␉␊ |
82 | ␉if (enable)␊ |
83 | ␉{␊ |
84 | ␉␉register_hook_callback("PreBoot", &HibernateEnabler_hook);␊ |
85 | ␉␉register_hook_callback("spinActivity_hook", &spinActivityIndicator_hook);␊ |
86 | ␉}␊ |
87 | } |