o Move logic that determines size of the input image into its own
file. That logic has grown quite significantly now; o add a special handling for the snapshot images. Those have some extra headers at the end of the image and we don't need those in the output image really. MFC after: 6 weeks
This commit is contained in:
parent
944fb7c553
commit
c9cda0bfe0
@ -3,7 +3,7 @@
|
|||||||
PROG= mkuzip
|
PROG= mkuzip
|
||||||
MAN= mkuzip.8
|
MAN= mkuzip.8
|
||||||
SRCS= mkuzip.c mkuz_blockcache.c mkuz_lzma.c mkuz_zlib.c mkuz_conveyor.c \
|
SRCS= mkuzip.c mkuz_blockcache.c mkuz_lzma.c mkuz_zlib.c mkuz_conveyor.c \
|
||||||
mkuz_blk.c mkuz_fqueue.c mkuz_time.c
|
mkuz_blk.c mkuz_fqueue.c mkuz_time.c mkuz_insize.c
|
||||||
|
|
||||||
#CFLAGS+= -DMKUZ_DEBUG
|
#CFLAGS+= -DMKUZ_DEBUG
|
||||||
|
|
||||||
|
@ -36,5 +36,7 @@ struct mkuz_cfg {
|
|||||||
int en_dedup;
|
int en_dedup;
|
||||||
int nworkers;
|
int nworkers;
|
||||||
int blksz;
|
int blksz;
|
||||||
|
const char *iname;
|
||||||
|
off_t isize;
|
||||||
const struct mkuz_format *handler;
|
const struct mkuz_format *handler;
|
||||||
};
|
};
|
||||||
|
80
usr.bin/mkuzip/mkuz_insize.c
Normal file
80
usr.bin/mkuzip/mkuz_insize.c
Normal file
@ -0,0 +1,80 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (c) 2004-2016 Maxim Sobolev <sobomax@FreeBSD.org>
|
||||||
|
* 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. Redistributions in binary form must reproduce the above copyright
|
||||||
|
* notice, this list of conditions and the following disclaimer in the
|
||||||
|
* documentation and/or other materials provided with the distribution.
|
||||||
|
*
|
||||||
|
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``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 OR CONTRIBUTORS 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.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include <sys/cdefs.h>
|
||||||
|
__FBSDID("$FreeBSD$");
|
||||||
|
|
||||||
|
#include <sys/disk.h>
|
||||||
|
#include <sys/ioctl.h>
|
||||||
|
#include <sys/param.h>
|
||||||
|
#include <sys/mount.h>
|
||||||
|
#include <sys/stat.h>
|
||||||
|
#include <err.h>
|
||||||
|
#include <fcntl.h>
|
||||||
|
|
||||||
|
#include "mkuz_cfg.h"
|
||||||
|
#include "mkuz_insize.h"
|
||||||
|
|
||||||
|
off_t
|
||||||
|
mkuz_get_insize(struct mkuz_cfg *cfp)
|
||||||
|
{
|
||||||
|
int ffd;
|
||||||
|
off_t ms;
|
||||||
|
struct stat sb;
|
||||||
|
struct statfs statfsbuf;
|
||||||
|
|
||||||
|
if (fstat(cfp->fdr, &sb) != 0) {
|
||||||
|
warn("fstat(%s)", cfp->iname);
|
||||||
|
return (-1);
|
||||||
|
}
|
||||||
|
if ((sb.st_flags & SF_SNAPSHOT) != 0) {
|
||||||
|
if (fstatfs(cfp->fdr, &statfsbuf) != 0) {
|
||||||
|
warn("fstatfs(%s)", cfp->iname);
|
||||||
|
return (-1);
|
||||||
|
}
|
||||||
|
ffd = open(statfsbuf.f_mntfromname, O_RDONLY);
|
||||||
|
if (ffd < 0) {
|
||||||
|
warn("open(%s, O_RDONLY)", statfsbuf.f_mntfromname);
|
||||||
|
return (-1);
|
||||||
|
}
|
||||||
|
if (ioctl(ffd, DIOCGMEDIASIZE, &ms) < 0) {
|
||||||
|
warn("ioctl(DIOCGMEDIASIZE)");
|
||||||
|
return (-1);
|
||||||
|
}
|
||||||
|
sb.st_size = ms;
|
||||||
|
} else if (S_ISCHR(sb.st_mode)) {
|
||||||
|
if (ioctl(cfp->fdr, DIOCGMEDIASIZE, &ms) < 0) {
|
||||||
|
warn("ioctl(DIOCGMEDIASIZE)");
|
||||||
|
return (-1);
|
||||||
|
}
|
||||||
|
sb.st_size = ms;
|
||||||
|
} else if (!S_ISREG(sb.st_mode)) {
|
||||||
|
warnx("%s: not a character device or regular file\n",
|
||||||
|
cfp->iname);
|
||||||
|
return (-1);
|
||||||
|
}
|
||||||
|
return (sb.st_size);
|
||||||
|
}
|
29
usr.bin/mkuzip/mkuz_insize.h
Normal file
29
usr.bin/mkuzip/mkuz_insize.h
Normal file
@ -0,0 +1,29 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (c) 2016 Maxim Sobolev <sobomax@FreeBSD.org>
|
||||||
|
* 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. Redistributions in binary form must reproduce the above copyright
|
||||||
|
* notice, this list of conditions and the following disclaimer in the
|
||||||
|
* documentation and/or other materials provided with the distribution.
|
||||||
|
*
|
||||||
|
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``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 OR CONTRIBUTORS 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.
|
||||||
|
*
|
||||||
|
* $FreeBSD$
|
||||||
|
*/
|
||||||
|
|
||||||
|
off_t mkuz_get_insize(struct mkuz_cfg *);
|
@ -28,7 +28,6 @@
|
|||||||
__FBSDID("$FreeBSD$");
|
__FBSDID("$FreeBSD$");
|
||||||
|
|
||||||
#include <sys/types.h>
|
#include <sys/types.h>
|
||||||
#include <sys/disk.h>
|
|
||||||
#include <sys/endian.h>
|
#include <sys/endian.h>
|
||||||
#include <sys/param.h>
|
#include <sys/param.h>
|
||||||
#include <sys/sysctl.h>
|
#include <sys/sysctl.h>
|
||||||
@ -58,6 +57,7 @@ __FBSDID("$FreeBSD$");
|
|||||||
#include "mkuz_format.h"
|
#include "mkuz_format.h"
|
||||||
#include "mkuz_fqueue.h"
|
#include "mkuz_fqueue.h"
|
||||||
#include "mkuz_time.h"
|
#include "mkuz_time.h"
|
||||||
|
#include "mkuz_insize.h"
|
||||||
|
|
||||||
#define DEFAULT_CLSTSIZE 16384
|
#define DEFAULT_CLSTSIZE 16384
|
||||||
|
|
||||||
@ -94,7 +94,7 @@ cmp_blkno(const struct mkuz_blk *bp, void *p)
|
|||||||
int main(int argc, char **argv)
|
int main(int argc, char **argv)
|
||||||
{
|
{
|
||||||
struct mkuz_cfg cfs;
|
struct mkuz_cfg cfs;
|
||||||
char *iname, *oname;
|
char *oname;
|
||||||
uint64_t *toc;
|
uint64_t *toc;
|
||||||
int i, io, opt, tmp;
|
int i, io, opt, tmp;
|
||||||
struct {
|
struct {
|
||||||
@ -102,7 +102,6 @@ int main(int argc, char **argv)
|
|||||||
FILE *f;
|
FILE *f;
|
||||||
} summary;
|
} summary;
|
||||||
struct iovec iov[2];
|
struct iovec iov[2];
|
||||||
struct stat sb;
|
|
||||||
uint64_t offset, last_offset;
|
uint64_t offset, last_offset;
|
||||||
struct cloop_header hdr;
|
struct cloop_header hdr;
|
||||||
struct mkuz_conveyor *cvp;
|
struct mkuz_conveyor *cvp;
|
||||||
@ -203,9 +202,9 @@ int main(int argc, char **argv)
|
|||||||
|
|
||||||
c_ctx = cfs.handler->f_init(cfs.blksz);
|
c_ctx = cfs.handler->f_init(cfs.blksz);
|
||||||
|
|
||||||
iname = argv[0];
|
cfs.iname = argv[0];
|
||||||
if (oname == NULL) {
|
if (oname == NULL) {
|
||||||
asprintf(&oname, "%s%s", iname, cfs.handler->default_sufx);
|
asprintf(&oname, "%s%s", cfs.iname, cfs.handler->default_sufx);
|
||||||
if (oname == NULL) {
|
if (oname == NULL) {
|
||||||
err(1, "can't allocate memory");
|
err(1, "can't allocate memory");
|
||||||
/* Not reached */
|
/* Not reached */
|
||||||
@ -219,30 +218,18 @@ int main(int argc, char **argv)
|
|||||||
signal(SIGXFSZ, exit);
|
signal(SIGXFSZ, exit);
|
||||||
atexit(cleanup);
|
atexit(cleanup);
|
||||||
|
|
||||||
cfs.fdr = open(iname, O_RDONLY);
|
cfs.fdr = open(cfs.iname, O_RDONLY);
|
||||||
if (cfs.fdr < 0) {
|
if (cfs.fdr < 0) {
|
||||||
err(1, "open(%s)", iname);
|
err(1, "open(%s)", cfs.iname);
|
||||||
/* Not reached */
|
/* Not reached */
|
||||||
}
|
}
|
||||||
if (fstat(cfs.fdr, &sb) != 0) {
|
cfs.isize = mkuz_get_insize(&cfs);
|
||||||
err(1, "fstat(%s)", iname);
|
if (cfs.isize < 0) {
|
||||||
|
errx(1, "can't determine input image size");
|
||||||
/* Not reached */
|
/* Not reached */
|
||||||
}
|
}
|
||||||
if (S_ISCHR(sb.st_mode)) {
|
hdr.nblocks = cfs.isize / cfs.blksz;
|
||||||
off_t ms;
|
if ((cfs.isize % cfs.blksz) != 0) {
|
||||||
|
|
||||||
if (ioctl(cfs.fdr, DIOCGMEDIASIZE, &ms) < 0) {
|
|
||||||
err(1, "ioctl(DIOCGMEDIASIZE)");
|
|
||||||
/* Not reached */
|
|
||||||
}
|
|
||||||
sb.st_size = ms;
|
|
||||||
} else if (!S_ISREG(sb.st_mode)) {
|
|
||||||
fprintf(stderr, "%s: not a character device or regular file\n",
|
|
||||||
iname);
|
|
||||||
exit(1);
|
|
||||||
}
|
|
||||||
hdr.nblocks = sb.st_size / cfs.blksz;
|
|
||||||
if ((sb.st_size % cfs.blksz) != 0) {
|
|
||||||
if (cfs.verbose != 0)
|
if (cfs.verbose != 0)
|
||||||
fprintf(stderr, "file size is not multiple "
|
fprintf(stderr, "file size is not multiple "
|
||||||
"of %d, padding data\n", cfs.blksz);
|
"of %d, padding data\n", cfs.blksz);
|
||||||
@ -270,7 +257,7 @@ int main(int argc, char **argv)
|
|||||||
|
|
||||||
if (cfs.verbose != 0) {
|
if (cfs.verbose != 0) {
|
||||||
fprintf(stderr, "data size %ju bytes, number of clusters "
|
fprintf(stderr, "data size %ju bytes, number of clusters "
|
||||||
"%u, index length %zu bytes\n", sb.st_size,
|
"%u, index length %zu bytes\n", cfs.isize,
|
||||||
hdr.nblocks, iov[1].iov_len);
|
hdr.nblocks, iov[1].iov_len);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -353,9 +340,9 @@ int main(int argc, char **argv)
|
|||||||
et = getdtime();
|
et = getdtime();
|
||||||
fprintf(summary.f, "compressed data to %ju bytes, saved %lld "
|
fprintf(summary.f, "compressed data to %ju bytes, saved %lld "
|
||||||
"bytes, %.2f%% decrease, %.2f bytes/sec.\n", offset,
|
"bytes, %.2f%% decrease, %.2f bytes/sec.\n", offset,
|
||||||
(long long)(sb.st_size - offset),
|
(long long)(cfs.isize - offset),
|
||||||
100.0 * (long long)(sb.st_size - offset) /
|
100.0 * (long long)(cfs.isize - offset) /
|
||||||
(float)sb.st_size, (float)sb.st_size / (et - st));
|
(float)cfs.isize, (float)cfs.isize / (et - st));
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Convert to big endian */
|
/* Convert to big endian */
|
||||||
|
Loading…
Reference in New Issue
Block a user