Chameleon

Chameleon Svn Source Tree

Root/branches/cparm/i386/modules/HibernateEnabler/HibernateEnabler.c

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

Archive Download this file

Revision: 1119