xref: /minix3/tests/fs/common/fstest_rumpfs.c (revision 0a6a1f1d05b60e214de2f05a7310ddd1f0e590e7)
1*0a6a1f1dSLionel Sambuc /*	$NetBSD: fstest_rumpfs.c,v 1.2 2014/03/16 10:28:03 njoly Exp $	*/
211be35a1SLionel Sambuc 
311be35a1SLionel Sambuc /*-
411be35a1SLionel Sambuc  * Copyright (c) 2010 The NetBSD Foundation, Inc.
511be35a1SLionel Sambuc  * All rights reserved.
611be35a1SLionel Sambuc  *
711be35a1SLionel Sambuc  * This code is derived from software contributed to The NetBSD Foundation
811be35a1SLionel Sambuc  * by Nicolas Joly.
911be35a1SLionel Sambuc  *
1011be35a1SLionel Sambuc  * Redistribution and use in source and binary forms, with or without
1111be35a1SLionel Sambuc  * modification, are permitted provided that the following conditions
1211be35a1SLionel Sambuc  * are met:
1311be35a1SLionel Sambuc  * 1. Redistributions of source code must retain the above copyright
1411be35a1SLionel Sambuc  *    notice, this list of conditions and the following disclaimer.
1511be35a1SLionel Sambuc  * 2. Redistributions in binary form must reproduce the above copyright
1611be35a1SLionel Sambuc  *    notice, this list of conditions and the following disclaimer in the
1711be35a1SLionel Sambuc  *    documentation and/or other materials provided with the distribution.
1811be35a1SLionel Sambuc  *
1911be35a1SLionel Sambuc  * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
2011be35a1SLionel Sambuc  * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
2111be35a1SLionel Sambuc  * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
2211be35a1SLionel Sambuc  * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
2311be35a1SLionel Sambuc  * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
2411be35a1SLionel Sambuc  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
2511be35a1SLionel Sambuc  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
2611be35a1SLionel Sambuc  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
2711be35a1SLionel Sambuc  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
2811be35a1SLionel Sambuc  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
2911be35a1SLionel Sambuc  * POSSIBILITY OF SUCH DAMAGE.
3011be35a1SLionel Sambuc  */
3111be35a1SLionel Sambuc 
3211be35a1SLionel Sambuc #include <sys/mount.h>
3311be35a1SLionel Sambuc #include <sys/stat.h>
3411be35a1SLionel Sambuc 
3511be35a1SLionel Sambuc #include <atf-c.h>
3611be35a1SLionel Sambuc #include <stdio.h>
3711be35a1SLionel Sambuc #include <stdlib.h>
3811be35a1SLionel Sambuc #include <string.h>
3911be35a1SLionel Sambuc #include <unistd.h>
4011be35a1SLionel Sambuc 
4111be35a1SLionel Sambuc #include <rump/rump.h>
4211be35a1SLionel Sambuc #include <rump/rump_syscalls.h>
4311be35a1SLionel Sambuc 
4411be35a1SLionel Sambuc #include "h_fsmacros.h"
4511be35a1SLionel Sambuc 
4611be35a1SLionel Sambuc int
rumpfs_fstest_newfs(const atf_tc_t * tc,void ** buf,const char * image,off_t size,void * fspriv)4711be35a1SLionel Sambuc rumpfs_fstest_newfs(const atf_tc_t *tc, void **buf, const char *image,
4811be35a1SLionel Sambuc     off_t size, void *fspriv)
4911be35a1SLionel Sambuc {
50*0a6a1f1dSLionel Sambuc 	char tmp[64];
51*0a6a1f1dSLionel Sambuc 	int res;
52*0a6a1f1dSLionel Sambuc 
53*0a6a1f1dSLionel Sambuc 	snprintf(tmp, sizeof(tmp), "%"PRId64, size);
54*0a6a1f1dSLionel Sambuc 	res = setenv("RUMP_MEMLIMIT", tmp, 0);
55*0a6a1f1dSLionel Sambuc 	if (res == -1)
56*0a6a1f1dSLionel Sambuc 		return res;
5711be35a1SLionel Sambuc 
5811be35a1SLionel Sambuc 	return rump_init();
5911be35a1SLionel Sambuc }
6011be35a1SLionel Sambuc 
6111be35a1SLionel Sambuc int
rumpfs_fstest_delfs(const atf_tc_t * tc,void * buf)6211be35a1SLionel Sambuc rumpfs_fstest_delfs(const atf_tc_t *tc, void *buf)
6311be35a1SLionel Sambuc {
6411be35a1SLionel Sambuc 
6511be35a1SLionel Sambuc 	return 0;
6611be35a1SLionel Sambuc }
6711be35a1SLionel Sambuc 
6811be35a1SLionel Sambuc int
rumpfs_fstest_mount(const atf_tc_t * tc,void * buf,const char * path,int flags)6911be35a1SLionel Sambuc rumpfs_fstest_mount(const atf_tc_t *tc, void *buf, const char *path, int flags)
7011be35a1SLionel Sambuc {
7111be35a1SLionel Sambuc 	int res;
7211be35a1SLionel Sambuc 
7311be35a1SLionel Sambuc 	res = rump_sys_mkdir(path, 0777);
7411be35a1SLionel Sambuc 	if (res == -1)
7511be35a1SLionel Sambuc 		return res;
7611be35a1SLionel Sambuc 
7711be35a1SLionel Sambuc 	return rump_sys_mount(MOUNT_RUMPFS, path, flags, NULL, 0);
7811be35a1SLionel Sambuc }
7911be35a1SLionel Sambuc 
8011be35a1SLionel Sambuc int
rumpfs_fstest_unmount(const atf_tc_t * tc,const char * path,int flags)8111be35a1SLionel Sambuc rumpfs_fstest_unmount(const atf_tc_t *tc, const char *path, int flags)
8211be35a1SLionel Sambuc {
8311be35a1SLionel Sambuc 	int res;
8411be35a1SLionel Sambuc 
8511be35a1SLionel Sambuc 	res = rump_sys_unmount(path, flags);
8611be35a1SLionel Sambuc 	if (res == -1)
8711be35a1SLionel Sambuc 		return res;
8811be35a1SLionel Sambuc 
8911be35a1SLionel Sambuc 	return rump_sys_rmdir(path);
9011be35a1SLionel Sambuc }
91