1 /* 2 * 3 * Copyright (c) International Business Machines Corp., 2001 4 * 5 * This program is free software; you can redistribute it and/or modify 6 * it under the terms of the GNU General Public License as published by 7 * the Free Software Foundation; either version 2 of the License, or 8 * (at your option) any later version. 9 * 10 * This program is distributed in the hope that it will be useful, 11 * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See 13 * the GNU General Public License for more details. 14 * 15 * You should have received a copy of the GNU General Public License 16 * along with this program; if not, write to the Free Software 17 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA 18 */ 19 20 /* 21 * NAME 22 * rename06 23 * 24 * DESCRIPTION 25 * This test will verify that rename(2) failed in EINVAL 26 * 27 * ALGORITHM 28 * Setup: 29 * Setup signal handling. 30 * Create temporary directory. 31 * Pause for SIGUSR1 if option specified. 32 * create the "old" directory 33 * create the "new" directory under the "old" directory 34 * 35 * Test: 36 * Loop if the proper options are given. 37 * rename the "old" to the "new" directory 38 * verify rename() failed and returned EINVAL 39 * 40 * Cleanup: 41 * Print errno log and/or timing stats if options given 42 * Delete the temporary directory created. 43 * 44 * USAGE 45 * rename06 [-c n] [-e] [-i n] [-I x] [-P x] [-t] 46 * where, -c n : Run n copies concurrently. 47 * -e : Turn on errno logging. 48 * -i n : Execute test n times. 49 * -I x : Execute test for x seconds. 50 * -P x : Pause for x seconds between iterations. 51 * -t : Turn on syscall timing. 52 * 53 * HISTORY 54 * 07/2001 Ported by Wayne Boyer 55 * 56 * RESTRICTIONS 57 * None. 58 */ 59 #include <sys/types.h> 60 #include <sys/fcntl.h> 61 #include <sys/stat.h> 62 #include <unistd.h> 63 #include <errno.h> 64 65 #include "test.h" 66 67 void setup(); 68 void cleanup(); 69 70 char *TCID = "rename06"; 71 int TST_TOTAL = 1; 72 73 int fd; 74 char fdir[255], mdir[255]; 75 struct stat buf1, buf2; 76 dev_t olddev, olddev1; 77 ino_t oldino, oldino1; 78 79 int main(int ac, char **av) 80 { 81 int lc; 82 83 /* 84 * parse standard options 85 */ 86 tst_parse_opts(ac, av, NULL, NULL); 87 88 /* 89 * perform global setup for test 90 */ 91 setup(); 92 93 /* 94 * check looping state if -i option given 95 */ 96 for (lc = 0; TEST_LOOPING(lc); lc++) { 97 98 tst_count = 0; 99 100 /* rename a directory to a subdirectory of itself */ 101 /* Call rename(2) */ 102 TEST(rename(fdir, mdir)); 103 104 if (TEST_RETURN != -1) { 105 tst_resm(TFAIL, "rename(%s, %s) succeed unexpected", 106 fdir, mdir); 107 continue; 108 } 109 110 if (errno != EINVAL) { 111 tst_resm(TFAIL, "Expected EINVAL got %d", TEST_ERRNO); 112 } else { 113 tst_resm(TPASS, "rename() returned EINVAL"); 114 } 115 } 116 117 cleanup(); 118 tst_exit(); 119 120 } 121 122 /* 123 * setup() - performs all ONE TIME setup for this test. 124 */ 125 void setup(void) 126 { 127 128 tst_sig(NOFORK, DEF_HANDLER, cleanup); 129 130 TEST_PAUSE; 131 132 /* Create a temporary directory and make it current. */ 133 tst_tmpdir(); 134 135 sprintf(fdir, "./tdir_%d", getpid()); 136 sprintf(mdir, "%s/rndir_%d", fdir, getpid()); 137 138 /* create "old" directory */ 139 if (stat(fdir, &buf1) != -1) { 140 tst_brkm(TBROK, cleanup, "tmp directory %s found!", fdir); 141 } 142 if (mkdir(fdir, 00770) == -1) { 143 tst_brkm(TBROK, cleanup, "Could not create directory %s", fdir); 144 } 145 if (stat(fdir, &buf1) == -1) { 146 tst_brkm(TBROK, cleanup, "failed to stat directory %s " 147 "in rename()", fdir); 148 149 } 150 /* save "old"'s dev and ino */ 151 olddev = buf1.st_dev; 152 oldino = buf1.st_ino; 153 154 /* create another directory */ 155 if (stat(mdir, &buf2) != -1) { 156 tst_brkm(TBROK, cleanup, "tmp directory %s found!", mdir); 157 } 158 if (mkdir(mdir, 00770) == -1) { 159 tst_brkm(TBROK, cleanup, "Could not create directory %s", mdir); 160 } 161 162 if (stat(mdir, &buf2) == -1) { 163 tst_brkm(TBROK, cleanup, "failed to stat directory %s " 164 "in rename()", mdir); 165 166 } 167 168 /* save "new"'s dev and ino */ 169 olddev1 = buf2.st_dev; 170 oldino1 = buf2.st_ino; 171 } 172 173 /* 174 * cleanup() - performs all ONE TIME cleanup for this test at 175 * completion or premature exit. 176 */ 177 void cleanup(void) 178 { 179 180 /* 181 * Remove the temporary directory. 182 */ 183 tst_rmdir(); 184 } 185