1 // SPDX-License-Identifier: CDDL-1.0 2 /* 3 * CDDL HEADER START 4 * 5 * This file and its contents are supplied under the terms of the 6 * Common Development and Distribution License ("CDDL"), version 1.0. 7 * You may only use this file in accordance with the terms of version 8 * 1.0 of the CDDL. 9 * 10 * A full copy of the text of the CDDL should have accompanied this 11 * source. A copy of the CDDL is also available via the Internet at 12 * http://www.illumos.org/license/CDDL. 13 * 14 * CDDL HEADER END 15 */ 16 17 /* 18 * Copyright (c) 2020 by Delphix. All rights reserved. 19 * Copyright (c) 2020 by Datto Inc. All rights reserved. 20 */ 21 #include <sys/types.h> 22 #include <sys/stat.h> 23 #include <fcntl.h> 24 #include <ctype.h> 25 #include <stdio.h> 26 #include <stdlib.h> 27 #include <string.h> 28 #include <unistd.h> 29 #include <libintl.h> 30 #include <stddef.h> 31 #include <libzfs.h> 32 #include "zstream.h" 33 34 void 35 zstream_usage(void) 36 { 37 (void) fprintf(stderr, 38 "usage: zstream command args ...\n" 39 "Available commands are:\n" 40 "\n" 41 "\tzstream dump [-vCd] FILE\n" 42 "\t... | zstream dump [-vCd]\n" 43 "\n" 44 "\tzstream decompress [-v] [OBJECT,OFFSET[,TYPE]] ...\n" 45 "\n" 46 "\tzstream recompress [ -l level] TYPE\n" 47 "\n" 48 "\tzstream token resume_token\n" 49 "\n" 50 "\tzstream redup [-v] FILE | ...\n"); 51 exit(1); 52 } 53 54 int 55 main(int argc, char *argv[]) 56 { 57 char *basename = strrchr(argv[0], '/'); 58 basename = basename ? (basename + 1) : argv[0]; 59 if (argc >= 1 && strcmp(basename, "zstreamdump") == 0) 60 return (zstream_do_dump(argc, argv)); 61 62 if (argc < 2) 63 zstream_usage(); 64 65 char *subcommand = argv[1]; 66 67 if (strcmp(subcommand, "dump") == 0) { 68 return (zstream_do_dump(argc - 1, argv + 1)); 69 } else if (strcmp(subcommand, "decompress") == 0) { 70 return (zstream_do_decompress(argc - 1, argv + 1)); 71 } else if (strcmp(subcommand, "recompress") == 0) { 72 return (zstream_do_recompress(argc - 1, argv + 1)); 73 } else if (strcmp(subcommand, "token") == 0) { 74 return (zstream_do_token(argc - 1, argv + 1)); 75 } else if (strcmp(subcommand, "redup") == 0) { 76 return (zstream_do_redup(argc - 1, argv + 1)); 77 } else { 78 zstream_usage(); 79 } 80 } 81