1*dabbbd0dShannken /* $NetBSD: t_p2kifs.c,v 1.7 2022/05/03 07:36:20 hannken Exp $ */
274861a96Spooka
374861a96Spooka /*-
474861a96Spooka * Copyright (c) 2010 The NetBSD Foundation, Inc.
574861a96Spooka * All rights reserved.
674861a96Spooka *
774861a96Spooka * Redistribution and use in source and binary forms, with or without
874861a96Spooka * modification, are permitted provided that the following conditions
974861a96Spooka * are met:
1074861a96Spooka * 1. Redistributions of source code must retain the above copyright
1174861a96Spooka * notice, this list of conditions and the following disclaimer.
1274861a96Spooka * 2. Redistributions in binary form must reproduce the above copyright
1374861a96Spooka * notice, this list of conditions and the following disclaimer in the
1474861a96Spooka * documentation and/or other materials provided with the distribution.
1574861a96Spooka *
1674861a96Spooka * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND
1774861a96Spooka * CONTRIBUTORS ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES,
1874861a96Spooka * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
1974861a96Spooka * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
2074861a96Spooka * IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS BE LIABLE FOR ANY
2174861a96Spooka * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
2274861a96Spooka * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
2374861a96Spooka * GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
2474861a96Spooka * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER
2574861a96Spooka * IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
2674861a96Spooka * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN
2774861a96Spooka * IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
2874861a96Spooka */
2974861a96Spooka
3074861a96Spooka #include <sys/types.h>
3174861a96Spooka #include <sys/mount.h>
3274861a96Spooka #include <sys/sysctl.h>
3374861a96Spooka
3474861a96Spooka #include <rump/rump.h>
35d35b86acSpooka #include <rump/rumpvnode_if.h>
3674861a96Spooka #include <rump/rump_syscalls.h>
3774861a96Spooka
3874861a96Spooka #include <atf-c.h>
3974861a96Spooka #include <fcntl.h>
4074861a96Spooka #include <stdio.h>
4174861a96Spooka #include <stdlib.h>
4274861a96Spooka #include <unistd.h>
4374861a96Spooka
44c54cb811Schristos #include "h_macros.h"
4574861a96Spooka
4674861a96Spooka ATF_TC(makecn);
ATF_TC_HEAD(makecn,tc)4774861a96Spooka ATF_TC_HEAD(makecn, tc)
4874861a96Spooka {
4974861a96Spooka
5074861a96Spooka atf_tc_set_md_var(tc, "descr", "Tests makecn/LOOKUP/freecn");
5174861a96Spooka }
5274861a96Spooka
5374861a96Spooka #define TESTFILE "testi"
5474861a96Spooka
ATF_TC_BODY(makecn,tc)5574861a96Spooka ATF_TC_BODY(makecn, tc)
5674861a96Spooka {
5774861a96Spooka struct componentname *cn;
581d9fa0a3Spooka char pathstr[MAXPATHLEN] = TESTFILE;
5974861a96Spooka struct vnode *vp;
6074861a96Spooka extern struct vnode *rumpns_rootvnode;
6174861a96Spooka
6274861a96Spooka rump_init();
6374861a96Spooka
6474861a96Spooka /*
6574861a96Spooka * Strategy is to create a componentname, edit the passed
6674861a96Spooka * string, and then do a lookup with the componentname.
6774861a96Spooka */
6874861a96Spooka RL(rump_sys_mkdir("/" TESTFILE, 0777));
6974861a96Spooka
7074861a96Spooka /* need stable lwp for componentname */
715c3365ceSpooka RZ(rump_pub_lwproc_rfork(RUMP_RFCFDG));
7274861a96Spooka
73*dabbbd0dShannken /* obey vnode locking rules */
74*dabbbd0dShannken RZ(RUMP_VOP_LOCK(rumpns_rootvnode, RUMP_LK_EXCLUSIVE));
75*dabbbd0dShannken
7674861a96Spooka /* try it once with the right path */
7774861a96Spooka cn = rump_pub_makecn(RUMP_NAMEI_LOOKUP, 0, pathstr, strlen(pathstr),
7874861a96Spooka rump_pub_cred_create(0, 0, 0, NULL), rump_pub_lwproc_curlwp());
7974861a96Spooka RZ(RUMP_VOP_LOOKUP(rumpns_rootvnode, &vp, cn));
8074861a96Spooka rump_pub_freecn(cn, RUMPCN_FREECRED);
8174861a96Spooka
8274861a96Spooka /* and then with modification-in-the-middle */
8374861a96Spooka cn = rump_pub_makecn(RUMP_NAMEI_LOOKUP, 0, pathstr, strlen(pathstr),
8474861a96Spooka rump_pub_cred_create(0, 0, 0, NULL), rump_pub_lwproc_curlwp());
8574861a96Spooka strcpy(pathstr, "/muuta");
8674861a96Spooka RZ(RUMP_VOP_LOOKUP(rumpns_rootvnode, &vp, cn));
87*dabbbd0dShannken
88*dabbbd0dShannken RZ(RUMP_VOP_UNLOCK(rumpns_rootvnode));
8974861a96Spooka rump_pub_freecn(cn, RUMPCN_FREECRED);
9074861a96Spooka }
9174861a96Spooka
ATF_TP_ADD_TCS(tp)9274861a96Spooka ATF_TP_ADD_TCS(tp)
9374861a96Spooka {
9474861a96Spooka
9574861a96Spooka ATF_TP_ADD_TC(tp, makecn);
9674861a96Spooka
9774861a96Spooka return atf_no_error();
9874861a96Spooka }
99