[PATCH] /proc/config.gz against 2.2.3

Oliver Xymoron (oxymoron@waste.org)
Sat, 13 Mar 1999 21:03:16 -0600 (CST)


On Sat, 13 Mar 1999, Alan Cox wrote:

> > 2. /proc/.config.gz
> > This is bad because a reader must decompress it himself. That is *every*
> > reader (unless he uses some shared library to do it transparently).
>
> This is very good because it keeps the kernel space small and the standard
> gzip tool can handle it as well as the standard zlib library.

So that we have something concrete to debate about, I've updated my patch
to apply to 2.2.3. I've even tested it. Woohoo.

Select yes for CONFIG_PROC_CONFIG and rebuild. Adds a cloneconfig build
target that unzips /proc/config.gz and does the equivalent of oldconfig.

Note this patch includes a program called bin2c in scripts/ that I think
should eventually replace the poorly named (and located) bin2hex scripts
in the sound driver directory.

And there's a special bonus feature! This patch also includes an updated
version of my little "patch names" Makefile hack. When you build the
kernel, it looks for files of the form patchdesc.foo and the resulting
kernel will report itself as 2.2.x+foo. So, for instance, Alan could
distribute his -ac series with files like patchdesc.ac2 and the resulting
kernel would be easily distinguishable from the standard Linux kernel both
at boot time and when using uname. Also extremely useful is that it puts
modules in 2.2.x+foo as well so you can have a standard kernel and several
patched kernels co-exist comfortably on the same machine. The patchdesc
files also provide a convenient place to put changelog info,
documentation, credits, etc. The current patch will build as
2.2.x+names+cfg.

The only objection I've gotten to this so far is from Ingo, who claimed it
would encourage forking. Any others?

diff -r -N -u linux-2.2.3/Documentation/Configure.help linux/Documentation/Configure.help
--- linux-2.2.3/Documentation/Configure.help Mon Mar 8 12:14:35 1999
+++ linux/Documentation/Configure.help Sat Mar 13 19:41:51 1999
@@ -6931,6 +6931,14 @@
This option will enlarge your kernel by about 18 KB. Several
programs depend on this, so everyone should say Y here.

+/proc/config.gz support
+CONFIG_PROC_CONFIG
+ Say Y here if you want a copy of your current kernel configuration
+ saved in the kernel that you build. This is extremely useful if you
+ ever build more than one kernel. The cost is around 1K-4K of running
+ memory. Only say no if you really can't spare this. You can sneeze
+ and lose more on memory than this.
+
NFS filesystem support
CONFIG_NFS_FS
If you are connected to some other (usually local) Unix computer
diff -r -N -u linux-2.2.3/Makefile linux/Makefile
--- linux-2.2.3/Makefile Wed Feb 24 18:30:59 1999
+++ linux/Makefile Sat Mar 13 20:24:06 1999
@@ -1,7 +1,7 @@
VERSION = 2
PATCHLEVEL = 2
SUBLEVEL = 3
-EXTRAVERSION =
+EXTRAVERSION =

ARCH := $(shell uname -m | sed -e s/i.86/i386/ -e s/sun4u/sparc64/ -e s/arm.*/arm/ -e s/sa110/arm/)

@@ -59,7 +59,10 @@

ROOT_DEV = CURRENT

-KERNELRELEASE=$(VERSION).$(PATCHLEVEL).$(SUBLEVEL)$(EXTRAVERSION)
+PATCHES=$(shell find -maxdepth 1 -name 'patchdesc.*[^~]' \
+ -printf '+%f' | sed -e 's/+patchdesc\./+/g')
+
+KERNELRELEASE=$(VERSION).$(PATCHLEVEL).$(SUBLEVEL)$(EXTRAVERSION)$(PATCHES)

#
# INSTALL_PATH specifies where to place the updated kernel and system map
@@ -239,6 +242,18 @@
scripts/split-include include/linux/autoconf.h include/config
@ touch include/config/MARKER

+cloneconfig: symlinks scripts/split-include
+ @if [ -f "/proc/config.gz" ]; then \
+ mv -f .config .config.bak; \
+ gzip -d < /proc/config.gz > .config; \
+ if [ -r include/linux/autoconf.h ]; then \
+ scripts/split-include include/linux/autoconf.h include/config; \
+ fi; \
+ else \
+ echo "Your current kernel does not support cloning."; \
+ fi
+ $(CONFIG_SHELL) scripts/Configure -d arch/$(ARCH)/config.in
+
linuxsubdirs: $(patsubst %, _dir_%, $(SUBDIRS))

