btrfs: add test for multiple fsync with adjacent preallocated extents
[xfstests-dev.git] / ltp / growfiles.c
index b322d494db8587e27cff86ce759917c48d18cd7e..7ac44aba0bede0f5e0ddf7ee8c47c46b0fd47bf3 100644 (file)
@@ -1,19 +1,7 @@
+// SPDX-License-Identifier: GPL-2.0
 /*
  * Copyright (c) 2000 Silicon Graphics, Inc.
  * All Rights Reserved.
- *
- * This program is free software; you can redistribute it and/or
- * modify it under the terms of the GNU General Public License as
- * published by the Free Software Foundation.
- *
- * This program is distributed in the hope that it would be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write the Free Software Foundation,
- * Inc.,  51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
  */
 /*
  * This program will grow a list of files.
 #include "dataascii.h"
 #include "random_range.h"
 #include "databin.h"
-
-
-extern char *openflags2symbols();
-
-extern int parse_open_flags();
-extern int background();
-extern int forker();
-extern int datapidgen();
-extern void databingen();
-extern int datapidchk();
-extern int databinchk();
-extern int file_lock();
-
-int file_size();
-int check_write();
-int shrinkfile();
-int check_file();
-int growfile();
+#include "open_flags.h"
+#include "forker.h"
+#include "file_lock.h"
+
+extern int datapidgen(int pid, unsigned char *buffer, int bsize, int offset);
+extern void databingen(int mode, unsigned char *buffer, int bsize, int offset);
+extern int datapidchk(int pid, char *buffer, int bsize, int offset, char **errmsg);
+extern int databinchk(int mode, char *buffer, int bsize, int offset, char **errmsg);
+
+int file_size(int fd);
+int check_write(int fd, int cf_inter, char *filename, int mode);
+int shrinkfile(int fd, char *filename, int trunc_incr, int trunc_inter, int just_trunc);
+int check_file(int fd, int cf_inter, char *filename, int no_file_check);
+int growfile(int fd, char *file, int grow_incr, unsigned char *buf);
 int cleanup();
 int handle_error();
-int lkfile();
+int lkfile(int fd, int operation, int lklevel);
 void usage();
 void help();
-void prt_examples();
+void prt_examples(FILE *stream);
 int set_sig();
 void sig_handler();
 static void notify_others();
-#ifndef NO_XFS
-int pre_alloc();
-#endif
+int pre_alloc(char *file, int fd, int size);
 
 
 #define NEWIO  1       /* Use the tlibio.c functions */
@@ -293,9 +275,7 @@ int tmp;
 char chr;
 int ret;
 int pre_alloc_space = 0;
-#ifndef NO_XFS
 int total_grow_value = 0;      /* used in pre-allocations */
-#endif
 int backgrnd = 1;              /* return control to user */
 struct stat statbuf;
 int time_iterval = -1;
@@ -564,13 +544,9 @@ extern int Forker_npids;   /* num of forked pid, defined in forker.c */
 
 
                case 'p' :      /* pre allocate space */
-#ifdef NO_XFS
                        printf("%s%s: --p is illegal option on this system\n",
                                Progname, TagName);
                        exit(1);
-#else
-                       pre_alloc_space++;
-#endif
                        break;
 
                case 'P':
@@ -806,7 +782,7 @@ extern int Forker_npids;    /* num of forked pid, defined in forker.c */
                        break;
 
                case 'W':
-                       sprintf( TagName, "(%.39s)", optarg );
+                       sprintf( TagName, "(%.37s)", optarg );
                        break;
 
                case 'y':
@@ -1147,7 +1123,6 @@ no whole file checking will be performed!\n", Progname, TagName, (int)getpid());
                        Progname, Pid, num_files);
        }
 
