t_full.c revision 1.11
11.11Smartin/*	$NetBSD: t_full.c,v 1.11 2019/07/16 17:29:17 martin Exp $	*/
21.1Spooka
31.1Spooka/*-
41.1Spooka * Copyright (c) 2010 The NetBSD Foundation, Inc.
51.1Spooka * All rights reserved.
61.1Spooka *
71.1Spooka * Redistribution and use in source and binary forms, with or without
81.1Spooka * modification, are permitted provided that the following conditions
91.1Spooka * are met:
101.1Spooka * 1. Redistributions of source code must retain the above copyright
111.1Spooka *    notice, this list of conditions and the following disclaimer.
121.1Spooka * 2. Redistributions in binary form must reproduce the above copyright
131.1Spooka *    notice, this list of conditions and the following disclaimer in the
141.1Spooka *    documentation and/or other materials provided with the distribution.
151.1Spooka *
161.1Spooka * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
171.1Spooka * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
181.1Spooka * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
191.1Spooka * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
201.1Spooka * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
211.1Spooka * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
221.1Spooka * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
231.1Spooka * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
241.1Spooka * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
251.1Spooka * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
261.1Spooka * POSSIBILITY OF SUCH DAMAGE.
271.1Spooka */
281.1Spooka
291.1Spooka#include <sys/stat.h>
301.1Spooka#include <sys/statvfs.h>
311.1Spooka
321.1Spooka#include <atf-c.h>
331.1Spooka#include <fcntl.h>
341.1Spooka#include <libgen.h>
351.1Spooka#include <stdlib.h>
361.1Spooka#include <unistd.h>
371.1Spooka
381.1Spooka#include <rump/rump_syscalls.h>
391.1Spooka#include <rump/rump.h>
401.1Spooka
411.1Spooka#include "../common/h_fsmacros.h"
421.9Schristos#include "h_macros.h"
431.1Spooka
441.1Spooka/*
451.1Spooka * Write this much over the image size.  This is to force an NFS commit,
461.1Spooka * since we might just stuff data into the cache and miss the problem.
471.1Spooka */
481.1Spooka#define NFSBONUS (1<<16)
491.1Spooka
501.1Spookastatic void
511.1Spookafillfs(const atf_tc_t *tc, const char *mp)
521.1Spooka{
531.1Spooka	char buf[8192];
541.1Spooka	size_t written;
551.1Spooka	ssize_t n = 0; /* xxxgcc */
561.1Spooka	size_t bonus;
571.1Spooka	int fd, i = 0;
581.1Spooka
591.10Shannken	if (FSTYPE_P2K_FFS(tc) || FSTYPE_PUFFS(tc) || FSTYPE_RUMPFS(tc) ||
601.10Shannken	    FSTYPE_ZFS(tc)) {
611.4Spooka		atf_tc_skip("fs does not support explicit block allocation "
621.4Spooka		    "(GOP_ALLOC)");
631.1Spooka	}
641.1Spooka
651.1Spooka	bonus = 0;
661.1Spooka	if (FSTYPE_NFS(tc))
671.1Spooka		bonus = NFSBONUS;
681.1Spooka
691.1Spooka	if (rump_sys_chdir(mp) == -1)
701.1Spooka		atf_tc_fail_errno("chdir mountpoint");
711.11Smartin	fd = rump_sys_open("afile", O_CREAT | O_RDWR, 0600);
721.1Spooka	if (fd == -1)
731.1Spooka		atf_tc_fail_errno("create file");
741.1Spooka
751.1Spooka	for (written = 0; written < FSTEST_IMGSIZE + bonus; written +=n) {
761.1Spooka		memset(buf, i++, sizeof(buf)); /* known garbage */
771.1Spooka		n = rump_sys_write(fd, buf, sizeof(buf));
781.1Spooka		if (n == -1)
791.1Spooka			break;
801.1Spooka	}
811.1Spooka	if (n == -1) {
821.1Spooka		if (errno != ENOSPC)
831.1Spooka			atf_tc_fail_errno("write");
841.1Spooka	} else {
851.1Spooka		atf_tc_fail("filled file system over size limit");
861.1Spooka	}
871.1Spooka
881.1Spooka	rump_sys_close(fd);
891.1Spooka	rump_sys_chdir("/");
901.1Spooka}
911.1Spooka
921.1SpookaATF_TC_FSAPPLY(fillfs, "fills file system, expects ENOSPC");
931.1Spooka
941.1SpookaATF_TP_ADD_TCS(tp)
951.1Spooka{
961.1Spooka
971.1Spooka	ATF_TP_FSAPPLY(fillfs);
981.1Spooka
991.1Spooka	return atf_no_error();
1001.1Spooka}
101