blob: 7e4d9271e831768b732ad71b7daf59d798f7a55e [file] [log] [blame]
plars865695b2001-08-27 22:15:12 +00001/*
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., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
18 */
19
20/*
21 * NAME
nstrazfa31d552002-05-14 16:50:06 +000022 * statfs02.c
plars865695b2001-08-27 22:15:12 +000023 *
24 * DESCRIPTION
25 * Testcase to check that statfs(2) sets errno correctly.
26 *
27 * ALGORITHM
28 * 1. Use a component of the pathname, which is not a directory
29 * in the "path" parameter to statfs(). Expect ENOTDIR
30 * 2. Pass a filename which doesn't exist, and expect ENOENT.
31 * 3. Pass a pathname which is more than MAXNAMLEN, and expect
32 * ENAMETOOLONG.
33 * 4. Pass a pointer to the pathname outside the address space of
34 * the process, and expect EFAULT.
35 * 5. Pass a pointer to the buf paramter outside the address space
36 * of the process, and expect EFAULT.
37 *
38 * USAGE: <for command-line>
nstrazfa31d552002-05-14 16:50:06 +000039 * statfs02 [-c n] [-e] [-i n] [-I x] [-P x] [-t]
plars865695b2001-08-27 22:15:12 +000040 * where, -c n : Run n copies concurrently.
41 * -e : Turn on errno logging.
42 * -i n : Execute test n times.
43 * -I x : Execute test for x seconds.
44 * -P x : Pause for x seconds between iterations.
45 * -t : Turn on syscall timing.
46 *
47 * HISTORY
48 * 07/2001 Ported by Wayne Boyer
49 *
50 * RESTRICTIONS
51 * NONE
52 *
53 */
54#include <sys/types.h>
55#include <sys/statfs.h>
56#include <sys/stat.h>
plars74948ad2002-11-14 16:16:14 +000057#include <fcntl.h>
plars865695b2001-08-27 22:15:12 +000058#include <sys/vfs.h>
plars1ad84512002-07-23 13:11:18 +000059#include <sys/mman.h>
plars865695b2001-08-27 22:15:12 +000060#include <errno.h>
61#include "test.h"
62#include "usctest.h"
63
nstrazfa31d552002-05-14 16:50:06 +000064char *TCID = "statfs02";
plars865695b2001-08-27 22:15:12 +000065int TST_TOTAL = 5;
66extern int Tst_count;
67
68int exp_enos[]={ENOTDIR, ENOENT, ENAMETOOLONG, EFAULT, 0};
69
plars1ad84512002-07-23 13:11:18 +000070char * bad_addr = 0;
71
plars865695b2001-08-27 22:15:12 +000072char bad_file[] = "abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstmnopqrstuvwxyzabcdefghijklmnopqrstmnopqrstuvwxyzabcdefghijklmnopqrstmnopqrstuvwxyzabcdefghijklmnopqrstmnopqrstuvwxyzabcdefghijklmnopqrstmnopqrstuvwxyzabcdefghijklmnopqrstmnopqrstuvwxyz";
73 char good_dir[100] = "testdir";
74 char fname[30] = "testfile";
75 struct statfs fsbuf;
76 char fname1[30];
77
78struct test_case_t {
79 char *path;
80 struct statfs *buf;
81 int error;
82} TC[] = {
83 /* path has a component which is not a directory - ENOTDIR */
84 {fname1, &fsbuf, ENOTDIR},
85
86 /* path does not exist - ENOENT */
87 {good_dir, &fsbuf, ENOENT},
88
89 /* path is too long - ENAMETOOLONG */
90 {bad_file, &fsbuf, ENAMETOOLONG},
91
92 /* path is an invalid address - EFAULT */
93 {(char *)-1, &fsbuf, EFAULT},
94
95 /* buf is an invalid address - EFAULT */
96 {fname, (struct statfs *)-1, EFAULT}
97};
98
99void setup(void);
100void cleanup(void);
101
plars74948ad2002-11-14 16:16:14 +0000102int main(int ac, char **av)
plars865695b2001-08-27 22:15:12 +0000103{
104 int lc; /* loop counter */
105 char *msg; /* message returned from parse_opts */
plars865695b2001-08-27 22:15:12 +0000106 int i;
107
108 /* parse standard options */
109 if ((msg = parse_opts(ac, av, (option_t *)NULL, NULL)) != (char *)NULL){
110 tst_brkm(TBROK, tst_exit, "OPTION PARSING ERROR - %s", msg);
111 /*NOTREACHED*/
112 }
113
114 setup();
115
116 /* set up the expected errnos */
117 TEST_EXP_ENOS(exp_enos);
118
119 /* check looping state if -i option given */
120 for (lc = 0; TEST_LOOPING(lc); lc++) {
121
122 /* reset Tst_count in case we are looping. */
123 Tst_count = 0;
124
125
126 /* loop through the test cases */
127 for (i = 0; i < TST_TOTAL; i++) {
128
129 TEST(statfs(TC[i].path, TC[i].buf));
130
131 if (TEST_RETURN != -1) {
132 tst_resm(TFAIL, "call succeeded unexpectedly");
133 continue;
134 }
135
136 TEST_ERROR_LOG(TEST_ERRNO);
137
138 if (TEST_ERRNO == TC[i].error) {
139 tst_resm(TPASS, "expected failure - "
140 "errno = %d : %s", TEST_ERRNO,
141 strerror(TEST_ERRNO));
142 } else {
143 tst_resm(TFAIL, "unexpected error - %d : %s - "
144 "expected %d", TEST_ERRNO,
145 strerror(TEST_ERRNO), TC[i].error);
146 }
147 }
148 }
149 cleanup();
150
151 /*NOTREACHED*/
152}
153
154/*
155 * setup() - performs all ONE TIME setup for this test.
156 */
157void
158setup()
159{
160 /* capture signals */
161 tst_sig(NOFORK, DEF_HANDLER, cleanup);
162
163 /* Pause if that option was specified */
164 TEST_PAUSE;
165
166 /* make a temporary directory and cd to it */
167 tst_tmpdir();
168
169 sprintf(fname, "%s.%d", fname, getpid());
170 if ((creat(fname, 0444)) == -1) {
171 tst_resm(TFAIL, "creat(2) FAILED to creat temp file");
172 }
173 sprintf(fname1, "%s/%s", fname, fname);
174
175 sprintf(good_dir, "%s.statfs.%d", good_dir, getpid());
plars1ad84512002-07-23 13:11:18 +0000176
177 bad_addr = mmap(0, 1, PROT_NONE, MAP_PRIVATE|MAP_ANONYMOUS, 0, 0);
178 if (bad_addr <= 0) {
179 tst_brkm(TBROK, cleanup, "mmap failed");
180 }
181 TC[3].path = bad_addr;
plars865695b2001-08-27 22:15:12 +0000182}
183
184
185/*
186 * cleanup() - performs all ONE TIME cleanup for this test at
187 * completion or premature exit.
188 */
189void
190cleanup()
191{
192 /*
193 * print timing stats if that option was specified.
194 * print errno log if that option was specified.
195 */
196 TEST_CLEANUP;
197
198 /* delete the test directory created in setup() */
199 tst_rmdir();
200
201 /* exit with return code appropriate for results */
202 tst_exit();
203}
204