1 /* -*- mode: c; c-basic-offset: 4; indent-tabs-mode: nil; -*-
2 * vim:expandtab:shiftwidth=4:tabstop=4:
4 * Copyright (C) 2001 Cluster File Systems, Inc. <braam@clusterfs.com>
6 * This file is part of Lustre, http://www.lustre.org.
8 * Lustre is free software; you can redistribute it and/or
9 * modify it under the terms of version 2 of the GNU General Public
10 * License as published by the Free Software Foundation.
12 * Lustre is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
17 * You should have received a copy of the GNU General Public License
18 * along with Lustre; if not, write to the Free Software
19 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
21 * Basic types definitions
54 #define __LITTLE_ENDIAN
56 #define inline __inline
57 #define __inline__ __inline
59 typedef unsigned __int8 __u8;
60 typedef signed __int8 __s8;
62 typedef signed __int64 __s64;
63 typedef unsigned __int64 __u64;
65 typedef signed __int16 __s16;
66 typedef unsigned __int16 __u16;
68 typedef signed __int32 __s32;
69 typedef unsigned __int32 __u32;
71 typedef signed __int64 __s64;
72 typedef unsigned __int64 __u64;
74 typedef unsigned long ULONG;
78 #define long_ptr __int64
79 #define ulong_ptr unsigned __int64
80 #define BITS_PER_LONG (64)
83 #define ulong_ptr unsigned long
84 #define BITS_PER_LONG (32)
89 typedef unsigned char u_char;
90 typedef unsigned short u_short;
91 typedef unsigned int u_int;
92 typedef unsigned long u_long;
95 typedef unsigned char unchar;
96 typedef unsigned short ushort;
97 typedef unsigned int uint;
98 typedef unsigned long ulong;
100 #ifndef __BIT_TYPES_DEFINED__
101 #define __BIT_TYPES_DEFINED__
103 typedef __u8 u_int8_t;
105 typedef __u16 u_int16_t;
106 typedef __s16 int16_t;
107 typedef __u32 u_int32_t;
108 typedef __s32 int32_t;
110 #endif /* !(__BIT_TYPES_DEFINED__) */
112 typedef __u8 uint8_t;
113 typedef __u16 uint16_t;
114 typedef __u32 uint32_t;
116 typedef __u64 uint64_t;
117 typedef __u64 u_int64_t;
118 typedef __s64 int64_t;
120 typedef long ssize_t;
122 typedef __u32 suseconds_t;
124 typedef __u32 pid_t, tid_t;
126 typedef __u16 uid_t, gid_t;
128 typedef __u16 mode_t;
129 typedef __u16 umode_t;
131 typedef ulong_ptr sigset_t;
133 typedef uint64_t loff_t;
134 typedef HANDLE cfs_handle_t;
135 typedef uint64_t cycles_t;
137 #ifndef INVALID_HANDLE_VALUE
138 #define INVALID_HANDLE_VALUE ((HANDLE)-1)
142 #ifdef __KERNEL__ /* kernel */
145 typedef __u32 time_t;
147 typedef unsigned short kdev_t;
149 #else /* !__KERNEL__ */
156 #endif /* __KERNEL__ */
166 * Winnt kernel has no capabilities.
169 typedef __u32 cfs_kernel_cap_t;
171 #define INT_MAX ((int)(~0U>>1))
172 #define INT_MIN (-INT_MAX - 1)
173 #define UINT_MAX (~0U)
175 #endif /* _WINNT_TYPES_H */
183 // Byte order swapping routines
187 #define ___swab16(x) RtlUshortByteSwap(x)
188 #define ___swab32(x) RtlUlongByteSwap(x)
189 #define ___swab64(x) RtlUlonglongByteSwap(x)
191 #define ___constant_swab16(x) \
193 (((__u16)(x) & (__u16)0x00ffU) << 8) | \
194 (((__u16)(x) & (__u16)0xff00U) >> 8) ))
196 #define ___constant_swab32(x) \
198 (((__u32)(x) & (__u32)0x000000ffUL) << 24) | \
199 (((__u32)(x) & (__u32)0x0000ff00UL) << 8) | \
200 (((__u32)(x) & (__u32)0x00ff0000UL) >> 8) | \
201 (((__u32)(x) & (__u32)0xff000000UL) >> 24) ))
203 #define ___constant_swab64(x) \
205 (__u64)(((__u64)(x) & (__u64)0x00000000000000ffUL) << 56) | \
206 (__u64)(((__u64)(x) & (__u64)0x000000000000ff00UL) << 40) | \
207 (__u64)(((__u64)(x) & (__u64)0x0000000000ff0000UL) << 24) | \
208 (__u64)(((__u64)(x) & (__u64)0x00000000ff000000UL) << 8) | \
209 (__u64)(((__u64)(x) & (__u64)0x000000ff00000000UL) >> 8) | \
210 (__u64)(((__u64)(x) & (__u64)0x0000ff0000000000UL) >> 24) | \
211 (__u64)(((__u64)(x) & (__u64)0x00ff000000000000UL) >> 40) | \
212 (__u64)(((__u64)(x) & (__u64)0xff00000000000000UL) >> 56) ))
215 #define __swab16(x) ___constant_swab16(x)
216 #define __swab32(x) ___constant_swab32(x)
217 #define __swab64(x) ___constant_swab64(x)
219 #define __swab16s(x) do { *(x) = __swab16((USHORT)(*(x)));} while(0)
220 #define __swab32s(x) do { *(x) = __swab32((ULONG)(*(x)));} while(0)
221 #define __swab64s(x) do { *(x) = __swab64((ULONGLONG)(*(x)));} while(0)
223 #define __constant_htonl(x) ___constant_swab32((x))
224 #define __constant_ntohl(x) ___constant_swab32((x))
225 #define __constant_htons(x) ___constant_swab16((x))
226 #define __constant_ntohs(x) ___constant_swab16((x))
227 #define __constant_cpu_to_le64(x) ((__u64)(x))
228 #define __constant_le64_to_cpu(x) ((__u64)(x))
229 #define __constant_cpu_to_le32(x) ((__u32)(x))
230 #define __constant_le32_to_cpu(x) ((__u32)(x))
231 #define __constant_cpu_to_le16(x) ((__u16)(x))
232 #define __constant_le16_to_cpu(x) ((__u16)(x))
233 #define __constant_cpu_to_be64(x) ___constant_swab64((x))
234 #define __constant_be64_to_cpu(x) ___constant_swab64((x))
235 #define __constant_cpu_to_be32(x) ___constant_swab32((x))
236 #define __constant_be32_to_cpu(x) ___constant_swab32((x))
237 #define __constant_cpu_to_be16(x) ___constant_swab16((x))
238 #define __constant_be16_to_cpu(x) ___constant_swab16((x))
239 #define __cpu_to_le64(x) ((__u64)(x))
240 #define __le64_to_cpu(x) ((__u64)(x))
241 #define __cpu_to_le32(x) ((__u32)(x))
242 #define __le32_to_cpu(x) ((__u32)(x))
243 #define __cpu_to_le16(x) ((__u16)(x))
244 #define __le16_to_cpu(x) ((__u16)(x))
245 #define __cpu_to_be64(x) __swab64((x))
246 #define __be64_to_cpu(x) __swab64((x))
247 #define __cpu_to_be32(x) __swab32((x))
248 #define __be32_to_cpu(x) __swab32((x))
249 #define __cpu_to_be16(x) __swab16((x))
250 #define __be16_to_cpu(x) __swab16((x))
251 #define __cpu_to_le64p(x) (*(__u64*)(x))
252 #define __le64_to_cpup(x) (*(__u64*)(x))
253 #define __cpu_to_le32p(x) (*(__u32*)(x))
254 #define __le32_to_cpup(x) (*(__u32*)(x))
255 #define __cpu_to_le16p(x) (*(__u16*)(x))
256 #define __le16_to_cpup(x) (*(__u16*)(x))
257 #define __cpu_to_be64p(x) __swab64p((x))
258 #define __be64_to_cpup(x) __swab64p((x))
259 #define __cpu_to_be32p(x) __swab32p((x))
260 #define __be32_to_cpup(x) __swab32p((x))
261 #define __cpu_to_be16p(x) __swab16p((x))
262 #define __be16_to_cpup(x) __swab16p((x))
263 #define __cpu_to_le64s(x) do {} while (0)
264 #define __le64_to_cpus(x) do {} while (0)
265 #define __cpu_to_le32s(x) do {} while (0)
266 #define __le32_to_cpus(x) do {} while (0)
267 #define __cpu_to_le16s(x) do {} while (0)
268 #define __le16_to_cpus(x) do {} while (0)
269 #define __cpu_to_be64s(x) __swab64s((x))
270 #define __be64_to_cpus(x) __swab64s((x))
271 #define __cpu_to_be32s(x) __swab32s((x))
272 #define __be32_to_cpus(x) __swab32s((x))
273 #define __cpu_to_be16s(x) __swab16s((x))
274 #define __be16_to_cpus(x) __swab16s((x))
277 #define cpu_to_le64 __cpu_to_le64
278 #define le64_to_cpu __le64_to_cpu
279 #define cpu_to_le32 __cpu_to_le32
280 #define le32_to_cpu __le32_to_cpu
281 #define cpu_to_le16 __cpu_to_le16
282 #define le16_to_cpu __le16_to_cpu
285 #define cpu_to_be64 __cpu_to_be64
286 #define be64_to_cpu __be64_to_cpu
287 #define cpu_to_be32 __cpu_to_be32
288 #define be32_to_cpu __be32_to_cpu
289 #define cpu_to_be16 __cpu_to_be16
290 #define be16_to_cpu __be16_to_cpu
291 #define cpu_to_le64p __cpu_to_le64p
292 #define le64_to_cpup __le64_to_cpup
293 #define cpu_to_le32p __cpu_to_le32p
294 #define le32_to_cpup __le32_to_cpup
295 #define cpu_to_le16p __cpu_to_le16p
296 #define le16_to_cpup __le16_to_cpup
297 #define cpu_to_be64p __cpu_to_be64p
298 #define be64_to_cpup __be64_to_cpup
299 #define cpu_to_be32p __cpu_to_be32p
300 #define be32_to_cpup __be32_to_cpup
301 #define cpu_to_be16p __cpu_to_be16p
302 #define be16_to_cpup __be16_to_cpup
303 #define cpu_to_le64s __cpu_to_le64s
304 #define le64_to_cpus __le64_to_cpus
305 #define cpu_to_le32s __cpu_to_le32s
306 #define le32_to_cpus __le32_to_cpus
307 #define cpu_to_le16s __cpu_to_le16s
308 #define le16_to_cpus __le16_to_cpus
309 #define cpu_to_be64s __cpu_to_be64s
310 #define be64_to_cpus __be64_to_cpus
311 #define cpu_to_be32s __cpu_to_be32s
312 #define be32_to_cpus __be32_to_cpus
313 #define cpu_to_be16s __cpu_to_be16s
314 #define be16_to_cpus __be16_to_cpus
318 // Network to host byte swap functions
321 #define ntohl(x) ( ( ( ( x ) & 0x000000ff ) << 24 ) | \
322 ( ( ( x ) & 0x0000ff00 ) << 8 ) | \
323 ( ( ( x ) & 0x00ff0000 ) >> 8 ) | \
324 ( ( ( x ) & 0xff000000 ) >> 24 ) )
326 #define ntohs(x) ( ( ( ( x ) & 0xff00 ) >> 8 ) | \
327 ( ( ( x ) & 0x00ff ) << 8 ) )
330 #define htonl(x) ntohl(x)
331 #define htons(x) ntohs(x)
335 #ifndef _I386_ERRNO_H
336 #define _I386_ERRNO_H
338 #define EPERM 1 /* Operation not permitted */
339 #define ENOENT 2 /* No such file or directory */
340 #define ESRCH 3 /* No such process */
341 #define EINTR 4 /* Interrupted system call */
342 #define EIO 5 /* I/O error */
343 #define ENXIO 6 /* No such device or address */
344 #define E2BIG 7 /* Arg list too long */
345 #define ENOEXEC 8 /* Exec format error */
346 #define EBADF 9 /* Bad file number */
347 #define ECHILD 10 /* No child processes */
348 #define EAGAIN 11 /* Try again */
349 #define ENOMEM 12 /* Out of memory */
350 #define EACCES 13 /* Permission denied */
351 #define EFAULT 14 /* Bad address */
352 #define ENOTBLK 15 /* Block device required */
353 #define EBUSY 16 /* Device or resource busy */
354 #define EEXIST 17 /* File exists */
355 #define EXDEV 18 /* Cross-device link */
356 #define ENODEV 19 /* No such device */
357 #define ENOTDIR 20 /* Not a directory */
358 #define EISDIR 21 /* Is a directory */
359 #define EINVAL 22 /* Invalid argument */
360 #define ENFILE 23 /* File table overflow */
361 #define EMFILE 24 /* Too many open files */
362 #define ENOTTY 25 /* Not a typewriter */
363 #define ETXTBSY 26 /* Text file busy */
364 #define EFBIG 27 /* File too large */
365 #define ENOSPC 28 /* No space left on device */
366 #define ESPIPE 29 /* Illegal seek */
367 #define EROFS 30 /* Read-only file system */
368 #define EMLINK 31 /* Too many links */
369 #define EPIPE 32 /* Broken pipe */
370 #define EDOM 33 /* Math argument out of domain of func */
371 #define ERANGE 34 /* Math result not representable */
373 #define EDEADLK 35 /* Resource deadlock would occur */
375 #define ENAMETOOLONG 36 /* File name too long */
377 #define ENOLCK 37 /* No record locks available */
379 #define ENOSYS 38 /* Function not implemented */
381 #define ENOTEMPTY 39 /* Directory not empty */
382 #define ELOOP 40 /* Too many symbolic links encountered */
383 #define EWOULDBLOCK EAGAIN /* Operation would block */
384 #define ENOMSG 42 /* No message of desired type */
385 #define EIDRM 43 /* Identifier removed */
386 #define ECHRNG 44 /* Channel number out of range */
387 #define EL2NSYNC 45 /* Level 2 not synchronized */
388 #define EL3HLT 46 /* Level 3 halted */
389 #define EL3RST 47 /* Level 3 reset */
390 #define ELNRNG 48 /* Link number out of range */
391 #define EUNATCH 49 /* Protocol driver not attached */
392 #define ENOCSI 50 /* No CSI structure available */
393 #define EL2HLT 51 /* Level 2 halted */
394 #define EBADE 52 /* Invalid exchange */
395 #define EBADR 53 /* Invalid request descriptor */
396 #define EXFULL 54 /* Exchange full */
397 #define ENOANO 55 /* No anode */
398 #define EBADRQC 56 /* Invalid request code */
399 #define EBADSLT 57 /* Invalid slot */
401 #define EDEADLOCK EDEADLK
403 #define EBFONT 59 /* Bad font file format */
404 #define ENOSTR 60 /* Device not a stream */
405 #define ENODATA 61 /* No data available */
406 #define ETIME 62 /* Timer expired */
407 #define ENOSR 63 /* Out of streams resources */
408 #define ENONET 64 /* Machine is not on the network */
409 #define ENOPKG 65 /* Package not installed */
410 #define EREMOTE 66 /* Object is remote */
411 #define ENOLINK 67 /* Link has been severed */
412 #define EADV 68 /* Advertise error */
413 #define ESRMNT 69 /* Srmount error */
414 #define ECOMM 70 /* Communication error on send */
415 #define EPROTO 71 /* Protocol error */
416 #define EMULTIHOP 72 /* Multihop attempted */
417 #define EDOTDOT 73 /* RFS specific error */
418 #define EBADMSG 74 /* Not a data message */
419 #define EOVERFLOW 75 /* Value too large for defined data type */
420 #define ENOTUNIQ 76 /* Name not unique on network */
421 #define EBADFD 77 /* File descriptor in bad state */
422 #define EREMCHG 78 /* Remote address changed */
423 #define ELIBACC 79 /* Can not access a needed shared library */
424 #define ELIBBAD 80 /* Accessing a corrupted shared library */
425 #define ELIBSCN 81 /* .lib section in a.out corrupted */
426 #define ELIBMAX 82 /* Attempting to link in too many shared libraries */
427 #define ELIBEXEC 83 /* Cannot exec a shared library directly */
429 #define EILSEQ 84 /* Illegal byte sequence */
430 #define ERESTART 85 /* Interrupted system call should be restarted */
431 #define ESTRPIPE 86 /* Streams pipe error */
432 #define EUSERS 87 /* Too many users */
433 #define ENOTSOCK 88 /* Socket operation on non-socket */
434 #define EDESTADDRREQ 89 /* Destination address required */
435 #define EMSGSIZE 90 /* Message too long */
436 #define EPROTOTYPE 91 /* Protocol wrong type for socket */
437 #define ENOPROTOOPT 92 /* Protocol not available */
438 #define EPROTONOSUPPORT 93 /* Protocol not supported */
439 #define ESOCKTNOSUPPORT 94 /* Socket type not supported */
440 #define EOPNOTSUPP 95 /* Operation not supported on transport endpoint */
441 #define EPFNOSUPPORT 96 /* Protocol family not supported */
442 #define EAFNOSUPPORT 97 /* Address family not supported by protocol */
443 #define EADDRINUSE 98 /* Address already in use */
444 #define EADDRNOTAVAIL 99 /* Cannot assign requested address */
445 #define ENETDOWN 100 /* Network is down */
446 #define ENETUNREACH 101 /* Network is unreachable */
447 #define ENETRESET 102 /* Network dropped connection because of reset */
448 #define ECONNABORTED 103 /* Software caused connection abort */
449 #define ECONNRESET 104 /* Connection reset by peer */
450 #define ENOBUFS 105 /* No buffer space available */
451 #define EISCONN 106 /* Transport endpoint is already connected */
452 #define ENOTCONN 107 /* Transport endpoint is not connected */
453 #define ESHUTDOWN 108 /* Cannot send after transport endpoint shutdown */
454 #define ETOOMANYREFS 109 /* Too many references: cannot splice */
455 #define ETIMEDOUT 110 /* Connection timed out */
456 #define ECONNREFUSED 111 /* Connection refused */
457 #define EHOSTDOWN 112 /* Host is down */
458 #define EHOSTUNREACH 113 /* No route to host */
459 #define EALREADY 114 /* Operation already in progress */
460 #define EINPROGRESS 115 /* Operation now in progress */
461 #define ESTALE 116 /* Stale NFS file handle */
462 #define EUCLEAN 117 /* Structure needs cleaning */
463 #define ENOTNAM 118 /* Not a XENIX named type file */
464 #define ENAVAIL 119 /* No XENIX semaphores available */
465 #define EISNAM 120 /* Is a named type file */
466 #define EREMOTEIO 121 /* Remote I/O error */
467 #define EDQUOT 122 /* Quota exceeded */
469 #define ENOMEDIUM 123 /* No medium found */
470 #define EMEDIUMTYPE 124 /* Wrong medium type */
472 /* Should never be seen by user programs */
473 #define ERESTARTSYS 512
474 #define ERESTARTNOINTR 513
475 #define ERESTARTNOHAND 514 /* restart if no handler.. */
476 #define ENOIOCTLCMD 515 /* No ioctl command */
478 /* Defined for the NFSv3 protocol */
479 #define EBADHANDLE 521 /* Illegal NFS file handle */
480 #define ENOTSYNC 522 /* Update synchronization mismatch */
481 #define EBADCOOKIE 523 /* Cookie is stale */
482 #define ENOTSUPP 524 /* Operation is not supported */
483 #define ETOOSMALL 525 /* Buffer or request is too small */
484 #define ESERVERFAULT 526 /* An untranslatable error occurred */
485 #define EBADTYPE 527 /* Type not supported by server */
486 #define EJUKEBOX 528 /* Request initiated, but will not complete before timeout */
490 /* open/fcntl - O_SYNC is only implemented on blocks devices and on files
491 located on an ext2 file system */
492 #define O_ACCMODE 0003
496 #define O_CREAT 0100 /* not fcntl */
497 #define O_EXCL 0200 /* not fcntl */
498 #define O_NOCTTY 0400 /* not fcntl */
499 #define O_TRUNC 01000 /* not fcntl */
500 #define O_APPEND 02000
501 #define O_NONBLOCK 04000
502 #define O_NDELAY O_NONBLOCK
503 #define O_SYNC 010000
504 #define FASYNC 020000 /* fcntl, for BSD compatibility */
505 #define O_DIRECT 040000 /* direct disk access hint */
506 #define O_LARGEFILE 0100000
507 #define O_DIRECTORY 0200000 /* must be a directory */
508 #define O_NOFOLLOW 0400000 /* don't follow links */
510 #define F_DUPFD 0 /* dup */
511 #define F_GETFD 1 /* get close_on_exec */
512 #define F_SETFD 2 /* set/clear close_on_exec */
513 #define F_GETFL 3 /* get file->f_flags */
514 #define F_SETFL 4 /* set file->f_flags */
519 #define F_SETOWN 8 /* for sockets. */
520 #define F_GETOWN 9 /* for sockets. */
521 #define F_SETSIG 10 /* for sockets. */
522 #define F_GETSIG 11 /* for sockets. */
524 #define F_GETLK64 12 /* using 'struct flock64' */
526 #define F_SETLKW64 14
528 /* for F_[GET|SET]FL */
529 #define FD_CLOEXEC 1 /* actually anything with low bit set goes */
531 /* for posix fcntl() and lockf() */
536 /* for old implementation of bsd flock () */
537 #define F_EXLCK 4 /* or 3 */
538 #define F_SHLCK 8 /* or 4 */
541 #define F_INPROGRESS 16
543 /* operations for bsd flock(), also used by the kernel implementation */
544 #define LOCK_SH 1 /* shared lock */
545 #define LOCK_EX 2 /* exclusive lock */
546 #define LOCK_NB 4 /* or'd with one of the above to prevent
548 #define LOCK_UN 8 /* remove lock */
550 #define LOCK_MAND 32 /* This is a mandatory flock */
551 #define LOCK_READ 64 /* ... Which allows concurrent read operations */
552 #define LOCK_WRITE 128 /* ... Which allows concurrent write operations */
553 #define LOCK_RW 192 /* ... Which allows concurrent read & write ops */
558 #ifndef LIBCFS_SIGNAL_H
559 #define LIBCFS_SIGNAL_H
595 #define SIGPOLL SIGIO
603 /* These should not be considered constants from userland. */
605 #define SIGRTMAX (_NSIG-1)
610 * SA_ONSTACK indicates that a registered stack_t will be used.
611 * SA_INTERRUPT is a no-op, but left due to historical reasons. Use the
612 * SA_RESTART flag to get restarting signals (which were the default long ago)
613 * SA_NOCLDSTOP flag to turn off SIGCHLD when children stop.
614 * SA_RESETHAND clears the handler when the signal is delivered.
615 * SA_NOCLDWAIT flag on SIGCHLD to inhibit zombies.
616 * SA_NODEFER prevents the current signal from being masked in the handler.
618 * SA_ONESHOT and SA_NOMASK are the historical Linux names for the Single
619 * Unix names RESETHAND and NODEFER respectively.
621 #define SA_NOCLDSTOP 0x00000001
622 #define SA_NOCLDWAIT 0x00000002 /* not supported yet */
623 #define SA_SIGINFO 0x00000004
624 #define SA_ONSTACK 0x08000000
625 #define SA_RESTART 0x10000000
626 #define SA_NODEFER 0x40000000
627 #define SA_RESETHAND 0x80000000
629 #define SA_NOMASK SA_NODEFER
630 #define SA_ONESHOT SA_RESETHAND
631 #define SA_INTERRUPT 0x20000000 /* dummy -- ignored */
633 #define SA_RESTORER 0x04000000
636 * sigaltstack controls
641 #define MINSIGSTKSZ 2048
642 #define SIGSTKSZ 8192
645 #define sigmask(sig) ((__u32)1 << ((sig) - 1))
647 #endif // LIBCFS_SIGNAL_H