plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 1 | /* |
Zeng Linggang | 327e619 | 2014-05-09 17:06:54 +0800 | [diff] [blame] | 2 | * Copyright (c) International Business Machines Corp., 2001 |
| 3 | * 07/2001 Ported by Wayne Boyer |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 4 | * |
Zeng Linggang | 327e619 | 2014-05-09 17:06:54 +0800 | [diff] [blame] | 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. |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 9 | * |
Zeng Linggang | 327e619 | 2014-05-09 17:06:54 +0800 | [diff] [blame] | 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. |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 14 | * |
Zeng Linggang | 327e619 | 2014-05-09 17:06:54 +0800 | [diff] [blame] | 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 |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 18 | */ |
| 19 | |
| 20 | /* |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 21 | * DESCRIPTION |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 22 | * 1. Use a component of the pathname, which is not a directory |
| 23 | * in the "path" parameter to statfs(). Expect ENOTDIR |
| 24 | * 2. Pass a filename which doesn't exist, and expect ENOENT. |
| 25 | * 3. Pass a pathname which is more than MAXNAMLEN, and expect |
| 26 | * ENAMETOOLONG. |
| 27 | * 4. Pass a pointer to the pathname outside the address space of |
| 28 | * the process, and expect EFAULT. |
| 29 | * 5. Pass a pointer to the buf paramter outside the address space |
| 30 | * of the process, and expect EFAULT. |
Zeng Linggang | 661ece3 | 2014-05-09 19:39:48 +0800 | [diff] [blame] | 31 | * 6. Pass a filename which has too many symbolic links, and expect |
| 32 | * ELOOP. |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 33 | */ |
Zeng Linggang | 327e619 | 2014-05-09 17:06:54 +0800 | [diff] [blame] | 34 | |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 35 | #include <sys/types.h> |
| 36 | #include <sys/statfs.h> |
| 37 | #include <sys/stat.h> |
plars | 74948ad | 2002-11-14 16:16:14 +0000 | [diff] [blame] | 38 | #include <fcntl.h> |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 39 | #include <sys/vfs.h> |
plars | 1ad8451 | 2002-07-23 13:11:18 +0000 | [diff] [blame] | 40 | #include <sys/mman.h> |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 41 | #include <errno.h> |
| 42 | #include "test.h" |
Zeng Linggang | 327e619 | 2014-05-09 17:06:54 +0800 | [diff] [blame] | 43 | #include "safe_macros.h" |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 44 | |
nstraz | fa31d55 | 2002-05-14 16:50:06 +0000 | [diff] [blame] | 45 | char *TCID = "statfs02"; |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 46 | |
Zeng Linggang | 327e619 | 2014-05-09 17:06:54 +0800 | [diff] [blame] | 47 | static int fd; |
plars | 1ad8451 | 2002-07-23 13:11:18 +0000 | [diff] [blame] | 48 | |
Zeng Linggang | 327e619 | 2014-05-09 17:06:54 +0800 | [diff] [blame] | 49 | #define TEST_FILE "statfs_file" |
| 50 | #define TEST_FILE1 TEST_FILE"/statfs_file1" |
| 51 | #define TEST_NOEXIST "statfs_noexist" |
Zeng Linggang | 661ece3 | 2014-05-09 19:39:48 +0800 | [diff] [blame] | 52 | #define TEST_SYMLINK "statfs_symlink" |
subrata_modak | bdbaec5 | 2009-02-26 12:14:51 +0000 | [diff] [blame] | 53 | |
Zeng Linggang | 327e619 | 2014-05-09 17:06:54 +0800 | [diff] [blame] | 54 | static char test_toolong[PATH_MAX+2]; |
| 55 | static struct statfs buf; |
| 56 | |
| 57 | static struct test_case_t { |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 58 | char *path; |
| 59 | struct statfs *buf; |
Zeng Linggang | 327e619 | 2014-05-09 17:06:54 +0800 | [diff] [blame] | 60 | int exp_error; |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 61 | } TC[] = { |
Zeng Linggang | 327e619 | 2014-05-09 17:06:54 +0800 | [diff] [blame] | 62 | {TEST_FILE1, &buf, ENOTDIR}, |
| 63 | {TEST_NOEXIST, &buf, ENOENT}, |
| 64 | {test_toolong, &buf, ENAMETOOLONG}, |
vapier | 7ec19d9 | 2006-02-27 04:38:56 +0000 | [diff] [blame] | 65 | #ifndef UCLINUX |
Zeng Linggang | 327e619 | 2014-05-09 17:06:54 +0800 | [diff] [blame] | 66 | {(char *)-1, &buf, EFAULT}, |
| 67 | {TEST_FILE, (struct statfs *)-1, EFAULT}, |
vapier | 7ec19d9 | 2006-02-27 04:38:56 +0000 | [diff] [blame] | 68 | #endif |
Zeng Linggang | 661ece3 | 2014-05-09 19:39:48 +0800 | [diff] [blame] | 69 | {TEST_SYMLINK, &buf, ELOOP}, |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 70 | }; |
| 71 | |
Zeng Linggang | 327e619 | 2014-05-09 17:06:54 +0800 | [diff] [blame] | 72 | int TST_TOTAL = ARRAY_SIZE(TC); |
| 73 | static void setup(void); |
| 74 | static void cleanup(void); |
| 75 | static void statfs_verify(const struct test_case_t *); |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 76 | |
plars | 74948ad | 2002-11-14 16:16:14 +0000 | [diff] [blame] | 77 | int main(int ac, char **av) |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 78 | { |
Cyril Hrubis | 89af32a | 2012-10-24 16:39:11 +0200 | [diff] [blame] | 79 | int lc; |
Cyril Hrubis | 0b9589f | 2014-05-27 17:40:33 +0200 | [diff] [blame] | 80 | const char *msg; |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 81 | int i; |
| 82 | |
Zeng Linggang | 327e619 | 2014-05-09 17:06:54 +0800 | [diff] [blame] | 83 | msg = parse_opts(ac, av, NULL, NULL); |
| 84 | if (msg != NULL) |
Garrett Cooper | 45e285d | 2010-11-22 12:19:25 -0800 | [diff] [blame] | 85 | tst_brkm(TBROK, NULL, "OPTION PARSING ERROR - %s", msg); |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 86 | |
| 87 | setup(); |
| 88 | |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 89 | for (lc = 0; TEST_LOOPING(lc); lc++) { |
Caspar Zhang | d59a659 | 2013-03-07 14:59:12 +0800 | [diff] [blame] | 90 | tst_count = 0; |
Zeng Linggang | 327e619 | 2014-05-09 17:06:54 +0800 | [diff] [blame] | 91 | for (i = 0; i < TST_TOTAL; i++) |
| 92 | statfs_verify(&TC[i]); |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 93 | } |
Garrett Cooper | 45e285d | 2010-11-22 12:19:25 -0800 | [diff] [blame] | 94 | |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 95 | cleanup(); |
Garrett Cooper | 1e6f5a6 | 2010-12-19 09:58:10 -0800 | [diff] [blame] | 96 | tst_exit(); |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 97 | } |
| 98 | |
Zeng Linggang | 327e619 | 2014-05-09 17:06:54 +0800 | [diff] [blame] | 99 | static void setup(void) |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 100 | { |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 101 | tst_sig(NOFORK, DEF_HANDLER, cleanup); |
| 102 | |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 103 | TEST_PAUSE; |
| 104 | |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 105 | tst_tmpdir(); |
| 106 | |
Zeng Linggang | 327e619 | 2014-05-09 17:06:54 +0800 | [diff] [blame] | 107 | fd = SAFE_CREAT(cleanup, TEST_FILE, 0444); |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 108 | |
Zeng Linggang | 327e619 | 2014-05-09 17:06:54 +0800 | [diff] [blame] | 109 | memset(test_toolong, 'a', PATH_MAX+1); |
plars | 1ad8451 | 2002-07-23 13:11:18 +0000 | [diff] [blame] | 110 | |
vapier | 62b16cf | 2007-02-09 20:48:23 +0000 | [diff] [blame] | 111 | #if !defined(UCLINUX) |
Zeng Linggang | 327e619 | 2014-05-09 17:06:54 +0800 | [diff] [blame] | 112 | TC[3].path = SAFE_MMAP(cleanup, 0, 1, PROT_NONE, |
| 113 | MAP_PRIVATE | MAP_ANONYMOUS, 0, 0); |
vapier | b5ed1f6 | 2006-08-24 04:16:32 +0000 | [diff] [blame] | 114 | #endif |
Zeng Linggang | 661ece3 | 2014-05-09 19:39:48 +0800 | [diff] [blame] | 115 | |
| 116 | SAFE_SYMLINK(cleanup, TEST_SYMLINK, "statfs_symlink_2"); |
| 117 | SAFE_SYMLINK(cleanup, "statfs_symlink_2", TEST_SYMLINK); |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 118 | } |
| 119 | |
Zeng Linggang | 327e619 | 2014-05-09 17:06:54 +0800 | [diff] [blame] | 120 | static void statfs_verify(const struct test_case_t *test) |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 121 | { |
Zeng Linggang | 327e619 | 2014-05-09 17:06:54 +0800 | [diff] [blame] | 122 | TEST(statfs(test->path, test->buf)); |
| 123 | |
| 124 | if (TEST_RETURN != -1) { |
| 125 | tst_resm(TFAIL, "call succeeded unexpectedly"); |
| 126 | return; |
| 127 | } |
| 128 | |
Zeng Linggang | 327e619 | 2014-05-09 17:06:54 +0800 | [diff] [blame] | 129 | if (TEST_ERRNO == test->exp_error) { |
| 130 | tst_resm(TPASS | TTERRNO, "expected failure"); |
| 131 | } else { |
| 132 | tst_resm(TFAIL | TTERRNO, "unexpected error, expected %d", |
| 133 | TEST_ERRNO); |
| 134 | } |
| 135 | } |
| 136 | |
| 137 | static void cleanup(void) |
| 138 | { |
| 139 | if (fd > 0) |
| 140 | close(fd); |
mridge | 3db3f03 | 2004-08-25 16:26:11 +0000 | [diff] [blame] | 141 | |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 142 | tst_rmdir(); |
Chris Dearman | ec6edca | 2012-10-17 19:54:01 -0700 | [diff] [blame] | 143 | } |