summaryrefslogtreecommitdiffstats
path: root/mdk-stage1/mar
diff options
context:
space:
mode:
authorGuillaume Cottenceau <gc@mandriva.com>2000-12-07 23:16:19 +0000
committerGuillaume Cottenceau <gc@mandriva.com>2000-12-07 23:16:19 +0000
commit0c0b00ab8086c07600680d41e2f8feefe0f8f150 (patch)
tree0da2100a6944b5efed0aa02d950d98a071bec0cc /mdk-stage1/mar
parent71d6a65fa155d25fc325d6a9b83a746f5845922e (diff)
downloaddrakx-0c0b00ab8086c07600680d41e2f8feefe0f8f150.tar
drakx-0c0b00ab8086c07600680d41e2f8feefe0f8f150.tar.gz
drakx-0c0b00ab8086c07600680d41e2f8feefe0f8f150.tar.bz2
drakx-0c0b00ab8086c07600680d41e2f8feefe0f8f150.tar.xz
drakx-0c0b00ab8086c07600680d41e2f8feefe0f8f150.zip
first draft can detect your cdrom drives
soon will launch the stage2
Diffstat (limited to 'mdk-stage1/mar')
-rw-r--r--mdk-stage1/mar/Makefile13
-rw-r--r--mdk-stage1/mar/mar-extract-only.c43
-rw-r--r--mdk-stage1/mar/mar-extract-only.h6
-rw-r--r--mdk-stage1/mar/mar-frontend.c18
-rw-r--r--mdk-stage1/mar/mar.h3
5 files changed, 49 insertions, 34 deletions
diff --git a/mdk-stage1/mar/Makefile b/mdk-stage1/mar/Makefile
index c35f50f02..e7f6977ce 100644
--- a/mdk-stage1/mar/Makefile
+++ b/mdk-stage1/mar/Makefile
@@ -18,7 +18,7 @@
#*****************************************************************************
-all: mar
+all: libmar.a mar
clean:
rm -f *.o mar
@@ -26,11 +26,18 @@ clean:
FLAGS = -Wall -Werror -Os -fomit-frame-pointer -c
-mar: mar-frontend.o mar-extract-only.o
- gcc -o mar mar-frontend.o mar-extract-only.o -lz
+mar: mar-frontend.o mar-extract-only-standalone.o
+ gcc -o mar mar-frontend.o mar-extract-only-standalone.o -lz
+
+libmar.a: mar-extract-only.o
+ ar -cru $@ $^
+ ranlib $@
mar-frontend.o: mar-frontend.c mar.h mar-extract-only.h
gcc $(FLAGS) mar-frontend.c
mar-extract-only.o: mar-extract-only.c mar-extract-only.h mar.h
gcc $(FLAGS) mar-extract-only.c
+
+mar-extract-only-standalone.o: mar-extract-only.c mar-extract-only.h mar.h
+ gcc $(FLAGS) -o $@ -D_STANDALONE_ mar-extract-only.c
diff --git a/mdk-stage1/mar/mar-extract-only.c b/mdk-stage1/mar/mar-extract-only.c
index 3627e84bb..b1079880e 100644
--- a/mdk-stage1/mar/mar-extract-only.c
+++ b/mdk-stage1/mar/mar-extract-only.c
@@ -26,15 +26,34 @@
#include "mar.h"
-
+#ifdef _STANDALONE_
void
gzerr(gzFile f) /* decrease code size */
{
fprintf(stderr, gzerror(f, &gz_errnum));
}
+void
+log_perror(char *msg)
+{
+ perror(msg);
+}
+void
+log_message(char *msg)
+{
+ fprintf(stderr, msg);
+}
+#else /* _STANDALONE_ */
+#include "../log.h"
+void
+gzerr(gzFile f) /* decrease code size */
+{
+ log_message(gzerror(f, &gz_errnum));
+}
+#endif /* _STANDALONE_ */
+
int
-calc_integrity(struct mar_stream *s)
+mar_calc_integrity(struct mar_stream *s)
{
char buf[4096];
int current_crc = 0;
@@ -51,20 +70,18 @@ calc_integrity(struct mar_stream *s)
gzerr(s->mar_gzfile);
return -1;
}
- DEBUG_MAR(printf("D: mar::calc_integrity more-bytes-to-handle-for-crc %d\n", bytes););
while (bytes > 0)
{
bytes--;
current_crc += buf[bytes];
}
}
- DEBUG_MAR(printf("D: mar::calc_integrity computed-crc %d\n", current_crc););
return current_crc;
}
int
-extract_file(struct mar_stream *s, char *filename, char *dest_dir)
+mar_extract_file(struct mar_stream *s, char *filename, char *dest_dir)
{
struct mar_element * elem = s->first_element;
while (elem)
@@ -80,13 +97,13 @@ extract_file(struct mar_stream *s, char *filename, char *dest_dir)
fd = creat(dest_file, 00660);
if (fd == -1)
{
- perror(dest_file);
+ log_perror(dest_file);
return -1;
}
buf = (char *) alloca(elem->file_length);
if (!buf)
{
- perror(dest_file);
+ log_perror(dest_file);
return -1;
}
if (gzseek(s->mar_gzfile, elem->data_offset, SEEK_SET) != elem->data_offset)
@@ -101,7 +118,7 @@ extract_file(struct mar_stream *s, char *filename, char *dest_dir)
}
if (write(fd, buf, elem->file_length) != elem->file_length)
{
- perror(dest_file);
+ log_perror(dest_file);
return -1;
}
close(fd); /* do not check return value for code size */
@@ -114,7 +131,7 @@ extract_file(struct mar_stream *s, char *filename, char *dest_dir)
int
-open_marfile(char *filename, struct mar_stream *s)
+mar_open_file(char *filename, struct mar_stream *s)
{
int end_filetable = 0;
struct mar_element * previous_element = NULL;
@@ -123,7 +140,7 @@ open_marfile(char *filename, struct mar_stream *s)
s->mar_gzfile = gzopen(filename, "rb");
if (!s->mar_gzfile)
{
- perror(filename);
+ log_perror(filename);
return -1;
}
@@ -134,11 +151,10 @@ open_marfile(char *filename, struct mar_stream *s)
return -1;
}
- DEBUG_MAR(printf("D: mar::open_marfile crc-in-marfile %d\n", s->crc32););
/* verify integrity */
- if (s->crc32 != calc_integrity(s))
+ if (s->crc32 != mar_calc_integrity(s))
{
- fprintf(stderr, "E: mar::open_marfile CRC check failed\n");
+ log_message("E: mar::open_marfile CRC check failed");
return -1;
}
else
@@ -167,7 +183,6 @@ open_marfile(char *filename, struct mar_stream *s)
{
struct mar_element * e = (struct mar_element *) malloc(sizeof(struct mar_element));
e->filename = strdup(buf);
- DEBUG_MAR(printf("D: mar::open_marfile processing-file %s\n", e->filename););
/* read file_length */
if (gzread(s->mar_gzfile, &(e->file_length), sizeof(int)) != sizeof(int))
{
diff --git a/mdk-stage1/mar/mar-extract-only.h b/mdk-stage1/mar/mar-extract-only.h
index f5db6c183..e8a88e96e 100644
--- a/mdk-stage1/mar/mar-extract-only.h
+++ b/mdk-stage1/mar/mar-extract-only.h
@@ -28,8 +28,8 @@
#include "mar.h"
-int open_marfile(char *filename, struct mar_stream *s);
-int extract_file(struct mar_stream *s, char *filename, char *dest_dir);
-int calc_integrity(struct mar_stream *s);
+int mar_open_file(char *filename, struct mar_stream *s);
+int mar_extract_file(struct mar_stream *s, char *filename, char *dest_dir);
+int mar_calc_integrity(struct mar_stream *s);
#endif
diff --git a/mdk-stage1/mar/mar-frontend.c b/mdk-stage1/mar/mar-frontend.c
index 55550d8a1..79a83a1c3 100644
--- a/mdk-stage1/mar/mar-frontend.c
+++ b/mdk-stage1/mar/mar-frontend.c
@@ -28,7 +28,7 @@
#include "mar-extract-only.h"
void
-list_files(struct mar_stream *s)
+mar_list_files(struct mar_stream *s)
{
struct mar_element * elem = s->first_element;
printf("%-20s%8s\n", "FILENAME", "LENGTH");
@@ -58,7 +58,7 @@ file_size(char *filename)
/* ``files'' is a NULL-terminated array of char* */
int
-create_marfile(char *dest_file, char **files)
+mar_create_file(char *dest_file, char **files)
{
int filenum = 0;
int current_offset_filetable;
@@ -179,27 +179,23 @@ main(int argc, char **argv)
if (strcmp(argv[1], "-l") == 0)
{
struct mar_stream s;
- if (open_marfile(argv[2], &s) != 0)
+ if (mar_open_file(argv[2], &s) != 0)
{
fprintf(stderr, "E: open-marfile-failed\n");
exit(-1);
}
- list_files(&s);
- if (s.crc32 == calc_integrity(&s))
- printf("CRC OK\n");
- else
- printf("CRC FAILED!\n");
+ mar_list_files(&s);
exit(0);
}
if ((strcmp(argv[1], "-x") == 0) && argc >= 4)
{
struct mar_stream s;
int i = 3;
- if (open_marfile(argv[2], &s) != 0)
+ if (mar_open_file(argv[2], &s) != 0)
exit(-1);
while (i < argc)
{
- int res = extract_file(&s, argv[i], "./");
+ int res = mar_extract_file(&s, argv[i], "./");
if (res == 1)
fprintf(stderr, "W: file-not-found-in-archive %s\n", argv[i]);
if (res == -1)
@@ -220,7 +216,7 @@ main(int argc, char **argv)
files[argc-3] = NULL;
{
int results;
- results = create_marfile(argv[2], files);
+ results = mar_create_file(argv[2], files);
if (results != 0)
fprintf(stderr, "E: create-marfile-failed\n");
exit(results);
diff --git a/mdk-stage1/mar/mar.h b/mdk-stage1/mar/mar.h
index bd731770b..e9633ab92 100644
--- a/mdk-stage1/mar/mar.h
+++ b/mdk-stage1/mar/mar.h
@@ -27,7 +27,6 @@
#ifndef MAR_H
#define MAR_H
-#if 1
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
@@ -36,8 +35,6 @@
#include <fcntl.h>
#include <errno.h>
#include <unistd.h>
-#endif
-//#include <minilibc.h>
#include <zlib.h>