The Design and Implementation of the FreeBSD Operating System, Second Edition
Now available: The Design and Implementation of the FreeBSD Operating System (Second Edition)


[ source navigation ] [ diff markup ] [ identifier search ] [ freetext search ] [ file search ] [ list types ] [ track identifier ]

FreeBSD/Linux Kernel Cross Reference
sys/contrib/openzfs/tests/zfs-tests/cmd/mkfiles.c

Version: -  FREEBSD  -  FREEBSD-13-STABLE  -  FREEBSD-13-0  -  FREEBSD-12-STABLE  -  FREEBSD-12-0  -  FREEBSD-11-STABLE  -  FREEBSD-11-0  -  FREEBSD-10-STABLE  -  FREEBSD-10-0  -  FREEBSD-9-STABLE  -  FREEBSD-9-0  -  FREEBSD-8-STABLE  -  FREEBSD-8-0  -  FREEBSD-7-STABLE  -  FREEBSD-7-0  -  FREEBSD-6-STABLE  -  FREEBSD-6-0  -  FREEBSD-5-STABLE  -  FREEBSD-5-0  -  FREEBSD-4-STABLE  -  FREEBSD-3-STABLE  -  FREEBSD22  -  l41  -  OPENBSD  -  linux-2.6  -  MK84  -  PLAN9  -  xnu-8792 
SearchContext: -  none  -  3  -  10 

    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.
    6  *
    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.
   10  */
   11 
   12 /*
   13  * Copyright (c) 2016 by Delphix. All rights reserved.
   14  */
   15 
   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>
   23 
   24 static void
   25 usage(const char *msg, int exit_value)
   26 {
   27         (void) fprintf(stderr, "usage: mkfiles basename max_file [min_file]\n"
   28             "%s\n", msg);
   29         exit(exit_value);
   30 }
   31 
   32 int
   33 main(int argc, char **argv)
   34 {
   35         unsigned int numfiles = 0;
   36         unsigned int first_file = 0;
   37         unsigned int i;
   38         char buf[MAXPATHLEN];
   39 
   40         if (argc < 3 || argc > 4)
   41                 usage("Invalid number of arguments", 1);
   42 
   43         if (sscanf(argv[2], "%u", &numfiles) != 1)
   44                 usage("Invalid maximum file", 2);
   45 
   46         if (argc == 4 && sscanf(argv[3], "%u", &first_file) != 1)
   47                 usage("Invalid first file", 3);
   48 
   49         for (i = first_file; i < first_file + numfiles; i++) {
   50                 int fd;
   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,
   54                             strerror(errno));
   55                         return (4);
   56                 } else if (fchown(fd, getuid(), getgid()) < 0) {
   57                         (void) fprintf(stderr, "Failed to chown %s %s\n", buf,
   58                             strerror(errno));
   59                         return (5);
   60                 }
   61                 (void) close(fd);
   62         }
   63         return (0);
   64 }

Cache object: bb07e408cff0cdd97f9d93a85597d6b3


[ source navigation ] [ diff markup ] [ identifier search ] [ freetext search ] [ file search ] [ list types ] [ track identifier ]


This page is part of the FreeBSD/Linux Linux Kernel Cross-Reference, and was automatically generated using a modified version of the LXR engine.