t_p2kifs.c revision 272343
1239675Srwatson/*	$NetBSD: t_p2kifs.c,v 1.4 2014/02/07 15:29:23 hannken Exp $	*/
2239675Srwatson
3239675Srwatson/*-
4239675Srwatson * Copyright (c) 2010 The NetBSD Foundation, Inc.
5239675Srwatson * All rights reserved.
6239675Srwatson *
7239675Srwatson * Redistribution and use in source and binary forms, with or without
8239675Srwatson * modification, are permitted provided that the following conditions
9239675Srwatson * are met:
10239675Srwatson * 1. Redistributions of source code must retain the above copyright
11239675Srwatson *    notice, this list of conditions and the following disclaimer.
12239675Srwatson * 2. Redistributions in binary form must reproduce the above copyright
13239675Srwatson *    notice, this list of conditions and the following disclaimer in the
14239675Srwatson *    documentation and/or other materials provided with the distribution.
15239675Srwatson *
16239675Srwatson * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND
17239675Srwatson * CONTRIBUTORS ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES,
18239675Srwatson * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
19239675Srwatson * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
20239675Srwatson * IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS BE LIABLE FOR ANY
21239675Srwatson * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
22239675Srwatson * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
23239675Srwatson * GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
24239675Srwatson * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER
25239675Srwatson * IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
26239675Srwatson * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN
27239675Srwatson * IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
28239675Srwatson */
29239675Srwatson
30239675Srwatson#include <sys/types.h>
31239675Srwatson#include <sys/mount.h>
32239675Srwatson#include <sys/sysctl.h>
33239675Srwatson
34239675Srwatson#include <rump/rump.h>
35239675Srwatson#include <rump/rump_syscalls.h>
36239675Srwatson
37239675Srwatson#include <atf-c.h>
38239675Srwatson#include <fcntl.h>
39239675Srwatson#include <stdio.h>
40239675Srwatson#include <stdlib.h>
41239675Srwatson#include <unistd.h>
42239675Srwatson
43239675Srwatson#include "../../h_macros.h"
44239675Srwatson
45239675SrwatsonATF_TC(makecn);
46239675SrwatsonATF_TC_HEAD(makecn, tc)
47239675Srwatson{
48239675Srwatson
49239675Srwatson	atf_tc_set_md_var(tc, "descr", "Tests makecn/LOOKUP/freecn");
50239675Srwatson}
51239675Srwatson
52239675Srwatson#define TESTFILE "testi"
53239675Srwatson
54239675SrwatsonATF_TC_BODY(makecn, tc)
55239675Srwatson{
56239675Srwatson	struct componentname *cn;
57239675Srwatson	char pathstr[MAXPATHLEN] = TESTFILE;
58239675Srwatson	struct vnode *vp;
59239675Srwatson	extern struct vnode *rumpns_rootvnode;
60239675Srwatson
61239675Srwatson	rump_init();
62239675Srwatson
63239675Srwatson	/*
64239675Srwatson	 * Strategy is to create a componentname, edit the passed
65257336Snwhitehorn	 * string, and then do a lookup with the componentname.
66239675Srwatson	 */
67239675Srwatson	RL(rump_sys_mkdir("/" TESTFILE, 0777));
68239675Srwatson
69239675Srwatson	/* need stable lwp for componentname */
70239675Srwatson	RZ(rump_pub_lwproc_rfork(RUMP_RFCFDG));
71239675Srwatson
72239675Srwatson	/* try it once with the right path */
73239675Srwatson	cn = rump_pub_makecn(RUMP_NAMEI_LOOKUP, 0, pathstr, strlen(pathstr),
74239675Srwatson	    rump_pub_cred_create(0, 0, 0, NULL), rump_pub_lwproc_curlwp());
75239675Srwatson	RZ(RUMP_VOP_LOOKUP(rumpns_rootvnode, &vp, cn));
76239675Srwatson	rump_pub_freecn(cn, RUMPCN_FREECRED);
77239675Srwatson
78239675Srwatson	/* and then with modification-in-the-middle */
79239675Srwatson	cn = rump_pub_makecn(RUMP_NAMEI_LOOKUP, 0, pathstr, strlen(pathstr),
80239675Srwatson	    rump_pub_cred_create(0, 0, 0, NULL), rump_pub_lwproc_curlwp());
81239675Srwatson	strcpy(pathstr, "/muuta");
82239675Srwatson	RZ(RUMP_VOP_LOOKUP(rumpns_rootvnode, &vp, cn));
83239675Srwatson	rump_pub_freecn(cn, RUMPCN_FREECRED);
84239675Srwatson}
85239675Srwatson
86239675SrwatsonATF_TP_ADD_TCS(tp)
87239675Srwatson{
88239675Srwatson
89239675Srwatson	ATF_TP_ADD_TC(tp, makecn);
90239675Srwatson
91239675Srwatson	return atf_no_error();
92239675Srwatson}
93239675Srwatson