xref: /minix3/tests/rump/rumpvfs/t_p2kifs.c (revision 0a6a1f1d05b60e214de2f05a7310ddd1f0e590e7)
1*0a6a1f1dSLionel Sambuc /*	$NetBSD: t_p2kifs.c,v 1.4 2014/02/07 15:29:23 hannken Exp $	*/
211be35a1SLionel Sambuc 
311be35a1SLionel Sambuc /*-
411be35a1SLionel Sambuc  * Copyright (c) 2010 The NetBSD Foundation, Inc.
511be35a1SLionel Sambuc  * All rights reserved.
611be35a1SLionel Sambuc  *
711be35a1SLionel Sambuc  * Redistribution and use in source and binary forms, with or without
811be35a1SLionel Sambuc  * modification, are permitted provided that the following conditions
911be35a1SLionel Sambuc  * are met:
1011be35a1SLionel Sambuc  * 1. Redistributions of source code must retain the above copyright
1111be35a1SLionel Sambuc  *    notice, this list of conditions and the following disclaimer.
1211be35a1SLionel Sambuc  * 2. Redistributions in binary form must reproduce the above copyright
1311be35a1SLionel Sambuc  *    notice, this list of conditions and the following disclaimer in the
1411be35a1SLionel Sambuc  *    documentation and/or other materials provided with the distribution.
1511be35a1SLionel Sambuc  *
1611be35a1SLionel Sambuc  * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND
1711be35a1SLionel Sambuc  * CONTRIBUTORS ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES,
1811be35a1SLionel Sambuc  * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
1911be35a1SLionel Sambuc  * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
2011be35a1SLionel Sambuc  * IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS BE LIABLE FOR ANY
2111be35a1SLionel Sambuc  * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
2211be35a1SLionel Sambuc  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
2311be35a1SLionel Sambuc  * GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
2411be35a1SLionel Sambuc  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER
2511be35a1SLionel Sambuc  * IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
2611be35a1SLionel Sambuc  * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN
2711be35a1SLionel Sambuc  * IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
2811be35a1SLionel Sambuc  */
2911be35a1SLionel Sambuc 
3011be35a1SLionel Sambuc #include <sys/types.h>
3111be35a1SLionel Sambuc #include <sys/mount.h>
3211be35a1SLionel Sambuc #include <sys/sysctl.h>
3311be35a1SLionel Sambuc 
3411be35a1SLionel Sambuc #include <rump/rump.h>
3511be35a1SLionel Sambuc #include <rump/rump_syscalls.h>
3611be35a1SLionel Sambuc 
3711be35a1SLionel Sambuc #include <atf-c.h>
3811be35a1SLionel Sambuc #include <fcntl.h>
3911be35a1SLionel Sambuc #include <stdio.h>
4011be35a1SLionel Sambuc #include <stdlib.h>
4111be35a1SLionel Sambuc #include <unistd.h>
4211be35a1SLionel Sambuc 
4311be35a1SLionel Sambuc #include "../../h_macros.h"
4411be35a1SLionel Sambuc 
4511be35a1SLionel Sambuc ATF_TC(makecn);
ATF_TC_HEAD(makecn,tc)4611be35a1SLionel Sambuc ATF_TC_HEAD(makecn, tc)
4711be35a1SLionel Sambuc {
4811be35a1SLionel Sambuc 
4911be35a1SLionel Sambuc 	atf_tc_set_md_var(tc, "descr", "Tests makecn/LOOKUP/freecn");
5011be35a1SLionel Sambuc }
5111be35a1SLionel Sambuc 
5211be35a1SLionel Sambuc #define TESTFILE "testi"
5311be35a1SLionel Sambuc 
ATF_TC_BODY(makecn,tc)5411be35a1SLionel Sambuc ATF_TC_BODY(makecn, tc)
5511be35a1SLionel Sambuc {
5611be35a1SLionel Sambuc 	struct componentname *cn;
5711be35a1SLionel Sambuc 	char pathstr[MAXPATHLEN] = TESTFILE;
5811be35a1SLionel Sambuc 	struct vnode *vp;
5911be35a1SLionel Sambuc 	extern struct vnode *rumpns_rootvnode;
6011be35a1SLionel Sambuc 
6111be35a1SLionel Sambuc 	rump_init();
6211be35a1SLionel Sambuc 
6311be35a1SLionel Sambuc 	/*
6411be35a1SLionel Sambuc 	 * Strategy is to create a componentname, edit the passed
6511be35a1SLionel Sambuc 	 * string, and then do a lookup with the componentname.
6611be35a1SLionel Sambuc 	 */
6711be35a1SLionel Sambuc 	RL(rump_sys_mkdir("/" TESTFILE, 0777));
6811be35a1SLionel Sambuc 
6911be35a1SLionel Sambuc 	/* need stable lwp for componentname */
7011be35a1SLionel Sambuc 	RZ(rump_pub_lwproc_rfork(RUMP_RFCFDG));
7111be35a1SLionel Sambuc 
7211be35a1SLionel Sambuc 	/* try it once with the right path */
7311be35a1SLionel Sambuc 	cn = rump_pub_makecn(RUMP_NAMEI_LOOKUP, 0, pathstr, strlen(pathstr),
7411be35a1SLionel Sambuc 	    rump_pub_cred_create(0, 0, 0, NULL), rump_pub_lwproc_curlwp());
7511be35a1SLionel Sambuc 	RZ(RUMP_VOP_LOOKUP(rumpns_rootvnode, &vp, cn));
7611be35a1SLionel Sambuc 	rump_pub_freecn(cn, RUMPCN_FREECRED);
7711be35a1SLionel Sambuc 
7811be35a1SLionel Sambuc 	/* and then with modification-in-the-middle */
7911be35a1SLionel Sambuc 	cn = rump_pub_makecn(RUMP_NAMEI_LOOKUP, 0, pathstr, strlen(pathstr),
8011be35a1SLionel Sambuc 	    rump_pub_cred_create(0, 0, 0, NULL), rump_pub_lwproc_curlwp());
8111be35a1SLionel Sambuc 	strcpy(pathstr, "/muuta");
8211be35a1SLionel Sambuc 	RZ(RUMP_VOP_LOOKUP(rumpns_rootvnode, &vp, cn));
8311be35a1SLionel Sambuc 	rump_pub_freecn(cn, RUMPCN_FREECRED);
8411be35a1SLionel Sambuc }
8511be35a1SLionel Sambuc 
ATF_TP_ADD_TCS(tp)8611be35a1SLionel Sambuc ATF_TP_ADD_TCS(tp)
8711be35a1SLionel Sambuc {
8811be35a1SLionel Sambuc 
8911be35a1SLionel Sambuc 	ATF_TP_ADD_TC(tp, makecn);
9011be35a1SLionel Sambuc 
9111be35a1SLionel Sambuc 	return atf_no_error();
9211be35a1SLionel Sambuc }
93