1 /* -*- mode: c; c-basic-offset: 8; indent-tabs-mode: nil; -*-
2 * vim:expandtab:shiftwidth=8:tabstop=8:
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 Lustre library routines.
28 #include <asm/types.h>
36 inline void lustre_put_page(struct page *page);
37 struct page * lustre_get_page(struct inode *dir, unsigned long n);
38 void lustre_prepare_page(unsigned from, unsigned to, struct page *page);
39 int lustre_commit_page(struct page *page, unsigned from, unsigned to);
45 #define MIN(a,b) (((a)<(b)) ? (a): (b))
47 #define MAX(a,b) (((a)>(b)) ? (a): (b))
48 #define MKSTR(ptr) ((ptr))? (ptr) : ""
50 static inline int size_round (int val)
52 return (val + 3) & (~0x3);
55 static inline int size_round0(int val)
59 return (val + 1 + 3) & (~0x3);
62 static inline size_t round_strlen(char *fset)
64 return size_round(strlen(fset) + 1);
68 static inline char *strdup(char *str)
70 char *tmp = kmalloc(strlen(str) + 1, GFP_KERNEL);
72 memcpy(tmp, str, strlen(str) + 1);
79 # define NTOH__u32(var) le32_to_cpu(var)
80 # define NTOH__u64(var) le64_to_cpu(var)
81 # define HTON__u32(var) cpu_to_le32(var)
82 # define HTON__u64(var) cpu_to_le64(var)
85 # define NTOH__u32(var) GUINT32_FROM_LE(var)
86 # define NTOH__u64(var) GUINT64_FROM_LE(var)
87 # define HTON__u32(var) GUINT32_TO_LE(var)
88 # define HTON__u64(var) GUINT64_TO_LE(var)
92 * copy sizeof(type) bytes from pointer to var and move ptr forward.
93 * return EFAULT if pointer goes beyond end
95 #define UNLOGV(var,type,ptr,end) \
98 ptr += sizeof(type); \
103 /* the following two macros convert to little endian */
104 /* type MUST be __u32 or __u64 */
105 #define LUNLOGV(var,type,ptr,end) \
107 var = NTOH##type(*(type *)ptr); \
108 ptr += sizeof(type); \
114 #define LOGV(var,type,ptr) \
116 *((type *)ptr) = var; \
117 ptr += sizeof(type); \
120 /* and in network order */
121 #define LLOGV(var,type,ptr) \
123 *((type *)ptr) = HTON##type(var); \
124 ptr += sizeof(type); \
129 * set var to point at (type *)ptr, move ptr forward with sizeof(type)
130 * return from function with EFAULT if ptr goes beyond end
132 #define UNLOGP(var,type,ptr,end) \
135 ptr += sizeof(type); \
140 #define LOGP(var,type,ptr) \
142 memcpy(ptr, var, sizeof(type)); \
143 ptr += sizeof(type); \
147 * set var to point at (char *)ptr, move ptr forward by size_round(len);
148 * return from function with EFAULT if ptr goes beyond end
150 #define UNLOGL(var,type,len,ptr,end) \
157 ptr += size_round(len * sizeof(type)); \
162 #define UNLOGL0(var,type,len,ptr,end) \
164 UNLOGL(var,type,len,ptr,end); \
165 if ( *((char *)ptr - size_round(len) + len - 1) != '\0')\
170 #define LOGL(var,len,ptr) \
173 memcpy((char *)ptr, (const char *)var, len); \
174 ptr += size_round(len); \
177 #define LOGL0(var,len,ptr) \
180 memcpy((char *)ptr, (const char *)var, len); \
181 *((char *)(ptr) + len) = 0; \
182 ptr += size_round(len + 1); \
185 #endif /* _LUSTRE_LIB_H */