xref: /aosp_15_r20/external/ltp/testcases/kernel/syscalls/mknod/mknod01.c (revision 49cdfc7efb34551c7342be41a7384b9c40d7cab7)
1*49cdfc7eSAndroid Build Coastguard Worker // SPDX-License-Identifier: GPL-2.0-only
2*49cdfc7eSAndroid Build Coastguard Worker /*
3*49cdfc7eSAndroid Build Coastguard Worker  * Copyright (c) 2000 Silicon Graphics, Inc.  All Rights Reserved.
4*49cdfc7eSAndroid Build Coastguard Worker  *  AUTHOR: William Roske, CO-PILOT: Dave Fenner
5*49cdfc7eSAndroid Build Coastguard Worker  * Copyright (c) 2023 SUSE LLC Avinesh Kumar <[email protected]>
6*49cdfc7eSAndroid Build Coastguard Worker  */
7*49cdfc7eSAndroid Build Coastguard Worker 
8*49cdfc7eSAndroid Build Coastguard Worker /*\
9*49cdfc7eSAndroid Build Coastguard Worker  * [Description]
10*49cdfc7eSAndroid Build Coastguard Worker  *
11*49cdfc7eSAndroid Build Coastguard Worker  * Verify that mknod(2) successfully creates a filesystem node with
12*49cdfc7eSAndroid Build Coastguard Worker  * various modes.
13*49cdfc7eSAndroid Build Coastguard Worker  */
14*49cdfc7eSAndroid Build Coastguard Worker 
15*49cdfc7eSAndroid Build Coastguard Worker #include <sys/sysmacros.h>
16*49cdfc7eSAndroid Build Coastguard Worker #include "tst_test.h"
17*49cdfc7eSAndroid Build Coastguard Worker 
18*49cdfc7eSAndroid Build Coastguard Worker #define PATH "test_node"
19*49cdfc7eSAndroid Build Coastguard Worker 
20*49cdfc7eSAndroid Build Coastguard Worker static int tcases[] = {
21*49cdfc7eSAndroid Build Coastguard Worker 	S_IFREG | 0777,
22*49cdfc7eSAndroid Build Coastguard Worker 	S_IFIFO | 0777,
23*49cdfc7eSAndroid Build Coastguard Worker 	S_IFCHR | 0777,
24*49cdfc7eSAndroid Build Coastguard Worker 	S_IFBLK | 0777,
25*49cdfc7eSAndroid Build Coastguard Worker 
26*49cdfc7eSAndroid Build Coastguard Worker 	S_IFREG | 04700,
27*49cdfc7eSAndroid Build Coastguard Worker 	S_IFREG | 02700,
28*49cdfc7eSAndroid Build Coastguard Worker 	S_IFREG | 06700,
29*49cdfc7eSAndroid Build Coastguard Worker };
30*49cdfc7eSAndroid Build Coastguard Worker 
31*49cdfc7eSAndroid Build Coastguard Worker 
run(unsigned int i)32*49cdfc7eSAndroid Build Coastguard Worker static void run(unsigned int i)
33*49cdfc7eSAndroid Build Coastguard Worker {
34*49cdfc7eSAndroid Build Coastguard Worker 	dev_t dev = 0;
35*49cdfc7eSAndroid Build Coastguard Worker 
36*49cdfc7eSAndroid Build Coastguard Worker 	if (S_ISCHR(tcases[i]) || S_ISBLK(tcases[i]))
37*49cdfc7eSAndroid Build Coastguard Worker 		dev = makedev(1, 3);
38*49cdfc7eSAndroid Build Coastguard Worker 
39*49cdfc7eSAndroid Build Coastguard Worker 	TST_EXP_PASS(mknod(PATH, tcases[i], dev),
40*49cdfc7eSAndroid Build Coastguard Worker 				"mknod(PATH, %o, %ld)",
41*49cdfc7eSAndroid Build Coastguard Worker 				tcases[i], dev);
42*49cdfc7eSAndroid Build Coastguard Worker 	SAFE_UNLINK(PATH);
43*49cdfc7eSAndroid Build Coastguard Worker }
44*49cdfc7eSAndroid Build Coastguard Worker 
45*49cdfc7eSAndroid Build Coastguard Worker static struct tst_test test = {
46*49cdfc7eSAndroid Build Coastguard Worker 	.test = run,
47*49cdfc7eSAndroid Build Coastguard Worker 	.tcnt = ARRAY_SIZE(tcases),
48*49cdfc7eSAndroid Build Coastguard Worker 	.needs_root = 1,
49*49cdfc7eSAndroid Build Coastguard Worker 	.needs_tmpdir = 1
50*49cdfc7eSAndroid Build Coastguard Worker };
51