• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2000 Silicon Graphics, Inc.  All Rights Reserved.
3  *  AUTHOR		: William Roske
4  *  CO-PILOT		: Dave Fenner
5  *
6  * This program is free software; you can redistribute it and/or modify it
7  * under the terms of version 2 of the GNU General Public License as
8  * published by the Free Software Foundation.
9  *
10  * This program is distributed in the hope that it would be useful, but
11  * WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
13  *
14  * Further, this software is distributed without any warranty that it is
15  * free of the rightful claim of any third person regarding infringement
16  * or the like.  Any license provided herein, whether implied or
17  * otherwise, applies only to this software file.  Patent licenses, if
18  * any, provided herein do not apply to combinations of this program with
19  * other software, or any other product whatsoever.
20  *
21  * You should have received a copy of the GNU General Public License along
22  * with this program; if not, write the Free Software Foundation, Inc.,
23  * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
24  *
25  * Contact information: Silicon Graphics, Inc., 1600 Amphitheatre Pkwy,
26  * Mountain View, CA  94043, or:
27  *
28  * http://www.sgi.com
29  *
30  * For further information regarding this notice, see:
31  *
32  * http://oss.sgi.com/projects/GenInfo/NoticeExplan/
33  *
34  */
35 
36 #include <unistd.h>
37 #include <errno.h>
38 #include <string.h>
39 #include <signal.h>
40 #include <sys/types.h>
41 #include <sys/stat.h>
42 #include <sys/sysmacros.h>
43 
44 #include "test.h"
45 #include "safe_macros.h"
46 
47 static void setup(void);
48 static void cleanup(void);
49 
50 char *TCID = "mknod01";
51 
52 #define PATH "test_node"
53 
54 int tcases[] = {		/* modes to give nodes created (1 per text case) */
55 	S_IFREG | 0777,		/* ordinary file with mode 0777 */
56 	S_IFIFO | 0777,		/* fifo special with mode 0777 */
57 	S_IFCHR | 0777,		/* character special with mode 0777 */
58 	S_IFBLK | 0777,		/* block special with mode 0777 */
59 
60 	S_IFREG | 04700,	/* ordinary file with mode 04700 (suid) */
61 	S_IFREG | 02700,	/* ordinary file with mode 02700 (sgid) */
62 	S_IFREG | 06700,	/* ordinary file with mode 06700 (sgid & suid) */
63 };
64 
65 int TST_TOTAL = ARRAY_SIZE(tcases);
66 
main(int ac,char ** av)67 int main(int ac, char **av)
68 {
69 	int lc, i;
70 	dev_t dev;
71 
72 	tst_parse_opts(ac, av, NULL, NULL);
73 
74 	setup();
75 
76 	for (lc = 0; TEST_LOOPING(lc); lc++) {
77 		tst_count = 0;
78 
79 		for (i = 0; i < TST_TOTAL; i++) {
80 			/*
81 			 * overlayfs doesn't support mknod char device with
82 			 * major 0 and minor 0, which is known as whiteout_dev
83 			 */
84 			if (S_ISCHR(tcases[i]))
85 				dev = makedev(1, 3);
86 			else
87 				dev = 0;
88 			TEST(mknod(PATH, tcases[i], dev));
89 
90 			if (TEST_RETURN == -1) {
91 				tst_resm(TFAIL,
92 					 "mknod(%s, %#o, %lu) failed, errno=%d : %s",
93 					 PATH, tcases[i], dev, TEST_ERRNO,
94 					 strerror(TEST_ERRNO));
95 			} else {
96 				tst_resm(TPASS,
97 					 "mknod(%s, %#o, %lu) returned %ld",
98 					 PATH, tcases[i], dev, TEST_RETURN);
99 			}
100 
101 			SAFE_UNLINK(cleanup, PATH);
102 		}
103 
104 	}
105 
106 	cleanup();
107 	tst_exit();
108 }
109 
setup(void)110 void setup(void)
111 {
112 	tst_require_root();
113 	tst_sig(NOFORK, DEF_HANDLER, cleanup);
114 
115 	TEST_PAUSE;
116 
117 	tst_tmpdir();
118 }
119 
cleanup(void)120 void cleanup(void)
121 {
122 	tst_rmdir();
123 }
124