Whamcloud - gitweb
Land b_head_libcfs onto HEAD (20080805_1722)
[fs/lustre-release.git] / libcfs / include / libcfs / posix / libcfs.h
1 /* -*- mode: c; c-basic-offset: 8; indent-tabs-mode: nil; -*-
2  * vim:expandtab:shiftwidth=8:tabstop=8:
3  *
4  * GPL HEADER START
5  *
6  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
7  *
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.
11  *
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).
17  *
18  * You should have received a copy of the GNU General Public License
19  * version 2 along with this program; If not, see [sun.com URL with a
20  * copy of GPLv2].
21  *
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
24  * have any questions.
25  *
26  * GPL HEADER END
27  */
28 /*
29  * Copyright  2008 Sun Microsystems, Inc. All rights reserved
30  * Use is subject to license terms.
31  */
32 /*
33  * This file is part of Lustre, http://www.lustre.org/
34  * Lustre is a trademark of Sun Microsystems, Inc.
35  *
36  * libcfs/include/libcfs/posix/libcfs.h
37  *
38  * Defines for posix userspace.
39  *
40  * Author: Robert Read <rread@sun.com>
41  */
42
43 #ifndef __LIBCFS_POSIX_LIBCFS_H__
44 #define __LIBCFS_POSIX_LIBCFS_H__
45
46 #include <sys/errno.h>
47 #include <string.h>
48 #include <stdarg.h>
49 #include <stdio.h>
50 #include <stdlib.h>
51 #include <sys/mman.h>
52 #include <sys/stat.h>
53 #include <unistd.h>
54 #include <fcntl.h>
55 #include <limits.h>
56 #include <assert.h>
57 #include <sys/signal.h>
58 #include <signal.h>
59 #include <sys/time.h>
60 #include <time.h>
61
62 #ifdef HAVE_LIBPTHREAD
63 #include <pthread.h>
64 #endif
65
66 #if defined(HAVE_SYS_TYPES_H)
67 #include <sys/types.h>
68 #endif
69
70 #ifdef HAVE_SYS_USER_H
71 # include <sys/user.h>
72 #endif
73
74 #ifdef HAVE_SYS_VFS_H
75 # include <sys/vfs.h>
76 #endif
77
78 #ifdef HAVE_STDINT_H
79 # include <stdint.h>
80 #endif
81
82 #include <libcfs/list.h>
83 #include <libcfs/posix/posix-types.h>
84 #include <libcfs/user-time.h>
85 #include <libcfs/user-prim.h>
86 #include <libcfs/user-mem.h>
87 #include <libcfs/user-lock.h>
88 #include <libcfs/user-tcpip.h>
89 #include <libcfs/posix/posix-wordsize.h>
90 #include <libcfs/user-bitops.h>
91
92 # define do_gettimeofday(tv) gettimeofday(tv, NULL);
93 typedef unsigned long long cycles_t;
94
95 #define IS_ERR(a) ((unsigned long)(a) > (unsigned long)-1000L)
96 #define PTR_ERR(a) ((long)(a))
97 #define ERR_PTR(a) ((void*)((long)(a)))
98
99 /* this goes in posix-fs.h */
100 #include <sys/mount.h>
101
102 #ifdef __linux__
103 #include <mntent.h>
104 #endif
105
106 typedef struct file cfs_file_t;
107 typedef struct dentry cfs_dentry_t;
108 #ifdef __linux__
109 typedef struct dirent64 cfs_dirent_t;
110 #endif
111
112 #ifdef __linux__
113 /* Userpace byte flipping */
114 # include <endian.h>
115 # include <byteswap.h>
116 # define __swab16(x) bswap_16(x)
117 # define __swab32(x) bswap_32(x)
118 # define __swab64(x) bswap_64(x)
119 # define __swab16s(x) do {*(x) = bswap_16(*(x));} while (0)
120 # define __swab32s(x) do {*(x) = bswap_32(*(x));} while (0)
121 # define __swab64s(x) do {*(x) = bswap_64(*(x));} while (0)
122 # if __BYTE_ORDER == __LITTLE_ENDIAN
123 #  define le16_to_cpu(x) (x)
124 #  define cpu_to_le16(x) (x)
125 #  define le32_to_cpu(x) (x)
126 #  define cpu_to_le32(x) (x)
127 #  define le64_to_cpu(x) (x)
128 #  define cpu_to_le64(x) (x)
129
130 #  define be16_to_cpu(x) bswap_16(x)
131 #  define cpu_to_be16(x) bswap_16(x)
132 #  define be32_to_cpu(x) bswap_32(x)
133 #  define cpu_to_be32(x) bswap_32(x)
134 #  define be64_to_cpu(x) bswap_64(x)
135 #  define cpu_to_be64(x) bswap_64(x)
136 # else
137 #  if __BYTE_ORDER == __BIG_ENDIAN
138 #   define le16_to_cpu(x) bswap_16(x)
139 #   define cpu_to_le16(x) bswap_16(x)
140 #   define le32_to_cpu(x) bswap_32(x)
141 #   define cpu_to_le32(x) bswap_32(x)
142 #   define le64_to_cpu(x) bswap_64(x)
143 #   define cpu_to_le64(x) bswap_64(x)
144
145 #   define be16_to_cpu(x) (x)
146 #   define cpu_to_be16(x) (x)
147 #   define be32_to_cpu(x) (x)
148 #   define cpu_to_be32(x) (x)
149 #   define be64_to_cpu(x) (x)
150 #   define cpu_to_be64(x) (x)
151
152 #  else
153 #   error "Unknown byte order"
154 #  endif /* __BIG_ENDIAN */
155 # endif /* __LITTLE_ENDIAN */
156 #elif __APPLE__
157 #define __cpu_to_le64(x)                        OSSwapHostToLittleInt64(x)
158 #define __cpu_to_le32(x)                        OSSwapHostToLittleInt32(x)
159 #define __cpu_to_le16(x)                        OSSwapHostToLittleInt16(x)
160
161 #define __le16_to_cpu(x)                        OSSwapLittleToHostInt16(x)
162 #define __le32_to_cpu(x)                        OSSwapLittleToHostInt32(x)
163 #define __le64_to_cpu(x)                        OSSwapLittleToHostInt64(x)
164
165 #define cpu_to_le64(x)                          __cpu_to_le64(x)
166 #define cpu_to_le32(x)                          __cpu_to_le32(x)
167 #define cpu_to_le16(x)                          __cpu_to_le16(x)
168
169 #define le64_to_cpu(x)                          __le64_to_cpu(x)
170 #define le32_to_cpu(x)                          __le32_to_cpu(x)
171 #define le16_to_cpu(x)                          __le16_to_cpu(x)
172
173 #define __swab16(x)                             OSSwapInt16(x)
174 #define __swab32(x)                             OSSwapInt32(x)
175 #define __swab64(x)                             OSSwapInt64(x)
176 #define __swab16s(x)                            do { *(x) = __swab16(*(x)); } while (0)
177 #define __swab32s(x)                            do { *(x) = __swab32(*(x)); } while (0)
178 #define __swab64s(x)                            do { *(x) = __swab64(*(x)); } while (0)
179 #endif
180
181
182 # ifndef THREAD_SIZE /* x86_64 linux has THREAD_SIZE in userspace */
183 #  define THREAD_SIZE 8192
184 # endif
185
186 #define LUSTRE_TRACE_SIZE (THREAD_SIZE >> 5)
187
188 #define CHECK_STACK() do { } while(0)
189 #define CDEBUG_STACK() (0L)
190
191 /* initial pid  */
192 #define LUSTRE_LNET_PID          12345
193
194 #define ENTRY_NESTING_SUPPORT (1)
195 #define ENTRY_NESTING   do {;} while (0)
196 #define EXIT_NESTING   do {;} while (0)
197 #define __current_nesting_level() (0)
198
199 /**
200  * Platform specific declarations for cfs_curproc API (libcfs/curproc.h)
201  *
202  * Implementation is in linux-curproc.c
203  */
204 #define CFS_CURPROC_COMM_MAX (sizeof ((struct task_struct *)0)->comm)
205
206 typedef __u32 cfs_kernel_cap_t;
207
208 /**
209  * Module support (probably shouldn't be used in generic code?)
210  */
211 struct module {
212         int count;
213 };
214
215 static inline void MODULE_AUTHOR(char *name)
216 {
217         printf("%s\n", name);
218 }
219 #define MODULE_DESCRIPTION(name) MODULE_AUTHOR(name)
220 #define MODULE_LICENSE(name) MODULE_AUTHOR(name)
221
222 #define THIS_MODULE NULL
223 #define __init
224 #define __exit
225
226 static inline int request_module(char *name)
227 {
228         return (-EINVAL);
229 }
230
231 static inline void __module_get(struct module *module)
232 {
233 }
234
235 static inline int try_module_get(struct module *module)
236 {
237         return 1;
238 }
239
240 static inline void module_put(struct module *module)
241 {
242 }
243
244
245 #endif