Whamcloud - gitweb
b=3031
[fs/lustre-release.git] / lustre / tests / ll_sparseness_write.c
1 /* -*- mode: c; c-basic-offset: 8; indent-tabs-mode: nil; -*-
2  * vim:expandtab:shiftwidth=8:tabstop=8:
3  */
4 #define _GNU_SOURCE
5 #include <stdio.h>
6 #include <stdlib.h>
7 #include <unistd.h>
8 #include <string.h>
9 #include <errno.h>
10 #include <sys/types.h>
11 #include <sys/wait.h>
12 #include <sys/stat.h>
13 #include <fcntl.h>
14
15 #define BUFSIZE (1024*1024)   
16
17 /* Function: pwrite character '+' to <filename> at <offset> (man pwrite)
18  * Return:   0 success
19  *           1 failure */
20 int main(int argc, char**argv)
21 {
22         int p_size;
23         unsigned int offset;
24         char *filename;
25         int fd;
26         char buf[] = "+++";
27         char *end;
28
29         if(argc != 3) {
30                 fprintf(stderr, "Usage: %s <filename> <offset>(KB)\n", argv[0]);
31                 exit(1);
32         }
33
34         filename = argv[1];
35         offset = strtoul(argv[2], &end, 10);
36         if (*end) {
37                 fprintf(stderr, "<offset> parameter should be integer\n");
38                 exit(1);
39         }
40
41         fd = open(filename, O_CREAT|O_RDWR, 0644);
42         if (fd == -1) {
43                 fprintf(stderr, "Opening %s fails (%s)\n", 
44                         filename, strerror(errno));
45                 return 1;
46         }
47
48         /* write the character '+' at offset */
49         p_size = pwrite(fd, buf, 1, offset);
50         if (p_size != 1) {
51                 fprintf(stderr, "pwrite %s fails (%s)\n", 
52                         filename, strerror(errno));
53                 close(fd);
54                 return 1;
55         }
56                 
57         close(fd);
58         return 0;
59 }