plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (c) 2000 Silicon Graphics, Inc. All Rights Reserved. |
| 3 | * |
| 4 | * This program is free software; you can redistribute it and/or modify it |
| 5 | * under the terms of version 2 of the GNU General Public License as |
| 6 | * published by the Free Software Foundation. |
| 7 | * |
| 8 | * This program is distributed in the hope that it would be useful, but |
| 9 | * WITHOUT ANY WARRANTY; without even the implied warranty of |
| 10 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. |
| 11 | * |
| 12 | * Further, this software is distributed without any warranty that it is |
| 13 | * free of the rightful claim of any third person regarding infringement |
| 14 | * or the like. Any license provided herein, whether implied or |
| 15 | * otherwise, applies only to this software file. Patent licenses, if |
| 16 | * any, provided herein do not apply to combinations of this program with |
| 17 | * other software, or any other product whatsoever. |
| 18 | * |
| 19 | * You should have received a copy of the GNU General Public License along |
Wanlong Gao | fed9641 | 2012-10-24 10:10:29 +0800 | [diff] [blame] | 20 | * with this program; if not, write the Free Software Foundation, Inc., |
| 21 | * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 22 | * |
| 23 | * Contact information: Silicon Graphics, Inc., 1600 Amphitheatre Pkwy, |
| 24 | * Mountain View, CA 94043, or: |
| 25 | * |
| 26 | * http://www.sgi.com |
| 27 | * |
| 28 | * For further information regarding this notice, see: |
| 29 | * |
| 30 | * http://oss.sgi.com/projects/GenInfo/NoticeExplan/ |
| 31 | * |
| 32 | */ |
subrata_modak | 56207ce | 2009-03-23 13:35:39 +0000 | [diff] [blame] | 33 | /* $Id: mkdir01.c,v 1.7 2009/03/23 13:35:54 subrata_modak Exp $ */ |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 34 | /********************************************************** |
subrata_modak | 4bb656a | 2009-02-26 12:02:09 +0000 | [diff] [blame] | 35 | * |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 36 | * OS Test - Silicon Graphics, Inc. |
subrata_modak | 4bb656a | 2009-02-26 12:02:09 +0000 | [diff] [blame] | 37 | * |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 38 | * TEST IDENTIFIER : mkdir01 |
subrata_modak | 4bb656a | 2009-02-26 12:02:09 +0000 | [diff] [blame] | 39 | * |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 40 | * EXECUTED BY : anyone |
subrata_modak | 4bb656a | 2009-02-26 12:02:09 +0000 | [diff] [blame] | 41 | * |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 42 | * TEST TITLE : Basic errno test for mkdir(2) |
subrata_modak | 4bb656a | 2009-02-26 12:02:09 +0000 | [diff] [blame] | 43 | * |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 44 | * PARENT DOCUMENT : mkstds02 |
subrata_modak | 4bb656a | 2009-02-26 12:02:09 +0000 | [diff] [blame] | 45 | * |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 46 | * TEST CASE TOTAL : 2 |
subrata_modak | 4bb656a | 2009-02-26 12:02:09 +0000 | [diff] [blame] | 47 | * |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 48 | * WALL CLOCK TIME : 1 |
subrata_modak | 4bb656a | 2009-02-26 12:02:09 +0000 | [diff] [blame] | 49 | * |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 50 | * CPU TYPES : ALL |
subrata_modak | 4bb656a | 2009-02-26 12:02:09 +0000 | [diff] [blame] | 51 | * |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 52 | * AUTHOR : Bill Branum |
subrata_modak | 4bb656a | 2009-02-26 12:02:09 +0000 | [diff] [blame] | 53 | * |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 54 | * CO-PILOT : Kathy Olmsted |
subrata_modak | 4bb656a | 2009-02-26 12:02:09 +0000 | [diff] [blame] | 55 | * |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 56 | * DATE STARTED : 4/15/92 |
subrata_modak | 4bb656a | 2009-02-26 12:02:09 +0000 | [diff] [blame] | 57 | * |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 58 | * INITIAL RELEASE : UNICOS 7.0 |
subrata_modak | 4bb656a | 2009-02-26 12:02:09 +0000 | [diff] [blame] | 59 | * |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 60 | * TEST CASES |
subrata_modak | 4bb656a | 2009-02-26 12:02:09 +0000 | [diff] [blame] | 61 | * |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 62 | * mkdir(2) test for errno(s) EFAULT. |
subrata_modak | bdbaec5 | 2009-02-26 12:14:51 +0000 | [diff] [blame] | 63 | * |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 64 | * INPUT SPECIFICATIONS |
| 65 | * The standard options for system call tests are accepted. |
| 66 | * (See the parse_opts(3) man page). |
subrata_modak | 4bb656a | 2009-02-26 12:02:09 +0000 | [diff] [blame] | 67 | * |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 68 | * DURATION |
| 69 | * Terminates - with frequency and infinite modes. |
subrata_modak | 4bb656a | 2009-02-26 12:02:09 +0000 | [diff] [blame] | 70 | * |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 71 | * SIGNALS |
| 72 | * Uses SIGUSR1 to pause before test if option set. |
| 73 | * (See the parse_opts(3) man page). |
| 74 | * |
| 75 | * ENVIRONMENTAL NEEDS |
| 76 | * No run-time environmental needs. |
subrata_modak | 4bb656a | 2009-02-26 12:02:09 +0000 | [diff] [blame] | 77 | * |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 78 | * DETAILED DESCRIPTION |
| 79 | * This test will verify that mkdir(2) returns a value of |
| 80 | * -1 and sets errno to EFAULT when the path argument points |
| 81 | * outside (above/below) the allocated address space of the |
| 82 | * process. |
subrata_modak | 4bb656a | 2009-02-26 12:02:09 +0000 | [diff] [blame] | 83 | * |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 84 | * Setup: |
| 85 | * Setup signal handling. |
| 86 | * Create and make current a temporary directory. |
| 87 | * Pause for SIGUSR1 if option specified. |
subrata_modak | 4bb656a | 2009-02-26 12:02:09 +0000 | [diff] [blame] | 88 | * |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 89 | * Test: |
| 90 | * Loop if the proper options are given. |
| 91 | * Execute system call |
| 92 | * Check return code, if system call failed (return=-1) |
| 93 | * Log the errno. |
| 94 | * If doing functional test |
| 95 | * check the errno returned and print result message |
subrata_modak | 4bb656a | 2009-02-26 12:02:09 +0000 | [diff] [blame] | 96 | * |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 97 | * Cleanup: |
| 98 | * Print errno log and/or timing stats if options given |
| 99 | * Remove the temporary directory. |
| 100 | * Exit. |
subrata_modak | 4bb656a | 2009-02-26 12:02:09 +0000 | [diff] [blame] | 101 | * |
| 102 | * |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 103 | *#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#**/ |
| 104 | |
| 105 | #include <errno.h> |
| 106 | #include <string.h> |
| 107 | #include <signal.h> |
| 108 | #include <sys/stat.h> |
| 109 | #include <sys/types.h> |
plars | 1ad8451 | 2002-07-23 13:11:18 +0000 | [diff] [blame] | 110 | #include <sys/mman.h> |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 111 | #include <fcntl.h> |
| 112 | #include <unistd.h> |
| 113 | #include "test.h" |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 114 | |
| 115 | void setup(); |
| 116 | void cleanup(); |
| 117 | |
Cyril Hrubis | fdce7d5 | 2013-04-04 18:35:48 +0200 | [diff] [blame] | 118 | char *TCID = "mkdir01"; |
| 119 | int TST_TOTAL = 2; |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 120 | |
subrata_modak | 56207ce | 2009-03-23 13:35:39 +0000 | [diff] [blame] | 121 | char *bad_addr = 0; |
plars | 1ad8451 | 2002-07-23 13:11:18 +0000 | [diff] [blame] | 122 | |
subrata_modak | 56207ce | 2009-03-23 13:35:39 +0000 | [diff] [blame] | 123 | int main(int ac, char **av) |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 124 | { |
Cyril Hrubis | 89af32a | 2012-10-24 16:39:11 +0200 | [diff] [blame] | 125 | int lc; |
Cyril Hrubis | 0b9589f | 2014-05-27 17:40:33 +0200 | [diff] [blame] | 126 | const char *msg; |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 127 | |
Garrett Cooper | 45e285d | 2010-11-22 12:19:25 -0800 | [diff] [blame] | 128 | if ((msg = parse_opts(ac, av, NULL, NULL)) != NULL) |
Garrett Cooper | 60fa801 | 2010-11-22 13:50:58 -0800 | [diff] [blame] | 129 | tst_brkm(TBROK, NULL, "OPTION PARSING ERROR - %s", msg); |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 130 | |
subrata_modak | 56207ce | 2009-03-23 13:35:39 +0000 | [diff] [blame] | 131 | setup(); |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 132 | |
subrata_modak | 56207ce | 2009-03-23 13:35:39 +0000 | [diff] [blame] | 133 | for (lc = 0; TEST_LOOPING(lc); lc++) { |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 134 | |
Caspar Zhang | d59a659 | 2013-03-07 14:59:12 +0800 | [diff] [blame] | 135 | tst_count = 0; |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 136 | |
subrata_modak | 56207ce | 2009-03-23 13:35:39 +0000 | [diff] [blame] | 137 | /* |
| 138 | * TEST CASE: 1 |
| 139 | * mkdir() call with pointer below allocated address space. |
| 140 | */ |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 141 | |
subrata_modak | 56207ce | 2009-03-23 13:35:39 +0000 | [diff] [blame] | 142 | /* Call mkdir(2) */ |
| 143 | TEST(mkdir(bad_addr, 0777)); |
subrata_modak | bdbaec5 | 2009-02-26 12:14:51 +0000 | [diff] [blame] | 144 | |
subrata_modak | 56207ce | 2009-03-23 13:35:39 +0000 | [diff] [blame] | 145 | /* check return code */ |
| 146 | if (TEST_RETURN == -1) { |
subrata_modak | 56207ce | 2009-03-23 13:35:39 +0000 | [diff] [blame] | 147 | } |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 148 | |
Cyril Hrubis | e38b961 | 2014-06-02 17:20:57 +0200 | [diff] [blame] | 149 | if (TEST_RETURN == -1) { |
| 150 | if (TEST_ERRNO == EFAULT) { |
| 151 | tst_resm(TPASS, |
| 152 | "mkdir - path argument pointing below allocated address space failed as expected with errno %d : %s", |
| 153 | TEST_ERRNO, |
| 154 | strerror(TEST_ERRNO)); |
subrata_modak | 56207ce | 2009-03-23 13:35:39 +0000 | [diff] [blame] | 155 | } else { |
| 156 | tst_resm(TFAIL, |
Cyril Hrubis | e38b961 | 2014-06-02 17:20:57 +0200 | [diff] [blame] | 157 | "mkdir - path argument pointing below allocated address space failed with errno %d : %s but expected %d (EFAULT)", |
| 158 | TEST_ERRNO, |
| 159 | strerror(TEST_ERRNO), EFAULT); |
subrata_modak | 56207ce | 2009-03-23 13:35:39 +0000 | [diff] [blame] | 160 | } |
Cyril Hrubis | e38b961 | 2014-06-02 17:20:57 +0200 | [diff] [blame] | 161 | } else { |
| 162 | tst_resm(TFAIL, |
| 163 | "mkdir - path argument pointing below allocated address space succeeded unexpectedly."); |
| 164 | |
subrata_modak | 56207ce | 2009-03-23 13:35:39 +0000 | [diff] [blame] | 165 | } |
robbiew | d34d581 | 2005-07-11 22:28:09 +0000 | [diff] [blame] | 166 | #if !defined(UCLINUX) |
subrata_modak | 56207ce | 2009-03-23 13:35:39 +0000 | [diff] [blame] | 167 | /* |
| 168 | * TEST CASE: 2 |
| 169 | * mkdir() call with pointer above allocated address space. |
| 170 | */ |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 171 | |
subrata_modak | 56207ce | 2009-03-23 13:35:39 +0000 | [diff] [blame] | 172 | /* Call mkdir(2) */ |
| 173 | TEST(mkdir(get_high_address(), 0777)); |
subrata_modak | bdbaec5 | 2009-02-26 12:14:51 +0000 | [diff] [blame] | 174 | |
subrata_modak | 56207ce | 2009-03-23 13:35:39 +0000 | [diff] [blame] | 175 | /* check return code */ |
| 176 | if (TEST_RETURN == -1) { |
subrata_modak | 56207ce | 2009-03-23 13:35:39 +0000 | [diff] [blame] | 177 | } |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 178 | |
Cyril Hrubis | e38b961 | 2014-06-02 17:20:57 +0200 | [diff] [blame] | 179 | if (TEST_RETURN == -1) { |
| 180 | if (TEST_ERRNO == EFAULT) { |
| 181 | tst_resm(TPASS, |
| 182 | "mkdir - path argument pointing above allocated address space failed as expected with errno %d : %s", |
| 183 | TEST_ERRNO, |
| 184 | strerror(TEST_ERRNO)); |
subrata_modak | 56207ce | 2009-03-23 13:35:39 +0000 | [diff] [blame] | 185 | } else { |
| 186 | tst_resm(TFAIL, |
Cyril Hrubis | e38b961 | 2014-06-02 17:20:57 +0200 | [diff] [blame] | 187 | "mkdir - path argument pointing above allocated address space failed with errno %d : %s but expected %d (EFAULT)", |
| 188 | TEST_ERRNO, |
| 189 | strerror(TEST_ERRNO), EFAULT); |
subrata_modak | 56207ce | 2009-03-23 13:35:39 +0000 | [diff] [blame] | 190 | } |
Cyril Hrubis | e38b961 | 2014-06-02 17:20:57 +0200 | [diff] [blame] | 191 | } else { |
| 192 | tst_resm(TFAIL, |
| 193 | "mkdir - path argument pointing above allocated address space succeeded unexpectedly."); |
| 194 | |
subrata_modak | 56207ce | 2009-03-23 13:35:39 +0000 | [diff] [blame] | 195 | } |
robbiew | d34d581 | 2005-07-11 22:28:09 +0000 | [diff] [blame] | 196 | #endif /* if !defined(UCLINUX) */ |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 197 | |
Garrett Cooper | 2c28215 | 2010-12-16 00:55:50 -0800 | [diff] [blame] | 198 | } |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 199 | |
subrata_modak | 56207ce | 2009-03-23 13:35:39 +0000 | [diff] [blame] | 200 | cleanup(); |
Garrett Cooper | 1e6f5a6 | 2010-12-19 09:58:10 -0800 | [diff] [blame] | 201 | tst_exit(); |
Garrett Cooper | 43088e1 | 2010-12-13 23:30:59 -0800 | [diff] [blame] | 202 | } |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 203 | |
| 204 | /*************************************************************** |
| 205 | * setup() - performs all ONE TIME setup for this test. |
| 206 | ***************************************************************/ |
Mike Frysinger | c57fba5 | 2014-04-09 18:56:30 -0400 | [diff] [blame] | 207 | void setup(void) |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 208 | { |
Garrett Cooper | 2c28215 | 2010-12-16 00:55:50 -0800 | [diff] [blame] | 209 | |
subrata_modak | 56207ce | 2009-03-23 13:35:39 +0000 | [diff] [blame] | 210 | tst_sig(NOFORK, DEF_HANDLER, cleanup); |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 211 | |
subrata_modak | 56207ce | 2009-03-23 13:35:39 +0000 | [diff] [blame] | 212 | TEST_PAUSE; |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 213 | |
subrata_modak | 56207ce | 2009-03-23 13:35:39 +0000 | [diff] [blame] | 214 | /* Create a temporary directory and make it current. */ |
| 215 | tst_tmpdir(); |
plars | 1ad8451 | 2002-07-23 13:11:18 +0000 | [diff] [blame] | 216 | |
subrata_modak | 56207ce | 2009-03-23 13:35:39 +0000 | [diff] [blame] | 217 | bad_addr = mmap(0, 1, PROT_NONE, |
| 218 | MAP_PRIVATE_EXCEPT_UCLINUX | MAP_ANONYMOUS, 0, 0); |
| 219 | if (bad_addr == MAP_FAILED) { |
| 220 | tst_brkm(TBROK, cleanup, "mmap failed"); |
| 221 | } |
Garrett Cooper | 2c28215 | 2010-12-16 00:55:50 -0800 | [diff] [blame] | 222 | } |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 223 | |
| 224 | /*************************************************************** |
| 225 | * cleanup() - performs all ONE TIME cleanup for this test at |
| 226 | * completion or premature exit. |
| 227 | ***************************************************************/ |
Mike Frysinger | c57fba5 | 2014-04-09 18:56:30 -0400 | [diff] [blame] | 228 | void cleanup(void) |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 229 | { |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 230 | |
subrata_modak | 56207ce | 2009-03-23 13:35:39 +0000 | [diff] [blame] | 231 | /* |
| 232 | * Remove the temporary directory. |
| 233 | */ |
| 234 | tst_rmdir(); |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 235 | |
subrata_modak | 56207ce | 2009-03-23 13:35:39 +0000 | [diff] [blame] | 236 | /* |
| 237 | * Exit with return code appropriate for results. |
| 238 | */ |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 239 | |
Chris Dearman | ec6edca | 2012-10-17 19:54:01 -0700 | [diff] [blame] | 240 | } |