open_by_handle: add filename to error reports
[xfstests-dev.git] / src / fault.c
1 /*
2  * Copyright (c) 2000-2003 Silicon Graphics, Inc.
3  * All Rights Reserved.
4  *
5  * This program is free software; you can redistribute it and/or
6  * modify it under the terms of the GNU General Public License as
7  * published by the Free Software Foundation.
8  *
9  * This program is distributed in the hope that it would be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12  * GNU General Public License for more details.
13  *
14  * You should have received a copy of the GNU General Public License
15  * along with this program; if not, write the Free Software Foundation,
16  * Inc.,  51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
17  */
18
19 #include "global.h"
20
21 void expect_error(int r, int err)
22 {
23     if (r<0) {
24         if (errno == err) {
25             printf("   --- got error %d as expected\n", err);   
26         } else {
27             perror("   !!! unexpected error");
28         }
29     } else {
30         printf("   !!! success instead of error %d as expected\n", err);
31     }
32 }
33
34 int
35 main(int argc, char **argv)
36 {
37     int                 fsfd;
38     
39     if (argc != 2) {
40         fprintf(stderr,"usage: %s <filesystem>\n",
41                 argv[0]);
42         exit(0);
43     }
44
45     fsfd = open(argv[1], O_RDONLY);
46
47     if (fsfd < 0) {
48         perror("open");
49         exit(1);
50     }
51     
52     printf("--- xfsctl with bad output address\n");
53 #ifdef XFS_IOC_FSCOUNTS
54     expect_error(xfsctl(argv[1], fsfd, XFS_IOC_FSCOUNTS, NULL), EFAULT);
55 #else
56 #ifdef XFS_FS_COUNTS
57     expect_error(syssgi(SGI_XFS_FSOPERATIONS, fsfd, XFS_FS_COUNTS, NULL, NULL), EFAULT);
58 #else
59 bozo!
60 #endif
61 #endif
62
63     printf("--- xfsctl with bad input address\n");
64 #ifdef XFS_IOC_SET_RESBLKS
65     expect_error(xfsctl(argv[1], fsfd, XFS_IOC_SET_RESBLKS, NULL), EFAULT);
66 #else
67 #ifdef XFS_SET_RESBLKS
68     expect_error(syssgi(SGI_XFS_FSOPERATIONS, fsfd, XFS_SET_RESBLKS, NULL, NULL), EFAULT);
69 #else
70 bozo!
71 #endif
72 #endif
73     
74     close(fsfd);
75     
76     return 0;
77 }