Home | History | Annotate | Line # | Download | only in rumpvfs
      1 /*	$NetBSD: t_p2kifs.c,v 1.7 2022/05/03 07:36:20 hannken Exp $	*/
      2 
      3 /*-
      4  * Copyright (c) 2010 The NetBSD Foundation, Inc.
      5  * All rights reserved.
      6  *
      7  * Redistribution and use in source and binary forms, with or without
      8  * modification, are permitted provided that the following conditions
      9  * are met:
     10  * 1. Redistributions of source code must retain the above copyright
     11  *    notice, this list of conditions and the following disclaimer.
     12  * 2. Redistributions in binary form must reproduce the above copyright
     13  *    notice, this list of conditions and the following disclaimer in the
     14  *    documentation and/or other materials provided with the distribution.
     15  *
     16  * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND
     17  * CONTRIBUTORS ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES,
     18  * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
     19  * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
     20  * IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS BE LIABLE FOR ANY
     21  * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
     22  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
     23  * GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
     24  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER
     25  * IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
     26  * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN
     27  * IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
     28  */
     29 
     30 #include <sys/types.h>
     31 #include <sys/mount.h>
     32 #include <sys/sysctl.h>
     33 
     34 #include <rump/rump.h>
     35 #include <rump/rumpvnode_if.h>
     36 #include <rump/rump_syscalls.h>
     37 
     38 #include <atf-c.h>
     39 #include <fcntl.h>
     40 #include <stdio.h>
     41 #include <stdlib.h>
     42 #include <unistd.h>
     43 
     44 #include "h_macros.h"
     45 
     46 ATF_TC(makecn);
     47 ATF_TC_HEAD(makecn, tc)
     48 {
     49 
     50 	atf_tc_set_md_var(tc, "descr", "Tests makecn/LOOKUP/freecn");
     51 }
     52 
     53 #define TESTFILE "testi"
     54 
     55 ATF_TC_BODY(makecn, tc)
     56 {
     57 	struct componentname *cn;
     58 	char pathstr[MAXPATHLEN] = TESTFILE;
     59 	struct vnode *vp;
     60 	extern struct vnode *rumpns_rootvnode;
     61 
     62 	rump_init();
     63 
     64 	/*
     65 	 * Strategy is to create a componentname, edit the passed
     66 	 * string, and then do a lookup with the componentname.
     67 	 */
     68 	RL(rump_sys_mkdir("/" TESTFILE, 0777));
     69 
     70 	/* need stable lwp for componentname */
     71 	RZ(rump_pub_lwproc_rfork(RUMP_RFCFDG));
     72 
     73 	/* obey vnode locking rules */
     74 	RZ(RUMP_VOP_LOCK(rumpns_rootvnode, RUMP_LK_EXCLUSIVE));
     75 
     76 	/* try it once with the right path */
     77 	cn = rump_pub_makecn(RUMP_NAMEI_LOOKUP, 0, pathstr, strlen(pathstr),
     78 	    rump_pub_cred_create(0, 0, 0, NULL), rump_pub_lwproc_curlwp());
     79 	RZ(RUMP_VOP_LOOKUP(rumpns_rootvnode, &vp, cn));
     80 	rump_pub_freecn(cn, RUMPCN_FREECRED);
     81 
     82 	/* and then with modification-in-the-middle */
     83 	cn = rump_pub_makecn(RUMP_NAMEI_LOOKUP, 0, pathstr, strlen(pathstr),
     84 	    rump_pub_cred_create(0, 0, 0, NULL), rump_pub_lwproc_curlwp());
     85 	strcpy(pathstr, "/muuta");
     86 	RZ(RUMP_VOP_LOOKUP(rumpns_rootvnode, &vp, cn));
     87 
     88 	RZ(RUMP_VOP_UNLOCK(rumpns_rootvnode));
     89 	rump_pub_freecn(cn, RUMPCN_FREECRED);
     90 }
     91 
     92 ATF_TP_ADD_TCS(tp)
     93 {
     94 
     95 	ATF_TP_ADD_TC(tp, makecn);
     96 
     97 	return atf_no_error();
     98 }
     99