generic/60[78]: ensure the initial DAX file flag state before test
[xfstests-dev.git] / dmapi / src / suite2 / src / mmap_cp.c
1 // SPDX-License-Identifier: GPL-2.0
2 /*
3  * Copyright (c) 2000-2001 Silicon Graphics, Inc.
4  * All Rights Reserved.
5  */
6 /*
7  *      mmap_fill
8  * 
9  *      use memory mapping to fill a filesystem! :)
10  */
11 #include <stdio.h>
12 #include <sys/types.h>
13 #include <sys/mman.h>
14 #include <sys/fcntl.h>
15 #include <sys/stat.h>
16 #include <strings.h>
17 #include <errno.h>
18
19
20 char * progname;
21 int     fd;                     /* file descriptor */
22 addr_t  ptr;                    /* mapped pointers */
23 long long  junk[512];
24
25 main(int argc, char * argv[])
26 {
27   printf("Sizeof junk = %d \n", junk);
28   exit(0);
29
30   if ((progname = strrchr(argv[0], '/')) == NULL)
31     progname = argv[0];
32   else
33     progname++;
34   
35   if (argc < 2) {
36     fprintf(stderr,"Usage: %s filename\n", progname);
37     exit(1);
38   }
39   
40   fd = open(argv[1], O_RDWR|O_CREAT, 0644);
41   if (fd < 0) {
42     fprintf(stderr,"%s: cannot open %s\n", progname, argv[1]);
43     perror(argv[1]);
44     exit(3);
45   }
46   
47   ptr = mmap(NULL, len, PROT_WRITE, MAP_SHARED|MAP_AUTOGROW , fd, 0);
48   if (ptr == MAP_FAILED) {
49     fprintf(stderr,"%s: cannot mmap %s\n", progname, argv[1]);
50     perror(argv[1]);
51     exit(3);
52   }
53   
54   while (1) {
55     bcopy(junk, ptr, size_of(junk));
56     ptr+=size_of(junk);
57   }
58   printf("%s complete.\n", progname);
59   return 0;
60 }