1 /* $NetBSD: t_ro.c,v 1.5 2011/02/22 21:23:19 yamt Exp $ */
4 * Copyright (c) 2010 The NetBSD Foundation, Inc.
7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions
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.
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.
30 #include <sys/statvfs.h>
38 #include <rump/rump_syscalls.h>
39 #include <rump/rump.h>
41 #include "../common/h_fsmacros.h"
42 #include "../../h_macros.h"
44 #define AFILE "testfile"
45 #define ADIR "testdir"
46 #define AFIFO "testfifo"
47 #define ASYMLINK "testsymlink"
48 #define ALINK "testlink"
49 #define FUNTEXT "this is some non-humppa text"
50 #define FUNSIZE (sizeof(FUNTEXT)-1)
53 nullgen(const atf_tc_t
*tc
, const char *mp
)
60 filegen(const atf_tc_t
*tc
, const char *mp
)
65 RL(fd
= rump_sys_open(AFILE
, O_CREAT
| O_RDWR
, 0777));
66 ATF_REQUIRE_EQ(rump_sys_write(fd
, FUNTEXT
, FUNSIZE
), FUNSIZE
);
67 RL(rump_sys_close(fd
));
78 create(const atf_tc_t
*tc
, const char *mp
)
82 ATF_REQUIRE_ERRNO(EROFS
, rump_sys_open(AFILE
, O_CREAT
|O_RDONLY
) == -1);
87 rmfile(const atf_tc_t
*tc
, const char *mp
)
91 ATF_REQUIRE_ERRNO(EROFS
, rump_sys_unlink(AFILE
) == -1);
96 fileio(const atf_tc_t
*tc
, const char *mp
)
102 if (FSTYPE_NFSRO(tc
))
108 RL(fd
= rump_sys_open(AFILE
, O_RDONLY
));
109 ATF_REQUIRE_EQ(rump_sys_read(fd
, buf
, FUNSIZE
), FUNSIZE
);
111 ATF_REQUIRE_STREQ(buf
, FUNTEXT
);
112 RL(rump_sys_close(fd
));
114 ATF_REQUIRE_ERRNO(expected
, rump_sys_open(AFILE
, O_WRONLY
) == -1);
115 ATF_REQUIRE_ERRNO(expected
, rump_sys_open(AFILE
, O_RDWR
) == -1);
120 attrs(const atf_tc_t
*tc
, const char *mp
)
122 struct timeval sometvs
[2];
128 RL(rump_sys_stat(AFILE
, &sb
));
130 ATF_REQUIRE_ERRNO(EROFS
, rump_sys_chmod(AFILE
, 0775) == -1);
131 if (!FSTYPE_MSDOS(tc
))
132 ATF_REQUIRE_ERRNO(EROFS
, rump_sys_chown(AFILE
, 1, 1) == -1);
133 ATF_REQUIRE_ERRNO(EROFS
, rump_sys_utimes(AFILE
, sometvs
) == -1);
135 RL(fd
= rump_sys_open(AFILE
, O_RDONLY
));
136 ATF_REQUIRE_ERRNO(EROFS
, rump_sys_fchmod(fd
, 0775) == -1);
137 if (!FSTYPE_MSDOS(tc
))
138 ATF_REQUIRE_ERRNO(EROFS
, rump_sys_fchown(fd
, 1, 1) == -1);
139 ATF_REQUIRE_ERRNO(EROFS
, rump_sys_futimes(fd
, sometvs
) == -1);
140 RL(rump_sys_close(fd
));
146 createdir(const atf_tc_t
*tc
, const char *mp
)
150 ATF_REQUIRE_ERRNO(EROFS
, rump_sys_mkdir(ADIR
, 0775) == -1);
155 createfifo(const atf_tc_t
*tc
, const char *mp
)
159 ATF_REQUIRE_ERRNO(EROFS
, rump_sys_mkfifo(AFIFO
, 0775) == -1);
164 createsymlink(const atf_tc_t
*tc
, const char *mp
)
168 ATF_REQUIRE_ERRNO(EROFS
, rump_sys_symlink("hoge", ASYMLINK
) == -1);
173 createlink(const atf_tc_t
*tc
, const char *mp
)
177 ATF_REQUIRE_ERRNO(EROFS
, rump_sys_link(AFILE
, ALINK
) == -1);
181 ATF_TC_FSAPPLY_RO(create
, "create file on r/o mount", nullgen
);
182 ATF_TC_FSAPPLY_RO(rmfile
, "remove file from r/o mount", filegen
);
183 ATF_TC_FSAPPLY_RO(fileio
, "can read a file but not write it", filegen
);
184 ATF_TC_FSAPPLY_RO(attrs
, "can query but not change attributes", filegen
);
185 ATF_TC_FSAPPLY_RO(createdir
, "create directory on r/o mount", nullgen
);
186 ATF_TC_FSAPPLY_RO(createfifo
, "create fifo on r/o mount", nullgen
);
187 ATF_TC_FSAPPLY_RO(createsymlink
, "create symlink on r/o mount", nullgen
);
188 ATF_TC_FSAPPLY_RO(createlink
, "create hardlink on r/o mount", filegen
);
193 ATF_TP_FSAPPLY_RO(create
);
194 ATF_TP_FSAPPLY_RO(rmfile
);
195 ATF_TP_FSAPPLY_RO(fileio
);
196 ATF_TP_FSAPPLY_RO(attrs
);
197 ATF_TP_FSAPPLY_RO(createdir
);
198 ATF_TP_FSAPPLY_RO(createfifo
);
199 ATF_TP_FSAPPLY_RO(createsymlink
);
200 ATF_TP_FSAPPLY_RO(createlink
);
202 return atf_no_error();