Commit | Line | Data |
---|---|---|
a82c63f1 | 1 | /* |
886d51a3 | 2 | * wrapper/random.c |
a82c63f1 MD |
3 | * |
4 | * wrapper around bootid read. Using KALLSYMS to get its address when | |
5 | * available, else we need to have a kernel that exports this function to GPL | |
6 | * modules. | |
7 | * | |
886d51a3 MD |
8 | * Copyright (C) 2011-2012 Mathieu Desnoyers <mathieu.desnoyers@efficios.com> |
9 | * | |
10 | * This library is free software; you can redistribute it and/or | |
11 | * modify it under the terms of the GNU Lesser General Public | |
12 | * License as published by the Free Software Foundation; only | |
13 | * version 2.1 of the License. | |
14 | * | |
15 | * This library is distributed in the hope that it will be useful, | |
16 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
17 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | |
18 | * Lesser General Public License for more details. | |
19 | * | |
20 | * You should have received a copy of the GNU Lesser General Public | |
21 | * License along with this library; if not, write to the Free Software | |
22 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA | |
a82c63f1 MD |
23 | */ |
24 | ||
25 | /* boot_id depends on sysctl */ | |
26 | #if defined(CONFIG_SYSCTL) | |
27 | ||
28 | #include <linux/fs.h> | |
29 | #include <linux/file.h> | |
30 | #include <linux/sched.h> | |
31 | #include <linux/uaccess.h> | |
32 | #include "random.h" | |
33 | ||
34 | /* | |
35 | * Returns string boot id. | |
36 | */ | |
37 | int wrapper_get_bootid(char *bootid) | |
38 | { | |
39 | struct file *file; | |
40 | int ret; | |
41 | ssize_t len; | |
42 | mm_segment_t old_fs; | |
43 | ||
44 | file = filp_open("/proc/sys/kernel/random/boot_id", O_RDONLY, 0); | |
45 | if (IS_ERR(file)) | |
46 | return PTR_ERR(file); | |
47 | ||
48 | old_fs = get_fs(); | |
49 | set_fs(KERNEL_DS); | |
50 | ||
51 | if (!file->f_op || !file->f_op->read) { | |
52 | ret = -EINVAL; | |
53 | goto end; | |
54 | } | |
55 | ||
56 | len = file->f_op->read(file, bootid, BOOT_ID_LEN - 1, &file->f_pos); | |
57 | if (len != BOOT_ID_LEN - 1) { | |
58 | ret = -EINVAL; | |
59 | goto end; | |
60 | } | |
61 | ||
62 | bootid[BOOT_ID_LEN - 1] = '\0'; | |
63 | ret = 0; | |
64 | end: | |
65 | set_fs(old_fs); | |
66 | filp_close(file, current->files); | |
67 | return ret; | |
68 | } | |
69 | ||
70 | #else | |
71 | ||
72 | int wrapper_get_bootid(char *bootid) | |
73 | { | |
74 | return -ENOSYS; | |
75 | } | |
76 | ||
77 | #endif |