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 [sun.com URL with a
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/posix/libcfs.h
38 * Defines for posix userspace.
40 * Author: Robert Read <rread@sun.com>
43 #ifndef __LIBCFS_POSIX_LIBCFS_H__
44 #define __LIBCFS_POSIX_LIBCFS_H__
46 #include <sys/errno.h>
57 #include <sys/signal.h>
62 #ifdef HAVE_LIBPTHREAD
66 #if defined(HAVE_SYS_TYPES_H)
67 #include <sys/types.h>
70 #ifdef HAVE_SYS_USER_H
71 # include <sys/user.h>
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>
92 # define do_gettimeofday(tv) gettimeofday(tv, NULL);
93 typedef unsigned long long cycles_t;
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)))
99 /* this goes in posix-fs.h */
100 #include <sys/mount.h>
106 typedef struct file cfs_file_t;
107 typedef struct dentry cfs_dentry_t;
109 typedef struct dirent64 cfs_dirent_t;
113 /* Userpace byte flipping */
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)
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)
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)
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)
153 # error "Unknown byte order"
154 # endif /* __BIG_ENDIAN */
155 # endif /* __LITTLE_ENDIAN */
157 #define __cpu_to_le64(x) OSSwapHostToLittleInt64(x)
158 #define __cpu_to_le32(x) OSSwapHostToLittleInt32(x)
159 #define __cpu_to_le16(x) OSSwapHostToLittleInt16(x)
161 #define __le16_to_cpu(x) OSSwapLittleToHostInt16(x)
162 #define __le32_to_cpu(x) OSSwapLittleToHostInt32(x)
163 #define __le64_to_cpu(x) OSSwapLittleToHostInt64(x)
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)
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)
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)
182 # ifndef THREAD_SIZE /* x86_64 linux has THREAD_SIZE in userspace */
183 # define THREAD_SIZE 8192
186 #define LUSTRE_TRACE_SIZE (THREAD_SIZE >> 5)
188 #define CHECK_STACK() do { } while(0)
189 #define CDEBUG_STACK() (0L)
192 #define LUSTRE_LNET_PID 12345
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)
200 * Platform specific declarations for cfs_curproc API (libcfs/curproc.h)
202 * Implementation is in linux-curproc.c
204 #define CFS_CURPROC_COMM_MAX (sizeof ((struct task_struct *)0)->comm)
206 typedef __u32 cfs_kernel_cap_t;
209 * Module support (probably shouldn't be used in generic code?)
215 static inline void MODULE_AUTHOR(char *name)
217 printf("%s\n", name);
219 #define MODULE_DESCRIPTION(name) MODULE_AUTHOR(name)
220 #define MODULE_LICENSE(name) MODULE_AUTHOR(name)
222 #define THIS_MODULE NULL
226 static inline int request_module(char *name)
231 static inline void __module_get(struct module *module)
235 static inline int try_module_get(struct module *module)
240 static inline void module_put(struct module *module)