11da177e4SLinus Torvalds /* 21da177e4SLinus Torvalds * kernel/configs.c 31da177e4SLinus Torvalds * Echo the kernel .config file used to build the kernel 41da177e4SLinus Torvalds * 51da177e4SLinus Torvalds * Copyright (C) 2002 Khalid Aziz <khalid_aziz@hp.com> 6f4b09ebcSAdrian Bunk * Copyright (C) 2002 Randy Dunlap <rdunlap@xenotime.net> 71da177e4SLinus Torvalds * Copyright (C) 2002 Al Stone <ahs3@fc.hp.com> 81da177e4SLinus Torvalds * Copyright (C) 2002 Hewlett-Packard Company 91da177e4SLinus Torvalds * 101da177e4SLinus Torvalds * This program is free software; you can redistribute it and/or modify 111da177e4SLinus Torvalds * it under the terms of the GNU General Public License as published by 121da177e4SLinus Torvalds * the Free Software Foundation; either version 2 of the License, or (at 131da177e4SLinus Torvalds * your option) any later version. 141da177e4SLinus Torvalds * 151da177e4SLinus Torvalds * This program is distributed in the hope that it will be useful, but 161da177e4SLinus Torvalds * WITHOUT ANY WARRANTY; without even the implied warranty of 171da177e4SLinus Torvalds * MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE, GOOD TITLE or 181da177e4SLinus Torvalds * NON INFRINGEMENT. See the GNU General Public License for more 191da177e4SLinus Torvalds * details. 201da177e4SLinus Torvalds * 211da177e4SLinus Torvalds * You should have received a copy of the GNU General Public License 221da177e4SLinus Torvalds * along with this program; if not, write to the Free Software 231da177e4SLinus Torvalds * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. 241da177e4SLinus Torvalds */ 251da177e4SLinus Torvalds 261da177e4SLinus Torvalds #include <linux/kernel.h> 271da177e4SLinus Torvalds #include <linux/module.h> 281da177e4SLinus Torvalds #include <linux/proc_fs.h> 291da177e4SLinus Torvalds #include <linux/seq_file.h> 301da177e4SLinus Torvalds #include <linux/init.h> 311da177e4SLinus Torvalds #include <asm/uaccess.h> 321da177e4SLinus Torvalds 331da177e4SLinus Torvalds /**************************************************/ 341da177e4SLinus Torvalds /* the actual current config file */ 351da177e4SLinus Torvalds 361da177e4SLinus Torvalds /* 371da177e4SLinus Torvalds * Define kernel_config_data and kernel_config_data_size, which contains the 381da177e4SLinus Torvalds * wrapped and compressed configuration file. The file is first compressed 391da177e4SLinus Torvalds * with gzip and then bounded by two eight byte magic numbers to allow 401da177e4SLinus Torvalds * extraction from a binary kernel image: 411da177e4SLinus Torvalds * 421da177e4SLinus Torvalds * IKCFG_ST 431da177e4SLinus Torvalds * <image> 441da177e4SLinus Torvalds * IKCFG_ED 451da177e4SLinus Torvalds */ 461da177e4SLinus Torvalds #define MAGIC_START "IKCFG_ST" 471da177e4SLinus Torvalds #define MAGIC_END "IKCFG_ED" 481da177e4SLinus Torvalds #include "config_data.h" 491da177e4SLinus Torvalds 501da177e4SLinus Torvalds 511da177e4SLinus Torvalds #define MAGIC_SIZE (sizeof(MAGIC_START) - 1) 521da177e4SLinus Torvalds #define kernel_config_data_size \ 531da177e4SLinus Torvalds (sizeof(kernel_config_data) - 1 - MAGIC_SIZE * 2) 541da177e4SLinus Torvalds 551da177e4SLinus Torvalds #ifdef CONFIG_IKCONFIG_PROC 561da177e4SLinus Torvalds 571da177e4SLinus Torvalds /**************************************************/ 581da177e4SLinus Torvalds /* globals and useful constants */ 591da177e4SLinus Torvalds 601da177e4SLinus Torvalds static ssize_t 611da177e4SLinus Torvalds ikconfig_read_current(struct file *file, char __user *buf, 621da177e4SLinus Torvalds size_t len, loff_t * offset) 631da177e4SLinus Torvalds { 6485badbdfSAkinobu Mita return simple_read_from_buffer(buf, len, offset, 6585badbdfSAkinobu Mita kernel_config_data + MAGIC_SIZE, 6685badbdfSAkinobu Mita kernel_config_data_size); 671da177e4SLinus Torvalds } 681da177e4SLinus Torvalds 6915ad7cdcSHelge Deller static const struct file_operations ikconfig_file_ops = { 701da177e4SLinus Torvalds .owner = THIS_MODULE, 711da177e4SLinus Torvalds .read = ikconfig_read_current, 721da177e4SLinus Torvalds }; 731da177e4SLinus Torvalds 741da177e4SLinus Torvalds /***************************************************/ 751da177e4SLinus Torvalds /* ikconfig_init: start up everything we need to */ 761da177e4SLinus Torvalds 771da177e4SLinus Torvalds static int __init ikconfig_init(void) 781da177e4SLinus Torvalds { 791da177e4SLinus Torvalds struct proc_dir_entry *entry; 801da177e4SLinus Torvalds 811da177e4SLinus Torvalds /* create the current config file */ 82*c74c120aSAlexey Dobriyan entry = create_proc_entry("config.gz", S_IFREG | S_IRUGO, NULL); 831da177e4SLinus Torvalds if (!entry) 841da177e4SLinus Torvalds return -ENOMEM; 851da177e4SLinus Torvalds 861da177e4SLinus Torvalds entry->proc_fops = &ikconfig_file_ops; 871da177e4SLinus Torvalds entry->size = kernel_config_data_size; 881da177e4SLinus Torvalds 891da177e4SLinus Torvalds return 0; 901da177e4SLinus Torvalds } 911da177e4SLinus Torvalds 921da177e4SLinus Torvalds /***************************************************/ 931da177e4SLinus Torvalds /* ikconfig_cleanup: clean up our mess */ 941da177e4SLinus Torvalds 951da177e4SLinus Torvalds static void __exit ikconfig_cleanup(void) 961da177e4SLinus Torvalds { 97*c74c120aSAlexey Dobriyan remove_proc_entry("config.gz", NULL); 981da177e4SLinus Torvalds } 991da177e4SLinus Torvalds 1001da177e4SLinus Torvalds module_init(ikconfig_init); 1011da177e4SLinus Torvalds module_exit(ikconfig_cleanup); 1021da177e4SLinus Torvalds 1031da177e4SLinus Torvalds MODULE_LICENSE("GPL"); 1041da177e4SLinus Torvalds MODULE_AUTHOR("Randy Dunlap"); 1051da177e4SLinus Torvalds MODULE_DESCRIPTION("Echo the kernel .config file used to build the kernel"); 1061da177e4SLinus Torvalds 1071da177e4SLinus Torvalds #endif /* CONFIG_IKCONFIG_PROC */ 108