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