t_p2kifs.c revision 272343
1272343Sngie/* $NetBSD: t_p2kifs.c,v 1.4 2014/02/07 15:29:23 hannken Exp $ */ 2272343Sngie 3272343Sngie/*- 4272343Sngie * Copyright (c) 2010 The NetBSD Foundation, Inc. 5272343Sngie * All rights reserved. 6272343Sngie * 7272343Sngie * Redistribution and use in source and binary forms, with or without 8272343Sngie * modification, are permitted provided that the following conditions 9272343Sngie * are met: 10272343Sngie * 1. Redistributions of source code must retain the above copyright 11272343Sngie * notice, this list of conditions and the following disclaimer. 12272343Sngie * 2. Redistributions in binary form must reproduce the above copyright 13272343Sngie * notice, this list of conditions and the following disclaimer in the 14272343Sngie * documentation and/or other materials provided with the distribution. 15272343Sngie * 16272343Sngie * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND 17272343Sngie * CONTRIBUTORS ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, 18272343Sngie * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF 19272343Sngie * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 20272343Sngie * IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS BE LIABLE FOR ANY 21272343Sngie * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 22272343Sngie * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE 23272343Sngie * GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 24272343Sngie * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER 25272343Sngie * IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR 26272343Sngie * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN 27272343Sngie * IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 28272343Sngie */ 29272343Sngie 30272343Sngie#include <sys/types.h> 31272343Sngie#include <sys/mount.h> 32272343Sngie#include <sys/sysctl.h> 33272343Sngie 34272343Sngie#include <rump/rump.h> 35272343Sngie#include <rump/rump_syscalls.h> 36272343Sngie 37272343Sngie#include <atf-c.h> 38272343Sngie#include <fcntl.h> 39272343Sngie#include <stdio.h> 40272343Sngie#include <stdlib.h> 41272343Sngie#include <unistd.h> 42272343Sngie 43272343Sngie#include "../../h_macros.h" 44272343Sngie 45272343SngieATF_TC(makecn); 46272343SngieATF_TC_HEAD(makecn, tc) 47272343Sngie{ 48272343Sngie 49272343Sngie atf_tc_set_md_var(tc, "descr", "Tests makecn/LOOKUP/freecn"); 50272343Sngie} 51272343Sngie 52272343Sngie#define TESTFILE "testi" 53272343Sngie 54272343SngieATF_TC_BODY(makecn, tc) 55272343Sngie{ 56272343Sngie struct componentname *cn; 57272343Sngie char pathstr[MAXPATHLEN] = TESTFILE; 58272343Sngie struct vnode *vp; 59272343Sngie extern struct vnode *rumpns_rootvnode; 60272343Sngie 61272343Sngie rump_init(); 62272343Sngie 63272343Sngie /* 64272343Sngie * Strategy is to create a componentname, edit the passed 65272343Sngie * string, and then do a lookup with the componentname. 66272343Sngie */ 67272343Sngie RL(rump_sys_mkdir("/" TESTFILE, 0777)); 68272343Sngie 69272343Sngie /* need stable lwp for componentname */ 70272343Sngie RZ(rump_pub_lwproc_rfork(RUMP_RFCFDG)); 71272343Sngie 72272343Sngie /* try it once with the right path */ 73272343Sngie cn = rump_pub_makecn(RUMP_NAMEI_LOOKUP, 0, pathstr, strlen(pathstr), 74272343Sngie rump_pub_cred_create(0, 0, 0, NULL), rump_pub_lwproc_curlwp()); 75272343Sngie RZ(RUMP_VOP_LOOKUP(rumpns_rootvnode, &vp, cn)); 76272343Sngie rump_pub_freecn(cn, RUMPCN_FREECRED); 77272343Sngie 78272343Sngie /* and then with modification-in-the-middle */ 79272343Sngie cn = rump_pub_makecn(RUMP_NAMEI_LOOKUP, 0, pathstr, strlen(pathstr), 80272343Sngie rump_pub_cred_create(0, 0, 0, NULL), rump_pub_lwproc_curlwp()); 81272343Sngie strcpy(pathstr, "/muuta"); 82272343Sngie RZ(RUMP_VOP_LOOKUP(rumpns_rootvnode, &vp, cn)); 83272343Sngie rump_pub_freecn(cn, RUMPCN_FREECRED); 84272343Sngie} 85272343Sngie 86272343SngieATF_TP_ADD_TCS(tp) 87272343Sngie{ 88272343Sngie 89272343Sngie ATF_TP_ADD_TC(tp, makecn); 90272343Sngie 91272343Sngie return atf_no_error(); 92272343Sngie} 93