$(patsubst %, _dir_%, $(SUBDIRS)) : dummy include/config/MARKER
@@ -272,13 +287,17 @@
@echo \#define LINUX_COMPILER \"`$(CC) $(CFLAGS) -v 2>&1 | tail -1`\" >> .ver
@mv -f .ver $@

+include/linux/config_data.h: newversion scripts/bin2c
+ gzip -9 < .config | scripts/bin2c kernel_config_data > $@
+
include/linux/version.h: ./Makefile
@echo \#define UTS_RELEASE \"$(KERNELRELEASE)\" > .ver
@echo \#define LINUX_VERSION_CODE `expr $(VERSION) \\* 65536 + $(PATCHLEVEL) \\* 256 + $(SUBLEVEL)` >> .ver
@echo '#define KERNEL_VERSION(a,b,c) (((a) << 16) + ((b) << 8) + (c))' >>.ver
@mv -f .ver $@

-init/version.o: init/version.c include/linux/compile.h include/config/MARKER
+init/version.o: init/version.c include/linux/compile.h include/config/MARKER\
+ include/linux/config_data.h
$(CC) $(CFLAGS) -DUTS_MACHINE='"$(ARCH)"' -c -o init/version.o init/version.c

init/main.o: init/main.c include/config/MARKER
@@ -346,7 +365,7 @@
rm -f core `find . -name '*.[oas]' ! -regex '.*lxdialog/.*' -print`
rm -f core `find . -type f -name 'core' -print`
rm -f core `find . -name '.*.flags' -print`
- rm -f vmlinux System.map
+ rm -f vmlinux System.map include/linux/config_data.h
rm -f .tmp*
rm -f drivers/char/consolemap_deftbl.c drivers/video/promcon_tbl.c
rm -f drivers/char/conmakehash
@@ -372,7 +391,7 @@
rm -rf include/config
rm -f .depend `find . -name .depend -print`
rm -f core `find . -size 0 -print`
- rm -f .hdepend scripts/mkdep scripts/split-include
+ rm -f .hdepend scripts/mkdep scripts/split-include scripts/bin2c
rm -f $(TOPDIR)/include/linux/modversions.h
rm -rf $(TOPDIR)/include/linux/modules
rm -rf modules
@@ -442,3 +461,6 @@

scripts/split-include: scripts/split-include.c
$(HOSTCC) $(HOSTCFLAGS) -o scripts/split-include scripts/split-include.c
+
+scripts/bin2c: scripts/bin2c.c
+ $(HOSTCC) $(HOSTCFLAGS) -o scripts/bin2c scripts/bin2c.c
diff -r -N -u linux-2.2.3/fs/Config.in linux/fs/Config.in
--- linux-2.2.3/fs/Config.in Sun Mar 7 17:25:23 1999
+++ linux/fs/Config.in Sat Mar 13 19:41:51 1999
@@ -34,6 +34,9 @@
fi
tristate 'OS/2 HPFS filesystem support (read only)' CONFIG_HPFS_FS
bool '/proc filesystem support' CONFIG_PROC_FS
+if [ "$CONFIG_PROC_FS" = "y" ] ; then
+ bool ' /proc/config.gz (kernel configuration)' CONFIG_PROC_CONFIG
+fi
if [ "$CONFIG_UNIX98_PTYS" = "y" ]; then
# It compiles as a module for testing only. It should not be used
# as a module in general. If we make this "tristate", a bunch of people
diff -r -N -u linux-2.2.3/fs/proc/array.c linux/fs/proc/array.c
--- linux-2.2.3/fs/proc/array.c Mon Mar 8 13:07:29 1999
+++ linux/fs/proc/array.c Sat Mar 13 19:41:51 1999
@@ -379,6 +379,17 @@
return strlen(buffer);
}

+#ifdef CONFIG_PROC_CONFIG
+static int get_proc_config(char *buffer)
+{
+ extern char *kernel_config_data;
+ extern int kernel_config_data_size;
+
+ memcpy(buffer, kernel_config_data, kernel_config_data_size);
+ return kernel_config_data_size;
+}
+#endif
+
static int get_cmdline(char * buffer)
{
extern char saved_command_line[];
@@ -1335,6 +1346,11 @@
case PROC_STRAM:
return get_stram_list(page);
#endif
+#ifdef CONFIG_PROC_CONFIG
+ case PROC_CONFIG:
+ return get_proc_config(page);
+#endif
+
}
return -EBADF;
}
diff -r -N -u linux-2.2.3/fs/proc/root.c linux/fs/proc/root.c
--- linux-2.2.3/fs/proc/root.c Fri Jan 15 17:38:59 1999
+++ linux/fs/proc/root.c Sat Mar 13 19:41:51 1999
@@ -668,6 +668,13 @@
NULL, NULL /* parent, subdir */
};
#endif
+#ifdef CONFIG_PROC_CONFIG
+static struct proc_dir_entry proc_root_config = {
+ PROC_CONFIG, 9, "config.gz",
+ S_IFREG | S_IRUGO, 1, 0, 0,
+ 0, &proc_array_inode_operations
+};
+#endif

