blob: 6838550296ceb58ab6bba14e9aa722bfd0a7f788 [file] [log] [blame]
robbiew3c557322003-03-03 16:01:42 +00001/*
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
Wanlong Gaofed96412012-10-24 10:10:29 +080013 * with this program; if not, write the Free Software Foundation, Inc.,
14 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
robbiew3c557322003-03-03 16:01:42 +000015 *
16 */
Cyril Hrubis19121ad2014-02-26 16:54:09 +010017
18/*
19 * Check that ustat() succeeds given correct parameters.
20 */
21
22#include <unistd.h>
23#include <ustat.h>
robbiew3c557322003-03-03 16:01:42 +000024#include <errno.h>
25#include <sys/types.h>
robbiew3c557322003-03-03 16:01:42 +000026#include <sys/stat.h>
Cyril Hrubis19121ad2014-02-26 16:54:09 +010027#include "test.h"
Cyril Hrubis19121ad2014-02-26 16:54:09 +010028#include "safe_macros.h"
robbiew3c557322003-03-03 16:01:42 +000029
Cyril Hrubis19121ad2014-02-26 16:54:09 +010030static void setup(void);
31static void cleanup(void);
robbiew3c557322003-03-03 16:01:42 +000032
33char *TCID = "ustat01";
34int TST_TOTAL = 1;
robbiew3c557322003-03-03 16:01:42 +000035
Cyril Hrubis19121ad2014-02-26 16:54:09 +010036static dev_t dev_num;
37static struct ustat ubuf;
robbiew3c557322003-03-03 16:01:42 +000038
subrata_modak56207ce2009-03-23 13:35:39 +000039int main(int argc, char *argv[])
robbiew3c557322003-03-03 16:01:42 +000040{
subrata_modak56207ce2009-03-23 13:35:39 +000041 int lc, i;
Cyril Hrubis0b9589f2014-05-27 17:40:33 +020042 const char *msg;
robbiew3c557322003-03-03 16:01:42 +000043
Garrett Coopera9e49f12010-12-16 10:54:03 -080044 if ((msg = parse_opts(argc, argv, NULL, NULL)) != NULL)
Garrett Cooper60fa8012010-11-22 13:50:58 -080045 tst_brkm(TBROK, NULL, "OPTION PARSING ERROR - %s", msg);
robbiew3c557322003-03-03 16:01:42 +000046
robbiew3c557322003-03-03 16:01:42 +000047 setup();
48
robbiew3c557322003-03-03 16:01:42 +000049 for (lc = 0; TEST_LOOPING(lc); lc++) {
Garrett Cooper2c282152010-12-16 00:55:50 -080050
Caspar Zhangd59a6592013-03-07 14:59:12 +080051 tst_count = 0;
robbiew3c557322003-03-03 16:01:42 +000052
subrata_modak56207ce2009-03-23 13:35:39 +000053 for (i = 0; i < TST_TOTAL; i++) {
Cyril Hrubis19121ad2014-02-26 16:54:09 +010054 TEST(ustat(dev_num, &ubuf));
55
Frediano Ziglio194168d2015-01-05 13:38:16 +000056 if (TEST_RETURN == -1 && TEST_ERRNO == ENOSYS)
57 tst_brkm(TCONF, cleanup, "ustat not supported");
58
robbiew3c557322003-03-03 16:01:42 +000059 if (TEST_RETURN == -1) {
robbiew3c557322003-03-03 16:01:42 +000060 tst_resm(TFAIL, "ustat(2) failed and set"
subrata_modak56207ce2009-03-23 13:35:39 +000061 "the errno to %d : %s",
62 TEST_ERRNO, strerror(TEST_ERRNO));
63 } else {
64 tst_resm(TPASS, "ustat(2) passed");
robbiew3c557322003-03-03 16:01:42 +000065 }
Garrett Cooper2c282152010-12-16 00:55:50 -080066 }
67 }
Cyril Hrubis19121ad2014-02-26 16:54:09 +010068
robbiew3c557322003-03-03 16:01:42 +000069 cleanup();
Garrett Cooper1e6f5a62010-12-19 09:58:10 -080070 tst_exit();
robbiew3c557322003-03-03 16:01:42 +000071}
72
Cyril Hrubis19121ad2014-02-26 16:54:09 +010073static void setup(void)
robbiew3c557322003-03-03 16:01:42 +000074{
Cyril Hrubis19121ad2014-02-26 16:54:09 +010075 struct stat buf;
Garrett Cooper2c282152010-12-16 00:55:50 -080076
robbiew3c557322003-03-03 16:01:42 +000077 tst_sig(NOFORK, DEF_HANDLER, cleanup);
78
robbiew3c557322003-03-03 16:01:42 +000079 TEST_PAUSE;
80
Cyril Hrubis19121ad2014-02-26 16:54:09 +010081 /* Find a valid device number */
82 SAFE_STAT(cleanup, "/", &buf);
robbiew3c557322003-03-03 16:01:42 +000083
Cyril Hrubis19121ad2014-02-26 16:54:09 +010084 dev_num = buf.st_dev;
Garrett Cooper2c282152010-12-16 00:55:50 -080085}
robbiew3c557322003-03-03 16:01:42 +000086
Cyril Hrubis19121ad2014-02-26 16:54:09 +010087static void cleanup(void)
robbiew3c557322003-03-03 16:01:42 +000088{
Chris Dearmanec6edca2012-10-17 19:54:01 -070089}