t_io.c revision 1.2 1 /* $NetBSD: t_io.c,v 1.2 2010/11/11 16:03:55 pooka Exp $ */
2
3 /*-
4 * Copyright (c) 2010 The NetBSD Foundation, Inc.
5 * All rights reserved.
6 *
7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions
9 * are met:
10 * 1. Redistributions of source code must retain the above copyright
11 * notice, this list of conditions and the following disclaimer.
12 * 2. Redistributions in binary form must reproduce the above copyright
13 * notice, this list of conditions and the following disclaimer in the
14 * documentation and/or other materials provided with the distribution.
15 *
16 * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
17 * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
18 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
19 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
20 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
21 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
22 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
23 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
24 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
25 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
26 * POSSIBILITY OF SUCH DAMAGE.
27 */
28
29 #include <sys/stat.h>
30 #include <sys/statvfs.h>
31
32 #include <atf-c.h>
33 #include <fcntl.h>
34 #include <libgen.h>
35 #include <stdlib.h>
36 #include <unistd.h>
37
38 #include <rump/rump_syscalls.h>
39 #include <rump/rump.h>
40
41 #include "../common/h_fsmacros.h"
42 #include "../../h_macros.h"
43
44 static void
45 holywrite(const atf_tc_t *tc, const char *mp)
46 {
47 char buf[1024];
48 char *b2, *b3;
49 size_t therange = getpagesize()+1;
50 int fd;
51
52 RL(rump_sys_chdir(mp));
53
54 RL(fd = rump_sys_open("file", O_RDWR|O_CREAT|O_TRUNC, 0666));
55
56 memset(buf, 'A', sizeof(buf));
57 RL(rump_sys_pwrite(fd, buf, 1, getpagesize()));
58
59 memset(buf, 'B', sizeof(buf));
60 RL(rump_sys_pwrite(fd, buf, 2, 0xfff));
61
62 REQUIRE_LIBC(b2 = malloc(2 * getpagesize()), NULL);
63 REQUIRE_LIBC(b3 = malloc(2 * getpagesize()), NULL);
64
65 RL(rump_sys_pread(fd, b2, therange, 0));
66
67 memset(b3, 0, therange);
68 memset(b3 + getpagesize() - 1, 'B', 2);
69
70 ATF_REQUIRE_EQ(memcmp(b2, b3, therange), 0);
71
72 rump_sys_close(fd);
73 rump_sys_chdir("/");
74 }
75
76 ATF_TC_FSAPPLY(holywrite, "create a sparse file and fill hole");
77
78 ATF_TP_ADD_TCS(tp)
79 {
80
81 ATF_TP_FSAPPLY(holywrite);
82
83 return atf_no_error();
84 }
85