Files
mirror_zfs/tests/zfs-tests/cmd/mkfiles.c
T

66 lines
1.6 KiB
C
Raw Normal View History

2025-01-04 11:04:27 +11:00
// SPDX-License-Identifier: CDDL-1.0
2015-07-01 15:23:09 -07:00
/*
* This file and its contents are supplied under the terms of the
* Common Development and Distribution License ("CDDL"), version 1.0.
* You may only use this file in accordance with the terms of version
* 1.0 of the CDDL.
*
* A full copy of the text of the CDDL should have accompanied this
* source. A copy of the CDDL is also available via the Internet at
* http://www.illumos.org/license/CDDL.
*/
/*
* Copyright (c) 2016 by Delphix. All rights reserved.
*/
#include <stdio.h>
#include <stdlib.h>
#include <fcntl.h>
#include <string.h>
#include <errno.h>
#include <unistd.h>
#include <sys/param.h>
static void
2022-04-19 20:38:30 +02:00
usage(const char *msg, int exit_value)
2015-07-01 15:23:09 -07:00
{
2022-04-19 20:38:30 +02:00
(void) fprintf(stderr, "usage: mkfiles basename max_file [min_file]\n"
"%s\n", msg);
2015-07-01 15:23:09 -07:00
exit(exit_value);
}
int
main(int argc, char **argv)
{
unsigned int numfiles = 0;
unsigned int first_file = 0;
unsigned int i;
char buf[MAXPATHLEN];
if (argc < 3 || argc > 4)
2022-04-19 20:38:30 +02:00
usage("Invalid number of arguments", 1);
2015-07-01 15:23:09 -07:00
if (sscanf(argv[2], "%u", &numfiles) != 1)
2022-04-19 20:38:30 +02:00
usage("Invalid maximum file", 2);
2015-07-01 15:23:09 -07:00
if (argc == 4 && sscanf(argv[3], "%u", &first_file) != 1)
2022-04-19 20:38:30 +02:00
usage("Invalid first file", 3);
2015-07-01 15:23:09 -07:00
for (i = first_file; i < first_file + numfiles; i++) {
2015-07-01 15:23:09 -07:00
int fd;
(void) snprintf(buf, MAXPATHLEN, "%s%u", argv[1], i);
if ((fd = open(buf, O_CREAT | O_EXCL, O_RDWR)) == -1) {
(void) fprintf(stderr, "Failed to create %s %s\n", buf,
strerror(errno));
2022-04-19 20:38:30 +02:00
return (4);
2019-12-18 12:29:43 -08:00
} else if (fchown(fd, getuid(), getgid()) < 0) {
(void) fprintf(stderr, "Failed to chown %s %s\n", buf,
strerror(errno));
2022-04-19 20:38:30 +02:00
return (5);
2015-07-01 15:23:09 -07:00
}
(void) close(fd);
}
return (0);
}