Print this page
    
10076 make usr/src/test smatch clean
    
      
        | Split | 
	Close | 
      
      | Expand all | 
      | Collapse all | 
    
    
          --- old/usr/src/test/zfs-tests/cmd/randfree_file/randfree_file.c
          +++ new/usr/src/test/zfs-tests/cmd/randfree_file/randfree_file.c
   1    1  /*
   2    2   * CDDL HEADER START
   3    3   *
   4    4   * The contents of this file are subject to the terms of the
   5    5   * Common Development and Distribution License (the "License").
   6    6   * You may not use this file except in compliance with the License.
   7    7   *
   8    8   * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
   9    9   * or http://www.opensolaris.org/os/licensing.
  10   10   * See the License for the specific language governing permissions
  11   11   * and limitations under the License.
  12   12   *
  13   13   * When distributing Covered Code, include this CDDL HEADER in each
  14   14   * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
  15   15   * If applicable, add the following below this CDDL HEADER, with the
  16   16   * fields enclosed by brackets "[]" replaced with your own identifying
  17   17   * information: Portions Copyright [yyyy] [name of copyright owner]
  18   18   *
  19   19   * CDDL HEADER END
  20   20   */
  
    | 
      ↓ open down ↓ | 
    20 lines elided | 
    
      ↑ open up ↑ | 
  
  21   21  
  22   22  /*
  23   23   * Copyright 2007 Sun Microsystems, Inc.  All rights reserved.
  24   24   * Use is subject to license terms.
  25   25   */
  26   26  
  27   27  /*
  28   28   * Copyright (c) 2012 by Delphix. All rights reserved.
  29   29   */
  30   30  
       31 +/*
       32 + * Copyright (c) 2018, Joyent, Inc.
       33 + */
       34 +
  31   35  #include "../file_common.h"
  32   36  
  33   37  /*
  34   38   * Create a file with assigned size and then free the specified
  35   39   * section of the file
  36   40   */
  37   41  
  38   42  static void usage(char *progname);
  39   43  
  40   44  static void
  41   45  usage(char *progname)
  42   46  {
  43   47          (void) fprintf(stderr,
  44   48              "usage: %s [-l filesize] [-s start-offset]"
  45   49              "[-n section-len] filename\n", progname);
  46   50          exit(1);
  47   51  }
  48   52  
  49   53  int
  50   54  main(int argc, char *argv[])
  51   55  {
  52   56          char *filename = NULL;
  53   57          char *buf;
  54   58          size_t filesize = 0;
  55   59          off_t start_off = 0;
  56   60          off_t off_len = 0;
  57   61          int  fd, ch;
  58   62          struct flock fl;
  59   63          mode_t mode = S_IRUSR | S_IWUSR | S_IRGRP | S_IROTH;
  60   64  
  61   65          while ((ch = getopt(argc, argv, "l:s:n:")) != EOF) {
  62   66                  switch (ch) {
  63   67                  case 'l':
  64   68                          filesize = atoll(optarg);
  65   69                          break;
  66   70                  case 's':
  67   71                          start_off = atoll(optarg);
  68   72                          break;
  69   73                  case 'n':
  70   74                          off_len = atoll(optarg);
  71   75                          break;
  72   76                  default:
  73   77                          usage(argv[0]);
  74   78                          break;
  75   79                  }
  76   80          }
  
    | 
      ↓ open down ↓ | 
    36 lines elided | 
    
      ↑ open up ↑ | 
  
  77   81  
  78   82          if (optind == argc - 1)
  79   83                  filename = argv[optind];
  80   84          else
  81   85                  usage(argv[0]);
  82   86  
  83   87          buf = (char *)malloc(filesize);
  84   88  
  85   89          if ((fd = open(filename, O_RDWR | O_CREAT | O_TRUNC, mode)) < 0) {
  86   90                  perror("open");
       91 +                free(buf);
  87   92                  return (1);
  88   93          }
  89   94          if (write(fd, buf, filesize) < filesize) {
  90   95                  perror("write");
       96 +                free(buf);
  91   97                  return (1);
  92   98          }
  93   99          fl.l_whence = SEEK_SET;
  94  100          fl.l_start = start_off;
  95  101          fl.l_len = off_len;
  96  102          if (fcntl(fd, F_FREESP, &fl) != 0) {
  97  103                  perror("fcntl");
      104 +                free(buf);
  98  105                  return (1);
  99  106          }
 100  107  
 101  108          free(buf);
 102  109          return (0);
 103  110  }
    
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX