6370 ZFS send fails to transmit some holes
[unleashed.git] / usr / src / test / zfs-tests / cmd / mkfiles / mkfiles.c
blob58c7d5f5097ff3e9d041ff66848b25e2133e1ca9
1 /*
2 * This file and its contents are supplied under the terms of the
3 * Common Development and Distribution License ("CDDL"), version 1.0.
4 * You may only use this file in accordance with the terms of version
5 * 1.0 of the CDDL.
7 * A full copy of the text of the CDDL should have accompanied this
8 * source. A copy of the CDDL is also available via the Internet at
9 * http://www.illumos.org/license/CDDL.
13 * Copyright (c) 2016 by Delphix. All rights reserved.
16 #include <stdio.h>
17 #include <stdlib.h>
18 #include <fcntl.h>
19 #include <string.h>
20 #include <errno.h>
21 #include <unistd.h>
22 #include <sys/param.h>
24 #define MAX_INT_LENGTH 10
26 static void
27 usage(char *msg, int exit_value)
29 (void) fprintf(stderr, "mkfiles basename max_file [min_file]\n");
30 (void) fprintf(stderr, "%s\n", msg);
31 exit(exit_value);
34 int
35 main(int argc, char **argv)
37 unsigned int numfiles = 0;
38 unsigned int first_file = 0;
39 if (argc < 3 || argc > 4)
40 usage("Invalid number of arguments", -1);
42 if (sscanf(argv[2], "%u", &numfiles) != 1)
43 usage("Invalid maximum file", -2);
45 if (argc == 4 && sscanf(argv[3], "%u", &first_file) != 1)
46 usage("Invalid first file", -3);
48 if (numfiles < first_file)
49 usage("First file larger than last file", -3);
51 char buf[MAXPATHLEN];
52 for (unsigned int i = first_file; i <= numfiles; i++) {
53 int fd;
54 (void) snprintf(buf, MAXPATHLEN, "%s%u", argv[1], i);
55 if ((fd = open(buf, O_CREAT | O_EXCL, O_RDWR)) == -1) {
56 (void) fprintf(stderr, "Failed to create %s %s\n", buf,
57 strerror(errno));
58 return (-4);
60 (void) close(fd);
62 return (0);