xref: /linux/kernel/configs.c (revision 1da177e4c3f41524e886b7f1b8a0c1fc7321cac2)
1*1da177e4SLinus Torvalds /*
2*1da177e4SLinus Torvalds  * kernel/configs.c
3*1da177e4SLinus Torvalds  * Echo the kernel .config file used to build the kernel
4*1da177e4SLinus Torvalds  *
5*1da177e4SLinus Torvalds  * Copyright (C) 2002 Khalid Aziz <khalid_aziz@hp.com>
6*1da177e4SLinus Torvalds  * Copyright (C) 2002 Randy Dunlap <rddunlap@osdl.org>
7*1da177e4SLinus Torvalds  * Copyright (C) 2002 Al Stone <ahs3@fc.hp.com>
8*1da177e4SLinus Torvalds  * Copyright (C) 2002 Hewlett-Packard Company
9*1da177e4SLinus Torvalds  *
10*1da177e4SLinus Torvalds  * This program is free software; you can redistribute it and/or modify
11*1da177e4SLinus Torvalds  * it under the terms of the GNU General Public License as published by
12*1da177e4SLinus Torvalds  * the Free Software Foundation; either version 2 of the License, or (at
13*1da177e4SLinus Torvalds  * your option) any later version.
14*1da177e4SLinus Torvalds  *
15*1da177e4SLinus Torvalds  * This program is distributed in the hope that it will be useful, but
16*1da177e4SLinus Torvalds  * WITHOUT ANY WARRANTY; without even the implied warranty of
17*1da177e4SLinus Torvalds  * MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE, GOOD TITLE or
18*1da177e4SLinus Torvalds  * NON INFRINGEMENT.  See the GNU General Public License for more
19*1da177e4SLinus Torvalds  * details.
20*1da177e4SLinus Torvalds  *
21*1da177e4SLinus Torvalds  * You should have received a copy of the GNU General Public License
22*1da177e4SLinus Torvalds  * along with this program; if not, write to the Free Software
23*1da177e4SLinus Torvalds  * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
24*1da177e4SLinus Torvalds  */
25*1da177e4SLinus Torvalds 
26*1da177e4SLinus Torvalds #include <linux/config.h>
27*1da177e4SLinus Torvalds #include <linux/kernel.h>
28*1da177e4SLinus Torvalds #include <linux/module.h>
29*1da177e4SLinus Torvalds #include <linux/proc_fs.h>
30*1da177e4SLinus Torvalds #include <linux/seq_file.h>
31*1da177e4SLinus Torvalds #include <linux/init.h>
32*1da177e4SLinus Torvalds #include <asm/uaccess.h>
33*1da177e4SLinus Torvalds 
34*1da177e4SLinus Torvalds /**************************************************/
35*1da177e4SLinus Torvalds /* the actual current config file                 */
36*1da177e4SLinus Torvalds 
37*1da177e4SLinus Torvalds /*
38*1da177e4SLinus Torvalds  * Define kernel_config_data and kernel_config_data_size, which contains the
39*1da177e4SLinus Torvalds  * wrapped and compressed configuration file.  The file is first compressed
40*1da177e4SLinus Torvalds  * with gzip and then bounded by two eight byte magic numbers to allow
41*1da177e4SLinus Torvalds  * extraction from a binary kernel image:
42*1da177e4SLinus Torvalds  *
43*1da177e4SLinus Torvalds  *   IKCFG_ST
44*1da177e4SLinus Torvalds  *   <image>
45*1da177e4SLinus Torvalds  *   IKCFG_ED
46*1da177e4SLinus Torvalds  */
47*1da177e4SLinus Torvalds #define MAGIC_START	"IKCFG_ST"
48*1da177e4SLinus Torvalds #define MAGIC_END	"IKCFG_ED"
49*1da177e4SLinus Torvalds #include "config_data.h"
50*1da177e4SLinus Torvalds 
51*1da177e4SLinus Torvalds 
52*1da177e4SLinus Torvalds #define MAGIC_SIZE (sizeof(MAGIC_START) - 1)
53*1da177e4SLinus Torvalds #define kernel_config_data_size \
54*1da177e4SLinus Torvalds 	(sizeof(kernel_config_data) - 1 - MAGIC_SIZE * 2)
55*1da177e4SLinus Torvalds 
56*1da177e4SLinus Torvalds #ifdef CONFIG_IKCONFIG_PROC
57*1da177e4SLinus Torvalds 
58*1da177e4SLinus Torvalds /**************************************************/
59*1da177e4SLinus Torvalds /* globals and useful constants                   */
60*1da177e4SLinus Torvalds 
61*1da177e4SLinus Torvalds static ssize_t
62*1da177e4SLinus Torvalds ikconfig_read_current(struct file *file, char __user *buf,
63*1da177e4SLinus Torvalds 		      size_t len, loff_t * offset)
64*1da177e4SLinus Torvalds {
65*1da177e4SLinus Torvalds 	loff_t pos = *offset;
66*1da177e4SLinus Torvalds 	ssize_t count;
67*1da177e4SLinus Torvalds 
68*1da177e4SLinus Torvalds 	if (pos >= kernel_config_data_size)
69*1da177e4SLinus Torvalds 		return 0;
70*1da177e4SLinus Torvalds 
71*1da177e4SLinus Torvalds 	count = min(len, (size_t)(kernel_config_data_size - pos));
72*1da177e4SLinus Torvalds 	if (copy_to_user(buf, kernel_config_data + MAGIC_SIZE + pos, count))
73*1da177e4SLinus Torvalds 		return -EFAULT;
74*1da177e4SLinus Torvalds 
75*1da177e4SLinus Torvalds 	*offset += count;
76*1da177e4SLinus Torvalds 	return count;
77*1da177e4SLinus Torvalds }
78*1da177e4SLinus Torvalds 
79*1da177e4SLinus Torvalds static struct file_operations ikconfig_file_ops = {
80*1da177e4SLinus Torvalds 	.owner = THIS_MODULE,
81*1da177e4SLinus Torvalds 	.read = ikconfig_read_current,
82*1da177e4SLinus Torvalds };
83*1da177e4SLinus Torvalds 
84*1da177e4SLinus Torvalds /***************************************************/
85*1da177e4SLinus Torvalds /* ikconfig_init: start up everything we need to */
86*1da177e4SLinus Torvalds 
87*1da177e4SLinus Torvalds static int __init ikconfig_init(void)
88*1da177e4SLinus Torvalds {
89*1da177e4SLinus Torvalds 	struct proc_dir_entry *entry;
90*1da177e4SLinus Torvalds 
91*1da177e4SLinus Torvalds 	/* create the current config file */
92*1da177e4SLinus Torvalds 	entry = create_proc_entry("config.gz", S_IFREG | S_IRUGO,
93*1da177e4SLinus Torvalds 				  &proc_root);
94*1da177e4SLinus Torvalds 	if (!entry)
95*1da177e4SLinus Torvalds 		return -ENOMEM;
96*1da177e4SLinus Torvalds 
97*1da177e4SLinus Torvalds 	entry->proc_fops = &ikconfig_file_ops;
98*1da177e4SLinus Torvalds 	entry->size = kernel_config_data_size;
99*1da177e4SLinus Torvalds 
100*1da177e4SLinus Torvalds 	return 0;
101*1da177e4SLinus Torvalds }
102*1da177e4SLinus Torvalds 
103*1da177e4SLinus Torvalds /***************************************************/
104*1da177e4SLinus Torvalds /* ikconfig_cleanup: clean up our mess           */
105*1da177e4SLinus Torvalds 
106*1da177e4SLinus Torvalds static void __exit ikconfig_cleanup(void)
107*1da177e4SLinus Torvalds {
108*1da177e4SLinus Torvalds 	remove_proc_entry("config.gz", &proc_root);
109*1da177e4SLinus Torvalds }
110*1da177e4SLinus Torvalds 
111*1da177e4SLinus Torvalds module_init(ikconfig_init);
112*1da177e4SLinus Torvalds module_exit(ikconfig_cleanup);
113*1da177e4SLinus Torvalds 
114*1da177e4SLinus Torvalds MODULE_LICENSE("GPL");
115*1da177e4SLinus Torvalds MODULE_AUTHOR("Randy Dunlap");
116*1da177e4SLinus Torvalds MODULE_DESCRIPTION("Echo the kernel .config file used to build the kernel");
117*1da177e4SLinus Torvalds 
118*1da177e4SLinus Torvalds #endif /* CONFIG_IKCONFIG_PROC */
119