Home | History | Annotate | Download | only in fstatfs
      1 /*
      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
     20  * with this program; if not, write the Free Software Foundation, Inc.,
     21  * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
     22  *
     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  */
     33 /*
     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  */
     40 
     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>
     47 
     48 #include "test.h"
     49 #include "safe_macros.h"
     50 
     51 static void setup(void);
     52 static void cleanup(void);
     53 
     54 char *TCID = "fstatfs01";
     55 
     56 static int file_fd;
     57 static int pipe_fd;
     58 
     59 static 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 
     67 int TST_TOTAL = ARRAY_SIZE(tcases);
     68 
     69 int main(int ac, char **av)
     70 {
     71 	int lc, i;
     72 	struct statfs stats;
     73 
     74 	tst_parse_opts(ac, av, NULL, NULL);
     75 
     76 	setup();
     77 
     78 	for (lc = 0; TEST_LOOPING(lc); lc++) {
     79 		tst_count = 0;
     80 
     81 		for (i = 0; i < TST_TOTAL; i++) {
     82 			TEST(fstatfs(*tcases[i].fd, &stats));
     83 
     84 			if (TEST_RETURN == -1) {
     85 				tst_resm(TFAIL | TTERRNO, "%s", tcases[i].msg);
     86 			} else {
     87 				tst_resm(TPASS, "%s - f_type=%lx",
     88 				         tcases[i].msg, stats.f_type);
     89 			}
     90 		}
     91 	}
     92 
     93 	cleanup();
     94 	tst_exit();
     95 }
     96 
     97 static void setup(void)
     98 {
     99 	int pipe[2];
    100 
    101 	tst_sig(NOFORK, DEF_HANDLER, cleanup);
    102 
    103 	TEST_PAUSE;
    104 
    105 	tst_tmpdir();
    106 
    107 	file_fd = SAFE_OPEN(cleanup, "test_file", O_RDWR | O_CREAT, 0700);
    108 
    109 	SAFE_PIPE(cleanup, pipe);
    110 	pipe_fd = pipe[0];
    111 	SAFE_CLOSE(cleanup, pipe[1]);
    112 }
    113 
    114 static void cleanup(void)
    115 {
    116 	if (file_fd > 0 && close(file_fd))
    117 		tst_resm(TWARN | TERRNO, "close(file_fd) failed");
    118 
    119 	if (pipe_fd > 0 && close(pipe_fd))
    120 		tst_resm(TWARN | TERRNO, "close(pipe_fd) failed");
    121 
    122 	tst_rmdir();
    123 }
    124