-#ifndef NO_XFS
        if ( pre_alloc_space ) {
                if ( iterations == 0 ) {
                    fprintf(stderr, "%s%s: %d %s/%d: can NOT pre-alloc and grow forever\n",
@@ -1170,7 +1145,6 @@ no whole file checking will be performed!\n", Progname, TagName, (int)getpid());
                        total_grow_value=bytes_to_consume;
                }
        }
-#endif
 
        /*
         * If delaying between iterations, get amount time to
@@ -1233,7 +1207,7 @@ no whole file checking will be performed!\n", Progname, TagName, (int)getpid());
                if ( Debug > 3 ) {
                    printf("%s: %d DEBUG3 %s/%d: %d Open filename = %s, open flags = %#o %s\n",
                        Progname, Pid, __FILE__, __LINE__, Iter_cnt, filename, ret, 
-                       openflags2symbols(ret, ",", NULL));
+                       openflags2symbols(ret, ",", 0));
                } else if ( Debug > 2 ) {
                    printf("%s: %d DEBUG3 %s/%d: %d filename = %s, open flags = %#o\n",
                        Progname, Pid, __FILE__, __LINE__, Iter_cnt, filename, ret);
@@ -1254,7 +1228,6 @@ no whole file checking will be performed!\n", Progname, TagName, (int)getpid());
 
                lkfile(fd, LOCK_EX, LKLVL1);   /* lock if lockfile is LKLVL1 */
 
-#ifndef NO_XFS
                /*
                 * preallocation is only done once, if specified.
                 */
@@ -1272,7 +1245,6 @@ no whole file checking will be performed!\n", Progname, TagName, (int)getpid());
                        Iter_cnt=0;     /* reset outside loop to restart from one */
                        continue;
                }
-#endif
 
                /*
                 * grow file by desired amount.
@@ -1281,7 +1253,7 @@ no whole file checking will be performed!\n", Progname, TagName, (int)getpid());
                 * if we are dealing with a FIFO file.
                 */
 
-               if (growfile(fd, filename, grow_incr, Buffer) != 0 ) {
+               if (growfile(fd, filename, grow_incr, (unsigned char *)Buffer) != 0 ) {
                        handle_error();
                        lkfile(fd, LOCK_UN, LKLVL1);   /* release lock */
                        close(fd);
@@ -1348,7 +1320,6 @@ no whole file checking will be performed!\n", Progname, TagName, (int)getpid());
                    }
                }
            }
-#ifndef NO_XFS
            /*
             * if Iter_cnt == 0, then we pre allocated space to all files
             * and we are starting outside loop over.  Set pre_alloc_space
@@ -1357,9 +1328,6 @@ no whole file checking will be performed!\n", Progname, TagName, (int)getpid());
            if ( Iter_cnt == 0 ) {
                pre_alloc_space=0;
            }
-#endif
-
-
        }   /* end iteration for loop */
 
 
@@ -1409,7 +1377,7 @@ set_sig()
 #ifdef SIGRESTART
                case SIGRESTART:
 #endif /* SIGRESTART */
-                case SIGCLD:
+                case SIGCHLD:
                     break;
 
                 default:
@@ -1475,11 +1443,12 @@ notify_others()
        send_signals=1; /* only send signals once */
 
         for (ind=0; ind< Forker_npids; ind++) {
-           if ( Forker_pids[ind] != Pid )
+           if ( Forker_pids[ind] != Pid ) {
                if ( Debug > 1 )
                    printf("%s%s: %d DEBUG2 %s/%d: Sending SIGUSR2 to pid %d\n",
                        Progname, TagName, Pid, __FILE__, __LINE__, Forker_pids[ind]);
                kill(Forker_pids[ind], SIGUSR2);
+           }
         }
     }
 
@@ -2279,7 +2248,7 @@ int mode;       /* write mode */
        if ( Debug > 0 )
            printf("%s%s: %d DEBUG1 %s/%d: **fd:%d, lk:%d, offset:%d, sz:%d open flags:%#o %s\n",
                Progname, TagName, Pid, __FILE__, __LINE__, fd, lockfile, 
-               Woffset, Grow_incr, Fileinfo.openflags, openflags2symbols(Fileinfo.openflags, ",", NULL));
+               Woffset, Grow_incr, Fileinfo.openflags, openflags2symbols(Fileinfo.openflags, ",", 0));
 
        fflush(stderr);
        return 1;
@@ -2594,7 +2563,6 @@ lkfile(int fd, int operation, int lklevel)
    return 0;
 }
 
-#ifndef NO_XFS
 /***********************************************************************
  *
  ***********************************************************************/
@@ -2605,7 +2573,6 @@ int fd;
 int size;
 {
 
-#ifndef NO_XFS
 #ifdef XFS_IOC_RESVSP
     struct xfs_flock64 f;
 
@@ -2634,9 +2601,7 @@ int size;
                         __FILE__, __LINE__, errno, strerror(errno));
                return -1;
        }
-#endif
 #endif
 
        return 0;
 }
-#endif