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

Archive Download this file

Revision: 1468