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