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