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 library routines.
25 #ifndef __LIBCFS_WINNT_PORTALS_UTILS_H__
26 #define __LIBCFS_WINNT_PORTALS_UTILS_H__
28 #ifndef __LIBCFS_PORTALS_UTILS_H__
29 #error Do not #include this file directly. #include <libcfs/portals_utils.h> instead
32 #ifndef cfs_is_flag_set
33 #define cfs_is_flag_set(x,f) (((x)&(f))==(f))
37 #define cfs_set_flag(x,f) ((x) |= (f))
40 #ifndef cfs_clear_flag
41 #define cfs_clear_flag(x,f) ((x) &= ~(f))
45 static inline __u32 __do_div(__u32 * n, __u32 b)
54 #define do_div(n,base) __do_div((__u32 *)&(n), (__u32) (base))
59 #include <libcfs/winnt/winnt-types.h>
61 char * strsep(char **s, const char *ct);
62 static inline size_t strnlen(const char * s, size_t count) {
64 while(len < count && s[len++]);
67 char * ul2dstr(ulong_ptr address, char *buf, int len);
69 #define simple_strtol(a1, a2, a3) strtol(a1, a2, a3)
70 #define simple_strtoll(a1, a2, a3) (__s64)strtoull(a1, a2, a3)
71 #define simple_strtoull(a1, a2, a3) strtoull(a1, a2, a3)
73 unsigned long simple_strtoul(const char *cp,char **endp, unsigned int base);
75 static inline int test_bit(int nr, void * addr)
77 return ((1UL << (nr & 31)) & (((volatile ULONG *) addr)[nr >> 5])) != 0;
80 static inline void clear_bit(int nr, void * addr)
82 (((volatile ULONG *) addr)[nr >> 5]) &= (~(1UL << (nr & 31)));
86 static inline void set_bit(int nr, void * addr)
88 (((volatile ULONG *) addr)[nr >> 5]) |= (1UL << (nr & 31));
91 static inline void read_random(char *buf, int len)
93 ULONG Seed = (ULONG) buf;
94 Seed = RtlRandom(&Seed);
96 if (len > sizeof(ULONG)) {
97 memcpy(buf, &Seed, sizeof(ULONG));
101 memcpy(buf, &Seed, len);
107 #define get_random_bytes(buf, len) read_random(buf, len)
109 /* do NOT use function or expression as parameters ... */
112 #define min_t(type,x,y) (type)(x) < (type)(y) ? (x): (y)
116 #define max_t(type,x,y) (type)(x) < (type)(y) ? (y): (x)
120 #define NIPQUAD(addr) \
121 ((unsigned char *)&addr)[0], \
122 ((unsigned char *)&addr)[1], \
123 ((unsigned char *)&addr)[2], \
124 ((unsigned char *)&addr)[3]
126 #define HIPQUAD(addr) \
127 ((unsigned char *)&addr)[3], \
128 ((unsigned char *)&addr)[2], \
129 ((unsigned char *)&addr)[1], \
130 ((unsigned char *)&addr)[0]
132 static int copy_from_user(void *to, void *from, int c)
138 static int copy_to_user(void *to, void *from, int c)
145 #define put_user(x, ptr) \
152 #define get_user(x,ptr) \
158 #define num_physpages (64 * 1024)
160 #define snprintf _snprintf
161 #define vsnprintf _vsnprintf
164 #endif /* !__KERNEL__ */
166 int cfs_error_code(NTSTATUS);