Home | History | Annotate | Download | only in ustat
      1 /*
      2  * Copyright (c) Wipro Technologies Ltd, 2003.  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.,
     14  * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
     15  *
     16  */
     17 
     18 /*
     19  * Check that ustat() succeeds given correct parameters.
     20  */
     21 
     22 #include <unistd.h>
     23 #include <errno.h>
     24 #include <sys/ustat.h>
     25 #include <sys/types.h>
     26 #include <sys/stat.h>
     27 #include "test.h"
     28 #include "safe_macros.h"
     29 
     30 static void setup(void);
     31 
     32 char *TCID = "ustat01";
     33 int TST_TOTAL = 1;
     34 
     35 static dev_t dev_num;
     36 static struct ustat ubuf;
     37 
     38 int main(int argc, char *argv[])
     39 {
     40 	int lc, i;
     41 
     42 	tst_parse_opts(argc, argv, NULL, NULL);
     43 
     44 	setup();
     45 
     46 	for (lc = 0; TEST_LOOPING(lc); lc++) {
     47 
     48 		tst_count = 0;
     49 
     50 		for (i = 0; i < TST_TOTAL; i++) {
     51 			TEST(ustat(dev_num, &ubuf));
     52 
     53 			if (TEST_RETURN == -1 && TEST_ERRNO == ENOSYS)
     54 				tst_brkm(TCONF, NULL, "ustat not supported");
     55 
     56 			if (TEST_RETURN == -1) {
     57 				tst_resm(TFAIL, "ustat(2) failed and set"
     58 					 "the errno to %d : %s",
     59 					 TEST_ERRNO, strerror(TEST_ERRNO));
     60 			} else {
     61 				tst_resm(TPASS, "ustat(2) passed");
     62 			}
     63 		}
     64 	}
     65 
     66 	tst_exit();
     67 }
     68 
     69 static void setup(void)
     70 {
     71 	struct stat buf;
     72 
     73 	tst_sig(NOFORK, DEF_HANDLER, NULL);
     74 
     75 	TEST_PAUSE;
     76 
     77 	/* Find a valid device number */
     78 	SAFE_STAT(NULL, "/", &buf);
     79 
     80 	dev_num = buf.st_dev;
     81 }
     82