fstest_tmpfs.c revision 1.2
11.2Spooka/* $NetBSD: fstest_tmpfs.c,v 1.2 2010/07/30 16:15:05 pooka Exp $ */ 21.1Spooka 31.1Spooka/*- 41.1Spooka * Copyright (c) 2010 The NetBSD Foundation, Inc. 51.1Spooka * All rights reserved. 61.1Spooka * 71.1Spooka * This code is derived from software contributed to The NetBSD Foundation 81.1Spooka * by Nicolas Joly. 91.1Spooka * 101.1Spooka * Redistribution and use in source and binary forms, with or without 111.1Spooka * modification, are permitted provided that the following conditions 121.1Spooka * are met: 131.1Spooka * 1. Redistributions of source code must retain the above copyright 141.1Spooka * notice, this list of conditions and the following disclaimer. 151.1Spooka * 2. Redistributions in binary form must reproduce the above copyright 161.1Spooka * notice, this list of conditions and the following disclaimer in the 171.1Spooka * documentation and/or other materials provided with the distribution. 181.1Spooka * 191.1Spooka * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS 201.1Spooka * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED 211.1Spooka * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 221.1Spooka * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS 231.1Spooka * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 241.1Spooka * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 251.1Spooka * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 261.1Spooka * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 271.1Spooka * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 281.1Spooka * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 291.1Spooka * POSSIBILITY OF SUCH DAMAGE. 301.1Spooka */ 311.1Spooka 321.1Spooka#include <sys/mount.h> 331.1Spooka#include <sys/stat.h> 341.1Spooka 351.1Spooka#include <atf-c.h> 361.1Spooka#include <stdio.h> 371.1Spooka#include <stdlib.h> 381.1Spooka#include <string.h> 391.1Spooka#include <unistd.h> 401.1Spooka 411.1Spooka#include <fs/tmpfs/tmpfs_args.h> 421.1Spooka 431.1Spooka#include <rump/rump.h> 441.1Spooka#include <rump/rump_syscalls.h> 451.1Spooka 461.1Spooka#include "h_fsmacros.h" 471.1Spooka 481.1Spookastruct tmpfstestargs { 491.1Spooka struct tmpfs_args ta_uargs; 501.1Spooka}; 511.1Spooka 521.1Spookaint 531.1Spookatmpfs_fstest_newfs(const atf_tc_t *tc, void **buf, const char *image, 541.2Spooka off_t size, void *fspriv) 551.1Spooka{ 561.1Spooka int res; 571.1Spooka struct tmpfstestargs *args; 581.1Spooka 591.1Spooka res = rump_init(); 601.1Spooka if (res != 0) 611.1Spooka return res; 621.1Spooka 631.1Spooka args = calloc(1, sizeof(*args)); 641.1Spooka if (args == NULL) 651.1Spooka return -1; 661.1Spooka 671.1Spooka args->ta_uargs.ta_version = TMPFS_ARGS_VERSION; 681.1Spooka args->ta_uargs.ta_root_mode = 0777; 691.1Spooka args->ta_uargs.ta_size_max = size; 701.1Spooka 711.1Spooka *buf = args; 721.1Spooka 731.1Spooka return 0; 741.1Spooka} 751.1Spooka 761.1Spookaint 771.1Spookatmpfs_fstest_delfs(const atf_tc_t *tc, void *buf) 781.1Spooka{ 791.1Spooka struct tmpfstestargs *args = buf; 801.1Spooka 811.1Spooka free(args); 821.1Spooka 831.1Spooka return 0; 841.1Spooka} 851.1Spooka 861.1Spookaint 871.1Spookatmpfs_fstest_mount(const atf_tc_t *tc, void *buf, const char *path, int flags) 881.1Spooka{ 891.1Spooka int res; 901.1Spooka struct tmpfstestargs *args = buf; 911.1Spooka 921.1Spooka res = rump_sys_mkdir(path, 0777); 931.1Spooka if (res == -1) 941.1Spooka return res; 951.1Spooka 961.1Spooka res = rump_sys_mount(MOUNT_TMPFS, path, flags, &args->ta_uargs, 971.1Spooka sizeof(args->ta_uargs)); 981.1Spooka return res; 991.1Spooka} 1001.1Spooka 1011.1Spookaint 1021.1Spookatmpfs_fstest_unmount(const atf_tc_t *tc, const char *path, int flags) 1031.1Spooka{ 1041.1Spooka int res; 1051.1Spooka 1061.1Spooka res = rump_sys_unmount(path, flags); 1071.1Spooka if (res == -1) 1081.1Spooka return res; 1091.1Spooka 1101.1Spooka res = rump_sys_rmdir(path); 1111.1Spooka return res; 1121.1Spooka} 113