2 * This Cplant(TM) source code is the property of Sandia National
5 * This Cplant(TM) source code is copyrighted by Sandia National
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)
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
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.
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.
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
34 * Questions or comments about this library should be sent to:
37 * Sandia National Laboratories, New Mexico
39 * Albuquerque, NM 87185-1110
45 * System IO common information.
51 #ifndef _IOID_T_DEFINED
52 #define _IOID_T_DEFINED
56 * This section about ioid_t and it's failure belong in <sys/types.h>
63 #if !defined(__IS_UNUSED) && defined(__GNUC__)
64 #define __IS_UNUSED __attribute__ ((unused))
69 #ifndef PATH_SEPARATOR
73 #define PATH_SEPARATOR '/'
78 * Max recursion depth allowed when resoving symbolic links.
80 #define MAX_SYMLINK 250
83 #ifndef _LARGEFILE64_SOURCE
85 * Not glibc I guess. Define this ourselves.
87 #define _LARGEFILE64_SOURCE 0
91 * Define internal file-offset type and it's maximum value.
93 #if _LARGEFILE64_SOURCE
94 #define _SYSIO_OFF_T off64_t
96 #define _SYSIO_OFF_T_MAX (LLONG_MAX)
99 * Don't have LLONG_MAX before C99. We'll need to define it ourselves.
101 #define _SYSIO_OFF_T_MAX (9223372036854775807LL)
104 #define _SYSIO_OFF_T off_t
105 #define _SYSIO_OFF_T_MAX LONG_MAX
109 * Internally, all directory entries are carried in the 64-bit capable
112 #if _LARGEFILE64_SOURCE
113 #define intnl_dirent dirent64
115 #define intnl_dirent dirent
120 * Internally, all file status is carried in the 64-bit capable
123 #if _LARGEFILE64_SOURCE
124 #define intnl_stat stat64
126 #define intnl_stat stat
131 #if _LARGEFILE64_SOURCE
132 #define intnl_statvfs statvfs64
134 #define intnl_statvfs statvfs
135 #define INTNL_STATVFS_IS_NATURAL 1
138 struct intnl_statvfs;
142 * Internally, all file status is carried in the 64-bit capable
145 #if _LARGEFILE64_SOURCE
146 #define intnl_xtvec xtvec64
148 #define intnl_xtvec xtvec
160 extern struct pnode *_sysio_cwd;
162 extern mode_t _sysio_umask;
164 extern int _sysio_init(void);
165 extern void _sysio_shutdown(void);
166 extern int _sysio_boot(const char *buf);
169 * SYSIO name label macros
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)
177 #define SYSIO_INTERFACE_NAME(x) x
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.
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,
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,
204 extern int SYSIO_INTERFACE_NAME(lstat)(const char *path, struct stat *buf);
206 extern int SYSIO_INTERFACE_NAME(getdirentries)(int fd, char *buf, int nbytes ,
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,
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, ...);
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);
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);
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);
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);
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);
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);
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,
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);
270 extern ioid_t SYSIO_INTERFACE_NAME(ipread)(int fd, void *buf, size_t count,
272 #if _LARGEFILE64_SOURCE
273 extern ioid_t SYSIO_INTERFACE_NAME(ipread64)(int fd, void *buf, size_t count,
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);
282 extern ssize_t SYSIO_INTERFACE_NAME(pread)(int fd, void *buf, size_t count,
284 #if _LARGEFILE64_SOURCE
285 extern ssize_t SYSIO_INTERFACE_NAME(pread64)(int fd, void *buf, size_t count,
288 extern ioid_t SYSIO_INTERFACE_NAME(ireadv)(int fd, const struct iovec *iov,
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,
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);
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);
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);
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);
318 extern ioid_t SYSIO_INTERFACE_NAME(iwritev)(int fd,
319 const struct iovec *iov,
321 extern ioid_t SYSIO_INTERFACE_NAME(iwrite)(int fd, const void *buf,
323 extern ssize_t SYSIO_INTERFACE_NAME(writev)(int fd, const struct iovec *iov,
325 extern ssize_t SYSIO_INTERFACE_NAME(write)(int fd, const void *buf,
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,
335 extern int SYSIO_INTERFACE_NAME(umount)(const char *target);
339 #define ASSERT(cond) \
341 printf("ASSERTION(" #cond ") failed: " __FILE__ ":" \
342 __FUNCTION__ ":%d\n", __LINE__); \
346 #define ERROR(fmt, a...) \
348 printf("ERROR(" __FILE__ ":%d):" fmt, __LINE__, ##a); \
352 #define ERROR(fmt) do{}while(0)
353 #define ASSERT do{}while(0)
357 * SYSIO interface frame macros
359 * + DISPLAY_BLOCK; Allocates storage on the stack for use by the set of
361 * + ENTER; Performs entry point work
362 * + RETURN; Returns a value and performs exit point work
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
368 #define SYSIO_INTERFACE_DISPLAY_BLOCK \
370 #define SYSIO_INTERFACE_ENTER \
372 _saved_errno = errno; \
375 #define SYSIO_INTERFACE_RETURN(rtn, err) \
378 errno = (err) ? -(err) : _saved_errno; \
382 /* syscall enter/leave hook functions */
384 extern void _sysio_sysenter();
385 extern void _sysio_sysleave();
387 #define SYSIO_ENTER \
392 #define SYSIO_LEAVE \