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 #if !defined(__IS_UNUSED) && defined(__GNUC__)
52 #define __IS_UNUSED __attribute__ ((unused))
57 #ifndef PATH_SEPARATOR
61 #define PATH_SEPARATOR '/'
66 * Max recursion depth allowed when resoving symbolic links.
68 #define MAX_SYMLINK 250
71 #ifndef _LARGEFILE64_SOURCE
73 * Not glibc I guess. Define this ourselves.
75 #define _LARGEFILE64_SOURCE 0
79 * Define internal file-offset type and it's maximum value.
81 #if _LARGEFILE64_SOURCE
82 #define _SYSIO_OFF_T off64_t
84 #define _SYSIO_OFF_T_MAX (LLONG_MAX)
87 * Don't have LLONG_MAX before C99. We'll need to define it ourselves.
89 #define _SYSIO_OFF_T_MAX (9223372036854775807LL)
92 #define _SYSIO_OFF_T off_t
93 #define _SYSIO_OFF_T_MAX LONG_MAX
97 * Internally, all directory entries are carried in the 64-bit capable
100 #if _LARGEFILE64_SOURCE
101 #define intnl_dirent dirent64
103 #define intnl_dirent dirent
108 * Internally, all file status is carried in the 64-bit capable
111 #if _LARGEFILE64_SOURCE
112 #define intnl_stat stat64
114 #define intnl_stat stat
119 #if _LARGEFILE64_SOURCE
120 #define intnl_statvfs statvfs64
122 #define intnl_statvfs statvfs
123 #define INTNL_STATVFS_IS_NATURAL 1
126 struct intnl_statvfs;
130 * Internally, all file status is carried in the 64-bit capable
133 #if _LARGEFILE64_SOURCE
134 #define intnl_xtvec xtvec64
136 #define intnl_xtvec xtvec
148 extern struct pnode *_sysio_cwd;
150 extern mode_t _sysio_umask;
152 extern int _sysio_init(void);
153 extern void _sysio_shutdown(void);
154 extern int _sysio_boot(const char *buf);
157 * SYSIO name label macros
159 #define XPREPEND(p,x) p ## x
160 #define PREPEND(p,x) XPREPEND(p,x)
161 #define SYSIO_LABEL_NAMES 0
162 #if SYSIO_LABEL_NAMES
163 #define SYSIO_INTERFACE_NAME(x) PREPEND(sysio__, x)
165 #define SYSIO_INTERFACE_NAME(x) x
169 * The following should be defined by the system includes, and probably are,
170 * but it's not illegal to have multiple externs, so long as they are the
171 * same. It helps when building the library in a standalone fashion.
173 extern int SYSIO_INTERFACE_NAME(access)(const char *path, int amode);
174 extern int SYSIO_INTERFACE_NAME(chdir)(const char *path);
175 extern int SYSIO_INTERFACE_NAME(chmod)(const char *path, mode_t mode);
176 extern int SYSIO_INTERFACE_NAME(fchmod)(int fd, mode_t mode);
177 extern int SYSIO_INTERFACE_NAME(chown)(const char *path, uid_t owner,
179 extern int SYSIO_INTERFACE_NAME(fchown)(int fd, uid_t owner, gid_t group);
180 extern int SYSIO_INTERFACE_NAME(close)(int d);
181 extern int SYSIO_INTERFACE_NAME(dup)(int oldfd);
182 extern int SYSIO_INTERFACE_NAME(dup2)(int oldfd, int newfd);
183 extern int SYSIO_INTERFACE_NAME(fcntl)(int fd, int cmd, ...);
184 extern int SYSIO_INTERFACE_NAME(fstat)(int fd, struct stat *buf);
185 extern int SYSIO_INTERFACE_NAME(fsync)(int fd);
186 extern char *SYSIO_INTERFACE_NAME(getcwd)(char *buf, size_t size);
187 extern off_t SYSIO_INTERFACE_NAME(lseek)(int fd, off_t offset, int whence);
188 #if _LARGEFILE64_SOURCE
189 extern off64_t SYSIO_INTERFACE_NAME(lseek64)(int fd, off64_t offset,
192 extern int SYSIO_INTERFACE_NAME(lstat)(const char *path, struct stat *buf);
194 extern int SYSIO_INTERFACE_NAME(getdirentries)(int fd, char *buf, int nbytes ,
197 extern ssize_t SYSIO_INTERFACE_NAME(getdirentries)(int fd, char *buf,
198 size_t nbytes, off_t *basep);
199 #if _LARGEFILE64_SOURCE
200 extern ssize_t SYSIO_INTERFACE_NAME(getdirentries64)(int fd,
206 extern int SYSIO_INTERFACE_NAME(mkdir)(const char *path, mode_t mode);
207 extern int SYSIO_INTERFACE_NAME(open)(const char *path, int flag, ...);
208 #if _LARGEFILE64_SOURCE
209 extern int SYSIO_INTERFACE_NAME(open64)(const char *path, int flag, ...);
211 extern int SYSIO_INTERFACE_NAME(creat)(const char *path, mode_t mode);
212 #if _LARGEFILE64_SOURCE
213 extern int SYSIO_INTERFACE_NAME(creat64)(const char *path, mode_t mode);
215 extern int SYSIO_INTERFACE_NAME(stat)(const char *path, struct stat *buf);
216 #if _LARGEFILE64_SOURCE
217 extern int SYSIO_INTERFACE_NAME(stat64)(const char *path, struct stat64 *buf);
220 extern int SYSIO_INTERFACE_NAME(statvfs)(const char *path, struct statvfs *buf);
221 #if _LARGEFILE64_SOURCE
222 extern int SYSIO_INTERFACE_NAME(statvfs64)(const char *path,
223 struct statvfs64 *buf);
225 extern int SYSIO_INTERFACE_NAME(fstatvfs)(int fd, struct statvfs *buf);
226 #if _LARGEFILE64_SOURCE
227 extern int SYSIO_INTERFACE_NAME(fstatvfs64)(int fd, struct statvfs64 *buf);
230 extern int SYSIO_INTERFACE_NAME(truncate)(const char *path, off_t length);
231 #if _LARGEFILE64_SOURCE
232 extern int SYSIO_INTERFACE_NAME(truncate64)(const char *path, off64_t length);
234 extern int SYSIO_INTERFACE_NAME(ftruncate)(int fd, off_t length);
235 #if _LARGEFILE64_SOURCE
236 extern int SYSIO_INTERFACE_NAME(ftruncate64)(int fd, off64_t length);
238 extern int SYSIO_INTERFACE_NAME(rmdir)(const char *path);
239 extern int SYSIO_INTERFACE_NAME(symlink)(const char *path1, const char *path2);
240 extern int SYSIO_INTERFACE_NAME(readlink)(const char *path,
243 extern int SYSIO_INTERFACE_NAME(link)(const char *oldpath, const char *newpath);
244 extern int SYSIO_INTERFACE_NAME(unlink)(const char *path);
245 extern int SYSIO_INTERFACE_NAME(rename)(const char *oldpath,
246 const char *newpath);
247 extern int SYSIO_INTERFACE_NAME(fdatasync)(int fd);
248 extern int SYSIO_INTERFACE_NAME(ioctl)(int fd, unsigned long request, ...);
249 extern mode_t SYSIO_INTERFACE_NAME(umask)(mode_t mask);
250 extern int SYSIO_INTERFACE_NAME(mknod)(const char *path,
251 mode_t mode, dev_t dev);
252 extern int SYSIO_INTERFACE_NAME(utime)(const char *path,
253 const struct utimbuf *buf);
254 extern int SYSIO_INTERFACE_NAME(mount)(const char *source, const char *target,
255 const char *filesystemtype,
256 unsigned long mountflags,
258 extern int SYSIO_INTERFACE_NAME(umount)(const char *target);
262 #define ASSERT(cond) \
264 printf("ASSERTION(" #cond ") failed: " __FILE__ ":" \
265 __FUNCTION__ ":%d\n", __LINE__); \
269 #define ERROR(fmt, a...) \
271 printf("ERROR(" __FILE__ ":%d):" fmt, __LINE__, ##a); \
275 #define ERROR(fmt) do{}while(0)
276 #define ASSERT do{}while(0)
280 * SYSIO interface frame macros
282 * + DISPLAY_BLOCK; Allocates storage on the stack for use by the set of
284 * + ENTER; Performs entry point work
285 * + RETURN; Returns a value and performs exit point work
287 * NB: For RETURN, the arguments are the return value and value for errno.
288 * If the value for errno is non-zero then that value, *negated*, is set
291 #define SYSIO_INTERFACE_DISPLAY_BLOCK \
293 #define SYSIO_INTERFACE_ENTER \
295 _saved_errno = errno; \
298 #define SYSIO_INTERFACE_RETURN(rtn, err) \
301 errno = (err) ? -(err) : _saved_errno; \
305 /* syscall enter/leave hook functions */
307 extern void _sysio_sysenter();
308 extern void _sysio_sysleave();
310 #define SYSIO_ENTER \
315 #define SYSIO_LEAVE \
325 /* accounting for IO stats read and write char count */
326 #if defined(REDSTORM)
327 #define _SYSIO_UPDACCT(w, cc) \
332 _add_iostats(0, (size_t )(cc)); \
334 _add_iostats((size_t )(cc), 0); \
337 #define _SYSIO_UPDACCT(w, cc)