2
* Author: Colin King <colin.king@canonical.com>
4
* Copyright (C) 2012 Canonical, Ltd.
6
* This program is free software; you can redistribute it and/or
7
* modify it under the terms of the GNU General Public License
8
* as published by the Free Software Foundation; either version 2
9
* of the License, or (at your option) any later version.
11
* This program is distributed in the hope that it will be useful,
12
* but WITHOUT ANY WARRANTY; without even the implied warranty of
13
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14
* GNU General Public License for more details.
16
* You should have received a copy of the GNU General Public License
17
* along with this program; if not, write to the Free Software
18
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
24
#include <sys/types.h>
32
#define TEST_PASSED (0)
33
#define TEST_FAILED (1)
34
#define TEST_ERROR (2)
36
#define BUFF_SZ (65536)
38
int test_exercise(char *filename, off_t size)
41
int ret = TEST_FAILED;
42
unsigned char buff[BUFF_SZ];
45
if ((fd = open(filename, O_RDWR | O_CREAT, 0600)) < 0) {
46
fprintf(stderr, "Failed to open %s: %s\n", filename, strerror(errno));
50
memset(buff, 0, sizeof(buff));
55
rc = write(fd, buff, (size > BUFF_SZ) ? BUFF_SZ : size);
63
/* If we got here, we didn't get ENOSPC, so we've failed */
71
void sighandler(int dummy)
76
int main(int argc, char **argv)
81
fprintf(stderr, "Syntax: %s filename size_in_K\n", argv[0]);
82
fprintf(stderr, "\tsize must be bigger than available space on the file system\n");
88
fprintf(stderr, "size should be > 0\n");
92
signal(SIGINT, sighandler);
93
exit(test_exercise(argv[1], len * 1024));