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