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
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.
22 #include <sys/param.h>
25 usage(const char *msg
, int exit_value
)
27 (void) fprintf(stderr
, "usage: mkfiles basename max_file [min_file]\n"
33 main(int argc
, char **argv
)
35 unsigned int numfiles
= 0;
36 unsigned int first_file
= 0;
40 if (argc
< 3 || argc
> 4)
41 usage("Invalid number of arguments", 1);
43 if (sscanf(argv
[2], "%u", &numfiles
) != 1)
44 usage("Invalid maximum file", 2);
46 if (argc
== 4 && sscanf(argv
[3], "%u", &first_file
) != 1)
47 usage("Invalid first file", 3);
49 for (i
= first_file
; i
< first_file
+ numfiles
; i
++) {
51 (void) snprintf(buf
, MAXPATHLEN
, "%s%u", argv
[1], i
);
52 if ((fd
= open(buf
, O_CREAT
| O_EXCL
, O_RDWR
)) == -1) {
53 (void) fprintf(stderr
, "Failed to create %s %s\n", buf
,
56 } else if (fchown(fd
, getuid(), getgid()) < 0) {
57 (void) fprintf(stderr
, "Failed to chown %s %s\n", buf
,