t_full.c revision 1.4
11.4Spooka/* $NetBSD: t_full.c,v 1.4 2010/11/11 17:44:44 pooka 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.1Spooka#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.4Spooka if (FSTYPE_PUFFS(tc) || FSTYPE_RUMPFS(tc)) { 601.4Spooka atf_tc_skip("fs does not support explicit block allocation " 611.4Spooka "(GOP_ALLOC)"); 621.1Spooka } 631.1Spooka 641.1Spooka bonus = 0; 651.1Spooka if (FSTYPE_NFS(tc)) 661.1Spooka bonus = NFSBONUS; 671.1Spooka 681.1Spooka if (rump_sys_chdir(mp) == -1) 691.1Spooka atf_tc_fail_errno("chdir mountpoint"); 701.1Spooka fd = rump_sys_open("afile", O_CREAT | O_RDWR); 711.1Spooka if (fd == -1) 721.1Spooka atf_tc_fail_errno("create file"); 731.1Spooka 741.1Spooka for (written = 0; written < FSTEST_IMGSIZE + bonus; written +=n) { 751.1Spooka memset(buf, i++, sizeof(buf)); /* known garbage */ 761.1Spooka n = rump_sys_write(fd, buf, sizeof(buf)); 771.1Spooka if (n == -1) 781.1Spooka break; 791.1Spooka } 801.1Spooka if (n == -1) { 811.1Spooka if (errno != ENOSPC) 821.1Spooka atf_tc_fail_errno("write"); 831.1Spooka } else { 841.1Spooka atf_tc_fail("filled file system over size limit"); 851.1Spooka } 861.1Spooka 871.1Spooka rump_sys_close(fd); 881.1Spooka rump_sys_chdir("/"); 891.1Spooka} 901.1Spooka 911.1SpookaATF_TC_FSAPPLY(fillfs, "fills file system, expects ENOSPC"); 921.1Spooka 931.1SpookaATF_TP_ADD_TCS(tp) 941.1Spooka{ 951.1Spooka 961.1Spooka ATF_TP_FSAPPLY(fillfs); 971.1Spooka 981.1Spooka return atf_no_error(); 991.1Spooka} 100