__initfunc(void proc_root_init(void))
{
@@ -741,7 +748,9 @@
#ifdef CONFIG_PROC_DEVICETREE
proc_device_tree_init();
#endif
-
+#ifdef CONFIG_PROC_CONFIG
+ proc_register(&proc_root, &proc_root_config);
+#endif
proc_bus = create_proc_entry("bus", S_IFDIR, 0);
}

diff -r -N -u linux-2.2.3/include/linux/proc_fs.h linux/include/linux/proc_fs.h
--- linux-2.2.3/include/linux/proc_fs.h Mon Mar 8 17:51:59 1999
+++ linux/include/linux/proc_fs.h Sat Mar 13 19:52:47 1999
@@ -52,6 +52,7 @@
PROC_STRAM,
PROC_SOUND,
PROC_MTRR, /* whether enabled or not */
+ PROC_CONFIG, /* whether enabled or not */
PROC_FS
};

diff -r -N -u linux-2.2.3/init/version.c linux/init/version.c
--- linux-2.2.3/init/version.c Mon Jan 5 03:41:01 1998
+++ linux/init/version.c Sat Mar 13 19:41:51 1999
@@ -6,10 +6,14 @@
* May be freely distributed as part of Linux.
*/

+#include <linux/config.h>
#include <linux/uts.h>
#include <linux/utsname.h>
#include <linux/version.h>
#include <linux/compile.h>
+#ifdef CONFIG_PROC_CONFIG
+#include <linux/config_data.h>
+#endif

#define version(a) Version_ ## a
#define version_string(a) version(a)
diff -r -N -u linux-2.2.3/patchdesc.cfg linux/patchdesc.cfg
--- linux-2.2.3/patchdesc.cfg Wed Dec 31 18:00:00 1969
+++ linux/patchdesc.cfg Sat Mar 13 19:41:51 1999
@@ -0,0 +1,7 @@
+This patch adds /proc/config.gz and make cloneconfig
+
+Oliver Xymoron <oxymoron@waste.org> Jan 15 1999
+
+Derived from a patch by Nicholas Leon <nicholas@binary9.net> with
+suggestions from Michael Chastain <mec@shout.net> and Peter T. Breuer
+<ptb@it.uc3m.es>
diff -r -N -u linux-2.2.3/patchdesc.names linux/patchdesc.names
--- linux-2.2.3/patchdesc.names Wed Dec 31 18:00:00 1969
+++ linux/patchdesc.names Sat Mar 13 19:41:35 1999
@@ -0,0 +1,7 @@
+This patch adds a simple method to identify patched kernels. Patches
+that include a file named 'patchdesc.*' in the top level source
+directory will cause the kernel to add the file extension to the
+version that is reported by uname(1). For instance, this file will
+result in the 2.x.x+name being reported.
+
+oxymoron@waste.org Jan 12 1999
diff -r -N -u linux-2.2.3/scripts/bin2c.c linux/scripts/bin2c.c
--- linux-2.2.3/scripts/bin2c.c Wed Dec 31 18:00:00 1969
+++ linux/scripts/bin2c.c Sat Mar 13 19:41:51 1999
@@ -0,0 +1,23 @@
+#include <stdio.h>
+
+int main(int argc, char *argv[])
+{
+ int ch,total=0;
+
+ if(argc>1) printf("const char *%s %s=\n",argv[1],argc>2?argv[2]:"");
+
+ do {
+ printf("\t\"");
+ while((ch=getchar())!=EOF)
+ {
+ total++;
+ printf("\\x%02x",ch);
+ if(total%16==0) break;
+ }
+ printf("\"\n");
+ } while(ch!=EOF);
+
+ if(argc>1) printf("\t;\n\nconst int %s_size = %d;\n",argv[1],total);
+
+ return 0;
+}

--
 "Love the dolphins," she advised him. "Write by W.A.S.T.E.." 

- To unsubscribe from this list: send the line "unsubscribe linux-kernel" in the body of a message to majordomo@vger.rutgers.edu Please read the FAQ at http://www.tux.org/lkml/