blob: 915d199d80bbb733d1a9be0e46518e683a911d4d [file] [log] [blame]
Dees_Troy51a0e822012-09-05 15:24:24 -04001#include <errno.h>
2#include <stdio.h>
3#include <stdlib.h>
4#include <sys/reboot.h>
5//#include <reboot/reboot.h>
6#include <unistd.h>
7
8#include "tw_reboot.h"
9#include "recovery_ui.h"
10#include "roots.h"
11#include "extra-functions.h"
12#include "data.h"
13#include "variables.h"
14
15// isRebootCommandSupported: Return 1 if command is supported, 0 if the command is not supported, -1 on error
16int tw_isRebootCommandSupported(RebootCommand command)
17{
18 switch (command)
19 {
20 case rb_system:
21 case rb_recovery:
22 case rb_poweroff:
23 case rb_bootloader:
24 case rb_download:
25 return 1;
26
27 default:
28 return 0;
29 }
30 return -1;
31}
32
33// setRebootMode: Set the reboot state (without rebooting). Return 0 on success, -1 on error or unsupported
34int tw_setRebootMode(RebootCommand command)
35{
36 return -1;
37}
38
39// reboot: Reboot the system. Return -1 on error, no return on success
40int tw_reboot(RebootCommand command)
41{
42 // Always force a sync before we reboot
43 sync();
44
45 ensure_path_unmounted("/sdcard");
46
47 switch (command)
48 {
49 case rb_current:
50 case rb_system:
51 finish_recovery("s");
52 sync();
53 check_and_run_script("/sbin/rebootsystem.sh", "reboot system");
54 return reboot(RB_AUTOBOOT);
55 case rb_recovery:
56 check_and_run_script("/sbin/rebootrecovery.sh", "reboot recovery");
57 return __reboot(LINUX_REBOOT_MAGIC1, LINUX_REBOOT_MAGIC2, LINUX_REBOOT_CMD_RESTART2, (void*) "recovery");
58 case rb_bootloader:
59 check_and_run_script("/sbin/rebootbootloader.sh", "reboot bootloader");
60 return __reboot(LINUX_REBOOT_MAGIC1, LINUX_REBOOT_MAGIC2, LINUX_REBOOT_CMD_RESTART2, (void*) "bootloader");
61 case rb_poweroff:
62 check_and_run_script("/sbin/poweroff.sh", "power off");
63 return reboot(RB_POWER_OFF);
64 case rb_download:
65 check_and_run_script("/sbin/rebootdownload.sh", "reboot download");
66 return __reboot(LINUX_REBOOT_MAGIC1, LINUX_REBOOT_MAGIC2, LINUX_REBOOT_CMD_RESTART2, (void*) "download");
67 return 1;
68 default:
69 return -1;
70 }
71 return -1;
72}
73