Whamcloud - gitweb
LU-12616 obclass: fix MDS start/stop race
[fs/lustre-release.git] / lustre / tests / ll_sparseness_write.c
1 /*
2  * GPL HEADER START
3  *
4  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5  *
6  * This program is free software; you can redistribute it and/or modify
7  * it under the terms of the GNU General Public License version 2 only,
8  * as published by the Free Software Foundation.
9  *
10  * This program is distributed in the hope that it will be useful, but
11  * WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
13  * General Public License version 2 for more details (a copy is included
14  * in the LICENSE file that accompanied this code).
15  *
16  * You should have received a copy of the GNU General Public License
17  * version 2 along with this program; If not, see
18  * http://www.gnu.org/licenses/gpl-2.0.html
19  *
20  * GPL HEADER END
21  */
22 /*
23  * Copyright (c) 2003, 2010, Oracle and/or its affiliates. All rights reserved.
24  * Use is subject to license terms.
25  */
26 /*
27  * This file is part of Lustre, http://www.lustre.org/
28  * Lustre is a trademark of Sun Microsystems, Inc.
29  */
30
31 #ifndef _GNU_SOURCE
32 #define _GNU_SOURCE
33 #endif
34 #include <stdio.h>
35 #include <stdlib.h>
36 #include <unistd.h>
37 #include <string.h>
38 #include <errno.h>
39 #include <sys/types.h>
40 #include <sys/wait.h>
41 #include <sys/stat.h>
42 #include <fcntl.h>
43
44 #define BUFSIZE (1024*1024)   
45
46 /* Function: pwrite character '+' to <filename> at <offset> (man pwrite)
47  * Return:   0 success
48  *           1 failure */
49 int main(int argc, char**argv)
50 {
51         int p_size;
52         unsigned int offset;
53         char *filename;
54         int fd;
55         char buf[] = "+++";
56         char *end;
57
58         if(argc != 3) {
59                 fprintf(stderr, "Usage: %s <filename> <offset>(KB)\n", argv[0]);
60                 exit(1);
61         }
62
63         filename = argv[1];
64         offset = strtoul(argv[2], &end, 10);
65         if (*end) {
66                 fprintf(stderr, "<offset> parameter should be integer\n");
67                 exit(1);
68         }
69
70         fd = open(filename, O_CREAT|O_RDWR, 0644);
71         if (fd == -1) {
72                 fprintf(stderr, "Opening %s fails (%s)\n", 
73                         filename, strerror(errno));
74                 return 1;
75         }
76
77         /* write the character '+' at offset */
78         p_size = pwrite(fd, buf, 1, offset);
79         if (p_size != 1) {
80                 fprintf(stderr, "pwrite %s fails (%s)\n", 
81                         filename, strerror(errno));
82                 close(fd);
83                 return 1;
84         }
85                 
86         close(fd);
87         return 0;
88 }