1 /* 2 * NAME 3 * rename07 4 * 5 * DESCRIPTION 6 * This test will verify that rename(2) failed in ENOTDIR 7 * 8 * CALLS 9 * stat,open,rename,mkdir,close 10 * 11 * ALGORITHM 12 * Setup: 13 * Setup signal handling. 14 * Create temporary directory. 15 * Pause for SIGUSR1 if option specified. 16 * create the "old" directory and the "new" file 17 * rename the "old" directory to the "new" file 18 * 19 * Test: 20 * Loop if the proper options are given. 21 * verify rename() failed and returned ENOTDIR 22 * 23 * Cleanup: 24 * Print errno log and/or timing stats if options given 25 * Delete the temporary directory created.* 26 * USAGE 27 * rename07 [-c n] [-e] [-i n] [-I x] [-p x] [-t] 28 * where, -c n : Run n copies concurrently. 29 * -e : Turn on errno logging. 30 * -i n : Execute test n times. 31 * -I x : Execute test for x seconds. 32 * -P x : Pause for x seconds between iterations. 33 * -t : Turn on syscall timing. 34 * 35 * HISTORY 36 * 07/2001 Ported by Wayne Boyer 37 * 38 * RESTRICTIONS 39 * None. 40 */ 41 #include <sys/types.h> 42 #include <fcntl.h> 43 #include <sys/stat.h> 44 #include <unistd.h> 45 #include <errno.h> 46 47 #include "test.h" 48 #include "safe_macros.h" 49 50 void setup(); 51 void cleanup(); 52 53 char *TCID = "rename07"; 54 int TST_TOTAL = 1; 55 56 int fd; 57 char mname[255], fdir[255]; 58 struct stat buf1, buf2; 59 dev_t olddev, olddev1; 60 ino_t oldino, oldino1; 61 62 int main(int ac, char **av) 63 { 64 int lc; 65 66 /* 67 * parse standard options 68 */ 69 tst_parse_opts(ac, av, NULL, NULL); 70 71 /* 72 * perform global setup for test 73 */ 74 setup(); 75 76 /* 77 * check looping state if -i option given 78 */ 79 for (lc = 0; TEST_LOOPING(lc); lc++) { 80 81 tst_count = 0; 82 83 /* rename a directory to a file */ 84 /* Call rename(2) */ 85 TEST(rename(fdir, mname)); 86 87 if (TEST_RETURN != -1) { 88 tst_resm(TFAIL, "rename(%s, %s) succeeded unexpectedly", 89 fdir, mname); 90 continue; 91 } 92 93 if (TEST_ERRNO != ENOTDIR) { 94 tst_resm(TFAIL, "Expected ENOTDIR got %d", TEST_ERRNO); 95 } else { 96 tst_resm(TPASS, "rename() returned ENOTDIR"); 97 } 98 } 99 100 cleanup(); 101 tst_exit(); 102 103 } 104 105 /* 106 * setup() - performs all ONE TIME setup for this test. 107 */ 108 void setup(void) 109 { 110 111 tst_sig(NOFORK, DEF_HANDLER, cleanup); 112 113 TEST_PAUSE; 114 115 /* Create a temporary directory and make it current. */ 116 tst_tmpdir(); 117 118 sprintf(fdir, "./rndir_%d", getpid()); 119 sprintf(mname, "./tfile_%d", getpid()); 120 121 /* create "old" directory */ 122 if (stat(fdir, &buf1) != -1) { 123 tst_brkm(TBROK, cleanup, "tmp directory %s found!", fdir); 124 } 125 126 SAFE_MKDIR(cleanup, fdir, 00770); 127 128 SAFE_STAT(cleanup, fdir, &buf1); 129 130 /* save "old"'s dev and ino */ 131 olddev = buf1.st_dev; 132 oldino = buf1.st_ino; 133 134 SAFE_TOUCH(cleanup, mname, 0700, NULL); 135 136 SAFE_STAT(cleanup, mname, &buf2); 137 138 /* save "new"'s dev and ino */ 139 olddev1 = buf2.st_dev; 140 oldino1 = buf2.st_ino; 141 } 142 143 /* 144 * cleanup() - performs all ONE TIME cleanup for this test at 145 * completion or premature exit. 146 */ 147 void cleanup(void) 148 { 149 150 /* 151 * Remove the temporary directory. 152 */ 153 tst_rmdir(); 154 } 155