861554a2b5639c78875a6c2f054e88ff732d22f1
[platform/kernel/linux-rpi.git] / drivers / misc / tizen-inform-reboot.c
1 /*
2  * Tizen reboot parameter passing notifier
3  *
4  * Written by: Junghoon Kim <jhoon20.kim@samsung.com>
5  *
6  * Copyright (C) 2017 Samsung Electronics Co., Ltd.
7  *
8  * This program is free software; you can redistribute it and/or modify
9  * it under the terms of the GNU General Public License version 2 as
10  * published by the Free Software Foundation.
11  */
12
13 #include <linux/notifier.h>
14 #include <linux/reboot.h>
15 #include <linux/syscalls.h>
16 #include <linux/file.h>
17 #include <linux/fcntl.h>
18 #include <linux/uaccess.h>
19
20 static int inform_reboot_notifier(struct notifier_block *nb,
21                                                 unsigned long val, void *buf)
22 {
23         char *cmd = buf;
24         char *filename = CONFIG_TIZEN_INFORM_PATH;
25         struct file *file;
26         loff_t pos = 0;
27
28         file = filp_open(filename, O_CREAT | O_WRONLY | O_TRUNC, 0644);
29         if (!IS_ERR(file)) {
30                 struct super_block *sb = file->f_path.dentry->d_sb;
31
32                 if (cmd) {
33                         if (!strncmp(cmd, "fota", 4))
34                                 cmd = "upgr";
35                         else if (!strncmp(cmd, "recovery", 8))
36                                 cmd = "rcvr";
37                         else if (!strncmp(cmd, "download", 8))
38                                 cmd = "dwnl";
39                         else
40                                 cmd = "ndef";
41                 } else
42                         cmd = "norm";
43
44                 vfs_write(file, cmd, strlen(cmd), &pos);
45
46                 down_read(&sb->s_umount);
47                 sync_filesystem(sb);
48                 up_read(&sb->s_umount);
49
50                 fput(file);
51         } else {
52                 pr_err("Reboot parameter passing is failed.\n"
53                                 "Inform file path should be described correctly in config.\n");
54         }
55
56         return NOTIFY_DONE;
57 }
58
59 static struct notifier_block nb_inform_reboot_block = {
60         .notifier_call = inform_reboot_notifier,
61         .priority = 256,
62 };
63
64 static int __init inform_reboot_init(void)
65 {
66         /* to support reboot parameter passing */
67         register_reboot_notifier(&nb_inform_reboot_block);
68         return 0;
69 }
70
71 subsys_initcall(inform_reboot_init);