xref: /freebsd/contrib/netbsd-tests/rump/rumpvfs/t_p2kifs.c (revision 63d1fd5970ec814904aa0f4580b10a0d302d08b2)
1*63d1fd59SEnji Cooper /*	$NetBSD: t_p2kifs.c,v 1.6 2017/01/13 21:30:43 christos Exp $	*/
257718be8SEnji Cooper 
357718be8SEnji Cooper /*-
457718be8SEnji Cooper  * Copyright (c) 2010 The NetBSD Foundation, Inc.
557718be8SEnji Cooper  * All rights reserved.
657718be8SEnji Cooper  *
757718be8SEnji Cooper  * Redistribution and use in source and binary forms, with or without
857718be8SEnji Cooper  * modification, are permitted provided that the following conditions
957718be8SEnji Cooper  * are met:
1057718be8SEnji Cooper  * 1. Redistributions of source code must retain the above copyright
1157718be8SEnji Cooper  *    notice, this list of conditions and the following disclaimer.
1257718be8SEnji Cooper  * 2. Redistributions in binary form must reproduce the above copyright
1357718be8SEnji Cooper  *    notice, this list of conditions and the following disclaimer in the
1457718be8SEnji Cooper  *    documentation and/or other materials provided with the distribution.
1557718be8SEnji Cooper  *
1657718be8SEnji Cooper  * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND
1757718be8SEnji Cooper  * CONTRIBUTORS ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES,
1857718be8SEnji Cooper  * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
1957718be8SEnji Cooper  * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
2057718be8SEnji Cooper  * IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS BE LIABLE FOR ANY
2157718be8SEnji Cooper  * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
2257718be8SEnji Cooper  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
2357718be8SEnji Cooper  * GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
2457718be8SEnji Cooper  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER
2557718be8SEnji Cooper  * IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
2657718be8SEnji Cooper  * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN
2757718be8SEnji Cooper  * IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
2857718be8SEnji Cooper  */
2957718be8SEnji Cooper 
3057718be8SEnji Cooper #include <sys/types.h>
3157718be8SEnji Cooper #include <sys/mount.h>
3257718be8SEnji Cooper #include <sys/sysctl.h>
3357718be8SEnji Cooper 
3457718be8SEnji Cooper #include <rump/rump.h>
35640235e2SEnji Cooper #include <rump/rumpvnode_if.h>
3657718be8SEnji Cooper #include <rump/rump_syscalls.h>
3757718be8SEnji Cooper 
3857718be8SEnji Cooper #include <atf-c.h>
3957718be8SEnji Cooper #include <fcntl.h>
4057718be8SEnji Cooper #include <stdio.h>
4157718be8SEnji Cooper #include <stdlib.h>
4257718be8SEnji Cooper #include <unistd.h>
4357718be8SEnji Cooper 
44*63d1fd59SEnji Cooper #include "h_macros.h"
4557718be8SEnji Cooper 
4657718be8SEnji Cooper ATF_TC(makecn);
4757718be8SEnji Cooper ATF_TC_HEAD(makecn, tc)
4857718be8SEnji Cooper {
4957718be8SEnji Cooper 
5057718be8SEnji Cooper 	atf_tc_set_md_var(tc, "descr", "Tests makecn/LOOKUP/freecn");
5157718be8SEnji Cooper }
5257718be8SEnji Cooper 
5357718be8SEnji Cooper #define TESTFILE "testi"
5457718be8SEnji Cooper 
5557718be8SEnji Cooper ATF_TC_BODY(makecn, tc)
5657718be8SEnji Cooper {
5757718be8SEnji Cooper 	struct componentname *cn;
5857718be8SEnji Cooper 	char pathstr[MAXPATHLEN] = TESTFILE;
5957718be8SEnji Cooper 	struct vnode *vp;
6057718be8SEnji Cooper 	extern struct vnode *rumpns_rootvnode;
6157718be8SEnji Cooper 
6257718be8SEnji Cooper 	rump_init();
6357718be8SEnji Cooper 
6457718be8SEnji Cooper 	/*
6557718be8SEnji Cooper 	 * Strategy is to create a componentname, edit the passed
6657718be8SEnji Cooper 	 * string, and then do a lookup with the componentname.
6757718be8SEnji Cooper 	 */
6857718be8SEnji Cooper 	RL(rump_sys_mkdir("/" TESTFILE, 0777));
6957718be8SEnji Cooper 
7057718be8SEnji Cooper 	/* need stable lwp for componentname */
7157718be8SEnji Cooper 	RZ(rump_pub_lwproc_rfork(RUMP_RFCFDG));
7257718be8SEnji Cooper 
7357718be8SEnji Cooper 	/* try it once with the right path */
7457718be8SEnji Cooper 	cn = rump_pub_makecn(RUMP_NAMEI_LOOKUP, 0, pathstr, strlen(pathstr),
7557718be8SEnji Cooper 	    rump_pub_cred_create(0, 0, 0, NULL), rump_pub_lwproc_curlwp());
7657718be8SEnji Cooper 	RZ(RUMP_VOP_LOOKUP(rumpns_rootvnode, &vp, cn));
7757718be8SEnji Cooper 	rump_pub_freecn(cn, RUMPCN_FREECRED);
7857718be8SEnji Cooper 
7957718be8SEnji Cooper 	/* and then with modification-in-the-middle */
8057718be8SEnji Cooper 	cn = rump_pub_makecn(RUMP_NAMEI_LOOKUP, 0, pathstr, strlen(pathstr),
8157718be8SEnji Cooper 	    rump_pub_cred_create(0, 0, 0, NULL), rump_pub_lwproc_curlwp());
8257718be8SEnji Cooper 	strcpy(pathstr, "/muuta");
8357718be8SEnji Cooper 	RZ(RUMP_VOP_LOOKUP(rumpns_rootvnode, &vp, cn));
8457718be8SEnji Cooper 	rump_pub_freecn(cn, RUMPCN_FREECRED);
8557718be8SEnji Cooper }
8657718be8SEnji Cooper 
8757718be8SEnji Cooper ATF_TP_ADD_TCS(tp)
8857718be8SEnji Cooper {
8957718be8SEnji Cooper 
9057718be8SEnji Cooper 	ATF_TP_ADD_TC(tp, makecn);
9157718be8SEnji Cooper 
9257718be8SEnji Cooper 	return atf_no_error();
9357718be8SEnji Cooper }
94