diff options
author | dim <dim@FreeBSD.org> | 2016-02-24 21:38:51 +0000 |
---|---|---|
committer | dim <dim@FreeBSD.org> | 2016-02-24 21:38:51 +0000 |
commit | 7ef26dcde64aff82cf88b8e9354f8000fdf1b1c8 (patch) | |
tree | 093f0dab43c9b41b5442d7a487fbbf387d5e7a2c /usr.bin | |
parent | 234d55af8b6e6a323f480cc9c25a31d2cd7ea81d (diff) | |
parent | c9f48b7d63385be81574c190e92e621b2b6570a3 (diff) | |
download | FreeBSD-src-7ef26dcde64aff82cf88b8e9354f8000fdf1b1c8.zip FreeBSD-src-7ef26dcde64aff82cf88b8e9354f8000fdf1b1c8.tar.gz |
Merge ^/head r295902 through r296006.
Diffstat (limited to 'usr.bin')
58 files changed, 772 insertions, 1052 deletions
diff --git a/usr.bin/Makefile b/usr.bin/Makefile index 474bee1..a30476f 100644 --- a/usr.bin/Makefile +++ b/usr.bin/Makefile @@ -99,7 +99,6 @@ SUBDIR= alias \ mkimg \ mklocale \ mktemp \ - mkulzma \ mkuzip \ mt \ ncal \ diff --git a/usr.bin/ar/Makefile.depend b/usr.bin/ar/Makefile.depend index cabff68..8def7bc 100644 --- a/usr.bin/ar/Makefile.depend +++ b/usr.bin/ar/Makefile.depend @@ -24,10 +24,4 @@ DIRDEPS = \ .if ${DEP_RELDIR} == ${_DEP_RELDIR} # local dependencies - needed for -jN in clean tree -acplex.o: acplex.c -acplex.o: y.tab.h -acplex.po: acplex.c -acplex.po: y.tab.h -acpyacc.o: acpyacc.c -acpyacc.po: acpyacc.c .endif diff --git a/usr.bin/awk/Makefile.depend b/usr.bin/awk/Makefile.depend index 2fddd14..cb80454 100644 --- a/usr.bin/awk/Makefile.depend +++ b/usr.bin/awk/Makefile.depend @@ -17,24 +17,4 @@ DIRDEPS = \ .if ${DEP_RELDIR} == ${_DEP_RELDIR} # local dependencies - needed for -jN in clean tree -awkgram.o: awkgram.c -awkgram.po: awkgram.c -b.o: ytab.h -b.po: ytab.h -lex.o: ytab.h -lex.po: ytab.h -lib.o: ytab.h -lib.po: ytab.h -main.o: ytab.h -main.po: ytab.h -parse.o: ytab.h -parse.po: ytab.h -proctab.o: proctab.c -proctab.o: ytab.h -proctab.po: proctab.c -proctab.po: ytab.h -run.o: ytab.h -run.po: ytab.h -tran.o: ytab.h -tran.po: ytab.h .endif diff --git a/usr.bin/bc/Makefile.depend b/usr.bin/bc/Makefile.depend index e759653..eb5b174 100644 --- a/usr.bin/bc/Makefile.depend +++ b/usr.bin/bc/Makefile.depend @@ -18,10 +18,4 @@ DIRDEPS = \ .if ${DEP_RELDIR} == ${_DEP_RELDIR} # local dependencies - needed for -jN in clean tree -bc.o: bc.c -bc.po: bc.c -scan.o: bc.h -scan.o: scan.c -scan.po: bc.h -scan.po: scan.c .endif diff --git a/usr.bin/clang/bugpoint/Makefile.depend b/usr.bin/clang/bugpoint/Makefile.depend index 2b2e060..4540509 100644 --- a/usr.bin/clang/bugpoint/Makefile.depend +++ b/usr.bin/clang/bugpoint/Makefile.depend @@ -42,6 +42,4 @@ DIRDEPS = \ .if ${DEP_RELDIR} == ${_DEP_RELDIR} # local dependencies - needed for -jN in clean tree -bugpoint.o: Intrinsics.inc.h -bugpoint.po: Intrinsics.inc.h .endif diff --git a/usr.bin/clang/clang/Makefile.depend b/usr.bin/clang/clang/Makefile.depend index bee00f5..24611b4 100644 --- a/usr.bin/clang/clang/Makefile.depend +++ b/usr.bin/clang/clang/Makefile.depend @@ -100,26 +100,4 @@ DIRDEPS = \ .if ${DEP_RELDIR} == ${_DEP_RELDIR} # local dependencies - needed for -jN in clean tree -cc1_main.o: DiagnosticCommonKinds.inc.h -cc1_main.o: DiagnosticDriverKinds.inc.h -cc1_main.o: DiagnosticFrontendKinds.inc.h -cc1_main.o: Options.inc.h -cc1_main.po: DiagnosticCommonKinds.inc.h -cc1_main.po: DiagnosticDriverKinds.inc.h -cc1_main.po: DiagnosticFrontendKinds.inc.h -cc1_main.po: Options.inc.h -cc1as_main.o: DiagnosticCommonKinds.inc.h -cc1as_main.o: DiagnosticDriverKinds.inc.h -cc1as_main.o: DiagnosticFrontendKinds.inc.h -cc1as_main.o: Options.inc.h -cc1as_main.po: DiagnosticCommonKinds.inc.h -cc1as_main.po: DiagnosticDriverKinds.inc.h -cc1as_main.po: DiagnosticFrontendKinds.inc.h -cc1as_main.po: Options.inc.h -driver.o: DiagnosticCommonKinds.inc.h -driver.o: DiagnosticDriverKinds.inc.h -driver.o: Options.inc.h -driver.po: DiagnosticCommonKinds.inc.h -driver.po: DiagnosticDriverKinds.inc.h -driver.po: Options.inc.h .endif diff --git a/usr.bin/clang/llc/Makefile.depend b/usr.bin/clang/llc/Makefile.depend index b61b871..89b7ace 100644 --- a/usr.bin/clang/llc/Makefile.depend +++ b/usr.bin/clang/llc/Makefile.depend @@ -80,6 +80,4 @@ DIRDEPS = \ .if ${DEP_RELDIR} == ${_DEP_RELDIR} # local dependencies - needed for -jN in clean tree -llc.o: Intrinsics.inc.h -llc.po: Intrinsics.inc.h .endif diff --git a/usr.bin/clang/llvm-dis/Makefile.depend b/usr.bin/clang/llvm-dis/Makefile.depend index fd46482..9ff2a96 100644 --- a/usr.bin/clang/llvm-dis/Makefile.depend +++ b/usr.bin/clang/llvm-dis/Makefile.depend @@ -24,6 +24,4 @@ DIRDEPS = \ .if ${DEP_RELDIR} == ${_DEP_RELDIR} # local dependencies - needed for -jN in clean tree -llvm-dis.o: Intrinsics.inc.h -llvm-dis.po: Intrinsics.inc.h .endif diff --git a/usr.bin/clang/llvm-lto/Makefile.depend b/usr.bin/clang/llvm-lto/Makefile.depend index cea3df4..65a810f 100644 --- a/usr.bin/clang/llvm-lto/Makefile.depend +++ b/usr.bin/clang/llvm-lto/Makefile.depend @@ -83,6 +83,4 @@ DIRDEPS = \ .if ${DEP_RELDIR} == ${_DEP_RELDIR} # local dependencies - needed for -jN in clean tree -llvm-lto.o: Intrinsics.inc.h -llvm-lto.po: Intrinsics.inc.h .endif diff --git a/usr.bin/clang/opt/Makefile.depend b/usr.bin/clang/opt/Makefile.depend index 029d956..021f7a6 100644 --- a/usr.bin/clang/opt/Makefile.depend +++ b/usr.bin/clang/opt/Makefile.depend @@ -84,12 +84,4 @@ DIRDEPS = \ .if ${DEP_RELDIR} == ${_DEP_RELDIR} # local dependencies - needed for -jN in clean tree -AnalysisWrappers.o: Intrinsics.inc.h -AnalysisWrappers.po: Intrinsics.inc.h -PassPrinters.o: Intrinsics.inc.h -PassPrinters.po: Intrinsics.inc.h -PrintSCC.o: Intrinsics.inc.h -PrintSCC.po: Intrinsics.inc.h -opt.o: Intrinsics.inc.h -opt.po: Intrinsics.inc.h .endif diff --git a/usr.bin/colldef/Makefile.depend b/usr.bin/colldef/Makefile.depend index 3ca32c6..26839bd 100644 --- a/usr.bin/colldef/Makefile.depend +++ b/usr.bin/colldef/Makefile.depend @@ -18,10 +18,4 @@ DIRDEPS = \ .if ${DEP_RELDIR} == ${_DEP_RELDIR} # local dependencies - needed for -jN in clean tree -parse.o: parse.c -parse.po: parse.c -scan.o: scan.c -scan.o: y.tab.h -scan.po: scan.c -scan.po: y.tab.h .endif diff --git a/usr.bin/compile_et/Makefile.depend b/usr.bin/compile_et/Makefile.depend index 94ad84e..1288666 100644 --- a/usr.bin/compile_et/Makefile.depend +++ b/usr.bin/compile_et/Makefile.depend @@ -20,12 +20,4 @@ DIRDEPS = \ .if ${DEP_RELDIR} == ${_DEP_RELDIR} # local dependencies - needed for -jN in clean tree -compile_et.o: parse.h -compile_et.po: parse.h -lex.o: lex.c -lex.o: parse.h -lex.po: lex.c -lex.po: parse.h -parse.o: parse.c -parse.po: parse.c .endif diff --git a/usr.bin/find/Makefile.depend b/usr.bin/find/Makefile.depend index 9de4374..ca0b2f9 100644 --- a/usr.bin/find/Makefile.depend +++ b/usr.bin/find/Makefile.depend @@ -16,6 +16,4 @@ DIRDEPS = \ .if ${DEP_RELDIR} == ${_DEP_RELDIR} # local dependencies - needed for -jN in clean tree -getdate.o: getdate.c -getdate.po: getdate.c .endif diff --git a/usr.bin/getconf/Makefile.depend b/usr.bin/getconf/Makefile.depend index cd02691..3646e2e 100644 --- a/usr.bin/getconf/Makefile.depend +++ b/usr.bin/getconf/Makefile.depend @@ -15,14 +15,4 @@ DIRDEPS = \ .if ${DEP_RELDIR} == ${_DEP_RELDIR} # local dependencies - needed for -jN in clean tree -confstr.o: confstr.c -confstr.po: confstr.c -limits.o: limits.c -limits.po: limits.c -pathconf.o: pathconf.c -pathconf.po: pathconf.c -progenv.o: progenv.c -progenv.po: progenv.c -sysconf.o: sysconf.c -sysconf.po: sysconf.c .endif diff --git a/usr.bin/iscsictl/Makefile.depend b/usr.bin/iscsictl/Makefile.depend index 05df091..6146f86 100644 --- a/usr.bin/iscsictl/Makefile.depend +++ b/usr.bin/iscsictl/Makefile.depend @@ -19,10 +19,4 @@ DIRDEPS = \ .if ${DEP_RELDIR} == ${_DEP_RELDIR} # local dependencies - needed for -jN in clean tree -parse.o: parse.c -parse.po: parse.c -token.o: token.c -token.o: y.tab.h -token.po: token.c -token.po: y.tab.h .endif diff --git a/usr.bin/kdump/Makefile.depend b/usr.bin/kdump/Makefile.depend index e3c5ae7..4faacfd 100644 --- a/usr.bin/kdump/Makefile.depend +++ b/usr.bin/kdump/Makefile.depend @@ -19,10 +19,4 @@ DIRDEPS = \ .if ${DEP_RELDIR} == ${_DEP_RELDIR} # local dependencies - needed for -jN in clean tree -kdump.o: kdump_subr.h -kdump.po: kdump_subr.h -kdump_subr.o: kdump_subr.c -kdump_subr.o: kdump_subr.h -kdump_subr.po: kdump_subr.c -kdump_subr.po: kdump_subr.h .endif diff --git a/usr.bin/kdump/kdump.c b/usr.bin/kdump/kdump.c index 8fe03ea..b4a1f69 100644 --- a/usr.bin/kdump/kdump.c +++ b/usr.bin/kdump/kdump.c @@ -142,28 +142,6 @@ static struct ktr_header ktr_header; c = ','; \ } while (0) -#if defined(__amd64__) || defined(__i386__) - -void linux_ktrsysret(struct ktr_sysret *, u_int); - -/* - * from linux.h - * Linux syscalls return negative errno's, we do positive and map them - */ -static int bsd_to_linux_errno[ELAST + 1] = { - -0, -1, -2, -3, -4, -5, -6, -7, -8, -9, - -10, -35, -12, -13, -14, -15, -16, -17, -18, -19, - -20, -21, -22, -23, -24, -25, -26, -27, -28, -29, - -30, -31, -32, -33, -34, -11,-115,-114, -88, -89, - -90, -91, -92, -93, -94, -95, -96, -97, -98, -99, - -100,-101,-102,-103,-104,-105,-106,-107,-108,-109, - -110,-111, -40, -36,-112,-113, -39, -11, -87,-122, - -116, -66, -6, -6, -6, -6, -6, -37, -38, -9, - -6, -6, -43, -42, -75,-125, -84, -95, -16, -74, - -72, -67, -71 -}; -#endif - struct proc_info { TAILQ_ENTRY(proc_info) info; @@ -393,13 +371,7 @@ main(int argc, char *argv[]) ktrsyscall((struct ktr_syscall *)m, sv_flags); break; case KTR_SYSRET: -#if defined(__amd64__) || defined(__i386__) - if ((sv_flags & SV_ABI_MASK) == SV_ABI_LINUX) - linux_ktrsysret((struct ktr_sysret *)m, - sv_flags); - else -#endif - ktrsysret((struct ktr_sysret *)m, sv_flags); + ktrsysret((struct ktr_sysret *)m, sv_flags); break; case KTR_NAMEI: case KTR_SYSCTL: @@ -1366,7 +1338,8 @@ ktrsysret(struct ktr_sysret *ktr, u_int sv_flags) else if (error == EJUSTRETURN) printf("JUSTRETURN"); else { - printf("-1 errno %d", ktr->ktr_error); + printf("-1 errno %d", sysdecode_freebsd_to_abi_errno( + syscallabi(sv_flags), error)); if (fancy) printf(" %s", strerror(ktr->ktr_error)); } @@ -1852,44 +1825,6 @@ ktrfaultend(struct ktr_faultend *ktr) printf("\n"); } -#if defined(__amd64__) || defined(__i386__) -void -linux_ktrsysret(struct ktr_sysret *ktr, u_int sv_flags) -{ - register_t ret = ktr->ktr_retval; - int error = ktr->ktr_error; - - syscallname(ktr->ktr_code, sv_flags); - printf(" "); - - if (error == 0) { - if (fancy) { - printf("%ld", (long)ret); - if (ret < 0 || ret > 9) - printf("/%#lx", (unsigned long)ret); - } else { - if (decimal) - printf("%ld", (long)ret); - else - printf("%#lx", (unsigned long)ret); - } - } else if (error == ERESTART) - printf("RESTART"); - else if (error == EJUSTRETURN) - printf("JUSTRETURN"); - else { - if (ktr->ktr_error <= ELAST + 1) - error = abs(bsd_to_linux_errno[ktr->ktr_error]); - else - error = 999; - printf("-1 errno %d", error); - if (fancy) - printf(" %s", strerror(ktr->ktr_error)); - } - putchar('\n'); -} -#endif - void usage(void) { diff --git a/usr.bin/lex/Makefile.depend b/usr.bin/lex/Makefile.depend index ae5191b..ca0b2f9 100644 --- a/usr.bin/lex/Makefile.depend +++ b/usr.bin/lex/Makefile.depend @@ -16,14 +16,4 @@ DIRDEPS = \ .if ${DEP_RELDIR} == ${_DEP_RELDIR} # local dependencies - needed for -jN in clean tree -parse.o: parse.c -parse.po: parse.c -scan.o: parse.h -scan.o: scan.c -scan.po: parse.h -scan.po: scan.c -skel.o: skel.c -skel.po: skel.c -yylex.o: parse.h -yylex.po: parse.h .endif diff --git a/usr.bin/localedef/Makefile.depend b/usr.bin/localedef/Makefile.depend index ac5eda1..ca0b2f9 100644 --- a/usr.bin/localedef/Makefile.depend +++ b/usr.bin/localedef/Makefile.depend @@ -16,24 +16,4 @@ DIRDEPS = \ .if ${DEP_RELDIR} == ${_DEP_RELDIR} # local dependencies - needed for -jN in clean tree -charmap.o: parser.h -charmap.po: parser.h -collate.o: parser.h -collate.po: parser.h -ctype.o: parser.h -ctype.po: parser.h -localedef.o: parser.h -localedef.po: parser.h -messages.o: parser.h -messages.po: parser.h -monetary.o: parser.h -monetary.po: parser.h -numeric.o: parser.h -numeric.po: parser.h -parser.o: parser.c -parser.po: parser.c -scanner.o: parser.h -scanner.po: parser.h -time.o: parser.h -time.po: parser.h .endif diff --git a/usr.bin/m4/Makefile.depend b/usr.bin/m4/Makefile.depend index 8ccf846..d97824a 100644 --- a/usr.bin/m4/Makefile.depend +++ b/usr.bin/m4/Makefile.depend @@ -20,10 +20,4 @@ DIRDEPS = \ .if ${DEP_RELDIR} == ${_DEP_RELDIR} # local dependencies - needed for -jN in clean tree -parser.o: parser.c -parser.po: parser.c -tokenizer.o: parser.h -tokenizer.o: tokenizer.c -tokenizer.po: parser.h -tokenizer.po: tokenizer.c .endif diff --git a/usr.bin/mkcsmapper/Makefile.depend b/usr.bin/mkcsmapper/Makefile.depend index b0cb3ac..75e2766 100644 --- a/usr.bin/mkcsmapper/Makefile.depend +++ b/usr.bin/mkcsmapper/Makefile.depend @@ -17,10 +17,4 @@ DIRDEPS = \ .if ${DEP_RELDIR} == ${_DEP_RELDIR} # local dependencies - needed for -jN in clean tree -lex.o: lex.c -lex.o: yacc.h -lex.po: lex.c -lex.po: yacc.h -yacc.o: yacc.c -yacc.po: yacc.c .endif diff --git a/usr.bin/mkcsmapper_static/Makefile b/usr.bin/mkcsmapper_static/Makefile index e16471a..21014e9 100644 --- a/usr.bin/mkcsmapper_static/Makefile +++ b/usr.bin/mkcsmapper_static/Makefile @@ -7,9 +7,7 @@ SRCS= citrus_bcs.c citrus_db_factory.c citrus_db_hash.c \ citrus_lookup_factory.c citrus_pivot_factory.c MAN= NO_SHARED= yes -.if ${MACHINE} == "host" -NO_WARNS= yes -.endif +NO_WMISSING_VARIABLE_DECLARATIONS= build-tools: mkcsmapper_static diff --git a/usr.bin/mkcsmapper_static/Makefile.depend b/usr.bin/mkcsmapper_static/Makefile.depend index ffee33f..75e2766 100644 --- a/usr.bin/mkcsmapper_static/Makefile.depend +++ b/usr.bin/mkcsmapper_static/Makefile.depend @@ -2,22 +2,19 @@ # Autogenerated - do NOT edit! DIRDEPS = \ + gnu/lib/csu \ + gnu/lib/libgcc \ include \ include/arpa \ include/xlocale \ lib/${CSU_DIR} \ lib/libc \ lib/libcompiler_rt \ + usr.bin/yacc.host \ .include <dirdeps.mk> .if ${DEP_RELDIR} == ${_DEP_RELDIR} # local dependencies - needed for -jN in clean tree -lex.o: lex.c -lex.o: yacc.h -lex.po: lex.c -lex.po: yacc.h -yacc.o: yacc.c -yacc.po: yacc.c .endif diff --git a/usr.bin/mkesdb/Makefile.depend b/usr.bin/mkesdb/Makefile.depend index 091f950..ca0b2f9 100644 --- a/usr.bin/mkesdb/Makefile.depend +++ b/usr.bin/mkesdb/Makefile.depend @@ -16,10 +16,4 @@ DIRDEPS = \ .if ${DEP_RELDIR} == ${_DEP_RELDIR} # local dependencies - needed for -jN in clean tree -lex.o: lex.c -lex.o: yacc.h -lex.po: lex.c -lex.po: yacc.h -yacc.o: yacc.c -yacc.po: yacc.c .endif diff --git a/usr.bin/mkesdb_static/Makefile b/usr.bin/mkesdb_static/Makefile index fb10f01..2696a23 100644 --- a/usr.bin/mkesdb_static/Makefile +++ b/usr.bin/mkesdb_static/Makefile @@ -7,9 +7,7 @@ SRCS= citrus_bcs.c citrus_db_factory.c citrus_db_hash.c \ citrus_lookup_factory.c MAN= NO_SHARED= yes -.if ${MACHINE} == "host" -NO_WARNS= yes -.endif +NO_WMISSING_VARIABLE_DECLARATIONS= build-tools: mkesdb_static diff --git a/usr.bin/mkulzma/Makefile.depend b/usr.bin/mkesdb_static/Makefile.depend index 987c487..75e2766 100644 --- a/usr.bin/mkulzma/Makefile.depend +++ b/usr.bin/mkesdb_static/Makefile.depend @@ -5,12 +5,12 @@ DIRDEPS = \ gnu/lib/csu \ gnu/lib/libgcc \ include \ + include/arpa \ include/xlocale \ lib/${CSU_DIR} \ lib/libc \ lib/libcompiler_rt \ - lib/liblzma \ - lib/libthr \ + usr.bin/yacc.host \ .include <dirdeps.mk> diff --git a/usr.bin/mklocale/Makefile.depend b/usr.bin/mklocale/Makefile.depend index b3bfc6d..75e2766 100644 --- a/usr.bin/mklocale/Makefile.depend +++ b/usr.bin/mklocale/Makefile.depend @@ -17,10 +17,4 @@ DIRDEPS = \ .if ${DEP_RELDIR} == ${_DEP_RELDIR} # local dependencies - needed for -jN in clean tree -lex.o: lex.c -lex.o: y.tab.h -lex.po: lex.c -lex.po: y.tab.h -yacc.o: yacc.c -yacc.po: yacc.c .endif diff --git a/usr.bin/mkulzma/Makefile b/usr.bin/mkulzma/Makefile deleted file mode 100644 index 15596bf..0000000 --- a/usr.bin/mkulzma/Makefile +++ /dev/null @@ -1,8 +0,0 @@ -# $FreeBSD$ - -PROG= mkulzma -MAN= mkulzma.8 - -LIBADD= lzma - -.include <bsd.prog.mk> diff --git a/usr.bin/mkulzma/mkulzma.8 b/usr.bin/mkulzma/mkulzma.8 deleted file mode 100644 index b4ac33f..0000000 --- a/usr.bin/mkulzma/mkulzma.8 +++ /dev/null @@ -1,107 +0,0 @@ -.\" ---------------------------------------------------------------------------- -.\" Derived from mkuzip.8 by Aleksandr Rybalko <ray@ddteam.net> -.\" ---------------------------------------------------------------------------- -.\" "THE BEER-WARE LICENSE" (Revision 42): -.\" <sobomax@FreeBSD.ORG> wrote this file. As long as you retain this notice you -.\" can do whatever you want with this stuff. If we meet some day, and you think -.\" this stuff is worth it, you can buy me a beer in return. Maxim Sobolev -.\" ---------------------------------------------------------------------------- -.\" -.\" $FreeBSD$ -.\" -.Dd March 17, 2006 -.Dt MKULZMA 8 -.Os -.Sh NAME -.Nm mkulzma -.Nd compress disk image for use with -.Xr geom_uncompress 4 -class -.Sh SYNOPSIS -.Nm -.Op Fl v -.Op Fl o Ar outfile -.Op Fl s Ar cluster_size -.Ar infile -.Sh DESCRIPTION -The -.Nm -utility compresses a disk image file so that the -.Xr geom_uncompress 4 -class will be able to decompress the resulting image at run-time. -This allows for a significant reduction of size of disk image at -the expense of some CPU time required to decompress the data each -time it is read. -The -.Nm -utility -works in two phases: -.Bl -enum -.It -An -.Ar infile -image is split into clusters; each cluster is compressed using liblzma. -.It -The resulting set of compressed clusters along with headers that allow -locating each individual cluster is written to the output file. -.El -.Pp -The options are: -.Bl -tag -width indent -.It Fl o Ar outfile -Name of the output file -.Ar outfile . -The default is to use the input name with the suffix -.Pa .ulzma . -.It Fl s Ar cluster_size -Split the image into clusters of -.Ar cluster_size -bytes, 16384 bytes by default. -The -.Ar cluster_size -should be a multiple of 512 bytes. -.It Fl v -Display verbose messages. -.El -.Sh NOTES -The compression ratio largely depends on the cluster size used. -.\" The following two sentences are unclear: how can xz(1) be -.\" used in a comparable fashion, and wouldn't a lzma-compressed -.\" image suffer from larger cluster sizes as well? -For large cluster sizes (16K and higher), typical compression ratios -are only 1-2% less than those achieved with -.Xr lzma 1 . -However, it should be kept in mind that larger cluster -sizes lead to higher overhead in the -.Xr geom_uncompress 4 -class, as the class has to decompress the whole cluster even if -only a few bytes from that cluster have to be read. -.Pp -The -.Nm -utility -inserts a short shell script at the beginning of the generated image, -which makes it possible to -.Dq run -the image just like any other shell script. -The script tries to load the -.Xr geom_uncompress 4 -class if it is not loaded, configure the image as an -.Xr md 4 -disk device using -.Xr mdconfig 8 , -and automatically mount it using -.Xr mount_cd9660 8 -on the mount point provided as the first argument to the script. -.Sh EXIT STATUS -.Ex -std -.Sh SEE ALSO -.Xr lzma 1 , -.Xr geom 4 , -.Xr geom_uncompress 4 , -.Xr md 4 , -.Xr mdconfig 8 , -.Xr mount_cd9660 8 -.Sh AUTHORS -.An Maxim Sobolev Aq Mt sobomax@FreeBSD.org -.An Aleksandr Rybalko Aq Mt ray@ddteam.net diff --git a/usr.bin/mkulzma/mkulzma.c b/usr.bin/mkulzma/mkulzma.c deleted file mode 100644 index b046c1e..0000000 --- a/usr.bin/mkulzma/mkulzma.c +++ /dev/null @@ -1,330 +0,0 @@ -/* - * ---------------------------------------------------------------------------- - * Derived from mkuzip.c by Aleksandr Rybalko <ray@ddteam.net> - * ---------------------------------------------------------------------------- - * "THE BEER-WARE LICENSE" (Revision 42): - * <sobomax@FreeBSD.ORG> wrote this file. As long as you retain this notice you - * can do whatever you want with this stuff. If we meet some day, and you think - * this stuff is worth it, you can buy me a beer in return. Maxim Sobolev - * ---------------------------------------------------------------------------- - * - * $FreeBSD$ - * - */ - -#include <sys/disk.h> -#include <sys/endian.h> -#include <sys/param.h> -#include <sys/stat.h> -#include <sys/uio.h> -#include <netinet/in.h> -#include <err.h> -#include <fcntl.h> -#include <stdio.h> -#include <stdlib.h> -#include <string.h> -#include <unistd.h> - -#include <lzma.h> - -#define CLSTSIZE 16384 -#define DEFAULT_SUFX ".ulzma" - -#define USED_BLOCKSIZE DEV_BSIZE - -#define CLOOP_MAGIC_LEN 128 -/* Format L3.0, since we move to XZ API */ -static char CLOOP_MAGIC_START[] = - "#!/bin/sh\n" - "#L3.0\n" - "n=uncompress\n" - "m=geom_$n\n" - "(kldstat -m $m 2>&-||kldload $m)>&-&&" - "mount_cd9660 /dev/`mdconfig -af $0`.$n $1\n" - "exit $?\n"; - -static char *readblock(int, char *, u_int32_t); -static void usage(void); -static void *safe_malloc(size_t); -static void cleanup(void); - -static char *cleanfile = NULL; - -int main(int argc, char **argv) -{ - char *iname, *oname, *obuf, *ibuf; - int fdr, fdw, i, opt, verbose, tmp; - struct iovec iov[2]; - struct stat sb; - uint32_t destlen; - uint64_t offset; - uint64_t *toc; - lzma_filter filters[2]; - lzma_options_lzma opt_lzma; - lzma_ret ret; - lzma_stream strm = LZMA_STREAM_INIT; - struct cloop_header { - char magic[CLOOP_MAGIC_LEN]; /* cloop magic */ - uint32_t blksz; /* block size */ - uint32_t nblocks; /* number of blocks */ - } hdr; - - memset(&hdr, 0, sizeof(hdr)); - hdr.blksz = CLSTSIZE; - strcpy(hdr.magic, CLOOP_MAGIC_START); - oname = NULL; - verbose = 0; - - while((opt = getopt(argc, argv, "o:s:v")) != -1) { - switch(opt) { - case 'o': - oname = optarg; - break; - - case 's': - tmp = atoi(optarg); - if (tmp <= 0) { - errx(1, - "invalid cluster size specified: %s", - optarg); - /* Not reached */ - } - if (tmp % USED_BLOCKSIZE != 0) { - errx(1, - "cluster size should be multiple of %d", - USED_BLOCKSIZE); - /* Not reached */ - } - if ( tmp > MAXPHYS) { - errx(1, "cluster size is too large"); - /* Not reached */ - } - hdr.blksz = tmp; - break; - - case 'v': - verbose = 1; - break; - - default: - usage(); - /* Not reached */ - } - } - argc -= optind; - argv += optind; - - if (argc != 1) { - usage(); - /* Not reached */ - } - - iname = argv[0]; - if (oname == NULL) { - asprintf(&oname, "%s%s", iname, DEFAULT_SUFX); - if (oname == NULL) { - err(1, "can't allocate memory"); - /* Not reached */ - } - } - - obuf = safe_malloc(hdr.blksz*2); - ibuf = safe_malloc(hdr.blksz); - - signal(SIGHUP, exit); - signal(SIGINT, exit); - signal(SIGTERM, exit); - signal(SIGXCPU, exit); - signal(SIGXFSZ, exit); - atexit(cleanup); - - fdr = open(iname, O_RDONLY); - if (fdr < 0) { - err(1, "open(%s)", iname); - /* Not reached */ - } - if (fstat(fdr, &sb) != 0) { - err(1, "fstat(%s)", iname); - /* Not reached */ - } - if (S_ISCHR(sb.st_mode)) { - off_t ms; - - if (ioctl(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 / hdr.blksz; - if ((sb.st_size % hdr.blksz) != 0) { - if (verbose != 0) - fprintf(stderr, "file size is not multiple " - "of %d, padding data\n", hdr.blksz); - hdr.nblocks++; - } - toc = safe_malloc((hdr.nblocks + 1) * sizeof(*toc)); - - fdw = open(oname, O_WRONLY | O_TRUNC | O_CREAT, - S_IRWXU | S_IRGRP | S_IXGRP | S_IROTH | S_IXOTH); - if (fdw < 0) { - err(1, "open(%s)", oname); - /* Not reached */ - } - cleanfile = oname; - - /* - * Prepare header that we will write later when we have index ready. - */ - iov[0].iov_base = (char *)&hdr; - iov[0].iov_len = sizeof(hdr); - iov[1].iov_base = (char *)toc; - iov[1].iov_len = (hdr.nblocks + 1) * sizeof(*toc); - offset = iov[0].iov_len + iov[1].iov_len; - - /* Reserve space for header */ - lseek(fdw, offset, SEEK_SET); - - if (verbose != 0) - fprintf(stderr, "data size %ju bytes, number of clusters " - "%u, index length %zu bytes\n", sb.st_size, - hdr.nblocks, iov[1].iov_len); - - /* Init lzma encoder */ - if (lzma_lzma_preset(&opt_lzma, LZMA_PRESET_DEFAULT)) - errx(1, "Error loading LZMA preset"); - - filters[0].id = LZMA_FILTER_LZMA2; - filters[0].options = &opt_lzma; - filters[1].id = LZMA_VLI_UNKNOWN; - - for(i = 0; i == 0 || ibuf != NULL; i++) { - ibuf = readblock(fdr, ibuf, hdr.blksz); - if (ibuf != NULL) { - destlen = hdr.blksz*2; - - ret = lzma_stream_encoder(&strm, filters, - LZMA_CHECK_CRC32); - if (ret != LZMA_OK) { - if (ret == LZMA_MEMLIMIT_ERROR) - errx(1, "can't compress data: " - "LZMA_MEMLIMIT_ERROR"); - - errx(1, "can't compress data: " - "LZMA compressor ERROR"); - } - - strm.next_in = ibuf; - strm.avail_in = hdr.blksz; - strm.next_out = obuf; - strm.avail_out = hdr.blksz*2; - - ret = lzma_code(&strm, LZMA_FINISH); - - if (ret != LZMA_STREAM_END) { - /* Error */ - errx(1, "lzma_code FINISH failed, code=%d, " - "pos(in=%zd, out=%zd)", - ret, - (hdr.blksz - strm.avail_in), - (hdr.blksz*2 - strm.avail_out)); - } - - destlen -= strm.avail_out; - - lzma_end(&strm); - - if (verbose != 0) - fprintf(stderr, "cluster #%d, in %u bytes, " - "out %u bytes\n", i, hdr.blksz, destlen); - } else { - destlen = USED_BLOCKSIZE - (offset % USED_BLOCKSIZE); - memset(obuf, 0, destlen); - if (verbose != 0) - fprintf(stderr, "padding data with %u bytes" - " so that file size is multiple of %d\n", - destlen, - USED_BLOCKSIZE); - } - if (write(fdw, obuf, destlen) < 0) { - err(1, "write(%s)", oname); - /* Not reached */ - } - toc[i] = htobe64(offset); - offset += destlen; - } - close(fdr); - - if (verbose != 0) - fprintf(stderr, "compressed data to %ju bytes, saved %lld " - "bytes, %.2f%% decrease.\n", offset, - (long long)(sb.st_size - offset), - 100.0 * (long long)(sb.st_size - offset) / - (float)sb.st_size); - - /* Convert to big endian */ - hdr.blksz = htonl(hdr.blksz); - hdr.nblocks = htonl(hdr.nblocks); - /* Write headers into pre-allocated space */ - lseek(fdw, 0, SEEK_SET); - if (writev(fdw, iov, 2) < 0) { - err(1, "writev(%s)", oname); - /* Not reached */ - } - cleanfile = NULL; - close(fdw); - - exit(0); -} - -static char * -readblock(int fd, char *ibuf, u_int32_t clstsize) -{ - int numread; - - bzero(ibuf, clstsize); - numread = read(fd, ibuf, clstsize); - if (numread < 0) { - err(1, "read() failed"); - /* Not reached */ - } - if (numread == 0) { - return NULL; - } - return ibuf; -} - -static void -usage(void) -{ - - fprintf(stderr, "usage: mkulzma [-v] [-o outfile] [-s cluster_size] " - "infile\n"); - exit(1); -} - -static void * -safe_malloc(size_t size) -{ - void *retval; - - retval = malloc(size); - if (retval == NULL) { - err(1, "can't allocate memory"); - /* Not reached */ - } - return retval; -} - -static void -cleanup(void) -{ - - if (cleanfile != NULL) - unlink(cleanfile); -} diff --git a/usr.bin/mkuzip/Makefile b/usr.bin/mkuzip/Makefile index 92ab43e..4050ad0 100644 --- a/usr.bin/mkuzip/Makefile +++ b/usr.bin/mkuzip/Makefile @@ -2,7 +2,8 @@ PROG= mkuzip MAN= mkuzip.8 +SRCS= mkuzip.c mkuz_blockcache.c mkuz_lzma.c mkuz_zlib.c -LIBADD= z +LIBADD= z md lzma .include <bsd.prog.mk> diff --git a/usr.bin/mkuzip/Makefile.depend b/usr.bin/mkuzip/Makefile.depend index d209adb..9d045c8 100644 --- a/usr.bin/mkuzip/Makefile.depend +++ b/usr.bin/mkuzip/Makefile.depend @@ -9,6 +9,9 @@ DIRDEPS = \ lib/${CSU_DIR} \ lib/libc \ lib/libcompiler_rt \ + lib/liblzma \ + lib/libmd \ + lib/libthr \ lib/libz \ diff --git a/usr.bin/mkuzip/mkuz_blockcache.c b/usr.bin/mkuzip/mkuz_blockcache.c new file mode 100644 index 0000000..a3ac564 --- /dev/null +++ b/usr.bin/mkuzip/mkuz_blockcache.c @@ -0,0 +1,97 @@ +/* + * 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. + * + */ + +#include <sys/cdefs.h> +__FBSDID("$FreeBSD$"); + +#include <sys/types.h> +#include <md5.h> +#include <stdlib.h> +#include <string.h> +#include <unistd.h> + +#if defined(MKUZ_DEBUG) +# include <stdio.h> +#endif + +#include "mkuz_blockcache.h" + +struct mkuz_blkcache { + struct mkuz_blkcache_hit hit; + off_t data_offset; + unsigned char digest[16]; + struct mkuz_blkcache *next; +}; + +static struct mkuz_blkcache blkcache; + +struct mkuz_blkcache_hit * +mkuz_blkcache_regblock(int fd, uint32_t blkno, off_t offset, ssize_t len, + void *data) +{ + struct mkuz_blkcache *bcep; + MD5_CTX mcontext; + off_t data_offset; + unsigned char mdigest[16]; + + data_offset = lseek(fd, 0, SEEK_CUR); + if (data_offset < 0) { + return (NULL); + } + MD5Init(&mcontext); + MD5Update(&mcontext, data, len); + MD5Final(mdigest, &mcontext); + if (blkcache.hit.len == 0) { + bcep = &blkcache; + } else { + for (bcep = &blkcache; bcep != NULL; bcep = bcep->next) { + if (bcep->hit.len != len) + continue; + if (memcmp(mdigest, bcep->digest, sizeof(mdigest)) == 0) { + break; + } + } + if (bcep != NULL) { +#if defined(MKUZ_DEBUG) + printf("cache hit %d, %d, %d\n", (int)bcep->hit.offset, (int)data_offset, (int)len); +#endif + return (&bcep->hit); + } + bcep = malloc(sizeof(struct mkuz_blkcache)); + if (bcep == NULL) + return (NULL); + memset(bcep, '\0', sizeof(struct mkuz_blkcache)); + bcep->next = blkcache.next; + blkcache.next = bcep; + } + memcpy(bcep->digest, mdigest, sizeof(mdigest)); + bcep->data_offset = data_offset; + bcep->hit.offset = offset; + bcep->hit.len = len; + bcep->hit.blkno = blkno; + return (NULL); +} diff --git a/usr.bin/mkuzip/mkuz_blockcache.h b/usr.bin/mkuzip/mkuz_blockcache.h new file mode 100644 index 0000000..2154ae8 --- /dev/null +++ b/usr.bin/mkuzip/mkuz_blockcache.h @@ -0,0 +1,36 @@ +/* + * 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$ + */ + +struct mkuz_blkcache_hit { + uint64_t offset; + ssize_t len; + uint32_t blkno; +}; + +struct mkuz_blkcache_hit *mkuz_blkcache_regblock(int, uint32_t, off_t, ssize_t, + void *); diff --git a/usr.bin/mkuzip/mkuz_cloop.h b/usr.bin/mkuzip/mkuz_cloop.h new file mode 100644 index 0000000..4ed7c50 --- /dev/null +++ b/usr.bin/mkuzip/mkuz_cloop.h @@ -0,0 +1,50 @@ +/* + * 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. + * + * $FreeBSD$ + */ + +/* CLOOP format and related constants */ + +/* + * Integer values (block size, number of blocks, offsets) + * are stored in big-endian (network) order on disk. + */ + +#define CLOOP_MAGIC_LEN 128 +#define CLOOP_OFS_COMPR 0x0b +#define CLOOP_OFS_VERSN (CLOOP_OFS_COMPR + 1) + +#define CLOOP_MAJVER_2 '2' +#define CLOOP_MAJVER_3 '3' + +#define CLOOP_COMP_LIBZ 'V' +#define CLOOP_COMP_LZMA 'L' + +struct cloop_header { + char magic[CLOOP_MAGIC_LEN]; /* cloop magic */ + uint32_t blksz; /* block size */ + uint32_t nblocks; /* number of blocks */ +}; diff --git a/usr.bin/mkuzip/mkuz_lzma.c b/usr.bin/mkuzip/mkuz_lzma.c new file mode 100644 index 0000000..d62376e --- /dev/null +++ b/usr.bin/mkuzip/mkuz_lzma.c @@ -0,0 +1,110 @@ +/* + * Copyright (c) 2004-2016 Maxim Sobolev <sobomax@FreeBSD.org> + * Copyright (c) 2011 Aleksandr Rybalko <ray@ddteam.net> + * 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/param.h> +#include <err.h> +#include <stdint.h> + +#include <lzma.h> + +#include "mkuzip.h" +#include "mkuz_lzma.h" + +#define USED_BLOCKSIZE DEV_BSIZE + +struct mkuz_lzma { + lzma_filter filters[2]; + lzma_options_lzma opt_lzma; + lzma_stream strm; + char *obuf; + uint32_t blksz; +}; + +static struct mkuz_lzma ulzma = {.strm = LZMA_STREAM_INIT}; + +void * +mkuz_lzma_init(uint32_t blksz) +{ + if (blksz % USED_BLOCKSIZE != 0) { + errx(1, "cluster size should be multiple of %d", + USED_BLOCKSIZE); + /* Not reached */ + } + if (blksz > MAXPHYS) { + errx(1, "cluster size is too large"); + /* Not reached */ + } + ulzma.obuf = mkuz_safe_malloc(blksz * 2); + + /* Init lzma encoder */ + if (lzma_lzma_preset(&ulzma.opt_lzma, LZMA_PRESET_DEFAULT)) + errx(1, "Error loading LZMA preset"); + + ulzma.filters[0].id = LZMA_FILTER_LZMA2; + ulzma.filters[0].options = &ulzma.opt_lzma; + ulzma.filters[1].id = LZMA_VLI_UNKNOWN; + + ulzma.blksz = blksz; + + return (ulzma.obuf); +} + +void +mkuz_lzma_compress(const char *ibuf, uint32_t *destlen) +{ + lzma_ret ret; + + ret = lzma_stream_encoder(&ulzma.strm, ulzma.filters, LZMA_CHECK_CRC32); + if (ret != LZMA_OK) { + if (ret == LZMA_MEMLIMIT_ERROR) + errx(1, "can't compress data: LZMA_MEMLIMIT_ERROR"); + + errx(1, "can't compress data: LZMA compressor ERROR"); + } + + ulzma.strm.next_in = ibuf; + ulzma.strm.avail_in = ulzma.blksz; + ulzma.strm.next_out = ulzma.obuf; + ulzma.strm.avail_out = ulzma.blksz * 2; + + ret = lzma_code(&ulzma.strm, LZMA_FINISH); + + if (ret != LZMA_STREAM_END) { + /* Error */ + errx(1, "lzma_code FINISH failed, code=%d, pos(in=%zd, " + "out=%zd)", ret, (ulzma.blksz - ulzma.strm.avail_in), + (ulzma.blksz * 2 - ulzma.strm.avail_out)); + } + + lzma_end(&ulzma.strm); + + *destlen = (ulzma.blksz * 2) - ulzma.strm.avail_out; +} diff --git a/usr.bin/mkuzip/mkuz_lzma.h b/usr.bin/mkuzip/mkuz_lzma.h new file mode 100644 index 0000000..426f8bc --- /dev/null +++ b/usr.bin/mkuzip/mkuz_lzma.h @@ -0,0 +1,42 @@ +/* + * Copyright (c) 2004-2016 Maxim Sobolev <sobomax@FreeBSD.org> + * Copyright (c) 2011 Aleksandr Rybalko <ray@ddteam.net> + * 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$ + */ + +/* Format L3.0, since we move to XZ API */ +#define CLOOP_MAGIC_LZMA \ + "#!/bin/sh\n" \ + "#L3.0\n" \ + "n=uncompress\n" \ + "m=geom_$n\n" \ + "(kldstat -m $m 2>&-||kldload $m)>&-&&" \ + "mount_cd9660 /dev/`mdconfig -af $0`.$n $1\n" \ + "exit $?\n" +#define DEFAULT_SUFX_LZMA ".ulzma" + +void *mkuz_lzma_init(uint32_t); +void mkuz_lzma_compress(const char *, uint32_t *); diff --git a/usr.bin/mkuzip/mkuz_zlib.c b/usr.bin/mkuzip/mkuz_zlib.c new file mode 100644 index 0000000..8828891 --- /dev/null +++ b/usr.bin/mkuzip/mkuz_zlib.c @@ -0,0 +1,81 @@ +/* + * 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/param.h> +#include <err.h> +#include <stdint.h> + +#include <zlib.h> + +#include "mkuzip.h" +#include "mkuz_zlib.h" + +struct mkuz_zlib { + char *obuf; + uLongf oblen; + uint32_t blksz; +}; + +static struct mkuz_zlib uzip; + +void * +mkuz_zlib_init(uint32_t blksz) +{ + if (blksz % DEV_BSIZE != 0) { + errx(1, "cluster size should be multiple of %d", + DEV_BSIZE); + /* Not reached */ + } + if (compressBound(blksz) > MAXPHYS) { + errx(1, "cluster size is too large"); + /* Not reached */ + } + uzip.oblen = compressBound(blksz); + uzip.obuf = mkuz_safe_malloc(uzip.oblen); + uzip.blksz = blksz; + + return (uzip.obuf); +} + +void +mkuz_zlib_compress(const char *ibuf, uint32_t *destlen) +{ + uLongf destlen_z; + + destlen_z = uzip.oblen; + if (compress2(uzip.obuf, &destlen_z, ibuf, uzip.blksz, + Z_BEST_COMPRESSION) != Z_OK) { + errx(1, "can't compress data: compress2() " + "failed"); + /* Not reached */ + } + + *destlen = (uint32_t)destlen_z; +} diff --git a/usr.bin/mkuzip/mkuz_zlib.h b/usr.bin/mkuzip/mkuz_zlib.h new file mode 100644 index 0000000..f50bba2 --- /dev/null +++ b/usr.bin/mkuzip/mkuz_zlib.h @@ -0,0 +1,36 @@ +/* + * 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. + * + * $FreeBSD$ + */ + +#define DEFAULT_SUFX_ZLIB ".uzip" + +#define CLOOP_MAGIC_ZLIB "#!/bin/sh\n#V2.0 Format\n" \ + "(kldstat -qm g_uzip||kldload geom_uzip)>&-&&" \ + "mount_cd9660 /dev/`mdconfig -af $0`.uzip $1\nexit $?\n" + +void *mkuz_zlib_init(uint32_t); +void mkuz_zlib_compress(const char *, uint32_t *); diff --git a/usr.bin/mkuzip/mkuzip.8 b/usr.bin/mkuzip/mkuzip.8 index c0b8315..c839551 100644 --- a/usr.bin/mkuzip/mkuzip.8 +++ b/usr.bin/mkuzip/mkuzip.8 @@ -1,9 +1,27 @@ -.\" ---------------------------------------------------------------------------- -.\" "THE BEER-WARE LICENSE" (Revision 42): -.\" <sobomax@FreeBSD.org> wrote this file. As long as you retain this notice you -.\" can do whatever you want with this stuff. If we meet some day, and you think -.\" this stuff is worth it, you can buy me a beer in return. Maxim Sobolev -.\" ---------------------------------------------------------------------------- +.\"- +.\" 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. .\" .\" $FreeBSD$ .\" @@ -39,7 +57,9 @@ works in two phases: An .Ar infile image is split into clusters; each cluster is compressed using -.Xr zlib 3 . +.Xr zlib 3 +or +.Xr lzma 3 . .It The resulting set of compressed clusters along with headers that allow locating each individual cluster is written to the output file. @@ -51,7 +71,23 @@ The options are: Name of the output file .Ar outfile . The default is to use the input name with the suffix -.Pa .uzip . +.Pa .uzip +for the +.Xr zlib 3 +compression or +.Pa .ulzma +for the +.Xr lzma 3 . +.It Fl L +Use +.Xr lzma 3 +compression algorithm instead of the default +.Xr zlib 3 . +The +.Xr lzma 3 +provides noticeable better compression levels on the same data set +at the expense of much slower compression speed (10-20x) and somewhat slower +decompression (2-3x). .It Fl s Ar cluster_size Split the image into clusters of .Ar cluster_size @@ -61,6 +97,27 @@ The should be a multiple of 512 bytes. .It Fl v Display verbose messages. +.It Fl Z +Disable zero-blocks detection and elimination. +When this option is set, the +.Nm +would compress empty blocks (i.e. clusters that consist of only zero bytes) +just as it would any other block. +When the option is not set, the +.Nm +detects such blocks and skips them from the output. +Setting +.Fl Z +results is slight increase of compressed image size, typically less than 0.1% +of a final size of the compressed image. +.It Fl d +Enable de-duplication. +When the option is enabled the +.Nm +detects identical blocks in the input and replaces each subsequent occurence +of such block with pointer to the very first one in the output. +Setting this option results is moderate decrease of compressed image size, +typically around 3-5% of a final size of the compressed image. .El .Sh NOTES The compression ratio largely depends on the cluster size used. @@ -92,11 +149,20 @@ disk device using and automatically mount it using .Xr mount_cd9660 8 on the mount point provided as the first argument to the script. +.Pp +The de-duplication is a +.Fx +specific feature and while it does not require any changes to on-disk +compressed image format, however it did require some matching changes to the +.Xr geom_uzip 4 +to handle resulting images correctly. .Sh EXIT STATUS .Ex -std .Sh SEE ALSO .Xr gzip 1 , +.Xr xz 1 , .Xr zlib 3 , +.Xr lzma 3 , .Xr geom 4 , .Xr geom_uzip 4 , .Xr md 4 , diff --git a/usr.bin/mkuzip/mkuzip.c b/usr.bin/mkuzip/mkuzip.c index 08c8ed0..1e3a204 100644 --- a/usr.bin/mkuzip/mkuzip.c +++ b/usr.bin/mkuzip/mkuzip.c @@ -1,15 +1,33 @@ /* - * ---------------------------------------------------------------------------- - * "THE BEER-WARE LICENSE" (Revision 42): - * <sobomax@FreeBSD.ORG> wrote this file. As long as you retain this notice you - * can do whatever you want with this stuff. If we meet some day, and you think - * this stuff is worth it, you can buy me a beer in return. Maxim Sobolev - * ---------------------------------------------------------------------------- + * Copyright (c) 2004-2016 Maxim Sobolev <sobomax@FreeBSD.org> + * All rights reserved. * - * $FreeBSD$ + * 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/types.h> #include <sys/disk.h> #include <sys/endian.h> @@ -17,7 +35,7 @@ #include <sys/stat.h> #include <sys/uio.h> #include <netinet/in.h> -#include <zlib.h> +#include <ctype.h> #include <err.h> #include <fcntl.h> #include <signal.h> @@ -26,18 +44,44 @@ #include <string.h> #include <unistd.h> -#define CLSTSIZE 16384 -#define DEFAULT_SUFX ".uzip" +#include "mkuzip.h" +#include "mkuz_cloop.h" +#include "mkuz_blockcache.h" +#include "mkuz_zlib.h" +#include "mkuz_lzma.h" + +#define DEFINE_RAW_METHOD(func, rval, args...) typedef rval (*func##_t)(args) + +#define DEFAULT_CLSTSIZE 16384 + +DEFINE_RAW_METHOD(f_init, void *, uint32_t); +DEFINE_RAW_METHOD(f_compress, void, const char *, uint32_t *); -#define CLOOP_MAGIC_LEN 128 -static char CLOOP_MAGIC_START[] = "#!/bin/sh\n#V2.0 Format\n" - "(kldstat -qm g_uzip||kldload geom_uzip)>&-&&" - "mount_cd9660 /dev/`mdconfig -af $0`.uzip $1\nexit $?\n"; +struct mkuz_format { + const char *magic; + const char *default_sufx; + f_init_t f_init; + f_compress_t f_compress; +}; + +static struct mkuz_format uzip_fmt = { + .magic = CLOOP_MAGIC_ZLIB, + .default_sufx = DEFAULT_SUFX_ZLIB, + .f_init = &mkuz_zlib_init, + .f_compress = &mkuz_zlib_compress +}; + +static struct mkuz_format ulzma_fmt = { + .magic = CLOOP_MAGIC_LZMA, + .default_sufx = DEFAULT_SUFX_LZMA, + .f_init = &mkuz_lzma_init, + .f_compress = &mkuz_lzma_compress +}; static char *readblock(int, char *, u_int32_t); static void usage(void); -static void *safe_malloc(size_t); static void cleanup(void); +static int memvcmp(const void *, unsigned char, size_t); static char *cleanfile = NULL; @@ -45,24 +89,24 @@ int main(int argc, char **argv) { char *iname, *oname, *obuf, *ibuf; uint64_t *toc; - int fdr, fdw, i, opt, verbose, tmp; + int fdr, fdw, i, opt, verbose, no_zcomp, tmp, en_dedup; struct iovec iov[2]; struct stat sb; - uLongf destlen; - uint64_t offset; - struct cloop_header { - char magic[CLOOP_MAGIC_LEN]; /* cloop magic */ - uint32_t blksz; /* block size */ - uint32_t nblocks; /* number of blocks */ - } hdr; + uint32_t destlen; + uint64_t offset, last_offset; + struct cloop_header hdr; + struct mkuz_blkcache_hit *chit; + const struct mkuz_format *handler; memset(&hdr, 0, sizeof(hdr)); - hdr.blksz = CLSTSIZE; - strcpy(hdr.magic, CLOOP_MAGIC_START); + hdr.blksz = DEFAULT_CLSTSIZE; oname = NULL; verbose = 0; + no_zcomp = 0; + en_dedup = 0; + handler = &uzip_fmt; - while((opt = getopt(argc, argv, "o:s:v")) != -1) { + while((opt = getopt(argc, argv, "o:s:vZdL")) != -1) { switch(opt) { case 'o': oname = optarg; @@ -75,15 +119,6 @@ int main(int argc, char **argv) optarg); /* Not reached */ } - if (tmp % DEV_BSIZE != 0) { - errx(1, "cluster size should be multiple of %d", - DEV_BSIZE); - /* Not reached */ - } - if (compressBound(tmp) > MAXPHYS) { - errx(1, "cluster size is too large"); - /* Not reached */ - } hdr.blksz = tmp; break; @@ -91,6 +126,18 @@ int main(int argc, char **argv) verbose = 1; break; + case 'Z': + no_zcomp = 1; + break; + + case 'd': + en_dedup = 1; + break; + + case 'L': + handler = &ulzma_fmt; + break; + default: usage(); /* Not reached */ @@ -104,17 +151,26 @@ int main(int argc, char **argv) /* Not reached */ } + strcpy(hdr.magic, handler->magic); + + if (en_dedup != 0) { + hdr.magic[CLOOP_OFS_VERSN] = CLOOP_MAJVER_3; + hdr.magic[CLOOP_OFS_COMPR] = + tolower(hdr.magic[CLOOP_OFS_COMPR]); + } + + obuf = handler->f_init(hdr.blksz); + iname = argv[0]; if (oname == NULL) { - asprintf(&oname, "%s%s", iname, DEFAULT_SUFX); + asprintf(&oname, "%s%s", iname, handler->default_sufx); if (oname == NULL) { err(1, "can't allocate memory"); /* Not reached */ } } - obuf = safe_malloc(compressBound(hdr.blksz)); - ibuf = safe_malloc(hdr.blksz); + ibuf = mkuz_safe_malloc(hdr.blksz); signal(SIGHUP, exit); signal(SIGINT, exit); @@ -152,7 +208,7 @@ int main(int argc, char **argv) "of %d, padding data\n", hdr.blksz); hdr.nblocks++; } - toc = safe_malloc((hdr.nblocks + 1) * sizeof(*toc)); + toc = mkuz_safe_malloc((hdr.nblocks + 1) * sizeof(*toc)); fdw = open(oname, O_WRONLY | O_TRUNC | O_CREAT, S_IRWXU | S_IRGRP | S_IXGRP | S_IROTH | S_IXOTH); @@ -177,40 +233,73 @@ int main(int argc, char **argv) "%u, index length %zu bytes\n", sb.st_size, hdr.nblocks, iov[1].iov_len); + last_offset = 0; for(i = 0; i == 0 || ibuf != NULL; i++) { ibuf = readblock(fdr, ibuf, hdr.blksz); if (ibuf != NULL) { - destlen = compressBound(hdr.blksz); - if (compress2(obuf, &destlen, ibuf, hdr.blksz, - Z_BEST_COMPRESSION) != Z_OK) { - errx(1, "can't compress data: compress2() " - "failed"); - /* Not reached */ + if (no_zcomp == 0 && \ + memvcmp(ibuf, '\0', hdr.blksz) != 0) { + /* All zeroes block */ + destlen = 0; + } else { + handler->f_compress(ibuf, &destlen); } - if (verbose != 0) - fprintf(stderr, "cluster #%d, in %u bytes, " - "out %lu bytes\n", i, hdr.blksz, destlen); } else { destlen = DEV_BSIZE - (offset % DEV_BSIZE); memset(obuf, 0, destlen); if (verbose != 0) - fprintf(stderr, "padding data with %lu bytes so " - "that file size is multiple of %d\n", destlen, - DEV_BSIZE); + fprintf(stderr, "padding data with %lu bytes " + "so that file size is multiple of %d\n", + (u_long)destlen, DEV_BSIZE); } - if (write(fdw, obuf, destlen) < 0) { - err(1, "write(%s)", oname); - /* Not reached */ + if (destlen > 0 && en_dedup != 0) { + chit = mkuz_blkcache_regblock(fdw, i, offset, destlen, + obuf); + /* + * There should be at least one non-empty block + * between us and the backref'ed offset, otherwise + * we won't be able to parse that sequence correctly + * as it would be indistinguishible from another + * empty block. + */ + if (chit != NULL && chit->offset == last_offset) { + chit = NULL; + } + } else { + chit = NULL; + } + if (chit != NULL) { + toc[i] = htobe64(chit->offset); + } else { + if (destlen > 0 && write(fdw, obuf, destlen) < 0) { + err(1, "write(%s)", oname); + /* Not reached */ + } + toc[i] = htobe64(offset); + last_offset = offset; + offset += destlen; + } + if (ibuf != NULL && verbose != 0) { + fprintf(stderr, "cluster #%d, in %u bytes, " + "out len=%lu offset=%lu", i, hdr.blksz, + chit == NULL ? (u_long)destlen : 0, + (u_long)be64toh(toc[i])); + if (chit != NULL) { + fprintf(stderr, " (backref'ed to #%d)", + chit->blkno); + } + fprintf(stderr, "\n"); + } - toc[i] = htobe64(offset); - offset += destlen; } close(fdr); if (verbose != 0) fprintf(stderr, "compressed data to %ju bytes, saved %lld " - "bytes, %.2f%% decrease.\n", offset, (long long)(sb.st_size - offset), - 100.0 * (long long)(sb.st_size - offset) / (float)sb.st_size); + "bytes, %.2f%% decrease.\n", offset, + (long long)(sb.st_size - offset), + 100.0 * (long long)(sb.st_size - offset) / + (float)sb.st_size); /* Convert to big endian */ hdr.blksz = htonl(hdr.blksz); @@ -248,12 +337,13 @@ static void usage(void) { - fprintf(stderr, "usage: mkuzip [-v] [-o outfile] [-s cluster_size] infile\n"); + fprintf(stderr, "usage: mkuzip [-vZdL] [-o outfile] [-s cluster_size] " + "infile\n"); exit(1); } -static void * -safe_malloc(size_t size) +void * +mkuz_safe_malloc(size_t size) { void *retval; @@ -272,3 +362,12 @@ cleanup(void) if (cleanfile != NULL) unlink(cleanfile); } + +static int +memvcmp(const void *memory, unsigned char val, size_t size) +{ + const u_char *mm; + + mm = (const u_char *)memory; + return (*mm == val) && memcmp(mm, mm + 1, size - 1) == 0; +} diff --git a/usr.bin/truss/cloudabi.h b/usr.bin/mkuzip/mkuzip.h index abc8c0c..4028b3a 100644 --- a/usr.bin/truss/cloudabi.h +++ b/usr.bin/mkuzip/mkuzip.h @@ -1,5 +1,6 @@ -/*- - * Copyright (c) 2015 Nuxi, https://nuxi.nl/ +/* + * 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 @@ -25,4 +26,4 @@ * $FreeBSD$ */ -long cloudabi_convert_errno(long); +void *mkuz_safe_malloc(size_t); diff --git a/usr.bin/netstat/Makefile.depend b/usr.bin/netstat/Makefile.depend index 2abbfbf..27fa660 100644 --- a/usr.bin/netstat/Makefile.depend +++ b/usr.bin/netstat/Makefile.depend @@ -22,14 +22,4 @@ DIRDEPS = \ .if ${DEP_RELDIR} == ${_DEP_RELDIR} # local dependencies - needed for -jN in clean tree -main.o: nl_defs.h -main.po: nl_defs.h -mroute.o: nl_defs.h -mroute.po: nl_defs.h -netisr.o: nl_defs.h -netisr.po: nl_defs.h -nl_symbols.o: nl_symbols.c -nl_symbols.po: nl_symbols.c -route.o: nl_defs.h -route.po: nl_defs.h .endif diff --git a/usr.bin/top/Makefile.depend b/usr.bin/top/Makefile.depend index accbe52..fafa76b 100644 --- a/usr.bin/top/Makefile.depend +++ b/usr.bin/top/Makefile.depend @@ -20,12 +20,4 @@ DIRDEPS = \ .if ${DEP_RELDIR} == ${_DEP_RELDIR} # local dependencies - needed for -jN in clean tree -commands.o: sigdesc.h -commands.po: sigdesc.h -display.o: top.local.h -display.po: top.local.h -top.o: top.local.h -top.po: top.local.h -username.o: top.local.h -username.po: top.local.h .endif diff --git a/usr.bin/truss/Makefile b/usr.bin/truss/Makefile index b28098c..7ba4392 100644 --- a/usr.bin/truss/Makefile +++ b/usr.bin/truss/Makefile @@ -2,7 +2,7 @@ NO_WERROR= PROG= truss -SRCS= cloudabi.c main.c setup.c syscalls.c +SRCS= main.c setup.c syscalls.c LIBADD= sysdecode diff --git a/usr.bin/truss/aarch64-cloudabi64.c b/usr.bin/truss/aarch64-cloudabi64.c index f2891af..27906ea 100644 --- a/usr.bin/truss/aarch64-cloudabi64.c +++ b/usr.bin/truss/aarch64-cloudabi64.c @@ -31,11 +31,9 @@ __FBSDID("$FreeBSD$"); #include <machine/armreg.h> -#include <errno.h> #include <stdio.h> #include <sysdecode.h> -#include "cloudabi.h" #include "truss.h" static int @@ -74,8 +72,6 @@ aarch64_cloudabi64_fetch_retval(struct trussinfo *trussinfo, long *retval, retval[0] = regs.x[0]; retval[1] = regs.x[1]; *errorp = (regs.spsr & PSR_C) != 0; - if (*errorp) - retval[0] = cloudabi_convert_errno(retval[0]); return (0); } diff --git a/usr.bin/truss/amd64-cloudabi64.c b/usr.bin/truss/amd64-cloudabi64.c index ce8b189..f7d7c1a 100644 --- a/usr.bin/truss/amd64-cloudabi64.c +++ b/usr.bin/truss/amd64-cloudabi64.c @@ -31,11 +31,9 @@ __FBSDID("$FreeBSD$"); #include <machine/psl.h> -#include <errno.h> #include <stdio.h> #include <sysdecode.h> -#include "cloudabi.h" #include "truss.h" static int @@ -83,8 +81,6 @@ amd64_cloudabi64_fetch_retval(struct trussinfo *trussinfo, long *retval, retval[0] = regs.r_rax; retval[1] = regs.r_rdx; *errorp = (regs.r_rflags & PSL_C) != 0; - if (*errorp) - retval[0] = cloudabi_convert_errno(retval[0]); return (0); } diff --git a/usr.bin/truss/amd64-linux32.c b/usr.bin/truss/amd64-linux32.c index 873ef01..279d228 100644 --- a/usr.bin/truss/amd64-linux32.c +++ b/usr.bin/truss/amd64-linux32.c @@ -83,28 +83,12 @@ amd64_linux32_fetch_args(struct trussinfo *trussinfo, u_int narg) return (0); } -/* - * Linux syscalls return negative errno's, we do positive and map them - */ -static const int bsd_to_linux_errno[] = { - -0, -1, -2, -3, -4, -5, -6, -7, -8, -9, - -10, -35, -12, -13, -14, -15, -16, -17, -18, -19, - -20, -21, -22, -23, -24, -25, -26, -27, -28, -29, - -30, -31, -32, -33, -34, -11,-115,-114, -88, -89, - -90, -91, -92, -93, -94, -95, -96, -97, -98, -99, - -100,-101,-102,-103,-104,-105,-106,-107,-108,-109, - -110,-111, -40, -36,-112,-113, -39, -11, -87,-122, - -116, -66, -6, -6, -6, -6, -6, -37, -38, -9, - -6, -}; - static int amd64_linux32_fetch_retval(struct trussinfo *trussinfo, long *retval, int *errorp) { struct reg regs; lwpid_t tid; - size_t i; tid = trussinfo->curthread->tid; if (ptrace(PT_GETREGS, tid, (caddr_t)®s, 0) < 0) { @@ -117,17 +101,6 @@ amd64_linux32_fetch_retval(struct trussinfo *trussinfo, long *retval, *errorp = !!(regs.r_rflags & PSL_C); if (*errorp) retval[0] = (int)retval[0]; - - if (*errorp) { - for (i = 0; i < nitems(bsd_to_linux_errno); i++) { - if (retval[0] == bsd_to_linux_errno[i]) { - retval[0] = i; - return (0); - } - } - - /* XXX: How to handle unknown errors? */ - } return (0); } diff --git a/usr.bin/truss/cloudabi.c b/usr.bin/truss/cloudabi.c deleted file mode 100644 index d426500..0000000 --- a/usr.bin/truss/cloudabi.c +++ /dev/null @@ -1,122 +0,0 @@ -/*- - * Copyright (c) 2015 Nuxi, https://nuxi.nl/ - * - * 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/param.h> - -#include <errno.h> - -#include <compat/cloudabi/cloudabi_syscalldefs.h> - -#include "cloudabi.h" - -long -cloudabi_convert_errno(long error) -{ - static const int table[] = { - [CLOUDABI_E2BIG] = E2BIG, - [CLOUDABI_EACCES] = EACCES, - [CLOUDABI_EADDRINUSE] = EADDRINUSE, - [CLOUDABI_EADDRNOTAVAIL] = EADDRNOTAVAIL, - [CLOUDABI_EAFNOSUPPORT] = EAFNOSUPPORT, - [CLOUDABI_EAGAIN] = EAGAIN, - [CLOUDABI_EALREADY] = EALREADY, - [CLOUDABI_EBADF] = EBADF, - [CLOUDABI_EBADMSG] = EBADMSG, - [CLOUDABI_EBUSY] = EBUSY, - [CLOUDABI_ECANCELED] = ECANCELED, - [CLOUDABI_ECHILD] = ECHILD, - [CLOUDABI_ECONNABORTED] = ECONNABORTED, - [CLOUDABI_ECONNREFUSED] = ECONNREFUSED, - [CLOUDABI_ECONNRESET] = ECONNRESET, - [CLOUDABI_EDEADLK] = EDEADLK, - [CLOUDABI_EDESTADDRREQ] = EDESTADDRREQ, - [CLOUDABI_EDOM] = EDOM, - [CLOUDABI_EDQUOT] = EDQUOT, - [CLOUDABI_EEXIST] = EEXIST, - [CLOUDABI_EFAULT] = EFAULT, - [CLOUDABI_EFBIG] = EFBIG, - [CLOUDABI_EHOSTUNREACH] = EHOSTUNREACH, - [CLOUDABI_EIDRM] = EIDRM, - [CLOUDABI_EILSEQ] = EILSEQ, - [CLOUDABI_EINPROGRESS] = EINPROGRESS, - [CLOUDABI_EINTR] = EINTR, - [CLOUDABI_EINVAL] = EINVAL, - [CLOUDABI_EIO] = EIO, - [CLOUDABI_EISCONN] = EISCONN, - [CLOUDABI_EISDIR] = EISDIR, - [CLOUDABI_ELOOP] = ELOOP, - [CLOUDABI_EMFILE] = EMFILE, - [CLOUDABI_EMLINK] = EMLINK, - [CLOUDABI_EMSGSIZE] = EMSGSIZE, - [CLOUDABI_EMULTIHOP] = EMULTIHOP, - [CLOUDABI_ENAMETOOLONG] = ENAMETOOLONG, - [CLOUDABI_ENETDOWN] = ENETDOWN, - [CLOUDABI_ENETRESET] = ENETRESET, - [CLOUDABI_ENETUNREACH] = ENETUNREACH, - [CLOUDABI_ENFILE] = ENFILE, - [CLOUDABI_ENOBUFS] = ENOBUFS, - [CLOUDABI_ENODEV] = ENODEV, - [CLOUDABI_ENOENT] = ENOENT, - [CLOUDABI_ENOEXEC] = ENOEXEC, - [CLOUDABI_ENOLCK] = ENOLCK, - [CLOUDABI_ENOLINK] = ENOLINK, - [CLOUDABI_ENOMEM] = ENOMEM, - [CLOUDABI_ENOMSG] = ENOMSG, - [CLOUDABI_ENOPROTOOPT] = ENOPROTOOPT, - [CLOUDABI_ENOSPC] = ENOSPC, - [CLOUDABI_ENOSYS] = ENOSYS, - [CLOUDABI_ENOTCONN] = ENOTCONN, - [CLOUDABI_ENOTDIR] = ENOTDIR, - [CLOUDABI_ENOTEMPTY] = ENOTEMPTY, - [CLOUDABI_ENOTRECOVERABLE] = ENOTRECOVERABLE, - [CLOUDABI_ENOTSOCK] = ENOTSOCK, - [CLOUDABI_ENOTSUP] = ENOTSUP, - [CLOUDABI_ENOTTY] = ENOTTY, - [CLOUDABI_ENXIO] = ENXIO, - [CLOUDABI_EOVERFLOW] = EOVERFLOW, - [CLOUDABI_EOWNERDEAD] = EOWNERDEAD, - [CLOUDABI_EPERM] = EPERM, - [CLOUDABI_EPIPE] = EPIPE, - [CLOUDABI_EPROTO] = EPROTO, - [CLOUDABI_EPROTONOSUPPORT] = EPROTONOSUPPORT, - [CLOUDABI_EPROTOTYPE] = EPROTOTYPE, - [CLOUDABI_ERANGE] = ERANGE, - [CLOUDABI_EROFS] = EROFS, - [CLOUDABI_ESPIPE] = ESPIPE, - [CLOUDABI_ESRCH] = ESRCH, - [CLOUDABI_ESTALE] = ESTALE, - [CLOUDABI_ETIMEDOUT] = ETIMEDOUT, - [CLOUDABI_ETXTBSY] = ETXTBSY, - [CLOUDABI_EXDEV] = EXDEV, - [CLOUDABI_ENOTCAPABLE] = ENOTCAPABLE, - }; - - if (error < 0 || error >= nitems(table) || table[error] == 0) - return (error); - return (table[error]); -} diff --git a/usr.bin/truss/extern.h b/usr.bin/truss/extern.h index 708d055..5ce3d3b 100644 --- a/usr.bin/truss/extern.h +++ b/usr.bin/truss/extern.h @@ -31,6 +31,7 @@ * $FreeBSD$ */ +extern int print_line_prefix(struct trussinfo *); extern void setup_and_wait(struct trussinfo *, char **); extern void start_tracing(struct trussinfo *, pid_t); extern void restore_proc(int); diff --git a/usr.bin/truss/i386-linux.c b/usr.bin/truss/i386-linux.c index c5f625d..52232b4 100644 --- a/usr.bin/truss/i386-linux.c +++ b/usr.bin/truss/i386-linux.c @@ -83,27 +83,11 @@ i386_linux_fetch_args(struct trussinfo *trussinfo, u_int narg) return (0); } -/* - * Linux syscalls return negative errno's, we do positive and map them - */ -static const int bsd_to_linux_errno[] = { - -0, -1, -2, -3, -4, -5, -6, -7, -8, -9, - -10, -35, -12, -13, -14, -15, -16, -17, -18, -19, - -20, -21, -22, -23, -24, -25, -26, -27, -28, -29, - -30, -31, -32, -33, -34, -11,-115,-114, -88, -89, - -90, -91, -92, -93, -94, -95, -96, -97, -98, -99, - -100,-101,-102,-103,-104,-105,-106,-107,-108,-109, - -110,-111, -40, -36,-112,-113, -39, -11, -87,-122, - -116, -66, -6, -6, -6, -6, -6, -37, -38, -9, - -6, -}; - static int i386_linux_fetch_retval(struct trussinfo *trussinfo, long *retval, int *errorp) { struct reg regs; lwpid_t tid; - size_t i; tid = trussinfo->curthread->tid; if (ptrace(PT_GETREGS, tid, (caddr_t)®s, 0) < 0) { @@ -114,17 +98,6 @@ i386_linux_fetch_retval(struct trussinfo *trussinfo, long *retval, int *errorp) retval[0] = regs.r_eax; retval[1] = regs.r_edx; *errorp = !!(regs.r_eflags & PSL_C); - - if (*errorp) { - for (i = 0; i < nitems(bsd_to_linux_errno); i++) { - if (retval[0] == bsd_to_linux_errno[i]) { - retval[0] = i; - return (0); - } - } - - /* XXX: How to handle unknown errors? */ - } return (0); } diff --git a/usr.bin/truss/main.c b/usr.bin/truss/main.c index 531d7db..38626fd 100644 --- a/usr.bin/truss/main.c +++ b/usr.bin/truss/main.c @@ -96,7 +96,7 @@ main(int ac, char **av) trussinfo->curthread = NULL; LIST_INIT(&trussinfo->proclist); init_syscalls(); - while ((c = getopt(ac, av, "p:o:facedDs:S")) != -1) { + while ((c = getopt(ac, av, "p:o:facedDs:SH")) != -1) { switch (c) { case 'p': /* specified pid */ pid = atoi(optarg); @@ -132,6 +132,9 @@ main(int ac, char **av) case 'S': /* Don't trace signals */ trussinfo->flags |= NOSIGS; break; + case 'H': + trussinfo->flags |= DISPLAYTIDS; + break; default: usage(); } diff --git a/usr.bin/truss/setup.c b/usr.bin/truss/setup.c index 24126ad..36dd571f 100644 --- a/usr.bin/truss/setup.c +++ b/usr.bin/truss/setup.c @@ -439,26 +439,46 @@ exit_syscall(struct trussinfo *info, struct ptrace_lwpinfo *pl) } } -static void -report_exit(struct trussinfo *info, siginfo_t *si) +int +print_line_prefix(struct trussinfo *info) { struct timespec timediff; + struct threadinfo *t; + int len; - if (info->flags & FOLLOWFORKS) - fprintf(info->outfile, "%5d: ", si->si_pid); - clock_gettime(CLOCK_REALTIME, &info->curthread->after); + len = 0; + t = info->curthread; + if (info->flags & (FOLLOWFORKS | DISPLAYTIDS)) { + if (info->flags & FOLLOWFORKS) + len += fprintf(info->outfile, "%5d", t->proc->pid); + if ((info->flags & (FOLLOWFORKS | DISPLAYTIDS)) == + (FOLLOWFORKS | DISPLAYTIDS)) + len += fprintf(info->outfile, " "); + if (info->flags & DISPLAYTIDS) + len += fprintf(info->outfile, "%6d", t->tid); + len += fprintf(info->outfile, ": "); + } if (info->flags & ABSOLUTETIMESTAMPS) { - timespecsubt(&info->curthread->after, &info->start_time, - &timediff); - fprintf(info->outfile, "%jd.%09ld ", (intmax_t)timediff.tv_sec, - timediff.tv_nsec); + timespecsubt(&t->after, &info->start_time, &timediff); + len += fprintf(info->outfile, "%jd.%09ld ", + (intmax_t)timediff.tv_sec, timediff.tv_nsec); } if (info->flags & RELATIVETIMESTAMPS) { - timespecsubt(&info->curthread->after, &info->curthread->before, - &timediff); - fprintf(info->outfile, "%jd.%09ld ", (intmax_t)timediff.tv_sec, - timediff.tv_nsec); + timespecsubt(&t->after, &t->before, &timediff); + len += fprintf(info->outfile, "%jd.%09ld ", + (intmax_t)timediff.tv_sec, timediff.tv_nsec); } + return (len); +} + +static void +report_exit(struct trussinfo *info, siginfo_t *si) +{ + struct threadinfo *t; + + t = info->curthread; + clock_gettime(CLOCK_REALTIME, &t->after); + print_line_prefix(info); if (si->si_code == CLD_EXITED) fprintf(info->outfile, "process exit, rval = %u\n", si->si_status); @@ -469,48 +489,26 @@ report_exit(struct trussinfo *info, siginfo_t *si) } static void -report_new_child(struct trussinfo *info, pid_t pid) +report_new_child(struct trussinfo *info) { - struct timespec timediff; + struct threadinfo *t; - clock_gettime(CLOCK_REALTIME, &info->curthread->after); - assert(info->flags & FOLLOWFORKS); - fprintf(info->outfile, "%5d: ", pid); - if (info->flags & ABSOLUTETIMESTAMPS) { - timespecsubt(&info->curthread->after, &info->start_time, - &timediff); - fprintf(info->outfile, "%jd.%09ld ", (intmax_t)timediff.tv_sec, - timediff.tv_nsec); - } - if (info->flags & RELATIVETIMESTAMPS) { - timediff.tv_sec = 0; - timediff.tv_nsec = 0; - fprintf(info->outfile, "%jd.%09ld ", (intmax_t)timediff.tv_sec, - timediff.tv_nsec); - } + t = info->curthread; + clock_gettime(CLOCK_REALTIME, &t->after); + t->before = t->after; + print_line_prefix(info); fprintf(info->outfile, "<new process>\n"); } static void report_signal(struct trussinfo *info, siginfo_t *si) { - struct timespec timediff; + struct threadinfo *t; char *signame; - if (info->flags & FOLLOWFORKS) - fprintf(info->outfile, "%5d: ", si->si_pid); - if (info->flags & ABSOLUTETIMESTAMPS) { - timespecsubt(&info->curthread->after, &info->start_time, - &timediff); - fprintf(info->outfile, "%jd.%09ld ", (intmax_t)timediff.tv_sec, - timediff.tv_nsec); - } - if (info->flags & RELATIVETIMESTAMPS) { - timespecsubt(&info->curthread->after, &info->curthread->before, - &timediff); - fprintf(info->outfile, "%jd.%09ld ", (intmax_t)timediff.tv_sec, - timediff.tv_nsec); - } + t = info->curthread; + clock_gettime(CLOCK_REALTIME, &t->after); + print_line_prefix(info); signame = strsig(si->si_status); fprintf(info->outfile, "SIGNAL %u (%s)\n", si->si_status, signame == NULL ? "?" : signame); @@ -572,7 +570,7 @@ eventloop(struct trussinfo *info) pending_signal = 0; } else if (pl.pl_flags & PL_FLAG_CHILD) { if ((info->flags & COUNTONLY) == 0) - report_new_child(info, si.si_pid); + report_new_child(info); pending_signal = 0; } else { if ((info->flags & NOSIGS) == 0) diff --git a/usr.bin/truss/syscalls.c b/usr.bin/truss/syscalls.c index b013390..b3a4c42 100644 --- a/usr.bin/truss/syscalls.c +++ b/usr.bin/truss/syscalls.c @@ -2005,38 +2005,18 @@ print_arg(struct syscall_args *sc, unsigned long *args, long *retval, void print_syscall(struct trussinfo *trussinfo) { - struct timespec timediff; struct threadinfo *t; const char *name; char **s_args; int i, len, nargs; - len = 0; t = trussinfo->curthread; - if (trussinfo->flags & FOLLOWFORKS) - len += fprintf(trussinfo->outfile, "%5d: ", - t->proc->pid); name = t->cs.name; nargs = t->cs.nargs; s_args = t->cs.s_args; - if (name != NULL && (strcmp(name, "execve") == 0 || - strcmp(name, "exit") == 0)) { - clock_gettime(CLOCK_REALTIME, &t->after); - } - - if (trussinfo->flags & ABSOLUTETIMESTAMPS) { - timespecsubt(&t->after, &trussinfo->start_time, &timediff); - len += fprintf(trussinfo->outfile, "%jd.%09ld ", - (intmax_t)timediff.tv_sec, timediff.tv_nsec); - } - - if (trussinfo->flags & RELATIVETIMESTAMPS) { - timespecsubt(&t->after, &t->before, &timediff); - len += fprintf(trussinfo->outfile, "%jd.%09ld ", - (intmax_t)timediff.tv_sec, timediff.tv_nsec); - } + len = print_line_prefix(trussinfo); len += fprintf(trussinfo->outfile, "%s(", name); for (i = 0; i < nargs; i++) { @@ -2059,11 +2039,11 @@ print_syscall_ret(struct trussinfo *trussinfo, int errorp, long *retval) struct timespec timediff; struct threadinfo *t; struct syscall *sc; + int error; t = trussinfo->curthread; sc = t->cs.sc; if (trussinfo->flags & COUNTONLY) { - clock_gettime(CLOCK_REALTIME, &t->after); timespecsubt(&t->after, &t->before, &timediff); timespecadd(&sc->time, &timediff, &sc->time); sc->ncalls++; @@ -2074,9 +2054,12 @@ print_syscall_ret(struct trussinfo *trussinfo, int errorp, long *retval) print_syscall(trussinfo); fflush(trussinfo->outfile); - if (errorp) + if (errorp) { + error = sysdecode_abi_to_freebsd_errno(t->proc->abi->abi, + retval[0]); fprintf(trussinfo->outfile, " ERR#%ld '%s'\n", retval[0], - strerror(retval[0])); + error == INT_MAX ? "Unknown error" : strerror(error)); + } #ifndef __LP64__ else if (sc->ret_type == 2) { off_t off; diff --git a/usr.bin/truss/truss.1 b/usr.bin/truss/truss.1 index fb02cb4..0246fa9 100644 --- a/usr.bin/truss/truss.1 +++ b/usr.bin/truss/truss.1 @@ -1,6 +1,6 @@ .\" $FreeBSD$ .\" -.Dd October 9, 2015 +.Dd February 23, 2016 .Dt TRUSS 1 .Os .Sh NAME @@ -8,12 +8,12 @@ .Nd trace system calls .Sh SYNOPSIS .Nm -.Op Fl facedDS +.Op Fl facedDHS .Op Fl o Ar file .Op Fl s Ar strsize .Fl p Ar pid .Nm -.Op Fl facedDS +.Op Fl facedDHS .Op Fl o Ar file .Op Fl s Ar strsize .Ar command Op Ar args @@ -32,6 +32,10 @@ Trace descendants of the original traced process created by .Xr fork 2 , .Xr vfork 2 , etc. +To distinguish events between processes, +the process ID +.Pq PID +of the process is included in the output of each event. .It Fl a Show the argument strings that are passed in each .Xr execve 2 @@ -52,6 +56,8 @@ since the trace was started. .It Fl D Include timestamps in the output showing the time elapsed since the last recorded event. +.It Fl H +Include the thread ID of in the output of each event. .It Fl S Do not display information about signals received by the process. (Normally, diff --git a/usr.bin/truss/truss.h b/usr.bin/truss/truss.h index 5ef2444..582ab0b 100644 --- a/usr.bin/truss/truss.h +++ b/usr.bin/truss/truss.h @@ -35,6 +35,7 @@ #define EXECVEARGS 0x00000010 #define EXECVEENVS 0x00000020 #define COUNTONLY 0x00000040 +#define DISPLAYTIDS 0x00000080 struct procinfo; struct trussinfo; diff --git a/usr.bin/vacation/Makefile.depend b/usr.bin/vacation/Makefile.depend index 1636b07..b0af42f 100644 --- a/usr.bin/vacation/Makefile.depend +++ b/usr.bin/vacation/Makefile.depend @@ -18,6 +18,4 @@ DIRDEPS = \ .if ${DEP_RELDIR} == ${_DEP_RELDIR} # local dependencies - needed for -jN in clean tree -vacation.o: sm_os.h -vacation.po: sm_os.h .endif diff --git a/usr.bin/xlint/lint1/Makefile.depend b/usr.bin/xlint/lint1/Makefile.depend index 22a5556..dab7995 100644 --- a/usr.bin/xlint/lint1/Makefile.depend +++ b/usr.bin/xlint/lint1/Makefile.depend @@ -18,14 +18,4 @@ DIRDEPS = \ .if ${DEP_RELDIR} == ${_DEP_RELDIR} # local dependencies - needed for -jN in clean tree -cgram.o: cgram.c -cgram.po: cgram.c -func.o: cgram.h -func.po: cgram.h -scan.o: cgram.h -scan.o: scan.c -scan.po: cgram.h -scan.po: scan.c -tree.o: cgram.h -tree.po: cgram.h .endif |