Print this page
15291 zfs-tests errno flaws exposed by 15220


   7  *
   8  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
   9  * or http://www.opensolaris.org/os/licensing.
  10  * See the License for the specific language governing permissions
  11  * and limitations under the License.
  12  *
  13  * When distributing Covered Code, include this CDDL HEADER in each
  14  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
  15  * If applicable, add the following below this CDDL HEADER, with the
  16  * fields enclosed by brackets "[]" replaced with your own identifying
  17  * information: Portions Copyright [yyyy] [name of copyright owner]
  18  *
  19  * CDDL HEADER END
  20  */
  21 
  22 /*
  23  * Copyright 2007 Sun Microsystems, Inc.  All rights reserved.
  24  * Use is subject to license terms.
  25  */
  26 




  27 #include "../file_common.h"
  28 #include <libgen.h>
  29 
  30 static unsigned char bigbuffer[BIGBUFFERSIZE];
  31 
  32 /*
  33  * Writes (or appends) a given value to a file repeatedly.
  34  * See header file for defaults.
  35  */
  36 
  37 static void usage(void);
  38 
  39 int
  40 main(int argc, char **argv)
  41 {
  42         int             bigfd;
  43         int             c;
  44         int             oflag = 0;
  45         int             err = 0;
  46         int             k;
  47         long            i;
  48         int64_t         good_writes = 0;
  49         uchar_t         nxtfillchar;
  50         /*
  51          * Default Parameters
  52          */
  53         int             write_count = BIGFILESIZE;
  54         uchar_t         fillchar = DATA;
  55         int             block_size = BLOCKSZ;
  56         char            *filename = NULL;
  57         char            *operation = NULL;
  58         offset_t        noffset, offset = 0;
  59         int             verbose = 0;
  60         int             rsync = 0;
  61         int             wsync = 0;

  62 
  63         /*
  64          * Process Arguments
  65          */
  66         while ((c = getopt(argc, argv, "b:c:d:s:f:o:vwr")) != -1) {
  67                 switch (c) {
  68                         case 'b':
  69                                 block_size = atoi(optarg);
  70                                 break;
  71                         case 'c':
  72                                 write_count = atoi(optarg);
  73                                 break;
  74                         case 'd':
  75                                 fillchar = atoi(optarg);
  76                                 break;
  77                         case 's':
  78                                 offset = atoll(optarg);
  79                                 break;
  80                         case 'f':
  81                                 filename = optarg;


 149                 oflag = (O_RDWR|O_APPEND);
 150         } else {
 151                 (void) printf("valid operations are <create|append> not '%s'\n",
 152                     operation);
 153                 usage();
 154         }
 155 
 156         if (rsync) {
 157                 oflag = oflag | O_RSYNC;
 158         }
 159 
 160         if (wsync) {
 161                 oflag = oflag | O_SYNC;
 162         }
 163 
 164         /*
 165          * Given an operation (create/overwrite/append), open the file
 166          * accordingly and perform a write of the appropriate type.
 167          */
 168         if ((bigfd = open(filename, oflag, 0666)) == -1) {

 169                 (void) printf("open %s: failed [%s]%d. Aborting!\n", filename,
 170                     strerror(errno), errno);
 171                 exit(errno);
 172         }
 173         noffset = llseek(bigfd, offset, SEEK_SET);
 174         if (noffset != offset) {

 175                 (void) printf("llseek %s (%lld/%lld) failed [%s]%d.Aborting!\n",
 176                     filename, offset, noffset, strerror(errno), errno);
 177                 exit(errno);
 178         }
 179 
 180         if (verbose) {
 181                 (void) printf("%s: block_size = %d, write_count = %d, "
 182                     "offset = %lld, data = %s%d\n", filename, block_size,
 183                     write_count, offset,
 184                     (fillchar == 0) ? "0->" : "",
 185                     (fillchar == 0) ? DATA_RANGE : fillchar);
 186         }
 187 
 188         for (i = 0; i < write_count; i++) {
 189                 ssize_t n;
 190 
 191                 if ((n = write(bigfd, &bigbuffer, block_size)) == -1) {

 192                         (void) printf("write failed (%ld), good_writes = %lld, "
 193                             "error: %s[%d]\n", (long)n, good_writes,
 194                             strerror(errno),
 195                             errno);
 196                         exit(errno);
 197                 }
 198                 good_writes++;
 199         }
 200 
 201         if (verbose) {
 202                 (void) printf("Success: good_writes = %lld (%lld)\n",
 203                     good_writes, (good_writes * block_size));
 204         }
 205 
 206         return (0);
 207 }
 208 
 209 static void
 210 usage(void)
 211 {
 212         char *base = (char *)"file_write";
 213         char *exec = (char *)getexecname();
 214 
 215         if (exec != NULL)
 216                 exec = strdup(exec);


   7  *
   8  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
   9  * or http://www.opensolaris.org/os/licensing.
  10  * See the License for the specific language governing permissions
  11  * and limitations under the License.
  12  *
  13  * When distributing Covered Code, include this CDDL HEADER in each
  14  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
  15  * If applicable, add the following below this CDDL HEADER, with the
  16  * fields enclosed by brackets "[]" replaced with your own identifying
  17  * information: Portions Copyright [yyyy] [name of copyright owner]
  18  *
  19  * CDDL HEADER END
  20  */
  21 
  22 /*
  23  * Copyright 2007 Sun Microsystems, Inc.  All rights reserved.
  24  * Use is subject to license terms.
  25  */
  26 
  27 /*
  28  * Copyright 2022 MNX Cloud, Inc.
  29  */
  30 
  31 #include "../file_common.h"
  32 #include <libgen.h>
  33 
  34 static unsigned char bigbuffer[BIGBUFFERSIZE];
  35 
  36 /*
  37  * Writes (or appends) a given value to a file repeatedly.
  38  * See header file for defaults.
  39  */
  40 
  41 static void usage(void);
  42 
  43 int
  44 main(int argc, char **argv)
  45 {
  46         int             bigfd;
  47         int             c;
  48         int             oflag = 0;
  49         int             err = 0;
  50         int             k;
  51         long            i;
  52         int64_t         good_writes = 0;
  53         uchar_t         nxtfillchar;
  54         /*
  55          * Default Parameters
  56          */
  57         int             write_count = BIGFILESIZE;
  58         uchar_t         fillchar = DATA;
  59         int             block_size = BLOCKSZ;
  60         char            *filename = NULL;
  61         char            *operation = NULL;
  62         offset_t        noffset, offset = 0;
  63         int             verbose = 0;
  64         int             rsync = 0;
  65         int             wsync = 0;
  66         int             exitcode;
  67 
  68         /*
  69          * Process Arguments
  70          */
  71         while ((c = getopt(argc, argv, "b:c:d:s:f:o:vwr")) != -1) {
  72                 switch (c) {
  73                         case 'b':
  74                                 block_size = atoi(optarg);
  75                                 break;
  76                         case 'c':
  77                                 write_count = atoi(optarg);
  78                                 break;
  79                         case 'd':
  80                                 fillchar = atoi(optarg);
  81                                 break;
  82                         case 's':
  83                                 offset = atoll(optarg);
  84                                 break;
  85                         case 'f':
  86                                 filename = optarg;


 154                 oflag = (O_RDWR|O_APPEND);
 155         } else {
 156                 (void) printf("valid operations are <create|append> not '%s'\n",
 157                     operation);
 158                 usage();
 159         }
 160 
 161         if (rsync) {
 162                 oflag = oflag | O_RSYNC;
 163         }
 164 
 165         if (wsync) {
 166                 oflag = oflag | O_SYNC;
 167         }
 168 
 169         /*
 170          * Given an operation (create/overwrite/append), open the file
 171          * accordingly and perform a write of the appropriate type.
 172          */
 173         if ((bigfd = open(filename, oflag, 0666)) == -1) {
 174                 exitcode = errno;
 175                 (void) printf("open %s: failed [%s]%d. Aborting!\n", filename,
 176                     strerror(errno), errno);
 177                 exit(exitcode);
 178         }
 179         noffset = llseek(bigfd, offset, SEEK_SET);
 180         if (noffset != offset) {
 181                 exitcode = errno;
 182                 (void) printf("llseek %s (%lld/%lld) failed [%s]%d.Aborting!\n",
 183                     filename, offset, noffset, strerror(errno), errno);
 184                 exit(exitcode);
 185         }
 186 
 187         if (verbose) {
 188                 (void) printf("%s: block_size = %d, write_count = %d, "
 189                     "offset = %lld, data = %s%d\n", filename, block_size,
 190                     write_count, offset,
 191                     (fillchar == 0) ? "0->" : "",
 192                     (fillchar == 0) ? DATA_RANGE : fillchar);
 193         }
 194 
 195         for (i = 0; i < write_count; i++) {
 196                 ssize_t n;
 197 
 198                 if ((n = write(bigfd, &bigbuffer, block_size)) == -1) {
 199                         exitcode = errno;
 200                         (void) printf("write failed (%ld), good_writes = %lld, "
 201                             "error: %s[%d]\n", (long)n, good_writes,
 202                             strerror(errno),
 203                             errno);
 204                         exit(exitcode);
 205                 }
 206                 good_writes++;
 207         }
 208 
 209         if (verbose) {
 210                 (void) printf("Success: good_writes = %lld (%lld)\n",
 211                     good_writes, (good_writes * block_size));
 212         }
 213 
 214         return (0);
 215 }
 216 
 217 static void
 218 usage(void)
 219 {
 220         char *base = (char *)"file_write";
 221         char *exec = (char *)getexecname();
 222 
 223         if (exec != NULL)
 224                 exec = strdup(exec);