Commit 78da498e authored by Mike Hibler's avatar Mike Hibler
Browse files

Lint and ifdefs for linux build

parent 73e1f225
......@@ -11,8 +11,8 @@ SUBDIR = os/imagezip
DISTFILES = ext2_fs.h imagehdr.h linux_types.h queue.h \
imagedump.c imagedump.8 imagezip.c imagezip.8 \
imageunzip.c imageunzip.8
EXPANDCOPYRIGHT = /n/fast/usr/lsrc/flux/doc/copyright/expand-copyr
imageunzip.c crc.c imageunzip.8
EXPANDCOPYRIGHT = /flux/doc/copyright/expand-copyr
WITH_NTFS = @WINSUPPORT@
......@@ -84,12 +84,14 @@ clean:
imagezip.tar.gz: imagezip.tar
gzip -c imagezip.tar > imagezip.tar.gz
imagezip.tar: Makefile.sa $(DISTFILES)
imagezip.tar: Makefile.sa Makefile-linux.sa $(DISTFILES)
rm -rf imagezip-dist; mkdir imagezip-dist
(cd $(SRCDIR); tar cf - Makefile.sa $(DISTFILES)) | \
(cd $(SRCDIR); tar cf - Makefile.sa Makefile-linux.sa $(DISTFILES)) | \
(cd imagezip-dist; tar xf -)
mv imagezip-dist/Makefile.sa imagezip-dist/Makefile
(cd imagezip-dist; $(EXPANDCOPYRIGHT) Makefile $(DISTFILES))
mv imagezip-dist/Makefile-linux.sa imagezip-dist/Makefile-linux
(cd imagezip-dist; \
$(EXPANDCOPYRIGHT) Makefile Makefile-linux $(DISTFILES))
tar cf imagezip.tar imagezip-dist
rm -rf imagezip-dist
......
#
# EMULAB-COPYRIGHT
# Copyright (c) 2000-2003 University of Utah and the Flux Group.
# All rights reserved.
#
#
# Makefile for the standalone version of imagezip/unzip.
# (Standalone meaning not part of the Netbed build environment.)
#
BINDIR= /usr/local/bin
PTHREADCFLAGS = -D_THREAD_SAFE -pthread
#PTHREADLIBS = -L/usr/local/lib -llgcc_r
# get 64-bit off_t and pread/pwrite protos
LINUXOPTS = -D_FILE_OFFSET_BITS=64 -D_GNU_SOURCE
CFLAGS = -Wall -O2 -g -static $(PTHREADCFLAGS) $(LINUXOPTS)
LIBS = -lz $(PTHREADLIBS)
UNZIPCFLAGS = $(CFLAGS) -Wall
UNZIPLIBS = $(LIBS)
all: imagezip imageunzip imagedump
imagezip: imagezip.o version.o
$(CC) $(CFLAGS) imagezip.o version.o $(LIBS) -o imagezip
imageunzip: imageunzip.o crc.o version.o
$(CC) $(CFLAGS) imageunzip.o crc.o version.o $(UNZIPLIBS) -o imageunzip
imageunzip.o: imageunzip.c
$(CC) -c $(UNZIPCFLAGS) -o imageunzip.o $<
imagedump: imagedump.o version.o
$(CC) $(CFLAGS) imagedump.o version.o $(LIBS) -o imagedump
version.c: imagezip.c imageunzip.c imagedump.c
echo >$@ "char build_info[] = \"Built `date +%d-%b-%Y` by `id -nu`@`hostname | sed 's/\..*//'`:`pwd`\";"
install:
$(INSTALL) imagezip $(DESTDIR)$(BINDIR)/imagezip
$(INSTALL) imageunzip $(DESTDIR)$(BINDIR)/imageunzip
$(INSTALL) imagedump $(DESTDIR)$(BINDIR)/imagedump
clean:
rm -f *.o imagezip imageunzip imagedump version.c
......@@ -29,8 +29,8 @@ all: imagezip imageunzip imagedump
imagezip: imagezip.o version.o
$(CC) $(CFLAGS) imagezip.o version.o $(LIBS) -o imagezip
imageunzip: imageunzip.o version.o
$(CC) $(CFLAGS) imageunzip.o version.o $(UNZIPLIBS) -o imageunzip
imageunzip: imageunzip.o crc.o version.o
$(CC) $(CFLAGS) imageunzip.o crc.o version.o $(UNZIPLIBS) -o imageunzip
imageunzip.o: imageunzip.c
$(CC) -c $(UNZIPCFLAGS) -o imageunzip.o $<
......
......@@ -246,7 +246,7 @@ dumpfile(char *name, int fd)
franges, SECTOBYTES(sectfree)/franges,
SECTOBYTES(fmin), SECTOBYTES(fmax));
if (aranges) {
int minsz, maxsz, i;
int maxsz, i;
printf(" %d allocated ranges: %qu/%qu/%qu ave/min/max size\n",
aranges, SECTOBYTES(sectinuse)/aranges,
......
......@@ -4,7 +4,7 @@
* All rights reserved.
*/
#include <sys/types.h>
#include <inttypes.h>
/*
* Magic number when image is compressed
......
......@@ -8,10 +8,6 @@
* Usage: imageunzip <input file>
*
* Writes the uncompressed data to stdout.
*
* XXX: Be nice to use pwrite. That would simplify the code a alot, but
* you cannot pwrite to a device that does not support seek (stdout),
* and I want to retain that capability.
*/
#include <stdio.h>
......@@ -23,7 +19,9 @@
#include <zlib.h>
#include <sys/types.h>
#include <sys/time.h>
#ifndef linux
#include <sys/disklabel.h>
#endif
#include "imagehdr.h"
#include "queue.h"
#ifndef NOTHREADS
......@@ -51,7 +49,6 @@ long long totalrdata = 0;
*/
static long outputminsec = 0;
static long outputmaxsec = 0;
static long long outputmaxsize = 0; /* Sanity check */
/* Why is this not defined in a public header file? */
#define BOOT_MAGIC 0xAA55
......@@ -123,6 +120,12 @@ unsigned long writeridles;
#define threadinit()
#define threadwait()
#define threadquit()
/* XXX keep the code simple */
#define pthread_mutex_lock(l)
#define pthread_mutex_unlock(l)
#define pthread_testcancel()
#undef CONDVARS_WORK
#else
static void threadinit(void);
static void threadwait(void);
......@@ -135,6 +138,7 @@ static pthread_mutex_t writequeue_mutex;
#ifdef CONDVARS_WORK
static pthread_cond_t writequeue_cond;
#endif
#endif
/*
* A queue of ready to write data blocks.
......@@ -153,13 +157,15 @@ typedef struct {
char *data;
} writebuf_t;
static queue_head_t writequeue;
static unsigned long maxwritebufmem = MAXWRITEBUFMEM;
static volatile unsigned long curwritebufmem, curwritebufs;
#ifndef NOTHREADS
static queue_head_t writequeue;
static pthread_mutex_t writebuf_mutex;
#ifdef CONDVARS_WORK
static pthread_cond_t writebuf_cond;
#endif
#endif
static volatile int writebufwanted;
/* stats */
......@@ -226,8 +232,6 @@ alloc_writebuf(off_t offset, off_t size, int allocbuf, int dowait)
#endif
pthread_testcancel();
} while (writebufwanted);
//fprintf(stderr, "alloc BLOCKDONE: cur=%lu max=%lu\n", curwritebufmem, maxwritebufmem);
}
} while (buf == NULL);
buf->refs = 1;
......@@ -239,7 +243,6 @@ alloc_writebuf(off_t offset, off_t size, int allocbuf, int dowait)
maxbufsalloced = curwritebufs;
if (curwritebufmem > maxmemalloced)
maxmemalloced = curwritebufmem;
//fprintf(stderr, "alloc %p: off=%qu size=%qu, doalloc=%d, buf=%p\n", wbuf, offset, size, allocbuf, buf);
pthread_mutex_unlock(&writebuf_mutex);
queue_init(&wbuf->chain);
......@@ -258,7 +261,7 @@ split_writebuf(writebuf_t *wbuf, off_t doff, int dowait)
off_t size;
assert(wbuf->buf != NULL);
//fprintf(stderr, "split %p: doff=%qu, buf=%p, data=%p, refs=%d\n", wbuf, doff, wbuf->buf, wbuf->data, wbuf->buf->refs);
splits++;
assert(doff < wbuf->size);
size = wbuf->size - doff;
......@@ -280,7 +283,6 @@ free_writebuf(writebuf_t *wbuf)
assert(wbuf != NULL);
pthread_mutex_lock(&writebuf_mutex);
//fprintf(stderr, "free %p: buf=%p, refs=%d\n", wbuf, wbuf->buf, wbuf->buf ? wbuf->buf->refs : -1);
if (wbuf->buf && --wbuf->buf->refs == 0) {
curwritebufs--;
curwritebufmem -= wbuf->buf->size;
......@@ -296,7 +298,6 @@ free_writebuf(writebuf_t *wbuf)
free(wbuf);
pthread_mutex_unlock(&writebuf_mutex);
}
#endif
static void
dowrite_request(writebuf_t *wbuf)
......@@ -440,8 +441,13 @@ main(int argc, char **argv)
break;
case 's':
#ifndef linux
slice = atoi(optarg);
break;
#else
fprintf(stderr, "slice mode not supported in Linux\n");
exit(1);
#endif
case 'D':
dostype = atoi(optarg);
......@@ -534,6 +540,7 @@ main(int argc, char **argv)
seekable = 1;
if (slice) {
#ifndef linux
off_t minseek;
if (readmbr(slice)) {
......@@ -546,6 +553,10 @@ main(int argc, char **argv)
perror("Setting seek pointer to slice");
exit(1);
}
#else
fprintf(stderr, "Slice mode in Linux!\n");
exit(1);
#endif
}
threadinit();
......@@ -569,7 +580,7 @@ main(int argc, char **argv)
chunklist[i] = i;
chunklist[i] = -1;
srandomdev();
srandom((long)(stamp.tv_usec^stamp.tv_sec));
for (i = 0; i < 50 * numchunks; i++) {
int c1 = random() % numchunks;
int c2 = random() % numchunks;
......@@ -625,9 +636,11 @@ main(int argc, char **argv)
/* This causes the output queue to drain */
threadquit();
#ifndef linux
/* Set the MBR type if necesary */
if (slice && dostype >= 0)
fixmbr(slice, dostype);
#endif
gettimeofday(&estamp, 0);
estamp.tv_sec -= stamp.tv_sec;
......@@ -649,7 +662,7 @@ main(int argc, char **argv)
decompblocks, writeridles, rdycount);
if (docrconly)
fprintf(stderr, "%s: CRC=%u\n", argv[0], ~crc);
dump_writebufs();
dump_writebufs();
return 0;
}
#else
......@@ -697,6 +710,7 @@ ImageUnzipInit(char *filename, int _slice, int _debug, int _fill,
seekable = 1;
if (slice) {
#ifndef linux
off_t minseek;
if (readmbr(slice)) {
......@@ -709,6 +723,10 @@ ImageUnzipInit(char *filename, int _slice, int _debug, int _fill,
perror("Setting seek pointer to slice");
exit(1);
}
#else
fprintf(stderr, "Slice mode in Linux!\n");
exit(1);
#endif
}
threadinit();
return 0;
......@@ -739,9 +757,11 @@ ImageUnzipQuit(void)
{
threadquit();
#ifndef linux
/* Set the MBR type if necesary */
if (slice && dostype >= 0)
fixmbr(slice, dostype);
#endif
fprintf(stderr, "Wrote %qd bytes (%qd actual)\n",
totaledata, totalrdata);
......@@ -1223,6 +1243,7 @@ writedata(off_t offset, size_t size, void *buf)
totalrdata += cc;
}
#ifndef linux
/*
* DOS partition table handling
*/
......@@ -1235,6 +1256,8 @@ struct doslabel {
#define DOSPARTSIZE \
(DOSPARTOFF + sizeof(doslabel.parts) + sizeof(doslabel.magic))
static long long outputmaxsize = 0;
/*
* Parse the DOS partition table to set the bounds of the slice we
* are writing to.
......@@ -1314,10 +1337,13 @@ fixmbr(int slice, int dtype)
}
return 0;
}
#endif
static struct blockreloc *reloctable;
static int numrelocs;
#ifndef linux
static void reloc_bsdlabel(struct disklabel *label, int reloctype);
#endif
static void
getrelocinfo(blockhdr_t *hdr)
......@@ -1372,12 +1398,14 @@ applyrelocs(off_t offset, size_t size, void *buf)
switch (reloc->type) {
case RELOC_NONE:
break;
#ifndef linux
case RELOC_FBSDDISKLABEL:
case RELOC_OBSDDISKLABEL:
assert(reloc->size >= sizeof(struct disklabel));
reloc_bsdlabel((struct disklabel *)(buf+coff),
reloc->type);
break;
#endif
default:
fprintf(stderr,
"Ignoring unknown relocation type %d\n",
......@@ -1388,6 +1416,7 @@ applyrelocs(off_t offset, size_t size, void *buf)
}
}
#ifndef linux
static void
reloc_bsdlabel(struct disklabel *label, int reloctype)
{
......@@ -1456,6 +1485,7 @@ reloc_bsdlabel(struct disklabel *label, int reloctype)
label->d_checksum = 0;
label->d_checksum = dkcksum(label);
}
#endif
#if !defined(CONDVARS_WORK) && !defined(FRISBEE)
#include <errno.h>
......
......@@ -27,8 +27,8 @@
#include <sys/time.h>
#include <sys/stat.h>
#include <zlib.h>
#define DKTYPENAMES
#ifndef linux
#define DKTYPENAMES
#include <sys/disklabel.h>
#include <ufs/ffs/fs.h>
#endif
......@@ -62,6 +62,10 @@
#define DOSPTYP_OPENBSD 0xa6
#endif
#ifndef NDOSPART
#define NDOSPART 4
#endif
char *infilename;
int infd, outfd, outcanseek;
int secsize = 512; /* XXX bytes. */
......@@ -630,6 +634,9 @@ read_bsdslice(int slice, u_int32_t start, u_int32_t size, int bsdtype)
}
if (debug) {
/* XXX silence gcc about dktypenames */
rval = DKMAXTYPES;
fprintf(stderr, " %c ", BSDPARTNAME(i));
fprintf(stderr, " start %9d, size %9d\t(%s)\n",
......@@ -952,7 +959,7 @@ read_linuxgroup(struct ext2_super_block *super,
offset += (off_t)EXT2_BLOCK_SIZE(super) * group->bg_block_bitmap;
if (devlseek(infd, offset, SEEK_SET) < 0) {
warn("Linux Group %d: "
"Could not seek to Group bitmap %ld",
"Could not seek to Group bitmap %d",
index, group->bg_block_bitmap);
return 1;
}
......@@ -2194,7 +2201,7 @@ static z_stream d_stream; /* Compression stream */
static off_t
compress_chunk(off_t off, off_t size, int *full, uint32_t *subblksize)
{
int cc, count, err, eof, finish, outsize;
int cc, count, err, tileof, finish, outsize;
off_t total = 0;
/*
......@@ -2217,10 +2224,10 @@ compress_chunk(off_t off, off_t size, int *full, uint32_t *subblksize)
* (and report back how much).
*/
if (!size) {
eof = 1;
size = QUAD_MAX;
tileof = 1;
size = BSIZE + 1;
} else
eof = 0;
tileof = 0;
while (size > 0) {
if (size > BSIZE)
......@@ -2261,9 +2268,10 @@ compress_chunk(off_t off, off_t size, int *full, uint32_t *subblksize)
break;
}
if (cc != count && !eof) {
if (cc != count && !tileof) {
fprintf(stderr, "Bad count in read, %d != %d at %qu\n",
cc, count, off+total);
cc, count,
off+total);
exit(1);
}
......@@ -2273,7 +2281,8 @@ compress_chunk(off_t off, off_t size, int *full, uint32_t *subblksize)
if (fixups != NULL)
applyfixups(off+total, count, inbuf);
size -= cc;
if (!tileof)
size -= cc;
total += cc;
outsize = SUBBLOCKSIZE - buffer_offset;
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment