vapier | d13d74b | 2006-02-11 07:24:00 +0000 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (c) Wipro Technologies Ltd, 2002. 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 | * You should have received a copy of the GNU General Public License along |
| 13 | * with this program; if not, write the Free Software Foundation, Inc., 59 |
| 14 | * Temple Place - Suite 330, Boston MA 02111-1307, USA. |
| 15 | * |
| 16 | */ |
| 17 | /****************************************************************************** |
subrata_modak | 4bb656a | 2009-02-26 12:02:09 +0000 | [diff] [blame] | 18 | * |
vapier | d13d74b | 2006-02-11 07:24:00 +0000 | [diff] [blame] | 19 | * TEST IDENTIFIER : umount02 |
subrata_modak | 4bb656a | 2009-02-26 12:02:09 +0000 | [diff] [blame] | 20 | * |
vapier | d13d74b | 2006-02-11 07:24:00 +0000 | [diff] [blame] | 21 | * EXECUTED BY : root / superuser |
subrata_modak | 4bb656a | 2009-02-26 12:02:09 +0000 | [diff] [blame] | 22 | * |
vapier | d13d74b | 2006-02-11 07:24:00 +0000 | [diff] [blame] | 23 | * TEST TITLE : Test for checking basic error conditions for umount(2) |
subrata_modak | 4bb656a | 2009-02-26 12:02:09 +0000 | [diff] [blame] | 24 | * |
vapier | d13d74b | 2006-02-11 07:24:00 +0000 | [diff] [blame] | 25 | * TEST CASE TOTAL : 5 |
subrata_modak | 4bb656a | 2009-02-26 12:02:09 +0000 | [diff] [blame] | 26 | * |
vapier | d13d74b | 2006-02-11 07:24:00 +0000 | [diff] [blame] | 27 | * AUTHOR : Nirmala Devi Dhanasekar <nirmala.devi@wipro.com> |
subrata_modak | 4bb656a | 2009-02-26 12:02:09 +0000 | [diff] [blame] | 28 | * |
vapier | d13d74b | 2006-02-11 07:24:00 +0000 | [diff] [blame] | 29 | * SIGNALS |
| 30 | * Uses SIGUSR1 to pause before test if option set. |
| 31 | * (See the parse_opts(3) man page). |
| 32 | * |
| 33 | * DESCRIPTION |
| 34 | * Check for basic errors returned by umount(2) system call. |
| 35 | * |
| 36 | * Verify that umount(2) returns -1 and sets errno to |
| 37 | * |
| 38 | * 1) EBUSY if it cannot be umounted, because dir is still busy. |
| 39 | * 2) EFAULT if specialfile or device file points to invalid address space. |
| 40 | * 3) ENOENT if pathname was empty or has a nonexistent component. |
subrata_modak | 4bb656a | 2009-02-26 12:02:09 +0000 | [diff] [blame] | 41 | * 4) EINVAL if specialfile or device is invalid or not a mount point. |
vapier | d13d74b | 2006-02-11 07:24:00 +0000 | [diff] [blame] | 42 | * 5) ENAMETOOLONG if pathname was longer than MAXPATHLEN. |
subrata_modak | bdbaec5 | 2009-02-26 12:14:51 +0000 | [diff] [blame] | 43 | * |
vapier | d13d74b | 2006-02-11 07:24:00 +0000 | [diff] [blame] | 44 | * Setup: |
| 45 | * Setup signal handling. |
| 46 | * Create a mount point. |
| 47 | * Pause for SIGUSR1 if option specified. |
subrata_modak | 4bb656a | 2009-02-26 12:02:09 +0000 | [diff] [blame] | 48 | * |
vapier | d13d74b | 2006-02-11 07:24:00 +0000 | [diff] [blame] | 49 | * Test: |
| 50 | * Loop if the proper options are given. |
| 51 | * Do necessary setup for each test. |
| 52 | * Execute system call |
| 53 | * Check return code, if system call failed and errno == expected errno |
| 54 | * Issue sys call passed with expected return value and errno. |
| 55 | * Otherwise, |
| 56 | * Issue sys call failed to produce expected error. |
| 57 | * Do cleanup for each test. |
subrata_modak | 4bb656a | 2009-02-26 12:02:09 +0000 | [diff] [blame] | 58 | * |
vapier | d13d74b | 2006-02-11 07:24:00 +0000 | [diff] [blame] | 59 | * Cleanup: |
| 60 | * Print errno log and/or timing stats if options given |
| 61 | * Delete the temporary directory(s)/file(s) created. |
subrata_modak | 4bb656a | 2009-02-26 12:02:09 +0000 | [diff] [blame] | 62 | * |
vapier | d13d74b | 2006-02-11 07:24:00 +0000 | [diff] [blame] | 63 | * USAGE: <for command-line> |
| 64 | * umount02 [-T type] -D device [-e] [-i n] [-I x] [-p x] [-t] |
| 65 | * where, -T type : specifies the type of filesystem to |
| 66 | * be mounted. Default ext2. |
| 67 | * -D device : device to be mounted. |
| 68 | * -e : Turn on errno logging. |
| 69 | * -i n : Execute test n times. |
| 70 | * -I x : Execute test for x seconds. |
| 71 | * -p : Pause for SIGUSR1 before starting |
| 72 | * -P x : Pause for x seconds between iterations. |
| 73 | * -t : Turn on syscall timing. |
| 74 | * |
| 75 | * RESTRICTIONS |
| 76 | * test must be run with the -D option |
| 77 | * test doesn't support -c option to run it in parallel, as mount |
| 78 | * syscall is not supposed to run in parallel. |
| 79 | *****************************************************************************/ |
| 80 | |
| 81 | #include <errno.h> |
| 82 | #include <sys/mount.h> |
| 83 | #include <sys/types.h> |
| 84 | #include <sys/stat.h> |
| 85 | #include <sys/fcntl.h> |
| 86 | #include <pwd.h> |
| 87 | #include "test.h" |
| 88 | #include "usctest.h" |
| 89 | |
| 90 | static void help(void); |
| 91 | static void setup(void); |
| 92 | static void cleanup(void); |
| 93 | |
| 94 | static int setup_test(int, int); |
| 95 | static int cleanup_test(int); |
| 96 | |
subrata_modak | 56207ce | 2009-03-23 13:35:39 +0000 | [diff] [blame] | 97 | char *TCID = "umount02"; /* Test program identifier. */ |
| 98 | extern int Tst_count; /* TestCase counter for tst_* routine */ |
vapier | d13d74b | 2006-02-11 07:24:00 +0000 | [diff] [blame] | 99 | |
| 100 | #define DEFAULT_FSTYPE "ext2" |
| 101 | #define FSTYPE_LEN 20 |
| 102 | #define DIR_MODE S_IRWXU | S_IRWXG | S_IROTH | S_IXOTH |
| 103 | #define FILE_MODE S_IRWXU | S_IRWXG | S_IRWXO |
| 104 | |
subrata_modak | 56207ce | 2009-03-23 13:35:39 +0000 | [diff] [blame] | 105 | static char *Einval = "nonexixstent"; |
| 106 | static char Longpathname[PATH_MAX + 2]; |
| 107 | static char Path[PATH_MAX]; |
| 108 | static char *Type; |
| 109 | static char *Fstype; |
| 110 | static char *Device; |
| 111 | static char *Mntpoint; |
vapier | d13d74b | 2006-02-11 07:24:00 +0000 | [diff] [blame] | 112 | static unsigned long Flag; |
| 113 | |
subrata_modak | 56207ce | 2009-03-23 13:35:39 +0000 | [diff] [blame] | 114 | static int fd; |
| 115 | static char mntpoint[PATH_MAX]; |
| 116 | static char *fstype; |
| 117 | static char *device; |
| 118 | static int Tflag = 0; |
| 119 | static int Dflag = 0; |
vapier | d13d74b | 2006-02-11 07:24:00 +0000 | [diff] [blame] | 120 | |
| 121 | static struct test_case_t { |
subrata_modak | 56207ce | 2009-03-23 13:35:39 +0000 | [diff] [blame] | 122 | char *err_desc; /* error description */ |
| 123 | int exp_errno; /* Expected error no */ |
| 124 | char *exp_errval; /* Expected error value string */ |
vapier | d13d74b | 2006-02-11 07:24:00 +0000 | [diff] [blame] | 125 | } testcases[] = { |
subrata_modak | 56207ce | 2009-03-23 13:35:39 +0000 | [diff] [blame] | 126 | { |
| 127 | "Already mounted/busy", EBUSY, "EBUSY"}, { |
| 128 | "Invalid address space", EFAULT, "EFAULT"}, { |
| 129 | "Directory not found", ENOENT, "ENOENT"}, { |
| 130 | "Invalid device ", EINVAL, "EINVAL"}, { |
| 131 | "Pathname too long", ENAMETOOLONG, "ENAMETOOLONG"} |
vapier | d13d74b | 2006-02-11 07:24:00 +0000 | [diff] [blame] | 132 | }; |
| 133 | |
| 134 | /* Total number of test cases. */ |
| 135 | int TST_TOTAL = sizeof(testcases) / sizeof(testcases[0]); |
| 136 | |
| 137 | static int exp_enos[] = { EBUSY, EINVAL, EFAULT, ENAMETOOLONG, ENOENT, 0 }; |
| 138 | |
subrata_modak | 56207ce | 2009-03-23 13:35:39 +0000 | [diff] [blame] | 139 | static option_t options[] = { /* options supported by umount02 test */ |
| 140 | {"T:", &Tflag, &fstype}, /* -T type of filesystem */ |
| 141 | {"D:", &Dflag, &device}, /* -D device used for mounting */ |
| 142 | {NULL, NULL, NULL} |
vapier | d13d74b | 2006-02-11 07:24:00 +0000 | [diff] [blame] | 143 | }; |
| 144 | |
subrata_modak | 56207ce | 2009-03-23 13:35:39 +0000 | [diff] [blame] | 145 | int main(int ac, char **av) |
vapier | d13d74b | 2006-02-11 07:24:00 +0000 | [diff] [blame] | 146 | { |
subrata_modak | 56207ce | 2009-03-23 13:35:39 +0000 | [diff] [blame] | 147 | int lc, i; /* loop counter */ |
| 148 | char *msg; /* message returned from parse_opts */ |
vapier | d13d74b | 2006-02-11 07:24:00 +0000 | [diff] [blame] | 149 | |
| 150 | /* parse standard options */ |
Garrett Cooper | 45e285d | 2010-11-22 12:19:25 -0800 | [diff] [blame^] | 151 | if ((msg = parse_opts(ac, av, options, &help)) != NULL) { |
vapier | d13d74b | 2006-02-11 07:24:00 +0000 | [diff] [blame] | 152 | tst_brkm(TBROK, NULL, "OPTION PARSING ERROR - %s", msg); |
| 153 | tst_exit(); |
| 154 | } |
| 155 | |
| 156 | /* Check for mandatory option of the testcase */ |
| 157 | if (Dflag == 0) { |
| 158 | tst_brkm(TBROK, NULL, "You must specifiy the device used for " |
| 159 | " mounting with -D option, Run '%s -h' for option " |
| 160 | " information.", TCID); |
| 161 | tst_exit(); |
| 162 | } |
| 163 | |
subrata_modak | 56207ce | 2009-03-23 13:35:39 +0000 | [diff] [blame] | 164 | Type = (char *)malloc(FSTYPE_LEN); |
vapier | d13d74b | 2006-02-11 07:24:00 +0000 | [diff] [blame] | 165 | if (!Type) { |
| 166 | tst_brkm(TBROK, NULL, "malloc - alloc of %d failed", |
| 167 | FSTYPE_LEN); |
| 168 | tst_exit(); |
| 169 | } |
| 170 | |
| 171 | if (Tflag == 1) { |
| 172 | strncpy(Type, fstype, |
subrata_modak | 56207ce | 2009-03-23 13:35:39 +0000 | [diff] [blame] | 173 | (FSTYPE_LEN < |
subrata_modak | 344d5c3 | 2009-05-13 07:12:43 +0000 | [diff] [blame] | 174 | (strlen(fstype)+1)) ? FSTYPE_LEN : (strlen(fstype)+1)); |
vapier | d13d74b | 2006-02-11 07:24:00 +0000 | [diff] [blame] | 175 | } else { |
subrata_modak | 344d5c3 | 2009-05-13 07:12:43 +0000 | [diff] [blame] | 176 | strncpy(Type, DEFAULT_FSTYPE, strlen(DEFAULT_FSTYPE)+1); |
vapier | d13d74b | 2006-02-11 07:24:00 +0000 | [diff] [blame] | 177 | } |
| 178 | |
subrata_modak | 56207ce | 2009-03-23 13:35:39 +0000 | [diff] [blame] | 179 | if (STD_COPIES != 1) { |
vapier | d13d74b | 2006-02-11 07:24:00 +0000 | [diff] [blame] | 180 | tst_resm(TINFO, "-c option has no effect for this testcase - " |
| 181 | "%s doesn't allow running more than one instance " |
| 182 | "at a time", TCID); |
| 183 | STD_COPIES = 1; |
| 184 | } |
| 185 | |
| 186 | /* perform global setup for test */ |
| 187 | setup(); |
| 188 | |
vapier | d13d74b | 2006-02-11 07:24:00 +0000 | [diff] [blame] | 189 | /* check looping state if -i option given */ |
| 190 | for (lc = 0; TEST_LOOPING(lc); lc++) { |
| 191 | |
| 192 | /* reset Tst_count in case we are looping. */ |
| 193 | Tst_count = 0; |
| 194 | |
| 195 | for (i = 0; i < TST_TOTAL; ++i) { |
| 196 | |
| 197 | if (setup_test(i, lc)) { |
| 198 | tst_resm(TWARN, "Not able to test mount(2) for " |
| 199 | "error %s as setup failed", |
| 200 | testcases[i].exp_errval); |
| 201 | continue; |
| 202 | } |
| 203 | |
| 204 | /* Call umount(2) to test different test conditions. |
| 205 | * verify that it fails with -1 return value and |
| 206 | * sets appropriate errno.*/ |
| 207 | |
| 208 | TEST(umount(Mntpoint)); |
| 209 | |
| 210 | /* check return code */ |
subrata_modak | 4bb656a | 2009-02-26 12:02:09 +0000 | [diff] [blame] | 211 | if ((TEST_RETURN == -1) && |
vapier | d13d74b | 2006-02-11 07:24:00 +0000 | [diff] [blame] | 212 | (TEST_ERRNO == testcases[i].exp_errno)) { |
| 213 | tst_resm(TPASS, "umount(2) expected failure; " |
subrata_modak | 56207ce | 2009-03-23 13:35:39 +0000 | [diff] [blame] | 214 | "Got errno - %s : %s", |
vapier | d13d74b | 2006-02-11 07:24:00 +0000 | [diff] [blame] | 215 | testcases[i].exp_errval, |
| 216 | testcases[i].err_desc); |
| 217 | } else { |
| 218 | tst_resm(TFAIL, "umount(2) failed to produce " |
subrata_modak | 56207ce | 2009-03-23 13:35:39 +0000 | [diff] [blame] | 219 | "expected error; %d, errno:%s got %d", |
vapier | d13d74b | 2006-02-11 07:24:00 +0000 | [diff] [blame] | 220 | testcases[i].exp_errno, |
| 221 | testcases[i].exp_errval, TEST_ERRNO); |
| 222 | } |
| 223 | |
| 224 | TEST_ERROR_LOG(TEST_ERRNO); |
| 225 | |
subrata_modak | 56207ce | 2009-03-23 13:35:39 +0000 | [diff] [blame] | 226 | (void)cleanup_test(i); |
vapier | d13d74b | 2006-02-11 07:24:00 +0000 | [diff] [blame] | 227 | |
subrata_modak | 56207ce | 2009-03-23 13:35:39 +0000 | [diff] [blame] | 228 | } /* End of TEST CASE LOOPING. */ |
| 229 | } /* End for TEST_LOOPING */ |
vapier | d13d74b | 2006-02-11 07:24:00 +0000 | [diff] [blame] | 230 | |
| 231 | /* cleanup and exit */ |
| 232 | cleanup(); |
| 233 | |
subrata_modak | 56207ce | 2009-03-23 13:35:39 +0000 | [diff] [blame] | 234 | /*NOTREACHED*/ return 0; |
vapier | d13d74b | 2006-02-11 07:24:00 +0000 | [diff] [blame] | 235 | |
subrata_modak | 56207ce | 2009-03-23 13:35:39 +0000 | [diff] [blame] | 236 | } /* End main */ |
vapier | d13d74b | 2006-02-11 07:24:00 +0000 | [diff] [blame] | 237 | |
| 238 | /* |
| 239 | * int |
| 240 | * setup_test() - Setup function for test cases based on the error values |
| 241 | * to be returned. |
| 242 | */ |
subrata_modak | 56207ce | 2009-03-23 13:35:39 +0000 | [diff] [blame] | 243 | int setup_test(int i, int cnt) |
vapier | d13d74b | 2006-02-11 07:24:00 +0000 | [diff] [blame] | 244 | { |
subrata_modak | 56207ce | 2009-03-23 13:35:39 +0000 | [diff] [blame] | 245 | char temp[20]; |
vapier | d13d74b | 2006-02-11 07:24:00 +0000 | [diff] [blame] | 246 | |
| 247 | Device = device; |
| 248 | Fstype = Type; |
| 249 | Mntpoint = mntpoint; |
| 250 | Flag = 0; |
| 251 | |
subrata_modak | 56207ce | 2009-03-23 13:35:39 +0000 | [diff] [blame] | 252 | switch (i) { |
vapier | d13d74b | 2006-02-11 07:24:00 +0000 | [diff] [blame] | 253 | case 0: |
| 254 | /* Setup for umount(2) returning errno EBUSY. */ |
subrata_modak | 344d5c3 | 2009-05-13 07:12:43 +0000 | [diff] [blame] | 255 | if(access(Device,F_OK)) { |
| 256 | tst_brkm(TBROK, cleanup, |
| 257 | "Device %s does not exist", Device); |
| 258 | return 1; |
| 259 | } |
vapier | d13d74b | 2006-02-11 07:24:00 +0000 | [diff] [blame] | 260 | |
| 261 | TEST(mount(Device, Mntpoint, Fstype, Flag, NULL)); |
| 262 | |
| 263 | if (TEST_RETURN == -1) { |
| 264 | tst_brkm(TBROK, cleanup, "mount(2) failed to mount " |
subrata_modak | 344d5c3 | 2009-05-13 07:12:43 +0000 | [diff] [blame] | 265 | "device %s at mountpoint %s, Got errno - %d :" |
vapier | d13d74b | 2006-02-11 07:24:00 +0000 | [diff] [blame] | 266 | " %s", Device, Mntpoint, TEST_ERRNO, |
| 267 | strerror(TEST_ERRNO)); |
| 268 | return 1; |
| 269 | } |
| 270 | |
| 271 | if (getcwd(Path, PATH_MAX) == NULL) { |
| 272 | tst_resm(TWARN, "getcwd() failed to get current working" |
subrata_modak | 56207ce | 2009-03-23 13:35:39 +0000 | [diff] [blame] | 273 | " directory errno = %d : %s", errno, |
| 274 | strerror(errno)); |
vapier | d13d74b | 2006-02-11 07:24:00 +0000 | [diff] [blame] | 275 | return 1; |
| 276 | } |
subrata_modak | 56207ce | 2009-03-23 13:35:39 +0000 | [diff] [blame] | 277 | sprintf(temp, "/%s/t_%d", Mntpoint, cnt); |
vapier | d13d74b | 2006-02-11 07:24:00 +0000 | [diff] [blame] | 278 | strcat(Path, temp); |
subrata_modak | 56207ce | 2009-03-23 13:35:39 +0000 | [diff] [blame] | 279 | if ((fd = open(Path, O_CREAT | O_RDWR, S_IRWXU)) == -1) { |
vapier | d13d74b | 2006-02-11 07:24:00 +0000 | [diff] [blame] | 280 | tst_resm(TWARN, "open() failed to create a file " |
| 281 | " %s errno = %d : %s", Path, errno, |
subrata_modak | 56207ce | 2009-03-23 13:35:39 +0000 | [diff] [blame] | 282 | strerror(errno)); |
vapier | d13d74b | 2006-02-11 07:24:00 +0000 | [diff] [blame] | 283 | return 1; |
| 284 | } else { |
| 285 | return 0; |
| 286 | } |
| 287 | case 1: |
| 288 | |
| 289 | /* Setup for umount(2) returning errno EFAULT. */ |
| 290 | |
| 291 | Mntpoint = NULL; |
| 292 | break; |
| 293 | case 2: |
| 294 | /* Setup for umount(2) returning errno ENOENT. */ |
| 295 | |
| 296 | Mntpoint = Einval; |
| 297 | break; |
| 298 | case 3: |
| 299 | /* Setup for umount(2) returning errno EINVAL. */ |
| 300 | |
| 301 | if (getcwd(Path, PATH_MAX) == NULL) { |
| 302 | tst_resm(TWARN, "getcwd() failed to get current working" |
subrata_modak | 56207ce | 2009-03-23 13:35:39 +0000 | [diff] [blame] | 303 | " directory errno = %d : %s", errno, |
| 304 | strerror(errno)); |
vapier | d13d74b | 2006-02-11 07:24:00 +0000 | [diff] [blame] | 305 | return 1; |
| 306 | } |
| 307 | Mntpoint = Path; |
| 308 | break; |
| 309 | case 4: |
| 310 | /* Setup for umount(2) returning errno ENAMETOOLONG. */ |
| 311 | |
subrata_modak | 56207ce | 2009-03-23 13:35:39 +0000 | [diff] [blame] | 312 | memset(Longpathname, 'a', PATH_MAX + 2); |
vapier | d13d74b | 2006-02-11 07:24:00 +0000 | [diff] [blame] | 313 | Mntpoint = Longpathname; |
| 314 | break; |
| 315 | } |
| 316 | return 0; |
| 317 | } |
| 318 | |
vapier | d13d74b | 2006-02-11 07:24:00 +0000 | [diff] [blame] | 319 | /* |
| 320 | * int |
| 321 | * cleanup_test() - Setup function for test cases based on the error values |
| 322 | * to be returned. |
| 323 | */ |
subrata_modak | 56207ce | 2009-03-23 13:35:39 +0000 | [diff] [blame] | 324 | int cleanup_test(int i) |
vapier | d13d74b | 2006-02-11 07:24:00 +0000 | [diff] [blame] | 325 | { |
subrata_modak | 56207ce | 2009-03-23 13:35:39 +0000 | [diff] [blame] | 326 | switch (i) { |
vapier | d13d74b | 2006-02-11 07:24:00 +0000 | [diff] [blame] | 327 | case 0: |
| 328 | close(fd); |
| 329 | TEST(umount(mntpoint)); |
| 330 | if (TEST_RETURN != 0) { |
| 331 | tst_resm(TWARN, "umount(2) Failed while unmounting" |
| 332 | " errno %d for testcase %s", TEST_ERRNO, |
subrata_modak | 56207ce | 2009-03-23 13:35:39 +0000 | [diff] [blame] | 333 | testcases[i].exp_errval); |
vapier | d13d74b | 2006-02-11 07:24:00 +0000 | [diff] [blame] | 334 | } |
| 335 | break; |
| 336 | } |
| 337 | return 0; |
| 338 | } |
vapier | d13d74b | 2006-02-11 07:24:00 +0000 | [diff] [blame] | 339 | |
| 340 | /* setup() - performs all ONE TIME setup for this test */ |
subrata_modak | 56207ce | 2009-03-23 13:35:39 +0000 | [diff] [blame] | 341 | void setup() |
vapier | d13d74b | 2006-02-11 07:24:00 +0000 | [diff] [blame] | 342 | { |
| 343 | /* capture signals */ |
| 344 | tst_sig(FORK, DEF_HANDLER, cleanup); |
| 345 | |
subrata_modak | 56207ce | 2009-03-23 13:35:39 +0000 | [diff] [blame] | 346 | /* Check whether we are root */ |
vapier | d13d74b | 2006-02-11 07:24:00 +0000 | [diff] [blame] | 347 | if (geteuid() != 0) { |
| 348 | if (Type != NULL) { |
| 349 | free(Type); |
| 350 | } |
| 351 | tst_brkm(TBROK, tst_exit, "Test must be run as root"); |
| 352 | } |
| 353 | |
subrata_modak | 4bb656a | 2009-02-26 12:02:09 +0000 | [diff] [blame] | 354 | /* make a temp directory */ |
vapier | d13d74b | 2006-02-11 07:24:00 +0000 | [diff] [blame] | 355 | tst_tmpdir(); |
| 356 | |
| 357 | (void)sprintf(mntpoint, "mnt_%d", getpid()); |
| 358 | |
| 359 | if (mkdir(mntpoint, DIR_MODE)) { |
| 360 | tst_brkm(TBROK, cleanup, "mkdir(%s, %#o) failed; " |
| 361 | "errno = %d: %s", mntpoint, DIR_MODE, errno, |
subrata_modak | 56207ce | 2009-03-23 13:35:39 +0000 | [diff] [blame] | 362 | strerror(errno)); |
vapier | d13d74b | 2006-02-11 07:24:00 +0000 | [diff] [blame] | 363 | } |
| 364 | |
| 365 | /* set up expected error numbers */ |
| 366 | TEST_EXP_ENOS(exp_enos); |
| 367 | |
| 368 | /* Pause if that option was specified */ |
| 369 | TEST_PAUSE; |
| 370 | |
| 371 | return; |
subrata_modak | 56207ce | 2009-03-23 13:35:39 +0000 | [diff] [blame] | 372 | } /* End setup() */ |
vapier | d13d74b | 2006-02-11 07:24:00 +0000 | [diff] [blame] | 373 | |
subrata_modak | 4bb656a | 2009-02-26 12:02:09 +0000 | [diff] [blame] | 374 | /* |
vapier | d13d74b | 2006-02-11 07:24:00 +0000 | [diff] [blame] | 375 | *cleanup() - performs all ONE TIME cleanup for this test at |
| 376 | * completion or premature exit. |
| 377 | */ |
subrata_modak | 56207ce | 2009-03-23 13:35:39 +0000 | [diff] [blame] | 378 | void cleanup() |
vapier | d13d74b | 2006-02-11 07:24:00 +0000 | [diff] [blame] | 379 | { |
| 380 | if (Type != NULL) { |
| 381 | free(Type); |
| 382 | } |
| 383 | |
| 384 | /* |
| 385 | * print timing stats if that option was specified. |
| 386 | * print errno log if that option was specified. |
| 387 | */ |
| 388 | TEST_CLEANUP; |
| 389 | |
| 390 | /* Remove tmp dir and all files in it. */ |
| 391 | tst_rmdir(); |
| 392 | |
| 393 | /* exit with return code appropriate for results */ |
| 394 | tst_exit(); |
| 395 | |
| 396 | return; |
subrata_modak | 56207ce | 2009-03-23 13:35:39 +0000 | [diff] [blame] | 397 | } /* End cleanup() */ |
vapier | d13d74b | 2006-02-11 07:24:00 +0000 | [diff] [blame] | 398 | |
| 399 | /* |
| 400 | * issue a help message |
| 401 | */ |
subrata_modak | 56207ce | 2009-03-23 13:35:39 +0000 | [diff] [blame] | 402 | void help() |
vapier | d13d74b | 2006-02-11 07:24:00 +0000 | [diff] [blame] | 403 | { |
| 404 | printf("-T type : specifies the type of filesystem to be mounted." |
subrata_modak | 56207ce | 2009-03-23 13:35:39 +0000 | [diff] [blame] | 405 | " Default ext2. \n"); |
vapier | d13d74b | 2006-02-11 07:24:00 +0000 | [diff] [blame] | 406 | printf("-D device : device used for mounting \n"); |
| 407 | } |