summaryrefslogtreecommitdiffstats
path: root/mdk-stage1/mar
diff options
context:
space:
mode:
Diffstat (limited to 'mdk-stage1/mar')
-rw-r--r--mdk-stage1/mar/.cvsignore1
-rw-r--r--mdk-stage1/mar/Makefile61
-rw-r--r--mdk-stage1/mar/mar-extract-only.c207
-rw-r--r--mdk-stage1/mar/mar-extract-only.h32
-rw-r--r--mdk-stage1/mar/mar-frontend.c199
-rw-r--r--mdk-stage1/mar/mar.h70
6 files changed, 0 insertions, 570 deletions
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 801785947..000000000
--- a/mdk-stage1/mar/Makefile
+++ /dev/null
@@ -1,61 +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
-
-
-ifeq (DIETLIBC, $(L))
-TARGETS += libmar-DIET.a
-endif
-
-
-all: $(TARGETS)
-
-clean:
- rm -f *.o libmar.a libmar-DIET.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 $@
-
-libmar-DIET.a: mar-extract-only-DIET.o
- ar -cru $@ $^
- ranlib $@
-
-mar-extract-only.o: mar-extract-only.c mar-extract-only.h mar.h
- gcc $(CFLAGS) $(GLIBC_INCLUDES) -c mar-extract-only.c
-
-mar-extract-only-DIET.o: mar-extract-only.c mar-extract-only.h mar.h
- gcc $(CFLAGS) $(DIETLIBC_INCLUDES) -o $@ -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 723cc376d..000000000
--- a/mdk-stage1/mar/mar-extract-only.c
+++ /dev/null
@@ -1,207 +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, 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");
- return -1;
- }
- i -= to_read;
- }
- if (BZ2_bzread(s.mar_zfile, buf, elem->file_length) != elem->file_length)
- {
- zerr(s.mar_zfile);
- return -1;
- }
- if (write(fd, buf, elem->file_length) != elem->file_length)
- {
- log_perror(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 6fa34efe4..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 2e87626db..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], &current_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) != 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 672d7ded8..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