abe3f18eaf6ed6a267a4a1054e1852d7ab5d0e5b
[xfstests-dev.git] / src / global.h
1 /*
2  * Copyright (c) 2000-2003 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., 59
21  * Temple Place - Suite 330, Boston MA 02111-1307, 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/SGIGPLNoticeExplan/
31  */
32  
33 #ifndef GLOBAL_H
34 #define GLOBAL_H
35
36 #include <config.h>
37
38 #ifdef HAVE_XFS_LIBXFS_H
39 #include <xfs/libxfs.h>
40 #endif
41
42 #ifdef HAVE_XFS_JDM_H
43 #include <xfs/jdm.h>
44 #endif
45
46 #ifdef HAVE_ATTR_ATTRIBUTES_H
47 #include <attr/attributes.h>
48 #endif
49
50 #ifdef HAVE_SYS_TYPES_H
51 #include <sys/types.h>
52 #endif
53
54 #ifdef HAVE_SYS_STAT_H
55 #include <sys/stat.h>
56 #endif
57
58 #ifdef HAVE_SYS_STATVFS_H
59 #include <sys/statvfs.h>
60 #endif
61
62 #ifdef HAVE_SYS_TIME_H
63 #include <sys/time.h>
64 #endif
65
66 #ifdef HAVE_SYS_IOCTL_H
67 #include <sys/ioctl.h>
68 #endif
69
70 #ifdef HAVE_SYS_WAIT_H
71 #include <sys/wait.h>
72 #endif
73
74 #ifdef HAVE_MALLOC_H
75 #include <malloc.h>
76 #endif
77
78 #ifdef HAVE_DIRENT_H
79 #include <dirent.h>
80 #endif
81
82 #ifdef HAVE_STDLIB_H
83 #include <stdlib.h>
84 #endif
85
86 #ifdef HAVE_UNISTD_H
87 #include <unistd.h>
88 #endif
89
90 #ifdef HAVE_ERRNO_H
91 #include <errno.h>
92 #endif
93
94 #ifdef HAVE_STRING_H
95 #include <string.h>
96 #endif
97
98 #ifdef HAVE_SYS_FCNTL_H
99 #include <fcntl.h>
100 #endif
101
102 #ifdef HAVE_TIME_H
103 #include <sys/time.h>
104 #endif
105
106 #ifdef HAVE_WAIT_H
107 #include <sys/wait.h>
108 #endif
109
110 #ifdef HAVE_DIRENT_H
111 #include <dirent.h>
112 #endif
113
114 #ifdef HAVE_SYS_PARAM_H
115 #include <sys/param.h>
116 #endif
117
118 #ifdef HAVE_SYS_ATTRIBUTES_H
119 #include <sys/attributes.h>
120 #endif
121
122 #ifdef HAVE_LIBGEN_H
123 #include <libgen.h>
124 #endif
125
126 #ifdef HAVE_ASSERT_H
127 #include <assert.h>
128 #endif
129
130 #ifdef STDC_HEADERS
131 #include <signal.h>
132 #endif
133
134 #ifdef HAVE_STRINGS_H
135 #include <strings.h>
136 #endif
137
138 #ifdef HAVE_SYS_SYSSGI_H
139 #include <sys/syssgi.h>
140 #endif
141
142 #ifdef HAVE_SYS_UUID_H
143 #include <sys/uuid.h>
144 #endif
145
146 #ifdef HAVE_SYS_FS_XFS_FSOPS_H
147 #include <sys/fs/xfs_fsops.h>
148 #endif
149
150 #ifdef HAVE_SYS_FS_XFS_ITABLE_H
151 #include <sys/fs/xfs_itable.h>
152 #endif
153
154 #ifdef HAVE_BSTRING_H
155 #include <bstring.h>
156 #endif
157
158 #ifdef HAVE_SYS_PARAM_H
159 #include <sys/param.h>
160 #endif
161
162 #endif
163
164 #ifdef sgi
165 #define xfs_flock64 flock64
166 #define xfs_flock64_t struct flock64
167
168 #define XFS_IOC_DIOINFO                F_DIOINFO                       
169 #define XFS_IOC_FSGETXATTR             F_FSGETXATTR                   
170 #define XFS_IOC_FSSETXATTR             F_FSSETXATTR                    
171 #define XFS_IOC_ALLOCSP64              F_ALLOCSP64                    
172 #define XFS_IOC_FREESP64               F_FREESP64                 
173 #define XFS_IOC_GETBMAP                F_GETBMAP                 
174 #define XFS_IOC_FSSETDM                F_FSSETDM                 
175 #define XFS_IOC_RESVSP                 F_RESVSP                 
176 #define XFS_IOC_UNRESVSP               F_UNRESVSP                 
177 #define XFS_IOC_RESVSP64               F_RESVSP64                 
178 #define XFS_IOC_UNRESVSP64             F_UNRESVSP64                 
179 #define XFS_IOC_GETBMAPA               F_GETBMAPA                 
180 #define XFS_IOC_FSGETXATTRA            F_FSGETXATTRA                         
181 #define XFS_IOC_GETBMAPX               F_GETBMAPX
182                    
183 #define XFS_IOC_FSGEOMETRY_V1          XFS_FS_GEOMETRY_V1          
184 #define XFS_IOC_FSBULKSTAT             SGI_FS_BULKSTAT     
185 #define XFS_IOC_FSBULKSTAT_SINGLE      SGI_FS_BULKSTAT_SINGLE
186 #define XFS_IOC_FSINUMBERS             /* TODO */
187 #define XFS_IOC_PATH_TO_FSHANDLE       /* TODO */                        
188 #define XFS_IOC_PATH_TO_HANDLE         /* TODO */                      
189 #define XFS_IOC_FD_TO_HANDLE           /* TODO */
190 #define XFS_IOC_OPEN_BY_HANDLE         /* TODO */
191 #define XFS_IOC_READLINK_BY_HANDLE     /* TODO */
192 #define XFS_IOC_SWAPEXT                /* TODO */
193 #define XFS_IOC_FSGROWFSDATA           XFS_GROWFS_DATA      
194 #define XFS_IOC_FSGROWFSLOG            XFS_GROWFS_LOG      
195 #define XFS_IOC_FSGROWFSRT             XFS_GROWFS_RT      
196 #define XFS_IOC_FSCOUNTS               XFS_FS_COUNTS      
197 #define XFS_IOC_SET_RESBLKS            XFS_SET_RESBLKS      
198 #define XFS_IOC_GET_RESBLKS            XFS_GET_RESBLKS      
199 #define XFS_IOC_ERROR_INJECTION        SGI_XFS_INJECT_ERROR
200 #define XFS_IOC_ERROR_CLEARALL         SGI_XFS_CLEARALL_ERROR
201 #define XFS_IOC_FREEZE                 XFS_FS_FREEZE      
202 #define XFS_IOC_THAW                   XFS_FS_THAW      
203 #define XFS_IOC_FSSETDM_BY_HANDLE      /* TODO */    
204 #define XFS_IOC_ATTRLIST_BY_HANDLE     /* TODO */      
205 #define XFS_IOC_ATTRMULTI_BY_HANDLE    /* TODO */      
206 #define XFS_IOC_FSGEOMETRY             XFS_FS_GEOMETRY      
207 #define XFS_IOC_GOINGDOWN              XFS_FS_GOINGDOWN
208
209 typedef struct xfs_error_injection {
210         __int32_t           fd;
211         __int32_t           errtag;
212 } xfs_error_injection_t;
213
214
215 typedef struct xfs_fsop_bulkreq {
216         ino64_t             *lastip;      
217         __int32_t           icount;   
218         xfs_bstat_t         *ubuffer;      
219         __int32_t           *ocount;       
220 } xfs_fsop_bulkreq_t;
221
222 static __inline__ int 
223 xfsctl(char* path, int fd, int cmd, void* arg) {
224   if (cmd >= 0 && cmd < XFS_FSOPS_COUNT) {
225     /*
226      * We have a problem in that xfsctl takes 1 arg but
227      * some sgi xfs ops take an input arg and/or an output arg
228      * So have to special case the ops to decide if xfsctl arg
229      * is an input or an output argument.
230      */
231     if (cmd == XFS_FS_GOINGDOWN) {
232       /* in arg */
233       return syssgi(SGI_XFS_FSOPERATIONS, fd, cmd, arg, 0);
234     } else {
235       /* out arg */
236       return syssgi(SGI_XFS_FSOPERATIONS, fd, cmd, 0, arg);
237     }
238   } else if (cmd == SGI_FS_BULKSTAT)
239     return syssgi(SGI_FS_BULKSTAT, fd, 
240                   ((xfs_fsop_bulkreq_t*)arg)->lastip,
241                   ((xfs_fsop_bulkreq_t*)arg)->icount,
242                   ((xfs_fsop_bulkreq_t*)arg)->ubuffer,
243                   ((xfs_fsop_bulkreq_t*)arg)->ocount);
244   else if (cmd == SGI_FS_BULKSTAT_SINGLE)
245     return syssgi(SGI_FS_BULKSTAT_SINGLE, fd, 
246                   ((xfs_fsop_bulkreq_t*)arg)->lastip,
247                   ((xfs_fsop_bulkreq_t*)arg)->ubuffer);
248   else if (cmd == SGI_XFS_INJECT_ERROR)
249     return syssgi(SGI_XFS_INJECT_ERROR,
250                   ((xfs_error_injection_t*)arg)->errtag, fd);
251   else if (cmd == SGI_XFS_CLEARALL_ERROR)
252     return syssgi(SGI_XFS_CLEARALL_ERROR, fd);
253   else
254     return fcntl(fd, cmd, arg);
255 }
256
257 #endif /* sgi */