summaryrefslogtreecommitdiffstats
path: root/tests/basic/posix/zero-fill-enospace.c
blob: b1aaa57c9ca0c12ca4d19094ebbeba7673b84811 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
#include <stdio.h>
#include <glusterfs/api/glfs.h>
#include <glusterfs/api/glfs-handles.h>

int
main (int argc, char *argv[])
{
        glfs_t    *fs = NULL;
        glfs_fd_t *fd = NULL;
        int        ret = 1;
        int        size = 0;

        if (argc != 6) {
                fprintf (stderr, "Syntax: %s <host> <volname> <file-path> <log-file> <size>\n", argv[0]);
                return 1;
        }

        fs = glfs_new (argv[2]);
        if (!fs) {
                fprintf (stderr, "glfs_new: returned NULL\n");
                return 1;
        }

        ret = glfs_set_volfile_server (fs, "tcp", argv[1], 24007);
        if (ret != 0) {
                fprintf (stderr, "glfs_set_volfile_server: retuned %d\n", ret);
                goto out;
        }
        ret = glfs_set_logging (fs, argv[4], 7);
        if (ret != 0) {
                fprintf (stderr, "glfs_set_logging: returned %d\n", ret);
                goto out;
        }
        ret = glfs_init (fs);
        if (ret != 0) {
                fprintf (stderr, "glfs_init: returned %d\n", ret);
                goto out;
        }

        fd = glfs_open (fs, argv[3], O_RDWR);
        if (fd == NULL) {
                fprintf (stderr, "glfs_open: returned NULL\n");
                goto out;
        }

        size = atoi(argv[5]);
        if (size < 0) {
                fprintf (stderr, "Wrong size %s", argv[5]);
                goto out;
        }
        ret = glfs_zerofill (fd, 0, atoi(argv[5]));
        if (ret <= 0) {
                fprintf (stderr, "glfs_zerofill: returned %d\n", ret);
                goto out;
        }

        ret = 0;

out:
        if (fd)
                glfs_close(fd);
        glfs_fini (fs);
        return ret;
}