1*653f037eSmartin /* $NetBSD: t_full.c,v 1.11 2019/07/16 17:29:17 martin Exp $ */
24439733dSpooka
34439733dSpooka /*-
44439733dSpooka * Copyright (c) 2010 The NetBSD Foundation, Inc.
54439733dSpooka * All rights reserved.
64439733dSpooka *
74439733dSpooka * Redistribution and use in source and binary forms, with or without
84439733dSpooka * modification, are permitted provided that the following conditions
94439733dSpooka * are met:
104439733dSpooka * 1. Redistributions of source code must retain the above copyright
114439733dSpooka * notice, this list of conditions and the following disclaimer.
124439733dSpooka * 2. Redistributions in binary form must reproduce the above copyright
134439733dSpooka * notice, this list of conditions and the following disclaimer in the
144439733dSpooka * documentation and/or other materials provided with the distribution.
154439733dSpooka *
164439733dSpooka * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
174439733dSpooka * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
184439733dSpooka * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
194439733dSpooka * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
204439733dSpooka * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
214439733dSpooka * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
224439733dSpooka * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
234439733dSpooka * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
244439733dSpooka * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
254439733dSpooka * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
264439733dSpooka * POSSIBILITY OF SUCH DAMAGE.
274439733dSpooka */
284439733dSpooka
294439733dSpooka #include <sys/stat.h>
304439733dSpooka #include <sys/statvfs.h>
314439733dSpooka
324439733dSpooka #include <atf-c.h>
334439733dSpooka #include <fcntl.h>
344439733dSpooka #include <libgen.h>
354439733dSpooka #include <stdlib.h>
364439733dSpooka #include <unistd.h>
374439733dSpooka
384439733dSpooka #include <rump/rump_syscalls.h>
394439733dSpooka #include <rump/rump.h>
404439733dSpooka
414439733dSpooka #include "../common/h_fsmacros.h"
42c54cb811Schristos #include "h_macros.h"
434439733dSpooka
444439733dSpooka /*
454439733dSpooka * Write this much over the image size. This is to force an NFS commit,
464439733dSpooka * since we might just stuff data into the cache and miss the problem.
474439733dSpooka */
484439733dSpooka #define NFSBONUS (1<<16)
494439733dSpooka
504439733dSpooka static void
fillfs(const atf_tc_t * tc,const char * mp)514439733dSpooka fillfs(const atf_tc_t *tc, const char *mp)
524439733dSpooka {
534439733dSpooka char buf[8192];
544439733dSpooka size_t written;
554439733dSpooka ssize_t n = 0; /* xxxgcc */
564439733dSpooka size_t bonus;
574439733dSpooka int fd, i = 0;
584439733dSpooka
591c0c955eShannken if (FSTYPE_P2K_FFS(tc) || FSTYPE_PUFFS(tc) || FSTYPE_RUMPFS(tc) ||
601c0c955eShannken FSTYPE_ZFS(tc)) {
6188b6bdf1Spooka atf_tc_skip("fs does not support explicit block allocation "
6288b6bdf1Spooka "(GOP_ALLOC)");
634439733dSpooka }
644439733dSpooka
654439733dSpooka bonus = 0;
664439733dSpooka if (FSTYPE_NFS(tc))
674439733dSpooka bonus = NFSBONUS;
684439733dSpooka
694439733dSpooka if (rump_sys_chdir(mp) == -1)
704439733dSpooka atf_tc_fail_errno("chdir mountpoint");
71*653f037eSmartin fd = rump_sys_open("afile", O_CREAT | O_RDWR, 0600);
724439733dSpooka if (fd == -1)
734439733dSpooka atf_tc_fail_errno("create file");
744439733dSpooka
754439733dSpooka for (written = 0; written < FSTEST_IMGSIZE + bonus; written +=n) {
764439733dSpooka memset(buf, i++, sizeof(buf)); /* known garbage */
774439733dSpooka n = rump_sys_write(fd, buf, sizeof(buf));
784439733dSpooka if (n == -1)
794439733dSpooka break;
804439733dSpooka }
814439733dSpooka if (n == -1) {
824439733dSpooka if (errno != ENOSPC)
834439733dSpooka atf_tc_fail_errno("write");
844439733dSpooka } else {
854439733dSpooka atf_tc_fail("filled file system over size limit");
864439733dSpooka }
874439733dSpooka
884439733dSpooka rump_sys_close(fd);
894439733dSpooka rump_sys_chdir("/");
904439733dSpooka }
914439733dSpooka
924439733dSpooka ATF_TC_FSAPPLY(fillfs, "fills file system, expects ENOSPC");
934439733dSpooka
ATF_TP_ADD_TCS(tp)944439733dSpooka ATF_TP_ADD_TCS(tp)
954439733dSpooka {
964439733dSpooka
974439733dSpooka ATF_TP_FSAPPLY(fillfs);
984439733dSpooka
994439733dSpooka return atf_no_error();
1004439733dSpooka }
101