pax_global_header00006660000000000000000000000064105764773710014533gustar00rootroot0000000000000052 comment=61bfc061edc961125bf5f717aaa6a5188d7ef198 .gear-rules000064400000000000000000000000431057647737100131410ustar00rootroot00000000000000tar: . name=@name@-@version@ base= .rpmwrap000064400000000000000000000001371057647737100125670ustar00rootroot00000000000000%_topdir %_macropath/.../ %_sourcedir %_topdir/sources %_specdir %_topdir/../ Makefile000064400000000000000000000016411057647737100125370ustar00rootroot00000000000000CC = gcc CFLAGS := -pipe -Wall -O2 INSTALL = /bin/install DESTDIR = bindir = /usr/bin libdir = /usr/lib includedir = /usr/include all: libs mar mkmar libs: libmar.a install: all $(INSTALL) -d $(DESTDIR)$(bindir) $(DESTDIR)$(libdir) $(DESTDIR)$(includedir) $(INSTALL) -m0755 mar $(DESTDIR)$(bindir)/mar $(INSTALL) -m0755 mkmar $(DESTDIR)$(bindir)/mkmar $(INSTALL) -m0644 libmar.a $(DESTDIR)$(libdir)/libmar.a $(INSTALL) -m0644 mar-extract-only.h $(DESTDIR)$(includedir)/mar-extract-only.h clean: rm -f *~ *.o libmar.a mar mar: mar-frontend.o mar-extract-only-standalone.o $(CC) $(CFLAGS) -o $@ $^ -lbz2 libmar.a: mar-extract-only.o ar -cru $@ $^ ranlib $@ mar-frontend.o: mar-frontend.c mar.h mar-extract-only.h mar-extract-only.o: mar-extract-only.c mar-extract-only.h mar.h mar-extract-only-standalone.o: mar-extract-only.c mar-extract-only.h mar.h $(CC) $(CFLAGS) -D_STANDALONE_ -c -o $@ mar-extract-only.c log.h000064400000000000000000000013421057647737100120270ustar00rootroot00000000000000/* * 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. * */ /* * Portions from Erik Troan (ewt@redhat.com) * * Copyright 1996 Red Hat Software * */ #ifndef _LOG_H_ #define _LOG_H_ #include void log_message(const char * s, ...) __attribute__ ((format (printf, 1, 2))); void vlog_message(const char * s, va_list args); void log_perror(char *msg); void open_log(void); void close_log(void); #endif mar-extract-only.c000064400000000000000000000131401057647737100144460ustar00rootroot00000000000000/* * 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 */ } #ifndef _STANDALONE_ int mar_extract_inplace(char *mar_filename, char *filename_to_extract, void **buf, int *len) { 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]; size_t i; *len = elem->file_length; 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"); return -1; } i -= to_read; } *buf = malloc(elem->file_length); if ((*buf) == NULL) { log_message("MAR: malloc failed"); return -1; } if (BZ2_bzread(s.mar_zfile, *buf, *len) != *len) { free(*buf); zerr(s.mar_zfile); return -1; } 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 */ } #endif /* _STANDALONE_ */ mar-extract-only.h000064400000000000000000000014631057647737100144600ustar00rootroot00000000000000/* * 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); int mar_extract_inplace(char *mar_filename, char *filename_to_extract, void **buf, int *len); char ** mar_list_contents(char *mar_filename); #endif mar-frontend.c000064400000000000000000000105231057647737100136360ustar00rootroot00000000000000/* * 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(basename(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]), basename(files[filenum])); current_offset_filetable += strlen(basename(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; } mar.h000064400000000000000000000033161057647737100120300ustar00rootroot00000000000000/* * 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 #define _GNU_SOURCE #include #include #include #include #include #include #include #include #include /* * 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 mar.spec000064400000000000000000000024701057647737100125330ustar00rootroot00000000000000Name: mar Version: 20070301 Release: alt1 Summary: mar - Mandrake Archiver License: GPL Group: Development/C Source: %name-%version.tar BuildRequires: bzlib-devel Provides: /usr/bin/mkmar %description An archiver that supports compression (through bzlib). %prep %setup -c %build make %install %makeinstall %files %_bindir/mar %_bindir/mkmar %_libdir/libmar.a %_includedir/mar-extract-only.h %changelog * Fri Mar 2 2007 Sergey Bolshakov 20070301-alt1 - rebuilt against glibc * Sun Dec 3 2006 L.A. Kostis 20050707-alt2 - mkmar: + Remove use of hasher internals (drop in-chroot and workdir switches). + Rework pcimap functions (derive some idea from mkinitrd). + Remove unwanted root checks. * Thu Jul 07 2005 Anton D. Kachalov 20050707-alt1 - multilib support - mkmar now may partially run in chroot env * Tue Dec 14 2004 Sergey Bolshakov 20041025-alt0.4 - mkmar modified to generate pci-ids via libhw also * Wed Nov 10 2004 Sergey Bolshakov 20041025-alt0.3 - mkmar script added * Tue Nov 2 2004 Sergey Bolshakov 20041025-alt0.2 - added 'extract to memory' feature * Wed Oct 27 2004 Sergey Bolshakov 20041025-alt0.1 - packaged for %distribution mkmar000075500000000000000000000043231057647737100121340ustar00rootroot00000000000000#!/bin/sh -e Info() { printf >&2 %s\\n "${0##*/}: $*" } Fatal() { Info "$@" exit 1 } #parse command line options TEMP=`getopt -n "$0" -o k:,o:,p:,r: -l kernel:,output:,pattern:,root: -- "$@"` || exit 1 eval set -- "$TEMP" kernel= output= pattern= root=. while :; do case "$1" in -k|--kernel-version) shift kernel="$1" ;; -o|--output) shift output="$1" ;; -p|--pattern*) shift pattern="$1" ;; -r|--root) shift root="$1" ;; --) shift; break ;; *) Fatal "Unrecognized option: $1" ;; esac shift done [ -n "$output" ] || Fatal 'Mandatory --output= option not specified.' [ -n "$pattern" ] || Fatal 'Mandatory --pattern= option not specified.' [ -n "$kernel" ] || kernel=`uname -r` exit_handler() { local rc=$? trap - EXIT [ $rc -eq 0 ] || rm -f -- "$output.mar" "$output.dep" "$output.map" exit $rc } trap exit_handler HUP PIPE INT TERM QUIT EXIT modpath="$(readlink -ev "$root/lib/modules/$kernel")" deps="$modpath/modules.dep" pcimap="$modpath/modules.pcimap" modules_list() { local dep mod path > "$output.dep" find "$modpath/" -type f | grep -w -f "$pattern" | while read path; do printf %s\\n "$path" if grep -qw "${path##*$root}: " "$deps"; then mod="${path##*/}" mod="${mod%.*}" echo -n "$mod:" >> "$output.dep" for dep in `grep -w "${path##*$root}: " $deps | sed 's|^[^:]\+:||'`; do dep="$(readlink -ev "$root/$dep")" printf %s\\n "$dep" dep="${dep##*/}" dep="${dep%.*}" printf ' %s' "$dep" >> "$output.dep" done echo >> "$output.dep" fi done | sort -u } # Scan $pcimap for ids corresponding to given module. # Inspired by ListPciModules() code from mkinitrd. grep_pcimap() { local sample="$1" && shift local PCI_ANY="0xffffffff" while read module vendor device ignored; do [ "$sample" = "$module" ] || continue # skip wildcards [ "$device" != "$PCI_ANY" -a "$vendor" != "$PCI_ANY" ] || continue printf '0x%04x 0x%04x %s\n' "$vendor" "$device" "$module" done < "$pcimap" } make_modules_map() { local mod list list="$(mar -l "$output.mar" |sed 's/^[[:space:]]\+\([^\.]\+\)\.ko$/\1/')" for mod in ${list}; do grep_pcimap "$mod" done > "$output.map" } mar -c "$output.mar" $(modules_list) make_modules_map