blob: 99f55d592589467812ce7388ec76e9222d90fc8c [file] [log] [blame]
plars865695b2001-08-27 22:15:12 +00001/*
2 * Copyright (c) 2000 Silicon Graphics, Inc. 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 * Further, this software is distributed without any warranty that it is
13 * free of the rightful claim of any third person regarding infringement
14 * or the like. Any license provided herein, whether implied or
15 * otherwise, applies only to this software file. Patent licenses, if
16 * any, provided herein do not apply to combinations of this program with
17 * other software, or any other product whatsoever.
18 *
19 * You should have received a copy of the GNU General Public License along
Wanlong Gaofed96412012-10-24 10:10:29 +080020 * with this program; if not, write the Free Software Foundation, Inc.,
21 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
plars865695b2001-08-27 22:15:12 +000022 *
23 * Contact information: Silicon Graphics, Inc., 1600 Amphitheatre Pkwy,
24 * Mountain View, CA 94043, or:
25 *
26 * http://www.sgi.com
27 *
28 * For further information regarding this notice, see:
29 *
30 * http://oss.sgi.com/projects/GenInfo/NoticeExplan/
31 *
32 */
Shuang Qiuc7a4cfa2014-04-30 17:26:57 +080033/*
34 * DETAILED DESCRIPTION
35 * This is a Phase I test for the fstatfs(2) system call. It is intended
36 * to provide a limited exposure of the system call, for now. It
37 * should/will be extended when full functional tests are written for
38 * fstatfs(2).
39 */
plars865695b2001-08-27 22:15:12 +000040
41#include <sys/types.h>
42#include <sys/fcntl.h>
43#include <sys/statfs.h>
44#include <errno.h>
45#include <signal.h>
46#include <string.h>
Cyril Hrubis4d91ec52014-06-10 18:37:33 +020047
plars865695b2001-08-27 22:15:12 +000048#include "test.h"
Cyril Hrubis4d91ec52014-06-10 18:37:33 +020049#include "safe_macros.h"
plars865695b2001-08-27 22:15:12 +000050
Shuang Qiuc7a4cfa2014-04-30 17:26:57 +080051static void setup(void);
52static void cleanup(void);
plars865695b2001-08-27 22:15:12 +000053
Cyril Hrubisfdce7d52013-04-04 18:35:48 +020054char *TCID = "fstatfs01";
plars865695b2001-08-27 22:15:12 +000055
Cyril Hrubis4d91ec52014-06-10 18:37:33 +020056static int file_fd;
57static int pipe_fd;
58
59static struct tcase {
60 int *fd;
61 const char *msg;
62} tcases[2] = {
63 {&file_fd, "fstatfs() on a file"},
64 {&pipe_fd, "fstatfs() on a pipe"},
65};
66
67int TST_TOTAL = ARRAY_SIZE(tcases);
plars865695b2001-08-27 22:15:12 +000068
subrata_modak56207ce2009-03-23 13:35:39 +000069int main(int ac, char **av)
plars865695b2001-08-27 22:15:12 +000070{
Cyril Hrubis4d91ec52014-06-10 18:37:33 +020071 int lc, i;
Cyril Hrubis0b9589f2014-05-27 17:40:33 +020072 const char *msg;
Cyril Hrubis4d91ec52014-06-10 18:37:33 +020073 struct statfs stats;
subrata_modak56207ce2009-03-23 13:35:39 +000074
Garrett Cooper45e285d2010-11-22 12:19:25 -080075 if ((msg = parse_opts(ac, av, NULL, NULL)) != NULL)
Garrett Cooper60fa8012010-11-22 13:50:58 -080076 tst_brkm(TBROK, NULL, "OPTION PARSING ERROR - %s", msg);
plars865695b2001-08-27 22:15:12 +000077
subrata_modak56207ce2009-03-23 13:35:39 +000078 setup();
plars865695b2001-08-27 22:15:12 +000079
subrata_modak56207ce2009-03-23 13:35:39 +000080 for (lc = 0; TEST_LOOPING(lc); lc++) {
Caspar Zhangd59a6592013-03-07 14:59:12 +080081 tst_count = 0;
plars865695b2001-08-27 22:15:12 +000082
Cyril Hrubis4d91ec52014-06-10 18:37:33 +020083 for (i = 0; i < TST_TOTAL; i++) {
84 TEST(fstatfs(*tcases[i].fd, &stats));
subrata_modakbdbaec52009-02-26 12:14:51 +000085
Cyril Hrubis4d91ec52014-06-10 18:37:33 +020086 if (TEST_RETURN == -1) {
87 tst_resm(TFAIL | TTERRNO, "%s", tcases[i].msg);
88 } else {
89 tst_resm(TPASS, "%s - f_type=%lx",
90 tcases[i].msg, stats.f_type);
91 }
subrata_modak56207ce2009-03-23 13:35:39 +000092 }
Garrett Cooper2c282152010-12-16 00:55:50 -080093 }
plars865695b2001-08-27 22:15:12 +000094
subrata_modak56207ce2009-03-23 13:35:39 +000095 cleanup();
Garrett Cooper15697992010-12-18 06:31:28 -080096 tst_exit();
Garrett Cooper2c282152010-12-16 00:55:50 -080097}
plars865695b2001-08-27 22:15:12 +000098
Shuang Qiuc7a4cfa2014-04-30 17:26:57 +080099static void setup(void)
plars865695b2001-08-27 22:15:12 +0000100{
Cyril Hrubis4d91ec52014-06-10 18:37:33 +0200101 int pipe[2];
102
subrata_modak56207ce2009-03-23 13:35:39 +0000103 tst_sig(NOFORK, DEF_HANDLER, cleanup);
plars865695b2001-08-27 22:15:12 +0000104
subrata_modak56207ce2009-03-23 13:35:39 +0000105 TEST_PAUSE;
plars865695b2001-08-27 22:15:12 +0000106
subrata_modak56207ce2009-03-23 13:35:39 +0000107 tst_tmpdir();
plars865695b2001-08-27 22:15:12 +0000108
Cyril Hrubis4d91ec52014-06-10 18:37:33 +0200109 file_fd = SAFE_OPEN(cleanup, "test_file", O_RDWR | O_CREAT, 0700);
110
111 SAFE_PIPE(cleanup, pipe);
112 pipe_fd = pipe[0];
113 SAFE_CLOSE(cleanup, pipe[1]);
Garrett Cooper2c282152010-12-16 00:55:50 -0800114}
plars865695b2001-08-27 22:15:12 +0000115
Shuang Qiuc7a4cfa2014-04-30 17:26:57 +0800116static void cleanup(void)
plars865695b2001-08-27 22:15:12 +0000117{
Cyril Hrubis4d91ec52014-06-10 18:37:33 +0200118 if (file_fd > 0 && close(file_fd))
119 tst_resm(TWARN | TERRNO, "close(file_fd) failed");
120
121 if (pipe_fd > 0 && close(pipe_fd))
122 tst_resm(TWARN | TERRNO, "close(pipe_fd) failed");
plars865695b2001-08-27 22:15:12 +0000123
subrata_modak56207ce2009-03-23 13:35:39 +0000124 tst_rmdir();
Chris Dearmanec6edca2012-10-17 19:54:01 -0700125}