Commit | Line | Data |
---|---|---|
a82c63f1 MD |
1 | /* |
2 | * Copyright (C) 2011 Mathieu Desnoyers (mathieu.desnoyers@efficios.com) | |
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 | * | |
8 | * Dual LGPL v2.1/GPL v2 license. | |
9 | */ | |
10 | ||
11 | /* boot_id depends on sysctl */ | |
12 | #if defined(CONFIG_SYSCTL) | |
13 | ||
14 | #include <linux/fs.h> | |
15 | #include <linux/file.h> | |
16 | #include <linux/sched.h> | |
17 | #include <linux/uaccess.h> | |
18 | #include "random.h" | |
19 | ||
20 | /* | |
21 | * Returns string boot id. | |
22 | */ | |
23 | int wrapper_get_bootid(char *bootid) | |
24 | { | |
25 | struct file *file; | |
26 | int ret; | |
27 | ssize_t len; | |
28 | mm_segment_t old_fs; | |
29 | ||
30 | file = filp_open("/proc/sys/kernel/random/boot_id", O_RDONLY, 0); | |
31 | if (IS_ERR(file)) | |
32 | return PTR_ERR(file); | |
33 | ||
34 | old_fs = get_fs(); | |
35 | set_fs(KERNEL_DS); | |
36 | ||
37 | if (!file->f_op || !file->f_op->read) { | |
38 | ret = -EINVAL; | |
39 | goto end; | |
40 | } | |
41 | ||
42 | len = file->f_op->read(file, bootid, BOOT_ID_LEN - 1, &file->f_pos); | |
43 | if (len != BOOT_ID_LEN - 1) { | |
44 | ret = -EINVAL; | |
45 | goto end; | |
46 | } | |
47 | ||
48 | bootid[BOOT_ID_LEN - 1] = '\0'; | |
49 | ret = 0; | |
50 | end: | |
51 | set_fs(old_fs); | |
52 | filp_close(file, current->files); | |
53 | return ret; | |
54 | } | |
55 | ||
56 | #else | |
57 | ||
58 | int wrapper_get_bootid(char *bootid) | |
59 | { | |
60 | return -ENOSYS; | |
61 | } | |
62 | ||
63 | #endif |