diff options
author | Pascal Rigaux <pixel@mandriva.com> | 2007-04-25 12:26:16 +0000 |
---|---|---|
committer | Pascal Rigaux <pixel@mandriva.com> | 2007-04-25 12:26:16 +0000 |
commit | 126777bc019a54afb4ec51299f2cf9d2841698aa (patch) | |
tree | 97f76e571902ead55ba138f1156a4b4f00b9b779 /mdk-stage1 | |
parent | f1f67448efc714873378dfeb8279fae68054a90a (diff) | |
download | drakx-backup-do-not-use-126777bc019a54afb4ec51299f2cf9d2841698aa.tar drakx-backup-do-not-use-126777bc019a54afb4ec51299f2cf9d2841698aa.tar.gz drakx-backup-do-not-use-126777bc019a54afb4ec51299f2cf9d2841698aa.tar.bz2 drakx-backup-do-not-use-126777bc019a54afb4ec51299f2cf9d2841698aa.tar.xz drakx-backup-do-not-use-126777bc019a54afb4ec51299f2cf9d2841698aa.zip |
re-sync after the big svn loss
Diffstat (limited to 'mdk-stage1')
168 files changed, 1336 insertions, 32460 deletions
diff --git a/mdk-stage1/.cvsignore b/mdk-stage1/.cvsignore deleted file mode 100644 index 28f91e89f..000000000 --- a/mdk-stage1/.cvsignore +++ /dev/null @@ -1,15 +0,0 @@ -init -init-stage2 -stage1-full -stage1-cdrom -stage1-disk -stage1-medias-usb -stage1-network -stage1-network-usb -debug.log -.depend -*.rdz* -mkinitrd_helper.tar.bz2 -hack_* -rescue-gui -dhcp-client diff --git a/mdk-stage1/Makefile b/mdk-stage1/Makefile index 04fe357ff..eebeb3e7a 100644 --- a/mdk-stage1/Makefile +++ b/mdk-stage1/Makefile @@ -14,6 +14,10 @@ # You should have received a copy of the GNU General Public License # along with this program; if not, write to the Free Software # Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. + +VERSION=1.7 +PRODUCT=drakx-installer-binaries + # # Portions from Erik Troan (ewt@redhat.com) Copyright 1996 Red Hat Software # @@ -44,21 +48,20 @@ top_dir = . include $(top_dir)/Makefile.common include $(top_dir)/../Makefile.config +ARCHDIR=$(ARCH) +ifeq (i386, $(ARCH)) +ARCHDIR=i586 +endif - -DEFS = -DDISTRIB_NAME=\"$(DISTRIB_NAME)\" -DDISTRIB_VERSION=\"$(DISTRIB_VERSION)\" -DDISTRIB_DESCR=\"$(DISTRIB_DESCR)\" $(ADDITIONAL_DEFS) -D_FILE_OFFSET_BITS=64 +DEFS = -DDISTRIB_NAME=\"$(DISTRIB_NAME)\" -DDISTRIB_VERSION=\"$(DISTRIB_VERSION)\" -DDISTRIB_DESCR=\"$(DISTRIB_DESCR)\" $(ADDITIONAL_DEFS) -D_FILE_OFFSET_BITS=64 -DARCH=\"$(ARCHDIR)\" -DCONFIG_USE_ZLIB COMPILE = $(CC) $(DEFS) $(CFLAGS) -ifeq (ppc, $(ARCH)) -INIT_HEADERS=init-libc-headers.h -else ifeq (DIETLIBC, $(L)) INIT_HEADERS=minilibc.h else INIT_HEADERS=init-libc-headers.h endif -endif INIT_DEFS = -DINIT_HEADERS=\"$(INIT_HEADERS)\" @@ -70,15 +73,7 @@ INITSRC = init.c INIT_DEFS += $(GLIBC_INCLUDES) endif -INIT_DEFS_ADD = -DBINARY=\"/sbin/stage1\" -ifdef MOVE -INIT_DEFS_ADD_STAGE2 = -DBINARY=\"/usr/bin/runstage2.pl\" -else -INIT_DEFS_ADD_STAGE2 = -DBINARY=\"/usr/bin/runinstall2\" -endif - INITOBJS = $(subst .c,.o,$(INITSRC)) -INITOBJS-STAGE2 = $(subst .c,-STAGE2.o,$(INITSRC)) #- frontends @@ -94,14 +89,13 @@ FRONTEND_OBJS = $(subst .c,.o,$($(F)_FRONTEND_SRC)) FRONTEND_LINK = $(FRONTEND_OBJS) $($(F)_FRONTEND_LIBS) +STAGE1_OWN_LIBS = ifeq (DIETLIBC, $(L)) -INSMOD = insmod-busybox +STAGE1_OWN_LIBS = /usr/$(LIB)/libz-diet.a else -INSMOD = insmod-modutils +STAGE1_OWN_LIBS = /usr/$(LIB)/libz.a endif -STAGE1_OWN_LIBS = $(INSMOD)/libinsmod.a mar/libmar.a bzlib/libbzlib.a - ifeq (DIETLIBC, $(L)) STAGE1_NETWORK_LIBS = /usr/lib/dietlibc/lib-$(ARCH)/librpc.a @@ -110,7 +104,7 @@ STAGE1_NETWORK_LIBS = /usr/$(LIB)/libresolv.a endif #- stage1 itself -STAGE1SRC = stage1.c log.c tools.c modules.c probing.c mount.c automatic.c frontend-common.c lomount.c thirdparty.c +STAGE1SRC = stage1.c log.c tools.c modules.c probing.c mount.c automatic.c frontend-common.c lomount.c thirdparty.c zlibsupport.c CDROMSRC = cdrom.c DISKSRC = disk.c directory.c partition.c NETWORKSRC = network.c nfsmount.c dhcp.c url.c dns.c adsl.c directory.c wireless.c @@ -122,8 +116,6 @@ ALLSRC = $(INITSRC) $(STAGE1_ALLSRC) -STAGE1OBJS-CDROM = $(subst .c,-CDROM.o,$(STAGE1SRC) $(CDROMSRC)) - CDROM_DEFS = -DSPAWN_SHELL -DDISABLE_DISK -DDISABLE_NETWORK @@ -139,32 +131,23 @@ NETWORK_STANDALONE_DEFS = -DDISABLE_CDROM -DDISABLE_DISK -DENABLE_NETWORK_STANDA STAGE1OBJS-FULL = $(subst .c,-FULL.o,$(STAGE1_ALLSRC)) -BINS = init init-stage2 stage1-full dhcp-client +BINS = init stage1 dhcp-client rescue-gui -ifndef MOVE +DIRS += pci-resource pcmcia-resource usb-resource slang newt ppp/pppd rp-pppoe/src ifeq (i386, $(ARCH)) -BINS += stage1-cdrom stage1-network +DIRS += pcmcia sysfs endif ifeq (x86_64, $(ARCH)) -BINS += stage1-cdrom stage1-network -endif -endif - -DIRS += mar pci-resource usb-resource bzlib $(INSMOD) slang newt ppp/pppd rp-pppoe/src -ifeq (i386, $(ARCH)) -DIRS += pcmcia_ -endif -ifeq (x86_64, $(ARCH)) -DIRS += pcmcia_ +DIRS += pcmcia sysfs endif ifeq (i386,$(ARCH)) -PCMCIA_LIB = pcmcia_/libpcmcia.a +PCMCIA_LIB = pcmcia/libpcmcia.a sysfs/libsysfs.a PCMCIA_DEFS = -DENABLE_PCMCIA endif ifeq (x86_64,$(ARCH)) -PCMCIA_LIB = pcmcia_/libpcmcia.a +PCMCIA_LIB = pcmcia/libpcmcia.a sysfs/libsysfs.a PCMCIA_DEFS = -DENABLE_PCMCIA endif @@ -183,19 +166,7 @@ init: $(INITOBJS) $(DIET) $(CC) $(LDFLAGS) -o $@ $^ $(STRIPCMD) $@ -init-stage2: $(INITOBJS-STAGE2) - $(DIET) $(CC) $(LDFLAGS) -o $@ $^ - $(STRIPCMD) $@ - -stage1-cdrom: $(STAGE1OBJS-CDROM) $(STAGE1_OWN_LIBS) $(FRONTEND_LINK) $(STAGE1_LIBC) - $(DIET) $(CC) $(LDFLAGS) -o $@ $^ - $(STRIPCMD) $@ - -stage1-network: $(STAGE1OBJS-NETWORK) $(STAGE1_OWN_LIBS) $(STAGE1_NETWORK_LIBS) $(FRONTEND_LINK) $(PCMCIA_LIB) $(STAGE1_LIBC) - $(DIET) $(CC) $(LDFLAGS) -o $@ $^ - $(STRIPCMD) $@ - -stage1-full: $(STAGE1OBJS-FULL) $(STAGE1_OWN_LIBS) $(STAGE1_NETWORK_LIBS) $(FRONTEND_LINK) bootsplash.o $(PCMCIA_LIB) $(STAGE1_LIBC) +stage1: $(STAGE1OBJS-FULL) $(STAGE1_OWN_LIBS) $(STAGE1_NETWORK_LIBS) $(FRONTEND_LINK) bootsplash.o $(PCMCIA_LIB) $(STAGE1_LIBC) $(DIET) $(CC) $(LDFLAGS) -o $@ $^ $(STRIPCMD) $@ @@ -205,13 +176,7 @@ dhcp-client: $(STAGE1OBJS-NETWORK-STANDALONE) $(STAGE1_OWN_LIBS) $(STAGE1_NETWOR $(INITOBJS): %.o: %.c - $(COMPILE) $(INIT_DEFS) $(INIT_DEFS_ADD) -c $< - -$(INITOBJS-STAGE2): %-STAGE2.o: %.c - $(COMPILE) $(INIT_DEFS) $(INIT_DEFS_ADD_STAGE2) -c $< -o $@ - -$(STAGE1OBJS-CDROM): %-CDROM.o: %.c - $(DIET) $(COMPILE) $(INCLUDES) $(CDROM_DEFS) -c $< -o $@ + $(COMPILE) $(INIT_DEFS) -c $< $(STAGE1OBJS-NETWORK): %-NETWORK.o: %.c $(DIET) $(COMPILE) $(INCLUDES) $(NETWORK_DEFS) $(PCMCIA_DEFS) $(USB_DEFS_GEN) -DENABLE_ADDITIONAL_MODULES -c $< -o $@ @@ -232,22 +197,23 @@ clean: localclean done localclean: - rm -f *.o .depend *.rdz *.img rescue-gui init-move $(BINS) - + rm -f *.o .depend *.rdz *.img $(BINS) -tar-mkinitrd_helper: clean - rm -rf mkinitrd_helper-subdir - mkdir mkinitrd_helper-subdir - cd mkinitrd_helper-subdir ; cp -a ../insmod-busybox ../Makefile.common ../insmod.h ../log.h . ; \ - cp ../Makefile.mkinitrd_helper Makefile - tar cfj mkinitrd_helper.tar.bz2 mkinitrd_helper-subdir --exclude CVS - rm -rf mkinitrd_helper-subdir rescue-gui: rescue-gui.o frontend-common.o $(FRONTEND_LINK) $(STAGE1_LIBC) $(DIET) $(CC) $(LDFLAGS) -o $@ $^ $(STRIPCMD) $@ +tar: + rm -rf $(PRODUCT)*.tar* $(PRODUCT)-$(VERSION) + mkdir -p $(PRODUCT)-$(VERSION) + svn export -q . $(PRODUCT)-$(VERSION)/mdk-stage1 + svn export -q ../kernel $(PRODUCT)-$(VERSION)/kernel + cp ../Makefile.config $(PRODUCT)-$(VERSION)/ + tar cfj $(PRODUCT)-$(VERSION).tar.bz2 $(PRODUCT)-$(VERSION) + rm -rf $(PRODUCT)-$(VERSION) + .depend: $(CPP) $(CFLAGS) -M $(ALLSRC) > .depend @@ -256,8 +222,6 @@ include .depend endif -*-CDROM.o: %-CDROM.o: %.o - *-NETWORK.o: %-NETWORK.o: %.o *-FULL.o: %-FULL.o: %.o diff --git a/mdk-stage1/Makefile.common b/mdk-stage1/Makefile.common index ce8aab84c..b668fab27 100644 --- a/mdk-stage1/Makefile.common +++ b/mdk-stage1/Makefile.common @@ -17,32 +17,30 @@ ARCH := $(patsubst i%86,i386,$(shell uname -m)) ARCH := $(patsubst sparc%,sparc,$(ARCH)) - #- default lib is dietlibc (honoured by main Makefile whenever possible) -L = DIETLIBC -#L = GLIBC - #- default frontend is newt (honoured by main Makefile whenever possible) F = NEWT # F = STDIO - #- override in some situations -ifeq (ia64, $(ARCH)) -L = GLIBC -endif +DIET = $(shell test -x /usr/bin/diet && echo diet) -ifeq (DIETLIBC, $(L)) -DIET = diet +ifeq ($(DIET), diet) + #- default lib is dietlibc (honoured by main Makefile whenever possible) +L = DIETLIBC +else +L = GLIBC endif #- flags used by all stuff CFLAGS = -Os -pipe -Wall -fomit-frame-pointer -fno-strict-aliasing ifneq (ppc, $(ARCH)) +ifneq (sparc, $(ARCH)) CFLAGS += -Werror endif +endif -DIETLIBC_INCLUDES = -I/usr/lib/dietlibc/include -I. -I$(top_dir)/bzlib -GLIBC_INCLUDES = -I. -I$(top_dir)/bzlib +DIETLIBC_INCLUDES = -I/usr/lib/dietlibc/include -I. +GLIBC_INCLUDES = -I. INCLUDES = $($(L)_INCLUDES) GLIBC_LDFLAGS = -static diff --git a/mdk-stage1/NEWS b/mdk-stage1/NEWS new file mode 100644 index 000000000..1c181f032 --- /dev/null +++ b/mdk-stage1/NEWS @@ -0,0 +1,10 @@ +1.7: +- don't kill our init/klogd when running stage2 + (bug introduced when switching to initramfs) + +1.6: +- write DNS settings in temporary ifcfg file + (fixes resolv.conf post install) + +1.5: +- fix infinite loop in wired interface mode diff --git a/mdk-stage1/bzlib/Makefile b/mdk-stage1/bzlib/Makefile deleted file mode 100644 index 929164253..000000000 --- a/mdk-stage1/bzlib/Makefile +++ /dev/null @@ -1,42 +0,0 @@ - #****************************************************************************** - # - # Guillaume Cottenceau (gc@mandrakesoft.com) - # - # Copyright 2000 Mandrakesoft - # - # This software may be freely redistributed under the terms of the GNU - # public license. - # - # You should have received a copy of the GNU General Public License - # along with this program; if not, write to the Free Software - # Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. - # - #***************************************************************************** - -top_dir = .. - -include $(top_dir)/Makefile.common - - -LIBNAME = libbzlib - -OBJS = blocksort.o bzlib.o compress.o crctable.o decompress.o huffman.o randtable.o - -DEFS = - -INCS = - - -TARGETS = $(LIBNAME).a - -all: $(TARGETS) - -clean: - rm -f *.o *.a - -$(LIBNAME).a: $(OBJS) - ar -cru $@ $^ - ranlib $@ - -$(OBJS): %.o: %.c - $(DIET) $(CC) $(CFLAGS) $(DEFS) $(INCS) $(INCLUDES) -c $< -o $@ diff --git a/mdk-stage1/bzlib/blocksort.c b/mdk-stage1/bzlib/blocksort.c deleted file mode 100644 index c1b78c483..000000000 --- a/mdk-stage1/bzlib/blocksort.c +++ /dev/null @@ -1,1138 +0,0 @@ - -/*-------------------------------------------------------------*/ -/*--- Block sorting machinery ---*/ -/*--- blocksort.c ---*/ -/*-------------------------------------------------------------*/ - -/*-- - This file is a part of bzip2 and/or libbzip2, a program and - library for lossless, block-sorting data compression. - - Copyright (C) 1996-2000 Julian R Seward. All rights reserved. - - Redistribution and use in source and binary forms, with or without - modification, are permitted provided that the following conditions - are met: - - 1. Redistributions of source code must retain the above copyright - notice, this list of conditions and the following disclaimer. - - 2. The origin of this software must not be misrepresented; you must - not claim that you wrote the original software. If you use this - software in a product, an acknowledgment in the product - documentation would be appreciated but is not required. - - 3. Altered source versions must be plainly marked as such, and must - not be misrepresented as being the original software. - - 4. The name of the author may not be used to endorse or promote - products derived from this software without specific prior written - permission. - - THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS - OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED - WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY - DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE - GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS - INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, - WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING - NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS - SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - - Julian Seward, Cambridge, UK. - jseward@acm.org - bzip2/libbzip2 version 1.0 of 21 March 2000 - - This program is based on (at least) the work of: - Mike Burrows - David Wheeler - Peter Fenwick - Alistair Moffat - Radford Neal - Ian H. Witten - Robert Sedgewick - Jon L. Bentley - - For more information on these sources, see the manual. - - To get some idea how the block sorting algorithms in this file - work, read my paper - On the Performance of BWT Sorting Algorithms - in Proceedings of the IEEE Data Compression Conference 2000, - Snowbird, Utah, USA, 27-30 March 2000. The main sort in this - file implements the algorithm called cache in the paper. ---*/ - -#ifdef HAVE_CONFIG_H -#include <config.h> -#endif - - -#include "bzlib_private.h" - -/*---------------------------------------------*/ -/*--- Fallback O(N log(N)^2) sorting ---*/ -/*--- algorithm, for repetitive blocks ---*/ -/*---------------------------------------------*/ - -/*---------------------------------------------*/ -static -__inline__ -void fallbackSimpleSort ( UInt32* fmap, - UInt32* eclass, - Int32 lo, - Int32 hi ) -{ - Int32 i, j, tmp; - UInt32 ec_tmp; - - if (lo == hi) return; - - if (hi - lo > 3) { - for ( i = hi-4; i >= lo; i-- ) { - tmp = fmap[i]; - ec_tmp = eclass[tmp]; - for ( j = i+4; j <= hi && ec_tmp > eclass[fmap[j]]; j += 4 ) - fmap[j-4] = fmap[j]; - fmap[j-4] = tmp; - } - } - - for ( i = hi-1; i >= lo; i-- ) { - tmp = fmap[i]; - ec_tmp = eclass[tmp]; - for ( j = i+1; j <= hi && ec_tmp > eclass[fmap[j]]; j++ ) - fmap[j-1] = fmap[j]; - fmap[j-1] = tmp; - } -} - - -/*---------------------------------------------*/ -#define fswap(zz1, zz2) \ - { Int32 zztmp = zz1; zz1 = zz2; zz2 = zztmp; } - -#define fvswap(zzp1, zzp2, zzn) \ -{ \ - Int32 yyp1 = (zzp1); \ - Int32 yyp2 = (zzp2); \ - Int32 yyn = (zzn); \ - while (yyn > 0) { \ - fswap(fmap[yyp1], fmap[yyp2]); \ - yyp1++; yyp2++; yyn--; \ - } \ -} - - -#define fmin(a,b) ((a) < (b)) ? (a) : (b) - -#define fpush(lz,hz) { stackLo[sp] = lz; \ - stackHi[sp] = hz; \ - sp++; } - -#define fpop(lz,hz) { sp--; \ - lz = stackLo[sp]; \ - hz = stackHi[sp]; } - -#define FALLBACK_QSORT_SMALL_THRESH 10 -#define FALLBACK_QSORT_STACK_SIZE 100 - - -static -void fallbackQSort3 ( UInt32* fmap, - UInt32* eclass, - Int32 loSt, - Int32 hiSt ) -{ - Int32 unLo, unHi, ltLo, gtHi, n, m; - Int32 sp, lo, hi; - UInt32 med, r, r3; - Int32 stackLo[FALLBACK_QSORT_STACK_SIZE]; - Int32 stackHi[FALLBACK_QSORT_STACK_SIZE]; - - r = 0; - - sp = 0; - fpush ( loSt, hiSt ); - - while (sp > 0) { - - AssertH ( sp < FALLBACK_QSORT_STACK_SIZE, 1004 ); - - fpop ( lo, hi ); - if (hi - lo < FALLBACK_QSORT_SMALL_THRESH) { - fallbackSimpleSort ( fmap, eclass, lo, hi ); - continue; - } - - /* Random partitioning. Median of 3 sometimes fails to - avoid bad cases. Median of 9 seems to help but - looks rather expensive. This too seems to work but - is cheaper. Guidance for the magic constants - 7621 and 32768 is taken from Sedgewick's algorithms - book, chapter 35. - */ - r = ((r * 7621) + 1) % 32768; - r3 = r % 3; - if (r3 == 0) med = eclass[fmap[lo]]; else - if (r3 == 1) med = eclass[fmap[(lo+hi)>>1]]; else - med = eclass[fmap[hi]]; - - unLo = ltLo = lo; - unHi = gtHi = hi; - - while (1) { - while (1) { - if (unLo > unHi) break; - n = (Int32)eclass[fmap[unLo]] - (Int32)med; - if (n == 0) { - fswap(fmap[unLo], fmap[ltLo]); - ltLo++; unLo++; - continue; - }; - if (n > 0) break; - unLo++; - } - while (1) { - if (unLo > unHi) break; - n = (Int32)eclass[fmap[unHi]] - (Int32)med; - if (n == 0) { - fswap(fmap[unHi], fmap[gtHi]); - gtHi--; unHi--; - continue; - }; - if (n < 0) break; - unHi--; - } - if (unLo > unHi) break; - fswap(fmap[unLo], fmap[unHi]); unLo++; unHi--; - } - - AssertD ( unHi == unLo-1, "fallbackQSort3(2)" ); - - if (gtHi < ltLo) continue; - - n = fmin(ltLo-lo, unLo-ltLo); fvswap(lo, unLo-n, n); - m = fmin(hi-gtHi, gtHi-unHi); fvswap(unLo, hi-m+1, m); - - n = lo + unLo - ltLo - 1; - m = hi - (gtHi - unHi) + 1; - - if (n - lo > hi - m) { - fpush ( lo, n ); - fpush ( m, hi ); - } else { - fpush ( m, hi ); - fpush ( lo, n ); - } - } -} - -#undef fmin -#undef fpush -#undef fpop -#undef fswap -#undef fvswap -#undef FALLBACK_QSORT_SMALL_THRESH -#undef FALLBACK_QSORT_STACK_SIZE - - -/*---------------------------------------------*/ -/* Pre: - nblock > 0 - eclass exists for [0 .. nblock-1] - ((UChar*)eclass) [0 .. nblock-1] holds block - ptr exists for [0 .. nblock-1] - - Post: - ((UChar*)eclass) [0 .. nblock-1] holds block - All other areas of eclass destroyed - fmap [0 .. nblock-1] holds sorted order - bhtab [ 0 .. 2+(nblock/32) ] destroyed -*/ - -#define SET_BH(zz) bhtab[(zz) >> 5] |= (1 << ((zz) & 31)) -#define CLEAR_BH(zz) bhtab[(zz) >> 5] &= ~(1 << ((zz) & 31)) -#define ISSET_BH(zz) (bhtab[(zz) >> 5] & (1 << ((zz) & 31))) -#define WORD_BH(zz) bhtab[(zz) >> 5] -#define UNALIGNED_BH(zz) ((zz) & 0x01f) - -static -void fallbackSort ( UInt32* fmap, - UInt32* eclass, - UInt32* bhtab, - Int32 nblock, - Int32 verb ) -{ - Int32 ftab[257]; - Int32 ftabCopy[256]; - Int32 H, i, j, k, l, r, cc, cc1; - Int32 nNotDone; - Int32 nBhtab; - UChar* eclass8 = (UChar*)eclass; - - /*-- - Initial 1-char radix sort to generate - initial fmap and initial BH bits. - --*/ - if (verb >= 4) - VPrintf0 ( " bucket sorting ...\n" ); - for (i = 0; i < 257; i++) ftab[i] = 0; - for (i = 0; i < nblock; i++) ftab[eclass8[i]]++; - for (i = 0; i < 256; i++) ftabCopy[i] = ftab[i]; - for (i = 1; i < 257; i++) ftab[i] += ftab[i-1]; - - for (i = 0; i < nblock; i++) { - j = eclass8[i]; - k = ftab[j] - 1; - ftab[j] = k; - fmap[k] = i; - } - - nBhtab = 2 + (nblock / 32); - for (i = 0; i < nBhtab; i++) bhtab[i] = 0; - for (i = 0; i < 256; i++) SET_BH(ftab[i]); - - /*-- - Inductively refine the buckets. Kind-of an - "exponential radix sort" (!), inspired by the - Manber-Myers suffix array construction algorithm. - --*/ - - /*-- set sentinel bits for block-end detection --*/ - for (i = 0; i < 32; i++) { - SET_BH(nblock + 2*i); - CLEAR_BH(nblock + 2*i + 1); - } - - /*-- the log(N) loop --*/ - H = 1; - while (1) { - - if (verb >= 4) - VPrintf1 ( " depth %6d has ", H ); - - j = 0; - for (i = 0; i < nblock; i++) { - if (ISSET_BH(i)) j = i; - k = fmap[i] - H; if (k < 0) k += nblock; - eclass[k] = j; - } - - nNotDone = 0; - r = -1; - while (1) { - - /*-- find the next non-singleton bucket --*/ - k = r + 1; - while (ISSET_BH(k) && UNALIGNED_BH(k)) k++; - if (ISSET_BH(k)) { - while (WORD_BH(k) == 0xffffffff) k += 32; - while (ISSET_BH(k)) k++; - } - l = k - 1; - if (l >= nblock) break; - while (!ISSET_BH(k) && UNALIGNED_BH(k)) k++; - if (!ISSET_BH(k)) { - while (WORD_BH(k) == 0x00000000) k += 32; - while (!ISSET_BH(k)) k++; - } - r = k - 1; - if (r >= nblock) break; - - /*-- now [l, r] bracket current bucket --*/ - if (r > l) { - nNotDone += (r - l + 1); - fallbackQSort3 ( fmap, eclass, l, r ); - - /*-- scan bucket and generate header bits-- */ - cc = -1; - for (i = l; i <= r; i++) { - cc1 = eclass[fmap[i]]; - if (cc != cc1) { SET_BH(i); cc = cc1; }; - } - } - } - - if (verb >= 4) - VPrintf1 ( "%6d unresolved strings\n", nNotDone ); - - H *= 2; - if (H > nblock || nNotDone == 0) break; - } - - /*-- - Reconstruct the original block in - eclass8 [0 .. nblock-1], since the - previous phase destroyed it. - --*/ - if (verb >= 4) - VPrintf0 ( " reconstructing block ...\n" ); - j = 0; - for (i = 0; i < nblock; i++) { - while (ftabCopy[j] == 0) j++; - ftabCopy[j]--; - eclass8[fmap[i]] = (UChar)j; - } - AssertH ( j < 256, 1005 ); -} - -#undef SET_BH -#undef CLEAR_BH -#undef ISSET_BH -#undef WORD_BH -#undef UNALIGNED_BH - - -/*---------------------------------------------*/ -/*--- The main, O(N^2 log(N)) sorting ---*/ -/*--- algorithm. Faster for "normal" ---*/ -/*--- non-repetitive blocks. ---*/ -/*---------------------------------------------*/ - -/*---------------------------------------------*/ -static -__inline__ -Bool mainGtU ( UInt32 i1, - UInt32 i2, - UChar* block, - UInt16* quadrant, - UInt32 nblock, - Int32* budget ) -{ - Int32 k; - UChar c1, c2; - UInt16 s1, s2; - - AssertD ( i1 != i2, "mainGtU" ); - /* 1 */ - c1 = block[i1]; c2 = block[i2]; - if (c1 != c2) return (c1 > c2); - i1++; i2++; - /* 2 */ - c1 = block[i1]; c2 = block[i2]; - if (c1 != c2) return (c1 > c2); - i1++; i2++; - /* 3 */ - c1 = block[i1]; c2 = block[i2]; - if (c1 != c2) return (c1 > c2); - i1++; i2++; - /* 4 */ - c1 = block[i1]; c2 = block[i2]; - if (c1 != c2) return (c1 > c2); - i1++; i2++; - /* 5 */ - c1 = block[i1]; c2 = block[i2]; - if (c1 != c2) return (c1 > c2); - i1++; i2++; - /* 6 */ - c1 = block[i1]; c2 = block[i2]; - if (c1 != c2) return (c1 > c2); - i1++; i2++; - /* 7 */ - c1 = block[i1]; c2 = block[i2]; - if (c1 != c2) return (c1 > c2); - i1++; i2++; - /* 8 */ - c1 = block[i1]; c2 = block[i2]; - if (c1 != c2) return (c1 > c2); - i1++; i2++; - /* 9 */ - c1 = block[i1]; c2 = block[i2]; - if (c1 != c2) return (c1 > c2); - i1++; i2++; - /* 10 */ - c1 = block[i1]; c2 = block[i2]; - if (c1 != c2) return (c1 > c2); - i1++; i2++; - /* 11 */ - c1 = block[i1]; c2 = block[i2]; - if (c1 != c2) return (c1 > c2); - i1++; i2++; - /* 12 */ - c1 = block[i1]; c2 = block[i2]; - if (c1 != c2) return (c1 > c2); - i1++; i2++; - - k = nblock + 8; - - do { - /* 1 */ - c1 = block[i1]; c2 = block[i2]; - if (c1 != c2) return (c1 > c2); - s1 = quadrant[i1]; s2 = quadrant[i2]; - if (s1 != s2) return (s1 > s2); - i1++; i2++; - /* 2 */ - c1 = block[i1]; c2 = block[i2]; - if (c1 != c2) return (c1 > c2); - s1 = quadrant[i1]; s2 = quadrant[i2]; - if (s1 != s2) return (s1 > s2); - i1++; i2++; - /* 3 */ - c1 = block[i1]; c2 = block[i2]; - if (c1 != c2) return (c1 > c2); - s1 = quadrant[i1]; s2 = quadrant[i2]; - if (s1 != s2) return (s1 > s2); - i1++; i2++; - /* 4 */ - c1 = block[i1]; c2 = block[i2]; - if (c1 != c2) return (c1 > c2); - s1 = quadrant[i1]; s2 = quadrant[i2]; - if (s1 != s2) return (s1 > s2); - i1++; i2++; - /* 5 */ - c1 = block[i1]; c2 = block[i2]; - if (c1 != c2) return (c1 > c2); - s1 = quadrant[i1]; s2 = quadrant[i2]; - if (s1 != s2) return (s1 > s2); - i1++; i2++; - /* 6 */ - c1 = block[i1]; c2 = block[i2]; - if (c1 != c2) return (c1 > c2); - s1 = quadrant[i1]; s2 = quadrant[i2]; - if (s1 != s2) return (s1 > s2); - i1++; i2++; - /* 7 */ - c1 = block[i1]; c2 = block[i2]; - if (c1 != c2) return (c1 > c2); - s1 = quadrant[i1]; s2 = quadrant[i2]; - if (s1 != s2) return (s1 > s2); - i1++; i2++; - /* 8 */ - c1 = block[i1]; c2 = block[i2]; - if (c1 != c2) return (c1 > c2); - s1 = quadrant[i1]; s2 = quadrant[i2]; - if (s1 != s2) return (s1 > s2); - i1++; i2++; - - if (i1 >= nblock) i1 -= nblock; - if (i2 >= nblock) i2 -= nblock; - - k -= 8; - (*budget)--; - } - while (k >= 0); - - return False; -} - - -/*---------------------------------------------*/ -/*-- - Knuth's increments seem to work better - than Incerpi-Sedgewick here. Possibly - because the number of elems to sort is - usually small, typically <= 20. ---*/ -static -Int32 incs[14] = { 1, 4, 13, 40, 121, 364, 1093, 3280, - 9841, 29524, 88573, 265720, - 797161, 2391484 }; - -static -void mainSimpleSort ( UInt32* ptr, - UChar* block, - UInt16* quadrant, - Int32 nblock, - Int32 lo, - Int32 hi, - Int32 d, - Int32* budget ) -{ - Int32 i, j, h, bigN, hp; - UInt32 v; - - bigN = hi - lo + 1; - if (bigN < 2) return; - - hp = 0; - while (incs[hp] < bigN) hp++; - hp--; - - for (; hp >= 0; hp--) { - h = incs[hp]; - - i = lo + h; - while (True) { - - /*-- copy 1 --*/ - if (i > hi) break; - v = ptr[i]; - j = i; - while ( mainGtU ( - ptr[j-h]+d, v+d, block, quadrant, nblock, budget - ) ) { - ptr[j] = ptr[j-h]; - j = j - h; - if (j <= (lo + h - 1)) break; - } - ptr[j] = v; - i++; - - /*-- copy 2 --*/ - if (i > hi) break; - v = ptr[i]; - j = i; - while ( mainGtU ( - ptr[j-h]+d, v+d, block, quadrant, nblock, budget - ) ) { - ptr[j] = ptr[j-h]; - j = j - h; - if (j <= (lo + h - 1)) break; - } - ptr[j] = v; - i++; - - /*-- copy 3 --*/ - if (i > hi) break; - v = ptr[i]; - j = i; - while ( mainGtU ( - ptr[j-h]+d, v+d, block, quadrant, nblock, budget - ) ) { - ptr[j] = ptr[j-h]; - j = j - h; - if (j <= (lo + h - 1)) break; - } - ptr[j] = v; - i++; - - if (*budget < 0) return; - } - } -} - - -/*---------------------------------------------*/ -/*-- - The following is an implementation of - an elegant 3-way quicksort for strings, - described in a paper "Fast Algorithms for - Sorting and Searching Strings", by Robert - Sedgewick and Jon L. Bentley. ---*/ - -#define mswap(zz1, zz2) \ - { Int32 zztmp = zz1; zz1 = zz2; zz2 = zztmp; } - -#define mvswap(zzp1, zzp2, zzn) \ -{ \ - Int32 yyp1 = (zzp1); \ - Int32 yyp2 = (zzp2); \ - Int32 yyn = (zzn); \ - while (yyn > 0) { \ - mswap(ptr[yyp1], ptr[yyp2]); \ - yyp1++; yyp2++; yyn--; \ - } \ -} - -static -__inline__ -UChar mmed3 ( UChar a, UChar b, UChar c ) -{ - UChar t; - if (a > b) { t = a; a = b; b = t; }; - if (b > c) { - b = c; - if (a > b) b = a; - } - return b; -} - -#define mmin(a,b) ((a) < (b)) ? (a) : (b) - -#define mpush(lz,hz,dz) { stackLo[sp] = lz; \ - stackHi[sp] = hz; \ - stackD [sp] = dz; \ - sp++; } - -#define mpop(lz,hz,dz) { sp--; \ - lz = stackLo[sp]; \ - hz = stackHi[sp]; \ - dz = stackD [sp]; } - - -#define mnextsize(az) (nextHi[az]-nextLo[az]) - -#define mnextswap(az,bz) \ - { Int32 tz; \ - tz = nextLo[az]; nextLo[az] = nextLo[bz]; nextLo[bz] = tz; \ - tz = nextHi[az]; nextHi[az] = nextHi[bz]; nextHi[bz] = tz; \ - tz = nextD [az]; nextD [az] = nextD [bz]; nextD [bz] = tz; } - - -#define MAIN_QSORT_SMALL_THRESH 20 -#define MAIN_QSORT_DEPTH_THRESH (BZ_N_RADIX + BZ_N_QSORT) -#define MAIN_QSORT_STACK_SIZE 100 - -static -void mainQSort3 ( UInt32* ptr, - UChar* block, - UInt16* quadrant, - Int32 nblock, - Int32 loSt, - Int32 hiSt, - Int32 dSt, - Int32* budget ) -{ - Int32 unLo, unHi, ltLo, gtHi, n, m, med; - Int32 sp, lo, hi, d; - - Int32 stackLo[MAIN_QSORT_STACK_SIZE]; - Int32 stackHi[MAIN_QSORT_STACK_SIZE]; - Int32 stackD [MAIN_QSORT_STACK_SIZE]; - - Int32 nextLo[3]; - Int32 nextHi[3]; - Int32 nextD [3]; - - sp = 0; - mpush ( loSt, hiSt, dSt ); - - while (sp > 0) { - - AssertH ( sp < MAIN_QSORT_STACK_SIZE, 1001 ); - - mpop ( lo, hi, d ); - if (hi - lo < MAIN_QSORT_SMALL_THRESH || - d > MAIN_QSORT_DEPTH_THRESH) { - mainSimpleSort ( ptr, block, quadrant, nblock, lo, hi, d, budget ); - if (*budget < 0) return; - continue; - } - - med = (Int32) - mmed3 ( block[ptr[ lo ]+d], - block[ptr[ hi ]+d], - block[ptr[ (lo+hi)>>1 ]+d] ); - - unLo = ltLo = lo; - unHi = gtHi = hi; - - while (True) { - while (True) { - if (unLo > unHi) break; - n = ((Int32)block[ptr[unLo]+d]) - med; - if (n == 0) { - mswap(ptr[unLo], ptr[ltLo]); - ltLo++; unLo++; continue; - }; - if (n > 0) break; - unLo++; - } - while (True) { - if (unLo > unHi) break; - n = ((Int32)block[ptr[unHi]+d]) - med; - if (n == 0) { - mswap(ptr[unHi], ptr[gtHi]); - gtHi--; unHi--; continue; - }; - if (n < 0) break; - unHi--; - } - if (unLo > unHi) break; - mswap(ptr[unLo], ptr[unHi]); unLo++; unHi--; - } - - AssertD ( unHi == unLo-1, "mainQSort3(2)" ); - - if (gtHi < ltLo) { - mpush(lo, hi, d+1 ); - continue; - } - - n = mmin(ltLo-lo, unLo-ltLo); mvswap(lo, unLo-n, n); - m = mmin(hi-gtHi, gtHi-unHi); mvswap(unLo, hi-m+1, m); - - n = lo + unLo - ltLo - 1; - m = hi - (gtHi - unHi) + 1; - - nextLo[0] = lo; nextHi[0] = n; nextD[0] = d; - nextLo[1] = m; nextHi[1] = hi; nextD[1] = d; - nextLo[2] = n+1; nextHi[2] = m-1; nextD[2] = d+1; - - if (mnextsize(0) < mnextsize(1)) mnextswap(0,1); - if (mnextsize(1) < mnextsize(2)) mnextswap(1,2); - if (mnextsize(0) < mnextsize(1)) mnextswap(0,1); - - AssertD (mnextsize(0) >= mnextsize(1), "mainQSort3(8)" ); - AssertD (mnextsize(1) >= mnextsize(2), "mainQSort3(9)" ); - - mpush (nextLo[0], nextHi[0], nextD[0]); - mpush (nextLo[1], nextHi[1], nextD[1]); - mpush (nextLo[2], nextHi[2], nextD[2]); - } -} - -#undef mswap -#undef mvswap -#undef mpush -#undef mpop -#undef mmin -#undef mnextsize -#undef mnextswap -#undef MAIN_QSORT_SMALL_THRESH -#undef MAIN_QSORT_DEPTH_THRESH -#undef MAIN_QSORT_STACK_SIZE - - -/*---------------------------------------------*/ -/* Pre: - nblock > N_OVERSHOOT - block32 exists for [0 .. nblock-1 +N_OVERSHOOT] - ((UChar*)block32) [0 .. nblock-1] holds block - ptr exists for [0 .. nblock-1] - - Post: - ((UChar*)block32) [0 .. nblock-1] holds block - All other areas of block32 destroyed - ftab [0 .. 65536 ] destroyed - ptr [0 .. nblock-1] holds sorted order - if (*budget < 0), sorting was abandoned -*/ - -#define BIGFREQ(b) (ftab[((b)+1) << 8] - ftab[(b) << 8]) -#define SETMASK (1 << 21) -#define CLEARMASK (~(SETMASK)) - -static -void mainSort ( UInt32* ptr, - UChar* block, - UInt16* quadrant, - UInt32* ftab, - Int32 nblock, - Int32 verb, - Int32* budget ) -{ - Int32 i, j, k, ss, sb; - Int32 runningOrder[256]; - Bool bigDone[256]; - Int32 copyStart[256]; - Int32 copyEnd [256]; - UChar c1; - Int32 numQSorted; - UInt16 s; - if (verb >= 4) VPrintf0 ( " main sort initialise ...\n" ); - - /*-- set up the 2-byte frequency table --*/ - for (i = 65536; i >= 0; i--) ftab[i] = 0; - - j = block[0] << 8; - i = nblock-1; - for (; i >= 3; i -= 4) { - quadrant[i] = 0; - j = (j >> 8) | ( ((UInt16)block[i]) << 8); - ftab[j]++; - quadrant[i-1] = 0; - j = (j >> 8) | ( ((UInt16)block[i-1]) << 8); - ftab[j]++; - quadrant[i-2] = 0; - j = (j >> 8) | ( ((UInt16)block[i-2]) << 8); - ftab[j]++; - quadrant[i-3] = 0; - j = (j >> 8) | ( ((UInt16)block[i-3]) << 8); - ftab[j]++; - } - for (; i >= 0; i--) { - quadrant[i] = 0; - j = (j >> 8) | ( ((UInt16)block[i]) << 8); - ftab[j]++; - } - - /*-- (emphasises close relationship of block & quadrant) --*/ - for (i = 0; i < BZ_N_OVERSHOOT; i++) { - block [nblock+i] = block[i]; - quadrant[nblock+i] = 0; - } - - if (verb >= 4) VPrintf0 ( " bucket sorting ...\n" ); - - /*-- Complete the initial radix sort --*/ - for (i = 1; i <= 65536; i++) ftab[i] += ftab[i-1]; - - s = block[0] << 8; - i = nblock-1; - for (; i >= 3; i -= 4) { - s = (s >> 8) | (block[i] << 8); - j = ftab[s] -1; - ftab[s] = j; - ptr[j] = i; - s = (s >> 8) | (block[i-1] << 8); - j = ftab[s] -1; - ftab[s] = j; - ptr[j] = i-1; - s = (s >> 8) | (block[i-2] << 8); - j = ftab[s] -1; - ftab[s] = j; - ptr[j] = i-2; - s = (s >> 8) | (block[i-3] << 8); - j = ftab[s] -1; - ftab[s] = j; - ptr[j] = i-3; - } - for (; i >= 0; i--) { - s = (s >> 8) | (block[i] << 8); - j = ftab[s] -1; - ftab[s] = j; - ptr[j] = i; - } - - /*-- - Now ftab contains the first loc of every small bucket. - Calculate the running order, from smallest to largest - big bucket. - --*/ - for (i = 0; i <= 255; i++) { - bigDone [i] = False; - runningOrder[i] = i; - } - - { - Int32 vv; - Int32 h = 1; - do h = 3 * h + 1; while (h <= 256); - do { - h = h / 3; - for (i = h; i <= 255; i++) { - vv = runningOrder[i]; - j = i; - while ( BIGFREQ(runningOrder[j-h]) > BIGFREQ(vv) ) { - runningOrder[j] = runningOrder[j-h]; - j = j - h; - if (j <= (h - 1)) goto zero; - } - zero: - runningOrder[j] = vv; - } - } while (h != 1); - } - - /*-- - The main sorting loop. - --*/ - - numQSorted = 0; - - for (i = 0; i <= 255; i++) { - - /*-- - Process big buckets, starting with the least full. - Basically this is a 3-step process in which we call - mainQSort3 to sort the small buckets [ss, j], but - also make a big effort to avoid the calls if we can. - --*/ - ss = runningOrder[i]; - - /*-- - Step 1: - Complete the big bucket [ss] by quicksorting - any unsorted small buckets [ss, j], for j != ss. - Hopefully previous pointer-scanning phases have already - completed many of the small buckets [ss, j], so - we don't have to sort them at all. - --*/ - for (j = 0; j <= 255; j++) { - if (j != ss) { - sb = (ss << 8) + j; - if ( ! (ftab[sb] & SETMASK) ) { - Int32 lo = ftab[sb] & CLEARMASK; - Int32 hi = (ftab[sb+1] & CLEARMASK) - 1; - if (hi > lo) { - if (verb >= 4) - VPrintf4 ( " qsort [0x%x, 0x%x] " - "done %d this %d\n", - ss, j, numQSorted, hi - lo + 1 ); - mainQSort3 ( - ptr, block, quadrant, nblock, - lo, hi, BZ_N_RADIX, budget - ); - numQSorted += (hi - lo + 1); - if (*budget < 0) return; - } - } - ftab[sb] |= SETMASK; - } - } - - AssertH ( !bigDone[ss], 1006 ); - - /*-- - Step 2: - Now scan this big bucket [ss] so as to synthesise the - sorted order for small buckets [t, ss] for all t, - including, magically, the bucket [ss,ss] too. - This will avoid doing Real Work in subsequent Step 1's. - --*/ - { - for (j = 0; j <= 255; j++) { - copyStart[j] = ftab[(j << 8) + ss] & CLEARMASK; - copyEnd [j] = (ftab[(j << 8) + ss + 1] & CLEARMASK) - 1; - } - for (j = ftab[ss << 8] & CLEARMASK; j < copyStart[ss]; j++) { - k = ptr[j]-1; if (k < 0) k += nblock; - c1 = block[k]; - if (!bigDone[c1]) - ptr[ copyStart[c1]++ ] = k; - } - for (j = (ftab[(ss+1) << 8] & CLEARMASK) - 1; j > copyEnd[ss]; j--) { - k = ptr[j]-1; if (k < 0) k += nblock; - c1 = block[k]; - if (!bigDone[c1]) - ptr[ copyEnd[c1]-- ] = k; - } - } - - AssertH ( copyStart[ss]-1 == copyEnd[ss], 1007 ); - - for (j = 0; j <= 255; j++) ftab[(j << 8) + ss] |= SETMASK; - - /*-- - Step 3: - The [ss] big bucket is now done. Record this fact, - and update the quadrant descriptors. Remember to - update quadrants in the overshoot area too, if - necessary. The "if (i < 255)" test merely skips - this updating for the last bucket processed, since - updating for the last bucket is pointless. - - The quadrant array provides a way to incrementally - cache sort orderings, as they appear, so as to - make subsequent comparisons in fullGtU() complete - faster. For repetitive blocks this makes a big - difference (but not big enough to be able to avoid - the fallback sorting mechanism, exponential radix sort). - - The precise meaning is: at all times: - - for 0 <= i < nblock and 0 <= j <= nblock - - if block[i] != block[j], - - then the relative values of quadrant[i] and - quadrant[j] are meaningless. - - else { - if quadrant[i] < quadrant[j] - then the string starting at i lexicographically - precedes the string starting at j - - else if quadrant[i] > quadrant[j] - then the string starting at j lexicographically - precedes the string starting at i - - else - the relative ordering of the strings starting - at i and j has not yet been determined. - } - --*/ - bigDone[ss] = True; - - if (i < 255) { - Int32 bbStart = ftab[ss << 8] & CLEARMASK; - Int32 bbSize = (ftab[(ss+1) << 8] & CLEARMASK) - bbStart; - Int32 shifts = 0; - - while ((bbSize >> shifts) > 65534) shifts++; - - for (j = bbSize-1; j >= 0; j--) { - Int32 a2update = ptr[bbStart + j]; - UInt16 qVal = (UInt16)(j >> shifts); - quadrant[a2update] = qVal; - if (a2update < BZ_N_OVERSHOOT) - quadrant[a2update + nblock] = qVal; - } - AssertH ( ((bbSize-1) >> shifts) <= 65535, 1002 ); - } - - } - - if (verb >= 4) - VPrintf3 ( " %d pointers, %d sorted, %d scanned\n", - nblock, numQSorted, nblock - numQSorted ); -} - -#undef BIGFREQ -#undef SETMASK -#undef CLEARMASK - - -/*---------------------------------------------*/ -/* Pre: - nblock > 0 - arr2 exists for [0 .. nblock-1 +N_OVERSHOOT] - ((UChar*)arr2) [0 .. nblock-1] holds block - arr1 exists for [0 .. nblock-1] - - Post: - ((UChar*)arr2) [0 .. nblock-1] holds block - All other areas of block destroyed - ftab [ 0 .. 65536 ] destroyed - arr1 [0 .. nblock-1] holds sorted order -*/ -void BZ2_blockSort ( EState* s ) -{ - UInt32* ptr = s->ptr; - UChar* block = s->block; - UInt32* ftab = s->ftab; - Int32 nblock = s->nblock; - Int32 verb = s->verbosity; - Int32 wfact = s->workFactor; - UInt16* quadrant; - Int32 budget; - Int32 budgetInit; - Int32 i; - - if (nblock < 10000) { - fallbackSort ( s->arr1, s->arr2, ftab, nblock, verb ); - } else { - /* Calculate the location for quadrant, remembering to get - the alignment right. Assumes that &(block[0]) is at least - 2-byte aligned -- this should be ok since block is really - the first section of arr2. - */ - i = nblock+BZ_N_OVERSHOOT; - if (i & 1) i++; - quadrant = (UInt16*)(&(block[i])); - - /* (wfact-1) / 3 puts the default-factor-30 - transition point at very roughly the same place as - with v0.1 and v0.9.0. - Not that it particularly matters any more, since the - resulting compressed stream is now the same regardless - of whether or not we use the main sort or fallback sort. - */ - if (wfact < 1 ) wfact = 1; - if (wfact > 100) wfact = 100; - budgetInit = nblock * ((wfact-1) / 3); - budget = budgetInit; - - mainSort ( ptr, block, quadrant, ftab, nblock, verb, &budget ); - if (verb >= 3) - VPrintf3 ( " %d work, %d block, ratio %5.2f\n", - budgetInit - budget, - nblock, - (float)(budgetInit - budget) / - (float)(nblock==0 ? 1 : nblock) ); - if (budget < 0) { - if (verb >= 2) - VPrintf0 ( " too repetitive; using fallback" - " sorting algorithm\n" ); - fallbackSort ( s->arr1, s->arr2, ftab, nblock, verb ); - } - } - - s->origPtr = -1; - for (i = 0; i < s->nblock; i++) - if (ptr[i] == 0) - { s->origPtr = i; break; }; - - AssertH( s->origPtr != -1, 1003 ); -} - - -/*-------------------------------------------------------------*/ -/*--- end blocksort.c ---*/ -/*-------------------------------------------------------------*/ diff --git a/mdk-stage1/bzlib/bzlib.c b/mdk-stage1/bzlib/bzlib.c deleted file mode 100644 index b1fc85236..000000000 --- a/mdk-stage1/bzlib/bzlib.c +++ /dev/null @@ -1,1567 +0,0 @@ - -/*-------------------------------------------------------------*/ -/*--- Library top-level functions. ---*/ -/*--- bzlib.c ---*/ -/*-------------------------------------------------------------*/ - -/*-- - This file is a part of bzip2 and/or libbzip2, a program and - library for lossless, block-sorting data compression. - - Copyright (C) 1996-2000 Julian R Seward. All rights reserved. - - Redistribution and use in source and binary forms, with or without - modification, are permitted provided that the following conditions - are met: - - 1. Redistributions of source code must retain the above copyright - notice, this list of conditions and the following disclaimer. - - 2. The origin of this software must not be misrepresented; you must - not claim that you wrote the original software. If you use this - software in a product, an acknowledgment in the product - documentation would be appreciated but is not required. - - 3. Altered source versions must be plainly marked as such, and must - not be misrepresented as being the original software. - - 4. The name of the author may not be used to endorse or promote - products derived from this software without specific prior written - permission. - - THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS - OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED - WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY - DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE - GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS - INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, - WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING - NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS - SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - - Julian Seward, Cambridge, UK. - jseward@acm.org - bzip2/libbzip2 version 1.0 of 21 March 2000 - - This program is based on (at least) the work of: - Mike Burrows - David Wheeler - Peter Fenwick - Alistair Moffat - Radford Neal - Ian H. Witten - Robert Sedgewick - Jon L. Bentley - - For more information on these sources, see the manual. ---*/ - -/*-- - CHANGES - ~~~~~~~ - 0.9.0 -- original version. - - 0.9.0a/b -- no changes in this file. - - 0.9.0c - * made zero-length BZ_FLUSH work correctly in bzCompress(). - * fixed bzWrite/bzRead to ignore zero-length requests. - * fixed bzread to correctly handle read requests after EOF. - * wrong parameter order in call to bzDecompressInit in - bzBuffToBuffDecompress. Fixed. ---*/ - -#ifdef HAVE_CONFIG_H -#include <config.h> -#endif - - - -#include "bzlib_private.h" - - -/*---------------------------------------------------*/ -/*--- Compression stuff ---*/ -/*---------------------------------------------------*/ - - -/*---------------------------------------------------*/ -#ifndef BZ_NO_STDIO -void BZ2_bz__AssertH__fail ( int errcode ) -{ - fprintf(stderr, - "\n\nbzip2/libbzip2: internal error number %d.\n" - "This is a bug in bzip2/libbzip2, %s.\n" - "Please report it to me at: jseward@acm.org. If this happened\n" - "when you were using some program which uses libbzip2 as a\n" - "component, you should also report this bug to the author(s)\n" - "of that program. Please make an effort to report this bug;\n" - "timely and accurate bug reports eventually lead to higher\n" - "quality software. Thanks. Julian Seward, 21 March 2000.\n\n", - errcode, - BZ2_bzlibVersion() - ); - exit(3); -} -#endif - - -/*---------------------------------------------------*/ -static -int bz_config_ok ( void ) -{ - if (sizeof(int) != 4) return 0; - if (sizeof(short) != 2) return 0; - if (sizeof(char) != 1) return 0; - return 1; -} - - -/*---------------------------------------------------*/ -static -void* default_bzalloc ( void* opaque __attribute__ ((unused)), Int32 items, Int32 size ) -{ - void* v = malloc ( items * size ); - return v; -} - -static -void default_bzfree ( void* opaque __attribute__ ((unused)), void* addr ) -{ - if (addr != NULL) free ( addr ); -} - - -/*---------------------------------------------------*/ -static -void prepare_new_block ( EState* s ) -{ - Int32 i; - s->nblock = 0; - s->numZ = 0; - s->state_out_pos = 0; - BZ_INITIALISE_CRC ( s->blockCRC ); - for (i = 0; i < 256; i++) s->inUse[i] = False; - s->blockNo++; -} - - -/*---------------------------------------------------*/ -static -void init_RL ( EState* s ) -{ - s->state_in_ch = 256; - s->state_in_len = 0; -} - - -static -Bool isempty_RL ( EState* s ) -{ - if (s->state_in_ch < 256 && s->state_in_len > 0) - return False; else - return True; -} - - -/*---------------------------------------------------*/ -int BZ_API(BZ2_bzCompressInit) - ( bz_stream* strm, - int blockSize100k, - int verbosity, - int workFactor ) -{ - Int32 n; - EState* s; - - if (!bz_config_ok()) return BZ_CONFIG_ERROR; - - if (strm == NULL || - blockSize100k < 1 || blockSize100k > 9 || - workFactor < 0 || workFactor > 250) - return BZ_PARAM_ERROR; - - if (workFactor == 0) workFactor = 30; - if (strm->bzalloc == NULL) strm->bzalloc = default_bzalloc; - if (strm->bzfree == NULL) strm->bzfree = default_bzfree; - - s = BZALLOC( sizeof(EState) ); - if (s == NULL) return BZ_MEM_ERROR; - s->strm = strm; - - s->arr1 = NULL; - s->arr2 = NULL; - s->ftab = NULL; - - n = 100000 * blockSize100k; - s->arr1 = BZALLOC( n * sizeof(UInt32) ); - s->arr2 = BZALLOC( (n+BZ_N_OVERSHOOT) * sizeof(UInt32) ); - s->ftab = BZALLOC( 65537 * sizeof(UInt32) ); - - if (s->arr1 == NULL || s->arr2 == NULL || s->ftab == NULL) { - if (s->arr1 != NULL) BZFREE(s->arr1); - if (s->arr2 != NULL) BZFREE(s->arr2); - if (s->ftab != NULL) BZFREE(s->ftab); - if (s != NULL) BZFREE(s); - return BZ_MEM_ERROR; - } - - s->blockNo = 0; - s->state = BZ_S_INPUT; - s->mode = BZ_M_RUNNING; - s->combinedCRC = 0; - s->blockSize100k = blockSize100k; - s->nblockMAX = 100000 * blockSize100k - 19; - s->verbosity = verbosity; - s->workFactor = workFactor; - - s->block = (UChar*)s->arr2; - s->mtfv = (UInt16*)s->arr1; - s->zbits = NULL; - s->ptr = (UInt32*)s->arr1; - - strm->state = s; - strm->total_in_lo32 = 0; - strm->total_in_hi32 = 0; - strm->total_out_lo32 = 0; - strm->total_out_hi32 = 0; - init_RL ( s ); - prepare_new_block ( s ); - return BZ_OK; -} - - -/*---------------------------------------------------*/ -static -void add_pair_to_block ( EState* s ) -{ - Int32 i; - UChar ch = (UChar)(s->state_in_ch); - for (i = 0; i < s->state_in_len; i++) { - BZ_UPDATE_CRC( s->blockCRC, ch ); - } - s->inUse[s->state_in_ch] = True; - switch (s->state_in_len) { - case 1: - s->block[s->nblock] = (UChar)ch; s->nblock++; - break; - case 2: - s->block[s->nblock] = (UChar)ch; s->nblock++; - s->block[s->nblock] = (UChar)ch; s->nblock++; - break; - case 3: - s->block[s->nblock] = (UChar)ch; s->nblock++; - s->block[s->nblock] = (UChar)ch; s->nblock++; - s->block[s->nblock] = (UChar)ch; s->nblock++; - break; - default: - s->inUse[s->state_in_len-4] = True; - s->block[s->nblock] = (UChar)ch; s->nblock++; - s->block[s->nblock] = (UChar)ch; s->nblock++; - s->block[s->nblock] = (UChar)ch; s->nblock++; - s->block[s->nblock] = (UChar)ch; s->nblock++; - s->block[s->nblock] = ((UChar)(s->state_in_len-4)); - s->nblock++; - break; - } -} - - -/*---------------------------------------------------*/ -static -void flush_RL ( EState* s ) -{ - if (s->state_in_ch < 256) add_pair_to_block ( s ); - init_RL ( s ); -} - - -/*---------------------------------------------------*/ -#define ADD_CHAR_TO_BLOCK(zs,zchh0) \ -{ \ - UInt32 zchh = (UInt32)(zchh0); \ - /*-- fast track the common case --*/ \ - if (zchh != zs->state_in_ch && \ - zs->state_in_len == 1) { \ - UChar ch = (UChar)(zs->state_in_ch); \ - BZ_UPDATE_CRC( zs->blockCRC, ch ); \ - zs->inUse[zs->state_in_ch] = True; \ - zs->block[zs->nblock] = (UChar)ch; \ - zs->nblock++; \ - zs->state_in_ch = zchh; \ - } \ - else \ - /*-- general, uncommon cases --*/ \ - if (zchh != zs->state_in_ch || \ - zs->state_in_len == 255) { \ - if (zs->state_in_ch < 256) \ - add_pair_to_block ( zs ); \ - zs->state_in_ch = zchh; \ - zs->state_in_len = 1; \ - } else { \ - zs->state_in_len++; \ - } \ -} - - -/*---------------------------------------------------*/ -static -Bool copy_input_until_stop ( EState* s ) -{ - Bool progress_in = False; - - if (s->mode == BZ_M_RUNNING) { - - /*-- fast track the common case --*/ - while (True) { - /*-- block full? --*/ - if (s->nblock >= s->nblockMAX) break; - /*-- no input? --*/ - if (s->strm->avail_in == 0) break; - progress_in = True; - ADD_CHAR_TO_BLOCK ( s, (UInt32)(*((UChar*)(s->strm->next_in))) ); - s->strm->next_in++; - s->strm->avail_in--; - s->strm->total_in_lo32++; - if (s->strm->total_in_lo32 == 0) s->strm->total_in_hi32++; - } - - } else { - - /*-- general, uncommon case --*/ - while (True) { - /*-- block full? --*/ - if (s->nblock >= s->nblockMAX) break; - /*-- no input? --*/ - if (s->strm->avail_in == 0) break; - /*-- flush/finish end? --*/ - if (s->avail_in_expect == 0) break; - progress_in = True; - ADD_CHAR_TO_BLOCK ( s, (UInt32)(*((UChar*)(s->strm->next_in))) ); - s->strm->next_in++; - s->strm->avail_in--; - s->strm->total_in_lo32++; - if (s->strm->total_in_lo32 == 0) s->strm->total_in_hi32++; - s->avail_in_expect--; - } - } - return progress_in; -} - - -/*---------------------------------------------------*/ -static -Bool copy_output_until_stop ( EState* s ) -{ - Bool progress_out = False; - - while (True) { - - /*-- no output space? --*/ - if (s->strm->avail_out == 0) break; - - /*-- block done? --*/ - if (s->state_out_pos >= s->numZ) break; - - progress_out = True; - *(s->strm->next_out) = s->zbits[s->state_out_pos]; - s->state_out_pos++; - s->strm->avail_out--; - s->strm->next_out++; - s->strm->total_out_lo32++; - if (s->strm->total_out_lo32 == 0) s->strm->total_out_hi32++; - } - - return progress_out; -} - - -/*---------------------------------------------------*/ -static -Bool handle_compress ( bz_stream* strm ) -{ - Bool progress_in = False; - Bool progress_out = False; - EState* s = strm->state; - - while (True) { - - if (s->state == BZ_S_OUTPUT) { - progress_out |= copy_output_until_stop ( s ); - if (s->state_out_pos < s->numZ) break; - if (s->mode == BZ_M_FINISHING && - s->avail_in_expect == 0 && - isempty_RL(s)) break; - prepare_new_block ( s ); - s->state = BZ_S_INPUT; - if (s->mode == BZ_M_FLUSHING && - s->avail_in_expect == 0 && - isempty_RL(s)) break; - } - - if (s->state == BZ_S_INPUT) { - progress_in |= copy_input_until_stop ( s ); - if (s->mode != BZ_M_RUNNING && s->avail_in_expect == 0) { - flush_RL ( s ); - BZ2_compressBlock ( s, (Bool)(s->mode == BZ_M_FINISHING) ); - s->state = BZ_S_OUTPUT; - } - else - if (s->nblock >= s->nblockMAX) { - BZ2_compressBlock ( s, False ); - s->state = BZ_S_OUTPUT; - } - else - if (s->strm->avail_in == 0) { - break; - } - } - - } - - return progress_in || progress_out; -} - - -/*---------------------------------------------------*/ -int BZ_API(BZ2_bzCompress) ( bz_stream *strm, int action ) -{ - Bool progress; - EState* s; - if (strm == NULL) return BZ_PARAM_ERROR; - s = strm->state; - if (s == NULL) return BZ_PARAM_ERROR; - if (s->strm != strm) return BZ_PARAM_ERROR; - - preswitch: - switch (s->mode) { - - case BZ_M_IDLE: - return BZ_SEQUENCE_ERROR; - - case BZ_M_RUNNING: - if (action == BZ_RUN) { - progress = handle_compress ( strm ); - return progress ? BZ_RUN_OK : BZ_PARAM_ERROR; - } - else - if (action == BZ_FLUSH) { - s->avail_in_expect = strm->avail_in; - s->mode = BZ_M_FLUSHING; - goto preswitch; - } - else - if (action == BZ_FINISH) { - s->avail_in_expect = strm->avail_in; - s->mode = BZ_M_FINISHING; - goto preswitch; - } - else - return BZ_PARAM_ERROR; - - case BZ_M_FLUSHING: - if (action != BZ_FLUSH) return BZ_SEQUENCE_ERROR; - if (s->avail_in_expect != s->strm->avail_in) - return BZ_SEQUENCE_ERROR; - progress = handle_compress ( strm ); - if (s->avail_in_expect > 0 || !isempty_RL(s) || - s->state_out_pos < s->numZ) return BZ_FLUSH_OK; - s->mode = BZ_M_RUNNING; - return BZ_RUN_OK; - - case BZ_M_FINISHING: - if (action != BZ_FINISH) return BZ_SEQUENCE_ERROR; - if (s->avail_in_expect != s->strm->avail_in) - return BZ_SEQUENCE_ERROR; - progress = handle_compress ( strm ); - if (!progress) return BZ_SEQUENCE_ERROR; - if (s->avail_in_expect > 0 || !isempty_RL(s) || - s->state_out_pos < s->numZ) return BZ_FINISH_OK; - s->mode = BZ_M_IDLE; - return BZ_STREAM_END; - } - return BZ_OK; /*--not reached--*/ -} - - -/*---------------------------------------------------*/ -int BZ_API(BZ2_bzCompressEnd) ( bz_stream *strm ) -{ - EState* s; - if (strm == NULL) return BZ_PARAM_ERROR; - s = strm->state; - if (s == NULL) return BZ_PARAM_ERROR; - if (s->strm != strm) return BZ_PARAM_ERROR; - - if (s->arr1 != NULL) BZFREE(s->arr1); - if (s->arr2 != NULL) BZFREE(s->arr2); - if (s->ftab != NULL) BZFREE(s->ftab); - BZFREE(strm->state); - - strm->state = NULL; - - return BZ_OK; -} - - -/*---------------------------------------------------*/ -/*--- Decompression stuff ---*/ -/*---------------------------------------------------*/ - -/*---------------------------------------------------*/ -int BZ_API(BZ2_bzDecompressInit) - ( bz_stream* strm, - int verbosity, - int small ) -{ - DState* s; - - if (!bz_config_ok()) return BZ_CONFIG_ERROR; - - if (strm == NULL) return BZ_PARAM_ERROR; - if (small != 0 && small != 1) return BZ_PARAM_ERROR; - if (verbosity < 0 || verbosity > 4) return BZ_PARAM_ERROR; - - if (strm->bzalloc == NULL) strm->bzalloc = default_bzalloc; - if (strm->bzfree == NULL) strm->bzfree = default_bzfree; - - s = BZALLOC( sizeof(DState) ); - if (s == NULL) return BZ_MEM_ERROR; - s->strm = strm; - strm->state = s; - s->state = BZ_X_MAGIC_1; - s->bsLive = 0; - s->bsBuff = 0; - s->calculatedCombinedCRC = 0; - strm->total_in_lo32 = 0; - strm->total_in_hi32 = 0; - strm->total_out_lo32 = 0; - strm->total_out_hi32 = 0; - s->smallDecompress = (Bool)small; - s->ll4 = NULL; - s->ll16 = NULL; - s->tt = NULL; - s->currBlockNo = 0; - s->verbosity = verbosity; - - return BZ_OK; -} - - -/*---------------------------------------------------*/ -static -void unRLE_obuf_to_output_FAST ( DState* s ) -{ - UChar k1; - - if (s->blockRandomised) { - - while (True) { - /* try to finish existing run */ - while (True) { - if (s->strm->avail_out == 0) return; - if (s->state_out_len == 0) break; - *( (UChar*)(s->strm->next_out) ) = s->state_out_ch; - BZ_UPDATE_CRC ( s->calculatedBlockCRC, s->state_out_ch ); - s->state_out_len--; - s->strm->next_out++; - s->strm->avail_out--; - s->strm->total_out_lo32++; - if (s->strm->total_out_lo32 == 0) s->strm->total_out_hi32++; - } - - /* can a new run be started? */ - if (s->nblock_used == s->save_nblock+1) return; - - - s->state_out_len = 1; - s->state_out_ch = s->k0; - BZ_GET_FAST(k1); BZ_RAND_UPD_MASK; - k1 ^= BZ_RAND_MASK; s->nblock_used++; - if (s->nblock_used == s->save_nblock+1) continue; - if (k1 != s->k0) { s->k0 = k1; continue; }; - - s->state_out_len = 2; - BZ_GET_FAST(k1); BZ_RAND_UPD_MASK; - k1 ^= BZ_RAND_MASK; s->nblock_used++; - if (s->nblock_used == s->save_nblock+1) continue; - if (k1 != s->k0) { s->k0 = k1; continue; }; - - s->state_out_len = 3; - BZ_GET_FAST(k1); BZ_RAND_UPD_MASK; - k1 ^= BZ_RAND_MASK; s->nblock_used++; - if (s->nblock_used == s->save_nblock+1) continue; - if (k1 != s->k0) { s->k0 = k1; continue; }; - - BZ_GET_FAST(k1); BZ_RAND_UPD_MASK; - k1 ^= BZ_RAND_MASK; s->nblock_used++; - s->state_out_len = ((Int32)k1) + 4; - BZ_GET_FAST(s->k0); BZ_RAND_UPD_MASK; - s->k0 ^= BZ_RAND_MASK; s->nblock_used++; - } - - } else { - - /* restore */ - UInt32 c_calculatedBlockCRC = s->calculatedBlockCRC; - UChar c_state_out_ch = s->state_out_ch; - Int32 c_state_out_len = s->state_out_len; - Int32 c_nblock_used = s->nblock_used; - Int32 c_k0 = s->k0; - UInt32* c_tt = s->tt; - UInt32 c_tPos = s->tPos; - char* cs_next_out = s->strm->next_out; - unsigned int cs_avail_out = s->strm->avail_out; - /* end restore */ - - UInt32 avail_out_INIT = cs_avail_out; - Int32 s_save_nblockPP = s->save_nblock+1; - unsigned int total_out_lo32_old; - - while (True) { - - /* try to finish existing run */ - if (c_state_out_len > 0) { - while (True) { - if (cs_avail_out == 0) goto return_notr; - if (c_state_out_len == 1) break; - *( (UChar*)(cs_next_out) ) = c_state_out_ch; - BZ_UPDATE_CRC ( c_calculatedBlockCRC, c_state_out_ch ); - c_state_out_len--; - cs_next_out++; - cs_avail_out--; - } - s_state_out_len_eq_one: - { - if (cs_avail_out == 0) { - c_state_out_len = 1; goto return_notr; - }; - *( (UChar*)(cs_next_out) ) = c_state_out_ch; - BZ_UPDATE_CRC ( c_calculatedBlockCRC, c_state_out_ch ); - cs_next_out++; - cs_avail_out--; - } - } - /* can a new run be started? */ - if (c_nblock_used == s_save_nblockPP) { - c_state_out_len = 0; goto return_notr; - }; - c_state_out_ch = c_k0; - BZ_GET_FAST_C(k1); c_nblock_used++; - if (k1 != c_k0) { - c_k0 = k1; goto s_state_out_len_eq_one; - }; - if (c_nblock_used == s_save_nblockPP) - goto s_state_out_len_eq_one; - - c_state_out_len = 2; - BZ_GET_FAST_C(k1); c_nblock_used++; - if (c_nblock_used == s_save_nblockPP) continue; - if (k1 != c_k0) { c_k0 = k1; continue; }; - - c_state_out_len = 3; - BZ_GET_FAST_C(k1); c_nblock_used++; - if (c_nblock_used == s_save_nblockPP) continue; - if (k1 != c_k0) { c_k0 = k1; continue; }; - - BZ_GET_FAST_C(k1); c_nblock_used++; - c_state_out_len = ((Int32)k1) + 4; - BZ_GET_FAST_C(c_k0); c_nblock_used++; - } - - return_notr: - total_out_lo32_old = s->strm->total_out_lo32; - s->strm->total_out_lo32 += (avail_out_INIT - cs_avail_out); - if (s->strm->total_out_lo32 < total_out_lo32_old) - s->strm->total_out_hi32++; - - /* save */ - s->calculatedBlockCRC = c_calculatedBlockCRC; - s->state_out_ch = c_state_out_ch; - s->state_out_len = c_state_out_len; - s->nblock_used = c_nblock_used; - s->k0 = c_k0; - s->tt = c_tt; - s->tPos = c_tPos; - s->strm->next_out = cs_next_out; - s->strm->avail_out = cs_avail_out; - /* end save */ - } -} - - - -/*---------------------------------------------------*/ -__inline__ Int32 BZ2_indexIntoF ( Int32 indx, Int32 *cftab ) -{ - Int32 nb, na, mid; - nb = 0; - na = 256; - do { - mid = (nb + na) >> 1; - if (indx >= cftab[mid]) nb = mid; else na = mid; - } - while (na - nb != 1); - return nb; -} - - -/*---------------------------------------------------*/ -static -void unRLE_obuf_to_output_SMALL ( DState* s ) -{ - UChar k1; - - if (s->blockRandomised) { - - while (True) { - /* try to finish existing run */ - while (True) { - if (s->strm->avail_out == 0) return; - if (s->state_out_len == 0) break; - *( (UChar*)(s->strm->next_out) ) = s->state_out_ch; - BZ_UPDATE_CRC ( s->calculatedBlockCRC, s->state_out_ch ); - s->state_out_len--; - s->strm->next_out++; - s->strm->avail_out--; - s->strm->total_out_lo32++; - if (s->strm->total_out_lo32 == 0) s->strm->total_out_hi32++; - } - - /* can a new run be started? */ - if (s->nblock_used == s->save_nblock+1) return; - - - s->state_out_len = 1; - s->state_out_ch = s->k0; - BZ_GET_SMALL(k1); BZ_RAND_UPD_MASK; - k1 ^= BZ_RAND_MASK; s->nblock_used++; - if (s->nblock_used == s->save_nblock+1) continue; - if (k1 != s->k0) { s->k0 = k1; continue; }; - - s->state_out_len = 2; - BZ_GET_SMALL(k1); BZ_RAND_UPD_MASK; - k1 ^= BZ_RAND_MASK; s->nblock_used++; - if (s->nblock_used == s->save_nblock+1) continue; - if (k1 != s->k0) { s->k0 = k1; continue; }; - - s->state_out_len = 3; - BZ_GET_SMALL(k1); BZ_RAND_UPD_MASK; - k1 ^= BZ_RAND_MASK; s->nblock_used++; - if (s->nblock_used == s->save_nblock+1) continue; - if (k1 != s->k0) { s->k0 = k1; continue; }; - - BZ_GET_SMALL(k1); BZ_RAND_UPD_MASK; - k1 ^= BZ_RAND_MASK; s->nblock_used++; - s->state_out_len = ((Int32)k1) + 4; - BZ_GET_SMALL(s->k0); BZ_RAND_UPD_MASK; - s->k0 ^= BZ_RAND_MASK; s->nblock_used++; - } - - } else { - - while (True) { - /* try to finish existing run */ - while (True) { - if (s->strm->avail_out == 0) return; - if (s->state_out_len == 0) break; - *( (UChar*)(s->strm->next_out) ) = s->state_out_ch; - BZ_UPDATE_CRC ( s->calculatedBlockCRC, s->state_out_ch ); - s->state_out_len--; - s->strm->next_out++; - s->strm->avail_out--; - s->strm->total_out_lo32++; - if (s->strm->total_out_lo32 == 0) s->strm->total_out_hi32++; - } - - /* can a new run be started? */ - if (s->nblock_used == s->save_nblock+1) return; - - s->state_out_len = 1; - s->state_out_ch = s->k0; - BZ_GET_SMALL(k1); s->nblock_used++; - if (s->nblock_used == s->save_nblock+1) continue; - if (k1 != s->k0) { s->k0 = k1; continue; }; - - s->state_out_len = 2; - BZ_GET_SMALL(k1); s->nblock_used++; - if (s->nblock_used == s->save_nblock+1) continue; - if (k1 != s->k0) { s->k0 = k1; continue; }; - - s->state_out_len = 3; - BZ_GET_SMALL(k1); s->nblock_used++; - if (s->nblock_used == s->save_nblock+1) continue; - if (k1 != s->k0) { s->k0 = k1; continue; }; - - BZ_GET_SMALL(k1); s->nblock_used++; - s->state_out_len = ((Int32)k1) + 4; - BZ_GET_SMALL(s->k0); s->nblock_used++; - } - - } -} - - -/*---------------------------------------------------*/ -int BZ_API(BZ2_bzDecompress) ( bz_stream *strm ) -{ - DState* s; - if (strm == NULL) return BZ_PARAM_ERROR; - s = strm->state; - if (s == NULL) return BZ_PARAM_ERROR; - if (s->strm != strm) return BZ_PARAM_ERROR; - - while (True) { - if (s->state == BZ_X_IDLE) return BZ_SEQUENCE_ERROR; - if (s->state == BZ_X_OUTPUT) { - if (s->smallDecompress) - unRLE_obuf_to_output_SMALL ( s ); else - unRLE_obuf_to_output_FAST ( s ); - if (s->nblock_used == s->save_nblock+1 && s->state_out_len == 0) { - BZ_FINALISE_CRC ( s->calculatedBlockCRC ); - if (s->verbosity >= 3) - VPrintf2 ( " {0x%x, 0x%x}", s->storedBlockCRC, - s->calculatedBlockCRC ); - if (s->verbosity >= 2) VPrintf0 ( "]" ); - if (s->calculatedBlockCRC != s->storedBlockCRC) - return BZ_DATA_ERROR; - s->calculatedCombinedCRC - = (s->calculatedCombinedCRC << 1) | - (s->calculatedCombinedCRC >> 31); - s->calculatedCombinedCRC ^= s->calculatedBlockCRC; - s->state = BZ_X_BLKHDR_1; - } else { - return BZ_OK; - } - } - if (s->state >= BZ_X_MAGIC_1) { - Int32 r = BZ2_decompress ( s ); - if (r == BZ_STREAM_END) { - if (s->verbosity >= 3) - VPrintf2 ( "\n combined CRCs: stored = 0x%x, computed = 0x%x", - s->storedCombinedCRC, s->calculatedCombinedCRC ); - if (s->calculatedCombinedCRC != s->storedCombinedCRC) - return BZ_DATA_ERROR; - return r; - } - if (s->state != BZ_X_OUTPUT) return r; - } - } - - AssertH ( 0, 6001 ); - - return 0; /*NOTREACHED*/ -} - - -/*---------------------------------------------------*/ -int BZ_API(BZ2_bzDecompressEnd) ( bz_stream *strm ) -{ - DState* s; - if (strm == NULL) return BZ_PARAM_ERROR; - s = strm->state; - if (s == NULL) return BZ_PARAM_ERROR; - if (s->strm != strm) return BZ_PARAM_ERROR; - - if (s->tt != NULL) BZFREE(s->tt); - if (s->ll16 != NULL) BZFREE(s->ll16); - if (s->ll4 != NULL) BZFREE(s->ll4); - - BZFREE(strm->state); - strm->state = NULL; - - return BZ_OK; -} - - -#ifndef BZ_NO_STDIO -/*---------------------------------------------------*/ -/*--- File I/O stuff ---*/ -/*---------------------------------------------------*/ - -#define BZ_SETERR(eee) \ -{ \ - if (bzerror != NULL) *bzerror = eee; \ - if (bzf != NULL) bzf->lastErr = eee; \ -} - -typedef - struct { - FILE* handle; - Char buf[BZ_MAX_UNUSED]; - Int32 bufN; - Bool writing; - bz_stream strm; - Int32 lastErr; - Bool initialisedOk; - } - bzFile; - - -/*---------------------------------------------*/ -static Bool myfeof ( FILE* f ) -{ - return feof(f) ? True : False; -} - - -/*---------------------------------------------------*/ -BZFILE* BZ_API(BZ2_bzWriteOpen) - ( int* bzerror, - FILE* f, - int blockSize100k, - int verbosity, - int workFactor ) -{ - Int32 ret; - bzFile* bzf = NULL; - - BZ_SETERR(BZ_OK); - - if (f == NULL || - (blockSize100k < 1 || blockSize100k > 9) || - (workFactor < 0 || workFactor > 250) || - (verbosity < 0 || verbosity > 4)) - { BZ_SETERR(BZ_PARAM_ERROR); return NULL; }; - - if (ferror(f)) - { BZ_SETERR(BZ_IO_ERROR); return NULL; }; - - bzf = malloc ( sizeof(bzFile) ); - if (bzf == NULL) - { BZ_SETERR(BZ_MEM_ERROR); return NULL; }; - - BZ_SETERR(BZ_OK); - bzf->initialisedOk = False; - bzf->bufN = 0; - bzf->handle = f; - bzf->writing = True; - bzf->strm.bzalloc = NULL; - bzf->strm.bzfree = NULL; - bzf->strm.opaque = NULL; - - if (workFactor == 0) workFactor = 30; - ret = BZ2_bzCompressInit ( &(bzf->strm), blockSize100k, - verbosity, workFactor ); - if (ret != BZ_OK) - { BZ_SETERR(ret); free(bzf); return NULL; }; - - bzf->strm.avail_in = 0; - bzf->initialisedOk = True; - return bzf; -} - - - -/*---------------------------------------------------*/ -void BZ_API(BZ2_bzWrite) - ( int* bzerror, - BZFILE* b, - void* buf, - int len ) -{ - Int32 n, n2, ret; - bzFile* bzf = (bzFile*)b; - - BZ_SETERR(BZ_OK); - if (bzf == NULL || buf == NULL || len < 0) - { BZ_SETERR(BZ_PARAM_ERROR); return; }; - if (!(bzf->writing)) - { BZ_SETERR(BZ_SEQUENCE_ERROR); return; }; - if (ferror(bzf->handle)) - { BZ_SETERR(BZ_IO_ERROR); return; }; - - if (len == 0) - { BZ_SETERR(BZ_OK); return; }; - - bzf->strm.avail_in = len; - bzf->strm.next_in = buf; - - while (True) { - bzf->strm.avail_out = BZ_MAX_UNUSED; - bzf->strm.next_out = bzf->buf; - ret = BZ2_bzCompress ( &(bzf->strm), BZ_RUN ); - if (ret != BZ_RUN_OK) - { BZ_SETERR(ret); return; }; - - if (bzf->strm.avail_out < BZ_MAX_UNUSED) { - n = BZ_MAX_UNUSED - bzf->strm.avail_out; - n2 = fwrite ( (void*)(bzf->buf), sizeof(UChar), - n, bzf->handle ); - if (n != n2 || ferror(bzf->handle)) - { BZ_SETERR(BZ_IO_ERROR); return; }; - } - - if (bzf->strm.avail_in == 0) - { BZ_SETERR(BZ_OK); return; }; - } -} - - -/*---------------------------------------------------*/ -void BZ_API(BZ2_bzWriteClose) - ( int* bzerror, - BZFILE* b, - int abandon, - unsigned int* nbytes_in, - unsigned int* nbytes_out ) -{ - BZ2_bzWriteClose64 ( bzerror, b, abandon, - nbytes_in, NULL, nbytes_out, NULL ); -} - - -void BZ_API(BZ2_bzWriteClose64) - ( int* bzerror, - BZFILE* b, - int abandon, - unsigned int* nbytes_in_lo32, - unsigned int* nbytes_in_hi32, - unsigned int* nbytes_out_lo32, - unsigned int* nbytes_out_hi32 ) -{ - Int32 n, n2, ret; - bzFile* bzf = (bzFile*)b; - - if (bzf == NULL) - { BZ_SETERR(BZ_OK); return; }; - if (!(bzf->writing)) - { BZ_SETERR(BZ_SEQUENCE_ERROR); return; }; - if (ferror(bzf->handle)) - { BZ_SETERR(BZ_IO_ERROR); return; }; - - if (nbytes_in_lo32 != NULL) *nbytes_in_lo32 = 0; - if (nbytes_in_hi32 != NULL) *nbytes_in_hi32 = 0; - if (nbytes_out_lo32 != NULL) *nbytes_out_lo32 = 0; - if (nbytes_out_hi32 != NULL) *nbytes_out_hi32 = 0; - - if ((!abandon) && bzf->lastErr == BZ_OK) { - while (True) { - bzf->strm.avail_out = BZ_MAX_UNUSED; - bzf->strm.next_out = bzf->buf; - ret = BZ2_bzCompress ( &(bzf->strm), BZ_FINISH ); - if (ret != BZ_FINISH_OK && ret != BZ_STREAM_END) - { BZ_SETERR(ret); return; }; - - if (bzf->strm.avail_out < BZ_MAX_UNUSED) { - n = BZ_MAX_UNUSED - bzf->strm.avail_out; - n2 = fwrite ( (void*)(bzf->buf), sizeof(UChar), - n, bzf->handle ); - if (n != n2 || ferror(bzf->handle)) - { BZ_SETERR(BZ_IO_ERROR); return; }; - } - - if (ret == BZ_STREAM_END) break; - } - } - - if ( !abandon && !ferror ( bzf->handle ) ) { - fflush ( bzf->handle ); - if (ferror(bzf->handle)) - { BZ_SETERR(BZ_IO_ERROR); return; }; - } - - if (nbytes_in_lo32 != NULL) - *nbytes_in_lo32 = bzf->strm.total_in_lo32; - if (nbytes_in_hi32 != NULL) - *nbytes_in_hi32 = bzf->strm.total_in_hi32; - if (nbytes_out_lo32 != NULL) - *nbytes_out_lo32 = bzf->strm.total_out_lo32; - if (nbytes_out_hi32 != NULL) - *nbytes_out_hi32 = bzf->strm.total_out_hi32; - - BZ_SETERR(BZ_OK); - BZ2_bzCompressEnd ( &(bzf->strm) ); - free ( bzf ); -} - - -/*---------------------------------------------------*/ -BZFILE* BZ_API(BZ2_bzReadOpen) - ( int* bzerror, - FILE* f, - int verbosity, - int small, - void* unused, - int nUnused ) -{ - bzFile* bzf = NULL; - int ret; - - BZ_SETERR(BZ_OK); - - if (f == NULL || - (small != 0 && small != 1) || - (verbosity < 0 || verbosity > 4) || - (unused == NULL && nUnused != 0) || - (unused != NULL && (nUnused < 0 || nUnused > BZ_MAX_UNUSED))) - { BZ_SETERR(BZ_PARAM_ERROR); return NULL; }; - - if (ferror(f)) - { BZ_SETERR(BZ_IO_ERROR); return NULL; }; - - bzf = malloc ( sizeof(bzFile) ); - if (bzf == NULL) - { BZ_SETERR(BZ_MEM_ERROR); return NULL; }; - - BZ_SETERR(BZ_OK); - - bzf->initialisedOk = False; - bzf->handle = f; - bzf->bufN = 0; - bzf->writing = False; - bzf->strm.bzalloc = NULL; - bzf->strm.bzfree = NULL; - bzf->strm.opaque = NULL; - - while (nUnused > 0) { - bzf->buf[bzf->bufN] = *((UChar*)(unused)); bzf->bufN++; - unused = ((void*)( 1 + ((UChar*)(unused)) )); - nUnused--; - } - - ret = BZ2_bzDecompressInit ( &(bzf->strm), verbosity, small ); - if (ret != BZ_OK) - { BZ_SETERR(ret); free(bzf); return NULL; }; - - bzf->strm.avail_in = bzf->bufN; - bzf->strm.next_in = bzf->buf; - - bzf->initialisedOk = True; - return bzf; -} - - -/*---------------------------------------------------*/ -void BZ_API(BZ2_bzReadClose) ( int *bzerror, BZFILE *b ) -{ - bzFile* bzf = (bzFile*)b; - - BZ_SETERR(BZ_OK); - if (bzf == NULL) - { BZ_SETERR(BZ_OK); return; }; - - if (bzf->writing) - { BZ_SETERR(BZ_SEQUENCE_ERROR); return; }; - - if (bzf->initialisedOk) - (void)BZ2_bzDecompressEnd ( &(bzf->strm) ); - free ( bzf ); -} - - -/*---------------------------------------------------*/ -int BZ_API(BZ2_bzRead) - ( int* bzerror, - BZFILE* b, - void* buf, - int len ) -{ - Int32 n, ret; - bzFile* bzf = (bzFile*)b; - - BZ_SETERR(BZ_OK); - - if (bzf == NULL || buf == NULL || len < 0) - { BZ_SETERR(BZ_PARAM_ERROR); return 0; }; - - if (bzf->writing) - { BZ_SETERR(BZ_SEQUENCE_ERROR); return 0; }; - - if (len == 0) - { BZ_SETERR(BZ_OK); return 0; }; - - bzf->strm.avail_out = len; - bzf->strm.next_out = buf; - - while (True) { - - if (ferror(bzf->handle)) - { BZ_SETERR(BZ_IO_ERROR); return 0; }; - - if (bzf->strm.avail_in == 0 && !myfeof(bzf->handle)) { - n = fread ( bzf->buf, sizeof(UChar), - BZ_MAX_UNUSED, bzf->handle ); - if (ferror(bzf->handle)) - { BZ_SETERR(BZ_IO_ERROR); return 0; }; - bzf->bufN = n; - bzf->strm.avail_in = bzf->bufN; - bzf->strm.next_in = bzf->buf; - } - - ret = BZ2_bzDecompress ( &(bzf->strm) ); - - if (ret != BZ_OK && ret != BZ_STREAM_END) - { BZ_SETERR(ret); return 0; }; - - if (ret == BZ_OK && myfeof(bzf->handle) && - bzf->strm.avail_in == 0 && bzf->strm.avail_out > 0) - { BZ_SETERR(BZ_UNEXPECTED_EOF); return 0; }; - - if (ret == BZ_STREAM_END) - { BZ_SETERR(BZ_STREAM_END); - return len - bzf->strm.avail_out; }; - if (bzf->strm.avail_out == 0) - { BZ_SETERR(BZ_OK); return len; }; - - } - - return 0; /*not reached*/ -} - - -/*---------------------------------------------------*/ -void BZ_API(BZ2_bzReadGetUnused) - ( int* bzerror, - BZFILE* b, - void** unused, - int* nUnused ) -{ - bzFile* bzf = (bzFile*)b; - if (bzf == NULL) - { BZ_SETERR(BZ_PARAM_ERROR); return; }; - if (bzf->lastErr != BZ_STREAM_END) - { BZ_SETERR(BZ_SEQUENCE_ERROR); return; }; - if (unused == NULL || nUnused == NULL) - { BZ_SETERR(BZ_PARAM_ERROR); return; }; - - BZ_SETERR(BZ_OK); - *nUnused = bzf->strm.avail_in; - *unused = bzf->strm.next_in; -} -#endif - - -/*---------------------------------------------------*/ -/*--- Misc convenience stuff ---*/ -/*---------------------------------------------------*/ - -/*---------------------------------------------------*/ -int BZ_API(BZ2_bzBuffToBuffCompress) - ( char* dest, - unsigned int* destLen, - char* source, - unsigned int sourceLen, - int blockSize100k, - int verbosity, - int workFactor ) -{ - bz_stream strm; - int ret; - - if (dest == NULL || destLen == NULL || - source == NULL || - blockSize100k < 1 || blockSize100k > 9 || - verbosity < 0 || verbosity > 4 || - workFactor < 0 || workFactor > 250) - return BZ_PARAM_ERROR; - - if (workFactor == 0) workFactor = 30; - strm.bzalloc = NULL; - strm.bzfree = NULL; - strm.opaque = NULL; - ret = BZ2_bzCompressInit ( &strm, blockSize100k, - verbosity, workFactor ); - if (ret != BZ_OK) return ret; - - strm.next_in = source; - strm.next_out = dest; - strm.avail_in = sourceLen; - strm.avail_out = *destLen; - - ret = BZ2_bzCompress ( &strm, BZ_FINISH ); - if (ret == BZ_FINISH_OK) goto output_overflow; - if (ret != BZ_STREAM_END) goto errhandler; - - /* normal termination */ - *destLen -= strm.avail_out; - BZ2_bzCompressEnd ( &strm ); - return BZ_OK; - - output_overflow: - BZ2_bzCompressEnd ( &strm ); - return BZ_OUTBUFF_FULL; - - errhandler: - BZ2_bzCompressEnd ( &strm ); - return ret; -} - - -/*---------------------------------------------------*/ -int BZ_API(BZ2_bzBuffToBuffDecompress) - ( char* dest, - unsigned int* destLen, - char* source, - unsigned int sourceLen, - int small, - int verbosity ) -{ - bz_stream strm; - int ret; - - if (dest == NULL || destLen == NULL || - source == NULL || - (small != 0 && small != 1) || - verbosity < 0 || verbosity > 4) - return BZ_PARAM_ERROR; - - strm.bzalloc = NULL; - strm.bzfree = NULL; - strm.opaque = NULL; - ret = BZ2_bzDecompressInit ( &strm, verbosity, small ); - if (ret != BZ_OK) return ret; - - strm.next_in = source; - strm.next_out = dest; - strm.avail_in = sourceLen; - strm.avail_out = *destLen; - - ret = BZ2_bzDecompress ( &strm ); - if (ret == BZ_OK) goto output_overflow_or_eof; - if (ret != BZ_STREAM_END) goto errhandler; - - /* normal termination */ - *destLen -= strm.avail_out; - BZ2_bzDecompressEnd ( &strm ); - return BZ_OK; - - output_overflow_or_eof: - if (strm.avail_out > 0) { - BZ2_bzDecompressEnd ( &strm ); - return BZ_UNEXPECTED_EOF; - } else { - BZ2_bzDecompressEnd ( &strm ); - return BZ_OUTBUFF_FULL; - }; - - errhandler: - BZ2_bzDecompressEnd ( &strm ); - return ret; -} - - -/*---------------------------------------------------*/ -/*-- - Code contributed by Yoshioka Tsuneo - (QWF00133@niftyserve.or.jp/tsuneo-y@is.aist-nara.ac.jp), - to support better zlib compatibility. - This code is not _officially_ part of libbzip2 (yet); - I haven't tested it, documented it, or considered the - threading-safeness of it. - If this code breaks, please contact both Yoshioka and me. ---*/ -/*---------------------------------------------------*/ - -/*---------------------------------------------------*/ -/*-- - return version like "0.9.0c". ---*/ -const char * BZ_API(BZ2_bzlibVersion)(void) -{ - return BZ_VERSION; -} - - -#ifndef BZ_NO_STDIO -/*---------------------------------------------------*/ - -#if defined(_WIN32) || defined(OS2) || defined(MSDOS) -# include <fcntl.h> -# include <io.h> -# define SET_BINARY_MODE(file) setmode(fileno(file),O_BINARY) -#else -# define SET_BINARY_MODE(file) -#endif -static -BZFILE * bzopen_or_bzdopen - ( const char *path, /* no use when bzdopen */ - int fd, /* no use when bzdopen */ - const char *mode, - int open_mode) /* bzopen: 0, bzdopen:1 */ -{ - int bzerr; - char unused[BZ_MAX_UNUSED]; - int blockSize100k = 9; - int writing = 0; - char mode2[10] = ""; - FILE *fp = NULL; - BZFILE *bzfp = NULL; - int verbosity = 0; - int workFactor = 30; - int smallMode = 0; - int nUnused = 0; - - if (mode == NULL) return NULL; - while (*mode) { - switch (*mode) { - case 'r': - writing = 0; break; - case 'w': - writing = 1; break; - case 's': - smallMode = 1; break; - default: - if (isdigit((int)(*mode))) { - blockSize100k = *mode-'0'; - } - } - mode++; - } - strcat(mode2, writing ? "w" : "r" ); - strcat(mode2,"b"); /* binary mode */ - - if (open_mode==0) { - if (path==NULL || strcmp(path,"")==0) { - fp = (writing ? stdout : stdin); - SET_BINARY_MODE(fp); - } else { - fp = fopen(path,mode2); - } - } else { -#ifdef BZ_STRICT_ANSI - fp = NULL; -#else - fp = fdopen(fd,mode2); -#endif - } - if (fp == NULL) return NULL; - - if (writing) { - /* Guard against total chaos and anarchy -- JRS */ - if (blockSize100k < 1) blockSize100k = 1; - if (blockSize100k > 9) blockSize100k = 9; - bzfp = BZ2_bzWriteOpen(&bzerr,fp,blockSize100k, - verbosity,workFactor); - } else { - bzfp = BZ2_bzReadOpen(&bzerr,fp,verbosity,smallMode, - unused,nUnused); - } - if (bzfp == NULL) { - if (fp != stdin && fp != stdout) fclose(fp); - return NULL; - } - return bzfp; -} - - -/*---------------------------------------------------*/ -/*-- - open file for read or write. - ex) bzopen("file","w9") - case path="" or NULL => use stdin or stdout. ---*/ -BZFILE * BZ_API(BZ2_bzopen) - ( const char *path, - const char *mode ) -{ - return bzopen_or_bzdopen(path,-1,mode,/*bzopen*/0); -} - - -/*---------------------------------------------------*/ -BZFILE * BZ_API(BZ2_bzdopen) - ( int fd, - const char *mode ) -{ - return bzopen_or_bzdopen(NULL,fd,mode,/*bzdopen*/1); -} - - -/*---------------------------------------------------*/ -int BZ_API(BZ2_bzread) (BZFILE* b, void* buf, int len ) -{ - int bzerr, nread; - if (((bzFile*)b)->lastErr == BZ_STREAM_END) return 0; - nread = BZ2_bzRead(&bzerr,b,buf,len); - if (bzerr == BZ_OK || bzerr == BZ_STREAM_END) { - return nread; - } else { - return -1; - } -} - - -/*---------------------------------------------------*/ -int BZ_API(BZ2_bzwrite) (BZFILE* b, void* buf, int len ) -{ - int bzerr; - - BZ2_bzWrite(&bzerr,b,buf,len); - if(bzerr == BZ_OK){ - return len; - }else{ - return -1; - } -} - - -/*---------------------------------------------------*/ -int BZ_API(BZ2_bzflush) (BZFILE *b __attribute__ ((unused))) -{ - /* do nothing now... */ - return 0; -} - - -/*---------------------------------------------------*/ -void BZ_API(BZ2_bzclose) (BZFILE* b) -{ - int bzerr; - FILE *fp = ((bzFile *)b)->handle; - - if (b==NULL) {return;} - if(((bzFile*)b)->writing){ - BZ2_bzWriteClose(&bzerr,b,0,NULL,NULL); - if(bzerr != BZ_OK){ - BZ2_bzWriteClose(NULL,b,1,NULL,NULL); - } - }else{ - BZ2_bzReadClose(&bzerr,b); - } - if(fp!=stdin && fp!=stdout){ - fclose(fp); - } -} - - -/*---------------------------------------------------*/ -/*-- - return last error code ---*/ -static char *bzerrorstrings[] = { - "OK" - ,"SEQUENCE_ERROR" - ,"PARAM_ERROR" - ,"MEM_ERROR" - ,"DATA_ERROR" - ,"DATA_ERROR_MAGIC" - ,"IO_ERROR" - ,"UNEXPECTED_EOF" - ,"OUTBUFF_FULL" - ,"CONFIG_ERROR" - ,"???" /* for future */ - ,"???" /* for future */ - ,"???" /* for future */ - ,"???" /* for future */ - ,"???" /* for future */ - ,"???" /* for future */ -}; - - -const char * BZ_API(BZ2_bzerror) (BZFILE *b, int *errnum) -{ - int err = ((bzFile *)b)->lastErr; - - if(err>0) err = 0; - *errnum = err; - return bzerrorstrings[err*-1]; -} -#endif - - -/*-------------------------------------------------------------*/ -/*--- end bzlib.c ---*/ -/*-------------------------------------------------------------*/ diff --git a/mdk-stage1/bzlib/bzlib.h b/mdk-stage1/bzlib/bzlib.h deleted file mode 100644 index c9447a295..000000000 --- a/mdk-stage1/bzlib/bzlib.h +++ /dev/null @@ -1,319 +0,0 @@ - -/*-------------------------------------------------------------*/ -/*--- Public header file for the library. ---*/ -/*--- bzlib.h ---*/ -/*-------------------------------------------------------------*/ - -/*-- - This file is a part of bzip2 and/or libbzip2, a program and - library for lossless, block-sorting data compression. - - Copyright (C) 1996-2000 Julian R Seward. All rights reserved. - - Redistribution and use in source and binary forms, with or without - modification, are permitted provided that the following conditions - are met: - - 1. Redistributions of source code must retain the above copyright - notice, this list of conditions and the following disclaimer. - - 2. The origin of this software must not be misrepresented; you must - not claim that you wrote the original software. If you use this - software in a product, an acknowledgment in the product - documentation would be appreciated but is not required. - - 3. Altered source versions must be plainly marked as such, and must - not be misrepresented as being the original software. - - 4. The name of the author may not be used to endorse or promote - products derived from this software without specific prior written - permission. - - THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS - OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED - WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY - DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE - GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS - INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, - WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING - NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS - SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - - Julian Seward, Cambridge, UK. - jseward@acm.org - bzip2/libbzip2 version 1.0 of 21 March 2000 - - This program is based on (at least) the work of: - Mike Burrows - David Wheeler - Peter Fenwick - Alistair Moffat - Radford Neal - Ian H. Witten - Robert Sedgewick - Jon L. Bentley - - For more information on these sources, see the manual. ---*/ - - -#ifndef _BZLIB_H -#define _BZLIB_H - -#ifdef __cplusplus -extern "C" { -#endif - -#define BZ_RUN 0 -#define BZ_FLUSH 1 -#define BZ_FINISH 2 - -#define BZ_OK 0 -#define BZ_RUN_OK 1 -#define BZ_FLUSH_OK 2 -#define BZ_FINISH_OK 3 -#define BZ_STREAM_END 4 -#define BZ_SEQUENCE_ERROR (-1) -#define BZ_PARAM_ERROR (-2) -#define BZ_MEM_ERROR (-3) -#define BZ_DATA_ERROR (-4) -#define BZ_DATA_ERROR_MAGIC (-5) -#define BZ_IO_ERROR (-6) -#define BZ_UNEXPECTED_EOF (-7) -#define BZ_OUTBUFF_FULL (-8) -#define BZ_CONFIG_ERROR (-9) - -typedef - struct { - char *next_in; - unsigned int avail_in; - unsigned int total_in_lo32; - unsigned int total_in_hi32; - - char *next_out; - unsigned int avail_out; - unsigned int total_out_lo32; - unsigned int total_out_hi32; - - void *state; - - void *(*bzalloc)(void *,int,int); - void (*bzfree)(void *,void *); - void *opaque; - } - bz_stream; - - -#ifndef BZ_IMPORT -#define BZ_EXPORT -#endif - -#ifdef _WIN32 -# include <stdio.h> -# include <windows.h> -# ifdef small - /* windows.h define small to char */ -# undef small -# endif -# ifdef BZ_EXPORT -# define BZ_API(func) WINAPI func -# define BZ_EXTERN extern -# else - /* import windows dll dynamically */ -# define BZ_API(func) (WINAPI * func) -# define BZ_EXTERN -# endif -#else -# define BZ_API(func) func -# define BZ_EXTERN extern -#endif - - -/*-- Core (low-level) library functions --*/ - -BZ_EXTERN int BZ_API(BZ2_bzCompressInit) ( - bz_stream* strm, - int blockSize100k, - int verbosity, - int workFactor - ); - -BZ_EXTERN int BZ_API(BZ2_bzCompress) ( - bz_stream* strm, - int action - ); - -BZ_EXTERN int BZ_API(BZ2_bzCompressEnd) ( - bz_stream* strm - ); - -BZ_EXTERN int BZ_API(BZ2_bzDecompressInit) ( - bz_stream *strm, - int verbosity, - int small - ); - -BZ_EXTERN int BZ_API(BZ2_bzDecompress) ( - bz_stream* strm - ); - -BZ_EXTERN int BZ_API(BZ2_bzDecompressEnd) ( - bz_stream *strm - ); - - - -/*-- High(er) level library functions --*/ - -#ifndef BZ_NO_STDIO -#define BZ_MAX_UNUSED 5000 - -typedef void BZFILE; - -BZ_EXTERN BZFILE* BZ_API(BZ2_bzReadOpen) ( - int* bzerror, - FILE* f, - int verbosity, - int small, - void* unused, - int nUnused - ); - -BZ_EXTERN void BZ_API(BZ2_bzReadClose) ( - int* bzerror, - BZFILE* b - ); - -BZ_EXTERN void BZ_API(BZ2_bzReadGetUnused) ( - int* bzerror, - BZFILE* b, - void** unused, - int* nUnused - ); - -BZ_EXTERN int BZ_API(BZ2_bzRead) ( - int* bzerror, - BZFILE* b, - void* buf, - int len - ); - -BZ_EXTERN BZFILE* BZ_API(BZ2_bzWriteOpen) ( - int* bzerror, - FILE* f, - int blockSize100k, - int verbosity, - int workFactor - ); - -BZ_EXTERN void BZ_API(BZ2_bzWrite) ( - int* bzerror, - BZFILE* b, - void* buf, - int len - ); - -BZ_EXTERN void BZ_API(BZ2_bzWriteClose) ( - int* bzerror, - BZFILE* b, - int abandon, - unsigned int* nbytes_in, - unsigned int* nbytes_out - ); - -BZ_EXTERN void BZ_API(BZ2_bzWriteClose64) ( - int* bzerror, - BZFILE* b, - int abandon, - unsigned int* nbytes_in_lo32, - unsigned int* nbytes_in_hi32, - unsigned int* nbytes_out_lo32, - unsigned int* nbytes_out_hi32 - ); -#endif - - -/*-- Utility functions --*/ - -BZ_EXTERN int BZ_API(BZ2_bzBuffToBuffCompress) ( - char* dest, - unsigned int* destLen, - char* source, - unsigned int sourceLen, - int blockSize100k, - int verbosity, - int workFactor - ); - -BZ_EXTERN int BZ_API(BZ2_bzBuffToBuffDecompress) ( - char* dest, - unsigned int* destLen, - char* source, - unsigned int sourceLen, - int small, - int verbosity - ); - - -/*-- - Code contributed by Yoshioka Tsuneo - (QWF00133@niftyserve.or.jp/tsuneo-y@is.aist-nara.ac.jp), - to support better zlib compatibility. - This code is not _officially_ part of libbzip2 (yet); - I haven't tested it, documented it, or considered the - threading-safeness of it. - If this code breaks, please contact both Yoshioka and me. ---*/ - -BZ_EXTERN const char * BZ_API(BZ2_bzlibVersion) ( - void - ); - -#ifndef BZ_NO_STDIO -BZ_EXTERN BZFILE * BZ_API(BZ2_bzopen) ( - const char *path, - const char *mode - ); - -BZ_EXTERN BZFILE * BZ_API(BZ2_bzdopen) ( - int fd, - const char *mode - ); - -BZ_EXTERN int BZ_API(BZ2_bzread) ( - BZFILE* b, - void* buf, - int len - ); - -BZ_EXTERN int BZ_API(BZ2_bzwrite) ( - BZFILE* b, - void* buf, - int len - ); - -BZ_EXTERN int BZ_API(BZ2_bzflush) ( - BZFILE* b - ); - -BZ_EXTERN void BZ_API(BZ2_bzclose) ( - BZFILE* b - ); - -BZ_EXTERN const char * BZ_API(BZ2_bzerror) ( - BZFILE *b, - int *errnum - ); -#endif - -#ifdef __cplusplus -} -#endif - -#endif - -/*-------------------------------------------------------------*/ -/*--- end bzlib.h ---*/ -/*-------------------------------------------------------------*/ diff --git a/mdk-stage1/bzlib/bzlib_private.h b/mdk-stage1/bzlib/bzlib_private.h deleted file mode 100644 index fb51c7a1d..000000000 --- a/mdk-stage1/bzlib/bzlib_private.h +++ /dev/null @@ -1,530 +0,0 @@ - -/*-------------------------------------------------------------*/ -/*--- Private header file for the library. ---*/ -/*--- bzlib_private.h ---*/ -/*-------------------------------------------------------------*/ - -/*-- - This file is a part of bzip2 and/or libbzip2, a program and - library for lossless, block-sorting data compression. - - Copyright (C) 1996-2000 Julian R Seward. All rights reserved. - - Redistribution and use in source and binary forms, with or without - modification, are permitted provided that the following conditions - are met: - - 1. Redistributions of source code must retain the above copyright - notice, this list of conditions and the following disclaimer. - - 2. The origin of this software must not be misrepresented; you must - not claim that you wrote the original software. If you use this - software in a product, an acknowledgment in the product - documentation would be appreciated but is not required. - - 3. Altered source versions must be plainly marked as such, and must - not be misrepresented as being the original software. - - 4. The name of the author may not be used to endorse or promote - products derived from this software without specific prior written - permission. - - THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS - OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED - WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY - DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE - GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS - INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, - WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING - NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS - SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - - Julian Seward, Cambridge, UK. - jseward@acm.org - bzip2/libbzip2 version 1.0 of 21 March 2000 - - This program is based on (at least) the work of: - Mike Burrows - David Wheeler - Peter Fenwick - Alistair Moffat - Radford Neal - Ian H. Witten - Robert Sedgewick - Jon L. Bentley - - For more information on these sources, see the manual. ---*/ - - -#ifndef _BZLIB_PRIVATE_H -#define _BZLIB_PRIVATE_H - -#include <stdlib.h> - -#ifndef BZ_NO_STDIO -#include <stdio.h> -#include <ctype.h> -#include <string.h> -#endif - -#include "bzlib.h" - - - -/*-- General stuff. --*/ - -#define BZ_VERSION "1.0.1, 23-June-2000" - -typedef char Char; -typedef unsigned char Bool; -typedef unsigned char UChar; -typedef int Int32; -typedef unsigned int UInt32; -typedef short Int16; -typedef unsigned short UInt16; - -#define True ((Bool)1) -#define False ((Bool)0) - -#ifndef __GNUC__ -#define __inline__ /* */ -#endif - -#ifndef BZ_NO_STDIO -extern void BZ2_bz__AssertH__fail ( int errcode ); -#define AssertH(cond,errcode) \ - { if (!(cond)) BZ2_bz__AssertH__fail ( errcode ); } -#if BZ_DEBUG -#define AssertD(cond,msg) \ - { if (!(cond)) { \ - fprintf ( stderr, \ - "\n\nlibbzip2(debug build): internal error\n\t%s\n", msg );\ - exit(1); \ - }} -#else -#define AssertD(cond,msg) /* */ -#endif -#define VPrintf0(zf) \ - fprintf(stderr,zf) -#define VPrintf1(zf,za1) \ - fprintf(stderr,zf,za1) -#define VPrintf2(zf,za1,za2) \ - fprintf(stderr,zf,za1,za2) -#define VPrintf3(zf,za1,za2,za3) \ - fprintf(stderr,zf,za1,za2,za3) -#define VPrintf4(zf,za1,za2,za3,za4) \ - fprintf(stderr,zf,za1,za2,za3,za4) -#define VPrintf5(zf,za1,za2,za3,za4,za5) \ - fprintf(stderr,zf,za1,za2,za3,za4,za5) -#else -extern void bz_internal_error ( int errcode ); -#define AssertH(cond,errcode) \ - { if (!(cond)) bz_internal_error ( errcode ); } -#define AssertD(cond,msg) /* */ -#define VPrintf0(zf) /* */ -#define VPrintf1(zf,za1) /* */ -#define VPrintf2(zf,za1,za2) /* */ -#define VPrintf3(zf,za1,za2,za3) /* */ -#define VPrintf4(zf,za1,za2,za3,za4) /* */ -#define VPrintf5(zf,za1,za2,za3,za4,za5) /* */ -#endif - - -#define BZALLOC(nnn) (strm->bzalloc)(strm->opaque,(nnn),1) -#define BZFREE(ppp) (strm->bzfree)(strm->opaque,(ppp)) - - -/*-- Constants for the back end. --*/ - -#define BZ_MAX_ALPHA_SIZE 258 -#define BZ_MAX_CODE_LEN 23 - -#define BZ_RUNA 0 -#define BZ_RUNB 1 - -#define BZ_N_GROUPS 6 -#define BZ_G_SIZE 50 -#define BZ_N_ITERS 4 - -#define BZ_MAX_SELECTORS (2 + (900000 / BZ_G_SIZE)) - - - -/*-- Stuff for randomising repetitive blocks. --*/ - -extern Int32 BZ2_rNums[512]; - -#define BZ_RAND_DECLS \ - Int32 rNToGo; \ - Int32 rTPos \ - -#define BZ_RAND_INIT_MASK \ - s->rNToGo = 0; \ - s->rTPos = 0 \ - -#define BZ_RAND_MASK ((s->rNToGo == 1) ? 1 : 0) - -#define BZ_RAND_UPD_MASK \ - if (s->rNToGo == 0) { \ - s->rNToGo = BZ2_rNums[s->rTPos]; \ - s->rTPos++; \ - if (s->rTPos == 512) s->rTPos = 0; \ - } \ - s->rNToGo--; - - - -/*-- Stuff for doing CRCs. --*/ - -extern UInt32 BZ2_crc32Table[256]; - -#define BZ_INITIALISE_CRC(crcVar) \ -{ \ - crcVar = 0xffffffffL; \ -} - -#define BZ_FINALISE_CRC(crcVar) \ -{ \ - crcVar = ~(crcVar); \ -} - -#define BZ_UPDATE_CRC(crcVar,cha) \ -{ \ - crcVar = (crcVar << 8) ^ \ - BZ2_crc32Table[(crcVar >> 24) ^ \ - ((UChar)cha)]; \ -} - - - -/*-- States and modes for compression. --*/ - -#define BZ_M_IDLE 1 -#define BZ_M_RUNNING 2 -#define BZ_M_FLUSHING 3 -#define BZ_M_FINISHING 4 - -#define BZ_S_OUTPUT 1 -#define BZ_S_INPUT 2 - -#define BZ_N_RADIX 2 -#define BZ_N_QSORT 12 -#define BZ_N_SHELL 18 -#define BZ_N_OVERSHOOT (BZ_N_RADIX + BZ_N_QSORT + BZ_N_SHELL + 2) - - - - -/*-- Structure holding all the compression-side stuff. --*/ - -typedef - struct { - /* pointer back to the struct bz_stream */ - bz_stream* strm; - - /* mode this stream is in, and whether inputting */ - /* or outputting data */ - Int32 mode; - Int32 state; - - /* remembers avail_in when flush/finish requested */ - UInt32 avail_in_expect; - - /* for doing the block sorting */ - UInt32* arr1; - UInt32* arr2; - UInt32* ftab; - Int32 origPtr; - - /* aliases for arr1 and arr2 */ - UInt32* ptr; - UChar* block; - UInt16* mtfv; - UChar* zbits; - - /* for deciding when to use the fallback sorting algorithm */ - Int32 workFactor; - - /* run-length-encoding of the input */ - UInt32 state_in_ch; - Int32 state_in_len; - BZ_RAND_DECLS; - - /* input and output limits and current posns */ - Int32 nblock; - Int32 nblockMAX; - Int32 numZ; - Int32 state_out_pos; - - /* map of bytes used in block */ - Int32 nInUse; - Bool inUse[256]; - UChar unseqToSeq[256]; - - /* the buffer for bit stream creation */ - UInt32 bsBuff; - Int32 bsLive; - - /* block and combined CRCs */ - UInt32 blockCRC; - UInt32 combinedCRC; - - /* misc administratium */ - Int32 verbosity; - Int32 blockNo; - Int32 blockSize100k; - - /* stuff for coding the MTF values */ - Int32 nMTF; - Int32 mtfFreq [BZ_MAX_ALPHA_SIZE]; - UChar selector [BZ_MAX_SELECTORS]; - UChar selectorMtf[BZ_MAX_SELECTORS]; - - UChar len [BZ_N_GROUPS][BZ_MAX_ALPHA_SIZE]; - Int32 code [BZ_N_GROUPS][BZ_MAX_ALPHA_SIZE]; - Int32 rfreq [BZ_N_GROUPS][BZ_MAX_ALPHA_SIZE]; - /* second dimension: only 3 needed; 4 makes index calculations faster */ - UInt32 len_pack[BZ_MAX_ALPHA_SIZE][4]; - - } - EState; - - - -/*-- externs for compression. --*/ - -extern void -BZ2_blockSort ( EState* ); - -extern void -BZ2_compressBlock ( EState*, Bool ); - -extern void -BZ2_bsInitWrite ( EState* ); - -extern void -BZ2_hbAssignCodes ( Int32*, UChar*, Int32, Int32, Int32 ); - -extern void -BZ2_hbMakeCodeLengths ( UChar*, Int32*, Int32, Int32 ); - - - -/*-- states for decompression. --*/ - -#define BZ_X_IDLE 1 -#define BZ_X_OUTPUT 2 - -#define BZ_X_MAGIC_1 10 -#define BZ_X_MAGIC_2 11 -#define BZ_X_MAGIC_3 12 -#define BZ_X_MAGIC_4 13 -#define BZ_X_BLKHDR_1 14 -#define BZ_X_BLKHDR_2 15 -#define BZ_X_BLKHDR_3 16 -#define BZ_X_BLKHDR_4 17 -#define BZ_X_BLKHDR_5 18 -#define BZ_X_BLKHDR_6 19 -#define BZ_X_BCRC_1 20 -#define BZ_X_BCRC_2 21 -#define BZ_X_BCRC_3 22 -#define BZ_X_BCRC_4 23 -#define BZ_X_RANDBIT 24 -#define BZ_X_ORIGPTR_1 25 -#define BZ_X_ORIGPTR_2 26 -#define BZ_X_ORIGPTR_3 27 -#define BZ_X_MAPPING_1 28 -#define BZ_X_MAPPING_2 29 -#define BZ_X_SELECTOR_1 30 -#define BZ_X_SELECTOR_2 31 -#define BZ_X_SELECTOR_3 32 -#define BZ_X_CODING_1 33 -#define BZ_X_CODING_2 34 -#define BZ_X_CODING_3 35 -#define BZ_X_MTF_1 36 -#define BZ_X_MTF_2 37 -#define BZ_X_MTF_3 38 -#define BZ_X_MTF_4 39 -#define BZ_X_MTF_5 40 -#define BZ_X_MTF_6 41 -#define BZ_X_ENDHDR_2 42 -#define BZ_X_ENDHDR_3 43 -#define BZ_X_ENDHDR_4 44 -#define BZ_X_ENDHDR_5 45 -#define BZ_X_ENDHDR_6 46 -#define BZ_X_CCRC_1 47 -#define BZ_X_CCRC_2 48 -#define BZ_X_CCRC_3 49 -#define BZ_X_CCRC_4 50 - - - -/*-- Constants for the fast MTF decoder. --*/ - -#define MTFA_SIZE 4096 -#define MTFL_SIZE 16 - - - -/*-- Structure holding all the decompression-side stuff. --*/ - -typedef - struct { - /* pointer back to the struct bz_stream */ - bz_stream* strm; - - /* state indicator for this stream */ - Int32 state; - - /* for doing the final run-length decoding */ - UChar state_out_ch; - Int32 state_out_len; - Bool blockRandomised; - BZ_RAND_DECLS; - - /* the buffer for bit stream reading */ - UInt32 bsBuff; - Int32 bsLive; - - /* misc administratium */ - Int32 blockSize100k; - Bool smallDecompress; - Int32 currBlockNo; - Int32 verbosity; - - /* for undoing the Burrows-Wheeler transform */ - Int32 origPtr; - UInt32 tPos; - Int32 k0; - Int32 unzftab[256]; - Int32 nblock_used; - Int32 cftab[257]; - Int32 cftabCopy[257]; - - /* for undoing the Burrows-Wheeler transform (FAST) */ - UInt32 *tt; - - /* for undoing the Burrows-Wheeler transform (SMALL) */ - UInt16 *ll16; - UChar *ll4; - - /* stored and calculated CRCs */ - UInt32 storedBlockCRC; - UInt32 storedCombinedCRC; - UInt32 calculatedBlockCRC; - UInt32 calculatedCombinedCRC; - - /* map of bytes used in block */ - Int32 nInUse; - Bool inUse[256]; - Bool inUse16[16]; - UChar seqToUnseq[256]; - - /* for decoding the MTF values */ - UChar mtfa [MTFA_SIZE]; - Int32 mtfbase[256 / MTFL_SIZE]; - UChar selector [BZ_MAX_SELECTORS]; - UChar selectorMtf[BZ_MAX_SELECTORS]; - UChar len [BZ_N_GROUPS][BZ_MAX_ALPHA_SIZE]; - - Int32 limit [BZ_N_GROUPS][BZ_MAX_ALPHA_SIZE]; - Int32 base [BZ_N_GROUPS][BZ_MAX_ALPHA_SIZE]; - Int32 perm [BZ_N_GROUPS][BZ_MAX_ALPHA_SIZE]; - Int32 minLens[BZ_N_GROUPS]; - - /* save area for scalars in the main decompress code */ - Int32 save_i; - Int32 save_j; - Int32 save_t; - Int32 save_alphaSize; - Int32 save_nGroups; - Int32 save_nSelectors; - Int32 save_EOB; - Int32 save_groupNo; - Int32 save_groupPos; - Int32 save_nextSym; - Int32 save_nblockMAX; - Int32 save_nblock; - Int32 save_es; - Int32 save_N; - Int32 save_curr; - Int32 save_zt; - Int32 save_zn; - Int32 save_zvec; - Int32 save_zj; - Int32 save_gSel; - Int32 save_gMinlen; - Int32* save_gLimit; - Int32* save_gBase; - Int32* save_gPerm; - - } - DState; - - - -/*-- Macros for decompression. --*/ - -#define BZ_GET_FAST(cccc) \ - s->tPos = s->tt[s->tPos]; \ - cccc = (UChar)(s->tPos & 0xff); \ - s->tPos >>= 8; - -#define BZ_GET_FAST_C(cccc) \ - c_tPos = c_tt[c_tPos]; \ - cccc = (UChar)(c_tPos & 0xff); \ - c_tPos >>= 8; - -#define SET_LL4(i,n) \ - { if (((i) & 0x1) == 0) \ - s->ll4[(i) >> 1] = (s->ll4[(i) >> 1] & 0xf0) | (n); else \ - s->ll4[(i) >> 1] = (s->ll4[(i) >> 1] & 0x0f) | ((n) << 4); \ - } - -#define GET_LL4(i) \ - ((((UInt32)(s->ll4[(i) >> 1])) >> (((i) << 2) & 0x4)) & 0xF) - -#define SET_LL(i,n) \ - { s->ll16[i] = (UInt16)(n & 0x0000ffff); \ - SET_LL4(i, n >> 16); \ - } - -#define GET_LL(i) \ - (((UInt32)s->ll16[i]) | (GET_LL4(i) << 16)) - -#define BZ_GET_SMALL(cccc) \ - cccc = BZ2_indexIntoF ( s->tPos, s->cftab ); \ - s->tPos = GET_LL(s->tPos); - - -/*-- externs for decompression. --*/ - -extern Int32 -BZ2_indexIntoF ( Int32, Int32* ); - -extern Int32 -BZ2_decompress ( DState* ); - -extern void -BZ2_hbCreateDecodeTables ( Int32*, Int32*, Int32*, UChar*, - Int32, Int32, Int32 ); - - -#endif - - -/*-- BZ_NO_STDIO seems to make NULL disappear on some platforms. --*/ - -#ifdef BZ_NO_STDIO -#ifndef NULL -#define NULL 0 -#endif -#endif - - -/*-------------------------------------------------------------*/ -/*--- end bzlib_private.h ---*/ -/*-------------------------------------------------------------*/ diff --git a/mdk-stage1/bzlib/compress.c b/mdk-stage1/bzlib/compress.c deleted file mode 100644 index 58d5abe7c..000000000 --- a/mdk-stage1/bzlib/compress.c +++ /dev/null @@ -1,720 +0,0 @@ - -/*-------------------------------------------------------------*/ -/*--- Compression machinery (not incl block sorting) ---*/ -/*--- compress.c ---*/ -/*-------------------------------------------------------------*/ - -/*-- - This file is a part of bzip2 and/or libbzip2, a program and - library for lossless, block-sorting data compression. - - Copyright (C) 1996-2000 Julian R Seward. All rights reserved. - - Redistribution and use in source and binary forms, with or without - modification, are permitted provided that the following conditions - are met: - - 1. Redistributions of source code must retain the above copyright - notice, this list of conditions and the following disclaimer. - - 2. The origin of this software must not be misrepresented; you must - not claim that you wrote the original software. If you use this - software in a product, an acknowledgment in the product - documentation would be appreciated but is not required. - - 3. Altered source versions must be plainly marked as such, and must - not be misrepresented as being the original software. - - 4. The name of the author may not be used to endorse or promote - products derived from this software without specific prior written - permission. - - THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS - OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED - WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY - DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE - GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS - INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, - WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING - NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS - SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - - Julian Seward, Cambridge, UK. - jseward@acm.org - bzip2/libbzip2 version 1.0 of 21 March 2000 - - This program is based on (at least) the work of: - Mike Burrows - David Wheeler - Peter Fenwick - Alistair Moffat - Radford Neal - Ian H. Witten - Robert Sedgewick - Jon L. Bentley - - For more information on these sources, see the manual. ---*/ - -/*-- - CHANGES - ~~~~~~~ - 0.9.0 -- original version. - - 0.9.0a/b -- no changes in this file. - - 0.9.0c - * changed setting of nGroups in sendMTFValues() so as to - do a bit better on small files ---*/ - -#ifdef HAVE_CONFIG_H -#include <config.h> -#endif - - - -#include "bzlib_private.h" - - -/*---------------------------------------------------*/ -/*--- Bit stream I/O ---*/ -/*---------------------------------------------------*/ - -/*---------------------------------------------------*/ -void BZ2_bsInitWrite ( EState* s ) -{ - s->bsLive = 0; - s->bsBuff = 0; -} - - -/*---------------------------------------------------*/ -static -void bsFinishWrite ( EState* s ) -{ - while (s->bsLive > 0) { - s->zbits[s->numZ] = (UChar)(s->bsBuff >> 24); - s->numZ++; - s->bsBuff <<= 8; - s->bsLive -= 8; - } -} - - -/*---------------------------------------------------*/ -#define bsNEEDW(nz) \ -{ \ - while (s->bsLive >= 8) { \ - s->zbits[s->numZ] \ - = (UChar)(s->bsBuff >> 24); \ - s->numZ++; \ - s->bsBuff <<= 8; \ - s->bsLive -= 8; \ - } \ -} - - -/*---------------------------------------------------*/ -static -__inline__ -void bsW ( EState* s, Int32 n, UInt32 v ) -{ - bsNEEDW ( n ); - s->bsBuff |= (v << (32 - s->bsLive - n)); - s->bsLive += n; -} - - -/*---------------------------------------------------*/ -static -void bsPutUInt32 ( EState* s, UInt32 u ) -{ - bsW ( s, 8, (u >> 24) & 0xffL ); - bsW ( s, 8, (u >> 16) & 0xffL ); - bsW ( s, 8, (u >> 8) & 0xffL ); - bsW ( s, 8, u & 0xffL ); -} - - -/*---------------------------------------------------*/ -static -void bsPutUChar ( EState* s, UChar c ) -{ - bsW( s, 8, (UInt32)c ); -} - - -/*---------------------------------------------------*/ -/*--- The back end proper ---*/ -/*---------------------------------------------------*/ - -/*---------------------------------------------------*/ -static -void makeMaps_e ( EState* s ) -{ - Int32 i; - s->nInUse = 0; - for (i = 0; i < 256; i++) - if (s->inUse[i]) { - s->unseqToSeq[i] = s->nInUse; - s->nInUse++; - } -} - - -/*---------------------------------------------------*/ -static -void generateMTFValues ( EState* s ) -{ - UChar yy[256]; - Int32 i, j; - Int32 zPend; - Int32 wr; - Int32 EOB; - - /* - After sorting (eg, here), - s->arr1 [ 0 .. s->nblock-1 ] holds sorted order, - and - ((UChar*)s->arr2) [ 0 .. s->nblock-1 ] - holds the original block data. - - The first thing to do is generate the MTF values, - and put them in - ((UInt16*)s->arr1) [ 0 .. s->nblock-1 ]. - Because there are strictly fewer or equal MTF values - than block values, ptr values in this area are overwritten - with MTF values only when they are no longer needed. - - The final compressed bitstream is generated into the - area starting at - (UChar*) (&((UChar*)s->arr2)[s->nblock]) - - These storage aliases are set up in bzCompressInit(), - except for the last one, which is arranged in - compressBlock(). - */ - UInt32* ptr = s->ptr; - UChar* block = s->block; - UInt16* mtfv = s->mtfv; - - makeMaps_e ( s ); - EOB = s->nInUse+1; - - for (i = 0; i <= EOB; i++) s->mtfFreq[i] = 0; - - wr = 0; - zPend = 0; - for (i = 0; i < s->nInUse; i++) yy[i] = (UChar) i; - - for (i = 0; i < s->nblock; i++) { - UChar ll_i; - AssertD ( wr <= i, "generateMTFValues(1)" ); - j = ptr[i]-1; if (j < 0) j += s->nblock; - ll_i = s->unseqToSeq[block[j]]; - AssertD ( ll_i < s->nInUse, "generateMTFValues(2a)" ); - - if (yy[0] == ll_i) { - zPend++; - } else { - - if (zPend > 0) { - zPend--; - while (True) { - if (zPend & 1) { - mtfv[wr] = BZ_RUNB; wr++; - s->mtfFreq[BZ_RUNB]++; - } else { - mtfv[wr] = BZ_RUNA; wr++; - s->mtfFreq[BZ_RUNA]++; - } - if (zPend < 2) break; - zPend = (zPend - 2) / 2; - }; - zPend = 0; - } - { - register UChar rtmp; - register UChar* ryy_j; - register UChar rll_i; - rtmp = yy[1]; - yy[1] = yy[0]; - ryy_j = &(yy[1]); - rll_i = ll_i; - while ( rll_i != rtmp ) { - register UChar rtmp2; - ryy_j++; - rtmp2 = rtmp; - rtmp = *ryy_j; - *ryy_j = rtmp2; - }; - yy[0] = rtmp; - j = ryy_j - &(yy[0]); - mtfv[wr] = j+1; wr++; s->mtfFreq[j+1]++; - } - - } - } - - if (zPend > 0) { - zPend--; - while (True) { - if (zPend & 1) { - mtfv[wr] = BZ_RUNB; wr++; - s->mtfFreq[BZ_RUNB]++; - } else { - mtfv[wr] = BZ_RUNA; wr++; - s->mtfFreq[BZ_RUNA]++; - } - if (zPend < 2) break; - zPend = (zPend - 2) / 2; - }; - zPend = 0; - } - - mtfv[wr] = EOB; wr++; s->mtfFreq[EOB]++; - - s->nMTF = wr; -} - - -/*---------------------------------------------------*/ -#define BZ_LESSER_ICOST 0 -#define BZ_GREATER_ICOST 15 - -static -void sendMTFValues ( EState* s ) -{ - Int32 v, t, i, j, gs, ge, totc, bt, bc, iter; - Int32 nSelectors, alphaSize, minLen, maxLen, selCtr; - Int32 nGroups, nBytes; - - /*-- - UChar len [BZ_N_GROUPS][BZ_MAX_ALPHA_SIZE]; - is a global since the decoder also needs it. - - Int32 code[BZ_N_GROUPS][BZ_MAX_ALPHA_SIZE]; - Int32 rfreq[BZ_N_GROUPS][BZ_MAX_ALPHA_SIZE]; - are also globals only used in this proc. - Made global to keep stack frame size small. - --*/ - - - UInt16 cost[BZ_N_GROUPS]; - Int32 fave[BZ_N_GROUPS]; - - UInt16* mtfv = s->mtfv; - - if (s->verbosity >= 3) - VPrintf3( " %d in block, %d after MTF & 1-2 coding, " - "%d+2 syms in use\n", - s->nblock, s->nMTF, s->nInUse ); - - alphaSize = s->nInUse+2; - for (t = 0; t < BZ_N_GROUPS; t++) - for (v = 0; v < alphaSize; v++) - s->len[t][v] = BZ_GREATER_ICOST; - - /*--- Decide how many coding tables to use ---*/ - AssertH ( s->nMTF > 0, 3001 ); - if (s->nMTF < 200) nGroups = 2; else - if (s->nMTF < 600) nGroups = 3; else - if (s->nMTF < 1200) nGroups = 4; else - if (s->nMTF < 2400) nGroups = 5; else - nGroups = 6; - - /*--- Generate an initial set of coding tables ---*/ - { - Int32 nPart, remF, tFreq, aFreq; - - nPart = nGroups; - remF = s->nMTF; - gs = 0; - while (nPart > 0) { - tFreq = remF / nPart; - ge = gs-1; - aFreq = 0; - while (aFreq < tFreq && ge < alphaSize-1) { - ge++; - aFreq += s->mtfFreq[ge]; - } - - if (ge > gs - && nPart != nGroups && nPart != 1 - && ((nGroups-nPart) % 2 == 1)) { - aFreq -= s->mtfFreq[ge]; - ge--; - } - - if (s->verbosity >= 3) - VPrintf5( " initial group %d, [%d .. %d], " - "has %d syms (%4.1f%%)\n", - nPart, gs, ge, aFreq, - (100.0 * (float)aFreq) / (float)(s->nMTF) ); - - for (v = 0; v < alphaSize; v++) - if (v >= gs && v <= ge) - s->len[nPart-1][v] = BZ_LESSER_ICOST; else - s->len[nPart-1][v] = BZ_GREATER_ICOST; - - nPart--; - gs = ge+1; - remF -= aFreq; - } - } - - /*--- - Iterate up to BZ_N_ITERS times to improve the tables. - ---*/ - for (iter = 0; iter < BZ_N_ITERS; iter++) { - - for (t = 0; t < nGroups; t++) fave[t] = 0; - - for (t = 0; t < nGroups; t++) - for (v = 0; v < alphaSize; v++) - s->rfreq[t][v] = 0; - - /*--- - Set up an auxiliary length table which is used to fast-track - the common case (nGroups == 6). - ---*/ - if (nGroups == 6) { - for (v = 0; v < alphaSize; v++) { - s->len_pack[v][0] = (s->len[1][v] << 16) | s->len[0][v]; - s->len_pack[v][1] = (s->len[3][v] << 16) | s->len[2][v]; - s->len_pack[v][2] = (s->len[5][v] << 16) | s->len[4][v]; - } - } - - nSelectors = 0; - totc = 0; - gs = 0; - while (True) { - - /*--- Set group start & end marks. --*/ - if (gs >= s->nMTF) break; - ge = gs + BZ_G_SIZE - 1; - if (ge >= s->nMTF) ge = s->nMTF-1; - - /*-- - Calculate the cost of this group as coded - by each of the coding tables. - --*/ - for (t = 0; t < nGroups; t++) cost[t] = 0; - - if (nGroups == 6 && 50 == ge-gs+1) { - /*--- fast track the common case ---*/ - register UInt32 cost01, cost23, cost45; - register UInt16 icv; - cost01 = cost23 = cost45 = 0; - -# define BZ_ITER(nn) \ - icv = mtfv[gs+(nn)]; \ - cost01 += s->len_pack[icv][0]; \ - cost23 += s->len_pack[icv][1]; \ - cost45 += s->len_pack[icv][2]; \ - - BZ_ITER(0); BZ_ITER(1); BZ_ITER(2); BZ_ITER(3); BZ_ITER(4); - BZ_ITER(5); BZ_ITER(6); BZ_ITER(7); BZ_ITER(8); BZ_ITER(9); - BZ_ITER(10); BZ_ITER(11); BZ_ITER(12); BZ_ITER(13); BZ_ITER(14); - BZ_ITER(15); BZ_ITER(16); BZ_ITER(17); BZ_ITER(18); BZ_ITER(19); - BZ_ITER(20); BZ_ITER(21); BZ_ITER(22); BZ_ITER(23); BZ_ITER(24); - BZ_ITER(25); BZ_ITER(26); BZ_ITER(27); BZ_ITER(28); BZ_ITER(29); - BZ_ITER(30); BZ_ITER(31); BZ_ITER(32); BZ_ITER(33); BZ_ITER(34); - BZ_ITER(35); BZ_ITER(36); BZ_ITER(37); BZ_ITER(38); BZ_ITER(39); - BZ_ITER(40); BZ_ITER(41); BZ_ITER(42); BZ_ITER(43); BZ_ITER(44); - BZ_ITER(45); BZ_ITER(46); BZ_ITER(47); BZ_ITER(48); BZ_ITER(49); - -# undef BZ_ITER - - cost[0] = cost01 & 0xffff; cost[1] = cost01 >> 16; - cost[2] = cost23 & 0xffff; cost[3] = cost23 >> 16; - cost[4] = cost45 & 0xffff; cost[5] = cost45 >> 16; - - } else { - /*--- slow version which correctly handles all situations ---*/ - for (i = gs; i <= ge; i++) { - UInt16 icv = mtfv[i]; - for (t = 0; t < nGroups; t++) cost[t] += s->len[t][icv]; - } - } - - /*-- - Find the coding table which is best for this group, - and record its identity in the selector table. - --*/ - bc = 999999999; bt = -1; - for (t = 0; t < nGroups; t++) - if (cost[t] < bc) { bc = cost[t]; bt = t; }; - totc += bc; - fave[bt]++; - s->selector[nSelectors] = bt; - nSelectors++; - - /*-- - Increment the symbol frequencies for the selected table. - --*/ - if (nGroups == 6 && 50 == ge-gs+1) { - /*--- fast track the common case ---*/ - -# define BZ_ITUR(nn) s->rfreq[bt][ mtfv[gs+(nn)] ]++ - - BZ_ITUR(0); BZ_ITUR(1); BZ_ITUR(2); BZ_ITUR(3); BZ_ITUR(4); - BZ_ITUR(5); BZ_ITUR(6); BZ_ITUR(7); BZ_ITUR(8); BZ_ITUR(9); - BZ_ITUR(10); BZ_ITUR(11); BZ_ITUR(12); BZ_ITUR(13); BZ_ITUR(14); - BZ_ITUR(15); BZ_ITUR(16); BZ_ITUR(17); BZ_ITUR(18); BZ_ITUR(19); - BZ_ITUR(20); BZ_ITUR(21); BZ_ITUR(22); BZ_ITUR(23); BZ_ITUR(24); - BZ_ITUR(25); BZ_ITUR(26); BZ_ITUR(27); BZ_ITUR(28); BZ_ITUR(29); - BZ_ITUR(30); BZ_ITUR(31); BZ_ITUR(32); BZ_ITUR(33); BZ_ITUR(34); - BZ_ITUR(35); BZ_ITUR(36); BZ_ITUR(37); BZ_ITUR(38); BZ_ITUR(39); - BZ_ITUR(40); BZ_ITUR(41); BZ_ITUR(42); BZ_ITUR(43); BZ_ITUR(44); - BZ_ITUR(45); BZ_ITUR(46); BZ_ITUR(47); BZ_ITUR(48); BZ_ITUR(49); - -# undef BZ_ITUR - - } else { - /*--- slow version which correctly handles all situations ---*/ - for (i = gs; i <= ge; i++) - s->rfreq[bt][ mtfv[i] ]++; - } - - gs = ge+1; - } - if (s->verbosity >= 3) { - VPrintf2 ( " pass %d: size is %d, grp uses are ", - iter+1, totc/8 ); - for (t = 0; t < nGroups; t++) - VPrintf1 ( "%d ", fave[t] ); - VPrintf0 ( "\n" ); - } - - /*-- - Recompute the tables based on the accumulated frequencies. - --*/ - for (t = 0; t < nGroups; t++) - BZ2_hbMakeCodeLengths ( &(s->len[t][0]), &(s->rfreq[t][0]), - alphaSize, 20 ); - } - - - AssertH( nGroups < 8, 3002 ); - AssertH( nSelectors < 32768 && - nSelectors <= (2 + (900000 / BZ_G_SIZE)), - 3003 ); - - - /*--- Compute MTF values for the selectors. ---*/ - { - UChar pos[BZ_N_GROUPS], ll_i, tmp2, tmp; - for (i = 0; i < nGroups; i++) pos[i] = i; - for (i = 0; i < nSelectors; i++) { - ll_i = s->selector[i]; - j = 0; - tmp = pos[j]; - while ( ll_i != tmp ) { - j++; - tmp2 = tmp; - tmp = pos[j]; - pos[j] = tmp2; - }; - pos[0] = tmp; - s->selectorMtf[i] = j; - } - }; - - /*--- Assign actual codes for the tables. --*/ - for (t = 0; t < nGroups; t++) { - minLen = 32; - maxLen = 0; - for (i = 0; i < alphaSize; i++) { - if (s->len[t][i] > maxLen) maxLen = s->len[t][i]; - if (s->len[t][i] < minLen) minLen = s->len[t][i]; - } - AssertH ( !(maxLen > 20), 3004 ); - AssertH ( !(minLen < 1), 3005 ); - BZ2_hbAssignCodes ( &(s->code[t][0]), &(s->len[t][0]), - minLen, maxLen, alphaSize ); - } - - /*--- Transmit the mapping table. ---*/ - { - Bool inUse16[16]; - for (i = 0; i < 16; i++) { - inUse16[i] = False; - for (j = 0; j < 16; j++) - if (s->inUse[i * 16 + j]) inUse16[i] = True; - } - - nBytes = s->numZ; - for (i = 0; i < 16; i++) - if (inUse16[i]) bsW(s,1,1); else bsW(s,1,0); - - for (i = 0; i < 16; i++) - if (inUse16[i]) - for (j = 0; j < 16; j++) { - if (s->inUse[i * 16 + j]) bsW(s,1,1); else bsW(s,1,0); - } - - if (s->verbosity >= 3) - VPrintf1( " bytes: mapping %d, ", s->numZ-nBytes ); - } - - /*--- Now the selectors. ---*/ - nBytes = s->numZ; - bsW ( s, 3, nGroups ); - bsW ( s, 15, nSelectors ); - for (i = 0; i < nSelectors; i++) { - for (j = 0; j < s->selectorMtf[i]; j++) bsW(s,1,1); - bsW(s,1,0); - } - if (s->verbosity >= 3) - VPrintf1( "selectors %d, ", s->numZ-nBytes ); - - /*--- Now the coding tables. ---*/ - nBytes = s->numZ; - - for (t = 0; t < nGroups; t++) { - Int32 curr = s->len[t][0]; - bsW ( s, 5, curr ); - for (i = 0; i < alphaSize; i++) { - while (curr < s->len[t][i]) { bsW(s,2,2); curr++; /* 10 */ }; - while (curr > s->len[t][i]) { bsW(s,2,3); curr--; /* 11 */ }; - bsW ( s, 1, 0 ); - } - } - - if (s->verbosity >= 3) - VPrintf1 ( "code lengths %d, ", s->numZ-nBytes ); - - /*--- And finally, the block data proper ---*/ - nBytes = s->numZ; - selCtr = 0; - gs = 0; - while (True) { - if (gs >= s->nMTF) break; - ge = gs + BZ_G_SIZE - 1; - if (ge >= s->nMTF) ge = s->nMTF-1; - AssertH ( s->selector[selCtr] < nGroups, 3006 ); - - if (nGroups == 6 && 50 == ge-gs+1) { - /*--- fast track the common case ---*/ - UInt16 mtfv_i; - UChar* s_len_sel_selCtr - = &(s->len[s->selector[selCtr]][0]); - Int32* s_code_sel_selCtr - = &(s->code[s->selector[selCtr]][0]); - -# define BZ_ITAH(nn) \ - mtfv_i = mtfv[gs+(nn)]; \ - bsW ( s, \ - s_len_sel_selCtr[mtfv_i], \ - s_code_sel_selCtr[mtfv_i] ) - - BZ_ITAH(0); BZ_ITAH(1); BZ_ITAH(2); BZ_ITAH(3); BZ_ITAH(4); - BZ_ITAH(5); BZ_ITAH(6); BZ_ITAH(7); BZ_ITAH(8); BZ_ITAH(9); - BZ_ITAH(10); BZ_ITAH(11); BZ_ITAH(12); BZ_ITAH(13); BZ_ITAH(14); - BZ_ITAH(15); BZ_ITAH(16); BZ_ITAH(17); BZ_ITAH(18); BZ_ITAH(19); - BZ_ITAH(20); BZ_ITAH(21); BZ_ITAH(22); BZ_ITAH(23); BZ_ITAH(24); - BZ_ITAH(25); BZ_ITAH(26); BZ_ITAH(27); BZ_ITAH(28); BZ_ITAH(29); - BZ_ITAH(30); BZ_ITAH(31); BZ_ITAH(32); BZ_ITAH(33); BZ_ITAH(34); - BZ_ITAH(35); BZ_ITAH(36); BZ_ITAH(37); BZ_ITAH(38); BZ_ITAH(39); - BZ_ITAH(40); BZ_ITAH(41); BZ_ITAH(42); BZ_ITAH(43); BZ_ITAH(44); - BZ_ITAH(45); BZ_ITAH(46); BZ_ITAH(47); BZ_ITAH(48); BZ_ITAH(49); - -# undef BZ_ITAH - - } else { - /*--- slow version which correctly handles all situations ---*/ - for (i = gs; i <= ge; i++) { - bsW ( s, - s->len [s->selector[selCtr]] [mtfv[i]], - s->code [s->selector[selCtr]] [mtfv[i]] ); - } - } - - - gs = ge+1; - selCtr++; - } - AssertH( selCtr == nSelectors, 3007 ); - - if (s->verbosity >= 3) - VPrintf1( "codes %d\n", s->numZ-nBytes ); -} - - -/*---------------------------------------------------*/ -void BZ2_compressBlock ( EState* s, Bool is_last_block ) -{ - if (s->nblock > 0) { - - BZ_FINALISE_CRC ( s->blockCRC ); - s->combinedCRC = (s->combinedCRC << 1) | (s->combinedCRC >> 31); - s->combinedCRC ^= s->blockCRC; - if (s->blockNo > 1) s->numZ = 0; - - if (s->verbosity >= 2) - VPrintf4( " block %d: crc = 0x%8x, " - "combined CRC = 0x%8x, size = %d\n", - s->blockNo, s->blockCRC, s->combinedCRC, s->nblock ); - - BZ2_blockSort ( s ); - } - - s->zbits = (UChar*) (&((UChar*)s->arr2)[s->nblock]); - - /*-- If this is the first block, create the stream header. --*/ - if (s->blockNo == 1) { - BZ2_bsInitWrite ( s ); - bsPutUChar ( s, 'B' ); - bsPutUChar ( s, 'Z' ); - bsPutUChar ( s, 'h' ); - bsPutUChar ( s, (UChar)('0' + s->blockSize100k) ); - } - - if (s->nblock > 0) { - - bsPutUChar ( s, 0x31 ); bsPutUChar ( s, 0x41 ); - bsPutUChar ( s, 0x59 ); bsPutUChar ( s, 0x26 ); - bsPutUChar ( s, 0x53 ); bsPutUChar ( s, 0x59 ); - - /*-- Now the block's CRC, so it is in a known place. --*/ - bsPutUInt32 ( s, s->blockCRC ); - - /*-- - Now a single bit indicating (non-)randomisation. - As of version 0.9.5, we use a better sorting algorithm - which makes randomisation unnecessary. So always set - the randomised bit to 'no'. Of course, the decoder - still needs to be able to handle randomised blocks - so as to maintain backwards compatibility with - older versions of bzip2. - --*/ - bsW(s,1,0); - - bsW ( s, 24, s->origPtr ); - generateMTFValues ( s ); - sendMTFValues ( s ); - } - - - /*-- If this is the last block, add the stream trailer. --*/ - if (is_last_block) { - - bsPutUChar ( s, 0x17 ); bsPutUChar ( s, 0x72 ); - bsPutUChar ( s, 0x45 ); bsPutUChar ( s, 0x38 ); - bsPutUChar ( s, 0x50 ); bsPutUChar ( s, 0x90 ); - bsPutUInt32 ( s, s->combinedCRC ); - if (s->verbosity >= 2) - VPrintf1( " final combined CRC = 0x%x\n ", s->combinedCRC ); - bsFinishWrite ( s ); - } -} - - -/*-------------------------------------------------------------*/ -/*--- end compress.c ---*/ -/*-------------------------------------------------------------*/ diff --git a/mdk-stage1/bzlib/crctable.c b/mdk-stage1/bzlib/crctable.c deleted file mode 100644 index c0ea3f769..000000000 --- a/mdk-stage1/bzlib/crctable.c +++ /dev/null @@ -1,148 +0,0 @@ - -/*-------------------------------------------------------------*/ -/*--- Table for doing CRCs ---*/ -/*--- crctable.c ---*/ -/*-------------------------------------------------------------*/ - -/*-- - This file is a part of bzip2 and/or libbzip2, a program and - library for lossless, block-sorting data compression. - - Copyright (C) 1996-2000 Julian R Seward. All rights reserved. - - Redistribution and use in source and binary forms, with or without - modification, are permitted provided that the following conditions - are met: - - 1. Redistributions of source code must retain the above copyright - notice, this list of conditions and the following disclaimer. - - 2. The origin of this software must not be misrepresented; you must - not claim that you wrote the original software. If you use this - software in a product, an acknowledgment in the product - documentation would be appreciated but is not required. - - 3. Altered source versions must be plainly marked as such, and must - not be misrepresented as being the original software. - - 4. The name of the author may not be used to endorse or promote - products derived from this software without specific prior written - permission. - - THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS - OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED - WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY - DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE - GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS - INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, - WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING - NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS - SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - - Julian Seward, Cambridge, UK. - jseward@acm.org - bzip2/libbzip2 version 1.0 of 21 March 2000 - - This program is based on (at least) the work of: - Mike Burrows - David Wheeler - Peter Fenwick - Alistair Moffat - Radford Neal - Ian H. Witten - Robert Sedgewick - Jon L. Bentley - - For more information on these sources, see the manual. ---*/ - -#ifdef HAVE_CONFIG_H -#include <config.h> -#endif - - -#include "bzlib_private.h" - -/*-- - I think this is an implementation of the AUTODIN-II, - Ethernet & FDDI 32-bit CRC standard. Vaguely derived - from code by Rob Warnock, in Section 51 of the - comp.compression FAQ. ---*/ - -UInt32 BZ2_crc32Table[256] = { - - /*-- Ugly, innit? --*/ - - 0x00000000L, 0x04c11db7L, 0x09823b6eL, 0x0d4326d9L, - 0x130476dcL, 0x17c56b6bL, 0x1a864db2L, 0x1e475005L, - 0x2608edb8L, 0x22c9f00fL, 0x2f8ad6d6L, 0x2b4bcb61L, - 0x350c9b64L, 0x31cd86d3L, 0x3c8ea00aL, 0x384fbdbdL, - 0x4c11db70L, 0x48d0c6c7L, 0x4593e01eL, 0x4152fda9L, - 0x5f15adacL, 0x5bd4b01bL, 0x569796c2L, 0x52568b75L, - 0x6a1936c8L, 0x6ed82b7fL, 0x639b0da6L, 0x675a1011L, - 0x791d4014L, 0x7ddc5da3L, 0x709f7b7aL, 0x745e66cdL, - 0x9823b6e0L, 0x9ce2ab57L, 0x91a18d8eL, 0x95609039L, - 0x8b27c03cL, 0x8fe6dd8bL, 0x82a5fb52L, 0x8664e6e5L, - 0xbe2b5b58L, 0xbaea46efL, 0xb7a96036L, 0xb3687d81L, - 0xad2f2d84L, 0xa9ee3033L, 0xa4ad16eaL, 0xa06c0b5dL, - 0xd4326d90L, 0xd0f37027L, 0xddb056feL, 0xd9714b49L, - 0xc7361b4cL, 0xc3f706fbL, 0xceb42022L, 0xca753d95L, - 0xf23a8028L, 0xf6fb9d9fL, 0xfbb8bb46L, 0xff79a6f1L, - 0xe13ef6f4L, 0xe5ffeb43L, 0xe8bccd9aL, 0xec7dd02dL, - 0x34867077L, 0x30476dc0L, 0x3d044b19L, 0x39c556aeL, - 0x278206abL, 0x23431b1cL, 0x2e003dc5L, 0x2ac12072L, - 0x128e9dcfL, 0x164f8078L, 0x1b0ca6a1L, 0x1fcdbb16L, - 0x018aeb13L, 0x054bf6a4L, 0x0808d07dL, 0x0cc9cdcaL, - 0x7897ab07L, 0x7c56b6b0L, 0x71159069L, 0x75d48ddeL, - 0x6b93dddbL, 0x6f52c06cL, 0x6211e6b5L, 0x66d0fb02L, - 0x5e9f46bfL, 0x5a5e5b08L, 0x571d7dd1L, 0x53dc6066L, - 0x4d9b3063L, 0x495a2dd4L, 0x44190b0dL, 0x40d816baL, - 0xaca5c697L, 0xa864db20L, 0xa527fdf9L, 0xa1e6e04eL, - 0xbfa1b04bL, 0xbb60adfcL, 0xb6238b25L, 0xb2e29692L, - 0x8aad2b2fL, 0x8e6c3698L, 0x832f1041L, 0x87ee0df6L, - 0x99a95df3L, 0x9d684044L, 0x902b669dL, 0x94ea7b2aL, - 0xe0b41de7L, 0xe4750050L, 0xe9362689L, 0xedf73b3eL, - 0xf3b06b3bL, 0xf771768cL, 0xfa325055L, 0xfef34de2L, - 0xc6bcf05fL, 0xc27dede8L, 0xcf3ecb31L, 0xcbffd686L, - 0xd5b88683L, 0xd1799b34L, 0xdc3abdedL, 0xd8fba05aL, - 0x690ce0eeL, 0x6dcdfd59L, 0x608edb80L, 0x644fc637L, - 0x7a089632L, 0x7ec98b85L, 0x738aad5cL, 0x774bb0ebL, - 0x4f040d56L, 0x4bc510e1L, 0x46863638L, 0x42472b8fL, - 0x5c007b8aL, 0x58c1663dL, 0x558240e4L, 0x51435d53L, - 0x251d3b9eL, 0x21dc2629L, 0x2c9f00f0L, 0x285e1d47L, - 0x36194d42L, 0x32d850f5L, 0x3f9b762cL, 0x3b5a6b9bL, - 0x0315d626L, 0x07d4cb91L, 0x0a97ed48L, 0x0e56f0ffL, - 0x1011a0faL, 0x14d0bd4dL, 0x19939b94L, 0x1d528623L, - 0xf12f560eL, 0xf5ee4bb9L, 0xf8ad6d60L, 0xfc6c70d7L, - 0xe22b20d2L, 0xe6ea3d65L, 0xeba91bbcL, 0xef68060bL, - 0xd727bbb6L, 0xd3e6a601L, 0xdea580d8L, 0xda649d6fL, - 0xc423cd6aL, 0xc0e2d0ddL, 0xcda1f604L, 0xc960ebb3L, - 0xbd3e8d7eL, 0xb9ff90c9L, 0xb4bcb610L, 0xb07daba7L, - 0xae3afba2L, 0xaafbe615L, 0xa7b8c0ccL, 0xa379dd7bL, - 0x9b3660c6L, 0x9ff77d71L, 0x92b45ba8L, 0x9675461fL, - 0x8832161aL, 0x8cf30badL, 0x81b02d74L, 0x857130c3L, - 0x5d8a9099L, 0x594b8d2eL, 0x5408abf7L, 0x50c9b640L, - 0x4e8ee645L, 0x4a4ffbf2L, 0x470cdd2bL, 0x43cdc09cL, - 0x7b827d21L, 0x7f436096L, 0x7200464fL, 0x76c15bf8L, - 0x68860bfdL, 0x6c47164aL, 0x61043093L, 0x65c52d24L, - 0x119b4be9L, 0x155a565eL, 0x18197087L, 0x1cd86d30L, - 0x029f3d35L, 0x065e2082L, 0x0b1d065bL, 0x0fdc1becL, - 0x3793a651L, 0x3352bbe6L, 0x3e119d3fL, 0x3ad08088L, - 0x2497d08dL, 0x2056cd3aL, 0x2d15ebe3L, 0x29d4f654L, - 0xc5a92679L, 0xc1683bceL, 0xcc2b1d17L, 0xc8ea00a0L, - 0xd6ad50a5L, 0xd26c4d12L, 0xdf2f6bcbL, 0xdbee767cL, - 0xe3a1cbc1L, 0xe760d676L, 0xea23f0afL, 0xeee2ed18L, - 0xf0a5bd1dL, 0xf464a0aaL, 0xf9278673L, 0xfde69bc4L, - 0x89b8fd09L, 0x8d79e0beL, 0x803ac667L, 0x84fbdbd0L, - 0x9abc8bd5L, 0x9e7d9662L, 0x933eb0bbL, 0x97ffad0cL, - 0xafb010b1L, 0xab710d06L, 0xa6322bdfL, 0xa2f33668L, - 0xbcb4666dL, 0xb8757bdaL, 0xb5365d03L, 0xb1f740b4L -}; - - -/*-------------------------------------------------------------*/ -/*--- end crctable.c ---*/ -/*-------------------------------------------------------------*/ diff --git a/mdk-stage1/bzlib/decompress.c b/mdk-stage1/bzlib/decompress.c deleted file mode 100644 index 65cf75d8f..000000000 --- a/mdk-stage1/bzlib/decompress.c +++ /dev/null @@ -1,664 +0,0 @@ - -/*-------------------------------------------------------------*/ -/*--- Decompression machinery ---*/ -/*--- decompress.c ---*/ -/*-------------------------------------------------------------*/ - -/*-- - This file is a part of bzip2 and/or libbzip2, a program and - library for lossless, block-sorting data compression. - - Copyright (C) 1996-2000 Julian R Seward. All rights reserved. - - Redistribution and use in source and binary forms, with or without - modification, are permitted provided that the following conditions - are met: - - 1. Redistributions of source code must retain the above copyright - notice, this list of conditions and the following disclaimer. - - 2. The origin of this software must not be misrepresented; you must - not claim that you wrote the original software. If you use this - software in a product, an acknowledgment in the product - documentation would be appreciated but is not required. - - 3. Altered source versions must be plainly marked as such, and must - not be misrepresented as being the original software. - - 4. The name of the author may not be used to endorse or promote - products derived from this software without specific prior written - permission. - - THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS - OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED - WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY - DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE - GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS - INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, - WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING - NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS - SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - - Julian Seward, Cambridge, UK. - jseward@acm.org - bzip2/libbzip2 version 1.0 of 21 March 2000 - - This program is based on (at least) the work of: - Mike Burrows - David Wheeler - Peter Fenwick - Alistair Moffat - Radford Neal - Ian H. Witten - Robert Sedgewick - Jon L. Bentley - - For more information on these sources, see the manual. ---*/ - -#ifdef HAVE_CONFIG_H -#include <config.h> -#endif - - -#include "bzlib_private.h" - - -/*---------------------------------------------------*/ -static -void makeMaps_d ( DState* s ) -{ - Int32 i; - s->nInUse = 0; - for (i = 0; i < 256; i++) - if (s->inUse[i]) { - s->seqToUnseq[s->nInUse] = i; - s->nInUse++; - } -} - - -/*---------------------------------------------------*/ -#define RETURN(rrr) \ - { retVal = rrr; goto save_state_and_return; }; - -#define GET_BITS(lll,vvv,nnn) \ - case lll: s->state = lll; \ - while (True) { \ - if (s->bsLive >= nnn) { \ - UInt32 v; \ - v = (s->bsBuff >> \ - (s->bsLive-nnn)) & ((1 << nnn)-1); \ - s->bsLive -= nnn; \ - vvv = v; \ - break; \ - } \ - if (s->strm->avail_in == 0) RETURN(BZ_OK); \ - s->bsBuff \ - = (s->bsBuff << 8) | \ - ((UInt32) \ - (*((UChar*)(s->strm->next_in)))); \ - s->bsLive += 8; \ - s->strm->next_in++; \ - s->strm->avail_in--; \ - s->strm->total_in_lo32++; \ - if (s->strm->total_in_lo32 == 0) \ - s->strm->total_in_hi32++; \ - } - -#define GET_UCHAR(lll,uuu) \ - GET_BITS(lll,uuu,8) - -#define GET_BIT(lll,uuu) \ - GET_BITS(lll,uuu,1) - -/*---------------------------------------------------*/ -#define GET_MTF_VAL(label1,label2,lval) \ -{ \ - if (groupPos == 0) { \ - groupNo++; \ - if (groupNo >= nSelectors) \ - RETURN(BZ_DATA_ERROR); \ - groupPos = BZ_G_SIZE; \ - gSel = s->selector[groupNo]; \ - gMinlen = s->minLens[gSel]; \ - gLimit = &(s->limit[gSel][0]); \ - gPerm = &(s->perm[gSel][0]); \ - gBase = &(s->base[gSel][0]); \ - } \ - groupPos--; \ - zn = gMinlen; \ - GET_BITS(label1, zvec, zn); \ - while (1) { \ - if (zn > 20 /* the longest code */) \ - RETURN(BZ_DATA_ERROR); \ - if (zvec <= gLimit[zn]) break; \ - zn++; \ - GET_BIT(label2, zj); \ - zvec = (zvec << 1) | zj; \ - }; \ - if (zvec - gBase[zn] < 0 \ - || zvec - gBase[zn] >= BZ_MAX_ALPHA_SIZE) \ - RETURN(BZ_DATA_ERROR); \ - lval = gPerm[zvec - gBase[zn]]; \ -} - - -/*---------------------------------------------------*/ -Int32 BZ2_decompress ( DState* s ) -{ - UChar uc; - Int32 retVal; - Int32 minLen, maxLen; - bz_stream* strm = s->strm; - - /* stuff that needs to be saved/restored */ - Int32 i; - Int32 j; - Int32 t; - Int32 alphaSize; - Int32 nGroups; - Int32 nSelectors; - Int32 EOB; - Int32 groupNo; - Int32 groupPos; - Int32 nextSym; - Int32 nblockMAX; - Int32 nblock; - Int32 es; - Int32 N; - Int32 curr; - Int32 zt; - Int32 zn; - Int32 zvec; - Int32 zj; - Int32 gSel; - Int32 gMinlen; - Int32* gLimit; - Int32* gBase; - Int32* gPerm; - - if (s->state == BZ_X_MAGIC_1) { - /*initialise the save area*/ - s->save_i = 0; - s->save_j = 0; - s->save_t = 0; - s->save_alphaSize = 0; - s->save_nGroups = 0; - s->save_nSelectors = 0; - s->save_EOB = 0; - s->save_groupNo = 0; - s->save_groupPos = 0; - s->save_nextSym = 0; - s->save_nblockMAX = 0; - s->save_nblock = 0; - s->save_es = 0; - s->save_N = 0; - s->save_curr = 0; - s->save_zt = 0; - s->save_zn = 0; - s->save_zvec = 0; - s->save_zj = 0; - s->save_gSel = 0; - s->save_gMinlen = 0; - s->save_gLimit = NULL; - s->save_gBase = NULL; - s->save_gPerm = NULL; - } - - /*restore from the save area*/ - i = s->save_i; - j = s->save_j; - t = s->save_t; - alphaSize = s->save_alphaSize; - nGroups = s->save_nGroups; - nSelectors = s->save_nSelectors; - EOB = s->save_EOB; - groupNo = s->save_groupNo; - groupPos = s->save_groupPos; - nextSym = s->save_nextSym; - nblockMAX = s->save_nblockMAX; - nblock = s->save_nblock; - es = s->save_es; - N = s->save_N; - curr = s->save_curr; - zt = s->save_zt; - zn = s->save_zn; - zvec = s->save_zvec; - zj = s->save_zj; - gSel = s->save_gSel; - gMinlen = s->save_gMinlen; - gLimit = s->save_gLimit; - gBase = s->save_gBase; - gPerm = s->save_gPerm; - - retVal = BZ_OK; - - switch (s->state) { - - GET_UCHAR(BZ_X_MAGIC_1, uc); - if (uc != 'B') RETURN(BZ_DATA_ERROR_MAGIC); - - GET_UCHAR(BZ_X_MAGIC_2, uc); - if (uc != 'Z') RETURN(BZ_DATA_ERROR_MAGIC); - - GET_UCHAR(BZ_X_MAGIC_3, uc) - if (uc != 'h') RETURN(BZ_DATA_ERROR_MAGIC); - - GET_BITS(BZ_X_MAGIC_4, s->blockSize100k, 8) - if (s->blockSize100k < '1' || - s->blockSize100k > '9') RETURN(BZ_DATA_ERROR_MAGIC); - s->blockSize100k -= '0'; - - if (s->smallDecompress) { - s->ll16 = BZALLOC( s->blockSize100k * 100000 * sizeof(UInt16) ); - s->ll4 = BZALLOC( - ((1 + s->blockSize100k * 100000) >> 1) * sizeof(UChar) - ); - if (s->ll16 == NULL || s->ll4 == NULL) RETURN(BZ_MEM_ERROR); - } else { - s->tt = BZALLOC( s->blockSize100k * 100000 * sizeof(Int32) ); - if (s->tt == NULL) RETURN(BZ_MEM_ERROR); - } - - GET_UCHAR(BZ_X_BLKHDR_1, uc); - - if (uc == 0x17) goto endhdr_2; - if (uc != 0x31) RETURN(BZ_DATA_ERROR); - GET_UCHAR(BZ_X_BLKHDR_2, uc); - if (uc != 0x41) RETURN(BZ_DATA_ERROR); - GET_UCHAR(BZ_X_BLKHDR_3, uc); - if (uc != 0x59) RETURN(BZ_DATA_ERROR); - GET_UCHAR(BZ_X_BLKHDR_4, uc); - if (uc != 0x26) RETURN(BZ_DATA_ERROR); - GET_UCHAR(BZ_X_BLKHDR_5, uc); - if (uc != 0x53) RETURN(BZ_DATA_ERROR); - GET_UCHAR(BZ_X_BLKHDR_6, uc); - if (uc != 0x59) RETURN(BZ_DATA_ERROR); - - s->currBlockNo++; - if (s->verbosity >= 2) - VPrintf1 ( "\n [%d: huff+mtf ", s->currBlockNo ); - - s->storedBlockCRC = 0; - GET_UCHAR(BZ_X_BCRC_1, uc); - s->storedBlockCRC = (s->storedBlockCRC << 8) | ((UInt32)uc); - GET_UCHAR(BZ_X_BCRC_2, uc); - s->storedBlockCRC = (s->storedBlockCRC << 8) | ((UInt32)uc); - GET_UCHAR(BZ_X_BCRC_3, uc); - s->storedBlockCRC = (s->storedBlockCRC << 8) | ((UInt32)uc); - GET_UCHAR(BZ_X_BCRC_4, uc); - s->storedBlockCRC = (s->storedBlockCRC << 8) | ((UInt32)uc); - - GET_BITS(BZ_X_RANDBIT, s->blockRandomised, 1); - - s->origPtr = 0; - GET_UCHAR(BZ_X_ORIGPTR_1, uc); - s->origPtr = (s->origPtr << 8) | ((Int32)uc); - GET_UCHAR(BZ_X_ORIGPTR_2, uc); - s->origPtr = (s->origPtr << 8) | ((Int32)uc); - GET_UCHAR(BZ_X_ORIGPTR_3, uc); - s->origPtr = (s->origPtr << 8) | ((Int32)uc); - - if (s->origPtr < 0) - RETURN(BZ_DATA_ERROR); - if (s->origPtr > 10 + 100000*s->blockSize100k) - RETURN(BZ_DATA_ERROR); - - /*--- Receive the mapping table ---*/ - for (i = 0; i < 16; i++) { - GET_BIT(BZ_X_MAPPING_1, uc); - if (uc == 1) - s->inUse16[i] = True; else - s->inUse16[i] = False; - } - - for (i = 0; i < 256; i++) s->inUse[i] = False; - - for (i = 0; i < 16; i++) - if (s->inUse16[i]) - for (j = 0; j < 16; j++) { - GET_BIT(BZ_X_MAPPING_2, uc); - if (uc == 1) s->inUse[i * 16 + j] = True; - } - makeMaps_d ( s ); - if (s->nInUse == 0) RETURN(BZ_DATA_ERROR); - alphaSize = s->nInUse+2; - - /*--- Now the selectors ---*/ - GET_BITS(BZ_X_SELECTOR_1, nGroups, 3); - if (nGroups < 2 || nGroups > 6) RETURN(BZ_DATA_ERROR); - GET_BITS(BZ_X_SELECTOR_2, nSelectors, 15); - if (nSelectors < 1) RETURN(BZ_DATA_ERROR); - for (i = 0; i < nSelectors; i++) { - j = 0; - while (True) { - GET_BIT(BZ_X_SELECTOR_3, uc); - if (uc == 0) break; - j++; - if (j >= nGroups) RETURN(BZ_DATA_ERROR); - } - s->selectorMtf[i] = j; - } - - /*--- Undo the MTF values for the selectors. ---*/ - { - UChar pos[BZ_N_GROUPS], tmp, v; - for (v = 0; v < nGroups; v++) pos[v] = v; - - for (i = 0; i < nSelectors; i++) { - v = s->selectorMtf[i]; - tmp = pos[v]; - while (v > 0) { pos[v] = pos[v-1]; v--; } - pos[0] = tmp; - s->selector[i] = tmp; - } - } - - /*--- Now the coding tables ---*/ - for (t = 0; t < nGroups; t++) { - GET_BITS(BZ_X_CODING_1, curr, 5); - for (i = 0; i < alphaSize; i++) { - while (True) { - if (curr < 1 || curr > 20) RETURN(BZ_DATA_ERROR); - GET_BIT(BZ_X_CODING_2, uc); - if (uc == 0) break; - GET_BIT(BZ_X_CODING_3, uc); - if (uc == 0) curr++; else curr--; - } - s->len[t][i] = curr; - } - } - - /*--- Create the Huffman decoding tables ---*/ - for (t = 0; t < nGroups; t++) { - minLen = 32; - maxLen = 0; - for (i = 0; i < alphaSize; i++) { - if (s->len[t][i] > maxLen) maxLen = s->len[t][i]; - if (s->len[t][i] < minLen) minLen = s->len[t][i]; - } - BZ2_hbCreateDecodeTables ( - &(s->limit[t][0]), - &(s->base[t][0]), - &(s->perm[t][0]), - &(s->len[t][0]), - minLen, maxLen, alphaSize - ); - s->minLens[t] = minLen; - } - - /*--- Now the MTF values ---*/ - - EOB = s->nInUse+1; - nblockMAX = 100000 * s->blockSize100k; - groupNo = -1; - groupPos = 0; - - for (i = 0; i <= 255; i++) s->unzftab[i] = 0; - - /*-- MTF init --*/ - { - Int32 ii, jj, kk; - kk = MTFA_SIZE-1; - for (ii = 256 / MTFL_SIZE - 1; ii >= 0; ii--) { - for (jj = MTFL_SIZE-1; jj >= 0; jj--) { - s->mtfa[kk] = (UChar)(ii * MTFL_SIZE + jj); - kk--; - } - s->mtfbase[ii] = kk + 1; - } - } - /*-- end MTF init --*/ - - nblock = 0; - GET_MTF_VAL(BZ_X_MTF_1, BZ_X_MTF_2, nextSym); - - while (True) { - - if (nextSym == EOB) break; - - if (nextSym == BZ_RUNA || nextSym == BZ_RUNB) { - - es = -1; - N = 1; - do { - if (nextSym == BZ_RUNA) es = es + (0+1) * N; else - if (nextSym == BZ_RUNB) es = es + (1+1) * N; - N = N * 2; - GET_MTF_VAL(BZ_X_MTF_3, BZ_X_MTF_4, nextSym); - } - while (nextSym == BZ_RUNA || nextSym == BZ_RUNB); - - es++; - uc = s->seqToUnseq[ s->mtfa[s->mtfbase[0]] ]; - s->unzftab[uc] += es; - - if (s->smallDecompress) - while (es > 0) { - if (nblock >= nblockMAX) RETURN(BZ_DATA_ERROR); - s->ll16[nblock] = (UInt16)uc; - nblock++; - es--; - } - else - while (es > 0) { - if (nblock >= nblockMAX) RETURN(BZ_DATA_ERROR); - s->tt[nblock] = (UInt32)uc; - nblock++; - es--; - }; - - continue; - - } else { - - if (nblock >= nblockMAX) RETURN(BZ_DATA_ERROR); - - /*-- uc = MTF ( nextSym-1 ) --*/ - { - Int32 ii, jj, kk, pp, lno, off; - UInt32 nn; - nn = (UInt32)(nextSym - 1); - - if (nn < MTFL_SIZE) { - /* avoid general-case expense */ - pp = s->mtfbase[0]; - uc = s->mtfa[pp+nn]; - while (nn > 3) { - Int32 z = pp+nn; - s->mtfa[(z) ] = s->mtfa[(z)-1]; - s->mtfa[(z)-1] = s->mtfa[(z)-2]; - s->mtfa[(z)-2] = s->mtfa[(z)-3]; - s->mtfa[(z)-3] = s->mtfa[(z)-4]; - nn -= 4; - } - while (nn > 0) { - s->mtfa[(pp+nn)] = s->mtfa[(pp+nn)-1]; nn--; - }; - s->mtfa[pp] = uc; - } else { - /* general case */ - lno = nn / MTFL_SIZE; - off = nn % MTFL_SIZE; - pp = s->mtfbase[lno] + off; - uc = s->mtfa[pp]; - while (pp > s->mtfbase[lno]) { - s->mtfa[pp] = s->mtfa[pp-1]; pp--; - }; - s->mtfbase[lno]++; - while (lno > 0) { - s->mtfbase[lno]--; - s->mtfa[s->mtfbase[lno]] - = s->mtfa[s->mtfbase[lno-1] + MTFL_SIZE - 1]; - lno--; - } - s->mtfbase[0]--; - s->mtfa[s->mtfbase[0]] = uc; - if (s->mtfbase[0] == 0) { - kk = MTFA_SIZE-1; - for (ii = 256 / MTFL_SIZE-1; ii >= 0; ii--) { - for (jj = MTFL_SIZE-1; jj >= 0; jj--) { - s->mtfa[kk] = s->mtfa[s->mtfbase[ii] + jj]; - kk--; - } - s->mtfbase[ii] = kk + 1; - } - } - } - } - /*-- end uc = MTF ( nextSym-1 ) --*/ - - s->unzftab[s->seqToUnseq[uc]]++; - if (s->smallDecompress) - s->ll16[nblock] = (UInt16)(s->seqToUnseq[uc]); else - s->tt[nblock] = (UInt32)(s->seqToUnseq[uc]); - nblock++; - - GET_MTF_VAL(BZ_X_MTF_5, BZ_X_MTF_6, nextSym); - continue; - } - } - - /* Now we know what nblock is, we can do a better sanity - check on s->origPtr. - */ - if (s->origPtr < 0 || s->origPtr >= nblock) - RETURN(BZ_DATA_ERROR); - - s->state_out_len = 0; - s->state_out_ch = 0; - BZ_INITIALISE_CRC ( s->calculatedBlockCRC ); - s->state = BZ_X_OUTPUT; - if (s->verbosity >= 2) VPrintf0 ( "rt+rld" ); - - /*-- Set up cftab to facilitate generation of T^(-1) --*/ - s->cftab[0] = 0; - for (i = 1; i <= 256; i++) s->cftab[i] = s->unzftab[i-1]; - for (i = 1; i <= 256; i++) s->cftab[i] += s->cftab[i-1]; - - if (s->smallDecompress) { - - /*-- Make a copy of cftab, used in generation of T --*/ - for (i = 0; i <= 256; i++) s->cftabCopy[i] = s->cftab[i]; - - /*-- compute the T vector --*/ - for (i = 0; i < nblock; i++) { - uc = (UChar)(s->ll16[i]); - SET_LL(i, s->cftabCopy[uc]); - s->cftabCopy[uc]++; - } - - /*-- Compute T^(-1) by pointer reversal on T --*/ - i = s->origPtr; - j = GET_LL(i); - do { - Int32 tmp = GET_LL(j); - SET_LL(j, i); - i = j; - j = tmp; - } - while (i != s->origPtr); - - s->tPos = s->origPtr; - s->nblock_used = 0; - if (s->blockRandomised) { - BZ_RAND_INIT_MASK; - BZ_GET_SMALL(s->k0); s->nblock_used++; - BZ_RAND_UPD_MASK; s->k0 ^= BZ_RAND_MASK; - } else { - BZ_GET_SMALL(s->k0); s->nblock_used++; - } - - } else { - - /*-- compute the T^(-1) vector --*/ - for (i = 0; i < nblock; i++) { - uc = (UChar)(s->tt[i] & 0xff); - s->tt[s->cftab[uc]] |= (i << 8); - s->cftab[uc]++; - } - - s->tPos = s->tt[s->origPtr] >> 8; - s->nblock_used = 0; - if (s->blockRandomised) { - BZ_RAND_INIT_MASK; - BZ_GET_FAST(s->k0); s->nblock_used++; - BZ_RAND_UPD_MASK; s->k0 ^= BZ_RAND_MASK; - } else { - BZ_GET_FAST(s->k0); s->nblock_used++; - } - - } - - RETURN(BZ_OK); - - - - endhdr_2: - - GET_UCHAR(BZ_X_ENDHDR_2, uc); - if (uc != 0x72) RETURN(BZ_DATA_ERROR); - GET_UCHAR(BZ_X_ENDHDR_3, uc); - if (uc != 0x45) RETURN(BZ_DATA_ERROR); - GET_UCHAR(BZ_X_ENDHDR_4, uc); - if (uc != 0x38) RETURN(BZ_DATA_ERROR); - GET_UCHAR(BZ_X_ENDHDR_5, uc); - if (uc != 0x50) RETURN(BZ_DATA_ERROR); - GET_UCHAR(BZ_X_ENDHDR_6, uc); - if (uc != 0x90) RETURN(BZ_DATA_ERROR); - - s->storedCombinedCRC = 0; - GET_UCHAR(BZ_X_CCRC_1, uc); - s->storedCombinedCRC = (s->storedCombinedCRC << 8) | ((UInt32)uc); - GET_UCHAR(BZ_X_CCRC_2, uc); - s->storedCombinedCRC = (s->storedCombinedCRC << 8) | ((UInt32)uc); - GET_UCHAR(BZ_X_CCRC_3, uc); - s->storedCombinedCRC = (s->storedCombinedCRC << 8) | ((UInt32)uc); - GET_UCHAR(BZ_X_CCRC_4, uc); - s->storedCombinedCRC = (s->storedCombinedCRC << 8) | ((UInt32)uc); - - s->state = BZ_X_IDLE; - RETURN(BZ_STREAM_END); - - default: AssertH ( False, 4001 ); - } - - AssertH ( False, 4002 ); - - save_state_and_return: - - s->save_i = i; - s->save_j = j; - s->save_t = t; - s->save_alphaSize = alphaSize; - s->save_nGroups = nGroups; - s->save_nSelectors = nSelectors; - s->save_EOB = EOB; - s->save_groupNo = groupNo; - s->save_groupPos = groupPos; - s->save_nextSym = nextSym; - s->save_nblockMAX = nblockMAX; - s->save_nblock = nblock; - s->save_es = es; - s->save_N = N; - s->save_curr = curr; - s->save_zt = zt; - s->save_zn = zn; - s->save_zvec = zvec; - s->save_zj = zj; - s->save_gSel = gSel; - s->save_gMinlen = gMinlen; - s->save_gLimit = gLimit; - s->save_gBase = gBase; - s->save_gPerm = gPerm; - - return retVal; -} - - -/*-------------------------------------------------------------*/ -/*--- end decompress.c ---*/ -/*-------------------------------------------------------------*/ diff --git a/mdk-stage1/bzlib/huffman.c b/mdk-stage1/bzlib/huffman.c deleted file mode 100644 index 8994f0bb9..000000000 --- a/mdk-stage1/bzlib/huffman.c +++ /dev/null @@ -1,232 +0,0 @@ - -/*-------------------------------------------------------------*/ -/*--- Huffman coding low-level stuff ---*/ -/*--- huffman.c ---*/ -/*-------------------------------------------------------------*/ - -/*-- - This file is a part of bzip2 and/or libbzip2, a program and - library for lossless, block-sorting data compression. - - Copyright (C) 1996-2000 Julian R Seward. All rights reserved. - - Redistribution and use in source and binary forms, with or without - modification, are permitted provided that the following conditions - are met: - - 1. Redistributions of source code must retain the above copyright - notice, this list of conditions and the following disclaimer. - - 2. The origin of this software must not be misrepresented; you must - not claim that you wrote the original software. If you use this - software in a product, an acknowledgment in the product - documentation would be appreciated but is not required. - - 3. Altered source versions must be plainly marked as such, and must - not be misrepresented as being the original software. - - 4. The name of the author may not be used to endorse or promote - products derived from this software without specific prior written - permission. - - THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS - OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED - WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY - DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE - GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS - INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, - WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING - NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS - SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - - Julian Seward, Cambridge, UK. - jseward@acm.org - bzip2/libbzip2 version 1.0 of 21 March 2000 - - This program is based on (at least) the work of: - Mike Burrows - David Wheeler - Peter Fenwick - Alistair Moffat - Radford Neal - Ian H. Witten - Robert Sedgewick - Jon L. Bentley - - For more information on these sources, see the manual. ---*/ - -#ifdef HAVE_CONFIG_H -#include <config.h> -#endif - - -#include "bzlib_private.h" - -/*---------------------------------------------------*/ -#define WEIGHTOF(zz0) ((zz0) & 0xffffff00) -#define DEPTHOF(zz1) ((zz1) & 0x000000ff) -#define MYMAX(zz2,zz3) ((zz2) > (zz3) ? (zz2) : (zz3)) - -#define ADDWEIGHTS(zw1,zw2) \ - (WEIGHTOF(zw1)+WEIGHTOF(zw2)) | \ - (1 + MYMAX(DEPTHOF(zw1),DEPTHOF(zw2))) - -#define UPHEAP(z) \ -{ \ - Int32 zz, tmp; \ - zz = z; tmp = heap[zz]; \ - while (weight[tmp] < weight[heap[zz >> 1]]) { \ - heap[zz] = heap[zz >> 1]; \ - zz >>= 1; \ - } \ - heap[zz] = tmp; \ -} - -#define DOWNHEAP(z) \ -{ \ - Int32 zz, yy, tmp; \ - zz = z; tmp = heap[zz]; \ - while (True) { \ - yy = zz << 1; \ - if (yy > nHeap) break; \ - if (yy < nHeap && \ - weight[heap[yy+1]] < weight[heap[yy]]) \ - yy++; \ - if (weight[tmp] < weight[heap[yy]]) break; \ - heap[zz] = heap[yy]; \ - zz = yy; \ - } \ - heap[zz] = tmp; \ -} - - -/*---------------------------------------------------*/ -void BZ2_hbMakeCodeLengths ( UChar *len, - Int32 *freq, - Int32 alphaSize, - Int32 maxLen ) -{ - /*-- - Nodes and heap entries run from 1. Entry 0 - for both the heap and nodes is a sentinel. - --*/ - Int32 nNodes, nHeap, n1, n2, i, j, k; - Bool tooLong; - - Int32 heap [ BZ_MAX_ALPHA_SIZE + 2 ]; - Int32 weight [ BZ_MAX_ALPHA_SIZE * 2 ]; - Int32 parent [ BZ_MAX_ALPHA_SIZE * 2 ]; - - for (i = 0; i < alphaSize; i++) - weight[i+1] = (freq[i] == 0 ? 1 : freq[i]) << 8; - - while (True) { - - nNodes = alphaSize; - nHeap = 0; - - heap[0] = 0; - weight[0] = 0; - parent[0] = -2; - - for (i = 1; i <= alphaSize; i++) { - parent[i] = -1; - nHeap++; - heap[nHeap] = i; - UPHEAP(nHeap); - } - - AssertH( nHeap < (BZ_MAX_ALPHA_SIZE+2), 2001 ); - - while (nHeap > 1) { - n1 = heap[1]; heap[1] = heap[nHeap]; nHeap--; DOWNHEAP(1); - n2 = heap[1]; heap[1] = heap[nHeap]; nHeap--; DOWNHEAP(1); - nNodes++; - parent[n1] = parent[n2] = nNodes; - weight[nNodes] = ADDWEIGHTS(weight[n1], weight[n2]); - parent[nNodes] = -1; - nHeap++; - heap[nHeap] = nNodes; - UPHEAP(nHeap); - } - - AssertH( nNodes < (BZ_MAX_ALPHA_SIZE * 2), 2002 ); - - tooLong = False; - for (i = 1; i <= alphaSize; i++) { - j = 0; - k = i; - while (parent[k] >= 0) { k = parent[k]; j++; } - len[i-1] = j; - if (j > maxLen) tooLong = True; - } - - if (! tooLong) break; - - for (i = 1; i < alphaSize; i++) { - j = weight[i] >> 8; - j = 1 + (j / 2); - weight[i] = j << 8; - } - } -} - - -/*---------------------------------------------------*/ -void BZ2_hbAssignCodes ( Int32 *code, - UChar *length, - Int32 minLen, - Int32 maxLen, - Int32 alphaSize ) -{ - Int32 n, vec, i; - - vec = 0; - for (n = minLen; n <= maxLen; n++) { - for (i = 0; i < alphaSize; i++) - if (length[i] == n) { code[i] = vec; vec++; }; - vec <<= 1; - } -} - - -/*---------------------------------------------------*/ -void BZ2_hbCreateDecodeTables ( Int32 *limit, - Int32 *base, - Int32 *perm, - UChar *length, - Int32 minLen, - Int32 maxLen, - Int32 alphaSize ) -{ - Int32 pp, i, j, vec; - - pp = 0; - for (i = minLen; i <= maxLen; i++) - for (j = 0; j < alphaSize; j++) - if (length[j] == i) { perm[pp] = j; pp++; }; - - for (i = 0; i < BZ_MAX_CODE_LEN; i++) base[i] = 0; - for (i = 0; i < alphaSize; i++) base[length[i]+1]++; - - for (i = 1; i < BZ_MAX_CODE_LEN; i++) base[i] += base[i-1]; - - for (i = 0; i < BZ_MAX_CODE_LEN; i++) limit[i] = 0; - vec = 0; - - for (i = minLen; i <= maxLen; i++) { - vec += (base[i+1] - base[i]); - limit[i] = vec-1; - vec <<= 1; - } - for (i = minLen + 1; i <= maxLen; i++) - base[i] = ((limit[i-1] + 1) << 1) - base[i]; -} - - -/*-------------------------------------------------------------*/ -/*--- end huffman.c ---*/ -/*-------------------------------------------------------------*/ diff --git a/mdk-stage1/bzlib/randtable.c b/mdk-stage1/bzlib/randtable.c deleted file mode 100644 index a1fc82cfb..000000000 --- a/mdk-stage1/bzlib/randtable.c +++ /dev/null @@ -1,128 +0,0 @@ - -/*-------------------------------------------------------------*/ -/*--- Table for randomising repetitive blocks ---*/ -/*--- randtable.c ---*/ -/*-------------------------------------------------------------*/ - -/*-- - This file is a part of bzip2 and/or libbzip2, a program and - library for lossless, block-sorting data compression. - - Copyright (C) 1996-2000 Julian R Seward. All rights reserved. - - Redistribution and use in source and binary forms, with or without - modification, are permitted provided that the following conditions - are met: - - 1. Redistributions of source code must retain the above copyright - notice, this list of conditions and the following disclaimer. - - 2. The origin of this software must not be misrepresented; you must - not claim that you wrote the original software. If you use this - software in a product, an acknowledgment in the product - documentation would be appreciated but is not required. - - 3. Altered source versions must be plainly marked as such, and must - not be misrepresented as being the original software. - - 4. The name of the author may not be used to endorse or promote - products derived from this software without specific prior written - permission. - - THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS - OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED - WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY - DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE - GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS - INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, - WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING - NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS - SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - - Julian Seward, Cambridge, UK. - jseward@acm.org - bzip2/libbzip2 version 1.0 of 21 March 2000 - - This program is based on (at least) the work of: - Mike Burrows - David Wheeler - Peter Fenwick - Alistair Moffat - Radford Neal - Ian H. Witten - Robert Sedgewick - Jon L. Bentley - - For more information on these sources, see the manual. ---*/ - -#ifdef HAVE_CONFIG_H -#include <config.h> -#endif - - -#include "bzlib_private.h" - - -/*---------------------------------------------*/ -Int32 BZ2_rNums[512] = { - 619, 720, 127, 481, 931, 816, 813, 233, 566, 247, - 985, 724, 205, 454, 863, 491, 741, 242, 949, 214, - 733, 859, 335, 708, 621, 574, 73, 654, 730, 472, - 419, 436, 278, 496, 867, 210, 399, 680, 480, 51, - 878, 465, 811, 169, 869, 675, 611, 697, 867, 561, - 862, 687, 507, 283, 482, 129, 807, 591, 733, 623, - 150, 238, 59, 379, 684, 877, 625, 169, 643, 105, - 170, 607, 520, 932, 727, 476, 693, 425, 174, 647, - 73, 122, 335, 530, 442, 853, 695, 249, 445, 515, - 909, 545, 703, 919, 874, 474, 882, 500, 594, 612, - 641, 801, 220, 162, 819, 984, 589, 513, 495, 799, - 161, 604, 958, 533, 221, 400, 386, 867, 600, 782, - 382, 596, 414, 171, 516, 375, 682, 485, 911, 276, - 98, 553, 163, 354, 666, 933, 424, 341, 533, 870, - 227, 730, 475, 186, 263, 647, 537, 686, 600, 224, - 469, 68, 770, 919, 190, 373, 294, 822, 808, 206, - 184, 943, 795, 384, 383, 461, 404, 758, 839, 887, - 715, 67, 618, 276, 204, 918, 873, 777, 604, 560, - 951, 160, 578, 722, 79, 804, 96, 409, 713, 940, - 652, 934, 970, 447, 318, 353, 859, 672, 112, 785, - 645, 863, 803, 350, 139, 93, 354, 99, 820, 908, - 609, 772, 154, 274, 580, 184, 79, 626, 630, 742, - 653, 282, 762, 623, 680, 81, 927, 626, 789, 125, - 411, 521, 938, 300, 821, 78, 343, 175, 128, 250, - 170, 774, 972, 275, 999, 639, 495, 78, 352, 126, - 857, 956, 358, 619, 580, 124, 737, 594, 701, 612, - 669, 112, 134, 694, 363, 992, 809, 743, 168, 974, - 944, 375, 748, 52, 600, 747, 642, 182, 862, 81, - 344, 805, 988, 739, 511, 655, 814, 334, 249, 515, - 897, 955, 664, 981, 649, 113, 974, 459, 893, 228, - 433, 837, 553, 268, 926, 240, 102, 654, 459, 51, - 686, 754, 806, 760, 493, 403, 415, 394, 687, 700, - 946, 670, 656, 610, 738, 392, 760, 799, 887, 653, - 978, 321, 576, 617, 626, 502, 894, 679, 243, 440, - 680, 879, 194, 572, 640, 724, 926, 56, 204, 700, - 707, 151, 457, 449, 797, 195, 791, 558, 945, 679, - 297, 59, 87, 824, 713, 663, 412, 693, 342, 606, - 134, 108, 571, 364, 631, 212, 174, 643, 304, 329, - 343, 97, 430, 751, 497, 314, 983, 374, 822, 928, - 140, 206, 73, 263, 980, 736, 876, 478, 430, 305, - 170, 514, 364, 692, 829, 82, 855, 953, 676, 246, - 369, 970, 294, 750, 807, 827, 150, 790, 288, 923, - 804, 378, 215, 828, 592, 281, 565, 555, 710, 82, - 896, 831, 547, 261, 524, 462, 293, 465, 502, 56, - 661, 821, 976, 991, 658, 869, 905, 758, 745, 193, - 768, 550, 608, 933, 378, 286, 215, 979, 792, 961, - 61, 688, 793, 644, 986, 403, 106, 366, 905, 644, - 372, 567, 466, 434, 645, 210, 389, 550, 919, 135, - 780, 773, 635, 389, 707, 100, 626, 958, 165, 504, - 920, 176, 193, 713, 857, 265, 203, 50, 668, 108, - 645, 990, 626, 197, 510, 357, 358, 850, 858, 364, - 936, 638 -}; - - -/*-------------------------------------------------------------*/ -/*--- end randtable.c ---*/ -/*-------------------------------------------------------------*/ diff --git a/mdk-stage1/cdrom.c b/mdk-stage1/cdrom.c index e951d35c3..199b1d830 100644 --- a/mdk-stage1/cdrom.c +++ b/mdk-stage1/cdrom.c @@ -37,14 +37,13 @@ static int mount_that_cd_device(char * dev_name) { char device_fullname[50]; + int mount_result; snprintf(device_fullname, sizeof(device_fullname), "/dev/%s", dev_name); -#ifdef MANDRAKE_MOVE - return my_mount(device_fullname, IMAGE_LOCATION, "supermount", 0); -#else - return my_mount(device_fullname, IMAGE_LOCATION, "iso9660", 0); -#endif + mount_result = my_mount(device_fullname, MEDIA_LOCATION, "iso9660", 0); + symlink(MEDIA_LOCATION_REL "/" ARCH, IMAGE_LOCATION); + return mount_result; } @@ -54,7 +53,7 @@ static enum return_type do_with_device(char * dev_name, char * dev_model) { if (!image_has_stage2()) { enum return_type results; - umount(IMAGE_LOCATION); + umount(MEDIA_LOCATION); results = ask_yes_no("That CDROM disc does not seem to be a " DISTRIB_NAME " Installation CDROM.\nRetry with another disc?"); if (results == RETURN_OK) return try_with_device(dev_name, dev_model); @@ -63,13 +62,11 @@ static enum return_type do_with_device(char * dev_name, char * dev_model) log_message("found a " DISTRIB_NAME " CDROM, good news!"); -#ifndef MANDRAKE_MOVE - may_load_clp(); + may_load_compressed_image(); if (!KEEP_MOUNTED) /* in rescue mode, we don't need the media anymore */ - umount(IMAGE_LOCATION); -#endif + umount(MEDIA_LOCATION); add_to_env("METHOD", "cdrom"); return RETURN_OK; @@ -117,7 +114,7 @@ int try_automatic(char ** medias, char ** medias_models) return i; } else - umount(IMAGE_LOCATION); + umount(MEDIA_LOCATION); } remove_wait_message(); @@ -144,6 +141,10 @@ enum return_type cdrom_prepare(void) if ((i = try_automatic(medias, medias_models)) != -1) return do_with_device(medias[i], medias_models[i]); + get_medias(CDROM, &medias, &medias_models, BUS_PCMCIA); + if ((i = try_automatic(medias, medias_models)) != -1) + return do_with_device(medias[i], medias_models[i]); + my_insmod("sr_mod", ANY_DRIVER_TYPE, NULL, 0); get_medias(CDROM, &medias, &medias_models, BUS_SCSI); if ((i = try_automatic(medias, medias_models)) != -1) diff --git a/mdk-stage1/config-stage1.h b/mdk-stage1/config-stage1.h index 54e3656f3..616783abc 100644 --- a/mdk-stage1/config-stage1.h +++ b/mdk-stage1/config-stage1.h @@ -33,57 +33,33 @@ #define KA_MAX_RETRY 5 -#define SLASH_LOCATION "/sysroot" - -#ifdef MANDRAKE_MOVE - -#define MEM_LIMIT_MOVE 120 - -#undef DISTRIB_NAME -#define DISTRIB_NAME "Mandrakemove" -#undef DISTRIB_DESCR -#define DISTRIB_DESCR DISTRIB_NAME - -#define IMAGE_LOCATION_DIR SLASH_LOCATION "/" -#define IMAGE_LOCATION_REL "cdrom" -#define IMAGE_LOCATION IMAGE_LOCATION_DIR IMAGE_LOCATION_REL - -#define CLP_LOCATION IMAGE_LOCATION - -#define STAGE2_LOCATION_ROOTED "/image" -#define STAGE2_LOCATION SLASH_LOCATION STAGE2_LOCATION_ROOTED - -#define BOOT_LOCATION SLASH_LOCATION "/image_boot" -#define ALWAYS_LOCATION SLASH_LOCATION "/image_always" -#define TOTEM_LOCATION SLASH_LOCATION "/image_totem" - -#else - #define LIVE_LOCATION_REL "install/stage2/live/" -#define CLP_LOCATION_REL "install/stage2/" -#define CLP_STAGE2_NAME "mdkinst.clp" -#define CLP_RESCUE_NAME "rescue.clp" -#define CLP_NAME(prefix) (IS_RESCUE ? prefix CLP_RESCUE_NAME : prefix CLP_STAGE2_NAME) -#define CLP_FILE_REL(prefix) CLP_NAME(prefix CLP_LOCATION_REL) - -/* the remote media is mounted in - - IMAGE_LOCATION_DIR "nfsimage", and IMAGE_LOCATION is a symlink image -> nfsimage/mdk/mirror/dir - - IMAGE_LOCATION_DIR "hdimage", and IMAGE_LOCATION is a symlink image -> hdimage/mdk/mirror/dir - - directly in IMAGE_LOCATION (for cdroms and .iso images) +#define COMPRESSED_LOCATION_REL "install/stage2/" +#define COMPRESSED_STAGE2_NAME "mdkinst.sqfs" +#define COMPRESSED_RESCUE_NAME "rescue.sqfs" +#define COMPRESSED_NAME(prefix) (IS_RESCUE ? prefix COMPRESSED_RESCUE_NAME : prefix COMPRESSED_STAGE2_NAME) +#define COMPRESSED_FILE_REL(prefix) COMPRESSED_NAME(prefix COMPRESSED_LOCATION_REL) + +/* the remote media is mounted in MEDIA_LOCATION, and + - IMAGE_LOCATION is a symlink image -> image/mdk/mirror/dir + - IMAGE_LOCATION is a symlink image -> loop/i586 and iso file is loopback mounted in LOOP_LOCATION */ -#define IMAGE_LOCATION_DIR SLASH_LOCATION "/tmp/" +#define MEDIA_LOCATION_REL "media" +#define MEDIA_LOCATION IMAGE_LOCATION_DIR MEDIA_LOCATION_REL + +#define LOOP_LOCATION_REL "loop" +#define LOOP_LOCATION IMAGE_LOCATION_DIR LOOP_LOCATION_REL + #define IMAGE_LOCATION_REL "image" +#define IMAGE_LOCATION_DIR "/tmp/" #define IMAGE_LOCATION IMAGE_LOCATION_DIR IMAGE_LOCATION_REL -#define CLP_LOCATION IMAGE_LOCATION "/" CLP_LOCATION_REL +#define COMPRESSED_LOCATION IMAGE_LOCATION "/" COMPRESSED_LOCATION_REL -/* - if we use a clp : STAGE2_LOCATION is a the mount point - - if we use the live: STAGE2_LOCATION is a relative symlink to IMAGE_LOCATION_REL/install/stage2/live +/* - if we use a compressed image : STAGE2_LOCATION is a the mount point + - if we use the live: STAGE2_LOCATION is a relative symlink to image/install/stage2/live */ -#define STAGE2_LOCATION_ROOTED "/tmp/stage2" -#define STAGE2_LOCATION SLASH_LOCATION STAGE2_LOCATION_ROOTED - -#endif +#define STAGE2_LOCATION "/tmp/stage2" /* user-definable (in Makefile): DISABLE_NETWORK, DISABLE_DISK, DISABLE_CDROM, DISABLE_PCMCIA */ diff --git a/mdk-stage1/directory.c b/mdk-stage1/directory.c index 6115b600c..6957efbda 100644 --- a/mdk-stage1/directory.c +++ b/mdk-stage1/directory.c @@ -65,10 +65,11 @@ static void choose_iso_in_directory(char *directory, char *location_full) strcat(isofile, "/"); strcat(isofile, *file); - if (lomount(isofile, IMAGE_LOCATION, &loopdev, 0)) { + if (lomount(isofile, LOOP_LOCATION, &loopdev, 0)) { log_message("unable to mount iso file \"%s\", skipping", isofile); continue; } + symlink(LOOP_LOCATION_REL "/" ARCH, IMAGE_LOCATION); if (image_has_stage2()) { log_message("stage2 installer found in ISO image \"%s\"", isofile); @@ -77,7 +78,8 @@ static void choose_iso_in_directory(char *directory, char *location_full) log_message("ISO image \"%s\" doesn't contain stage2 installer", isofile); } - umount(IMAGE_LOCATION); + unlink(IMAGE_LOCATION); + umount(LOOP_LOCATION); del_loop(loopdev); } @@ -122,46 +124,35 @@ enum return_type try_with_directory(char *directory, char *method_live, char *me unlink(IMAGE_LOCATION); strcpy(location_full, directory); -#ifndef MANDRAKE_MOVE if (!stat(directory, &statbuf) && S_ISDIR(statbuf.st_mode)) { choose_iso_in_directory(directory, location_full); } -#endif loopdev = NULL; if (!stat(location_full, &statbuf) && !S_ISDIR(statbuf.st_mode)) { log_message("%s exists and is not a directory, assuming this is an ISO image", location_full); - if (lomount(location_full, IMAGE_LOCATION, &loopdev, 0)) { + if (lomount(location_full, LOOP_LOCATION, &loopdev, 0)) { stg1_error_message("Could not mount file %s as an ISO image of the " DISTRIB_NAME " Distribution.", location_full); return RETURN_ERROR; } + symlink(LOOP_LOCATION_REL "/" ARCH, IMAGE_LOCATION); add_to_env("ISOPATH", location_full); add_to_env("METHOD", method_iso); } else { int offset = strncmp(location_full, IMAGE_LOCATION_DIR, sizeof(IMAGE_LOCATION_DIR) - 1) == 0 ? sizeof(IMAGE_LOCATION_DIR) - 1 : 0; log_message("assuming %s is a mirror tree", location_full + offset); - rmdir(IMAGE_LOCATION); /* useful if we loopback mounted it */ symlink(location_full + offset, IMAGE_LOCATION); add_to_env("METHOD", method_live); } -#ifdef MANDRAKE_MOVE - if (access(IMAGE_LOCATION "/live_tree/etc/fstab", R_OK) && access(IMAGE_LOCATION "/live_tree.clp", R_OK)) { + if (access(IMAGE_LOCATION "/" COMPRESSED_LOCATION_REL, R_OK)) { stg1_error_message("I can't find the " DISTRIB_NAME " Distribution in the specified directory. " - "(I need the file " IMAGE_LOCATION "/live_tree/etc/fstab" ")\n" + "(I need the subdirectory " COMPRESSED_LOCATION_REL ")\n" "Here's a short extract of the files in the directory:\n" "%s", extract_list_directory(IMAGE_LOCATION)); ret = RETURN_BACK; - } -#else - if (access(IMAGE_LOCATION "/" CLP_LOCATION_REL, R_OK)) { - stg1_error_message("I can't find the " DISTRIB_NAME " Distribution in the specified directory. " - "(I need the subdirectory " CLP_LOCATION_REL ")\n" - "Here's a short extract of the files in the directory:\n" - "%s", extract_list_directory(IMAGE_LOCATION)); - ret = RETURN_BACK; - } else if (may_load_clp() != RETURN_OK) { + } else if (may_load_compressed_image() != RETURN_OK) { stg1_error_message("Could not load program into memory."); ret = RETURN_ERROR; } @@ -169,10 +160,9 @@ enum return_type try_with_directory(char *directory, char *method_live, char *me if (ret == RETURN_OK) log_message("found the " DISTRIB_NAME " Installation, good news!"); -#endif if (!KEEP_MOUNTED || ret != RETURN_OK) { /* in rescue mode, we don't need the media anymore */ - umount(IMAGE_LOCATION); + umount(LOOP_LOCATION); del_loop(loopdev); } diff --git a/mdk-stage1/disk.c b/mdk-stage1/disk.c index e3e84d7da..4b85347f5 100644 --- a/mdk-stage1/disk.c +++ b/mdk-stage1/disk.c @@ -34,7 +34,6 @@ #include "probing.h" #include "log.h" #include "mount.h" -#include "lomount.h" #include "automatic.h" #include "directory.h" #include "partition.h" @@ -48,8 +47,6 @@ static enum return_type try_with_device(char *dev_name) static char ** answers_location = NULL; char location_full[500]; - char * disk_own_mount = IMAGE_LOCATION_DIR "hdimage"; - char * parts[50]; char * parts_comments[50]; enum return_type results; @@ -74,8 +71,8 @@ static enum return_type try_with_device(char *dev_name) return results; } - /* in testing mode, assume the partition is already mounted on IMAGE_LOCATION_DIR "hdimage" */ - if (!IS_TESTING && try_mount(choice, disk_own_mount)) { + /* in testing mode, assume the partition is already mounted on MEDIA_LOCATION */ + if (!IS_TESTING && try_mount(choice, MEDIA_LOCATION)) { stg1_error_message("I can't find a valid filesystem (tried: ext2, vfat, ntfs, reiserfs). " "Make sure the partition has been cleanly unmounted."); return try_with_device(dev_name); @@ -85,11 +82,11 @@ static enum return_type try_with_device(char *dev_name) if (ask_from_entries_auto("Please enter the directory (or ISO image file) containing the " DISTRIB_NAME " Distribution install source.", questions_location, &answers_location, 24, questions_location_auto, NULL) != RETURN_OK) { - umount(disk_own_mount); + umount(MEDIA_LOCATION); return try_with_device(dev_name); } - strcpy(location_full, disk_own_mount); + strcpy(location_full, MEDIA_LOCATION); strcat(location_full, "/"); strcat(location_full, answers_location[0]); @@ -108,7 +105,7 @@ static enum return_type try_with_device(char *dev_name) } if (!KEEP_MOUNTED) - umount(disk_own_mount); + umount(MEDIA_LOCATION); return RETURN_OK; } diff --git a/mdk-stage1/doc/TECH-INFOS b/mdk-stage1/doc/TECH-INFOS index e52134da5..67151410e 100644 --- a/mdk-stage1/doc/TECH-INFOS +++ b/mdk-stage1/doc/TECH-INFOS @@ -37,7 +37,11 @@ if nfs/ftp/http: if multiple interfaces detected: `interface' <- (list-of-detected-interfaces) - (if "auto", use the first interface with a link beat) + if "auto": + use the first interface with a link beat + if "wired": + use the first wired interface with a link beat + or the first wired interface if none has a link beat fi diff --git a/mdk-stage1/init.c b/mdk-stage1/init.c index f5a46010b..a47017b58 100644 --- a/mdk-stage1/init.c +++ b/mdk-stage1/init.c @@ -32,6 +32,11 @@ #define TIOCSCTTY 0x540E #endif + +#define BINARY "/sbin/stage1" +#define BINARY_STAGE2 "/usr/bin/runinstall2" + + char * env[] = { "PATH=/usr/bin:/bin:/sbin:/usr/sbin:/mnt/sbin:/mnt/usr/sbin:/mnt/bin:/mnt/usr/bin", "LD_LIBRARY_PATH=/lib:/usr/lib:/mnt/lib:/mnt/usr/lib:/usr/X11R6/lib:/mnt/usr/X11R6/lib" @@ -347,60 +352,10 @@ void unmount_filesystems(void) for (i = nb = 0; i < numfs; i++) if (fs[i].mounted) { -#ifdef MANDRAKE_MOVE - if (!strcmp(fs[i].name, "/cdrom") || !strcmp(fs[i].name, "/image_always")) - continue; -#endif printf("\tumount failed: %s\n", fs[i].name); if (strcmp(fs[i].fs, "ext3") == 0) nb++; /* don't count not-ext3 umount failed */ } -#ifdef MANDRAKE_MOVE - if (!disallow_eject) { - fd = open("/proc/fs/supermount/subfs", O_RDONLY, 0); - if (fd > 0) { - char devices[100][100]; - int i = 0; - char * ptr1, * ptr2; - size = read(fd, buf, sizeof(buf) - 1); - buf[size] = '\0'; - close(fd); - ptr1 = buf; - ptr2 = buf; - while (*ptr1 && *ptr2) { - char * ptrf = ptr1; - while (*ptr2 && *ptr2 != '\n') - ptr2++; - while (*ptrf && *ptrf != ' ') - ptrf++; - if (*ptrf) - *ptrf = '\0'; - strcpy(devices[i], ptr1); - i++; - if (*ptr2) - ptr2++; - ptr1 = ptr2; - } - while (i >= 1) { - i--; - strcat(devices[i], " release force"); - fd = open("/proc/fs/supermount/subfs", O_WRONLY, 0); - write(fd, devices[i], strlen(devices[i])); - close(fd); - } - } - fd = open("/dev/cdrom", O_RDONLY|O_NONBLOCK, 0); - if (fd > 0) { - ioctl(fd, CDROM_LOCKDOOR, 0); - close(fd); - } - fd = open("/dev/cdrom", O_RDONLY|O_NONBLOCK, 0); - if (fd > 0) { - ioctl(fd, CDROMEJECT, 0); - close(fd); - } - } -#endif if (nb) { printf("failed to umount some filesystems\n"); @@ -437,6 +392,7 @@ int main(int argc, char **argv) pid_t installpid, childpid; int wait_status; int fd; + int counter = 0; int abnormal_termination = 0; if (argc > 1 && argv[1][0] >= '0' && argv[1][0] <= '9') { @@ -455,9 +411,12 @@ int main(int argc, char **argv) if (!testing) { - mkdir("/proc", 0755); + mkdir("/proc", 0755); if (mount("/proc", "/proc", "proc", 0, NULL)) fatal_error("Unable to mount proc filesystem"); + mkdir("/sys", 0755); + if (mount("none", "/sys", "sysfs", 0, NULL)) + fatal_error("Unable to mount sysfs filesystem"); } @@ -465,11 +424,6 @@ int main(int argc, char **argv) signal(SIGINT, SIG_IGN); signal(SIGTSTP, SIG_IGN); -#ifdef MANDRAKE_MOVE - /* disallow Ctrl Alt Del to reboot */ - reboot(0xfee1dead, 672274793, BMAGIC_SOFT); -#endif - if (!testing) { fd = open("/dev/console", O_RDWR, 0); if (fd < 0) @@ -506,20 +460,26 @@ int main(int argc, char **argv) */ do { + if (counter == 1) { + printf("proceeding, please wait...\n"); + } + if (!(installpid = fork())) { /* child */ char * child_argv[2]; - child_argv[0] = BINARY; + child_argv[0] = counter == 0 ? BINARY : BINARY_STAGE2; child_argv[1] = NULL; execve(child_argv[0], child_argv, env); - printf("error in exec of %s :-( [%d]\n", BINARY, errno); + printf("error in exec of %s :-( [%d]\n", child_argv[0], errno); return 0; } do { childpid = wait4(-1, &wait_status, 0, NULL); } while (childpid != installpid); + + counter++; } while (WIFEXITED(wait_status) && WEXITSTATUS(wait_status) == exit_value_restart); /* allow Ctrl Alt Del to reboot */ @@ -530,7 +490,12 @@ int main(int argc, char **argv) } else if (WIFEXITED(wait_status) && WEXITSTATUS(wait_status) == exit_value_proceed) { kill(klog_pid, 9); printf("proceeding, please wait...\n"); - return 0; + + { + char * child_argv[2] = { "/sbin/init", NULL }; + execve(child_argv[0], child_argv, env); + } + fatal_error("failed to exec /sbin/init"); } else if (!WIFEXITED(wait_status) || WEXITSTATUS(wait_status) != 0) { printf("exited abnormally :-( "); if (WIFSIGNALED(wait_status)) diff --git a/mdk-stage1/insmod-busybox/.cvsignore b/mdk-stage1/insmod-busybox/.cvsignore deleted file mode 100644 index 26a2c08c9..000000000 --- a/mdk-stage1/insmod-busybox/.cvsignore +++ /dev/null @@ -1,2 +0,0 @@ -insmod -insmod-DIET diff --git a/mdk-stage1/insmod-busybox/Config.h b/mdk-stage1/insmod-busybox/Config.h deleted file mode 100644 index f02ac0253..000000000 --- a/mdk-stage1/insmod-busybox/Config.h +++ /dev/null @@ -1,133 +0,0 @@ -/* vi: set sw=4 ts=4: */ -// This file defines the feature set to be compiled into busybox. -// When you turn things off here, they won't be compiled in at all. -// -//// This file is parsed by sed. You MUST use single line comments. -// i.e. //#define BB_BLAH -// -// -// BusyBox Applications -#define BB_INSMOD -// End of Applications List -// -// -// -// --------------------------------------------------------- -// This is where feature definitions go. Generally speaking, -// turning this stuff off makes things a bit smaller (and less -// pretty/useful). -// -// -// -// Turn this on to use Erik's very cool devps, and devmtab kernel drivers, -// thereby eliminating the need for the /proc filesystem and thereby saving -// lots and lots memory for more important things. You can not use this and -// USE_PROCFS at the same time... NOTE: If you enable this feature, you -// _must_ have patched the kernel to include the devps patch that is included -// in the busybox/kernel-patches directory. You will also need to create some -// device special files in /dev on your embedded system: -// mknod /dev/mtab c 10 22 -// mknod /dev/ps c 10 21 -// I emailed Linus and this patch will not be going into the stock kernel. -//#define BB_FEATURE_USE_DEVPS_PATCH -// -// enable features that use the /proc filesystem (apps that -// break without this will tell you on compile)... -// You can't use this and BB_FEATURE_USE_DEVPS_PATCH -// at the same time... -#define BB_FEATURE_USE_PROCFS - -// -// Enable tab completion in the shell (not yet -// working very well -- so don't turn this on) -//#define BB_FEATURE_SH_TAB_COMPLETION -// -//Turn on extra fbset options -//#define BB_FEATURE_FBSET_FANCY -// -//Turn on fbset readmode support -//#define BB_FEATURE_FBSET_READMODE -// -// You must enable one or both of these features -// Support insmod/lsmod/rmmod for post 2.1 kernels -#define BB_FEATURE_NEW_MODULE_INTERFACE -// -// Support insmod/lsmod/rmmod for pre 2.1 kernels -//#define BB_FEATURE_OLD_MODULE_INTERFACE -// -// Support module version checking -//#define BB_FEATURE_INSMOD_VERSION_CHECKING -// -// Support for Minix filesystem, version 2 -//#define BB_FEATURE_MINIX2 -// -// -// Enable busybox --install [-s] -// to create links (or symlinks) for all the commands that are -// compiled into the binary. (needs /proc filesystem) -// #define BB_FEATURE_INSTALLER -// -// Clean up all memory before exiting -- usually not needed -// as the OS can clean up... Don't enable this unless you -// have a really good reason for cleaning things up manually. -//#define BB_FEATURE_CLEAN_UP -// -// End of Features List -// -// -// -// -// -// -//--------------------------------------------------- -// Nothing beyond this point should ever be touched by -// mere mortals so leave this stuff alone. -// -#ifdef BB_FEATURE_MOUNT_MTAB_SUPPORT -#define BB_MTAB -#endif -// -#if defined BB_FEATURE_SH_COMMAND_EDITING && defined BB_SH -#define BB_CMDEDIT -#endif -// -#ifdef BB_KILLALL -#ifndef BB_KILL -#define BB_KILL -#endif -#endif -// -#ifdef BB_FEATURE_LINUXRC -#ifndef BB_INIT -#define BB_INIT -#endif -#define BB_LINUXRC -#endif -// -#ifdef BB_GZIP -#ifndef BB_GUNZIP -#define BB_GUNZIP -#endif -#endif -// -#if defined BB_MOUNT && defined BB_FEATURE_NFSMOUNT -#define BB_NFSMOUNT -#endif -// -#if defined BB_FEATURE_SH_COMMAND_EDITING -#ifndef BB_FEATURE_USE_TERMIOS -#define BB_FEATURE_USE_TERMIOS -#endif -#endif -// -#if defined BB_FEATURE_AUTOWIDTH -#ifndef BB_FEATURE_USE_TERMIOS -#define BB_FEATURE_USE_TERMIOS -#endif -#endif -// -#if defined BB_INSMOD -#if ! defined BB_FEATURE_NEW_MODULE_INTERFACE && ! defined BB_FEATURE_OLD_MODULE_INTERFACE -#define BB_FEATURE_NEW_MODULE_INTERFACE -#endif -#endif diff --git a/mdk-stage1/insmod-busybox/Makefile b/mdk-stage1/insmod-busybox/Makefile deleted file mode 100644 index 236874f96..000000000 --- a/mdk-stage1/insmod-busybox/Makefile +++ /dev/null @@ -1,43 +0,0 @@ - #****************************************************************************** - # - # insmod from busybox (i386 only) - # - # $Id$ - # - # Copyright (C) 1999,2000 by Lineo, inc. - # - #***************************************************************************** - -top_dir = .. - -include $(top_dir)/Makefile.common - - -all: insmod libinsmod.a - -clean: - rm -f *.o insmod libinsmod.a - - -FLAGS = -c -Wall -Os -fomit-frame-pointer -D_GNU_SOURCE -DBB_VER='"0.60.5"' -DBB_BT='"2003.04.16-15:25+0000"' - - -insmod: insmod-frontend.o insmod.o utility-standalone.o - $(DIET) gcc -o $@ $^ - $(STRIPCMD) $@ - -libinsmod.a: insmod.o utility.o - ar cru $@ $^ - ranlib $@ - -insmod-frontend.o: insmod-frontend.c busybox.h - $(DIET) gcc $(FLAGS) $(INCLUDES) insmod-frontend.c - -utility.o: utility.c busybox.h - $(DIET) gcc $(FLAGS) $(INCLUDES) utility.c - -utility-standalone.o: utility.c busybox.h - $(DIET) gcc $(FLAGS) $(INCLUDES) -o $@ -D_STANDALONE_ utility.c - -insmod.o: insmod.c busybox.h - $(DIET) gcc $(FLAGS) $(INCLUDES) insmod.c diff --git a/mdk-stage1/insmod-busybox/README b/mdk-stage1/insmod-busybox/README deleted file mode 100644 index 0ae697e92..000000000 --- a/mdk-stage1/insmod-busybox/README +++ /dev/null @@ -1,8 +0,0 @@ -This insmod code comes from busybox-0.60.5 - -<http://www.busybox.net/> - -Suported architectures: x86, x86-64, ppc, arm, sh3, sh4, m68k, mips. - - -gb diff --git a/mdk-stage1/insmod-busybox/busybox.h b/mdk-stage1/insmod-busybox/busybox.h deleted file mode 100644 index 9e6052fce..000000000 --- a/mdk-stage1/insmod-busybox/busybox.h +++ /dev/null @@ -1,477 +0,0 @@ -/* vi: set sw=4 ts=4: */ -/* - * Busybox main internal header file - * - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA - * - * Based in part on code from sash, Copyright (c) 1999 by David I. Bell - * Permission has been granted to redistribute this code under the GPL. - * - */ -#ifndef _BB_INTERNAL_H_ -#define _BB_INTERNAL_H_ 1 - -#include "Config.h" - -#ifdef DMALLOC -#include "dmalloc.h" -#endif - -#include <stdlib.h> -#include <stdarg.h> -#include <string.h> -#include <unistd.h> -#include <errno.h> -#include <sys/stat.h> -#include <sys/param.h> -/* for the _syscall() macros */ -#include <sys/syscall.h> -#include <linux/unistd.h> -#include <linux/kernel.h> - -/* Some useful definitions */ -#define FALSE ((int) 1) -#define TRUE ((int) 0) - -/* for mtab.c */ -#define MTAB_GETMOUNTPT '1' -#define MTAB_GETDEVICE '2' - -#define BUF_SIZE 8192 -#define EXPAND_ALLOC 1024 - - -#define isBlank(ch) (((ch) == ' ') || ((ch) == '\t')) -#define isDecimal(ch) (((ch) >= '0') && ((ch) <= '9')) -#define isOctal(ch) (((ch) >= '0') && ((ch) <= '7')) -#define isWildCard(ch) (((ch) == '*') || ((ch) == '?') || ((ch) == '[')) - -/* Macros for min/max. */ -#ifndef MIN -#define MIN(a,b) (((a)<(b))?(a):(b)) -#endif - -#ifndef MAX -#define MAX(a,b) (((a)>(b))?(a):(b)) -#endif - - -/* I don't like nested includes, but the string and io functions are used - * too often - */ -#include <stdio.h> -#if !defined(NO_STRING_H) || defined(STDC_HEADERS) -# include <string.h> -# if !defined(STDC_HEADERS) && !defined(NO_MEMORY_H) && !defined(__GNUC__) -# include <memory.h> -# endif -# define memzero(s, n) memset ((void *)(s), 0, (n)) -#else -# include <strings.h> -# define strchr index -# define strrchr rindex -# define memcpy(d, s, n) bcopy((s), (d), (n)) -# define memcmp(s1, s2, n) bcmp((s1), (s2), (n)) -# define memzero(s, n) bzero((s), (n)) -#endif - - -enum Location { - _BB_DIR_ROOT = 0, - _BB_DIR_BIN, - _BB_DIR_SBIN, - _BB_DIR_USR_BIN, - _BB_DIR_USR_SBIN -}; - -struct BB_applet { - const char* name; - int (*main)(int argc, char** argv); - enum Location location; - const char* usage; -}; -/* From busybox.c */ -extern const struct BB_applet applets[]; - -extern int ar_main(int argc, char **argv); -extern int basename_main(int argc, char **argv); -extern int bogomips_main(int argc, char **argv); -extern int busybox_main(int argc, char** argv); -extern int cat_main(int argc, char** argv); -extern int chmod_chown_chgrp_main(int argc, char** argv); -extern int chroot_main(int argc, char** argv); -extern int chvt_main(int argc, char** argv); -extern int clear_main(int argc, char** argv); -extern int cp_mv_main(int argc, char** argv); -extern int cut_main(int argc, char** argv); -extern int date_main(int argc, char** argv); -extern int dc_main(int argc, char** argv); -extern int dd_main(int argc, char** argv); -extern int dirname_main(int argc, char** argv); -extern int deallocvt_main(int argc, char** argv); -extern int df_main(int argc, char** argv); -extern int dmesg_main(int argc, char** argv); -extern int dos2unix_main(int argc, char** argv); -extern int du_main(int argc, char** argv); -extern int dumpkmap_main(int argc, char** argv); -extern int dutmp_main(int argc, char** argv); -extern int echo_main(int argc, char** argv); -extern int expr_main(int argc, char** argv); -extern int false_main(int argc, char** argv); -extern int fbset_main(int argc, char** argv); -extern int fdisk_main(int argc, char** argv); -extern int fdflush_main(int argc, char **argv); -extern int fsck_minix_main(int argc, char **argv); -extern int find_main(int argc, char** argv); -extern int free_main(int argc, char** argv); -extern int freeramdisk_main(int argc, char** argv); -extern int getopt_main(int argc, char** argv); -extern int grep_main(int argc, char** argv); -extern int gunzip_main (int argc, char** argv); -extern int gzip_main(int argc, char** argv); -extern int halt_main(int argc, char** argv); -extern int head_main(int argc, char** argv); -extern int hostid_main(int argc, char** argv); -extern int hostname_main(int argc, char** argv); -extern int id_main(int argc, char** argv); -extern int init_main(int argc, char** argv); -extern int insmod_main(int argc, char** argv); -extern int kill_main(int argc, char** argv); -extern int length_main(int argc, char** argv); -extern int ln_main(int argc, char** argv); -extern int loadacm_main(int argc, char** argv); -extern int loadfont_main(int argc, char** argv); -extern int loadkmap_main(int argc, char** argv); -extern int losetup_main(int argc, char** argv); -extern int logger_main(int argc, char **argv); -extern int logname_main(int argc, char **argv); -extern int ls_main(int argc, char** argv); -extern int lsmod_main(int argc, char** argv); -extern int makedevs_main(int argc, char** argv); -extern int md5sum_main(int argc, char** argv); -extern int mkdir_main(int argc, char** argv); -extern int mkfifo_main(int argc, char **argv); -extern int mkfs_minix_main(int argc, char **argv); -extern int mknod_main(int argc, char** argv); -extern int mkswap_main(int argc, char** argv); -extern int mktemp_main(int argc, char **argv); -extern int nc_main(int argc, char** argv); -extern int more_main(int argc, char** argv); -extern int mount_main(int argc, char** argv); -extern int mt_main(int argc, char** argv); -extern int nslookup_main(int argc, char **argv); -extern int ping_main(int argc, char **argv); -extern int poweroff_main(int argc, char **argv); -extern int printf_main(int argc, char** argv); -extern int ps_main(int argc, char** argv); -extern int pwd_main(int argc, char** argv); -extern int rdate_main(int argc, char** argv); -extern int reboot_main(int argc, char** argv); -extern int renice_main(int argc, char** argv); -extern int reset_main(int argc, char** argv); -extern int rm_main(int argc, char** argv); -extern int rmdir_main(int argc, char **argv); -extern int rmmod_main(int argc, char** argv); -extern int sed_main(int argc, char** argv); -extern int sfdisk_main(int argc, char** argv); -extern int setkeycodes_main(int argc, char** argv); -extern int shell_main(int argc, char** argv); -extern int sleep_main(int argc, char** argv); -extern int sort_main(int argc, char** argv); -extern int swap_on_off_main(int argc, char** argv); -extern int sync_main(int argc, char** argv); -extern int syslogd_main(int argc, char **argv); -extern int tail_main(int argc, char** argv); -extern int tar_main(int argc, char** argv); -extern int tee_main(int argc, char** argv); -extern int test_main(int argc, char** argv); -extern int telnet_main(int argc, char** argv); -extern int touch_main(int argc, char** argv); -extern int tr_main(int argc, char** argv); -extern int true_main(int argc, char** argv); -extern int tput_main(int argc, char** argv); -extern int tryopen_main(int argc, char** argv); -extern int tty_main(int argc, char** argv); -extern int umount_main(int argc, char** argv); -extern int uname_main(int argc, char** argv); -extern int uniq_main(int argc, char** argv); -extern int unix2dos_main(int argc, char** argv); -extern int unrpm_main(int argc, char** argv); -extern int update_main(int argc, char** argv); -extern int uptime_main(int argc, char** argv); -extern int usleep_main(int argc, char** argv); -extern int uuencode_main(int argc, char** argv); -extern int uudecode_main(int argc, char** argv); -extern int wc_main(int argc, char** argv); -extern int wget_main(int argc, char** argv); -extern int which_main(int argc, char** argv); -extern int whoami_main(int argc, char** argv); -extern int xargs_main(int argc, char** argv); -extern int yes_main(int argc, char** argv); - -extern const char ar_usage[]; -extern const char basename_usage[]; -extern const char cat_usage[]; -extern const char chgrp_usage[]; -extern const char chmod_usage[]; -extern const char chown_usage[]; -extern const char chroot_usage[]; -extern const char chvt_usage[]; -extern const char clear_usage[]; -extern const char cp_usage[]; -extern const char cut_usage[]; -extern const char date_usage[]; -extern const char dc_usage[]; -extern const char dd_usage[]; -extern const char deallocvt_usage[]; -extern const char df_usage[]; -extern const char dirname_usage[]; -extern const char dmesg_usage[]; -extern const char dos2unix_usage[]; -extern const char du_usage[]; -extern const char dumpkmap_usage[]; -extern const char dutmp_usage[]; -extern const char echo_usage[]; -extern const char expr_usage[]; -extern const char false_usage[]; -extern const char fdflush_usage[]; -extern const char find_usage[]; -extern const char free_usage[]; -extern const char freeramdisk_usage[]; -extern const char fsck_minix_usage[]; -extern const char grep_usage[]; -extern const char gunzip_usage[]; -extern const char gzip_usage[]; -extern const char halt_usage[]; -extern const char head_usage[]; -extern const char hostid_usage[]; -extern const char hostname_usage[]; -extern const char id_usage[]; -extern const char insmod_usage[]; -extern const char kill_usage[]; -extern const char killall_usage[]; -extern const char length_usage[]; -extern const char ln_usage[]; -extern const char loadacm_usage[]; -extern const char loadfont_usage[]; -extern const char loadkmap_usage[]; -extern const char logger_usage[]; -extern const char logname_usage[]; -extern const char ls_usage[]; -extern const char lsmod_usage[]; -extern const char makedevs_usage[]; -extern const char md5sum_usage[]; -extern const char mkdir_usage[]; -extern const char mkfifo_usage[]; -extern const char mkfs_minix_usage[]; -extern const char mknod_usage[]; -extern const char mkswap_usage[]; -extern const char mktemp_usage[]; -extern const char more_usage[]; -extern const char mount_usage[]; -extern const char mt_usage[]; -extern const char mv_usage[]; -extern const char nc_usage[]; -extern const char nslookup_usage[]; -extern const char ping_usage[]; -extern const char poweroff_usage[]; -extern const char printf_usage[]; -extern const char ps_usage[]; -extern const char pwd_usage[]; -extern const char rdate_usage[]; -extern const char reboot_usage[]; -extern const char renice_usage[]; -extern const char reset_usage[]; -extern const char rm_usage[]; -extern const char rmdir_usage[]; -extern const char rmmod_usage[]; -extern const char sed_usage[]; -extern const char setkeycodes_usage[]; -extern const char shell_usage[]; -extern const char sleep_usage[]; -extern const char sort_usage[]; -extern const char swapoff_usage[]; -extern const char swapon_usage[]; -extern const char sync_usage[]; -extern const char syslogd_usage[]; -extern const char tail_usage[]; -extern const char tar_usage[]; -extern const char tee_usage[]; -extern const char telnet_usage[]; -extern const char test_usage[]; -extern const char touch_usage[]; -extern const char tr_usage[]; -extern const char true_usage[]; -extern const char tty_usage[]; -extern const char umount_usage[]; -extern const char uname_usage[]; -extern const char uniq_usage[]; -extern const char unix2dos_usage[]; -extern const char unrpm_usage[]; -extern const char update_usage[]; -extern const char uptime_usage[]; -extern const char usleep_usage[]; -extern const char uudecode_usage[]; -extern const char uuencode_usage[]; -extern const char wc_usage[]; -extern const char wget_usage[]; -extern const char which_usage[]; -extern const char whoami_usage[]; -extern const char xargs_usage[]; -extern const char yes_usage[]; - -extern const char *applet_name; - -extern void usage(const char *usage) __attribute__ ((noreturn)); -extern void errorMsg(const char *s, ...) __attribute__ ((format (printf, 1, 2))); -extern void logperror(char *s); -extern void fatalError(const char *s, ...) __attribute__ ((noreturn, format (printf, 1, 2))); - -const char *modeString(int mode); -const char *timeString(time_t timeVal); -int isDirectory(const char *name, const int followLinks, struct stat *statBuf); -int isDevice(const char *name); - -typedef struct ino_dev_hash_bucket_struct { - struct ino_dev_hash_bucket_struct *next; - ino_t ino; - dev_t dev; - char name[1]; -} ino_dev_hashtable_bucket_t; -int is_in_ino_dev_hashtable(const struct stat *statbuf, char **name); -void add_to_ino_dev_hashtable(const struct stat *statbuf, const char *name); -void reset_ino_dev_hashtable(void); - -int copyFile(const char *srcName, const char *destName, - int setModes, int followLinks, int forceFlag); -int copySubFile(int srcFd, int dstFd, size_t remaining); -char *buildName(const char *dirName, const char *fileName); -int makeString(int argc, const char **argv, char *buf, int bufLen); -char *getChunk(int size); -char *chunkstrdup(const char *str); -void freeChunks(void); -int fullWrite(int fd, const char *buf, int len); -int fullRead(int fd, char *buf, int len); -int recursiveAction(const char *fileName, int recurse, int followLinks, int depthFirst, - int (*fileAction) (const char *fileName, struct stat* statbuf, void* userData), - int (*dirAction) (const char *fileName, struct stat* statbuf, void* userData), - void* userData); - -extern int createPath (const char *name, int mode); -extern int parse_mode( const char* s, mode_t* theMode); - -extern int get_kernel_revision(void); - -extern int get_console_fd(char* tty_name); -extern struct mntent *findMountPoint(const char *name, const char *table); -extern void write_mtab(char* blockDevice, char* directory, - char* filesystemType, long flags, char* string_flags); -extern void erase_mtab(const char * name); -extern void mtab_read(void); -extern char *mtab_first(void **iter); -extern char *mtab_next(void **iter); -extern char *mtab_getinfo(const char *match, const char which); -extern int check_wildcard_match(const char* text, const char* pattern); -extern long getNum (const char *cp); -extern pid_t* findPidByName( char* pidName); -extern int find_real_root_device_name(char* name); -extern char *get_line_from_file(FILE *file); -extern void print_file(FILE *file); -extern int print_file_by_name(char *filename); -extern char process_escape_sequence(char **ptr); -extern char *get_last_path_component(char *path); -// extern void xregcomp(regex_t *preg, const char *regex, int cflags); - -#ifndef DMALLOC -extern void *xmalloc (size_t size); -extern void *xrealloc(void *old, size_t size); -extern void *xcalloc(size_t nmemb, size_t size); -extern char *xstrdup (const char *s); -#endif -extern char *xstrndup (const char *s, int n); - - -/* These parse entries in /etc/passwd and /etc/group. This is desirable - * for BusyBox since we want to avoid using the glibc NSS stuff, which - * increases target size and is often not needed embedded systems. */ -extern long my_getpwnam(char *name); -extern long my_getgrnam(char *name); -extern void my_getpwuid(char *name, long uid); -extern void my_getgrgid(char *group, long gid); -extern long my_getpwnamegid(char *name); - -extern int device_open(char *device, int mode); - -#if defined BB_FEATURE_MOUNT_LOOP -extern int del_loop(const char *device); -extern int set_loop(const char *device, const char *file, int offset, int *loopro); -extern char *find_unused_loop_device (void); -#endif - - -#if (__GLIBC__ < 2) && (defined BB_SYSLOGD || defined BB_INIT) -extern int vdprintf(int d, const char *format, va_list ap); -#endif - -#if defined BB_NFSMOUNT -int nfsmount(const char *spec, const char *node, int *flags, - char **extra_opts, char **mount_opts, int running_bg); -#endif - -#ifndef RB_POWER_OFF -/* Stop system and switch power off if possible. */ -#define RB_POWER_OFF 0x4321fedc -#endif - -/* Include our own copy of struct sysinfo to avoid binary compatability - * problems with Linux 2.4, which changed things. Grumble, grumble. */ -//struct sysinfo { -// long uptime; /* Seconds since boot */ -// unsigned long loads[3]; /* 1, 5, and 15 minute load averages */ -// unsigned long totalram; /* Total usable main memory size */ -// unsigned long freeram; /* Available memory size */ -// unsigned long sharedram; /* Amount of shared memory */ -// unsigned long bufferram; /* Memory used by buffers */ -// unsigned long totalswap; /* Total swap space size */ -// unsigned long freeswap; /* swap space still available */ -// unsigned short procs; /* Number of current processes */ -// unsigned long totalhigh; /* Total high memory size */ -// unsigned long freehigh; /* Available high memory size */ -// unsigned int mem_unit; /* Memory unit size in bytes */ -// char _f[20-2*sizeof(long)-sizeof(int)]; /* Padding: libc5 uses this.. */ -//}; -extern int sysinfo (struct sysinfo* info); - -/* Bit map related macros -- libc5 doens't provide these... sigh. */ -#ifndef setbit -#define NBBY CHAR_BIT -#define setbit(a,i) ((a)[(i)/NBBY] |= 1<<((i)%NBBY)) -#define clrbit(a,i) ((a)[(i)/NBBY] &= ~(1<<((i)%NBBY))) -#define isset(a,i) ((a)[(i)/NBBY] & (1<<((i)%NBBY))) -#define isclr(a,i) (((a)[(i)/NBBY] & (1<<((i)%NBBY))) == 0) -#endif - -/* Merge from busybox 0.60.5 */ -#define error_msg errorMsg -#define perror_msg(FORMAT,...) error_msg(FORMAT ": %s", ## __VA_ARGS__, strerror(errno)) -#define recursive_action recursiveAction - -#define safe_strncpy(DST, SRC, SIZE) do { \ - (DST)[SIZE-1] = '\0'; \ - return strncpy((DST), (SRC),(SIZE)-1); \ -} while (0) - -#endif /* _BB_INTERNAL_H_ */ diff --git a/mdk-stage1/insmod-busybox/insmod-frontend.c b/mdk-stage1/insmod-busybox/insmod-frontend.c deleted file mode 100644 index 963a96893..000000000 --- a/mdk-stage1/insmod-busybox/insmod-frontend.c +++ /dev/null @@ -1,24 +0,0 @@ -/* - * Guillaume Cottenceau (gc@mandrakesoft.com) - * - * Copyright 2000 Mandrakesoft - * - * This software may be freely redistributed under the terms of the GNU - * public license. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. - * - */ - -#include <stdio.h> - - -int insmod_main( int argc, char **argv); - -int main( int argc, char **argv) -{ - printf("Using insmod provided by busybox.\n"); - return insmod_main(argc, argv); -} diff --git a/mdk-stage1/insmod-busybox/insmod.c b/mdk-stage1/insmod-busybox/insmod.c deleted file mode 100644 index e6e5b8f5f..000000000 --- a/mdk-stage1/insmod-busybox/insmod.c +++ /dev/null @@ -1,3758 +0,0 @@ -/* vi: set sw=4 ts=4: */ -/* - * Mini insmod implementation for busybox - * - * This version of insmod supports x86, ARM, SH3/4, powerpc, m68k, - * MIPS, and x86-64. - * - * - * Copyright (C) 1999,2000 by Lineo, inc. and Erik Andersen - * Copyright (C) 1999-2002 Erik Andersen <andersee@debian.org> - * Written by Erik Andersen and Ron Alder <alder@lineo.com> - * - * Modified by Bryan Rittmeyer <bryan@ixiacom.com> to support SH4 - * and (theoretically) SH3. I have only tested SH4 in little endian mode. - * - * Modified by Alcove, Julien Gaulmin <julien.gaulmin@alcove.fr> and - * Nicolas Ferre <nicolas.ferre@alcove.fr> to support ARM7TDMI. Only - * very minor changes required to also work with StrongArm and presumably - * all ARM based systems. - * - * Magnus Damm <damm@opensource.se> 22-May-2002. - * The plt and got code are now using the same structs. - * Added generic linked list code to fully support PowerPC. - * Replaced the mess in arch_apply_relocation() with architecture blocks. - * The arch_create_got() function got cleaned up with architecture blocks. - * These blocks should be easy maintain and sync with obj_xxx.c in modutils. - * - * Magnus Damm <damm@opensource.se> added PowerPC support 20-Feb-2001. - * PowerPC specific code stolen from modutils-2.3.16, - * written by Paul Mackerras, Copyright 1996, 1997 Linux International. - * I've only tested the code on mpc8xx platforms in big-endian mode. - * Did some cleanup and added BB_USE_xxx_ENTRIES... - * - * Quinn Jensen <jensenq@lineo.com> added MIPS support 23-Feb-2001. - * based on modutils-2.4.2 - * MIPS specific support for Elf loading and relocation. - * Copyright 1996, 1997 Linux International. - * Contributed by Ralf Baechle <ralf@gnu.ai.mit.edu> - * - * Based almost entirely on the Linux modutils-2.3.11 implementation. - * Copyright 1996, 1997 Linux International. - * New implementation contributed by Richard Henderson <rth@tamu.edu> - * Based on original work by Bjorn Ekwall <bj0rn@blox.se> - * Restructured (and partly rewritten) by: - * Björn Ekwall <bj0rn@blox.se> February 1999 - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA - * - */ - -#include "../insmod.h" -#include <stdlib.h> -#include <stdio.h> -#include <stddef.h> -#include <errno.h> -#include <unistd.h> -#include <dirent.h> -#include <ctype.h> -#include <assert.h> -#include <string.h> -#include <fcntl.h> -#include <sys/utsname.h> -#include "busybox.h" - -#ifdef BB_FEATURE_NEW_MODULE_INTERFACE -# undef BB_FEATURE_OLD_MODULE_INTERFACE -# define new_sys_init_module init_module -#else -# define old_sys_init_module init_module -#endif - -/* FIXME: Remove once we switched to dietlibc 0.22 */ -#if 0 - -#undef new_sys_init_module -#define __NR_new_sys_init_module __NR_init_module -struct new_module; -_syscall2(int, new_sys_init_module, const char *, name, - const struct new_module *, info) - -#undef old_sys_init_module -#define __NR_old_sys_init_module __NR_init_module -struct old_mod_routines; -struct old_symbol_table; -_syscall5(int, old_sys_init_module, const char *, name, char *, code, - unsigned, codesize, struct old_mod_routines *, routines, - struct old_symbol_table *, symtab) - -_syscall1(int, delete_module, const char *, name) - -#if defined(__i386__) || defined(__m68k__) || defined(__arm__) -/* Jump through hoops to fixup error return codes */ -#define __NR__create_module __NR_create_module -static inline _syscall2(long, _create_module, const char *, name, size_t, - size) -unsigned long create_module(const char *name, size_t size) -{ - long ret = _create_module(name, size); - - if (ret == -1 && errno > 125) { - ret = -errno; - errno = 0; - } - return ret; -} -#else -_syscall2(unsigned long, create_module, const char *, name, size_t, size) -#endif - -#endif - -#ifdef BB_FEATURE_INSMOD_LOADINKMEM -#define LOADBITS 0 -#else -#define LOADBITS 1 -#endif - -#if defined(__arm__) -#define BB_USE_PLT_ENTRIES -#define BB_PLT_ENTRY_SIZE 8 -#define BB_USE_GOT_ENTRIES -#define BB_GOT_ENTRY_SIZE 8 -#define BB_USE_SINGLE - -#define MATCH_MACHINE(x) (x == EM_ARM) -#define SHT_RELM SHT_REL -#define Elf32_RelM Elf32_Rel -#define ELFCLASSM ELFCLASS32 -#endif - -#if defined(__i386__) -#define BB_USE_GOT_ENTRIES -#define BB_GOT_ENTRY_SIZE 4 -#define BB_USE_SINGLE - -#ifndef EM_486 -#define MATCH_MACHINE(x) (x == EM_386) -#else -#define MATCH_MACHINE(x) (x == EM_386 || x == EM_486) -#endif - -#define SHT_RELM SHT_REL -#define Elf32_RelM Elf32_Rel -#define ELFCLASSM ELFCLASS32 -#endif - -#if defined(__x86_64__) -#define BB_USE_GOT_ENTRIES -#define BB_GOT_ENTRY_SIZE 8 -#define BB_USE_SINGLE - -#define MATCH_MACHINE(x) (x == EM_X86_64) - -#define SHT_RELM SHT_RELA -#define Elf64_RelM Elf64_Rela -#define ELFCLASSM ELFCLASS64 -#endif - -#if defined(__mc68000__) -#define BB_USE_GOT_ENTRIES -#define BB_GOT_ENTRY_SIZE 4 -#define BB_USE_SINGLE - -#define MATCH_MACHINE(x) (x == EM_68K) -#define SHT_RELM SHT_RELA -#define Elf32_RelM Elf32_Rela -#endif - -#if defined(__mips__) -/* Account for ELF spec changes. */ -#ifndef EM_MIPS_RS3_LE -#ifdef EM_MIPS_RS4_BE -#define EM_MIPS_RS3_LE EM_MIPS_RS4_BE -#else -#define EM_MIPS_RS3_LE 10 -#endif -#endif /* !EM_MIPS_RS3_LE */ - -#define MATCH_MACHINE(x) (x == EM_MIPS || x == EM_MIPS_RS3_LE) -#define SHT_RELM SHT_REL -#define Elf32_RelM Elf32_Rel -#define ELFCLASSM ELFCLASS32 -#define ARCHDATAM "__dbe_table" -#endif - -#if defined(__powerpc__) -#define BB_USE_PLT_ENTRIES -#define BB_PLT_ENTRY_SIZE 16 -#define BB_USE_PLT_LIST -#define BB_LIST_ARCHTYPE ElfW(Addr) -#define BB_USE_LIST - -#define MATCH_MACHINE(x) (x == EM_PPC) -#define SHT_RELM SHT_RELA -#define Elf32_RelM Elf32_Rela -#define ELFCLASSM ELFCLASS32 -#define ARCHDATAM "__ftr_fixup" -#endif - -#if defined(__sh__) -#define BB_USE_GOT_ENTRIES -#define BB_GOT_ENTRY_SIZE 4 -#define BB_USE_SINGLE - -#define MATCH_MACHINE(x) (x == EM_SH) -#define SHT_RELM SHT_RELA -#define Elf32_RelM Elf32_Rela -#define ELFCLASSM ELFCLASS32 - -/* the SH changes have only been tested on the SH4 in =little endian= mode */ -/* I'm not sure about big endian, so let's warn: */ - -#if (defined(__SH4__) || defined(__SH3__)) && defined(__BIG_ENDIAN__) -#error insmod.c may require changes for use on big endian SH4/SH3 -#endif - -/* it may or may not work on the SH1/SH2... So let's error on those - also */ -#if (defined(__sh__) && (!(defined(__SH3__) || defined(__SH4__)))) -#error insmod.c may require changes for non-SH3/SH4 use -#endif -#endif - -#ifndef SHT_RELM -#error Sorry, but insmod.c does not yet support this architecture... -#endif - -//---------------------------------------------------------------------------- -//--------modutils module.h, lines 45-242 -//---------------------------------------------------------------------------- - -/* Definitions for the Linux module syscall interface. - Copyright 1996, 1997 Linux International. - - Contributed by Richard Henderson <rth@tamu.edu> - - This file is part of the Linux modutils. - - This program is free software; you can redistribute it and/or modify it - under the terms of the GNU General Public License as published by the - Free Software Foundation; either version 2 of the License, or (at your - option) any later version. - - This program is distributed in the hope that it will be useful, but - WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - General Public License for more details. - - You should have received a copy of the GNU General Public License - along with this program; if not, write to the Free Software Foundation, - Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ - - -#ifndef MODUTILS_MODULE_H -#define MODUTILS_MODULE_H - -/* This file contains the structures used by the 2.0 and 2.1 kernels. - We do not use the kernel headers directly because we do not wish - to be dependant on a particular kernel version to compile insmod. */ - - -/*======================================================================*/ -/* The structures used by Linux 2.0. */ - -/* The symbol format used by get_kernel_syms(2). */ -struct old_kernel_sym -{ - unsigned long value; - char name[60]; -}; - -struct old_module_ref -{ - unsigned long module; /* kernel addresses */ - unsigned long next; -}; - -struct old_module_symbol -{ - unsigned long addr; - unsigned long name; -}; - -struct old_symbol_table -{ - int size; /* total, including string table!!! */ - int n_symbols; - int n_refs; - struct old_module_symbol symbol[0]; /* actual size defined by n_symbols */ - struct old_module_ref ref[0]; /* actual size defined by n_refs */ -}; - -struct old_mod_routines -{ - unsigned long init; - unsigned long cleanup; -}; - -struct old_module -{ - unsigned long next; - unsigned long ref; /* the list of modules that refer to me */ - unsigned long symtab; - unsigned long name; - int size; /* size of module in pages */ - unsigned long addr; /* address of module */ - int state; - unsigned long cleanup; /* cleanup routine */ -}; - -/* Sent to init_module(2) or'ed into the code size parameter. */ -static const int OLD_MOD_AUTOCLEAN = 0x40000000; /* big enough, but no sign problems... */ - -int get_kernel_syms(struct old_kernel_sym *); -int old_sys_init_module(const char *name, char *code, unsigned codesize, - struct old_mod_routines *, struct old_symbol_table *); - -/*======================================================================*/ -/* For sizeof() which are related to the module platform and not to the - environment isnmod is running in, use sizeof_xx instead of sizeof(xx). */ - -#define tgt_sizeof_char sizeof(char) -#define tgt_sizeof_short sizeof(short) -#define tgt_sizeof_int sizeof(int) -#define tgt_sizeof_long sizeof(long) -#define tgt_sizeof_char_p sizeof(char *) -#define tgt_sizeof_void_p sizeof(void *) -#define tgt_long long - -#if defined(__sparc__) && !defined(__sparc_v9__) && defined(ARCH_sparc64) -#undef tgt_sizeof_long -#undef tgt_sizeof_char_p -#undef tgt_sizeof_void_p -#undef tgt_long -static const int tgt_sizeof_long = 8; -static const int tgt_sizeof_char_p = 8; -static const int tgt_sizeof_void_p = 8; -#define tgt_long long long -#endif - -/*======================================================================*/ -/* The structures used in Linux 2.1. */ - -/* Note: new_module_symbol does not use tgt_long intentionally */ -struct new_module_symbol -{ - unsigned long value; - unsigned long name; -}; - -struct new_module_persist; - -struct new_module_ref -{ - unsigned tgt_long dep; /* kernel addresses */ - unsigned tgt_long ref; - unsigned tgt_long next_ref; -}; - -struct new_module -{ - unsigned tgt_long size_of_struct; /* == sizeof(module) */ - unsigned tgt_long next; - unsigned tgt_long name; - unsigned tgt_long size; - - tgt_long usecount; - unsigned tgt_long flags; /* AUTOCLEAN et al */ - - unsigned nsyms; - unsigned ndeps; - - unsigned tgt_long syms; - unsigned tgt_long deps; - unsigned tgt_long refs; - unsigned tgt_long init; - unsigned tgt_long cleanup; - unsigned tgt_long ex_table_start; - unsigned tgt_long ex_table_end; -#ifdef __alpha__ - unsigned tgt_long gp; -#endif - /* Everything after here is extension. */ - unsigned tgt_long persist_start; - unsigned tgt_long persist_end; - unsigned tgt_long can_unload; - unsigned tgt_long runsize; -#ifdef BB_FEATURE_NEW_MODULE_INTERFACE - const char *kallsyms_start; /* All symbols for kernel debugging */ - const char *kallsyms_end; - const char *archdata_start; /* arch specific data for module */ - const char *archdata_end; - const char *kernel_data; /* Reserved for kernel internal use */ -#endif -}; - -#ifdef ARCHDATAM -#define ARCHDATA_SEC_NAME ARCHDATAM -#else -#define ARCHDATA_SEC_NAME "__archdata" -#endif -#define KALLSYMS_SEC_NAME "__kallsyms" - - -struct new_module_info -{ - unsigned long addr; - unsigned long size; - unsigned long flags; - long usecount; -}; - -/* Bits of module.flags. */ -static const int NEW_MOD_RUNNING = 1; -static const int NEW_MOD_DELETED = 2; -static const int NEW_MOD_AUTOCLEAN = 4; -static const int NEW_MOD_VISITED = 8; -static const int NEW_MOD_USED_ONCE = 16; - -int new_sys_init_module(const char *name, const struct new_module *); -int query_module(const char *name, int which, void *buf, size_t bufsize, - size_t *ret); - -/* Values for query_module's which. */ - -static const int QM_MODULES = 1; -static const int QM_DEPS = 2; -static const int QM_REFS = 3; -static const int QM_SYMBOLS = 4; -static const int QM_INFO = 5; - -/*======================================================================*/ -/* The system calls unchanged between 2.0 and 2.1. */ - -unsigned long create_module(const char *, size_t); -int delete_module(const char *); - - -#endif /* module.h */ - -//---------------------------------------------------------------------------- -//--------end of modutils module.h -//---------------------------------------------------------------------------- - - - -//---------------------------------------------------------------------------- -//--------modutils obj.h, lines 253-462 -//---------------------------------------------------------------------------- - -/* Elf object file loading and relocation routines. - Copyright 1996, 1997 Linux International. - - Contributed by Richard Henderson <rth@tamu.edu> - - This file is part of the Linux modutils. - - This program is free software; you can redistribute it and/or modify it - under the terms of the GNU General Public License as published by the - Free Software Foundation; either version 2 of the License, or (at your - option) any later version. - - This program is distributed in the hope that it will be useful, but - WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - General Public License for more details. - - You should have received a copy of the GNU General Public License - along with this program; if not, write to the Free Software Foundation, - Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ - - -#ifndef MODUTILS_OBJ_H -static const int MODUTILS_OBJ_H = 1; - -/* The relocatable object is manipulated using elfin types. */ - -#include <stdio.h> -#include <elf.h> -#include <endian.h> - -#if __BYTE_ORDER == __LITTLE_ENDIAN -#define ELFDATAM ELFDATA2LSB -#elif __BYTE_ORDER == __BIG_ENDIAN -#define ELFDATAM ELFDATA2MSB -#endif - -#ifndef ElfW -# if ELFCLASSM == ELFCLASS32 -# define ElfW(x) Elf32_ ## x -# define ELFW(x) ELF32_ ## x -# else -# define ElfW(x) Elf64_ ## x -# define ELFW(x) ELF64_ ## x -# endif -#endif - -/* For some reason this is missing from libc5. */ -#ifndef ELF32_ST_INFO -# define ELF32_ST_INFO(bind, type) (((bind) << 4) + ((type) & 0xf)) -#endif - -#ifndef ELF64_ST_INFO -# define ELF64_ST_INFO(bind, type) (((bind) << 4) + ((type) & 0xf)) -#endif - -struct obj_string_patch; -struct obj_symbol_patch; - -struct obj_section -{ - ElfW(Shdr) header; - const char *name; - char *contents; - struct obj_section *load_next; - int idx; -}; - -struct obj_symbol -{ - struct obj_symbol *next; /* hash table link */ - const char *name; - unsigned long value; - unsigned long size; - int secidx; /* the defining section index/module */ - int info; - int ksymidx; /* for export to the kernel symtab */ - int referenced; /* actually used in the link */ -}; - -/* Hardcode the hash table size. We shouldn't be needing so many - symbols that we begin to degrade performance, and we get a big win - by giving the compiler a constant divisor. */ - -#define HASH_BUCKETS 521 - -struct obj_file -{ - ElfW(Ehdr) header; - ElfW(Addr) baseaddr; - struct obj_section **sections; - struct obj_section *load_order; - struct obj_section **load_order_search_start; - struct obj_string_patch *string_patches; - struct obj_symbol_patch *symbol_patches; - int (*symbol_cmp)(const char *, const char *); - unsigned long (*symbol_hash)(const char *); - unsigned long local_symtab_size; - struct obj_symbol **local_symtab; - struct obj_symbol *symtab[HASH_BUCKETS]; -}; - -enum obj_reloc -{ - obj_reloc_ok, - obj_reloc_overflow, - obj_reloc_dangerous, - obj_reloc_unhandled -}; - -struct obj_string_patch -{ - struct obj_string_patch *next; - int reloc_secidx; - ElfW(Addr) reloc_offset; - ElfW(Addr) string_offset; -}; - -struct obj_symbol_patch -{ - struct obj_symbol_patch *next; - int reloc_secidx; - ElfW(Addr) reloc_offset; - struct obj_symbol *sym; -}; - - -/* Generic object manipulation routines. */ - -static unsigned long obj_elf_hash(const char *); - -static unsigned long obj_elf_hash_n(const char *, unsigned long len); - -static struct obj_symbol *obj_find_symbol (struct obj_file *f, - const char *name); - -static ElfW(Addr) obj_symbol_final_value(struct obj_file *f, - struct obj_symbol *sym); - -#ifdef BB_FEATURE_INSMOD_VERSION_CHECKING -static void obj_set_symbol_compare(struct obj_file *f, - int (*cmp)(const char *, const char *), - unsigned long (*hash)(const char *)); -#endif - -static struct obj_section *obj_find_section (struct obj_file *f, - const char *name); - -static void obj_insert_section_load_order (struct obj_file *f, - struct obj_section *sec); - -static struct obj_section *obj_create_alloced_section (struct obj_file *f, - const char *name, - unsigned long align, - unsigned long size); - -static struct obj_section *obj_create_alloced_section_first (struct obj_file *f, - const char *name, - unsigned long align, - unsigned long size); - -static void *obj_extend_section (struct obj_section *sec, unsigned long more); - -static int obj_string_patch(struct obj_file *f, int secidx, ElfW(Addr) offset, - const char *string); - -#ifdef BB_FEATURE_NEW_MODULE_INTERFACE -static int obj_symbol_patch(struct obj_file *f, int secidx, ElfW(Addr) offset, - struct obj_symbol *sym); -#endif - -static int obj_check_undefineds(struct obj_file *f); - -static void obj_allocate_commons(struct obj_file *f); - -static unsigned long obj_load_size (struct obj_file *f); - -static int obj_relocate (struct obj_file *f, ElfW(Addr) base); - -static struct obj_file *obj_load(FILE *f, int loadprogbits); - -static int obj_create_image (struct obj_file *f, char *image); - -/* Architecture specific manipulation routines. */ - -static struct obj_file *arch_new_file (void); - -static struct obj_section *arch_new_section (void); - -static struct obj_symbol *arch_new_symbol (void); - -static enum obj_reloc arch_apply_relocation (struct obj_file *f, - struct obj_section *targsec, - struct obj_section *symsec, - struct obj_symbol *sym, - ElfW(RelM) *rel, ElfW(Addr) value); - -static void arch_create_got (struct obj_file *f); - -#ifdef BB_FEATURE_NEW_MODULE_INTERFACE -static int arch_init_module (struct obj_file *f, struct new_module *); -#endif - -#endif /* obj.h */ -//---------------------------------------------------------------------------- -//--------end of modutils obj.h -//---------------------------------------------------------------------------- - - - - - -#define _PATH_MODULES "/lib/modules" -static const int STRVERSIONLEN = 32; - -/*======================================================================*/ - -static const int flag_force_load = 1; -static const int flag_autoclean = 0; -static const int flag_quiet = 0; -static const int flag_export = 1; - - -/*======================================================================*/ - -#if defined(BB_USE_LIST) - -struct arch_list_entry -{ - struct arch_list_entry *next; - BB_LIST_ARCHTYPE addend; - int offset; - int inited : 1; -}; - -#endif - -#if defined(BB_USE_SINGLE) - -struct arch_single_entry -{ - int offset; - int inited : 1; - int allocated : 1; -}; - -#endif - -#if defined(__mips__) -struct mips_hi16 -{ - struct mips_hi16 *next; - Elf32_Addr *addr; - Elf32_Addr value; -}; -#endif - -struct arch_file { - struct obj_file root; -#if defined(BB_USE_PLT_ENTRIES) - struct obj_section *plt; -#endif -#if defined(BB_USE_GOT_ENTRIES) - struct obj_section *got; -#endif -#if defined(__mips__) - struct mips_hi16 *mips_hi16_list; -#endif -}; - -struct arch_symbol { - struct obj_symbol root; -#if defined(BB_USE_PLT_ENTRIES) -#if defined(BB_USE_PLT_LIST) - struct arch_list_entry *pltent; -#else - struct arch_single_entry pltent; -#endif -#endif -#if defined(BB_USE_GOT_ENTRIES) - struct arch_single_entry gotent; -#endif -}; - - -struct external_module { - const char *name; - ElfW(Addr) addr; - int used; - size_t nsyms; - struct new_module_symbol *syms; -}; - -static struct new_module_symbol *ksyms; -static size_t nksyms; - -static struct external_module *ext_modules; -static int n_ext_modules; -static int n_ext_modules_used; -extern int delete_module(const char *); - -#ifndef FILENAME_MAX -#define FILENAME_MAX 4095 -#endif - -static char m_filename[FILENAME_MAX]; -static char m_fullName[FILENAME_MAX]; - - - -/*======================================================================*/ - -static struct obj_file *arch_new_file(void) -{ - struct arch_file *f; - f = xmalloc(sizeof(*f)); - - memset(f, 0, sizeof(*f)); - - return &f->root; -} - -static struct obj_section *arch_new_section(void) -{ - return xmalloc(sizeof(struct obj_section)); -} - -static struct obj_symbol *arch_new_symbol(void) -{ - struct arch_symbol *sym; - sym = xmalloc(sizeof(*sym)); - - memset(sym, 0, sizeof(*sym)); - - return &sym->root; -} - -static enum obj_reloc -arch_apply_relocation(struct obj_file *f, - struct obj_section *targsec, - struct obj_section *symsec, - struct obj_symbol *sym, - ElfW(RelM) *rel, ElfW(Addr) v) -{ - struct arch_file *ifile = (struct arch_file *) f; - enum obj_reloc ret = obj_reloc_ok; - ElfW(Addr) *loc = (ElfW(Addr) *) (targsec->contents + rel->r_offset); - ElfW(Addr) dot = targsec->header.sh_addr + rel->r_offset; -#if defined(BB_USE_GOT_ENTRIES) || defined(BB_USE_PLT_ENTRIES) - struct arch_symbol *isym = (struct arch_symbol *) sym; -#endif -#if defined(BB_USE_GOT_ENTRIES) - ElfW(Addr) got = ifile->got ? ifile->got->header.sh_addr : 0; -#endif -#if defined(BB_USE_PLT_ENTRIES) - ElfW(Addr) plt = ifile->plt ? ifile->plt->header.sh_addr : 0; - unsigned long *ip; -#if defined(BB_USE_PLT_LIST) - struct arch_list_entry *pe; -#else - struct arch_single_entry *pe; -#endif -#endif - - switch (ELF32_R_TYPE(rel->r_info)) { - -#if defined(__arm__) - case R_ARM_NONE: - break; - - case R_ARM_ABS32: - *loc += v; - break; - - case R_ARM_GOT32: - goto bb_use_got; - - case R_ARM_GOTPC: - /* relative reloc, always to _GLOBAL_OFFSET_TABLE_ - * (which is .got) similar to branch, - * but is full 32 bits relative */ - - assert(got); - *loc += got - dot; - break; - - case R_ARM_PC24: - case R_ARM_PLT32: - goto bb_use_plt; - - case R_ARM_GOTOFF: /* address relative to the got */ - assert(got); - *loc += v - got; - break; - -#elif defined(__i386__) - - case R_386_NONE: - break; - - case R_386_32: - *loc += v; - break; - - case R_386_PLT32: - case R_386_PC32: - *loc += v - dot; - break; - - case R_386_GLOB_DAT: - case R_386_JMP_SLOT: - *loc = v; - break; - - case R_386_RELATIVE: - *loc += f->baseaddr; - break; - - case R_386_GOTPC: - assert(got != 0); - *loc += got - dot; - break; - - case R_386_GOT32: - goto bb_use_got; - - case R_386_GOTOFF: - assert(got != 0); - *loc += v - got; - break; - -#elif defined(__x86_64__) - - case R_X86_64_NONE: - break; - - case R_X86_64_64: - *loc += v; - break; - - case R_X86_64_32: - *(unsigned int *) loc += v; - break; - - case R_X86_64_32S: - *(signed int *) loc += v; - break; - - case R_X86_64_16: - *(unsigned short *) loc += v; - break; - - case R_X86_64_8: - *(unsigned char *) loc += v; - break; - - case R_X86_64_PC32: - *(unsigned int *) loc += v - dot; - break; - - case R_X86_64_PC16: - *(unsigned short *) loc += v - dot; - break; - - case R_X86_64_PC8: - *(unsigned char *) loc += v - dot; - break; - - case R_X86_64_GLOB_DAT: - case R_X86_64_JUMP_SLOT: - *loc = v; - break; - - case R_X86_64_RELATIVE: - *loc += f->baseaddr; - break; - - case R_X86_64_GOT32: - case R_X86_64_GOTPCREL: - goto bb_use_got; - -#elif defined(__mc68000__) - - case R_68K_NONE: - break; - - case R_68K_32: - *loc += v; - break; - - case R_68K_8: - if (v > 0xff) { - ret = obj_reloc_overflow; - } - *(char *)loc = v; - break; - - case R_68K_16: - if (v > 0xffff) { - ret = obj_reloc_overflow; - } - *(short *)loc = v; - break; - - case R_68K_PC8: - v -= dot; - if ((Elf32_Sword)v > 0x7f || - (Elf32_Sword)v < -(Elf32_Sword)0x80) { - ret = obj_reloc_overflow; - } - *(char *)loc = v; - break; - - case R_68K_PC16: - v -= dot; - if ((Elf32_Sword)v > 0x7fff || - (Elf32_Sword)v < -(Elf32_Sword)0x8000) { - ret = obj_reloc_overflow; - } - *(short *)loc = v; - break; - - case R_68K_PC32: - *(int *)loc = v - dot; - break; - - case R_68K_GLOB_DAT: - case R_68K_JMP_SLOT: - *loc = v; - break; - - case R_68K_RELATIVE: - *(int *)loc += f->baseaddr; - break; - - case R_68K_GOT32: - goto bb_use_got; - - case R_68K_GOTOFF: - assert(got != 0); - *loc += v - got; - break; - -#elif defined(__mips__) - - case R_MIPS_NONE: - break; - - case R_MIPS_32: - *loc += v; - break; - - case R_MIPS_26: - if (v % 4) - ret = obj_reloc_dangerous; - if ((v & 0xf0000000) != ((dot + 4) & 0xf0000000)) - ret = obj_reloc_overflow; - *loc = - (*loc & ~0x03ffffff) | ((*loc + (v >> 2)) & - 0x03ffffff); - break; - - case R_MIPS_HI16: - { - struct mips_hi16 *n; - - /* We cannot relocate this one now because we don't know the value - of the carry we need to add. Save the information, and let LO16 - do the actual relocation. */ - n = (struct mips_hi16 *) xmalloc(sizeof *n); - n->addr = loc; - n->value = v; - n->next = ifile->mips_hi16_list; - ifile->mips_hi16_list = n; - break; - } - - case R_MIPS_LO16: - { - unsigned long insnlo = *loc; - Elf32_Addr val, vallo; - - /* Sign extend the addend we extract from the lo insn. */ - vallo = ((insnlo & 0xffff) ^ 0x8000) - 0x8000; - - if (ifile->mips_hi16_list != NULL) { - struct mips_hi16 *l; - - l = ifile->mips_hi16_list; - while (l != NULL) { - struct mips_hi16 *next; - unsigned long insn; - - /* The value for the HI16 had best be the same. */ - assert(v == l->value); - - /* Do the HI16 relocation. Note that we actually don't - need to know anything about the LO16 itself, except where - to find the low 16 bits of the addend needed by the LO16. */ - insn = *l->addr; - val = - ((insn & 0xffff) << 16) + - vallo; - val += v; - - /* Account for the sign extension that will happen in the - low bits. */ - val = - ((val >> 16) + - ((val & 0x8000) != - 0)) & 0xffff; - - insn = (insn & ~0xffff) | val; - *l->addr = insn; - - next = l->next; - free(l); - l = next; - } - - ifile->mips_hi16_list = NULL; - } - - /* Ok, we're done with the HI16 relocs. Now deal with the LO16. */ - val = v + vallo; - insnlo = (insnlo & ~0xffff) | (val & 0xffff); - *loc = insnlo; - break; - } - -#elif defined(__powerpc__) - - case R_PPC_ADDR16_HA: - *(unsigned short *)loc = (v + 0x8000) >> 16; - break; - - case R_PPC_ADDR16_HI: - *(unsigned short *)loc = v >> 16; - break; - - case R_PPC_ADDR16_LO: - *(unsigned short *)loc = v; - break; - - case R_PPC_REL24: - goto bb_use_plt; - - case R_PPC_REL32: - *loc = v - dot; - break; - - case R_PPC_ADDR32: - *loc = v; - break; - -#elif defined(__sh__) - - case R_SH_NONE: - break; - - case R_SH_DIR32: - *loc += v; - break; - - case R_SH_REL32: - *loc += v - dot; - break; - - case R_SH_PLT32: - *loc = v - dot; - break; - - case R_SH_GLOB_DAT: - case R_SH_JMP_SLOT: - *loc = v; - break; - - case R_SH_RELATIVE: - *loc = f->baseaddr + rel->r_addend; - break; - - case R_SH_GOTPC: - assert(got != 0); - *loc = got - dot + rel->r_addend; - break; - - case R_SH_GOT32: - goto bb_use_got; - - case R_SH_GOTOFF: - assert(got != 0); - *loc = v - got; - break; - -#endif - - default: - printf("Warning: unhandled reloc %d\n",(int)ELF32_R_TYPE(rel->r_info)); - ret = obj_reloc_unhandled; - break; - -#if defined(BB_USE_PLT_ENTRIES) - - bb_use_plt: - - /* find the plt entry and initialize it if necessary */ - assert(isym != NULL); - -#if defined(BB_USE_PLT_LIST) - for (pe = isym->pltent; pe != NULL && pe->addend != rel->r_addend;) - pe = pe->next; - assert(pe != NULL); -#else - pe = &isym->pltent; -#endif - - if (! pe->inited) { - ip = (unsigned long *) (ifile->plt->contents + pe->offset); - - /* generate some machine code */ - -#if defined(__arm__) - ip[0] = 0xe51ff004; /* ldr pc,[pc,#-4] */ - ip[1] = v; /* sym@ */ -#endif -#if defined(__powerpc__) - ip[0] = 0x3d600000 + ((v + 0x8000) >> 16); /* lis r11,sym@ha */ - ip[1] = 0x396b0000 + (v & 0xffff); /* addi r11,r11,sym@l */ - ip[2] = 0x7d6903a6; /* mtctr r11 */ - ip[3] = 0x4e800420; /* bctr */ -#endif - pe->inited = 1; - } - - /* relative distance to target */ - v -= dot; - /* if the target is too far away.... */ - if ((int)v < -0x02000000 || (int)v >= 0x02000000) { - /* go via the plt */ - v = plt + pe->offset - dot; - } - if (v & 3) - ret = obj_reloc_dangerous; - - /* merge the offset into the instruction. */ -#if defined(__arm__) - /* Convert to words. */ - v >>= 2; - - *loc = (*loc & ~0x00ffffff) | ((v + *loc) & 0x00ffffff); -#endif -#if defined(__powerpc__) - *loc = (*loc & ~0x03fffffc) | (v & 0x03fffffc); -#endif - break; -#endif /* BB_USE_PLT_ENTRIES */ - -#if defined(BB_USE_GOT_ENTRIES) - bb_use_got: - - assert(isym != NULL); - /* needs an entry in the .got: set it, once */ - if (!isym->gotent.inited) { - isym->gotent.inited = 1; - *(ElfW(Addr) *) (ifile->got->contents + isym->gotent.offset) = v; - } - /* make the reloc with_respect_to_.got */ -#if defined(__sh__) - *loc += isym->gotent.offset + rel->r_addend; -#elif defined(__i386__) || defined(__arm__) || defined(__mc68000__) - *loc += isym->gotent.offset; -#elif defined(__x86_64__) - /* XXX are these really correct? */ - if (ELF64_R_TYPE(rel->r_info) == R_X86_64_GOTPCREL) - *(unsigned int *) loc += v + isym->gotent.offset; - else - *loc += isym->gotent.offset; -#endif - break; - -#endif /* BB_USE_GOT_ENTRIES */ - } - - return ret; -} - -#if defined(BB_USE_LIST) - -static int arch_list_add(ElfW(RelM) *rel, struct arch_list_entry **list, - int offset, int size) -{ - struct arch_list_entry *pe; - - for (pe = *list; pe != NULL; pe = pe->next) { - if (pe->addend == rel->r_addend) { - break; - } - } - - if (pe == NULL) { - pe = xmalloc(sizeof(struct arch_list_entry)); - pe->next = *list; - pe->addend = rel->r_addend; - pe->offset = offset; - pe->inited = 0; - *list = pe; - return size; - } - return 0; -} - -#endif - -#if defined(BB_USE_SINGLE) - -static int arch_single_init(ElfW(RelM) *rel, struct arch_single_entry *single, - int offset, int size) -{ - if (single->allocated == 0) { - single->allocated = 1; - single->offset = offset; - single->inited = 0; - return size; - } - return 0; -} - -#endif - -#if defined(BB_USE_GOT_ENTRIES) || defined(BB_USE_PLT_ENTRIES) - -static struct obj_section *arch_xsect_init(struct obj_file *f, char *name, - int offset, int size) -{ - struct obj_section *myrelsec = obj_find_section(f, name); - - if (offset == 0) { - offset += size; - } - - if (myrelsec) { - obj_extend_section(myrelsec, offset); - } else { - myrelsec = obj_create_alloced_section(f, name, - size, offset); - assert(myrelsec); - } - - return myrelsec; -} - -#endif - -static void arch_create_got(struct obj_file *f) -{ -#if defined(BB_USE_GOT_ENTRIES) || defined(BB_USE_PLT_ENTRIES) - struct arch_file *ifile = (struct arch_file *) f; - int i; -#if defined(BB_USE_GOT_ENTRIES) - int got_offset = 0, got_needed = 0, got_allocate; -#endif -#if defined(BB_USE_PLT_ENTRIES) - int plt_offset = 0, plt_needed = 0, plt_allocate; -#endif - struct obj_section *relsec, *symsec, *strsec; - ElfW(RelM) *rel, *relend; - ElfW(Sym) *symtab, *extsym; - const char *strtab, *name; - struct arch_symbol *intsym; - - for (i = 0; i < f->header.e_shnum; ++i) { - relsec = f->sections[i]; - - if (relsec->header.sh_type != SHT_RELM) - continue; - - symsec = f->sections[relsec->header.sh_link]; - strsec = f->sections[symsec->header.sh_link]; - - rel = (ElfW(RelM) *) relsec->contents; - relend = rel + (relsec->header.sh_size / sizeof(ElfW(RelM))); - symtab = (ElfW(Sym) *) symsec->contents; - strtab = (const char *) strsec->contents; - - for (; rel < relend; ++rel) { - extsym = &symtab[ELF32_R_SYM(rel->r_info)]; - -#if defined(BB_USE_GOT_ENTRIES) - got_allocate = 0; -#endif -#if defined(BB_USE_PLT_ENTRIES) - plt_allocate = 0; -#endif - - switch (ELF32_R_TYPE(rel->r_info)) { - -#if defined(__arm__) - - case R_ARM_PC24: - case R_ARM_PLT32: - plt_allocate = 1; - break; - - case R_ARM_GOTOFF: - case R_ARM_GOTPC: - got_needed = 1; - continue; - - case R_ARM_GOT32: - got_allocate = 1; - break; - -#elif defined(__i386__) - - case R_386_GOTPC: - case R_386_GOTOFF: - got_needed = 1; - continue; - - case R_386_GOT32: - got_allocate = 1; - break; - -#elif defined(__x86_64__) - - case R_X86_64_GOTPCREL: - case R_X86_64_GOT32: - got_needed = 1; - continue; - -#elif defined(__powerpc__) - - case R_PPC_REL24: - plt_allocate = 1; - break; - -#elif defined(__mc68000__) - - case R_68K_GOT32: - got_allocate = 1; - break; - - case R_68K_GOTOFF: - got_needed = 1; - continue; - -#elif defined(__sh__) - - case R_SH_GOT32: - got_allocate = 1; - break; - - case R_SH_GOTPC: - case R_SH_GOTOFF: - got_needed = 1; - continue; - -#endif - default: - continue; - } - - if (extsym->st_name != 0) { - name = strtab + extsym->st_name; - } else { - name = f->sections[extsym->st_shndx]->name; - } - intsym = (struct arch_symbol *) obj_find_symbol(f, name); -#if defined(BB_USE_GOT_ENTRIES) - if (got_allocate) { - got_offset += arch_single_init( - rel, &intsym->gotent, - got_offset, BB_GOT_ENTRY_SIZE); - - got_needed = 1; - } -#endif -#if defined(BB_USE_PLT_ENTRIES) - if (plt_allocate) { -#if defined(BB_USE_PLT_LIST) - plt_offset += arch_list_add( - rel, &intsym->pltent, - plt_offset, BB_PLT_ENTRY_SIZE); -#else - plt_offset += arch_single_init( - rel, &intsym->pltent, - plt_offset, BB_PLT_ENTRY_SIZE); -#endif - plt_needed = 1; - } -#endif - } - } - -#if defined(BB_USE_GOT_ENTRIES) - if (got_needed) { - ifile->got = arch_xsect_init(f, ".got", got_offset, - BB_GOT_ENTRY_SIZE); - } -#endif - -#if defined(BB_USE_PLT_ENTRIES) - if (plt_needed) { - ifile->plt = arch_xsect_init(f, ".plt", plt_offset, - BB_PLT_ENTRY_SIZE); - } -#endif - -#endif /* defined(BB_USE_GOT_ENTRIES) || defined(BB_USE_PLT_ENTRIES) */ -} - -#ifdef BB_FEATURE_NEW_MODULE_INTERFACE -static int arch_init_module(struct obj_file *f, struct new_module *mod) -{ - return 1; -} -#endif - - -/*======================================================================*/ - -/* Standard ELF hash function. */ -static inline unsigned long obj_elf_hash_n(const char *name, unsigned long n) -{ - unsigned long h = 0; - unsigned long g; - unsigned char ch; - - while (n > 0) { - ch = *name++; - h = (h << 4) + ch; - if ((g = (h & 0xf0000000)) != 0) { - h ^= g >> 24; - h &= ~g; - } - n--; - } - return h; -} - -static unsigned long obj_elf_hash(const char *name) -{ - return obj_elf_hash_n(name, strlen(name)); -} - -#ifdef BB_FEATURE_INSMOD_VERSION_CHECKING -/* String comparison for non-co-versioned kernel and module. */ - -static int ncv_strcmp(const char *a, const char *b) -{ - size_t alen = strlen(a), blen = strlen(b); - - if (blen == alen + 10 && b[alen] == '_' && b[alen + 1] == 'R') - return strncmp(a, b, alen); - else if (alen == blen + 10 && a[blen] == '_' && a[blen + 1] == 'R') - return strncmp(a, b, blen); - else - return strcmp(a, b); -} - -/* String hashing for non-co-versioned kernel and module. Here - we are simply forced to drop the crc from the hash. */ - -static unsigned long ncv_symbol_hash(const char *str) -{ - size_t len = strlen(str); - if (len > 10 && str[len - 10] == '_' && str[len - 9] == 'R') - len -= 10; - return obj_elf_hash_n(str, len); -} - -static void -obj_set_symbol_compare(struct obj_file *f, - int (*cmp) (const char *, const char *), - unsigned long (*hash) (const char *)) -{ - if (cmp) - f->symbol_cmp = cmp; - if (hash) { - struct obj_symbol *tmptab[HASH_BUCKETS], *sym, *next; - int i; - - f->symbol_hash = hash; - - memcpy(tmptab, f->symtab, sizeof(tmptab)); - memset(f->symtab, 0, sizeof(f->symtab)); - - for (i = 0; i < HASH_BUCKETS; ++i) - for (sym = tmptab[i]; sym; sym = next) { - unsigned long h = hash(sym->name) % HASH_BUCKETS; - next = sym->next; - sym->next = f->symtab[h]; - f->symtab[h] = sym; - } - } -} - -#endif /* BB_FEATURE_INSMOD_VERSION_CHECKING */ - -static struct obj_symbol * -obj_add_symbol(struct obj_file *f, const char *name, - unsigned long symidx, int info, - int secidx, ElfW(Addr) value, - unsigned long size) -{ - struct obj_symbol *sym; - unsigned long hash = f->symbol_hash(name) % HASH_BUCKETS; - int n_type = ELFW(ST_TYPE) (info); - int n_binding = ELFW(ST_BIND) (info); - - for (sym = f->symtab[hash]; sym; sym = sym->next) - if (f->symbol_cmp(sym->name, name) == 0) { - int o_secidx = sym->secidx; - int o_info = sym->info; - int o_type = ELFW(ST_TYPE) (o_info); - int o_binding = ELFW(ST_BIND) (o_info); - - /* A redefinition! Is it legal? */ - - if (secidx == SHN_UNDEF) - return sym; - else if (o_secidx == SHN_UNDEF) - goto found; - else if (n_binding == STB_GLOBAL && o_binding == STB_LOCAL) { - /* Cope with local and global symbols of the same name - in the same object file, as might have been created - by ld -r. The only reason locals are now seen at this - level at all is so that we can do semi-sensible things - with parameters. */ - - struct obj_symbol *nsym, **p; - - nsym = arch_new_symbol(); - nsym->next = sym->next; - nsym->ksymidx = -1; - - /* Excise the old (local) symbol from the hash chain. */ - for (p = &f->symtab[hash]; *p != sym; p = &(*p)->next) - continue; - *p = sym = nsym; - goto found; - } else if (n_binding == STB_LOCAL) { - /* Another symbol of the same name has already been defined. - Just add this to the local table. */ - sym = arch_new_symbol(); - sym->next = NULL; - sym->ksymidx = -1; - f->local_symtab[symidx] = sym; - goto found; - } else if (n_binding == STB_WEAK) - return sym; - else if (o_binding == STB_WEAK) - goto found; - /* Don't unify COMMON symbols with object types the programmer - doesn't expect. */ - else if (secidx == SHN_COMMON - && (o_type == STT_NOTYPE || o_type == STT_OBJECT)) - return sym; - else if (o_secidx == SHN_COMMON - && (n_type == STT_NOTYPE || n_type == STT_OBJECT)) - goto found; - else { - /* Don't report an error if the symbol is coming from - the kernel or some external module. */ - if (secidx <= SHN_HIRESERVE) - error_msg("%s multiply defined", name); - return sym; - } - } - - /* Completely new symbol. */ - sym = arch_new_symbol(); - sym->next = f->symtab[hash]; - f->symtab[hash] = sym; - sym->ksymidx = -1; - - if (ELFW(ST_BIND)(info) == STB_LOCAL && symidx != -1) { - if (symidx >= f->local_symtab_size) - error_msg("local symbol %s with index %ld exceeds local_symtab_size %ld", - name, (long) symidx, (long) f->local_symtab_size); - else - f->local_symtab[symidx] = sym; - } - - found: - sym->name = name; - sym->value = value; - sym->size = size; - sym->secidx = secidx; - sym->info = info; - - return sym; -} - -static struct obj_symbol * -obj_find_symbol(struct obj_file *f, const char *name) -{ - struct obj_symbol *sym; - unsigned long hash = f->symbol_hash(name) % HASH_BUCKETS; - - for (sym = f->symtab[hash]; sym; sym = sym->next) - if (f->symbol_cmp(sym->name, name) == 0) - return sym; - - return NULL; -} - -static ElfW(Addr) - obj_symbol_final_value(struct obj_file * f, struct obj_symbol * sym) -{ - if (sym) { - if (sym->secidx >= SHN_LORESERVE) - return sym->value; - - return sym->value + f->sections[sym->secidx]->header.sh_addr; - } else { - /* As a special case, a NULL sym has value zero. */ - return 0; - } -} - -static struct obj_section *obj_find_section(struct obj_file *f, const char *name) -{ - int i, n = f->header.e_shnum; - - for (i = 0; i < n; ++i) - if (strcmp(f->sections[i]->name, name) == 0) - return f->sections[i]; - - return NULL; -} - -static int obj_load_order_prio(struct obj_section *a) -{ - unsigned long af, ac; - - af = a->header.sh_flags; - - ac = 0; - if (a->name[0] != '.' || strlen(a->name) != 10 || - strcmp(a->name + 5, ".init")) - ac |= 32; - if (af & SHF_ALLOC) - ac |= 16; - if (!(af & SHF_WRITE)) - ac |= 8; - if (af & SHF_EXECINSTR) - ac |= 4; - if (a->header.sh_type != SHT_NOBITS) - ac |= 2; - - return ac; -} - -static void -obj_insert_section_load_order(struct obj_file *f, struct obj_section *sec) -{ - struct obj_section **p; - int prio = obj_load_order_prio(sec); - for (p = f->load_order_search_start; *p; p = &(*p)->load_next) - if (obj_load_order_prio(*p) < prio) - break; - sec->load_next = *p; - *p = sec; -} - -static struct obj_section *obj_create_alloced_section(struct obj_file *f, - const char *name, - unsigned long align, - unsigned long size) -{ - int newidx = f->header.e_shnum++; - struct obj_section *sec; - - f->sections = xrealloc(f->sections, (newidx + 1) * sizeof(sec)); - f->sections[newidx] = sec = arch_new_section(); - - memset(sec, 0, sizeof(*sec)); - sec->header.sh_type = SHT_PROGBITS; - sec->header.sh_flags = SHF_WRITE | SHF_ALLOC; - sec->header.sh_size = size; - sec->header.sh_addralign = align; - sec->name = name; - sec->idx = newidx; - if (size) - sec->contents = xmalloc(size); - - obj_insert_section_load_order(f, sec); - - return sec; -} - -static struct obj_section *obj_create_alloced_section_first(struct obj_file *f, - const char *name, - unsigned long align, - unsigned long size) -{ - int newidx = f->header.e_shnum++; - struct obj_section *sec; - - f->sections = xrealloc(f->sections, (newidx + 1) * sizeof(sec)); - f->sections[newidx] = sec = arch_new_section(); - - memset(sec, 0, sizeof(*sec)); - sec->header.sh_type = SHT_PROGBITS; - sec->header.sh_flags = SHF_WRITE | SHF_ALLOC; - sec->header.sh_size = size; - sec->header.sh_addralign = align; - sec->name = name; - sec->idx = newidx; - if (size) - sec->contents = xmalloc(size); - - sec->load_next = f->load_order; - f->load_order = sec; - if (f->load_order_search_start == &f->load_order) - f->load_order_search_start = &sec->load_next; - - return sec; -} - -static void *obj_extend_section(struct obj_section *sec, unsigned long more) -{ - unsigned long oldsize = sec->header.sh_size; - if (more) { - sec->contents = xrealloc(sec->contents, sec->header.sh_size += more); - } - return sec->contents + oldsize; -} - - -/* Conditionally add the symbols from the given symbol set to the - new module. */ - -static int -add_symbols_from( - struct obj_file *f, - int idx, struct new_module_symbol *syms, size_t nsyms) -{ - struct new_module_symbol *s; - size_t i; - int used = 0; - - for (i = 0, s = syms; i < nsyms; ++i, ++s) { - - /* Only add symbols that are already marked external. If we - override locals we may cause problems for argument initialization. - We will also create a false dependency on the module. */ - struct obj_symbol *sym; - - sym = obj_find_symbol(f, (char *) s->name); - if (sym && !ELFW(ST_BIND) (sym->info) == STB_LOCAL) { - sym = obj_add_symbol(f, (char *) s->name, -1, - ELFW(ST_INFO) (STB_GLOBAL, STT_NOTYPE), - idx, s->value, 0); - /* Did our symbol just get installed? If so, mark the - module as "used". */ - if (sym->secidx == idx) - used = 1; - } - } - - return used; -} - -static void add_kernel_symbols(struct obj_file *f) -{ - struct external_module *m; - int i, nused = 0; - - /* Add module symbols first. */ - - for (i = 0, m = ext_modules; i < n_ext_modules; ++i, ++m) - if (m->nsyms - && add_symbols_from(f, SHN_HIRESERVE + 2 + i, m->syms, - m->nsyms)) m->used = 1, ++nused; - - n_ext_modules_used = nused; - - /* And finally the symbols from the kernel proper. */ - - if (nksyms) - add_symbols_from(f, SHN_HIRESERVE + 1, ksyms, nksyms); -} - -static char *get_modinfo_value(struct obj_file *f, const char *key) -{ - struct obj_section *sec; - char *p, *v, *n, *ep; - size_t klen = strlen(key); - - sec = obj_find_section(f, ".modinfo"); - if (sec == NULL) - return NULL; - p = sec->contents; - ep = p + sec->header.sh_size; - while (p < ep) { - v = strchr(p, '='); - n = strchr(p, '\0'); - if (v) { - if (p + klen == v && strncmp(p, key, klen) == 0) - return v + 1; - } else { - if (p + klen == n && strcmp(p, key) == 0) - return n; - } - p = n + 1; - } - - return NULL; -} - - -/*======================================================================*/ -/* Functions relating to module loading in pre 2.1 kernels. */ - -static int -old_process_module_arguments(struct obj_file *f, int argc, char **argv) -{ - while (argc > 0) { - char *p, *q; - struct obj_symbol *sym; - int *loc; - - p = *argv; - if ((q = strchr(p, '=')) == NULL) { - argc--; - continue; - } - *q++ = '\0'; - - sym = obj_find_symbol(f, p); - - /* Also check that the parameter was not resolved from the kernel. */ - if (sym == NULL || sym->secidx > SHN_HIRESERVE) { - error_msg("symbol for parameter %s not found", p); - return 0; - } - - loc = (int *) (f->sections[sym->secidx]->contents + sym->value); - - /* Do C quoting if we begin with a ". */ - if (*q == '"') { - char *r, *str; - - str = alloca(strlen(q)); - for (r = str, q++; *q != '"'; ++q, ++r) { - if (*q == '\0') { - error_msg("improperly terminated string argument for %s", p); - return 0; - } else if (*q == '\\') - switch (*++q) { - case 'a': - *r = '\a'; - break; - case 'b': - *r = '\b'; - break; - case 'e': - *r = '\033'; - break; - case 'f': - *r = '\f'; - break; - case 'n': - *r = '\n'; - break; - case 'r': - *r = '\r'; - break; - case 't': - *r = '\t'; - break; - - case '0': - case '1': - case '2': - case '3': - case '4': - case '5': - case '6': - case '7': - { - int c = *q - '0'; - if (q[1] >= '0' && q[1] <= '7') { - c = (c * 8) + *++q - '0'; - if (q[1] >= '0' && q[1] <= '7') - c = (c * 8) + *++q - '0'; - } - *r = c; - } - break; - - default: - *r = *q; - break; - } else - *r = *q; - } - *r = '\0'; - obj_string_patch(f, sym->secidx, sym->value, str); - } else if (*q >= '0' && *q <= '9') { - do - *loc++ = strtoul(q, &q, 0); - while (*q++ == ','); - } else { - char *contents = f->sections[sym->secidx]->contents; - char *myloc = contents + sym->value; - char *r; /* To search for commas */ - - /* Break the string with comas */ - while ((r = strchr(q, ',')) != (char *) NULL) { - *r++ = '\0'; - obj_string_patch(f, sym->secidx, myloc - contents, q); - myloc += sizeof(char *); - q = r; - } - - /* last part */ - obj_string_patch(f, sym->secidx, myloc - contents, q); - } - - argc--, argv++; - } - - return 1; -} - -#ifdef BB_FEATURE_INSMOD_VERSION_CHECKING -static int old_is_module_checksummed(struct obj_file *f) -{ - return obj_find_symbol(f, "Using_Versions") != NULL; -} -/* Get the module's kernel version in the canonical integer form. */ - -static int -old_get_module_version(struct obj_file *f, char str[STRVERSIONLEN]) -{ - struct obj_symbol *sym; - char *p, *q; - int a, b, c; - - sym = obj_find_symbol(f, "kernel_version"); - if (sym == NULL) - return -1; - - p = f->sections[sym->secidx]->contents + sym->value; - safe_strncpy(str, p, STRVERSIONLEN); - - a = strtoul(p, &p, 10); - if (*p != '.') - return -1; - b = strtoul(p + 1, &p, 10); - if (*p != '.') - return -1; - c = strtoul(p + 1, &q, 10); - if (p + 1 == q) - return -1; - - return a << 16 | b << 8 | c; -} - -#endif /* BB_FEATURE_INSMOD_VERSION_CHECKING */ - -#ifdef BB_FEATURE_OLD_MODULE_INTERFACE - -/* Fetch all the symbols and divvy them up as appropriate for the modules. */ - -static int old_get_kernel_symbols(const char *m_name) -{ - struct old_kernel_sym *ks, *k; - struct new_module_symbol *s; - struct external_module *mod; - int nks, nms, nmod, i; - - nks = get_kernel_syms(NULL); - if (nks <= 0) { - if (nks) - perror_msg("get_kernel_syms: %s", m_name); - else - error_msg("No kernel symbols"); - return 0; - } - - ks = k = xmalloc(nks * sizeof(*ks)); - - if (get_kernel_syms(ks) != nks) { - perror("inconsistency with get_kernel_syms -- is someone else " - "playing with modules?"); - free(ks); - return 0; - } - - /* Collect the module information. */ - - mod = NULL; - nmod = -1; - - while (k->name[0] == '#' && k->name[1]) { - struct old_kernel_sym *k2; - - /* Find out how many symbols this module has. */ - for (k2 = k + 1; k2->name[0] != '#'; ++k2) - continue; - nms = k2 - k - 1; - - mod = xrealloc(mod, (++nmod + 1) * sizeof(*mod)); - mod[nmod].name = k->name + 1; - mod[nmod].addr = k->value; - mod[nmod].used = 0; - mod[nmod].nsyms = nms; - mod[nmod].syms = s = (nms ? xmalloc(nms * sizeof(*s)) : NULL); - - for (i = 0, ++k; i < nms; ++i, ++s, ++k) { - s->name = (unsigned long) k->name; - s->value = k->value; - } - - k = k2; - } - - ext_modules = mod; - n_ext_modules = nmod + 1; - - /* Now collect the symbols for the kernel proper. */ - - if (k->name[0] == '#') - ++k; - - nksyms = nms = nks - (k - ks); - ksyms = s = (nms ? xmalloc(nms * sizeof(*s)) : NULL); - - for (i = 0; i < nms; ++i, ++s, ++k) { - s->name = (unsigned long) k->name; - s->value = k->value; - } - - return 1; -} - -/* Return the kernel symbol checksum version, or zero if not used. */ - -static int old_is_kernel_checksummed(void) -{ - /* Using_Versions is the first symbol. */ - if (nksyms > 0 - && strcmp((char *) ksyms[0].name, - "Using_Versions") == 0) return ksyms[0].value; - else - return 0; -} - - -static int old_create_mod_use_count(struct obj_file *f) -{ - struct obj_section *sec; - - sec = obj_create_alloced_section_first(f, ".moduse", sizeof(long), - sizeof(long)); - - obj_add_symbol(f, "mod_use_count_", -1, - ELFW(ST_INFO) (STB_LOCAL, STT_OBJECT), sec->idx, 0, - sizeof(long)); - - return 1; -} - -static int -old_init_module(const char *m_name, struct obj_file *f, - unsigned long m_size) -{ - char *image; - struct old_mod_routines routines; - struct old_symbol_table *symtab; - int ret; - - /* Create the symbol table */ - { - int nsyms = 0, strsize = 0, total; - - /* Size things first... */ - if (flag_export) { - int i; - for (i = 0; i < HASH_BUCKETS; ++i) { - struct obj_symbol *sym; - for (sym = f->symtab[i]; sym; sym = sym->next) - if (ELFW(ST_BIND) (sym->info) != STB_LOCAL - && sym->secidx <= SHN_HIRESERVE) - { - sym->ksymidx = nsyms++; - strsize += strlen(sym->name) + 1; - } - } - } - - total = (sizeof(struct old_symbol_table) - + nsyms * sizeof(struct old_module_symbol) - + n_ext_modules_used * sizeof(struct old_module_ref) - + strsize); - symtab = xmalloc(total); - symtab->size = total; - symtab->n_symbols = nsyms; - symtab->n_refs = n_ext_modules_used; - - if (flag_export && nsyms) { - struct old_module_symbol *ksym; - char *str; - int i; - - ksym = symtab->symbol; - str = ((char *) ksym + nsyms * sizeof(struct old_module_symbol) - + n_ext_modules_used * sizeof(struct old_module_ref)); - - for (i = 0; i < HASH_BUCKETS; ++i) { - struct obj_symbol *sym; - for (sym = f->symtab[i]; sym; sym = sym->next) - if (sym->ksymidx >= 0) { - ksym->addr = obj_symbol_final_value(f, sym); - ksym->name = - (unsigned long) str - (unsigned long) symtab; - - strcpy(str, sym->name); - str += strlen(sym->name) + 1; - ksym++; - } - } - } - - if (n_ext_modules_used) { - struct old_module_ref *ref; - int i; - - ref = (struct old_module_ref *) - ((char *) symtab->symbol + nsyms * sizeof(struct old_module_symbol)); - - for (i = 0; i < n_ext_modules; ++i) - if (ext_modules[i].used) - ref++->module = ext_modules[i].addr; - } - } - - /* Fill in routines. */ - - routines.init = - obj_symbol_final_value(f, obj_find_symbol(f, "init_module")); - routines.cleanup = - obj_symbol_final_value(f, obj_find_symbol(f, "cleanup_module")); - - /* Whew! All of the initialization is complete. Collect the final - module image and give it to the kernel. */ - - image = xmalloc(m_size); - obj_create_image(f, image); - - /* image holds the complete relocated module, accounting correctly for - mod_use_count. However the old module kernel support assume that - it is receiving something which does not contain mod_use_count. */ - ret = old_sys_init_module(m_name, image + sizeof(long), - m_size | (flag_autoclean ? OLD_MOD_AUTOCLEAN - : 0), &routines, symtab); - if (ret) - perror_msg("init_module: %s", m_name); - - free(image); - free(symtab); - - return ret == 0; -} - -#else - -#define old_create_mod_use_count(x) TRUE -#define old_init_module(x, y, z) TRUE - -#endif /* BB_FEATURE_OLD_MODULE_INTERFACE */ - - - -/*======================================================================*/ -/* Functions relating to module loading after 2.1.18. */ - -static int -new_process_module_arguments(struct obj_file *f, int argc, char **argv) -{ - while (argc > 0) { - char *p, *q, *key; - struct obj_symbol *sym; - char *contents, *loc; - int min, max, n; - - p = *argv; - if ((q = strchr(p, '=')) == NULL) { - argc--; - continue; - } - - key = alloca(q - p + 6); - memcpy(key, "parm_", 5); - memcpy(key + 5, p, q - p); - key[q - p + 5] = 0; - - p = get_modinfo_value(f, key); - key += 5; - if (p == NULL) { - error_msg("invalid parameter %s", key); - return 0; - } - - sym = obj_find_symbol(f, key); - - /* Also check that the parameter was not resolved from the kernel. */ - if (sym == NULL || sym->secidx > SHN_HIRESERVE) { - error_msg("symbol for parameter %s not found", key); - return 0; - } - - if (isdigit(*p)) { - min = strtoul(p, &p, 10); - if (*p == '-') - max = strtoul(p + 1, &p, 10); - else - max = min; - } else - min = max = 1; - - contents = f->sections[sym->secidx]->contents; - loc = contents + sym->value; - n = (*++q != '\0'); - - while (1) { - if ((*p == 's') || (*p == 'c')) { - char *str; - - /* Do C quoting if we begin with a ", else slurp the lot. */ - if (*q == '"') { - char *r; - - str = alloca(strlen(q)); - for (r = str, q++; *q != '"'; ++q, ++r) { - if (*q == '\0') { - error_msg("improperly terminated string argument for %s", - key); - return 0; - } else if (*q == '\\') - switch (*++q) { - case 'a': - *r = '\a'; - break; - case 'b': - *r = '\b'; - break; - case 'e': - *r = '\033'; - break; - case 'f': - *r = '\f'; - break; - case 'n': - *r = '\n'; - break; - case 'r': - *r = '\r'; - break; - case 't': - *r = '\t'; - break; - - case '0': - case '1': - case '2': - case '3': - case '4': - case '5': - case '6': - case '7': - { - int c = *q - '0'; - if (q[1] >= '0' && q[1] <= '7') { - c = (c * 8) + *++q - '0'; - if (q[1] >= '0' && q[1] <= '7') - c = (c * 8) + *++q - '0'; - } - *r = c; - } - break; - - default: - *r = *q; - break; - } else - *r = *q; - } - *r = '\0'; - ++q; - } else { - char *r; - - /* In this case, the string is not quoted. We will break - it using the coma (like for ints). If the user wants to - include comas in a string, he just has to quote it */ - - /* Search the next coma */ - r = strchr(q, ','); - - /* Found ? */ - if (r != (char *) NULL) { - /* Recopy the current field */ - str = alloca(r - q + 1); - memcpy(str, q, r - q); - - /* I don't know if it is usefull, as the previous case - doesn't null terminate the string ??? */ - str[r - q] = '\0'; - - /* Keep next fields */ - q = r; - } else { - /* last string */ - str = q; - q = ""; - } - } - - if (*p == 's') { - /* Normal string */ - obj_string_patch(f, sym->secidx, loc - contents, str); - loc += tgt_sizeof_char_p; - } else { - /* Array of chars (in fact, matrix !) */ - unsigned long charssize; /* size of each member */ - - /* Get the size of each member */ - /* Probably we should do that outside the loop ? */ - if (!isdigit(*(p + 1))) { - error_msg("parameter type 'c' for %s must be followed by" - " the maximum size", key); - return 0; - } - charssize = strtoul(p + 1, (char **) NULL, 10); - - /* Check length */ - if (strlen(str) >= charssize) { - error_msg("string too long for %s (max %ld)", key, - charssize - 1); - return 0; - } - - /* Copy to location */ - strcpy((char *) loc, str); - loc += charssize; - } - } else { - long v = strtoul(q, &q, 0); - switch (*p) { - case 'b': - *loc++ = v; - break; - case 'h': - *(short *) loc = v; - loc += tgt_sizeof_short; - break; - case 'i': - *(int *) loc = v; - loc += tgt_sizeof_int; - break; - case 'l': - *(long *) loc = v; - loc += tgt_sizeof_long; - break; - - default: - error_msg("unknown parameter type '%c' for %s", *p, key); - return 0; - } - } - - retry_end_of_value: - switch (*q) { - case '\0': - goto end_of_arg; - - case ' ': - case '\t': - case '\n': - case '\r': - ++q; - goto retry_end_of_value; - - case ',': - if (++n > max) { - error_msg("too many values for %s (max %d)", key, max); - return 0; - } - ++q; - break; - - default: - error_msg("invalid argument syntax for %s", key); - return 0; - } - } - - end_of_arg: - if (n < min) { - error_msg("too few values for %s (min %d)", key, min); - return 0; - } - - argc--, argv++; - } - - return 1; -} - -#ifdef BB_FEATURE_INSMOD_VERSION_CHECKING -static int new_is_module_checksummed(struct obj_file *f) -{ - const char *p = get_modinfo_value(f, "using_checksums"); - if (p) - return atoi(p); - else - return 0; -} - -/* Get the module's kernel version in the canonical integer form. */ - -static int -new_get_module_version(struct obj_file *f, char str[STRVERSIONLEN]) -{ - char *p, *q; - int a, b, c; - - p = get_modinfo_value(f, "kernel_version"); - if (p == NULL) - return -1; - safe_strncpy(str, p, STRVERSIONLEN); - - a = strtoul(p, &p, 10); - if (*p != '.') - return -1; - b = strtoul(p + 1, &p, 10); - if (*p != '.') - return -1; - c = strtoul(p + 1, &q, 10); - if (p + 1 == q) - return -1; - - return a << 16 | b << 8 | c; -} - -#endif /* BB_FEATURE_INSMOD_VERSION_CHECKING */ - - -#ifdef BB_FEATURE_NEW_MODULE_INTERFACE - -/* Fetch the loaded modules, and all currently exported symbols. */ - -static int new_get_kernel_symbols(void) -{ - char *module_names, *mn; - struct external_module *modules, *m; - struct new_module_symbol *syms, *s; - size_t ret, bufsize, nmod, nsyms, i, j; - - /* Collect the loaded modules. */ - - module_names = xmalloc(bufsize = 256); - retry_modules_load: - if (query_module(NULL, QM_MODULES, module_names, bufsize, &ret)) { - if (errno == ENOSPC && bufsize < ret) { - module_names = xrealloc(module_names, bufsize = ret); - goto retry_modules_load; - } - perror_msg("QM_MODULES"); - return 0; - } - - n_ext_modules = nmod = ret; - - /* Collect the modules' symbols. */ - - if (nmod){ - ext_modules = modules = xmalloc(nmod * sizeof(*modules)); - memset(modules, 0, nmod * sizeof(*modules)); - for (i = 0, mn = module_names, m = modules; - i < nmod; ++i, ++m, mn += strlen(mn) + 1) { - struct new_module_info info; - - if (query_module(mn, QM_INFO, &info, sizeof(info), &ret)) { - if (errno == ENOENT) { - /* The module was removed out from underneath us. */ - continue; - } - perror_msg("query_module: QM_INFO: %s", mn); - return 0; - } - - syms = xmalloc(bufsize = 1024); - retry_mod_sym_load: - if (query_module(mn, QM_SYMBOLS, syms, bufsize, &ret)) { - switch (errno) { - case ENOSPC: - syms = xrealloc(syms, bufsize = ret); - goto retry_mod_sym_load; - case ENOENT: - /* The module was removed out from underneath us. */ - continue; - default: - perror_msg("query_module: QM_SYMBOLS: %s", mn); - return 0; - } - } - nsyms = ret; - - m->name = mn; - m->addr = info.addr; - m->nsyms = nsyms; - m->syms = syms; - - for (j = 0, s = syms; j < nsyms; ++j, ++s) { - s->name += (unsigned long) syms; - } - } - } - - /* Collect the kernel's symbols. */ - - syms = xmalloc(bufsize = 16 * 1024); - retry_kern_sym_load: - if (query_module(NULL, QM_SYMBOLS, syms, bufsize, &ret)) { - if (errno == ENOSPC && bufsize < ret) { - syms = xrealloc(syms, bufsize = ret); - goto retry_kern_sym_load; - } - perror_msg("kernel: QM_SYMBOLS"); - return 0; - } - nksyms = nsyms = ret; - ksyms = syms; - - for (j = 0, s = syms; j < nsyms; ++j, ++s) { - s->name += (unsigned long) syms; - } - return 1; -} - - -/* Return the kernel symbol checksum version, or zero if not used. */ - -static int new_is_kernel_checksummed(void) -{ - struct new_module_symbol *s; - size_t i; - - /* Using_Versions is not the first symbol, but it should be in there. */ - - for (i = 0, s = ksyms; i < nksyms; ++i, ++s) - if (strcmp((char *) s->name, "Using_Versions") == 0) - return s->value; - - return 0; -} - - -static int new_create_this_module(struct obj_file *f, const char *m_name) -{ - struct obj_section *sec; - - sec = obj_create_alloced_section_first(f, ".this", tgt_sizeof_long, - sizeof(struct new_module)); - memset(sec->contents, 0, sizeof(struct new_module)); - - obj_add_symbol(f, "__this_module", -1, - ELFW(ST_INFO) (STB_LOCAL, STT_OBJECT), sec->idx, 0, - sizeof(struct new_module)); - - obj_string_patch(f, sec->idx, offsetof(struct new_module, name), - m_name); - - return 1; -} - - -static int new_create_module_ksymtab(struct obj_file *f) -{ - struct obj_section *sec; - int i; - - /* We must always add the module references. */ - - if (n_ext_modules_used) { - struct new_module_ref *dep; - struct obj_symbol *tm; - - sec = obj_create_alloced_section(f, ".kmodtab", tgt_sizeof_void_p, - (sizeof(struct new_module_ref) - * n_ext_modules_used)); - if (!sec) - return 0; - - tm = obj_find_symbol(f, "__this_module"); - dep = (struct new_module_ref *) sec->contents; - for (i = 0; i < n_ext_modules; ++i) - if (ext_modules[i].used) { - dep->dep = ext_modules[i].addr; - obj_symbol_patch(f, sec->idx, - (char *) &dep->ref - sec->contents, tm); - dep->next_ref = 0; - ++dep; - } - } - - if (flag_export && !obj_find_section(f, "__ksymtab")) { - size_t nsyms; - int *loaded; - - sec = - obj_create_alloced_section(f, "__ksymtab", tgt_sizeof_void_p, - 0); - - /* We don't want to export symbols residing in sections that - aren't loaded. There are a number of these created so that - we make sure certain module options don't appear twice. */ - - loaded = alloca(sizeof(int) * (i = f->header.e_shnum)); - while (--i >= 0) - loaded[i] = (f->sections[i]->header.sh_flags & SHF_ALLOC) != 0; - - for (nsyms = i = 0; i < HASH_BUCKETS; ++i) { - struct obj_symbol *sym; - for (sym = f->symtab[i]; sym; sym = sym->next) - if (ELFW(ST_BIND) (sym->info) != STB_LOCAL - && sym->secidx <= SHN_HIRESERVE - && (sym->secidx >= SHN_LORESERVE - || loaded[sym->secidx])) { - ElfW(Addr) ofs = nsyms * 2 * tgt_sizeof_void_p; - - obj_symbol_patch(f, sec->idx, ofs, sym); - obj_string_patch(f, sec->idx, ofs + tgt_sizeof_void_p, - sym->name); - - nsyms++; - } - } - - obj_extend_section(sec, nsyms * 2 * tgt_sizeof_char_p); - } - - return 1; -} - - -static int -new_init_module(const char *m_name, struct obj_file *f, - unsigned long m_size) -{ - struct new_module *module; - struct obj_section *sec; - void *image; - int ret; - tgt_long m_addr; - - sec = obj_find_section(f, ".this"); - if (!sec || !sec->contents) { - perror_msg("corrupt module %s?",m_name); - exit(EXIT_FAILURE); - } - module = (struct new_module *) sec->contents; - m_addr = sec->header.sh_addr; - - module->size_of_struct = sizeof(*module); - module->size = m_size; - module->flags = flag_autoclean ? NEW_MOD_AUTOCLEAN : 0; - - sec = obj_find_section(f, "__ksymtab"); - if (sec && sec->header.sh_size) { - module->syms = sec->header.sh_addr; - module->nsyms = sec->header.sh_size / (2 * tgt_sizeof_char_p); - } - - if (n_ext_modules_used) { - sec = obj_find_section(f, ".kmodtab"); - module->deps = sec->header.sh_addr; - module->ndeps = n_ext_modules_used; - } - - module->init = - obj_symbol_final_value(f, obj_find_symbol(f, "init_module")); - module->cleanup = - obj_symbol_final_value(f, obj_find_symbol(f, "cleanup_module")); - - sec = obj_find_section(f, "__ex_table"); - if (sec) { - module->ex_table_start = sec->header.sh_addr; - module->ex_table_end = sec->header.sh_addr + sec->header.sh_size; - } - - sec = obj_find_section(f, ".text.init"); - if (sec) { - module->runsize = sec->header.sh_addr - m_addr; - } - sec = obj_find_section(f, ".data.init"); - if (sec) { - if (!module->runsize || - module->runsize > sec->header.sh_addr - m_addr) - module->runsize = sec->header.sh_addr - m_addr; - } - sec = obj_find_section(f, ARCHDATA_SEC_NAME); - if (sec && sec->header.sh_size) { - module->archdata_start = (void*)sec->header.sh_addr; - module->archdata_end = module->archdata_start + sec->header.sh_size; - } - sec = obj_find_section(f, KALLSYMS_SEC_NAME); - if (sec && sec->header.sh_size) { - module->kallsyms_start = (void*)sec->header.sh_addr; - module->kallsyms_end = module->kallsyms_start + sec->header.sh_size; - } - - if (!arch_init_module(f, module)) - return 0; - - /* Whew! All of the initialization is complete. Collect the final - module image and give it to the kernel. */ - - image = xmalloc(m_size); - obj_create_image(f, image); - - ret = new_sys_init_module(m_name, (struct new_module *) image); - if (ret) - perror_msg("init_module: %s", m_name); - - free(image); - - return ret == 0; -} - -#else - -#define new_init_module(x, y, z) TRUE -#define new_create_this_module(x, y) 0 -#define new_create_module_ksymtab(x) -#define query_module(v, w, x, y, z) -1 - -#endif /* BB_FEATURE_NEW_MODULE_INTERFACE */ - - -/*======================================================================*/ - -static int -obj_string_patch(struct obj_file *f, int secidx, ElfW(Addr) offset, - const char *string) -{ - struct obj_string_patch *p; - struct obj_section *strsec; - size_t len = strlen(string) + 1; - char *loc; - - p = xmalloc(sizeof(*p)); - p->next = f->string_patches; - p->reloc_secidx = secidx; - p->reloc_offset = offset; - f->string_patches = p; - - strsec = obj_find_section(f, ".kstrtab"); - if (strsec == NULL) { - strsec = obj_create_alloced_section(f, ".kstrtab", 1, len); - p->string_offset = 0; - loc = strsec->contents; - } else { - p->string_offset = strsec->header.sh_size; - loc = obj_extend_section(strsec, len); - } - memcpy(loc, string, len); - - return 1; -} - -#ifdef BB_FEATURE_NEW_MODULE_INTERFACE -static int -obj_symbol_patch(struct obj_file *f, int secidx, ElfW(Addr) offset, - struct obj_symbol *sym) -{ - struct obj_symbol_patch *p; - - p = xmalloc(sizeof(*p)); - p->next = f->symbol_patches; - p->reloc_secidx = secidx; - p->reloc_offset = offset; - p->sym = sym; - f->symbol_patches = p; - - return 1; -} -#endif - -static int obj_check_undefineds(struct obj_file *f) -{ - unsigned long i; - int ret = 1; - - for (i = 0; i < HASH_BUCKETS; ++i) { - struct obj_symbol *sym; - for (sym = f->symtab[i]; sym; sym = sym->next) - if (sym->secidx == SHN_UNDEF) { - if (ELFW(ST_BIND) (sym->info) == STB_WEAK) { - sym->secidx = SHN_ABS; - sym->value = 0; - } else { - if (!flag_quiet) { - error_msg("unresolved symbol %s", sym->name); - } - ret = 0; - } - } - } - - return ret; -} - -static void obj_allocate_commons(struct obj_file *f) -{ - struct common_entry { - struct common_entry *next; - struct obj_symbol *sym; - } *common_head = NULL; - - unsigned long i; - - for (i = 0; i < HASH_BUCKETS; ++i) { - struct obj_symbol *sym; - for (sym = f->symtab[i]; sym; sym = sym->next) - if (sym->secidx == SHN_COMMON) { - /* Collect all COMMON symbols and sort them by size so as to - minimize space wasted by alignment requirements. */ - { - struct common_entry **p, *n; - for (p = &common_head; *p; p = &(*p)->next) - if (sym->size <= (*p)->sym->size) - break; - - n = alloca(sizeof(*n)); - n->next = *p; - n->sym = sym; - *p = n; - } - } - } - - for (i = 1; i < f->local_symtab_size; ++i) { - struct obj_symbol *sym = f->local_symtab[i]; - if (sym && sym->secidx == SHN_COMMON) { - struct common_entry **p, *n; - for (p = &common_head; *p; p = &(*p)->next) - if (sym == (*p)->sym) - break; - else if (sym->size < (*p)->sym->size) { - n = alloca(sizeof(*n)); - n->next = *p; - n->sym = sym; - *p = n; - break; - } - } - } - - if (common_head) { - /* Find the bss section. */ - for (i = 0; i < f->header.e_shnum; ++i) - if (f->sections[i]->header.sh_type == SHT_NOBITS) - break; - - /* If for some reason there hadn't been one, create one. */ - if (i == f->header.e_shnum) { - struct obj_section *sec; - - f->sections = xrealloc(f->sections, (i + 1) * sizeof(sec)); - f->sections[i] = sec = arch_new_section(); - f->header.e_shnum = i + 1; - - memset(sec, 0, sizeof(*sec)); - sec->header.sh_type = SHT_PROGBITS; - sec->header.sh_flags = SHF_WRITE | SHF_ALLOC; - sec->name = ".bss"; - sec->idx = i; - } - - /* Allocate the COMMONS. */ - { - ElfW(Addr) bss_size = f->sections[i]->header.sh_size; - ElfW(Addr) max_align = f->sections[i]->header.sh_addralign; - struct common_entry *c; - - for (c = common_head; c; c = c->next) { - ElfW(Addr) align = c->sym->value; - - if (align > max_align) - max_align = align; - if (bss_size & (align - 1)) - bss_size = (bss_size | (align - 1)) + 1; - - c->sym->secidx = i; - c->sym->value = bss_size; - - bss_size += c->sym->size; - } - - f->sections[i]->header.sh_size = bss_size; - f->sections[i]->header.sh_addralign = max_align; - } - } - - /* For the sake of patch relocation and parameter initialization, - allocate zeroed data for NOBITS sections now. Note that after - this we cannot assume NOBITS are really empty. */ - for (i = 0; i < f->header.e_shnum; ++i) { - struct obj_section *s = f->sections[i]; - if (s->header.sh_type == SHT_NOBITS) { - if (s->header.sh_size != 0) - s->contents = memset(xmalloc(s->header.sh_size), - 0, s->header.sh_size); - else - s->contents = NULL; - - s->header.sh_type = SHT_PROGBITS; - } - } -} - -static unsigned long obj_load_size(struct obj_file *f) -{ - unsigned long dot = 0; - struct obj_section *sec; - - /* Finalize the positions of the sections relative to one another. */ - - for (sec = f->load_order; sec; sec = sec->load_next) { - ElfW(Addr) align; - - align = sec->header.sh_addralign; - if (align && (dot & (align - 1))) - dot = (dot | (align - 1)) + 1; - - sec->header.sh_addr = dot; - dot += sec->header.sh_size; - } - - return dot; -} - -static int obj_relocate(struct obj_file *f, ElfW(Addr) base) -{ - int i, n = f->header.e_shnum; - int ret = 1; - - /* Finalize the addresses of the sections. */ - - f->baseaddr = base; - for (i = 0; i < n; ++i) - f->sections[i]->header.sh_addr += base; - - /* And iterate over all of the relocations. */ - - for (i = 0; i < n; ++i) { - struct obj_section *relsec, *symsec, *targsec, *strsec; - ElfW(RelM) * rel, *relend; - ElfW(Sym) * symtab; - const char *strtab; - - relsec = f->sections[i]; - if (relsec->header.sh_type != SHT_RELM) - continue; - - symsec = f->sections[relsec->header.sh_link]; - targsec = f->sections[relsec->header.sh_info]; - strsec = f->sections[symsec->header.sh_link]; - - rel = (ElfW(RelM) *) relsec->contents; - relend = rel + (relsec->header.sh_size / sizeof(ElfW(RelM))); - symtab = (ElfW(Sym) *) symsec->contents; - strtab = (const char *) strsec->contents; - - for (; rel < relend; ++rel) { - ElfW(Addr) value = 0; - struct obj_symbol *intsym = NULL; - unsigned long symndx; - ElfW(Sym) * extsym = 0; - const char *errmsg; - - /* Attempt to find a value to use for this relocation. */ - - symndx = ELFW(R_SYM) (rel->r_info); - if (symndx) { - /* Note we've already checked for undefined symbols. */ - - extsym = &symtab[symndx]; - if (ELFW(ST_BIND) (extsym->st_info) == STB_LOCAL) { - /* Local symbols we look up in the local table to be sure - we get the one that is really intended. */ - intsym = f->local_symtab[symndx]; - } else { - /* Others we look up in the hash table. */ - const char *name; - if (extsym->st_name) - name = strtab + extsym->st_name; - else - name = f->sections[extsym->st_shndx]->name; - intsym = obj_find_symbol(f, name); - } - - value = obj_symbol_final_value(f, intsym); - intsym->referenced = 1; - } -#if SHT_RELM == SHT_RELA -#if defined(__alpha__) && defined(AXP_BROKEN_GAS) - /* Work around a nasty GAS bug, that is fixed as of 2.7.0.9. */ - if (!extsym || !extsym->st_name || - ELFW(ST_BIND) (extsym->st_info) != STB_LOCAL) -#endif - value += rel->r_addend; -#endif - - /* Do it! */ - switch (arch_apply_relocation - (f, targsec, symsec, intsym, rel, value)) { - case obj_reloc_ok: - break; - - case obj_reloc_overflow: - errmsg = "Relocation overflow"; - goto bad_reloc; - case obj_reloc_dangerous: - errmsg = "Dangerous relocation"; - goto bad_reloc; - case obj_reloc_unhandled: - errmsg = "Unhandled relocation"; - bad_reloc: - if (extsym) { - error_msg("%s of type %ld for %s", errmsg, - (long) ELFW(R_TYPE) (rel->r_info), - strtab + extsym->st_name); - } else { - error_msg("%s of type %ld", errmsg, - (long) ELFW(R_TYPE) (rel->r_info)); - } - ret = 0; - break; - } - } - } - - /* Finally, take care of the patches. */ - - if (f->string_patches) { - struct obj_string_patch *p; - struct obj_section *strsec; - ElfW(Addr) strsec_base; - strsec = obj_find_section(f, ".kstrtab"); - strsec_base = strsec->header.sh_addr; - - for (p = f->string_patches; p; p = p->next) { - struct obj_section *targsec = f->sections[p->reloc_secidx]; - *(ElfW(Addr) *) (targsec->contents + p->reloc_offset) - = strsec_base + p->string_offset; - } - } - - if (f->symbol_patches) { - struct obj_symbol_patch *p; - - for (p = f->symbol_patches; p; p = p->next) { - struct obj_section *targsec = f->sections[p->reloc_secidx]; - *(ElfW(Addr) *) (targsec->contents + p->reloc_offset) - = obj_symbol_final_value(f, p->sym); - } - } - - return ret; -} - -static int obj_create_image(struct obj_file *f, char *image) -{ - struct obj_section *sec; - ElfW(Addr) base = f->baseaddr; - - for (sec = f->load_order; sec; sec = sec->load_next) { - char *secimg; - - if (sec->contents == 0 || sec->header.sh_size == 0) - continue; - - secimg = image + (sec->header.sh_addr - base); - - /* Note that we allocated data for NOBITS sections earlier. */ - memcpy(secimg, sec->contents, sec->header.sh_size); - } - - return 1; -} - -/*======================================================================*/ - -static struct obj_file *obj_load(FILE * fp, int loadprogbits) -{ - struct obj_file *f; - ElfW(Shdr) * section_headers; - int shnum, i; - char *shstrtab; - - /* Read the file header. */ - - f = arch_new_file(); - memset(f, 0, sizeof(*f)); - f->symbol_cmp = strcmp; - f->symbol_hash = obj_elf_hash; - f->load_order_search_start = &f->load_order; - - fseek(fp, 0, SEEK_SET); - if (fread(&f->header, sizeof(f->header), 1, fp) != 1) { - perror_msg("error reading ELF header"); - return NULL; - } - - if (f->header.e_ident[EI_MAG0] != ELFMAG0 - || f->header.e_ident[EI_MAG1] != ELFMAG1 - || f->header.e_ident[EI_MAG2] != ELFMAG2 - || f->header.e_ident[EI_MAG3] != ELFMAG3) { - error_msg("not an ELF file"); - return NULL; - } - if (f->header.e_ident[EI_CLASS] != ELFCLASSM - || f->header.e_ident[EI_DATA] != ELFDATAM - || f->header.e_ident[EI_VERSION] != EV_CURRENT - || !MATCH_MACHINE(f->header.e_machine)) { - error_msg("ELF file not for this architecture"); - return NULL; - } - if (f->header.e_type != ET_REL) { - error_msg("ELF file not a relocatable object"); - return NULL; - } - - /* Read the section headers. */ - - if (f->header.e_shentsize != sizeof(ElfW(Shdr))) { - error_msg("section header size mismatch: %lu != %lu", - (unsigned long) f->header.e_shentsize, - (unsigned long) sizeof(ElfW(Shdr))); - return NULL; - } - - shnum = f->header.e_shnum; - f->sections = xmalloc(sizeof(struct obj_section *) * shnum); - memset(f->sections, 0, sizeof(struct obj_section *) * shnum); - - section_headers = alloca(sizeof(ElfW(Shdr)) * shnum); - fseek(fp, f->header.e_shoff, SEEK_SET); - if (fread(section_headers, sizeof(ElfW(Shdr)), shnum, fp) != shnum) { - perror_msg("error reading ELF section headers"); - return NULL; - } - - /* Read the section data. */ - - for (i = 0; i < shnum; ++i) { - struct obj_section *sec; - - f->sections[i] = sec = arch_new_section(); - memset(sec, 0, sizeof(*sec)); - - sec->header = section_headers[i]; - sec->idx = i; - - if(sec->header.sh_size) switch (sec->header.sh_type) { - case SHT_NULL: - case SHT_NOTE: - case SHT_NOBITS: - /* ignore */ - break; - - case SHT_PROGBITS: -#if LOADBITS - if (!loadprogbits) { - sec->contents = NULL; - break; - } -#endif - case SHT_SYMTAB: - case SHT_STRTAB: - case SHT_RELM: - if (sec->header.sh_size > 0) { - sec->contents = xmalloc(sec->header.sh_size); - fseek(fp, sec->header.sh_offset, SEEK_SET); - if (fread(sec->contents, sec->header.sh_size, 1, fp) != 1) { - perror_msg("error reading ELF section data"); - return NULL; - } - } else { - sec->contents = NULL; - } - break; - -#if SHT_RELM == SHT_REL - case SHT_RELA: - error_msg("RELA relocations not supported on this architecture"); - return NULL; -#else - case SHT_REL: - error_msg("REL relocations not supported on this architecture"); - return NULL; -#endif - - default: - if (sec->header.sh_type >= SHT_LOPROC) { - /* Assume processor specific section types are debug - info and can safely be ignored. If this is ever not - the case (Hello MIPS?), don't put ifdefs here but - create an arch_load_proc_section(). */ - break; - } - - error_msg("can't handle sections of type %ld", - (long) sec->header.sh_type); - return NULL; - } - } - - /* Do what sort of interpretation as needed by each section. */ - - shstrtab = f->sections[f->header.e_shstrndx]->contents; - - for (i = 0; i < shnum; ++i) { - struct obj_section *sec = f->sections[i]; - sec->name = shstrtab + sec->header.sh_name; - } - - for (i = 0; i < shnum; ++i) { - struct obj_section *sec = f->sections[i]; - - /* .modinfo should be contents only but gcc has no attribute for that. - * The kernel may have marked .modinfo as ALLOC, ignore this bit. - */ - if (strcmp(sec->name, ".modinfo") == 0) - sec->header.sh_flags &= ~SHF_ALLOC; - - if (sec->header.sh_flags & SHF_ALLOC) - obj_insert_section_load_order(f, sec); - - switch (sec->header.sh_type) { - case SHT_SYMTAB: - { - unsigned long nsym, j; - char *strtab; - ElfW(Sym) * sym; - - if (sec->header.sh_entsize != sizeof(ElfW(Sym))) { - error_msg("symbol size mismatch: %lu != %lu", - (unsigned long) sec->header.sh_entsize, - (unsigned long) sizeof(ElfW(Sym))); - return NULL; - } - - nsym = sec->header.sh_size / sizeof(ElfW(Sym)); - strtab = f->sections[sec->header.sh_link]->contents; - sym = (ElfW(Sym) *) sec->contents; - - /* Allocate space for a table of local symbols. */ - j = f->local_symtab_size = sec->header.sh_info; - f->local_symtab = xcalloc(j, sizeof(struct obj_symbol *)); - - /* Insert all symbols into the hash table. */ - for (j = 1, ++sym; j < nsym; ++j, ++sym) { - const char *name; - if (sym->st_name) - name = strtab + sym->st_name; - else - name = f->sections[sym->st_shndx]->name; - - obj_add_symbol(f, name, j, sym->st_info, sym->st_shndx, - sym->st_value, sym->st_size); - } - } - break; - - case SHT_RELM: - if (sec->header.sh_entsize != sizeof(ElfW(RelM))) { - error_msg("relocation entry size mismatch: %lu != %lu", - (unsigned long) sec->header.sh_entsize, - (unsigned long) sizeof(ElfW(RelM))); - return NULL; - } - break; - /* XXX Relocation code from modutils-2.3.19 is not here. - * Why? That's about 20 lines of code from obj/obj_load.c, - * which gets done in a second pass through the sections. - * This BusyBox insmod does similar work in obj_relocate(). */ - } - } - - return f; -} - -#ifdef BB_FEATURE_INSMOD_LOADINKMEM -/* - * load the unloaded sections directly into the memory allocated by - * kernel for the module - */ - -static int obj_load_progbits(FILE * fp, struct obj_file* f, char* imagebase) -{ - ElfW(Addr) base = f->baseaddr; - struct obj_section* sec; - - for (sec = f->load_order; sec; sec = sec->load_next) { - - /* section already loaded? */ - if (sec->contents != NULL) - continue; - - if (sec->header.sh_size == 0) - continue; - - sec->contents = imagebase + (sec->header.sh_addr - base); - fseek(fp, sec->header.sh_offset, SEEK_SET); - if (fread(sec->contents, sec->header.sh_size, 1, fp) != 1) { - error_msg("error reading ELF section data: %s\n", strerror(errno)); - return 0; - } - - } - return 1; -} -#endif - -static void hide_special_symbols(struct obj_file *f) -{ - static const char *const specials[] = { - "cleanup_module", - "init_module", - "kernel_version", - NULL - }; - - struct obj_symbol *sym; - const char *const *p; - - for (p = specials; *p; ++p) - if ((sym = obj_find_symbol(f, *p)) != NULL) - sym->info = - ELFW(ST_INFO) (STB_LOCAL, ELFW(ST_TYPE) (sym->info)); -} - -#ifdef BB_FEATURE_INSMOD_CHECK_TAINTED -static int obj_gpl_license(struct obj_file *f, const char **license) -{ - struct obj_section *sec; - /* This list must match *exactly* the list of allowable licenses in - * linux/include/linux/module.h. Checking for leading "GPL" will not - * work, somebody will use "GPL sucks, this is proprietary". - */ - static const char *gpl_licenses[] = { - "GPL", - "GPL v2", - "GPL and additional rights", - "Dual BSD/GPL", - "Dual MPL/GPL", - }; - - if ((sec = obj_find_section(f, ".modinfo"))) { - const char *value, *ptr, *endptr; - ptr = sec->contents; - endptr = ptr + sec->header.sh_size; - while (ptr < endptr) { - if ((value = strchr(ptr, '=')) && strncmp(ptr, "license", value-ptr) == 0) { - int i; - if (license) - *license = value+1; - for (i = 0; i < sizeof(gpl_licenses)/sizeof(gpl_licenses[0]); ++i) { - if (strcmp(value+1, gpl_licenses[i]) == 0) - return(0); - } - return(2); - } - if (strchr(ptr, '\0')) - ptr = strchr(ptr, '\0') + 1; - else - ptr = endptr; - } - } - return(1); -} - -#define TAINT_FILENAME "/proc/sys/kernel/tainted" -#define TAINT_PROPRIETORY_MODULE (1<<0) -#define TAINT_FORCED_MODULE (1<<1) -#define TAINT_UNSAFE_SMP (1<<2) -#define TAINT_URL "http://www.tux.org/lkml/#export-tainted" - -static void set_tainted(struct obj_file *f, int fd, char *m_name, - int kernel_has_tainted, int taint, const char *text1, const char *text2) -{ - char buf[80]; - int oldval; - static int first = 1; - if (fd < 0 && !kernel_has_tainted) - return; /* New modutils on old kernel */ - printf("Warning: loading %s will taint the kernel: %s%s\n", - m_name, text1, text2); - if (first) { - printf(" See %s for information about tainted modules\n", TAINT_URL); - first = 0; - } - if (fd >= 0) { - read(fd, buf, sizeof(buf)-1); - buf[sizeof(buf)-1] = '\0'; - oldval = strtoul(buf, NULL, 10); - sprintf(buf, "%d\n", oldval | taint); - write(fd, buf, strlen(buf)); - } -} -#endif - -/* Check if loading this module will taint the kernel. */ -static void check_tainted_module(struct obj_file *f, char *m_name) -{ -#ifdef BB_FEATURE_INSMOD_CHECK_TAINTED - static const char tainted_file[] = TAINT_FILENAME; - int fd, kernel_has_tainted; - const char *ptr; - - kernel_has_tainted = 1; - if ((fd = open(tainted_file, O_RDWR)) < 0) { - if (errno == ENOENT) - kernel_has_tainted = 0; - else if (errno == EACCES) - kernel_has_tainted = 1; - else { - perror(tainted_file); - kernel_has_tainted = 0; - } - } - - switch (obj_gpl_license(f, &ptr)) { - case 0: - break; - case 1: - set_tainted(f, fd, m_name, kernel_has_tainted, TAINT_PROPRIETORY_MODULE, "no license", ""); - break; - case 2: - /* The module has a non-GPL license so we pretend that the - * kernel always has a taint flag to get a warning even on - * kernels without the proc flag. - */ - set_tainted(f, fd, m_name, 1, TAINT_PROPRIETORY_MODULE, "non-GPL license - ", ptr); - break; - default: - set_tainted(f, fd, m_name, 1, TAINT_PROPRIETORY_MODULE, "Unexpected return from obj_gpl_license", ""); - break; - } - - if (flag_force_load) - set_tainted(f, fd, m_name, 1, TAINT_FORCED_MODULE, "forced load", ""); - - if (fd >= 0) - close(fd); -#endif -} - -void my_usage(void) -{ - printf("Usage."); - exit(0); -} - -extern int insmod_main( int argc, char **argv) -{ - int k_crcs; - int k_new_syscalls; - int len; - char *tmp; - unsigned long m_size; - ElfW(Addr) m_addr; - FILE *fp; - struct obj_file *f; - char m_name[FILENAME_MAX] = "\0"; - int exit_status = EXIT_FAILURE; - int m_has_modinfo; -#ifdef BB_FEATURE_INSMOD_VERSION_CHECKING - struct utsname uts_info; - char m_strversion[STRVERSIONLEN]; - int m_version; - int m_crcs; -#endif - - if (argc <= 1) - my_usage(); - - argv++; argc--; - - /* Grab the module name */ - if ((tmp = strrchr(*argv, '/')) != NULL) { - tmp++; - } else { - tmp = *argv; - } - len = strlen(tmp); - - if (len > 2 && tmp[len - 2] == '.' && tmp[len - 1] == 'o') - len -= 2; - memcpy(m_name, tmp, len); - strcpy(m_fullName, m_name); - strcat(m_fullName, ".o"); - - /* Get a filedesc for the module. Check we we have a complete path */ - if ((fp = fopen(*argv, "r")) == NULL) { - errorMsg("Module %s not found", *argv); - return -1; - } else - memcpy(m_filename, *argv, strlen(*argv)); - - - if ((f = obj_load(fp, LOADBITS)) == NULL) { - logperror("Could not load the module"); - goto out; - } - - if (get_modinfo_value(f, "kernel_version") == NULL) - m_has_modinfo = 0; - else - m_has_modinfo = 1; - -#ifdef BB_FEATURE_INSMOD_VERSION_CHECKING - /* Version correspondence? */ - if (!flag_quiet) { - if (uname(&uts_info) < 0) - uts_info.release[0] = '\0'; - if (m_has_modinfo) { - m_version = new_get_module_version(f, m_strversion); - } else { - m_version = old_get_module_version(f, m_strversion); - if (m_version == -1) { - error_msg("couldn't find the kernel version the module was " - "compiled for"); - goto out; - } - } - - if (strncmp(uts_info.release, m_strversion, STRVERSIONLEN) != 0) { - if (flag_force_load) { - error_msg("Warning: kernel-module version mismatch\n" - "\t%s was compiled for kernel version %s\n" - "\twhile this kernel is version %s", - m_filename, m_strversion, uts_info.release); - } else { - error_msg("kernel-module version mismatch\n" - "\t%s was compiled for kernel version %s\n" - "\twhile this kernel is version %s.", - m_filename, m_strversion, uts_info.release); - goto out; - } - } - } - k_crcs = 0; -#endif /* BB_FEATURE_INSMOD_VERSION_CHECKING */ - - k_new_syscalls = !query_module(NULL, 0, NULL, 0, NULL); - - if (k_new_syscalls) { -#ifdef BB_FEATURE_NEW_MODULE_INTERFACE - if (!new_get_kernel_symbols()) - goto out; - k_crcs = new_is_kernel_checksummed(); -#else - error_msg("Not configured to support new kernels"); - goto out; -#endif - } else { -#ifdef BB_FEATURE_OLD_MODULE_INTERFACE - if (!old_get_kernel_symbols(m_name)) - goto out; - k_crcs = old_is_kernel_checksummed(); -#else - error_msg("Not configured to support old kernels"); - goto out; -#endif - } - -#ifdef BB_FEATURE_INSMOD_VERSION_CHECKING - if (m_has_modinfo) - m_crcs = new_is_module_checksummed(f); - else - m_crcs = old_is_module_checksummed(f); - - if (m_crcs != k_crcs) - obj_set_symbol_compare(f, ncv_strcmp, ncv_symbol_hash); -#endif /* BB_FEATURE_INSMOD_VERSION_CHECKING */ - - /* Let the module know about the kernel symbols. */ - add_kernel_symbols(f); - - /* Allocate common symbols, symbol tables, and string tables. */ - - if (k_new_syscalls - ? !new_create_this_module(f, m_name) - : !old_create_mod_use_count(f)) - { - goto out; - } - - if (!obj_check_undefineds(f)) { - goto out; - } - obj_allocate_commons(f); - check_tainted_module(f, m_name); - - if (m_has_modinfo - ? !new_process_module_arguments(f, argc - 1, argv + 1) - : !old_process_module_arguments(f, argc - 1, argv + 1)) - { - goto out; - } - - arch_create_got(f); - hide_special_symbols(f); - - if (k_new_syscalls) - new_create_module_ksymtab(f); - - /* Find current size of the module */ - m_size = obj_load_size(f); - - - m_addr = create_module(m_name, m_size); - if (m_addr==-1) switch (errno) { - case EEXIST: - error_msg("A module named %s already exists", m_name); - goto out; - case ENOMEM: - error_msg("Can't allocate kernel memory for module; needed %lu bytes", - m_size); - goto out; - default: - perror_msg("create_module: %s", m_name); - goto out; - } - -#if !LOADBITS - /* - * the PROGBITS section was not loaded by the obj_load - * now we can load them directly into the kernel memory - */ - if (!obj_load_progbits(fp, f, (char*)m_addr)) { - delete_module(m_name); - goto out; - } -#endif - - if (!obj_relocate(f, m_addr)) { - delete_module(m_name); - goto out; - } - - if (k_new_syscalls - ? !new_init_module(m_name, f, m_size) - : !old_init_module(m_name, f, m_size)) - { - delete_module(m_name); - goto out; - } - - exit_status = EXIT_SUCCESS; - -out: - fclose(fp); - return(exit_status); -} - -int insmod_call(char * full_filename, char * params) -{ - int argc = 2; - char *argv[50]; - char * ptr = params; - argv[0] = "stage1"; - argv[1] = full_filename; - - while (ptr != NULL) { - argv[argc] = ptr; - argc++; - ptr = strchr(ptr, ' '); - if (ptr) { - ptr[0] = '\0'; - ptr++; - } - } - - return insmod_main(argc, argv); -} diff --git a/mdk-stage1/insmod-busybox/loop.h b/mdk-stage1/insmod-busybox/loop.h deleted file mode 100644 index cba8c6b2b..000000000 --- a/mdk-stage1/insmod-busybox/loop.h +++ /dev/null @@ -1,5 +0,0 @@ -#include <linux/posix_types.h> -#undef dev_t -#define dev_t __kernel_dev_t -#include <linux/loop.h> -#undef dev_t diff --git a/mdk-stage1/insmod-busybox/messages.c b/mdk-stage1/insmod-busybox/messages.c deleted file mode 100644 index 81fd9c75c..000000000 --- a/mdk-stage1/insmod-busybox/messages.c +++ /dev/null @@ -1,90 +0,0 @@ -/* vi: set sw=4 ts=4: */ -/* - * Copyright (C) 2000 by BitterSweet Enterprises, LLC. - * Written by Karl M. Hegbloom <karlheg@debian.org> - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA - * - */ - -/* - * Let's put all of these messages in one place, and link this in as - * a separate object module, so that there are not going to be - * multiple non-unique but very similar strings in the binary. - * Perhaps this will make it simpler to internationalize also, and - * may make the binary slightly smaller. - */ - -// To use this header file, include something like this: -// -//#define BB_DECLARE_EXTERN -//#define bb_need_memory_exhausted -//#include "messages.c" -// -//Then just use the string memory_exhausted when it is needed. -// - -#include "busybox.h" -#ifndef _BB_MESSAGES_C -#define _BB_MESSAGES_C - -#ifdef BB_DECLARE_EXTERN -# define BB_DEF_MESSAGE(symbol, string_const) extern const char *symbol; -#else -# define BB_DEF_MESSAGE(symbol, string_const) const char *symbol = string_const; -#endif - - -#if defined bb_need_full_version || ! defined BB_DECLARE_EXTERN - BB_DEF_MESSAGE(full_version, - "BusyBox v" BB_VER " (" BB_BT ") multi-call binary -- GPL2") -#endif -#if defined bb_need_name_too_long || ! defined BB_DECLARE_EXTERN - BB_DEF_MESSAGE(name_too_long, "file name too long\n") -#endif -#if defined bb_need_omitting_directory || ! defined BB_DECLARE_EXTERN - BB_DEF_MESSAGE(omitting_directory, "%s: omitting directory\n") -#endif -#if defined bb_need_not_a_directory || ! defined BB_DECLARE_EXTERN - BB_DEF_MESSAGE(not_a_directory, "%s: not a directory\n") -#endif -#if defined bb_need_memory_exhausted || ! defined BB_DECLARE_EXTERN - BB_DEF_MESSAGE(memory_exhausted, "memory exhausted\n") -#endif -#if defined bb_need_invalid_date || ! defined BB_DECLARE_EXTERN - BB_DEF_MESSAGE(invalid_date, "invalid date `%s'\n") -#endif -#if defined bb_need_invalid_option || ! defined BB_DECLARE_EXTERN - BB_DEF_MESSAGE(invalid_option, "invalid option -- %c\n") -#endif -#if defined bb_need_io_error || ! defined BB_DECLARE_EXTERN - BB_DEF_MESSAGE(io_error, "%s: input/output error -- %s\n") -#endif -#if defined bb_need_help || ! defined BB_DECLARE_EXTERN - BB_DEF_MESSAGE(dash_dash_help, "--help") -#endif -#if defined bb_need_write_error || ! defined BB_DECLARE_EXTERN - BB_DEF_MESSAGE(write_error, "Write Error\n") -#endif -#if defined bb_need_too_few_args || ! defined BB_DECLARE_EXTERN - BB_DEF_MESSAGE(too_few_args, "too few arguments\n") -#endif -#if defined bb_need_name_longer_then_foo || ! defined BB_DECLARE_EXTERN - BB_DEF_MESSAGE(name_longer_then_foo, "Names longer then %d chars not supported.\n") -#endif - - -#endif /* _BB_MESSAGES_C */ - diff --git a/mdk-stage1/insmod-busybox/utility.c b/mdk-stage1/insmod-busybox/utility.c deleted file mode 100644 index ffd323347..000000000 --- a/mdk-stage1/insmod-busybox/utility.c +++ /dev/null @@ -1,1759 +0,0 @@ -/* vi: set sw=4 ts=4: */ -/* - * Utility routines. - * - * Copyright (C) tons of folks. Tracking down who wrote what - * isn't something I'm going to worry about... If you wrote something - * here, please feel free to acknowledge your work. - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA - * - * Based in part on code from sash, Copyright (c) 1999 by David I. Bell - * Permission has been granted to redistribute this code under the GPL. - * - */ - -#include "busybox.h" -#if defined (BB_CHMOD_CHOWN_CHGRP) \ - || defined (BB_CP_MV) \ - || defined (BB_FIND) \ - || defined (BB_INSMOD) \ - || defined (BB_LS) \ - || defined (BB_RM) \ - || defined (BB_TAR) -/* same conditions as recursiveAction */ -#define bb_need_name_too_long -#endif -#define bb_need_memory_exhausted -#define bb_need_full_version -#define BB_DECLARE_EXTERN -#include "messages.c" - -#include <stdio.h> -#include <string.h> -#include <errno.h> -#include <fcntl.h> -#include <dirent.h> -#include <time.h> -#include <utime.h> -#include <unistd.h> -#include <ctype.h> -#include <sys/ioctl.h> -#include <sys/utsname.h> /* for uname(2) */ - -/* Busybox mount uses either /proc/filesystems or /dev/mtab to get the - * list of available filesystems used for the -t auto option */ -#if defined BB_FEATURE_USE_PROCFS && defined BB_FEATURE_USE_DEVPS_PATCH -//#error Sorry, but busybox can't use both /proc and /dev/ps at the same time -- Pick one and try again. -#error "Sorry, but busybox can't use both /proc and /dev/ps at the same time -- Pick one and try again." -#endif - - -#if defined BB_MOUNT || defined BB_UMOUNT || defined BB_DF -# if defined BB_MTAB -const char mtab_file[] = "/etc/mtab"; -# else -# if defined BB_FEATURE_USE_PROCFS -const char mtab_file[] = "/proc/mounts"; -# else -# if defined BB_FEATURE_USE_DEVPS_PATCH -const char mtab_file[] = "/dev/mtab"; -# else -# error With (BB_MOUNT||BB_UMOUNT||BB_DF) defined, you must define either BB_MTAB or ( BB_FEATURE_USE_PROCFS | BB_FEATURE_USE_DEVPS_PATCH) -# endif -# endif -# endif -#endif - -#ifdef _STANDALONE_ -void errorMsg(const char *s, ...) -{ - va_list p; - - fflush(stdout); - printf("busybox: "); - va_start(p, s); - vprintf(s, p); - va_end(p); - printf("\n"); - fflush(stdout); -} - -extern void logperror(char *s) -{ - perror(s); -} - -void fatalError(const char *s, ...) -{ - va_list p; - - fflush(stdout); - fprintf(stdout, "busybox: "); - va_start(p, s); - vfprintf(stdout, s, p); - va_end(p); - fprintf(stdout, "\n"); - fflush(stdout); - exit(FALSE); -} -#else /* _STANDALONE_ */ -#include "../log.h" -extern void errorMsg(const char *s, ...) -{ - va_list p; - - va_start(p, s); - vlog_message(s, p); - va_end(p); -} - -extern void logperror(char *s) -{ - log_perror(s); -} - -extern void fatalError(const char *s, ...) -{ - va_list p; - - va_start(p, s); - vlog_message(s, p); - va_end(p); - while (1); -} -#endif /* _STANDALONE_ */ - - -#if defined BB_INIT -/* Returns kernel version encoded as major*65536 + minor*256 + patch, - * so, for example, to check if the kernel is greater than 2.2.11: - * if (get_kernel_revision() <= 2*65536+2*256+11) { <stuff> } - */ -extern int get_kernel_revision(void) -{ - struct utsname name; - int major = 0, minor = 0, patch = 0; - - if (uname(&name) == -1) { - perror("cannot get system information"); - return (0); - } - sscanf(name.version, "%d.%d.%d", &major, &minor, &patch); - return major * 65536 + minor * 256 + patch; -} -#endif /* BB_INIT */ - - - -#if defined BB_FREE || defined BB_INIT || defined BB_UNAME || defined BB_UPTIME -_syscall1(int, sysinfo, struct sysinfo *, info); -#endif /* BB_INIT */ - -#if defined BB_MOUNT || defined BB_UMOUNT - -#ifndef __NR_umount2 -#define __NR_umount2 52 -#endif - -/* Include our own version of <sys/mount.h>, since libc5 doesn't - * know about umount2 */ -extern _syscall1(int, umount, const char *, special_file); -extern _syscall2(int, umount2, const char *, special_file, int, flags); -extern _syscall5(int, mount, const char *, special_file, const char *, dir, - const char *, fstype, unsigned long int, rwflag, const void *, data); -#endif - -#if defined BB_INSMOD || defined BB_LSMOD -#ifndef __NR_query_module -#define __NR_query_module 167 -#endif -_syscall5(int, query_module, const char *, name, int, which, - void *, buf, size_t, bufsize, size_t*, ret); -#endif - - -#if defined (BB_CP_MV) || defined (BB_DU) - -#define HASH_SIZE 311 /* Should be prime */ -#define hash_inode(i) ((i) % HASH_SIZE) - -static ino_dev_hashtable_bucket_t *ino_dev_hashtable[HASH_SIZE]; - -/* - * Return 1 if statbuf->st_ino && statbuf->st_dev are recorded in - * `ino_dev_hashtable', else return 0 - * - * If NAME is a non-NULL pointer to a character pointer, and there is - * a match, then set *NAME to the value of the name slot in that - * bucket. - */ -int is_in_ino_dev_hashtable(const struct stat *statbuf, char **name) -{ - ino_dev_hashtable_bucket_t *bucket; - - bucket = ino_dev_hashtable[hash_inode(statbuf->st_ino)]; - while (bucket != NULL) { - if ((bucket->ino == statbuf->st_ino) && - (bucket->dev == statbuf->st_dev)) - { - if (name) *name = bucket->name; - return 1; - } - bucket = bucket->next; - } - return 0; -} - -/* Add statbuf to statbuf hash table */ -void add_to_ino_dev_hashtable(const struct stat *statbuf, const char *name) -{ - int i; - size_t s; - ino_dev_hashtable_bucket_t *bucket; - - i = hash_inode(statbuf->st_ino); - s = name ? strlen(name) : 0; - bucket = xmalloc(sizeof(ino_dev_hashtable_bucket_t) + s); - bucket->ino = statbuf->st_ino; - bucket->dev = statbuf->st_dev; - if (name) - strcpy(bucket->name, name); - else - bucket->name[0] = '\0'; - bucket->next = ino_dev_hashtable[i]; - ino_dev_hashtable[i] = bucket; -} - -/* Clear statbuf hash table */ -void reset_ino_dev_hashtable(void) -{ - int i; - ino_dev_hashtable_bucket_t *bucket; - - for (i = 0; i < HASH_SIZE; i++) { - while (ino_dev_hashtable[i] != NULL) { - bucket = ino_dev_hashtable[i]->next; - free(ino_dev_hashtable[i]); - ino_dev_hashtable[i] = bucket; - } - } -} - -#endif /* BB_CP_MV || BB_DU */ - -#if defined (BB_CP_MV) || defined (BB_DU) || defined (BB_LN) || defined (BB_AR) -/* - * Return TRUE if a fileName is a directory. - * Nonexistant files return FALSE. - */ -int isDirectory(const char *fileName, const int followLinks, struct stat *statBuf) -{ - int status; - int didMalloc = 0; - - if (statBuf == NULL) { - statBuf = (struct stat *)xmalloc(sizeof(struct stat)); - ++didMalloc; - } - - if (followLinks == TRUE) - status = stat(fileName, statBuf); - else - status = lstat(fileName, statBuf); - - if (status < 0 || !(S_ISDIR(statBuf->st_mode))) { - status = FALSE; - } - else status = TRUE; - - if (didMalloc) { - free(statBuf); - statBuf = NULL; - } - return status; -} -#endif - -#if defined (BB_AR) || defined BB_CP_MV -/* - * Copy readSize bytes between two file descriptors - */ -int copySubFile(int srcFd, int dstFd, size_t remaining) -{ - size_t size; - char buffer[BUFSIZ]; - - while (remaining > 0) { - if (remaining > BUFSIZ) - size = BUFSIZ; - else - size = remaining; - if (fullWrite(dstFd, buffer, fullRead(srcFd, buffer, size)) < size) - return(FALSE); - remaining -= size; - } - return (TRUE); -} -#endif - - -#if defined (BB_CP_MV) -/* - * Copy one file to another, while possibly preserving its modes, times, and - * modes. Returns TRUE if successful, or FALSE on a failure with an error - * message output. (Failure is not indicated if attributes cannot be set.) - * -Erik Andersen - */ -int -copyFile(const char *srcName, const char *destName, - int setModes, int followLinks, int forceFlag) -{ - int rfd; - int wfd; - int status; - struct stat srcStatBuf; - struct stat dstStatBuf; - struct utimbuf times; - - if (followLinks == TRUE) - status = stat(srcName, &srcStatBuf); - else - status = lstat(srcName, &srcStatBuf); - - if (status < 0) { - perror(srcName); - return FALSE; - } - - if (followLinks == TRUE) - status = stat(destName, &dstStatBuf); - else - status = lstat(destName, &dstStatBuf); - - if (status < 0 || forceFlag==TRUE) { - unlink(destName); - dstStatBuf.st_ino = -1; - dstStatBuf.st_dev = -1; - } - - if ((srcStatBuf.st_dev == dstStatBuf.st_dev) && - (srcStatBuf.st_ino == dstStatBuf.st_ino)) { - errorMsg("Copying file \"%s\" to itself\n", srcName); - return FALSE; - } - - if (S_ISDIR(srcStatBuf.st_mode)) { - //fprintf(stderr, "copying directory %s to %s\n", srcName, destName); - /* Make sure the directory is writable */ - status = mkdir(destName, 0777777 ^ umask(0)); - if (status < 0 && errno != EEXIST) { - perror(destName); - return FALSE; - } - } else if (S_ISLNK(srcStatBuf.st_mode)) { - char link_val[BUFSIZ + 1]; - int link_size; - - //fprintf(stderr, "copying link %s to %s\n", srcName, destName); - /* Warning: This could possibly truncate silently, to BUFSIZ chars */ - link_size = readlink(srcName, &link_val[0], BUFSIZ); - if (link_size < 0) { - perror(srcName); - return FALSE; - } - link_val[link_size] = '\0'; - status = symlink(link_val, destName); - if (status < 0) { - perror(destName); - return FALSE; - } -#if (__GLIBC__ >= 2) && (__GLIBC_MINOR__ >= 1) - if (setModes == TRUE) { - /* Try to set owner, but fail silently like GNU cp */ - lchown(destName, srcStatBuf.st_uid, srcStatBuf.st_gid); - } -#endif - return TRUE; - } else if (S_ISFIFO(srcStatBuf.st_mode)) { - //fprintf(stderr, "copying fifo %s to %s\n", srcName, destName); - if (mkfifo(destName, 0644) < 0) { - perror(destName); - return FALSE; - } - } else if (S_ISBLK(srcStatBuf.st_mode) || S_ISCHR(srcStatBuf.st_mode) - || S_ISSOCK(srcStatBuf.st_mode)) { - //fprintf(stderr, "copying soc, blk, or chr %s to %s\n", srcName, destName); - if (mknod(destName, srcStatBuf.st_mode, srcStatBuf.st_rdev) < 0) { - perror(destName); - return FALSE; - } - } else if (S_ISREG(srcStatBuf.st_mode)) { - //fprintf(stderr, "copying regular file %s to %s\n", srcName, destName); - rfd = open(srcName, O_RDONLY); - if (rfd < 0) { - perror(srcName); - return FALSE; - } - - wfd = open(destName, O_WRONLY | O_CREAT | O_TRUNC, - srcStatBuf.st_mode); - if (wfd < 0) { - perror(destName); - close(rfd); - return FALSE; - } - - if (copySubFile(rfd, wfd, srcStatBuf.st_size)==FALSE) - goto error_exit; - - close(rfd); - if (close(wfd) < 0) { - return FALSE; - } - } - - if (setModes == TRUE) { - /* This is fine, since symlinks never get here */ - if (chown(destName, srcStatBuf.st_uid, srcStatBuf.st_gid) < 0) { - perror(destName); - exit FALSE; - } - if (chmod(destName, srcStatBuf.st_mode) < 0) { - perror(destName); - exit FALSE; - } - times.actime = srcStatBuf.st_atime; - times.modtime = srcStatBuf.st_mtime; - if (utime(destName, ×) < 0) { - perror(destName); - exit FALSE; - } - } - - return TRUE; - - error_exit: - perror(destName); - close(rfd); - close(wfd); - - return FALSE; -} -#endif /* BB_CP_MV */ - - - -#if defined BB_TAR || defined BB_LS ||defined BB_AR - -#define TYPEINDEX(mode) (((mode) >> 12) & 0x0f) -#define TYPECHAR(mode) ("0pcCd?bB-?l?s???" [TYPEINDEX(mode)]) - -/* The special bits. If set, display SMODE0/1 instead of MODE0/1 */ -static const mode_t SBIT[] = { - 0, 0, S_ISUID, - 0, 0, S_ISGID, - 0, 0, S_ISVTX -}; - -/* The 9 mode bits to test */ -static const mode_t MBIT[] = { - S_IRUSR, S_IWUSR, S_IXUSR, - S_IRGRP, S_IWGRP, S_IXGRP, - S_IROTH, S_IWOTH, S_IXOTH -}; - -#define MODE1 "rwxrwxrwx" -#define MODE0 "---------" -#define SMODE1 "..s..s..t" -#define SMODE0 "..S..S..T" - -/* - * Return the standard ls-like mode string from a file mode. - * This is static and so is overwritten on each call. - */ -const char *modeString(int mode) -{ - static char buf[12]; - - int i; - - buf[0] = TYPECHAR(mode); - for (i = 0; i < 9; i++) { - if (mode & SBIT[i]) - buf[i + 1] = (mode & MBIT[i]) ? SMODE1[i] : SMODE0[i]; - else - buf[i + 1] = (mode & MBIT[i]) ? MODE1[i] : MODE0[i]; - } - return buf; -} -#endif /* BB_TAR || BB_LS */ - - -#if defined BB_TAR || defined BB_AR -/* - * Return the standard ls-like time string from a time_t - * This is static and so is overwritten on each call. - */ -const char *timeString(time_t timeVal) -{ - time_t now; - char *str; - static char buf[26]; - - time(&now); - - str = ctime(&timeVal); - - strcpy(buf, &str[4]); - buf[12] = '\0'; - - if ((timeVal > now) || (timeVal < now - 365 * 24 * 60 * 60L)) { - strcpy(&buf[7], &str[20]); - buf[11] = '\0'; - } - - return buf; -} -#endif /* BB_TAR || BB_AR */ - -#if defined BB_TAR || defined BB_CP_MV || defined BB_AR -/* - * Write all of the supplied buffer out to a file. - * This does multiple writes as necessary. - * Returns the amount written, or -1 on an error. - */ -int fullWrite(int fd, const char *buf, int len) -{ - int cc; - int total; - - total = 0; - - while (len > 0) { - cc = write(fd, buf, len); - - if (cc < 0) - return -1; - - buf += cc; - total += cc; - len -= cc; - } - - return total; -} -#endif /* BB_TAR || BB_CP_MV || BB_AR */ - - -#if defined BB_TAR || defined BB_TAIL || defined BB_AR || defined BB_SH || defined BB_CP_MV -/* - * Read all of the supplied buffer from a file. - * This does multiple reads as necessary. - * Returns the amount read, or -1 on an error. - * A short read is returned on an end of file. - */ -int fullRead(int fd, char *buf, int len) -{ - int cc; - int total; - - total = 0; - - while (len > 0) { - cc = read(fd, buf, len); - - if (cc < 0) - return -1; - - if (cc == 0) - break; - - buf += cc; - total += cc; - len -= cc; - } - - return total; -} -#endif /* BB_TAR || BB_TAIL || BB_AR || BB_SH */ - - -#if defined (BB_CHMOD_CHOWN_CHGRP) \ - || defined (BB_CP_MV) \ - || defined (BB_FIND) \ - || defined (BB_INSMOD) \ - || defined (BB_LS) \ - || defined (BB_RM) \ - || defined (BB_TAR) - -/* - * Walk down all the directories under the specified - * location, and do something (something specified - * by the fileAction and dirAction function pointers). - * - * Unfortunatly, while nftw(3) could replace this and reduce - * code size a bit, nftw() wasn't supported before GNU libc 2.1, - * and so isn't sufficiently portable to take over since glibc2.1 - * is so stinking huge. - */ -int recursiveAction(const char *fileName, - int recurse, int followLinks, int depthFirst, - int (*fileAction) (const char *fileName, - struct stat * statbuf, - void* userData), - int (*dirAction) (const char *fileName, - struct stat * statbuf, - void* userData), - void* userData) -{ - int status; - struct stat statbuf; - struct dirent *next; - - if (followLinks == TRUE) - status = stat(fileName, &statbuf); - else - status = lstat(fileName, &statbuf); - - if (status < 0) { -#ifdef BB_DEBUG_PRINT_SCAFFOLD - fprintf(stderr, - "status=%d followLinks=%d TRUE=%d\n", - status, followLinks, TRUE); -#endif - perror(fileName); - return FALSE; - } - - if ((followLinks == FALSE) && (S_ISLNK(statbuf.st_mode))) { - if (fileAction == NULL) - return TRUE; - else - return fileAction(fileName, &statbuf, userData); - } - - if (recurse == FALSE) { - if (S_ISDIR(statbuf.st_mode)) { - if (dirAction != NULL) - return (dirAction(fileName, &statbuf, userData)); - else - return TRUE; - } - } - - if (S_ISDIR(statbuf.st_mode)) { - DIR *dir; - - dir = opendir(fileName); - if (!dir) { - perror(fileName); - return FALSE; - } - if (dirAction != NULL && depthFirst == FALSE) { - status = dirAction(fileName, &statbuf, userData); - if (status == FALSE) { - perror(fileName); - return FALSE; - } - } - while ((next = readdir(dir)) != NULL) { - char nextFile[BUFSIZ + 1]; - - if ((strcmp(next->d_name, "..") == 0) - || (strcmp(next->d_name, ".") == 0)) { - continue; - } - if (strlen(fileName) + strlen(next->d_name) + 1 > BUFSIZ) { - errorMsg("name_too_long"); - return FALSE; - } - memset(nextFile, 0, sizeof(nextFile)); - sprintf(nextFile, "%s/%s", fileName, next->d_name); - status = - recursiveAction(nextFile, TRUE, followLinks, depthFirst, - fileAction, dirAction, userData); - if (status == FALSE) { - closedir(dir); - return FALSE; - } - } - status = closedir(dir); - if (status < 0) { - perror(fileName); - return FALSE; - } - if (dirAction != NULL && depthFirst == TRUE) { - status = dirAction(fileName, &statbuf, userData); - if (status == FALSE) { - perror(fileName); - return FALSE; - } - } - } else { - if (fileAction == NULL) - return TRUE; - else - return fileAction(fileName, &statbuf, userData); - } - return TRUE; -} - -#endif /* BB_CHMOD_CHOWN_CHGRP || BB_CP_MV || BB_FIND || BB_LS || BB_INSMOD */ - - - -#if defined (BB_TAR) || defined (BB_MKDIR) || defined (BB_AR) -/* - * Attempt to create the directories along the specified path, except for - * the final component. The mode is given for the final directory only, - * while all previous ones get default protections. Errors are not reported - * here, as failures to restore files can be reported later. - */ -extern int createPath(const char *name, int mode) -{ - char *cp; - char *cpOld; - char buf[BUFSIZ + 1]; - int retVal = 0; - - strcpy(buf, name); - for (cp = buf; *cp == '/'; cp++); - cp = strchr(cp, '/'); - while (cp) { - cpOld = cp; - cp = strchr(cp + 1, '/'); - *cpOld = '\0'; - retVal = mkdir(buf, cp ? 0777 : mode); - if (retVal != 0 && errno != EEXIST) { - perror(buf); - return FALSE; - } - *cpOld = '/'; - } - return TRUE; -} -#endif /* BB_TAR || BB_MKDIR */ - - - -#if defined (BB_CHMOD_CHOWN_CHGRP) || defined (BB_MKDIR) \ - || defined (BB_MKFIFO) || defined (BB_MKNOD) || defined (BB_AR) -/* [ugoa]{+|-|=}[rwxst] */ - - - -extern int parse_mode(const char *s, mode_t * theMode) -{ - mode_t andMode = - - S_ISVTX | S_ISUID | S_ISGID | S_IRWXU | S_IRWXG | S_IRWXO; - mode_t orMode = 0; - mode_t mode = 0; - mode_t groups = 0; - char type; - char c; - - if (s==NULL) - return (FALSE); - - do { - for (;;) { - switch (c = *s++) { - case '\0': - return -1; - case 'u': - groups |= S_ISUID | S_IRWXU; - continue; - case 'g': - groups |= S_ISGID | S_IRWXG; - continue; - case 'o': - groups |= S_IRWXO; - continue; - case 'a': - groups |= S_ISUID | S_ISGID | S_IRWXU | S_IRWXG | S_IRWXO; - continue; - case '+': - case '=': - case '-': - type = c; - if (groups == 0) /* The default is "all" */ - groups |= - S_ISUID | S_ISGID | S_IRWXU | S_IRWXG | S_IRWXO; - break; - default: - if (isdigit(c) && c >= '0' && c <= '7' && - mode == 0 && groups == 0) { - *theMode = strtol(--s, NULL, 8); - return (TRUE); - } else - return (FALSE); - } - break; - } - - while ((c = *s++) != '\0') { - switch (c) { - case ',': - break; - case 'r': - mode |= S_IRUSR | S_IRGRP | S_IROTH; - continue; - case 'w': - mode |= S_IWUSR | S_IWGRP | S_IWOTH; - continue; - case 'x': - mode |= S_IXUSR | S_IXGRP | S_IXOTH; - continue; - case 's': - mode |= S_IXGRP | S_ISUID | S_ISGID; - continue; - case 't': - mode |= 0; - continue; - default: - *theMode &= andMode; - *theMode |= orMode; - return (TRUE); - } - break; - } - switch (type) { - case '=': - andMode &= ~(groups); - /* fall through */ - case '+': - orMode |= mode & groups; - break; - case '-': - andMode &= ~(mode & groups); - orMode &= andMode; - break; - } - } while (c == ','); - *theMode &= andMode; - *theMode |= orMode; - return (TRUE); -} - - -#endif -/* BB_CHMOD_CHOWN_CHGRP || BB_MKDIR || BB_MKFIFO || BB_MKNOD */ - - - - - -#if defined BB_CHMOD_CHOWN_CHGRP || defined BB_PS || defined BB_LS \ - || defined BB_TAR || defined BB_ID || defined BB_LOGGER \ - || defined BB_LOGNAME || defined BB_WHOAMI - -/* This parses entries in /etc/passwd and /etc/group. This is desirable - * for BusyBox, since we want to avoid using the glibc NSS stuff, which - * increases target size and is often not needed or wanted for embedded - * systems. - * - * /etc/passwd entries look like this: - * root:x:0:0:root:/root:/bin/bash - * and /etc/group entries look like this: - * root:x:0: - * - * This uses buf as storage to hold things. - * - */ -unsigned long my_getid(const char *filename, char *name, long id, long *gid) -{ - FILE *file; - char *rname, *start, *end, buf[128]; - long rid; - long rgid = 0; - - file = fopen(filename, "r"); - if (file == NULL) { - /* Do not complain. It is ok for /etc/passwd and - * friends to be missing... */ - return (-1); - } - - while (fgets(buf, 128, file) != NULL) { - if (buf[0] == '#') - continue; - - /* username/group name */ - start = buf; - end = strchr(start, ':'); - if (end == NULL) - continue; - *end = '\0'; - rname = start; - - /* password */ - start = end + 1; - end = strchr(start, ':'); - if (end == NULL) - continue; - - /* uid in passwd, gid in group */ - start = end + 1; - rid = (unsigned long) strtol(start, &end, 10); - if (end == start) - continue; - - /* gid in passwd */ - start = end + 1; - rgid = (unsigned long) strtol(start, &end, 10); - - if (name) { - if (0 == strcmp(rname, name)) { - if (gid) *gid = rgid; - fclose(file); - return (rid); - } - } - if (id != -1 && id == rid) { - strncpy(name, rname, 8); - if (gid) *gid = rgid; - fclose(file); - return (TRUE); - } - } - fclose(file); - return (-1); -} - -/* returns a uid given a username */ -long my_getpwnam(char *name) -{ - return my_getid("/etc/passwd", name, -1, NULL); -} - -/* returns a gid given a group name */ -long my_getgrnam(char *name) -{ - return my_getid("/etc/group", name, -1, NULL); -} - -/* gets a username given a uid */ -void my_getpwuid(char *name, long uid) -{ - my_getid("/etc/passwd", name, uid, NULL); -} - -/* gets a groupname given a gid */ -void my_getgrgid(char *group, long gid) -{ - my_getid("/etc/group", group, gid, NULL); -} - -/* gets a gid given a user name */ -long my_getpwnamegid(char *name) -{ - long gid; - my_getid("/etc/passwd", name, -1, &gid); - return gid; -} - -#endif - /* BB_CHMOD_CHOWN_CHGRP || BB_PS || BB_LS || BB_TAR \ - || BB_ID || BB_LOGGER || BB_LOGNAME || BB_WHOAMI */ - - -#if (defined BB_CHVT) || (defined BB_DEALLOCVT) || (defined BB_SETKEYCODES) - -/* From <linux/kd.h> */ -#define KDGKBTYPE 0x4B33 /* get keyboard type */ -#define KB_84 0x01 -#define KB_101 0x02 /* this is what we always answer */ - -int is_a_console(int fd) -{ - char arg; - - arg = 0; - return (ioctl(fd, KDGKBTYPE, &arg) == 0 - && ((arg == KB_101) || (arg == KB_84))); -} - -static int open_a_console(char *fnam) -{ - int fd; - - /* try read-only */ - fd = open(fnam, O_RDWR); - - /* if failed, try read-only */ - if (fd < 0 && errno == EACCES) - fd = open(fnam, O_RDONLY); - - /* if failed, try write-only */ - if (fd < 0 && errno == EACCES) - fd = open(fnam, O_WRONLY); - - /* if failed, fail */ - if (fd < 0) - return -1; - - /* if not a console, fail */ - if (!is_a_console(fd)) { - close(fd); - return -1; - } - - /* success */ - return fd; -} - -/* - * Get an fd for use with kbd/console ioctls. - * We try several things because opening /dev/console will fail - * if someone else used X (which does a chown on /dev/console). - * - * if tty_name is non-NULL, try this one instead. - */ - -int get_console_fd(char *tty_name) -{ - int fd; - - if (tty_name) { - if (-1 == (fd = open_a_console(tty_name))) - return -1; - else - return fd; - } - - fd = open_a_console("/dev/tty"); - if (fd >= 0) - return fd; - - fd = open_a_console("/dev/tty0"); - if (fd >= 0) - return fd; - - fd = open_a_console("/dev/console"); - if (fd >= 0) - return fd; - - for (fd = 0; fd < 3; fd++) - if (is_a_console(fd)) - return fd; - - errorMsg("Couldnt get a file descriptor referring to the console\n"); - return -1; /* total failure */ -} - - -#endif /* BB_CHVT || BB_DEALLOCVT || BB_SETKEYCODES */ - - -#if defined BB_FIND || defined BB_INSMOD -/* - * Routine to see if a text string is matched by a wildcard pattern. - * Returns TRUE if the text is matched, or FALSE if it is not matched - * or if the pattern is invalid. - * * matches zero or more characters - * ? matches a single character - * [abc] matches 'a', 'b' or 'c' - * \c quotes character c - * Adapted from code written by Ingo Wilken, and - * then taken from sash, Copyright (c) 1999 by David I. Bell - * Permission is granted to use, distribute, or modify this source, - * provided that this copyright notice remains intact. - * Permission to distribute this code under the GPL has been granted. - */ -extern int check_wildcard_match(const char *text, const char *pattern) -{ - const char *retryPat; - const char *retryText; - int ch; - int found; - int len; - - retryPat = NULL; - retryText = NULL; - - while (*text || *pattern) { - ch = *pattern++; - - switch (ch) { - case '*': - retryPat = pattern; - retryText = text; - break; - - case '[': - found = FALSE; - - while ((ch = *pattern++) != ']') { - if (ch == '\\') - ch = *pattern++; - - if (ch == '\0') - return FALSE; - - if (*text == ch) - found = TRUE; - } - len=strlen(text); - if (found == FALSE && len!=0) { - return FALSE; - } - if (found == TRUE) { - if (strlen(pattern)==0 && len==1) { - return TRUE; - } - if (len!=0) { - text++; - continue; - } - } - - /* fall into next case */ - - case '?': - if (*text++ == '\0') - return FALSE; - - break; - - case '\\': - ch = *pattern++; - - if (ch == '\0') - return FALSE; - - /* fall into next case */ - - default: - if (*text == ch) { - if (*text) - text++; - break; - } - - if (*text) { - pattern = retryPat; - text = ++retryText; - break; - } - - return FALSE; - } - - if (pattern == NULL) - return FALSE; - } - - return TRUE; -} -#endif /* BB_FIND || BB_INSMOD */ - - - - -#if defined BB_DF || defined BB_MTAB -/* - * Given a block device, find the mount table entry if that block device - * is mounted. - * - * Given any other file (or directory), find the mount table entry for its - * filesystem. - */ -extern struct mntent *findMountPoint(const char *name, const char *table) -{ - struct stat s; - dev_t mountDevice; - FILE *mountTable; - struct mntent *mountEntry; - - if (stat(name, &s) != 0) - return 0; - - if ((s.st_mode & S_IFMT) == S_IFBLK) - mountDevice = s.st_rdev; - else - mountDevice = s.st_dev; - - - if ((mountTable = setmntent(table, "r")) == 0) - return 0; - - while ((mountEntry = getmntent(mountTable)) != 0) { - if (strcmp(name, mountEntry->mnt_dir) == 0 - || strcmp(name, mountEntry->mnt_fsname) == 0) /* String match. */ - break; - if (stat(mountEntry->mnt_fsname, &s) == 0 && s.st_rdev == mountDevice) /* Match the device. */ - break; - if (stat(mountEntry->mnt_dir, &s) == 0 && s.st_dev == mountDevice) /* Match the directory's mount point. */ - break; - } - endmntent(mountTable); - return mountEntry; -} -#endif /* BB_DF || BB_MTAB */ - - - -#if defined BB_DD || defined BB_TAIL -/* - * Read a number with a possible multiplier. - * Returns -1 if the number format is illegal. - */ -extern long getNum(const char *cp) -{ - long value; - - if (!isDecimal(*cp)) - return -1; - - value = 0; - - while (isDecimal(*cp)) - value = value * 10 + *cp++ - '0'; - - switch (*cp++) { - case 'M': - case 'm': /* `tail' uses it traditionally */ - value *= 1048576; - break; - - case 'k': - value *= 1024; - break; - - case 'b': - value *= 512; - break; - - case 'w': - value *= 2; - break; - - case '\0': - return value; - - default: - return -1; - } - - if (*cp) - return -1; - - return value; -} -#endif /* BB_DD || BB_TAIL */ - - -#if defined BB_INIT || defined BB_SYSLOGD -/* try to open up the specified device */ -extern int device_open(char *device, int mode) -{ - int m, f, fd = -1; - - m = mode | O_NONBLOCK; - - /* Retry up to 5 times */ - for (f = 0; f < 5; f++) - if ((fd = open(device, m, 0600)) >= 0) - break; - if (fd < 0) - return fd; - /* Reset original flags. */ - if (m != mode) - fcntl(fd, F_SETFL, mode); - return fd; -} -#endif /* BB_INIT BB_SYSLOGD */ - - -#if defined BB_KILLALL || ( defined BB_FEATURE_LINUXRC && ( defined BB_HALT || defined BB_REBOOT || defined BB_POWEROFF )) -#ifdef BB_FEATURE_USE_DEVPS_PATCH -#include <linux/devps.h> /* For Erik's nifty devps device driver */ -#endif - -#if defined BB_FEATURE_USE_DEVPS_PATCH -/* findPidByName() - * - * This finds the pid of the specified process, - * by using the /dev/ps device driver. - * - * Returns a list of all matching PIDs - */ -extern pid_t* findPidByName( char* pidName) -{ - int fd, i, j; - char device[] = "/dev/ps"; - pid_t num_pids; - pid_t* pid_array = NULL; - pid_t* pidList=NULL; - - /* open device */ - fd = open(device, O_RDONLY); - if (fd < 0) - fatalError( "open failed for `%s': %s\n", device, strerror (errno)); - - /* Find out how many processes there are */ - if (ioctl (fd, DEVPS_GET_NUM_PIDS, &num_pids)<0) - fatalError( "\nDEVPS_GET_PID_LIST: %s\n", strerror (errno)); - - /* Allocate some memory -- grab a few extras just in case - * some new processes start up while we wait. The kernel will - * just ignore any extras if we give it too many, and will trunc. - * the list if we give it too few. */ - pid_array = (pid_t*) xcalloc( num_pids+10, sizeof(pid_t)); - pid_array[0] = num_pids+10; - - /* Now grab the pid list */ - if (ioctl (fd, DEVPS_GET_PID_LIST, pid_array)<0) - fatalError( "\nDEVPS_GET_PID_LIST: %s\n", strerror (errno)); - - /* Now search for a match */ - for (i=1, j=0; i<pid_array[0] ; i++) { - char* p; - struct pid_info info; - - info.pid = pid_array[i]; - if (ioctl (fd, DEVPS_GET_PID_INFO, &info)<0) - fatalError( "\nDEVPS_GET_PID_INFO: %s\n", strerror (errno)); - - /* Make sure we only match on the process name */ - p=info.command_line+1; - while ((*p != 0) && !isspace(*(p)) && (*(p-1) != '\\')) { - (p)++; - } - if (isspace(*(p))) - *p='\0'; - - if ((strstr(info.command_line, pidName) != NULL) - && (strlen(pidName) == strlen(info.command_line))) { - pidList=xrealloc( pidList, sizeof(pid_t) * (j+2)); - pidList[j++]=info.pid; - } - } - if (pidList) - pidList[j]=0; - - /* Free memory */ - free( pid_array); - - /* close device */ - if (close (fd) != 0) - fatalError( "close failed for `%s': %s\n",device, strerror (errno)); - - return pidList; -} -#else /* BB_FEATURE_USE_DEVPS_PATCH */ -#if ! defined BB_FEATURE_USE_PROCFS -#error Sorry, I depend on the /proc filesystem right now. -#endif - -/* findPidByName() - * - * This finds the pid of the specified process. - * Currently, it's implemented by rummaging through - * the proc filesystem. - * - * Returns a list of all matching PIDs - */ -extern pid_t* findPidByName( char* pidName) -{ - DIR *dir; - struct dirent *next; - pid_t* pidList=NULL; - int i=0; - - dir = opendir("/proc"); - if (!dir) - fatalError( "Cannot open /proc: %s\n", strerror (errno)); - - while ((next = readdir(dir)) != NULL) { - FILE *status; - char filename[256]; - char buffer[256]; - - /* If it isn't a number, we don't want it */ - if (!isdigit(*next->d_name)) - continue; - - sprintf(filename, "/proc/%s/cmdline", next->d_name); - status = fopen(filename, "r"); - if (!status) { - continue; - } - fgets(buffer, 256, status); - fclose(status); - - if (strstr(get_last_path_component(buffer), pidName) != NULL) { - pidList=xrealloc( pidList, sizeof(pid_t) * (i+2)); - pidList[i++]=strtol(next->d_name, NULL, 0); - } - } - - if (pidList) - pidList[i]=0; - return pidList; -} -#endif /* BB_FEATURE_USE_DEVPS_PATCH */ -#endif /* BB_KILLALL || ( BB_FEATURE_LINUXRC && ( BB_HALT || BB_REBOOT || BB_POWEROFF )) */ - -#ifndef DMALLOC -/* this should really be farmed out to libbusybox.a */ -extern void *xmalloc(size_t size) -{ - void *ptr = malloc(size); - - if (!ptr) - fatalError("memory_exhausted"); - return ptr; -} - -extern void *xrealloc(void *old, size_t size) -{ - void *ptr; - if (!size) - size = 1; - ptr = realloc(old, size); - if (!ptr) - fatalError("memory_exhausted"); - return ptr; -} - -extern void *xcalloc(size_t nmemb, size_t size) -{ - void *ptr = calloc(nmemb, size); - if (!ptr) - fatalError("memory_exhausted"); - return ptr; -} -#endif - -#if defined BB_FEATURE_NFSMOUNT || defined BB_SH || defined BB_LS -# ifndef DMALLOC -extern char * xstrdup (const char *s) { - char *t; - - if (s == NULL) - return NULL; - - t = strdup (s); - - if (t == NULL) - fatalError("memory_exhausted"); - - return t; -} -# endif -#endif - -#if defined BB_FEATURE_NFSMOUNT -extern char * xstrndup (const char *s, int n) { - char *t; - - if (s == NULL) - fatalError("xstrndup bug"); - - t = xmalloc(n+1); - strncpy(t,s,n); - t[n] = 0; - - return t; -} -#endif - - -#if (__GLIBC__ < 2) && (defined BB_SYSLOGD || defined BB_INIT) -extern int vdprintf(int d, const char *format, va_list ap) -{ - char buf[BUF_SIZE]; - int len; - - len = vsprintf(buf, format, ap); - return write(d, buf, len); -} -#endif /* BB_SYSLOGD */ - - -#if defined BB_FEATURE_MOUNT_LOOP -#include <fcntl.h> -#include "loop.h" /* Pull in loop device support */ - -extern int del_loop(const char *device) -{ - int fd; - - if ((fd = open(device, O_RDONLY)) < 0) { - perror(device); - return (FALSE); - } - if (ioctl(fd, LOOP_CLR_FD, 0) < 0) { - perror("ioctl: LOOP_CLR_FD"); - return (FALSE); - } - close(fd); - return (TRUE); -} - -extern int set_loop(const char *device, const char *file, int offset, - int *loopro) -{ - struct loop_info loopinfo; - int fd, ffd, mode; - - mode = *loopro ? O_RDONLY : O_RDWR; - if ((ffd = open(file, mode)) < 0 && !*loopro - && (errno != EROFS || (ffd = open(file, mode = O_RDONLY)) < 0)) { - perror(file); - return 1; - } - if ((fd = open(device, mode)) < 0) { - close(ffd); - perror(device); - return 1; - } - *loopro = (mode == O_RDONLY); - - memset(&loopinfo, 0, sizeof(loopinfo)); - strncpy(loopinfo.lo_name, file, LO_NAME_SIZE); - loopinfo.lo_name[LO_NAME_SIZE - 1] = 0; - - loopinfo.lo_offset = offset; - - loopinfo.lo_encrypt_key_size = 0; - if (ioctl(fd, LOOP_SET_FD, ffd) < 0) { - perror("ioctl: LOOP_SET_FD"); - close(fd); - close(ffd); - return 1; - } - if (ioctl(fd, LOOP_SET_STATUS, &loopinfo) < 0) { - (void) ioctl(fd, LOOP_CLR_FD, 0); - perror("ioctl: LOOP_SET_STATUS"); - close(fd); - close(ffd); - return 1; - } - close(fd); - close(ffd); - return 0; -} - -extern char *find_unused_loop_device(void) -{ - char dev[20]; - int i, fd; - struct stat statbuf; - struct loop_info loopinfo; - - for (i = 0; i <= 7; i++) { - sprintf(dev, "/dev/loop%d", i); - if (stat(dev, &statbuf) == 0 && S_ISBLK(statbuf.st_mode)) { - if ((fd = open(dev, O_RDONLY)) >= 0) { - if (ioctl(fd, LOOP_GET_STATUS, &loopinfo) == -1) { - if (errno == ENXIO) { /* probably free */ - close(fd); - return strdup(dev); - } - } - close(fd); - } - } - } - return NULL; -} -#endif /* BB_FEATURE_MOUNT_LOOP */ - -#if defined BB_MOUNT || defined BB_DF || ( defined BB_UMOUNT && ! defined BB_MTAB) -extern int find_real_root_device_name(char* name) -{ - DIR *dir; - struct dirent *entry; - struct stat statBuf, rootStat; - char fileName[BUFSIZ]; - - if (stat("/", &rootStat) != 0) { - errorMsg("could not stat '/'\n"); - return( FALSE); - } - - dir = opendir("/dev"); - if (!dir) { - errorMsg("could not open '/dev'\n"); - return( FALSE); - } - - while((entry = readdir(dir)) != NULL) { - - /* Must skip ".." since that is "/", and so we - * would get a false positive on ".." */ - if (strcmp(entry->d_name, "..") == 0) - continue; - - snprintf( fileName, strlen(name)+1, "/dev/%s", entry->d_name); - - if (stat(fileName, &statBuf) != 0) - continue; - /* Some char devices have the same dev_t as block - * devices, so make sure this is a block device */ - if (! S_ISBLK(statBuf.st_mode)) - continue; - if (statBuf.st_rdev == rootStat.st_rdev) { - strcpy(name, fileName); - return ( TRUE); - } - } - - return( FALSE); -} -#endif - - -/* get_line_from_file() - This function reads an entire line from a text file - * up to a newline. It returns a malloc'ed char * which must be stored and - * free'ed by the caller. */ -extern char *get_line_from_file(FILE *file) -{ - static const int GROWBY = 80; /* how large we will grow strings by */ - - int ch; - int idx = 0; - char *linebuf = NULL; - int linebufsz = 0; - - while (1) { - ch = fgetc(file); - if (ch == EOF) - break; - /* grow the line buffer as necessary */ - while (idx > linebufsz-2) - linebuf = xrealloc(linebuf, linebufsz += GROWBY); - linebuf[idx++] = (char)ch; - if ((char)ch == '\n') - break; - } - - if (idx == 0) - return NULL; - - linebuf[idx] = 0; - return linebuf; -} - -#if defined BB_CAT -extern void print_file(FILE *file) -{ - int c; - - while ((c = getc(file)) != EOF) - putc(c, stdout); - fclose(file); - fflush(stdout); -} - -extern int print_file_by_name(char *filename) -{ - FILE *file; - file = fopen(filename, "r"); - if (file == NULL) { - return FALSE; - } - print_file(file); - return TRUE; -} -#endif /* BB_CAT || BB_LSMOD */ - -#if defined BB_ECHO || defined BB_TR -char process_escape_sequence(char **ptr) -{ - char c; - - switch (c = *(*ptr)++) { - case 'a': - c = '\a'; - break; - case 'b': - c = '\b'; - break; - case 'f': - c = '\f'; - break; - case 'n': - c = '\n'; - break; - case 't': - c = '\t'; - break; - case 'v': - c = '\v'; - break; - case '\\': - c = '\\'; - break; - case '0': case '1': case '2': case '3': - case '4': case '5': case '6': case '7': - c -= '0'; - if ('0' <= **ptr && **ptr <= '7') { - c = c * 8 + (*(*ptr)++ - '0'); - if ('0' <= **ptr && **ptr <= '7') - c = c * 8 + (*(*ptr)++ - '0'); - } - break; - default: - (*ptr)--; - c = '\\'; - break; - } - return c; -} -#endif - -#if defined BB_BASENAME || defined BB_LN || defined BB_SH -char *get_last_path_component(char *path) -{ - char *s=path+strlen(path)-1; - - /* strip trailing slashes */ - while (s && *s == '/') { - *s-- = '\0'; - } - - /* find last component */ - s = strrchr(path, '/'); - if (s==NULL) return path; - else return s+1; -} -#endif - -#if defined BB_GREP || defined BB_SED -void xregcomp(regex_t *preg, const char *regex, int cflags) -{ - int ret; - if ((ret = regcomp(preg, regex, cflags)) != 0) { - int errmsgsz = regerror(ret, preg, NULL, 0); - char *errmsg = xmalloc(errmsgsz); - regerror(ret, preg, errmsg, errmsgsz); - fatalError("bb_regcomp: %s\n", errmsg); - } -} -#endif - -/* END CODE */ -/* -Local Variables: -c-file-style: "linux" -c-basic-offset: 4 -tab-width: 4 -End: -*/ diff --git a/mdk-stage1/insmod-modutils/Makefile b/mdk-stage1/insmod-modutils/Makefile deleted file mode 100644 index 48508ba1f..000000000 --- a/mdk-stage1/insmod-modutils/Makefile +++ /dev/null @@ -1,59 +0,0 @@ - #****************************************************************************** - # - # insmod from modutils (generic) - # - # $Id$ - # - # Copyright 1996, 1997 Linux International. - # - #***************************************************************************** - -top_dir = .. - -include $(top_dir)/Makefile.common - - -INCS = -I./include - -TAINT_URL = http://www.tux.org/lkml/\#export-tainted - -DEFS = -Wno-error -D_GNU_SOURCE \ - -DELF_MACHINE_H='"elf_$(ARCH).h"' -DARCH_$(ARCH) \ - -DTAINT_URL='"$(TAINT_URL)"' - - -DIRS = util obj - -all: dirs insmod libinsmod.a - -dirs: - @for n in . $(DIRS); do \ - [ "$$n" = "." ] || make -C $$n ;\ - done - -clean: - @for n in $(DIRS); do \ - (cd $$n; make clean) \ - done - rm -rf t *.o insmod libinsmod.a - - -insmod: insmod-frontend.o insmod.o ./util/libutil-STANDALONE.a ./obj/libobj.a - $(DIET) gcc -o $@ $^ - $(STRIPCMD) $@ - -t/.create_stuff: util/libutil.a obj/libobj.a - rm -rf t - mkdir t - cd t && for e in $^; do ar -x ../$$e; done - touch t/.create_stuff - -libinsmod.a: insmod.o t/.create_stuff - ar cru $@ insmod.o t/* - ranlib $@ - -insmod-frontend.o: insmod-frontend.c insmod.c - $(DIET) gcc $(CFLAGS) $(DEFS) $(INCS) $(INCLUDES) -c insmod-frontend.c - -insmod.o: insmod.c - $(DIET) gcc $(CFLAGS) $(DEFS) $(INCS) $(INCLUDES) -c insmod.c diff --git a/mdk-stage1/insmod-modutils/include/config.h b/mdk-stage1/insmod-modutils/include/config.h deleted file mode 100644 index 3a37b00d4..000000000 --- a/mdk-stage1/insmod-modutils/include/config.h +++ /dev/null @@ -1,108 +0,0 @@ -/* - * Configuration file management - * - * Copyright 1994, 1995, 1996, 1997: - * Jacques Gelinas <jack@solucorp.qc.ca> - * Björn Ekwall <bj0rn@blox.se> February, March 1999 - * - * This file is part of the Linux modutils. - * - * This program is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License as published by the - * Free Software Foundation; either version 2 of the License, or (at your - * option) any later version. - * - * This program is distributed in the hope that it will be useful, but - * WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software Foundation, - * Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. - */ - -#ifndef _CONFIG_H -#define _CONFIG_H - -#include <stdio.h> -#include <sys/utsname.h> - -#define MODUTILS_MACROS "/lib/modutils/macros" -#define ETC_MODULES_CONF "/etc/modules.conf" - -#define EXEC_PRE_INSTALL 0 -#define EXEC_POST_INSTALL 1 -#define EXEC_PRE_REMOVE 2 -#define EXEC_POST_REMOVE 3 -#define EXEC_INSTALL 4 -#define EXEC_REMOVE 5 - -struct PATH_TYPE { - char *type; - char *path; -}; - -struct EXEC_TYPE { - int when; - char *module; - char *cmd; -}; - -typedef struct { - char *name; - GLOB_LIST *opts; - int autoclean; -} OPT_LIST; - -/* config.c */ -extern int flag_autoclean; -extern struct utsname uts_info; -extern char *aliaslist[]; -extern struct PATH_TYPE *modpath; -extern int nmodpath; -extern struct EXEC_TYPE *execs; -extern int nexecs; -extern char *insmod_opt; -extern char *config_file; -extern char *optlist[]; -extern char *prune[]; -extern OPT_LIST *opt_list; -extern OPT_LIST *abovelist; -extern OPT_LIST *belowlist; -extern OPT_LIST *prunelist; -extern OPT_LIST *probe_list; -extern OPT_LIST *probeall_list; -extern OPT_LIST *aliases; -extern time_t config_mtime; -extern int root_check_off; /* Check modules are owned by root? */ - -/* Information about generated files */ -struct gen_files { - char *base; /* xxx in /lib/modules/`uname -r`/modules.xxx */ - char *name; /* name actually used */ - time_t mtime; -}; - -extern struct gen_files gen_file[]; -extern const int gen_file_count; -/* The enum order must match the gen_file initialization order in config.c */ -enum gen_file_enum { - GEN_GENERIC_STRINGFILE, - GEN_PCIMAPFILE, - GEN_ISAPNPMAPFILE, - GEN_USBMAPFILE, - GEN_PARPORTMAPFILE, - GEN_IEEE1394MAPFILE, - GEN_PNPBIOSMAPFILE, - GEN_DEPFILE, -}; - -extern char *persistdir; - -char *fgets_strip(char *buf, int sizebuf, FILE * fin, int *lineno); -int config_read(int all, char *force_ver, char *base_dir, char *conf_file); -GLOB_LIST *config_lstmod(const char *match, const char *type, int first_only); -char *search_module_path(const char *base); - -#endif /* _CONFIG_H */ diff --git a/mdk-stage1/insmod-modutils/include/elf_alpha.h b/mdk-stage1/insmod-modutils/include/elf_alpha.h deleted file mode 100644 index 4202bcc14..000000000 --- a/mdk-stage1/insmod-modutils/include/elf_alpha.h +++ /dev/null @@ -1,9 +0,0 @@ -/* Machine-specific elf macros for the Alpha. */ - -#define ELFCLASSM ELFCLASS64 -#define ELFDATAM ELFDATA2LSB - -#define MATCH_MACHINE(x) (x == EM_ALPHA) - -#define SHT_RELM SHT_RELA -#define Elf64_RelM Elf64_Rela diff --git a/mdk-stage1/insmod-modutils/include/elf_arm.h b/mdk-stage1/insmod-modutils/include/elf_arm.h deleted file mode 100644 index cf04cafe0..000000000 --- a/mdk-stage1/insmod-modutils/include/elf_arm.h +++ /dev/null @@ -1,9 +0,0 @@ -/* Machine-specific elf macros for ARM. */ - -#define ELFCLASSM ELFCLASS32 -#define ELFDATAM ELFDATA2LSB - -#define MATCH_MACHINE(x) (x == EM_ARM) - -#define SHT_RELM SHT_REL -#define Elf32_RelM Elf32_Rel diff --git a/mdk-stage1/insmod-modutils/include/elf_hppa.h b/mdk-stage1/insmod-modutils/include/elf_hppa.h deleted file mode 100644 index 9a1bd34ce..000000000 --- a/mdk-stage1/insmod-modutils/include/elf_hppa.h +++ /dev/null @@ -1,9 +0,0 @@ -/* Machine-specific elf macros for HP-PA. */ - -#define ELFCLASSM ELFCLASS32 -#define ELFDATAM ELFDATA2MSB - -#define MATCH_MACHINE(x) (x == EM_PARISC) - -#define SHT_RELM SHT_RELA -#define Elf32_RelM Elf32_Rela diff --git a/mdk-stage1/insmod-modutils/include/elf_hppa64.h b/mdk-stage1/insmod-modutils/include/elf_hppa64.h deleted file mode 100644 index 05b201aef..000000000 --- a/mdk-stage1/insmod-modutils/include/elf_hppa64.h +++ /dev/null @@ -1,9 +0,0 @@ -/* Machine-specific elf macros for HP-PA64. */ - -#define ELFCLASSM ELFCLASS64 -#define ELFDATAM ELFDATA2MSB - -#define MATCH_MACHINE(x) (x == EM_PARISC) - -#define SHT_RELM SHT_RELA -#define Elf64_RelM Elf64_Rela diff --git a/mdk-stage1/insmod-modutils/include/elf_i386.h b/mdk-stage1/insmod-modutils/include/elf_i386.h deleted file mode 100644 index f5c57d384..000000000 --- a/mdk-stage1/insmod-modutils/include/elf_i386.h +++ /dev/null @@ -1,9 +0,0 @@ -/* Machine-specific elf macros for i386 et al. */ - -#define ELFCLASSM ELFCLASS32 -#define ELFDATAM ELFDATA2LSB - -#define MATCH_MACHINE(x) (x == EM_386) - -#define SHT_RELM SHT_REL -#define Elf32_RelM Elf32_Rel diff --git a/mdk-stage1/insmod-modutils/include/elf_ia64.h b/mdk-stage1/insmod-modutils/include/elf_ia64.h deleted file mode 100644 index b4d902956..000000000 --- a/mdk-stage1/insmod-modutils/include/elf_ia64.h +++ /dev/null @@ -1,9 +0,0 @@ -/* Machine-specific elf macros for ia64. */ - -#define ELFCLASSM ELFCLASS64 -#define ELFDATAM ELFDATA2LSB - -#define MATCH_MACHINE(x) (x == EM_IA_64) - -#define SHT_RELM SHT_RELA -#define Elf64_RelM Elf64_Rela diff --git a/mdk-stage1/insmod-modutils/include/elf_m68k.h b/mdk-stage1/insmod-modutils/include/elf_m68k.h deleted file mode 100644 index c488ba9d1..000000000 --- a/mdk-stage1/insmod-modutils/include/elf_m68k.h +++ /dev/null @@ -1,9 +0,0 @@ -/* Machine-specific elf macros for m68k. */ - -#define ELFCLASSM ELFCLASS32 -#define ELFDATAM ELFDATA2MSB - -#define MATCH_MACHINE(x) (x == EM_68K) - -#define SHT_RELM SHT_RELA -#define Elf32_RelM Elf32_Rela diff --git a/mdk-stage1/insmod-modutils/include/elf_mips.h b/mdk-stage1/insmod-modutils/include/elf_mips.h deleted file mode 100644 index 4b91ddd01..000000000 --- a/mdk-stage1/insmod-modutils/include/elf_mips.h +++ /dev/null @@ -1,23 +0,0 @@ -/* Machine-specific elf macros for MIPS. */ - -#define ELFCLASSM ELFCLASS32 -#ifdef __MIPSEB__ -#define ELFDATAM ELFDATA2MSB -#endif -#ifdef __MIPSEL__ -#define ELFDATAM ELFDATA2LSB -#endif - -/* Account for ELF spec changes. */ -#ifndef EM_MIPS_RS3_LE -#ifdef EM_MIPS_RS4_BE -#define EM_MIPS_RS3_LE EM_MIPS_RS4_BE -#else -#define EM_MIPS_RS3_LE 10 -#endif -#endif /* !EM_MIPS_RS3_LE */ - -#define MATCH_MACHINE(x) (x == EM_MIPS || x == EM_MIPS_RS3_LE) - -#define SHT_RELM SHT_REL -#define Elf32_RelM Elf32_Rel diff --git a/mdk-stage1/insmod-modutils/include/elf_ppc.h b/mdk-stage1/insmod-modutils/include/elf_ppc.h deleted file mode 100644 index b0060ace1..000000000 --- a/mdk-stage1/insmod-modutils/include/elf_ppc.h +++ /dev/null @@ -1,9 +0,0 @@ -/* Machine-specific elf macros for the PowerPC. */ - -#define ELFCLASSM ELFCLASS32 -#define ELFDATAM ELFDATA2MSB - -#define MATCH_MACHINE(x) (x == EM_PPC) - -#define SHT_RELM SHT_RELA -#define Elf32_RelM Elf32_Rela diff --git a/mdk-stage1/insmod-modutils/include/elf_s390.h b/mdk-stage1/insmod-modutils/include/elf_s390.h deleted file mode 100644 index 7a35bde93..000000000 --- a/mdk-stage1/insmod-modutils/include/elf_s390.h +++ /dev/null @@ -1,11 +0,0 @@ -/* Machine-specific elf macros for i386 et al. */ - -#define ELFCLASSM ELFCLASS32 -#define ELFDATAM ELFDATA2MSB - -#define EM_S390_OLD 0xa390 - -#define MATCH_MACHINE(x) (x == EM_S390 || x == EM_S390_OLD) - -#define SHT_RELM SHT_RELA -#define Elf32_RelM Elf32_Rela diff --git a/mdk-stage1/insmod-modutils/include/elf_sparc.h b/mdk-stage1/insmod-modutils/include/elf_sparc.h deleted file mode 100644 index 8903b2654..000000000 --- a/mdk-stage1/insmod-modutils/include/elf_sparc.h +++ /dev/null @@ -1,9 +0,0 @@ -/* Machine-specific elf macros for the Sparc. */ - -#define ELFCLASSM ELFCLASS32 -#define ELFDATAM ELFDATA2MSB - -#define MATCH_MACHINE(x) (x == EM_SPARC) - -#define SHT_RELM SHT_RELA -#define Elf32_RelM Elf32_Rela diff --git a/mdk-stage1/insmod-modutils/include/elf_sparc64.h b/mdk-stage1/insmod-modutils/include/elf_sparc64.h deleted file mode 100644 index 891e0c3d9..000000000 --- a/mdk-stage1/insmod-modutils/include/elf_sparc64.h +++ /dev/null @@ -1,26 +0,0 @@ -/* Machine-specific elf macros for the Sparc. */ - -#define ELFCLASSM ELFCLASS64 -#define ELFDATAM ELFDATA2MSB - -#ifndef EM_SPARCV9 -#define EM_SPARCV9 43 -#endif -#ifndef EM_SPARC64 -#define EM_SPARC64 11 -#endif -#define MATCH_MACHINE(x) ((x) == EM_SPARCV9 || (x) == EM_SPARC64) - -#define SHT_RELM SHT_RELA -#define Elf64_RelM Elf64_Rela - -#ifndef ELF64_R_SYM -#define ELF64_R_SYM(x) ((x) >> 32) -#define ELF64_R_TYPE(x) ((unsigned)(x)) -#endif - -#ifndef ELF64_ST_BIND -#define ELF64_ST_BIND(x) ((x) >> 4) -#define ELF64_ST_TYPE(x) ((x) & 0xf) -#endif - diff --git a/mdk-stage1/insmod-modutils/include/kallsyms.h b/mdk-stage1/insmod-modutils/include/kallsyms.h deleted file mode 100644 index 90bb75f22..000000000 --- a/mdk-stage1/insmod-modutils/include/kallsyms.h +++ /dev/null @@ -1,129 +0,0 @@ -#ifndef MODUTILS_KALLSYMS_H -#define MODUTILS_KALLSYMS_H 1 - -/* kallsyms headers - Copyright 2000 Keith Owens <kaos@ocs.com.au> - - This file is part of the Linux modutils. It is exported to kernel - space so debuggers can access the kallsyms data. - - The kallsyms data contains all the non-stack symbols from a kernel - or a module. The kernel symbols are held between __start___kallsyms - and __stop___kallsyms. The symbols for a module are accessed via - the struct module chain which is based at module_list. - - This program is free software; you can redistribute it and/or modify it - under the terms of the GNU General Public License as published by the - Free Software Foundation; either version 2 of the License, or (at your - option) any later version. - - This program is distributed in the hope that it will be useful, but - WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - General Public License for more details. - - You should have received a copy of the GNU General Public License - along with this program; if not, write to the Free Software Foundation, - Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. - */ - -/* Have to (re)define these ElfW entries here because external kallsyms - * code does not have access to modutils/include/obj.h. This code is - * included from user spaces tools (modutils) and kernel, they need - * different includes. - */ - -#ifndef ELFCLASS32 -#ifdef __KERNEL__ -#include <linux/elf.h> -#else /* __KERNEL__ */ -#include <elf.h> -#endif /* __KERNEL__ */ -#endif /* ELFCLASS32 */ - -#ifndef ELFCLASSM -#define ELFCLASSM ELF_CLASS -#endif - -#ifndef ElfW -# if ELFCLASSM == ELFCLASS32 -# define ElfW(x) Elf32_ ## x -# define ELFW(x) ELF32_ ## x -# else -# define ElfW(x) Elf64_ ## x -# define ELFW(x) ELF64_ ## x -# endif -#endif - -/* Format of data in the kallsyms section. - * Most of the fields are small numbers but the total size and all - * offsets can be large so use the 32/64 bit types for these fields. - * - * Do not use sizeof() on these structures, modutils may be using extra - * fields. Instead use the size fields in the header to access the - * other bits of data. - */ - -struct kallsyms_header { - int size; /* Size of this header */ - ElfW(Word) total_size; /* Total size of kallsyms data */ - int sections; /* Number of section entries */ - ElfW(Off) section_off; /* Offset to first section entry */ - int section_size; /* Size of one section entry */ - int symbols; /* Number of symbol entries */ - ElfW(Off) symbol_off; /* Offset to first symbol entry */ - int symbol_size; /* Size of one symbol entry */ - ElfW(Off) string_off; /* Offset to first string */ - ElfW(Addr) start; /* Start address of first section */ - ElfW(Addr) end; /* End address of last section */ -}; - -struct kallsyms_section { - ElfW(Addr) start; /* Start address of section */ - ElfW(Word) size; /* Size of this section */ - ElfW(Off) name_off; /* Offset to section name */ - ElfW(Word) flags; /* Flags from section */ -}; - -struct kallsyms_symbol { - ElfW(Off) section_off; /* Offset to section that owns this symbol */ - ElfW(Addr) symbol_addr; /* Address of symbol */ - ElfW(Off) name_off; /* Offset to symbol name */ -}; - -#define KALLSYMS_SEC_NAME "__kallsyms" -#define KALLSYMS_IDX 2 /* obj_kallsyms creates kallsyms as section 2 */ - -#define kallsyms_next_sec(h,s) \ - ((s) = (struct kallsyms_section *)((char *)(s) + (h)->section_size)) -#define kallsyms_next_sym(h,s) \ - ((s) = (struct kallsyms_symbol *)((char *)(s) + (h)->symbol_size)) - -int kallsyms_symbol_to_address( - const char *name, /* Name to lookup */ - unsigned long *token, /* Which module to start with */ - const char **mod_name, /* Set to module name or "kernel" */ - unsigned long *mod_start, /* Set to start address of module */ - unsigned long *mod_end, /* Set to end address of module */ - const char **sec_name, /* Set to section name */ - unsigned long *sec_start, /* Set to start address of section */ - unsigned long *sec_end, /* Set to end address of section */ - const char **sym_name, /* Set to full symbol name */ - unsigned long *sym_start, /* Set to start address of symbol */ - unsigned long *sym_end /* Set to end address of symbol */ - ); - -int kallsyms_address_to_symbol( - unsigned long address, /* Address to lookup */ - const char **mod_name, /* Set to module name */ - unsigned long *mod_start, /* Set to start address of module */ - unsigned long *mod_end, /* Set to end address of module */ - const char **sec_name, /* Set to section name */ - unsigned long *sec_start, /* Set to start address of section */ - unsigned long *sec_end, /* Set to end address of section */ - const char **sym_name, /* Set to full symbol name */ - unsigned long *sym_start, /* Set to start address of symbol */ - unsigned long *sym_end /* Set to end address of symbol */ - ); - -#endif /* kallsyms.h */ diff --git a/mdk-stage1/insmod-modutils/include/kerneld.h b/mdk-stage1/insmod-modutils/include/kerneld.h deleted file mode 100644 index f32e34b4a..000000000 --- a/mdk-stage1/insmod-modutils/include/kerneld.h +++ /dev/null @@ -1,44 +0,0 @@ -/* Definitions for the Linux kerneld SYSV IPC interface. - This file was part of the Linux kernel, and so is covered by the GPL. */ - -#ifndef MODUTILS_KERNELD_H -#define MODUTILS_KERNELD_H - -#define KERNELD_SYSTEM 1 -#define KERNELD_REQUEST_MODULE 2 /* "insmod" */ -#define KERNELD_RELEASE_MODULE 3 /* "rmmod" */ -#define KERNELD_DELAYED_RELEASE_MODULE 4 /* "rmmod" */ -#define KERNELD_CANCEL_RELEASE_MODULE 5 /* "rmmod" */ -#define KERNELD_REQUEST_ROUTE 6 /* net/ipv4/route.c */ -#define KERNELD_BLANKER 7 /* drivers/char/console.c */ -#define KERNELD_PNP 8 /* drivers/pnp/kerneld.c */ -#define KERNELD_ARP 256 /* net/ipv4/arp.c */ - -#ifdef NEW_KERNELD_PROTOCOL -# define OLDIPC_KERNELD 00040000 /* old kerneld message channel */ -# define IPC_KERNELD 00140000 /* new kerneld message channel */ -# define KDHDR (sizeof(long) + sizeof(short) + sizeof(short)) -# define NULL_KDHDR 0, 2, 0 -#else /* NEW_KERNELD_PROTOCOL */ -# define IPC_KERNELD 00040000 -# define KDHDR (sizeof(long)) -# define NULL_KDHDR 0 -#endif /* NEW_KERNELD_PROTOCOL */ - -#define KERNELD_MAXCMD 0x7ffeffff -#define KERNELD_MINSEQ 0x7fff0000 /* "commands" legal up to 0x7ffeffff */ -#define KERNELD_WAIT 0x80000000 -#define KERNELD_NOWAIT 0 - -struct kerneld_msg - { - long mtype; - long id; -#ifdef NEW_KERNELD_PROTOCOL - short version; - short pid; -#endif /* NEW_KERNELD_PROTOCOL */ - char text[1]; - }; - -#endif /* kerneld.h */ diff --git a/mdk-stage1/insmod-modutils/include/modstat.h b/mdk-stage1/insmod-modutils/include/modstat.h deleted file mode 100644 index b8a58eeae..000000000 --- a/mdk-stage1/insmod-modutils/include/modstat.h +++ /dev/null @@ -1,55 +0,0 @@ -/* - * For kernel module status and information - * - * Add module_name_list and l_module_name_list. - * Keith Owens <kaos@ocs.com.au> November 1999. - * Björn Ekwall <bj0rn@blox.se> February 1999. - * - * This file is part of the Linux modutils. - * - * This program is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License as published by the - * Free Software Foundation; either version 2 of the License, or (at your - * option) any later version. - * - * This program is distributed in the hope that it will be useful, but - * WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software Foundation, - * Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. - */ -#ifndef _KERNEL_H -#define _KERNEL_H - -#define K_SYMBOLS 1 /* Want info about symbols */ -#define K_INFO 2 /* Want extended module info */ -#define K_REFS 4 /* Want info about references */ - -struct module_stat { - char *name; - unsigned long addr; - unsigned long modstruct; /* COMPAT_2_0! *//* depends on architecture? */ - unsigned long size; - unsigned long flags; - long usecount; - size_t nsyms; - struct module_symbol *syms; - size_t nrefs; - struct module_stat **refs; - unsigned long status; -}; - -extern struct module_stat *module_stat; -extern size_t n_module_stat; -extern char *module_name_list; -extern size_t l_module_name_list; -extern struct module_symbol *ksyms; -extern size_t nksyms; -extern int k_new_syscalls; - -int get_kernel_info(int type); - -#endif /* _KERNEL_H */ diff --git a/mdk-stage1/insmod-modutils/include/module.h b/mdk-stage1/insmod-modutils/include/module.h deleted file mode 100644 index ae8224f8a..000000000 --- a/mdk-stage1/insmod-modutils/include/module.h +++ /dev/null @@ -1,217 +0,0 @@ -#ifndef MODUTILS_MODULE_H -#define MODUTILS_MODULE_H 1 - -/* Definitions for the Linux module syscall interface. - Copyright 1996, 1997 Linux International. - - Contributed by Richard Henderson <rth@tamu.edu> - - This file is part of the Linux modutils. - - This program is free software; you can redistribute it and/or modify it - under the terms of the GNU General Public License as published by the - Free Software Foundation; either version 2 of the License, or (at your - option) any later version. - - This program is distributed in the hope that it will be useful, but - WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - General Public License for more details. - - You should have received a copy of the GNU General Public License - along with this program; if not, write to the Free Software Foundation, - Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ - - -/* This file contains the structures used by the 2.0 and 2.1 kernels. - We do not use the kernel headers directly because we do not wish - to be dependant on a particular kernel version to compile insmod. */ - - -/*======================================================================*/ -/* The structures used by Linux 2.0. */ - -/* The symbol format used by get_kernel_syms(2). */ -struct old_kernel_sym -{ - unsigned long value; - char name[60]; -}; - -struct old_module_ref -{ - unsigned long module; /* kernel addresses */ - unsigned long next; -}; - -struct old_module_symbol -{ - unsigned long addr; - unsigned long name; -}; - -struct old_symbol_table -{ - int size; /* total, including string table!!! */ - int n_symbols; - int n_refs; - struct old_module_symbol symbol[0]; /* actual size defined by n_symbols */ - struct old_module_ref ref[0]; /* actual size defined by n_refs */ -}; - -struct old_mod_routines -{ - unsigned long init; - unsigned long cleanup; -}; - -struct old_module -{ - unsigned long next; - unsigned long ref; /* the list of modules that refer to me */ - unsigned long symtab; - unsigned long name; - int size; /* size of module in pages */ - unsigned long addr; /* address of module */ - int state; - unsigned long cleanup; /* cleanup routine */ -}; - -/* Sent to init_module(2) or'ed into the code size parameter. */ -#define OLD_MOD_AUTOCLEAN 0x40000000 /* big enough, but no sign problems... */ - -int get_kernel_syms(struct old_kernel_sym *); -int old_sys_init_module(const char *name, char *code, unsigned codesize, - struct old_mod_routines *, struct old_symbol_table *); - -/*======================================================================*/ -/* For sizeof() which are related to the module platform and not to the - environment isnmod is running in, use sizeof_xx instead of sizeof(xx). */ - -#define tgt_sizeof_char sizeof(char) -#define tgt_sizeof_short sizeof(short) -#define tgt_sizeof_int sizeof(int) -#define tgt_sizeof_long sizeof(long) -#define tgt_sizeof_char_p sizeof(char *) -#define tgt_sizeof_void_p sizeof(void *) -#define tgt_long long -#define tgt_long_fmt "l" - -/* This assumes that long long on a 32 bit system is equivalent to long on the - * equivalent 64 bit system. Also that void and char pointers are 8 bytes on - * all 64 bit systems. Add per system tweaks if it ever becomes necessary. - */ -#if defined(COMMON_3264) && defined(ONLY_64) -#undef tgt_long -#undef tgt_long_fmt -#undef tgt_sizeof_long -#undef tgt_sizeof_char_p -#undef tgt_sizeof_void_p -#define tgt_long long long -#define tgt_long_fmt "ll" -#define tgt_sizeof_long 8 -#define tgt_sizeof_char_p 8 -#define tgt_sizeof_void_p 8 -#endif - -/*======================================================================*/ -/* The structures used in Linux 2.1 onwards. */ - -/* Note: module_symbol does not use tgt_long intentionally */ -struct module_symbol -{ - unsigned long value; - unsigned long name; -}; - -struct module_ref -{ - unsigned tgt_long dep; /* kernel addresses */ - unsigned tgt_long ref; - unsigned tgt_long next_ref; -}; - -struct module -{ - unsigned tgt_long size_of_struct; /* == sizeof(module) */ - unsigned tgt_long next; - unsigned tgt_long name; - unsigned tgt_long size; - - tgt_long usecount; - unsigned tgt_long flags; /* AUTOCLEAN et al */ - - unsigned nsyms; - unsigned ndeps; - - unsigned tgt_long syms; - unsigned tgt_long deps; - unsigned tgt_long refs; - unsigned tgt_long init; - unsigned tgt_long cleanup; - unsigned tgt_long ex_table_start; - unsigned tgt_long ex_table_end; -#ifdef __alpha__ - unsigned tgt_long gp; -#endif - /* Everything after here is extension. */ - unsigned tgt_long read_start; /* Read data from existing module */ - unsigned tgt_long read_end; - unsigned tgt_long can_unload; - unsigned tgt_long runsize; - unsigned tgt_long kallsyms_start; - unsigned tgt_long kallsyms_end; - unsigned tgt_long archdata_start; - unsigned tgt_long archdata_end; - unsigned tgt_long kernel_data; -}; - -struct module_info -{ - unsigned long addr; - unsigned long size; - unsigned long flags; - long usecount; -}; - -/* Bits of module.flags. */ -#define NEW_MOD_RUNNING 1 -#define NEW_MOD_DELETED 2 -#define NEW_MOD_AUTOCLEAN 4 -#define NEW_MOD_VISITED 8 -#define NEW_MOD_USED_ONCE 16 -#define NEW_MOD_INITIALIZING 64 - -int sys_init_module(const char *name, const struct module *); -int query_module(const char *name, int which, void *buf, size_t bufsize, - size_t *ret); - -/* Values for query_module's which. */ - -#define QM_MODULES 1 -#define QM_DEPS 2 -#define QM_REFS 3 -#define QM_SYMBOLS 4 -#define QM_INFO 5 - -/*======================================================================*/ -/* The system calls unchanged between 2.0 and 2.1. */ - -unsigned long create_module(const char *, size_t); -int delete_module(const char *); - -/* In safe mode the last parameter is forced to be a module name and meta - * expansion is not allowed on that name. - */ -extern unsigned int safemode; - -/*======================================================================*/ -/* Tainted kernel information. This must match include/linux/kernel.h */ -/* and kernel/panic.c. */ - -#define TAINT_FILENAME "/proc/sys/kernel/tainted" -#define TAINT_PROPRIETORY_MODULE (1<<0) -#define TAINT_FORCED_MODULE (1<<1) -#define TAINT_UNSAFE_SMP (1<<2) - -#endif /* module.h */ diff --git a/mdk-stage1/insmod-modutils/include/obj.h b/mdk-stage1/insmod-modutils/include/obj.h deleted file mode 100644 index de346b16a..000000000 --- a/mdk-stage1/insmod-modutils/include/obj.h +++ /dev/null @@ -1,298 +0,0 @@ -#ifndef MODUTILS_OBJ_H -#define MODUTILS_OBJ_H 1 - -/* Elf object file loading and relocation routines. - Copyright 1996, 1997 Linux International. - - Contributed by Richard Henderson <rth@tamu.edu> - obj_free() added by Björn Ekwall <bj0rn@blox.se> March 1999 - - This file is part of the Linux modutils. - - This program is free software; you can redistribute it and/or modify it - under the terms of the GNU General Public License as published by the - Free Software Foundation; either version 2 of the License, or (at your - option) any later version. - - This program is distributed in the hope that it will be useful, but - WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - General Public License for more details. - - You should have received a copy of the GNU General Public License - along with this program; if not, write to the Free Software Foundation, - Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ - - -/* The relocatable object is manipulated using elfin types. */ - -#include <stdio.h> -#include <sys/types.h> -#include <elf.h> -#include ELF_MACHINE_H -#include "module.h" - -#ifndef ElfW -# if ELFCLASSM == ELFCLASS32 -# define ElfW(x) Elf32_ ## x -# define ELFW(x) ELF32_ ## x -# else -# define ElfW(x) Elf64_ ## x -# define ELFW(x) ELF64_ ## x -# endif -#endif - -#if defined(COMMON_3264) && defined(ONLY_32) -# define ObjW(x) obj32_ ## x -#else -# if defined(COMMON_3264) && defined(ONLY_64) -# define ObjW(x) obj64_ ## x -# else -# define ObjW(x) obj_ ## x -# endif -#endif - -/* For some reason this is missing from lib5. */ -#ifndef ELF32_ST_INFO -# define ELF32_ST_INFO(bind, type) (((bind) << 4) + ((type) & 0xf)) -#endif - -#ifndef ELF64_ST_INFO -# define ELF64_ST_INFO(bind, type) (((bind) << 4) + ((type) & 0xf)) -#endif - -struct obj_string_patch_struct; -struct obj_symbol_patch_struct; - -struct obj_section -{ - ElfW(Shdr) header; - const char *name; - char *contents; - struct obj_section *load_next; - int idx; -}; - -struct obj_symbol -{ - struct obj_symbol *next; /* hash table link */ - const char *name; - tgt_long value; - unsigned long size; - int secidx; /* the defining section index/module */ - int info; - int ksymidx; /* for export to the kernel symtab */ - int r_type; /* relocation type */ -}; - -/* Hardcode the hash table size. We shouldn't be needing so many - symbols that we begin to degrade performance, and we get a big win - by giving the compiler a constant divisor. */ - -#define HASH_BUCKETS 521 - -struct obj_file -{ - ElfW(Ehdr) header; - ElfW(Addr) baseaddr; - struct obj_section **sections; - struct obj_section *load_order; - struct obj_section **load_order_search_start; - struct obj_string_patch_struct *string_patches; - struct obj_symbol_patch_struct *symbol_patches; - int (*symbol_cmp)(const char *, const char *); - unsigned long (*symbol_hash)(const char *); - unsigned long local_symtab_size; - struct obj_symbol **local_symtab; - struct obj_symbol *symtab[HASH_BUCKETS]; - const char *filename; - char *persist; -}; - -enum obj_reloc -{ - obj_reloc_ok, - obj_reloc_overflow, - obj_reloc_dangerous, - obj_reloc_unhandled, - obj_reloc_constant_gp -}; - -struct obj_string_patch_struct -{ - struct obj_string_patch_struct *next; - int reloc_secidx; - ElfW(Addr) reloc_offset; - ElfW(Addr) string_offset; -}; - -struct obj_symbol_patch_struct -{ - struct obj_symbol_patch_struct *next; - int reloc_secidx; - ElfW(Addr) reloc_offset; - struct obj_symbol *sym; -}; - - -/* Generic object manipulation routines. */ - -#define obj_elf_hash ObjW(elf_hash) -#define obj_elf_hash_n ObjW(elf_hash_n) -#define obj_add_symbol ObjW(add_symbol) -#define obj_find_symbol ObjW(find_symbol) -#define obj_symbol_final_value ObjW(symbol_final_value) -#define obj_set_symbol_compare ObjW(set_symbol_compare) -#define obj_find_section ObjW(find_section) -#define obj_insert_section_load_order ObjW(insert_section_load_order) -#define obj_create_alloced_section ObjW(create_alloced_section) -#define obj_create_alloced_section_first \ - ObjW(create_alloced_section_first) -#define obj_extend_section ObjW(extend_section) -#define obj_string_patch ObjW(string_patch) -#define obj_symbol_patch ObjW(symbol_patch) -#define obj_check_undefineds ObjW(check_undefineds) -#define obj_clear_undefineds ObjW(clear_undefineds) -#define obj_allocate_commons ObjW(allocate_commons) -#define obj_load_size ObjW(load_size) -#define obj_relocate ObjW(relocate) -#define obj_load ObjW(load) -#define obj_free ObjW(free) -#define obj_create_image ObjW(create_image) -#define obj_addr_to_native_ptr ObjW(addr_to_native_ptr) -#define obj_native_ptr_to_addr ObjW(native_ptr_to_addr) -#define obj_kallsyms ObjW(kallsyms) -#define obj_gpl_license ObjW(gpl_license) -#define arch_new_file ObjW(arch_new_file) -#define arch_new_section ObjW(arch_new_section) -#define arch_new_symbol ObjW(arch_new_symbol) -#define arch_apply_relocation ObjW(arch_apply_relocation) -#define arch_create_got ObjW(arch_create_got) -#define arch_init_module ObjW(arch_init_module) -#define arch_load_proc_section ObjW(arch_load_proc_section) -#define arch_finalize_section_address ObjW(arch_finalize_section_address) -#define arch_archdata ObjW(arch_archdata) - -unsigned long obj_elf_hash (const char *); - -unsigned long obj_elf_hash_n (const char *, unsigned long len); - -struct obj_symbol *obj_add_symbol (struct obj_file *f, const char *name, - unsigned long symidx, int info, int secidx, - ElfW(Addr) value, unsigned long size); - -struct obj_symbol *obj_find_symbol (struct obj_file *f, - const char *name); - -ElfW(Addr) obj_symbol_final_value (struct obj_file *f, - struct obj_symbol *sym); - -void obj_set_symbol_compare (struct obj_file *f, - int (*cmp)(const char *, const char *), - unsigned long (*hash)(const char *)); - -struct obj_section *obj_find_section (struct obj_file *f, - const char *name); - -void obj_insert_section_load_order (struct obj_file *f, - struct obj_section *sec); - -struct obj_section *obj_create_alloced_section (struct obj_file *f, - const char *name, - unsigned long align, - unsigned long size, - unsigned long flags); - -struct obj_section *obj_create_alloced_section_first (struct obj_file *f, - const char *name, - unsigned long align, - unsigned long size); - -void *obj_extend_section (struct obj_section *sec, unsigned long more); - -int obj_string_patch (struct obj_file *f, int secidx, ElfW(Addr) offset, - const char *string); - -int obj_symbol_patch (struct obj_file *f, int secidx, ElfW(Addr) offset, - struct obj_symbol *sym); - -int obj_check_undefineds (struct obj_file *f, int quiet); - -void obj_clear_undefineds (struct obj_file *f); - -void obj_allocate_commons (struct obj_file *f); - -unsigned long obj_load_size (struct obj_file *f); - -int obj_relocate (struct obj_file *f, ElfW(Addr) base); - -struct obj_file *obj_load (int f, Elf32_Half e_type, const char *filename); - -void obj_free (struct obj_file *f); - -int obj_create_image (struct obj_file *f, char *image); - -int obj_kallsyms (struct obj_file *fin, struct obj_file **fout); - -/* Architecture specific manipulation routines. */ - -struct obj_file *arch_new_file (void); - -struct obj_section *arch_new_section (void); - -struct obj_symbol *arch_new_symbol (void); - -enum obj_reloc arch_apply_relocation (struct obj_file *f, - struct obj_section *targsec, - struct obj_section *symsec, - struct obj_symbol *sym, - ElfW(RelM) *rel, ElfW(Addr) value); - -int arch_create_got (struct obj_file *f); - -struct module; -int arch_init_module (struct obj_file *f, struct module *); - -int arch_load_proc_section (struct obj_section *sec, int fp); - -int arch_finalize_section_address (struct obj_file *f, ElfW(Addr) base); - -int arch_archdata (struct obj_file *fin, struct obj_section *sec); - -#define ARCHDATA_SEC_NAME "__archdata" - -/* Pointers in objects can be 32 or 64 bit */ -union obj_ptr_4 { - Elf32_Word addr; - void *ptr; -}; -union obj_ptr_8 { - u_int64_t addr; /* Should be Elf64_Xword but not all users have this yet */ - void *ptr; -}; - -void *obj_addr_to_native_ptr(ElfW(Addr)); - -ElfW(Addr) obj_native_ptr_to_addr(void *); - -/* Standard method of finding relocation symbols, sets isym */ -#define obj_find_relsym(isym, f, find, rel, symtab, strtab) \ - { \ - unsigned long symndx = ELFW(R_SYM)((rel)->r_info); \ - ElfW(Sym) *extsym = (symtab)+symndx; \ - if (ELFW(ST_BIND)(extsym->st_info) == STB_LOCAL) { \ - isym = (typeof(isym)) (f)->local_symtab[symndx]; \ - } \ - else { \ - const char *name; \ - if (extsym->st_name) \ - name = (strtab) + extsym->st_name; \ - else \ - name = (f)->sections[extsym->st_shndx]->name; \ - isym = (typeof(isym)) obj_find_symbol((find), name); \ - } \ - } - -int obj_gpl_license(struct obj_file *, const char **); - -#endif /* obj.h */ diff --git a/mdk-stage1/insmod-modutils/include/util.h b/mdk-stage1/insmod-modutils/include/util.h deleted file mode 100644 index 0a1354bec..000000000 --- a/mdk-stage1/insmod-modutils/include/util.h +++ /dev/null @@ -1,99 +0,0 @@ -#ifndef MODUTILS_UTIL_H -#define MODUTILS_UTIL_H 1 - -/* Miscelaneous utility functions. - Copyright 1996, 1997 Linux International. - - Contributed by Richard Henderson <rth@tamu.edu> - - This file is part of the Linux modutils. - - This program is free software; you can redistribute it and/or modify it - under the terms of the GNU General Public License as published by the - Free Software Foundation; either version 2 of the License, or (at your - option) any later version. - - This program is distributed in the hope that it will be useful, but - WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - General Public License for more details. - - You should have received a copy of the GNU General Public License - along with this program; if not, write to the Free Software Foundation, - Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ - - -#include <stdio.h> -#include <sys/stat.h> - -#define SHELL_META "&();|<>$`\"'\\!{}[]~=+:?*" /* Sum of bj0rn and Debian */ - -void *xmalloc(size_t); -void *xrealloc(void *, size_t); -char *xstrdup(const char *); -char *xstrcat(char *, const char *, size_t); -int xsystem(const char *, char *const[]); -int arch64(void); - -typedef int (*xftw_func_t)(const char *, const struct stat *); -extern int xftw(const char *directory, xftw_func_t); - -/* Error logging */ -extern int log; -extern int errors; -extern const char *error_file; - -extern int flag_verbose; -extern void verbose(const char *ctl,...); - -void error(const char *fmt, ...) -#ifdef __GNUC__ - __attribute__((format(printf, 1, 2))) -#endif - ; - -void lprintf(const char *fmt, ...) -#ifdef __GNUC__ - __attribute__((format(printf, 1, 2))) -#endif - ; - -void setsyslog(const char *program); - -/* - * Generic globlist <bj0rn@blox.se> - */ -typedef struct { - int pathc; /* Count of paths matched so far */ - char **pathv; /* List of matched pathnames. */ -} GLOB_LIST; -int meta_expand(char *pt, GLOB_LIST *g, char *base_dir, char *version, int type); -#define ME_BUILTIN_COMMAND 1 -#define ME_SHELL_COMMAND 2 -#define ME_GLOB 4 -#define ME_ALL (ME_GLOB|ME_SHELL_COMMAND|ME_BUILTIN_COMMAND) - -extern void snap_shot(const char *module_name, int number); -extern void snap_shot_log(const char *fmt,...); - -#ifdef CONFIG_USE_ZLIB -int gzf_open(const char *name, int mode); -int gzf_read(int fd, void *buf, size_t count); -off_t gzf_lseek(int fd, off_t offset, int whence); -void gzf_close(int fd); - -#else /* ! CONFIG_USE_ZLIB */ - -#include <unistd.h> - -#define gzf_open open -#define gzf_read read -#define gzf_lseek lseek -#define gzf_close close - -#endif /* CONFIG_USE_ZLIB */ - -#define SYMPREFIX "__insmod_"; -extern const char symprefix[10]; /* Must be sizeof(SYMPREFIX), including nul */ - -#endif /* util.h */ diff --git a/mdk-stage1/insmod-modutils/include/version.h b/mdk-stage1/insmod-modutils/include/version.h deleted file mode 100644 index 9ca0c57a9..000000000 --- a/mdk-stage1/insmod-modutils/include/version.h +++ /dev/null @@ -1 +0,0 @@ -#define MODUTILS_VERSION "2.4.19" diff --git a/mdk-stage1/insmod-modutils/insmod-frontend.c b/mdk-stage1/insmod-modutils/insmod-frontend.c deleted file mode 100644 index 26fe73c47..000000000 --- a/mdk-stage1/insmod-modutils/insmod-frontend.c +++ /dev/null @@ -1,24 +0,0 @@ -/* - * Guillaume Cottenceau (gc@mandrakesoft.com) - * - * Copyright 2000 Mandrakesoft - * - * This software may be freely redistributed under the terms of the GNU - * public license. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. - * - */ - -#include <stdio.h> - - -int insmod_main( int argc, char **argv); - -int main( int argc, char **argv) -{ - printf("Using insmod provided by modutils.\n"); - return insmod_main(argc, argv); -} diff --git a/mdk-stage1/insmod-modutils/insmod.c b/mdk-stage1/insmod-modutils/insmod.c deleted file mode 100644 index b0b7c2a0d..000000000 --- a/mdk-stage1/insmod-modutils/insmod.c +++ /dev/null @@ -1,2141 +0,0 @@ -/* Insert a module into a running kernel. - Copyright 1996, 1997 Linux International. - - New implementation contributed by Richard Henderson <rth@tamu.edu> - Based on original work by Bjorn Ekwall <bj0rn@blox.se> - Restructured (and partly rewritten) by: - Björn Ekwall <bj0rn@blox.se> February 1999 - - This file is part of the Linux modutils. - - This program is free software; you can redistribute it and/or modify it - under the terms of the GNU General Public License as published by the - Free Software Foundation; either version 2 of the License, or (at your - option) any later version. - - This program is distributed in the hope that it will be useful, but - WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - General Public License for more details. - - You should have received a copy of the GNU General Public License - along with this program; if not, write to the Free Software Foundation, - Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. - */ - - /* - Fixes: - - Adjust module size for mod_use_count in old_init_module: - B. James Phillippe <bryan@terran.org> - - Merged modprobe + many fixes: Björn Ekwall <bj0rn@blox.se> February 1999 - SMP "friendliness" (and -P): Bill Zumach <zumach+@transarc.com> - - Ksymoops support: Keith Owens <kaos@ocs.com.au> August 1999. - - Add -r flag: Keith Owens <kaos@ocs.com.au> October 1999. - - More flexible recognition of the way the utility was called. - Suggested by Stepan Kasal, implemented in a different way by Keith - Owens <kaos@ocs.com.au> December 1999. - - Rationalize common code for 32/64 bit architectures. - Keith Owens <kaos@ocs.com.au> December 1999. - Add arch64(). - Keith Owens <kaos@ocs.com.au> December 1999. - kallsyms support - Keith Owens <kaos@ocs.com.au> April 2000. - archdata support - Keith Owens <kaos@ocs.com.au> August 2000. - Add insmod -O, move print map before sys_init_module. - Keith Owens <kaos@ocs.com.au> October 2000. - Add insmod -S. - Keith Owens <kaos@ocs.com.au> November 2000. - Add persistent data support. - Keith Owens <kaos@ocs.com.au> November 2000. - Add tainted module support. - Keith Owens <kaos@ocs.com.au> September 2001. - */ - -#include "../insmod.h" -#include <sys/types.h> -#include <stdlib.h> -#include <unistd.h> -#include <string.h> -#include <limits.h> -#include <ctype.h> -#include <errno.h> -#include <stddef.h> -#include <getopt.h> -#include <sys/stat.h> -#include <sys/file.h> -#include <sys/fcntl.h> - -#include "module.h" -#include "obj.h" -#include "kallsyms.h" -#include "util.h" -#include "version.h" - -#include "modstat.h" -#include "config.h" - -#define STRVERSIONLEN 32 - -/*======================================================================*/ - -static int flag_force_load = 0; -static int flag_silent_probe = 0; -static int flag_export = 1; -static int flag_load_map = 0; -static int flag_ksymoops = 1; -static int flag_numeric_only = 0; - -static int n_ext_modules_used; -static int m_has_modinfo; -static int gplonly_seen; -static int warnings; - -extern int insmod_main(int argc, char **argv); -extern int insmod_main_32(int argc, char **argv); -extern int insmod_main_64(int argc, char **argv); -extern int modprobe_main(int argc, char **argv); -extern int rmmod_main(int argc, char **argv); -extern int ksyms_main(int argc, char **argv); -extern int lsmod_main(int argc, char **argv); -extern int kallsyms_main(int argc, char **argv); - -/*======================================================================*/ - -/* Only use the numeric part of the version string? */ - -static void use_numeric_only(int major, int minor, char *str) -{ - if (((major << 8) + minor) >= 0x0205 /* kernel 2.5 */ - || flag_numeric_only) - *str = '\0'; -} - -/* Get the kernel version in the canonical integer form. */ - -static int get_kernel_version(char str[STRVERSIONLEN]) -{ - char *p, *q; - int a, b, c; - - strncpy(str, uts_info.release, STRVERSIONLEN-1); - str[STRVERSIONLEN-1] = '\0'; - p = str; - - a = strtoul(p, &p, 10); - if (*p != '.') - return -1; - b = strtoul(p + 1, &p, 10); - if (*p != '.') - return -1; - c = strtoul(p + 1, &q, 10); - if (p + 1 == q) - return -1; - use_numeric_only(a, b, q); - - return a << 16 | b << 8 | c; -} - -/* String comparison for non-co-versioned kernel and module. - * prefix should be the same as used by genksyms for this kernel. - */ -static char *ncv_prefix = NULL; /* Overridden by --prefix option */ -static int ncv_plen = 0; - -/* Only set prefix once. If set by the user, use it. If not set by the - * user, look for a well known kernel symbol and derive the prefix from - * there. Otherwise set the prefix depending on whether uts_info - * includes SMP or not for backwards compatibility. - */ -static void set_ncv_prefix(char *prefix) -{ - static char derived_prefix[256]; - static const char *well_known_symbol[] = { "get_module_symbol_R", - "inter_module_get_R", - }; - struct module_symbol *s; - int i, j, l, m, pl; - const char *name; - char *p; - - if (ncv_prefix) - return; - - if (prefix) - ncv_prefix = prefix; - else { - /* Extract the prefix (if any) from well known symbols */ - for (i = 0, s = ksyms; i < nksyms; ++i, ++s) { - name = (char *) s->name; - l = strlen(name); - for (j = 0; j < sizeof(well_known_symbol)/sizeof(well_known_symbol[0]); ++j) { - m = strlen(well_known_symbol[j]); - if (m + 8 > l || - strncmp(name, well_known_symbol[j], m)) - continue; - pl = l - m - 8; - if (pl > sizeof(derived_prefix)-1) - continue; /* Prefix is wrong length */ - /* Must end with 8 hex digits */ - (void) strtoul(name+l-8, &p, 16); - if (*p == 0) { - strncpy(derived_prefix, name+m, pl); - *(derived_prefix+pl) = '\0'; - ncv_prefix = derived_prefix; - break; - } - } - } - } - if (!ncv_prefix) { - p = strchr(uts_info.version, ' '); - if (p && *(++p) && !strncmp(p, "SMP ", 4)) - ncv_prefix = "smp_"; - else - ncv_prefix = ""; - } - ncv_plen = strlen(ncv_prefix); - if (flag_verbose) - lprintf("Symbol version prefix '%s'", ncv_prefix); -} - -static int ncv_strcmp(const char *a, const char *b) -{ - size_t alen = strlen(a), blen = strlen(b); - - if (blen == alen + 10 + ncv_plen && - b[alen] == '_' && - b[alen + 1] == 'R' && - !(ncv_plen && strncmp(b + alen + 2, ncv_prefix, ncv_plen))) { - return strncmp(a, b, alen); - } else if (alen == blen + 10 + ncv_plen && - a[blen] == '_' && a[blen + 1] == 'R' && - !(ncv_plen && strncmp(a + blen + 2, ncv_prefix, ncv_plen))) { - return strncmp(a, b, blen); - } else - return strcmp(a, b); -} - -/* - * String hashing for non-co-versioned kernel and module. - * Here we are simply forced to drop the crc from the hash. - */ -static unsigned long ncv_symbol_hash(const char *str) -{ - size_t len = strlen(str); - - if (len > 10 + ncv_plen && - str[len - 10 - ncv_plen] == '_' && - str[len - 9 - ncv_plen] == 'R' && - !( - ncv_plen && - strncmp(str + len - (8 + ncv_plen), ncv_prefix, ncv_plen) - )) - len -= 10 + ncv_plen; - return obj_elf_hash_n(str, len); -} - -/* - * Conditionally add the symbols from the given symbol set - * to the new module. - */ -static int add_symbols_from(struct obj_file *f, int idx, - struct module_symbol *syms, size_t nsyms, int gpl) -{ - struct module_symbol *s; - size_t i; - int used = 0; - - for (i = 0, s = syms; i < nsyms; ++i, ++s) { - /* - * Only add symbols that are already marked external. - * If we override locals we may cause problems for - * argument initialization. - * We will also create a false dependency on the module. - */ - struct obj_symbol *sym; - - /* GPL licensed modules can use symbols exported with - * EXPORT_SYMBOL_GPL, so ignore any GPLONLY_ prefix on the - * exported names. Non-GPL modules never see any GPLONLY_ - * symbols so they cannot fudge it by adding the prefix on - * their references. - */ - if (strncmp((char *)s->name, "GPLONLY_", 8) == 0) { - gplonly_seen = 1; - if (gpl) - ((char *)s->name) += 8; - else - continue; - } - - sym = obj_find_symbol(f, (char *) s->name); -#ifdef ARCH_ppc64 - if (!sym) - { - static size_t buflen = 0; - static char *buf = 0; - int len; - - /* ppc64 is one of those architectures with - function descriptors. A function is exported - and accessed across object boundaries via its - function descriptor. The function code symbol - happens to be the function name, prefixed with - '.', and a function call is a branch to the - code symbol. The linker recognises when a call - crosses object boundaries, and inserts a stub - to call via the function descriptor. - obj_ppc64.c of course does the same thing, so - here we recognise that an undefined code symbol - can be satisfied by the corresponding function - descriptor symbol. */ - - len = strlen ((char *) s->name) + 2; - if (buflen < len) - { - buflen = len + (len >> 1); - if (buf) - free (buf); - buf = malloc (buflen); - } - buf[0] = '.'; - strcpy (buf + 1, (char *) s->name); - sym = obj_find_symbol(f, buf); - } -#endif /* ARCH_ppc64 */ - - if (sym && ELFW(ST_BIND) (sym->info) != STB_LOCAL) { - sym = obj_add_symbol(f, (char *) s->name, -1, - ELFW(ST_INFO) (STB_GLOBAL, STT_NOTYPE), - idx, s->value, 0); - /* - * Did our symbol just get installed? - * If so, mark the module as "used". - */ - if (sym->secidx == idx) - used = 1; - } - } - - return used; -} - -static void add_kernel_symbols(struct obj_file *f, int gpl) -{ - struct module_stat *m; - size_t i, nused = 0; - - /* Add module symbols first. */ - for (i = 0, m = module_stat; i < n_module_stat; ++i, ++m) - if (m->nsyms && - add_symbols_from(f, SHN_HIRESERVE + 2 + i, m->syms, m->nsyms, gpl)) - m->status = 1 /* used */, ++nused; - n_ext_modules_used = nused; - - /* And finally the symbols from the kernel proper. */ - if (nksyms) - add_symbols_from(f, SHN_HIRESERVE + 1, ksyms, nksyms, gpl); -} - -static void hide_special_symbols(struct obj_file *f) -{ - struct obj_symbol *sym; - const char *const *p; - static const char *const specials[] = - { - "cleanup_module", - "init_module", - "kernel_version", - NULL - }; - - for (p = specials; *p; ++p) - if ((sym = obj_find_symbol(f, *p)) != NULL) - sym->info = ELFW(ST_INFO) (STB_LOCAL, ELFW(ST_TYPE) (sym->info)); -} - -static void print_load_map(struct obj_file *f) -{ - struct obj_symbol *sym; - struct obj_symbol **all, **p; - struct obj_section *sec; - int load_map_cmp(const void *a, const void *b) { - struct obj_symbol **as = (struct obj_symbol **) a; - struct obj_symbol **bs = (struct obj_symbol **) b; - unsigned long aa = obj_symbol_final_value(f, *as); - unsigned long ba = obj_symbol_final_value(f, *bs); - return aa < ba ? -1 : aa > ba ? 1 : 0; - } - int i, nsyms, *loaded; - - /* Report on the section layout. */ - - lprintf("Sections: Size %-*s Align", - (int) (2 * sizeof(void *)), "Address"); - - for (sec = f->load_order; sec; sec = sec->load_next) { - int a; - unsigned long tmp; - - for (a = -1, tmp = sec->header.sh_addralign; tmp; ++a) - tmp >>= 1; - if (a == -1) - a = 0; - - lprintf("%-15s %08lx %0*lx 2**%d", - sec->name, - (long)sec->header.sh_size, - (int) (2 * sizeof(void *)), - (long)sec->header.sh_addr, - a); - } - - /* Quick reference which section indicies are loaded. */ - - loaded = alloca(sizeof(int) * (i = f->header.e_shnum)); - while (--i >= 0) - loaded[i] = (f->sections[i]->header.sh_flags & SHF_ALLOC) != 0; - - /* Collect the symbols we'll be listing. */ - - for (nsyms = i = 0; i < HASH_BUCKETS; ++i) - for (sym = f->symtab[i]; sym; sym = sym->next) - if (sym->secidx <= SHN_HIRESERVE - && (sym->secidx >= SHN_LORESERVE || loaded[sym->secidx])) - ++nsyms; - - all = alloca(nsyms * sizeof(struct obj_symbol *)); - - for (i = 0, p = all; i < HASH_BUCKETS; ++i) - for (sym = f->symtab[i]; sym; sym = sym->next) - if (sym->secidx <= SHN_HIRESERVE - && (sym->secidx >= SHN_LORESERVE || loaded[sym->secidx])) - *p++ = sym; - - /* Sort them by final value. */ - qsort(all, nsyms, sizeof(struct obj_file *), load_map_cmp); - - /* And list them. */ - lprintf("\nSymbols:"); - for (p = all; p < all + nsyms; ++p) { - char type = '?'; - unsigned long value; - - sym = *p; - if (sym->secidx == SHN_ABS) { - type = 'A'; - value = sym->value; - } else if (sym->secidx == SHN_UNDEF) { - type = 'U'; - value = 0; - } else { - struct obj_section *sec = f->sections[sym->secidx]; - - if (sec->header.sh_type == SHT_NOBITS) - type = 'B'; - else if (sec->header.sh_flags & SHF_ALLOC) { - if (sec->header.sh_flags & SHF_EXECINSTR) - type = 'T'; - else if (sec->header.sh_flags & SHF_WRITE) - type = 'D'; - else - type = 'R'; - } - value = sym->value + sec->header.sh_addr; - } - - if (ELFW(ST_BIND) (sym->info) == STB_LOCAL) - type = tolower(type); - - lprintf("%0*lx %c %s", (int) (2 * sizeof(void *)), value, - type, sym->name); - } -} - -/************************************************************************/ -/* begin compat */ - -static char * get_modinfo_value(struct obj_file *f, const char *key) -{ - struct obj_section *sec; - char *p, *v, *n, *ep; - size_t klen = strlen(key); - - sec = obj_find_section(f, ".modinfo"); - if (sec == NULL) - return NULL; - - p = sec->contents; - ep = p + sec->header.sh_size; - while (p < ep) { - v = strchr(p, '='); - n = strchr(p, '\0'); - if (v) { - if (v - p == klen && strncmp(p, key, klen) == 0) - return v + 1; - } else { - if (n - p == klen && strcmp(p, key) == 0) - return n; - } - p = n + 1; - } - - return NULL; -} - -static int create_this_module(struct obj_file *f, const char *m_name) -{ - struct obj_section *sec; - - sec = obj_create_alloced_section_first(f, ".this", tgt_sizeof_long, - sizeof(struct module)); - memset(sec->contents, 0, sizeof(struct module)); - - obj_add_symbol(f, "__this_module", -1, ELFW(ST_INFO) (STB_LOCAL, STT_OBJECT), - sec->idx, 0, sizeof(struct module)); - - obj_string_patch(f, sec->idx, offsetof(struct module, name), m_name); - - return 1; -} - -#ifdef COMPAT_2_0 -static int old_create_mod_use_count(struct obj_file *f) -{ - struct obj_section *sec; - struct obj_symbol *got; - - sec = obj_create_alloced_section_first(f, ".moduse", - sizeof(long), sizeof(long)); - - obj_add_symbol(f, "mod_use_count_", - -1, ELFW(ST_INFO)(STB_LOCAL, STT_OBJECT), - sec->idx, 0, sizeof(long)); - - /* - * patb: if there is a _GLOBAL_OFFSET_TABLE_, - * add .got section for PIC type modules; - * we have to do this here, because obj_* calls are not made until - * after obj_check_undefined - * is there a better place for this exception? - */ - got = obj_find_symbol(f, "_GLOBAL_OFFSET_TABLE_"); - if (got) - { - sec = obj_create_alloced_section(f, ".got", - sizeof(long), sizeof(long), - SHF_WRITE); - got->secidx = sec->idx; /* mark the symbol as defined */ - } - return 1; -} -#endif - -/* add an entry to the __ksymtab section, creating it if necessary */ -static void add_ksymtab(struct obj_file *f, struct obj_symbol *sym) -{ - struct obj_section *sec; - ElfW(Addr) ofs; - - /* ensure __ksymtab is allocated, EXPORT_NOSYMBOLS creates a non-alloc section. - * If __ksymtab is defined but not marked alloc, x out the first character - * (no obj_delete routine) and create a new __ksymtab with the correct - * characteristics. - */ - sec = obj_find_section(f, "__ksymtab"); - if (sec && !(sec->header.sh_flags & SHF_ALLOC)) { - *((char *)(sec->name)) = 'x'; /* override const */ - sec = NULL; - } - if (!sec) - sec = obj_create_alloced_section(f, "__ksymtab", - tgt_sizeof_void_p, 0, 0); - if (!sec) - return; - sec->header.sh_flags |= SHF_ALLOC; - - ofs = sec->header.sh_size; - obj_symbol_patch(f, sec->idx, ofs, sym); - obj_string_patch(f, sec->idx, ofs + tgt_sizeof_void_p, sym->name); - obj_extend_section(sec, 2 * tgt_sizeof_char_p); -} - -static int create_module_ksymtab(struct obj_file *f) -{ - struct obj_section *sec; - int i; - - /* We must always add the module references. */ - - if (n_ext_modules_used) { - struct module_ref *dep; - struct obj_symbol *tm; - - sec = obj_create_alloced_section(f, ".kmodtab", - tgt_sizeof_void_p, - sizeof(struct module_ref) * n_ext_modules_used, 0); - if (!sec) - return 0; - - tm = obj_find_symbol(f, "__this_module"); - dep = (struct module_ref *) sec->contents; - for (i = 0; i < n_module_stat; ++i) - if (module_stat[i].status /* used */) { - dep->dep = module_stat[i].addr; -#ifdef ARCH_ppc64 - dep->dep |= ppc64_module_base (f); -#endif - obj_symbol_patch(f, sec->idx, (char *) &dep->ref - sec->contents, tm); - dep->next_ref = 0; - ++dep; - } - } - if (flag_export && !obj_find_section(f, "__ksymtab")) { - int *loaded; - - /* We don't want to export symbols residing in sections that - aren't loaded. There are a number of these created so that - we make sure certain module options don't appear twice. */ - - loaded = alloca(sizeof(int) * (i = f->header.e_shnum)); - while (--i >= 0) - loaded[i] = (f->sections[i]->header.sh_flags & SHF_ALLOC) != 0; - - for (i = 0; i < HASH_BUCKETS; ++i) { - struct obj_symbol *sym; - for (sym = f->symtab[i]; sym; sym = sym->next) { - if (ELFW(ST_BIND) (sym->info) != STB_LOCAL - && sym->secidx <= SHN_HIRESERVE - && (sym->secidx >= SHN_LORESERVE - || loaded[sym->secidx])) { - add_ksymtab(f, sym); - } - } - } - } - return 1; -} - -/* Get the module's kernel version in the canonical integer form. */ -static int get_module_version(struct obj_file *f, char str[STRVERSIONLEN]) -{ - int a, b, c; - char *p, *q; - - if ((p = get_modinfo_value(f, "kernel_version")) == NULL) { - struct obj_symbol *sym; - - m_has_modinfo = 0; - if ((sym = obj_find_symbol(f, "kernel_version")) == NULL) - sym = obj_find_symbol(f, "__module_kernel_version"); - if (sym == NULL) - return -1; - p = f->sections[sym->secidx]->contents + sym->value; - } else - m_has_modinfo = 1; - - strncpy(str, p, STRVERSIONLEN-1); - str[STRVERSIONLEN-1] = '\0'; - p = str; - - a = strtoul(p, &p, 10); - if (*p != '.') - return -1; - b = strtoul(p + 1, &p, 10); - if (*p != '.') - return -1; - c = strtoul(p + 1, &q, 10); - if (p + 1 == q) - return -1; - use_numeric_only(a, b, q); - - return a << 16 | b << 8 | c; -} - -/* Return the kernel symbol checksum version, or zero if not used. */ -static int is_kernel_checksummed(void) -{ - struct module_symbol *s; - size_t i; - - /* - * Using_Versions might not be the first symbol, - * but it should be in there. - */ - for (i = 0, s = ksyms; i < nksyms; ++i, ++s) - if (strcmp((char *) s->name, "Using_Versions") == 0) - return s->value; - - return 0; -} - -static int is_module_checksummed(struct obj_file *f) -{ - if (m_has_modinfo) { - const char *p = get_modinfo_value(f, "using_checksums"); - if (p) - return atoi(p); - else - return 0; - } else - return obj_find_symbol(f, "Using_Versions") != NULL; -} - -/* add module source, timestamp, kernel version and a symbol for the - * start of some sections. this info is used by ksymoops to do better - * debugging. - */ -static void add_ksymoops_symbols(struct obj_file *f, const char *filename, - const char *m_name) -{ - struct obj_section *sec; - struct obj_symbol *sym; - char *name, *absolute_filename; - char str[STRVERSIONLEN], real[PATH_MAX]; - int i, l, lm_name, lfilename, use_ksymtab, version; - struct stat statbuf; - - static const char *section_names[] = { - ".text", - ".rodata", - ".data", - ".bss" - }; - - if (realpath(filename, real)) { - absolute_filename = xstrdup(real); - } - else { - int save_errno = errno; - error("cannot get realpath for %s", filename); - errno = save_errno; - perror(""); - absolute_filename = xstrdup(filename); - } - - lm_name = strlen(m_name); - lfilename = strlen(absolute_filename); - - /* add to ksymtab if it already exists or there is no ksymtab and other symbols - * are not to be exported. otherwise leave ksymtab alone for now, the - * "export all symbols" compatibility code will export these symbols later. - */ - - use_ksymtab = obj_find_section(f, "__ksymtab") || !flag_export; - - if ((sec = obj_find_section(f, ".this"))) { - /* tag the module header with the object name, last modified - * timestamp and module version. worst case for module version - * is 0xffffff, decimal 16777215. putting all three fields in - * one symbol is less readable but saves kernel space. - */ - l = sizeof(symprefix)+ /* "__insmod_" */ - lm_name+ /* module name */ - 2+ /* "_O" */ - lfilename+ /* object filename */ - 2+ /* "_M" */ - 2*sizeof(statbuf.st_mtime)+ /* mtime in hex */ - 2+ /* "_V" */ - 8+ /* version in dec */ - 1; /* nul */ - name = xmalloc(l); - if (stat(absolute_filename, &statbuf) != 0) - statbuf.st_mtime = 0; - version = get_module_version(f, str); /* -1 if not found */ - snprintf(name, l, "%s%s_O%s_M%0*lX_V%d", - symprefix, m_name, absolute_filename, - (int)(2*sizeof(statbuf.st_mtime)), statbuf.st_mtime, - version); - sym = obj_add_symbol(f, name, -1, - ELFW(ST_INFO) (STB_GLOBAL, STT_NOTYPE), - sec->idx, sec->header.sh_addr, 0); - if (use_ksymtab) - add_ksymtab(f, sym); - } - free(absolute_filename); - - /* record where the persistent data is going, same address as previous symbol */ - - if (f->persist) { - l = sizeof(symprefix)+ /* "__insmod_" */ - lm_name+ /* module name */ - 2+ /* "_P" */ - strlen(f->persist)+ /* data store */ - 1; /* nul */ - name = xmalloc(l); - snprintf(name, l, "%s%s_P%s", - symprefix, m_name, f->persist); - sym = obj_add_symbol(f, name, -1, ELFW(ST_INFO) (STB_GLOBAL, STT_NOTYPE), - sec->idx, sec->header.sh_addr, 0); - if (use_ksymtab) - add_ksymtab(f, sym); - } - - /* tag the desired sections if size is non-zero */ - - for (i = 0; i < sizeof(section_names)/sizeof(section_names[0]); ++i) { - if ((sec = obj_find_section(f, section_names[i])) && - sec->header.sh_size) { - l = sizeof(symprefix)+ /* "__insmod_" */ - lm_name+ /* module name */ - 2+ /* "_S" */ - strlen(sec->name)+ /* section name */ - 2+ /* "_L" */ - 8+ /* length in dec */ - 1; /* nul */ - name = xmalloc(l); - snprintf(name, l, "%s%s_S%s_L%ld", - symprefix, m_name, sec->name, - (long)sec->header.sh_size); - sym = obj_add_symbol(f, name, -1, ELFW(ST_INFO) (STB_GLOBAL, STT_NOTYPE), - sec->idx, sec->header.sh_addr, 0); - if (use_ksymtab) - add_ksymtab(f, sym); - } - } -} - -static int process_module_arguments(struct obj_file *f, int argc, char **argv, int required) -{ - for (; argc > 0; ++argv, --argc) { - struct obj_symbol *sym; - int c; - int min, max; - int n; - char *contents; - char *input; - char *fmt; - char *key; - char *loc; - - if ((input = strchr(*argv, '=')) == NULL) - continue; - - n = input - *argv; - input += 1; /* skip '=' */ - - key = alloca(n + 6); - - if (m_has_modinfo) { - memcpy(key, "parm_", 5); - memcpy(key + 5, *argv, n); - key[n + 5] = '\0'; - if ((fmt = get_modinfo_value(f, key)) == NULL) { - if (required || flag_verbose) { - lprintf("Warning: ignoring %s, no such parameter in this module", *argv); - ++warnings; - continue; - } - } - key += 5; - - if (isdigit(*fmt)) { - min = strtoul(fmt, &fmt, 10); - if (*fmt == '-') - max = strtoul(fmt + 1, &fmt, 10); - else - max = min; - } else - min = max = 1; - } else { /* not m_has_modinfo */ - memcpy(key, *argv, n); - key[n] = '\0'; - - if (isdigit(*input)) - fmt = "i"; - else - fmt = "s"; - min = max = 0; - } - - sym = obj_find_symbol(f, key); - - /* - * Also check that the parameter was not - * resolved from the kernel. - */ - if (sym == NULL || sym->secidx > SHN_HIRESERVE) { - error("symbol for parameter %s not found", key); - return 0; - } - - contents = f->sections[sym->secidx]->contents; - loc = contents + sym->value; - n = 1; - - while (*input) { - char *str; - - switch (*fmt) { - case 's': - case 'c': - /* - * Do C quoting if we begin with a ", - * else slurp the lot. - */ - if (*input == '"') { - char *r; - - str = alloca(strlen(input)); - for (r = str, input++; *input != '"'; ++input, ++r) { - if (*input == '\0') { - error("improperly terminated string argument for %s", key); - return 0; - } - /* else */ - if (*input != '\\') { - *r = *input; - continue; - } - /* else handle \ */ - switch (*++input) { - case 'a': *r = '\a'; break; - case 'b': *r = '\b'; break; - case 'e': *r = '\033'; break; - case 'f': *r = '\f'; break; - case 'n': *r = '\n'; break; - case 'r': *r = '\r'; break; - case 't': *r = '\t'; break; - - case '0': - case '1': - case '2': - case '3': - case '4': - case '5': - case '6': - case '7': - c = *input - '0'; - if ('0' <= input[1] && input[1] <= '7') { - c = (c * 8) + *++input - '0'; - if ('0' <= input[1] && input[1] <= '7') - c = (c * 8) + *++input - '0'; - } - *r = c; - break; - - default: *r = *input; break; - } - } - *r = '\0'; - ++input; - } else { - /* - * The string is not quoted. - * We will break it using the comma - * (like for ints). - * If the user wants to include commas - * in a string, he just has to quote it - */ - char *r; - - /* Search the next comma */ - if ((r = strchr(input, ',')) != NULL) { - /* - * Found a comma - * Recopy the current field - */ - str = alloca(r - input + 1); - memcpy(str, input, r - input); - str[r - input] = '\0'; - /* Keep next fields */ - input = r; - } else { - /* last string */ - str = input; - input = ""; - } - } - - if (*fmt == 's') { - /* Normal string */ - obj_string_patch(f, sym->secidx, loc - contents, str); - loc += tgt_sizeof_char_p; - } else { - /* Array of chars (in fact, matrix !) */ - long charssize; /* size of each member */ - - /* Get the size of each member */ - /* Probably we should do that outside the loop ? */ - if (!isdigit(*(fmt + 1))) { - error("parameter type 'c' for %s must be followed by" - " the maximum size", key); - return 0; - } - charssize = strtoul(fmt + 1, (char **) NULL, 10); - - /* Check length */ - if (strlen(str) >= charssize-1) { - error("string too long for %s (max %ld)", - key, charssize - 1); - return 0; - } - /* Copy to location */ - strcpy((char *) loc, str); /* safe, see check above */ - loc += charssize; - } - /* - * End of 's' and 'c' - */ - break; - - case 'b': - *loc++ = strtoul(input, &input, 0); - break; - - case 'h': - *(short *) loc = strtoul(input, &input, 0); - loc += tgt_sizeof_short; - break; - - case 'i': - *(int *) loc = strtoul(input, &input, 0); - loc += tgt_sizeof_int; - break; - - case 'l': - *(long *) loc = strtoul(input, &input, 0); - loc += tgt_sizeof_long; - break; - - default: - error("unknown parameter type '%c' for %s", - *fmt, key); - return 0; - } - /* - * end of switch (*fmt) - */ - - while (*input && isspace(*input)) - ++input; - if (*input == '\0') - break; /* while (*input) */ - /* else */ - - if (*input == ',') { - if (max && (++n > max)) { - error("too many values for %s (max %d)", key, max); - return 0; - } - ++input; - /* continue with while (*input) */ - } else { - error("invalid argument syntax for %s: '%c'", - key, *input); - return 0; - } - } /* end of while (*input) */ - - if (min && (n < min)) { - error("too few values for %s (min %d)", key, min); - return 0; - } - } /* end of for (;argc > 0;) */ - - return 1; -} - - -/* Add a kallsyms section if the kernel supports all symbols. */ -static int add_kallsyms(struct obj_file *f, - struct obj_section **module_kallsyms, int force_kallsyms) -{ - struct module_symbol *s; - struct obj_file *f_kallsyms; - struct obj_section *sec_kallsyms; - size_t i; - int l; - const char *p, *pt_R; - unsigned long start = 0, stop = 0; - - for (i = 0, s = ksyms; i < nksyms; ++i, ++s) { - p = (char *)s->name; - pt_R = strstr(p, "_R"); - if (pt_R) - l = pt_R - p; - else - l = strlen(p); - if (strncmp(p, "__start_" KALLSYMS_SEC_NAME, l) == 0) - start = s->value; - else if (strncmp(p, "__stop_" KALLSYMS_SEC_NAME, l) == 0) - stop = s->value; - } - - if (start >= stop && !force_kallsyms) - return(0); - - /* The kernel contains all symbols, do the same for this module. */ - - /* Add an empty kallsyms section to the module if necessary */ - for (i = 0; i < f->header.e_shnum; ++i) { - if (strcmp(f->sections[i]->name, KALLSYMS_SEC_NAME) == 0) { - *module_kallsyms = f->sections[i]; - break; - } - } - if (!*module_kallsyms) - *module_kallsyms = obj_create_alloced_section(f, KALLSYMS_SEC_NAME, 0, 0, 0); - - /* Size and populate kallsyms */ - if (obj_kallsyms(f, &f_kallsyms)) - return(1); - sec_kallsyms = f_kallsyms->sections[KALLSYMS_IDX]; - (*module_kallsyms)->header.sh_addralign = sec_kallsyms->header.sh_addralign; - (*module_kallsyms)->header.sh_size = sec_kallsyms->header.sh_size; - free((*module_kallsyms)->contents); - (*module_kallsyms)->contents = sec_kallsyms->contents; - sec_kallsyms->contents = NULL; - obj_free(f_kallsyms); - - return 0; -} - - -/* Add an arch data section if the arch wants it. */ -static int add_archdata(struct obj_file *f, - struct obj_section **sec) -{ - size_t i; - - *sec = NULL; - /* Add an empty archdata section to the module if necessary */ - for (i = 0; i < f->header.e_shnum; ++i) { - if (strcmp(f->sections[i]->name, ARCHDATA_SEC_NAME) == 0) { - *sec = f->sections[i]; - break; - } - } - if (!*sec) - *sec = obj_create_alloced_section(f, ARCHDATA_SEC_NAME, 16, 0, 0); - - /* Size and populate archdata */ - if (arch_archdata(f, *sec)) - return(1); - return 0; -} - - -static int init_module(const char *m_name, struct obj_file *f, - unsigned long m_size, const char *blob_name, - unsigned int noload, unsigned int flag_load_map) -{ - struct module *module; - struct obj_section *sec; - void *image; - int ret = 0; - tgt_long m_addr; - - sec = obj_find_section(f, ".this"); - module = (struct module *) sec->contents; - m_addr = sec->header.sh_addr; - - module->size_of_struct = sizeof(*module); - module->size = m_size; - module->flags = flag_autoclean ? NEW_MOD_AUTOCLEAN : 0; - - sec = obj_find_section(f, "__ksymtab"); - if (sec && sec->header.sh_size) { - module->syms = sec->header.sh_addr; - module->nsyms = sec->header.sh_size / (2 * tgt_sizeof_char_p); - } - if (n_ext_modules_used) { - sec = obj_find_section(f, ".kmodtab"); - module->deps = sec->header.sh_addr; - module->ndeps = n_ext_modules_used; - } - module->init = obj_symbol_final_value(f, obj_find_symbol(f, "init_module")); - module->cleanup = obj_symbol_final_value(f, - obj_find_symbol(f, "cleanup_module")); - - sec = obj_find_section(f, "__ex_table"); - if (sec) { - module->ex_table_start = sec->header.sh_addr; - module->ex_table_end = sec->header.sh_addr + sec->header.sh_size; - } - sec = obj_find_section(f, ".text.init"); - if (sec) { - module->runsize = sec->header.sh_addr - m_addr; - } - sec = obj_find_section(f, ".data.init"); - if (sec) { - if (!module->runsize || - module->runsize > sec->header.sh_addr - m_addr) - module->runsize = sec->header.sh_addr - m_addr; - } - sec = obj_find_section(f, ARCHDATA_SEC_NAME); - if (sec && sec->header.sh_size) { - module->archdata_start = sec->header.sh_addr; - module->archdata_end = module->archdata_start + sec->header.sh_size; - } - sec = obj_find_section(f, KALLSYMS_SEC_NAME); - if (sec && sec->header.sh_size) { - module->kallsyms_start = sec->header.sh_addr; - module->kallsyms_end = module->kallsyms_start + sec->header.sh_size; - } - if (!arch_init_module(f, module)) - return 0; - - /* - * Whew! All of the initialization is complete. - * Collect the final module image and give it to the kernel. - */ - image = xmalloc(m_size); - obj_create_image(f, image); - - if (flag_load_map) - print_load_map(f); - - if (blob_name) { - int fd, l; - fd = open(blob_name, O_WRONLY|O_CREAT|O_TRUNC, S_IRUSR|S_IWUSR|S_IRGRP|S_IROTH); - if (fd < 0) { - error("open %s failed %m", blob_name); - ret = -1; - } - else { - if ((l = write(fd, image, m_size)) != m_size) { - error("write %s failed %m", blob_name); - ret = -1; - } - close(fd); - } - } - - if (ret == 0 && !noload) { - fflush(stdout); /* Flush any debugging output */ - ret = sys_init_module(m_name, (struct module *) image); - if (ret) { - error("init_module: %m"); - lprintf("Hint: insmod errors can be caused by incorrect module parameters, " - "including invalid IO or IRQ parameters.\n" - " You may find more information in syslog or the output from dmesg"); - } - } - - free(image); - - return ret == 0; -} - -#ifdef COMPAT_2_0 -static int old_init_module(const char *m_name, struct obj_file *f, - unsigned long m_size) -{ - char *image; - struct old_mod_routines routines; - struct old_symbol_table *symtab; - int ret; - int nsyms = 0, strsize = 0, total; - - /* Create the symbol table */ - /* Size things first... */ - if (flag_export) { - int i; - for (i = 0; i < HASH_BUCKETS; ++i) { - struct obj_symbol *sym; - - for (sym = f->symtab[i]; sym; sym = sym->next) - if (ELFW(ST_BIND) (sym->info) != STB_LOCAL && - sym->secidx <= SHN_HIRESERVE) { - sym->ksymidx = nsyms++; - strsize += strlen(sym->name) + 1; - } - } - } - total = (sizeof(struct old_symbol_table) + - nsyms * sizeof(struct old_module_symbol) + - n_ext_modules_used * sizeof(struct old_module_ref) + - strsize); - symtab = xmalloc(total); - symtab->size = total; - symtab->n_symbols = nsyms; - symtab->n_refs = n_ext_modules_used; - - if (flag_export && nsyms) { - struct old_module_symbol *ksym; - char *str; - int i; - - ksym = symtab->symbol; - str = ((char *) ksym + - nsyms * sizeof(struct old_module_symbol) + - n_ext_modules_used * sizeof(struct old_module_ref)); - - for (i = 0; i < HASH_BUCKETS; ++i) { - struct obj_symbol *sym; - for (sym = f->symtab[i]; sym; sym = sym->next) - if (sym->ksymidx >= 0) { - ksym->addr = obj_symbol_final_value(f, sym); - ksym->name = (unsigned long) str - (unsigned long) symtab; - - str = stpcpy(str, sym->name) + 1; - ksym++; - } - } - } - - if (n_ext_modules_used) { - struct old_module_ref *ref; - int i; - - ref = (struct old_module_ref *) - ((char *) symtab->symbol + nsyms * sizeof(struct old_module_symbol)); - - for (i = 0; i < n_module_stat; ++i) { - if (module_stat[i].status /* used */) { - ref++->module = module_stat[i].modstruct; - } - } - } - - /* Fill in routines. */ - - routines.init = obj_symbol_final_value(f, obj_find_symbol(f, "init_module")); - routines.cleanup = obj_symbol_final_value(f, - obj_find_symbol(f, "cleanup_module")); - - /* - * Whew! All of the initialization is complete. - * Collect the final module image and give it to the kernel. - */ - image = xmalloc(m_size); - obj_create_image(f, image); - - /* - * image holds the complete relocated module, - * accounting correctly for mod_use_count. - * However the old module kernel support assume that it - * is receiving something which does not contain mod_use_count. - */ - ret = old_sys_init_module(m_name, image + sizeof(long), - (m_size - sizeof(long)) | - (flag_autoclean ? OLD_MOD_AUTOCLEAN : 0), - &routines, - symtab); - if (ret) - error("init_module: %m"); - - free(image); - free(symtab); - - return ret == 0; -} -#endif -/* end compat */ -/************************************************************************/ - -/* Check that a module parameter has a reasonable definition */ -static int check_module_parameter(struct obj_file *f, char *key, char *value, int *persist_flag) -{ - struct obj_symbol *sym; - int min, max; - char *p = value; - - sym = obj_find_symbol(f, key); - if (sym == NULL) { - /* FIXME: For 2.2 kernel compatibility, only issue warnings for - * most error conditions. Make these all errors in 2.5. - */ - lprintf("Warning: %s symbol for parameter %s not found", error_file, key); - ++warnings; - return(1); - } - - if (isdigit(*p)) { - min = strtoul(p, &p, 10); - if (*p == '-') - max = strtoul(p + 1, &p, 10); - else - max = min; - } else - min = max = 1; - - if (max < min) { - lprintf("Warning: %s parameter %s has max < min!", error_file, key); - ++warnings; - return(1); - } - - switch (*p) { - case 'c': - if (!isdigit(p[1])) { - lprintf("%s parameter %s has no size after 'c'!", error_file, key); - ++warnings; - return(1); - } - while (isdigit(p[1])) - ++p; /* swallow c array size */ - break; - case 'b': /* drop through */ - case 'h': /* drop through */ - case 'i': /* drop through */ - case 'l': /* drop through */ - case 's': - break; - case '\0': - lprintf("%s parameter %s has no format character!", error_file, key); - ++warnings; - return(1); - default: - lprintf("%s parameter %s has unknown format character '%c'", error_file, key, *p); - ++warnings; - return(1); - } - switch (*++p) { - case 'p': - if (*(p-1) == 's') { - error("parameter %s is invalid persistent string", key); - return(1); - } - *persist_flag = 1; - break; - case '\0': - break; - default: - lprintf("%s parameter %s has unknown format modifier '%c'", error_file, key, *p); - ++warnings; - return(1); - } - return(0); -} - -/* Check that all module parameters have reasonable definitions */ -static void check_module_parameters(struct obj_file *f, int *persist_flag) -{ - struct obj_section *sec; - char *ptr, *value, *n, *endptr; - int namelen, err = 0; - - sec = obj_find_section(f, ".modinfo"); - if (sec == NULL) { - /* module does not support typed parameters */ - return; - } - - ptr = sec->contents; - endptr = ptr + sec->header.sh_size; - while (ptr < endptr && !err) { - value = strchr(ptr, '='); - n = strchr(ptr, '\0'); - if (value) { - namelen = value - ptr; - if (namelen >= 5 && strncmp(ptr, "parm_", 5) == 0 - && !(namelen > 10 && strncmp(ptr, "parm_desc_", 10) == 0)) { - char *pname = xmalloc(namelen + 1); - strncpy(pname, ptr + 5, namelen - 5); - pname[namelen - 5] = '\0'; - err = check_module_parameter(f, pname, value+1, persist_flag); - free(pname); - } - } else { - if (n - ptr >= 5 && strncmp(ptr, "parm_", 5) == 0) { - error("parameter %s found with no value", ptr); - err = 1; - } - } - ptr = n + 1; - } - - if (err) - *persist_flag = 0; - return; -} - -static void set_tainted(struct obj_file *f, int fd, int kernel_has_tainted, - int noload, int taint, - const char *text1, const char *text2) -{ - char buf[80]; - int oldval; - static int first = 1; - if (fd < 0 && !kernel_has_tainted) - return; /* New modutils on old kernel */ - lprintf("Warning: loading %s will taint the kernel: %s%s", - f->filename, text1, text2); - ++warnings; - if (first) { - lprintf(" See %s for information about tainted modules", TAINT_URL); - first = 0; - } - if (fd >= 0 && !noload) { - read(fd, buf, sizeof(buf)-1); - buf[sizeof(buf)-1] = '\0'; - oldval = strtoul(buf, NULL, 10); - sprintf(buf, "%d\n", oldval | taint); - write(fd, buf, strlen(buf)); - } -} - -/* Check if loading this module will taint the kernel. */ -static void check_tainted_module(struct obj_file *f, int noload) -{ - static const char tainted_file[] = TAINT_FILENAME; - int fd, kernel_has_tainted; - const char *ptr; - - if ((fd = open(tainted_file, O_RDWR)) < 0) { - if (errno == ENOENT) - kernel_has_tainted = 0; - else if (errno == EACCES) - kernel_has_tainted = 1; - else { - perror(tainted_file); - kernel_has_tainted = 0; - } - } - else - kernel_has_tainted = 1; - - switch (obj_gpl_license(f, &ptr)) { - case 0: - break; - case 1: - set_tainted(f, fd, kernel_has_tainted, noload, TAINT_PROPRIETORY_MODULE, "no license", ""); - break; - case 2: - /* The module has a non-GPL license so we pretend that the - * kernel always has a taint flag to get a warning even on - * kernels without the proc flag. - */ - set_tainted(f, fd, 1, noload, TAINT_PROPRIETORY_MODULE, "non-GPL license - ", ptr); - break; - default: - set_tainted(f, fd, 1, noload, TAINT_PROPRIETORY_MODULE, "Unexpected return from obj_gpl_license", ""); - break; - } - - if (flag_force_load) - set_tainted(f, fd, 1, noload, TAINT_FORCED_MODULE, "forced load", ""); - if (fd >= 0) - close(fd); -} - -/* For common 3264 code, only compile the usage message once, in the 64 bit version */ -#if defined(COMMON_3264) && defined(ONLY_32) -extern void insmod_usage(void); /* Use the copy in the 64 bit version */ -#else /* Common 64 bit version or any non common code - compile usage routine */ -void insmod_usage(void) -{ - fputs("Usage:\n" - "insmod [-fhkLmnpqrsSvVxXyYN] [-e persist_name] [-o module_name] [-O blob_name] [-P prefix] module [ symbol=value ... ]\n" - "\n" - " module Name of a loadable kernel module ('.o' can be omitted)\n" - " -f, --force Force loading under wrong kernel version\n" - " -h, --help Print this message\n" - " -k, --autoclean Make module autoclean-able\n" - " -L, --lock Prevent simultaneous loads of the same module\n" - " -m, --map Generate load map (so crashes can be traced)\n" - " -n, --noload Don't load, just show\n" - " -p, --probe Probe mode; check if the module matches the kernel\n" - " -q, --quiet Don't print unresolved symbols\n" - " -r, --root Allow root to load modules not owned by root\n" - " -s, --syslog Report errors via syslog\n" - " -S, --kallsyms Force kallsyms on module\n" - " -v, --verbose Verbose output\n" - " -V, --version Show version\n" - " -x, --noexport Do not export externs\n" - " -X, --export Do export externs (default)\n" - " -y, --noksymoops Do not add ksymoops symbols\n" - " -Y, --ksymoops Do add ksymoops symbols (default)\n" - " -N, --numeric-only Only check the numeric part of the kernel version\n" - " -e persist_name\n" - " --persist=persist_name Filename to hold any persistent data from the module\n" - " -o NAME, --name=NAME Set internal module name to NAME\n" - " -O NAME, --blob=NAME Save the object as a binary blob in NAME\n" - " -P PREFIX\n" - " --prefix=PREFIX Prefix for kernel or module symbols\n" - ,stderr); - exit(1); -} -#endif /* defined(COMMON_3264) && defined(ONLY_32) */ - -#if defined(COMMON_3264) && defined(ONLY_32) -#define INSMOD_MAIN insmod_main_32 /* 32 bit version */ -#elif defined(COMMON_3264) && defined(ONLY_64) -#define INSMOD_MAIN insmod_main_64 /* 64 bit version */ -#else -#define INSMOD_MAIN insmod_main /* Not common code */ -#endif - -int INSMOD_MAIN(int argc, char **argv) -{ - int k_version; - int k_crcs; - char k_strversion[STRVERSIONLEN]; - struct option long_opts[] = { - {"force", 0, 0, 'f'}, - {"help", 0, 0, 'h'}, - {"autoclean", 0, 0, 'k'}, - {"lock", 0, 0, 'L'}, - {"map", 0, 0, 'm'}, - {"noload", 0, 0, 'n'}, - {"probe", 0, 0, 'p'}, - {"poll", 0, 0, 'p'}, /* poll is deprecated, remove in 2.5 */ - {"quiet", 0, 0, 'q'}, - {"root", 0, 0, 'r'}, - {"syslog", 0, 0, 's'}, - {"kallsyms", 0, 0, 'S'}, - {"verbose", 0, 0, 'v'}, - {"version", 0, 0, 'V'}, - {"noexport", 0, 0, 'x'}, - {"export", 0, 0, 'X'}, - {"noksymoops", 0, 0, 'y'}, - {"ksymoops", 0, 0, 'Y'}, - {"persist", 1, 0, 'e'}, - {"numeric-only", 1, 0, 'N'}, - {"name", 1, 0, 'o'}, - {"blob", 1, 0, 'O'}, - {"prefix", 1, 0, 'P'}, - {0, 0, 0, 0} - }; - char *m_name = NULL; - char *blob_name = NULL; /* Save object as binary blob */ - int m_version; - ElfW(Addr) m_addr; - unsigned long m_size; - int m_crcs; - char m_strversion[STRVERSIONLEN]; - char *filename; - char *persist_name = NULL; /* filename to hold any persistent data */ - int fp; - struct obj_file *f; - struct obj_section *kallsyms = NULL, *archdata = NULL; - int o; - int noload = 0; - int dolock = 1; /*Note: was: 0; */ - int quiet = 0; - int exit_status = 1; - int force_kallsyms = 0; - int persist_parms = 0; /* does module have persistent parms? */ - int i; - int gpl; - - error_file = "insmod"; - - /* To handle repeated calls from combined modprobe */ - errors = optind = 0; - - /* Process the command line. */ - while ((o = getopt_long(argc, argv, "fhkLmnpqrsSvVxXyYNe:o:O:P:R:", - &long_opts[0], NULL)) != EOF) - switch (o) { - case 'f': /* force loading */ - flag_force_load = 1; - break; - case 'h': /* Print the usage message. */ - insmod_usage(); - break; - case 'k': /* module loaded by kerneld, auto-cleanable */ - flag_autoclean = 1; - break; - case 'L': /* protect against recursion. */ - dolock = 1; - break; - case 'm': /* generate load map */ - flag_load_map = 1; - break; - case 'n': /* don't load, just check */ - noload = 1; - break; - case 'p': /* silent probe mode */ - flag_silent_probe = 1; - break; - case 'q': /* Don't print unresolved symbols */ - quiet = 1; - break; - case 'r': /* allow root to load non-root modules */ - root_check_off = !root_check_off; - break; - case 's': /* start syslog */ - setsyslog("insmod"); - break; - case 'S': /* Force kallsyms */ - force_kallsyms = 1; - break; - case 'v': /* verbose output */ - flag_verbose = 1; - break; - case 'V': - fputs("insmod version " MODUTILS_VERSION "\n", stderr); - break; - case 'x': /* do not export externs */ - flag_export = 0; - break; - case 'X': /* do export externs */ - flag_export = 1; - break; - case 'y': /* do not define ksymoops symbols */ - flag_ksymoops = 0; - break; - case 'Y': /* do define ksymoops symbols */ - flag_ksymoops = 1; - break; - case 'N': /* only check numeric part of kernel version */ - flag_numeric_only = 1; - break; - - case 'e': /* persistent data filename */ - free(persist_name); - persist_name = xstrdup(optarg); - break; - case 'o': /* name the output module */ - m_name = optarg; - break; - case 'O': /* save the output module object */ - blob_name = optarg; - break; - case 'P': /* use prefix on crc */ - set_ncv_prefix(optarg); - break; - - default: - insmod_usage(); - break; - } - - if (optind >= argc) { - insmod_usage(); - } - filename = argv[optind++]; - - if (config_read(0, NULL, "", NULL) < 0) { - error("Failed handle configuration"); - } - - if (persist_name && !*persist_name && - (!persistdir || !*persistdir)) { - free(persist_name); - persist_name = NULL; - if (flag_verbose) { - lprintf("insmod: -e \"\" ignored, no persistdir"); - ++warnings; - } - } - - if (m_name == NULL) { - size_t len; - char *p; - - if ((p = strrchr(filename, '/')) != NULL) - p++; - else - p = filename; - len = strlen(p); - if (len > 2 && p[len - 2] == '.' && p[len - 1] == 'o') - len -= 2; - else if (len > 4 && p[len - 4] == '.' && p[len - 3] == 'm' - && p[len - 2] == 'o' && p[len - 1] == 'd') - len -= 4; -#ifdef CONFIG_USE_ZLIB - else if (len > 5 && !strcmp(p + len - 5, ".o.gz")) - len -= 5; -#endif - - m_name = xmalloc(len + 1); - memcpy(m_name, p, len); - m_name[len] = '\0'; - } - - /* Locate the file to be loaded. */ - if (!strchr(filename, '/') && !strchr(filename, '.')) { - char *tmp = search_module_path(filename); - if (tmp == NULL) { - error("%s: no module by that name found", filename); - return 1; - } - filename = tmp; - lprintf("Using %s", filename); - } else if (flag_verbose) - lprintf("Using %s", filename); - - /* And open it. */ - if ((fp = gzf_open(filename, O_RDONLY)) == -1) { - error("%s: %m", filename); - return 1; - } - /* Try to prevent multiple simultaneous loads. */ - if (dolock) - flock(fp, LOCK_EX); - - if (!get_kernel_info(K_SYMBOLS)) - goto out; - - /* - * Set the genksyms prefix if this is a versioned kernel - * and it's not already set. - */ - set_ncv_prefix(NULL); - - for (i = 0; !noload && i < n_module_stat; ++i) { - if (strcmp(module_stat[i].name, m_name) == 0) { - error("a module named %s already exists", m_name); - goto out; - } - } - - error_file = filename; - if ((f = obj_load(fp, ET_REL, filename)) == NULL) - goto out; - - /* Version correspondence? */ - k_version = get_kernel_version(k_strversion); - m_version = get_module_version(f, m_strversion); - if (m_version == -1) { - error("couldn't find the kernel version the module was compiled for"); - goto out; - } - - k_crcs = is_kernel_checksummed(); - m_crcs = is_module_checksummed(f); - if ((m_crcs == 0 || k_crcs == 0) && - strncmp(k_strversion, m_strversion, STRVERSIONLEN) != 0) { - if (flag_force_load) { - lprintf("Warning: kernel-module version mismatch\n" - "\t%s was compiled for kernel version %s\n" - "\twhile this kernel is version %s", - filename, m_strversion, k_strversion); - ++warnings; - } else { - if (!quiet) - error("kernel-module version mismatch\n" - "\t%s was compiled for kernel version %s\n" - "\twhile this kernel is version %s.", - filename, m_strversion, k_strversion); - goto out; - } - } - if (m_crcs != k_crcs) - obj_set_symbol_compare(f, ncv_strcmp, ncv_symbol_hash); - - /* Let the module know about the kernel symbols. */ - gpl = obj_gpl_license(f, NULL) == 0; - add_kernel_symbols(f, gpl); - -#ifdef ARCH_ppc64 - if (!ppc64_process_syms (f)) - goto out; -#endif - - /* Allocate common symbols, symbol tables, and string tables. - * - * The calls marked DEPMOD indicate the bits of code that depmod - * uses to do a pseudo relocation, ignoring undefined symbols. - * Any changes made to the relocation sequence here should be - * checked against depmod. - */ -#ifdef COMPAT_2_0 - if (k_new_syscalls - ? !create_this_module(f, m_name) - : !old_create_mod_use_count(f)) - goto out; -#else - if (!create_this_module(f, m_name)) - goto out; -#endif - - arch_create_got(f); /* DEPMOD */ - if (!obj_check_undefineds(f, quiet)) { /* DEPMOD, obj_clear_undefineds */ - if (!gpl && !quiet) { - if (gplonly_seen) - error("\n" - "Hint: You are trying to load a module without a GPL compatible license\n" - " and it has unresolved symbols. The module may be trying to access\n" - " GPLONLY symbols but the problem is more likely to be a coding or\n" - " user error. Contact the module supplier for assistance, only they\n" - " can help you.\n"); - else - error("\n" - "Hint: You are trying to load a module without a GPL compatible license\n" - " and it has unresolved symbols. Contact the module supplier for\n" - " assistance, only they can help you.\n"); - } - goto out; - } - obj_allocate_commons(f); /* DEPMOD */ - - check_module_parameters(f, &persist_parms); - check_tainted_module(f, noload); - - if (optind < argc) { - if (!process_module_arguments(f, argc - optind, argv + optind, 1)) - goto out; - } - hide_special_symbols(f); - - if (persist_parms && persist_name && *persist_name) { - f->persist = persist_name; - persist_name = NULL; - } - - if (persist_parms && - persist_name && !*persist_name) { - /* -e "". This is ugly. Take the filename, compare it against - * each of the module paths until we find a match on the start - * of the filename, assume the rest is the relative path. Have - * to do it this way because modprobe uses absolute filenames - * for module names in modules.dep and the format of modules.dep - * does not allow for any backwards compatible changes, so there - * is nowhere to store the relative filename. The only way this - * should fail to calculate a relative path is "insmod ./xxx", for - * that case the user has to specify -e filename. - */ - int j, l = strlen(filename); - char *relative = NULL; - char *p; - for (i = 0; i < nmodpath; ++i) { - p = modpath[i].path; - j = strlen(p); - while (j && p[j] == '/') - --j; - if (j < l && strncmp(filename, p, j) == 0 && filename[j] == '/') { - while (filename[j] == '/') - ++j; - relative = xstrdup(filename+j); - break; - } - } - if (relative) { - i = strlen(relative); - if (i > 3 && strcmp(relative+i-3, ".gz") == 0) - relative[i -= 3] = '\0'; - if (i > 2 && strcmp(relative+i-2, ".o") == 0) - relative[i -= 2] = '\0'; - else if (i > 4 && strcmp(relative+i-4, ".mod") == 0) - relative[i -= 4] = '\0'; - f->persist = xmalloc(strlen(persistdir) + 1 + i + 1); - strcpy(f->persist, persistdir); /* safe, xmalloc */ - strcat(f->persist, "/"); /* safe, xmalloc */ - strcat(f->persist, relative); /* safe, xmalloc */ - free(relative); - } - else - error("Cannot calculate persistent filename"); - } - - if (f->persist && *(f->persist) != '/') { - error("Persistent filenames must be absolute, ignoring '%s'", - f->persist); - free(f->persist); - f->persist = NULL; - } - - if (f->persist && !flag_ksymoops) { - error("has persistent data but ksymoops symbols are not available"); - free(f->persist); - f->persist = NULL; - } - - if (f->persist && !k_new_syscalls) { - error("has persistent data but the kernel is too old to support it"); - free(f->persist); - f->persist = NULL; - } - - if (persist_parms && flag_verbose) { - if (f->persist) - lprintf("Persist filename '%s'", f->persist); - else - lprintf("No persistent filename available"); - } - - if (f->persist) { - FILE *fp = fopen(f->persist, "r"); - if (!fp) { - if (flag_verbose) - lprintf("Cannot open persist file '%s' %m", f->persist); - } - else { - int pargc = 0; - char *pargv[1000]; /* hard coded but big enough */ - char line[3000]; /* hard coded but big enough */ - char *p; - while (fgets(line, sizeof(line), fp)) { - p = strchr(line, '\n'); - if (!p) { - error("Persistent data line is too long\n%s", line); - break; - } - *p = '\0'; - p = line; - while (isspace(*p)) - ++p; - if (!*p || *p == '#') - continue; - if (pargc == sizeof(pargv)/sizeof(pargv[0])) { - error("More than %d persistent parameters", pargc); - break; - } - pargv[pargc++] = xstrdup(p); - } - fclose(fp); - if (!process_module_arguments(f, pargc, pargv, 0)) - goto out; - while (pargc--) - free(pargv[pargc]); - } - } - - if (flag_ksymoops) - add_ksymoops_symbols(f, filename, m_name); - - if (k_new_syscalls) - create_module_ksymtab(f); - - /* archdata based on relocatable addresses */ - if (add_archdata(f, &archdata)) - goto out; - - /* kallsyms based on relocatable addresses */ - if (add_kallsyms(f, &kallsyms, force_kallsyms)) - goto out; - /**** No symbols or sections to be changed after kallsyms above ***/ - - if (errors) - goto out; - - /* If we were just checking, we made it. */ - if (flag_silent_probe) { - exit_status = 0; - goto out; - } - /* Module has now finished growing; find its size and install it. */ - m_size = obj_load_size(f); /* DEPMOD */ - - if (noload) { - /* Don't bother actually touching the kernel. */ - m_addr = 0x12340000; - } else { - errno = 0; - m_addr = create_module(m_name, m_size); -#ifdef ARCH_ppc64 - m_addr |= ppc64_module_base (f); -#endif - switch (errno) { - case 0: - break; - case EEXIST: - if (dolock) { - /* - * Assume that we were just invoked - * simultaneous with another insmod - * and return success. - */ - exit_status = 0; - goto out; - } - error("a module named %s already exists", m_name); - goto out; - case ENOMEM: - error("can't allocate kernel memory for module; needed %lu bytes", - m_size); - goto out; - default: - error("create_module: %m"); - goto out; - } - } - - /* module is already built, complete with ksymoops symbols for the - * persistent filename. If the kernel does not support persistent data - * then give an error but continue. It is too difficult to clean up at - * this stage and this error will only occur on backported modules. - * rmmod will also get an error so warn the user now. - */ - if (f->persist && !noload) { - struct { - struct module m; - int data; - } test_read; - memset(&test_read, 0, sizeof(test_read)); - test_read.m.size_of_struct = -sizeof(test_read.m); /* -ve size => read, not write */ - test_read.m.read_start = m_addr + sizeof(struct module); - test_read.m.read_end = test_read.m.read_start + sizeof(test_read.data); - if (sys_init_module(m_name, (struct module *) &test_read)) { - int old_errors = errors; - error("has persistent data but the kernel is too old to support it." - " Expect errors during rmmod as well"); - errors = old_errors; - } - } - - if (!obj_relocate(f, m_addr)) { /* DEPMOD */ - if (!noload) - delete_module(m_name); - goto out; - } - - /* Do archdata again, this time we have the final addresses */ - if (add_archdata(f, &archdata)) - goto out; - - /* Do kallsyms again, this time we have the final addresses */ - if (add_kallsyms(f, &kallsyms, force_kallsyms)) - goto out; - -#ifdef COMPAT_2_0 - if (k_new_syscalls) - init_module(m_name, f, m_size, blob_name, noload, flag_load_map); - else if (!noload) - old_init_module(m_name, f, m_size); -#else - init_module(m_name, f, m_size, blob_name, noload, flag_load_map); -#endif - if (errors) { - if (!noload) - delete_module(m_name); - goto out; - } - if (warnings && !noload) - lprintf("Module %s loaded, with warnings", m_name); - exit_status = 0; - - out: - if (dolock) - flock(fp, LOCK_UN); - close(fp); - if (!noload) - snap_shot(NULL, 0); - - return exit_status; -} - -/* For common 3264 code, add an overall insmod_main, in the 64 bit version. */ -#if defined(COMMON_3264) && defined(ONLY_64) -int insmod_main(int argc, char **argv) -{ - if (arch64()) - return insmod_main_64(argc, argv); - else - return insmod_main_32(argc, argv); -} -#endif /* defined(COMMON_3264) && defined(ONLY_64) */ - - -int insmod_call(char * full_filename, char * params) -{ - int argc = 2; - char *argv[50]; - char * ptr = params; - argv[0] = "stage1"; - argv[1] = full_filename; - - while (ptr != NULL) { - argv[argc] = ptr; - argc++; - ptr = strchr(ptr, ' '); - if (ptr) { - ptr[0] = '\0'; - ptr++; - } - } - - return insmod_main(argc, argv); -} diff --git a/mdk-stage1/insmod-modutils/obj/Makefile b/mdk-stage1/insmod-modutils/obj/Makefile deleted file mode 100644 index d44b2a6c6..000000000 --- a/mdk-stage1/insmod-modutils/obj/Makefile +++ /dev/null @@ -1,38 +0,0 @@ - #****************************************************************************** - # - # insmod from modutils (generic) - # - # $Id$ - # - # Copyright 1996, 1997 Linux International. - # - #***************************************************************************** - -top_dir = ../.. - -include $(top_dir)/Makefile.common - - -all: libobj.a - -clean: - rm -f *.o *.a - - -INCS = -I./../include - -DEFS = -D_GNU_SOURCE -DELF_MACHINE_H='"elf_$(ARCH).h"' -DARCH_$(ARCH) -DCONFIG_ROOT_CHECK_OFF=0 - -ifeq (x86_64, $(ARCH)) -DEFS += -Wno-error -endif - -OBJS = obj_kallsyms.o obj_common.o obj_load.o obj_reloc.o obj_$(ARCH).o \ - obj_gpl_license.o - -libobj.a: $(OBJS) - ar cru $@ $^ - ranlib $@ - -%.o: %.c - $(DIET) gcc $(CFLAGS) $(DEFS) $(INCS) $(INCLUDES) -c $< diff --git a/mdk-stage1/insmod-modutils/obj/obj_alpha.c b/mdk-stage1/insmod-modutils/obj/obj_alpha.c deleted file mode 100644 index 175012716..000000000 --- a/mdk-stage1/insmod-modutils/obj/obj_alpha.c +++ /dev/null @@ -1,328 +0,0 @@ -/* Alpha specific support for Elf loading and relocation. - Copyright 1996, 1997 Linux International. - - Contributed by Richard Henderson <rth@tamu.edu> - - This file is part of the Linux modutils. - - This program is free software; you can redistribute it and/or modify it - under the terms of the GNU General Public License as published by the - Free Software Foundation; either version 2 of the License, or (at your - option) any later version. - - This program is distributed in the hope that it will be useful, but - WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - General Public License for more details. - - You should have received a copy of the GNU General Public License - along with this program; if not, write to the Free Software Foundation, - Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ - -#include <string.h> -#include <assert.h> - -#include <module.h> -#include <obj.h> -#include <util.h> - - -/* This relocation got renamed, and the change hasn't propagated yet. */ -#ifndef R_ALPHA_GPREL16 -#define R_ALPHA_GPREL16 R_ALPHA_IMMED_GP_16 -#endif - -/*======================================================================*/ - -struct alpha_got_entry -{ - struct alpha_got_entry *next; - ElfW(Addr) addend; - int offset; - int reloc_done; -}; - -struct alpha_file -{ - struct obj_file root; - struct obj_section *got; -}; - -struct alpha_symbol -{ - struct obj_symbol root; - struct alpha_got_entry *got_entries; -}; - - -/*======================================================================*/ - -struct obj_file * -arch_new_file (void) -{ - struct alpha_file *f; - f = xmalloc(sizeof(*f)); - f->got = NULL; - return &f->root; -} - -struct obj_section * -arch_new_section (void) -{ - return xmalloc(sizeof(struct obj_section)); -} - -struct obj_symbol * -arch_new_symbol (void) -{ - struct alpha_symbol *sym; - sym = xmalloc(sizeof(*sym)); - sym->got_entries = NULL; - return &sym->root; -} - -int -arch_load_proc_section(struct obj_section *sec, int fp) -{ - /* Assume it's just a debugging section that we can safely - ignore ... */ - sec->contents = NULL; - - return 0; -} - -enum obj_reloc -arch_apply_relocation (struct obj_file *f, - struct obj_section *targsec, - struct obj_section *symsec, - struct obj_symbol *sym, - Elf64_Rela *rel, - Elf64_Addr v) -{ - struct alpha_file *af = (struct alpha_file *)f; - struct alpha_symbol *asym = (struct alpha_symbol *)sym; - - unsigned long *lloc = (unsigned long *)(targsec->contents + rel->r_offset); - unsigned int *iloc = (unsigned int *)lloc; - unsigned short *sloc = (unsigned short *)lloc; - Elf64_Addr dot = targsec->header.sh_addr + rel->r_offset; - Elf64_Addr gp = af->got->header.sh_addr + 0x8000; - - enum obj_reloc ret = obj_reloc_ok; - - switch (ELF64_R_TYPE(rel->r_info)) - { - case R_ALPHA_NONE: - case R_ALPHA_LITUSE: - break; - - case R_ALPHA_REFQUAD: - *lloc += v; - break; - - case R_ALPHA_GPREL16: - v -= gp; - if ((Elf64_Sxword)v > 0x7fff - || (Elf64_Sxword)v < -(Elf64_Sxword)0x8000) - ret = obj_reloc_overflow; - *sloc = v; - break; - - case R_ALPHA_GPRELLOW: - /* GPRELLOW does not overflow. Errors are seen in the - corresponding GPRELHIGH. */ - v -= gp; - *sloc = v; - break; - - case R_ALPHA_GPRELHIGH: - v -= gp; - v = ((Elf64_Sxword)v >> 16) + ((v >> 15) & 1); - if ((Elf64_Sxword)v > 0x7fff - || (Elf64_Sxword)v < -(Elf64_Sxword)0x8000) - ret = obj_reloc_overflow; - *sloc = v; - break; - - case R_ALPHA_GPREL32: - v -= gp; - if ((Elf64_Sxword)v > 0x7fffffff - || (Elf64_Sxword)v < -(Elf64_Sxword)0x80000000) - ret = obj_reloc_overflow; - *iloc = v; - break; - - case R_ALPHA_LITERAL: - { - struct alpha_got_entry *gotent; - - assert(asym != NULL); - gotent = asym->got_entries; - while (gotent->addend != rel->r_addend) - gotent = gotent->next; - - if (!gotent->reloc_done) - { - *(unsigned long *)(af->got->contents + gotent->offset) = v; - gotent->reloc_done = 1; - } - - *sloc = gotent->offset - 0x8000; - } - break; - - case R_ALPHA_GPDISP: - { - unsigned int *p_ldah, *p_lda; - unsigned int i_ldah, i_lda, hi, lo; - - p_ldah = iloc; - p_lda = (unsigned int *)((char *)iloc + rel->r_addend); - i_ldah = *p_ldah; - i_lda = *p_lda; - - /* Make sure the instructions are righteous. */ - if ((i_ldah >> 26) != 9 || (i_lda >> 26) != 8) - ret = obj_reloc_dangerous; - - /* Extract the existing addend. */ - v = (i_ldah & 0xffff) << 16 | (i_lda & 0xffff); - v = (v ^ 0x80008000) - 0x80008000; - - v += gp - dot; - - if ((Elf64_Sxword)v >= 0x7fff8000 - || (Elf64_Sxword)v < -(Elf64_Sxword)0x80000000) - ret = obj_reloc_overflow; - - /* Modify the instructions and finish up. */ - lo = v & 0xffff; - hi = ((v >> 16) + ((v >> 15) & 1)) & 0xffff; - - *p_ldah = (i_ldah & 0xffff0000) | hi; - *p_lda = (i_lda & 0xffff0000) | lo; - } - break; - - case R_ALPHA_BRADDR: - v -= dot + 4; - if (v % 4) - ret = obj_reloc_dangerous; - else if ((Elf64_Sxword)v > 0x3fffff - || (Elf64_Sxword)v < -(Elf64_Sxword)0x400000) - ret = obj_reloc_overflow; - v /= 4; - - *iloc = (*iloc & ~0x1fffff) | (v & 0x1fffff); - break; - - case R_ALPHA_HINT: - v -= dot + 4; - if (v % 4) - ret = obj_reloc_dangerous; - v /= 4; - - *iloc = (*iloc & ~0x3fff) | (v & 0x3fff); - break; - - default: - ret = obj_reloc_unhandled; - break; - } - - return ret; -} - -int -arch_create_got (struct obj_file *f) -{ - struct alpha_file *af = (struct alpha_file *)f; - int i, n, offset = 0; - - n = af->root.header.e_shnum; - for (i = 0; i < n; ++i) - { - struct obj_section *relsec, *symsec, *strsec; - Elf64_Rela *rel, *relend; - Elf64_Sym *symtab; - const char *strtab; - - relsec = af->root.sections[i]; - if (relsec->header.sh_type != SHT_RELA) - continue; - - symsec = af->root.sections[relsec->header.sh_link]; - strsec = af->root.sections[symsec->header.sh_link]; - - rel = (Elf64_Rela *)relsec->contents; - relend = rel + (relsec->header.sh_size / sizeof(Elf64_Rela)); - symtab = (Elf64_Sym *)symsec->contents; - strtab = (const char *)strsec->contents; - - for (; rel < relend; ++rel) - { - struct alpha_got_entry *ent; - struct alpha_symbol *intsym; - - if (ELF64_R_TYPE(rel->r_info) != R_ALPHA_LITERAL) - continue; - - obj_find_relsym(intsym, f, &af->root, rel, symtab, strtab); - - for (ent = intsym->got_entries; ent ; ent = ent->next) - if (ent->addend == rel->r_addend) - goto found; - - ent = xmalloc(sizeof(*ent)); - ent->addend = rel->r_addend; - ent->offset = offset; - ent->reloc_done = 0; - ent->next = intsym->got_entries; - intsym->got_entries = ent; - offset += 8; - - found:; - } - } - - if (offset > 0x10000) - { - error(".got section overflow: %#x > 0x10000", offset); - return 0; - } - - /* We always want a .got section so that we always have a GP for - use with GPDISP and GPREL relocs. Besides, if the section - is empty we don't use up space anyway. */ - af->got = obj_create_alloced_section(&af->root, ".got", 8, offset, - SHF_WRITE | SHF_ALPHA_GPREL); - - return 1; -} - -int -arch_init_module (struct obj_file *f, struct module *mod) -{ - struct alpha_file *af = (struct alpha_file *)f; - - mod->gp = af->got->header.sh_addr + 0x8000; - - return 1; -} - -int -arch_finalize_section_address(struct obj_file *f, Elf64_Addr base) -{ - int i, n = f->header.e_shnum; - - f->baseaddr = base; - for (i = 0; i < n; ++i) - f->sections[i]->header.sh_addr += base; - return 1; -} - -int -arch_archdata (struct obj_file *fin, struct obj_section *sec) -{ - return 0; -} diff --git a/mdk-stage1/insmod-modutils/obj/obj_arm.c b/mdk-stage1/insmod-modutils/obj/obj_arm.c deleted file mode 100644 index 78b53700c..000000000 --- a/mdk-stage1/insmod-modutils/obj/obj_arm.c +++ /dev/null @@ -1,310 +0,0 @@ -/* ARM specific support for Elf loading and relocation. - Copyright 1996, 1997, 1998 Linux International. - - Contributed by Phil Blundell <philb@gnu.org> - and wms <woody@corelcomputer.com> - based on the i386 code by Richard Henderson <rth@tamu.edu> - - This file is part of the Linux modutils. - - This program is free software; you can redistribute it and/or modify it - under the terms of the GNU General Public License as published by the - Free Software Foundation; either version 2 of the License, or (at your - option) any later version. - - This program is distributed in the hope that it will be useful, but - WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - General Public License for more details. - - You should have received a copy of the GNU General Public License - along with this program; if not, write to the Free Software Foundation, - Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ - -#include <string.h> -#include <assert.h> - -#include <module.h> -#include <obj.h> -#include <util.h> - - -/*======================================================================*/ - -struct arm_plt_entry -{ - int offset; - int allocated:1; - int inited:1; // has been set up -}; - -struct arm_got_entry -{ - int offset; - int allocated : 1; - unsigned reloc_done : 1; -}; - -struct arm_file -{ - struct obj_file root; - struct obj_section *plt; - struct obj_section *got; -}; - -struct arm_symbol -{ - struct obj_symbol root; - struct arm_plt_entry pltent; - struct arm_got_entry gotent; -}; - - -/*======================================================================*/ - -struct obj_file * -arch_new_file (void) -{ - struct arm_file *f; - f = xmalloc(sizeof(*f)); - f->got = NULL; - return &f->root; -} - -struct obj_section * -arch_new_section (void) -{ - return xmalloc(sizeof(struct obj_section)); -} - -struct obj_symbol * -arch_new_symbol (void) -{ - struct arm_symbol *sym; - sym = xmalloc(sizeof(*sym)); - memset(&sym->gotent, 0, sizeof(sym->gotent)); - memset(&sym->pltent, 0, sizeof(sym->pltent)); - return &sym->root; -} - -int -arch_load_proc_section(struct obj_section *sec, int fp) -{ - /* Assume it's just a debugging section that we can safely - ignore ... */ - sec->contents = NULL; - - return 0; -} - -enum obj_reloc -arch_apply_relocation (struct obj_file *f, - struct obj_section *targsec, - struct obj_section *symsec, - struct obj_symbol *sym, - Elf32_Rel *rel, - Elf32_Addr v) -{ - struct arm_file *afile = (struct arm_file *)f; - struct arm_symbol *asym = (struct arm_symbol *)sym; - - Elf32_Addr *loc = (Elf32_Addr *)(targsec->contents + rel->r_offset); - Elf32_Addr dot = targsec->header.sh_addr + rel->r_offset; - Elf32_Addr got = afile->got ? afile->got->header.sh_addr : 0; - Elf32_Addr plt = afile->plt ? afile->plt->header.sh_addr : 0; - - struct arm_plt_entry *pe; - unsigned long *ip; - - enum obj_reloc ret = obj_reloc_ok; - - switch (ELF32_R_TYPE(rel->r_info)) - { - case R_ARM_NONE: - break; - - case R_ARM_ABS32: - *loc += v; - break; - - case R_ARM_GOT32: - /* needs an entry in the .got: set it, once */ - if (! asym->gotent.reloc_done) - { - asym->gotent.reloc_done = 1; - *(Elf32_Addr *)(afile->got->contents + asym->gotent.offset) = v; - } - /* make the reloc with_respect_to_.got */ - *loc += asym->gotent.offset; - break; - - /* relative reloc, always to _GLOBAL_OFFSET_TABLE_ (which is .got) - similar to branch, but is full 32 bits relative */ - case R_ARM_GOTPC: - assert(got); - *loc += got - dot; - break; - - case R_ARM_PC24: - case R_ARM_PLT32: - /* find the plt entry and initialize it if necessary */ - assert(asym != NULL); - pe = (struct arm_plt_entry*) &asym->pltent; - if (! pe->inited) - { - ip = (unsigned long *) (afile->plt->contents + pe->offset); - ip[0] = 0xe51ff004; /* ldr pc,[pc,#-4] */ - ip[1] = v; /* sym@ */ - pe->inited = 1; - } - - /* relative distance to target */ - v -= dot; - /* if the target is too far away.... */ - if ((int)v < -0x02000000 || (int)v >= 0x02000000) - { - /* go via the plt */ - v = plt + pe->offset - dot; - } - if (v & 3) - ret = obj_reloc_dangerous; - - /* Convert to words. */ - v >>= 2; - - /* merge the offset into the instruction. */ - *loc = (*loc & ~0x00ffffff) | ((v + *loc) & 0x00ffffff); - break; - - /* address relative to the got */ - case R_ARM_GOTOFF: - assert(got); - *loc += v - got; - break; - - default: - printf("Warning: unhandled reloc %d\n",ELF32_R_TYPE(rel->r_info)); - ret = obj_reloc_unhandled; - break; - } - - return ret; -} - -int -arch_create_got (struct obj_file *f) -{ - struct arm_file *afile = (struct arm_file *) f; - int i; - struct obj_section *sec, *syms, *strs; - ElfW(Rel) *rel, *relend; - ElfW(Sym) *symtab, *extsym; - const char *strtab; - struct arm_symbol *intsym; - struct arm_plt_entry *pe; - struct arm_got_entry *ge; - int got_offset = 0, plt_offset = 0; - - for (i = 0; i < f->header.e_shnum; ++i) - { - sec = f->sections[i]; - if (sec->header.sh_type != SHT_RELM) - continue; - syms = f->sections[sec->header.sh_link]; - strs = f->sections[syms->header.sh_link]; - - rel = (ElfW(RelM) *) sec->contents; - relend = rel + (sec->header.sh_size / sizeof(ElfW(RelM))); - symtab = (ElfW(Sym) *) syms->contents; - strtab = (const char *) strs->contents; - - for (; rel < relend; ++rel) - { - extsym = &symtab[ELF32_R_SYM(rel->r_info)]; - - switch(ELF32_R_TYPE(rel->r_info)) { - case R_ARM_PC24: - case R_ARM_PLT32: - obj_find_relsym(intsym, f, f, rel, symtab, strtab); - - pe = &intsym->pltent; - - if (! pe->allocated) - { - pe->allocated = 1; - pe->offset = plt_offset; - plt_offset += 8; - pe->inited = 0; - } - break; - - /* these two don_t need got entries, but they need - the .got to exist */ - case R_ARM_GOTOFF: - case R_ARM_GOTPC: - if (got_offset==0) got_offset = 4; - break; - - case R_ARM_GOT32: - obj_find_relsym(intsym, f, f, rel, symtab, strtab); - - ge = (struct arm_got_entry *) &intsym->gotent; - if (! ge->allocated) - { - ge->allocated = 1; - ge->offset = got_offset; - got_offset += sizeof(void*); - } - break; - - default: - continue; - } - } - } - - /* if there was a _GLOBAL_OFFSET_TABLE_, then the .got section - exists already; find it and use it */ - if (got_offset) - { - struct obj_section* sec = obj_find_section(f, ".got"); - if (sec) - obj_extend_section(sec, got_offset); - else - { - sec = obj_create_alloced_section(f, ".got", 8, got_offset, - SHF_WRITE); - assert(sec); - } - afile->got = sec; - } - - if (plt_offset) - afile->plt = obj_create_alloced_section(f, ".plt", 8, plt_offset, - SHF_WRITE); - - return 1; -} - -int -arch_init_module (struct obj_file *f, struct module *mod) -{ - return 1; -} - -int -arch_finalize_section_address(struct obj_file *f, Elf32_Addr base) -{ - int i, n = f->header.e_shnum; - - f->baseaddr = base; - for (i = 0; i < n; ++i) - f->sections[i]->header.sh_addr += base; - return 1; -} - -int -arch_archdata (struct obj_file *fin, struct obj_section *sec) -{ - return 0; -} diff --git a/mdk-stage1/insmod-modutils/obj/obj_common.c b/mdk-stage1/insmod-modutils/obj/obj_common.c deleted file mode 100644 index a957ff1be..000000000 --- a/mdk-stage1/insmod-modutils/obj/obj_common.c +++ /dev/null @@ -1,416 +0,0 @@ -/* Elf file, section, and symbol manipulation routines. - Copyright 1996, 1997 Linux International. - - Contributed by Richard Henderson <rth@tamu.edu> - - This file is part of the Linux modutils. - - This program is free software; you can redistribute it and/or modify it - under the terms of the GNU General Public License as published by the - Free Software Foundation; either version 2 of the License, or (at your - option) any later version. - - This program is distributed in the hope that it will be useful, but - WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - General Public License for more details. - - You should have received a copy of the GNU General Public License - along with this program; if not, write to the Free Software Foundation, - Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ - -#include <stdlib.h> -#include <string.h> -#include <assert.h> -#include <alloca.h> - -#include <obj.h> -#include <util.h> -#include <module.h> - -/*======================================================================*/ - -/* Standard ELF hash function. */ -inline unsigned long -obj_elf_hash_n(const char *name, unsigned long n) -{ - unsigned long h = 0; - unsigned long g; - unsigned char ch; - - while (n > 0) - { - ch = *name++; - h = (h << 4) + ch; - if ((g = (h & 0xf0000000)) != 0) - { - h ^= g >> 24; - h &= ~g; - } - n--; - } - return h; -} - -unsigned long -obj_elf_hash (const char *name) -{ - return obj_elf_hash_n(name, strlen(name)); -} - -void -obj_set_symbol_compare (struct obj_file *f, - int (*cmp)(const char *, const char *), - unsigned long (*hash)(const char *)) -{ - if (cmp) - f->symbol_cmp = cmp; - if (hash) - { - struct obj_symbol *tmptab[HASH_BUCKETS], *sym, *next; - int i; - - f->symbol_hash = hash; - - memcpy(tmptab, f->symtab, sizeof(tmptab)); - memset(f->symtab, 0, sizeof(f->symtab)); - - for (i = 0; i < HASH_BUCKETS; ++i) - for (sym = tmptab[i]; sym ; sym = next) - { - unsigned long h = hash(sym->name) % HASH_BUCKETS; - next = sym->next; - sym->next = f->symtab[h]; - f->symtab[h] = sym; - } - } -} - -struct obj_symbol * -obj_add_symbol (struct obj_file *f, const char *name, unsigned long symidx, - int info, int secidx, ElfW(Addr) value, unsigned long size) -{ - struct obj_symbol *sym; - unsigned long hash = f->symbol_hash(name) % HASH_BUCKETS; - int n_type = ELFW(ST_TYPE)(info); - int n_binding = ELFW(ST_BIND)(info); - - for (sym = f->symtab[hash]; sym; sym = sym->next) - if (f->symbol_cmp(sym->name, name) == 0) - { - int o_secidx = sym->secidx; - int o_info = sym->info; - int o_type = ELFW(ST_TYPE)(o_info); - int o_binding = ELFW(ST_BIND)(o_info); - - /* A redefinition! Is it legal? */ - - if (secidx == SHN_UNDEF) - return sym; - else if (o_secidx == SHN_UNDEF) - goto found; - else if (n_binding == STB_GLOBAL && o_binding == STB_LOCAL) - { - /* Cope with local and global symbols of the same name - in the same object file, as might have been created - by ld -r. The only reason locals are now seen at this - level at all is so that we can do semi-sensible things - with parameters. */ - - struct obj_symbol *nsym, **p; - - nsym = arch_new_symbol(); - nsym->next = sym->next; - nsym->ksymidx = -1; - - /* Excise the old (local) symbol from the hash chain. */ - for (p = &f->symtab[hash]; *p != sym; p = &(*p)->next) - continue; - *p = sym = nsym; - goto found; - } - else if (n_binding == STB_LOCAL) - { - /* Another symbol of the same name has already been defined. - Just add this to the local table. */ - sym = arch_new_symbol(); - sym->next = NULL; - sym->ksymidx = -1; - f->local_symtab[symidx] = sym; - goto found; - } - else if (n_binding == STB_WEAK) - return sym; - else if (o_binding == STB_WEAK) - goto found; - /* Don't unify COMMON symbols with object types the programmer - doesn't expect. */ - else if (secidx == SHN_COMMON - && (o_type == STT_NOTYPE || o_type == STT_OBJECT)) - return sym; - else if (o_secidx == SHN_COMMON - && (n_type == STT_NOTYPE || n_type == STT_OBJECT)) - goto found; - else - { - /* Don't report an error if the symbol is coming from - the kernel or some external module. */ - if (secidx <= SHN_HIRESERVE) - error("%s multiply defined", name); - return sym; - } - } - - /* Completely new symbol. */ - sym = arch_new_symbol(); - sym->next = f->symtab[hash]; - f->symtab[hash] = sym; - sym->ksymidx = -1; - - if (ELFW(ST_BIND)(info) == STB_LOCAL && symidx != -1) { - if (symidx >= f->local_symtab_size) - error("local symbol %s with index %ld exceeds local_symtab_size %ld", - name, (long) symidx, (long) f->local_symtab_size); - else - f->local_symtab[symidx] = sym; - } - -found: - sym->name = name; - sym->value = value; - sym->size = size; - sym->secidx = secidx; - sym->info = info; - sym->r_type = 0; /* should be R_arch_NONE for all arch */ - - return sym; -} - -struct obj_symbol * -obj_find_symbol (struct obj_file *f, const char *name) -{ - struct obj_symbol *sym; - unsigned long hash = f->symbol_hash(name) % HASH_BUCKETS; - - for (sym = f->symtab[hash]; sym; sym = sym->next) - if (f->symbol_cmp(sym->name, name) == 0) - return sym; - - return NULL; -} - -ElfW(Addr) -obj_symbol_final_value (struct obj_file *f, struct obj_symbol *sym) -{ - if (sym) - { - if (sym->secidx >= SHN_LORESERVE) - return sym->value; - - return sym->value + f->sections[sym->secidx]->header.sh_addr; - } - else - { - /* As a special case, a NULL sym has value zero. */ - return 0; - } -} - -struct obj_section * -obj_find_section (struct obj_file *f, const char *name) -{ - int i, n = f->header.e_shnum; - - for (i = 0; i < n; ++i) - if (strcmp(f->sections[i]->name, name) == 0) - return f->sections[i]; - - return NULL; -} - -#if defined (ARCH_alpha) -#define ARCH_SHF_SHORT SHF_ALPHA_GPREL -#elif defined (ARCH_ia64) -#define ARCH_SHF_SHORT SHF_IA_64_SHORT -#else -#define ARCH_SHF_SHORT 0 -#endif - -static int -obj_load_order_prio(struct obj_section *a) -{ - unsigned long af, ac; - - af = a->header.sh_flags; - - ac = 0; - if (a->name[0] != '.' - || strlen(a->name) != 10 - || strcmp(a->name + 5, ".init")) - ac |= 64; - if (af & SHF_ALLOC) ac |= 32; - if (af & SHF_EXECINSTR) ac |= 16; - if (!(af & SHF_WRITE)) ac |= 8; - if (a->header.sh_type != SHT_NOBITS) ac |= 4; - /* Desired order is - P S AC & 7 - .data 1 0 4 - .got 1 1 3 - .sdata 1 1 1 - .sbss 0 1 1 - .bss 0 0 0 */ - if (strcmp (a->name, ".got") == 0) ac |= 2; - if (af & ARCH_SHF_SHORT) - ac = (ac & ~4) | 1; - - return ac; -} - -void -obj_insert_section_load_order (struct obj_file *f, struct obj_section *sec) -{ - struct obj_section **p; - int prio = obj_load_order_prio(sec); - for (p = f->load_order_search_start; *p ; p = &(*p)->load_next) - if (obj_load_order_prio(*p) < prio) - break; - sec->load_next = *p; - *p = sec; -} - -struct obj_section * -obj_create_alloced_section (struct obj_file *f, const char *name, - unsigned long align, unsigned long size, - unsigned long flags) -{ - int newidx = f->header.e_shnum++; - struct obj_section *sec; - - f->sections = xrealloc(f->sections, (newidx+1) * sizeof(sec)); - f->sections[newidx] = sec = arch_new_section(); - - memset(sec, 0, sizeof(*sec)); - sec->header.sh_type = SHT_PROGBITS; - sec->header.sh_flags = flags | SHF_ALLOC; - sec->header.sh_size = size; - sec->header.sh_addralign = align; - sec->name = name; - sec->idx = newidx; - if (size) - sec->contents = xmalloc(size); - - obj_insert_section_load_order(f, sec); - - return sec; -} - -struct obj_section * -obj_create_alloced_section_first (struct obj_file *f, const char *name, - unsigned long align, unsigned long size) -{ - int newidx = f->header.e_shnum++; - struct obj_section *sec; - - f->sections = xrealloc(f->sections, (newidx+1) * sizeof(sec)); - f->sections[newidx] = sec = arch_new_section(); - - memset(sec, 0, sizeof(*sec)); - sec->header.sh_type = SHT_PROGBITS; - sec->header.sh_flags = SHF_WRITE|SHF_ALLOC; - sec->header.sh_size = size; - sec->header.sh_addralign = align; - sec->name = name; - sec->idx = newidx; - if (size) - sec->contents = xmalloc(size); - - sec->load_next = f->load_order; - f->load_order = sec; - if (f->load_order_search_start == &f->load_order) - f->load_order_search_start = &sec->load_next; - - return sec; -} - -void * -obj_extend_section (struct obj_section *sec, unsigned long more) -{ - unsigned long oldsize = sec->header.sh_size; - sec->contents = xrealloc(sec->contents, sec->header.sh_size += more); - return sec->contents + oldsize; -} - -/* Convert an object pointer (address) to a native pointer and vice versa. - * It gets interesting when the object has 64 bit pointers but modutils - * is running 32 bit. This is nasty code but it stops the compiler giving - * spurious warning messages. "I know what I am doing" ... - */ - -void * -obj_addr_to_native_ptr (ElfW(Addr) addr) -{ - unsigned int convert = (sizeof(void *) << 8) + sizeof(addr); /* to, from */ - union obj_ptr_4 p4; - union obj_ptr_8 p8; - switch (convert) { - case 0x0404: - p4.addr = addr; - return(p4.ptr); - break; - case 0x0408: - p4.addr = addr; - if (p4.addr != addr) { - error("obj_addr_to_native_ptr truncation %" tgt_long_fmt "x", - (tgt_long) addr); - exit(1); - } - return(p4.ptr); - break; - case 0x0804: - p8.addr = addr; - return(p8.ptr); - break; - case 0x0808: - p8.addr = addr; - return(p8.ptr); - break; - default: - error("obj_addr_to_native_ptr unknown conversion 0x%04x", convert); - exit(1); - } -} - -ElfW(Addr) -obj_native_ptr_to_addr (void *ptr) -{ - unsigned int convert = (sizeof(ElfW(Addr)) << 8) + sizeof(ptr); /* to, from */ - union obj_ptr_4 p4; - union obj_ptr_8 p8; - switch (convert) { - case 0x0404: - p4.ptr = ptr; - return(p4.addr); - break; - case 0x0408: - p8.ptr = ptr; - p4.addr = p8.addr; - if (p4.addr != p8.addr) { - error("obj_native_ptr_to_addr truncation %" tgt_long_fmt "x", - (tgt_long) p8.addr); - exit(1); - } - return(p4.addr); - break; - case 0x0804: - p4.ptr = ptr; - return(p4.addr); /* compiler expands to 8 */ - break; - case 0x0808: - p8.ptr = ptr; - return(p8.addr); - break; - default: - error("obj_native_ptr_to_addr unknown conversion 0x%04x", convert); - exit(1); - } -} diff --git a/mdk-stage1/insmod-modutils/obj/obj_hppa.c b/mdk-stage1/insmod-modutils/obj/obj_hppa.c deleted file mode 100644 index a6f703c5d..000000000 --- a/mdk-stage1/insmod-modutils/obj/obj_hppa.c +++ /dev/null @@ -1,638 +0,0 @@ -/* - * PA-RISC specific support for Elf loading and relocation. - * Copyright 2000 David Huggins-Daines <dhd@linuxcare.com>, Linuxcare Inc. - * Copyright 2000 Richard Hirst <rhirst@linuxcare.com>, Linuxcare Inc. - * - * Based on the IA-64 support, which is: - * Copyright 2000 Mike Stephens <mike.stephens@intel.com> - * - * This file is part of the Linux modutils. - * - * This program is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License as published by the - * Free Software Foundation; either version 2 of the License, or (at your - * option) any later version. - * - * This program is distributed in the hope that it will be useful, but - * WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software Foundation, - * Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. - */ - -#include <stdlib.h> -#include <string.h> -#include <assert.h> - -#include <module.h> -#include <obj.h> -#include <util.h> -#include <modstat.h> /* For ksyms */ - - -typedef struct _hppa_stub_t -{ - struct _hppa_stub_t *next; - int offset; - int reloc_done; -} hppa_stub_t; - -typedef struct _hppa_symbol_t -{ - struct obj_symbol root; - hppa_stub_t *stub; -} hppa_symbol_t; - -typedef struct _hppa_file_t -{ - struct obj_file root; - struct obj_section *stub; - Elf32_Addr dp; -} hppa_file_t; - -/* The ABI defines various more esoteric types, but these are the only - ones we actually need. */ -enum hppa_fsel -{ - e_fsel, - e_lsel, - e_rsel, - e_lrsel, - e_rrsel -}; - -struct obj_file * -arch_new_file (void) -{ - hppa_file_t *f; - f = xmalloc(sizeof(*f)); - f->stub = NULL; - return &f->root; -} - -struct obj_section * -arch_new_section (void) -{ - return xmalloc(sizeof(struct obj_section)); -} - -struct obj_symbol * -arch_new_symbol (void) -{ - hppa_symbol_t *sym; - sym = xmalloc(sizeof(*sym)); - sym->stub = NULL; - return &sym->root; -} - -/* This is called for architecture specific sections we might need to - do special things to. */ -int -arch_load_proc_section(struct obj_section *sec, int fp) -{ - /* Assume it's just a debugging section that we can safely - ignore ... */ - sec->contents = NULL; - - return 0; -} - -/* ================================================================= - - These functions are from libhppa.h in the GNU BFD library. - (c) 1990, 91, 92, 93, 94, 95, 96, 98, 99, 2000 - Free Software Foundation, Inc. - - ================================================================= */ - -/* The *sign_extend functions are used to assemble various bitfields - taken from an instruction and return the resulting immediate - value. */ - -static inline int -sign_extend (x, len) - int x, len; -{ - int signbit = (1 << (len - 1)); - int mask = (signbit << 1) - 1; - return ((x & mask) ^ signbit) - signbit; -} - -static inline int -low_sign_extend (x, len) - int x, len; -{ - return (x >> 1) - ((x & 1) << (len - 1)); -} - - -/* The re_assemble_* functions prepare an immediate value for - insertion into an opcode. pa-risc uses all sorts of weird bitfields - in the instruction to hold the value. */ - -static inline int -sign_unext (x, len) - int x, len; -{ - int len_ones; - - len_ones = (1 << len) - 1; - - return x & len_ones; -} - -static inline int -low_sign_unext (x, len) - int x, len; -{ - int temp; - int sign; - - sign = (x >> (len-1)) & 1; - - temp = sign_unext (x, len-1); - - return (temp << 1) | sign; -} - -static inline int -re_assemble_3 (as3) - int as3; -{ - return (( (as3 & 4) << (13-2)) - | ((as3 & 3) << (13+1))); -} - -static inline int -re_assemble_12 (as12) - int as12; -{ - return (( (as12 & 0x800) >> 11) - | ((as12 & 0x400) >> (10 - 2)) - | ((as12 & 0x3ff) << (1 + 2))); -} - -static inline int -re_assemble_14 (as14) - int as14; -{ - return (( (as14 & 0x1fff) << 1) - | ((as14 & 0x2000) >> 13)); -} - -static inline int -re_assemble_16 (as16) - int as16; -{ - int s, t; - - /* Unusual 16-bit encoding, for wide mode only. */ - t = (as16 << 1) & 0xffff; - s = (as16 & 0x8000); - return (t ^ s ^ (s >> 1)) | (s >> 15); -} - -static inline int -re_assemble_17 (as17) - int as17; -{ - return (( (as17 & 0x10000) >> 16) - | ((as17 & 0x0f800) << (16 - 11)) - | ((as17 & 0x00400) >> (10 - 2)) - | ((as17 & 0x003ff) << (1 + 2))); -} - -static inline int -re_assemble_21 (as21) - int as21; -{ - return (( (as21 & 0x100000) >> 20) - | ((as21 & 0x0ffe00) >> 8) - | ((as21 & 0x000180) << 7) - | ((as21 & 0x00007c) << 14) - | ((as21 & 0x000003) << 12)); -} - -static inline int -re_assemble_22 (as22) - int as22; -{ - return (( (as22 & 0x200000) >> 21) - | ((as22 & 0x1f0000) << (21 - 16)) - | ((as22 & 0x00f800) << (16 - 11)) - | ((as22 & 0x000400) >> (10 - 2)) - | ((as22 & 0x0003ff) << (1 + 2))); -} - - -/* Handle field selectors for PA instructions. - The L and R (and LS, RS etc.) selectors are used in pairs to form a - full 32 bit address. eg. - - LDIL L'start,%r1 ; put left part into r1 - LDW R'start(%r1),%r2 ; add r1 and right part to form address - - This function returns sign extended values in all cases. -*/ - -static inline unsigned int -hppa_field_adjust (value, addend, r_field) - unsigned int value; - int addend; - enum hppa_fsel r_field; -{ - unsigned int sym_val; - - sym_val = value - addend; - switch (r_field) - { - case e_fsel: - /* F: No change. */ - break; - - case e_lsel: - /* L: Select top 21 bits. */ - value = value >> 11; - break; - - case e_rsel: - /* R: Select bottom 11 bits. */ - value = value & 0x7ff; - break; - - case e_lrsel: - /* LR: L with rounding of the addend to nearest 8k. */ - value = sym_val + ((addend + 0x1000) & -0x2000); - value = value >> 11; - break; - - case e_rrsel: - /* RR: R with rounding of the addend to nearest 8k. - We need to return a value such that 2048 * LR'x + RR'x == x - ie. RR'x = s+a - (s + (((a + 0x1000) & -0x2000) & -0x800)) - . = s+a - ((s & -0x800) + ((a + 0x1000) & -0x2000)) - . = (s & 0x7ff) + a - ((a + 0x1000) & -0x2000) */ - value = (sym_val & 0x7ff) + (((addend & 0x1fff) ^ 0x1000) - 0x1000); - break; - - default: - abort(); - } - return value; -} - -/* Insert VALUE into INSN using R_FORMAT to determine exactly what - bits to change. */ - -static inline int -hppa_rebuild_insn (insn, value, r_format) - int insn; - int value; - int r_format; -{ - switch (r_format) - { - case 11: - return (insn & ~ 0x7ff) | low_sign_unext (value, 11); - - case 12: - return (insn & ~ 0x1ffd) | re_assemble_12 (value); - - - case 10: - return (insn & ~ 0x3ff1) | re_assemble_14 (value & -8); - - case -11: - return (insn & ~ 0x3ff9) | re_assemble_14 (value & -4); - - case 14: - return (insn & ~ 0x3fff) | re_assemble_14 (value); - - - case -10: - return (insn & ~ 0xfff1) | re_assemble_16 (value & -8); - - case -16: - return (insn & ~ 0xfff9) | re_assemble_16 (value & -4); - - case 16: - return (insn & ~ 0xffff) | re_assemble_16 (value); - - - case 17: - return (insn & ~ 0x1f1ffd) | re_assemble_17 (value); - - case 21: - return (insn & ~ 0x1fffff) | re_assemble_21 (value); - - case 22: - return (insn & ~ 0x3ff1ffd) | re_assemble_22 (value); - - case 32: - return value; - - default: - abort (); - } - return insn; -} - -/* ==================================================================== - - End of functions from GNU BFD. - - ==================================================================== */ - -/* This is where we get the opportunity to create any extra dynamic - sections we might need. In our case we do not need a GOT because - our code is not PIC, but we do need to create a stub section. - - This is significantly less complex than what we do for shared - libraries because, obviously, modules are not shared. Also we have - no issues related to symbol visibility, lazy linking, etc. - The kernels dp is fixed (at symbol $global$), and we can fix up any - DPREL refs in the module to use that same dp value. - All PCREL* refs result in a stub with the following format: - - ldil L'func_addr,%r1 - be,n R'func_addr(%sr4,%r1) - - Note, all PCREL* get a stub, regardless of whether they are - local or external. With local ones, and external ones to other - modules, there is a good chance we could manage without the stub. - I'll leave that for a future optimisation. - */ - -#define LDIL_R1 0x20200000 /* ldil L'XXX,%r1 */ -#define BE_N_SR4_R1 0xe0202002 /* be,n R'XXX(%sr4,%r1) */ - -#define STUB_SIZE 8 - -int -arch_create_got(struct obj_file *f) -{ - hppa_file_t *hfile = (hppa_file_t *)f; - int i, n; - int stub_offset = 0; - - /* Create stub section. - * XXX set flags, see obj_ia64.c - */ - hfile->stub = obj_create_alloced_section(f, ".stub", STUB_SIZE, - 0, SHF_WRITE); - - /* Actually this is a lot like check_relocs() in a BFD backend. We - walk all sections and all their relocations and look for ones - that need special treatment. */ - n = hfile->root.header.e_shnum; - for (i = 0; i < n; ++i) - { - struct obj_section *relsec, *symsec, *strsec; - Elf32_Rela *rel, *relend; - Elf32_Sym *symtab; - char const *strtab; - - relsec = hfile->root.sections[i]; - if (relsec->header.sh_type != SHT_RELA) - continue; - - symsec = hfile->root.sections[relsec->header.sh_link]; - strsec = hfile->root.sections[symsec->header.sh_link]; - - rel = (Elf32_Rela *)relsec->contents; - relend = rel + (relsec->header.sh_size / sizeof(Elf32_Rela)); - symtab = (Elf32_Sym *)symsec->contents; - strtab = (char const *)strsec->contents; - - for (; rel < relend; rel++) - { - int need_stub = 0; - - switch (ELF32_R_TYPE(rel->r_info)) - { - default: - continue; - - case R_PARISC_PCREL17F: - case R_PARISC_PCREL22F: - need_stub = 1; - break; - } - - if (need_stub) - { - hppa_symbol_t *hsym; - int local; - - obj_find_relsym(hsym, f, f, rel, symtab, strtab); - local = hsym->root.secidx <= SHN_HIRESERVE; - - if (need_stub) - { - hppa_stub_t *stub; - - if (hsym->stub == NULL) - { - stub = (hppa_stub_t *) xmalloc(sizeof(hppa_stub_t)); - stub->offset = stub_offset; - stub->reloc_done = 0; - hsym->stub = stub; - stub_offset += STUB_SIZE; - need_stub = 0; - } - } - } - } - } - if (stub_offset) - { - hfile->stub->contents = xmalloc(stub_offset); - hfile->stub->header.sh_size = stub_offset; - } - return 1; -} - - -enum obj_reloc -arch_apply_relocation(struct obj_file *f, - struct obj_section *targsec, - struct obj_section *symsec, - struct obj_symbol *sym, - Elf32_Rela *rel, - Elf32_Addr v) -{ - hppa_file_t *hfile = (hppa_file_t *) f; - hppa_symbol_t *hsym = (hppa_symbol_t *) sym; - - Elf32_Addr *loc = (Elf32_Addr *)(targsec->contents + rel->r_offset); - Elf32_Addr dot = (targsec->header.sh_addr + rel->r_offset) & ~0x03; - Elf32_Addr dp = hfile->dp; - Elf32_Word r_info = ELF32_R_TYPE(rel->r_info); - - enum obj_reloc ret = obj_reloc_ok; - enum hppa_fsel fsel = e_fsel; /* Avoid compiler warning */ - unsigned int r_format; - - /* Fix up the value, and determine whether we can handle this - relocation. */ - switch (r_info) - { - case R_PARISC_PLABEL32: - case R_PARISC_DIR32: - case R_PARISC_DIR21L: - case R_PARISC_DIR14R: - /* Easy. */ - break; - - case R_PARISC_SEGREL32: - v -= f->baseaddr; - break; - - case R_PARISC_DPREL21L: - case R_PARISC_DPREL14R: - v -= dp; - break; - - case R_PARISC_PCREL17F: - case R_PARISC_PCREL22F: - /* Find an import stub. */ - assert(hsym->stub != NULL); - assert(hfile->stub != NULL); - /* XXX Optimise. We may not need a stub for short branches */ - if (!hsym->stub->reloc_done) { - /* Need to create the .stub entry */ - Elf32_Addr *pstub, stubv; - - pstub = (Elf32_Addr *)(hfile->stub->contents + hsym->stub->offset); - pstub[0] = LDIL_R1; - pstub[1] = BE_N_SR4_R1; - stubv = hppa_field_adjust(v, rel->r_addend, e_lrsel); - pstub[0] = hppa_rebuild_insn(pstub[0], stubv, 21); - stubv = hppa_field_adjust(v, rel->r_addend, e_rrsel); - stubv >>= 2; /* Branch; divide by 4 */ - pstub[1] = hppa_rebuild_insn(pstub[1], stubv, 17); - hsym->stub->reloc_done = 1; - } - v = hsym->stub->offset + hfile->stub->header.sh_addr; - break; - - default: - return obj_reloc_unhandled; - } - - /* Find the field selector. */ - switch (r_info) - { - case R_PARISC_DIR32: - case R_PARISC_PLABEL32: - case R_PARISC_PCREL17F: - case R_PARISC_SEGREL32: - case R_PARISC_PCREL22F: - fsel = e_fsel; - break; - - case R_PARISC_DPREL21L: - case R_PARISC_DIR21L: - fsel = e_lrsel; - break; - - case R_PARISC_DPREL14R: - case R_PARISC_DIR14R: - fsel = e_rrsel; - break; - } - - v = hppa_field_adjust(v, rel->r_addend, fsel); - - switch (r_info) - { - case R_PARISC_PCREL17F: - case R_PARISC_PCREL17R: - case R_PARISC_PCREL22F: - v = v - dot - 8; - case R_PARISC_DIR17F: - case R_PARISC_DIR17R: - /* This is a branch. Divide the offset by four. */ - v >>= 2; - break; - default: - break; - } - - /* Find the format. */ - switch (r_info) - { - case R_PARISC_DIR32: - case R_PARISC_PLABEL32: - case R_PARISC_SEGREL32: - r_format = 32; - break; - - case R_PARISC_DPREL21L: - case R_PARISC_DIR21L: - r_format = 21; - break; - - case R_PARISC_PCREL17F: - r_format = 17; - break; - - case R_PARISC_DPREL14R: - case R_PARISC_DIR14R: - r_format = 14; - break; - - case R_PARISC_PCREL22F: - r_format = 22; - break; - - default: - abort(); - } - - *loc = hppa_rebuild_insn(*loc, v, r_format); - - return ret; -} - -int -arch_init_module (struct obj_file *f, struct module *mod) -{ - return 1; -} - -int -arch_finalize_section_address(struct obj_file *f, Elf32_Addr base) -{ - int i, n = f->header.e_shnum; - - f->baseaddr = base; - for (i = 0; i < n; ++i) - f->sections[i]->header.sh_addr += base; - return 1; -} - -int -arch_archdata (struct obj_file *f, struct obj_section *sec) -{ - struct module_symbol *s; - int i; - hppa_file_t *hfile = (hppa_file_t *)f; - - /* Initialise dp to the kernels dp (symbol $global$) - */ - for (i = 0, s = ksyms; i < nksyms; i++, s++) - if (!strcmp((char *)s->name, "$global$")) - break; - if (i >= nksyms) { - error("Cannot initialise dp, '$global$' not found\n"); - return 1; - } - hfile->dp = s->value; - - return 0; -} - diff --git a/mdk-stage1/insmod-modutils/obj/obj_hppa64.c b/mdk-stage1/insmod-modutils/obj/obj_hppa64.c deleted file mode 100644 index d9f1ada9d..000000000 --- a/mdk-stage1/insmod-modutils/obj/obj_hppa64.c +++ /dev/null @@ -1,682 +0,0 @@ -/* - * hppa parisc64 specific support for Elf loading and relocation. - * Copyright 2000 Richard Hirst <rhirst@linuxcare.com>, Linuxcare Inc. - * - * Based on ia64 specific support which was - * Copyright 2000 Mike Stephens <mike.stephens@intel.com> - * - * This file is part of the Linux modutils. - * - * This program is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License as published by the - * Free Software Foundation; either version 2 of the License, or (at your - * option) any later version. - * - * This program is distributed in the hope that it will be useful, but - * WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software Foundation, - * Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. - */ - -#include <string.h> -#include <assert.h> -#include <stdlib.h> - -#include <module.h> -#include <obj.h> -#include <util.h> - -#ifndef FALSE -#define FALSE 0 -#endif -#ifndef TRUE -#define TRUE ~FALSE -#endif - -/*======================================================================*/ - -typedef struct _hppa64_opd_t -{ - int offset; - int reloc_done; -} hppa64_opd_t; - -typedef struct _hppa64_stub_t -{ - struct _hppa64_stub_t *next; - Elf64_Addr addend; - int offset; - int reloc_done; -} hppa64_stub_t; - -typedef struct _hppa64_got_t -{ - struct _hppa64_got_t *next; - Elf64_Addr addend; - int offset; - int reloc_done; -} hppa64_got_t; - -typedef struct _hppa64_symbol_t -{ - struct obj_symbol root; - hppa64_got_t *gotent; - hppa64_opd_t *opdent; - hppa64_stub_t *stubent; -} hppa64_symbol_t; - -typedef struct _hppa64_file_t -{ - struct obj_file root; - struct obj_section *got; - struct obj_section *opd; - struct obj_section *stub; - Elf64_Addr gp; - Elf64_Addr text; - Elf64_Addr data; - Elf64_Addr bss; -} hppa64_file_t; - -/* - * XXX This stub assumes it can reach the .got entry with a +/- 8K offset - * from dp. Perhaps we should use a .plt for these entries to give a - * greater chance of that being true. - * - * 53 7b 00 00 ldd 0(dp),dp - * R_PARISC_LTOFF14R <.got entry offset from dp> - * 53 61 00 20 ldd 10(dp),r1 - * e8 20 d0 00 bve (r1) - * 53 7b 00 30 ldd 18(dp),dp - * - * We need a different stub for millicode calls, which doesn't depend on - * or modify dp: - * - * 20 20 00 00 ldil 0,r1 - * R_PARISC_DIR21L <addr of kernels opd entry> - * 34 21 00 00 ldo 0(r1),r1 - * R_PARISC_DIR14R <addr of kernels opd entry> - * 50 21 00 20 ldd 10(r1),r1 - * e8 20 d0 02 bve,n (r1) - */ - -/* NOTE: to keep the code cleaner we make all stubs the same size. - */ - -#define SIZEOF_STUB 16 - -unsigned char hppa64_stub_extern[] = -{ - 0x53, 0x7b, 0x00, 0x00, - 0x53, 0x61, 0x00, 0x20, - 0xe8, 0x20, 0xd0, 0x00, - 0x53, 0x7b, 0x00, 0x30, -}; - -unsigned char hppa64_stub_millicode[] = -{ - 0x20, 0x20, 0x00, 0x00, - 0x34, 0x21, 0x00, 0x00, - 0x50, 0x21, 0x00, 0x20, - 0xe8, 0x20, 0xd0, 0x02, -}; - -/*======================================================================*/ - -enum obj_reloc -patch_14r(Elf64_Xword v64, Elf64_Word *p) -{ - Elf64_Word i = *p; - Elf64_Word v = (Elf64_Word)v64; - - if (v & 0x80000000) - v |= ~0x7ff; - else - v &= 0x7ff; - i &= ~ 0x3fff; - i |= (v & 0x1fff) << 1 | - (v & 0x2000) >> 13; - *p = i; - - return obj_reloc_ok; -} - -enum obj_reloc -patch_21l(Elf64_Xword v64, Elf64_Word *p) -{ - Elf64_Word i = *p; - Elf64_Word v = (Elf64_Word)v64; - - v &= 0xfffff800; - if (v & 0x80000000) - v += 0x800; - i &= ~ 0x1fffff; - i |= (v & 0x80000000) >> 31 | - (v & 0x7ff00000) >> 19 | - (v & 0x000c0000) >> 4 | - (v & 0x0003e000) << 3 | - (v & 0x00001800) << 1; - *p = i; - - return obj_reloc_ok; -} - - -/* All 14 bits this time... This is used to patch the .got offset in - * a stub for PCREL22F. - */ - -enum obj_reloc -patch_14r2(Elf64_Xword v64, Elf64_Word *p) -{ - Elf64_Word i = *p; - Elf64_Word v = (Elf64_Word)v64; - - if ((Elf64_Sxword)v64 > 0x1fffL || - (Elf64_Sxword)v64 < -0x2000L) - return obj_reloc_overflow; - i &= ~ 0x3fff; - i |= (v & 0x2000) >> 13 | - (v & 0x1fff) << 1; - *p = i; - - return obj_reloc_ok; -} - - -enum obj_reloc -patch_22f(Elf64_Xword v64, Elf64_Word *p) -{ - Elf64_Word i = *p; - Elf64_Word v = (Elf64_Word)v64; - - if ((Elf64_Sxword)v64 > 0x800000-1 || - (Elf64_Sxword)v64 < -0x800000) - return obj_reloc_overflow; - - i &= ~ 0x03ff1ffd; - i |= (v & 0x00800000) >> 23 | - (v & 0x007c0000) << 3 | - (v & 0x0003e000) << 3 | - (v & 0x00001000) >> 10 | - (v & 0x00000ffc) << 1; - *p = i; - - return obj_reloc_ok; -} - - -struct obj_section * -obj_hppa64_create_alloced_section (struct obj_file *f, const char *name, - unsigned long align, unsigned long size, unsigned long sh_flags) -{ - int newidx = f->header.e_shnum++; - struct obj_section *sec; - - f->sections = xrealloc(f->sections, (newidx+1) * sizeof(sec)); - f->sections[newidx] = sec = arch_new_section(); - - memset(sec, 0, sizeof(*sec)); - sec->header.sh_type = SHT_PROGBITS; - sec->header.sh_flags = sh_flags; - sec->header.sh_size = size; - sec->header.sh_addralign = align; - sec->name = name; - sec->idx = newidx; - if (size) - sec->contents = xmalloc(size); - - obj_insert_section_load_order(f, sec); - - return sec; -} - -/*======================================================================*/ - -struct obj_file * -arch_new_file (void) -{ - hppa64_file_t *f; - f = xmalloc(sizeof(*f)); - f->got = NULL; - f->opd = NULL; - f->stub = NULL; - return &f->root; -} - -struct obj_section * -arch_new_section (void) -{ - return xmalloc(sizeof(struct obj_section)); -} - -struct obj_symbol * -arch_new_symbol (void) -{ - hppa64_symbol_t *sym; - sym = xmalloc(sizeof(*sym)); - sym->gotent = NULL; - sym->opdent = NULL; - sym->stubent = NULL; - return &sym->root; -} - -/* This may not be needed, but does no harm (copied from ia64). - */ - -int -arch_load_proc_section(struct obj_section *sec, int fp) -{ - switch (sec->header.sh_type) - { - case SHT_PARISC_EXT : - sec->contents = NULL; - break; - - case SHT_PARISC_UNWIND : - if (sec->header.sh_size > 0) - { - sec->contents = xmalloc(sec->header.sh_size); - gzf_lseek(fp, sec->header.sh_offset, SEEK_SET); - if (gzf_read(fp, sec->contents, sec->header.sh_size) != sec->header.sh_size) - { - error("error reading ELF section data: %m"); - return -1; - } - } - else - sec->contents = NULL; - break; - default: - error("Unknown section header type: %08x", sec->header.sh_type); - return -1; - } - return 0; -} - -int -arch_create_got(struct obj_file *f) -{ - hppa64_file_t *hfile = (hppa64_file_t *)f; - int i; - int n; - int got_offset = 0; - int opd_offset = 64; - int stub_offset = 0; - - n = hfile->root.header.e_shnum; - for (i = 0; i < n; ++i) - { - struct obj_section *relsec, *symsec, *strsec; - Elf64_Rela *rel, *relend; - Elf64_Sym *symtab; - const char *strtab; - - relsec = hfile->root.sections[i]; - if (relsec->header.sh_type != SHT_RELA) - continue; - - symsec = hfile->root.sections[relsec->header.sh_link]; - strsec = hfile->root.sections[symsec->header.sh_link]; - - rel = (Elf64_Rela *)relsec->contents; - relend = rel + (relsec->header.sh_size / sizeof(Elf64_Rela)); - symtab = (Elf64_Sym *)symsec->contents; - strtab = (const char *)strsec->contents; - - for (; rel < relend; ++rel) - { - int need_got = FALSE; - int need_opd = FALSE; - int need_stub = FALSE; - - switch (ELF64_R_TYPE(rel->r_info)) - { - default: - { - unsigned r_info = ELF64_R_TYPE(rel->r_info); - printf("r_info 0x%x not handled\n", r_info); - } - continue; - case R_PARISC_LTOFF14R: - case R_PARISC_LTOFF21L: - /* These are simple indirect references to symbols through the - * DLT. We need to create a DLT entry for any symbols which - * appears in a DLTIND relocation. - */ - need_got = TRUE; - break; - case R_PARISC_PCREL22F: - /* These are function calls. Depending on their precise - * target we may need to make a stub for them. The stub - * uses the dlt, so we need to create dlt entries for - * these symbols too. - */ - need_got = TRUE; - need_stub = TRUE; - break; - case R_PARISC_DIR64: - case R_PARISC_SEGREL32: - break; - case R_PARISC_FPTR64: - /* This is a simple OPD entry (only created for local symbols, - * see below). - */ - need_opd = TRUE; - break; - } - - if (need_got || need_opd || need_stub) - { - hppa64_symbol_t *isym; - int local; - - obj_find_relsym(isym, f, f, rel, symtab, strtab); - local = isym->root.secidx <= SHN_HIRESERVE; - - if (need_stub) - { - hppa64_stub_t *stub; - - for (stub = isym->stubent; stub != NULL; stub = stub->next) - if (stub->addend == rel->r_addend) - break; - if (stub == NULL) - { - stub = (hppa64_stub_t *) xmalloc(sizeof(hppa64_stub_t)); - stub->next = isym->stubent; - stub->addend = rel->r_addend; - stub->offset = stub_offset; - stub->reloc_done = FALSE; - isym->stubent = stub; - { - stub_offset += SIZEOF_STUB; - } - need_stub = FALSE; - } - } - if (need_got) - { - hppa64_got_t *got; - - for (got = isym->gotent; got != NULL; got = got->next) - if (got->addend == rel->r_addend) - break; - if (got == NULL) - { - got = (hppa64_got_t *) xmalloc(sizeof(hppa64_got_t)); - got->next = isym->gotent; - got->addend = rel->r_addend; - got->offset = got_offset; - got->reloc_done = FALSE; - isym->gotent = got; - got_offset += 8; - need_got = FALSE; - } - } - if (need_opd && local) - { - hppa64_opd_t *opd; - - if (isym->opdent == NULL) - { - opd = (hppa64_opd_t *) xmalloc(sizeof(hppa64_opd_t)); - opd->offset = opd_offset; - opd->reloc_done = FALSE; - isym->opdent = opd; - opd_offset += 32; - need_opd = FALSE; - } - } - } - } - } - - hfile->got = obj_hppa64_create_alloced_section(f, ".got", 8, got_offset, - (SHF_ALLOC | SHF_WRITE | SHF_PARISC_SHORT)); - assert(hfile->got != NULL); - - hfile->opd = obj_hppa64_create_alloced_section(f, ".opd", 16, opd_offset, - (SHF_ALLOC | SHF_WRITE | SHF_PARISC_SHORT)); - assert(hfile->opd != NULL); - - if (stub_offset > 0) - { - hfile->stub = obj_hppa64_create_alloced_section(f, ".stub", 16, - stub_offset, (SHF_ALLOC | SHF_EXECINSTR | SHF_PARISC_SHORT)); - assert(hfile->stub != NULL); - } - - return 1; -} - - -/* This is a small simple version which seems to work fine. ia64 has - * a much more complex algorithm. We point dp at the end of the .got, - * which is the start of the .opd. - */ - -int -arch_finalize_section_address(struct obj_file *f, Elf64_Addr base) -{ - hppa64_file_t *hfile = (hppa64_file_t *)f; - int n = f->header.e_shnum; - int i; - - f->baseaddr = base; - for (i = 0; i < n; ++i) - f->sections[i]->header.sh_addr += base; - - /* Pick a sensible value for gp */ - hfile->gp = hfile->got->header.sh_addr + hfile->got->header.sh_size; - - return 1; -} - - -enum obj_reloc -arch_apply_relocation(struct obj_file *f, - struct obj_section *targsec, - struct obj_section *symsec, - struct obj_symbol *sym, - Elf64_Rela *rel, - Elf64_Addr v) -{ - hppa64_file_t *hfile = (hppa64_file_t *) f; - hppa64_symbol_t *isym = (hppa64_symbol_t *) sym; - - Elf64_Word *loc = (Elf64_Word *)(targsec->contents + rel->r_offset); - Elf64_Addr dot = (targsec->header.sh_addr + rel->r_offset) & ~0x03; - - Elf64_Addr got = hfile->got->header.sh_addr; - Elf64_Addr gp = hfile->gp; - - Elf64_Xword r_info = ELF64_R_TYPE(rel->r_info); - - enum obj_reloc ret = obj_reloc_ok; - - switch (r_info) - { - default: - ret = obj_reloc_unhandled; - break; - case R_PARISC_LTOFF14R: - case R_PARISC_LTOFF21L: - { - hppa64_got_t *ge; - - assert(isym != NULL); - for (ge = isym->gotent; ge != NULL && ge->addend != rel->r_addend; ) - ge = ge->next; - assert(ge != NULL); - if (!ge->reloc_done) - { - ge->reloc_done = TRUE; - *(Elf64_Addr *)(hfile->got->contents + ge->offset) = v; - } - v = got + ge->offset - gp; - if (r_info == R_PARISC_LTOFF14R) - ret = patch_14r(v, loc); - else - ret = patch_21l(v, loc); - } - break; - case R_PARISC_PCREL22F: - { - hppa64_got_t *ge; - - assert(isym != NULL); - for (ge = isym->gotent; ge != NULL && ge->addend != rel->r_addend; ) - ge = ge->next; - assert(ge != NULL); - if (!ge->reloc_done) - { - ge->reloc_done = TRUE; - *(Elf64_Addr *)(hfile->got->contents + ge->offset) = v; - } - if ((isym->root.secidx > SHN_HIRESERVE) || - ((Elf64_Sxword) (v - dot - 8) > 0x800000-1) || - ((Elf64_Sxword) (v - dot - 8) < -0x800000)) - { - hppa64_stub_t *se; - - for (se = isym->stubent; se != NULL && se->addend != rel->r_addend; ) - se = se->next; - assert(se != NULL); - if (!se->reloc_done) - { - /* This requires that we can get from dp to the entry in +/- 8K, - * or +/- 1000 entries. patch_14r2() will check that. - * Only need these dlt entries for calls to external/far - * functions, so should probably put them in a seperate section - * before dlt and point dp at the section. Change to that - * scheme if we hit problems with big modules. - */ - unsigned char *stub; - - if (!strncmp(isym->root.name, "$$", 2)) { - stub = hppa64_stub_millicode; - memcpy((Elf64_Addr *)(hfile->stub->contents + se->offset), - stub, SIZEOF_STUB); - v = (Elf64_Addr)isym->root.value; - ret = patch_21l(v, (Elf64_Word *)(hfile->stub->contents + se->offset)); - if (ret == obj_reloc_ok) - ret = patch_14r(v, (Elf64_Word *)(hfile->stub->contents + se->offset + 4)); - } - else { - stub = hppa64_stub_extern; - memcpy((Elf64_Addr *)(hfile->stub->contents + se->offset), - stub, SIZEOF_STUB); - v = (Elf64_Addr)(hfile->got->header.sh_addr + ge->offset) - gp; - ret = patch_14r2(v, (Elf64_Word *)(hfile->stub->contents + se->offset)); - } - se->reloc_done = TRUE; - } - v = hfile->stub->header.sh_addr + se->offset; - } - v = v - dot - 8; - if (ret == obj_reloc_ok) - ret = patch_22f(v, loc); - } - break; - case R_PARISC_DIR64: - { - loc[0] = v >> 32; - loc[1] = v; - } - break; - case R_PARISC_SEGREL32: - { - loc[0] = v - f->baseaddr; - } - break; - case R_PARISC_FPTR64: - { - assert(isym != NULL); - if (isym->root.secidx <= SHN_HIRESERVE) /* local */ - { - assert(isym->opdent != NULL); - if (!isym->opdent->reloc_done) - { - isym->opdent->reloc_done = TRUE; - *(Elf64_Addr *)(hfile->opd->contents + isym->opdent->offset + 16) = v; - *(Elf64_Addr *)(hfile->opd->contents + isym->opdent->offset + 24) = gp; - } - v = hfile->opd->header.sh_addr + isym->opdent->offset; - } - loc[0] = v >> 32; - loc[1] = v; - } - break; - } - return ret; -} - -int -arch_init_module (struct obj_file *f, struct module *mod) -{ - hppa64_file_t *hfile = (hppa64_file_t *)f; - Elf64_Addr *opd = (Elf64_Addr *)(hfile->opd->contents); - - opd[0] = 0; - opd[1] = 0; - if ((opd[2] = mod->init) != 0) - { - opd[3] = hfile->gp; - mod->init = hfile->opd->header.sh_addr; - } - - opd[4] = 0; - opd[5] = 0; - if ((opd[6] = mod->cleanup) != 0) - { - opd[7] = hfile->gp; - mod->cleanup = hfile->opd->header.sh_addr + 32; - } - - return 1; -} - -/* XXX Is this relevant to parisc? */ - -int -arch_archdata (struct obj_file *f, struct obj_section *archdata_sec) -{ - hppa64_file_t *hfile = (hppa64_file_t *)f; - struct archdata { - unsigned tgt_long unw_table; - unsigned tgt_long segment_base; - unsigned tgt_long unw_start; - unsigned tgt_long unw_end; - unsigned tgt_long gp; - } *ad; - int i; - struct obj_section *sec; - - free(archdata_sec->contents); - archdata_sec->contents = xmalloc(sizeof(struct archdata)); - memset(archdata_sec->contents, 0, sizeof(struct archdata)); - archdata_sec->header.sh_size = sizeof(struct archdata); - - ad = (struct archdata *)(archdata_sec->contents); - ad->gp = hfile->gp; - ad->unw_start = 0; - ad->unw_end = 0; - ad->unw_table = 0; - ad->segment_base = f->sections[1]->header.sh_addr; - for (i = 0; i < f->header.e_shnum; ++i) - { - sec = f->sections[i]; - if (sec->header.sh_type == SHT_PARISC_UNWIND) - { - ad->unw_start = sec->header.sh_addr; - ad->unw_end = sec->header.sh_addr + sec->header.sh_size; - break; - } - } - - return 0; -} diff --git a/mdk-stage1/insmod-modutils/obj/obj_i386.c b/mdk-stage1/insmod-modutils/obj/obj_i386.c deleted file mode 100644 index fcbce8e04..000000000 --- a/mdk-stage1/insmod-modutils/obj/obj_i386.c +++ /dev/null @@ -1,237 +0,0 @@ -/* i386 specific support for Elf loading and relocation. - Copyright 1996, 1997 Linux International. - - Contributed by Richard Henderson <rth@tamu.edu> - - This file is part of the Linux modutils. - - This program is free software; you can redistribute it and/or modify it - under the terms of the GNU General Public License as published by the - Free Software Foundation; either version 2 of the License, or (at your - option) any later version. - - This program is distributed in the hope that it will be useful, but - WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - General Public License for more details. - - You should have received a copy of the GNU General Public License - along with this program; if not, write to the Free Software Foundation, - Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ - -#include <string.h> -#include <assert.h> - -#include <module.h> -#include <obj.h> -#include <util.h> - - -/*======================================================================*/ - -struct i386_got_entry -{ - int offset; - unsigned offset_done : 1; - unsigned reloc_done : 1; -}; - -struct i386_file -{ - struct obj_file root; - struct obj_section *got; -}; - -struct i386_symbol -{ - struct obj_symbol root; - struct i386_got_entry gotent; -}; - - -/*======================================================================*/ - -struct obj_file * -arch_new_file (void) -{ - struct i386_file *f; - f = xmalloc(sizeof(*f)); - f->got = NULL; - return &f->root; -} - -struct obj_section * -arch_new_section (void) -{ - return xmalloc(sizeof(struct obj_section)); -} - -struct obj_symbol * -arch_new_symbol (void) -{ - struct i386_symbol *sym; - sym = xmalloc(sizeof(*sym)); - memset(&sym->gotent, 0, sizeof(sym->gotent)); - return &sym->root; -} - -int -arch_load_proc_section(struct obj_section *sec, int fp) -{ - /* Assume it's just a debugging section that we can safely - ignore ... */ - sec->contents = NULL; - - return 0; -} - -enum obj_reloc -arch_apply_relocation (struct obj_file *f, - struct obj_section *targsec, - struct obj_section *symsec, - struct obj_symbol *sym, - Elf32_Rel *rel, - Elf32_Addr v) -{ - struct i386_file *ifile = (struct i386_file *)f; - struct i386_symbol *isym = (struct i386_symbol *)sym; - - Elf32_Addr *loc = (Elf32_Addr *)(targsec->contents + rel->r_offset); - Elf32_Addr dot = targsec->header.sh_addr + rel->r_offset; - Elf32_Addr got = ifile->got ? ifile->got->header.sh_addr : 0; - - enum obj_reloc ret = obj_reloc_ok; - - switch (ELF32_R_TYPE(rel->r_info)) - { - case R_386_NONE: - break; - - case R_386_32: - *loc += v; - break; - - case R_386_PLT32: - case R_386_PC32: - *loc += v - dot; - break; - - case R_386_GLOB_DAT: - case R_386_JMP_SLOT: - *loc = v; - break; - - case R_386_RELATIVE: - *loc += f->baseaddr; - break; - - case R_386_GOTPC: - assert(got != 0); - *loc += got - dot; - break; - - case R_386_GOT32: - assert(isym != NULL); - if (!isym->gotent.reloc_done) - { - isym->gotent.reloc_done = 1; - *(Elf32_Addr *)(ifile->got->contents + isym->gotent.offset) = v; - } - *loc += isym->gotent.offset; - break; - - case R_386_GOTOFF: - assert(got != 0); - *loc += v - got; - break; - - default: - ret = obj_reloc_unhandled; - break; - } - - return ret; -} - -int -arch_create_got (struct obj_file *f) -{ - struct i386_file *ifile = (struct i386_file *)f; - int i, n, offset = 0, gotneeded = 0; - - n = ifile->root.header.e_shnum; - for (i = 0; i < n; ++i) - { - struct obj_section *relsec, *symsec, *strsec; - Elf32_Rel *rel, *relend; - Elf32_Sym *symtab; - const char *strtab; - - relsec = ifile->root.sections[i]; - if (relsec->header.sh_type != SHT_REL) - continue; - - symsec = ifile->root.sections[relsec->header.sh_link]; - strsec = ifile->root.sections[symsec->header.sh_link]; - - rel = (Elf32_Rel *)relsec->contents; - relend = rel + (relsec->header.sh_size / sizeof(Elf32_Rel)); - symtab = (Elf32_Sym *)symsec->contents; - strtab = (const char *)strsec->contents; - - for (; rel < relend; ++rel) - { - struct i386_symbol *intsym; - - switch (ELF32_R_TYPE(rel->r_info)) - { - case R_386_GOTPC: - case R_386_GOTOFF: - gotneeded = 1; - default: - continue; - - case R_386_GOT32: - break; - } - - obj_find_relsym(intsym, f, &ifile->root, rel, symtab, strtab); - - if (!intsym->gotent.offset_done) - { - intsym->gotent.offset_done = 1; - intsym->gotent.offset = offset; - offset += 4; - } - } - } - - if (offset > 0 || gotneeded) - ifile->got = obj_create_alloced_section(&ifile->root, ".got", 4, offset, - SHF_WRITE); - - return 1; -} - -int -arch_init_module (struct obj_file *f, struct module *mod) -{ - return 1; -} - -int -arch_finalize_section_address(struct obj_file *f, Elf32_Addr base) -{ - int i, n = f->header.e_shnum; - - f->baseaddr = base; - for (i = 0; i < n; ++i) - f->sections[i]->header.sh_addr += base; - return 1; -} - -int -arch_archdata (struct obj_file *fin, struct obj_section *sec) -{ - return 0; -} diff --git a/mdk-stage1/insmod-modutils/obj/obj_ia64.c b/mdk-stage1/insmod-modutils/obj/obj_ia64.c deleted file mode 100644 index d207a9042..000000000 --- a/mdk-stage1/insmod-modutils/obj/obj_ia64.c +++ /dev/null @@ -1,1022 +0,0 @@ -/* - * ia64 specific support for Elf loading and relocation. - * Copyright 2000 Mike Stephens <mike.stephens@intel.com> - * - * This file is part of the Linux modutils. - * - * This program is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License as published by the - * Free Software Foundation; either version 2 of the License, or (at your - * option) any later version. - * - * This program is distributed in the hope that it will be useful, but - * WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software Foundation, - * Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. - */ - -#include <string.h> -#include <assert.h> -#include <stdlib.h> - -#include <module.h> -#include <obj.h> -#include <util.h> - -#ifndef FALSE -#define FALSE 0 -#endif -#ifndef TRUE -#define TRUE ~FALSE -#endif - -/*======================================================================*/ - -typedef struct _ia64_opd_t -{ - int offset; - int reloc_done; -} ia64_opd_t; - -typedef struct _ia64_plt_t -{ - struct _ia64_plt_t *next; - Elf64_Addr addend; - int text_offset; - int data_offset; - int reloc_done; -} ia64_plt_t; - -typedef struct _ia64_got_t -{ - struct _ia64_got_t *next; - Elf64_Addr addend; - int offset; - int reloc_done; -} ia64_got_t; - -typedef struct _ia64_symbol_t -{ - struct obj_symbol root; - ia64_got_t *gotent; - ia64_opd_t *opdent; - ia64_plt_t *pltent; -} ia64_symbol_t; - -typedef struct _ia64_file_t -{ - struct obj_file root; - struct obj_section *got; - struct obj_section *opd; - struct obj_section *pltt; - struct obj_section *pltd; - Elf64_Addr gp; - Elf64_Addr text; - Elf64_Addr data; - Elf64_Addr bss; -} ia64_file_t; - -/* - * aa=gp rel address of the function descriptor in the .IA_64.pltoff section - */ -unsigned char ia64_plt_local[] = -{ - 0x0b, 0x78, 0x00, 0x02, 0x00, 0x24, /* [MMI] addl r15=aa,gp;; */ - 0x00, 0x41, 0x3c, 0x30, 0x28, 0xc0, /* ld8 r16=[r15],8 */ - 0x01, 0x08, 0x00, 0x84, /* mov r14=gp;; */ - 0x11, 0x08, 0x00, 0x1e, 0x18, 0x10, /* [MIB] ld8 gp=[r15] */ - 0x60, 0x80, 0x04, 0x80, 0x03, 0x00, /* mov b6=r16 */ - 0x60, 0x00, 0x80, 0x00 /* br.few b6;; */ -}; - -unsigned char ia64_plt_extern[] = -{ - 0x0b, 0x80, 0x00, 0x02, 0x00, 0x24, /* [MMI] addl r16=aa,gp;; */ - 0xf0, 0x00, 0x40, 0x30, 0x20, 0x00, /* ld8 r15=[r16] */ - 0x00, 0x00, 0x04, 0x00, /* nop.i 0x0;; */ - 0x0b, 0x80, 0x20, 0x1e, 0x18, 0x14, /* [MMI] ld8 r16=[r15],8;; */ - 0x10, 0x00, 0x3c, 0x30, 0x20, 0xc0, /* ld8 gp=[r15] */ - 0x00, 0x09, 0x00, 0x07, /* mov b6=r16;; */ - 0x11, 0x00, 0x00, 0x00, 0x01, 0x00, /* [MIB] nop.m 0x0 */ - 0x00, 0x00, 0x00, 0x02, 0x00, 0x00, /* nop.i 0x0 */ - 0x60, 0x00, 0x80, 0x00 /* br.few b6;; */ -}; - -/*======================================================================*/ - -/* - * return the instruction at slot in bundle - */ -Elf64_Xword -obj_ia64_ins_extract_from_bundle(Elf64_Addr *bundle, Elf64_Xword slot) -{ - switch (slot) - { - case 0 : - return (*bundle >> 5) & 0x1ffffffffff; - - case 1 : - return (((*bundle >> 46) & 0x3ffff) | - (*(bundle + 1) << 18)) & 0x1ffffffffff; - - case 2 : - return (*(bundle + 1) >> 23) & 0x1ffffffffff; - - default: - } - return (-1); -} - -/* - * insert a instruction at slot in bundle - */ -void -obj_ia64_ins_insert_in_bundle(Elf64_Addr *bundle, Elf64_Xword slot, Elf64_Xword ins) -{ - Elf64_Xword i; - Elf64_Xword in = ins & 0x1ffffffffff; - - switch (slot) - { - case 0 : - i = *bundle & 0xffffc0000000001f; - *bundle = i | (in << 5); - break; - - case 1 : - i = *bundle & 0x00003fffffffffff; - *bundle = i | (in << 46); - - ++bundle; - i = *bundle & 0xffffffffff800000; - *bundle = i | (in >> 18); - break; - - case 2 : - ++bundle; - i = *bundle & 0x00000000007fffff; - *bundle = i | (in << 23); - break; - } -} - -/* - * add a immediate 14 value to the instruction at slot in bundle - */ -enum obj_reloc -obj_ia64_ins_imm14(Elf64_Xword v, Elf64_Addr *bundle, Elf64_Xword slot) -{ - Elf64_Xword ins; - - ins = obj_ia64_ins_extract_from_bundle(bundle, slot); - ins &= 0xffffffee07f01fff; - ins |= ((v & 0x2000) << 23) | ((v & 0x1f80) << 20) | ((v & 0x007f) << 13); - obj_ia64_ins_insert_in_bundle(bundle, slot, ins); - if (((Elf64_Sxword) v > 8191) || ((Elf64_Sxword) v < -8192)) - return obj_reloc_overflow; - return obj_reloc_ok; -} - -/* - * add a immediate 22 value to the instruction at slot in bundle - */ -enum obj_reloc -obj_ia64_ins_imm22(Elf64_Xword v, Elf64_Addr *bundle, Elf64_Xword slot) -{ - Elf64_Xword ins; - - ins = obj_ia64_ins_extract_from_bundle(bundle, slot); - ins &= 0xffffffe000301fff; - ins |= ((v & 0x200000) << 15) | ((v & 0x1f0000) << 6) | - ((v & 0x00ff80) << 20) | ((v & 0x00007f) << 13); - obj_ia64_ins_insert_in_bundle(bundle, slot, ins); - if (((Elf64_Sxword) v > 2097151) || ((Elf64_Sxword) v < -2097152)) - return obj_reloc_overflow; - return obj_reloc_ok; -} - -/* - * add a immediate 21 value (form 1) to the instruction at slot in bundle - */ -enum obj_reloc -obj_ia64_ins_pcrel21b(Elf64_Xword v, Elf64_Addr *bundle, Elf64_Xword slot) -{ - Elf64_Xword ins; - - ins = obj_ia64_ins_extract_from_bundle(bundle, slot); - ins &= 0xffffffee00001fff; - ins |= ((v & 0x1000000) << 12) | ((v & 0x0fffff0) << 9); - obj_ia64_ins_insert_in_bundle(bundle, slot, ins); - return obj_reloc_ok; -} - -/* - * add a immediate 21 value (form 2) to the instruction at slot in bundle - */ -enum obj_reloc -obj_ia64_ins_pcrel21m(Elf64_Xword v, Elf64_Addr *bundle, Elf64_Xword slot) -{ - Elf64_Xword ins; - - ins = obj_ia64_ins_extract_from_bundle(bundle, slot); - ins &= 0xffffffee000fe03f; - ins |= ((v & 0x1000000) << 12) | ((v & 0x0fff800) << 9) | - ((v & 0x00007f0) << 2); - obj_ia64_ins_insert_in_bundle(bundle, slot, ins); - return obj_reloc_ok; -} - -/* - * add a immediate 21 value (form 3) to the instruction at slot in bundle - */ -enum obj_reloc -obj_ia64_ins_pcrel21f(Elf64_Xword v, Elf64_Addr *bundle, Elf64_Xword slot) -{ - Elf64_Xword ins; - - ins = obj_ia64_ins_extract_from_bundle(bundle, slot); - ins &= 0xffffffeffc00003f; - ins |= ((v & 0x1000000) << 12) | ((v & 0x0fffff0) << 2); - obj_ia64_ins_insert_in_bundle(bundle, slot, ins); - return obj_reloc_ok; -} - -/* - * add a immediate 64 value to the instruction at slot in bundle - */ -enum obj_reloc -obj_ia64_ins_imm64(Elf64_Xword v, Elf64_Addr *bundle, Elf64_Xword slot) -{ - Elf64_Xword ins; - - assert(slot == 2); - - ins = obj_ia64_ins_extract_from_bundle(bundle, slot); - ins &= 0xffffffe000101fff; - ins |= ((v & 0x8000000000000000) >> 27) | ((v & 0x0000000000200000)) | - ((v & 0x00000000001f0000) << 6) | ((v & 0x000000000000ff80) << 20) | - ((v & 0x000000000000007f) << 13); - obj_ia64_ins_insert_in_bundle(bundle, slot, ins); - obj_ia64_ins_insert_in_bundle(bundle, --slot, ((v & 0x7fffffffffc00000) >> 22)); - return obj_reloc_ok; -} - -/* - * create a plt entry - */ -enum obj_reloc -obj_ia64_generate_plt(Elf64_Addr v, - Elf64_Addr gp, - ia64_file_t *ifile, - ia64_symbol_t *isym, - ia64_plt_t *pltent) -{ - *(Elf64_Addr *)(ifile->pltd->contents + pltent->data_offset) = v; - if (isym->root.secidx <= SHN_HIRESERVE) - { - /* local entry */ - *(Elf64_Addr *)(ifile->pltd->contents + pltent->data_offset + 8) = gp; - memcpy((Elf64_Addr *)(ifile->pltt->contents + pltent->text_offset), - ia64_plt_local, sizeof(ia64_plt_local)); - } - else - { - /* external entry */ - memcpy((Elf64_Addr *)(ifile->pltt->contents + pltent->text_offset), - ia64_plt_extern, sizeof(ia64_plt_extern)); - } - return obj_ia64_ins_imm22( - (ifile->pltd->header.sh_addr + pltent->data_offset - gp), - (Elf64_Addr *)(ifile->pltt->contents + pltent->text_offset), 0); -} - - -/*======================================================================*/ - -struct obj_file * -arch_new_file (void) -{ - ia64_file_t *f; - f = xmalloc(sizeof(*f)); - f->got = NULL; - f->opd = NULL; - f->pltt = NULL; - f->pltd = NULL; - return &f->root; -} - -struct obj_section * -arch_new_section (void) -{ - return xmalloc(sizeof(struct obj_section)); -} - -struct obj_symbol * -arch_new_symbol (void) -{ - ia64_symbol_t *sym; - sym = xmalloc(sizeof(*sym)); - sym->gotent = NULL; - sym->opdent = NULL; - sym->pltent = NULL; - return &sym->root; -} - -int -arch_load_proc_section(struct obj_section *sec, int fp) -{ - switch (sec->header.sh_type) - { - case SHT_IA_64_EXT : - sec->contents = NULL; - break; - - case SHT_IA_64_UNWIND : - if (sec->header.sh_size > 0) - { - sec->contents = xmalloc(sec->header.sh_size); - gzf_lseek(fp, sec->header.sh_offset, SEEK_SET); - if (gzf_read(fp, sec->contents, sec->header.sh_size) != sec->header.sh_size) - { - error("error reading ELF section data: %m"); - return -1; - } - } - else - sec->contents = NULL; - break; - - default: - error("Unknown section header type: %08x", sec->header.sh_type); - return -1; - } - return 0; -} - -int -arch_create_got(struct obj_file *f) -{ - ia64_file_t *ifile = (ia64_file_t *)f; - int i; - int n; - int got_offset = 0; - int opd_offset = 32; - int plt_text_offset = 0; - int plt_data_offset = 0; - - n = ifile->root.header.e_shnum; - for (i = 0; i < n; ++i) - { - struct obj_section *relsec, *symsec, *strsec; - Elf64_Rela *rel, *relend; - Elf64_Sym *symtab; - const char *strtab; - - relsec = ifile->root.sections[i]; - if (relsec->header.sh_type != SHT_RELA) - continue; - - symsec = ifile->root.sections[relsec->header.sh_link]; - strsec = ifile->root.sections[symsec->header.sh_link]; - - rel = (Elf64_Rela *)relsec->contents; - relend = rel + (relsec->header.sh_size / sizeof(Elf64_Rela)); - symtab = (Elf64_Sym *)symsec->contents; - strtab = (const char *)strsec->contents; - - for (; rel < relend; ++rel) - { - int need_got = FALSE; - int need_opd = FALSE; - int need_plt = FALSE; - - switch (ELF64_R_TYPE(rel->r_info)) - { - default: - continue; - - case R_IA64_FPTR64I : /* @fptr(sym + add), mov imm64 */ - case R_IA64_FPTR32LSB : /* @fptr(sym + add), data4 LSB */ - case R_IA64_FPTR64LSB : /* @fptr(sym + add), data8 LSB */ - need_opd = TRUE; - break; - - case R_IA64_LTOFF22 : /* @ltoff(sym + add), add imm22 */ - case R_IA64_LTOFF22X : - case R_IA64_LTOFF64I : /* @ltoff(sym + add), mov imm64 */ - need_got = TRUE; - break; - - case R_IA64_LTOFF_FPTR22 : /* @ltoff(@fptr(s+a)), imm22 */ - case R_IA64_LTOFF_FPTR64I : /* @ltoff(@fptr(s+a)), imm64 */ - case R_IA64_LTOFF_FPTR32LSB : - case R_IA64_LTOFF_FPTR64LSB : - need_got = TRUE; - need_opd = TRUE; - break; - - case R_IA64_PLTOFF22 : /* @pltoff(sym + add), add imm22 */ - case R_IA64_PLTOFF64I : /* @pltoff(sym + add), mov imm64 */ - case R_IA64_PLTOFF64LSB : /* @pltoff(sym + add), data8 LSB */ - - case R_IA64_PCREL21B : /* @pcrel(sym + add), ptb, call */ - case R_IA64_PCREL21M : /* @pcrel(sym + add), chk.s */ - case R_IA64_PCREL21F : /* @pcrel(sym + add), fchkf */ - need_plt = TRUE; - break; - } - - if (need_got || need_opd || need_plt) - { - ia64_symbol_t *isym; - int local; - - obj_find_relsym(isym, f, f, rel, symtab, strtab); - local = isym->root.secidx <= SHN_HIRESERVE; - - if (need_plt) - { - ia64_plt_t *plt; - - for (plt = isym->pltent; plt != NULL; plt = plt->next) - if (plt->addend == rel->r_addend) - break; - if (plt == NULL) - { - plt = (ia64_plt_t *) xmalloc(sizeof(ia64_plt_t)); - plt->next = isym->pltent; - plt->addend = rel->r_addend; - plt->text_offset = plt_text_offset; - plt->data_offset = plt_data_offset; - plt->reloc_done = FALSE; - isym->pltent = plt; - if (local) - { - plt_text_offset += sizeof(ia64_plt_local); - plt_data_offset += 16; - } - else - { - plt_text_offset += sizeof(ia64_plt_extern); - plt_data_offset += 8; - } - need_plt = FALSE; - } - } - if (need_got) - { - ia64_got_t *got; - - for (got = isym->gotent; got != NULL; got = got->next) - if (got->addend == rel->r_addend) - break; - if (got == NULL) - { - got = (ia64_got_t *) xmalloc(sizeof(ia64_got_t)); - got->next = isym->gotent; - got->addend = rel->r_addend; - got->offset = got_offset; - got->reloc_done = FALSE; - isym->gotent = got; - got_offset += 8; - need_got = FALSE; - } - } - if (need_opd && local) - { - ia64_opd_t *opd; - - if (isym->opdent == NULL) - { - opd = (ia64_opd_t *) xmalloc(sizeof(ia64_opd_t)); - opd->offset = opd_offset; - opd->reloc_done = FALSE; - isym->opdent = opd; - opd_offset += 16; - need_opd = FALSE; - } - } - } - } - } - - ifile->got = obj_create_alloced_section(f, ".got", 8, got_offset, - SHF_WRITE | SHF_IA_64_SHORT); - assert(ifile->got != NULL); - - ifile->opd = obj_create_alloced_section(f, ".opd", 16, opd_offset, - SHF_WRITE | SHF_IA_64_SHORT); - assert(ifile->opd != NULL); - - if (plt_text_offset > 0) - { - ifile->pltt = obj_create_alloced_section(f, ".plt", 16, - plt_text_offset, - SHF_WRITE | SHF_IA_64_SHORT); - ifile->pltd = obj_create_alloced_section(f, ".IA_64.pltoff", 16, - plt_data_offset, - SHF_WRITE | SHF_IA_64_SHORT); - assert(ifile->pltt != NULL); - assert(ifile->pltd != NULL); - } - - return 1; -} - -int -arch_finalize_section_address(struct obj_file *f, Elf64_Addr base) -{ - ia64_file_t *ifile = (ia64_file_t *)f; - Elf64_Addr min_addr = (Elf64_Addr) -1; - Elf64_Addr max_addr = 0; - Elf64_Addr min_short_addr = (Elf64_Addr) -1; - Elf64_Addr max_short_addr = 0; - Elf64_Addr gp; - Elf64_Addr text = (Elf64_Addr) -1; - Elf64_Addr data = (Elf64_Addr) -1; - Elf64_Addr bss = (Elf64_Addr) -1; - int n = f->header.e_shnum; - int i; - - /* - * Finalize the addresses of the sections, find the min and max - * address of all sections marked short, and collect min and max - * address of any type, for use in selecting a nice gp. - * - * The algorithm used for selecting set the GP value was taken from - * the ld/bfd code contributed by David Mosberger-Tang <davidm@hpl.hp.com> - */ - f->baseaddr = base; - for (i = 0; i < n; ++i) - { - Elf64_Shdr *header = &f->sections[i]->header; - Elf64_Addr lo; - Elf64_Addr hi; - - header->sh_addr += base; - if (header->sh_flags & SHF_ALLOC) - { - lo = header->sh_addr; - hi = header->sh_addr + header->sh_size; - if (hi < lo) - hi = (Elf64_Addr) -1; - - if (min_addr > lo) - min_addr = lo; - if (max_addr < hi) - max_addr = hi; - if (header->sh_flags & SHF_IA_64_SHORT) - { - if (min_short_addr > lo) - min_short_addr = lo; - if (max_short_addr < hi) - max_short_addr = hi; - } - if ((header->sh_type & SHT_NOBITS) && (lo < bss)) - bss = lo; - else if ((header->sh_flags & SHF_EXECINSTR) && (lo < text)) - text = lo; - else if (lo < data) - data = lo; - } - } - /* Pick a sensible value for gp */ - - /* Start with just the address of the .got */ - gp = ifile->got->header.sh_addr; - - /* - * If it is possible to address the entire image, but we - * don't with the choice above, adjust. - */ - if ((max_addr - min_addr < 0x400000) && (max_addr - gp <= 0x200000) && - (gp - min_addr > 0x200000)) - { - gp = min_addr + 0x200000; - } - else if (max_short_addr != 0) - { - /* If we don't cover all the short data, adjust */ - if (max_short_addr - gp >= 0x200000) - gp = min_short_addr + 0x200000; - - /* If we're addressing stuff past the end, adjust back */ - if (gp > max_addr) - gp = max_addr - 0x200000 + 8; - } - - /* - * Validate whether all SHF_IA_64_SHORT sections are within - * range of the chosen GP. - */ - if (max_short_addr != 0) - { - if (max_short_addr - min_short_addr >= 0x400000) - { - error("short data segment overflowed (0x%lx >= 0x400000)", - (unsigned long)(max_short_addr - min_short_addr)); - return 0; - } - else if (((gp > min_short_addr) && (gp - min_short_addr > 0x200000)) || - ((gp < max_short_addr) && (max_short_addr - gp >= 0x200000))) - { - error("GP does not cover short data segment"); - return 0; - } - } - ifile->gp = gp; - ifile->text = text; - ifile->data = data; - ifile->bss = bss; - return 1; -} - -/* Targets can be unaligned, use memcpy instead of assignment */ -#define COPY_64LSB(loc, v) \ - do { \ - Elf64_Xword reloc = (v); \ - memcpy((void *)(loc), &reloc, 8); \ - } while(0) -#define COPY_32LSB(loc, v) \ - do { \ - Elf32_Xword reloc = (v); \ - memcpy((void *)(loc), &reloc, 4); \ - if ((v) != reloc) \ - ret = obj_reloc_overflow; \ - } while(0) - -enum obj_reloc -arch_apply_relocation(struct obj_file *f, - struct obj_section *targsec, - struct obj_section *symsec, - struct obj_symbol *sym, - Elf64_Rela *rel, - Elf64_Addr v) -{ - ia64_file_t *ifile = (ia64_file_t *) f; - ia64_symbol_t *isym = (ia64_symbol_t *) sym; - - Elf64_Addr loc = (Elf64_Addr)(targsec->contents + rel->r_offset); - Elf64_Addr dot = (targsec->header.sh_addr + rel->r_offset) & ~0x03; - - Elf64_Addr got = ifile->got->header.sh_addr; - Elf64_Addr gp = ifile->gp; - - Elf64_Addr *bundle = (Elf64_Addr *)(loc & ~0x03); - Elf64_Xword slot = loc & 0x03; - - Elf64_Xword r_info = ELF64_R_TYPE(rel->r_info); - - enum obj_reloc ret = obj_reloc_ok; - - /* We cannot load modules compiled with -mconstant-gp */ -#ifndef EF_IA_64_CONS_GP -#define EF_IA_64_CONS_GP 0x00000040 -#endif -#ifndef EF_IA_64_NOFUNCDESC_CONS_GP -#define EF_IA_64_NOFUNCDESC_CONS_GP 0x00000080 -#endif - if (f->header.e_flags & (EF_IA_64_CONS_GP | EF_IA_64_NOFUNCDESC_CONS_GP)) - return obj_reloc_constant_gp; - - switch (r_info) - { - case R_IA64_NONE : /* none */ - case R_IA64_LDXMOV : /* Use of LTOFF22X. */ - break; - - case R_IA64_IMM14 : /* symbol + addend, add imm14 */ - ret = obj_ia64_ins_imm14(v, bundle, slot); - break; - - case R_IA64_IMM22 : /* symbol + addend, add imm22 */ - ret = obj_ia64_ins_imm22(v, bundle, slot); - break; - - case R_IA64_IMM64 : /* symbol + addend, movl imm64 */ - ret = obj_ia64_ins_imm64(v, bundle, slot); - break; - - case R_IA64_DIR32LSB : /* symbol + addend, data4 LSB */ - COPY_32LSB(loc, v); - break; - - case R_IA64_DIR64LSB : /* symbol + addend, data8 LSB */ - COPY_64LSB(loc, v); - break; - - case R_IA64_GPREL22 : /* @gprel(sym + add), add imm22 */ - v -= gp; - ret = obj_ia64_ins_imm22(v, bundle, slot); - break; - - case R_IA64_GPREL64I : /* @gprel(sym + add), mov imm64 */ - v -= gp; - ret = obj_ia64_ins_imm64(v, bundle, slot); - break; - - case R_IA64_GPREL32LSB : /* @gprel(sym + add), data4 LSB */ - COPY_32LSB(loc, v-gp); - break; - - case R_IA64_GPREL64LSB : /* @gprel(sym + add), data8 LSB */ - COPY_64LSB(loc, v-gp); - break; - - case R_IA64_LTOFF22 : /* @ltoff(sym + add), add imm22 */ - case R_IA64_LTOFF22X : /* LTOFF22, relaxable. */ - case R_IA64_LTOFF64I : /* @ltoff(sym + add), mov imm64 */ - { - ia64_got_t *ge; - - assert(isym != NULL); - for (ge = isym->gotent; ge != NULL && ge->addend != rel->r_addend; ) - ge = ge->next; - assert(ge != NULL); - if (!ge->reloc_done) - { - ge->reloc_done = TRUE; - *(Elf64_Addr *)(ifile->got->contents + ge->offset) = v; - } - v = got + ge->offset - gp; - if (r_info == R_IA64_LTOFF64I) - ret = obj_ia64_ins_imm64(v, bundle, slot); - else - ret = obj_ia64_ins_imm22(v, bundle, slot); - } - break; - - case R_IA64_PLTOFF22 : /* @pltoff(sym + add), add imm22 */ - case R_IA64_PLTOFF64I : /* @pltoff(sym + add), mov imm64 */ - case R_IA64_PLTOFF64LSB : /* @pltoff(sym + add), data8 LSB */ - { - ia64_plt_t *pe; - - assert(isym != NULL); - for (pe = isym->pltent; pe != NULL && pe->addend != rel->r_addend; ) - pe = pe->next; - assert(pe != NULL); - if (!pe->reloc_done) - { - pe->reloc_done = TRUE; - ret = obj_ia64_generate_plt(v, gp, ifile, isym, pe); - } - v = ifile->pltt->header.sh_addr + pe->text_offset - gp; - switch (r_info) - { - case R_IA64_PLTOFF22 : - ret = obj_ia64_ins_imm22(v, bundle, slot); - break; - - case R_IA64_PLTOFF64I : - ret = obj_ia64_ins_imm64(v, bundle, slot); - break; - - case R_IA64_PLTOFF64LSB : - COPY_64LSB(loc, v); - break; - } - } - break; - - case R_IA64_FPTR64I : /* @fptr(sym + add), mov imm64 */ - case R_IA64_FPTR32LSB : /* @fptr(sym + add), data4 LSB */ - case R_IA64_FPTR64LSB : /* @fptr(sym + add), data8 LSB */ - assert(isym != NULL); - if (isym->root.secidx <= SHN_HIRESERVE) - { - assert(isym->opdent != NULL); - if (!isym->opdent->reloc_done) - { - isym->opdent->reloc_done = TRUE; - *(Elf64_Addr *)(ifile->opd->contents + isym->opdent->offset) = v; - *(Elf64_Addr *)(ifile->opd->contents + isym->opdent->offset + 8) = gp; - } - v = ifile->opd->header.sh_addr + isym->opdent->offset; - } - switch (r_info) - { - case R_IA64_FPTR64I : - ret = obj_ia64_ins_imm64(v, bundle, slot); - break; - - case R_IA64_FPTR32LSB : - COPY_32LSB(loc, v); - break; - - case R_IA64_FPTR64LSB : /* @fptr(sym + add), data8 LSB */ - /* Target can be unaligned */ - COPY_64LSB(loc, v); - break; - } - break; - - case R_IA64_PCREL21B : /* @pcrel(sym + add), ptb, call */ - case R_IA64_PCREL21M : /* @pcrel(sym + add), chk.s */ - case R_IA64_PCREL21F : /* @pcrel(sym + add), fchkf */ - assert(isym != NULL); - if ((isym->root.secidx > SHN_HIRESERVE) || - ((Elf64_Sxword) (v - dot) > 16777215) || - ((Elf64_Sxword) (v - dot) < -16777216)) - { - ia64_plt_t *pe; - - for (pe = isym->pltent; pe != NULL && pe->addend != rel->r_addend; ) - pe = pe->next; - assert(pe != NULL); - if (!pe->reloc_done) - { - pe->reloc_done = TRUE; - ret = obj_ia64_generate_plt(v, gp, ifile, isym, pe); - } - v = ifile->pltt->header.sh_addr + pe->text_offset; - } - v -= dot; - switch (r_info) - { - case R_IA64_PCREL21B : - ret = obj_ia64_ins_pcrel21b(v, bundle, slot); - break; - - case R_IA64_PCREL21M : - ret = obj_ia64_ins_pcrel21m(v, bundle, slot); - break; - - case R_IA64_PCREL21F : - ret = obj_ia64_ins_pcrel21f(v, bundle, slot); - break; - } - break; - - case R_IA64_PCREL32LSB : /* @pcrel(sym + add), data4 LSB */ - COPY_32LSB(loc, v-dot); - break; - - case R_IA64_PCREL64LSB : /* @pcrel(sym + add), data8 LSB */ - COPY_64LSB(loc, v-dot); - break; - - case R_IA64_LTOFF_FPTR22 : /* @ltoff(@fptr(s+a)), imm22 */ - case R_IA64_LTOFF_FPTR64I : /* @ltoff(@fptr(s+a)), imm64 */ - case R_IA64_LTOFF_FPTR32LSB : /* @ltoff(@fptr(s+a)), data4 */ - case R_IA64_LTOFF_FPTR64LSB : /* @ltoff(@fptr(s+a)), data8 */ - { - ia64_got_t *ge; - - assert(isym != NULL); - if (isym->root.secidx <= SHN_HIRESERVE) - { - assert(isym->opdent != NULL); - if (!isym->opdent->reloc_done) - { - isym->opdent->reloc_done = TRUE; - *(Elf64_Addr *)(ifile->opd->contents + isym->opdent->offset) = v; - *(Elf64_Addr *)(ifile->opd->contents + isym->opdent->offset + 8) = gp; - } - v = ifile->opd->header.sh_addr + isym->opdent->offset; - } - for (ge = isym->gotent; ge != NULL && ge->addend != rel->r_addend; ) - ge = ge->next; - assert(ge != NULL); - if (!ge->reloc_done) - { - ge->reloc_done = TRUE; - *(Elf64_Addr *)(ifile->got->contents + ge->offset) = v; - } - v = got + ge->offset - gp; - switch (r_info) - { - case R_IA64_LTOFF_FPTR22 : - ret = obj_ia64_ins_imm22(v, bundle, slot); - break; - - case R_IA64_LTOFF_FPTR64I : - ret = obj_ia64_ins_imm64(v, bundle, slot); - break; - - case R_IA64_LTOFF_FPTR32LSB : - COPY_32LSB(loc, v); - break; - - case R_IA64_LTOFF_FPTR64LSB : - COPY_64LSB(loc, v); - break; - } - } - break; - - case R_IA64_SEGREL32LSB : /* @segrel(sym + add), data4 LSB */ - case R_IA64_SEGREL64LSB : /* @segrel(sym + add), data8 LSB */ - /* Only one segment for modules, see segment_base in arch_archdata */ - v -= f->sections[1]->header.sh_addr; - if (r_info == R_IA64_SEGREL32LSB) - COPY_32LSB(loc, v); - else - COPY_64LSB(loc, v); - break; - - case R_IA64_SECREL32LSB : /* @secrel(sym + add), data4 LSB */ - COPY_32LSB(loc, targsec->header.sh_addr - v); - break; - - case R_IA64_SECREL64LSB : /* @secrel(sym + add), data8 LSB */ - COPY_64LSB(loc, targsec->header.sh_addr - v); - break; - - /* - * We don't handle the big-endian relocates - * - * R_IA64_DIR32MSB symbol + addend, data4 MSB - * R_IA64_DIR64MSB symbol + addend, data8 MSB - * R_IA64_GPREL32MSB @gprel(sym + add), data4 MSB - * R_IA64_GPREL64MSB @gprel(sym + add), data8 MSB - * R_IA64_PLTOFF64MSB @pltoff(sym + add), data8 MSB - * R_IA64_FPTR32MSB @fptr(sym + add), data4 MSB - * R_IA64_FPTR64MSB @fptr(sym + add), data8 MSB - * R_IA64_PCREL32MSB @pcrel(sym + add), data4 MSB - * R_IA64_PCREL64MSB @pcrel(sym + add), data8 MSB - * R_IA64_SEGREL32MSB @segrel(sym + add), data4 MSB - * R_IA64_SEGREL64MSB @segrel(sym + add), data8 MSB - * R_IA64_SECREL32MSB @secrel(sym + add), data4 MSB - * R_IA64_SECREL64MSB @secrel(sym + add), data8 MSB - * R_IA64_REL32MSB data 4 + REL - * R_IA64_REL64MSB data 8 + REL - * R_IA64_LTV32MSB symbol + addend, data4 MSB - * R_IA64_LTV64MSB symbol + addend, data8 MSB - * R_IA64_IPLTMSB dynamic reloc, imported PLT, MSB - */ - default: - case R_IA64_REL32LSB : /* data 4 + REL */ - case R_IA64_REL64LSB : /* data 8 + REL */ - case R_IA64_LTV32LSB : /* symbol + addend, data4 LSB */ - case R_IA64_LTV64LSB : /* symbol + addend, data8 LSB */ - case R_IA64_IPLTLSB : /* dynamic reloc, imported PLT, LSB */ - ret = obj_reloc_unhandled; - break; - } - return ret; -} - -int -arch_init_module (struct obj_file *f, struct module *mod) -{ - ia64_file_t *ifile = (ia64_file_t *)f; - Elf64_Addr *opd = (Elf64_Addr *)(ifile->opd->contents); - - if ((opd[0] = mod->init) != 0) - { - opd[1] = ifile->gp; - mod->init = ifile->opd->header.sh_addr; - } - - if ((opd[2] = mod->cleanup) != 0) - { - opd[3] = ifile->gp; - mod->cleanup = ifile->opd->header.sh_addr + 16; - } - - return 1; -} - -int -arch_archdata (struct obj_file *f, struct obj_section *archdata_sec) -{ - ia64_file_t *ifile = (ia64_file_t *)f; - struct archdata { - unsigned tgt_long unw_table; - unsigned tgt_long segment_base; - unsigned tgt_long unw_start; - unsigned tgt_long unw_end; - unsigned tgt_long gp; - } *ad; - int i; - struct obj_section *sec; - - free(archdata_sec->contents); - archdata_sec->contents = xmalloc(sizeof(struct archdata)); - memset(archdata_sec->contents, 0, sizeof(struct archdata)); - archdata_sec->header.sh_size = sizeof(struct archdata); - - ad = (struct archdata *)(archdata_sec->contents); - ad->gp = ifile->gp; - ad->unw_start = 0; - ad->unw_end = 0; - ad->unw_table = 0; - ad->segment_base = f->sections[1]->header.sh_addr; - for (i = 0; i < f->header.e_shnum; ++i) - { - sec = f->sections[i]; - if (sec->header.sh_type == SHT_IA_64_UNWIND) - { - ad->unw_start = sec->header.sh_addr; - ad->unw_end = sec->header.sh_addr + sec->header.sh_size; - break; - } - } - - return 0; -} diff --git a/mdk-stage1/insmod-modutils/obj/obj_kallsyms.c b/mdk-stage1/insmod-modutils/obj/obj_kallsyms.c deleted file mode 100644 index 917a007e1..000000000 --- a/mdk-stage1/insmod-modutils/obj/obj_kallsyms.c +++ /dev/null @@ -1,290 +0,0 @@ -/* Build a section containing all non-stack symbols. - Copyright 2000 Keith Owens <kaos@ocs.com.au> - - This file is part of the Linux modutils. - - This program is free software; you can redistribute it and/or modify it - under the terms of the GNU General Public License as published by the - Free Software Foundation; either version 2 of the License, or (at your - option) any later version. - - This program is distributed in the hope that it will be useful, but - WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - General Public License for more details. - - You should have received a copy of the GNU General Public License - along with this program; if not, write to the Free Software Foundation, - Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ - -#include <stdlib.h> -#include <string.h> -#include <malloc.h> - -#include "obj.h" -#include "kallsyms.h" -#include "util.h" - -/*======================================================================*/ - -#define EXPAND_BY 4096 /* Arbitrary */ - -/* Append a string to the big list of strings */ - -static void -append_string (const char *s, char **strings, - ElfW(Word) *strings_size, ElfW(Word) *strings_left) -{ - size_t l = strlen(s) + 1; - while (l > *strings_left) { - *strings = xrealloc(*strings, *strings_size += EXPAND_BY); - *strings_left += EXPAND_BY; - } - memcpy((char *)*strings+*strings_size-*strings_left, s, l); - *strings_left -= l; -} - - -/* Append a symbol to the big list of symbols */ - -static void -append_symbol (const struct kallsyms_symbol *s, - struct kallsyms_symbol **symbols, - ElfW(Word) *symbols_size, ElfW(Word) *symbols_left) -{ - size_t l = sizeof(*s); - while (l > *symbols_left) { - *symbols = xrealloc(*symbols, *symbols_size += EXPAND_BY); - *symbols_left += EXPAND_BY; - } - memcpy((char *)*symbols+*symbols_size-*symbols_left, s, l); - *symbols_left -= l; -} - -/* qsort compare routine to sort symbols */ - -static const char *sym_strings; - -static int -symbol_compare (const void *a, const void *b) -{ - struct kallsyms_symbol *c = (struct kallsyms_symbol *) a; - struct kallsyms_symbol *d = (struct kallsyms_symbol *) b; - - if (c->symbol_addr > d->symbol_addr) - return(1); - if (c->symbol_addr < d->symbol_addr) - return(-1); - return(strcmp(sym_strings+c->name_off, sym_strings+d->name_off)); -} - - -/* Extract all symbols from the input obj_file, ignore ones that are - * no use for debugging, build an output obj_file containing only the - * kallsyms section. - * - * The kallsyms section is a bit unusual. It deliberately has no - * relocatable data, all "pointers" are represented as byte offsets - * into the the section. This means it can be stored anywhere without - * relocation problems. In particular it can be stored within a kernel - * image, it can be stored separately from the kernel image, it can be - * appended to a module just before loading, it can be stored in a - * separate area etc. - * - * Format of the kallsyms section. - * - * Header: - * Size of header. - * Total size of kallsyms data, including strings. - * Number of loaded sections. - * Offset to first section entry from start of header. - * Size of each section entry, excluding the name string. - * Number of symbols. - * Offset to first symbol entry from start of header. - * Size of each symbol entry, excluding the name string. - * - * Section entry - one per loaded section. - * Start of section[1]. - * Size of section. - * Offset to name of section, from start of strings. - * Section flags. - * - * Symbol entry - one per symbol in the input file[2]. - * Offset of section that owns this symbol, from start of section data. - * Address of symbol within the real section[1]. - * Offset to name of symbol, from start of strings. - * - * Notes: [1] This is an exception to the "represent pointers as - * offsets" rule, it is a value, not an offset. The start - * address of a section or a symbol is extracted from the - * obj_file data which may contain absolute or relocatable - * addresses. If the addresses are relocatable then the - * caller must adjust the section and/or symbol entries in - * kallsyms after relocation. - * [2] Only symbols that fall within loaded sections are stored. - */ - -int -obj_kallsyms (struct obj_file *fin, struct obj_file **fout_result) -{ - struct obj_file *fout; - int i, loaded = 0, *fin_to_allsym_map; - struct obj_section *isec, *osec; - struct kallsyms_header *a_hdr; - struct kallsyms_section *a_sec; - ElfW(Off) sec_off; - struct kallsyms_symbol *symbols = NULL, a_sym; - ElfW(Word) symbols_size = 0, symbols_left = 0; - char *strings = NULL, *p; - ElfW(Word) strings_size = 0, strings_left = 0; - ElfW(Off) file_offset; - static char strtab[] = "\000" KALLSYMS_SEC_NAME; - - /* Create the kallsyms section. */ - fout = arch_new_file(); - memset(fout, 0, sizeof(*fout)); - fout->symbol_cmp = strcmp; - fout->symbol_hash = obj_elf_hash; - fout->load_order_search_start = &fout->load_order; - - /* Copy file characteristics from input file and modify to suit */ - memcpy(&fout->header, &fin->header, sizeof(fout->header)); - fout->header.e_type = ET_REL; /* Output is relocatable */ - fout->header.e_entry = 0; /* No entry point */ - fout->header.e_phoff = 0; /* No program header */ - file_offset = sizeof(fout->header); /* Step over Elf header */ - fout->header.e_shoff = file_offset; /* Section headers next */ - fout->header.e_phentsize = 0; /* No program header */ - fout->header.e_phnum = 0; /* No program header */ - fout->header.e_shnum = KALLSYMS_IDX+1; /* Initial, strtab, kallsyms */ - fout->header.e_shstrndx = KALLSYMS_IDX-1; /* strtab */ - file_offset += fout->header.e_shentsize * fout->header.e_shnum; - - /* Populate the section data for kallsyms itself */ - fout->sections = xmalloc(sizeof(*(fout->sections))*fout->header.e_shnum); - memset(fout->sections, 0, sizeof(*(fout->sections))*fout->header.e_shnum); - - fout->sections[0] = osec = arch_new_section(); - memset(osec, 0, sizeof(*osec)); - osec->header.sh_type = SHT_NULL; - osec->header.sh_link = SHN_UNDEF; - - fout->sections[KALLSYMS_IDX-1] = osec = arch_new_section(); - memset(osec, 0, sizeof(*osec)); - osec->name = ".strtab"; - osec->header.sh_type = SHT_STRTAB; - osec->header.sh_link = SHN_UNDEF; - osec->header.sh_offset = file_offset; - osec->header.sh_size = sizeof(strtab); - osec->contents = xmalloc(sizeof(strtab)); - memcpy(osec->contents, strtab, sizeof(strtab)); - file_offset += osec->header.sh_size; - - fout->sections[KALLSYMS_IDX] = osec = arch_new_section(); - memset(osec, 0, sizeof(*osec)); - osec->name = KALLSYMS_SEC_NAME; - osec->header.sh_name = 1; /* Offset in strtab */ - osec->header.sh_type = SHT_PROGBITS; /* Load it */ - osec->header.sh_flags = SHF_ALLOC; /* Read only data */ - osec->header.sh_link = SHN_UNDEF; - osec->header.sh_addralign = sizeof(ElfW(Word)); - file_offset = (file_offset + osec->header.sh_addralign - 1) - & -(osec->header.sh_addralign); - osec->header.sh_offset = file_offset; - - /* How many loaded sections are there? */ - for (i = 0; i < fin->header.e_shnum; ++i) { - if (fin->sections[i]->header.sh_flags & SHF_ALLOC) - ++loaded; - } - - /* Initial contents, header + one entry per input section. No strings. */ - osec->header.sh_size = sizeof(*a_hdr) + loaded*sizeof(*a_sec); - a_hdr = (struct kallsyms_header *) (osec->contents = - xmalloc(osec->header.sh_size)); - memset(osec->contents, 0, osec->header.sh_size); - a_hdr->size = sizeof(*a_hdr); - a_hdr->sections = loaded; - a_hdr->section_off = a_hdr->size; - a_hdr->section_size = sizeof(*a_sec); - a_hdr->symbol_off = osec->header.sh_size; - a_hdr->symbol_size = sizeof(a_sym); - a_hdr->start = (ElfW(Addr))(~0); - - /* Map input section numbers to kallsyms section offsets. */ - sec_off = 0; /* Offset to first kallsyms section entry */ - fin_to_allsym_map = xmalloc(sizeof(*fin_to_allsym_map)*fin->header.e_shnum); - for (i = 0; i < fin->header.e_shnum; ++i) { - isec = fin->sections[i]; - if (isec->header.sh_flags & SHF_ALLOC) { - fin_to_allsym_map[isec->idx] = sec_off; - sec_off += a_hdr->section_size; - } - else - fin_to_allsym_map[isec->idx] = -1; /* Ignore this section */ - } - - /* Copy the loaded section data. */ - a_sec = (struct kallsyms_section *) ((char *) a_hdr + a_hdr->section_off); - for (i = 0; i < fin->header.e_shnum; ++i) { - isec = fin->sections[i]; - if (!(isec->header.sh_flags & SHF_ALLOC)) - continue; - a_sec->start = isec->header.sh_addr; - a_sec->size = isec->header.sh_size; - a_sec->flags = isec->header.sh_flags; - a_sec->name_off = strings_size - strings_left; - append_string(isec->name, &strings, &strings_size, &strings_left); - if (a_sec->start < a_hdr->start) - a_hdr->start = a_sec->start; - if (a_sec->start+a_sec->size > a_hdr->end) - a_hdr->end = a_sec->start+a_sec->size; - ++a_sec; - } - - /* Build the kallsyms symbol table from the symbol hashes. */ - for (i = 0; i < HASH_BUCKETS; ++i) { - struct obj_symbol *sym = fin->symtab[i]; - for (sym = fin->symtab[i]; sym ; sym = sym->next) { - if (!sym || sym->secidx >= fin->header.e_shnum) - continue; - if ((a_sym.section_off = fin_to_allsym_map[sym->secidx]) == -1) - continue; - if (strcmp(sym->name, "gcc2_compiled.") == 0 || - strncmp(sym->name, "__insmod_", 9) == 0) - continue; - a_sym.symbol_addr = sym->value; - if (fin->header.e_type == ET_REL) - a_sym.symbol_addr += fin->sections[sym->secidx]->header.sh_addr; - a_sym.name_off = strings_size - strings_left; - append_symbol(&a_sym, &symbols, &symbols_size, &symbols_left); - append_string(sym->name, &strings, &strings_size, &strings_left); - ++a_hdr->symbols; - } - } - free(fin_to_allsym_map); - - /* Sort the symbols into ascending order by address and name */ - sym_strings = strings; /* For symbol_compare */ - qsort((char *) symbols, (unsigned) a_hdr->symbols, - sizeof(* symbols), symbol_compare); - sym_strings = NULL; - - /* Put the lot together */ - osec->header.sh_size = a_hdr->total_size = - a_hdr->symbol_off + - a_hdr->symbols*a_hdr->symbol_size + - strings_size - strings_left; - a_hdr = (struct kallsyms_header *) (osec->contents = - xrealloc(a_hdr, a_hdr->total_size)); - p = (char *)a_hdr + a_hdr->symbol_off; - memcpy(p, symbols, a_hdr->symbols*a_hdr->symbol_size); - free(symbols); - p += a_hdr->symbols*a_hdr->symbol_size; - a_hdr->string_off = p - (char *)a_hdr; - memcpy(p, strings, strings_size - strings_left); - free(strings); - - *fout_result = fout; - return 0; -} diff --git a/mdk-stage1/insmod-modutils/obj/obj_load.c b/mdk-stage1/insmod-modutils/obj/obj_load.c deleted file mode 100644 index 62977acb7..000000000 --- a/mdk-stage1/insmod-modutils/obj/obj_load.c +++ /dev/null @@ -1,343 +0,0 @@ -/* Elf file reader. - Copyright 1996, 1997 Linux International. - - Contributed by Richard Henderson <rth@tamu.edu> - obj_free() added by Björn Ekwall <bj0rn@blox.se> March 1999 - Support for kallsyms Keith Owens <kaos@ocs.com.au> April 2000 - - This file is part of the Linux modutils. - - This program is free software; you can redistribute it and/or modify it - under the terms of the GNU General Public License as published by the - Free Software Foundation; either version 2 of the License, or (at your - option) any later version. - - This program is distributed in the hope that it will be useful, but - WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - General Public License for more details. - - You should have received a copy of the GNU General Public License - along with this program; if not, write to the Free Software Foundation, - Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ - -#include <alloca.h> -#include <string.h> -#include <stdlib.h> -#include <unistd.h> - -#include "obj.h" -#include "util.h" - -/*======================================================================*/ - -struct obj_file * -obj_load (int fp, Elf32_Half e_type, const char *filename) -{ - struct obj_file *f; - ElfW(Shdr) *section_headers; - int shnum, i; - char *shstrtab; - - /* Read the file header. */ - - f = arch_new_file(); - memset(f, 0, sizeof(*f)); - f->symbol_cmp = strcmp; - f->symbol_hash = obj_elf_hash; - f->load_order_search_start = &f->load_order; - - gzf_lseek(fp, 0, SEEK_SET); - if (gzf_read(fp, &f->header, sizeof(f->header)) != sizeof(f->header)) - { - error("cannot read ELF header from %s", filename); - return NULL; - } - - if (f->header.e_ident[EI_MAG0] != ELFMAG0 - || f->header.e_ident[EI_MAG1] != ELFMAG1 - || f->header.e_ident[EI_MAG2] != ELFMAG2 - || f->header.e_ident[EI_MAG3] != ELFMAG3) - { - error("%s is not an ELF file", filename); - return NULL; - } - if (f->header.e_ident[EI_CLASS] != ELFCLASSM - || f->header.e_ident[EI_DATA] != ELFDATAM - || f->header.e_ident[EI_VERSION] != EV_CURRENT - || !MATCH_MACHINE(f->header.e_machine)) - { - error("ELF file %s not for this architecture", filename); - return NULL; - } - if (f->header.e_type != e_type && e_type != ET_NONE) - { - switch (e_type) { - case ET_REL: - error("ELF file %s not a relocatable object", filename); - break; - case ET_EXEC: - error("ELF file %s not an executable object", filename); - break; - default: - error("ELF file %s has wrong type, expecting %d got %d", - filename, e_type, f->header.e_type); - break; - } - return NULL; - } - - /* Read the section headers. */ - - if (f->header.e_shentsize != sizeof(ElfW(Shdr))) - { - error("section header size mismatch %s: %lu != %lu", - filename, - (unsigned long)f->header.e_shentsize, - (unsigned long)sizeof(ElfW(Shdr))); - return NULL; - } - - shnum = f->header.e_shnum; - f->sections = xmalloc(sizeof(struct obj_section *) * shnum); - memset(f->sections, 0, sizeof(struct obj_section *) * shnum); - - section_headers = alloca(sizeof(ElfW(Shdr)) * shnum); - gzf_lseek(fp, f->header.e_shoff, SEEK_SET); - if (gzf_read(fp, section_headers, sizeof(ElfW(Shdr))*shnum) != sizeof(ElfW(Shdr))*shnum) - { - error("error reading ELF section headers %s: %m", filename); - return NULL; - } - - /* Read the section data. */ - - for (i = 0; i < shnum; ++i) - { - struct obj_section *sec; - - f->sections[i] = sec = arch_new_section(); - memset(sec, 0, sizeof(*sec)); - - sec->header = section_headers[i]; - sec->idx = i; - - switch (sec->header.sh_type) - { - case SHT_NULL: - case SHT_NOTE: - case SHT_NOBITS: - /* ignore */ - break; - - case SHT_PROGBITS: - case SHT_SYMTAB: - case SHT_STRTAB: - case SHT_RELM: - if (sec->header.sh_size > 0) - { - sec->contents = xmalloc(sec->header.sh_size); - gzf_lseek(fp, sec->header.sh_offset, SEEK_SET); - if (gzf_read(fp, sec->contents, sec->header.sh_size) != sec->header.sh_size) - { - error("error reading ELF section data %s: %m", filename); - return NULL; - } - } - else - sec->contents = NULL; - break; - -#if SHT_RELM == SHT_REL - case SHT_RELA: - if (sec->header.sh_size) { - error("RELA relocations not supported on this architecture %s", filename); - return NULL; - } - break; -#else - case SHT_REL: - if (sec->header.sh_size) { - error("REL relocations not supported on this architecture %s", filename); - return NULL; - } - break; -#endif - - default: - if (sec->header.sh_type >= SHT_LOPROC) - { - if (arch_load_proc_section(sec, fp) < 0) - return NULL; - break; - } - - error("can't handle sections of type %ld %s", - (long)sec->header.sh_type, filename); - return NULL; - } - } - - /* Do what sort of interpretation as needed by each section. */ - - shstrtab = f->sections[f->header.e_shstrndx]->contents; - - for (i = 0; i < shnum; ++i) - { - struct obj_section *sec = f->sections[i]; - sec->name = shstrtab + sec->header.sh_name; - } - - for (i = 0; i < shnum; ++i) - { - struct obj_section *sec = f->sections[i]; - - /* .modinfo and .modstring should be contents only but gcc has no - * attribute for that. The kernel may have marked these sections as - * ALLOC, ignore the allocate bit. - */ - if (strcmp(sec->name, ".modinfo") == 0 || - strcmp(sec->name, ".modstring") == 0) - sec->header.sh_flags &= ~SHF_ALLOC; - - if (sec->header.sh_flags & SHF_ALLOC) - obj_insert_section_load_order(f, sec); - - switch (sec->header.sh_type) - { - case SHT_SYMTAB: - { - unsigned long nsym, j; - char *strtab; - ElfW(Sym) *sym; - - if (sec->header.sh_entsize != sizeof(ElfW(Sym))) - { - error("symbol size mismatch %s: %lu != %lu", - filename, - (unsigned long)sec->header.sh_entsize, - (unsigned long)sizeof(ElfW(Sym))); - return NULL; - } - - nsym = sec->header.sh_size / sizeof(ElfW(Sym)); - strtab = f->sections[sec->header.sh_link]->contents; - sym = (ElfW(Sym) *) sec->contents; - - /* Allocate space for a table of local symbols. */ - j = f->local_symtab_size = sec->header.sh_info; - f->local_symtab = xmalloc(j *= sizeof(struct obj_symbol *)); - memset(f->local_symtab, 0, j); - - /* Insert all symbols into the hash table. */ - for (j = 1, ++sym; j < nsym; ++j, ++sym) - { - const char *name; - if (sym->st_name) - name = strtab+sym->st_name; - else - name = f->sections[sym->st_shndx]->name; - - obj_add_symbol(f, name, j, sym->st_info, sym->st_shndx, - sym->st_value, sym->st_size); - - } - } - break; - } - } - - /* second pass to add relocation data to symbols */ - for (i = 0; i < shnum; ++i) - { - struct obj_section *sec = f->sections[i]; - switch (sec->header.sh_type) - { - case SHT_RELM: - { - unsigned long nrel, j, nsyms; - ElfW(RelM) *rel; - struct obj_section *symtab; - char *strtab; - if (sec->header.sh_entsize != sizeof(ElfW(RelM))) - { - error("relocation entry size mismatch %s: %lu != %lu", - filename, - (unsigned long)sec->header.sh_entsize, - (unsigned long)sizeof(ElfW(RelM))); - return NULL; - } - - nrel = sec->header.sh_size / sizeof(ElfW(RelM)); - rel = (ElfW(RelM) *) sec->contents; - symtab = f->sections[sec->header.sh_link]; - nsyms = symtab->header.sh_size / symtab->header.sh_entsize; - strtab = f->sections[symtab->header.sh_link]->contents; - - /* Save the relocate type in each symbol entry. */ - for (j = 0; j < nrel; ++j, ++rel) - { - struct obj_symbol *intsym; - unsigned long symndx; - symndx = ELFW(R_SYM)(rel->r_info); - if (symndx) - { - if (symndx >= nsyms) - { - error("%s: Bad symbol index: %08lx >= %08lx", - filename, symndx, nsyms); - continue; - } - - obj_find_relsym(intsym, f, f, rel, (ElfW(Sym) *)(symtab->contents), strtab); - intsym->r_type = ELFW(R_TYPE)(rel->r_info); - } - } - } - break; - } - } - - f->filename = xstrdup(filename); - - return f; -} - -void obj_free(struct obj_file *f) -{ - struct obj_section *sec; - struct obj_symbol *sym; - struct obj_symbol *next; - int i; - int n; - - if (f->sections) { - n = f->header.e_shnum; - for (i = 0; i < n; ++i) { - if ((sec = f->sections[i]) != NULL) { - if (sec->contents) - free(sec->contents); - free(sec); - } - } - free(f->sections); - } - - for (i = 0; i < HASH_BUCKETS; ++i) { - for (sym = f->symtab[i]; sym; sym = next) { - next = sym->next; - free(sym); - } - } - - if (f->local_symtab) - free(f->local_symtab); - - if (f->filename) - free((char *)(f->filename)); - - if (f->persist) - free((char *)(f->persist)); - - free(f); -} diff --git a/mdk-stage1/insmod-modutils/obj/obj_m68k.c b/mdk-stage1/insmod-modutils/obj/obj_m68k.c deleted file mode 100644 index abc070bca..000000000 --- a/mdk-stage1/insmod-modutils/obj/obj_m68k.c +++ /dev/null @@ -1,145 +0,0 @@ -/* m68k specific support for Elf loading and relocation. - Copyright 1996, 1997 Linux International. - - Contributed by Richard Henderson <rth@tamu.edu> - - This file is part of the Linux modutils. - - This program is free software; you can redistribute it and/or modify it - under the terms of the GNU General Public License as published by the - Free Software Foundation; either version 2 of the License, or (at your - option) any later version. - - This program is distributed in the hope that it will be useful, but - WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - General Public License for more details. - - You should have received a copy of the GNU General Public License - along with this program; if not, write to the Free Software Foundation, - Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ - -#include <stddef.h> -#include <module.h> -#include <obj.h> -#include <util.h> - - -/*======================================================================*/ - -struct obj_file * -arch_new_file (void) -{ - return xmalloc(sizeof(struct obj_file)); -} - -struct obj_section * -arch_new_section (void) -{ - return xmalloc(sizeof(struct obj_section)); -} - -struct obj_symbol * -arch_new_symbol (void) -{ - return xmalloc(sizeof(struct obj_symbol)); -} - -int -arch_load_proc_section(struct obj_section *sec, int fp) -{ - /* Assume it's just a debugging section that we can safely - ignore ... */ - sec->contents = NULL; - - return 0; -} - -enum obj_reloc -arch_apply_relocation (struct obj_file *ef, - struct obj_section *targsec, - struct obj_section *symsec, - struct obj_symbol *sym, - Elf32_Rela *rel, - Elf32_Addr v) -{ - char *loc = targsec->contents + rel->r_offset; - Elf32_Addr dot = targsec->header.sh_addr + rel->r_offset; - - enum obj_reloc ret = obj_reloc_ok; - - switch (ELF32_R_TYPE(rel->r_info)) - { - case R_68K_NONE: - break; - - case R_68K_8: - if (v > 0xff) - ret = obj_reloc_overflow; - *(char *)loc = v; - break; - case R_68K_16: - if (v > 0xffff) - ret = obj_reloc_overflow; - *(short *)loc = v; - break; - case R_68K_32: - *(int *)loc = v; - break; - - case R_68K_PC8: - v -= dot; - if ((Elf32_Sword)v > 0x7f || (Elf32_Sword)v < -(Elf32_Sword)0x80) - ret = obj_reloc_overflow; - *(char *)loc = v; - break; - case R_68K_PC16: - v -= dot; - if ((Elf32_Sword)v > 0x7fff || (Elf32_Sword)v < -(Elf32_Sword)0x8000) - ret = obj_reloc_overflow; - *(short *)loc = v; - break; - case R_68K_PC32: - *(int *)loc = v - dot; - break; - - case R_68K_RELATIVE: - *(int *)loc += ef->baseaddr; - break; - - default: - ret = obj_reloc_unhandled; - break; - } - - return ret; -} - -int -arch_create_got (struct obj_file *ef) -{ - return 1; -} - -int -arch_init_module (struct obj_file *f, struct module *mod) -{ - return 1; -} - -int -arch_finalize_section_address(struct obj_file *f, Elf32_Addr base) -{ - int i, n = f->header.e_shnum; - - f->baseaddr = base; - for (i = 0; i < n; ++i) - f->sections[i]->header.sh_addr += base; - return 1; -} - -int -arch_archdata (struct obj_file *fin, struct obj_section *sec) -{ - return 0; -} diff --git a/mdk-stage1/insmod-modutils/obj/obj_mips.c b/mdk-stage1/insmod-modutils/obj/obj_mips.c deleted file mode 100644 index 2db0791b6..000000000 --- a/mdk-stage1/insmod-modutils/obj/obj_mips.c +++ /dev/null @@ -1,254 +0,0 @@ -/* MIPS specific support for Elf loading and relocation. - Copyright 1997, 1998 Linux International. - Contributed by Ralf Baechle <ralf@gnu.ai.mit.edu> - - This file is part of the Linux modutils. - - This program is free software; you can redistribute it and/or modify it - under the terms of the GNU General Public License as published by the - Free Software Foundation; either version 2 of the License, or (at your - option) any later version. - - This program is distributed in the hope that it will be useful, but - WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - General Public License for more details. - - You should have received a copy of the GNU General Public License - along with this program; if not, write to the Free Software Foundation, - Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ - -#include <string.h> -#include <stdlib.h> -#include <assert.h> - -#include <module.h> -#include <obj.h> -#include <util.h> - - -/*======================================================================*/ - -struct mips_hi16 -{ - struct mips_hi16 *next; - Elf32_Addr *addr; - Elf32_Addr value; -}; - -struct mips_file -{ - struct obj_file root; - struct mips_hi16 *mips_hi16_list; -}; - -/*======================================================================*/ - -struct obj_file * -arch_new_file (void) -{ - struct mips_file *mf; - - mf = xmalloc(sizeof(*mf)); - mf->mips_hi16_list = NULL; - - return (struct obj_file *) mf; -} - -struct obj_section * -arch_new_section (void) -{ - return xmalloc(sizeof(struct obj_section)); -} - -struct obj_symbol * -arch_new_symbol (void) -{ - return xmalloc(sizeof(struct obj_symbol)); -} - -int -arch_load_proc_section(struct obj_section *sec, int fp) -{ - switch (sec->header.sh_type) - { - case SHT_MIPS_DEBUG: - case SHT_MIPS_REGINFO: - /* Actually these two sections are as useless as something can be ... */ - sec->contents = NULL; - break; - - case SHT_MIPS_LIBLIST: - case SHT_MIPS_CONFLICT: - case SHT_MIPS_GPTAB: - case SHT_MIPS_UCODE: - case SHT_MIPS_OPTIONS: - case SHT_MIPS_DWARF: - case SHT_MIPS_EVENTS: - /* These shouldn't ever be in a module file. */ - error("Unhandled section header type: %08x", sec->header.sh_type); - - default: - /* We don't even know the type. This time it might as well be a - supernova. */ - error("Unknown section header type: %08x", sec->header.sh_type); - return -1; - } - - return 0; -} - -enum obj_reloc -arch_apply_relocation (struct obj_file *f, - struct obj_section *targsec, - struct obj_section *symsec, - struct obj_symbol *sym, - Elf32_Rel *rel, - Elf32_Addr v) -{ - struct mips_file *mf = (struct mips_file *)f; - Elf32_Addr *loc = (Elf32_Addr *)(targsec->contents + rel->r_offset); - Elf32_Addr dot = targsec->header.sh_addr + rel->r_offset; - enum obj_reloc ret = obj_reloc_ok; - - /* _gp_disp is a magic symbol for PIC which is not supported for - the kernel and loadable modules. */ - if (strcmp(sym->name, "_gp_disp") == 0) - ret = obj_reloc_unhandled; - - switch (ELF32_R_TYPE(rel->r_info)) - { - case R_MIPS_NONE: - break; - - case R_MIPS_32: - *loc += v; - break; - - case R_MIPS_26: - if (v % 4) - ret = obj_reloc_dangerous; - if ((v & 0xf0000000) != ((dot + 4) & 0xf0000000)) - ret = obj_reloc_overflow; - *loc = (*loc & ~0x03ffffff) | ((*loc + (v >> 2)) & 0x03ffffff); - break; - - case R_MIPS_HI16: - { - struct mips_hi16 *n; - - /* We cannot relocate this one now because we don't know the value - of the carry we need to add. Save the information, and let LO16 - do the actual relocation. */ - n = (struct mips_hi16 *) xmalloc (sizeof *n); - n->addr = loc; - n->value = v; - n->next = mf->mips_hi16_list; - mf->mips_hi16_list = n; - break; - } - - case R_MIPS_LO16: - { - unsigned long insnlo = *loc; - Elf32_Addr val, vallo; - - /* Sign extend the addend we extract from the lo insn. */ - vallo = ((insnlo & 0xffff) ^ 0x8000) - 0x8000; - - if (mf->mips_hi16_list != NULL) - { - struct mips_hi16 *l; - - l = mf->mips_hi16_list; - while (l != NULL) - { - struct mips_hi16 *next; - unsigned long insn; - - /* The value for the HI16 had best be the same. */ - assert(v == l->value); - - /* Do the HI16 relocation. Note that we actually don't - need to know anything about the LO16 itself, except where - to find the low 16 bits of the addend needed by the LO16. */ - insn = *l->addr; - val = ((insn & 0xffff) << 16) + vallo; - val += v; - - /* Account for the sign extension that will happen in the - low bits. */ - val = ((val >> 16) + ((val & 0x8000) != 0)) & 0xffff; - - insn = (insn &~ 0xffff) | val; - *l->addr = insn; - - next = l->next; - free(l); - l = next; - } - - mf->mips_hi16_list = NULL; - } - - /* Ok, we're done with the HI16 relocs. Now deal with the LO16. */ - val = v + vallo; - insnlo = (insnlo & ~0xffff) | (val & 0xffff); - *loc = insnlo; - break; - } - - default: - ret = obj_reloc_unhandled; - break; - } - - return ret; -} - -int -arch_create_got (struct obj_file *f) -{ - return 1; -} - -int -arch_init_module (struct obj_file *f, struct module *mod) -{ - return 1; -} - -int -arch_finalize_section_address(struct obj_file *f, Elf32_Addr base) -{ - int i, n = f->header.e_shnum; - - f->baseaddr = base; - for (i = 0; i < n; ++i) - f->sections[i]->header.sh_addr += base; - return 1; -} - -int -arch_archdata (struct obj_file *f, struct obj_section *archdata_sec) -{ - struct archdata { - unsigned tgt_long __start___dbe_table; - unsigned tgt_long __stop___dbe_table; - } *ad; - struct obj_section *sec; - - if (archdata_sec->contents) - free(archdata_sec->contents); - archdata_sec->header.sh_size = 0; - sec = obj_find_section(f, "__dbe_table"); - if (sec) { - ad = (struct archdata *) (archdata_sec->contents) = xmalloc(sizeof(*ad)); - memset(ad, 0, sizeof(*ad)); - archdata_sec->header.sh_size = sizeof(*ad); - ad->__start___dbe_table = sec->header.sh_addr; - ad->__stop___dbe_table = sec->header.sh_addr + sec->header.sh_size; - } - - return 0; -} diff --git a/mdk-stage1/insmod-modutils/obj/obj_ppc.c b/mdk-stage1/insmod-modutils/obj/obj_ppc.c deleted file mode 100644 index 4889454f2..000000000 --- a/mdk-stage1/insmod-modutils/obj/obj_ppc.c +++ /dev/null @@ -1,266 +0,0 @@ -/* PowerPC specific support for Elf loading and relocation. - Copyright 1996, 1997 Linux International. - - Adapted by Paul Mackerras <paulus@cs.anu.edu.au> from the - obj-sparc.c and obj-alpha.c files. - - This file is part of the Linux modutils. - - This program is free software; you can redistribute it and/or modify it - under the terms of the GNU General Public License as published by the - Free Software Foundation; either version 2 of the License, or (at your - option) any later version. - - This program is distributed in the hope that it will be useful, but - WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - General Public License for more details. - - You should have received a copy of the GNU General Public License - along with this program; if not, write to the Free Software Foundation, - Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ - -#include <stddef.h> -#include <module.h> -#include <obj.h> -#include <util.h> -#include <assert.h> - - -/*======================================================================*/ - -/* - * Unfortunately, the bl (branch-and-link) instruction used for - * procedure calls on the PowerPC can only reach +/- 32MB from the - * current instruction. If the module is loaded far enough away from - * the main kernel text (or other modules) that this limit is - * exceeded, we have to redirect procedure calls via a procedure - * linkage table (PLT). Each entry in the PLT contains instructions - * to put the address of the procedure in a register and jump to it. - */ - -typedef unsigned int instruction; /* a powerpc instruction (4 bytes) */ - -struct ppc_plt_entry -{ - struct ppc_plt_entry *next; - ElfW(Addr) addend; - int offset; - int inited; -}; - -struct ppc_file -{ - struct obj_file file; - struct obj_section *plt; -}; - -struct ppc_symbol -{ - struct obj_symbol sym; - struct ppc_plt_entry *plt_entries; -}; - -struct obj_file * -arch_new_file (void) -{ - struct ppc_file *f; - - f = xmalloc(sizeof(struct ppc_file)); - f->plt = NULL; - return &f->file; -} - -struct obj_section * -arch_new_section (void) -{ - return xmalloc(sizeof(struct obj_section)); -} - -struct obj_symbol * -arch_new_symbol (void) -{ - struct ppc_symbol *p; - - p = xmalloc(sizeof(struct ppc_symbol)); - p->plt_entries = NULL; - return &p->sym; -} - -int -arch_load_proc_section(struct obj_section *sec, int fp) -{ - /* Assume it's just a debugging section that we can safely - ignore ... */ - sec->contents = NULL; - - return 0; -} - -enum obj_reloc -arch_apply_relocation (struct obj_file *ef, - struct obj_section *targsec, - struct obj_section *symsec, - struct obj_symbol *sym, - Elf32_Rela *rel, - Elf32_Addr v) -{ - Elf32_Addr *loc = (Elf32_Addr *)(targsec->contents + rel->r_offset); - Elf32_Addr dot = targsec->header.sh_addr + rel->r_offset; - struct ppc_file *pf = (struct ppc_file *) ef; - struct ppc_symbol *psym = (struct ppc_symbol *) sym; - struct ppc_plt_entry *pe; - instruction *ip; - - enum obj_reloc ret = obj_reloc_ok; - - switch (ELF32_R_TYPE(rel->r_info)) - { - case R_PPC_ADDR16_HA: - *(unsigned short *)loc = (v + 0x8000) >> 16; - break; - - case R_PPC_ADDR16_HI: - *(unsigned short *)loc = v >> 16; - break; - - case R_PPC_ADDR16_LO: - *(unsigned short *)loc = v; - break; - - case R_PPC_REL24: - /* find the plt entry and initialize it if necessary */ - assert(psym != NULL); - for (pe = psym->plt_entries; pe != NULL && pe->addend != rel->r_addend; ) - pe = pe->next; - assert(pe != NULL); - if (!pe->inited) - { - ip = (instruction *) (pf->plt->contents + pe->offset); - ip[0] = 0x3d600000 + ((v + 0x8000) >> 16); /* lis r11,sym@ha */ - ip[1] = 0x396b0000 + (v & 0xffff); /* addi r11,r11,sym@l */ - ip[2] = 0x7d6903a6; /* mtctr r11 */ - ip[3] = 0x4e800420; /* bctr */ - pe->inited = 1; - } - - v -= dot; - if ((int)v < -0x02000000 || (int)v >= 0x02000000) - { - /* go via the plt */ - v = pf->plt->header.sh_addr + pe->offset - dot; - } - if (v & 3) - ret = obj_reloc_dangerous; - *loc = (*loc & ~0x03fffffc) | (v & 0x03fffffc); - break; - - case R_PPC_REL32: - *loc = v - dot; - break; - - case R_PPC_ADDR32: - *loc = v; - break; - - default: - ret = obj_reloc_unhandled; - break; - } - - return ret; -} - -int -arch_create_got (struct obj_file *f) -{ - struct ppc_file *pf = (struct ppc_file *) f; - int i, offset; - struct obj_section *sec, *syms, *strs; - ElfW(Rela) *rel, *relend; - ElfW(Sym) *symtab; - const char *strtab; - struct ppc_symbol *intsym; - struct ppc_plt_entry *pe; - - offset = 0; - for (i = 0; i < f->header.e_shnum; ++i) - { - sec = f->sections[i]; - if (sec->header.sh_type != SHT_RELM) - continue; - syms = f->sections[sec->header.sh_link]; - strs = f->sections[syms->header.sh_link]; - - rel = (ElfW(RelM) *) sec->contents; - relend = rel + (sec->header.sh_size / sizeof(ElfW(RelM))); - symtab = (ElfW(Sym) *) syms->contents; - strtab = (const char *) strs->contents; - - for (; rel < relend; ++rel) - { - if (ELF32_R_TYPE(rel->r_info) != R_PPC_REL24) - continue; - obj_find_relsym(intsym, f, f, rel, symtab, strtab); - - for (pe = intsym->plt_entries; pe != NULL; pe = pe->next) - if (pe->addend == rel->r_addend) - break; - if (pe == NULL) - { - pe = xmalloc(sizeof(struct ppc_plt_entry)); - pe->next = intsym->plt_entries; - pe->addend = rel->r_addend; - pe->offset = offset; - pe->inited = 0; - intsym->plt_entries = pe; - offset += 16; - } - } - } - - pf->plt = obj_create_alloced_section(f, ".plt", 16, offset, SHF_WRITE); - - return 1; -} - -int -arch_init_module (struct obj_file *f, struct module *mod) -{ - return 1; -} - -int -arch_finalize_section_address(struct obj_file *f, Elf32_Addr base) -{ - int i, n = f->header.e_shnum; - - f->baseaddr = base; - for (i = 0; i < n; ++i) - f->sections[i]->header.sh_addr += base; - return 1; -} - -int -arch_archdata (struct obj_file *f, struct obj_section *archdata_sec) -{ - struct archdata { - unsigned tgt_long __start___ftr_fixup; - unsigned tgt_long __stop___ftr_fixup; - } *ad; - struct obj_section *sec; - - if (archdata_sec->contents) - free(archdata_sec->contents); - archdata_sec->header.sh_size = 0; - sec = obj_find_section(f, "__ftr_fixup"); - if (sec) { - ad = (struct archdata *) (archdata_sec->contents) = xmalloc(sizeof(*ad)); - memset(ad, 0, sizeof(*ad)); - archdata_sec->header.sh_size = sizeof(*ad); - ad->__start___ftr_fixup = sec->header.sh_addr; - ad->__stop___ftr_fixup = sec->header.sh_addr + sec->header.sh_size; - } - - return 0; -} diff --git a/mdk-stage1/insmod-modutils/obj/obj_reloc.c b/mdk-stage1/insmod-modutils/obj/obj_reloc.c deleted file mode 100644 index 3f2c8aab0..000000000 --- a/mdk-stage1/insmod-modutils/obj/obj_reloc.c +++ /dev/null @@ -1,413 +0,0 @@ -/* Elf relocation routines. - Copyright 1996, 1997 Linux International. - - Contributed by Richard Henderson <rth@tamu.edu> - - This file is part of the Linux modutils. - - This program is free software; you can redistribute it and/or modify it - under the terms of the GNU General Public License as published by the - Free Software Foundation; either version 2 of the License, or (at your - option) any later version. - - This program is distributed in the hope that it will be useful, but - WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - General Public License for more details. - - You should have received a copy of the GNU General Public License - along with this program; if not, write to the Free Software Foundation, - Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ - -#include <string.h> -#include <assert.h> -#include <alloca.h> - -#include <obj.h> -#include <util.h> - -/*======================================================================*/ - -int -obj_string_patch(struct obj_file *f, int secidx, ElfW(Addr) offset, - const char *string) -{ - struct obj_string_patch_struct *p; - struct obj_section *strsec; - size_t len = strlen(string)+1; - char *loc; - - p = xmalloc(sizeof(*p)); - p->next = f->string_patches; - p->reloc_secidx = secidx; - p->reloc_offset = offset; - f->string_patches = p; - - strsec = obj_find_section(f, ".kstrtab"); - if (strsec == NULL) - { - strsec = obj_create_alloced_section(f, ".kstrtab", 1, len, 0); - p->string_offset = 0; - loc = strsec->contents; - } - else - { - p->string_offset = strsec->header.sh_size; - loc = obj_extend_section(strsec, len); - } - memcpy(loc, string, len); - - return 1; -} - -int -obj_symbol_patch(struct obj_file *f, int secidx, ElfW(Addr) offset, - struct obj_symbol *sym) -{ - struct obj_symbol_patch_struct *p; - - p = xmalloc(sizeof(*p)); - p->next = f->symbol_patches; - p->reloc_secidx = secidx; - p->reloc_offset = offset; - p->sym = sym; - f->symbol_patches = p; - - return 1; -} - -int -obj_check_undefineds(struct obj_file *f, int quiet) -{ - unsigned long i; - int ret = 1; - - for (i = 0; i < HASH_BUCKETS; ++i) - { - struct obj_symbol *sym; - for (sym = f->symtab[i]; sym ; sym = sym->next) - if (sym->secidx == SHN_UNDEF) - { - if (ELFW(ST_BIND)(sym->info) == STB_WEAK) - { - sym->secidx = SHN_ABS; - sym->value = 0; - } - else if (sym->r_type) /* assumes R_arch_NONE is 0 on all arch */ - { - if (!quiet) - error("unresolved symbol %s", sym->name); - ret = 0; - } - } - } - - return ret; -} - -void -obj_clear_undefineds(struct obj_file *f) -{ - unsigned long i; - struct obj_symbol *sym; - for (i = 0; i < HASH_BUCKETS; ++i) - { - for (sym = f->symtab[i]; sym ; sym = sym->next) - if (sym->secidx == SHN_UNDEF) - { - sym->secidx = SHN_ABS; - sym->value = 0; - } - } -} - -void -obj_allocate_commons(struct obj_file *f) -{ - struct common_entry - { - struct common_entry *next; - struct obj_symbol *sym; - } *common_head = NULL; - - unsigned long i; - - for (i = 0; i < HASH_BUCKETS; ++i) - { - struct obj_symbol *sym; - for (sym = f->symtab[i]; sym ; sym = sym->next) - if (sym->secidx == SHN_COMMON) - { - /* Collect all COMMON symbols and sort them by size so as to - minimize space wasted by alignment requirements. */ - { - struct common_entry **p, *n; - for (p = &common_head; *p ; p = &(*p)->next) - if (sym->size <= (*p)->sym->size) - break; - - n = alloca(sizeof(*n)); - n->next = *p; - n->sym = sym; - *p = n; - } - } - } - - for (i = 1; i < f->local_symtab_size; ++i) - { - struct obj_symbol *sym = f->local_symtab[i]; - if (sym && sym->secidx == SHN_COMMON) - { - struct common_entry **p, *n; - for (p = &common_head; *p ; p = &(*p)->next) - if (sym == (*p)->sym) - break; - else if (sym->size < (*p)->sym->size) - { - n = alloca(sizeof(*n)); - n->next = *p; - n->sym = sym; - *p = n; - break; - } - } - } - - if (common_head) - { - /* Find the bss section. */ - for (i = 0; i < f->header.e_shnum; ++i) - if (f->sections[i]->header.sh_type == SHT_NOBITS) - break; - - /* If for some reason there hadn't been one, create one. */ - if (i == f->header.e_shnum) - { - struct obj_section *sec; - - f->sections = xrealloc(f->sections, (i+1) * sizeof(sec)); - f->sections[i] = sec = arch_new_section(); - f->header.e_shnum = i+1; - - memset(sec, 0, sizeof(*sec)); - sec->header.sh_type = SHT_PROGBITS; - sec->header.sh_flags = SHF_WRITE|SHF_ALLOC; - sec->name = ".bss"; - sec->idx = i; - } - - /* Allocate the COMMONS. */ - { - ElfW(Addr) bss_size = f->sections[i]->header.sh_size; - ElfW(Addr) max_align = f->sections[i]->header.sh_addralign; - struct common_entry *c; - - for (c = common_head; c ; c = c->next) - { - ElfW(Addr) align = c->sym->value; - - if (align > max_align) - max_align = align; - if (bss_size & (align - 1)) - bss_size = (bss_size | (align - 1)) + 1; - - c->sym->secidx = i; - c->sym->value = bss_size; - - bss_size += c->sym->size; - } - - f->sections[i]->header.sh_size = bss_size; - f->sections[i]->header.sh_addralign = max_align; - } - } - - /* For the sake of patch relocation and parameter initialization, - allocate zeroed data for NOBITS sections now. Note that after - this we cannot assume NOBITS are really empty. */ - for (i = 0; i < f->header.e_shnum; ++i) - { - struct obj_section *s = f->sections[i]; - if (s->header.sh_type == SHT_NOBITS) - { - if (s->header.sh_size) - s->contents = memset(xmalloc(s->header.sh_size), - 0, s->header.sh_size); - else - s->contents = NULL; - s->header.sh_type = SHT_PROGBITS; - } - } -} - -unsigned long -obj_load_size (struct obj_file *f) -{ - unsigned long dot = 0; - struct obj_section *sec; - - /* Finalize the positions of the sections relative to one another. */ - - for (sec = f->load_order; sec ; sec = sec->load_next) - { - ElfW(Addr) align; - - align = sec->header.sh_addralign; - if (align && (dot & (align - 1))) - dot = (dot | (align - 1)) + 1; - - sec->header.sh_addr = dot; - dot += sec->header.sh_size; - } - - return dot; -} - -int -obj_relocate (struct obj_file *f, ElfW(Addr) base) -{ - int i, n = f->header.e_shnum; - int ret = 1; - - /* Finalize the addresses of the sections. */ - - arch_finalize_section_address(f, base); - - /* And iterate over all of the relocations. */ - - for (i = 0; i < n; ++i) - { - struct obj_section *relsec, *symsec, *targsec, *strsec; - ElfW(RelM) *rel, *relend; - ElfW(Sym) *symtab; - const char *strtab; - unsigned long nsyms; - - relsec = f->sections[i]; - if (relsec->header.sh_type != SHT_RELM) - continue; - - symsec = f->sections[relsec->header.sh_link]; - targsec = f->sections[relsec->header.sh_info]; - strsec = f->sections[symsec->header.sh_link]; - - if (!(targsec->header.sh_flags & SHF_ALLOC)) - continue; - - rel = (ElfW(RelM) *)relsec->contents; - relend = rel + (relsec->header.sh_size / sizeof(ElfW(RelM))); - symtab = (ElfW(Sym) *)symsec->contents; - nsyms = symsec->header.sh_size / symsec->header.sh_entsize; - strtab = (const char *)strsec->contents; - - for (; rel < relend; ++rel) - { - ElfW(Addr) value = 0; - struct obj_symbol *intsym = NULL; - unsigned long symndx; - const char *errmsg; - - /* Attempt to find a value to use for this relocation. */ - - symndx = ELFW(R_SYM)(rel->r_info); - if (symndx) - { - /* Note we've already checked for undefined symbols. */ - - if (symndx >= nsyms) - { - error("Bad symbol index: %08lx >= %08lx", - symndx, nsyms); - continue; - } - - obj_find_relsym(intsym, f, f, rel, symtab, strtab); - value = obj_symbol_final_value(f, intsym); - } - -#if SHT_RELM == SHT_RELA - value += rel->r_addend; -#endif - - /* Do it! */ - switch (arch_apply_relocation(f,targsec,symsec,intsym,rel,value)) - { - case obj_reloc_ok: - break; - - case obj_reloc_overflow: - errmsg = "Relocation overflow"; - goto bad_reloc; - case obj_reloc_dangerous: - errmsg = "Dangerous relocation"; - goto bad_reloc; - case obj_reloc_unhandled: - errmsg = "Unhandled relocation"; - goto bad_reloc; - case obj_reloc_constant_gp: - errmsg = "Modules compiled with -mconstant-gp cannot be loaded"; - goto bad_reloc; - bad_reloc: - error("%s of type %ld for %s", errmsg, - (long)ELFW(R_TYPE)(rel->r_info), intsym->name); - ret = 0; - break; - } - } - } - - /* Finally, take care of the patches. */ - - if (f->string_patches) - { - struct obj_string_patch_struct *p; - struct obj_section *strsec; - ElfW(Addr) strsec_base; - strsec = obj_find_section(f, ".kstrtab"); - strsec_base = strsec->header.sh_addr; - - for (p = f->string_patches; p ; p = p->next) - { - struct obj_section *targsec = f->sections[p->reloc_secidx]; - *(ElfW(Addr) *)(targsec->contents + p->reloc_offset) - = strsec_base + p->string_offset; - } - } - - if (f->symbol_patches) - { - struct obj_symbol_patch_struct *p; - - for (p = f->symbol_patches; p; p = p->next) - { - struct obj_section *targsec = f->sections[p->reloc_secidx]; - *(ElfW(Addr) *)(targsec->contents + p->reloc_offset) - = obj_symbol_final_value(f, p->sym); - } - } - - return ret; -} - -int -obj_create_image (struct obj_file *f, char *image) -{ - struct obj_section *sec; - ElfW(Addr) base = f->baseaddr; - - for (sec = f->load_order; sec ; sec = sec->load_next) - { - char *secimg; - - if (sec->contents == 0) - continue; - - secimg = image + (sec->header.sh_addr - base); - - /* Note that we allocated data for NOBITS sections earlier. */ - memcpy(secimg, sec->contents, sec->header.sh_size); - } - - return 1; -} diff --git a/mdk-stage1/insmod-modutils/obj/obj_s390.c b/mdk-stage1/insmod-modutils/obj/obj_s390.c deleted file mode 100644 index a76e28479..000000000 --- a/mdk-stage1/insmod-modutils/obj/obj_s390.c +++ /dev/null @@ -1,332 +0,0 @@ -/* IBM S/390 31-bit specific support for Elf loading and relocation. - Copyright 2000, 2001 IBM Deutschland Entwicklung GmbH, IBM Corporation. - - Contributed by Martin Schwidefsky <schwidefsky@de.ibm.com> - - Derived from obj/obj_i386.c: - Copyright 1996, 1997 Linux International. - Contributed by Richard Henderson <rth@tamu.edu> - - This file is part of the Linux modutils. - - This program is free software; you can redistribute it and/or modify it - under the terms of the GNU General Public License as published by the - Free Software Foundation; either version 2 of the License, or (at your - option) any later version. - - This program is distributed in the hope that it will be useful, but - WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - General Public License for more details. - - You should have received a copy of the GNU General Public License - along with this program; if not, write to the Free Software Foundation, - Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ - -#include <string.h> -#include <assert.h> - -#include <module.h> -#include <obj.h> -#include <util.h> - - -/*======================================================================*/ - -struct s390_plt_entry -{ - long offset; - int allocated:1; - int initialized:1; -}; - -struct s390_got_entry -{ - long offset; - unsigned allocated:1; - unsigned reloc_done : 1; -}; - -struct s390_file -{ - struct obj_file root; - struct obj_section *plt; - struct obj_section *got; -}; - -struct s390_symbol -{ - struct obj_symbol root; - struct s390_plt_entry pltent; - struct s390_got_entry gotent; -}; - - -/*======================================================================*/ - -struct obj_file * -arch_new_file (void) -{ - struct s390_file *f; - f = xmalloc(sizeof(*f)); - f->got = NULL; - f->plt = NULL; - return &f->root; -} - -struct obj_section * -arch_new_section (void) -{ - return xmalloc(sizeof(struct obj_section)); -} - -struct obj_symbol * -arch_new_symbol (void) -{ - struct s390_symbol *sym; - sym = xmalloc(sizeof(*sym)); - memset(&sym->gotent, 0, sizeof(sym->gotent)); - memset(&sym->pltent, 0, sizeof(sym->pltent)); - return &sym->root; -} - -int -arch_load_proc_section(struct obj_section *sec, int fp) -{ - /* Assume it's just a debugging section that we can safely - ignore ... */ - sec->contents = NULL; - - return 0; -} - -enum obj_reloc -arch_apply_relocation (struct obj_file *f, - struct obj_section *targsec, - struct obj_section *symsec, - struct obj_symbol *sym, - Elf32_Rela *rel, - Elf32_Addr v) -{ - struct s390_file *ifile = (struct s390_file *) f; - struct s390_symbol *isym = (struct s390_symbol *) sym; - struct s390_plt_entry *pe; - - Elf32_Addr *loc = (Elf32_Addr *)(targsec->contents + rel->r_offset); - Elf32_Addr dot = targsec->header.sh_addr + rel->r_offset; - Elf32_Addr got = ifile->got ? ifile->got->header.sh_addr : 0; - Elf32_Addr plt = ifile->plt ? ifile->plt->header.sh_addr : 0; - - enum obj_reloc ret = obj_reloc_ok; - - switch (ELF32_R_TYPE(rel->r_info)) - { - case R_390_NONE: - break; - - case R_390_32: - *(unsigned int *) loc += v; - break; - case R_390_16: - *(unsigned short *) loc += v; - break; - case R_390_8: - *(unsigned char *) loc += v; - break; - - case R_390_PC32: - *(unsigned int *) loc += v - dot; - break; - case R_390_PC16DBL: - *(unsigned short *) loc += (v - dot) >> 1; - break; - case R_390_PC16: - *(unsigned short *) loc += v - dot; - break; - - case R_390_PLT32: - case R_390_PLT16DBL: - /* find the plt entry and initialize it. */ - assert(isym != NULL); - pe = (struct s390_plt_entry *) &isym->pltent; - assert(pe->allocated); - if (pe->initialized == 0) { - unsigned int *ip = (unsigned int *)(ifile->plt->contents + pe->offset); - ip[0] = 0x0d105810; /* basr 1,0; lg 1,10(1); br 1 */ - ip[1] = 0x100607f1; - if (ELF32_R_TYPE(rel->r_info) == R_390_PLT16DBL) - ip[2] = v - 2; - else - ip[2] = v; - pe->initialized = 1; - } - - /* Insert relative distance to target. */ - v = plt + pe->offset - dot; - if (ELF32_R_TYPE(rel->r_info) == R_390_PLT32) - *(unsigned int *) loc = (unsigned int) v; - else if (ELF32_R_TYPE(rel->r_info) == R_390_PLT16DBL) - *(unsigned short *) loc = (unsigned short) ((v + 2) >> 1); - break; - - case R_390_GLOB_DAT: - case R_390_JMP_SLOT: - *loc = v; - break; - - case R_390_RELATIVE: - *loc += f->baseaddr; - break; - - case R_390_GOTPC: - assert(got != 0); - *(unsigned long *) loc += got - dot; - break; - - case R_390_GOT12: - case R_390_GOT16: - case R_390_GOT32: - assert(isym != NULL); - assert(got != 0); - if (!isym->gotent.reloc_done) - { - isym->gotent.reloc_done = 1; - *(Elf32_Addr *)(ifile->got->contents + isym->gotent.offset) = v; - } - if (ELF32_R_TYPE(rel->r_info) == R_390_GOT12) - *(unsigned short *) loc |= (*(unsigned short *) loc + isym->gotent.offset) & 0xfff; - else if (ELF32_R_TYPE(rel->r_info) == R_390_GOT16) - *(unsigned short *) loc += isym->gotent.offset; - else if (ELF32_R_TYPE(rel->r_info) == R_390_GOT32) - *(unsigned int *) loc += isym->gotent.offset; - break; - - case R_390_GOTOFF: - assert(got != 0); - *loc += v - got; - break; - - default: - ret = obj_reloc_unhandled; - break; - } - - return ret; -} - -int -arch_create_got (struct obj_file *f) -{ - struct s390_file *ifile = (struct s390_file *) f; - int i, got_offset = 0, plt_offset = 0, gotneeded = 0; - - for (i = 0; i < f->header.e_shnum; ++i) - { - struct obj_section *relsec, *symsec, *strsec; - Elf32_Rela *rel, *relend; - Elf32_Sym *symtab; - const char *strtab; - - relsec = f->sections[i]; - if (relsec->header.sh_type != SHT_RELA) - continue; - - symsec = f->sections[relsec->header.sh_link]; - strsec = f->sections[symsec->header.sh_link]; - - rel = (Elf32_Rela *)relsec->contents; - relend = rel + (relsec->header.sh_size / sizeof(Elf32_Rela)); - symtab = (Elf32_Sym *)symsec->contents; - strtab = (const char *)strsec->contents; - - for (; rel < relend; ++rel) - { - struct s390_symbol *intsym; - struct s390_plt_entry *pe; - struct s390_got_entry *ge; - - switch (ELF32_R_TYPE(rel->r_info)) { - /* These four relocations refer to a plt entry. */ - case R_390_PLT16DBL: - case R_390_PLT32: - obj_find_relsym(intsym, f, f, rel, symtab, strtab); - assert(intsym); - pe = &intsym->pltent; - if (!pe->allocated) { - pe->allocated = 1; - pe->offset = plt_offset; - plt_offset += 12; - } - break; - /* The next three don't need got entries but the address - of the got itself. */ - case R_390_GOTPC: - case R_390_GOTOFF: - gotneeded = 1; - break; - - case R_390_GOT12: - case R_390_GOT16: - case R_390_GOT32: - obj_find_relsym(intsym, f, f, rel, symtab, strtab); - assert(intsym); - ge = (struct s390_got_entry *) &intsym->gotent; - if (!ge->allocated) { - ge->allocated = 1; - ge->offset = got_offset; - got_offset += sizeof(void*); - } - break; - - default: - break; - } - } - } - - if (got_offset > 0 || gotneeded) { - struct obj_section *gotsec; - struct obj_symbol *gotsym; - - gotsec = obj_find_section(f, ".got"); - if (gotsec == NULL) - gotsec = obj_create_alloced_section(f, ".got", 4, got_offset, SHF_WRITE); - else - obj_extend_section(gotsec, got_offset); - gotsym = obj_add_symbol(f, "_GLOBAL_OFFSET_TABLE_", -1, - ELFW(ST_INFO) (STB_LOCAL, STT_OBJECT), - gotsec->idx, 0, 0); - gotsym->secidx = gotsec->idx; /* mark the symbol as defined */ - ifile->got = gotsec; - } - - if (plt_offset > 0) - ifile->plt = obj_create_alloced_section(f, ".plt", 4, plt_offset, - SHF_WRITE); - - return 1; -} - -int -arch_init_module (struct obj_file *f, struct module *mod) -{ - return 1; -} - -int -arch_finalize_section_address(struct obj_file *f, Elf32_Addr base) -{ - int i, n = f->header.e_shnum; - - f->baseaddr = base; - for (i = 0; i < n; ++i) - f->sections[i]->header.sh_addr += base; - return 1; -} - -int -arch_archdata (struct obj_file *fin, struct obj_section *sec) -{ - return 0; -} - diff --git a/mdk-stage1/insmod-modutils/obj/obj_sparc.c b/mdk-stage1/insmod-modutils/obj/obj_sparc.c deleted file mode 100644 index d1eb3da44..000000000 --- a/mdk-stage1/insmod-modutils/obj/obj_sparc.c +++ /dev/null @@ -1,224 +0,0 @@ -/* Sparc specific support for Elf loading and relocation. - Copyright 1996, 1997 Linux International. - - Contributed by Richard Henderson <rth@tamu.edu> - - This file is part of the Linux modutils. - - This program is free software; you can redistribute it and/or modify it - under the terms of the GNU General Public License as published by the - Free Software Foundation; either version 2 of the License, or (at your - option) any later version. - - This program is distributed in the hope that it will be useful, but - WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - General Public License for more details. - - You should have received a copy of the GNU General Public License - along with this program; if not, write to the Free Software Foundation, - Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ - -#include <stddef.h> -#include <module.h> -#include <obj.h> -#include <util.h> - - -/*======================================================================*/ - -struct obj_file * -arch_new_file (void) -{ - return xmalloc(sizeof(struct obj_file)); -} - -struct obj_section * -arch_new_section (void) -{ - return xmalloc(sizeof(struct obj_section)); -} - -struct obj_symbol * -arch_new_symbol (void) -{ - return xmalloc(sizeof(struct obj_symbol)); -} - -int -arch_load_proc_section(struct obj_section *sec, int fp) -{ - /* Assume it's just a debugging section that we can safely - ignore ... */ - sec->contents = NULL; - - return 0; -} - -enum obj_reloc -arch_apply_relocation (struct obj_file *ef, - struct obj_section *targsec, - struct obj_section *symsec, - struct obj_symbol *sym, - Elf32_Rela *rel, - Elf32_Addr v) -{ - Elf32_Addr *loc = (Elf32_Addr *)(targsec->contents + rel->r_offset); - Elf32_Addr dot = targsec->header.sh_addr + rel->r_offset; - - enum obj_reloc ret = obj_reloc_ok; - - switch (ELF32_R_TYPE(rel->r_info)) - { - case R_SPARC_NONE: - break; - case R_SPARC_8: - if (v > 0xff) - ret = obj_reloc_overflow; - *loc = (*loc & ~0xff) | (v & 0xff); - break; - case R_SPARC_16: - if (v > 0xffff) - ret = obj_reloc_overflow; - *loc = (*loc & ~0xffff) | (v & 0xffff); - break; - case R_SPARC_32: - *loc = v; - break; - case R_SPARC_DISP8: - v -= dot; - if (v > 0xff) - ret = obj_reloc_overflow; - *loc = (*loc & ~0xff) | (v & 0xff); - break; - case R_SPARC_DISP16: - v -= dot; - if (v > 0xffff) - ret = obj_reloc_overflow; - *loc = (*loc & ~0xffff) | (v & 0xffff); - break; - case R_SPARC_DISP32: - v -= dot; - *loc = v; - break; - case R_SPARC_WDISP30: - v -= dot; - if (v % 4) - ret = obj_reloc_dangerous; - *loc = (*loc & ~0x3fffffff) | (v >> 2); - break; - case R_SPARC_WDISP22: - v -= dot; - if (v % 4) - ret = obj_reloc_dangerous; - *loc = (*loc & ~0x3fffff) | ((v >> 2) & 0x3fffff); - break; - case R_SPARC_HI22: - *loc = (*loc & ~0x3fffff) | (v >> 10); - break; - case R_SPARC_22: - if (v > 0x3fffff) - ret = obj_reloc_overflow; - *loc = (*loc & ~0x3fffff) | (v & 0x3fffff); - break; - case R_SPARC_13: - if (v > 0x1fff) - ret = obj_reloc_overflow; - *loc = (*loc & ~0x1fff) | (v & 0x1fff); - break; - case R_SPARC_LO10: - *loc = (*loc & ~0x3ff) | (v & 0x3ff); - break; - - case R_SPARC_PC10: - v -= dot; - *loc = (*loc & ~0x3ff) | (v & 0x3ff); - break; - case R_SPARC_PC22: - v -= dot; - *loc = (*loc & ~0x3fffff) | (v >> 10); - break; - - case R_SPARC_UA32: - *(((char *)loc) + 0) = (char)(v >> 24); - *(((char *)loc) + 1) = (char)(v >> 16); - *(((char *)loc) + 2) = (char)(v >> 8); - *(((char *)loc) + 3) = (char)v; - break; - -#ifdef R_SPARC_10 - case R_SPARC_10: - if (v > 0x3ff) - ret = obj_reloc_overflow; - *loc = (*loc & ~0x3ff) | (v & 0x3ff); - break; - case R_SPARC_11: - if (v > 0x7ff) - ret = obj_reloc_overflow; - *loc = (*loc & ~0x7ff) | (v & 0x7ff); - break; - case R_SPARC_WDISP16: - v -= dot; - if (v % 4) - ret = obj_reloc_dangerous; - *loc = (*loc & ~0x303fff) | ((v << 4) & 0x300000) | ((v >> 2) & 0x3fff); - break; - case R_SPARC_WDISP19: - v -= dot; - if (v % 4) - ret = obj_reloc_dangerous; - *loc = (*loc & ~0x7ffff) | ((v >> 2) & 0x7ffff); - break; - case R_SPARC_7: - if (v > 0x7f) - ret = obj_reloc_overflow; - *loc = (*loc & ~0x7f) | (v & 0x7f); - break; - case R_SPARC_5: - if (v > 0x1f) - ret = obj_reloc_overflow; - *loc = (*loc & ~0x1f) | (v & 0x1f); - break; - case R_SPARC_6: - if (v > 0x3f) - ret = obj_reloc_overflow; - *loc = (*loc & ~0x3f) | (v & 0x3f); - break; -#endif /* R_SPARC_10 */ - - default: - ret = obj_reloc_unhandled; - break; - } - - return ret; -} - -int -arch_create_got (struct obj_file *ef) -{ - return 1; -} - -int -arch_init_module (struct obj_file *f, struct module *mod) -{ - return 1; -} - -int -arch_finalize_section_address(struct obj_file *f, Elf32_Addr base) -{ - int i, n = f->header.e_shnum; - - f->baseaddr = base; - for (i = 0; i < n; ++i) - f->sections[i]->header.sh_addr += base; - return 1; -} - -int -arch_archdata (struct obj_file *fin, struct obj_section *sec) -{ - return 0; -} diff --git a/mdk-stage1/insmod-modutils/obj/obj_sparc64.c b/mdk-stage1/insmod-modutils/obj/obj_sparc64.c deleted file mode 100644 index f025667f8..000000000 --- a/mdk-stage1/insmod-modutils/obj/obj_sparc64.c +++ /dev/null @@ -1,350 +0,0 @@ -/* Sparc64 specific support for Elf loading and relocation. - Copyright 1997 Linux International. - - Contributed by Jakub Jelinek <jj@sunsite.mff.cuni.cz> - - This file is part of the Linux modutils. - - This program is free software; you can redistribute it and/or modify it - under the terms of the GNU General Public License as published by the - Free Software Foundation; either version 2 of the License, or (at your - option) any later version. - - This program is distributed in the hope that it will be useful, but - WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - General Public License for more details. - - You should have received a copy of the GNU General Public License - along with this program; if not, write to the Free Software Foundation, - Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ - -#include <stddef.h> -#include <module.h> -#include <obj.h> -#include <util.h> - - -/*======================================================================*/ - -struct obj_file * -arch_new_file (void) -{ - return xmalloc(sizeof(struct obj_file)); -} - -struct obj_section * -arch_new_section (void) -{ - return xmalloc(sizeof(struct obj_section)); -} - -struct obj_symbol * -arch_new_symbol (void) -{ - return xmalloc(sizeof(struct obj_symbol)); -} - -#ifdef BROKEN_SPARC64_RELOCS - -#undef R_SPARC_PLT32 -#undef R_SPARC_HIPLT22 -#undef R_SPARC_LOPLT10 -#undef R_SPARC_PCPLT32 -#undef R_SPARC_PCPLT22 -#undef R_SPARC_PCPLT10 -#undef R_SPARC_10 -#undef R_SPARC_11 -#undef R_SPARC_64 -#undef R_SPARC_OLO10 -#undef R_SPARC_HH22 -#undef R_SPARC_HM10 -#undef R_SPARC_LM22 -#undef R_SPARC_PC_HH22 -#undef R_SPARC_PC_HM10 -#undef R_SPARC_PC_LM22 -#undef R_SPARC_WDISP16 -#undef R_SPARC_WDISP19 -#undef R_SPARC_GLOB_JMP -#undef R_SPARC_7 -#undef R_SPARC_5 -#undef R_SPARC_6 - -#define R_SPARC_10 24 -#define R_SPARC_11 25 -#define R_SPARC_64 26 -#define R_SPARC_OLO10 27 -#define R_SPARC_HH22 28 -#define R_SPARC_HM10 29 -#define R_SPARC_LM22 30 -#define R_SPARC_PC_HH22 31 -#define R_SPARC_PC_HM10 32 -#define R_SPARC_PC_LM22 33 -#define R_SPARC_WDISP16 34 -#define R_SPARC_WDISP19 35 -#define R_SPARC_GLOB_JMP 36 -#define R_SPARC_7 37 -#define R_SPARC_5 38 -#define R_SPARC_6 39 - -#else - -#ifndef R_SPARC_64 - -#define R_SPARC_64 32 -#define R_SPARC_OLO10 33 -#define R_SPARC_HH22 34 -#define R_SPARC_HM10 35 -#define R_SPARC_LM22 36 -#define R_SPARC_PC_HH22 37 -#define R_SPARC_PC_HM10 38 -#define R_SPARC_PC_LM22 39 - -#endif - -#endif - -int -arch_load_proc_section(struct obj_section *sec, int fp) -{ - /* Assume it's just a debugging section that we can safely - ignore ... */ - sec->contents = NULL; - - return 0; -} - -#define ELF64_R_TYPE_ID(info) ((info) & 0xff) -#define ELF64_R_TYPE_DATA(info) ((info) >> 8) - -enum obj_reloc -arch_apply_relocation (struct obj_file *ef, - struct obj_section *targsec, - struct obj_section *symsec, - struct obj_symbol *sym, - Elf64_Rela *rel, - Elf64_Addr v) -{ - unsigned int *loc = (unsigned int *)(targsec->contents + rel->r_offset); - unsigned int dot = targsec->header.sh_addr + rel->r_offset; - - enum obj_reloc ret = obj_reloc_ok; - - switch (ELF64_R_TYPE_ID(rel->r_info)) - { - case R_SPARC_NONE: - break; - - case R_SPARC_64: - case R_SPARC_UA64: - if (! ((long) loc & 3)) { - /* Common in .eh_frame */ - ((unsigned int *) loc) [0] = v >> 32; - ((unsigned int *) loc) [1] = v; - break; - } - ((unsigned char *) loc) [0] = v >> 56; - ((unsigned char *) loc) [1] = v >> 48; - ((unsigned char *) loc) [2] = v >> 40; - ((unsigned char *) loc) [3] = v >> 32; - ((unsigned char *) loc) [4] = v >> 24; - ((unsigned char *) loc) [5] = v >> 16; - ((unsigned char *) loc) [6] = v >> 8; - ((unsigned char *) loc) [7] = v; - break; - case R_SPARC_32: - case R_SPARC_UA32: - if (! ((long) loc & 3)) { - *loc = v; - break; - } - ((unsigned char *) loc) [0] = v >> 24; - ((unsigned char *) loc) [1] = v >> 16; - ((unsigned char *) loc) [2] = v >> 8; - ((unsigned char *) loc) [3] = v; - break; - case R_SPARC_16: - if (v > 0xffff) - ret = obj_reloc_overflow; - *loc = (*loc & ~0xffff) | (v & 0xffff); - break; - case R_SPARC_8: - if (v > 0xff) - ret = obj_reloc_overflow; - *loc = (*loc & ~0xff) | (v & 0xff); - break; - - case R_SPARC_DISP32: - v -= dot; - *loc = v; - break; - case R_SPARC_DISP16: - v -= dot; - if (v > 0xffff) - ret = obj_reloc_overflow; - *loc = (*loc & ~0xffff) | (v & 0xffff); - break; - case R_SPARC_DISP8: - v -= dot; - if (v > 0xff) - ret = obj_reloc_overflow; - *loc = (*loc & ~0xff) | (v & 0xff); - break; - case R_SPARC_WDISP30: - v -= dot; - if (v % 4) - ret = obj_reloc_dangerous; - *loc = (*loc & ~0x3fffffff) | ((v >> 2) & 0x3fffffff); - break; - - /* MEDLOW code model relocs */ - case R_SPARC_LO10: - *loc = (*loc & ~0x3ff) | (v & 0x3ff); - break; - case R_SPARC_HI22: - *loc = (*loc & ~0x3fffff) | (v >> 10); - break; - case R_SPARC_OLO10: - *loc = (*loc & ~0x1fff) | (((v & 0x3ff) + ELF64_R_TYPE_DATA (rel->r_info)) & 0x1fff); - break; - - /* MEDMID code model relocs */ - case R_SPARC_H44: - *loc = (*loc & ~0x3fffff) | (v >> 22); - break; - case R_SPARC_M44: - *loc = (*loc & ~0x3ff) | ((v >> 12) & 0x3ff); - break; - case R_SPARC_L44: - *loc = (*loc & ~0xfff) | (v & 0xfff); - break; - - /* MEDANY code model relocs */ - case R_SPARC_HH22: - *loc = (*loc & ~0x3fffff) | (v >> 42); - break; - case R_SPARC_HM10: - *loc = (*loc & ~0x3ff) | ((v >> 32) & 0x3ff); - break; - case R_SPARC_LM22: - *loc = (*loc & ~0x3fffff) | ((v >> 10) & 0x3fffff); - break; - - case R_SPARC_WDISP22: - v -= dot; - if (v % 4) - ret = obj_reloc_dangerous; - *loc = (*loc & ~0x3fffff) | ((v >> 2) & 0x3fffff); - break; - case R_SPARC_22: - if (v > 0x3fffff) - ret = obj_reloc_overflow; - *loc = (*loc & ~0x3fffff) | (v & 0x3fffff); - break; - case R_SPARC_13: - if (v > 0x1fff) - ret = obj_reloc_overflow; - *loc = (*loc & ~0x1fff) | (v & 0x1fff); - break; - - case R_SPARC_PC10: - v -= dot; - *loc = (*loc & ~0x3ff) | (v & 0x3ff); - break; - case R_SPARC_PC22: - v -= dot; - *loc = (*loc & ~0x3fffff) | ((v >> 10) & 0x3fffff); - break; - -#ifdef R_SPARC_10 - case R_SPARC_10: - if (v > 0x3ff) - ret = obj_reloc_overflow; - *loc = (*loc & ~0x3ff) | (v & 0x3ff); - break; - case R_SPARC_11: - if (v > 0x7ff) - ret = obj_reloc_overflow; - *loc = (*loc & ~0x7ff) | (v & 0x7ff); - break; - -#ifdef R_SPARC_64 - case R_SPARC_PC_HH22: - v -= dot; - *loc = (*loc & ~0x3fffff) | (v >> 42); - break; - case R_SPARC_PC_HM10: - v -= dot; - *loc = (*loc & ~0x3ff) | ((v >> 32) & 0x3ff); - break; - case R_SPARC_PC_LM22: - v -= dot; - *loc = (*loc & ~0x3fffff) | ((v >> 10) & 0x3fffff); - break; -#endif - - case R_SPARC_WDISP16: - v -= dot; - if (v % 4) - ret = obj_reloc_dangerous; - *loc = (*loc & ~0x303fff) | ((v << 4) & 0x300000) | ((v >> 2) & 0x3fff); - break; - case R_SPARC_WDISP19: - v -= dot; - if (v % 4) - ret = obj_reloc_dangerous; - *loc = (*loc & ~0x7ffff) | ((v >> 2) & 0x7ffff); - break; - case R_SPARC_7: - if (v > 0x7f) - ret = obj_reloc_overflow; - *loc = (*loc & ~0x7f) | (v & 0x7f); - break; - case R_SPARC_5: - if (v > 0x1f) - ret = obj_reloc_overflow; - *loc = (*loc & ~0x1f) | (v & 0x1f); - break; - case R_SPARC_6: - if (v > 0x3f) - ret = obj_reloc_overflow; - *loc = (*loc & ~0x3f) | (v & 0x3f); - break; -#endif /* R_SPARC_10 */ - - default: - ret = obj_reloc_unhandled; - break; - } - - return ret; -} - -int -arch_create_got (struct obj_file *ef) -{ - return 1; -} - -int -arch_init_module (struct obj_file *f, struct module *mod) -{ - return 1; -} - -int -arch_finalize_section_address(struct obj_file *f, Elf64_Addr base) -{ - int i, n = f->header.e_shnum; - - f->baseaddr = base; - for (i = 0; i < n; ++i) - f->sections[i]->header.sh_addr += base; - return 1; -} - -int -arch_archdata (struct obj_file *fin, struct obj_section *sec) -{ - return 0; -} diff --git a/mdk-stage1/insmod-modutils/util/Makefile b/mdk-stage1/insmod-modutils/util/Makefile deleted file mode 100644 index dd8107435..000000000 --- a/mdk-stage1/insmod-modutils/util/Makefile +++ /dev/null @@ -1,42 +0,0 @@ - #****************************************************************************** - # - # insmod from modutils (generic) - # - # $Id$ - # - # Copyright 1996, 1997 Linux International. - # - #***************************************************************************** - -top_dir = ../.. - -include $(top_dir)/Makefile.common - - -all: libutil.a libutil-STANDALONE.a - -clean: - rm -f *.o *.a - - -INCS = -I./../include - -DEFS = -Wno-error -D_GNU_SOURCE -DELF_MACHINE_H='"elf_$(ARCH).h"' -DARCH_$(ARCH) -DHAVE_WORDEXP=1 -DHAVE_GLOB=1 -DCONFIG_ROOT_CHECK_OFF=0 - - -OBJS = xmalloc.o xrealloc.o xstrcat.o xstrdup.o xsystem.o xftw.o \ - modstat.o meta_expand.o config.o snap_shot.o arch64.o gzfiles.o sys_nim.o sys_oim.o - -libutil.a: $(OBJS) logger.o - ar cru $@ $^ - ranlib $@ - -libutil-STANDALONE.a: $(OBJS) logger-standalone.o - ar cru $@ $^ - ranlib $@ - -logger-standalone.o: logger.c - $(DIET) gcc $(CFLAGS) $(DEFS) $(INCS) $(INCLUDES) -o $@ -D_STANDALONE_ -c logger.c - -%.o: %.c - $(DIET) gcc $(CFLAGS) $(DEFS) $(INCS) $(INCLUDES) -c $< diff --git a/mdk-stage1/insmod-modutils/util/alias.h b/mdk-stage1/insmod-modutils/util/alias.h deleted file mode 100644 index 7d0c08938..000000000 --- a/mdk-stage1/insmod-modutils/util/alias.h +++ /dev/null @@ -1,310 +0,0 @@ -/* - * This file is split out from config.c for easier editing - */ - -/* - * tbpath and tbtype are used to build the complete set of paths for finding - * modules, but only when we search for individual directories, they are not - * used for [boot] and [toplevel] searches. - */ -static char *tbpath[] = -{ - "/lib/modules", - NULL /* marks the end of the list! */ -}; - -char *tbtype[] = -{ - "kernel", /* as of 2.3.14 this must be first */ - "fs", - "net", - "scsi", - "block", - "cdrom", - "ipv4", - "ipv6", - "sound", - "fc4", - "video", - "misc", - "pcmcia", - "atm", - "usb", - "ide", - "ieee1394", - "mtd", - NULL /* marks the end of the list! */ -}; - -/* - * This is the list of pre-defined aliases. - * Each entry can be overridden by an entry in /etc/modules.conf - */ -char *aliaslist[] = -{ - "binfmt-0000 off", - "binfmt-204 binfmt_aout", - "binfmt-263 binfmt_aout", - "binfmt-264 binfmt_aout", - "binfmt-267 binfmt_aout", - "binfmt-387 binfmt_aout", - "binfmt-332 iBCS", - "binfmt--310 binfmt_java", - - "block-major-1 rd", - "block-major-2 floppy", - "block-major-3 ide-probe-mod", - "block-major-7 loop", - "block-major-8 sd_mod", - "block-major-9 md", /* For modular RAID */ - "block-major-11 sr_mod", - "block-major-13 xd", - "block-major-15 cdu31a", - "block-major-16 gscd", - "block-major-17 optcd", - "block-major-18 sjcd", - "block-major-20 mcdx", - "block-major-22 ide-probe-mod", - "block-major-23 mcd", - "block-major-24 sonycd535", - "block-major-25 sbpcd", - "block-major-26 sbpcd", - "block-major-27 sbpcd", - "block-major-29 aztcd", - "block-major-32 cm206", - "block-major-33 ide-probe-mod", - "block-major-34 ide-probe-mod", - "block-major-37 ide-tape", - "block-major-44 ftl", /* from David Woodhouse <dwmw2@infradead.org> */ - "block-major-46 pcd", - "block-major-47 pf", - "block-major-56 ide-probe-mod", - "block-major-57 ide-probe-mod", - "block-major-58 lvm-mod", - "block-major-88 ide-probe-mod", - "block-major-89 ide-probe-mod", - "block-major-90 ide-probe-mod", - "block-major-91 ide-probe-mod", - "block-major-93 nftl", /* from David Woodhouse <dwmw2@infradead.org> */ - "block-major-97 pg", - -#if !defined(__s390__) && !defined(__s390x__) - "char-major-4 serial", -#else - "char-major-4 off", -#endif - "char-major-5 serial", - "char-major-6 lp", - "char-major-9 st", - "char-major-10 off", /* was: mouse, was: misc */ - "char-major-10-0 busmouse", /* /dev/logibm Logitech bus mouse */ - "char-major-10-1 off", /* /dev/psaux PS/2-style mouse port */ - "char-major-10-2 msbusmouse", /* /dev/inportbm Microsoft Inport bus mouse */ - "char-major-10-3 atixlmouse", /* /dev/atibm ATI XL bus mouse */ - /* /dev/jbm J-mouse */ - /* /dev/amigamouse Amiga mouse (68k/Amiga) */ - /* /dev/atarimouse Atari mouse */ - /* /dev/sunmouse Sun mouse */ - /* /dev/beep Fancy beep device */ - /* /dev/modreq Kernel module load request */ - "char-major-10-130 wdt", /* /dev/watchdog Watchdog timer port */ - "char-major-10-131 wdt", /* /dev/temperature Machine internal temperature */ - /* /dev/hwtrap Hardware fault trap */ - /* /dev/exttrp External device trap */ - "char-major-10-135 rtc", /* /dev/rtc Real time clock */ - "char-major-10-139 openprom", /* /dev/openprom Linux/Sparc interface */ - "char-major-10-144 nvram", /* from Tigran Aivazian <tigran@sco.COM> */ - "char-major-10-157 applicom", /* from David Woodhouse <dwmw2@infradead.org> */ - "char-major-10-175 agpgart", /* /dev/agpgart GART AGP mapping access */ - "char-major-10-184 microcode", /* Tigran Aivazian <tigran@veritas.com> */ - - "char-major-13 input", - "char-major-13-32 mousedev", - "char-major-14 soundcore", - "char-major-19 cyclades", - "char-major-20 cyclades", - "char-major-21 sg", - "char-major-22 pcxx", /* ?? */ - "char-major-23 pcxx", /* ?? */ - "char-major-27 ftape", - "char-major-34 scc", - "char-major-35 tclmidi", - "char-major-36 netlink", - "char-major-37 ide-tape", - "char-major-48 riscom8", - "char-major-49 riscom8", - "char-major-57 esp", - "char-major-58 esp", - "char-major-63 kdebug", - "char-major-90 mtdchar", /* from David Woodhouse <dwmw2@infradead.org> */ - "char-major-96 pt", - "char-major-99 ppdev", - "char-major-107 3dfx", /* from Tigran Aivazian <tigran@sco.COM> */ - "char-major-108 ppp_generic", - "char-major-109 lvm-mod", - "char-major-161 ircomm-tty", - "char-major-171 raw1394", - "char-major-195 NVdriver", - "char-major-200 vxspec", - - "dos msdos", - "dummy0 dummy", - "dummy1 dummy", - "eth0 off", - "iso9660 isofs", - "md-personality-1 linear", - "md-personality-2 raid0", - "md-personality-3 raid1", - "md-personality-4 raid5", - "md-personality-7 multipath", - - "net-pf-1 unix", /* PF_UNIX 1 Unix domain sockets */ - "net-pf-2 ipv4", /* PF_INET 2 Internet IP Protocol */ - "net-pf-3 off", /* PF_AX25 3 Amateur Radio AX.25 */ - "net-pf-4 ipx", /* PF_IPX 4 Novell IPX */ - "net-pf-5 appletalk", /* PF_APPLETALK 5 Appletalk DDP */ - "net-pf-6 off", /* PF_NETROM 6 Amateur radio NetROM */ - /* PF_BRIDGE 7 Multiprotocol bridge */ - /* PF_AAL5 8 Reserved for Werner's ATM */ - /* PF_X25 9 Reserved for X.25 project */ - "net-pf-10 off", /* PF_INET6 10 IP version 6 */ - - /* next two from <dairiki@matthews.dairiki.org> Thanks! */ - "net-pf-17 af_packet", - "net-pf-19 off", /* acorn econet */ - - "netalias-2 ip_alias", - - /* To be able to attach some dongles */ - "irlan0 irlan", - "irda-dongle-0 tekram", - "irda-dongle-1 esi", - "irda-dongle-2 actisys", - "irda-dongle-3 actisys", - "irda-dongle-4 girbil", - "irda-dongle-5 litelink", - "irda-dongle-6 airport", - "irda-dongle-7 old_belkin", - - "plip0 plip", - "plip1 plip", - "tunl0 ipip", - "cipcb0 cipcb", - "cipcb1 cipcb", - "cipcb2 cipcb", - "cipcb3 cipcb", -#if defined(__s390__) || defined(__s390x__) - "ctc0 ctc", - "ctc1 ctc", - "ctc2 ctc", - "iucv0 netiucv", - "iucv1 netiucv", -#endif - "ppp0 ppp", - "ppp1 ppp", - "slip0 slip", - "slip1 slip", - "tty-ldisc-1 slip", - "tty-ldisc-3 ppp_async", - "tty-ldisc-11 irtty", /* IrDA over a normal serial port, or a serial port compatible IrDA port */ - "tty-ldisc-14 ppp_synctty", - "ppp-compress-18 ppp_mppe", - "ppp-compress-21 bsd_comp", - "ppp-compress-24 ppp_deflate", - "ppp-compress-26 ppp_deflate", - "ppp ppp_async", /* for 2.4 */ - -#ifndef __sparc__ - "parport_lowlevel parport_pc", -#else - "parport_lowlevel parport_ax", -#endif - - "usbdevfs usbcore", - - NULL /* marks the end of the list! */ -}; - -/* - * This is the list of pre-defined options. - * Each entry can be overridden by an entry in /etc/modules.conf - */ -char *optlist[] = -{ - "dummy0 -o dummy0", - "dummy1 -o dummy1", - "sb io=0x220 irq=7 dma=1 dma16=5 mpu_io=0x330", - NULL /* marks the end of the list! */ -}; - -/* - * This is the list of pre-defined "above"s, - * used for pull-in of additional modules - * Each entry can be overridden by an entry in /etc/modules.conf - */ -char *above[] = -{ - "hid keybdev mousedev", - "usbmouse hid", - "wacom evdev", - NULL /* marks the end of the list! */ -}; - -/* - * This is the list of pre-defined "below"s, - * used for push-in of additional modules - * Each entry can be overridden by an entry in /etc/modules.conf - */ -char *below[] = -{ - NULL /* marks the end of the list! */ -}; - -/* - * This is the list of pre-defined "post-install"s, - * used to execute commands after loading modules. - * /etc/modules.conf can add entries but not remove them. - */ -char *post_install[] = -{ - "binfmt_misc /bin/mount -t binfmt_misc none /proc/sys/fs/binfmt_misc > /dev/null 2>&1 || :", - NULL -}; - -/* - * This is the list of pre-defined "pre-remove"s, - * used to execute commands before unloading modules. - * /etc/modules.conf can add entries but not remove them. - */ -char *pre_remove[] = -{ - "binfmt_misc /bin/umount /proc/sys/fs/binfmt_misc > /dev/null 2>&1 || :", - NULL -}; - -/* - * This is the list of pre-defined "prune"s, - * used to exclude paths from scan of /lib/modules. - * /etc/modules.conf can add entries but not remove them. - */ -char *prune[] = -{ - "modules.dep", - "modules.description", - "modules.generic_string", - "modules.pcimap", - "modules.isapnpmap", - "modules.usbmap", - "modules.parportmap", - "modules.ieee1394map", - "modules.pnpbiosmap", - "System.map", - ".config", - "build", /* symlink to source tree */ - "vmlinux", - "vmlinuz", - "bzImage", - "zImage", - ".rhkmvtag", /* wish RedHat had told me before they did this */ - NULL /* marks the end of the list! */ -}; diff --git a/mdk-stage1/insmod-modutils/util/arch64.c b/mdk-stage1/insmod-modutils/util/arch64.c deleted file mode 100644 index 90886d16b..000000000 --- a/mdk-stage1/insmod-modutils/util/arch64.c +++ /dev/null @@ -1,43 +0,0 @@ -/* Misc utility functions. - Copyright 1996, 1997 Linux International. - Written by Keith Owens <kaos@ocs.com.au> - - This file is part of the Linux modutils. - - This program is free software; you can redistribute it and/or modify it - under the terms of the GNU General Public License as published by the - Free Software Foundation; either version 2 of the License, or (at your - option) any later version. - - This program is distributed in the hope that it will be useful, but - WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - General Public License for more details. - - You should have received a copy of the GNU General Public License - along with this program; if not, write to the Free Software Foundation, - Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ - -#include <stdlib.h> -#include <string.h> -#include <sys/utsname.h> -#include "util.h" - -/*======================================================================*/ - -/* Indicate if the current machine uses 64 bit architecture */ -int arch64(void) -{ - struct utsname uts; - char *uname_m; - if (uname(&uts)) - return(0); - if ((uname_m = getenv("UNAME_MACHINE"))) { - int l = strlen(uname_m); - if (l >= sizeof(uts.machine)) - l = sizeof(uts.machine)-1; - memcpy(uts.machine, uname_m, l); - uts.machine[l] = '\0'; - } - return(strstr(uts.machine, "64") != NULL); -} diff --git a/mdk-stage1/insmod-modutils/util/config.c b/mdk-stage1/insmod-modutils/util/config.c deleted file mode 100644 index 778fe2b7f..000000000 --- a/mdk-stage1/insmod-modutils/util/config.c +++ /dev/null @@ -1,1614 +0,0 @@ -/* - * Handle the configuration, including /etc/modules.conf - * - * Copyright 1994, 1995, 1996, 1997: - * Jacques Gelinas <jack@solucorp.qc.ca> - * Björn Ekwall <bj0rn@blox.se> February 1999 - * Keith Owens <kaos@ocs.com.au> October 1999 - * - * "kernelversion" idea from the Debian release via: - * Wichert Akkerman <wakkerma@cs.leidenuniv.nl> - * - * Björn, inspired by Richard Henderson <rth@twiddle.net>, cleaned up - * the wildcard handling and started using ftw in March 1999 - * Cleanup of hardcoded arrays: Björn Ekwall <bj0rn@blox.se> March 1999 - * Many additional keywords: Björn Ekwall <bj0rn@blox.se> (C) March 1999 - * Standardize on /etc/modules.conf Keith Owens <kaos@ocs.com.au> October 1999 - * - * Alpha typecast:Michal Jaegermann <michal@ellpspace.math.ualberta.ca> - * - * This file is part of the Linux modutils. - * - * This program is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License as published by the - * Free Software Foundation; either version 2 of the License, or (at your - * option) any later version. - * - * This program is distributed in the hope that it will be useful, but - * WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software Foundation, - * Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. - */ - -/* - * Specification: /etc/modules.conf / format - * Modules may be located at different places in the filesystem. - * - * The file /etc/modules.conf contains different definitions to - * control the manipulation of modules. - * - * Standard Unix style comments and continuation line are supported. - * Comments begin with a # and continue until the end of the line. - * A line continues on the next one if the last non-white character - * is a \. - */ -/* #Specification: /etc/modules.conf / format / official name */ - -#include <stdio.h> -#include <stdarg.h> -#include <assert.h> -#include <stdlib.h> -#include <string.h> -#include <unistd.h> -#include <ctype.h> -#include <sys/stat.h> -#include <signal.h> -#include <limits.h> -#include <sys/param.h> -#include <errno.h> - -#include "util.h" -#include "config.h" -#include "alias.h" - -int flag_autoclean; /* set/used by modprobe and insmod */ - -struct utsname uts_info; - -struct PATH_TYPE *modpath; -int nmodpath = 0; -static int maxpath = 0; - -struct EXEC_TYPE *execs; -int nexecs = 0; -static int maxexecs = 0; - -OPT_LIST *opt_list; -static int n_opt_list; - -OPT_LIST *abovelist; -static int n_abovelist; - -OPT_LIST *belowlist; -static int n_belowlist; - -OPT_LIST *prunelist; -static int n_prunelist; - -OPT_LIST *probe_list; -static int n_probe_list; - -OPT_LIST *probeall_list; -static int n_probeall_list; - -OPT_LIST *aliases; -static int n_aliases; - -char *persistdir = "/var/lib/modules/persist"; - -const char symprefix[] = SYMPREFIX; - -char *insmod_opt = NULL; -char *config_file = NULL; /* Which file was actually used */ -time_t config_mtime; -int root_check_off = CONFIG_ROOT_CHECK_OFF; /* Default is modules must be owned by root */ -static char *config_version; /* Hack for config_add */ -int quick = 0; /* Option -A */ - -/* The initialization order must match the gen_file_enum order in config.h */ -struct gen_files gen_file[] = { - {"generic_string", NULL, 0}, - {"pcimap", NULL, 0}, - {"isapnpmap", NULL, 0}, - {"usbmap", NULL, 0}, - {"parportmap", NULL, 0}, - {"ieee1394map", NULL, 0}, - {"pnpbiosmap", NULL, 0}, - {"dep", NULL, 0}, -}; - -const int gen_file_count = sizeof(gen_file)/sizeof(gen_file[0]); - -int flag_verbose; - -unsigned long safemode; - -void verbose(const char *ctl,...) -{ - if (flag_verbose) { - va_list list; - va_start(list, ctl); - vprintf(ctl, list); - va_end(list); - fflush(stdout); - } -} - - -/* - * Check to see if the existing modules.xxx files need updating, - * based on the timestamps of the modules and the config file. - */ -static int check_update (const char *file, const struct stat *sb) -{ - int len = strlen(file); - int i; - - if (!S_ISREG(sb->st_mode)) - return 0; - for (i = 0; i < gen_file_count; ++i) { - if (sb->st_mtime > gen_file[i].mtime) - break; - } - if (i == gen_file_count) - return 0; /* All generated files are up to date */ - - if (len > 2 && !strcmp(file + len - 2, ".o")) - return 1; - else if (len > 4 && !strcmp(file + len - 4, ".mod")) - return 1; -#ifdef CONFIG_USE_ZLIB - else if (len > 5 && !strcmp(file + len - 5, ".o.gz")) - return 1; -#endif - return 0; -} - -static int need_update (const char *force_ver, const char *base_dir) -{ - struct stat tmp; - char dep[PATH_MAX]; - int i; - uname (&uts_info); - if (!force_ver) - force_ver = uts_info.release; - - if (strlen (force_ver) > 50) - /* That's just silly. */ - return 1; - - for (i = 0; i < gen_file_count; ++i) { - if (stat(gen_file[i].name, &tmp)) - return 1; /* No dependency file yet, so we need to build it. */ - gen_file[i].mtime = tmp.st_mtime; - } - - if (stat ("/etc/modules.conf", &tmp) && - stat ("/etc/conf.modules", &tmp)) - return 1; - - for (i = 0; i < gen_file_count; ++i) { - if (tmp.st_mtime > gen_file[i].mtime) - return 1; /* Config file is newer. */ - } - - snprintf (dep, sizeof(dep), "%s/lib/modules/%s", base_dir, force_ver); - return xftw (dep, check_update); -} - - -/* - * Strip white char at the end of a string. - * Return the address of the last non white char + 1 (point on the '\0'). - */ -static char *strip_end(char *str) -{ - int len = strlen(str); - - for (str += len - 1; len > 0 && (isspace(*str)); --len, --str) - *str = '\0'; - return str + 1; -} - -/* - * Read a line of a configuration file and process continuation lines. - * Return buf, or NULL if EOF. - * Blank at the end of line are always stripped. - * Everything on a line following comchar is a comment. - * - * Continuation character is \ - * Comment character is # - */ -char *fgets_strip(char *buf, int sizebuf, FILE * fin, int *lineno) -{ - int nocomment = 1; /* No comments found ? */ - int contline = 0; - char *start = buf; - char *ret = NULL; - char comchar = '#'; - char contchar = '\\'; - - *buf = '\0'; - - while (fgets(buf, sizebuf, fin) != NULL) { - char *end = strip_end(buf); - char *pt = strchr(buf, comchar); - - if (pt != NULL) { - nocomment = 0; - *pt = '\0'; - end = strip_end(buf); - } - - if (lineno != NULL) - (*lineno)++; - ret = start; - if (contline) { - char *pt = buf; - - while (isspace(*pt)) - pt++; - if (pt > buf + 1) { - strcpy(buf + 1, pt); /* safe, backward copy */ - buf[0] = ' '; - end -= (int) (pt - buf) - 1; - } else if (pt == buf + 1) { - buf[0] = ' '; - } - } - if (end > buf && *(end - 1) == contchar) { - if (end == buf + 1 || *(end - 2) != contchar) { - /* Continuation */ - contline = 1; - end--; - *end = '\0'; - buf = end; - } else { - *(end - 1) = '\0'; - break; - } - } else { - break; - } - } - - return ret; -} - -static char *next_word(char *pt) -{ - char *match; - char *pt2; - - /* find end of word */ - for (pt2 = pt; *pt2 && !(isspace(*pt2)); ++pt2) { - if ((match = strchr("\"'`", *pt2)) != NULL) { - for (++pt2; *pt2 && *pt2 != *match; ++pt2) { - if (*pt2 == '\\' && *(pt2 + 1) == *match) - ++pt2; - } - } - } - - /* skip leading whitespace before next word */ - if (*pt2) { - *pt2++ = '\0'; /* terminate last word */ - while (*pt2 && isspace(*pt2)) - ++pt2; - } - return pt2; -} - -static GLOB_LIST *addlist(GLOB_LIST *orig, GLOB_LIST *add) -{ - if (!orig) - return add; - /* else */ - orig->pathv = (char **)xrealloc(orig->pathv, - (orig->pathc + add->pathc + 1) * - sizeof(char *)); - memcpy(orig->pathv + orig->pathc, add->pathv, - add->pathc * sizeof(char *)); - orig->pathc += add->pathc; - orig->pathv[orig->pathc] = NULL; - /* - free(add->pathv); - free(add); - */ - return orig; -} - -static void decode_list(int *n, OPT_LIST **list, char *arg, int adding, - char *version, int opts) -{ - GLOB_LIST *pg; - GLOB_LIST *prevlist = NULL; - int i, autoclean = 1; - int where = *n; - char *arg2 = next_word(arg); - - if (opts && !strcmp (arg, "-k")) { - if (!*arg2) - error("Missing module argument after -k\n"); - arg = arg2; - arg2 = next_word(arg); - autoclean = 0; - } - - for (i = 0; i < *n; ++i) { - if (strcmp((*list)[i].name, arg) == 0) { - if (adding) - prevlist = (*list)[i].opts; - else - free((*list)[i].opts); - (*list)[i].opts = NULL; - where = i; - break; - } - } - if (where == *n) { - (*list) = (OPT_LIST *)xrealloc((*list), - (*n + 2) * sizeof(OPT_LIST)); - (*list)[*n].name = xstrdup(arg); - (*list)[*n].autoclean = autoclean; - *n += 1; - memset(&(*list)[*n], 0, sizeof(OPT_LIST)); - } else if (!autoclean) - (*list)[where].autoclean = 0; - pg = (GLOB_LIST *)xmalloc(sizeof(GLOB_LIST)); - meta_expand(arg2, pg, NULL, version, ME_ALL); - (*list)[where].opts = addlist(prevlist, pg); -} - -static void decode_exec(char *arg, int type) -{ - char *arg2; - - execs[nexecs].when = type; - arg2 = next_word(arg); - execs[nexecs].module = xstrdup(arg); - execs[nexecs].cmd = xstrdup(arg2); - if (++nexecs >= maxexecs) { - maxexecs += 10; - execs = (struct EXEC_TYPE *)xrealloc(execs, - maxexecs * sizeof(struct EXEC_TYPE)); - } -} - -static int build_list(char **in, OPT_LIST **out, char *version, int opts) -{ - GLOB_LIST *pg; - int i; - - for (i = 0; in[i]; ++i) { - char *p = xstrdup(in[i]); - char *pt = next_word(p); - char *pn = p; - - *out = (OPT_LIST *)xrealloc(*out, (i + 2) * sizeof(OPT_LIST)); - (*out)[i].autoclean = 1; - if (opts && !strcmp (p, "-k")) { - pn = pt; - pt = next_word(pn); - (*out)[i].autoclean = 0; - } - pg = (GLOB_LIST *)xmalloc(sizeof(GLOB_LIST)); - meta_expand(pt, pg, NULL, version, ME_ALL); - (*out)[i].name = xstrdup(pn); - (*out)[i].opts = pg; - free(p); - } - memset(&(*out)[i], 0, sizeof(OPT_LIST)); - - return i; -} - -/* Environment variables can override defaults, testing only */ -static void gen_file_env(struct gen_files *gf) -{ - if (!safemode) { - char *e = xmalloc(strlen(gf->base)+5), *p1 = gf->base, *p2 = e; - while ((*p2++ = toupper(*p1++))) ; - strcpy(p2-1, "PATH"); /* safe, xmalloc */ - if ((p2 = getenv(e)) != NULL) { - free(gf->name); - gf->name = xstrdup(p2); - } - free(e); - } -} - -/* Read a config option for a generated filename */ -static int gen_file_conf(struct gen_files *gf, int assgn, const char *parm, const char *arg) -{ - - int l = strlen(gf->base); - if (assgn && - strncmp(parm, gf->base, l) == 0 && - strcmp(parm+l, "file") == 0 && - !gf->name) { - gf->name = xstrdup(arg); - return(0); - } - return(1); -} - -/* Check we have a name for a generated file */ -static int gen_file_check(struct gen_files *gf, GLOB_LIST *g, - char *base_dir, char *version) -{ - char tmp[PATH_MAX]; - int ret = 0; - if (!gf->name) { - /* - * Specification: config file / no xxxfile parameter - * The default value for generated filename xxx is: - * - * xxxfile=/lib/modules/`uname -r`/modules.xxx - * - * If the config file exists but lacks an xxxfile - * specification, the default value is used since - * the system can't work without one. - */ - snprintf(tmp, sizeof(tmp), "%s/lib/modules/%s/modules.%s", - base_dir, version, gf->base); - gf->name = xstrdup(tmp); - } else { /* xxxfile defined in modules.conf */ - /* - * If we have a xxxfile definition in the configuration file - * we must resolve any shell meta-chars in its value. - */ - if (meta_expand(gf->name, g, base_dir, version, ME_ALL)) - ret = -1; - else if (!g->pathv || g->pathv[0] == NULL) - ret = -1; - else { - free(gf->name); - gf->name = xstrdup(g->pathv[0]); - } - } - return(ret); -} - -/* - * Read the configuration file. - * If parameter "all" == 0 then ignore everything except path info - * Return -1 if any error. - * Error messages generated. - */ -static int do_read(int all, char *force_ver, char *base_dir, char *conf_file, int depth) -{ - #define MAX_LEVEL 20 - FILE *fin; - GLOB_LIST g; - int i; - int assgn; - int drop_default_paths = 1; - int lineno = 0; - int ret = 0; - int state[MAX_LEVEL + 1]; /* nested "if" */ - int level = 0; - char buf[3000]; - char tmpline[PATH_MAX]; - char **pathp; - char *envpath; - char *version; - char *type; - char **glb; - char old_name[] = "/etc/conf.modules"; - int conf_file_specified = 0; - - /* - * The configuration file is optional. - * No error is printed if it is missing. - * If it is missing the following content is assumed. - * - * path[boot]=/lib/modules/boot - * - * path[toplevel]=/lib/modules/`uname -r` - * - * path[toplevel]=/lib/modules/`kernelversion` - * (where kernelversion gives the major kernel version: "2.0", "2.2"...) - * - * path[toplevel]=/lib/modules/default - * - * path[kernel]=/lib/modules/kernel - * path[fs]=/lib/modules/fs - * path[net]=/lib/modules/net - * path[scsi]=/lib/modules/scsi - * path[block]=/lib/modules/block - * path[cdrom]=/lib/modules/cdrom - * path[ipv4]=/lib/modules/ipv4 - * path[ipv6]=/lib/modules/ipv6 - * path[sound]=/lib/modules/sound - * path[fc4]=/lib/modules/fc4 - * path[video]=/lib/modules/video - * path[misc]=/lib/modules/misc - * path[pcmcia]=/lib/modules/pcmcia - * path[atm]=/lib/modules/atm - * path[usb]=/lib/modules/usb - * path[ide]=/lib/modules/ide - * path[ieee1394]=/lib/modules/ieee1394 - * path[mtd]=/lib/modules/mtd - * - * The idea is that modprobe will look first if the - * modules are compiled for the current release of the kernel. - * If not found, it will look for modules that fit for the - * general kernelversion (2.0, 2.2 and so on). - * If still not found, it will look into the default release. - * And if still not found, it will look in the other directories. - * - * The strategy should be like this: - * When you install a new linux kernel, the modules should go - * into a directory related to the release (version) of the kernel. - * Then you can do a symlink "default" to this directory. - * - * Each time you compile a new kernel, the make modules_install - * will create a new directory, but it won't change thee default. - * - * When you get a module unrelated to the kernel distribution - * you can place it in one of the last three directory types. - * - * This is the default strategy. Of course you can overide - * this in /etc/modules.conf. - * - * 2.3.15 added a new file tree walk algorithm which made it possible to - * point at a top level directory and get the same behaviour as earlier - * versions of modutils. 2.3.16 takes this one stage further, it - * removes all the individual directory names from most of the scans, - * only pointing at the top level directory. The only exception is the - * last ditch scan, scanning all of /lib/modules would be a bad idea(TM) - * so the last ditch scan still runs individual directory names under - * /lib/modules. - * - * Additional syntax: - * - * [add] above module module1 ... - * Specify additional modules to pull in on top of a module - * - * [add] below module module1 ... - * Specify additional modules needed to be able to load a module - * - * [add] prune filename ... - * - * [add] probe name module1 ... - * When "name" is requested, modprobe tries to install each - * module in the list until it succeeds. - * - * [add] probeall name module1 ... - * When "name" is requested, modprobe tries to install all - * modules in the list. - * If any module is installed, the command has succeeded. - * - * [add] options module option_list - * - * For all of the above, the optional "add" prefix is used to - * add to a list instead of replacing the contents. - * - * include FILE_TO_INCLUDE - * This does what you expect. No limitation on include levels. - * - * persistdir=persist_directory - * Name the directory to save persistent data from modules. - * - * In the following WORD is a sequence if non-white characters. - * If ' " or ` is found in the string, all characters up to the - * matching ' " or ` will also be included, even whitespace. - * Every WORD will then be expanded w.r.t. meta-characters. - * If the expanded result gives more than one word, then only - * the first word of the result will be used. - * - * - * define CODE WORD - * Do a putenv("CODE=WORD") - * - * EXPRESSION below can be: - * WORD compare_op WORD - * where compare_op is one of == != < <= >= > - * The string values of the WORDs are compared - * or - * -n WORD compare_op WORD - * where compare_op is one of == != < <= >= > - * The numeric values of the WORDs are compared - * or - * WORD - * if the expansion of WORD fails, or if the - * expansion is "0" (zero), "false" or "" (empty) - * then the expansion has the value FALSE. - * Otherwise the expansion has the value TRUE - * or - * -f FILENAME - * Test if the file FILENAME exists - * or - * -k - * Test if "autoclean" (i.e. called from the kernel) - * or - * ! EXPRESSION - * A negated expression is also an expression - * - * if EXPRESSION - * any config line - * ... - * elseif EXPRESSION - * any config line - * ... - * else - * any config line - * ... - * endif - * - * The else and elseif keywords are optional. - * "if"-statements nest up to 20 levels. - */ - - state[0] = 1; - - if (force_ver) - version = force_ver; - else - version = uts_info.release; - - config_version = xstrdup(version); - - /* Only read the default entries on the first file */ - if (depth == 0) { - maxpath = 100; - modpath = (struct PATH_TYPE *)xmalloc(maxpath * sizeof(struct PATH_TYPE)); - nmodpath = 0; - - maxexecs = 10; - execs = (struct EXEC_TYPE *)xmalloc(maxexecs * sizeof(struct EXEC_TYPE)); - nexecs = 0; - - /* - * Build predef options - */ - if (all && optlist[0]) - n_opt_list = build_list(optlist, &opt_list, version, 1); - - /* - * Build predef above - */ - if (all && above[0]) - n_abovelist = build_list(above, &abovelist, version, 0); - - /* - * Build predef below - */ - if (all && below[0]) - n_belowlist = build_list(below, &belowlist, version, 0); - - /* - * Build predef prune list - */ - if (prune[0]) - n_prunelist = build_list(prune, &prunelist, version, 0); - - /* - * Build predef aliases - */ - if (all && aliaslist[0]) - n_aliases = build_list(aliaslist, &aliases, version, 0); - - /* - * Build predef postinstalls - */ - if (all && post_install[0]) - for (i=0 ; post_install[i] ; i++ ) - decode_exec(xstrdup(post_install[i]), EXEC_POST_INSTALL); - - /* - * Build predef preremoves - */ - if (all && pre_remove[0]) - for (i=0 ; pre_remove[i] ; i++ ) - decode_exec(xstrdup(pre_remove[i]), EXEC_PRE_REMOVE); - - /* Order and priority is now: (MODPATH + modules.conf) || (predefs + modules.conf) */ - if ((envpath = getenv("MODPATH")) != NULL && !safemode) { - size_t len; - char *p; - char *path; - - /* Make a copy so's we can mung it with strtok. */ - len = strlen(envpath) + 1; - p = alloca(len); - memcpy(p, envpath, len); - path = alloca(PATH_MAX); - - for (p = strtok(p, ":"); p != NULL; p = strtok(NULL, ":")) { - len = snprintf(path, PATH_MAX, p, version); - modpath[nmodpath].path = xstrdup(path); - if ((type = strrchr(path, '/')) != NULL) - type += 1; - else - type = "misc"; - modpath[nmodpath].type = xstrdup(type); - if (++nmodpath >= maxpath) { - maxpath += 100; - modpath = (struct PATH_TYPE *)xrealloc(modpath, - maxpath * sizeof(struct PATH_TYPE)); - } - - } - } else { - /* - * Build the default "path[type]" configuration - */ - int n; - char *k; - - /* The first entry in the path list */ - modpath[nmodpath].type = xstrdup("boot"); - snprintf(tmpline, sizeof(tmpline), "%s/lib/modules/boot", base_dir); - modpath[nmodpath].path = xstrdup(tmpline); - ++nmodpath; - - /* The second entry in the path list, `uname -r` */ - modpath[nmodpath].type = xstrdup("toplevel"); - snprintf(tmpline, sizeof(tmpline), "%s/lib/modules/%s", base_dir, version); - modpath[nmodpath].path = xstrdup(tmpline); - ++nmodpath; - - /* The third entry in the path list, `kernelversion` */ - modpath[nmodpath].type = xstrdup("toplevel"); - for (n = 0, k = version; *k; ++k) { - if (*k == '.' && ++n == 2) - break; - } - snprintf(tmpline, sizeof(tmpline), "%s/lib/modules/%.*s", base_dir, - (/* typecast for Alpha */ int)(k - version), version); - modpath[nmodpath].path = xstrdup(tmpline); - ++nmodpath; - - /* The rest of the entries in the path list */ - for (pathp = tbpath; *pathp; ++pathp) { - char **type; - - for (type = tbtype; *type; ++type) { - char path[PATH_MAX]; - - snprintf(path, sizeof(path), "%s%s/%s", base_dir, *pathp, *type); - if (meta_expand(path, &g, NULL, version, ME_ALL)) - return -1; - - for (glb = g.pathv; glb && *glb; ++glb) { - modpath[nmodpath].type = xstrdup(*type); - modpath[nmodpath].path = *glb; - if (++nmodpath >= maxpath) { - maxpath += 100; - modpath = (struct PATH_TYPE *)xrealloc(modpath, - maxpath * sizeof(struct PATH_TYPE)); - } - } - } - } - } - - /* Environment overrides for testing only, undocumented */ - for (i = 0; i < gen_file_count; ++i) - gen_file_env(gen_file+i); - - } /* End of depth == 0 */ - - if (conf_file || - ((conf_file = getenv("MODULECONFIG")) != NULL && *conf_file && !safemode)) { - if (!(fin = fopen(conf_file, "r"))) { - error("Can't open %s", conf_file); - return -1; - } - conf_file_specified = 1; - } else { - if (!(fin = fopen((conf_file = ETC_MODULES_CONF), "r"))) { - /* Fall back to non-standard name */ - if ((fin = fopen((conf_file = old_name), "r"))) { - fprintf(stderr, - "Warning: modutils is reading from %s because\n" - " %s does not exist. The use of %s is\n" - " deprecated, please rename %s to %s\n" - " as soon as possible. Command\n" - " mv %s %s\n", - old_name, ETC_MODULES_CONF, - old_name, old_name, ETC_MODULES_CONF, - old_name, ETC_MODULES_CONF); - } - /* So what... use the default configuration */ - } - } - - if (fin) { - struct stat statbuf1, statbuf2; - if (fstat(fileno(fin), &statbuf1) == 0) - config_mtime = statbuf1.st_mtime; - config_file = xstrdup(conf_file); /* Save name actually used */ - if (!conf_file_specified && - stat(ETC_MODULES_CONF, &statbuf1) == 0 && - stat(old_name, &statbuf2) == 0) { - /* Both /etc files exist */ - if (statbuf1.st_dev == statbuf2.st_dev && - statbuf1.st_ino == statbuf2.st_ino) { - if (lstat(ETC_MODULES_CONF, &statbuf1) == 0 && - S_ISLNK(statbuf1.st_mode)) - fprintf(stderr, - "Warning: You do not need a link from %s to\n" - " %s. The use of %s is deprecated,\n" - " please remove %s and rename %s\n" - " to %s as soon as possible. Commands.\n" - " rm %s\n" - " mv %s %s\n", - ETC_MODULES_CONF, old_name, - old_name, ETC_MODULES_CONF, old_name, ETC_MODULES_CONF, - ETC_MODULES_CONF, - old_name, ETC_MODULES_CONF); - else { -#ifndef NO_WARN_ON_OLD_LINK - fprintf(stderr, - "Warning: You do not need a link from %s to\n" - " %s. The use of %s is deprecated,\n" - " please remove %s as soon as possible. Command\n" - " rm %s\n", - old_name, ETC_MODULES_CONF, - old_name, old_name, - old_name); -#endif - } - } - else - fprintf(stderr, - "Warning: modutils is reading from %s and\n" - " ignoring %s. The use of %s is deprecated,\n" - " please remove %s as soon as possible. Command\n" - " rm %s\n", - ETC_MODULES_CONF, old_name, - old_name, old_name, - old_name); - } - } - - /* - * Finally, decode the file - */ - while (fin && fgets_strip(buf, sizeof(buf) - 1, fin, &lineno) != NULL) { - char *arg2; - char *parm = buf; - char *arg; - int one_err = 0; - int adding; - - while (isspace(*parm)) - parm++; - - if (strncmp(parm, "add", 3) == 0) { - adding = 1; - parm += 3; - while (isspace(*parm)) - parm++; - } else - adding = 0; - - arg = parm; - - if (*parm == '\0') - continue; - - one_err = 1; - - while (*arg > ' ' && *arg != '=') - arg++; - - if (*arg == '=') - assgn = 1; - else - assgn = 0; - *arg++ = '\0'; - while (isspace(*arg)) - arg++; - - /* - * endif - */ - if (!assgn && strcmp(parm, "endif") == 0) { - if (level > 0) - --level; - else { - error("unmatched endif in line %d", lineno); - return -1; - } - continue; - } - - /* - * else - */ - if (!assgn && strcmp(parm, "else") == 0) { - if (level <= 0) { - error("else without if in line %d", lineno); - return -1; - } - state[level] = !state[level]; - continue; - } - - /* - * elseif - */ - if (!assgn && strcmp(parm, "elseif") == 0) { - if (level <= 0) { - error("elseif without if in line %d", lineno); - return -1; - } - if (state[level] != 0) { - /* - * We have already found a TRUE - * if statement in this "chain". - * That's what "2" means. - */ - state[level] = 2; - continue; - } - /* else: No TRUE if has been found, cheat */ - /* - * The "if" handling increments level, - * but this is the _same_ level as before. - * So, compensate for it. - */ - --level; - parm = "if"; - /* Fallthru to "if" */ - } - - /* - * if - */ - if (strcmp(parm, "if") == 0) { - char *cmp; - int not = 0; - int numeric = 0; - - if (level >= MAX_LEVEL) { - error("Too many nested if's in line %d\n", lineno); - return -1; - } - state[++level] = 0; /* default false */ - - if (*arg == '!') { - not = 1; - arg = next_word(arg); - } - - if (strncmp(arg, "-k", 2) == 0) { - state[level] = flag_autoclean; - continue; - } - - if (strncmp(arg, "-f", 2) == 0) { - char *file = next_word(arg); - meta_expand(file, &g, NULL, version, ME_ALL); - if (access(g.pathc ? g.pathv[0] : file, R_OK) == 0) - state[level] = !not; - else - state[level] = not; - continue; - } - - if (strncmp(arg, "-n", 2) == 0) { - numeric = 1; - arg = next_word(arg); - } - - - cmp = next_word(arg); - if (*cmp) { - GLOB_LIST g2; - long n1 = 0; - long n2 = 0; - char *w1 = ""; - char *w2 = ""; - - arg2 = next_word(cmp); - - meta_expand(arg, &g, NULL, version, ME_ALL); - if (g.pathc && g.pathv[0]) - w1 = g.pathv[0]; - - meta_expand(arg2, &g2, NULL, version, ME_ALL); - if (g2.pathc && g2.pathv[0]) - w2 = g2.pathv[0]; - - if (numeric) { - n1 = strtol(w1, NULL, 0); - n2 = strtol(w2, NULL, 0); - } - - if (strcmp(cmp, "==") == 0 || - strcmp(cmp, "=") == 0) { - if (numeric) - state[level] = (n1 == n2); - else - state[level] = strcmp(w1, w2) == 0; - } else if (strcmp(cmp, "!=") == 0) { - if (numeric) - state[level] = (n1 != n2); - else - state[level] = strcmp(w1, w2) != 0; - } else if (strcmp(cmp, ">=") == 0) { - if (numeric) - state[level] = (n1 >= n2); - else - state[level] = strcmp(w1, w2) >= 0; - } else if (strcmp(cmp, "<=") == 0) { - if (numeric) - state[level] = (n1 <= n2); - else - state[level] = strcmp(w1, w2) <= 0; - } else if (strcmp(cmp, ">") == 0) { - if (numeric) - state[level] = (n1 > n2); - else - state[level] = strcmp(w1, w2) > 0; - } else if (strcmp(cmp, "<") == 0) { - if (numeric) - state[level] = (n1 < n2); - else - state[level] = strcmp(w1, w2) < 0; - } - } else { /* Check defined value, if any */ - /* undef or defined as - * "" or "0" or "false" => false - * defined => true - */ - if (!meta_expand(arg, &g, NULL, version, ME_ALL) && - g.pathc > 0 && - strcmp(g.pathv[0], "0") != 0 && - strcmp(g.pathv[0], "false") != 0 && - strlen(g.pathv[0]) != 0) - state[level] = 1; /* true */ - } - if (not) - state[level] = !state[level]; - - continue; - } - - /* - * Should we bother? - */ - if (state[level] != 1) - continue; - - /* - * define - */ - if (!assgn && strcmp(parm, "define") == 0) { - char env[PATH_MAX]; - - arg2 = next_word(arg); - meta_expand(arg2, &g, NULL, version, ME_ALL); - snprintf(env, sizeof(env), "%s=%s", arg, (g.pathc ? g.pathv[0] : "")); - putenv(xstrdup(env)); - one_err = 0; - } - - /* - * include - */ - if (!assgn && strcmp(parm, "include") == 0) { - meta_expand(arg, &g, NULL, version, ME_ALL); - - if (!do_read(all, version, base_dir, g.pathc ? g.pathv[0] : arg, depth+1)) - one_err = 0; - else - error("include %s failed\n", arg); - } - - /* - * above - */ - else if (all && !assgn && strcmp(parm, "above") == 0) { - decode_list(&n_abovelist, &abovelist, arg, adding, version, 0); - one_err = 0; - } - - /* - * below - */ - else if (all && !assgn && strcmp(parm, "below") == 0) { - decode_list(&n_belowlist, &belowlist, arg, adding, version, 0); - one_err = 0; - } - - /* - * prune - */ - else if (!assgn && strcmp(parm, "prune") == 0) { - decode_list(&n_prunelist, &prunelist, arg, adding, version, 0); - one_err = 0; - } - - /* - * probe - */ - else if (all && !assgn && strcmp(parm, "probe") == 0) { - decode_list(&n_probe_list, &probe_list, arg, adding, version, 0); - one_err = 0; - } - - /* - * probeall - */ - else if (all && !assgn && strcmp(parm, "probeall") == 0) { - decode_list(&n_probeall_list, &probeall_list, arg, adding, version, 0); - one_err = 0; - } - - /* - * options - */ - else if (all && !assgn && strcmp(parm, "options") == 0) { - decode_list(&n_opt_list, &opt_list, arg, adding, version, 1); - one_err = 0; - } - - /* - * alias - */ - else if (all && !assgn && strcmp(parm, "alias") == 0) { - /* - * Replace any previous (default) definitions - * for the same module - */ - decode_list(&n_aliases, &aliases, arg, 0, version, 0); - one_err = 0; - } - - /* - * Specification: /etc/modules.conf - * The format of the commands in /etc/modules.conf are: - * - * pre-install module command - * install module command - * post-install module command - * pre-remove module command - * remove module command - * post-remove module command - * - * The different words are separated by tabs or spaces. - */ - /* - * pre-install - */ - else if (all && !assgn && (strcmp(parm, "pre-install") == 0)) { - decode_exec(arg, EXEC_PRE_INSTALL); - one_err = 0; - } - - /* - * install - */ - else if (all && !assgn && (strcmp(parm, "install") == 0)) { - decode_exec(arg, EXEC_INSTALL); - one_err = 0; - } - - /* - * post-install - */ - else if (all && !assgn && (strcmp(parm, "post-install") == 0)) { - decode_exec(arg, EXEC_POST_INSTALL); - one_err = 0; - } - - /* - * pre-remove - */ - else if (all && !assgn && (strcmp(parm, "pre-remove") == 0)) { - decode_exec(arg, EXEC_PRE_REMOVE); - one_err = 0; - } - - /* - * remove - */ - else if (all && !assgn && (strcmp(parm, "remove") == 0)) { - decode_exec(arg, EXEC_REMOVE); - one_err = 0; - } - - /* - * post-remove - */ - else if (all && !assgn && (strcmp(parm, "post-remove") == 0)) { - decode_exec(arg, EXEC_POST_REMOVE); - one_err = 0; - } - - /* - * insmod_opt= - */ - else if (assgn && (strcmp(parm, "insmod_opt") == 0)) { - insmod_opt = xstrdup(arg); - one_err = 0; - } - - /* - * keep - */ - else if (!assgn && (strcmp(parm, "keep") == 0)) { - drop_default_paths = 0; - one_err = 0; - } - - /* - * path...= - */ - else if (assgn && strncmp(parm, "path", 4) == 0) { - /* - * Specification: config file / path parameter - * The path parameter specifies a directory to - * search for modules. - * This parameter may be repeated multiple times. - * - * Note that the actual path may be defined using - * wildcards and other shell meta-chars, such as "*?`". - * For example: - * path[misc]=/lib/modules/1.1.5?/misc - * - * Optionally the path keyword carries a tag. - * This tells us a little more about the purpose of - * this directory and allows some automated operations. - * A path is marked with a tag by adding the tag, - * enclosed in square brackets, to the path keyword: - * # - * path[boot]=/lib/modules/boot - * # - * This case identifies the path a of directory - * holding modules loadable a boot time. - */ - - if (drop_default_paths) { - int n; - - /* - * Specification: config file / path / default - * - * Whenever there is a path[] specification - * in the config file, all the default - * path are reset. - * - * If one instead wants to _add_ to the default - * set of paths, one has to have the option - * keep - * before the first path[]-specification line - * in the configuration file. - */ - drop_default_paths = 0; - for (n = 0; n < nmodpath; n++) { - free(modpath[n].path); - free(modpath[n].type); - } - nmodpath = 0; - } - - /* - * Get (the optional) tag - * If the tag is missing, the word "misc" - * is assumed. - */ - type = "misc"; - - if (parm[4] == '[') { - char *pt_type = parm + 5; - - while (*pt_type != '\0' && *pt_type != ']') - pt_type++; - - if (*pt_type == ']' && pt_type[1] == '\0') { - *pt_type = '\0'; - type = parm + 5; - } /* else CHECKME */ - } - - /* - * Handle the actual path description - */ - if (meta_expand(arg, &g, base_dir, version, ME_ALL)) - return -1; - for (glb = g.pathv; glb && *glb; ++glb) { - modpath[nmodpath].type = xstrdup(type); - modpath[nmodpath].path = *glb; - if (++nmodpath >= maxpath) { - maxpath += 100; - modpath = (struct PATH_TYPE *)xrealloc(modpath, - maxpath * sizeof(struct PATH_TYPE)); - } - } - one_err = 0; - } - - /* - * persistdir - */ - else if (assgn && strcmp(parm, "persistdir") == 0) { - meta_expand(arg, &g, NULL, version, ME_ALL); - persistdir = xstrdup(g.pathc ? g.pathv[0] : arg); - one_err = 0; - } - - /* Names for generated files in config file */ - for (i = 0; one_err && i < gen_file_count; ++i) - one_err = gen_file_conf(gen_file+i, assgn, parm, arg); - - /* - * any errors so far? - */ - if (all == 0) - one_err = 0; - else if (one_err) { - error("Invalid line %d in %s\n\t%s", - lineno, conf_file, buf); - ret = -1; - } - } - if (fin) - fclose(fin); - - if (level) { - error("missing endif at %s EOF", conf_file); - ret = -1; - } - - if (ret) - return ret; - /* else */ - - if (depth == 0) { - /* Check we have names for generated files */ - for (i = 0; !ret && i < gen_file_count; ++i) - ret = gen_file_check(gen_file+i, &g, base_dir, version); - } - - return ret; -} - -int config_read(int all, char *force_ver, char *base_dir, char *conf_file) -{ - int r; - if (modpath != NULL) - return 0; /* already initialized */ - - if (uname(&uts_info) < 0) { - error("Failed to find kernel name information"); - return -1; - } - - if (access(MODUTILS_MACROS, R_OK) == 0){ - r = do_read(all, force_ver, base_dir, MODUTILS_MACROS, 0); - r = do_read(all, force_ver, "", conf_file, 1); - } else { - r = do_read(all, force_ver, base_dir, conf_file, 0); - } - - if (quick && !r && !need_update (force_ver, base_dir)) - exit (0); - - return r; -} - -/****************************************************************************/ -/* - * FIXME: Far too much global state. KAO. - */ -static int found; -static int favail; -static int one_only; -static int meta_expand_type; -char **list; -static const char *filter_by_file; -static char *filter_by_dir; - -/* - * Add a file name if it exist - */ -static int config_add(const char *file, const struct stat *sb) -{ - int i; - int npaths = 0; - char **paths = NULL; - - if (meta_expand_type) { - GLOB_LIST g; - char **p; - char full[PATH_MAX]; - - snprintf(full, sizeof(full), "%s/%s", file, filter_by_file); - - if (filter_by_dir && !strstr(full, filter_by_dir)) - return 0; - - if (meta_expand(full, &g, NULL, config_version, meta_expand_type)) - return 1; - for (p = g.pathv; p && *p; ++p) { - paths = (char **)xrealloc(paths, - (npaths + 1) * sizeof(char *)); - paths[npaths++] = *p; - } - } else { /* normal path match or match with "*" */ - if (!S_ISREG(sb->st_mode)) - return 0; - - if (strcmp(filter_by_file, "*")) { - char *p; - - if ((p = strrchr(file, '/')) == NULL) - p = (char *)file; - else - p += 1; - - if (strcmp(p, filter_by_file)) - return 0; - } - if (filter_by_dir && !strstr(file, filter_by_dir)) - return 0; - paths = (char **)xmalloc(sizeof(char **)); - *paths = xstrdup(file); - npaths = 1; - } - - for (i = 0; i < npaths; ++i) { - struct stat sbuf; - - if (S_ISDIR(sb->st_mode)) { - if (stat(paths[i], &sbuf) == 0) - sb = &sbuf; - } - if (S_ISREG(sb->st_mode) && sb->st_mode & S_IRUSR) { - int j; - char **this; - - if (!root_check_off) { - if (sb->st_uid != 0) { - error("%s is not owned by root", paths[i]); - continue; - } - } - - /* avoid duplicates */ - for (j = 0, this = list; j < found; ++j, ++this) { - if (strcmp(*this, paths[i]) == 0) { - free(paths[i]); - goto next; - } - } - - list[found] = paths[i]; - if (++found >= favail) - list = (char **)xrealloc(list, - (favail += 100) * sizeof(char *)); - - if (one_only) { - for (j = i + 1; j < npaths; ++j) - free(paths[j]); - free(paths); - return 1; /* finish xftw */ - } - } - next: ; - } - - if (npaths > 0) - free(paths); - - return 0; -} - -/* - * Find modules matching the name "match" in directory of type "type" - * (type == NULL matches all) - * - * Return a pointer to the list of modules found (or NULL if error). - * Update the counter (sent as parameter). - */ -GLOB_LIST *config_lstmod(const char *match, const char *type, int first_only) -{ - /* - * Note: - * There are _no_ wildcards remaining in the path descriptions! - */ - struct stat sb; - int i; - int ret = 0; - char *path = NULL; - char this[PATH_MAX]; - - if (!match) - match = "*"; - one_only = first_only; - found = 0; - filter_by_file = match; - filter_by_dir = NULL; - if (type) { - char tmpdir[PATH_MAX]; - snprintf(tmpdir, sizeof(tmpdir), "/%s/", type); - filter_by_dir = xstrdup(tmpdir); - } - /* In safe mode, the module name is always handled as is, without meta - * expansion. It might have come from an end user via kmod and must - * not be trusted. Even in unsafe mode, only apply globbing to the - * module name, not command expansion. We trust config file input so - * applying command expansion is safe, we do not trust command line input. - * This assumes that the only time the user can specify -C config file - * is when they run under their own authority. In particular all - * mechanisms that call modprobe as root on behalf of the user must - * run in safe mode, without letting the user supply a config filename. - */ - meta_expand_type = 0; - if (strpbrk(match, SHELL_META) && strcmp(match, "*") && !safemode) - meta_expand_type = ME_GLOB|ME_BUILTIN_COMMAND; - - list = (char **)xmalloc((favail = 100) * sizeof(char *)); - - for (i = 0; i < nmodpath; i++) { - path = modpath[i].path; - /* Special case: insmod: handle single, non-wildcard match */ - if (first_only && strpbrk(match, SHELL_META) == NULL) { - /* Fix for "2.1.121 syntax */ - snprintf(this, sizeof(this), "%s/%s/%s", path, - modpath[i].type, match); - if (stat(this, &sb) == 0 && - config_add(this, &sb)) - break; - /* End fix for "2.1.121 syntax */ - - snprintf(this, sizeof(this), "%s/%s", path, match); - if (stat(this, &sb) == 0 && - config_add(this, &sb)) - break; - } - - /* Start looking */ - if ((ret = xftw(path, config_add))) { - break; - } - } - if (ret >= 0) { - GLOB_LIST *g = (GLOB_LIST *)xmalloc(sizeof(GLOB_LIST)); - g->pathc = found; - g->pathv = list; - free(filter_by_dir); - return g; - } - free(list); - free(filter_by_dir); - return NULL; -} - -/* Given a bare module name, poke through the module path to find the file. */ -char *search_module_path(const char *base) -{ - GLOB_LIST *g; - - if (config_read(0, NULL, "", NULL) < 0) - return NULL; - /* else */ - g = config_lstmod(base, NULL, 1); - if (g == NULL || g->pathc == 0) { - char base_o[PATH_MAX]; - - snprintf(base_o, sizeof(base_o), "%s.o", base); - g = config_lstmod(base_o, NULL, 1); -#ifdef CONFIG_USE_ZLIB - if (g == NULL || g->pathc == 0) { - snprintf(base_o, sizeof(base_o), "%s.o.gz", base); - g = config_lstmod(base_o, NULL, 1); - } -#endif - } - if (g == NULL || g->pathc == 0) - return NULL; - /* else */ - return g->pathv[0]; -} diff --git a/mdk-stage1/insmod-modutils/util/gzfiles.c b/mdk-stage1/insmod-modutils/util/gzfiles.c deleted file mode 100644 index 8d02253bb..000000000 --- a/mdk-stage1/insmod-modutils/util/gzfiles.c +++ /dev/null @@ -1,74 +0,0 @@ -/* - * This simple library intends to make it transparent to read gzipped and/or - * standard files. This is simple enough to fit modutils' needs, but may be - * easily adapted to anyone's needs. It's completely free, do what you want - * with it . - Willy Tarreau <willy@meta-x.org> - 2000/05/05 - - */ - -#ifdef CONFIG_USE_ZLIB - -#include <stdio.h> -#include <zlib.h> -#include <sys/types.h> -#include <fcntl.h> -#include <unistd.h> - -/* redefinition of gz_stream which isn't exported by zlib */ -typedef struct gz_stream { - z_stream stream; - int z_err; /* error code for last stream operation */ - int z_eof; /* set if end of input file */ - FILE *file; /* .gz file */ - Byte *inbuf; /* input buffer */ - Byte *outbuf; /* output buffer */ - uLong crc; /* crc32 of uncompressed data */ - char *msg; /* error message */ - char *path; /* path name for debugging only */ - int transparent; /* 1 if input file is not a .gz file */ - char mode; /* 'w' or 'r' */ - long startpos; /* start of compressed data in file (header skipped) */ -} gz_stream; - -/* maximum number of simultaneous open files, also greater file descriptor number */ -#define MAXFD 64 - -/* this static list is assumed to be filled with NULLs at runtime */ -static gzFile gzf_fds[MAXFD]; - -/* returns the filedesc of the opened file. */ -int gzf_open(const char *name, int mode) { - int fd; - gzFile g; - - if ((g=gzopen(name, "rb")) != NULL) { - fd=fileno(((gz_stream*)g)->file); - gzf_fds[fd]=g; - } - else if ((fd=open(name, mode)) != -1) { - gzf_fds[fd]=NULL; /* NULL means not GZ mode */ - } - return fd; -} - -off_t gzf_lseek(int fd, off_t offset, int whence) { - if (fd<0 || fd>=MAXFD || gzf_fds[fd]==NULL) - return lseek(fd, offset, whence); - else - return gzseek(gzf_fds[fd], offset, whence); -} - -int gzf_read(int fd, void *buf, size_t count) { - if (fd<0 || fd>=MAXFD || gzf_fds[fd]==NULL) - return read(fd, buf, count); - else - return gzread(gzf_fds[fd], buf, count); -} - -void gzf_close(int fd) { - if (fd<0 || fd>=MAXFD || gzf_fds[fd]==NULL) - close(fd); - else - gzclose(gzf_fds[fd]); -} -#endif - diff --git a/mdk-stage1/insmod-modutils/util/logger.c b/mdk-stage1/insmod-modutils/util/logger.c deleted file mode 100644 index 4774a0beb..000000000 --- a/mdk-stage1/insmod-modutils/util/logger.c +++ /dev/null @@ -1,160 +0,0 @@ -/* Error logging facilities. - Copyright 1996, 1997 Linux International. - - Contributed by Richard Henderson <rth@tamu.edu> - - This file is part of the Linux modutils. - - This program is free software; you can redistribute it and/or modify it - under the terms of the GNU General Public License as published by the - Free Software Foundation; either version 2 of the License, or (at your - option) any later version. - - This program is distributed in the hope that it will be useful, but - WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - General Public License for more details. - - You should have received a copy of the GNU General Public License - along with this program; if not, write to the Free Software Foundation, - Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA - */ - -#include <limits.h> -#include <stdio.h> -#include <stdarg.h> -#include <stdlib.h> -#include <errno.h> -#include <syslog.h> - -#include "util.h" - -/*======================================================================*/ - -int log; - -int errors; -const char *error_file; - -#define STOREMSG -#ifdef STOREMSG -struct cbuf { - struct cbuf *next; - int type; - char *msg; -} *head, *tail; - -static void dumpmsg(void) -{ - for (;head; head = head->next) - syslog(head->type, "%s", head->msg); -} -#endif /* STOREMSG */ - -void setsyslog(const char *program) -{ - openlog(program, LOG_CONS, LOG_DAEMON); -#ifdef STOREMSG - atexit(dumpmsg); -#endif - log = 1; -} - -#ifdef _STANDALONE_ -static int silent; - -const char *program_name; - -static void savemsg(int type, char *msg) -{ - struct cbuf *me = (struct cbuf *)xmalloc(sizeof(struct cbuf)); - char *s = xstrdup(msg); - - me->next = NULL; - me->type = type; - me->msg = s; - - if (tail) - tail->next = me; - else - head = me; - tail = me; -} - -void error(const char *fmt,...) -{ - va_list args; - - if (silent) - ; - else if (log) { - char buf[2*PATH_MAX]; - int n; - - if (error_file) - n = snprintf(buf, sizeof(buf), "%s: ", error_file); - else - n = 0; - va_start(args, fmt); - vsnprintf(buf + n, sizeof(buf) - n, fmt, args); - va_end(args); -#ifdef STOREMSG - savemsg(LOG_ERR, buf); -#else - syslog(LOG_ERR, "%s", buf); -#endif - } else { - if (error_file) - fprintf(stderr, "%s: ", error_file); - va_start(args, fmt); - vfprintf(stderr, fmt, args); - va_end(args); - putc('\n', stderr); - } - - errors++; -} - -void lprintf(const char *fmt,...) -{ - va_list args; - - if (silent); - else if (log) { - char buf[2*PATH_MAX]; - va_start(args, fmt); - vsnprintf(buf, sizeof(buf), fmt, args); - va_end(args); -#ifdef STOREMSG - savemsg(LOG_INFO, buf); -#else - syslog(LOG_INFO, "%s", buf); -#endif - } else { - va_start(args, fmt); - vfprintf(stdout, fmt, args); - va_end(args); - putchar('\n'); - } -} -#else /* _STANDALONE_ */ -#include "../../log.h" -void error(const char *s, ...) -{ - va_list p; - - va_start(p, s); - vlog_message(s, p); - va_end(p); -} - -void lprintf(const char *s, ...) -{ - va_list p; - - va_start(p, s); - vlog_message(s, p); - va_end(p); -} -#endif - diff --git a/mdk-stage1/insmod-modutils/util/meta_expand.c b/mdk-stage1/insmod-modutils/util/meta_expand.c deleted file mode 100644 index 41fb4024c..000000000 --- a/mdk-stage1/insmod-modutils/util/meta_expand.c +++ /dev/null @@ -1,339 +0,0 @@ -/* - * Handle expansion of meta charaters - * - * Copyright 1999 Björn Ekwall <bj0rn@blox.se> - * - * "kernelversion" idea from the Debian release via: - * Wichert Akkerman <wakkerma@cs.leidenuniv.nl> - * - * Use wordexp(): idea from Tim Waugh <tim@cyberelk.demon.co.uk> - * - * Alpha typecast: Michal Jaegermann <michal@ellpspace.math.ualberta.ca> - * - * This file is part of the Linux modutils. - * - * This program is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License as published by the - * Free Software Foundation; either version 2 of the License, or (at your - * option) any later version. - * - * This program is distributed in the hope that it will be useful, but - * WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software Foundation, - * Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. - */ - -#ifdef HAVE_WORDEXP -#undef HAVE_WORDEXP -#define HAVE_WORDEXP 0 -#endif - -#include <stdio.h> -#include <stdlib.h> -#include <limits.h> -#include <string.h> -#include <ctype.h> -#if HAVE_WORDEXP -#include <wordexp.h> -#elif HAVE_GLOB -#include <glob.h> -#endif -#include "util.h" - -/* - * Split into words delimited by whitespace, - * handle remaining quotes though... - * If strip_quotes != 0 then strip one level of quotes from the line. - */ -static void split_line(GLOB_LIST *g, char *line, int strip_quotes) -{ - int len; - char *d; - char *e; - char *p; - char tmpline[PATH_MAX]; - - for (p = line; *p; p = e) { - /* Skip leading whitespace */ - while (*p && isspace(*p)) - ++p; - - /* find end of word */ - d = tmpline; - for (e = p; *e && !(isspace(*e)); ++e) { - char match; - - /* Quote handling */ - switch (*e) { - case '\\': - if (!strip_quotes) - *d++ = *e; - break; - - case '"': - case '\'': - match = *e; - if (!strip_quotes) - *d++ = *e; - for (++e; *e && *e != match; ++e) { - *d++ = *e; - if (*e == '\\' && *(e + 1) == match) - *d++ = *++e; - } - if (!strip_quotes) - *d++ = *e; - break; - - default: - *d++ = *e; - break; - } - } - - if ((len = (int)(d - tmpline)) > 0) { - char *str = xmalloc(len + 1); - strncpy(str, tmpline, len); - str[len] = '\0'; - g->pathv = (char **)xrealloc(g->pathv, - (g->pathc + 2) * sizeof(char *)); - g->pathv[g->pathc++] = str; - } - } - - if (g->pathc) - g->pathv[g->pathc] = NULL; -} - -static int glob_it(char *pt, GLOB_LIST *g) -{ -#if HAVE_WORDEXP - wordexp_t w; - - memset(&w, 0, sizeof(w)); - if (wordexp(pt, &w, WRDE_UNDEF)) { - /* - error("wordexp %s failed", pt); - */ - return -1; - } - /* else */ - g->pathc = w.we_wordc; - g->pathv = w.we_wordv; - - return 0; -#elif HAVE_GLOB /* but not wordexp */ - glob_t w; - - memset(&w, 0, sizeof(w)); - if (glob(pt, GLOB_NOSORT, NULL, &w)) { - /* - error("glob %s failed", pt); - */ - return -1; - } - /* else */ - if (w.gl_pathc && strpbrk(w.gl_pathv[0], SHELL_META)) { - globfree(&w); - return -1; - } - g->pathc = w.gl_pathc; - g->pathv = w.gl_pathv; - - return 0; -#else /* Neither wordexp nor glob */ - return -1; -#endif -} - -/* - * Expand the string (including meta-character) to a list of matches - * - * Return 0 if OK else -1 - */ -int meta_expand(char *pt, GLOB_LIST *g, char *base_dir, char *version, int type) -{ - FILE *fin; - int len = 0; - char *line = NULL; - char *p, *p1; - char tmpline[PATH_MAX + 1]; - char wrk[sizeof(tmpline)]; - char tmpcmd[2*sizeof(tmpline)+20]; /* room for /bin/echo "text" */ - - g->pathc = 0; - g->pathv = NULL; - - /* - * Take care of version dependent expansions - * Needed for forced version handling - */ - if ((p = strchr(pt, '`')) != NULL && (type & ME_BUILTIN_COMMAND)) { - do { - char *s; - - for (s = p + 1; isspace(*s); ++s) - ; - - if (strncmp(s, "uname -r", 8) == 0) { - while (*s && (*s != '`')) - ++s; - if (*s == '`') { - *p = '\0'; - snprintf(wrk, sizeof(wrk), "%s%s%s", - pt, - version, - s + 1); - *p = '`'; - } - strcpy(tmpline, wrk); /* safe, same size */ - pt = tmpline; - } else if (strncmp(s, "kernelversion", 13) == 0) { - while (*s && (*s != '`')) - ++s; - if (*s == '`') { - int n; - char *k; - - *p = '\0'; - for (n = 0, k = version; *k; ++k) { - if (*k == '.' && ++n == 2) - break; - } - snprintf(wrk, sizeof(wrk), "%s%.*s%s", - pt, - /* typecast for Alpha */ - (int)(k - version), - version, - s + 1); - *p = '`'; - strcpy(tmpline, wrk); /* safe, same size */ - pt = tmpline; - } - } else - break; - } while ((p = strchr(pt, '`')) != NULL); - } - - /* - * Any remaining meta-chars? - */ - if (strpbrk(pt, SHELL_META) == NULL) { - /* - * No meta-chars. - * Split into words, delimited by whitespace. - */ - snprintf(wrk, sizeof(wrk), "%s%s", (base_dir ? base_dir : ""), pt); - strcpy(tmpline, wrk); /* safe, same size */ - if ((p = strtok(tmpline, " \t\n")) != NULL) { - while (p) { - g->pathv = (char **)xrealloc(g->pathv, - (g->pathc + 2) * sizeof(char *)); - g->pathv[g->pathc++] = xstrdup(p); - p = strtok(NULL, " \t\n"); - } - } - if (g->pathc) - g->pathv[g->pathc] = NULL; - return 0; - } - /* else */ - /* - * Handle remaining meta-chars - */ - - /* - * Just plain quotes? - */ - if (strpbrk(pt, "&();|<>$`!{}[]~=+:?*") == NULL && - (p = strpbrk(pt, "\"'\\"))) { - split_line(g, pt, 1); - return 0; - } - - if (strpbrk(pt, "&();|<>$`\"'\\!{}~+:[]~?*") == NULL) { - /* Only "=" remaining, should be module options */ - split_line(g, pt, 0); - return 0; - } - - /* - * If there are meta-characters and - * if they are only shell glob meta-characters: do globbing - */ -#if HAVE_WORDEXP - if (strpbrk(pt, "&();|<>`\"'\\!{}~=+:") == NULL && - strpbrk(pt, "$[]~?*")) -#else - if (strpbrk(pt, "&();|<>$`\"'\\!{}~=+:") == NULL && - strpbrk(pt, "[]~?*")) -#endif - if ((type & ME_GLOB) && glob_it(pt, g) == 0) - return 0; - - if (strpbrk(pt, "&();|<>$`\"'\\!{}~+:[]~?*") == NULL) { - /* Only "=" remaining, should be module options */ - split_line(g, pt, 0); - return 0; - } - - /* - * Last resort: Use "echo". - * DANGER: Applying shell expansion to user supplied input is a - * major security risk. Modutils code should only do meta - * expansion via shell commands for trusted data. Basically - * this means only for data in the config file. Even that - * assumes that the user cannot run modprobe as root with - * their own config file. Programs (including the kernel) - * that invoke modprobe as root with user supplied input must - * pass exactly one user supplied parameter and must set - * safe mode. - */ - if (!(type & ME_SHELL_COMMAND)) - return 0; - snprintf(wrk, sizeof(wrk), "%s%s", (base_dir ? base_dir : ""), pt); - strcpy(tmpline, wrk); /* safe, same size */ - snprintf(tmpcmd, sizeof(tmpcmd), "/bin/echo \""); - for (p = tmpline, p1 = tmpcmd + strlen(tmpcmd); *p; ++p, ++p1) { - if (*p == '"' || *p == '\\') - *p1++ = '\\'; - *p1 = *p; - } - *p1++ = '"'; - *p1++ = '\0'; - if (p1 - tmpcmd > sizeof(tmpcmd)) { - error("tmpcmd overflow, should never happen"); - exit(1); - } - if ((fin = popen(tmpcmd, "r")) == NULL) { - error("Can't execute: %s", tmpcmd); - return -1; - } - /* else */ - - /* - * Collect the result - */ - while (fgets(tmpcmd, PATH_MAX, fin) != NULL) { - int l = strlen(tmpcmd); - - line = (char *)xrealloc(line, len + l + 1); - line[len] = '\0'; - strcat(line + len, tmpcmd); /* safe, realloc */ - len += l; - } - pclose(fin); - - if (line) { - /* shell used to strip one set of quotes. Paranoia code in - * 2.3.20 stops that strip so we do it ourselves. - */ - split_line(g, line, 1); - free(line); - } - - return 0; -} diff --git a/mdk-stage1/insmod-modutils/util/modstat.c b/mdk-stage1/insmod-modutils/util/modstat.c deleted file mode 100644 index 142b5ba49..000000000 --- a/mdk-stage1/insmod-modutils/util/modstat.c +++ /dev/null @@ -1,419 +0,0 @@ -/* - * Get kernel symbol table(s) and other relevant module info. - * - * Add module_name_list and l_module_name_list. - * Keith Owens <kaos@ocs.com.au> November 1999. - * Björn Ekwall <bj0rn@blox.se> in February 1999 (C) - * Initial work contributed by Richard Henderson <rth@tamu.edu> - * - * This file is part of the Linux modutils. - * - * This program is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License as published by the - * Free Software Foundation; either version 2 of the License, or (at your - * option) any later version. - * - * This program is distributed in the hope that it will be useful, but - * WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software Foundation, - * Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. - */ - -#include <unistd.h> -#include <stdlib.h> -#include <string.h> -#include <sys/types.h> -#include <sys/stat.h> -#include <fcntl.h> -#include <errno.h> -#include "util.h" -#include "module.h" -#include "obj.h" -#include "modstat.h" - -struct module_stat *module_stat; -size_t n_module_stat; -char *module_name_list; -size_t l_module_name_list; -struct module_symbol *ksyms; -size_t nksyms; -int k_new_syscalls; - -static void *old_kernsym; - -/************************************************************************/ -static void drop(void) -{ - /* - * Clean the slate for multiple runs - */ - if (module_stat) { - struct module_stat *m; - int i; - - for (i = 0, m = module_stat; i < n_module_stat; ++i, ++m) { - if (m->syms) - free(m->syms); - if (m->refs) - free(m->refs); - } - free(module_stat); - module_stat = NULL; - n_module_stat = 0; - } - if (module_name_list) { - free(module_name_list); - module_name_list = NULL; - l_module_name_list = 0; - } - if (ksyms) { - free(ksyms); - ksyms = NULL; - nksyms = 0; - } - if (old_kernsym) { - free(old_kernsym); - old_kernsym = NULL; - } -} - -static int new_get_kernel_info(int type) -{ - struct module_stat *modules; - struct module_stat *m; - struct module_symbol *syms; - struct module_symbol *s; - size_t ret; - size_t bufsize; - size_t nmod; - size_t nsyms; - size_t i; - size_t j; - char *module_names; - char *mn; - - drop(); - - /* - * Collect the loaded modules - */ - module_names = xmalloc(bufsize = 256); - while (query_module(NULL, QM_MODULES, module_names, bufsize, &ret)) { - if (errno != ENOSPC) { - error("QM_MODULES: %m\n"); - return 0; - } - module_names = xrealloc(module_names, bufsize = ret); - } - module_name_list = module_names; - l_module_name_list = bufsize; - n_module_stat = nmod = ret; - module_stat = modules = xmalloc(nmod * sizeof(struct module_stat)); - memset(modules, 0, nmod * sizeof(struct module_stat)); - - /* Collect the info from the modules */ - for (i = 0, mn = module_names, m = modules; - i < nmod; - ++i, ++m, mn += strlen(mn) + 1) { - struct module_info info; - - m->name = mn; - if (query_module(mn, QM_INFO, &info, sizeof(info), &ret)) { - if (errno == ENOENT) { - /* The module was removed out from underneath us. */ - m->flags = NEW_MOD_DELETED; - continue; - } - /* else oops */ - error("module %s: QM_INFO: %m", mn); - return 0; - } - - m->addr = info.addr; - - if (type & K_INFO) { - m->size = info.size; - m->flags = info.flags; - m->usecount = info.usecount; - m->modstruct = info.addr; - } - - if (type & K_REFS) { - int mm; - char *mrefs; - char *mr; - - mrefs = xmalloc(bufsize = 64); - while (query_module(mn, QM_REFS, mrefs, bufsize, &ret)) { - if (errno != ENOSPC) { - error("QM_REFS: %m"); - return 1; - } - mrefs = xrealloc(mrefs, bufsize = ret); - } - for (j = 0, mr = mrefs; - j < ret; - ++j, mr += strlen(mr) + 1) { - for (mm = 0; mm < i; ++mm) { - if (strcmp(mr, module_stat[mm].name) == 0) { - m->nrefs += 1; - m->refs = xrealloc(m->refs, m->nrefs * sizeof(struct module_stat **)); - m->refs[m->nrefs - 1] = module_stat + mm; - break; - } - } - } - free(mrefs); - } - - if (type & K_SYMBOLS) { /* Want info about symbols */ - syms = xmalloc(bufsize = 1024); - while (query_module(mn, QM_SYMBOLS, syms, bufsize, &ret)) { - if (errno == ENOSPC) { - syms = xrealloc(syms, bufsize = ret); - continue; - } - if (errno == ENOENT) { - /* - * The module was removed out - * from underneath us. - */ - m->flags = NEW_MOD_DELETED; - free(syms); - goto next; - } else { - error("module %s: QM_SYMBOLS: %m", mn); - return 0; - } - } - nsyms = ret; - - m->nsyms = nsyms; - m->syms = syms; - - /* Convert string offsets to string pointers */ - for (j = 0, s = syms; j < nsyms; ++j, ++s) - s->name += (unsigned long) syms; - } - next: ; - } - - if (type & K_SYMBOLS) { /* Want info about symbols */ - /* Collect the kernel's symbols. */ - syms = xmalloc(bufsize = 16 * 1024); - while (query_module(NULL, QM_SYMBOLS, syms, bufsize, &ret)) { - if (errno != ENOSPC) { - error("kernel: QM_SYMBOLS: %m"); - return 0; - } - syms = xrealloc(syms, bufsize = ret); - } - nksyms = nsyms = ret; - ksyms = syms; - - /* Convert string offsets to string pointers */ - for (j = 0, s = syms; j < nsyms; ++j, ++s) - s->name += (unsigned long) syms; - } - - return 1; -} - -#ifdef COMPAT_2_0 -/************************************************************************/ - -#define mscan(offs,siz,ptr) \ - if (lseek(kmem_fd, (off_t)(offs), SEEK_SET) == -1 || \ - read(kmem_fd, (ptr), (siz)) != (siz)) { \ - if (kmem_fd != -1) \ - close(kmem_fd); \ - error("kmem: %m"); \ - return 0; \ - } - -#define OLD_MOD_RUNNING 1 -#define OLD_MOD_DELETED 2 -#define OLD_MOD_VISITED 0x20000000 - -/* Fetch all the symbols and divvy them up as appropriate for the modules. */ -static int old_get_kernel_info(int type) -{ - struct old_kernel_sym *kernsym; - struct old_kernel_sym *k; - struct module_stat *module; - struct module_stat *mod; - struct module_symbol *s = NULL; - int kmem_fd = -1; - int nkernsym; - int nmod; - int nm; - int nms; - int i; - - drop(); - module_name_list = xmalloc(1); - *module_name_list = '\0'; - - if ((nkernsym = get_kernel_syms(NULL)) < 0) { - error("get_kernel_syms: %m"); - return 0; - } - kernsym = k = xmalloc(nkernsym * sizeof(struct old_kernel_sym)); - old_kernsym = kernsym; - if (get_kernel_syms(kernsym) != nkernsym) { - error("inconsistency with get_kernel_syms -- is someone else " - "playing with modules?"); - free(kernsym); - return 0; - } - - /* Number of modules */ - for (k = kernsym, nmod = 0, i = 0; i < nkernsym; ++i, ++k) { - if (k->name[0] == '#') { - if (k->name[1]) { - ++nmod; - i = strlen(k->name+1) + 1; - module_name_list = - xrealloc(module_name_list, - l_module_name_list + i); - strcpy(module_name_list+l_module_name_list, /* safe, xrealloc */ - k->name+1); - l_module_name_list += i; /* NUL separated strings */ - } - else - break; - } - } - module_stat = mod = module = xmalloc(nmod * sizeof(struct module_stat)); - memset(module, 0, nmod * sizeof(struct module_stat)); - n_module_stat = nmod; - - /* - * Will we need kernel internal info? - */ - if ((type & K_INFO) || (type & K_REFS)) { - if ((kmem_fd = open("/dev/kmem", O_RDONLY)) < 0) { - perror("ksyms: open /dev/kmem"); - return 0; - } - } - - /* - * Collect the module information. - */ - for (k = kernsym, nm = 0, i = 0; i < nkernsym; ++i, ++k) { - if (k->name[0] == '#') { - struct old_kernel_sym *p; - struct old_module info; - - if (k->name[1] == '\0') - break; /* kernel resident symbols follow */ - /* else normal module */ - - module = mod++; - ++nm; - module->name = k->name + 1; - module->modstruct = k->value; - - if ((type & K_INFO) || (type & K_REFS)) { - long tmp; - /* - * k->value is the address of the - * struct old_module - * in the kernel (for use via /dev/kmem) - */ - mscan(k->value, sizeof(info), &info); - module->addr = info.addr; - module->size = info.size * getpagesize(); - - mscan(info.addr, sizeof(long), &tmp); - module->flags = info.state & - (OLD_MOD_RUNNING | OLD_MOD_DELETED); - module->flags |= NEW_MOD_USED_ONCE; /* Cheat */ - if (tmp & OLD_MOD_AUTOCLEAN) - module->flags |= NEW_MOD_AUTOCLEAN; - if (tmp & OLD_MOD_VISITED) - module->flags |= NEW_MOD_VISITED; - - module->usecount = tmp & ~(OLD_MOD_AUTOCLEAN | OLD_MOD_VISITED); - } - - if ((type & K_REFS) && info.ref) { - struct old_module_ref mr; - int j; - unsigned long ref = info.ref; - - do { - mscan(ref, sizeof(struct old_module_ref), &mr); - for (j = 0; j < nm -1; ++j) { - if (mr.module == module_stat[j].modstruct) { - module->nrefs += 1; - module->refs = xrealloc(module->refs, module->nrefs * sizeof(struct module_stat **)); - module->refs[module->nrefs - 1] = module_stat + j; - break; - } - } - } while ((ref = mr.next) != 0); - } - - if (!(type & K_SYMBOLS)) - continue; - /* - * Find out how many symbols this module has. - */ - for (nms = 0, p = k+1; p->name[0] != '#'; ++p) - ++nms; - s = xmalloc(nms * sizeof(struct module_symbol)); - module->syms = s; - module->nsyms = nms; - } else if (type & K_SYMBOLS) { /* Want info about symbols */ - s->name = (unsigned long) k->name; - s->value = k->value; - ++s; - } - } - if ((type & K_INFO) || (type & K_REFS)) { - if (kmem_fd != -1) - close(kmem_fd); - } - - /* - * Kernel resident symbols follows - */ - if (type & K_SYMBOLS) { /* Want info about symbols */ - if (k->name[0] == '#') - ++k; - nksyms = nkernsym - (k - kernsym); - if (nksyms) { - ksyms = s = xmalloc(nksyms * sizeof(struct module_symbol)); - for (i = 0; i < nksyms; ++i, ++k) { - if (k->name[0] != '#') { - s->name = (unsigned long) k->name; - s->value = k->value; - ++s; - } - } - nksyms = s - ksyms; - } else - ksyms = NULL; - } - - return 1; -} -#endif /* COMPAT_2_0 */ - -int get_kernel_info(int type) -{ - k_new_syscalls = !query_module(NULL, 0, NULL, 0, NULL); - -#ifdef COMPAT_2_0 - if (!k_new_syscalls) - return old_get_kernel_info(type); -#endif /* COMPAT_2_0 */ - - return new_get_kernel_info(type); -} diff --git a/mdk-stage1/insmod-modutils/util/snap_shot.c b/mdk-stage1/insmod-modutils/util/snap_shot.c deleted file mode 100644 index adf54d28e..000000000 --- a/mdk-stage1/insmod-modutils/util/snap_shot.c +++ /dev/null @@ -1,154 +0,0 @@ -/* Take a snap shot of ksyms and modules for Oops debugging - Copyright 1999 Linux International. - - Contributed by Keith Owens <kaos@ocs.com.au> - - This file is part of the Linux modutils. - - This program is free software; you can redistribute it and/or modify it - under the terms of the GNU General Public License as published by the - Free Software Foundation; either version 2 of the License, or (at your - option) any later version. - - This program is distributed in the hope that it will be useful, but - WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - General Public License for more details. - - You should have received a copy of the GNU General Public License - along with this program; if not, write to the Free Software Foundation, - Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA - */ - -#include <errno.h> -#include <stdio.h> -#include <stdarg.h> -#include <time.h> -#include <unistd.h> -#include <string.h> - -#include "module.h" -#include "obj.h" -#include "modstat.h" -#include "util.h" - -static char snap_dir[] = "/var/log/ksymoops"; - -/* If snap_dir exists, take a snap shot of ksyms and modules to snap_dir. - * Prefix the files with the equivalent of - * date +%Y%m%d%T%M%S | sed -e 's/://g' - */ -void snap_shot(const char *module_names, int n_module_names) -{ - char file[] = "ccyymmddhhmmss.modules", buffer[4096]; - static char *infile[] = { "/proc/ksyms", "/proc/modules" }; - static char *suffix[] = { "ksyms", "modules" }; - struct tm *local; - time_t t; - int i, l; - FILE *in, *out; - - if (module_names) { - /* Only snap shot if the list of modules has changed. - * Otherwise auto cleanup takes a snap shot every time - * and ends up with a large snap shot directory. - */ - char *new_module_names; - size_t n_new_module_names; - get_kernel_info(0); - new_module_names = module_name_list; - n_new_module_names = n_module_stat; - if (n_module_names && n_new_module_names == n_module_names) { - while (n_module_names) { - if (strcmp(module_names, new_module_names)) - break; /* difference detected */ - i = strlen(module_names) + 1; - module_names += i; - new_module_names += i; - --n_module_names; - } - } - if (!n_module_names) - return; /* no difference, no need for snap shot */ - } - - if (chdir(snap_dir)) - return; - t = time(NULL); - local = localtime(&t); - for (i = 0; i < sizeof(infile)/sizeof(infile[0]); ++i) { - snprintf(file, sizeof(file), "%04d%02d%02d%02d%02d%02d.%s", - local->tm_year+1900, - local->tm_mon + 1, - local->tm_mday, - local->tm_hour, - local->tm_min, - local->tm_sec, - suffix[i]); - out = fopen(file, "w"); - if (!out) { - error("cannot create %s/%s %m", snap_dir, file); - return; - } - in = fopen(infile[i], "r"); - if (!in) { - error("cannot open %s %m", infile[i]); - return; - } - while ((l = fread(buffer, 1, sizeof(buffer), in)) > 0) { - if (fwrite(buffer, l, 1, out) != 1) { - error("unable to write to %s %m", file); - fclose(in); - fclose(out); - return; - } - } - if (ferror(in)) - error("unable to read from %s %m", infile[i]); - fclose(in); - fflush(out); - fclose(out); - } -} - -/* If snap_dir exists, log a message to snap_dir. The log file is called the - * equivalent of date +%Y%m%d | sed -e 's/://g'. Each line is prefixed with - * timestamp down to seconds and followed by a newline. - */ -void snap_shot_log(const char *fmt,...) -{ - char date[] = "ccyymmdd", file[] = "ccyymmdd.log", stamp[] = "ccyymmdd hhmmss"; - struct tm *local; - time_t t; - FILE *log; - va_list args; - int save_errno = errno; - - if (chdir(snap_dir)) - return; - t = time(NULL); - local = localtime(&t); - snprintf(date, sizeof(date), "%04d%02d%02d", - local->tm_year+1900, - local->tm_mon + 1, - local->tm_mday); - snprintf(file, sizeof(file), "%s.log", date); - log = fopen(file, "a"); - if (!log) { - error("cannot create %s/%s %m", snap_dir, file); - return; - } - snprintf(stamp, sizeof(stamp), "%s %02d%02d%02d", - date, - local->tm_hour, - local->tm_min, - local->tm_sec); - fprintf(log, "%s ", stamp); - va_start(args, fmt); - errno = save_errno; /* fmt may use %m */ - vfprintf(log, fmt, args); - va_end(args); - fprintf(log, "\n"); - fflush(log); - fclose(log); -} diff --git a/mdk-stage1/insmod-modutils/util/sys_cm.c b/mdk-stage1/insmod-modutils/util/sys_cm.c deleted file mode 100644 index d19a5ba4b..000000000 --- a/mdk-stage1/insmod-modutils/util/sys_cm.c +++ /dev/null @@ -1,86 +0,0 @@ -/* Functions for the Linux module syscall interface. - Copyright 1996, 1997 Linux International. - Contributed by Richard Henderson <rth@tamu.edu> - - This file is part of the Linux modutils. - - This program is free software; you can redistribute it and/or modify it - under the terms of the GNU General Public License as published by the - Free Software Foundation; either version 2 of the License, or (at your - option) any later version. - - This program is distributed in the hope that it will be useful, but - WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - General Public License for more details. - - You should have received a copy of the GNU General Public License - along with this program; if not, write to the Free Software Foundation, - Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ - -#include <stdlib.h> -#include <errno.h> - -#include "module.h" - -/* Kernel headers before 2.1.mumble need this on the Alpha to get - _syscall* defined. */ -#define __LIBRARY__ - -#include <asm/unistd.h> - - -/*======================================================================*/ - -#if defined(__i386__) || defined(__m68k__) || defined(__arm__) - -#define __NR__create_module __NR_create_module -static inline _syscall2(long, _create_module, const char *, name, size_t, size) - -unsigned long create_module(const char *name, size_t size) -{ - /* Why all this fuss? - - In linux 2.1, the address returned by create module point in - kernel space which is now mapped at the top of user space (at - 0xc0000000 on i386). This looks like a negative number for a - long. The normal syscall macro of linux 2.0 (and all libc compile - with linux 2.0 or below) consider that the return value is a - negative number and consider it is an error number (A kernel - convention, return value are positive or negative, indicating the - error number). - - By checking the value of errno, we know if we have been fooled by - the syscall2 macro and we fix it. */ - - long ret = _create_module(name, size); - if (ret == -1 && errno > 125) - { - ret = -errno; - errno = 0; - } - return ret; -} - -#elif defined(__alpha__) - -/* Alpha doesn't have the same problem, exactly, but a bug in older - kernels fails to clear the error flag. Clear it here explicitly. */ - -#define __NR__create_module __NR_create_module -static inline _syscall4(unsigned long, _create_module, const char *, name, - size_t, size, size_t, dummy, size_t, err); - -unsigned long create_module(const char *name, size_t size) -{ - return _create_module(name, size, 0, 0); -} - -#else - -/* Sparc, MIPS, (and Alpha, but that's another problem) don't mistake - return values for errors due to the nature of the system call. */ - -_syscall2(unsigned long, create_module, const char *, name, size_t, size) - -#endif diff --git a/mdk-stage1/insmod-modutils/util/sys_dm.c b/mdk-stage1/insmod-modutils/util/sys_dm.c deleted file mode 100644 index 611234efa..000000000 --- a/mdk-stage1/insmod-modutils/util/sys_dm.c +++ /dev/null @@ -1,35 +0,0 @@ -/* Functions for the Linux module syscall interface. - Copyright 1996, 1997 Linux International. - Contributed by Richard Henderson <rth@tamu.edu> - - This file is part of the Linux modutils. - - This program is free software; you can redistribute it and/or modify it - under the terms of the GNU General Public License as published by the - Free Software Foundation; either version 2 of the License, or (at your - option) any later version. - - This program is distributed in the hope that it will be useful, but - WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - General Public License for more details. - - You should have received a copy of the GNU General Public License - along with this program; if not, write to the Free Software Foundation, - Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ - -#include <stdlib.h> -#include <errno.h> - -#include "module.h" - -/* Kernel headers before 2.1.mumble need this on the Alpha to get - _syscall* defined. */ -#define __LIBRARY__ - -#include <asm/unistd.h> - - -/*======================================================================*/ - -_syscall1(int, delete_module, const char *, name) diff --git a/mdk-stage1/insmod-modutils/util/sys_gks.c b/mdk-stage1/insmod-modutils/util/sys_gks.c deleted file mode 100644 index b639fc990..000000000 --- a/mdk-stage1/insmod-modutils/util/sys_gks.c +++ /dev/null @@ -1,35 +0,0 @@ -/* Functions for the Linux module syscall interface. - Copyright 1996, 1997 Linux International. - Contributed by Richard Henderson <rth@tamu.edu> - - This file is part of the Linux modutils. - - This program is free software; you can redistribute it and/or modify it - under the terms of the GNU General Public License as published by the - Free Software Foundation; either version 2 of the License, or (at your - option) any later version. - - This program is distributed in the hope that it will be useful, but - WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - General Public License for more details. - - You should have received a copy of the GNU General Public License - along with this program; if not, write to the Free Software Foundation, - Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ - -#include <stdlib.h> -#include <errno.h> - -#include "module.h" - -/* Kernel headers before 2.1.mumble need this on the Alpha to get - _syscall* defined. */ -#define __LIBRARY__ - -#include <asm/unistd.h> - - -/*======================================================================*/ - -_syscall1(int, get_kernel_syms, struct old_kernel_sym *, ksyms) diff --git a/mdk-stage1/insmod-modutils/util/sys_nim.c b/mdk-stage1/insmod-modutils/util/sys_nim.c deleted file mode 100644 index c267ddf10..000000000 --- a/mdk-stage1/insmod-modutils/util/sys_nim.c +++ /dev/null @@ -1,51 +0,0 @@ -/* Functions for the Linux module syscall interface. - Copyright 1996, 1997 Linux International. - Contributed by Richard Henderson <rth@tamu.edu> - - This file is part of the Linux modutils. - - This program is free software; you can redistribute it and/or modify it - under the terms of the GNU General Public License as published by the - Free Software Foundation; either version 2 of the License, or (at your - option) any later version. - - This program is distributed in the hope that it will be useful, but - WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - General Public License for more details. - - You should have received a copy of the GNU General Public License - along with this program; if not, write to the Free Software Foundation, - Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ - -#include <stdlib.h> -#include <errno.h> - -#include "module.h" - -/* Kernel headers before 2.1.mumble need this on the Alpha to get - _syscall* defined. */ -#define __LIBRARY__ - -#include <asm/unistd.h> - - -/*======================================================================*/ - -#ifndef CONFIG_USE_SYSCALL - -extern int init_module(const char *name, const struct module *info); - -int -sys_init_module(const char *name, const struct module *info) -{ - return init_module(name, info); -} - -#else - -#define __NR_sys_init_module __NR_init_module -_syscall2(int, sys_init_module, const char *, name, - const struct module *, info) - -#endif diff --git a/mdk-stage1/insmod-modutils/util/sys_oim.c b/mdk-stage1/insmod-modutils/util/sys_oim.c deleted file mode 100644 index b915e36a5..000000000 --- a/mdk-stage1/insmod-modutils/util/sys_oim.c +++ /dev/null @@ -1,38 +0,0 @@ -/* Functions for the Linux module syscall interface. - Copyright 1996, 1997 Linux International. - Contributed by Richard Henderson <rth@tamu.edu> - - This file is part of the Linux modutils. - - This program is free software; you can redistribute it and/or modify it - under the terms of the GNU General Public License as published by the - Free Software Foundation; either version 2 of the License, or (at your - option) any later version. - - This program is distributed in the hope that it will be useful, but - WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - General Public License for more details. - - You should have received a copy of the GNU General Public License - along with this program; if not, write to the Free Software Foundation, - Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ - -#include <stdlib.h> -#include <errno.h> - -#include "module.h" - -/* Kernel headers before 2.1.mumble need this on the Alpha to get - _syscall* defined. */ -#define __LIBRARY__ - -#include <asm/unistd.h> - - -/*======================================================================*/ - -#define __NR_old_sys_init_module __NR_init_module -_syscall5(int, old_sys_init_module, const char *, name, char *, code, - unsigned, codesize, struct old_mod_routines *, routines, - struct old_symbol_table *, symtab) diff --git a/mdk-stage1/insmod-modutils/util/sys_qm.c b/mdk-stage1/insmod-modutils/util/sys_qm.c deleted file mode 100644 index ba478832b..000000000 --- a/mdk-stage1/insmod-modutils/util/sys_qm.c +++ /dev/null @@ -1,54 +0,0 @@ -/* Functions for the Linux module syscall interface. - Copyright 1996, 1997 Linux International. - Contributed by Richard Henderson <rth@tamu.edu> - - This file is part of the Linux modutils. - - This program is free software; you can redistribute it and/or modify it - under the terms of the GNU General Public License as published by the - Free Software Foundation; either version 2 of the License, or (at your - option) any later version. - - This program is distributed in the hope that it will be useful, but - WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - General Public License for more details. - - You should have received a copy of the GNU General Public License - along with this program; if not, write to the Free Software Foundation, - Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ - -#include <stdlib.h> -#include <errno.h> - -#include "module.h" - -/* Kernel headers before 2.1.mumble need this on the Alpha to get - _syscall* defined. */ -#define __LIBRARY__ - -#include <asm/unistd.h> - - -/*======================================================================*/ - -/* I am fucking tired of the "this doesn't build on 2.0.x" questions. - But if you ask, we still officially require 2.1.x to build. */ -#if !defined(__NR_query_module) -# if defined(__i386__) -# define __NR_query_module 167 -# elif defined(__alpha__) -# define __NR_query_module 347 -# elif defined(__sparc__) -# define __NR_query_module 184 -# elif defined(__mc68000__) -# define __NR_query_module 167 -# elif defined(__arm__) -# define __NR_query_module (__NR_SYSCALL_BASE + 167) -# elif defined(__mips__) -# define __NR_query_module 4187 -# endif -#endif - -_syscall5(int, query_module, const char *, name, int, which, - void *, buf, size_t, bufsize, size_t *, ret); diff --git a/mdk-stage1/insmod-modutils/util/xftw.c b/mdk-stage1/insmod-modutils/util/xftw.c deleted file mode 100644 index fe764a63c..000000000 --- a/mdk-stage1/insmod-modutils/util/xftw.c +++ /dev/null @@ -1,422 +0,0 @@ -/* - * modutils specific implementation of ftw(). - * - * Copyright 2000: - * Keith Owens <kaos@ocs.com.au> August 2000 - * - * This file is part of the Linux modutils. - * - * This program is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License as published by the - * Free Software Foundation; either version 2 of the License, or (at your - * option) any later version. - * - * This program is distributed in the hope that it will be useful, but - * WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software Foundation, - * Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. - */ - -/* - modutils requires special processing during the file tree walk - of /lib/modules/<version> and any paths that the user specifies. - The standard ftw() does a blind walk of all paths and can end - up following the build symlink down the kernel source tree. - Although nftw() has the option to get more control such as not - automatically following symbolic links, even that is not enough - for modutils. The requirements are: - - Paths must be directories or symlinks to directories. - - Each directory is read and sorted into alphabetical order - before processing. - - A directory is type 1 iff it was specified on a path statement - (either explicit or default) and the directory contains a - subdirectory with one of the known names and the directory name - does not end with "/kernel". Otherwise it is type 2. - - In a type 1 directory, walk the kernel subdirectory if it exists, - then the old known names in their historical order then any - remaining directory entries in alphabetical order and finally any - non-directory entries in alphabetical order. - - Entries in a type 1 directory are filtered against the "prune" - list. A type 1 directory can contain additional files which - are not modules nor symlinks to modules. The prune list skips - known additional files, if a distribution wants to store - additional text files in the top level directory they should be - added to the prune list. - - A type 2 directory must contain only modules or symlinks to - modules. They are processed in alphabetical order, without - pruning. Symlinks to directories are an error in type 2 - directories. - - The user function is not called for type 1 directories, nor for - pruned entries. It is called for type 2 directories and their - contents. It is also called for any files left in a type 1 - directory after pruning and processing type 2 subdirectories. - The user function never sees symlinks, they are resolved before - calling the function. - - Why have different directory types? The original file tree - walk was not well defined. Some users specified each directory - individually, others just pointed at the top level directory. - Either version worked until the "build" symlink was added. Now - users who specify the top level directory end up running the - entire kernel source tree looking for modules, not nice. We - cannot just ignore symlinks because pcmcia uses symlinks to - modules for backwards compatibility. - - Type 1 is when a user specifies the top level directory which needs - special processing, type 2 is individual subdirectories. But the - only way to tell the difference is by looking at the contents. The - "/kernel" directory introduced in 2.3.12 either contains nothing - (old make modules_install) or contains all the kernel modules using - the same tree structure as the source. Because "/kernel" can - contain old names but is really a type 2 directory, it is detected - as a special case. - */ - -#include <dirent.h> -#include <errno.h> -#include <limits.h> -#include <malloc.h> -#include <stdlib.h> -#include <string.h> -#include <sys/stat.h> - -#include "util.h" -#include "config.h" - -extern char *tbpath[]; - -extern OPT_LIST *prune_list; -extern int n_prune_list; - -extern char *tbtype[]; - -struct xftw_dirent { - struct stat statbuf; - char *name; - char *fullname; -}; - -#define XFTW_MAXDEPTH 64 /* Maximum directory depth handled */ - -typedef struct { - struct xftw_dirent *contents; - int size; - int used; -} xftw_tree_t; - -static xftw_tree_t tree[XFTW_MAXDEPTH]; - -/* Free all data for one tree level */ -static void xftw_free_tree(int depth) -{ - int i; - xftw_tree_t *t = tree+depth; - for (i = 0; i < t->size; ++i) { - free(t->contents[i].name); - free(t->contents[i].fullname); - } - free(t->contents); - t->contents = NULL; - t->size = 0; - t->used = 0; -} - -/* Increment dirents used at this depth, resizing if necessary */ -static void xftw_add_dirent(int depth) -{ - xftw_tree_t *t = tree+depth; - int i, size = t->size; - if (++t->used < size) - return; - size += 10; /* arbitrary increment */ - t->contents = xrealloc(t->contents, size*sizeof(*(t->contents))); - for (i = t->size; i < size; ++i) { - memset(&(t->contents[i].statbuf), 0, sizeof(t->contents[i].statbuf)); - t->contents[i].name = NULL; - t->contents[i].fullname = NULL; - } - t->size = size; -} - -/* Concatenate directory name and entry name into one string. - * Note: caller must free result or leak. - */ -static char *xftw_dir_name(const char *directory, const char *entry) -{ - int i = strlen(directory); - char *name; - if (entry) - i += strlen(entry); - i += 2; - name = xmalloc(i); - strcpy(name, directory); /* safe, xmalloc */ - if (*directory && entry) - strcat(name, "/"); /* safe, xmalloc */ - if (entry) - strcat(name, entry); /* safe, xmalloc */ - return(name); -} - -/* Call the user function for a directory entry */ -static int xftw_do_name(const char *directory, const char *entry, struct stat *sb, xftw_func_t funcptr) -{ - int ret = 0; - char *name = xftw_dir_name(directory, entry); - - if (S_ISLNK(sb->st_mode)) { - char real[PATH_MAX], *newname; - verbose("resolving %s symlink to ", name); - if (!(newname = realpath(name, real))) { - if (errno == ENOENT) { - verbose("%s: does not exist, dangling symlink ignored\n", real); - goto cleanup; - } - perror("... failed"); - goto cleanup; - } - verbose("%s ", newname); - if (lstat(newname, sb)) { - error("lstat on %s failed ", newname); - perror(""); - goto cleanup; - } - free(name); - name = xstrdup(newname); - } - - if (!S_ISREG(sb->st_mode) && - !S_ISDIR(sb->st_mode)) { - error("%s is not plain file nor directory\n", name); - goto cleanup; - } - - verbose("user function %s\n", name); - ret = (*funcptr)(name, sb); -cleanup: - free(name); - return(ret); -} - -/* Sort directory entries into alphabetical order */ -static int xftw_sortdir(const void *a, const void *b) -{ - return(strcmp(((struct xftw_dirent *)a)->name, ((struct xftw_dirent *)b)->name)); -} - -/* Read a directory and sort it, ignoring "." and ".." */ -static int xftw_readdir(const char *directory, int depth) -{ - DIR *d; - struct dirent *ent; - verbose("xftw_readdir %s\n", directory); - if (!(d = opendir(directory))) { - perror(directory); - return(1); - } - while ((ent = readdir(d))) { - char *name; - struct xftw_dirent *f; - if (strcmp(ent->d_name, ".") == 0 || - strcmp(ent->d_name, "..") == 0) - continue; - name = xftw_dir_name(directory, ent->d_name); - xftw_add_dirent(depth); - f = tree[depth].contents+tree[depth].used-1; - f->name = xstrdup(ent->d_name); - f->fullname = name; /* do not free name, it is in use */ - if (lstat(name, &(f->statbuf))) { - perror(name); - return(1); - } - } - closedir(d); - qsort(tree[depth].contents, tree[depth].used, sizeof(*(tree[0].contents)), &xftw_sortdir); - return(0); -} - -/* Process a type 2 directory */ -int xftw_type2(const char *directory, const char *entry, int depth, xftw_func_t funcptr) -{ - int ret, i; - xftw_tree_t *t = tree+depth; - struct stat statbuf; - char *dirname = xftw_dir_name(directory, entry); - - verbose("type 2 %s\n", dirname); - if (depth > XFTW_MAXDEPTH) { - error("xftw_type2 exceeded maxdepth\n"); - ret = 1; - goto cleanup; - } - if ((ret = xftw_readdir(dirname, depth))) - goto cleanup; - - t = tree+depth; - /* user function sees type 2 directories */ - if ((ret = lstat(dirname, &statbuf)) || - (ret = xftw_do_name("", dirname, &statbuf, funcptr))) - goto cleanup; - - /* user sees all contents of type 2 directory, no pruning */ - for (i = 0; i < t->used; ++i) { - struct xftw_dirent *c = t->contents+i; - if (S_ISLNK(c->statbuf.st_mode)) { - if (!stat(c->name, &(c->statbuf))) { - if (S_ISDIR(c->statbuf.st_mode)) { - error("symlink to directory is not allowed, %s ignored\n", c->name); - *(c->name) = '\0'; /* ignore it */ - } - } - } - if (!*(c->name)) - continue; - if (S_ISDIR(c->statbuf.st_mode)) { - /* recursion is the curse of the programming classes */ - ret = xftw_type2(dirname, c->name, depth+1, funcptr); - if (ret) - goto cleanup; - } - else if ((ret = xftw_do_name(dirname, c->name, &(c->statbuf), funcptr))) - goto cleanup; - *(c->name) = '\0'; /* processed */ - } - - ret = 0; -cleanup: - free(dirname); - return(ret); -} - -/* Only external visible function. Decide on the type of directory and - * process accordingly. - */ -int xftw(const char *directory, xftw_func_t funcptr) -{ - struct stat statbuf; - int ret, i, j, type; - xftw_tree_t *t; - struct xftw_dirent *c; - - verbose("xftw starting at %s ", directory); - if (lstat(directory, &statbuf)) { - verbose("lstat on %s failed\n", directory); - return(0); - } - if (S_ISLNK(statbuf.st_mode)) { - char real[PATH_MAX]; - verbose("resolving symlink to "); - if (!(directory = realpath(directory, real))) { - if (errno == ENOENT) { - verbose("%s: does not exist, dangling symlink ignored\n", real); - return(0); - } - perror("... failed"); - return(-1); - } - verbose("%s ", directory); - if (lstat(directory, &statbuf)) { - error("lstat on %s failed ", directory); - perror(""); - return(-1); - } - } - if (!S_ISDIR(statbuf.st_mode)) { - error("%s is not a directory\n", directory); - return(-1); - } - verbose("\n"); - - /* All returns after this point must be via cleanup */ - - if ((ret = xftw_readdir(directory, 0))) - goto cleanup; - - t = tree; /* depth 0 */ - type = 2; - for (i = 0 ; type == 2 && i < t->used; ++i) { - c = t->contents+i; - for (j = 0; tbtype[j]; ++j) { - if (strcmp(c->name, tbtype[j]) == 0 && - S_ISDIR(c->statbuf.st_mode)) { - const char *p = directory + strlen(directory) - 1; - if (*p == '/') - --p; - if (p - directory >= 6 && strncmp(p-6, "/kernel", 7) == 0) - continue; /* "/kernel" path is a special case, type 2 */ - type = 1; /* known subdirectory */ - break; - } - } - } - - if (type == 1) { - OPT_LIST *p; - /* prune entries in type 1 directories only */ - for (i = 0 ; i < t->used; ++i) { - for (p = prunelist; p->name; ++p) { - c = t->contents+i; - if (strcmp(p->name, c->name) == 0) { - verbose("pruned %s\n", c->name); - *(c->name) = '\0'; /* ignore */ - } - } - } - /* run known subdirectories first in historical order, "kernel" is now top of list */ - for (i = 0 ; i < t->used; ++i) { - c = t->contents+i; - for (j = 0; tbtype[j]; ++j) { - if (*(c->name) && - strcmp(c->name, tbtype[j]) == 0 && - S_ISDIR(c->statbuf.st_mode)) { - if ((ret = xftw_type2(directory, c->name, 1, funcptr))) - goto cleanup; - *(c->name) = '\0'; /* processed */ - } - } - } - /* any other directories left, in alphabetical order */ - for (i = 0 ; i < t->used; ++i) { - c = t->contents+i; - if (*(c->name) && - S_ISDIR(c->statbuf.st_mode)) { - if ((ret = xftw_type2(directory, c->name, 1, funcptr))) - goto cleanup; - *(c->name) = '\0'; /* processed */ - } - } - /* anything else is passed to the user function */ - for (i = 0 ; i < t->used; ++i) { - c = t->contents+i; - if (*(c->name)) { - verbose("%s found in type 1 directory %s\n", c->name, directory); - if ((ret = xftw_do_name(directory, c->name, &(c->statbuf), funcptr))) - goto cleanup; - *(c->name) = '\0'; /* processed */ - } - } - } - else { - /* type 2 */ - xftw_free_tree(0); - if ((ret = xftw_type2(directory, NULL, 0, funcptr))) - goto cleanup; - } - - /* amazing, it all worked */ - ret = 0; -cleanup: - for (i = 0; i < XFTW_MAXDEPTH; ++i) - xftw_free_tree(i); - return(ret); -} diff --git a/mdk-stage1/insmod-modutils/util/xmalloc.c b/mdk-stage1/insmod-modutils/util/xmalloc.c deleted file mode 100644 index da0be2953..000000000 --- a/mdk-stage1/insmod-modutils/util/xmalloc.c +++ /dev/null @@ -1,37 +0,0 @@ -/* Misc utility functions. - Copyright 1996, 1997 Linux International. - Contributed by Richard Henderson <rth@tamu.edu> - - This file is part of the Linux modutils. - - This program is free software; you can redistribute it and/or modify it - under the terms of the GNU General Public License as published by the - Free Software Foundation; either version 2 of the License, or (at your - option) any later version. - - This program is distributed in the hope that it will be useful, but - WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - General Public License for more details. - - You should have received a copy of the GNU General Public License - along with this program; if not, write to the Free Software Foundation, - Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ - -#include <stdlib.h> -#include "util.h" - - -/*======================================================================*/ - -void * -xmalloc(size_t size) -{ - void *ptr = malloc(size ? size : 1); - if (!ptr) - { - error("Out of memory"); - exit(1); - } - return ptr; -} diff --git a/mdk-stage1/insmod-modutils/util/xrealloc.c b/mdk-stage1/insmod-modutils/util/xrealloc.c deleted file mode 100644 index adc0558f1..000000000 --- a/mdk-stage1/insmod-modutils/util/xrealloc.c +++ /dev/null @@ -1,37 +0,0 @@ -/* Misc utility functions. - Copyright 1996, 1997 Linux International. - Contributed by Richard Henderson <rth@tamu.edu> - - This file is part of the Linux modutils. - - This program is free software; you can redistribute it and/or modify it - under the terms of the GNU General Public License as published by the - Free Software Foundation; either version 2 of the License, or (at your - option) any later version. - - This program is distributed in the hope that it will be useful, but - WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - General Public License for more details. - - You should have received a copy of the GNU General Public License - along with this program; if not, write to the Free Software Foundation, - Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ - -#include <stdlib.h> -#include "util.h" - - -/*======================================================================*/ - -void * -xrealloc(void *old, size_t size) -{ - void *ptr = realloc(old, size); - if (!ptr) - { - error("Out of memory"); - exit(1); - } - return ptr; -} diff --git a/mdk-stage1/insmod-modutils/util/xstrcat.c b/mdk-stage1/insmod-modutils/util/xstrcat.c deleted file mode 100644 index ed4a2bf20..000000000 --- a/mdk-stage1/insmod-modutils/util/xstrcat.c +++ /dev/null @@ -1,38 +0,0 @@ -/* Misc utility functions. - Copyright 2000 Keith Owens <kaos@ocs.com.au> - - This file is part of the Linux modutils. - - This program is free software; you can redistribute it and/or modify it - under the terms of the GNU General Public License as published by the - Free Software Foundation; either version 2 of the License, or (at your - option) any later version. - - This program is distributed in the hope that it will be useful, but - WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - General Public License for more details. - - You should have received a copy of the GNU General Public License - along with this program; if not, write to the Free Software Foundation, - Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ - -#include <stdlib.h> -#include <string.h> -#include "util.h" - - -/*======================================================================*/ - -char * -xstrcat(char *dest, const char *src, size_t size) -{ - int ldest = strlen(dest); - int lsrc = strlen(src); - if ((size - ldest - 1) < lsrc) { - error("xstrcat: destination overflow"); - exit(1); - } - memcpy(dest+ldest, src, lsrc+1); - return(dest); -} diff --git a/mdk-stage1/insmod-modutils/util/xstrdup.c b/mdk-stage1/insmod-modutils/util/xstrdup.c deleted file mode 100644 index 46889a094..000000000 --- a/mdk-stage1/insmod-modutils/util/xstrdup.c +++ /dev/null @@ -1,39 +0,0 @@ -/* Misc utility functions. - Copyright 1996, 1997 Linux International. - Contributed by Richard Henderson <rth@tamu.edu> - - This file is part of the Linux modutils. - - This program is free software; you can redistribute it and/or modify it - under the terms of the GNU General Public License as published by the - Free Software Foundation; either version 2 of the License, or (at your - option) any later version. - - This program is distributed in the hope that it will be useful, but - WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - General Public License for more details. - - You should have received a copy of the GNU General Public License - along with this program; if not, write to the Free Software Foundation, - Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ - -#include <stdio.h> -#include <stdlib.h> -#include <string.h> -#include "util.h" - - -/*======================================================================*/ - -char * -xstrdup(const char *s) -{ - char *n = strdup(s); - if (!n) - { - error("Out of memory"); - exit(1); - } - return n; -} diff --git a/mdk-stage1/insmod-modutils/util/xsystem.c b/mdk-stage1/insmod-modutils/util/xsystem.c deleted file mode 100644 index 8ffa490a9..000000000 --- a/mdk-stage1/insmod-modutils/util/xsystem.c +++ /dev/null @@ -1,49 +0,0 @@ -/* Misc utility functions. - Copyright 2000 Keith Owens <kaos@ocs.com.au> - - This file is part of the Linux modutils. - - This program is free software; you can redistribute it and/or modify it - under the terms of the GNU General Public License as published by the - Free Software Foundation; either version 2 of the License, or (at your - option) any later version. - - This program is distributed in the hope that it will be useful, but - WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - General Public License for more details. - - You should have received a copy of the GNU General Public License - along with this program; if not, write to the Free Software Foundation, - Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ - -#include <sys/types.h> -#include <sys/wait.h> -#include <errno.h> -#include <unistd.h> - - -/*======================================================================*/ - -/* Clone of the system() function From Steven's Advanced Programming in a Unix - * Environment. Modified to use *argv[] and execvp to avoid shell expansion - * problems, modutils runs as root so system() is unsafe. - */ - -int -xsystem(const char *file, char *const argv[]) -{ - pid_t pid; - int status; - if ((pid = fork()) < 0) - return(-1); - if (pid == 0) { - execvp(file, argv); - _exit(127); - } - while (waitpid(pid, &status, 0) < 0) { - if (errno != EINTR) - return(-1); - } - return(status); -} diff --git a/mdk-stage1/insmod.h b/mdk-stage1/insmod.h deleted file mode 100644 index 67a746858..000000000 --- a/mdk-stage1/insmod.h +++ /dev/null @@ -1,20 +0,0 @@ -/* - * Guillaume Cottenceau (gc@mandrakesoft.com) - * - * Copyright 2000 Mandrakesoft - * - * This software may be freely redistributed under the terms of the GNU - * public license. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. - * - */ - -#ifndef _INSMOD_INTERFACE_H_ -#define _INSMOD_INTERFACE_H_ - -int insmod_call(char * full_filename, char * params); - -#endif diff --git a/mdk-stage1/linux-2.2/nfs.h b/mdk-stage1/linux-2.2/nfs.h deleted file mode 100644 index 7936d5a71..000000000 --- a/mdk-stage1/linux-2.2/nfs.h +++ /dev/null @@ -1,226 +0,0 @@ -/* - * NFS protocol definitions - */ -#ifndef _LINUX_NFS_H -#define _LINUX_NFS_H - -#include <linux/sunrpc/msg_prot.h> - -#define NFS_PORT 2049 -#define NFS_MAXDATA 8192 -#define NFS_MAXPATHLEN 1024 -#define NFS_MAXNAMLEN 255 -#define NFS_MAXGROUPS 16 -#define NFS_FHSIZE 32 -#define NFS_COOKIESIZE 4 -#define NFS_FIFO_DEV (-1) -#define NFSMODE_FMT 0170000 -#define NFSMODE_DIR 0040000 -#define NFSMODE_CHR 0020000 -#define NFSMODE_BLK 0060000 -#define NFSMODE_REG 0100000 -#define NFSMODE_LNK 0120000 -#define NFSMODE_SOCK 0140000 -#define NFSMODE_FIFO 0010000 - - -enum nfs_stat { - NFS_OK = 0, - NFSERR_PERM = 1, - NFSERR_NOENT = 2, - NFSERR_IO = 5, - NFSERR_NXIO = 6, - NFSERR_EAGAIN = 11, - NFSERR_ACCES = 13, - NFSERR_EXIST = 17, - NFSERR_XDEV = 18, - NFSERR_NODEV = 19, - NFSERR_NOTDIR = 20, - NFSERR_ISDIR = 21, - NFSERR_INVAL = 22, /* that Sun forgot */ - NFSERR_FBIG = 27, - NFSERR_NOSPC = 28, - NFSERR_ROFS = 30, - NFSERR_OPNOTSUPP = 45, - NFSERR_NAMETOOLONG = 63, - NFSERR_NOTEMPTY = 66, - NFSERR_DQUOT = 69, - NFSERR_STALE = 70, - NFSERR_WFLUSH = 99 -}; - -enum nfs_ftype { - NFNON = 0, - NFREG = 1, - NFDIR = 2, - NFBLK = 3, - NFCHR = 4, - NFLNK = 5, - NFSOCK = 6, - NFBAD = 7, - NFFIFO = 8 -}; - -struct nfs_fh { - char data[NFS_FHSIZE]; -}; - -#define NFS_PROGRAM 100003 -#define NFS_VERSION 2 -#define NFSPROC_NULL 0 -#define NFSPROC_GETATTR 1 -#define NFSPROC_SETATTR 2 -#define NFSPROC_ROOT 3 -#define NFSPROC_LOOKUP 4 -#define NFSPROC_READLINK 5 -#define NFSPROC_READ 6 -#define NFSPROC_WRITECACHE 7 -#define NFSPROC_WRITE 8 -#define NFSPROC_CREATE 9 -#define NFSPROC_REMOVE 10 -#define NFSPROC_RENAME 11 -#define NFSPROC_LINK 12 -#define NFSPROC_SYMLINK 13 -#define NFSPROC_MKDIR 14 -#define NFSPROC_RMDIR 15 -#define NFSPROC_READDIR 16 -#define NFSPROC_STATFS 17 - -/* Mount support for NFSroot */ -#ifdef __KERNEL__ -#define NFS_MNT_PROGRAM 100005 -#define NFS_MNT_VERSION 1 -#define NFS_MNT_PORT 627 -#define NFS_MNTPROC_MNT 1 -#define NFS_MNTPROC_UMNT 3 -#endif - -#if defined(__KERNEL__) || defined(NFS_NEED_KERNEL_TYPES) - -extern struct rpc_program nfs_program; -extern struct rpc_stat nfs_rpcstat; - -struct nfs_time { - __u32 seconds; - __u32 useconds; -}; - -struct nfs_fattr { - enum nfs_ftype type; - __u32 mode; - __u32 nlink; - __u32 uid; - __u32 gid; - __u32 size; - __u32 blocksize; - __u32 rdev; - __u32 blocks; - __u32 fsid; - __u32 fileid; - struct nfs_time atime; - struct nfs_time mtime; - struct nfs_time ctime; -}; - -struct nfs_sattr { - __u32 mode; - __u32 uid; - __u32 gid; - __u32 size; - struct nfs_time atime; - struct nfs_time mtime; -}; - -struct nfs_fsinfo { - __u32 tsize; - __u32 bsize; - __u32 blocks; - __u32 bfree; - __u32 bavail; -}; - -struct nfs_writeargs { - struct nfs_fh * fh; - __u32 offset; - __u32 count; - const void * buffer; -}; - -#ifdef NFS_NEED_XDR_TYPES - -struct nfs_sattrargs { - struct nfs_fh * fh; - struct nfs_sattr * sattr; -}; - -struct nfs_diropargs { - struct nfs_fh * fh; - const char * name; -}; - -struct nfs_readargs { - struct nfs_fh * fh; - __u32 offset; - __u32 count; - void * buffer; -}; - -struct nfs_createargs { - struct nfs_fh * fh; - const char * name; - struct nfs_sattr * sattr; -}; - -struct nfs_renameargs { - struct nfs_fh * fromfh; - const char * fromname; - struct nfs_fh * tofh; - const char * toname; -}; - -struct nfs_linkargs { - struct nfs_fh * fromfh; - struct nfs_fh * tofh; - const char * toname; -}; - -struct nfs_symlinkargs { - struct nfs_fh * fromfh; - const char * fromname; - const char * topath; - struct nfs_sattr * sattr; -}; - -struct nfs_readdirargs { - struct nfs_fh * fh; - __u32 cookie; - void * buffer; - unsigned int bufsiz; -}; - -struct nfs_diropok { - struct nfs_fh * fh; - struct nfs_fattr * fattr; -}; - -struct nfs_readres { - struct nfs_fattr * fattr; - unsigned int count; -}; - -struct nfs_readlinkres { - char ** string; - unsigned int * lenp; - unsigned int maxlen; - void * buffer; -}; - -struct nfs_readdirres { - void * buffer; - unsigned int bufsiz; -}; - -#endif /* NFS_NEED_XDR_TYPES */ -#endif /* __KERNEL__ */ - -#endif diff --git a/mdk-stage1/linux-2.2/nfs_mount.h b/mdk-stage1/linux-2.2/nfs_mount.h deleted file mode 100644 index 60493b150..000000000 --- a/mdk-stage1/linux-2.2/nfs_mount.h +++ /dev/null @@ -1,53 +0,0 @@ -#ifndef _LINUX_NFS_MOUNT_H -#define _LINUX_NFS_MOUNT_H - -/* - * linux/include/linux/nfs_mount.h - * - * Copyright (C) 1992 Rick Sladkey - * - * structure passed from user-space to kernel-space during an nfs mount - */ - -/* - * WARNING! Do not delete or change the order of these fields. If - * a new field is required then add it to the end. The version field - * tracks which fields are present. This will ensure some measure of - * mount-to-kernel version compatibility. Some of these aren't used yet - * but here they are anyway. - */ -#define NFS_MOUNT_VERSION 3 - -struct nfs_mount_data { - int version; /* 1 */ - int fd; /* 1 */ - struct nfs_fh root; /* 1 */ - int flags; /* 1 */ - int rsize; /* 1 */ - int wsize; /* 1 */ - int timeo; /* 1 */ - int retrans; /* 1 */ - int acregmin; /* 1 */ - int acregmax; /* 1 */ - int acdirmin; /* 1 */ - int acdirmax; /* 1 */ - struct sockaddr_in addr; /* 1 */ - char hostname[256]; /* 1 */ - int namlen; /* 2 */ - unsigned int bsize; /* 3 */ -}; - -/* bits in the flags field */ - -#define NFS_MOUNT_SOFT 0x0001 /* 1 */ -#define NFS_MOUNT_INTR 0x0002 /* 1 */ -#define NFS_MOUNT_SECURE 0x0004 /* 1 */ -#define NFS_MOUNT_POSIX 0x0008 /* 1 */ -#define NFS_MOUNT_NOCTO 0x0010 /* 1 */ -#define NFS_MOUNT_NOAC 0x0020 /* 1 */ -#define NFS_MOUNT_TCP 0x0040 /* 2 */ -#define NFS_MOUNT_VER3 0x0080 /* 3 */ -#define NFS_MOUNT_KERBEROS 0x0100 /* 3 */ -#define NFS_MOUNT_NONLM 0x0200 /* 3 */ - -#endif diff --git a/mdk-stage1/log.c b/mdk-stage1/log.c index c108a8f50..a8406f6b2 100644 --- a/mdk-stage1/log.c +++ b/mdk-stage1/log.c @@ -77,7 +77,7 @@ void open_log(void) { if (!IS_TESTING) { logtty = fopen("/dev/tty3", "w"); - logfile = fopen(SLASH_LOCATION "/tmp/stage1.log", "w"); + logfile = fopen("/tmp/stage1.log", "w"); } else logfile = fopen("debug.log", "w"); diff --git a/mdk-stage1/lomount.c b/mdk-stage1/lomount.c index e1142e4dd..2f80ec71c 100644 --- a/mdk-stage1/lomount.c +++ b/mdk-stage1/lomount.c @@ -60,7 +60,7 @@ struct loop_info #define LOOP_GET_STATUS 0x4C03 int -set_loop (const char *device, const char *file, int gz) +set_loop (const char *device, const char *file) { struct loop_info loopinfo; int fd, ffd, mode; @@ -79,12 +79,6 @@ set_loop (const char *device, const char *file, int gz) strncpy(loopinfo.lo_name, file, LO_NAME_SIZE); loopinfo.lo_name[LO_NAME_SIZE - 1] = 0; loopinfo.lo_offset = 0; - if (gz) { - my_insmod("cryptoloop", ANY_DRIVER_TYPE, NULL, 1); - my_insmod("zlib_inflate", ANY_DRIVER_TYPE, NULL, 1); - my_insmod("gzloop", ANY_DRIVER_TYPE, NULL, 1); - loopinfo.lo_encrypt_type = 13; /* LO_CRYPT_GZ */ - } #ifdef MCL_FUTURE /* @@ -162,7 +156,7 @@ del_loop(char * loopdev) } int -lomount(char *loopfile, char *where, char **dev, int gz) +lomount(char *loopfile, char *where, char **dev, int compressed) { long int flag; @@ -172,6 +166,9 @@ lomount(char *loopfile, char *where, char **dev, int gz) flag |= MS_RDONLY; my_insmod("loop", ANY_DRIVER_TYPE, "max_loop=256", 1); + if (compressed) { + my_insmod("squashfs", ANY_DRIVER_TYPE, NULL, 1); + } if (!(loopdev = find_free_loop())) { log_message("could not find a free loop"); @@ -180,12 +177,12 @@ lomount(char *loopfile, char *where, char **dev, int gz) if (dev) *dev = loopdev; - if (set_loop(loopdev, loopfile, gz)) { + if (set_loop(loopdev, loopfile)) { log_message("set_loop failed on %s (%s)", loopdev, strerror(errno)); return 1; } - if (my_mount(loopdev, where, "iso9660", 0)) { + if (my_mount(loopdev, where, compressed ? "squashfs" : "iso9660", 0)) { del_loop(loopdev); return 1; } diff --git a/mdk-stage1/lomount.h b/mdk-stage1/lomount.h index 05ddd520b..4115507f2 100644 --- a/mdk-stage1/lomount.h +++ b/mdk-stage1/lomount.h @@ -15,7 +15,7 @@ #ifndef LOMOUNT_H #define LOMOUNT_H -int lomount(char *loopfile, char *where, char **loopdev, int gz); +int lomount(char *loopfile, char *where, char **loopdev, int compressed); void del_loop(char *loopdev); #endif diff --git a/mdk-stage1/mar/.cvsignore b/mdk-stage1/mar/.cvsignore deleted file mode 100644 index bfde37886..000000000 --- a/mdk-stage1/mar/.cvsignore +++ /dev/null @@ -1 +0,0 @@ -mar diff --git a/mdk-stage1/mar/Makefile b/mdk-stage1/mar/Makefile deleted file mode 100644 index 4271bb954..000000000 --- a/mdk-stage1/mar/Makefile +++ /dev/null @@ -1,49 +0,0 @@ - #****************************************************************************** - # - # mar - The Mandrake Archiver - # - # $Id$ - # - # Guillaume Cottenceau (gc@mandrakesoft.com) - # - # Copyright 2000 Mandrakesoft - # - # This software may be freely redistributed under the terms of the GNU - # public license. - # - # You should have received a copy of the GNU General Public License - # along with this program; if not, write to the Free Software - # Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. - # - #***************************************************************************** - -top_dir = .. - -include $(top_dir)/Makefile.common - - -TARGETS = libmar.a mar - - -all: $(TARGETS) - -clean: - rm -f *.o libmar.a mar - - -mar: mar-frontend.o mar-extract-only-standalone.o - gcc -o mar mar-frontend.o mar-extract-only-standalone.o -lbz2 - $(STRIPCMD) $@ - -libmar.a: mar-extract-only.o - ar -cru $@ $^ - ranlib $@ - -mar-extract-only.o: mar-extract-only.c mar-extract-only.h mar.h - $(DIET) gcc $(CFLAGS) $(INCLUDES) -c mar-extract-only.c - -mar-frontend.o: mar-frontend.c mar.h mar-extract-only.h - gcc $(CFLAGS) $(GLIBC_INCLUDES) -c mar-frontend.c - -mar-extract-only-standalone.o: mar-extract-only.c mar-extract-only.h mar.h - gcc $(CFLAGS) $(GLIBC_INCLUDES) -o $@ -D_STANDALONE_ -c mar-extract-only.c diff --git a/mdk-stage1/mar/mar-extract-only.c b/mdk-stage1/mar/mar-extract-only.c deleted file mode 100644 index dbc9c1bbc..000000000 --- a/mdk-stage1/mar/mar-extract-only.c +++ /dev/null @@ -1,214 +0,0 @@ -/* - * Guillaume Cottenceau (gc@mandrakesoft.com) - * - * Copyright 2000 Mandrakesoft - * - * This software may be freely redistributed under the terms of the GNU - * public license. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. - * - */ - -/* - * mar - The Mandrake Archiver - * - * An archiver that supports compression (through zlib). - * - */ - -/* - * This code should suffice for stage1 on-the-fly uncompression of kernel modules. - * (and it DOES perform tests and return values, blaaaah..) - */ - -#include "mar-extract-only.h" -#include "mar.h" - -#ifdef _STANDALONE_ -void -zerr(BZFILE * f) /* decrease code size */ -{ - fprintf(stderr, BZ2_bzerror(f, &z_errnum)); -} - -inline void -log_perror(char *msg) -{ - perror(msg); -} -void -log_message(char *msg) -{ - fprintf(stderr, msg); -} -#else /* _STANDALONE_ */ -#include "../log.h" -void -zerr(BZFILE * f) /* decrease code size */ -{ - log_message(BZ2_bzerror(f, &z_errnum)); -} -#endif /* _STANDALONE_ */ - - -static int -mar_open_file(char *filename, struct mar_stream *s) -{ - int end_filetable = 0; - struct mar_element * previous_element = NULL; - - /* mar_zfile */ - s->mar_zfile = BZ2_bzopen(filename, "rb"); - if (!s->mar_zfile) - { - log_perror(filename); - return -1; - } - - while (end_filetable == 0) - { - char buf[512]; - int ptr = 0; - /* read filename */ - do - { - if (BZ2_bzread(s->mar_zfile, &(buf[ptr]), sizeof(char)) != sizeof(char)) - { - zerr(s->mar_zfile); - return -1; - } - ptr++; - } while ((buf[ptr-1] != 0) && (ptr < 512)); - /* ptr == 1 when we arrive on the "char 0" of the end of the filetable */ - if (ptr > 1) - { - struct mar_element * e = (struct mar_element *) malloc(sizeof(struct mar_element)); - e->filename = strdup(buf); - /* read file_length */ - if (BZ2_bzread(s->mar_zfile, &(e->file_length), sizeof(int)) != sizeof(int)) - { - zerr(s->mar_zfile); - return -1; - } - /* read data_offset */ - if (BZ2_bzread(s->mar_zfile, &(e->data_offset), sizeof(int)) != sizeof(int)) - { - zerr(s->mar_zfile); - return -1; - } - /* write down chaining */ - if (previous_element) - previous_element->next_element = e; - else - s->first_element = e; - previous_element = e; - } - else - end_filetable = 1; - - } - /* chaining for last element */ - previous_element->next_element = NULL; - - return 0; -} - - -char ** -mar_list_contents(char * mar_filename) -{ - struct mar_stream s; - struct mar_element * elem; - char * tmp_contents[500]; - char ** answ; - int i = 0; - - if (mar_open_file(mar_filename, &s)) - return NULL; - - elem = s.first_element; - while (elem) - { - tmp_contents[i++] = strdup(elem->filename); - elem = elem->next_element; - } - tmp_contents[i++] = NULL; - answ = (char **) malloc(sizeof(char *) * i); - memcpy(answ, tmp_contents, sizeof(char *) * i); - return answ; -} - - -int -mar_extract_file(char *mar_filename, char *filename_to_extract, char *dest_dir) -{ - struct mar_stream s; - struct mar_element * elem; - - if (mar_open_file(mar_filename, &s)) - return -1; - - elem = s.first_element; - while (elem) - { - if (strcmp(elem->filename, filename_to_extract) == 0) - { - char garb_buf[4096]; - char *buf; - char *dest_file; - int fd; - size_t i; - dest_file = (char *) alloca(strlen(dest_dir) + strlen(filename_to_extract) + 1); - strcpy(dest_file, dest_dir); - strcat(dest_file, filename_to_extract); - fd = creat(dest_file, 00660); - if (fd == -1) - { - log_perror(dest_file); - return -1; - } - buf = (char *) alloca(elem->file_length); - if (!buf) - { - log_perror(dest_file); - return -1; - } - i = elem->data_offset; - while (i > 0) { - int to_read = i > sizeof(garb_buf) ? sizeof(garb_buf) : i; - if (BZ2_bzread(s.mar_zfile, garb_buf, to_read) != to_read) { - log_message("MAR: unexpected EOF in stream"); - close(fd); - unlink(dest_file); - return -1; - } - i -= to_read; - } - if (BZ2_bzread(s.mar_zfile, buf, elem->file_length) != elem->file_length) - { - zerr(s.mar_zfile); - close(fd); - unlink(dest_file); - return -1; - } - if (write(fd, buf, elem->file_length) != elem->file_length) - { - log_perror(dest_file); - close(fd); - unlink(dest_file); - return -1; - } - close(fd); /* do not check return value for code size */ - BZ2_bzclose(s.mar_zfile); - return 0; - } - elem = elem->next_element; - } - BZ2_bzclose(s.mar_zfile); - return 1; /* 1 for file_not_found_in_archive */ -} - - diff --git a/mdk-stage1/mar/mar-extract-only.h b/mdk-stage1/mar/mar-extract-only.h deleted file mode 100644 index 715d75556..000000000 --- a/mdk-stage1/mar/mar-extract-only.h +++ /dev/null @@ -1,32 +0,0 @@ -/* - * Guillaume Cottenceau (gc@mandrakesoft.com) - * - * Copyright 2000 Mandrakesoft - * - * This software may be freely redistributed under the terms of the GNU - * public license. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. - * - */ - -/* - * mar - The Mandrake Archiver - * - * An archiver that supports compression (through zlib). - * - */ - -/* - * Header for stage1 on-the-fly needs. - */ - -#ifndef MAR_EXTRACT_ONLY_H -#define MAR_EXTRACT_ONLY_H - -int mar_extract_file(char *mar_filename, char *filename_to_extract, char *dest_dir); -char ** mar_list_contents(char *mar_filename); - -#endif diff --git a/mdk-stage1/mar/mar-frontend.c b/mdk-stage1/mar/mar-frontend.c deleted file mode 100644 index cfffc34ae..000000000 --- a/mdk-stage1/mar/mar-frontend.c +++ /dev/null @@ -1,199 +0,0 @@ -/* - * Guillaume Cottenceau (gc@mandrakesoft.com) - * - * Copyright 2000 Mandrakesoft - * - * This software may be freely redistributed under the terms of the GNU - * public license. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. - * - */ - -/* - * mar - The Mandrake Archiver - * - * An archiver that supports compression (through zlib). - * - */ - -/* - * This code includes the extracting and creating features. - * - */ - -#include "mar.h" -#include "mar-extract-only.h" - - -int -file_size(char *filename) -{ - struct stat buf; - if (stat(filename, &buf) != 0) - { - perror(filename); - return -1; - } - return buf.st_size; -} - - -/* Yes I don't use the datastructure I directly write the final fileformat in memory then write down it. - * Yes it's bad. - */ -/* ``files'' is a NULL-terminated array of char* */ - -char * fnf_tag = "FILE_NOT_FOUND&"; - -int -mar_create_file(char *dest_file, char **files) -{ - int filenum = 0; - int current_offset_filetable = 0; - int current_delta_rawdata = 0; - int filetable_size; - char * temp_marfile_buffer; - int total_length = 0; - - filetable_size = sizeof(char); /* ``char 0'' */ - while (files[filenum]) - { - int fsiz = file_size(files[filenum]); - if (fsiz == -1) - files[filenum] = fnf_tag; - else { - filetable_size += 2*sizeof(int) /* file_length, data_offset */ + strlen(files[filenum]) + 1; - total_length += fsiz; - } - filenum++; - } - - total_length += filetable_size; - - temp_marfile_buffer = (char *) malloc(total_length); /* create the whole file in-memory (not with alloca! it can be bigger than typical limit for stack of programs (ulimit -s) */ - DEBUG_MAR(printf("D: mar::create_marfile total-length %d\n", total_length);); - - filenum = 0; - while (files[filenum]) - { - if (strcmp(files[filenum], fnf_tag)) { - FILE * f = fopen(files[filenum], "r"); - int fsize; - if (!f) - { - perror(files[filenum]); - return -1; - } - - /* filename */ - strcpy(&(temp_marfile_buffer[current_offset_filetable]), files[filenum]); - current_offset_filetable += strlen(files[filenum]) + 1; - - /* file_length */ - fsize = file_size(files[filenum]); - if (fsize == -1) return -1; - memcpy(&temp_marfile_buffer[current_offset_filetable], &fsize, sizeof(int)); - current_offset_filetable += sizeof(int); - - /* data_offset */ - memcpy(&temp_marfile_buffer[current_offset_filetable], ¤t_delta_rawdata, sizeof(int)); - current_offset_filetable += sizeof(int); - - /* data_raw_data */ - if (fread(&temp_marfile_buffer[current_delta_rawdata + filetable_size], 1, fsize, f) != (size_t)fsize) - { - perror(files[filenum]); - return -1; - } - fclose(f); - - current_delta_rawdata += fsize; - } - - filenum++; - } - - /* write down ``char 0'' to terminate file table */ - memset(&temp_marfile_buffer[current_offset_filetable], 0, sizeof(char)); - - /* ok, buffer is ready, let's write it on-disk */ - { - BZFILE * f = BZ2_bzopen(dest_file, "w9"); - if (!f) - { - perror(dest_file); - return -1; - } - if (BZ2_bzwrite(f, temp_marfile_buffer, total_length) != total_length) - { - fprintf(stderr, BZ2_bzerror(f, &z_errnum)); - return -1; - } - BZ2_bzclose(f); - } - - printf("mar: created archive %s (%d files, length %d)\n", dest_file, filenum, total_length); - return 0; -} - - -void -print_usage(char *progname) -{ - printf("Usage: %s [-lxc] [files..]\n", progname); - exit(0); -} - -int -main(int argc, char **argv) -{ - if (argc <= 2) - print_usage(argv[0]); - - if (argc >= 3) - { - if (strcmp(argv[1], "-l") == 0) - { - char ** contents = mar_list_contents(argv[2]); - if (contents) - while (contents && *contents) { - printf("\t%s\n", *contents); - contents++; - } - exit(0); - } - if ((strcmp(argv[1], "-x") == 0) && argc == 4) - { - int res = mar_extract_file(argv[2], argv[3], "./"); - if (res == 1) - fprintf(stderr, "W: file-not-found-in-archive %s\n", argv[3]); - if (res == -1) - exit(-1); - exit(0); - } - if ((strcmp(argv[1], "-c") == 0) && argc >= 4) - { - char **files = (char **) alloca(((argc-3)+1) * sizeof(char *)); - int i = 3; - while (i < argc) - { - files[i-3] = argv[i]; - i++; - } - files[argc-3] = NULL; - { - int results; - results = mar_create_file(argv[2], files); - if (results != 0) - fprintf(stderr, "E: create-marfile-failed\n"); - exit(results); - } - - } - } - - return 0; -} diff --git a/mdk-stage1/mar/mar.h b/mdk-stage1/mar/mar.h deleted file mode 100644 index 61b50ca90..000000000 --- a/mdk-stage1/mar/mar.h +++ /dev/null @@ -1,70 +0,0 @@ -/* - * Guillaume Cottenceau (gc@mandrakesoft.com) - * - * Copyright 2000 Mandrakesoft - * - * This software may be freely redistributed under the terms of the GNU - * public license. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. - * - */ - -/* - * mar - The Mandrake Archiver - * - * An archiver that supports compression (through bzlib). - * - * Designed to be small so these bad designs are inside: - * . archive and compression are mixed together - * . create the mar file in-memory - * . does not free memory - * - */ - -#ifndef MAR_H -#define MAR_H - -#include <stdio.h> -#include <stdlib.h> -#include <string.h> -#include <sys/types.h> -#include <sys/stat.h> -#include <fcntl.h> -#include <errno.h> -#include <unistd.h> - -#include <bzlib.h> - -/* - * Format of a mar file: - * - * ASCIIZ filename \ | - * int file_length | repeated | bzipped - * int pointer_in_archive / | - * char 0 | - * raw_files_data / - * - */ - -struct mar_element -{ - char * filename; /* filename (ASCIIZ) of the element */ - int file_length; /* length (in bytes) of the raw data of the element */ - int data_offset; /* seek start of the raw data in the underlying mar stream */ - struct mar_element * next_element; /* pointer to the next element in the mar stream; NULL if last */ -}; - -struct mar_stream -{ - struct mar_element * first_element; /* pointer to the first element inside the mar stream */ - BZFILE * mar_zfile; /* associated zfile (opened) */ -}; - -int z_errnum; - -#define DEBUG_MAR(x) - -#endif diff --git a/mdk-stage1/mkinitrd_helper/Makefile b/mdk-stage1/mkinitrd_helper/Makefile deleted file mode 100644 index 269fd3ddc..000000000 --- a/mdk-stage1/mkinitrd_helper/Makefile +++ /dev/null @@ -1,46 +0,0 @@ - #****************************************************************************** - # - # Guillaume Cottenceau (gc@mandrakesoft.com) - # - # Copyright 2000 Mandrakesoft - # - # This software may be freely redistributed under the terms of the GNU - # public license. - # - # You should have received a copy of the GNU General Public License - # along with this program; if not, write to the Free Software - # Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. - # - #***************************************************************************** - -top_dir = .. - -include $(top_dir)/Makefile.common - - -VERSION = 1.1.1 - -DEFS = -DVERSION=\"$(VERSION)\" - - -MKINITRD_HELPER_SRC = mkinitrd_helper.c -MKINITRD_HELPER_LIBS = ../insmod-busybox/libinsmod-DIET.a - -MKINITRD_HELPER_OBJS = $(subst .c,.o,$(MKINITRD_HELPER_SRC)) - -BIN = mkinitrd_helper - -all: $(BIN) - -clean: - rm -f *.o $(BIN) - -FLAGS = -Wall -Werror -Os -fomit-frame-pointer -c - - -$(MKINITRD_HELPER_OBJS): %.o: %.c - $(CC) $(DEFS) $(DIETLIBC_INCLUDES) -I.. -c $< -o $@ - -mkinitrd_helper: $(MKINITRD_HELPER_OBJS) $(MKINITRD_HELPER_LIBS) $(DIETLIBC_LIBC) - $(CC) $(DIETLIBC_LDFLAGS_STAGE1) -o $@ $^ - $(STRIPCMD) $@ diff --git a/mdk-stage1/mkinitrd_helper/mkinitrd_helper.c b/mdk-stage1/mkinitrd_helper/mkinitrd_helper.c deleted file mode 100644 index 3e47bca2d..000000000 --- a/mdk-stage1/mkinitrd_helper/mkinitrd_helper.c +++ /dev/null @@ -1,308 +0,0 @@ -/* - * Guillaume Cottenceau (gc@mandrakesoft.com) - * - * Copyright 2001 Mandrakesoft - * - * This software is covered by the GPL license. - * - * This software may be freely redistributed under the terms of the GNU - * public license. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. - * - * - * This little program replaces usual sash and insmod.static based script - * from mkinitrd (that insmod modules, plus possibly mount a partition and - * losetup a loopback-based / on the partition). - * - * - * On my machine: - * gzipped sash + insmod.static 502491 bytes - * gzipped <this-program> 14243 bytes - * - * There will be room for linux-2.4 and many modules, now. Cool. - * - */ - -#include <stdlib.h> -#include <stdio.h> -#include <string.h> -#include <errno.h> -#include <sys/mount.h> -#include <sys/types.h> -#include <sys/stat.h> -#include <fcntl.h> -#include <unistd.h> -#include <sys/ioctl.h> -#include <signal.h> - -#include "insmod.h" - -int quiet = 0; - -void vlog_message(const char * s, va_list args) -{ - vprintf(s, args); - printf("\n"); -} - -void log_perror(char *msg) -{ - perror(msg); -} - - -static void fatal_error(char *msg) -{ - printf("[] E: %s\n[] giving hand to kernel.\n", msg); - exit(-1); -} - -static void warning(char *msg) -{ - printf("[] W: %s\n", msg); -} - -static void parse_parms(const char * parm, char ** parm1, char ** parm2, char ** parm3) -{ - char * ptr; - - ptr = strchr(parm, '\n'); - if (!ptr) - fatal_error("bad config file: no newline after parms"); - - *parm1 = malloc(ptr-parm+1); /* yup, never freed :-) */ - memcpy(*parm1, parm, ptr-parm); - (*parm1)[ptr-parm] = '\0'; - - if (!parm2) - return; - - *parm2 = strchr(*parm1, ' '); - if (!*parm2) - return; - **parm2 = '\0'; - (*parm2)++; - - if (!parm3) - return; - - *parm3 = strchr(*parm2, ' '); - if (!*parm3) - return; - **parm3 = '\0'; - (*parm3)++; -} - - -static void insmod_(const char * parm) -{ - char * mod_name, * options; - - parse_parms(parm, &mod_name, &options, NULL); - -#ifdef DEBUG - printf("insmod %s options %s\n", mod_name, options); -#endif - if (!quiet) - printf("[] Loading module %s\n", mod_name); - - if (insmod_call(mod_name, options)) - perror("insmod failed"); -} - - -static void mount_(const char * parm) -{ - char * dev, * location, * fs; - unsigned long flags; - char * opts = NULL; - - parse_parms(parm, &dev, &location, &fs); - -#ifdef DEBUG - printf("mounting %s on %s as type %s\n", dev, location, fs); -#endif - if (!quiet) - printf("[] Mounting device containing loopback root filesystem\n"); - - flags = MS_MGC_VAL; - - if (!strcmp(fs, "vfat")) - opts = "check=relaxed"; - - if (mount(dev, location, fs, flags, opts)) - perror("mount failed"); -} - - -#define LO_NAME_SIZE 64 -#define LO_KEY_SIZE 32 - -struct loop_info -{ - int lo_number; /* ioctl r/o */ - dev_t lo_device; /* ioctl r/o */ - unsigned long lo_inode; /* ioctl r/o */ - dev_t lo_rdevice; /* ioctl r/o */ - int lo_offset; - int lo_encrypt_type; - int lo_encrypt_key_size; /* ioctl w/o */ - int lo_flags; /* ioctl r/o */ - char lo_name[LO_NAME_SIZE]; - unsigned char lo_encrypt_key[LO_KEY_SIZE]; /* ioctl w/o */ - unsigned long lo_init[2]; - char reserved[4]; -}; - -#define LOOP_SET_FD 0x4C00 -#define LOOP_CLR_FD 0x4C01 -#define LOOP_SET_STATUS 0x4C02 - -static void set_loop_(const char * parm) -{ - struct loop_info loopinfo; - int fd, ffd; - char * device, * file; - - parse_parms(parm, &device, &file, NULL); - -#ifdef DEBUG - printf("set_looping %s with %s\n", device, file); -#endif - if (!quiet) - printf("[] Setting up loopback file %s\n", file); - - if ((ffd = open(file, O_RDWR)) < 0) { - perror("set_loop, opening file in rw"); - exit(-1); - } - - if ((fd = open(device, O_RDWR)) < 0) { - perror("set_loop, opening loop device in rw"); - close(ffd); - exit(-1); - } - - memset(&loopinfo, 0, sizeof (loopinfo)); - strncpy(loopinfo.lo_name, file, LO_NAME_SIZE); - loopinfo.lo_name[LO_NAME_SIZE - 1] = 0; - loopinfo.lo_offset = 0; - - if (ioctl(fd, LOOP_SET_FD, ffd) < 0) { - close(fd); - close(ffd); - perror("LOOP_SET_FD"); - exit(-1); - } - - if (ioctl(fd, LOOP_SET_STATUS, &loopinfo) < 0) { - (void) ioctl (fd, LOOP_CLR_FD, 0); - close(fd); - close(ffd); - perror("LOOP_SET_STATUS"); - exit(-1); - } - - close(fd); - close(ffd); -} - - -#define MD_MAJOR 9 -#define RAID_AUTORUN _IO (MD_MAJOR, 0x14) -#include <linux/raid/md_u.h> - -static void raidautorun_(const char * parm) -{ - char * device; - int fd; - - parse_parms(parm, &device, NULL, NULL); - - if (!quiet) - printf("[] Calling raid autorun for %s\n", device); - - fd = open(device, O_RDWR, 0); - if (fd < 0) { - printf("raidautorun: failed to open %s: %d\n", device, errno); - return; - } - - if (ioctl(fd, RAID_AUTORUN, 0)) { - printf("raidautorun: RAID_AUTORUN failed: %d\n", errno); - } - - close(fd); -} - -static int handle_command(char ** ptr, char * cmd_name, void (*cmd_func)(const char * parm)) -{ - if (!strncmp(*ptr, cmd_name, strlen(cmd_name))) { - *ptr = strchr(*ptr, '\n'); - if (!*ptr) - fatal_error("Bad config file: no newline after command"); - (*ptr)++; - cmd_func(*ptr); - *ptr = strchr(*ptr, '\n'); - if (!*ptr) - exit(0); - (*ptr)++; - return 1; - } - return 0; -} - - -int main(int argc, char **argv) -{ - int fd_conf, i; - char buf[5000]; - char * ptr; - - if (strstr(argv[0], "modprobe")) - exit(0); - - if (mount("/proc", "/loopfs", "proc", 0, NULL)) - printf("[] couldn't mount proc filesystem\n"); - else { - int fd_cmdline = open("/loopfs/cmdline", O_RDONLY); - if (fd_cmdline > 0) { - i = read(fd_cmdline, buf, sizeof(buf)); - if (i == -1) - warning("could not read cmdline"); - else { - buf[i] = '\0'; - if (strstr(buf, "quiet")) - quiet = 1; - } - close(fd_cmdline); - } - umount("/loopfs"); - } - - if (!quiet) - printf("[] initrd_helper v" VERSION "\n"); - - if ((fd_conf = open("/mkinitrd_helper.conf", O_RDONLY)) < 0) - fatal_error("could not open mkinitrd_helper config file"); - - i = read(fd_conf, buf, sizeof(buf)); - if (i == -1) - fatal_error("could not read mkinitrd_helper config file"); - buf[i] = '\0'; - close(fd_conf); - - ptr = buf; - - while (*ptr) - if (!(handle_command(&ptr, "insmod", insmod_) + - handle_command(&ptr, "mount", mount_) + - handle_command(&ptr, "raidautorun", raidautorun_) + - handle_command(&ptr, "set_loop", set_loop_))) - warning("unkown command (trying to continue)"); - - return 0; -} diff --git a/mdk-stage1/modules.c b/mdk-stage1/modules.c index 11e118030..43120bc4f 100644 --- a/mdk-stage1/modules.c +++ b/mdk-stage1/modules.c @@ -27,22 +27,17 @@ #include <string.h> #include <stdio.h> #include <errno.h> -#include "insmod.h" #include "stage1.h" #include "log.h" -#include "mar/mar-extract-only.h" #include "frontend.h" #include "mount.h" #include "modules_descr.h" +#include "zlibsupport.h" #include "modules.h" static struct module_deps_elem * modules_deps = NULL; -static char archive_name[] = "/modules/modules.mar"; -static char additional_archive_name[] = "/tmp/tmpfs/modules.mar"; -int allow_additional_modules_floppy = 1; - extern long init_module(void *, unsigned long, const char *); @@ -62,161 +57,30 @@ static const char *moderror(int err) } } -static void *grab_file(const char *filename, unsigned long *size) -{ - unsigned int max = 16384; - int ret, fd; - void *buffer = malloc(max); - - fd = open(filename, O_RDONLY, 0); - if (fd < 0) - return NULL; - - *size = 0; - while ((ret = read(fd, buffer + *size, max - *size)) > 0) { - *size += ret; - if (*size == max) - buffer = realloc(buffer, max *= 2); - } - if (ret < 0) { - free(buffer); - buffer = NULL; - } - close(fd); - return buffer; -} - -static enum return_type ensure_additional_modules_available(void) -{ -#ifdef ENABLE_ADDITIONAL_MODULES - struct stat statbuf; - if (stat(additional_archive_name, &statbuf)) { - char floppy_mount_location[] = "/tmp/floppy"; - char floppy_modules_mar[] = "/tmp/floppy/modules.mar"; - int ret; - int automatic = 0; - - if (stat("/tmp/tmpfs", &statbuf)) { - if (scall(mkdir("/tmp/tmpfs", 0755), "mkdir")) - return RETURN_ERROR; - if (scall(mount("none", "/tmp/tmpfs", "tmpfs", MS_MGC_VAL, NULL), "mount tmpfs")) - return RETURN_ERROR; - } - - if (IS_AUTOMATIC) { - unset_automatic(); - automatic = 1; - } - - retry: - stg1_info_message("Please insert the Additional Drivers floppy.");; - - while (my_mount(floppy_device(), floppy_mount_location, "ext2", 0) == -1) { - enum return_type results = ask_yes_no(errno == ENXIO ? - "There is no detected floppy drive, or no floppy disk in drive.\nRetry?" - : errno == EINVAL ? - "Floppy is not a Linux ext2 floppy in first floppy drive.\nRetry?" - : "Can't find a linux ext2 floppy in first floppy drive.\nRetry?"); - if (results != RETURN_OK) { - allow_additional_modules_floppy = 0; - if (automatic) - set_param(MODE_AUTOMATIC); - return results; - } - } - - if (stat(floppy_modules_mar, &statbuf)) { - stg1_error_message("This is not an Additional Drivers floppy, as far as I can see."); - umount(floppy_mount_location); - goto retry; - } - - init_progression("Copying...", file_size(floppy_modules_mar)); - ret = copy_file(floppy_modules_mar, additional_archive_name, update_progression); - end_progression(); - umount(floppy_mount_location); - if (automatic) - set_param(MODE_AUTOMATIC); - return ret; - } else - return RETURN_OK; -#else - allow_additional_modules_floppy = 0; - return RETURN_ERROR; -#endif -} - int insmod_local_file(char * path, char * options) { - if (kernel_version() <= 4) { - return insmod_call(path, options); - } else { - void *file; - unsigned long len; - int rc; + void *file; + unsigned long len; + int rc; - file = grab_file(path, &len); + file = grab_file(path, &len); - if (!file) { - log_perror(asprintf_("\terror reading %s", path)); - return -1; - } + if (!file) { + log_perror(asprintf_("\terror reading %s", path)); + return -1; + } - rc = init_module(file, len, options ? options : ""); - if (rc) - log_message("\terror: %s", moderror(errno)); - return rc; - } + rc = init_module(file, len, options ? options : ""); + if (rc) + log_message("\terror: %s", moderror(errno)); + return rc; } static char *kernel_module_extension(void) { - return kernel_version() <= 4 ? ".o" : ".ko"; -} - -/* unarchive and insmod given module - * WARNING: module must not contain the trailing ".o" - */ -static enum insmod_return insmod_archived_file(const char * mod_name, char * options, int allow_modules_floppy) -{ - char module_name[50]; - char final_name[50] = "/tmp/"; - int i, rc; - - strncpy(module_name, mod_name, sizeof(module_name)); - strcat(module_name, kernel_module_extension()); - i = mar_extract_file(archive_name, module_name, "/tmp/"); - if (i == 1) { - static int recurse = 0; - if (allow_additional_modules_floppy && allow_modules_floppy && !recurse) { - recurse = 1; - if (ensure_additional_modules_available() == RETURN_OK) - i = mar_extract_file(additional_archive_name, module_name, "/tmp/"); - recurse = 0; - } - } - if (i == 1) { - log_message("file-not-found-in-archive %s (maybe you can try another boot floppy such as 'hdcdrom_usb.img')", module_name); - return INSMOD_FAILED_FILE_NOT_FOUND; - } - if (i != 0) - return INSMOD_FAILED; - - strcat(final_name, module_name); - - rc = insmod_local_file(final_name, options); - - unlink(final_name); /* sucking no space left on device */ - - if (rc) { - log_message("\tfailed"); - return INSMOD_FAILED; - } - return INSMOD_OK; + return ".ko.gz"; } - - static int load_modules_dependencies(void) { char * deps_file = "/modules/modules.dep"; @@ -380,10 +244,7 @@ static enum insmod_return insmod_with_deps(const char * mod_name, char * options log_message("needs %s", mod_name); { char *file = asprintf_("/modules/%s%s", mod_name, kernel_module_extension()); - if (access(file, R_OK) == 0) - return insmod_local_file(file, options); - else - return insmod_archived_file(mod_name, options, allow_modules_floppy); + return insmod_local_file(file, options); } } @@ -409,11 +270,10 @@ static const char * get_name_kernel_26_transition(const char * name) int i; /* pcitable contains 2.4 names. this will need to change if/when it contains 2.6 names! */ - if (kernel_version() > 4) - for (i=0; i<mappings_nb; i++) { - if (streq(name, mappings[i].name_24)) - return mappings[i].name_26; - } + for (i=0; i<mappings_nb; i++) { + if (streq(name, mappings[i].name_24)) + return mappings[i].name_26; + } return name; } @@ -528,8 +388,7 @@ enum return_type ask_insmod(enum driver_type type) snprintf(msg, sizeof(msg), "Which driver should I try to gain %s access?", mytype); { - char ** modules = mar_list_contents(ensure_additional_modules_available() == RETURN_OK ? additional_archive_name - : archive_name); + char ** modules = NULL; char ** descrs = malloc(sizeof(char *) * string_array_length(modules)); char ** p_modules = modules; char ** p_descrs = descrs; @@ -538,7 +397,7 @@ enum return_type ask_insmod(enum driver_type type) *p_descrs = NULL; for (i = 0 ; i < modules_descriptions_num ; i++) { if (!strncmp(*p_modules, modules_descriptions[i].module, strlen(modules_descriptions[i].module)) - && (*p_modules)[strlen(modules_descriptions[i].module)] == '.') /* one contains '.o' not the other */ + && (*p_modules)[strlen(modules_descriptions[i].module)] == '.') /* one contains '.ko.gz' not the other */ *p_descrs = modules_descriptions[i].descr; } p_modules++; @@ -551,7 +410,7 @@ enum return_type ask_insmod(enum driver_type type) } if (results == RETURN_OK) { - choice[strlen(choice)-strlen(kernel_module_extension())] = '\0'; /* remove trailing .ko or .o */ + choice[strlen(choice)-strlen(kernel_module_extension())] = '\0'; /* remove trailing .ko.gz */ return insmod_with_options(choice, type); } else return results; diff --git a/mdk-stage1/modules.h b/mdk-stage1/modules.h index d42d55218..1d48f71e3 100644 --- a/mdk-stage1/modules.h +++ b/mdk-stage1/modules.h @@ -32,6 +32,5 @@ struct module_deps_elem { }; extern int disable_modules; -extern int allow_additional_modules_floppy; #endif diff --git a/mdk-stage1/network.c b/mdk-stage1/network.c index b8dbb64c3..f02903c55 100644 --- a/mdk-stage1/network.c +++ b/mdk-stage1/network.c @@ -318,6 +318,12 @@ static int save_netinfo(struct interface_info * intf) fprintf(f, "NETMASK=%s\n", inet_ntoa(intf->netmask)); fprintf(f, "NETWORK=%s\n", inet_ntoa(intf->network)); fprintf(f, "BROADCAST=%s\n", inet_ntoa(intf->broadcast)); + if (domain) + fprintf(f, "DOMAIN=%s\n", domain); + if (dns_server.s_addr != 0) + fprintf(f, "DNS1=%s\n", inet_ntoa(dns_server)); + if (dns_server2.s_addr != 0) + fprintf(f, "DNS2=%s\n", inet_ntoa(dns_server2)); } else if (intf->boot_proto == BOOTPROTO_ADSL_PPPOE) { fprintf(f, "BOOTPROTO=adsl_pppoe\n"); fprintf(f, "USER=%s\n", intf->user); @@ -602,7 +608,7 @@ static enum return_type bringup_networking(struct interface_info * intf) } -static char * auto_select_up_intf(void) +static char * auto_select_up_intf(int detection_mode) { #define SIOCETHTOOL 0x8946 #define ETHTOOL_GLINK 0x0000000a /* Get link status (ethtool_value) */ @@ -623,19 +629,36 @@ static char * auto_select_up_intf(void) ptr = interfaces; while (ptr && *ptr) { - struct ifreq ifr; - struct ethtool_value edata; - strncpy(ifr.ifr_name, *ptr, IFNAMSIZ); - edata.cmd = ETHTOOL_GLINK; - ifr.ifr_data = (caddr_t)&edata; - if (ioctl(s, SIOCETHTOOL, &ifr) == 0 && edata.data) { - close(s); - log_message("NETWORK: choosing interface %s (link beat detected)", *ptr); - return *ptr; + if (detection_mode != AUTO_DETECTION_WIRED || !wireless_is_aware(s, *interfaces)) { + struct ifreq ifr; + struct ethtool_value edata; + strncpy(ifr.ifr_name, *ptr, IFNAMSIZ); + edata.cmd = ETHTOOL_GLINK; + ifr.ifr_data = (caddr_t)&edata; + if (ioctl(s, SIOCETHTOOL, &ifr) == 0 && edata.data) { + close(s); + log_message("NETWORK: choosing interface %s (link beat detected)", *ptr); + return *ptr; + } } ptr++; } + log_message("NETWORK: no interface has a link beat"); + + if (detection_mode == AUTO_DETECTION_WIRED) { + ptr = interfaces; + while (ptr && *ptr) { + if (!wireless_is_aware(s, *interfaces)) { + close(s); + log_message("NETWORK: choosing interface %s (wired interface)", *ptr); + return *ptr; + } + ptr++; + } + log_message("NETWORK: no interface is wired"); + } + close(s); return NULL; @@ -670,11 +693,18 @@ static char * interface_select(void) if (count == 1) return *interfaces; - /* this can't be done in ask_from_list_comments_auto because "auto" isn't in the interfaces list */ - if (IS_AUTOMATIC && streq(get_auto_value("interface"), "auto")) { - choice = auto_select_up_intf(); - if (choice) - return choice; + /* this can't be done in ask_from_list_comments_auto because "auto" and "wired" are not in the interfaces list */ + if (IS_AUTOMATIC) { + enum auto_detection_type auto_detect = AUTO_DETECTION_NONE; + if (streq(get_auto_value("interface"), "auto")) + auto_detect = AUTO_DETECTION_ALL; + else if (streq(get_auto_value("interface"), "wired")) + auto_detect = AUTO_DETECTION_WIRED; + if (auto_detect != AUTO_DETECTION_NONE) { + choice = auto_select_up_intf(auto_detect); + if (choice) + return choice; + } } i = 0; @@ -692,7 +722,6 @@ static char * interface_select(void) return choice; } -#ifndef MANDRAKE_MOVE static enum return_type get_http_proxy(char **http_proxy_host, char **http_proxy_port) { char *questions[] = { "HTTP proxy host", "HTTP proxy port", NULL }; @@ -887,7 +916,6 @@ static int choose_mirror_from_list(char *http_proxy_host, char *http_proxy_port, return results; } -#endif /* -=-=-- */ @@ -931,7 +959,6 @@ enum return_type nfs_prepare(void) char * questions[] = { "NFS server name", DISTRIB_NAME " directory", NULL }; char * questions_auto[] = { "server", "directory", NULL }; static char ** answers = NULL; - char * nfs_own_mount = IMAGE_LOCATION_DIR "nfsimage"; char * nfsmount_location; enum return_type results = intf_select_and_up(NULL, NULL); @@ -952,16 +979,16 @@ enum return_type nfs_prepare(void) strcat(nfsmount_location, ":"); strcat(nfsmount_location, answers[1]); - if (my_mount(nfsmount_location, nfs_own_mount, "nfs", 0) == -1) { + if (my_mount(nfsmount_location, MEDIA_LOCATION, "nfs", 0) == -1) { stg1_error_message("I can't mount the directory from the NFS server."); results = RETURN_BACK; continue; } free(nfsmount_location); nfsmount_location = NULL; - results = try_with_directory(nfs_own_mount, "nfs", "nfs-iso"); + results = try_with_directory(MEDIA_LOCATION, "nfs", "nfs-iso"); if (results != RETURN_OK) - umount(nfs_own_mount); + umount(MEDIA_LOCATION); if (results == RETURN_ERROR) return RETURN_ERROR; } @@ -971,7 +998,6 @@ enum return_type nfs_prepare(void) } -#ifndef MANDRAKE_MOVE enum return_type ftp_prepare(void) { char * questions[] = { "FTP server", DISTRIB_NAME " directory", "Login", "Password", NULL }; @@ -1038,8 +1064,6 @@ enum return_type ftp_prepare(void) if (use_http_proxy) { log_message("FTP: don't connect to %s directly, will use proxy", answers[0]); } else { - char *kernels_list_file, *kernels_list; - log_message("FTP: trying to connect to %s", answers[0]); ftp_serv_response = ftp_open_connection(answers[0], answers[2], answers[3], ""); if (ftp_serv_response < 0) { @@ -1053,32 +1077,9 @@ enum return_type ftp_prepare(void) results = RETURN_BACK; continue; } - kernels_list_file = asprintf_("%s/" CLP_LOCATION_REL "mdkinst.kernels", location_full); - - log_message("FTP: trying to retrieve %s", kernels_list_file); - fd = ftp_start_download(ftp_serv_response, kernels_list_file, &size); - - if (fd < 0) { - char *msg = str_ftp_error(fd); - log_message("FTP: error get %d for remote file %s", fd, kernels_list_file); - stg1_error_message("Error: %s.", msg ? msg : "couldn't retrieve list of kernel versions"); - results = RETURN_BACK; - continue; - } - - kernels_list = alloca(size); - size = read(fd, kernels_list, size); - close(fd); - ftp_end_data_command(ftp_serv_response); - - if (!strstr(kernels_list, asprintf_("%s\n", kernel_uname.release))) { - stg1_info_message("The modules for this kernel (%s) can't be found on this mirror, please update your boot disk", kernel_uname.release); - results = RETURN_BACK; - continue; - } } - strcat(location_full, CLP_FILE_REL("/")); + strcat(location_full, COMPRESSED_FILE_REL("/")); log_message("FTP: trying to retrieve %s", location_full); @@ -1107,7 +1108,7 @@ enum return_type ftp_prepare(void) log_message("FTP: size of download %d bytes", size); - results = load_clp_fd(fd, size); + results = load_compressed_fd(fd, size); if (results == RETURN_OK) { if (!use_http_proxy) ftp_end_data_command(ftp_serv_response); @@ -1183,7 +1184,7 @@ enum return_type http_prepare(void) strcpy(location_full, answers[1][0] == '/' ? "" : "/"); strcat(location_full, answers[1]); - strcat(location_full, CLP_FILE_REL("/")); + strcat(location_full, COMPRESSED_FILE_REL("/")); log_message("HTTP: trying to retrieve %s from %s", location_full, answers[0]); @@ -1202,7 +1203,7 @@ enum return_type http_prepare(void) log_message("HTTP: size of download %d bytes", size); - if (load_clp_fd(fd, size) != RETURN_OK) { + if (load_compressed_fd(fd, size) != RETURN_OK) { unset_automatic(); /* we are in a fallback mode */ return RETURN_ERROR; } @@ -1240,5 +1241,3 @@ enum return_type ka_prepare(void) return perform_ka(); } #endif - -#endif diff --git a/mdk-stage1/network.h b/mdk-stage1/network.h index e4612e259..3d2d94871 100644 --- a/mdk-stage1/network.h +++ b/mdk-stage1/network.h @@ -29,16 +29,15 @@ enum return_type intf_select_and_up(); enum return_type nfs_prepare(void); -#ifndef MANDRAKE_MOVE enum return_type ftp_prepare(void); enum return_type http_prepare(void); #ifndef DISABLE_KA enum return_type ka_prepare(void); #endif -#endif enum boot_proto_type { BOOTPROTO_STATIC, BOOTPROTO_DHCP, BOOTPROTO_ADSL_PPPOE }; +enum auto_detection_type { AUTO_DETECTION_NONE, AUTO_DETECTION_ALL, AUTO_DETECTION_WIRED }; /* all of these in_addr things are in network byte order! */ struct interface_info { diff --git a/mdk-stage1/newt/newt.c b/mdk-stage1/newt/newt.c index a41b7900b..8ff5e39a5 100644 --- a/mdk-stage1/newt/newt.c +++ b/mdk-stage1/newt/newt.c @@ -191,7 +191,7 @@ int newtInit(void) { char * MonoValue, * MonoEnv = "NEWT_MONO"; /* use the version variable just to be sure it gets included */ - strlen(version); + (void) strlen(version); SLtt_get_terminfo(); SLtt_get_screen_size(); diff --git a/mdk-stage1/nfsmount.c b/mdk-stage1/nfsmount.c index 55a0b0b1e..ce329d43c 100644 --- a/mdk-stage1/nfsmount.c +++ b/mdk-stage1/nfsmount.c @@ -39,7 +39,7 @@ * Wed Oct 1 23:55:28 1997: Dick Streefland <dick_streefland@tasking.com> * Implemented the "bg", "fg" and "retry" mount options for NFS. * - * 1999-02-22 Arkadiusz Mi¶kiewicz <misiek@pld.ORG.PL> + * 1999-02-22 Arkadiusz MiÅ›kiewicz <misiek@pld.ORG.PL> * - added Native Language Support * * Modified by Olaf Kirch and Trond Myklebust for new NFS code, diff --git a/mdk-stage1/partition.c b/mdk-stage1/partition.c index 8fd581017..d41fa7ebf 100644 --- a/mdk-stage1/partition.c +++ b/mdk-stage1/partition.c @@ -34,7 +34,6 @@ #include "probing.h" #include "log.h" #include "mount.h" -#include "lomount.h" #include "automatic.h" #include "disk.h" diff --git a/mdk-stage1/pci-resource/.cvsignore b/mdk-stage1/pci-resource/.cvsignore deleted file mode 100644 index 4c7b0844b..000000000 --- a/mdk-stage1/pci-resource/.cvsignore +++ /dev/null @@ -1 +0,0 @@ -pci-ids.h diff --git a/mdk-stage1/pci-resource/update-pci-ids.pl b/mdk-stage1/pci-resource/update-pci-ids.pl index 021757fc4..82eb060bf 100755 --- a/mdk-stage1/pci-resource/update-pci-ids.pl +++ b/mdk-stage1/pci-resource/update-pci-ids.pl @@ -33,7 +33,8 @@ my %t = ( ); foreach my $type (keys %t) { - my @modules = chomp_(`perl ../../kernel/modules.pl pci_modules4stage1 "$t{$type}"`); + my @modules = chomp_(`perl ../../kernel/modules.pl pci_modules4stage1 "$t{$type}"`) + or die "unable to get PCI modules"; my (@entries, @entries_full); diff --git a/mdk-stage1/Makefile.mkinitrd_helper b/mdk-stage1/pcmcia-resource/Makefile index a8db2fbe0..46dda9be1 100644 --- a/mdk-stage1/Makefile.mkinitrd_helper +++ b/mdk-stage1/pcmcia-resource/Makefile @@ -1,8 +1,8 @@ #****************************************************************************** # - # Guillaume Cottenceau (gc@mandrakesoft.com) + # Olivier Blin (blino@mandriva.com) # - # Copyright 2000 Mandrakesoft + # Copyright 2006 Mandriva # # This software may be freely redistributed under the terms of the GNU # public license. @@ -13,18 +13,12 @@ # #***************************************************************************** +TARGET=pcmcia-ids.h -DIRS = dietlibc insmod-busybox +all: $(TARGET) +$(TARGET): + perl update-pcmcia-ids.pl > $@ || { rm -f $@; exit 1; } -all: dirs - -dirs: - @for n in . $(DIRS); do \ - [ "$$n" = "." ] || make -C $$n ;\ - done - -clean: - @for n in $(DIRS); do \ - (cd $$n; make clean) \ - done +clean: + rm -f $(TARGET) diff --git a/mdk-stage1/pcmcia-resource/update-pcmcia-ids.pl b/mdk-stage1/pcmcia-resource/update-pcmcia-ids.pl new file mode 100755 index 000000000..2dd7728b6 --- /dev/null +++ b/mdk-stage1/pcmcia-resource/update-pcmcia-ids.pl @@ -0,0 +1,41 @@ +#!/usr/bin/perl + +use strict; +use MDK::Common; + +my @aliases; +my ($main) = `ls -t /lib/modules/*/modules.alias`; +foreach (cat_(chomp_($main))) { + push @aliases, [ $1, $2 ] if /^alias\s+(pcmcia:\S+)\s+(\S+)$/; #- modalias, module +} +@aliases or die "unable to get PCMCIA aliases"; + +print ' +struct pcmcia_alias { + const char *modalias; + const char *module; +}; + +'; + +my %t = ( + network => 'network/pcmcia', + medias => 'disk/pcmcia', +); + +foreach my $type (keys %t) { + my @modules = chomp_(`perl ../../kernel/modules.pl pci_modules4stage1 "$t{$type}"`) + or die "unable to get PCMCIA modules"; + + print "#ifndef DISABLE_".uc($type)." +struct pcmcia_alias ${type}_pcmcia_ids[] = { +"; + print qq|\t{ "$_->[0]", "$_->[1]" },\n| foreach grep { member($_->[1], @modules) } @aliases; + print "}; +unsigned int ${type}_pcmcia_num_ids = sizeof(${type}_pcmcia_ids) / sizeof(struct pcmcia_alias); + +#endif + +"; + +} diff --git a/mdk-stage1/pcmcia/Makefile b/mdk-stage1/pcmcia/Makefile new file mode 100644 index 000000000..9e111f115 --- /dev/null +++ b/mdk-stage1/pcmcia/Makefile @@ -0,0 +1,52 @@ + #****************************************************************************** + # + # Guillaume Cottenceau (gc@mandrakesoft.com) + # + # Copyright 2001 Mandrakesoft + # + # This software may be freely redistributed under the terms of the GNU + # public license. + # + # You should have received a copy of the GNU General Public License + # along with this program; if not, write to the Free Software + # Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. + # + #***************************************************************************** + +# startup.c is based on pcmcia-socket-startup from pcmciautils-013 + +top_dir = .. + +include $(top_dir)/Makefile.common + +TARGET = libpcmcia.a +YFLAGS := -d + +all: $(TARGET) pcmcia_probe.o + +clean: + rm -f *.o $(TARGET) lex_config.c yacc_config.c yacc_config.h + +FLAGS = -D__linux__ -Wall -Werror -Wno-deprecated-declarations -Os -fomit-frame-pointer -pipe -c -I.. -D_BSD_SOURCE +# (blino) make sure yynewerror and yyerrlab are uselessly used +FLAGS += -Dlint +LFLAGS += --nounput + + +OBJS = probe.o startup.o yacc_config.o lex_config.o + + +%.c %.h : %.y + $(YACC) $(YFLAGS) $< + mv y.tab.c $*.c + mv y.tab.h $*.h + +$(TARGET): $(OBJS) yacc_config.h + ar -cru $@ $^ + ranlib $@ + +$(OBJS): %.o: %.c + $(DIET) gcc $(FLAGS) $(INCLUDES) -c $< -o $@ + +pcmcia_probe.o: probe.c + $(DIET) gcc -fPIC $(FLAGS) $(INCLUDES) -c $< -o $@ diff --git a/mdk-stage1/pcmcia_/bulkmem.h b/mdk-stage1/pcmcia/bulkmem.h index 7748d4432..7748d4432 100644 --- a/mdk-stage1/pcmcia_/bulkmem.h +++ b/mdk-stage1/pcmcia/bulkmem.h diff --git a/mdk-stage1/pcmcia_/cirrus.h b/mdk-stage1/pcmcia/cirrus.h index 78f73b26d..78f73b26d 100644 --- a/mdk-stage1/pcmcia_/cirrus.h +++ b/mdk-stage1/pcmcia/cirrus.h diff --git a/mdk-stage1/pcmcia_/cistpl.h b/mdk-stage1/pcmcia/cistpl.h index 1d4cac20e..1d4cac20e 100644 --- a/mdk-stage1/pcmcia_/cistpl.h +++ b/mdk-stage1/pcmcia/cistpl.h diff --git a/mdk-stage1/pcmcia_/cs.h b/mdk-stage1/pcmcia/cs.h index 9abeac216..9abeac216 100644 --- a/mdk-stage1/pcmcia_/cs.h +++ b/mdk-stage1/pcmcia/cs.h diff --git a/mdk-stage1/pcmcia_/cs_types.h b/mdk-stage1/pcmcia/cs_types.h index 4598d7f48..4598d7f48 100644 --- a/mdk-stage1/pcmcia_/cs_types.h +++ b/mdk-stage1/pcmcia/cs_types.h diff --git a/mdk-stage1/pcmcia_/driver_ops.h b/mdk-stage1/pcmcia/driver_ops.h index 2f0a066d3..2f0a066d3 100644 --- a/mdk-stage1/pcmcia_/driver_ops.h +++ b/mdk-stage1/pcmcia/driver_ops.h diff --git a/mdk-stage1/pcmcia_/ds.h b/mdk-stage1/pcmcia/ds.h index 29db7b415..29db7b415 100644 --- a/mdk-stage1/pcmcia_/ds.h +++ b/mdk-stage1/pcmcia/ds.h diff --git a/mdk-stage1/pcmcia_/i82365.h b/mdk-stage1/pcmcia/i82365.h index 38ff167fb..38ff167fb 100644 --- a/mdk-stage1/pcmcia_/i82365.h +++ b/mdk-stage1/pcmcia/i82365.h diff --git a/mdk-stage1/pcmcia_/merge_from_pcitable b/mdk-stage1/pcmcia/merge_from_pcitable index 3b88a1cd8..3b88a1cd8 100755 --- a/mdk-stage1/pcmcia_/merge_from_pcitable +++ b/mdk-stage1/pcmcia/merge_from_pcitable diff --git a/mdk-stage1/pcmcia_/pcmcia.h b/mdk-stage1/pcmcia/pcmcia.h index 3559d5fd6..ea0bccc2a 100644 --- a/mdk-stage1/pcmcia_/pcmcia.h +++ b/mdk-stage1/pcmcia/pcmcia.h @@ -16,6 +16,6 @@ #define _PCMCIA_CARDMGR_INTERFACE_H_ char * pcmcia_probe(void); -int cardmgr_call(void); +void pcmcia_socket_startup(int socket_no); #endif diff --git a/mdk-stage1/pcmcia_/probe.c b/mdk-stage1/pcmcia/probe.c index 8f8a4bc8e..8f8a4bc8e 100644 --- a/mdk-stage1/pcmcia_/probe.c +++ b/mdk-stage1/pcmcia/probe.c diff --git a/mdk-stage1/pcmcia_/tcic.h b/mdk-stage1/pcmcia/tcic.h index cad193885..cad193885 100644 --- a/mdk-stage1/pcmcia_/tcic.h +++ b/mdk-stage1/pcmcia/tcic.h diff --git a/mdk-stage1/pcmcia_/version.h b/mdk-stage1/pcmcia/version.h index 3be8f28bc..3be8f28bc 100644 --- a/mdk-stage1/pcmcia_/version.h +++ b/mdk-stage1/pcmcia/version.h diff --git a/mdk-stage1/pcmcia_/vg468.h b/mdk-stage1/pcmcia/vg468.h index 23890cd07..23890cd07 100644 --- a/mdk-stage1/pcmcia_/vg468.h +++ b/mdk-stage1/pcmcia/vg468.h diff --git a/mdk-stage1/pcmcia_/cardmgr.c b/mdk-stage1/pcmcia_/cardmgr.c deleted file mode 100644 index f67b02f72..000000000 --- a/mdk-stage1/pcmcia_/cardmgr.c +++ /dev/null @@ -1,1652 +0,0 @@ -/* - * Guillaume Cottenceau (gc@mandrakesoft.com) - * - * Copyright 2000 Mandrakesoft - * - * This software may be freely redistributed under the terms of the GNU - * public license. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. - * - * - * Code comes from /anonymous@projects.sourceforge.net:/pub/pcmcia-cs/pcmcia-cs-3.1.29.tar.bz2 - * - * Licence of this code follows: - * - */ -/*====================================================================== - - PCMCIA Card Manager daemon - - cardmgr.c 1.161 2001/08/24 12:19:19 - - The contents of this file are subject to the Mozilla Public - License Version 1.1 (the "License"); you may not use this file - except in compliance with the License. You may obtain a copy of - the License at http://www.mozilla.org/MPL/ - - Software distributed under the License is distributed on an "AS - IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or - implied. See the License for the specific language governing - rights and limitations under the License. - - The initial developer of the original code is David A. Hinds - <dahinds@users.sourceforge.net>. Portions created by David A. Hinds - are Copyright (C) 1999 David A. Hinds. All Rights Reserved. - - Alternatively, the contents of this file may be used under the - terms of the GNU General Public License version 2 (the "GPL"), in - which case the provisions of the GPL are applicable instead of the - above. If you wish to allow the use of your version of this file - only under the terms of the GPL and not to allow others to use - your version of this file under the MPL, indicate your decision - by deleting the provisions above and replace them with the notice - and other provisions required by the GPL. If you do not delete - the provisions above, a recipient may use your version of this - file under either the MPL or the GPL. - -======================================================================*/ - -#ifndef __linux__ -#include <pcmcia/u_compat.h> -#endif - -#include <sys/types.h> -#include <stdio.h> -#include <stdlib.h> -#include <string.h> -#include <unistd.h> -#include <fcntl.h> -#include <errno.h> -//mdk-stage1// #include <syslog.h> -//mdk-stage1// #include <getopt.h> -#include <signal.h> -#include <sys/time.h> -#include <sys/ioctl.h> -#include <sys/wait.h> -#include <sys/stat.h> -#include <sys/utsname.h> -#include <sys/file.h> - -#include <pcmcia_/version.h> -//mdk-stage1// #include <pcmcia/config.h> -#include <pcmcia_/cs_types.h> -#include <pcmcia_/cs.h> -#include <pcmcia_/cistpl.h> -#include <pcmcia_/ds.h> - -#include "cardmgr.h" - -#include "../log.h" -#include "modules.h" -#include "pcmcia.h" - -/*====================================================================*/ - -typedef struct socket_info_t { - int fd; - int state; - card_info_t *card; - bind_info_t *bind[MAX_BINDINGS]; - mtd_ident_t *mtd[2*CISTPL_MAX_DEVICES]; -} socket_info_t; - -#define SOCKET_PRESENT 0x01 -#define SOCKET_READY 0x02 -#define SOCKET_HOTPLUG 0x04 - -/* Linked list of resource adjustments */ -struct adjust_list_t *root_adjust = NULL; - -/* Linked list of device definitions */ -struct device_info_t *root_device = NULL; - -/* Special pointer to "anonymous" card definition */ -struct card_info_t *blank_card = NULL; - -/* Linked list of card definitions */ -struct card_info_t *root_card = NULL; - -/* Linked list of function definitions */ -struct card_info_t *root_func = NULL; - -/* Linked list of MTD definitions */ -struct mtd_ident_t *root_mtd = NULL; - -/* Default MTD */ -struct mtd_ident_t *default_mtd = NULL; - -static int sockets; -static struct socket_info_t socket[MAX_SOCKS]; - -/* Default path for config file, device scripts */ -#ifdef ETC -static char *configpath = ETC; -#else -static char *configpath = "/etc/pcmcia"; -#endif - -/* Default path for pid file */ -//mdk-stage1// static char *pidfile = "/var/run/cardmgr.pid"; - -#ifdef __linux__ -/* Default path for finding modules */ -//mdk-stage1// static char *modpath = NULL; -#endif - -/* Default path for socket info table */ -static char *stabfile; - -/* If set, don't generate beeps when cards are inserted */ -//mdk-stage1// static int be_quiet = 0; - -/* If set, use modprobe instead of insmod */ -//mdk-stage1// static int do_modprobe = 0; - -/* If set, configure already inserted cards, then exit */ -//mdk-stage1// static int one_pass = 0; - -/* Extra message logging? */ -//mdk-stage1// static int verbose = 0; - -/*====================================================================*/ - -#ifdef __linux__ - -static int major = 0; - -static int lookup_dev(char *name) -{ - FILE *f; - int n; - char s[32], t[32]; - - f = fopen("/proc/devices", "r"); - if (f == NULL) - return -errno; - while (fgets(s, 32, f) != NULL) { - if (sscanf(s, "%d %s", &n, t) == 2) - if (strcmp(name, t) == 0) - break; - } - fclose(f); - if (strcmp(name, t) == 0) - return n; - else - return -ENODEV; -} - -int open_dev(dev_t dev, int mode) -{ - char * fn = "/tmp/cardmgr_tmp"; - int fd; - - unlink(fn); - if (mknod(fn, mode, dev) != 0) - return -1; - fd = open(fn, (mode&S_IWRITE)?O_RDWR:O_RDONLY); - if (fd < 0) - fd = open(fn, O_NONBLOCK|((mode&S_IWRITE)?O_RDWR:O_RDONLY)); - unlink(fn); - return fd; -} - -#endif /* __linux__ */ - -int open_sock(int sock, int mode) -{ -#ifdef __linux__ - dev_t dev = (major<<8)+sock; - return open_dev(dev, mode); -#endif -#ifdef __BEOS__ - int fd; - char fn[B_OS_NAME_LENGTH]; - sprintf(fn, "/dev/pcmcia/sock%d", sock); - return open(fn, (mode & S_IWRITE) ? O_RDWR: O_RDONLY); -#endif -} - -/*====================================================================== - - xlate_scsi_name() is a sort-of-hack used to deduce the minor - device numbers of SCSI devices, from the information available to - the low-level driver. - -======================================================================*/ - -#ifdef __linux__ - -#include <linux/major.h> -#include <scsi/scsi.h> -//mdk-stage1// #define VERSION(v,p,s) (((v)<<16)+(p<<8)+s) -//mdk-stage1// #if (LINUX_VERSION_CODE < VERSION(2,1,126)) -//mdk-stage1// #define SCSI_DISK0_MAJOR SCSI_DISK_MAJOR -//mdk-stage1// #endif - -static int xlate_scsi_name(bind_info_t *bind) -{ - int i, fd, mode, minor; - u_int arg[2], id1, id2; - - id1 = strtol(bind->name+3, NULL, 16); - if ((bind->major == SCSI_DISK0_MAJOR) || - (bind->major == SCSI_CDROM_MAJOR)) - mode = S_IREAD|S_IFBLK; - else - mode = S_IREAD|S_IFCHR; - - for (i = 0; i < 16; i++) { - minor = (bind->major == SCSI_DISK0_MAJOR) ? (i<<4) : i; - fd = open_dev((bind->major<<8)+minor, mode); - if (fd < 0) - continue; - if (ioctl(fd, SCSI_IOCTL_GET_IDLUN, arg) == 0) { - id2 = (arg[0]&0x0f) + ((arg[0]>>4)&0xf0) + - ((arg[0]>>8)&0xf00) + ((arg[0]>>12)&0xf000); - if (id1 == id2) { - close(fd); - switch (bind->major) { - case SCSI_DISK0_MAJOR: - case SCSI_GENERIC_MAJOR: - sprintf(bind->name+2, "%c", 'a'+i); break; - case SCSI_CDROM_MAJOR: - sprintf(bind->name, "scd%d", i); break; - case SCSI_TAPE_MAJOR: - sprintf(bind->name+2, "%d", i); break; - } - bind->minor = minor; - return 0; - } - } - close(fd); - } - return -1; -} -#endif - -/*====================================================================*/ - -#define BEEP_TIME 150 -#define BEEP_OK 1000 -#define BEEP_WARN 2000 -#define BEEP_ERR 4000 - -#ifdef __linux__ - -//mdk-stage1// #include <sys/kd.h> -//mdk-stage1// -static void beep(unsigned int ms, unsigned int freq) -{ -//mdk-stage1// int fd, arg; -//mdk-stage1// -//mdk-stage1// if (be_quiet) -//mdk-stage1// return; -//mdk-stage1// fd = open("/dev/console", O_RDWR); -//mdk-stage1// if (fd < 0) -//mdk-stage1// return; -//mdk-stage1// arg = (ms << 16) | freq; -//mdk-stage1// ioctl(fd, KDMKTONE, arg); -//mdk-stage1// close(fd); -//mdk-stage1// usleep(ms*1000); -} - -#endif /* __linux__ */ - -#ifdef __BEOS__ -static void beep(unsigned int ms, unsigned int freq) -{ - if (!be_quiet) system("/bin/beep"); -} -#endif - -/*====================================================================*/ - -//mdk-stage1// static void write_pid(void) -//mdk-stage1// { -//mdk-stage1// FILE *f; -//mdk-stage1// f = fopen(pidfile, "w"); -//mdk-stage1// if (f == NULL) -//mdk-stage1// syslog(LOG_WARNING, "could not open %s: %m", pidfile); -//mdk-stage1// else { -//mdk-stage1// fprintf(f, "%d\n", getpid()); -//mdk-stage1// fclose(f); -//mdk-stage1// } -//mdk-stage1// } - -static void write_stab(void) -{ - int i, j, k; - FILE *f; - socket_info_t *s; - bind_info_t *bind; - - f = fopen(stabfile, "w"); - if (f == NULL) { - log_message("CM: fopen(stabfile) failed: %m"); - return; - } -#ifndef __BEOS__ - if (flock(fileno(f), LOCK_EX) != 0) { - log_message("CM: flock(stabfile) failed: %m"); - return; - } -#endif - for (i = 0; i < sockets; i++) { - s = &socket[i]; - fprintf(f, "Socket %d: ", i); - if (!(s->state & SOCKET_PRESENT)) { - fprintf(f, "empty\n"); -//mdk-stage1// } else if (s->state & SOCKET_HOTPLUG) { -//mdk-stage1// fprintf(f, "CardBus hotplug device\n"); - } else if (!s->card) { - fprintf(f, "unsupported card\n"); - } else { - fprintf(f, "%s\n", s->card->name); - for (j = 0; j < s->card->bindings; j++) - for (k = 0, bind = s->bind[j]; - bind != NULL; - k++, bind = bind->next) { - char *class = s->card->device[j]->class; - fprintf(f, "%d\t%s\t%s\t%d\t%s", - i, (class ? class : "none"), - bind->dev_info, k, bind->name); - if (bind->major) - fprintf(f, "\t%d\t%d\n", - bind->major, bind->minor); - else - fputc('\n', f); - } - } - } - fflush(f); -#ifndef __BEOS__ - flock(fileno(f), LOCK_UN); -#endif - fclose(f); -} - -/*====================================================================*/ - -static int get_tuple(int ns, cisdata_t code, ds_ioctl_arg_t *arg) -{ - socket_info_t *s = &socket[ns]; - - arg->tuple.DesiredTuple = code; - arg->tuple.Attributes = 0; - if (ioctl(s->fd, DS_GET_FIRST_TUPLE, arg) != 0) - return -1; - arg->tuple.TupleOffset = 0; - if (ioctl(s->fd, DS_GET_TUPLE_DATA, arg) != 0) { - log_message("CM: error reading CIS data on socket %d: %m", ns); - return -1; - } - if (ioctl(s->fd, DS_PARSE_TUPLE, arg) != 0) { - log_message("CM: error parsing CIS on socket %d: %m", ns); - return -1; - } - return 0; -} - -/*====================================================================== - - Code to fetch a 2.4 kernel's hot plug PCI driver list - - This is distasteful but is the best I could come up with. - -======================================================================*/ - -#ifdef __linux__ - -typedef struct pci_id { - u_short vendor, device; - struct pci_id *next; -} pci_id_t; - -static int get_pci_id(int ns, pci_id_t *id) -{ - socket_info_t *s = &socket[ns]; - config_info_t config; - - config.Function = config.ConfigBase = 0; - if ((ioctl(s->fd, DS_GET_CONFIGURATION_INFO, &config) != 0) || - (config.IntType != INT_CARDBUS) || !config.ConfigBase) - return 0; - id->vendor = config.ConfigBase & 0xffff; - id->device = config.ConfigBase >> 16; - return 1; -} - -#endif /* __linux__ */ - -/*====================================================================*/ - -//mdk-stage1// static void log_card_info(cistpl_vers_1_t *vers, -//mdk-stage1// cistpl_manfid_t *manfid, -//mdk-stage1// cistpl_funcid_t *funcid, -//mdk-stage1// pci_id_t *pci_id) -//mdk-stage1// { -//mdk-stage1// char v[256] = ""; -//mdk-stage1// int i; -//mdk-stage1// static char *fn[] = { -//mdk-stage1// "multi", "memory", "serial", "parallel", "fixed disk", -//mdk-stage1// "video", "network", "AIMS", "SCSI" -//mdk-stage1// }; -//mdk-stage1// -//mdk-stage1// if (vers) { -//mdk-stage1// for (i = 0; i < vers->ns; i++) -//mdk-stage1// sprintf(v+strlen(v), "%s\"%s\"", -//mdk-stage1// (i>0) ? ", " : "", vers->str+vers->ofs[i]); -//mdk-stage1// syslog(LOG_INFO, " product info: %s", v); -//mdk-stage1// } else { -//mdk-stage1// syslog(LOG_INFO, " no product info available"); -//mdk-stage1// } -//mdk-stage1// *v = '\0'; -//mdk-stage1// if (manfid->manf != 0) -//mdk-stage1// sprintf(v, " manfid: 0x%04x, 0x%04x", -//mdk-stage1// manfid->manf, manfid->card); -//mdk-stage1// if (funcid->func != 0xff) -//mdk-stage1// sprintf(v+strlen(v), " function: %d (%s)", funcid->func, -//mdk-stage1// fn[funcid->func]); -//mdk-stage1// if (strlen(v) > 0) syslog(LOG_INFO, "%s", v); -//mdk-stage1// if (pci_id->vendor != 0) -//mdk-stage1// syslog(LOG_INFO, " PCI id: 0x%04x, 0x%04x", -//mdk-stage1// pci_id->vendor, pci_id->device); -//mdk-stage1// } - -static card_info_t *lookup_card(int ns) -{ - socket_info_t *s = &socket[ns]; - card_info_t *card = NULL; - ds_ioctl_arg_t arg; - cistpl_vers_1_t *vers = NULL; - cistpl_manfid_t manfid = { 0, 0 }; - pci_id_t pci_id = { 0, 0 }; - cistpl_funcid_t funcid = { 0xff, 0xff }; - cs_status_t status; - int i, ret, has_cis = 0; - - /* Do we have a CIS structure? */ - ret = ioctl(s->fd, DS_VALIDATE_CIS, &arg); - has_cis = ((ret == 0) && (arg.cisinfo.Chains > 0)); - - /* Try to read VERS_1, MANFID tuples */ - if (has_cis) { - /* rule of thumb: cards with no FUNCID, but with common memory - device geometry information, are probably memory cards */ - if (get_tuple(ns, CISTPL_FUNCID, &arg) == 0) - memcpy(&funcid, &arg.tuple_parse.parse.funcid, - sizeof(funcid)); - else if (get_tuple(ns, CISTPL_DEVICE_GEO, &arg) == 0) - funcid.func = CISTPL_FUNCID_MEMORY; - if (get_tuple(ns, CISTPL_MANFID, &arg) == 0) - memcpy(&manfid, &arg.tuple_parse.parse.manfid, - sizeof(manfid)); - if (get_tuple(ns, CISTPL_VERS_1, &arg) == 0) - vers = &arg.tuple_parse.parse.version_1; - - for (card = root_card; card; card = card->next) { - - if (card->ident_type & - ~(VERS_1_IDENT|MANFID_IDENT|TUPLE_IDENT)) - continue; - - if (card->ident_type & VERS_1_IDENT) { - if (vers == NULL) - continue; - for (i = 0; i < card->id.vers.ns; i++) { - if (strcmp(card->id.vers.pi[i], "*") == 0) - continue; - if (i >= vers->ns) - break; - if (strcmp(card->id.vers.pi[i], - vers->str+vers->ofs[i]) != 0) - break; - } - if (i < card->id.vers.ns) - continue; - } - - if (card->ident_type & MANFID_IDENT) { - if ((manfid.manf != card->manfid.manf) || - (manfid.card != card->manfid.card)) - continue; - } - - if (card->ident_type & TUPLE_IDENT) { - arg.tuple.DesiredTuple = card->id.tuple.code; - arg.tuple.Attributes = 0; - ret = ioctl(s->fd, DS_GET_FIRST_TUPLE, &arg); - if (ret != 0) continue; - arg.tuple.TupleOffset = card->id.tuple.ofs; - ret = ioctl(s->fd, DS_GET_TUPLE_DATA, &arg); - if (ret != 0) continue; - if (strncmp((char *)arg.tuple_parse.data, - card->id.tuple.info, - strlen(card->id.tuple.info)) != 0) - continue; - } - - break; /* we have a match */ - } - } - - /* Check PCI vendor/device info */ - status.Function = 0; - ioctl(s->fd, DS_GET_STATUS, &status); - if (status.CardState & CS_EVENT_CB_DETECT) { - if (get_pci_id(ns, &pci_id)) { - if (!card) { - for (card = root_card; card; card = card->next) - if ((card->ident_type == PCI_IDENT) && - (pci_id.vendor == card->manfid.manf) && - (pci_id.device == card->manfid.card)) - break; - } - } else { - /* this is a 2.4 kernel; hotplug handles these cards */ -//mdk-stage1// s->state |= SOCKET_HOTPLUG; - log_message("CM: socket %d: CardBus hotplug device", ns); - //beep(BEEP_TIME, BEEP_OK); -//mdk-stage1// return NULL; - } - } - - /* Try for a FUNCID match */ - if (!card && (funcid.func != 0xff)) { - for (card = root_func; card; card = card->next) - if (card->id.func.funcid == funcid.func) - break; - } - - if (card) { - log_message("CM: socket %d: %s", ns, card->name); - beep(BEEP_TIME, BEEP_OK); -//mdk-stage1// if (verbose) log_card_info(vers, &manfid, &funcid, &pci_id); - return card; - } - - if (!blank_card || (status.CardState & CS_EVENT_CB_DETECT) || - manfid.manf || manfid.card || pci_id.vendor || vers) { - log_message("CM: unsupported card in socket %d", ns); -//mdk-stage1// if (one_pass) return NULL; - beep(BEEP_TIME, BEEP_ERR); -//mdk-stage1// log_card_info(vers, &manfid, &funcid, &pci_id); - return NULL; - } else { - card = blank_card; - log_message("CM: socket %d: %s", ns, card->name); - beep(BEEP_TIME, BEEP_WARN); - return card; - } -} - -/*====================================================================*/ - -static int load_config(void) -{ - if (chdir(configpath) != 0) { - log_message("CM: chdir to %s failed: %m", configpath); - return -1; - } - if (parse_configfile("config") != 0) { - log_message("CM: parsing of config file failed: %m"); - return -1; - } - if (root_device == NULL) - log_message("CM: no device drivers defined"); - if ((root_card == NULL) && (root_func == NULL)) - log_message("CM: no cards defined"); - return 0; -} - -//mdk-stage1// /*====================================================================*/ -//mdk-stage1// -//mdk-stage1// static void free_card(card_info_t *card) -//mdk-stage1// { -//mdk-stage1// if (card && (--card->refs == 0)) { -//mdk-stage1// int i; -//mdk-stage1// free(card->name); -//mdk-stage1// switch(card->ident_type) { -//mdk-stage1// case VERS_1_IDENT: -//mdk-stage1// for (i = 0; i < card->id.vers.ns; i++) -//mdk-stage1// free(card->id.vers.pi[i]); -//mdk-stage1// break; -//mdk-stage1// case TUPLE_IDENT: -//mdk-stage1// free(card->id.tuple.info); -//mdk-stage1// break; -//mdk-stage1// default: -//mdk-stage1// break; -//mdk-stage1// } -//mdk-stage1// free(card); -//mdk-stage1// } -//mdk-stage1// } -//mdk-stage1// -//mdk-stage1// static void free_device(device_info_t *dev) -//mdk-stage1// { -//mdk-stage1// if (dev && (--dev->refs == 0)) { -//mdk-stage1// int i; -//mdk-stage1// for (i = 0; i < dev->modules; i++) { -//mdk-stage1// free(dev->module[i]); -//mdk-stage1// if (dev->opts[i]) free(dev->opts[i]); -//mdk-stage1// } -//mdk-stage1// if (dev->class) free(dev->class); -//mdk-stage1// free(dev); -//mdk-stage1// } -//mdk-stage1// } -//mdk-stage1// -//mdk-stage1// static void free_mtd(mtd_ident_t *mtd) -//mdk-stage1// { -//mdk-stage1// if (mtd && (--mtd->refs == 0)) { -//mdk-stage1// free(mtd->name); -//mdk-stage1// free(mtd->module); -//mdk-stage1// free(mtd); -//mdk-stage1// } -//mdk-stage1// } -//mdk-stage1// -//mdk-stage1// static void free_config(void) -//mdk-stage1// { -//mdk-stage1// while (root_adjust != NULL) { -//mdk-stage1// adjust_list_t *adj = root_adjust; -//mdk-stage1// root_adjust = root_adjust->next; -//mdk-stage1// free(adj); -//mdk-stage1// } -//mdk-stage1// -//mdk-stage1// while (root_device != NULL) { -//mdk-stage1// device_info_t *dev = root_device; -//mdk-stage1// root_device = root_device->next; -//mdk-stage1// free_device(dev); -//mdk-stage1// } -//mdk-stage1// -//mdk-stage1// while (root_card != NULL) { -//mdk-stage1// card_info_t *card = root_card; -//mdk-stage1// root_card = root_card->next; -//mdk-stage1// free_card(card); -//mdk-stage1// } -//mdk-stage1// -//mdk-stage1// while (root_func != NULL) { -//mdk-stage1// card_info_t *card = root_func; -//mdk-stage1// root_func = root_func->next; -//mdk-stage1// free_card(card); -//mdk-stage1// } -//mdk-stage1// blank_card = NULL; -//mdk-stage1// -//mdk-stage1// while (root_mtd != NULL) { -//mdk-stage1// mtd_ident_t *mtd = root_mtd; -//mdk-stage1// root_mtd = root_mtd->next; -//mdk-stage1// free_mtd(mtd); -//mdk-stage1// } -//mdk-stage1// default_mtd = NULL; -//mdk-stage1// } -//mdk-stage1// -//mdk-stage1// /*====================================================================*/ -//mdk-stage1// -//mdk-stage1// static int execute(char *msg, char *cmd) -//mdk-stage1// { -//mdk-stage1// int ret; -//mdk-stage1// FILE *f; -//mdk-stage1// char line[256]; -//mdk-stage1// -//mdk-stage1// syslog(LOG_INFO, "executing: '%s'", cmd); -//mdk-stage1// strcat(cmd, " 2>&1"); -//mdk-stage1// f = popen(cmd, "r"); -//mdk-stage1// while (fgets(line, 255, f)) { -//mdk-stage1// line[strlen(line)-1] = '\0'; -//mdk-stage1// syslog(LOG_INFO, "+ %s", line); -//mdk-stage1// } -//mdk-stage1// ret = pclose(f); -//mdk-stage1// if (WIFEXITED(ret)) { -//mdk-stage1// if (WEXITSTATUS(ret)) -//mdk-stage1// syslog(LOG_INFO, "%s exited with status %d", -//mdk-stage1// msg, WEXITSTATUS(ret)); -//mdk-stage1// return WEXITSTATUS(ret); -//mdk-stage1// } else -//mdk-stage1// syslog(LOG_INFO, "%s exited on signal %d", -//mdk-stage1// msg, WTERMSIG(ret)); -//mdk-stage1// return -1; -//mdk-stage1// } -//mdk-stage1// -//mdk-stage1// /*====================================================================*/ -//mdk-stage1// -//mdk-stage1// static int execute_on_dev(char *action, char *class, char *dev) -//mdk-stage1// { -//mdk-stage1// /* Fixed length strings are ok here */ -//mdk-stage1// char msg[128], cmd[128]; -//mdk-stage1// -//mdk-stage1// sprintf(msg, "%s cmd", action); -//mdk-stage1// sprintf(cmd, "./%s %s %s", class, action, dev); -//mdk-stage1// return execute(msg, cmd); -//mdk-stage1// } -//mdk-stage1// -//mdk-stage1// static int execute_on_all(char *cmd, char *class, int sn, int fn) -//mdk-stage1// { -//mdk-stage1// socket_info_t *s = &socket[sn]; -//mdk-stage1// bind_info_t *bind; -//mdk-stage1// int ret = 0; -//mdk-stage1// for (bind = s->bind[fn]; bind != NULL; bind = bind->next) -//mdk-stage1// if (bind->name[0] && (bind->name[2] != '#')) -//mdk-stage1// ret |= execute_on_dev(cmd, class, bind->name); -//mdk-stage1// return ret; -//mdk-stage1// } -//mdk-stage1// -//mdk-stage1// /*====================================================================*/ -//mdk-stage1// -//mdk-stage1// #ifdef __linux__ -//mdk-stage1// -//mdk-stage1// typedef struct module_list_t { -//mdk-stage1// char *mod; -//mdk-stage1// int usage; -//mdk-stage1// struct module_list_t *next; -//mdk-stage1// } module_list_t; -//mdk-stage1// -//mdk-stage1// static module_list_t *module_list = NULL; -//mdk-stage1// -//mdk-stage1// static int try_insmod(char *mod, char *opts) -//mdk-stage1// { -//mdk-stage1// char *cmd = malloc(strlen(mod) + strlen(modpath) + -//mdk-stage1// (opts ? strlen(opts) : 0) + 30); -//mdk-stage1// int ret; -//mdk-stage1// -//mdk-stage1// strcpy(cmd, "insmod "); -//mdk-stage1// if (strchr(mod, '/') != NULL) -//mdk-stage1// sprintf(cmd+7, "%s/%s.o", modpath, mod); -//mdk-stage1// else -//mdk-stage1// sprintf(cmd+7, "%s/pcmcia/%s.o", modpath, mod); -//mdk-stage1// if (access(cmd+7, R_OK) != 0) { -//mdk-stage1// syslog(LOG_INFO, "module %s not available", cmd+7); -//mdk-stage1// free(cmd); -//mdk-stage1// return -1; -//mdk-stage1// } -//mdk-stage1// if (opts) { -//mdk-stage1// strcat(cmd, " "); -//mdk-stage1// strcat(cmd, opts); -//mdk-stage1// } -//mdk-stage1// ret = execute("insmod", cmd); -//mdk-stage1// free(cmd); -//mdk-stage1// return ret; -//mdk-stage1// } -//mdk-stage1// -//mdk-stage1// static int try_modprobe(char *mod, char *opts) -//mdk-stage1// { -//mdk-stage1// char *cmd = malloc(strlen(mod) + (opts ? strlen(opts) : 0) + 20); -//mdk-stage1// char *s = strrchr(mod, '/'); -//mdk-stage1// int ret; -//mdk-stage1// -//mdk-stage1// sprintf(cmd, "modprobe %s", (s) ? s+1 : mod); -//mdk-stage1// if (opts) { -//mdk-stage1// strcat(cmd, " "); -//mdk-stage1// strcat(cmd, opts); -//mdk-stage1// } -//mdk-stage1// ret = execute("modprobe", cmd); -//mdk-stage1// free(cmd); -//mdk-stage1// return ret; -//mdk-stage1// } - -static void install_module(char *mod, char *opts) -{ - my_insmod(mod, ANY_DRIVER_TYPE, opts, 1); -//mdk-stage1// module_list_t *ml; -//mdk-stage1// -//mdk-stage1// for (ml = module_list; ml != NULL; ml = ml->next) -//mdk-stage1// if (strcmp(mod, ml->mod) == 0) break; -//mdk-stage1// if (ml == NULL) { -//mdk-stage1// ml = (module_list_t *)malloc(sizeof(struct module_list_t)); -//mdk-stage1// ml->mod = mod; -//mdk-stage1// ml->usage = 0; -//mdk-stage1// ml->next = module_list; -//mdk-stage1// module_list = ml; -//mdk-stage1// } -//mdk-stage1// ml->usage++; -//mdk-stage1// if (ml->usage != 1) -//mdk-stage1// return; -//mdk-stage1// -//mdk-stage1// #ifdef __linux__ -//mdk-stage1// if (access("/proc/bus/pccard/drivers", R_OK) == 0) { -//mdk-stage1// FILE *f = fopen("/proc/bus/pccard/drivers", "r"); -//mdk-stage1// if (f) { -//mdk-stage1// char a[61], s[33]; -//mdk-stage1// while (fgets(a, 60, f)) { -//mdk-stage1// int is_kernel; -//mdk-stage1// sscanf(a, "%s %d", s, &is_kernel); -//mdk-stage1// if (strcmp(s, mod) != 0) continue; -//mdk-stage1// /* If it isn't a module, we won't try to rmmod */ -//mdk-stage1// ml->usage += is_kernel; -//mdk-stage1// fclose(f); -//mdk-stage1// return; -//mdk-stage1// } -//mdk-stage1// fclose(f); -//mdk-stage1// } -//mdk-stage1// } -//mdk-stage1// #endif -//mdk-stage1// -//mdk-stage1// if (do_modprobe) { -//mdk-stage1// if (try_modprobe(mod, opts) != 0) -//mdk-stage1// try_insmod(mod, opts); -//mdk-stage1// } else { -//mdk-stage1// if (try_insmod(mod, opts) != 0) -//mdk-stage1// try_modprobe(mod, opts); -//mdk-stage1// } -} - -//mdk-stage1// static void remove_module(char *mod) -//mdk-stage1// { -//mdk-stage1// char *s, cmd[128]; -//mdk-stage1// module_list_t *ml; -//mdk-stage1// -//mdk-stage1// for (ml = module_list; ml != NULL; ml = ml->next) -//mdk-stage1// if (strcmp(mod, ml->mod) == 0) break; -//mdk-stage1// if (ml != NULL) { -//mdk-stage1// ml->usage--; -//mdk-stage1// if (ml->usage == 0) { -//mdk-stage1// /* Strip off leading path names */ -//mdk-stage1// s = strrchr(mod, '/'); -//mdk-stage1// s = (s) ? s+1 : mod; -//mdk-stage1// sprintf(cmd, do_modprobe ? "modprobe -r %s" : "rmmod %s", s); -//mdk-stage1// execute(do_modprobe ? "modprobe" : "rmmod", cmd); -//mdk-stage1// } -//mdk-stage1// } -//mdk-stage1// } -//mdk-stage1// -//mdk-stage1// #endif /* __linux__ */ -//mdk-stage1// -//mdk-stage1// /*====================================================================*/ -//mdk-stage1// -//mdk-stage1// #ifdef __BEOS__ -//mdk-stage1// -//mdk-stage1// #define install_module(a,b) -//mdk-stage1// #define remove_module(a) -//mdk-stage1// -//mdk-stage1// static void republish_driver(char *mod) -//mdk-stage1// { -//mdk-stage1// int fd = open("/dev", O_RDWR); -//mdk-stage1// write(fd, mod, strlen(mod)); -//mdk-stage1// close(fd); -//mdk-stage1// } -//mdk-stage1// -//mdk-stage1// #endif /* __BEOS__ */ -//mdk-stage1// -//mdk-stage1// /*====================================================================*/ - -static mtd_ident_t *lookup_mtd(region_info_t *region) -{ - mtd_ident_t *mtd; - int match = 0; - - for (mtd = root_mtd; mtd; mtd = mtd->next) { - switch (mtd->mtd_type) { - case JEDEC_MTD: - if ((mtd->jedec_mfr == region->JedecMfr) && - (mtd->jedec_info == region->JedecInfo)) { - match = 1; - break; - } - case DTYPE_MTD: - break; - default: - break; - } - if (match) break; - } - if (mtd) - return mtd; - else - return default_mtd; -} - -/*====================================================================*/ - -static void bind_mtd(int sn) -{ - socket_info_t *s = &socket[sn]; - region_info_t region; - bind_info_t bind; - mtd_info_t mtd_info; - mtd_ident_t *mtd; - int i, attr, ret, nr; - - nr = 0; - for (attr = 0; attr < 2; attr++) { - region.Attributes = attr; - ret = ioctl(s->fd, DS_GET_FIRST_REGION, ®ion); - while (ret == 0) { - mtd = lookup_mtd(®ion); - if (mtd) { - /* Have we seen this MTD before? */ - for (i = 0; i < nr; i++) - if (s->mtd[i] == mtd) break; - if (i == nr) { - install_module(mtd->module, mtd->opts); - s->mtd[nr] = mtd; - mtd->refs++; - nr++; - } - log_message("CM: %s memory region at 0x%x: %s", - attr ? "Attribute" : "Common", region.CardOffset, - mtd->name); - /* Bind MTD to this region */ - strcpy(mtd_info.dev_info, s->mtd[i]->module); - mtd_info.Attributes = region.Attributes; - mtd_info.CardOffset = region.CardOffset; - if (ioctl(s->fd, DS_BIND_MTD, &mtd_info) != 0) { - log_message("CM: bind MTD '%s' to region at 0x%x failed: %m", - (char *)mtd_info.dev_info, region.CardOffset); - } - } - ret = ioctl(s->fd, DS_GET_NEXT_REGION, ®ion); - } - } - s->mtd[nr] = NULL; - - /* Now bind each unique MTD as a normal client of this socket */ - for (i = 0; i < nr; i++) { - strcpy(bind.dev_info, s->mtd[i]->module); - bind.function = 0; - if (ioctl(s->fd, DS_BIND_REQUEST, &bind) != 0) - log_message("CM: bind MTD '%s' to socket %d failed: %m", - (char *)bind.dev_info, sn); - } -} - -/*====================================================================*/ - -static void update_cis(socket_info_t *s) -{ - cisdump_t cis; - FILE *f = fopen(s->card->cis_file, "r"); - if (f == NULL) - log_message("CM: could not open '%s': %m", s->card->cis_file); - else { - cis.Length = fread(cis.Data, 1, CISTPL_MAX_CIS_SIZE, f); - fclose(f); - if (ioctl(s->fd, DS_REPLACE_CIS, &cis) != 0) - log_message("CM: could not replace CIS: %m"); - } -} - -/*====================================================================*/ - -static void do_insert(int sn) -{ - socket_info_t *s = &socket[sn]; - card_info_t *card; - device_info_t **dev; - bind_info_t *bind, **tail; - int i, j, ret; - - /* Already identified? */ - if ((s->card != NULL) && (s->card != blank_card)) - return; - - log_message("CM: initializing socket %d", sn); - card = lookup_card(sn); - if (s->state & SOCKET_HOTPLUG) { - write_stab(); - return; - } - /* Make sure we've learned something new before continuing */ - if (card == s->card) - return; - s->card = card; - card->refs++; - if (card->cis_file) update_cis(s); - - dev = card->device; - - /* Set up MTD's */ - for (i = 0; i < card->bindings; i++) - if (dev[i]->needs_mtd) - break; - if (i < card->bindings) - bind_mtd(sn); - -#ifdef __linux__ - /* Install kernel modules */ - for (i = 0; i < card->bindings; i++) { - dev[i]->refs++; - for (j = 0; j < dev[i]->modules; j++) - install_module(dev[i]->module[j], dev[i]->opts[j]); - } -#endif - - /* Bind drivers by their dev_info identifiers */ - for (i = 0; i < card->bindings; i++) { - bind = calloc(1, sizeof(bind_info_t)); - strcpy((char *)bind->dev_info, (char *)dev[i]->dev_info); - if (strcmp(bind->dev_info, "cb_enabler") == 0) - bind->function = BIND_FN_ALL; - else - bind->function = card->dev_fn[i]; - if (ioctl(s->fd, DS_BIND_REQUEST, bind) != 0) { - if (errno == EBUSY) { - log_message("CM: '%s' already bound to socket %d", - (char *)bind->dev_info, sn); - } else { - log_message("CM: bind '%s' to socket %d failed: %m", - (char *)bind->dev_info, sn); - beep(BEEP_TIME, BEEP_ERR); - write_stab(); - return; - } - } - -#ifdef __BEOS__ - republish_driver(dev[i]->module[0]); -#endif - - for (ret = j = 0; j < 10; j++) { - ret = ioctl(s->fd, DS_GET_DEVICE_INFO, bind); - if ((ret == 0) || (errno != EAGAIN)) - break; - usleep(100000); - } - if (ret != 0) { - log_message("CM: get dev info on socket %d failed: %m", - sn); - ioctl(s->fd, DS_UNBIND_REQUEST, bind); - beep(BEEP_TIME, BEEP_ERR); - write_stab(); - return; - } - tail = &s->bind[i]; - while (ret == 0) { - bind_info_t *old; -#ifdef __linux__ - if ((strlen(bind->name) > 3) && (bind->name[2] == '#')) - xlate_scsi_name(bind); -#endif - old = *tail = bind; tail = (bind_info_t **)&bind->next; - bind = (bind_info_t *)malloc(sizeof(bind_info_t)); - memcpy(bind, old, sizeof(bind_info_t)); - ret = ioctl(s->fd, DS_GET_NEXT_DEVICE, bind); - } - *tail = NULL; free(bind); - write_stab(); - } - -//mdk-stage1// /* Run "start" commands */ -//mdk-stage1// for (i = ret = 0; i < card->bindings; i++) -//mdk-stage1// if (dev[i]->class) -//mdk-stage1// ret |= execute_on_all("start", dev[i]->class, sn, i); -//mdk-stage1// beep(BEEP_TIME, (ret) ? BEEP_ERR : BEEP_OK); - -} - -//mdk-stage1// /*====================================================================*/ -//mdk-stage1// -//mdk-stage1// static int do_check(int sn) -//mdk-stage1// { -//mdk-stage1// socket_info_t *s = &socket[sn]; -//mdk-stage1// card_info_t *card; -//mdk-stage1// device_info_t **dev; -//mdk-stage1// int i, ret; -//mdk-stage1// -//mdk-stage1// card = s->card; -//mdk-stage1// if (card == NULL) -//mdk-stage1// return 0; -//mdk-stage1// -//mdk-stage1// /* Run "check" commands */ -//mdk-stage1// dev = card->device; -//mdk-stage1// for (i = 0; i < card->bindings; i++) { -//mdk-stage1// if (dev[i]->class) { -//mdk-stage1// ret = execute_on_all("check", dev[i]->class, sn, i); -//mdk-stage1// if (ret != 0) -//mdk-stage1// return CS_IN_USE; -//mdk-stage1// } -//mdk-stage1// } -//mdk-stage1// return 0; -//mdk-stage1// } -//mdk-stage1// -//mdk-stage1// /*====================================================================*/ -//mdk-stage1// -//mdk-stage1// static void do_remove(int sn) -//mdk-stage1// { -//mdk-stage1// socket_info_t *s = &socket[sn]; -//mdk-stage1// card_info_t *card; -//mdk-stage1// device_info_t **dev; -//mdk-stage1// bind_info_t *bind; -//mdk-stage1// int i, j; -//mdk-stage1// -//mdk-stage1// if (verbose) syslog(LOG_INFO, "shutting down socket %d", sn); -//mdk-stage1// -//mdk-stage1// card = s->card; -//mdk-stage1// if (card == NULL) -//mdk-stage1// goto done; -//mdk-stage1// -//mdk-stage1// /* Run "stop" commands */ -//mdk-stage1// dev = card->device; -//mdk-stage1// for (i = 0; i < card->bindings; i++) { -//mdk-stage1// if (dev[i]->class) { -//mdk-stage1// execute_on_all("stop", dev[i]->class, sn, i); -//mdk-stage1// } -//mdk-stage1// } -//mdk-stage1// -//mdk-stage1// /* unbind driver instances */ -//mdk-stage1// for (i = 0; i < card->bindings; i++) { -//mdk-stage1// if (s->bind[i]) { -//mdk-stage1// if (ioctl(s->fd, DS_UNBIND_REQUEST, s->bind[i]) != 0) -//mdk-stage1// syslog(LOG_INFO, "unbind '%s' from socket %d failed: %m", -//mdk-stage1// (char *)s->bind[i]->dev_info, sn); -//mdk-stage1// while (s->bind[i]) { -//mdk-stage1// bind = s->bind[i]; -//mdk-stage1// s->bind[i] = bind->next; -//mdk-stage1// free(bind); -//mdk-stage1// } -//mdk-stage1// } -//mdk-stage1// } -//mdk-stage1// for (i = 0; (s->mtd[i] != NULL); i++) { -//mdk-stage1// bind_info_t b; -//mdk-stage1// strcpy(b.dev_info, s->mtd[i]->module); -//mdk-stage1// b.function = 0; -//mdk-stage1// if (ioctl(s->fd, DS_UNBIND_REQUEST, &b) != 0) -//mdk-stage1// syslog(LOG_INFO, "unbind MTD '%s' from socket %d failed: %m", -//mdk-stage1// s->mtd[i]->module, sn); -//mdk-stage1// } -//mdk-stage1// -//mdk-stage1// /* remove kernel modules in inverse order */ -//mdk-stage1// for (i = 0; i < card->bindings; i++) { -//mdk-stage1// for (j = dev[i]->modules-1; j >= 0; j--) -//mdk-stage1// remove_module(dev[i]->module[j]); -//mdk-stage1// free_device(dev[i]); -//mdk-stage1// } -//mdk-stage1// /* Remove any MTD's bound to this socket */ -//mdk-stage1// for (i = 0; (s->mtd[i] != NULL); i++) { -//mdk-stage1// remove_module(s->mtd[i]->module); -//mdk-stage1// free_mtd(s->mtd[i]); -//mdk-stage1// s->mtd[i] = NULL; -//mdk-stage1// } -//mdk-stage1// -//mdk-stage1// done: -//mdk-stage1// beep(BEEP_TIME, BEEP_OK); -//mdk-stage1// free_card(card); -//mdk-stage1// s->card = NULL; -//mdk-stage1// write_stab(); -//mdk-stage1// } -//mdk-stage1// -//mdk-stage1// /*====================================================================*/ -//mdk-stage1// -//mdk-stage1// static void do_suspend(int sn) -//mdk-stage1// { -//mdk-stage1// socket_info_t *s = &socket[sn]; -//mdk-stage1// card_info_t *card; -//mdk-stage1// device_info_t **dev; -//mdk-stage1// int i, ret; -//mdk-stage1// -//mdk-stage1// card = s->card; -//mdk-stage1// if (card == NULL) -//mdk-stage1// return; -//mdk-stage1// dev = card->device; -//mdk-stage1// for (i = 0; i < card->bindings; i++) { -//mdk-stage1// if (dev[i]->class) { -//mdk-stage1// ret = execute_on_all("suspend", dev[i]->class, sn, i); -//mdk-stage1// if (ret != 0) -//mdk-stage1// beep(BEEP_TIME, BEEP_ERR); -//mdk-stage1// } -//mdk-stage1// } -//mdk-stage1// } -//mdk-stage1// -//mdk-stage1// /*====================================================================*/ -//mdk-stage1// -//mdk-stage1// static void do_resume(int sn) -//mdk-stage1// { -//mdk-stage1// socket_info_t *s = &socket[sn]; -//mdk-stage1// card_info_t *card; -//mdk-stage1// device_info_t **dev; -//mdk-stage1// int i, ret; -//mdk-stage1// -//mdk-stage1// card = s->card; -//mdk-stage1// if (card == NULL) -//mdk-stage1// return; -//mdk-stage1// dev = card->device; -//mdk-stage1// for (i = 0; i < card->bindings; i++) { -//mdk-stage1// if (dev[i]->class) { -//mdk-stage1// ret = execute_on_all("resume", dev[i]->class, sn, i); -//mdk-stage1// if (ret != 0) -//mdk-stage1// beep(BEEP_TIME, BEEP_ERR); -//mdk-stage1// } -//mdk-stage1// } -//mdk-stage1// } - -/*====================================================================*/ - -static void wait_for_pending(void) -{ - cs_status_t status; - int i; - status.Function = 0; - for (;;) { - usleep(100000); - for (i = 0; i < sockets; i++) - if ((ioctl(socket[i].fd, DS_GET_STATUS, &status) == 0) && - (status.CardState & CS_EVENT_CARD_INSERTION)) - break; - if (i == sockets) break; - } -} - -//mdk-stage1// /*====================================================================*/ -//mdk-stage1// -//mdk-stage1// static void free_resources(void) -//mdk-stage1// { -//mdk-stage1// adjust_list_t *al; -//mdk-stage1// int fd = socket[0].fd; -//mdk-stage1// -//mdk-stage1// for (al = root_adjust; al; al = al->next) { -//mdk-stage1// if (al->adj.Action == ADD_MANAGED_RESOURCE) { -//mdk-stage1// al->adj.Action = REMOVE_MANAGED_RESOURCE; -//mdk-stage1// ioctl(fd, DS_ADJUST_RESOURCE_INFO, &al->adj); -//mdk-stage1// } else if ((al->adj.Action == REMOVE_MANAGED_RESOURCE) && -//mdk-stage1// (al->adj.Resource == RES_IRQ)) { -//mdk-stage1// al->adj.Action = ADD_MANAGED_RESOURCE; -//mdk-stage1// ioctl(fd, DS_ADJUST_RESOURCE_INFO, &al->adj); -//mdk-stage1// } -//mdk-stage1// } -//mdk-stage1// -//mdk-stage1// } - -/*====================================================================*/ - -static void adjust_resources(void) -{ - adjust_list_t *al; - int ret; - char tmp[64]; - int fd = socket[0].fd; - - for (al = root_adjust; al; al = al->next) { - ret = ioctl(fd, DS_ADJUST_RESOURCE_INFO, &al->adj); - if (ret != 0) { - switch (al->adj.Resource) { - case RES_MEMORY_RANGE: - sprintf(tmp, "memory %#lx-%#lx", - al->adj.resource.memory.Base, - al->adj.resource.memory.Base + - al->adj.resource.memory.Size - 1); - break; - case RES_IO_RANGE: - sprintf(tmp, "IO ports %#x-%#x", - al->adj.resource.io.BasePort, - al->adj.resource.io.BasePort + - al->adj.resource.io.NumPorts - 1); - break; - case RES_IRQ: - sprintf(tmp, "irq %u", al->adj.resource.irq.IRQ); - break; - } - log_message("CM: could not adjust resource: %s: %m", tmp); - } - } -} - -//mdk-stage1// /*====================================================================*/ -//mdk-stage1// -//mdk-stage1// static int cleanup_files = 0; -//mdk-stage1// -//mdk-stage1// static void fork_now(void) -//mdk-stage1// { -//mdk-stage1// int ret; -//mdk-stage1// if ((ret = fork()) > 0) { -//mdk-stage1// cleanup_files = 0; -//mdk-stage1// exit(0); -//mdk-stage1// } -//mdk-stage1// if (ret == -1) -//mdk-stage1// syslog(LOG_ERR, "forking: %m"); -//mdk-stage1// if (setsid() < 0) -//mdk-stage1// syslog(LOG_ERR, "detaching from tty: %m"); -//mdk-stage1// } -//mdk-stage1// -//mdk-stage1// static void done(void) -//mdk-stage1// { -//mdk-stage1// syslog(LOG_INFO, "exiting"); -//mdk-stage1// if (cleanup_files) { -//mdk-stage1// unlink(pidfile); -//mdk-stage1// unlink(stabfile); -//mdk-stage1// } -//mdk-stage1// } -//mdk-stage1// -//mdk-stage1// /*====================================================================*/ -//mdk-stage1// -//mdk-stage1// /* most recent signal */ -//mdk-stage1// static int caught_signal = 0; -//mdk-stage1// -//mdk-stage1// static void catch_signal(int sig) -//mdk-stage1// { -//mdk-stage1// caught_signal = sig; -//mdk-stage1// if (signal(sig, catch_signal) == SIG_ERR) -//mdk-stage1// syslog(LOG_INFO, "signal(%d): %m", sig); -//mdk-stage1// } -//mdk-stage1// -//mdk-stage1// static void handle_signal(void) -//mdk-stage1// { -//mdk-stage1// int i; -//mdk-stage1// switch (caught_signal) { -//mdk-stage1// case SIGTERM: -//mdk-stage1// case SIGINT: -//mdk-stage1// for (i = 0; i < sockets; i++) -//mdk-stage1// if ((socket[i].state & SOCKET_PRESENT) && -//mdk-stage1// (do_check(i) == 0)) do_remove(i); -//mdk-stage1// free_resources(); -//mdk-stage1// exit(0); -//mdk-stage1// break; -//mdk-stage1// case SIGHUP: -//mdk-stage1// free_resources(); -//mdk-stage1// free_config(); -//mdk-stage1// syslog(LOG_INFO, "re-loading config file"); -//mdk-stage1// load_config(); -//mdk-stage1// adjust_resources(); -//mdk-stage1// break; -//mdk-stage1// #ifdef SIGPWR -//mdk-stage1// case SIGPWR: -//mdk-stage1// break; -//mdk-stage1// #endif -//mdk-stage1// } -//mdk-stage1// } - -/*====================================================================*/ - -static int init_sockets(void) -{ - int fd, i; - servinfo_t serv; - -#ifdef __linux__ - major = lookup_dev("pcmcia"); - if (major < 0) { - if (major == -ENODEV) - log_message("CM: no pcmcia driver in /proc/devices"); - else - log_message("CM: could not open /proc/devices: %m"); - return -1; - } -#endif - for (fd = -1, i = 0; i < MAX_SOCKS; i++) { - fd = open_sock(i, S_IFCHR|S_IREAD|S_IWRITE); - if (fd < 0) break; - socket[i].fd = fd; - socket[i].state = 0; - } - if ((fd < 0) && (errno != ENODEV) && (errno != ENOENT)) - log_message("CM: open_sock(socket %d) failed: %m", i); - sockets = i; - if (sockets == 0) { - log_message("CM: no sockets found!"); - return -1; - } else - log_message("CM: watching %d sockets", sockets); - - if (ioctl(socket[0].fd, DS_GET_CARD_SERVICES_INFO, &serv) == 0) { - if (serv.Revision != CS_RELEASE_CODE) - log_message("CM: warning, Card Services release does not match kernel (generally harmless)"); - } else { - log_message("CM: could not get CS revision info!"); - return -1; - } - adjust_resources(); - return 0; -} - -//mdk-stage1// /*====================================================================*/ -//mdk-stage1// -//mdk-stage1// int main(int argc, char *argv[]) -//mdk-stage1// { -//mdk-stage1// int optch, errflg; -//mdk-stage1// int i, max_fd, ret, event, pass; -//mdk-stage1// int delay_fork = 0; -//mdk-stage1// struct timeval tv; -//mdk-stage1// fd_set fds; -//mdk-stage1// -//mdk-stage1// if (access("/var/lib/pcmcia", R_OK) == 0) { -//mdk-stage1// stabfile = "/var/lib/pcmcia/stab"; -//mdk-stage1// } else { -//mdk-stage1// stabfile = "/var/run/stab"; -//mdk-stage1// } -//mdk-stage1// -//mdk-stage1// errflg = 0; -//mdk-stage1// while ((optch = getopt(argc, argv, "Vqdvofc:m:p:s:")) != -1) { -//mdk-stage1// switch (optch) { -//mdk-stage1// case 'V': -//mdk-stage1// fprintf(stderr, "cardmgr version " CS_RELEASE "\n"); -//mdk-stage1// return 0; -//mdk-stage1// break; -//mdk-stage1// case 'q': -//mdk-stage1// be_quiet = 1; break; -//mdk-stage1// case 'v': -//mdk-stage1// verbose = 1; break; -//mdk-stage1// case 'o': -//mdk-stage1// one_pass = 1; break; -//mdk-stage1// case 'f': -//mdk-stage1// delay_fork = 1; break; -//mdk-stage1// case 'c': -//mdk-stage1// configpath = strdup(optarg); break; -//mdk-stage1// #ifdef __linux__ -//mdk-stage1// case 'd': -//mdk-stage1// do_modprobe = 1; break; -//mdk-stage1// case 'm': -//mdk-stage1// modpath = strdup(optarg); break; -//mdk-stage1// #endif -//mdk-stage1// case 'p': -//mdk-stage1// pidfile = strdup(optarg); break; -//mdk-stage1// case 's': -//mdk-stage1// stabfile = strdup(optarg); break; -//mdk-stage1// default: -//mdk-stage1// errflg = 1; break; -//mdk-stage1// } -//mdk-stage1// } -//mdk-stage1// if (errflg || (optind < argc)) { -//mdk-stage1// fprintf(stderr, "usage: %s [-V] [-q] [-v] [-d] [-o] [-f] " -//mdk-stage1// "[-c configpath] [-m modpath]\n " -//mdk-stage1// "[-p pidfile] [-s stabfile]\n", argv[0]); -//mdk-stage1// exit(EXIT_FAILURE); -//mdk-stage1// } -//mdk-stage1// -//mdk-stage1// #ifdef DEBUG -//mdk-stage1// openlog("cardmgr", LOG_PID|LOG_PERROR, LOG_DAEMON); -//mdk-stage1// #else -//mdk-stage1// openlog("cardmgr", LOG_PID|LOG_CONS, LOG_DAEMON); -//mdk-stage1// close(0); close(1); close(2); -//mdk-stage1// if (!delay_fork && !one_pass) -//mdk-stage1// fork_now(); -//mdk-stage1// #endif -//mdk-stage1// -//mdk-stage1// syslog(LOG_INFO, "starting, version is " CS_RELEASE); -//mdk-stage1// atexit(&done); -//mdk-stage1// putenv("PATH=/bin:/sbin:/usr/bin:/usr/sbin"); -//mdk-stage1// if (verbose) -//mdk-stage1// putenv("VERBOSE=1"); -//mdk-stage1// -//mdk-stage1// #ifdef __linux__ -//mdk-stage1// if (modpath == NULL) { -//mdk-stage1// if (access("/lib/modules/preferred", X_OK) == 0) -//mdk-stage1// modpath = "/lib/modules/preferred"; -//mdk-stage1// else { -//mdk-stage1// struct utsname utsname; -//mdk-stage1// if (uname(&utsname) != 0) { -//mdk-stage1// syslog(LOG_ERR, "uname(): %m"); -//mdk-stage1// exit(EXIT_FAILURE); -//mdk-stage1// } -//mdk-stage1// modpath = (char *)malloc(strlen(utsname.release)+14); -//mdk-stage1// sprintf(modpath, "/lib/modules/%s", utsname.release); -//mdk-stage1// } -//mdk-stage1// } -//mdk-stage1// if (access(modpath, X_OK) != 0) -//mdk-stage1// syslog(LOG_INFO, "cannot access %s: %m", modpath); -//mdk-stage1// /* We default to using modprobe if it is available */ -//mdk-stage1// do_modprobe |= (access("/sbin/modprobe", X_OK) == 0); -//mdk-stage1// #endif /* __linux__ */ -//mdk-stage1// -//mdk-stage1// load_config(); -//mdk-stage1// -//mdk-stage1// if (init_sockets() != 0) -//mdk-stage1// exit(EXIT_FAILURE); -//mdk-stage1// -//mdk-stage1// /* If we've gotten this far, then clean up pid and stab at exit */ -//mdk-stage1// write_pid(); -//mdk-stage1// write_stab(); -//mdk-stage1// cleanup_files = 1; -//mdk-stage1// -//mdk-stage1// if (signal(SIGHUP, catch_signal) == SIG_ERR) -//mdk-stage1// syslog(LOG_ERR, "signal(SIGHUP): %m"); -//mdk-stage1// if (signal(SIGTERM, catch_signal) == SIG_ERR) -//mdk-stage1// syslog(LOG_ERR, "signal(SIGTERM): %m"); -//mdk-stage1// if (signal(SIGINT, catch_signal) == SIG_ERR) -//mdk-stage1// syslog(LOG_ERR, "signal(SIGINT): %m"); -//mdk-stage1// #ifdef SIGPWR -//mdk-stage1// if (signal(SIGPWR, catch_signal) == SIG_ERR) -//mdk-stage1// syslog(LOG_ERR, "signal(SIGPWR): %m"); -//mdk-stage1// #endif -//mdk-stage1// -//mdk-stage1// for (i = max_fd = 0; i < sockets; i++) -//mdk-stage1// max_fd = (socket[i].fd > max_fd) ? socket[i].fd : max_fd; -//mdk-stage1// -//mdk-stage1// /* First select() call: poll, don't wait */ -//mdk-stage1// tv.tv_sec = tv.tv_usec = 0; -//mdk-stage1// -//mdk-stage1// /* Wait for sockets in setup-pending state to settle */ -//mdk-stage1// if (one_pass || delay_fork) -//mdk-stage1// wait_for_pending(); -//mdk-stage1// -//mdk-stage1// for (pass = 0; ; pass++) { -//mdk-stage1// FD_ZERO(&fds); -//mdk-stage1// for (i = 0; i < sockets; i++) -//mdk-stage1// FD_SET(socket[i].fd, &fds); -//mdk-stage1// -//mdk-stage1// while ((ret = select(max_fd+1, &fds, NULL, NULL, -//mdk-stage1// ((pass == 0) ? &tv : NULL))) < 0) { -//mdk-stage1// if (errno == EINTR) { -//mdk-stage1// handle_signal(); -//mdk-stage1// } else { -//mdk-stage1// syslog(LOG_ERR, "select(): %m"); -//mdk-stage1// exit(EXIT_FAILURE); -//mdk-stage1// } -//mdk-stage1// } -//mdk-stage1// -//mdk-stage1// for (i = 0; i < sockets; i++) { -//mdk-stage1// if (!FD_ISSET(socket[i].fd, &fds)) -//mdk-stage1// continue; -//mdk-stage1// ret = read(socket[i].fd, &event, 4); -//mdk-stage1// if ((ret == -1) && (errno != EAGAIN)) -//mdk-stage1// syslog(LOG_INFO, "read(%d): %m\n", i); -//mdk-stage1// if (ret != 4) -//mdk-stage1// continue; -//mdk-stage1// -//mdk-stage1// switch (event) { -//mdk-stage1// case CS_EVENT_CARD_REMOVAL: -//mdk-stage1// socket[i].state = 0; -//mdk-stage1// do_remove(i); -//mdk-stage1// break; -//mdk-stage1// case CS_EVENT_EJECTION_REQUEST: -//mdk-stage1// ret = do_check(i); -//mdk-stage1// if (ret == 0) { -//mdk-stage1// socket[i].state = 0; -//mdk-stage1// do_remove(i); -//mdk-stage1// } -//mdk-stage1// write(socket[i].fd, &ret, 4); -//mdk-stage1// break; -//mdk-stage1// case CS_EVENT_CARD_INSERTION: -//mdk-stage1// case CS_EVENT_INSERTION_REQUEST: -//mdk-stage1// socket[i].state |= SOCKET_PRESENT; -//mdk-stage1// case CS_EVENT_CARD_RESET: -//mdk-stage1// socket[i].state |= SOCKET_READY; -//mdk-stage1// do_insert(i); -//mdk-stage1// break; -//mdk-stage1// case CS_EVENT_RESET_PHYSICAL: -//mdk-stage1// socket[i].state &= ~SOCKET_READY; -//mdk-stage1// break; -//mdk-stage1// case CS_EVENT_PM_SUSPEND: -//mdk-stage1// do_suspend(i); -//mdk-stage1// break; -//mdk-stage1// case CS_EVENT_PM_RESUME: -//mdk-stage1// do_resume(i); -//mdk-stage1// break; -//mdk-stage1// } -//mdk-stage1// -//mdk-stage1// } -//mdk-stage1// -//mdk-stage1// if (one_pass) -//mdk-stage1// exit(EXIT_SUCCESS); -//mdk-stage1// if (delay_fork) { -//mdk-stage1// fork_now(); -//mdk-stage1// write_pid(); -//mdk-stage1// } -//mdk-stage1// -//mdk-stage1// } /* repeat */ -//mdk-stage1// return 0; -//mdk-stage1// } - - - -static void cardmgr_fail(void) -{ - log_message("CM: cardmgr: failed"); -} - -int cardmgr_call(void) -{ - int i, max_fd, ret, event; - struct timeval tv; - fd_set fds; - - stabfile = "/var/run/stab"; - - log_message("CM: cardmgr/hacked starting, version is " CS_RELEASE); - - if (load_config()) { - cardmgr_fail(); - return -1; - } - - if (init_sockets()) { - cardmgr_fail(); - return -1; - } - - /* If we've gotten this far, then clean up pid and stab at exit */ - write_stab(); - - for (i = max_fd = 0; i < sockets; i++) - max_fd = (socket[i].fd > max_fd) ? socket[i].fd : max_fd; - - /* First select() call: poll, don't wait */ - tv.tv_sec = tv.tv_usec = 0; - - /* Wait for sockets in setup-pending state to settle */ - wait_for_pending(); - - - FD_ZERO(&fds); - for (i = 0; i < sockets; i++) - FD_SET(socket[i].fd, &fds); - - if (select(max_fd+1, &fds, NULL, NULL, &tv) < 0) { - log_perror("CM: select fails"); - return -1; - } - - for (i = 0; i < sockets; i++) { - if (!FD_ISSET(socket[i].fd, &fds)) - continue; - ret = read(socket[i].fd, &event, 4); - if ((ret == -1) && (errno != EAGAIN)) - log_message("CM: read(%d): %m", i); - if (ret != 4) - continue; - - switch (event) { - case CS_EVENT_CARD_INSERTION: - case CS_EVENT_INSERTION_REQUEST: - socket[i].state |= SOCKET_PRESENT; - case CS_EVENT_CARD_RESET: - socket[i].state |= SOCKET_READY; - do_insert(i); - break; - case CS_EVENT_RESET_PHYSICAL: - socket[i].state &= ~SOCKET_READY; - break; - } - - } - - return 0; - -} diff --git a/mdk-stage1/pcmcia_/cardmgr.h b/mdk-stage1/pcmcia_/cardmgr.h deleted file mode 100644 index 1d002e972..000000000 --- a/mdk-stage1/pcmcia_/cardmgr.h +++ /dev/null @@ -1,112 +0,0 @@ -/* - * cardmgr.h 1.37 2001/08/24 12:19:20 - * - * The contents of this file are subject to the Mozilla Public License - * Version 1.1 (the "License"); you may not use this file except in - * compliance with the License. You may obtain a copy of the License - * at http://www.mozilla.org/MPL/ - * - * Software distributed under the License is distributed on an "AS IS" - * basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See - * the License for the specific language governing rights and - * limitations under the License. - * - * The initial developer of the original code is David A. Hinds - * <dahinds@users.sourceforge.net>. Portions created by David A. Hinds - * are Copyright (C) 1999 David A. Hinds. All Rights Reserved. - * - * Alternatively, the contents of this file may be used under the - * terms of the GNU General Public License version 2 (the "GPL"), in - * which case the provisions of the GPL are applicable instead of the - * above. If you wish to allow the use of your version of this file - * only under the terms of the GPL and not to allow others to use - * your version of this file under the MPL, indicate your decision by - * deleting the provisions above and replace them with the notice and - * other provisions required by the GPL. If you do not delete the - * provisions above, a recipient may use your version of this file - * under either the MPL or the GPL. - */ - -#define MAX_SOCKS 8 -#define MAX_BINDINGS 4 -#define MAX_MODULES 4 - -typedef struct adjust_list_t { - adjust_t adj; - struct adjust_list_t *next; -} adjust_list_t; - -typedef struct func_ident_t { - u_char funcid; -} func_ident_t; - -typedef struct manfid_ident_t { - u_short manf; - u_short card; -} manfid_ident_t; - -typedef struct vers_ident_t { - int ns; - char *pi[4]; -} vers_ident_t; - -typedef struct tuple_ident_t { - cisdata_t code; - long ofs; - char *info; -} tuple_ident_t; - -typedef struct device_info_t { - dev_info_t dev_info; - int needs_mtd; - int modules; - char *module[MAX_MODULES]; - char *opts[MAX_MODULES]; - char *class; - int refs; - struct device_info_t *next; -} device_info_t; - -#define VERS_1_IDENT 0x0001 -#define MANFID_IDENT 0x0002 -#define TUPLE_IDENT 0x0010 -#define FUNC_IDENT 0x0020 -#define BLANK_IDENT 0x0040 -#define PCI_IDENT 0x0080 -#define EXCL_IDENT 0x00f0 - -typedef struct card_info_t { - char *name; - int ident_type; - union { - vers_ident_t vers; - tuple_ident_t tuple; - func_ident_t func; - } id; - manfid_ident_t manfid; - int bindings; - device_info_t *device[MAX_BINDINGS]; - int dev_fn[MAX_BINDINGS]; - char *cis_file; - int refs; - struct card_info_t *next; -} card_info_t; - -typedef struct mtd_ident_t { - char *name; - enum { - JEDEC_MTD=1, DTYPE_MTD, DEFAULT_MTD - } mtd_type; - int dtype, jedec_mfr, jedec_info; - char *module, *opts; - int refs; - struct mtd_ident_t *next; -} mtd_ident_t; - -extern adjust_list_t *root_adjust; -extern device_info_t *root_device; -extern card_info_t *blank_card; -extern card_info_t *root_card, *root_func; -extern mtd_ident_t *root_mtd, *default_mtd; - -int parse_configfile(char *fn); diff --git a/mdk-stage1/pcmcia_/lex_config.c b/mdk-stage1/pcmcia_/lex_config.c deleted file mode 100644 index 2f990618d..000000000 --- a/mdk-stage1/pcmcia_/lex_config.c +++ /dev/null @@ -1,2053 +0,0 @@ -/* A lexical scanner generated by flex */ - -/* Scanner skeleton version: - * $Header$ - */ - -#define FLEX_SCANNER -#define YY_FLEX_MAJOR_VERSION 2 -#define YY_FLEX_MINOR_VERSION 5 - -#include <stdio.h> - - -/* cfront 1.2 defines "c_plusplus" instead of "__cplusplus" */ -#ifdef c_plusplus -#ifndef __cplusplus -#define __cplusplus -#endif -#endif - - -#ifdef __cplusplus - -#include <stdlib.h> -#include <unistd.h> - -/* Use prototypes in function declarations. */ -#define YY_USE_PROTOS - -/* The "const" storage-class-modifier is valid. */ -#define YY_USE_CONST - -#else /* ! __cplusplus */ - -#if __STDC__ - -#define YY_USE_PROTOS -#define YY_USE_CONST - -#endif /* __STDC__ */ -#endif /* ! __cplusplus */ - -#ifdef __TURBOC__ - #pragma warn -rch - #pragma warn -use -#include <io.h> -#include <stdlib.h> -#define YY_USE_CONST -#define YY_USE_PROTOS -#endif - -#ifdef YY_USE_CONST -#define yyconst const -#else -#define yyconst -#endif - - -#ifdef YY_USE_PROTOS -#define YY_PROTO(proto) proto -#else -#define YY_PROTO(proto) () -#endif - -/* Returned upon end-of-file. */ -#define YY_NULL 0 - -/* Promotes a possibly negative, possibly signed char to an unsigned - * integer for use as an array index. If the signed char is negative, - * we want to instead treat it as an 8-bit unsigned char, hence the - * double cast. - */ -#define YY_SC_TO_UI(c) ((unsigned int) (unsigned char) c) - -/* Enter a start condition. This macro really ought to take a parameter, - * but we do it the disgusting crufty way forced on us by the ()-less - * definition of BEGIN. - */ -#define BEGIN yy_start = 1 + 2 * - -/* Translate the current start state into a value that can be later handed - * to BEGIN to return to the state. The YYSTATE alias is for lex - * compatibility. - */ -#define YY_START ((yy_start - 1) / 2) -#define YYSTATE YY_START - -/* Action number for EOF rule of a given start state. */ -#define YY_STATE_EOF(state) (YY_END_OF_BUFFER + state + 1) - -/* Special action meaning "start processing a new file". */ -#define YY_NEW_FILE yyrestart( yyin ) - -#define YY_END_OF_BUFFER_CHAR 0 - -/* Size of default input buffer. */ -#define YY_BUF_SIZE 16384 - -typedef struct yy_buffer_state *YY_BUFFER_STATE; - -extern int yyleng; -extern FILE *yyin, *yyout; - -#define EOB_ACT_CONTINUE_SCAN 0 -#define EOB_ACT_END_OF_FILE 1 -#define EOB_ACT_LAST_MATCH 2 - -/* The funky do-while in the following #define is used to turn the definition - * int a single C statement (which needs a semi-colon terminator). This - * avoids problems with code like: - * - * if ( condition_holds ) - * yyless( 5 ); - * else - * do_something_else(); - * - * Prior to using the do-while the compiler would get upset at the - * "else" because it interpreted the "if" statement as being all - * done when it reached the ';' after the yyless() call. - */ - -/* Return all but the first 'n' matched characters back to the input stream. */ - -#define yyless(n) \ - do \ - { \ - /* Undo effects of setting up yytext. */ \ - *yy_cp = yy_hold_char; \ - YY_RESTORE_YY_MORE_OFFSET \ - yy_c_buf_p = yy_cp = yy_bp + n - YY_MORE_ADJ; \ - YY_DO_BEFORE_ACTION; /* set up yytext again */ \ - } \ - while ( 0 ) - -//mdk-stage1// #define unput(c) yyunput( c, yytext_ptr ) - -/* The following is because we cannot portably get our hands on size_t - * (without autoconf's help, which isn't available because we want - * flex-generated scanners to compile on their own). - */ -typedef unsigned int yy_size_t; - - -struct yy_buffer_state - { - FILE *yy_input_file; - - char *yy_ch_buf; /* input buffer */ - char *yy_buf_pos; /* current position in input buffer */ - - /* Size of input buffer in bytes, not including room for EOB - * characters. - */ - yy_size_t yy_buf_size; - - /* Number of characters read into yy_ch_buf, not including EOB - * characters. - */ - int yy_n_chars; - - /* Whether we "own" the buffer - i.e., we know we created it, - * and can realloc() it to grow it, and should free() it to - * delete it. - */ - int yy_is_our_buffer; - - /* Whether this is an "interactive" input source; if so, and - * if we're using stdio for input, then we want to use getc() - * instead of fread(), to make sure we stop fetching input after - * each newline. - */ - int yy_is_interactive; - - /* Whether we're considered to be at the beginning of a line. - * If so, '^' rules will be active on the next match, otherwise - * not. - */ - int yy_at_bol; - - /* Whether to try to fill the input buffer when we reach the - * end of it. - */ - int yy_fill_buffer; - - int yy_buffer_status; -#define YY_BUFFER_NEW 0 -#define YY_BUFFER_NORMAL 1 - /* When an EOF's been seen but there's still some text to process - * then we mark the buffer as YY_EOF_PENDING, to indicate that we - * shouldn't try reading from the input source any more. We might - * still have a bunch of tokens to match, though, because of - * possible backing-up. - * - * When we actually see the EOF, we change the status to "new" - * (via yyrestart()), so that the user can continue scanning by - * just pointing yyin at a new input file. - */ -#define YY_BUFFER_EOF_PENDING 2 - }; - -static YY_BUFFER_STATE yy_current_buffer = 0; - -/* We provide macros for accessing buffer states in case in the - * future we want to put the buffer states in a more general - * "scanner state". - */ -#define YY_CURRENT_BUFFER yy_current_buffer - - -/* yy_hold_char holds the character lost when yytext is formed. */ -static char yy_hold_char; - -static int yy_n_chars; /* number of characters read into yy_ch_buf */ - - -int yyleng; - -/* Points to current character in buffer. */ -static char *yy_c_buf_p = (char *) 0; -static int yy_init = 1; /* whether we need to initialize */ -static int yy_start = 0; /* start state number */ - -/* Flag which is used to allow yywrap()'s to do buffer switches - * instead of setting up a fresh yyin. A bit of a hack ... - */ -static int yy_did_buffer_switch_on_eof; - -void yyrestart YY_PROTO(( FILE *input_file )); - -void yy_switch_to_buffer YY_PROTO(( YY_BUFFER_STATE new_buffer )); -void yy_load_buffer_state YY_PROTO(( void )); -YY_BUFFER_STATE yy_create_buffer YY_PROTO(( FILE *file, int size )); -void yy_delete_buffer YY_PROTO(( YY_BUFFER_STATE b )); -void yy_init_buffer YY_PROTO(( YY_BUFFER_STATE b, FILE *file )); -void yy_flush_buffer YY_PROTO(( YY_BUFFER_STATE b )); -#define YY_FLUSH_BUFFER yy_flush_buffer( yy_current_buffer ) - -YY_BUFFER_STATE yy_scan_buffer YY_PROTO(( char *base, yy_size_t size )); -YY_BUFFER_STATE yy_scan_string YY_PROTO(( yyconst char *yy_str )); -YY_BUFFER_STATE yy_scan_bytes YY_PROTO(( yyconst char *bytes, int len )); - -static void *yy_flex_alloc YY_PROTO(( yy_size_t )); -static void *yy_flex_realloc YY_PROTO(( void *, yy_size_t )); -static void yy_flex_free YY_PROTO(( void * )); - -#define yy_new_buffer yy_create_buffer - -#define yy_set_interactive(is_interactive) \ - { \ - if ( ! yy_current_buffer ) \ - yy_current_buffer = yy_create_buffer( yyin, YY_BUF_SIZE ); \ - yy_current_buffer->yy_is_interactive = is_interactive; \ - } - -#define yy_set_bol(at_bol) \ - { \ - if ( ! yy_current_buffer ) \ - yy_current_buffer = yy_create_buffer( yyin, YY_BUF_SIZE ); \ - yy_current_buffer->yy_at_bol = at_bol; \ - } - -#define YY_AT_BOL() (yy_current_buffer->yy_at_bol) - -typedef unsigned char YY_CHAR; -FILE *yyin = (FILE *) 0, *yyout = (FILE *) 0; -typedef int yy_state_type; -extern char *yytext; -#define yytext_ptr yytext - -static yy_state_type yy_get_previous_state YY_PROTO(( void )); -static yy_state_type yy_try_NUL_trans YY_PROTO(( yy_state_type current_state )); -static int yy_get_next_buffer YY_PROTO(( void )); -static void yy_fatal_error YY_PROTO(( yyconst char msg[] )); - -/* Done after the current pattern has been matched and before the - * corresponding action - sets up yytext. - */ -#define YY_DO_BEFORE_ACTION \ - yytext_ptr = yy_bp; \ - yyleng = (int) (yy_cp - yy_bp); \ - yy_hold_char = *yy_cp; \ - *yy_cp = '\0'; \ - yy_c_buf_p = yy_cp; - -#define YY_NUM_RULES 45 -#define YY_END_OF_BUFFER 46 -static yyconst short int yy_accept[247] = - { 0, - 5, 5, 2, 2, 46, 44, 5, 4, 5, 44, - 6, 41, 41, 44, 44, 44, 44, 44, 44, 44, - 44, 44, 44, 44, 44, 44, 44, 44, 44, 3, - 2, 45, 5, 5, 6, 0, 43, 0, 6, 41, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 30, 0, - 0, 0, 3, 2, 0, 43, 0, 42, 0, 0, - 0, 0, 9, 0, 0, 0, 0, 0, 0, 0, - 0, 18, 0, 0, 0, 0, 23, 0, 0, 0, - - 0, 26, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 8, 10, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 25, - 0, 27, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 11, 0, 0, 14, 0, 0, 0, 0, - 19, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 31, 0, 0, 0, 0, 0, 13, 0, - 0, 0, 0, 20, 21, 22, 0, 0, 0, 28, - 0, 0, 0, 1, 0, 0, 0, 0, 12, 15, - 0, 0, 17, 0, 0, 0, 0, 29, 0, 0, - - 32, 0, 0, 0, 0, 16, 0, 0, 0, 0, - 0, 0, 0, 39, 7, 0, 0, 24, 0, 0, - 0, 0, 0, 36, 0, 0, 0, 0, 0, 0, - 33, 0, 0, 0, 34, 0, 0, 0, 40, 0, - 0, 35, 37, 0, 38, 0 - } ; - -static yyconst int yy_ec[256] = - { 0, - 1, 1, 1, 1, 1, 1, 1, 1, 2, 3, - 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, - 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, - 1, 4, 1, 5, 6, 1, 1, 1, 1, 1, - 1, 1, 1, 1, 1, 1, 1, 7, 8, 8, - 8, 8, 8, 8, 8, 8, 8, 1, 6, 1, - 1, 1, 1, 1, 9, 9, 9, 9, 9, 9, - 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, - 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, - 1, 10, 1, 1, 11, 1, 12, 13, 14, 15, - - 16, 17, 18, 1, 19, 20, 21, 22, 23, 24, - 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, - 35, 1, 1, 1, 1, 1, 1, 1, 1, 1, - 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, - 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, - 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, - 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, - 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, - 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, - 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, - - 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, - 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, - 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, - 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, - 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, - 1, 1, 1, 1, 1 - } ; - -static yyconst int yy_meta[36] = - { 0, - 1, 2, 3, 2, 1, 1, 4, 4, 4, 1, - 1, 4, 4, 4, 4, 4, 4, 1, 1, 1, - 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, - 1, 1, 1, 1, 1 - } ; - -static yyconst short int yy_base[253] = - { 0, - 0, 0, 34, 37, 293, 294, 40, 294, 41, 41, - 0, 41, 45, 31, 273, 42, 40, 257, 38, 34, - 274, 47, 273, 262, 53, 271, 57, 35, 60, 0, - 79, 294, 82, 83, 0, 83, 294, 87, 0, 87, - 0, 263, 260, 260, 255, 253, 269, 74, 245, 265, - 244, 253, 262, 248, 259, 249, 249, 256, 255, 80, - 239, 240, 248, 238, 80, 236, 236, 232, 294, 236, - 233, 245, 0, 97, 95, 97, 108, 0, 230, 234, - 242, 241, 294, 226, 242, 234, 226, 229, 234, 235, - 226, 294, 231, 229, 220, 213, 294, 228, 209, 212, - - 228, 294, 209, 219, 221, 217, 216, 206, 211, 203, - 215, 219, 194, 294, 294, 199, 196, 212, 209, 193, - 208, 192, 190, 206, 200, 190, 195, 187, 190, 294, - 192, 294, 188, 184, 200, 198, 195, 192, 188, 181, - 191, 181, 294, 181, 186, 294, 186, 189, 180, 183, - 294, 182, 161, 179, 183, 165, 170, 167, 158, 177, - 166, 171, 294, 161, 174, 172, 158, 152, 294, 165, - 165, 154, 162, 294, 166, 294, 153, 154, 158, 294, - 157, 157, 160, 294, 146, 157, 140, 136, 294, 294, - 147, 141, 294, 150, 133, 151, 139, 294, 148, 133, - - 294, 143, 142, 127, 126, 294, 142, 138, 140, 140, - 124, 124, 136, 294, 294, 126, 118, 294, 130, 118, - 113, 114, 115, 294, 125, 127, 108, 116, 99, 87, - 294, 90, 87, 86, 294, 96, 78, 74, 294, 75, - 64, 294, 294, 46, 294, 294, 118, 122, 126, 130, - 134, 64 - } ; - -static yyconst short int yy_def[253] = - { 0, - 246, 1, 247, 247, 246, 246, 246, 246, 246, 248, - 249, 246, 246, 246, 246, 246, 246, 246, 246, 246, - 246, 246, 246, 246, 246, 246, 246, 246, 246, 250, - 246, 246, 246, 246, 249, 248, 246, 251, 249, 246, - 252, 246, 246, 246, 246, 246, 246, 246, 246, 246, - 246, 246, 246, 246, 246, 246, 246, 246, 246, 246, - 246, 246, 246, 246, 246, 246, 246, 246, 246, 246, - 246, 246, 250, 246, 248, 248, 251, 252, 246, 246, - 246, 246, 246, 246, 246, 246, 246, 246, 246, 246, - 246, 246, 246, 246, 246, 246, 246, 246, 246, 246, - - 246, 246, 246, 246, 246, 246, 246, 246, 246, 246, - 246, 246, 246, 246, 246, 246, 246, 246, 246, 246, - 246, 246, 246, 246, 246, 246, 246, 246, 246, 246, - 246, 246, 246, 246, 246, 246, 246, 246, 246, 246, - 246, 246, 246, 246, 246, 246, 246, 246, 246, 246, - 246, 246, 246, 246, 246, 246, 246, 246, 246, 246, - 246, 246, 246, 246, 246, 246, 246, 246, 246, 246, - 246, 246, 246, 246, 246, 246, 246, 246, 246, 246, - 246, 246, 246, 246, 246, 246, 246, 246, 246, 246, - 246, 246, 246, 246, 246, 246, 246, 246, 246, 246, - - 246, 246, 246, 246, 246, 246, 246, 246, 246, 246, - 246, 246, 246, 246, 246, 246, 246, 246, 246, 246, - 246, 246, 246, 246, 246, 246, 246, 246, 246, 246, - 246, 246, 246, 246, 246, 246, 246, 246, 246, 246, - 246, 246, 246, 246, 246, 0, 246, 246, 246, 246, - 246, 246 - } ; - -static yyconst short int yy_nxt[330] = - { 0, - 6, 7, 8, 9, 10, 11, 12, 13, 6, 6, - 6, 14, 15, 16, 17, 18, 19, 6, 20, 21, - 6, 6, 22, 23, 24, 25, 6, 26, 27, 28, - 6, 29, 6, 6, 6, 31, 32, 31, 31, 32, - 31, 33, 33, 33, 34, 37, 35, 40, 40, 42, - 38, 40, 40, 45, 43, 48, 51, 53, 56, 69, - 46, 54, 57, 47, 62, 70, 63, 78, 52, 49, - 66, 58, 67, 245, 41, 71, 59, 64, 72, 244, - 74, 68, 74, 33, 33, 33, 34, 37, 35, 36, - 85, 76, 38, 40, 40, 98, 77, 104, 74, 37, - - 74, 37, 243, 242, 38, 86, 38, 241, 105, 99, - 36, 240, 76, 239, 238, 237, 236, 77, 30, 30, - 30, 30, 36, 36, 36, 36, 39, 39, 235, 39, - 73, 234, 233, 73, 75, 75, 75, 75, 232, 231, - 230, 229, 228, 227, 226, 225, 224, 223, 222, 221, - 220, 219, 218, 217, 216, 215, 214, 213, 212, 211, - 210, 209, 208, 207, 206, 205, 204, 203, 202, 201, - 200, 199, 198, 197, 196, 195, 194, 193, 192, 191, - 190, 189, 188, 187, 186, 185, 184, 183, 182, 181, - 180, 179, 178, 177, 176, 175, 174, 173, 172, 171, - - 170, 169, 168, 167, 166, 165, 164, 163, 162, 161, - 160, 159, 158, 157, 156, 155, 154, 153, 152, 151, - 150, 149, 148, 147, 146, 145, 144, 143, 142, 141, - 140, 139, 138, 137, 136, 135, 134, 133, 132, 131, - 130, 129, 128, 127, 126, 125, 124, 123, 122, 121, - 120, 119, 118, 117, 116, 115, 114, 113, 112, 111, - 110, 109, 108, 107, 106, 103, 102, 101, 100, 97, - 96, 95, 94, 93, 92, 91, 90, 89, 88, 87, - 84, 83, 82, 81, 80, 79, 65, 61, 60, 55, - 50, 44, 246, 5, 246, 246, 246, 246, 246, 246, - - 246, 246, 246, 246, 246, 246, 246, 246, 246, 246, - 246, 246, 246, 246, 246, 246, 246, 246, 246, 246, - 246, 246, 246, 246, 246, 246, 246, 246, 246 - } ; - -static yyconst short int yy_chk[330] = - { 0, - 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, - 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, - 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, - 1, 1, 1, 1, 1, 3, 3, 3, 4, 4, - 4, 7, 9, 7, 9, 10, 9, 12, 12, 14, - 10, 13, 13, 16, 14, 17, 19, 20, 22, 28, - 16, 20, 22, 16, 25, 28, 25, 252, 19, 17, - 27, 22, 27, 244, 12, 29, 22, 25, 29, 241, - 31, 27, 31, 33, 34, 33, 34, 36, 34, 38, - 48, 38, 36, 40, 40, 60, 38, 65, 74, 75, - - 74, 76, 240, 238, 75, 48, 76, 237, 65, 60, - 77, 236, 77, 234, 233, 232, 230, 77, 247, 247, - 247, 247, 248, 248, 248, 248, 249, 249, 229, 249, - 250, 228, 227, 250, 251, 251, 251, 251, 226, 225, - 223, 222, 221, 220, 219, 217, 216, 213, 212, 211, - 210, 209, 208, 207, 205, 204, 203, 202, 200, 199, - 197, 196, 195, 194, 192, 191, 188, 187, 186, 185, - 183, 182, 181, 179, 178, 177, 175, 173, 172, 171, - 170, 168, 167, 166, 165, 164, 162, 161, 160, 159, - 158, 157, 156, 155, 154, 153, 152, 150, 149, 148, - - 147, 145, 144, 142, 141, 140, 139, 138, 137, 136, - 135, 134, 133, 131, 129, 128, 127, 126, 125, 124, - 123, 122, 121, 120, 119, 118, 117, 116, 113, 112, - 111, 110, 109, 108, 107, 106, 105, 104, 103, 101, - 100, 99, 98, 96, 95, 94, 93, 91, 90, 89, - 88, 87, 86, 85, 84, 82, 81, 80, 79, 72, - 71, 70, 68, 67, 66, 64, 63, 62, 61, 59, - 58, 57, 56, 55, 54, 53, 52, 51, 50, 49, - 47, 46, 45, 44, 43, 42, 26, 24, 23, 21, - 18, 15, 5, 246, 246, 246, 246, 246, 246, 246, - - 246, 246, 246, 246, 246, 246, 246, 246, 246, 246, - 246, 246, 246, 246, 246, 246, 246, 246, 246, 246, - 246, 246, 246, 246, 246, 246, 246, 246, 246 - } ; - -static yy_state_type yy_last_accepting_state; -static char *yy_last_accepting_cpos; - -/* The intent behind this definition is that it'll catch - * any uses of REJECT which flex missed. - */ -#define REJECT reject_used_but_not_detected -#define yymore() yymore_used_but_not_detected -#define YY_MORE_ADJ 0 -#define YY_RESTORE_YY_MORE_OFFSET -char *yytext; -#line 1 "lex_config.l" -#define INITIAL 0 -/* Special state for handling include files */ -#define src 1 - -#line 5 "lex_config.l" -/* - * lex_config.l 1.40 2001/08/24 12:21:25 - * - * The contents of this file are subject to the Mozilla Public License - * Version 1.1 (the "License"); you may not use this file except in - * compliance with the License. You may obtain a copy of the License - * at http://www.mozilla.org/MPL/ - * - * Software distributed under the License is distributed on an "AS IS" - * basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See - * the License for the specific language governing rights and - * limitations under the License. - * - * The initial developer of the original code is David A. Hinds - * <dahinds@users.sourceforge.net>. Portions created by David A. Hinds - * are Copyright (C) 1999 David A. Hinds. All Rights Reserved. - * - * Alternatively, the contents of this file may be used under the - * terms of the GNU General Public License version 2 (the "GPL"), in - * which case the provisions of the GPL are applicable instead of the - * above. If you wish to allow the use of your version of this file - * only under the terms of the GPL and not to allow others to use - * your version of this file under the MPL, indicate your decision by - * deleting the provisions above and replace them with the notice and - * other provisions required by the GPL. If you do not delete the - * provisions above, a recipient may use your version of this file - * under either the MPL or the GPL. - */ - -#undef src -#include <stdio.h> -#include <stdlib.h> -#include <unistd.h> -#include <string.h> -#include <syslog.h> -#include <glob.h> -#define src 1 - -#include <pcmcia_/cs_types.h> -#include <pcmcia_/cs.h> - -#include "yacc_config.h" - -/* For assembling nice error messages */ -char *current_file; -int current_lineno; - -static int lex_number(char *s); -static int lex_string(char *s); -static void do_source(char *fn); -static int do_eof(void); - - -/* Macros after this point can all be overridden by user definitions in - * section 1. - */ - -#ifndef YY_SKIP_YYWRAP -#ifdef __cplusplus -extern "C" int yywrap YY_PROTO(( void )); -#else -extern int yywrap YY_PROTO(( void )); -#endif -#endif - -#ifndef YY_NO_UNPUT -//mdk-stage1// static void yyunput YY_PROTO(( int c, char *buf_ptr )); -#endif - -#ifndef yytext_ptr -static void yy_flex_strncpy YY_PROTO(( char *, yyconst char *, int )); -#endif - -#ifdef YY_NEED_STRLEN -static int yy_flex_strlen YY_PROTO(( yyconst char * )); -#endif - -#ifndef YY_NO_INPUT -#ifdef __cplusplus -static int yyinput YY_PROTO(( void )); -#else -static int input YY_PROTO(( void )); -#endif -#endif - -#if YY_STACK_USED -static int yy_start_stack_ptr = 0; -static int yy_start_stack_depth = 0; -static int *yy_start_stack = 0; -#ifndef YY_NO_PUSH_STATE -static void yy_push_state YY_PROTO(( int new_state )); -#endif -#ifndef YY_NO_POP_STATE -static void yy_pop_state YY_PROTO(( void )); -#endif -#ifndef YY_NO_TOP_STATE -static int yy_top_state YY_PROTO(( void )); -#endif - -#else -#define YY_NO_PUSH_STATE 1 -#define YY_NO_POP_STATE 1 -#define YY_NO_TOP_STATE 1 -#endif - -#ifdef YY_MALLOC_DECL -YY_MALLOC_DECL -#else -#if __STDC__ -#ifndef __cplusplus -#include <stdlib.h> -#endif -#else -/* Just try to get by without declaring the routines. This will fail - * miserably on non-ANSI systems for which sizeof(size_t) != sizeof(int) - * or sizeof(void*) != sizeof(int). - */ -#endif -#endif - -/* Amount of stuff to slurp up with each read. */ -#ifndef YY_READ_BUF_SIZE -#define YY_READ_BUF_SIZE 8192 -#endif - -/* Copy whatever the last rule matched to the standard output. */ - -#ifndef ECHO -/* This used to be an fputs(), but since the string might contain NUL's, - * we now use fwrite(). - */ -#define ECHO (void) fwrite( yytext, yyleng, 1, yyout ) -#endif - -/* Gets input and stuffs it into "buf". number of characters read, or YY_NULL, - * is returned in "result". - */ -#ifndef YY_INPUT -#define YY_INPUT(buf,result,max_size) \ - if ( yy_current_buffer->yy_is_interactive ) \ - { \ - int c = '*', n; \ - for ( n = 0; n < max_size && \ - (c = getc( yyin )) != EOF && c != '\n'; ++n ) \ - buf[n] = (char) c; \ - if ( c == '\n' ) \ - buf[n++] = (char) c; \ - if ( c == EOF && ferror( yyin ) ) \ - YY_FATAL_ERROR( "input in flex scanner failed" ); \ - result = n; \ - } \ - else if ( ((result = fread( buf, 1, max_size, yyin )) == 0) \ - && ferror( yyin ) ) \ - YY_FATAL_ERROR( "input in flex scanner failed" ); -#endif - -/* No semi-colon after return; correct usage is to write "yyterminate();" - - * we don't want an extra ';' after the "return" because that will cause - * some compilers to complain about unreachable statements. - */ -#ifndef yyterminate -#define yyterminate() return YY_NULL -#endif - -/* Number of entries by which start-condition stack grows. */ -#ifndef YY_START_STACK_INCR -#define YY_START_STACK_INCR 25 -#endif - -/* Report a fatal error. */ -#ifndef YY_FATAL_ERROR -#define YY_FATAL_ERROR(msg) yy_fatal_error( msg ) -#endif - -/* Default declaration of generated scanner - a define so the user can - * easily add parameters. - */ -#ifndef YY_DECL -#define YY_DECL int yylex YY_PROTO(( void )) -#endif - -/* Code executed at the beginning of each rule, after yytext and yyleng - * have been set up. - */ -#ifndef YY_USER_ACTION -#define YY_USER_ACTION -#endif - -/* Code executed at the end of each rule. */ -#ifndef YY_BREAK -#define YY_BREAK break; -#endif - -#define YY_RULE_SETUP \ - YY_USER_ACTION - -YY_DECL - { - register yy_state_type yy_current_state; - register char *yy_cp = NULL, *yy_bp = NULL; - register int yy_act; - -#line 63 "lex_config.l" - - - - if ( yy_init ) - { - yy_init = 0; - -#ifdef YY_USER_INIT - YY_USER_INIT; -#endif - - if ( ! yy_start ) - yy_start = 1; /* first start state */ - - if ( ! yyin ) - yyin = stdin; - - if ( ! yyout ) - yyout = stdout; - - if ( ! yy_current_buffer ) - yy_current_buffer = - yy_create_buffer( yyin, YY_BUF_SIZE ); - - yy_load_buffer_state(); - } - - while ( 1 ) /* loops until end-of-file is reached */ - { - yy_cp = yy_c_buf_p; - - /* Support of yytext. */ - *yy_cp = yy_hold_char; - - /* yy_bp points to the position in yy_ch_buf of the start of - * the current run. - */ - yy_bp = yy_cp; - - yy_current_state = yy_start; -yy_match: - do - { - register YY_CHAR yy_c = yy_ec[YY_SC_TO_UI(*yy_cp)]; - if ( yy_accept[yy_current_state] ) - { - yy_last_accepting_state = yy_current_state; - yy_last_accepting_cpos = yy_cp; - } - while ( yy_chk[yy_base[yy_current_state] + yy_c] != yy_current_state ) - { - yy_current_state = (int) yy_def[yy_current_state]; - if ( yy_current_state >= 247 ) - yy_c = yy_meta[(unsigned int) yy_c]; - } - yy_current_state = yy_nxt[yy_base[yy_current_state] + (unsigned int) yy_c]; - ++yy_cp; - } - while ( yy_base[yy_current_state] != 294 ); - -yy_find_action: - yy_act = yy_accept[yy_current_state]; - if ( yy_act == 0 ) - { /* have to back up */ - yy_cp = yy_last_accepting_cpos; - yy_current_state = yy_last_accepting_state; - yy_act = yy_accept[yy_current_state]; - } - - YY_DO_BEFORE_ACTION; - - -do_action: /* This label is used only to access EOF actions. */ - - - switch ( yy_act ) - { /* beginning of action switch */ - case 0: /* must back up */ - /* undo the effects of YY_DO_BEFORE_ACTION */ - *yy_cp = yy_hold_char; - yy_cp = yy_last_accepting_cpos; - yy_current_state = yy_last_accepting_state; - goto yy_find_action; - -case 1: -YY_RULE_SETUP -#line 65 "lex_config.l" -BEGIN(src); - YY_BREAK -case 2: -YY_RULE_SETUP -#line 66 "lex_config.l" -/* skip */ ; - YY_BREAK -case 3: -YY_RULE_SETUP -#line 67 "lex_config.l" -do_source(yytext); BEGIN(INITIAL); - YY_BREAK -case YY_STATE_EOF(INITIAL): -case YY_STATE_EOF(src): -#line 68 "lex_config.l" -if (do_eof()) yyterminate(); - YY_BREAK -case 4: -YY_RULE_SETUP -#line 70 "lex_config.l" -current_lineno++; - YY_BREAK -case 5: -YY_RULE_SETUP -#line 71 "lex_config.l" -/* skip */ ; - YY_BREAK -case 6: -YY_RULE_SETUP -#line 72 "lex_config.l" -/* skip */ ; - YY_BREAK -case 7: -YY_RULE_SETUP -#line 74 "lex_config.l" -return ANONYMOUS; - YY_BREAK -case 8: -YY_RULE_SETUP -#line 75 "lex_config.l" -return BIND; - YY_BREAK -case 9: -YY_RULE_SETUP -#line 76 "lex_config.l" -return CIS; - YY_BREAK -case 10: -YY_RULE_SETUP -#line 77 "lex_config.l" -return CARD; - YY_BREAK -case 11: -YY_RULE_SETUP -#line 78 "lex_config.l" -return CLASS; - YY_BREAK -case 12: -YY_RULE_SETUP -#line 79 "lex_config.l" -return DEFAULT; - YY_BREAK -case 13: -YY_RULE_SETUP -#line 80 "lex_config.l" -return DEVICE; - YY_BREAK -case 14: -YY_RULE_SETUP -#line 81 "lex_config.l" -return DTYPE; - YY_BREAK -case 15: -YY_RULE_SETUP -#line 82 "lex_config.l" -return EXCLUDE; - YY_BREAK -case 16: -YY_RULE_SETUP -#line 83 "lex_config.l" -return FUNCTION; - YY_BREAK -case 17: -YY_RULE_SETUP -#line 84 "lex_config.l" -return INCLUDE; - YY_BREAK -case 18: -YY_RULE_SETUP -#line 85 "lex_config.l" -return IRQ_NO; - YY_BREAK -case 19: -YY_RULE_SETUP -#line 86 "lex_config.l" -return JEDEC; - YY_BREAK -case 20: -YY_RULE_SETUP -#line 87 "lex_config.l" -return MANFID; - YY_BREAK -case 21: -YY_RULE_SETUP -#line 88 "lex_config.l" -return MEMORY; - YY_BREAK -case 22: -YY_RULE_SETUP -#line 89 "lex_config.l" -return MODULE; - YY_BREAK -case 23: -YY_RULE_SETUP -#line 90 "lex_config.l" -return MTD; - YY_BREAK -case 24: -YY_RULE_SETUP -#line 91 "lex_config.l" -return NEEDS_MTD; - YY_BREAK -case 25: -YY_RULE_SETUP -#line 92 "lex_config.l" -return OPTS; - YY_BREAK -case 26: -YY_RULE_SETUP -#line 93 "lex_config.l" -return PCI; - YY_BREAK -case 27: -YY_RULE_SETUP -#line 94 "lex_config.l" -return PORT; - YY_BREAK -case 28: -YY_RULE_SETUP -#line 95 "lex_config.l" -return REGION; - YY_BREAK -case 29: -YY_RULE_SETUP -#line 96 "lex_config.l" -return RESERVE; - YY_BREAK -case 30: -YY_RULE_SETUP -#line 97 "lex_config.l" -return TO; - YY_BREAK -case 31: -YY_RULE_SETUP -#line 98 "lex_config.l" -return TUPLE; - YY_BREAK -case 32: -YY_RULE_SETUP -#line 99 "lex_config.l" -return VERSION; - YY_BREAK -case 33: -YY_RULE_SETUP -#line 101 "lex_config.l" -return lex_number("1"); - YY_BREAK -case 34: -YY_RULE_SETUP -#line 102 "lex_config.l" -return lex_number("2"); - YY_BREAK -case 35: -YY_RULE_SETUP -#line 103 "lex_config.l" -return lex_number("3"); - YY_BREAK -case 36: -YY_RULE_SETUP -#line 104 "lex_config.l" -return lex_number("4"); - YY_BREAK -case 37: -YY_RULE_SETUP -#line 105 "lex_config.l" -return lex_number("5"); - YY_BREAK -case 38: -YY_RULE_SETUP -#line 106 "lex_config.l" -return lex_number("6"); - YY_BREAK -case 39: -YY_RULE_SETUP -#line 107 "lex_config.l" -return lex_number("7"); - YY_BREAK -case 40: -YY_RULE_SETUP -#line 108 "lex_config.l" -return lex_number("8"); - YY_BREAK -case 41: -YY_RULE_SETUP -#line 110 "lex_config.l" -return lex_number(yytext); - YY_BREAK -case 42: -YY_RULE_SETUP -#line 112 "lex_config.l" -return lex_number(yytext); - YY_BREAK -case 43: -YY_RULE_SETUP -#line 114 "lex_config.l" -return lex_string(yytext); - YY_BREAK -case 44: -YY_RULE_SETUP -#line 116 "lex_config.l" -return yytext[0]; - YY_BREAK -case 45: -YY_RULE_SETUP -#line 118 "lex_config.l" -ECHO; - YY_BREAK - - case YY_END_OF_BUFFER: - { - /* Amount of text matched not including the EOB char. */ - int yy_amount_of_matched_text = (int) (yy_cp - yytext_ptr) - 1; - - /* Undo the effects of YY_DO_BEFORE_ACTION. */ - *yy_cp = yy_hold_char; - YY_RESTORE_YY_MORE_OFFSET - - if ( yy_current_buffer->yy_buffer_status == YY_BUFFER_NEW ) - { - /* We're scanning a new file or input source. It's - * possible that this happened because the user - * just pointed yyin at a new source and called - * yylex(). If so, then we have to assure - * consistency between yy_current_buffer and our - * globals. Here is the right place to do so, because - * this is the first action (other than possibly a - * back-up) that will match for the new input source. - */ - yy_n_chars = yy_current_buffer->yy_n_chars; - yy_current_buffer->yy_input_file = yyin; - yy_current_buffer->yy_buffer_status = YY_BUFFER_NORMAL; - } - - /* Note that here we test for yy_c_buf_p "<=" to the position - * of the first EOB in the buffer, since yy_c_buf_p will - * already have been incremented past the NUL character - * (since all states make transitions on EOB to the - * end-of-buffer state). Contrast this with the test - * in input(). - */ - if ( yy_c_buf_p <= &yy_current_buffer->yy_ch_buf[yy_n_chars] ) - { /* This was really a NUL. */ - yy_state_type yy_next_state; - - yy_c_buf_p = yytext_ptr + yy_amount_of_matched_text; - - yy_current_state = yy_get_previous_state(); - - /* Okay, we're now positioned to make the NUL - * transition. We couldn't have - * yy_get_previous_state() go ahead and do it - * for us because it doesn't know how to deal - * with the possibility of jamming (and we don't - * want to build jamming into it because then it - * will run more slowly). - */ - - yy_next_state = yy_try_NUL_trans( yy_current_state ); - - yy_bp = yytext_ptr + YY_MORE_ADJ; - - if ( yy_next_state ) - { - /* Consume the NUL. */ - yy_cp = ++yy_c_buf_p; - yy_current_state = yy_next_state; - goto yy_match; - } - - else - { - yy_cp = yy_c_buf_p; - goto yy_find_action; - } - } - - else switch ( yy_get_next_buffer() ) - { - case EOB_ACT_END_OF_FILE: - { - yy_did_buffer_switch_on_eof = 0; - - if ( yywrap() ) - { - /* Note: because we've taken care in - * yy_get_next_buffer() to have set up - * yytext, we can now set up - * yy_c_buf_p so that if some total - * hoser (like flex itself) wants to - * call the scanner after we return the - * YY_NULL, it'll still work - another - * YY_NULL will get returned. - */ - yy_c_buf_p = yytext_ptr + YY_MORE_ADJ; - - yy_act = YY_STATE_EOF(YY_START); - goto do_action; - } - - else - { - if ( ! yy_did_buffer_switch_on_eof ) - YY_NEW_FILE; - } - break; - } - - case EOB_ACT_CONTINUE_SCAN: - yy_c_buf_p = - yytext_ptr + yy_amount_of_matched_text; - - yy_current_state = yy_get_previous_state(); - - yy_cp = yy_c_buf_p; - yy_bp = yytext_ptr + YY_MORE_ADJ; - goto yy_match; - - case EOB_ACT_LAST_MATCH: - yy_c_buf_p = - &yy_current_buffer->yy_ch_buf[yy_n_chars]; - - yy_current_state = yy_get_previous_state(); - - yy_cp = yy_c_buf_p; - yy_bp = yytext_ptr + YY_MORE_ADJ; - goto yy_find_action; - } - break; - } - - default: - YY_FATAL_ERROR( - "fatal flex scanner internal error--no action found" ); - } /* end of action switch */ - } /* end of scanning one token */ - } /* end of yylex */ - - -/* yy_get_next_buffer - try to read in a new buffer - * - * Returns a code representing an action: - * EOB_ACT_LAST_MATCH - - * EOB_ACT_CONTINUE_SCAN - continue scanning from current position - * EOB_ACT_END_OF_FILE - end of file - */ - -static int yy_get_next_buffer() - { - register char *dest = yy_current_buffer->yy_ch_buf; - register char *source = yytext_ptr; - register int number_to_move, i; - int ret_val; - - if ( yy_c_buf_p > &yy_current_buffer->yy_ch_buf[yy_n_chars + 1] ) - YY_FATAL_ERROR( - "fatal flex scanner internal error--end of buffer missed" ); - - if ( yy_current_buffer->yy_fill_buffer == 0 ) - { /* Don't try to fill the buffer, so this is an EOF. */ - if ( yy_c_buf_p - yytext_ptr - YY_MORE_ADJ == 1 ) - { - /* We matched a single character, the EOB, so - * treat this as a final EOF. - */ - return EOB_ACT_END_OF_FILE; - } - - else - { - /* We matched some text prior to the EOB, first - * process it. - */ - return EOB_ACT_LAST_MATCH; - } - } - - /* Try to read more data. */ - - /* First move last chars to start of buffer. */ - number_to_move = (int) (yy_c_buf_p - yytext_ptr) - 1; - - for ( i = 0; i < number_to_move; ++i ) - *(dest++) = *(source++); - - if ( yy_current_buffer->yy_buffer_status == YY_BUFFER_EOF_PENDING ) - /* don't do the read, it's not guaranteed to return an EOF, - * just force an EOF - */ - yy_current_buffer->yy_n_chars = yy_n_chars = 0; - - else - { - int num_to_read = - yy_current_buffer->yy_buf_size - number_to_move - 1; - - while ( num_to_read <= 0 ) - { /* Not enough room in the buffer - grow it. */ -#ifdef YY_USES_REJECT - YY_FATAL_ERROR( -"input buffer overflow, can't enlarge buffer because scanner uses REJECT" ); -#else - - /* just a shorter name for the current buffer */ - YY_BUFFER_STATE b = yy_current_buffer; - - int yy_c_buf_p_offset = - (int) (yy_c_buf_p - b->yy_ch_buf); - - if ( b->yy_is_our_buffer ) - { - int new_size = b->yy_buf_size * 2; - - if ( new_size <= 0 ) - b->yy_buf_size += b->yy_buf_size / 8; - else - b->yy_buf_size *= 2; - - b->yy_ch_buf = (char *) - /* Include room in for 2 EOB chars. */ - yy_flex_realloc( (void *) b->yy_ch_buf, - b->yy_buf_size + 2 ); - } - else - /* Can't grow it, we don't own it. */ - b->yy_ch_buf = 0; - - if ( ! b->yy_ch_buf ) - YY_FATAL_ERROR( - "fatal error - scanner input buffer overflow" ); - - yy_c_buf_p = &b->yy_ch_buf[yy_c_buf_p_offset]; - - num_to_read = yy_current_buffer->yy_buf_size - - number_to_move - 1; -#endif - } - - if ( num_to_read > YY_READ_BUF_SIZE ) - num_to_read = YY_READ_BUF_SIZE; - - /* Read in more data. */ - YY_INPUT( (&yy_current_buffer->yy_ch_buf[number_to_move]), - yy_n_chars, num_to_read ); - - yy_current_buffer->yy_n_chars = yy_n_chars; - } - - if ( yy_n_chars == 0 ) - { - if ( number_to_move == YY_MORE_ADJ ) - { - ret_val = EOB_ACT_END_OF_FILE; - yyrestart( yyin ); - } - - else - { - ret_val = EOB_ACT_LAST_MATCH; - yy_current_buffer->yy_buffer_status = - YY_BUFFER_EOF_PENDING; - } - } - - else - ret_val = EOB_ACT_CONTINUE_SCAN; - - yy_n_chars += number_to_move; - yy_current_buffer->yy_ch_buf[yy_n_chars] = YY_END_OF_BUFFER_CHAR; - yy_current_buffer->yy_ch_buf[yy_n_chars + 1] = YY_END_OF_BUFFER_CHAR; - - yytext_ptr = &yy_current_buffer->yy_ch_buf[0]; - - return ret_val; - } - - -/* yy_get_previous_state - get the state just before the EOB char was reached */ - -static yy_state_type yy_get_previous_state() - { - register yy_state_type yy_current_state; - register char *yy_cp; - - yy_current_state = yy_start; - - for ( yy_cp = yytext_ptr + YY_MORE_ADJ; yy_cp < yy_c_buf_p; ++yy_cp ) - { - register YY_CHAR yy_c = (*yy_cp ? yy_ec[YY_SC_TO_UI(*yy_cp)] : 1); - if ( yy_accept[yy_current_state] ) - { - yy_last_accepting_state = yy_current_state; - yy_last_accepting_cpos = yy_cp; - } - while ( yy_chk[yy_base[yy_current_state] + yy_c] != yy_current_state ) - { - yy_current_state = (int) yy_def[yy_current_state]; - if ( yy_current_state >= 247 ) - yy_c = yy_meta[(unsigned int) yy_c]; - } - yy_current_state = yy_nxt[yy_base[yy_current_state] + (unsigned int) yy_c]; - } - - return yy_current_state; - } - - -/* yy_try_NUL_trans - try to make a transition on the NUL character - * - * synopsis - * next_state = yy_try_NUL_trans( current_state ); - */ - -#ifdef YY_USE_PROTOS -static yy_state_type yy_try_NUL_trans( yy_state_type yy_current_state ) -#else -static yy_state_type yy_try_NUL_trans( yy_current_state ) -yy_state_type yy_current_state; -#endif - { - register int yy_is_jam; - register char *yy_cp = yy_c_buf_p; - - register YY_CHAR yy_c = 1; - if ( yy_accept[yy_current_state] ) - { - yy_last_accepting_state = yy_current_state; - yy_last_accepting_cpos = yy_cp; - } - while ( yy_chk[yy_base[yy_current_state] + yy_c] != yy_current_state ) - { - yy_current_state = (int) yy_def[yy_current_state]; - if ( yy_current_state >= 247 ) - yy_c = yy_meta[(unsigned int) yy_c]; - } - yy_current_state = yy_nxt[yy_base[yy_current_state] + (unsigned int) yy_c]; - yy_is_jam = (yy_current_state == 246); - - return yy_is_jam ? 0 : yy_current_state; - } - - -//mdk-stage1// #ifndef YY_NO_UNPUT -//mdk-stage1// #ifdef YY_USE_PROTOS -//mdk-stage1// static void yyunput( int c, register char *yy_bp ) -//mdk-stage1// #else -//mdk-stage1// static void yyunput( c, yy_bp ) -//mdk-stage1// int c; -//mdk-stage1// register char *yy_bp; -//mdk-stage1// #endif -//mdk-stage1// { -//mdk-stage1// register char *yy_cp = yy_c_buf_p; -//mdk-stage1// -//mdk-stage1// /* undo effects of setting up yytext */ -//mdk-stage1// *yy_cp = yy_hold_char; -//mdk-stage1// -//mdk-stage1// if ( yy_cp < yy_current_buffer->yy_ch_buf + 2 ) -//mdk-stage1// { /* need to shift things up to make room */ -//mdk-stage1// /* +2 for EOB chars. */ -//mdk-stage1// register int number_to_move = yy_n_chars + 2; -//mdk-stage1// register char *dest = &yy_current_buffer->yy_ch_buf[ -//mdk-stage1// yy_current_buffer->yy_buf_size + 2]; -//mdk-stage1// register char *source = -//mdk-stage1// &yy_current_buffer->yy_ch_buf[number_to_move]; -//mdk-stage1// -//mdk-stage1// while ( source > yy_current_buffer->yy_ch_buf ) -//mdk-stage1// *--dest = *--source; -//mdk-stage1// -//mdk-stage1// yy_cp += (int) (dest - source); -//mdk-stage1// yy_bp += (int) (dest - source); -//mdk-stage1// yy_current_buffer->yy_n_chars = -//mdk-stage1// yy_n_chars = yy_current_buffer->yy_buf_size; -//mdk-stage1// -//mdk-stage1// if ( yy_cp < yy_current_buffer->yy_ch_buf + 2 ) -//mdk-stage1// YY_FATAL_ERROR( "flex scanner push-back overflow" ); -//mdk-stage1// } -//mdk-stage1// -//mdk-stage1// *--yy_cp = (char) c; -//mdk-stage1// -//mdk-stage1// -//mdk-stage1// yytext_ptr = yy_bp; -//mdk-stage1// yy_hold_char = *yy_cp; -//mdk-stage1// yy_c_buf_p = yy_cp; -//mdk-stage1// } -//mdk-stage1// #endif /* ifndef YY_NO_UNPUT */ - - -#ifdef __cplusplus -static int yyinput() -#else -static int input() -#endif - { - int c; - - *yy_c_buf_p = yy_hold_char; - - if ( *yy_c_buf_p == YY_END_OF_BUFFER_CHAR ) - { - /* yy_c_buf_p now points to the character we want to return. - * If this occurs *before* the EOB characters, then it's a - * valid NUL; if not, then we've hit the end of the buffer. - */ - if ( yy_c_buf_p < &yy_current_buffer->yy_ch_buf[yy_n_chars] ) - /* This was really a NUL. */ - *yy_c_buf_p = '\0'; - - else - { /* need more input */ - int offset = yy_c_buf_p - yytext_ptr; - ++yy_c_buf_p; - - switch ( yy_get_next_buffer() ) - { - case EOB_ACT_LAST_MATCH: - /* This happens because yy_g_n_b() - * sees that we've accumulated a - * token and flags that we need to - * try matching the token before - * proceeding. But for input(), - * there's no matching to consider. - * So convert the EOB_ACT_LAST_MATCH - * to EOB_ACT_END_OF_FILE. - */ - - /* Reset buffer status. */ - yyrestart( yyin ); - - /* fall through */ - - case EOB_ACT_END_OF_FILE: - { - if ( yywrap() ) - return EOF; - - if ( ! yy_did_buffer_switch_on_eof ) - YY_NEW_FILE; -#ifdef __cplusplus - return yyinput(); -#else - return input(); -#endif - } - - case EOB_ACT_CONTINUE_SCAN: - yy_c_buf_p = yytext_ptr + offset; - break; - } - } - } - - c = *(unsigned char *) yy_c_buf_p; /* cast for 8-bit char's */ - *yy_c_buf_p = '\0'; /* preserve yytext */ - yy_hold_char = *++yy_c_buf_p; - - - return c; - } - - -#ifdef YY_USE_PROTOS -void yyrestart( FILE *input_file ) -#else -void yyrestart( input_file ) -FILE *input_file; -#endif - { - if ( ! yy_current_buffer ) - yy_current_buffer = yy_create_buffer( yyin, YY_BUF_SIZE ); - - yy_init_buffer( yy_current_buffer, input_file ); - yy_load_buffer_state(); - } - - -#ifdef YY_USE_PROTOS -void yy_switch_to_buffer( YY_BUFFER_STATE new_buffer ) -#else -void yy_switch_to_buffer( new_buffer ) -YY_BUFFER_STATE new_buffer; -#endif - { - if ( yy_current_buffer == new_buffer ) - return; - - if ( yy_current_buffer ) - { - /* Flush out information for old buffer. */ - *yy_c_buf_p = yy_hold_char; - yy_current_buffer->yy_buf_pos = yy_c_buf_p; - yy_current_buffer->yy_n_chars = yy_n_chars; - } - - yy_current_buffer = new_buffer; - yy_load_buffer_state(); - - /* We don't actually know whether we did this switch during - * EOF (yywrap()) processing, but the only time this flag - * is looked at is after yywrap() is called, so it's safe - * to go ahead and always set it. - */ - yy_did_buffer_switch_on_eof = 1; - } - - -#ifdef YY_USE_PROTOS -void yy_load_buffer_state( void ) -#else -void yy_load_buffer_state() -#endif - { - yy_n_chars = yy_current_buffer->yy_n_chars; - yytext_ptr = yy_c_buf_p = yy_current_buffer->yy_buf_pos; - yyin = yy_current_buffer->yy_input_file; - yy_hold_char = *yy_c_buf_p; - } - - -#ifdef YY_USE_PROTOS -YY_BUFFER_STATE yy_create_buffer( FILE *file, int size ) -#else -YY_BUFFER_STATE yy_create_buffer( file, size ) -FILE *file; -int size; -#endif - { - YY_BUFFER_STATE b; - - b = (YY_BUFFER_STATE) yy_flex_alloc( sizeof( struct yy_buffer_state ) ); - if ( ! b ) - YY_FATAL_ERROR( "out of dynamic memory in yy_create_buffer()" ); - - b->yy_buf_size = size; - - /* yy_ch_buf has to be 2 characters longer than the size given because - * we need to put in 2 end-of-buffer characters. - */ - b->yy_ch_buf = (char *) yy_flex_alloc( b->yy_buf_size + 2 ); - if ( ! b->yy_ch_buf ) - YY_FATAL_ERROR( "out of dynamic memory in yy_create_buffer()" ); - - b->yy_is_our_buffer = 1; - - yy_init_buffer( b, file ); - - return b; - } - - -#ifdef YY_USE_PROTOS -void yy_delete_buffer( YY_BUFFER_STATE b ) -#else -void yy_delete_buffer( b ) -YY_BUFFER_STATE b; -#endif - { - if ( ! b ) - return; - - if ( b == yy_current_buffer ) - yy_current_buffer = (YY_BUFFER_STATE) 0; - - if ( b->yy_is_our_buffer ) - yy_flex_free( (void *) b->yy_ch_buf ); - - yy_flex_free( (void *) b ); - } - - -#ifndef YY_ALWAYS_INTERACTIVE -#ifndef YY_NEVER_INTERACTIVE -extern int isatty YY_PROTO(( int )); -#endif -#endif - -#ifdef YY_USE_PROTOS -void yy_init_buffer( YY_BUFFER_STATE b, FILE *file ) -#else -void yy_init_buffer( b, file ) -YY_BUFFER_STATE b; -FILE *file; -#endif - - - { - yy_flush_buffer( b ); - - b->yy_input_file = file; - b->yy_fill_buffer = 1; - -#if YY_ALWAYS_INTERACTIVE - b->yy_is_interactive = 1; -#else -#if YY_NEVER_INTERACTIVE - b->yy_is_interactive = 0; -#else - b->yy_is_interactive = file ? (isatty( fileno(file) ) > 0) : 0; -#endif -#endif - } - - -#ifdef YY_USE_PROTOS -void yy_flush_buffer( YY_BUFFER_STATE b ) -#else -void yy_flush_buffer( b ) -YY_BUFFER_STATE b; -#endif - - { - if ( ! b ) - return; - - b->yy_n_chars = 0; - - /* We always need two end-of-buffer characters. The first causes - * a transition to the end-of-buffer state. The second causes - * a jam in that state. - */ - b->yy_ch_buf[0] = YY_END_OF_BUFFER_CHAR; - b->yy_ch_buf[1] = YY_END_OF_BUFFER_CHAR; - - b->yy_buf_pos = &b->yy_ch_buf[0]; - - b->yy_at_bol = 1; - b->yy_buffer_status = YY_BUFFER_NEW; - - if ( b == yy_current_buffer ) - yy_load_buffer_state(); - } - - -#ifndef YY_NO_SCAN_BUFFER -#ifdef YY_USE_PROTOS -YY_BUFFER_STATE yy_scan_buffer( char *base, yy_size_t size ) -#else -YY_BUFFER_STATE yy_scan_buffer( base, size ) -char *base; -yy_size_t size; -#endif - { - YY_BUFFER_STATE b; - - if ( size < 2 || - base[size-2] != YY_END_OF_BUFFER_CHAR || - base[size-1] != YY_END_OF_BUFFER_CHAR ) - /* They forgot to leave room for the EOB's. */ - return 0; - - b = (YY_BUFFER_STATE) yy_flex_alloc( sizeof( struct yy_buffer_state ) ); - if ( ! b ) - YY_FATAL_ERROR( "out of dynamic memory in yy_scan_buffer()" ); - - b->yy_buf_size = size - 2; /* "- 2" to take care of EOB's */ - b->yy_buf_pos = b->yy_ch_buf = base; - b->yy_is_our_buffer = 0; - b->yy_input_file = 0; - b->yy_n_chars = b->yy_buf_size; - b->yy_is_interactive = 0; - b->yy_at_bol = 1; - b->yy_fill_buffer = 0; - b->yy_buffer_status = YY_BUFFER_NEW; - - yy_switch_to_buffer( b ); - - return b; - } -#endif - - -#ifndef YY_NO_SCAN_STRING -#ifdef YY_USE_PROTOS -YY_BUFFER_STATE yy_scan_string( yyconst char *yy_str ) -#else -YY_BUFFER_STATE yy_scan_string( yy_str ) -yyconst char *yy_str; -#endif - { - int len; - for ( len = 0; yy_str[len]; ++len ) - ; - - return yy_scan_bytes( yy_str, len ); - } -#endif - - -#ifndef YY_NO_SCAN_BYTES -#ifdef YY_USE_PROTOS -YY_BUFFER_STATE yy_scan_bytes( yyconst char *bytes, int len ) -#else -YY_BUFFER_STATE yy_scan_bytes( bytes, len ) -yyconst char *bytes; -int len; -#endif - { - YY_BUFFER_STATE b; - char *buf; - yy_size_t n; - int i; - - /* Get memory for full buffer, including space for trailing EOB's. */ - n = len + 2; - buf = (char *) yy_flex_alloc( n ); - if ( ! buf ) - YY_FATAL_ERROR( "out of dynamic memory in yy_scan_bytes()" ); - - for ( i = 0; i < len; ++i ) - buf[i] = bytes[i]; - - buf[len] = buf[len+1] = YY_END_OF_BUFFER_CHAR; - - b = yy_scan_buffer( buf, n ); - if ( ! b ) - YY_FATAL_ERROR( "bad buffer in yy_scan_bytes()" ); - - /* It's okay to grow etc. this buffer, and we should throw it - * away when we're done. - */ - b->yy_is_our_buffer = 1; - - return b; - } -#endif - - -#ifndef YY_NO_PUSH_STATE -#ifdef YY_USE_PROTOS -static void yy_push_state( int new_state ) -#else -static void yy_push_state( new_state ) -int new_state; -#endif - { - if ( yy_start_stack_ptr >= yy_start_stack_depth ) - { - yy_size_t new_size; - - yy_start_stack_depth += YY_START_STACK_INCR; - new_size = yy_start_stack_depth * sizeof( int ); - - if ( ! yy_start_stack ) - yy_start_stack = (int *) yy_flex_alloc( new_size ); - - else - yy_start_stack = (int *) yy_flex_realloc( - (void *) yy_start_stack, new_size ); - - if ( ! yy_start_stack ) - YY_FATAL_ERROR( - "out of memory expanding start-condition stack" ); - } - - yy_start_stack[yy_start_stack_ptr++] = YY_START; - - BEGIN(new_state); - } -#endif - - -#ifndef YY_NO_POP_STATE -static void yy_pop_state() - { - if ( --yy_start_stack_ptr < 0 ) - YY_FATAL_ERROR( "start-condition stack underflow" ); - - BEGIN(yy_start_stack[yy_start_stack_ptr]); - } -#endif - - -#ifndef YY_NO_TOP_STATE -static int yy_top_state() - { - return yy_start_stack[yy_start_stack_ptr - 1]; - } -#endif - -#ifndef YY_EXIT_FAILURE -#define YY_EXIT_FAILURE 2 -#endif - -#ifdef YY_USE_PROTOS -static void yy_fatal_error( yyconst char msg[] ) -#else -static void yy_fatal_error( msg ) -char msg[]; -#endif - { - (void) fprintf( stderr, "%s\n", msg ); - exit( YY_EXIT_FAILURE ); - } - - - -/* Redefine yyless() so it works in section 3 code. */ - -#undef yyless -#define yyless(n) \ - do \ - { \ - /* Undo effects of setting up yytext. */ \ - yytext[yyleng] = yy_hold_char; \ - yy_c_buf_p = yytext + n; \ - yy_hold_char = *yy_c_buf_p; \ - *yy_c_buf_p = '\0'; \ - yyleng = n; \ - } \ - while ( 0 ) - - -/* Internal utility routines. */ - -#ifndef yytext_ptr -#ifdef YY_USE_PROTOS -static void yy_flex_strncpy( char *s1, yyconst char *s2, int n ) -#else -static void yy_flex_strncpy( s1, s2, n ) -char *s1; -yyconst char *s2; -int n; -#endif - { - register int i; - for ( i = 0; i < n; ++i ) - s1[i] = s2[i]; - } -#endif - -#ifdef YY_NEED_STRLEN -#ifdef YY_USE_PROTOS -static int yy_flex_strlen( yyconst char *s ) -#else -static int yy_flex_strlen( s ) -yyconst char *s; -#endif - { - register int n; - for ( n = 0; s[n]; ++n ) - ; - - return n; - } -#endif - - -#ifdef YY_USE_PROTOS -static void *yy_flex_alloc( yy_size_t size ) -#else -static void *yy_flex_alloc( size ) -yy_size_t size; -#endif - { - return (void *) malloc( size ); - } - -#ifdef YY_USE_PROTOS -static void *yy_flex_realloc( void *ptr, yy_size_t size ) -#else -static void *yy_flex_realloc( ptr, size ) -void *ptr; -yy_size_t size; -#endif - { - /* The cast to (char *) in the following accommodates both - * implementations that use char* generic pointers, and those - * that use void* generic pointers. It works with the latter - * because both ANSI C and C++ allow castless assignment from - * any pointer type to void*, and deal with argument conversions - * as though doing an assignment. - */ - return (void *) realloc( (char *) ptr, size ); - } - -#ifdef YY_USE_PROTOS -static void yy_flex_free( void *ptr ) -#else -static void yy_flex_free( ptr ) -void *ptr; -#endif - { - free( ptr ); - } - -#if YY_MAIN -int main() - { - yylex(); - return 0; - } -#endif -#line 118 "lex_config.l" - - -#ifndef yywrap -int yywrap() { return 1; } -#endif - -/*====================================================================== - - Stuff to parse basic data types - -======================================================================*/ - -static int lex_number(char *s) -{ - yylval.num = strtoul(s, NULL, 0); - return NUMBER; -} - -static int lex_string(char *s) -{ - int n = strlen(s); - yylval.str = malloc(n-1); - strncpy(yylval.str, s+1, n-2); - yylval.str[n-2] = '\0'; - return STRING; -} - -/*====================================================================== - - Code to support nesting of configuration files - -======================================================================*/ - -#define MAX_SOURCE_DEPTH 4 -struct source_stack { - YY_BUFFER_STATE buffer; - char *filename; - int lineno, fileno; - FILE *file; - glob_t glob; -} source_stack[MAX_SOURCE_DEPTH]; -static int source_stack_ptr = 0; -static int parse_env = 0; - -static int get_glob(void) -{ - struct source_stack *s = &source_stack[source_stack_ptr]; - while (s->fileno < s->glob.gl_pathc) { - char *fn = s->glob.gl_pathv[s->fileno]; - s->file = fopen(fn, "r"); - if (s->file == NULL) { - if (strpbrk(fn, "?*[") == NULL) - syslog(LOG_INFO, "could not open '%s': %m", fn); - s->fileno++; - } else { - current_lineno = 1; - current_file = strdup(fn); - yy_switch_to_buffer(yy_create_buffer(s->file, YY_BUF_SIZE)); - source_stack_ptr++; - s->fileno++; - return 0; - } - } - return -1; -} - -static void do_source(char *fn) -{ - struct source_stack *s = &source_stack[source_stack_ptr]; - - if (source_stack_ptr >= MAX_SOURCE_DEPTH) { - syslog(LOG_INFO, "source depth limit exceeded"); - return; - } - glob(fn, GLOB_NOCHECK, NULL, &s->glob); - s->fileno = 0; - s->buffer = YY_CURRENT_BUFFER; - s->lineno = current_lineno; - s->filename = current_file; - get_glob(); -} - -static int do_eof(void) -{ - struct source_stack *s = &source_stack[--source_stack_ptr]; - if (source_stack_ptr < 0) { - if (parse_env == 0) { - char *t = getenv("PCMCIA_OPTS"); - if (t == NULL) return -1; - parse_env = 1; - source_stack_ptr = 0; - current_file = "PCMCIA_OPTS"; - current_lineno = 1; - yy_scan_string(t); - return 0; - } else - return -1; - } - fclose(s->file); - free(current_file); - yy_delete_buffer(YY_CURRENT_BUFFER); - if (get_glob() != 0) { - yy_switch_to_buffer(s->buffer); - current_lineno = s->lineno; - current_file = s->filename; - } - return 0; -} - -/*====================================================================== - - The main entry point... returns -1 if the file can't be accessed. - -======================================================================*/ -int yyparse(void); - -int parse_configfile(char *fn) -{ - FILE *f; - - f = fopen(fn, "r"); - if (!f) { - syslog(LOG_INFO, "could not open '%s': %m", fn); - return -1; - } - current_lineno = 1; - current_file = fn; - source_stack_ptr = 0; - yyrestart(f); - yyparse(); - fclose(f); - return 0; -} - diff --git a/mdk-stage1/pcmcia_/yacc_config.c b/mdk-stage1/pcmcia_/yacc_config.c deleted file mode 100644 index 2262d52f3..000000000 --- a/mdk-stage1/pcmcia_/yacc_config.c +++ /dev/null @@ -1,1015 +0,0 @@ -#define YYBYACC 1 -#define YYMAJOR 1 -#define YYMINOR 9 -#define yyclearin (yychar=(-1)) -#define yyerrok (yyerrflag=0) -#define YYRECOVERING (yyerrflag!=0) -#define YYPREFIX "yy" -#line 2 "yacc_config.y" -/* - * yacc_config.y 1.53 2001/08/24 12:21:34 - * - * The contents of this file are subject to the Mozilla Public License - * Version 1.1 (the "License"); you may not use this file except in - * compliance with the License. You may obtain a copy of the License - * at http://www.mozilla.org/MPL/ - * - * Software distributed under the License is distributed on an "AS IS" - * basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See - * the License for the specific language governing rights and - * limitations under the License. - * - * The initial developer of the original code is David A. Hinds - * <dahinds@users.sourceforge.net>. Portions created by David A. Hinds - * are Copyright (C) 1999 David A. Hinds. All Rights Reserved. - * - * Alternatively, the contents of this file may be used under the - * terms of the GNU General Public License version 2 (the "GPL"), in - * which case the provisions of the GPL are applicable instead of the - * above. If you wish to allow the use of your version of this file - * only under the terms of the GPL and not to allow others to use - * your version of this file under the MPL, indicate your decision by - * deleting the provisions above and replace them with the notice and - * other provisions required by the GPL. If you do not delete the - * provisions above, a recipient may use your version of this file - * under either the MPL or the GPL. - */ - -#include <stdlib.h> -#include <stdarg.h> -#include <stdio.h> -#include <string.h> -#include <syslog.h> -#include <sys/types.h> - -#include <pcmcia_/cs_types.h> -#include <pcmcia_/cs.h> -#include <pcmcia_/cistpl.h> -#include <pcmcia_/ds.h> - -#include "cardmgr.h" - -/* If bison: generate nicer error messages */ -#define YYERROR_VERBOSE 1 - -/* from lex_config, for nice error messages */ -extern char *current_file; -extern int current_lineno; - -void yyerror(char *msg, ...); - -static int add_binding(card_info_t *card, char *name, int fn); -static int add_module(device_info_t *card, char *name); - -#line 65 "yacc_config.y" -typedef union { - char *str; - unsigned long num; - struct device_info_t *device; - struct card_info_t *card; - struct mtd_ident_t *mtd; - struct adjust_list_t *adjust; -} YYSTYPE; -#line 77 "y.tab.c" -#define DEVICE 257 -#define CARD 258 -#define ANONYMOUS 259 -#define TUPLE 260 -#define MANFID 261 -#define VERSION 262 -#define FUNCTION 263 -#define PCI 264 -#define BIND 265 -#define CIS 266 -#define TO 267 -#define NEEDS_MTD 268 -#define MODULE 269 -#define OPTS 270 -#define CLASS 271 -#define REGION 272 -#define JEDEC 273 -#define DTYPE 274 -#define DEFAULT 275 -#define MTD 276 -#define INCLUDE 277 -#define EXCLUDE 278 -#define RESERVE 279 -#define IRQ_NO 280 -#define PORT 281 -#define MEMORY 282 -#define STRING 283 -#define NUMBER 284 -#define YYERRCODE 256 -short yylhs[] = { -1, - 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, - 1, 1, 2, 2, 2, 3, 3, 3, 3, 7, - 7, 7, 7, 7, 7, 7, 7, 7, 8, 9, - 10, 11, 12, 12, 13, 15, 14, 14, 14, 14, - 4, 21, 5, 5, 5, 6, 16, 16, 16, 16, - 18, 17, 19, 20, 20, 22, -}; -short yylen[] = { 2, - 0, 2, 2, 2, 2, 2, 2, 2, 2, 2, - 2, 3, 2, 4, 4, 2, 1, 1, 1, 2, - 1, 1, 1, 1, 1, 1, 1, 1, 2, 7, - 5, 5, 3, 3, 3, 3, 3, 5, 3, 5, - 2, 4, 3, 3, 3, 3, 2, 1, 1, 1, - 3, 4, 2, 3, 3, 4, -}; -short yydefred[] = { 1, - 0, 8, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 17, 0, 19, 0, 21, 22, 23, 24, - 0, 26, 0, 28, 0, 49, 48, 50, 0, 6, - 7, 16, 20, 0, 47, 0, 0, 0, 0, 9, - 10, 11, 0, 41, 0, 0, 0, 0, 29, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 53, 0, 0, 0, 0, 13, 0, 0, 12, 43, - 46, 44, 45, 0, 0, 33, 35, 0, 0, 36, - 34, 0, 0, 51, 54, 55, 42, 56, 0, 0, - 0, 0, 0, 0, 0, 52, 14, 15, 0, 31, - 32, 38, 40, 0, 30, -}; -short yydgoto[] = { 1, - 11, 40, 12, 13, 14, 15, 16, 17, 18, 19, - 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, - 30, 31, -}; -short yysindex[] = { 0, - -250, 0, -279, -278, -274, -265, -259, -242, -242, -242, - -10, -248, 0, -44, 0, -249, 0, 0, 0, 0, - -9, 0, -3, 0, -243, 0, 0, 0, -233, 0, - 0, 0, 0, -228, 0, -227, -240, -238, -237, 0, - 0, 0, -242, 0, -235, -232, -231, -230, 0, -234, - -229, -226, -225, -224, -222, -221, -220, -219, -218, -217, - 0, -215, -213, -212, -211, 0, 9, 11, 0, 0, - 0, 0, 0, 14, 21, 0, 0, 30, -192, 0, - 0, -191, -207, 0, 0, 0, 0, 0, -206, -205, - -204, -203, -202, -201, -200, 0, 0, 0, 41, 0, - 0, 0, 0, -197, 0, -}; -short yyrindex[] = { 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 107, 149, 0, 90, 0, 124, 0, 0, 0, 0, - 49, 0, 73, 0, 0, 0, 0, 0, 141, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, - 0, 25, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, -}; -short yygindex[] = { 0, - 0, -7, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, -}; -#define YYTABLESIZE 428 -short yytable[] = { 48, - 37, 41, 42, 32, 33, 2, 3, 4, 34, 49, - 50, 51, 52, 53, 54, 55, 56, 35, 5, 44, - 45, 6, 46, 36, 39, 7, 8, 9, 10, 59, - 60, 61, 62, 43, 57, 69, 63, 37, 38, 39, - 58, 64, 65, 66, 37, 67, 68, 70, 25, 74, - 71, 72, 73, 89, 75, 90, 76, 91, 77, 78, - 79, 80, 81, 82, 92, 83, 84, 85, 39, 86, - 87, 88, 27, 93, 94, 95, 96, 97, 98, 99, - 100, 101, 102, 103, 104, 105, 0, 0, 0, 18, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 2, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 5, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 4, 0, 0, 0, 0, 0, 0, 0, 3, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 47, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 37, 37, 37, 37, - 37, 37, 37, 37, 37, 37, 37, 0, 0, 37, - 0, 0, 37, 0, 0, 0, 37, 37, 37, 37, - 39, 39, 39, 39, 39, 39, 39, 39, 39, 39, - 39, 0, 0, 39, 0, 0, 39, 0, 0, 0, - 39, 39, 39, 39, 25, 25, 25, 25, 25, 25, - 25, 25, 25, 25, 25, 0, 0, 25, 0, 0, - 25, 0, 0, 0, 25, 25, 25, 25, 27, 27, - 27, 27, 27, 27, 27, 27, 27, 27, 27, 0, - 0, 27, 0, 0, 27, 18, 18, 18, 27, 27, - 27, 27, 0, 0, 0, 0, 0, 18, 18, 0, - 18, 18, 2, 2, 2, 18, 18, 18, 18, 0, - 0, 0, 0, 0, 0, 2, 0, 0, 2, 5, - 5, 5, 2, 2, 2, 2, 0, 0, 0, 0, - 0, 0, 5, 0, 0, 5, 4, 4, 4, 5, - 5, 5, 5, 0, 3, 3, 3, 0, 0, 4, - 0, 0, 4, 0, 0, 0, 4, 4, 4, 4, - 3, 0, 0, 0, 3, 3, 3, 3, -}; -short yycheck[] = { 44, - 0, 9, 10, 283, 283, 256, 257, 258, 283, 259, - 260, 261, 262, 263, 264, 265, 266, 283, 269, 268, - 269, 272, 271, 283, 0, 276, 277, 278, 279, 273, - 274, 275, 276, 44, 44, 43, 270, 280, 281, 282, - 44, 270, 270, 284, 44, 284, 284, 283, 0, 284, - 283, 283, 283, 45, 284, 45, 283, 44, 284, 284, - 283, 283, 283, 283, 44, 284, 284, 283, 44, 283, - 283, 283, 0, 44, 267, 267, 284, 284, 284, 284, - 284, 284, 284, 284, 44, 283, -1, -1, -1, 0, - -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, - -1, -1, -1, -1, -1, -1, 0, -1, -1, -1, - -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, - -1, -1, -1, 0, -1, -1, -1, -1, -1, -1, - -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, - 0, -1, -1, -1, -1, -1, -1, -1, 0, -1, - -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, - -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, - -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, - -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, - -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, - -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, - -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, - -1, -1, -1, -1, -1, 270, -1, -1, -1, -1, - -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, - -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, - -1, -1, -1, -1, -1, -1, 256, 257, 258, 259, - 260, 261, 262, 263, 264, 265, 266, -1, -1, 269, - -1, -1, 272, -1, -1, -1, 276, 277, 278, 279, - 256, 257, 258, 259, 260, 261, 262, 263, 264, 265, - 266, -1, -1, 269, -1, -1, 272, -1, -1, -1, - 276, 277, 278, 279, 256, 257, 258, 259, 260, 261, - 262, 263, 264, 265, 266, -1, -1, 269, -1, -1, - 272, -1, -1, -1, 276, 277, 278, 279, 256, 257, - 258, 259, 260, 261, 262, 263, 264, 265, 266, -1, - -1, 269, -1, -1, 272, 256, 257, 258, 276, 277, - 278, 279, -1, -1, -1, -1, -1, 268, 269, -1, - 271, 272, 256, 257, 258, 276, 277, 278, 279, -1, - -1, -1, -1, -1, -1, 269, -1, -1, 272, 256, - 257, 258, 276, 277, 278, 279, -1, -1, -1, -1, - -1, -1, 269, -1, -1, 272, 256, 257, 258, 276, - 277, 278, 279, -1, 256, 257, 258, -1, -1, 269, - -1, -1, 272, -1, -1, -1, 276, 277, 278, 279, - 272, -1, -1, -1, 276, 277, 278, 279, -}; -#define YYFINAL 1 -#ifndef YYDEBUG -#define YYDEBUG 0 -#endif -#define YYMAXTOKEN 284 -#if YYDEBUG -char *yyname[] = { -"end-of-file",0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, -0,0,0,0,0,0,0,0,0,0,"','","'-'",0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, -0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, -0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, -0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, -0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, -0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,"DEVICE","CARD", -"ANONYMOUS","TUPLE","MANFID","VERSION","FUNCTION","PCI","BIND","CIS","TO", -"NEEDS_MTD","MODULE","OPTS","CLASS","REGION","JEDEC","DTYPE","DEFAULT","MTD", -"INCLUDE","EXCLUDE","RESERVE","IRQ_NO","PORT","MEMORY","STRING","NUMBER", -}; -char *yyrule[] = { -"$accept : list", -"list :", -"list : list adjust", -"list : list device", -"list : list mtd", -"list : list card", -"list : list opts", -"list : list mtd_opts", -"list : list error", -"adjust : INCLUDE resource", -"adjust : EXCLUDE resource", -"adjust : RESERVE resource", -"adjust : adjust ',' resource", -"resource : IRQ_NO NUMBER", -"resource : PORT NUMBER '-' NUMBER", -"resource : MEMORY NUMBER '-' NUMBER", -"device : DEVICE STRING", -"device : needs_mtd", -"device : module", -"device : class", -"card : CARD STRING", -"card : anonymous", -"card : tuple", -"card : manfid", -"card : pci", -"card : version", -"card : function", -"card : bind", -"card : cis", -"anonymous : card ANONYMOUS", -"tuple : card TUPLE NUMBER ',' NUMBER ',' STRING", -"manfid : card MANFID NUMBER ',' NUMBER", -"pci : card PCI NUMBER ',' NUMBER", -"version : card VERSION STRING", -"version : version ',' STRING", -"function : card FUNCTION NUMBER", -"cis : card CIS STRING", -"bind : card BIND STRING", -"bind : card BIND STRING TO NUMBER", -"bind : bind ',' STRING", -"bind : bind ',' STRING TO NUMBER", -"needs_mtd : device NEEDS_MTD", -"opts : MODULE STRING OPTS STRING", -"module : device MODULE STRING", -"module : module OPTS STRING", -"module : module ',' STRING", -"class : device CLASS STRING", -"region : REGION STRING", -"region : dtype", -"region : jedec", -"region : default", -"dtype : region DTYPE NUMBER", -"jedec : region JEDEC NUMBER NUMBER", -"default : region DEFAULT", -"mtd : region MTD STRING", -"mtd : mtd OPTS STRING", -"mtd_opts : MTD STRING OPTS STRING", -}; -#endif -#ifdef YYSTACKSIZE -#undef YYMAXDEPTH -#define YYMAXDEPTH YYSTACKSIZE -#else -#ifdef YYMAXDEPTH -#define YYSTACKSIZE YYMAXDEPTH -#else -#define YYSTACKSIZE 500 -#define YYMAXDEPTH 500 -#endif -#endif -int yydebug; -int yynerrs; -int yyerrflag; -int yychar; -short *yyssp; -YYSTYPE *yyvsp; -YYSTYPE yyval; -YYSTYPE yylval; -short yyss[YYSTACKSIZE]; -YYSTYPE yyvs[YYSTACKSIZE]; -#define yystacksize YYSTACKSIZE -#line 468 "yacc_config.y" -void yyerror(char *msg, ...) -{ - va_list ap; - char str[256]; - - va_start(ap, msg); - sprintf(str, "config error, file '%s' line %d: ", - current_file, current_lineno); - vsprintf(str+strlen(str), msg, ap); -#if YYDEBUG - fprintf(stderr, "%s\n", str); -#else - syslog(LOG_ERR, "%s", str); -#endif - va_end(ap); -} - -static int add_binding(card_info_t *card, char *name, int fn) -{ - device_info_t *dev = root_device; - if (card->bindings == MAX_BINDINGS) { - yyerror("too many bindings\n"); - return -1; - } - for (; dev; dev = dev->next) - if (strcmp((char *)dev->dev_info, name) == 0) break; - if (dev == NULL) { - yyerror("unknown device: %s", name); - return -1; - } - card->device[card->bindings] = dev; - card->dev_fn[card->bindings] = fn; - card->bindings++; - free(name); - return 0; -} - -static int add_module(device_info_t *dev, char *name) -{ - if (dev->modules == MAX_MODULES) { - yyerror("too many modules"); - return -1; - } - dev->module[dev->modules] = name; - dev->opts[dev->modules] = NULL; - dev->modules++; - return 0; -} - -#if YYDEBUG -adjust_list_t *root_adjust = NULL; -device_info_t *root_device = NULL; -card_info_t *root_card = NULL, *blank_card = NULL, *root_func = NULL; -mtd_ident_t *root_mtd = NULL, *default_mtd = NULL; - -void main(int argc, char *argv[]) -{ - yydebug = 1; - if (argc > 1) - parse_configfile(argv[1]); -} -#endif -#line 426 "y.tab.c" -#define YYABORT goto yyabort -#define YYREJECT goto yyabort -#define YYACCEPT goto yyaccept -#define YYERROR goto yyerrlab -int yylex(void); -int -yyparse() -{ - register int yym, yyn, yystate; -#if YYDEBUG - register char *yys; - extern char *getenv(); - - if (yys = getenv("YYDEBUG")) - { - yyn = *yys; - if (yyn >= '0' && yyn <= '9') - yydebug = yyn - '0'; - } -#endif - - yynerrs = 0; - yyerrflag = 0; - yychar = (-1); - - yyssp = yyss; - yyvsp = yyvs; - *yyssp = yystate = 0; - -yyloop: - if ((yyn = yydefred[yystate])) goto yyreduce; - if (yychar < 0) - { - if ((yychar = yylex()) < 0) yychar = 0; -#if YYDEBUG - if (yydebug) - { - yys = 0; - if (yychar <= YYMAXTOKEN) yys = yyname[yychar]; - if (!yys) yys = "illegal-symbol"; - printf("%sdebug: state %d, reading %d (%s)\n", - YYPREFIX, yystate, yychar, yys); - } -#endif - } - if ((yyn = yysindex[yystate]) && (yyn += yychar) >= 0 && - yyn <= YYTABLESIZE && yycheck[yyn] == yychar) - { -#if YYDEBUG - if (yydebug) - printf("%sdebug: state %d, shifting to state %d\n", - YYPREFIX, yystate, yytable[yyn]); -#endif - if (yyssp >= yyss + yystacksize - 1) - { - goto yyoverflow; - } - *++yyssp = yystate = yytable[yyn]; - *++yyvsp = yylval; - yychar = (-1); - if (yyerrflag > 0) --yyerrflag; - goto yyloop; - } - if ((yyn = yyrindex[yystate]) && (yyn += yychar) >= 0 && - yyn <= YYTABLESIZE && yycheck[yyn] == yychar) - { - yyn = yytable[yyn]; - goto yyreduce; - } - if (yyerrflag) goto yyinrecovery; - yyerror("syntax error"); -#ifdef lint - goto yyerrlab; -#endif -yyerrlab: - ++yynerrs; -yyinrecovery: - if (yyerrflag < 3) - { - yyerrflag = 3; - for (;;) - { - if ((yyn = yysindex[*yyssp]) && (yyn += YYERRCODE) >= 0 && - yyn <= YYTABLESIZE && yycheck[yyn] == YYERRCODE) - { -#if YYDEBUG - if (yydebug) - printf("%sdebug: state %d, error recovery shifting\ - to state %d\n", YYPREFIX, *yyssp, yytable[yyn]); -#endif - if (yyssp >= yyss + yystacksize - 1) - { - goto yyoverflow; - } - *++yyssp = yystate = yytable[yyn]; - *++yyvsp = yylval; - goto yyloop; - } - else - { -#if YYDEBUG - if (yydebug) - printf("%sdebug: error recovery discarding state %d\n", - YYPREFIX, *yyssp); -#endif - if (yyssp <= yyss) goto yyabort; - --yyssp; - --yyvsp; - } - } - } - else - { - if (yychar == 0) goto yyabort; -#if YYDEBUG - if (yydebug) - { - yys = 0; - if (yychar <= YYMAXTOKEN) yys = yyname[yychar]; - if (!yys) yys = "illegal-symbol"; - printf("%sdebug: state %d, error recovery discards token %d (%s)\n", - YYPREFIX, yystate, yychar, yys); - } -#endif - yychar = (-1); - goto yyloop; - } -yyreduce: -#if YYDEBUG - if (yydebug) - printf("%sdebug: state %d, reducing by rule %d (%s)\n", - YYPREFIX, yystate, yyn, yyrule[yyn]); -#endif - yym = yylen[yyn]; - yyval = yyvsp[1-yym]; - switch (yyn) - { -case 2: -#line 84 "yacc_config.y" -{ - adjust_list_t **tail = &root_adjust; - while (*tail != NULL) tail = &(*tail)->next; - *tail = yyvsp[0].adjust; - } -break; -case 3: -#line 90 "yacc_config.y" -{ - yyvsp[0].device->next = root_device; - root_device = yyvsp[0].device; - } -break; -case 4: -#line 95 "yacc_config.y" -{ - if (yyvsp[0].mtd->mtd_type == 0) { - yyerror("no ID method for this card"); - YYERROR; - } - if (yyvsp[0].mtd->module == NULL) { - yyerror("no MTD module specified"); - YYERROR; - } - yyvsp[0].mtd->next = root_mtd; - root_mtd = yyvsp[0].mtd; - } -break; -case 5: -#line 108 "yacc_config.y" -{ - if (yyvsp[0].card->ident_type == 0) { - yyerror("no ID method for this card"); - YYERROR; - } - if (yyvsp[0].card->bindings == 0) { - yyerror("no function bindings"); - YYERROR; - } - if (yyvsp[0].card->ident_type == FUNC_IDENT) { - yyvsp[0].card->next = root_func; - root_func = yyvsp[0].card; - } else { - yyvsp[0].card->next = root_card; - root_card = yyvsp[0].card; - } - } -break; -case 9: -#line 131 "yacc_config.y" -{ - yyvsp[0].adjust->adj.Action = ADD_MANAGED_RESOURCE; - yyval.adjust = yyvsp[0].adjust; - } -break; -case 10: -#line 136 "yacc_config.y" -{ - yyvsp[0].adjust->adj.Action = REMOVE_MANAGED_RESOURCE; - yyval.adjust = yyvsp[0].adjust; - } -break; -case 11: -#line 141 "yacc_config.y" -{ - yyvsp[0].adjust->adj.Action = ADD_MANAGED_RESOURCE; - yyvsp[0].adjust->adj.Attributes |= RES_RESERVED; - yyval.adjust = yyvsp[0].adjust; - } -break; -case 12: -#line 147 "yacc_config.y" -{ - yyvsp[0].adjust->adj.Action = yyvsp[-2].adjust->adj.Action; - yyvsp[0].adjust->adj.Attributes = yyvsp[-2].adjust->adj.Attributes; - yyvsp[0].adjust->next = yyvsp[-2].adjust; - yyval.adjust = yyvsp[0].adjust; - } -break; -case 13: -#line 156 "yacc_config.y" -{ - yyval.adjust = calloc(sizeof(adjust_list_t), 1); - yyval.adjust->adj.Resource = RES_IRQ; - yyval.adjust->adj.resource.irq.IRQ = yyvsp[0].num; - } -break; -case 14: -#line 162 "yacc_config.y" -{ - if ((yyvsp[0].num < yyvsp[-2].num) || (yyvsp[0].num > 0xffff)) { - yyerror("invalid port range"); - YYERROR; - } - yyval.adjust = calloc(sizeof(adjust_list_t), 1); - yyval.adjust->adj.Resource = RES_IO_RANGE; - yyval.adjust->adj.resource.io.BasePort = yyvsp[-2].num; - yyval.adjust->adj.resource.io.NumPorts = yyvsp[0].num - yyvsp[-2].num + 1; - } -break; -case 15: -#line 173 "yacc_config.y" -{ - if (yyvsp[0].num < yyvsp[-2].num) { - yyerror("invalid address range"); - YYERROR; - } - yyval.adjust = calloc(sizeof(adjust_list_t), 1); - yyval.adjust->adj.Resource = RES_MEMORY_RANGE; - yyval.adjust->adj.resource.memory.Base = yyvsp[-2].num; - yyval.adjust->adj.resource.memory.Size = yyvsp[0].num - yyvsp[-2].num + 1; - } -break; -case 16: -#line 186 "yacc_config.y" -{ - yyval.device = calloc(sizeof(device_info_t), 1); - yyval.device->refs = 1; - strcpy(yyval.device->dev_info, yyvsp[0].str); - free(yyvsp[0].str); - } -break; -case 20: -#line 198 "yacc_config.y" -{ - yyval.card = calloc(sizeof(card_info_t), 1); - yyval.card->refs = 1; - yyval.card->name = yyvsp[0].str; - } -break; -case 29: -#line 214 "yacc_config.y" -{ - if (yyvsp[-1].card->ident_type != 0) { - yyerror("ID method already defined"); - YYERROR; - } - if (blank_card) { - yyerror("Anonymous card already defined"); - YYERROR; - } - yyvsp[-1].card->ident_type = BLANK_IDENT; - blank_card = yyvsp[-1].card; - } -break; -case 30: -#line 229 "yacc_config.y" -{ - if (yyvsp[-6].card->ident_type != 0) { - yyerror("ID method already defined"); - YYERROR; - } - yyvsp[-6].card->ident_type = TUPLE_IDENT; - yyvsp[-6].card->id.tuple.code = yyvsp[-4].num; - yyvsp[-6].card->id.tuple.ofs = yyvsp[-2].num; - yyvsp[-6].card->id.tuple.info = yyvsp[0].str; - } -break; -case 31: -#line 242 "yacc_config.y" -{ - if (yyvsp[-4].card->ident_type & EXCL_IDENT) { - yyerror("ID method already defined"); - YYERROR; - } - yyvsp[-4].card->ident_type = MANFID_IDENT; - yyvsp[-4].card->manfid.manf = yyvsp[-2].num; - yyvsp[-4].card->manfid.card = yyvsp[0].num; - } -break; -case 32: -#line 253 "yacc_config.y" -{ - if (yyvsp[-4].card->ident_type != 0) { - yyerror("ID method already defined"); - YYERROR; - } - yyvsp[-4].card->ident_type = PCI_IDENT; - yyvsp[-4].card->manfid.manf = yyvsp[-2].num; - yyvsp[-4].card->manfid.card = yyvsp[0].num; - } -break; -case 33: -#line 264 "yacc_config.y" -{ - if (yyvsp[-2].card->ident_type & EXCL_IDENT) { - yyerror("ID method already defined\n"); - YYERROR; - } - yyvsp[-2].card->ident_type = VERS_1_IDENT; - yyvsp[-2].card->id.vers.ns = 1; - yyvsp[-2].card->id.vers.pi[0] = yyvsp[0].str; - } -break; -case 34: -#line 274 "yacc_config.y" -{ - if (yyvsp[-2].card->id.vers.ns == 4) { - yyerror("too many version strings"); - YYERROR; - } - yyvsp[-2].card->id.vers.pi[yyvsp[-2].card->id.vers.ns] = yyvsp[0].str; - yyvsp[-2].card->id.vers.ns++; - } -break; -case 35: -#line 285 "yacc_config.y" -{ - if (yyvsp[-2].card->ident_type != 0) { - yyerror("ID method already defined\n"); - YYERROR; - } - yyvsp[-2].card->ident_type = FUNC_IDENT; - yyvsp[-2].card->id.func.funcid = yyvsp[0].num; - } -break; -case 36: -#line 296 "yacc_config.y" -{ yyvsp[-2].card->cis_file = strdup(yyvsp[0].str); } -break; -case 37: -#line 300 "yacc_config.y" -{ - if (add_binding(yyvsp[-2].card, yyvsp[0].str, 0) != 0) - YYERROR; - } -break; -case 38: -#line 305 "yacc_config.y" -{ - if (add_binding(yyvsp[-4].card, yyvsp[-2].str, yyvsp[0].num) != 0) - YYERROR; - } -break; -case 39: -#line 310 "yacc_config.y" -{ - if (add_binding(yyvsp[-2].card, yyvsp[0].str, 0) != 0) - YYERROR; - } -break; -case 40: -#line 315 "yacc_config.y" -{ - if (add_binding(yyvsp[-4].card, yyvsp[-2].str, yyvsp[0].num) != 0) - YYERROR; - } -break; -case 41: -#line 322 "yacc_config.y" -{ - yyvsp[-1].device->needs_mtd = 1; - } -break; -case 42: -#line 328 "yacc_config.y" -{ - device_info_t *d; - int i, found = 0; - for (d = root_device; d; d = d->next) { - for (i = 0; i < d->modules; i++) - if (strcmp(yyvsp[-2].str, d->module[i]) == 0) break; - if (i < d->modules) { - if (d->opts[i]) - free(d->opts[i]); - d->opts[i] = strdup(yyvsp[0].str); - found = 1; - } - } - free(yyvsp[-2].str); free(yyvsp[0].str); - if (!found) { - yyerror("module name not found!"); - YYERROR; - } - } -break; -case 43: -#line 350 "yacc_config.y" -{ - if (add_module(yyvsp[-2].device, yyvsp[0].str) != 0) - YYERROR; - } -break; -case 44: -#line 355 "yacc_config.y" -{ - if (yyvsp[-2].device->opts[yyvsp[-2].device->modules-1] == NULL) { - yyvsp[-2].device->opts[yyvsp[-2].device->modules-1] = yyvsp[0].str; - } else { - yyerror("too many options"); - YYERROR; - } - } -break; -case 45: -#line 364 "yacc_config.y" -{ - if (add_module(yyvsp[-2].device, yyvsp[0].str) != 0) - YYERROR; - } -break; -case 46: -#line 371 "yacc_config.y" -{ - if (yyvsp[-2].device->class != NULL) { - yyerror("extra class string"); - YYERROR; - } - yyvsp[-2].device->class = yyvsp[0].str; - } -break; -case 47: -#line 381 "yacc_config.y" -{ - yyval.mtd = calloc(sizeof(mtd_ident_t), 1); - yyval.mtd->refs = 1; - yyval.mtd->name = yyvsp[0].str; - } -break; -case 51: -#line 392 "yacc_config.y" -{ - if (yyvsp[-2].mtd->mtd_type != 0) { - yyerror("ID method already defined"); - YYERROR; - } - yyvsp[-2].mtd->mtd_type = DTYPE_MTD; - yyvsp[-2].mtd->dtype = yyvsp[0].num; - } -break; -case 52: -#line 403 "yacc_config.y" -{ - if (yyvsp[-3].mtd->mtd_type != 0) { - yyerror("ID method already defined"); - YYERROR; - } - yyvsp[-3].mtd->mtd_type = JEDEC_MTD; - yyvsp[-3].mtd->jedec_mfr = yyvsp[-1].num; - yyvsp[-3].mtd->jedec_info = yyvsp[0].num; - } -break; -case 53: -#line 415 "yacc_config.y" -{ - if (yyvsp[-1].mtd->mtd_type != 0) { - yyerror("ID method already defined"); - YYERROR; - } - if (default_mtd) { - yyerror("Default MTD already defined"); - YYERROR; - } - yyvsp[-1].mtd->mtd_type = DEFAULT_MTD; - default_mtd = yyvsp[-1].mtd; - } -break; -case 54: -#line 430 "yacc_config.y" -{ - if (yyvsp[-2].mtd->module != NULL) { - yyerror("extra MTD entry"); - YYERROR; - } - yyvsp[-2].mtd->module = yyvsp[0].str; - } -break; -case 55: -#line 438 "yacc_config.y" -{ - if (yyvsp[-2].mtd->opts == NULL) { - yyvsp[-2].mtd->opts = yyvsp[0].str; - } else { - yyerror("too many options"); - YYERROR; - } - } -break; -case 56: -#line 449 "yacc_config.y" -{ - mtd_ident_t *m; - int found = 0; - for (m = root_mtd; m; m = m->next) - if (strcmp(yyvsp[-2].str, m->module) == 0) break; - if (m) { - if (m->opts) free(m->opts); - m->opts = strdup(yyvsp[0].str); - found = 1; - } - free(yyvsp[-2].str); free(yyvsp[0].str); - if (!found) { - yyerror("MTD name not found!"); - YYERROR; - } - } -break; -#line 966 "y.tab.c" - } - yyssp -= yym; - yystate = *yyssp; - yyvsp -= yym; - yym = yylhs[yyn]; - if (yystate == 0 && yym == 0) - { -#if YYDEBUG - if (yydebug) - printf("%sdebug: after reduction, shifting from state 0 to\ - state %d\n", YYPREFIX, YYFINAL); -#endif - yystate = YYFINAL; - *++yyssp = YYFINAL; - *++yyvsp = yyval; - if (yychar < 0) - { - if ((yychar = yylex()) < 0) yychar = 0; -#if YYDEBUG - if (yydebug) - { - yys = 0; - if (yychar <= YYMAXTOKEN) yys = yyname[yychar]; - if (!yys) yys = "illegal-symbol"; - printf("%sdebug: state %d, reading %d (%s)\n", - YYPREFIX, YYFINAL, yychar, yys); - } -#endif - } - if (yychar == 0) goto yyaccept; - goto yyloop; - } - if ((yyn = yygindex[yym]) && (yyn += yystate) >= 0 && - yyn <= YYTABLESIZE && yycheck[yyn] == yystate) - yystate = yytable[yyn]; - else - yystate = yydgoto[yym]; -#if YYDEBUG - if (yydebug) - printf("%sdebug: after reduction, shifting from state %d \ -to state %d\n", YYPREFIX, *yyssp, yystate); -#endif - if (yyssp >= yyss + yystacksize - 1) - { - goto yyoverflow; - } - *++yyssp = yystate; - *++yyvsp = yyval; - goto yyloop; -yyoverflow: - yyerror("yacc stack overflow"); -yyabort: - return (1); -yyaccept: - return (0); -} diff --git a/mdk-stage1/pcmcia_/yacc_config.h b/mdk-stage1/pcmcia_/yacc_config.h deleted file mode 100644 index f9b881def..000000000 --- a/mdk-stage1/pcmcia_/yacc_config.h +++ /dev/null @@ -1,37 +0,0 @@ -#define DEVICE 257 -#define CARD 258 -#define ANONYMOUS 259 -#define TUPLE 260 -#define MANFID 261 -#define VERSION 262 -#define FUNCTION 263 -#define PCI 264 -#define BIND 265 -#define CIS 266 -#define TO 267 -#define NEEDS_MTD 268 -#define MODULE 269 -#define OPTS 270 -#define CLASS 271 -#define REGION 272 -#define JEDEC 273 -#define DTYPE 274 -#define DEFAULT 275 -#define MTD 276 -#define INCLUDE 277 -#define EXCLUDE 278 -#define RESERVE 279 -#define IRQ_NO 280 -#define PORT 281 -#define MEMORY 282 -#define STRING 283 -#define NUMBER 284 -typedef union { - char *str; - unsigned long num; - struct device_info_t *device; - struct card_info_t *card; - struct mtd_ident_t *mtd; - struct adjust_list_t *adjust; -} YYSTYPE; -extern YYSTYPE yylval; diff --git a/mdk-stage1/ppp/.cvsignore b/mdk-stage1/ppp/.cvsignore deleted file mode 100644 index c258b925d..000000000 --- a/mdk-stage1/ppp/.cvsignore +++ /dev/null @@ -1 +0,0 @@ -pppd-bin diff --git a/mdk-stage1/ppp/pppd/.cvsignore b/mdk-stage1/ppp/pppd/.cvsignore deleted file mode 100644 index 476ef2253..000000000 --- a/mdk-stage1/ppp/pppd/.cvsignore +++ /dev/null @@ -1,2 +0,0 @@ -pppd -pppd-DIET diff --git a/mdk-stage1/ppp/pppd/Makefile b/mdk-stage1/ppp/pppd/Makefile index 3544dd19d..fb5658879 100644 --- a/mdk-stage1/ppp/pppd/Makefile +++ b/mdk-stage1/ppp/pppd/Makefile @@ -20,7 +20,7 @@ include $(top_dir)/Makefile.common TARGETS = pppd -BINTARGET = ../pppd-bin +BINTARGET = ../../pppd all: $(TARGETS) @@ -29,6 +29,8 @@ clean: rm -f *.o *.a $(BINTARGET) pppd FLAGS = -Wall -Wno-deprecated-declarations -Werror -Os -fomit-frame-pointer -DDO_BSD_COMPRESS=0 -D_linux_=1 -DHAVE_MMAP -DNO_DRAND48 -D_BSD_SOURCE -D_GNU_SOURCE +# (blino) for gcc-4.1.1, dereferencing type-punned pointer will break strict-aliasing rules, in options.c:711 +FLAGS += -fno-strict-aliasing INCS = -I../include -I. diff --git a/mdk-stage1/ppp/pppd/ipv6cp.c b/mdk-stage1/ppp/pppd/ipv6cp.c index 54ff7d7d8..35fa2b53a 100644 --- a/mdk-stage1/ppp/pppd/ipv6cp.c +++ b/mdk-stage1/ppp/pppd/ipv6cp.c @@ -22,30 +22,30 @@ Alain.Durand@imag.fr, IMAG, Jean-Luc.Richier@imag.fr, IMAG-LSR. - Ce travail a été fait au sein du GIE DYADE (Groupement d'Intérêt - Économique ayant pour membres BULL S.A. et l'INRIA). + Ce travail a été fait au sein du GIE DYADE (Groupement d'Intérêt + Économique ayant pour membres BULL S.A. et l'INRIA). Ce logiciel informatique est disponible aux conditions - usuelles dans la recherche, c'est-à-dire qu'il peut - être utilisé, copié, modifié, distribué à l'unique - condition que ce texte soit conservé afin que + usuelles dans la recherche, c'est-à -dire qu'il peut + être utilisé, copié, modifié, distribué à l'unique + condition que ce texte soit conservé afin que l'origine de ce logiciel soit reconnue. Le nom de l'Institut National de Recherche en Informatique et en Automatique (INRIA), de l'IMAG, ou d'une personne morale - ou physique ayant participé à l'élaboration de ce logiciel ne peut - être utilisé sans son accord préalable explicite. + ou physique ayant participé à l'élaboration de ce logiciel ne peut + être utilisé sans son accord préalable explicite. Ce logiciel est fourni tel quel sans aucune garantie, - support ou responsabilité d'aucune sorte. - Ce logiciel est dérivé de sources d'origine + support ou responsabilité d'aucune sorte. + Ce logiciel est dérivé de sources d'origine "University of California at Berkeley" et "Digital Equipment Corporation" couvertes par des copyrights. - L'Institut d'Informatique et de Mathématiques Appliquées de Grenoble (IMAG) - est une fédération d'unités mixtes de recherche du CNRS, de l'Institut National - Polytechnique de Grenoble et de l'Université Joseph Fourier regroupant - sept laboratoires dont le laboratoire Logiciels, Systèmes, Réseaux (LSR). + L'Institut d'Informatique et de Mathématiques Appliquées de Grenoble (IMAG) + est une fédération d'unités mixtes de recherche du CNRS, de l'Institut National + Polytechnique de Grenoble et de l'Université Joseph Fourier regroupant + sept laboratoires dont le laboratoire Logiciels, Systèmes, Réseaux (LSR). This work has been done in the context of GIE DYADE (joint R & D venture between BULL S.A. and INRIA). diff --git a/mdk-stage1/ppp/pppd/ipv6cp.h b/mdk-stage1/ppp/pppd/ipv6cp.h index 60d366eb3..c98d80209 100644 --- a/mdk-stage1/ppp/pppd/ipv6cp.h +++ b/mdk-stage1/ppp/pppd/ipv6cp.h @@ -22,30 +22,30 @@ Alain.Durand@imag.fr, IMAG, Jean-Luc.Richier@imag.fr, IMAG-LSR. - Ce travail a été fait au sein du GIE DYADE (Groupement d'Intérêt - Économique ayant pour membres BULL S.A. et l'INRIA). + Ce travail a été fait au sein du GIE DYADE (Groupement d'Intérêt + Économique ayant pour membres BULL S.A. et l'INRIA). Ce logiciel informatique est disponible aux conditions - usuelles dans la recherche, c'est-à-dire qu'il peut - être utilisé, copié, modifié, distribué à l'unique - condition que ce texte soit conservé afin que + usuelles dans la recherche, c'est-à -dire qu'il peut + être utilisé, copié, modifié, distribué à l'unique + condition que ce texte soit conservé afin que l'origine de ce logiciel soit reconnue. Le nom de l'Institut National de Recherche en Informatique et en Automatique (INRIA), de l'IMAG, ou d'une personne morale - ou physique ayant participé à l'élaboration de ce logiciel ne peut - être utilisé sans son accord préalable explicite. + ou physique ayant participé à l'élaboration de ce logiciel ne peut + être utilisé sans son accord préalable explicite. Ce logiciel est fourni tel quel sans aucune garantie, - support ou responsabilité d'aucune sorte. - Ce logiciel est dérivé de sources d'origine + support ou responsabilité d'aucune sorte. + Ce logiciel est dérivé de sources d'origine "University of California at Berkeley" et "Digital Equipment Corporation" couvertes par des copyrights. - L'Institut d'Informatique et de Mathématiques Appliquées de Grenoble (IMAG) - est une fédération d'unités mixtes de recherche du CNRS, de l'Institut National - Polytechnique de Grenoble et de l'Université Joseph Fourier regroupant - sept laboratoires dont le laboratoire Logiciels, Systèmes, Réseaux (LSR). + L'Institut d'Informatique et de Mathématiques Appliquées de Grenoble (IMAG) + est une fédération d'unités mixtes de recherche du CNRS, de l'Institut National + Polytechnique de Grenoble et de l'Université Joseph Fourier regroupant + sept laboratoires dont le laboratoire Logiciels, Systèmes, Réseaux (LSR). This work has been done in the context of GIE DYADE (joint R & D venture between BULL S.A. and INRIA). diff --git a/mdk-stage1/probing.c b/mdk-stage1/probing.c index 31f7db0b1..803c11806 100644 --- a/mdk-stage1/probing.c +++ b/mdk-stage1/probing.c @@ -35,7 +35,9 @@ #include <string.h> #include <sys/types.h> #include <sys/stat.h> +#include <dirent.h> #include <fcntl.h> +#include <fnmatch.h> #include <sys/socket.h> #include <net/if.h> #include <sys/ioctl.h> @@ -50,6 +52,10 @@ #ifdef ENABLE_USB #include "usb-resource/usb-ids.h" #endif +#ifdef ENABLE_PCMCIA +#include "sysfs/libsysfs.h" +#include "pcmcia-resource/pcmcia-ids.h" +#endif #include "probing.h" @@ -121,21 +127,44 @@ char * get_net_intf_description(char * intf_name) } #endif -struct pcitable_entry detected_devices[50]; +struct pcitable_entry *detected_devices = NULL; int detected_devices_len = 0; +static void detected_devices_destroy(void) +{ + if (detected_devices) + free(detected_devices); +} + +static struct pcitable_entry *detected_device_new(void) +{ + static int detected_devices_maxlen = 0; + if (detected_devices_len >= detected_devices_maxlen) { + detected_devices_maxlen += 32; + if (detected_devices == NULL) + detected_devices = malloc(detected_devices_maxlen * sizeof(*detected_devices)); + else + detected_devices = realloc(detected_devices, detected_devices_maxlen * sizeof(*detected_devices)); + if (detected_devices == NULL) + log_perror("detected_device_new: could not (re)allocate table. Let it crash, sorry"); + } + return &detected_devices[detected_devices_len++]; +} + /* FIXME: factorize with probe_that_type() */ -static void add_detected_device(unsigned short vendor, unsigned short device, const char *name, const char *module) +static void add_detected_device(unsigned short vendor, unsigned short device, unsigned int subvendor, unsigned int subdevice, const char *name, const char *module) { - struct pcitable_entry *dev = &detected_devices[detected_devices_len++]; + struct pcitable_entry *dev = detected_device_new(); dev->vendor = vendor; dev->device = device; - strncpy(dev->module, module, 19); - dev->module[19] = '\0'; - strncpy(dev->description, name, 99); - dev->description[99] = '\0'; - log_message("detected device (%x, %x, %s, %s)", vendor, device, name, module); + dev->subvendor = subvendor; + dev->subdevice = subdevice; + strncpy(dev->module, module, sizeof(dev->module) - 1); + dev->module[sizeof(dev->module) - 1] = '\0'; + strncpy(dev->description, name, sizeof(dev->description) - 1); + dev->description[sizeof(dev->description) - 1] = '\0'; + log_message("detected device (%04x, %04x, %04x, %04x, %s, %s)", vendor, device, subvendor, subdevice, name, module); } static int check_device_full(struct pci_module_map_full * pcidb_full, unsigned int len_full, @@ -146,7 +175,7 @@ static int check_device_full(struct pci_module_map_full * pcidb_full, unsigned i for (i = 0; i < len_full; i++) if (pcidb_full[i].vendor == vendor && pcidb_full[i].device == device) { if (pcidb_full[i].subvendor == subvendor && pcidb_full[i].subdevice == subdevice) { - add_detected_device(pcidb_full[i].vendor, pcidb_full[i].device, + add_detected_device(vendor, device, subvendor, subdevice, pcidb_full[i].name, pcidb_full[i].module); return 1; } @@ -155,11 +184,13 @@ static int check_device_full(struct pci_module_map_full * pcidb_full, unsigned i } static int check_device(struct pci_module_map * pcidb, unsigned int len, - unsigned short vendor, unsigned short device) { + unsigned short vendor, unsigned short device, + unsigned short subvendor, unsigned short subdevice) +{ int i; for (i = 0; i < len; i++) if (pcidb[i].vendor == vendor && pcidb[i].device == device) { - add_detected_device(pcidb[i].vendor, pcidb[i].device, + add_detected_device(vendor, device, subvendor, subdevice, pcidb[i].name, pcidb[i].module); return 1; } @@ -169,7 +200,7 @@ static int check_device(struct pci_module_map * pcidb, unsigned int len, void probing_detect_devices() { FILE * f = NULL; - char buf[200]; + char buf[512]; /* XXX the better fix is to readjust on '\n' */ static int already_detected_devices = 0; if (already_detected_devices) @@ -213,31 +244,36 @@ void probing_detect_devices() #ifndef DISABLE_MEDIAS if (check_device_full(medias_pci_ids_full, medias_num_ids_full, vendor, device, subvendor, subdevice)) continue; - if (check_device(medias_pci_ids, medias_num_ids, vendor, device)) + if (check_device(medias_pci_ids, medias_num_ids, vendor, device, subvendor, subdevice)) continue; #endif #ifndef DISABLE_NETWORK if (check_device_full(network_pci_ids_full, network_num_ids_full, vendor, device, subvendor, subdevice)) continue; - if (check_device(network_pci_ids, network_num_ids, vendor, device)) + if (check_device(network_pci_ids, network_num_ids, vendor, device, subvendor, subdevice)) continue; #endif #endif #ifdef ENABLE_USB - if (check_device(usb_pci_ids, usb_num_ids, vendor, device)) + if (check_device(usb_pci_ids, usb_num_ids, vendor, device, subvendor, subdevice)) continue; #endif /* device can't be found in built-in pcitables, but keep it */ - add_detected_device(vendor, device, "", ""); + add_detected_device(vendor, device, subvendor, subdevice, "", ""); } fclose(f); already_detected_devices = 1; } +void probing_destroy(void) +{ + detected_devices_destroy(); +} + #ifndef DISABLE_MEDIAS static const char * get_alternate_module(const char * name) { @@ -266,16 +302,15 @@ static const char * get_alternate_module(const char * name) } #endif -void discovered_device(enum driver_type type, - unsigned short vendor, unsigned short device, unsigned short subvendor, unsigned short subdevice, - const char * description, const char * driver) +void discovered_device(enum driver_type type, const char * description, const char * driver) { + + enum insmod_return failed = INSMOD_FAILED; - log_message("PCI: device %04x %04x %04x %04x is \"%s\", driver is %s", vendor, device, subvendor, subdevice, description, driver); #ifndef DISABLE_MEDIAS if (type == SCSI_ADAPTERS) { const char * alternate = NULL; - wait_message("Loading driver for SCSI adapter:\n \n%s", description); + wait_message("Loading driver for media adapter:\n \n%s", description); failed = my_insmod(driver, SCSI_ADAPTERS, NULL, 1); alternate = get_alternate_module(driver); if (!IS_NOAUTO && alternate) { @@ -440,7 +475,8 @@ void probe_that_type(enum driver_type type, enum media_bus bus __attribute__ ((u continue; found_pci_device: - discovered_device(type_, vendor, device, subvendor, subdevice, name, module); + log_message("PCI: device %04x %04x %04x %04x is \"%s\", driver is %s", vendor, device, subvendor, subdevice, name, module); + discovered_device(type_, name, module); } end_pci_probe:; if (f) @@ -502,16 +538,7 @@ void probe_that_type(enum driver_type type, enum media_bus bus __attribute__ ((u for (i = 0; i < len; i++) { if (usbdb[i].vendor == vendor && usbdb[i].id == id) { log_message("USB: device %04x %04x is \"%s\" (%s)", vendor, id, usbdb[i].name, usbdb[i].module); -#ifndef DISABLE_NETWORK - if (type == NETWORK_DEVICES) { - stg1_info_message("About to load driver for usb network device:\n \n%s", usbdb[i].name); - prepare_intf_descr(usbdb[i].name); - warning_insmod_failed(my_insmod(usbdb[i].module, NETWORK_DEVICES, NULL, 1)); - if (intf_descr_for_discover) /* for modules providing more than one net intf */ - net_discovered_interface(NULL); - } -#endif - + discovered_device(type, usbdb[i].name, usbdb[i].module); } } } @@ -521,6 +548,95 @@ void probe_that_type(enum driver_type type, enum media_bus bus __attribute__ ((u } #endif +#ifdef ENABLE_PCMCIA + /* ---- PCMCIA probe ---------------------------------------------- */ + if ((bus == BUS_PCMCIA || bus == BUS_ANY) && !(IS_NOAUTO)) { + struct pcmcia_alias * pcmciadb = NULL; + unsigned int len = 0; + char *base = "/sys/bus/pcmcia/devices"; + DIR *dir; + struct dirent *dent; + + dir = opendir(base); + if (dir == NULL) + goto end_pcmcia_probe; + + switch (type) { +#ifndef DISABLE_MEDIAS + case SCSI_ADAPTERS: + pcmciadb = medias_pcmcia_ids; + len = medias_pcmcia_num_ids; + break; +#endif +#ifndef DISABLE_NETWORK + case NETWORK_DEVICES: + pcmciadb = network_pcmcia_ids; + len = network_pcmcia_num_ids; + break; +#endif + default: + goto end_pcmcia_probe; + } + + for (dent = readdir(dir); dent != NULL; dent = readdir(dir)) { + struct sysfs_attribute *modalias_attr; + char keyfile[256]; + int i, id; + + if (dent->d_name[0] == '.') + continue; + + log_message("PCMCIA: device found %s", dent->d_name); + + snprintf(keyfile, sizeof(keyfile)-1, "%s/%s/modalias", base, dent->d_name); + modalias_attr = sysfs_open_attribute(keyfile); + if (!modalias_attr) + continue; + if (sysfs_read_attribute(modalias_attr) != 0 || !modalias_attr->value) { + sysfs_close_attribute(modalias_attr); + continue; + } + + log_message("PCMCIA: device found %s", modalias_attr->value); + + for (i = 0; i < len; i++) { + if (!fnmatch(pcmciadb[i].modalias, modalias_attr->value, 0)) { + char product[256]; + + log_message("PCMCIA: device found %s (%s)", pcmciadb[i].modalias, pcmciadb[i].module); + strcpy(product, ""); + for (id = 1; id <= 4; id++) { + struct sysfs_attribute *product_attr; + snprintf(keyfile, sizeof(keyfile)-1, "%s/%s/prod_id%d", base, dent->d_name, id); + product_attr = sysfs_open_attribute(keyfile); + if (!product_attr) + continue; + if (sysfs_read_attribute(product_attr) || !product_attr->value) { + sysfs_close_attribute(product_attr); + continue; + } + snprintf(product + strlen(product), sizeof(product)-strlen(product)-1, "%s%s", product[0] ? " " : "", product_attr->value); + if (product[strlen(product)-1] == '\n') + product[strlen(product)-1] = '\0'; + sysfs_close_attribute(product_attr); + } + + if (!product[0]) + strcpy(product, "PCMCIA device"); + + log_message("PCMCIA: device found %s (%s)", product, pcmciadb[i].module); + discovered_device(type, product, pcmciadb[i].module); + } + } + + sysfs_close_attribute(modalias_attr); + } + end_pcmcia_probe:; + if (dir) + closedir(dir); + } +#endif + /* be sure to load usb-storage after SCSI adapters, so that they are in same order than reboot, so that naming is the same */ if (type == SCSI_ADAPTERS && already_probed_usb_controllers && !already_loaded_usb_scsi) { @@ -549,8 +665,8 @@ static void find_media(enum media_bus bus) if (medias) free(medias); /* that does not free the strings, by the way */ - if (bus == BUS_SCSI || bus == BUS_USB || bus == BUS_ANY) { - log_message("looking for SCSI adapters"); + if (bus == BUS_SCSI || bus == BUS_USB || bus == BUS_PCMCIA || bus == BUS_ANY) { + log_message("looking for media adapters"); probe_that_type(SCSI_ADAPTERS, bus); } /* ----------------------------------------------- */ @@ -626,7 +742,7 @@ static void find_media(enum media_bus bus) find_media_after_ide: /* ----------------------------------------------- */ - if (bus != BUS_SCSI && bus != BUS_USB && bus != BUS_ANY) + if (bus != BUS_SCSI && bus != BUS_USB && bus != BUS_PCMCIA && bus != BUS_ANY) goto find_media_after_scsi; log_message("looking for scsi media"); diff --git a/mdk-stage1/probing.h b/mdk-stage1/probing.h index 6efa7b464..ed1af8ea6 100644 --- a/mdk-stage1/probing.h +++ b/mdk-stage1/probing.h @@ -26,7 +26,7 @@ enum media_type { CDROM, DISK, FLOPPY, TAPE, UNKNOWN_MEDIA }; enum driver_type { SCSI_ADAPTERS, NETWORK_DEVICES, USB_CONTROLLERS, ANY_DRIVER_TYPE }; -enum media_bus { BUS_IDE, BUS_SCSI, BUS_USB, BUS_ANY }; +enum media_bus { BUS_IDE, BUS_SCSI, BUS_USB, BUS_PCMCIA, BUS_ANY }; void get_medias(enum media_type media, char *** names, char *** models, enum media_bus bus); char ** get_net_devices(void); @@ -35,17 +35,24 @@ char * get_net_intf_description(char * intf_name); void prepare_intf_descr(const char * intf_descr); void probe_that_type(enum driver_type type, enum media_bus bus); +/* Make sure the MATCH_ALL value is greater than all possible values + for subvendor & subdevice: this simplifies the orderer */ +#define PCITABLE_MATCH_ALL 0x10000 + struct pcitable_entry { /* some bits stolen from pci-resource/pci-ids.h * FIXME: split pci-ids.h into pci-ids.c and pci-ids.h so that the header can be re-used */ unsigned short vendor; /* PCI vendor id */ unsigned short device; /* PCI device id */ + unsigned int subvendor; /* PCI subvendor id */ + unsigned int subdevice; /* PCI subdevice id */ char module[20]; /* module to load */ char description[100]; /* PCI human readable description */ }; -extern struct pcitable_entry detected_devices[50]; +extern struct pcitable_entry *detected_devices; extern int detected_devices_len; void probing_detect_devices(); +void probing_destroy(void); #endif diff --git a/mdk-stage1/rp-pppoe/.cvsignore b/mdk-stage1/rp-pppoe/.cvsignore deleted file mode 100644 index 1f345b56b..000000000 --- a/mdk-stage1/rp-pppoe/.cvsignore +++ /dev/null @@ -1 +0,0 @@ -pppoe-bin diff --git a/mdk-stage1/rp-pppoe/src/.cvsignore b/mdk-stage1/rp-pppoe/src/.cvsignore deleted file mode 100644 index a59197332..000000000 --- a/mdk-stage1/rp-pppoe/src/.cvsignore +++ /dev/null @@ -1,2 +0,0 @@ -pppoe -pppoe-DIET diff --git a/mdk-stage1/rp-pppoe/src/Makefile b/mdk-stage1/rp-pppoe/src/Makefile index d36ad6c60..b618e12a9 100644 --- a/mdk-stage1/rp-pppoe/src/Makefile +++ b/mdk-stage1/rp-pppoe/src/Makefile @@ -20,7 +20,7 @@ include $(top_dir)/Makefile.common TARGETS = pppoe -BINTARGET = ../pppoe-bin +BINTARGET = ../../pppoe all: $(TARGETS) diff --git a/mdk-stage1/slang/sltoken.c b/mdk-stage1/slang/sltoken.c index d08967a24..c9852e68a 100644 --- a/mdk-stage1/slang/sltoken.c +++ b/mdk-stage1/slang/sltoken.c @@ -265,70 +265,70 @@ static unsigned char Char_Type_Table[256][2] = { OP_CHAR, OFS_BOR }, /* | */ { SEP_CHAR, CBRACE_TOKEN }, /* } */ { OP_CHAR, OFS_BNOT }, /* ~ */ { BAD_CHAR, 0 }, /* 0x7f */ - { ALPHA_CHAR, 0 }, /* € */ { ALPHA_CHAR, 0 }, /* */ - { ALPHA_CHAR, 0 }, /* ‚ */ { ALPHA_CHAR, 0 }, /* ƒ */ - { ALPHA_CHAR, 0 }, /* „ */ { ALPHA_CHAR, 0 }, /* … */ - { ALPHA_CHAR, 0 }, /* † */ { ALPHA_CHAR, 0 }, /* ‡ */ - { ALPHA_CHAR, 0 }, /* ˆ */ { ALPHA_CHAR, 0 }, /* ‰ */ - { ALPHA_CHAR, 0 }, /* Š */ { ALPHA_CHAR, 0 }, /* ‹ */ - { ALPHA_CHAR, 0 }, /* Œ */ { ALPHA_CHAR, 0 }, /* */ - { ALPHA_CHAR, 0 }, /* Ž */ { ALPHA_CHAR, 0 }, /* */ - { ALPHA_CHAR, 0 }, /* */ { ALPHA_CHAR, 0 }, /* ‘ */ - { ALPHA_CHAR, 0 }, /* ’ */ { ALPHA_CHAR, 0 }, /* “ */ - { ALPHA_CHAR, 0 }, /* ” */ { ALPHA_CHAR, 0 }, /* • */ - { ALPHA_CHAR, 0 }, /* – */ { ALPHA_CHAR, 0 }, /* — */ - { ALPHA_CHAR, 0 }, /* ˜ */ { ALPHA_CHAR, 0 }, /* ™ */ - { ALPHA_CHAR, 0 }, /* š */ { ALPHA_CHAR, 0 }, /* › */ - { ALPHA_CHAR, 0 }, /* œ */ { ALPHA_CHAR, 0 }, /* */ - { ALPHA_CHAR, 0 }, /* ž */ { ALPHA_CHAR, 0 }, /* Ÿ */ - { ALPHA_CHAR, 0 }, /* */ { ALPHA_CHAR, 0 }, /* ¡ */ - { ALPHA_CHAR, 0 }, /* ¢ */ { ALPHA_CHAR, 0 }, /* £ */ - { ALPHA_CHAR, 0 }, /* ¤ */ { ALPHA_CHAR, 0 }, /* ¥ */ - { ALPHA_CHAR, 0 }, /* ¦ */ { ALPHA_CHAR, 0 }, /* § */ - { ALPHA_CHAR, 0 }, /* ¨ */ { ALPHA_CHAR, 0 }, /* © */ - { ALPHA_CHAR, 0 }, /* ª */ { ALPHA_CHAR, 0 }, /* « */ - { ALPHA_CHAR, 0 }, /* ¬ */ { ALPHA_CHAR, 0 }, /* */ - { ALPHA_CHAR, 0 }, /* ® */ { ALPHA_CHAR, 0 }, /* ¯ */ - { ALPHA_CHAR, 0 }, /* ° */ { ALPHA_CHAR, 0 }, /* ± */ - { ALPHA_CHAR, 0 }, /* ² */ { ALPHA_CHAR, 0 }, /* ³ */ - { ALPHA_CHAR, 0 }, /* ´ */ { ALPHA_CHAR, 0 }, /* µ */ - { ALPHA_CHAR, 0 }, /* ¶ */ { ALPHA_CHAR, 0 }, /* · */ - { ALPHA_CHAR, 0 }, /* ¸ */ { ALPHA_CHAR, 0 }, /* ¹ */ - { ALPHA_CHAR, 0 }, /* º */ { ALPHA_CHAR, 0 }, /* » */ - { ALPHA_CHAR, 0 }, /* ¼ */ { ALPHA_CHAR, 0 }, /* ½ */ - { ALPHA_CHAR, 0 }, /* ¾ */ { ALPHA_CHAR, 0 }, /* ¿ */ - { ALPHA_CHAR, 0 }, /* À */ { ALPHA_CHAR, 0 }, /* Á */ - { ALPHA_CHAR, 0 }, /*  */ { ALPHA_CHAR, 0 }, /* à */ - { ALPHA_CHAR, 0 }, /* Ä */ { ALPHA_CHAR, 0 }, /* Å */ - { ALPHA_CHAR, 0 }, /* Æ */ { ALPHA_CHAR, 0 }, /* Ç */ - { ALPHA_CHAR, 0 }, /* È */ { ALPHA_CHAR, 0 }, /* É */ - { ALPHA_CHAR, 0 }, /* Ê */ { ALPHA_CHAR, 0 }, /* Ë */ - { ALPHA_CHAR, 0 }, /* Ì */ { ALPHA_CHAR, 0 }, /* Í */ - { ALPHA_CHAR, 0 }, /* Î */ { ALPHA_CHAR, 0 }, /* Ï */ - { ALPHA_CHAR, 0 }, /* Ð */ { ALPHA_CHAR, 0 }, /* Ñ */ - { ALPHA_CHAR, 0 }, /* Ò */ { ALPHA_CHAR, 0 }, /* Ó */ - { ALPHA_CHAR, 0 }, /* Ô */ { ALPHA_CHAR, 0 }, /* Õ */ - { ALPHA_CHAR, 0 }, /* Ö */ { ALPHA_CHAR, 0 }, /* × */ - { ALPHA_CHAR, 0 }, /* Ø */ { ALPHA_CHAR, 0 }, /* Ù */ - { ALPHA_CHAR, 0 }, /* Ú */ { ALPHA_CHAR, 0 }, /* Û */ - { ALPHA_CHAR, 0 }, /* Ü */ { ALPHA_CHAR, 0 }, /* Ý */ - { ALPHA_CHAR, 0 }, /* Þ */ { ALPHA_CHAR, 0 }, /* ß */ - { ALPHA_CHAR, 0 }, /* à */ { ALPHA_CHAR, 0 }, /* á */ - { ALPHA_CHAR, 0 }, /* â */ { ALPHA_CHAR, 0 }, /* ã */ - { ALPHA_CHAR, 0 }, /* ä */ { ALPHA_CHAR, 0 }, /* å */ - { ALPHA_CHAR, 0 }, /* æ */ { ALPHA_CHAR, 0 }, /* ç */ - { ALPHA_CHAR, 0 }, /* è */ { ALPHA_CHAR, 0 }, /* é */ - { ALPHA_CHAR, 0 }, /* ê */ { ALPHA_CHAR, 0 }, /* ë */ - { ALPHA_CHAR, 0 }, /* ì */ { ALPHA_CHAR, 0 }, /* í */ - { ALPHA_CHAR, 0 }, /* î */ { ALPHA_CHAR, 0 }, /* ï */ - { ALPHA_CHAR, 0 }, /* ð */ { ALPHA_CHAR, 0 }, /* ñ */ - { ALPHA_CHAR, 0 }, /* ò */ { ALPHA_CHAR, 0 }, /* ó */ - { ALPHA_CHAR, 0 }, /* ô */ { ALPHA_CHAR, 0 }, /* õ */ - { ALPHA_CHAR, 0 }, /* ö */ { ALPHA_CHAR, 0 }, /* ÷ */ - { ALPHA_CHAR, 0 }, /* ø */ { ALPHA_CHAR, 0 }, /* ù */ - { ALPHA_CHAR, 0 }, /* ú */ { ALPHA_CHAR, 0 }, /* û */ - { ALPHA_CHAR, 0 }, /* ü */ { ALPHA_CHAR, 0 }, /* ý */ - { ALPHA_CHAR, 0 }, /* þ */ { ALPHA_CHAR, 0 }, /* ÿ */ + { ALPHA_CHAR, 0 }, /* € */ { ALPHA_CHAR, 0 }, /*  */ + { ALPHA_CHAR, 0 }, /* ‚ */ { ALPHA_CHAR, 0 }, /* ƒ */ + { ALPHA_CHAR, 0 }, /* „ */ { ALPHA_CHAR, 0 }, /* Â… */ + { ALPHA_CHAR, 0 }, /* † */ { ALPHA_CHAR, 0 }, /* ‡ */ + { ALPHA_CHAR, 0 }, /* ˆ */ { ALPHA_CHAR, 0 }, /* ‰ */ + { ALPHA_CHAR, 0 }, /* Š */ { ALPHA_CHAR, 0 }, /* ‹ */ + { ALPHA_CHAR, 0 }, /* ÂŒ */ { ALPHA_CHAR, 0 }, /*  */ + { ALPHA_CHAR, 0 }, /* ÂŽ */ { ALPHA_CHAR, 0 }, /*  */ + { ALPHA_CHAR, 0 }, /*  */ { ALPHA_CHAR, 0 }, /* ‘ */ + { ALPHA_CHAR, 0 }, /* Â’ */ { ALPHA_CHAR, 0 }, /* “ */ + { ALPHA_CHAR, 0 }, /* ” */ { ALPHA_CHAR, 0 }, /* • */ + { ALPHA_CHAR, 0 }, /* – */ { ALPHA_CHAR, 0 }, /* — */ + { ALPHA_CHAR, 0 }, /* ˜ */ { ALPHA_CHAR, 0 }, /* ™ */ + { ALPHA_CHAR, 0 }, /* š */ { ALPHA_CHAR, 0 }, /* › */ + { ALPHA_CHAR, 0 }, /* Âœ */ { ALPHA_CHAR, 0 }, /*  */ + { ALPHA_CHAR, 0 }, /* ž */ { ALPHA_CHAR, 0 }, /* Ÿ */ + { ALPHA_CHAR, 0 }, /*  */ { ALPHA_CHAR, 0 }, /* ¡ */ + { ALPHA_CHAR, 0 }, /* ¢ */ { ALPHA_CHAR, 0 }, /* £ */ + { ALPHA_CHAR, 0 }, /* ¤ */ { ALPHA_CHAR, 0 }, /* Â¥ */ + { ALPHA_CHAR, 0 }, /* ¦ */ { ALPHA_CHAR, 0 }, /* § */ + { ALPHA_CHAR, 0 }, /* ¨ */ { ALPHA_CHAR, 0 }, /* © */ + { ALPHA_CHAR, 0 }, /* ª */ { ALPHA_CHAR, 0 }, /* « */ + { ALPHA_CHAR, 0 }, /* ¬ */ { ALPHA_CHAR, 0 }, /*  */ + { ALPHA_CHAR, 0 }, /* ® */ { ALPHA_CHAR, 0 }, /* ¯ */ + { ALPHA_CHAR, 0 }, /* ° */ { ALPHA_CHAR, 0 }, /* ± */ + { ALPHA_CHAR, 0 }, /* ² */ { ALPHA_CHAR, 0 }, /* ³ */ + { ALPHA_CHAR, 0 }, /* ´ */ { ALPHA_CHAR, 0 }, /* µ */ + { ALPHA_CHAR, 0 }, /* ¶ */ { ALPHA_CHAR, 0 }, /* · */ + { ALPHA_CHAR, 0 }, /* ¸ */ { ALPHA_CHAR, 0 }, /* ¹ */ + { ALPHA_CHAR, 0 }, /* º */ { ALPHA_CHAR, 0 }, /* » */ + { ALPHA_CHAR, 0 }, /* ¼ */ { ALPHA_CHAR, 0 }, /* ½ */ + { ALPHA_CHAR, 0 }, /* ¾ */ { ALPHA_CHAR, 0 }, /* ¿ */ + { ALPHA_CHAR, 0 }, /* À */ { ALPHA_CHAR, 0 }, /* à */ + { ALPHA_CHAR, 0 }, /*  */ { ALPHA_CHAR, 0 }, /* à */ + { ALPHA_CHAR, 0 }, /* Ä */ { ALPHA_CHAR, 0 }, /* Ã… */ + { ALPHA_CHAR, 0 }, /* Æ */ { ALPHA_CHAR, 0 }, /* Ç */ + { ALPHA_CHAR, 0 }, /* È */ { ALPHA_CHAR, 0 }, /* É */ + { ALPHA_CHAR, 0 }, /* Ê */ { ALPHA_CHAR, 0 }, /* Ë */ + { ALPHA_CHAR, 0 }, /* ÃŒ */ { ALPHA_CHAR, 0 }, /* à */ + { ALPHA_CHAR, 0 }, /* ÃŽ */ { ALPHA_CHAR, 0 }, /* à */ + { ALPHA_CHAR, 0 }, /* à */ { ALPHA_CHAR, 0 }, /* Ñ */ + { ALPHA_CHAR, 0 }, /* Ã’ */ { ALPHA_CHAR, 0 }, /* Ó */ + { ALPHA_CHAR, 0 }, /* Ô */ { ALPHA_CHAR, 0 }, /* Õ */ + { ALPHA_CHAR, 0 }, /* Ö */ { ALPHA_CHAR, 0 }, /* × */ + { ALPHA_CHAR, 0 }, /* Ø */ { ALPHA_CHAR, 0 }, /* Ù */ + { ALPHA_CHAR, 0 }, /* Ú */ { ALPHA_CHAR, 0 }, /* Û */ + { ALPHA_CHAR, 0 }, /* Ãœ */ { ALPHA_CHAR, 0 }, /* à */ + { ALPHA_CHAR, 0 }, /* Þ */ { ALPHA_CHAR, 0 }, /* ß */ + { ALPHA_CHAR, 0 }, /* à */ { ALPHA_CHAR, 0 }, /* á */ + { ALPHA_CHAR, 0 }, /* â */ { ALPHA_CHAR, 0 }, /* ã */ + { ALPHA_CHAR, 0 }, /* ä */ { ALPHA_CHAR, 0 }, /* Ã¥ */ + { ALPHA_CHAR, 0 }, /* æ */ { ALPHA_CHAR, 0 }, /* ç */ + { ALPHA_CHAR, 0 }, /* è */ { ALPHA_CHAR, 0 }, /* é */ + { ALPHA_CHAR, 0 }, /* ê */ { ALPHA_CHAR, 0 }, /* ë */ + { ALPHA_CHAR, 0 }, /* ì */ { ALPHA_CHAR, 0 }, /* à */ + { ALPHA_CHAR, 0 }, /* î */ { ALPHA_CHAR, 0 }, /* ï */ + { ALPHA_CHAR, 0 }, /* ð */ { ALPHA_CHAR, 0 }, /* ñ */ + { ALPHA_CHAR, 0 }, /* ò */ { ALPHA_CHAR, 0 }, /* ó */ + { ALPHA_CHAR, 0 }, /* ô */ { ALPHA_CHAR, 0 }, /* õ */ + { ALPHA_CHAR, 0 }, /* ö */ { ALPHA_CHAR, 0 }, /* ÷ */ + { ALPHA_CHAR, 0 }, /* ø */ { ALPHA_CHAR, 0 }, /* ù */ + { ALPHA_CHAR, 0 }, /* ú */ { ALPHA_CHAR, 0 }, /* û */ + { ALPHA_CHAR, 0 }, /* ü */ { ALPHA_CHAR, 0 }, /* ý */ + { ALPHA_CHAR, 0 }, /* þ */ { ALPHA_CHAR, 0 }, /* ÿ */ }; int _SLcheck_identifier_syntax (char *name) diff --git a/mdk-stage1/stage1-data/stage1-with-busybox.tar.bz2 b/mdk-stage1/stage1-data/stage1-with-busybox.tar.bz2 Binary files differdeleted file mode 100644 index 337b13666..000000000 --- a/mdk-stage1/stage1-data/stage1-with-busybox.tar.bz2 +++ /dev/null diff --git a/mdk-stage1/stage1-data/stage1-with-ka.tar.bz2 b/mdk-stage1/stage1-data/stage1-with-ka.tar.bz2 Binary files differdeleted file mode 100644 index b11adf85d..000000000 --- a/mdk-stage1/stage1-data/stage1-with-ka.tar.bz2 +++ /dev/null diff --git a/mdk-stage1/stage1-data/stage1-with-sash.tar.bz2 b/mdk-stage1/stage1-data/stage1-with-sash.tar.bz2 Binary files differdeleted file mode 100644 index 56279ae90..000000000 --- a/mdk-stage1/stage1-data/stage1-with-sash.tar.bz2 +++ /dev/null diff --git a/mdk-stage1/stage1-data/stage1.tar.bz2 b/mdk-stage1/stage1-data/stage1.tar.bz2 Binary files differdeleted file mode 100644 index 98e62b362..000000000 --- a/mdk-stage1/stage1-data/stage1.tar.bz2 +++ /dev/null diff --git a/mdk-stage1/stage1.c b/mdk-stage1/stage1.c index 6024f20ca..41456cc5c 100644 --- a/mdk-stage1/stage1.c +++ b/mdk-stage1/stage1.c @@ -34,7 +34,6 @@ #include <stdarg.h> #include <signal.h> #include <linux/unistd.h> -_syscall2(int,pivot_root,const char *,new_root,const char *,put_old) #include "stage1.h" @@ -45,11 +44,10 @@ _syscall2(int,pivot_root,const char *,new_root,const char *,put_old) #include "tools.h" #include "automatic.h" #include "mount.h" -#include "insmod.h" #include "thirdparty.h" #ifdef ENABLE_PCMCIA -#include "pcmcia_/pcmcia.h" +#include "pcmcia/pcmcia.h" #endif #ifndef DISABLE_CDROM @@ -121,7 +119,7 @@ static pid_t shell_pid = 0; static void spawn_shell(void) { int fd; - char * shell_name[] = { "/tmp/sh", NULL }; + char * shell_name[] = { "/sbin/sh", NULL }; log_message("spawning a shell"); @@ -236,12 +234,10 @@ static void handle_pcmcia(void) my_insmod("ds", ANY_DRIVER_TYPE, NULL, 0); my_insmod("pcmcia", ANY_DRIVER_TYPE, NULL, 0); - /* call to cardmgr takes time, let's use the wait message */ - wait_message("Enabling PCMCIA extension cards..."); - log_message("cardmgr rc: %d", cardmgr_call()); - remove_wait_message(); + /* setup a dynamic resource database for non statically mapped PCMCIA sockets */ + pcmcia_socket_startup(-1); - add_to_env("PCMCIA", pcmcia_adapter); + add_to_env("PCMCIA", pcmcia_adapter); } #endif @@ -283,17 +279,14 @@ static void method_select_and_prepare(void) #endif #ifndef DISABLE_CDROM means[i] = cdrom_install; means_auto[i++] = cdrom_install_auto; - allow_additional_modules_floppy = 0; #endif #ifndef DISABLE_DISK means[i] = disk_install; means_auto[i++] = disk_install_auto; - allow_additional_modules_floppy = 0; #endif means[i] = thirdparty_install; means_auto[i++] = thirdparty_install_auto; means[i] = NULL; unlink(IMAGE_LOCATION); - rmdir(IMAGE_LOCATION); /* useful if we change the method, eg: we have automatic:cdrom but go back to nfs */ results = ask_from_list_auto("Please choose the installation method.", means, &choice, "method", means_auto); @@ -314,7 +307,6 @@ static void method_select_and_prepare(void) if (!strcmp(choice, network_nfs_install)) results = nfs_prepare(); -#ifndef MANDRAKE_MOVE if (!strcmp(choice, network_ftp_install)) results = ftp_prepare(); @@ -326,7 +318,6 @@ static void method_select_and_prepare(void) results = ka_prepare(); #endif #endif -#endif if (!strcmp(choice, thirdparty_install)) { thirdparty_load_modules(); @@ -348,203 +339,30 @@ static enum return_type create_initial_fs_symlinks(char* symlinks) if (scall(!(f = fopen(symlinks, "rb")), "fopen")) return RETURN_ERROR; while (fgets(buf, sizeof(buf), f)) { - char oldpath[500], newpath[500], newpathfinal[500]; + char oldpath[500], newpath[500]; buf[strlen(buf)-1] = '\0'; // trim \n if (sscanf(buf, "%s %s", oldpath, newpath) != 2) { - sprintf(oldpath, "%s%s", STAGE2_LOCATION_ROOTED, buf); - sprintf(newpathfinal, "%s%s", SLASH_LOCATION, buf); - } else { - sprintf(newpathfinal, "%s%s", SLASH_LOCATION, newpath); + sprintf(oldpath, "%s%s", STAGE2_LOCATION, buf); + sprintf(newpath, "%s", buf); } - log_message("creating symlink %s -> %s", oldpath, newpathfinal); - if (scall(symlink(oldpath, newpathfinal), "symlink")) - return RETURN_ERROR; - } - fclose(f); - return RETURN_OK; -} - -static enum return_type create_initial_fs_devices(char* devices) -{ - FILE *f; - char buf[5000]; - - // need to create the few devices needed to start up stage2 in a decent manner, we can't symlink or they will keep CD busy - if (scall(mkdir(SLASH_LOCATION "/dev", 0755), "mkdir")) - return RETURN_ERROR; - if (scall(!(f = fopen(devices, "rb")), "fopen")) - return RETURN_ERROR; - while (fgets(buf, sizeof(buf), f)) { - char name[500], path[500], type; - int major, minor; - sscanf(buf, "%s %c %d %d", name, &type, &major, &minor); - sprintf(path, "%s%s", SLASH_LOCATION, name); - log_message("creating device %s %c %d %d", path, type, major, minor); - if (scall(mknod(path, (type == 'c' ? S_IFCHR : S_IFBLK) | 0600, makedev(major, minor)), "mknod")) + recursiveRemove_if_it_exists(newpath); + log_message("creating symlink %s -> %s", oldpath, newpath); + if (scall(symlink(oldpath, newpath), "symlink")) return RETURN_ERROR; } fclose(f); return RETURN_OK; } -#ifdef MANDRAKE_MOVE -static enum return_type handle_move_clp(char* clp_name, char* live, char* location_live, char* location_mount, int* is_symlink, int preload) -{ - if (mount_clp_may_preload(clp_name, location_mount, preload) == RETURN_OK) { - return RETURN_OK; - } else { - char *full_live = asprintf_("%s%s", location_live, live); - log_message("no %s found (or disabled), trying to fallback on plain tree", clp_name); - if (!access(full_live, R_OK)) { - if (scall(symlink(location_live, location_mount), "symlink")) - return RETURN_ERROR; - *is_symlink = 1; - return RETURN_OK; - } else { - log_message("move: can't find %s nor %s, proceeding hoping files will be there", clp_name, full_live); - return RETURN_OK; - } - } -} - -int mandrake_move_post(void) -{ - int boot__real_is_symlink_to_raw = 0; - int always__real_is_symlink_to_raw = 0; - int totem__real_is_symlink_to_raw = 0; - int main__real_is_symlink_to_raw = 0; - - if (handle_move_clp("live_tree_boot.clp", "/usr/bin/runstage2.pl", - IMAGE_LOCATION "/live_tree_boot", BOOT_LOCATION, - &boot__real_is_symlink_to_raw, 1) != RETURN_OK) - return RETURN_ERROR; - - if (handle_move_clp("live_tree_always.clp", "/bin/bash", - IMAGE_LOCATION "/live_tree_always", ALWAYS_LOCATION, - &always__real_is_symlink_to_raw, 1) != RETURN_OK) - return RETURN_ERROR; - - if (handle_move_clp("live_tree_totem.clp", "/usr/bin/totem", - IMAGE_LOCATION "/live_tree_totem", TOTEM_LOCATION, - &totem__real_is_symlink_to_raw, 1) != RETURN_OK) - return RETURN_ERROR; - - if (handle_move_clp("live_tree.clp", "/etc/fstab", - IMAGE_LOCATION "/live_tree", STAGE2_LOCATION, - &main__real_is_symlink_to_raw, 0) != RETURN_OK) - return RETURN_ERROR; - - // in case we didn't mount any clp, because gzloop.o is not available later in /lib/modules - my_insmod("gzloop", ANY_DRIVER_TYPE, NULL, 0); - - // hardcoded :( - if (!access(TOTEM_LOCATION, R_OK)) { - if (scall(symlink("/image_totem/usr", SLASH_LOCATION "/usr"), "symlink")) - return RETURN_ERROR; - } else - // need a fallback in case we don't use image_totem.clp nor live_tree_totem, but we're in -u mode - if (scall(symlink(STAGE2_LOCATION_ROOTED "/usr", SLASH_LOCATION "/usr"), "symlink")) - return RETURN_ERROR; - - if (create_initial_fs_symlinks(STAGE2_LOCATION "/move/symlinks") != RETURN_OK || - create_initial_fs_devices(STAGE2_LOCATION "/move/devices") != RETURN_OK) - return RETURN_ERROR; - - if (boot__real_is_symlink_to_raw) { - if (scall(unlink(BOOT_LOCATION), "unlink")) - return RETURN_ERROR; - if (scall(symlink(IMAGE_LOCATION_REL "/live_tree_boot", BOOT_LOCATION), "symlink")) - return RETURN_ERROR; - } - - if (always__real_is_symlink_to_raw) { - if (scall(unlink(ALWAYS_LOCATION), "unlink")) - return RETURN_ERROR; - if (scall(symlink(IMAGE_LOCATION_REL "/live_tree_always", ALWAYS_LOCATION), "symlink")) - return RETURN_ERROR; - } - - if (totem__real_is_symlink_to_raw) { - if (scall(unlink(TOTEM_LOCATION), "unlink")) - return RETURN_ERROR; - if (scall(symlink(IMAGE_LOCATION_REL "/live_tree_totem", TOTEM_LOCATION), "symlink")) - return RETURN_ERROR; - } - - if (main__real_is_symlink_to_raw) { - if (scall(unlink(STAGE2_LOCATION), "unlink")) - return RETURN_ERROR; - if (scall(symlink(IMAGE_LOCATION_REL "/live_tree", STAGE2_LOCATION), "symlink")) - return RETURN_ERROR; - } - return RETURN_OK; -} -#endif - -int do_pivot_root(void) -{ - int fd; - char rootdev[] = "0x0100"; - - if (IS_DEBUGSTAGE1) - while (1); - - log_message("pivot_rooting"); - // trick so that kernel won't try to mount the root device when initrd exits - if (scall((fd = open("/proc/sys/kernel/real-root-dev", O_WRONLY)) < 0, "open")) - return RETURN_ERROR; - if (scall(write(fd, rootdev, strlen(rootdev)) != (signed)strlen(rootdev), "write")) { - close(fd); - return RETURN_ERROR; - } - close(fd); - - if (scall(mkdir(SLASH_LOCATION "/stage1", 0755), "mkdir")) - return RETURN_ERROR; - - if (scall(pivot_root(SLASH_LOCATION, SLASH_LOCATION "/stage1"), "pivot_root")) - return RETURN_ERROR; - - return RETURN_OK; -} - void finish_preparing(void) { -#ifdef MANDRAKE_MOVE - if (mandrake_move_post() != RETURN_OK) - stg1_fatal_message("Fatal error when launching MandrakeMove."); -#else - mkdir(SLASH_LOCATION "/etc", 0755); - mkdir(SLASH_LOCATION "/var", 0755); - if (IS_RESCUE) { - if (create_initial_fs_symlinks(STAGE2_LOCATION "/usr/share/symlinks") != RETURN_OK) - stg1_fatal_message("Fatal error finishing initialization."); - - } else { - if (create_initial_fs_symlinks(STAGE2_LOCATION "/usr/share/symlinks") != RETURN_OK || - create_initial_fs_devices(STAGE2_LOCATION "/usr/share/devices") != RETURN_OK) - stg1_fatal_message("Fatal error finishing initialization."); - } -#endif + recursiveRemove("/init"); + + if (create_initial_fs_symlinks(STAGE2_LOCATION "/usr/share/symlinks") != RETURN_OK) + stg1_fatal_message("Fatal error finishing initialization."); /* /tmp/syslog is used by the second init, so it must be copied now, not in stage2 */ /* we remove it to ensure the old one is not copied over it in stage2 */ - copy_file("/tmp/syslog", SLASH_LOCATION "/tmp/syslog", NULL); - unlink("/tmp/syslog"); - copy_file("/etc/resolv.conf", SLASH_LOCATION "/etc/resolv.conf", NULL); - mkdir(SLASH_LOCATION "/modules", 0755); - copy_file("/modules/modules.dep", SLASH_LOCATION "/modules/modules.dep", NULL); - - if (!IS_RESCUE) { - copy_file(STAGE2_LOCATION "/etc/init", SLASH_LOCATION "/etc/init", NULL); - chmod(SLASH_LOCATION "/etc/init", 0755); - } - - umount("/tmp/tmpfs"); - do_pivot_root(); - - if (file_size(IS_RESCUE ? "/sbin/init" : "/etc/init") == -1) - stg1_fatal_message("Fatal error giving hand to second stage."); #ifdef SPAWN_SHELL if (shell_pid != 0) { @@ -576,13 +394,6 @@ int main(int argc __attribute__ ((unused)), char **argv __attribute__ ((unused)) set_param(MODE_TESTING); } - if (!IS_TESTING) { - mkdir(SLASH_LOCATION, 0755); - if (scall(mount("none", SLASH_LOCATION, "tmpfs", MS_MGC_VAL, NULL), "mount tmpfs")) - fatal_error("Fatal error initializing."); - mkdir(SLASH_LOCATION "/tmp", 0755); - } - #ifdef SPAWN_INTERACTIVE spawn_interactive(); #endif @@ -618,18 +429,13 @@ int main(int argc __attribute__ ((unused)), char **argv __attribute__ ((unused)) "your own risk. Alternatively, you may reboot your system now."); } -#ifdef MANDRAKE_MOVE - if (total_memory() < MEM_LIMIT_MOVE) - stg1_info_message(DISTRIB_NAME " typically needs more than %d Mbytes of memory (detected %d Mbytes). You may proceed, but the machine may crash or lock up for no apparent reason. Continue at your own risk. Alternatively, you may reboot your system now.", - MEM_LIMIT_MOVE, total_memory()); -#endif method_select_and_prepare(); -#ifndef MANDRAKE_MOVE + thirdparty_destroy(); + if (access(STAGE2_LOCATION, R_OK) != 0) if (symlink(IMAGE_LOCATION_REL "/" LIVE_LOCATION_REL, STAGE2_LOCATION) != 0) log_perror("symlink from " IMAGE_LOCATION_REL "/" LIVE_LOCATION_REL " to " STAGE2_LOCATION " failed"); -#endif #ifdef SPAWN_INTERACTIVE if (interactive_pid != 0) @@ -641,9 +447,9 @@ int main(int argc __attribute__ ((unused)), char **argv __attribute__ ((unused)) finish_frontend(); close_log(); - if (IS_TESTING) - return 0; + if (IS_RESCUE) + return 66; /* ask init to exec new init */ else - return 66; + return 0x35; /* ask init to run stage2 binary */ #endif } diff --git a/mdk-stage1/pcmcia_/Makefile b/mdk-stage1/sysfs/Makefile index 9cecc8784..5cab07408 100644 --- a/mdk-stage1/pcmcia_/Makefile +++ b/mdk-stage1/sysfs/Makefile @@ -1,8 +1,9 @@ #****************************************************************************** # # Guillaume Cottenceau (gc@mandrakesoft.com) + # Olivier Blin (blino@mandriva.com) # - # Copyright 2001 Mandrakesoft + # Copyright 2006 Mandriva # # This software may be freely redistributed under the terms of the GNU # public license. @@ -13,23 +14,24 @@ # #***************************************************************************** +# minimal sysfs library ripped from sysfsutils-2.0.0 + top_dir = .. include $(top_dir)/Makefile.common +TARGET = libsysfs.a -all: libpcmcia.a +all: $(TARGET) clean: - rm -f *.o libpcmcia.a + rm -f *.o $(TARGET) FLAGS = -D__linux__ -Wall -Werror -Wno-deprecated-declarations -Os -fomit-frame-pointer -pipe -c -I.. -D_BSD_SOURCE +OBJS = sysfs_attr.o sysfs_utils.o -OBJS = probe.o cardmgr.o lex_config.o yacc_config.o - - -libpcmcia.a: $(OBJS) +$(TARGET): $(OBJS) ar -cru $@ $^ ranlib $@ diff --git a/mdk-stage1/sysfs/libsysfs.h b/mdk-stage1/sysfs/libsysfs.h new file mode 100644 index 000000000..7bdf54fea --- /dev/null +++ b/mdk-stage1/sysfs/libsysfs.h @@ -0,0 +1,90 @@ +/* + * libsysfs.h + * + * Header Definitions for libsysfs + * + * Copyright (C) IBM Corp. 2004-2005 + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + * + */ +#ifndef _LIBSYSFS_H_ +#define _LIBSYSFS_H_ + +#include <sys/types.h> +#include <string.h> + +#define SYSFS_FSTYPE_NAME "sysfs" +#define SYSFS_PROC_MNTS "/proc/mounts" +#define SYSFS_BUS_NAME "bus" +#define SYSFS_CLASS_NAME "class" +#define SYSFS_BLOCK_NAME "block" +#define SYSFS_DEVICES_NAME "devices" +#define SYSFS_DRIVERS_NAME "drivers" +#define SYSFS_MODULE_NAME "module" +#define SYSFS_NAME_ATTRIBUTE "name" +#define SYSFS_MOD_PARM_NAME "parameters" +#define SYSFS_MOD_SECT_NAME "sections" +#define SYSFS_UNKNOWN "unknown" +#define SYSFS_PATH_ENV "SYSFS_PATH" + +#define SYSFS_PATH_MAX 256 +#define SYSFS_NAME_LEN 64 +#define SYSFS_BUS_ID_SIZE 32 + +/* mount path for sysfs, can be overridden by exporting SYSFS_PATH */ +#define SYSFS_MNT_PATH "/sys" + +enum sysfs_attribute_method { + SYSFS_METHOD_SHOW = 0x01, /* attr can be read by user */ + SYSFS_METHOD_STORE = 0x02, /* attr can be changed by user */ +}; + +/* + * NOTE: + * 1. We have the statically allocated "name" as the first element of all + * the structures. This feature is used in the "sorter" function for dlists + * 2. As is the case with attrlist + * 3. As is the case with path + */ +struct sysfs_attribute { + char name[SYSFS_NAME_LEN]; + char path[SYSFS_PATH_MAX]; + char *value; + unsigned short len; /* value length */ + enum sysfs_attribute_method method; /* show and store */ +}; + +#ifdef __cplusplus +extern "C" { +#endif + +/* + * Function Prototypes + */ +extern int sysfs_get_name_from_path(const char *path, char *name, size_t len); + +/* sysfs directory and file access */ +extern void sysfs_close_attribute(struct sysfs_attribute *sysattr); +extern struct sysfs_attribute *sysfs_open_attribute(const char *path); +extern int sysfs_read_attribute(struct sysfs_attribute *sysattr); +extern int sysfs_write_attribute(struct sysfs_attribute *sysattr, + const char *new_value, size_t len); + +#ifdef __cplusplus +} +#endif + +#endif /* _LIBSYSFS_H_ */ diff --git a/mdk-stage1/sysfs/sysfs.h b/mdk-stage1/sysfs/sysfs.h new file mode 100644 index 000000000..76754a421 --- /dev/null +++ b/mdk-stage1/sysfs/sysfs.h @@ -0,0 +1,64 @@ +/* + * sysfs.h + * + * Internal Header Definitions for libsysfs + * + * Copyright (C) IBM Corp. 2003-2005 + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + * + */ +#ifndef _SYSFS_H_ +#define _SYSFS_H_ + +#include <stdio.h> +#include <stdlib.h> +#include <unistd.h> +#include <string.h> +#include <ctype.h> +#include <dirent.h> +#include <sys/stat.h> +#include <fcntl.h> +#include <errno.h> + +#define safestrcpy(to, from) strncpy(to, from, sizeof(to)-1) +#define safestrcat(to, from) strncat(to, from, sizeof(to) - strlen(to)-1) + +#define safestrcpymax(to, from, max) \ +do { \ + to[max-1] = '\0'; \ + strncpy(to, from, max-1); \ +} while (0) + +#define safestrcatmax(to, from, max) \ +do { \ + to[max-1] = '\0'; \ + strncat(to, from, max - strlen(to)-1); \ +} while (0) + +extern struct sysfs_attribute *get_attribute(void *dev, const char *name); +extern struct dlist *read_dir_subdirs(const char *path); +extern struct dlist *read_dir_links(const char *path); +extern struct dlist *get_dev_attributes_list(void *dev); +extern struct dlist *get_attributes_list(struct dlist *alist, const char *path); + +/* Debugging */ +#ifdef DEBUG +#define dprintf(format, arg...) fprintf(stderr, format, ## arg) +#else +#define dprintf(format, arg...) do { } while (0) +#endif + +#endif /* _SYSFS_H_ */ diff --git a/mdk-stage1/sysfs/sysfs_attr.c b/mdk-stage1/sysfs/sysfs_attr.c new file mode 100644 index 000000000..6d6771188 --- /dev/null +++ b/mdk-stage1/sysfs/sysfs_attr.c @@ -0,0 +1,241 @@ +/* + * sysfs_dir.c + * + * Directory utility functions for libsysfs + * + * Copyright (C) IBM Corp. 2003-2005 + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + * + */ +#include "libsysfs.h" +#include "sysfs.h" + +/** + * sysfs_close_attribute: closes and cleans up attribute + * @sysattr: attribute to close. + */ +void sysfs_close_attribute(struct sysfs_attribute *sysattr) +{ + if (sysattr) { + if (sysattr->value) + free(sysattr->value); + free(sysattr); + } +} + +/** + * alloc_attribute: allocates and initializes attribute structure + * returns struct sysfs_attribute with success and NULL with error. + */ +static struct sysfs_attribute *alloc_attribute(void) +{ + return (struct sysfs_attribute *) + calloc(1, sizeof(struct sysfs_attribute)); +} + +/** + * sysfs_open_attribute: creates sysfs_attribute structure + * @path: path to attribute. + * returns sysfs_attribute struct with success and NULL with error. + */ +struct sysfs_attribute *sysfs_open_attribute(const char *path) +{ + struct sysfs_attribute *sysattr = NULL; + struct stat fileinfo; + + if (!path) { + errno = EINVAL; + return NULL; + } + sysattr = alloc_attribute(); + if (!sysattr) { + dprintf("Error allocating attribute at %s\n", path); + return NULL; + } + if (sysfs_get_name_from_path(path, sysattr->name, + SYSFS_NAME_LEN) != 0) { + dprintf("Error retrieving attrib name from path: %s\n", path); + sysfs_close_attribute(sysattr); + return NULL; + } + safestrcpy(sysattr->path, path); + if ((stat(sysattr->path, &fileinfo)) != 0) { + dprintf("Stat failed: No such attribute?\n"); + sysattr->method = 0; + free(sysattr); + sysattr = NULL; + } else { + if (fileinfo.st_mode & S_IRUSR) + sysattr->method |= SYSFS_METHOD_SHOW; + if (fileinfo.st_mode & S_IWUSR) + sysattr->method |= SYSFS_METHOD_STORE; + } + + return sysattr; +} + +/** + * sysfs_read_attribute: reads value from attribute + * @sysattr: attribute to read + * returns 0 with success and -1 with error. + */ +int sysfs_read_attribute(struct sysfs_attribute *sysattr) +{ + char *fbuf = NULL; + char *vbuf = NULL; + ssize_t length = 0; + long pgsize = 0; + int fd; + + if (!sysattr) { + errno = EINVAL; + return -1; + } + if (!(sysattr->method & SYSFS_METHOD_SHOW)) { + dprintf("Show method not supported for attribute %s\n", + sysattr->path); + errno = EACCES; + return -1; + } + pgsize = getpagesize(); + fbuf = (char *)calloc(1, pgsize+1); + if (!fbuf) { + dprintf("calloc failed\n"); + return -1; + } + if ((fd = open(sysattr->path, O_RDONLY)) < 0) { + dprintf("Error reading attribute %s\n", sysattr->path); + free(fbuf); + return -1; + } + length = read(fd, fbuf, pgsize); + if (length < 0) { + dprintf("Error reading from attribute %s\n", sysattr->path); + close(fd); + free(fbuf); + return -1; + } + if (sysattr->len > 0) { + if ((sysattr->len == length) && + (!(strncmp(sysattr->value, fbuf, length)))) { + close(fd); + free(fbuf); + return 0; + } + free(sysattr->value); + } + sysattr->len = length; + close(fd); + vbuf = (char *)realloc(fbuf, length+1); + if (!vbuf) { + dprintf("realloc failed\n"); + free(fbuf); + return -1; + } + sysattr->value = vbuf; + + return 0; +} + +/** + * sysfs_write_attribute: write value to the attribute + * @sysattr: attribute to write + * @new_value: value to write + * @len: length of "new_value" + * returns 0 with success and -1 with error. + */ +int sysfs_write_attribute(struct sysfs_attribute *sysattr, + const char *new_value, size_t len) +{ + int fd; + int length; + + if (!sysattr || !new_value || len == 0) { + errno = EINVAL; + return -1; + } + + if (!(sysattr->method & SYSFS_METHOD_STORE)) { + dprintf ("Store method not supported for attribute %s\n", + sysattr->path); + errno = EACCES; + return -1; + } + if (sysattr->method & SYSFS_METHOD_SHOW) { + /* + * read attribute again to see if we can get an updated value + */ + if ((sysfs_read_attribute(sysattr))) { + dprintf("Error reading attribute\n"); + return -1; + } + if ((strncmp(sysattr->value, new_value, sysattr->len)) == 0 && + (len == sysattr->len)) { + dprintf("Attr %s already has the requested value %s\n", + sysattr->name, new_value); + return 0; + } + } + /* + * open O_WRONLY since some attributes have no "read" but only + * "write" permission + */ + if ((fd = open(sysattr->path, O_WRONLY)) < 0) { + dprintf("Error reading attribute %s\n", sysattr->path); + return -1; + } + + length = write(fd, new_value, len); + if (length < 0) { + dprintf("Error writing to the attribute %s - invalid value?\n", + sysattr->name); + close(fd); + return -1; + } else if ((unsigned int)length != len) { + dprintf("Could not write %zd bytes to attribute %s\n", + len, sysattr->name); + /* + * since we could not write user supplied number of bytes, + * restore the old value if one available + */ + if (sysattr->method & SYSFS_METHOD_SHOW) { + length = write(fd, sysattr->value, sysattr->len); + close(fd); + return -1; + } + } + + /* + * Validate length that has been copied. Alloc appropriate area + * in sysfs_attribute. Verify first if the attribute supports reading + * (show method). If it does not, do not bother + */ + if (sysattr->method & SYSFS_METHOD_SHOW) { + if (length != sysattr->len) { + sysattr->value = (char *)realloc + (sysattr->value, length); + sysattr->len = length; + safestrcpymax(sysattr->value, new_value, length); + } else { + /*"length" of the new value is same as old one */ + safestrcpymax(sysattr->value, new_value, length); + } + } + + close(fd); + return 0; +} + diff --git a/mdk-stage1/sysfs/sysfs_utils.c b/mdk-stage1/sysfs/sysfs_utils.c new file mode 100644 index 000000000..a0354a8f8 --- /dev/null +++ b/mdk-stage1/sysfs/sysfs_utils.c @@ -0,0 +1,59 @@ +/* + * sysfs_utils.c + * + * System utility functions for libsysfs + * + * Copyright (C) IBM Corp. 2003-2005 + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + * + */ +#include "libsysfs.h" +#include "sysfs.h" + +/** + * sysfs_get_name_from_path: returns last name from a "/" delimited path + * @path: path to get name from + * @name: where to put name + * @len: size of name + */ +int sysfs_get_name_from_path(const char *path, char *name, size_t len) +{ + char tmp[SYSFS_PATH_MAX]; + char *n = NULL; + + if (!path || !name || len == 0) { + errno = EINVAL; + return -1; + } + memset(tmp, 0, SYSFS_PATH_MAX); + safestrcpy(tmp, path); + n = strrchr(tmp, '/'); + if (n == NULL) { + errno = EINVAL; + return -1; + } + if (*(n+1) == '\0') { + *n = '\0'; + n = strrchr(tmp, '/'); + if (n == NULL) { + errno = EINVAL; + return -1; + } + } + n++; + safestrcpymax(name, n, len); + return 0; +} diff --git a/mdk-stage1/thirdparty.c b/mdk-stage1/thirdparty.c index f5dac2808..8c73bd88e 100644 --- a/mdk-stage1/thirdparty.c +++ b/mdk-stage1/thirdparty.c @@ -21,7 +21,6 @@ #include "stage1.h" #include "log.h" -#include "insmod.h" #include "modules.h" #include "mount.h" #include "frontend.h" @@ -33,7 +32,8 @@ #define THIRDPARTY_MOUNT_LOCATION "/tmp/thirdparty" -static struct pcitable_entry pcitable[100]; +#define N_PCITABLE_ENTRIES 100 +static struct pcitable_entry pcitable[N_PCITABLE_ENTRIES]; static int pcitable_len = 0; static enum return_type thirdparty_choose_device(char ** device, int probe_only) @@ -218,6 +218,25 @@ static enum return_type thirdparty_prompt_modules(const char *modules_location, } +static int pcitable_orderer(const void *a, const void *b) +{ + int ret; + struct pcitable_entry *ap = (struct pcitable_entry *)a; + struct pcitable_entry *bp = (struct pcitable_entry *)b; + + if ((ret = ap->vendor - bp->vendor) != 0) + return ret; + if ((ret = ap->device - bp->device) != 0) + return ret; + if ((ret = ap->subvendor - bp->subvendor) != 0) + return ret; + if ((ret = ap->subdevice - bp->subdevice) != 0) + return ret; + + return 0; +} + + static void thirdparty_load_pcitable(const char *modules_location) { char pcitable_filename[100]; @@ -228,14 +247,21 @@ static void thirdparty_load_pcitable(const char *modules_location) log_message("third_party: no external pcitable found"); return; } - while (1) { + pcitable_len = 0; + while (pcitable_len < N_PCITABLE_ENTRIES) { char buf[200]; struct pcitable_entry *e; if (!fgets(buf, sizeof(buf), f)) break; e = &pcitable[pcitable_len++]; - sscanf(buf, "%hx\t%hx\t\"%[^ \"]\"\t\"%[^ \"]\"", &e->vendor, &e->device, e->module, e->description); + if (sscanf(buf, "%hx\t%hx\t\"%[^ \"]\"\t\"%[^\"]\"", &e->vendor, &e->device, e->module, e->description) == 4) + e->subvendor = e->subdevice = PCITABLE_MATCH_ALL; + else + sscanf(buf, "%hx\t%hx\t%x\t%x\t\"%[^ \"]\"\t\"%[^\"]\"", &e->vendor, &e->device, &e->subvendor, &e->subdevice, e->module, e->description); } fclose(f); + + /* sort pcitable by most specialised entries first */ + qsort(pcitable, pcitable_len, sizeof(pcitable[0]), pcitable_orderer); } @@ -248,8 +274,13 @@ static int thirdparty_is_detected(char *driver) { if (pcitable[j].vendor == detected_devices[i].vendor && pcitable[j].device == detected_devices[i].device && !strcmp(pcitable[j].module, driver)) { - log_message("probing: found device for module %s", driver); - return 1; + const int subvendor = pcitable[j].subvendor; + const int subdevice = pcitable[j].subdevice; + if ((subvendor == PCITABLE_MATCH_ALL && subdevice == PCITABLE_MATCH_ALL) || + (subvendor == detected_devices[i].subvendor && subdevice == detected_devices[i].subdevice)) { + log_message("probing: found device for module %s", driver); + return 1; + } } } /* if not found, compare with the detected driver */ @@ -314,7 +345,7 @@ static enum return_type thirdparty_autoload_modules(const char *modules_location static enum return_type thirdparty_try_directory(char * root_directory, int interactive) { char modules_location[100]; char modules_location_release[100]; - char list_filename[50]; + char *list_filename; FILE *f_load, *f_detect; char **modules_list, **modules_list_release; struct utsname kernel_uname; @@ -354,6 +385,8 @@ static enum return_type thirdparty_try_directory(char * root_directory, int inte return RETURN_ERROR; } + list_filename = alloca(strlen(modules_location) + 10 /* max: "/to_detect" */ + 1); + sprintf(list_filename, "%s/to_load", modules_location); f_load = fopen(list_filename, "rb"); if (f_load) { @@ -418,3 +451,8 @@ void thirdparty_load_modules(void) if (results != RETURN_OK) return thirdparty_load_modules(); } + +void thirdparty_destroy(void) +{ + probing_destroy(); +} diff --git a/mdk-stage1/thirdparty.h b/mdk-stage1/thirdparty.h index 23066374c..c999d6a58 100644 --- a/mdk-stage1/thirdparty.h +++ b/mdk-stage1/thirdparty.h @@ -29,4 +29,7 @@ void thirdparty_load_media_modules(void); */ void thirdparty_load_modules(void); +/* destroy all data structures related to the thirdparty module */ +void thirdparty_destroy(void); + #endif diff --git a/mdk-stage1/tools.c b/mdk-stage1/tools.c index 17a4774fd..baba72b0d 100644 --- a/mdk-stage1/tools.c +++ b/mdk-stage1/tools.c @@ -233,12 +233,8 @@ int total_memory(void) int image_has_stage2() { -#ifdef MANDRAKE_MOVE - return access(IMAGE_LOCATION "/live_tree.clp", R_OK) == 0; -#else - return access(CLP_FILE_REL(IMAGE_LOCATION "/"), R_OK) == 0 || + return access(COMPRESSED_FILE_REL(IMAGE_LOCATION "/"), R_OK) == 0 || access(IMAGE_LOCATION "/" LIVE_LOCATION_REL, R_OK) == 0; -#endif } int ramdisk_possible(void) @@ -251,12 +247,12 @@ int ramdisk_possible(void) } } -int clp_preload(void) +int compressed_image_preload(void) { if (total_memory() > (IS_RESCUE ? MEM_LIMIT_RESCUE_PRELOAD : MEM_LIMIT_DRAKX_PRELOAD)) return 1; else { - log_message("warning, not preloading clp due to low mem"); + log_message("warning, not preloading compressed due to low mem"); return 0; } } @@ -316,73 +312,124 @@ enum return_type copy_file(char * from, char * to, void (*callback_func)(int ove } } -enum return_type mount_clp(char *clp, char *location_mount) +enum return_type recursiveRemove(char *file) +{ + struct stat sb; + + if (lstat(file, &sb) != 0) { + log_message("failed to stat %s: %d", file, errno); + return RETURN_ERROR; + } + + /* only descend into subdirectories if device is same as dir */ + if (S_ISDIR(sb.st_mode)) { + char * strBuf = alloca(strlen(file) + 1024); + DIR * dir; + struct dirent * d; + + if (!(dir = opendir(file))) { + log_message("error opening %s: %d", file, errno); + return RETURN_ERROR; + } + while ((d = readdir(dir))) { + if (!strcmp(d->d_name, ".") || !strcmp(d->d_name, "..")) + continue; + + strcpy(strBuf, file); + strcat(strBuf, "/"); + strcat(strBuf, d->d_name); + + if (recursiveRemove(strBuf) != 0) { + closedir(dir); + return RETURN_ERROR; + } + } + closedir(dir); + + if (rmdir(file)) { + log_message("failed to rmdir %s: %d", file, errno); + return RETURN_ERROR; + } + } else { + if (unlink(file) != 0) { + log_message("failed to remove %s: %d", file, errno); + return RETURN_ERROR; + } + } + return RETURN_OK; +} + +enum return_type recursiveRemove_if_it_exists(char *file) +{ + struct stat sb; + + if (lstat(file, &sb) != 0) { + /* if file doesn't exist, simply return OK */ + return RETURN_OK; + } + + return recursiveRemove(file); +} + +enum return_type mount_compressed_image(char *compressed_image, char *location_mount) { - if (lomount(clp, location_mount, NULL, 1)) { + if (lomount(compressed_image, location_mount, NULL, 1)) { stg1_error_message("Could not mount compressed loopback :(."); return RETURN_ERROR; } return RETURN_OK; } -enum return_type preload_mount_clp(int clp_fd, int clp_size, char *clp_name, char *location_mount) +enum return_type preload_mount_compressed_fd(int compressed_fd, int image_size, char *image_name, char *location_mount) { int ret; - char *clp_tmpfs = asprintf_("%s/tmp/%s", SLASH_LOCATION, clp_name); -#ifdef MANDRAKE_MOVE - static int count = 0; - char buf[5000]; - sprintf(buf, "Loading program into memory (part %d)...", ++count); -#else + char *compressed_tmpfs = asprintf_("/tmp/%s", image_name); char *buf = "Loading program into memory..."; -#endif - init_progression(buf, clp_size); - ret = save_fd(clp_fd, clp_tmpfs, update_progression); + init_progression(buf, image_size); + ret = save_fd(compressed_fd, compressed_tmpfs, update_progression); end_progression(); if (ret != RETURN_OK) return ret; - return mount_clp(clp_tmpfs, location_mount); + return mount_compressed_image(compressed_tmpfs, location_mount); } -enum return_type mount_clp_may_preload(char *clp_name, char *location_mount, int preload) +enum return_type mount_compressed_image_may_preload(char *image_name, char *location_mount, int preload) { - char *clp = asprintf_("%s/%s", CLP_LOCATION, clp_name); + char *compressed_image = asprintf_("%s/%s", COMPRESSED_LOCATION, image_name); - log_message("mount_clp_may_preload: %s into %s (preload = %d)", clp, location_mount, preload); + log_message("mount_compressed_may_preload: %s into %s (preload = %d)", compressed_image, location_mount, preload); - if (access(clp, R_OK) != 0) return RETURN_ERROR; + if (access(compressed_image, R_OK) != 0) return RETURN_ERROR; if (preload) { - int clp_fd = open(clp, O_RDONLY); - if (clp_fd != -1) { - return preload_mount_clp(clp_fd, file_size(clp), clp_name, location_mount); + int compressed_fd = open(compressed_image, O_RDONLY); + if (compressed_fd != -1) { + return preload_mount_compressed_fd(compressed_fd, file_size(compressed_image), image_name, location_mount); } else { - log_perror(clp); + log_perror(compressed_image); return RETURN_ERROR; } } else { - return mount_clp(clp, location_mount); + return mount_compressed_image(compressed_image, location_mount); } } -#ifndef MANDRAKE_MOVE -enum return_type may_load_clp(void) +enum return_type may_load_compressed_image(void) { if (!IS_RESCUE && access(IMAGE_LOCATION "/" LIVE_LOCATION_REL, R_OK) == 0) { /* LIVE install */ return RETURN_OK; } else { - /* CLP install */ - return mount_clp_may_preload(CLP_NAME(""), STAGE2_LOCATION, clp_preload()); + /* compressed install */ + return mount_compressed_image_may_preload(COMPRESSED_NAME(""), STAGE2_LOCATION, compressed_image_preload()); } } -enum return_type load_clp_fd(int fd, int size) +enum return_type load_compressed_fd(int fd, int size) { - return preload_mount_clp(fd, size, CLP_NAME(""), STAGE2_LOCATION); + return preload_mount_compressed_fd(fd, size, COMPRESSED_NAME(""), STAGE2_LOCATION); } -#endif /* pixel's */ void * memdup(void *src, size_t size) @@ -396,7 +443,7 @@ void * memdup(void *src, size_t size) void add_to_env(char * name, char * value) { - FILE* fakeenv = fopen(SLASH_LOCATION "/tmp/env", "a"); + FILE* fakeenv = fopen("/tmp/env", "a"); if (fakeenv) { char* e = asprintf_("%s=%s\n", name, value); fwrite(e, 1, strlen(e), fakeenv); @@ -543,9 +590,10 @@ char * asprintf_(const char *msg, ...) { int n; char * s; + char dummy; va_list arg_ptr; va_start(arg_ptr, msg); - n = vsnprintf(0, 1000000, msg, arg_ptr); + n = vsnprintf(&dummy, sizeof(dummy), msg, arg_ptr); va_start(arg_ptr, msg); if ((s = malloc(n + 1))) { vsnprintf(s, n + 1, msg, arg_ptr); diff --git a/mdk-stage1/tools.h b/mdk-stage1/tools.h index b7681a16b..fd5236a93 100644 --- a/mdk-stage1/tools.h +++ b/mdk-stage1/tools.h @@ -1,3 +1,4 @@ + /* * Guillaume Cottenceau (gc@mandrakesoft.com) * @@ -36,13 +37,13 @@ int total_memory(void); int image_has_stage2(); int ramdisk_possible(void); enum return_type copy_file(char * from, char * to, void (*callback_func)(int overall)); -enum return_type preload_mount_clp(int clp_fd, int clp_size, char *clp_name, char *location_mount); -enum return_type mount_clp(char *clp, char *location_mount); -enum return_type mount_clp_may_preload(char *clp_name, char *location_mount, int preload); -#ifndef MANDRAKE_MOVE -enum return_type load_clp_fd(int fd, int size); -enum return_type may_load_clp(void); -#endif +enum return_type recursiveRemove(char *file); +enum return_type recursiveRemove_if_it_exists(char *file); +enum return_type preload_mount_compressed_fd(int compressed_fd, int image_size, char *image_name, char *location_mount); +enum return_type mount_compressed_image(char *compressed_image, char *location_mount); +enum return_type mount_compressed_image_may_preload(char *image_name, char *location_mount, int preload); +enum return_type load_compressed_fd(int fd, int size); +enum return_type may_load_compressed_image(void); void * memdup(void *src, size_t size); void add_to_env(char * name, char * value); char ** list_directory(char * direct); diff --git a/mdk-stage1/url.c b/mdk-stage1/url.c index 808bfd057..640825cf5 100644 --- a/mdk-stage1/url.c +++ b/mdk-stage1/url.c @@ -441,8 +441,8 @@ static int _http_download_file(char * hostname, char * remotename, int * size, c return FTPERR_FAILED_CONNECT; } - buf = proxyprotocol ? asprintf_("GET %s://%s%s HTTP/0.9\r\nHost: %s\r\n\r\n", proxyprotocol, hostname, remotename, hostname) - : asprintf_("GET %s HTTP/0.9\r\nHost: %s\r\n\r\n", remotename, hostname); + buf = proxyprotocol ? asprintf_("GET %s://%s%s HTTP/1.0\r\nHost: %s\r\n\r\n", proxyprotocol, hostname, remotename, hostname) + : asprintf_("GET %s HTTP/1.0\r\nHost: %s\r\n\r\n", remotename, hostname); write(sock, buf, strlen(buf)); diff --git a/mdk-stage1/usb-resource/.cvsignore b/mdk-stage1/usb-resource/.cvsignore deleted file mode 100644 index a7d0cfa9a..000000000 --- a/mdk-stage1/usb-resource/.cvsignore +++ /dev/null @@ -1 +0,0 @@ -usb-ids.h diff --git a/mdk-stage1/usb-resource/update-usb-ids.pl b/mdk-stage1/usb-resource/update-usb-ids.pl index 749d09d7e..b938cdb1a 100755 --- a/mdk-stage1/usb-resource/update-usb-ids.pl +++ b/mdk-stage1/usb-resource/update-usb-ids.pl @@ -38,7 +38,8 @@ int usb_num_ids=sizeof(usb_pci_ids)/sizeof(struct pci_module_map); print "struct usb_module_map usb_usb_ids[] = { "; -my @modules = chomp_(`perl ../../kernel/modules.pl pci_modules4stage1 "network/usb disk/usb"`); +my @modules = chomp_(`perl ../../kernel/modules.pl pci_modules4stage1 "network/usb disk/usb"`) +or die "unable to get USB modules"; foreach my $k (sort keys %$usb) { my $v = $usb->{$k}; diff --git a/mdk-stage1/wireless.c b/mdk-stage1/wireless.c index c241bd662..cefe6c1f7 100644 --- a/mdk-stage1/wireless.c +++ b/mdk-stage1/wireless.c @@ -26,21 +26,18 @@ #include "log.h" #include "wireless.h" -static int wireless_open_socket(); -static int wireless_close_socket(int socket); static int wireless_ioctl(int socket, const char *ifname, int request, struct iwreq *wrq); -static int wireless_is_aware(int socket, const char *ifname); static int wireless_set_mode_managed(int socket, const char *ifname); static int wireless_disable_key(int socket, const char *ifname); static int wireless_set_restricted_key(int socket, const char *ifname, const char *key); static int wireless_set_essid(int socket, const char *ifname, const char *essid); -static int wireless_open_socket() +int wireless_open_socket() { return socket(AF_INET, SOCK_DGRAM, 0); } -static int wireless_close_socket(int socket) +int wireless_close_socket(int socket) { return close(socket); } @@ -51,7 +48,7 @@ static int wireless_ioctl(int socket, const char *ifname, int request, struct iw return ioctl(socket, request, wrq); } -static int wireless_is_aware(int socket, const char *ifname) +int wireless_is_aware(int socket, const char *ifname) { struct iwreq wrq; return wireless_ioctl(socket, ifname, SIOCGIWNAME, &wrq) == 0; diff --git a/mdk-stage1/wireless.h b/mdk-stage1/wireless.h index 36f247b23..3e5bb7790 100644 --- a/mdk-stage1/wireless.h +++ b/mdk-stage1/wireless.h @@ -17,6 +17,9 @@ #include "frontend.h" +int wireless_open_socket(); +int wireless_close_socket(int socket); +int wireless_is_aware(int socket, const char *ifname); enum return_type configure_wireless(const char *ifname); #endif diff --git a/mdk-stage1/zlibsupport.c b/mdk-stage1/zlibsupport.c new file mode 100644 index 000000000..ecbe7a5ef --- /dev/null +++ b/mdk-stage1/zlibsupport.c @@ -0,0 +1,119 @@ +/* Support for compressed modules. Willy Tarreau <willy@meta-x.org> + * did the support for modutils, Andrey Borzenkov <arvidjaar@mail.ru> + * ported it to module-init-tools, and I said it was too ugly to live + * and rewrote it 8). + * + * (C) 2003 Rusty Russell, IBM Corporation. + */ +#include <sys/types.h> +#include <sys/stat.h> +#include <fcntl.h> +#include <stdlib.h> +#include <unistd.h> +#include <sys/mman.h> + +#include "zlibsupport.h" + +#ifdef CONFIG_USE_ZLIB +#include <zlib.h> + +void *grab_contents(gzFile *gzfd, unsigned long *size) +{ + unsigned int max = 16384; + void *buffer = malloc(max); + int ret; + + if (!buffer) + return NULL; + + *size = 0; + while ((ret = gzread(gzfd, buffer + *size, max - *size)) > 0) { + *size += ret; + if (*size == max) { + void *p; + + p = realloc(buffer, max *= 2); + if (!p) + goto out_err; + + buffer = p; + } + } + if (ret < 0) + goto out_err; + + return buffer; + +out_err: + free(buffer); + return NULL; +} + +void *grab_fd(int fd, unsigned long *size) +{ + gzFile gzfd; + + gzfd = gzdopen(fd, "rb"); + if (!gzfd) + return NULL; + + /* gzclose(gzfd) would close fd, which would drop locks. + Don't blame zlib: POSIX locking semantics are so horribly + broken that they should be ripped out. */ + return grab_contents(gzfd, size); +} + +/* gzopen handles uncompressed files transparently. */ +void *grab_file(const char *filename, unsigned long *size) +{ + gzFile gzfd; + void *buffer; + + gzfd = gzopen(filename, "rb"); + if (!gzfd) + return NULL; + buffer = grab_contents(gzfd, size); + gzclose(gzfd); + return buffer; +} + +void release_file(void *data, unsigned long size) +{ + free(data); +} +#else /* ... !CONFIG_USE_ZLIB */ + +void *grab_fd(int fd, unsigned long *size) +{ + struct stat st; + void *map; + int ret; + + ret = fstat(fd, &st); + if (ret < 0) + return NULL; + *size = st.st_size; + map = mmap(0, *size, PROT_READ|PROT_WRITE, MAP_PRIVATE, fd, 0); + if (map == MAP_FAILED) + map = NULL; + return map; +} + +void *grab_file(const char *filename, unsigned long *size) +{ + int fd; + void *map; + + fd = open(filename, O_RDONLY, 0); + if (fd < 0) + return NULL; + map = grab_fd(fd, size); + close(fd); + return map; +} + +void release_file(void *data, unsigned long size) +{ + munmap(data, size); +} +#endif diff --git a/mdk-stage1/zlibsupport.h b/mdk-stage1/zlibsupport.h new file mode 100644 index 000000000..be3c7296a --- /dev/null +++ b/mdk-stage1/zlibsupport.h @@ -0,0 +1,11 @@ +#ifndef _ZLIB_SUPPORT_H +#define _ZLIB_SUPPORT_H + +/* Grab file. Decompresses if that is supported. Returns NULL on error. */ +extern void *grab_file(const char *filename, unsigned long *size); +extern void *grab_fd(int fd, unsigned long *size); + +/* Free it up. */ +extern void release_file(void *data, unsigned long size); + +#endif /* _ZLIB_SUPPORT_H */ |