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 * lnet/include/libcfs/winnt/portals_utils.h
38 * Basic library routines.
41 #ifndef __LIBCFS_WINNT_PORTALS_UTILS_H__
42 #define __LIBCFS_WINNT_PORTALS_UTILS_H__
44 #ifndef __LIBCFS_PORTALS_UTILS_H__
45 #error Do not #include this file directly. #include <libcfs/portals_utils.h> instead
48 #ifndef cfs_is_flag_set
49 #define cfs_is_flag_set(x,f) (((x)&(f))==(f))
53 #define cfs_set_flag(x,f) ((x) |= (f))
56 #ifndef cfs_clear_flag
57 #define cfs_clear_flag(x,f) ((x) &= ~(f))
61 static inline __u32 __do_div(__u32 * n, __u32 b)
70 #define do_div(n,base) __do_div((__u32 *)&(n), (__u32) (base))
75 #include <libcfs/winnt/winnt-types.h>
77 char * strsep(char **s, const char *ct);
78 static inline size_t strnlen(const char * s, size_t count) {
80 while(len < count && s[len++]);
83 char * ul2dstr(ulong_ptr address, char *buf, int len);
85 #define simple_strtol(a1, a2, a3) strtol(a1, a2, a3)
86 #define simple_strtoll(a1, a2, a3) (__s64)strtoull(a1, a2, a3)
87 #define simple_strtoull(a1, a2, a3) strtoull(a1, a2, a3)
89 unsigned long simple_strtoul(const char *cp,char **endp, unsigned int base);
91 static inline int test_bit(int nr, void * addr)
93 return ((1UL << (nr & 31)) & (((volatile ULONG *) addr)[nr >> 5])) != 0;
96 static inline void clear_bit(int nr, void * addr)
98 (((volatile ULONG *) addr)[nr >> 5]) &= (~(1UL << (nr & 31)));
102 static inline void set_bit(int nr, void * addr)
104 (((volatile ULONG *) addr)[nr >> 5]) |= (1UL << (nr & 31));
107 static inline void read_random(char *buf, int len)
109 ULONG Seed = (ULONG) buf;
110 Seed = RtlRandom(&Seed);
112 if (len > sizeof(ULONG)) {
113 memcpy(buf, &Seed, sizeof(ULONG));
114 len -= sizeof(ULONG);
115 buf += sizeof(ULONG);
117 memcpy(buf, &Seed, len);
123 #define get_random_bytes(buf, len) read_random(buf, len)
125 /* do NOT use function or expression as parameters ... */
128 #define min_t(type,x,y) (type)(x) < (type)(y) ? (x): (y)
132 #define max_t(type,x,y) (type)(x) < (type)(y) ? (y): (x)
136 #define NIPQUAD(addr) \
137 ((unsigned char *)&addr)[0], \
138 ((unsigned char *)&addr)[1], \
139 ((unsigned char *)&addr)[2], \
140 ((unsigned char *)&addr)[3]
142 #define HIPQUAD(addr) \
143 ((unsigned char *)&addr)[3], \
144 ((unsigned char *)&addr)[2], \
145 ((unsigned char *)&addr)[1], \
146 ((unsigned char *)&addr)[0]
148 static int copy_from_user(void *to, void *from, int c)
154 static int copy_to_user(void *to, void *from, int c)
161 #define put_user(x, ptr) \
168 #define get_user(x,ptr) \
174 #define num_physpages (64 * 1024)
176 #define snprintf _snprintf
177 #define vsnprintf _vsnprintf
180 #endif /* !__KERNEL__ */
182 int cfs_error_code(NTSTATUS);