-
Notifications
You must be signed in to change notification settings - Fork 3
/
reboot.c
59 lines (51 loc) · 1.4 KB
/
reboot.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
#include <errno.h>
#include <stdio.h>
#include <stdlib.h>
#include <sys/reboot.h>
#include <reboot/reboot.h>
#include <unistd.h>
#include "tw_reboot.h"
#include "recovery_ui.h"
// isRebootCommandSupported: Return 1 if command is supported, 0 if the command is not supported, -1 on error
int tw_isRebootCommandSupported(RebootCommand command)
{
switch (command)
{
case rb_system:
case rb_recovery:
case rb_poweroff:
case rb_bootloader:
return 1;
default:
return 0;
}
return -1;
}
// setRebootMode: Set the reboot state (without rebooting). Return 0 on success, -1 on error or unsupported
int tw_setRebootMode(RebootCommand command)
{
return -1;
}
// reboot: Reboot the system. Return -1 on error, no return on success
int tw_reboot(RebootCommand command)
{
// Always force a sync before we reboot
sync();
ensure_path_unmounted("/sdcard");
switch (command)
{
case rb_current:
case rb_system:
finish_recovery("s");
return reboot(RB_AUTOBOOT);
case rb_recovery:
return __reboot(LINUX_REBOOT_MAGIC1, LINUX_REBOOT_MAGIC2, LINUX_REBOOT_CMD_RESTART2, (void*) "recovery");
case rb_bootloader:
return __reboot(LINUX_REBOOT_MAGIC1, LINUX_REBOOT_MAGIC2, LINUX_REBOOT_CMD_RESTART2, (void*) "bootloader");
case rb_poweroff:
return reboot(RB_POWER_OFF);
default:
return -1;
}
return -1;
}