11.3Skamil/*	$NetBSD: fstest_tmpfs.c,v 1.3 2020/06/17 00:16:21 kamil 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.3Skamil#include <rump/rump_syscallshotgun.h>
451.1Spooka#include <rump/rump_syscalls.h>
461.1Spooka
471.1Spooka#include "h_fsmacros.h"
481.1Spooka
491.1Spookastruct tmpfstestargs {
501.1Spooka        struct tmpfs_args ta_uargs;
511.1Spooka};
521.1Spooka
531.1Spookaint
541.1Spookatmpfs_fstest_newfs(const atf_tc_t *tc, void **buf, const char *image,
551.2Spooka    off_t size, void *fspriv)
561.1Spooka{
571.1Spooka	int res;
581.1Spooka	struct tmpfstestargs *args;
591.1Spooka
601.1Spooka	res = rump_init();
611.1Spooka	if (res != 0)
621.1Spooka		return res;
631.1Spooka
641.1Spooka	args = calloc(1, sizeof(*args));
651.1Spooka	if (args == NULL)
661.1Spooka		return -1;
671.1Spooka
681.1Spooka	args->ta_uargs.ta_version = TMPFS_ARGS_VERSION;
691.1Spooka	args->ta_uargs.ta_root_mode = 0777;
701.1Spooka	args->ta_uargs.ta_size_max = size;
711.1Spooka
721.1Spooka	*buf = args;
731.1Spooka
741.1Spooka	return 0;
751.1Spooka}
761.1Spooka
771.1Spookaint
781.1Spookatmpfs_fstest_delfs(const atf_tc_t *tc, void *buf)
791.1Spooka{
801.1Spooka	struct tmpfstestargs *args = buf;
811.1Spooka
821.1Spooka	free(args);
831.1Spooka
841.1Spooka	return 0;
851.1Spooka}
861.1Spooka
871.1Spookaint
881.1Spookatmpfs_fstest_mount(const atf_tc_t *tc, void *buf, const char *path, int flags)
891.1Spooka{
901.1Spooka	int res;
911.1Spooka	struct tmpfstestargs *args = buf;
921.1Spooka
931.1Spooka	res = rump_sys_mkdir(path, 0777);
941.1Spooka	if (res == -1)
951.1Spooka		return res;
961.1Spooka
971.1Spooka	res = rump_sys_mount(MOUNT_TMPFS, path, flags, &args->ta_uargs,
981.1Spooka	    sizeof(args->ta_uargs));
991.1Spooka	return res;
1001.1Spooka}
1011.1Spooka
1021.1Spookaint
1031.1Spookatmpfs_fstest_unmount(const atf_tc_t *tc, const char *path, int flags)
1041.1Spooka{
1051.1Spooka	int res;
1061.1Spooka
1071.1Spooka	res = rump_sys_unmount(path, flags);
1081.1Spooka	if (res == -1)
1091.1Spooka		return res;
1101.1Spooka
1111.1Spooka	res = rump_sys_rmdir(path);
1121.1Spooka	return res;
1131.1Spooka}
114