Whamcloud - gitweb
fb05d75ced0d5d862feec5319f936e580cfa8709
[fs/lustre-release.git] / libsysio / include / sysio.h
1 /*
2  *    This Cplant(TM) source code is the property of Sandia National
3  *    Laboratories.
4  *
5  *    This Cplant(TM) source code is copyrighted by Sandia National
6  *    Laboratories.
7  *
8  *    The redistribution of this Cplant(TM) source code is subject to the
9  *    terms of the GNU Lesser General Public License
10  *    (see cit/LGPL or http://www.gnu.org/licenses/lgpl.html)
11  *
12  *    Cplant(TM) Copyright 1998-2004 Sandia Corporation. 
13  *    Under the terms of Contract DE-AC04-94AL85000, there is a non-exclusive
14  *    license for use of this work by or on behalf of the US Government.
15  *    Export of this program may require a license from the United States
16  *    Government.
17  */
18
19 /*
20  * This library is free software; you can redistribute it and/or
21  * modify it under the terms of the GNU Lesser General Public
22  * License as published by the Free Software Foundation; either
23  * version 2.1 of the License, or (at your option) any later version.
24  * 
25  * This library is distributed in the hope that it will be useful,
26  * but WITHOUT ANY WARRANTY; without even the implied warranty of
27  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
28  * Lesser General Public License for more details.
29  * 
30  * You should have received a copy of the GNU Lesser General Public
31  * License along with this library; if not, write to the Free Software
32  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
33  *
34  * Questions or comments about this library should be sent to:
35  *
36  * Lee Ward
37  * Sandia National Laboratories, New Mexico
38  * P.O. Box 5800
39  * Albuquerque, NM 87185-1110
40  *
41  * lee@sandia.gov
42  */
43
44 /*
45  * System IO common information.
46  */
47
48 #include <limits.h>
49 #include <stdarg.h>
50
51 #ifndef _IOID_T_DEFINED
52 #define _IOID_T_DEFINED
53 /*
54  * FIXME:
55  *
56  * This section about ioid_t and it's failure belong in <sys/types.h>
57  */
58 typedef void *ioid_t;
59
60 #define IOID_FAIL                       0
61 #endif
62
63 #if !defined(__IS_UNUSED) && defined(__GNUC__)
64 #define __IS_UNUSED     __attribute__ ((unused))
65 #else
66 #define __IS_UNUSED
67 #endif
68
69 #ifndef PATH_SEPARATOR
70 /*
71  * Path separator.
72  */
73 #define PATH_SEPARATOR                  '/'
74 #endif
75
76 #ifndef MAX_SYMLINK
77 /*
78  * Max recursion depth allowed when resoving symbolic links.
79  */
80 #define MAX_SYMLINK                     250
81 #endif
82
83 #ifndef _LARGEFILE64_SOURCE
84 /*
85  * Not glibc I guess. Define this ourselves.
86  */
87 #define _LARGEFILE64_SOURCE             0
88 #endif
89
90 /*
91  * Define internal file-offset type and it's maximum value.
92  */
93 #if _LARGEFILE64_SOURCE
94 #define _SYSIO_OFF_T                    off64_t
95 #ifdef LLONG_MAX
96 #define _SYSIO_OFF_T_MAX                (LLONG_MAX)
97 #else
98 /*
99  * Don't have LLONG_MAX before C99. We'll need to define it ourselves.
100  */
101 #define _SYSIO_OFF_T_MAX                (9223372036854775807LL)
102 #endif
103 #else
104 #define _SYSIO_OFF_T                    off_t
105 #define _SYSIO_OFF_T_MAX                LONG_MAX
106 #endif
107
108 /*
109  * Internally, all directory entries are carried in the 64-bit capable
110  * structure.
111  */
112 #if _LARGEFILE64_SOURCE
113 #define intnl_dirent dirent64
114 #else
115 #define intnl_dirent dirent
116 #endif
117 struct dirent;
118
119 /*
120  * Internally, all file status is carried in the 64-bit capable
121  * structure.
122  */
123 #if _LARGEFILE64_SOURCE
124 #define intnl_stat stat64
125 #else
126 #define intnl_stat stat
127 #endif
128 struct stat;
129
130 #ifdef _HAVE_STATVFS
131 #if _LARGEFILE64_SOURCE
132 #define intnl_statvfs statvfs64
133 #else
134 #define intnl_statvfs statvfs
135 #define INTNL_STATVFS_IS_NATURAL        1
136 #endif
137 struct statvfs;
138 struct intnl_statvfs;
139 #endif
140
141 /*
142  * Internally, all file status is carried in the 64-bit capable
143  * structure.
144  */
145 #if _LARGEFILE64_SOURCE
146 #define intnl_xtvec xtvec64
147 #else
148 #define intnl_xtvec xtvec
149 #endif
150 struct intnl_xtvec;
151
152 struct iovec;
153
154 struct utimbuf;
155
156 struct intnl_stat;
157
158 struct pnode;
159
160 extern struct pnode *_sysio_cwd;
161
162 extern mode_t _sysio_umask;
163
164 extern int _sysio_init(void);
165 extern void _sysio_shutdown(void);
166 extern int _sysio_boot(const char *buf);
167
168 /*
169  * SYSIO name label macros
170  */
171 #define XPREPEND(p,x) p ## x
172 #define PREPEND(p,x) XPREPEND(p,x)
173 #define SYSIO_LABEL_NAMES 0
174 #if SYSIO_LABEL_NAMES
175 #define SYSIO_INTERFACE_NAME(x) PREPEND(sysio__, x)
176 #else
177 #define SYSIO_INTERFACE_NAME(x) x
178 #endif
179
180 /*
181  * The following should be defined by the system includes, and probably are,
182  * but it's not illegal to have multiple externs, so long as they are the
183  * same. It helps when building the library in a standalone fashion.
184  */
185 extern int SYSIO_INTERFACE_NAME(access)(const char *path, int amode);
186 extern int SYSIO_INTERFACE_NAME(chdir)(const char *path);
187 extern int SYSIO_INTERFACE_NAME(chmod)(const char *path, mode_t mode);
188 extern int SYSIO_INTERFACE_NAME(fchmod)(int fd, mode_t mode);
189 extern int SYSIO_INTERFACE_NAME(chown)(const char *path, uid_t owner,
190                                        gid_t group);
191 extern int SYSIO_INTERFACE_NAME(fchown)(int fd, uid_t owner, gid_t group);
192 extern int SYSIO_INTERFACE_NAME(close)(int d);
193 extern int SYSIO_INTERFACE_NAME(dup)(int oldfd);
194 extern int SYSIO_INTERFACE_NAME(dup2)(int oldfd, int newfd);
195 extern int SYSIO_INTERFACE_NAME(fcntl)(int fd, int cmd, ...);
196 extern int SYSIO_INTERFACE_NAME(fstat)(int fd, struct stat *buf);
197 extern int SYSIO_INTERFACE_NAME(fsync)(int fd);
198 extern char *SYSIO_INTERFACE_NAME(getcwd)(char *buf, size_t size);
199 extern off_t SYSIO_INTERFACE_NAME(lseek)(int fd, off_t offset, int whence);
200 #if _LARGEFILE64_SOURCE
201 extern off64_t SYSIO_INTERFACE_NAME(lseek64)(int fd, off64_t offset, 
202                                              int whence);
203 #endif
204 extern int SYSIO_INTERFACE_NAME(lstat)(const char *path, struct stat *buf);
205 #ifdef BSD
206 extern int SYSIO_INTERFACE_NAME(getdirentries)(int fd, char *buf, int nbytes , 
207                                                long *basep);
208 #else
209 extern ssize_t SYSIO_INTERFACE_NAME(getdirentries)(int fd, char *buf, 
210                                                    size_t nbytes, off_t *basep);
211 #if _LARGEFILE64_SOURCE
212 extern ssize_t SYSIO_INTERFACE_NAME(getdirentries64)(int fd,
213                                                      char *buf,
214                                                      size_t nbytes,
215                                                      off64_t *basep);
216 #endif
217 #endif
218 extern int SYSIO_INTERFACE_NAME(mkdir)(const char *path, mode_t mode);
219 extern int SYSIO_INTERFACE_NAME(open)(const char *path, int flag, ...);
220 #if _LARGEFILE64_SOURCE
221 extern int SYSIO_INTERFACE_NAME(open64)(const char *path, int flag, ...);
222 #endif
223 extern int SYSIO_INTERFACE_NAME(creat)(const char *path, mode_t mode);
224 #if _LARGEFILE64_SOURCE
225 extern int SYSIO_INTERFACE_NAME(creat64)(const char *path, mode_t mode);
226 #endif
227 extern int SYSIO_INTERFACE_NAME(stat)(const char *path, struct stat *buf);
228 #if _LARGEFILE64_SOURCE
229 extern int SYSIO_INTERFACE_NAME(stat64)(const char *path, struct stat64 *buf);
230 #endif
231 #ifdef _HAVE_STATVFS
232 extern int SYSIO_INTERFACE_NAME(statvfs)(const char *path, struct statvfs *buf);
233 #if _LARGEFILE64_SOURCE
234 extern int SYSIO_INTERFACE_NAME(statvfs64)(const char *path, 
235                                 struct statvfs64 *buf);
236 #endif
237 extern int SYSIO_INTERFACE_NAME(fstatvfs)(int fd, struct statvfs *buf);
238 #if _LARGEFILE64_SOURCE
239 extern int SYSIO_INTERFACE_NAME(fstatvfs64)(int fd, struct statvfs64 *buf);
240 #endif
241 #endif
242 extern int SYSIO_INTERFACE_NAME(truncate)(const char *path, off_t length);
243 #if _LARGEFILE64_SOURCE
244 extern int SYSIO_INTERFACE_NAME(truncate64)(const char *path, off64_t length);
245 #endif
246 extern int SYSIO_INTERFACE_NAME(ftruncate)(int fd, off_t length);
247 #if _LARGEFILE64_SOURCE
248 extern int SYSIO_INTERFACE_NAME(ftruncate64)(int fd, off64_t length);
249 #endif
250 extern int SYSIO_INTERFACE_NAME(rmdir)(const char *path);
251 extern int SYSIO_INTERFACE_NAME(symlink)(const char *path1, const char *path2);
252 extern int SYSIO_INTERFACE_NAME(readlink)(const char *path,
253                                 char *buf,
254                                 size_t bufsiz);
255 extern int SYSIO_INTERFACE_NAME(link)(const char *oldpath, const char *newpath);
256 extern int SYSIO_INTERFACE_NAME(unlink)(const char *path);
257 extern int SYSIO_INTERFACE_NAME(rename)(const char *oldpath, 
258                                         const char *newpath);
259 extern int SYSIO_INTERFACE_NAME(fdatasync)(int fd);
260 extern int SYSIO_INTERFACE_NAME(ioctl)(int fd, unsigned long request, ...);
261 extern mode_t SYSIO_INTERFACE_NAME(umask)(mode_t mask);
262 extern int SYSIO_INTERFACE_NAME(iodone)(ioid_t ioid);
263 extern ssize_t SYSIO_INTERFACE_NAME(iowait)(ioid_t ioid);
264 extern ioid_t SYSIO_INTERFACE_NAME(ipreadv)(int fd, const struct iovec *iov, 
265                                    size_t count, off_t offset);
266 #if _LARGEFILE64_SOURCE
267 extern ioid_t SYSIO_INTERFACE_NAME(ipread64v)(int fd, const struct iovec *iov, 
268                                               size_t count, off64_t offset);
269 #endif
270 extern ioid_t SYSIO_INTERFACE_NAME(ipread)(int fd, void *buf, size_t count, 
271                                            off_t offset);
272 #if _LARGEFILE64_SOURCE
273 extern ioid_t SYSIO_INTERFACE_NAME(ipread64)(int fd, void *buf, size_t count, 
274                                              off64_t offset);
275 #endif
276 extern ssize_t SYSIO_INTERFACE_NAME(preadv)(int fd, const struct iovec *iov, 
277                                             size_t count, off_t offset);
278 #if _LARGEFILE64_SOURCE
279 extern ssize_t SYSIO_INTERFACE_NAME(pread64v)(int fd, const struct iovec *iov, 
280                                               size_t count, off64_t offset);
281 #endif
282 extern ssize_t SYSIO_INTERFACE_NAME(pread)(int fd, void *buf, size_t count, 
283                                            off_t offset);
284 #if _LARGEFILE64_SOURCE
285 extern ssize_t SYSIO_INTERFACE_NAME(pread64)(int fd, void *buf, size_t count, 
286                                              off64_t offset);
287 #endif
288 extern ioid_t SYSIO_INTERFACE_NAME(ireadv)(int fd, const struct iovec *iov, 
289                                            int count);
290 extern ioid_t SYSIO_INTERFACE_NAME(iread)(int fd, void *buf, size_t count);
291 extern ssize_t SYSIO_INTERFACE_NAME(readv)(int fd, const struct iovec *iov, 
292                                            int count);
293 extern ssize_t SYSIO_INTERFACE_NAME(read)(int fd, void *buf, size_t count);
294 extern ioid_t SYSIO_INTERFACE_NAME(ipwritev)(int fd, const struct iovec *iov, 
295                                              size_t count, off_t offset);
296 #if _LARGEFILE64_SOURCE
297 extern ioid_t SYSIO_INTERFACE_NAME(ipwrite64v)(int fd, const struct iovec *iov, 
298                                                size_t count, off64_t offset);
299 #endif
300 extern ioid_t SYSIO_INTERFACE_NAME(ipwrite)(int fd, const void *buf, 
301                                             size_t count, off_t offset);
302 #if _LARGEFILE64_SOURCE
303 extern ioid_t SYSIO_INTERFACE_NAME(ipwrite64)(int fd, const void *buf, 
304                                               size_t count, off64_t offset);
305 #endif
306 extern ssize_t SYSIO_INTERFACE_NAME(pwritev)(int fd, const struct iovec *iov, 
307                                              size_t count, off_t offset);
308 #if _LARGEFILE64_SOURCE
309 extern ssize_t SYSIO_INTERFACE_NAME(pwrite64v)(int fd, const struct iovec *iov, 
310                                                size_t count, off64_t offset);
311 #endif
312 extern ssize_t SYSIO_INTERFACE_NAME(pwrite)(int fd, const void *buf, 
313                                             size_t count, off_t offset);
314 #if _LARGEFILE64_SOURCE
315 extern ssize_t SYSIO_INTERFACE_NAME(pwrite64)(int fd, const void *buf, 
316                                               size_t count, off64_t offset);
317 #endif
318 extern ioid_t SYSIO_INTERFACE_NAME(iwritev)(int fd, 
319                                             const struct iovec *iov, 
320                                             int count);
321 extern ioid_t SYSIO_INTERFACE_NAME(iwrite)(int fd, const void *buf, 
322                                            size_t count);
323 extern ssize_t SYSIO_INTERFACE_NAME(writev)(int fd, const struct iovec *iov, 
324                                             int count);
325 extern ssize_t SYSIO_INTERFACE_NAME(write)(int fd, const void *buf, 
326                                            size_t count);
327 extern int SYSIO_INTERFACE_NAME(mknod)(const char *path, 
328                                        mode_t mode, dev_t dev);
329 extern int SYSIO_INTERFACE_NAME(utime)(const char *path, 
330                                        const struct utimbuf *buf);
331 extern int SYSIO_INTERFACE_NAME(mount)(const char *source, const char *target,
332                                        const char *filesystemtype,
333                                        unsigned long mountflags,
334                                        const void *data);
335 extern int SYSIO_INTERFACE_NAME(umount)(const char *target);
336
337 /* for debugging */
338 #if 0
339 #define ASSERT(cond)                                                    \
340         if (!(cond)) {                                                  \
341                 printf("ASSERTION(" #cond ") failed: " __FILE__ ":"     \
342                         __FUNCTION__ ":%d\n", __LINE__);                \
343                 abort();                                                \
344         }
345
346 #define ERROR(fmt, a...)                                                \
347         do {                                                            \
348                 printf("ERROR(" __FILE__ ":%d):" fmt, __LINE__, ##a);   \
349         while(0)
350
351 #else
352 #define ERROR(fmt)      do{}while(0)
353 #define ASSERT          do{}while(0)
354 #endif
355
356 /*
357  * SYSIO interface frame macros
358  *
359  * + DISPLAY_BLOCK; Allocates storage on the stack for use by the set of
360  *      macros.
361  * + ENTER; Performs entry point work
362  * + RETURN; Returns a value and performs exit point work
363  *
364  * NB: For RETURN, the arguments are the return value and value for errno.
365  * If the value for errno is non-zero then that value, *negated*, is set
366  * into errno.
367  */
368 #define SYSIO_INTERFACE_DISPLAY_BLOCK \
369         int _saved_errno;
370 #define SYSIO_INTERFACE_ENTER \
371         do { \
372                 _saved_errno = errno; \
373                 SYSIO_ENTER; \
374         } while (0)
375 #define SYSIO_INTERFACE_RETURN(rtn, err) \
376         do { \
377                 SYSIO_LEAVE; \
378                 errno = (err) ? -(err) : _saved_errno; \
379                 return (rtn); \
380         } while(0) 
381
382 /* syscall enter/leave hook functions  */
383 #if 0
384 extern void _sysio_sysenter();
385 extern void _sysio_sysleave();
386
387 #define SYSIO_ENTER                                                     \
388         do {                                                            \
389                 _sysio_sysenter();                                      \
390         } while(0)
391
392 #define SYSIO_LEAVE                                                     \
393         do {                                                            \
394                 _sysio_sysleave();                                      \
395         } while(0)
396 #else
397 #define SYSIO_ENTER
398 #define SYSIO_LEAVE
399
400 #endif