Back to home page

LXR

 
 

    


0001 /*
0002  * kernel/configs.c
0003  * Echo the kernel .config file used to build the kernel
0004  *
0005  * Copyright (C) 2002 Khalid Aziz <khalid_aziz@hp.com>
0006  * Copyright (C) 2002 Randy Dunlap <rdunlap@xenotime.net>
0007  * Copyright (C) 2002 Al Stone <ahs3@fc.hp.com>
0008  * Copyright (C) 2002 Hewlett-Packard Company
0009  *
0010  * This program is free software; you can redistribute it and/or modify
0011  * it under the terms of the GNU General Public License as published by
0012  * the Free Software Foundation; either version 2 of the License, or (at
0013  * your option) any later version.
0014  *
0015  * This program is distributed in the hope that it will be useful, but
0016  * WITHOUT ANY WARRANTY; without even the implied warranty of
0017  * MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE, GOOD TITLE or
0018  * NON INFRINGEMENT.  See the GNU General Public License for more
0019  * details.
0020  *
0021  * You should have received a copy of the GNU General Public License
0022  * along with this program; if not, write to the Free Software
0023  * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
0024  */
0025 
0026 #include <linux/kernel.h>
0027 #include <linux/module.h>
0028 #include <linux/proc_fs.h>
0029 #include <linux/seq_file.h>
0030 #include <linux/init.h>
0031 #include <linux/uaccess.h>
0032 
0033 /**************************************************/
0034 /* the actual current config file                 */
0035 
0036 /*
0037  * Define kernel_config_data and kernel_config_data_size, which contains the
0038  * wrapped and compressed configuration file.  The file is first compressed
0039  * with gzip and then bounded by two eight byte magic numbers to allow
0040  * extraction from a binary kernel image:
0041  *
0042  *   IKCFG_ST
0043  *   <image>
0044  *   IKCFG_ED
0045  */
0046 #define MAGIC_START "IKCFG_ST"
0047 #define MAGIC_END   "IKCFG_ED"
0048 #include "config_data.h"
0049 
0050 
0051 #define MAGIC_SIZE (sizeof(MAGIC_START) - 1)
0052 #define kernel_config_data_size \
0053     (sizeof(kernel_config_data) - 1 - MAGIC_SIZE * 2)
0054 
0055 #ifdef CONFIG_IKCONFIG_PROC
0056 
0057 static ssize_t
0058 ikconfig_read_current(struct file *file, char __user *buf,
0059               size_t len, loff_t * offset)
0060 {
0061     return simple_read_from_buffer(buf, len, offset,
0062                        kernel_config_data + MAGIC_SIZE,
0063                        kernel_config_data_size);
0064 }
0065 
0066 static const struct file_operations ikconfig_file_ops = {
0067     .owner = THIS_MODULE,
0068     .read = ikconfig_read_current,
0069     .llseek = default_llseek,
0070 };
0071 
0072 static int __init ikconfig_init(void)
0073 {
0074     struct proc_dir_entry *entry;
0075 
0076     /* create the current config file */
0077     entry = proc_create("config.gz", S_IFREG | S_IRUGO, NULL,
0078                 &ikconfig_file_ops);
0079     if (!entry)
0080         return -ENOMEM;
0081 
0082     proc_set_size(entry, kernel_config_data_size);
0083 
0084     return 0;
0085 }
0086 
0087 static void __exit ikconfig_cleanup(void)
0088 {
0089     remove_proc_entry("config.gz", NULL);
0090 }
0091 
0092 module_init(ikconfig_init);
0093 module_exit(ikconfig_cleanup);
0094 
0095 #endif /* CONFIG_IKCONFIG_PROC */
0096 
0097 MODULE_LICENSE("GPL");
0098 MODULE_AUTHOR("Randy Dunlap");
0099 MODULE_DESCRIPTION("Echo the kernel .config file used to build the kernel");