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#include <linux/config.h>
27#include <linux/kernel.h>
28#include <linux/module.h>
29#include <linux/proc_fs.h>
30#include <linux/seq_file.h>
31#include <linux/init.h>
32#include <asm/uaccess.h>
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47#define MAGIC_START "IKCFG_ST"
48#define MAGIC_END "IKCFG_ED"
49#include "config_data.h"
50
51
52#define MAGIC_SIZE (sizeof(MAGIC_START) - 1)
53#define kernel_config_data_size \
54 (sizeof(kernel_config_data) - 1 - MAGIC_SIZE * 2)
55
56#ifdef CONFIG_IKCONFIG_PROC
57
58
59
60
61static ssize_t
62ikconfig_read_current(struct file *file, char __user *buf,
63 size_t len, loff_t * offset)
64{
65 loff_t pos = *offset;
66 ssize_t count;
67
68 if (pos >= kernel_config_data_size)
69 return 0;
70
71 count = min(len, (size_t)(kernel_config_data_size - pos));
72 if (copy_to_user(buf, kernel_config_data + MAGIC_SIZE + pos, count))
73 return -EFAULT;
74
75 *offset += count;
76 return count;
77}
78
79static struct file_operations ikconfig_file_ops = {
80 .owner = THIS_MODULE,
81 .read = ikconfig_read_current,
82};
83
84
85
86
87static int __init ikconfig_init(void)
88{
89 struct proc_dir_entry *entry;
90
91
92 entry = create_proc_entry("config.gz", S_IFREG | S_IRUGO,
93 &proc_root);
94 if (!entry)
95 return -ENOMEM;
96
97 entry->proc_fops = &ikconfig_file_ops;
98 entry->size = kernel_config_data_size;
99
100 return 0;
101}
102
103
104
105
106static void __exit ikconfig_cleanup(void)
107{
108 remove_proc_entry("config.gz", &proc_root);
109}
110
111module_init(ikconfig_init);
112module_exit(ikconfig_cleanup);
113
114MODULE_LICENSE("GPL");
115MODULE_AUTHOR("Randy Dunlap");
116MODULE_DESCRIPTION("Echo the kernel .config file used to build the kernel");
117
118#endif
119