ReactOS 0.4.15-dev-7958-gcd0bb1a
util.h
Go to the documentation of this file.
1/* NFSv4.1 client for Windows
2 * Copyright © 2012 The Regents of the University of Michigan
3 *
4 * Olga Kornievskaia <aglo@umich.edu>
5 * Casey Bodley <cbodley@umich.edu>
6 *
7 * This library is free software; you can redistribute it and/or modify it
8 * under the terms of the GNU Lesser General Public License as published by
9 * the Free Software Foundation; either version 2.1 of the License, or (at
10 * your option) any later version.
11 *
12 * This library is distributed in the hope that it will be useful, but
13 * without any warranty; without even the implied warranty of merchantability
14 * or fitness for a particular purpose. See the GNU Lesser General Public
15 * License for more details.
16 *
17 * You should have received a copy of the GNU Lesser General Public License
18 * along with this library; if not, write to the Free Software Foundation,
19 * Inc., 51 Franklin Street, Fifth Floor, Boston, MA
20 */
21
22#ifndef __NFS41_DAEMON_UTIL_H__
23#define __NFS41_DAEMON_UTIL_H__
24
25#include "nfs41_types.h"
26#include "from_kernel.h"
27
29struct __nfs41_session;
31enum stable_how4;
32
33int safe_read(unsigned char **pos, uint32_t *remaining, void *dest, uint32_t dest_len);
34int safe_write(unsigned char **pos, uint32_t *remaining, void *dest, uint32_t dest_len);
35int get_name(unsigned char **pos, uint32_t *remaining, const char **out_name);
36
37const char* strip_path(
38 IN const char *path,
39 OUT uint32_t *len_out OPTIONAL);
40
42 IN const struct __nfs41_session *session,
43 IN const nfs41_fh *fh);
45 IN const struct __nfs41_session *session,
46 IN const nfs41_fh *fh);
47
50 IN OUT enum stable_how4 *stable);
53
54/* bitmap4 */
55static __inline bool_t bitmap_isset(
56 IN const bitmap4 *mask,
59{
60 return mask->count > word && mask->arr[word] & flag;
61}
62static __inline void bitmap_set(
66{
67 if (mask->count > word)
68 mask->arr[word] |= flag;
69 else {
70 mask->count = word + 1;
71 mask->arr[word] = flag;
72 }
73}
74static __inline void bitmap_unset(
78{
79 if (mask->count > word) {
80 mask->arr[word] &= ~flag;
81 while (mask->count && mask->arr[mask->count-1] == 0)
82 mask->count--;
83 }
84}
85static __inline void bitmap_intersect(
86 IN bitmap4 *dst,
87 IN const bitmap4 *src)
88{
89 uint32_t i, count = 0;
90 for (i = 0; i < 3; i++) {
91 dst->arr[i] &= src->arr[i];
92 if (dst->arr[i])
93 count = i+1;
94 }
95 dst->count = min(dst->count, count);
96}
97
99 IN const nfs41_file_info *info);
101 IN const nfs41_file_info *info,
102 OUT PFILE_BASIC_INFO basic_out);
104 IN const nfs41_file_info *info,
105 OUT PFILE_STANDARD_INFO std_out);
107 IN const nfs41_file_info *info,
109
110/* http://msdn.microsoft.com/en-us/library/ms724290%28VS.85%29.aspx:
111 * A file time is a 64-bit value that represents the number of
112 * 100-nanosecond intervals that have elapsed since 12:00 A.M.
113 * January 1, 1601 Coordinated Universal Time (UTC). */
114#define FILETIME_EPOCH 116444736000000000LL
115
116static __inline void file_time_to_nfs_time(
117 IN const PLARGE_INTEGER file_time,
118 OUT nfstime4 *nfs_time)
119{
120 LONGLONG diff = file_time->QuadPart - FILETIME_EPOCH;
121 nfs_time->seconds = diff / 10000000;
122 nfs_time->nseconds = (uint32_t)((diff % 10000000)*100);
123}
124
125static __inline void nfs_time_to_file_time(
126 IN const nfstime4 *nfs_time,
127 OUT PLARGE_INTEGER file_time)
128{
129 file_time->QuadPart = FILETIME_EPOCH +
130 nfs_time->seconds * 10000000 +
131 nfs_time->nseconds / 100;
132}
133
134void get_file_time(
135 OUT PLARGE_INTEGER file_time);
136void get_nfs_time(
137 OUT nfstime4 *nfs_time);
138
139static __inline void nfstime_normalize(
140 IN OUT nfstime4 *nfstime)
141{
142 /* return time in normalized form (0 <= nsec < 1s) */
143 while ((int32_t)nfstime->nseconds < 0) {
144 nfstime->nseconds += 1000000000;
145 nfstime->seconds--;
146 }
147}
148static __inline void nfstime_diff(
149 IN const nfstime4 *lhs,
150 IN const nfstime4 *rhs,
152{
153 /* result = lhs - rhs */
154 result->seconds = lhs->seconds - rhs->seconds;
155 result->nseconds = lhs->nseconds - rhs->nseconds;
157}
158static __inline void nfstime_abs(
159 IN const nfstime4 *nt,
161{
162 if (nt->seconds < 0) {
163 const nfstime4 zero = { 0, 0 };
164 nfstime_diff(&zero, nt, result); /* result = 0 - nt */
165 } else if (result != nt)
166 memcpy(result, nt, sizeof(nfstime4));
167}
168
169
172 IN const nfs41_fh *fh,
173 OUT nfs41_component *silly);
174
176 IN const multi_addr4 *addrs,
177 IN const netaddr4 *addr,
178 OUT OPTIONAL uint32_t *index_out);
179
180/* nfs_to_windows_error
181 * Returns a windows ERROR_ code corresponding to the given NFS4ERR_ status.
182 * If the status is outside the range of valid NFS4ERR_ values, it is returned
183 * unchanged. Otherwise, if the status does not match a value in the mapping,
184 * a debug warning is generated and the default_error value is returned.
185 */
186int nfs_to_windows_error(int status, int default_error);
187
189
190#ifndef __REACTOS__
192#else
194#endif
195 return 8 + ((offset - 1) & ~7);
196}
197#ifndef __REACTOS__
199#else
201#endif
202 return 4 + ((offset - 1) & ~3);
203}
204
205/* path parsing */
206#ifndef __REACTOS__
207__inline int is_delimiter(char c) {
208#else
209FORCEINLINE int is_delimiter(char c) {
210#endif
211 return c == '\\' || c == '/' || c == '\0';
212}
213#ifndef __REACTOS__
214__inline const char* next_delimiter(const char *pos, const char *end) {
215#else
216FORCEINLINE const char* next_delimiter(const char *pos, const char *end) {
217#endif
218 while (pos < end && !is_delimiter(*pos))
219 pos++;
220 return pos;
221}
222#ifndef __REACTOS__
223__inline const char* prev_delimiter(const char *pos, const char *start) {
224#else
225FORCEINLINE const char* prev_delimiter(const char *pos, const char *start) {
226#endif
227 while (pos > start && !is_delimiter(*pos))
228 pos--;
229 return pos;
230}
231#ifndef __REACTOS__
232__inline const char* next_non_delimiter(const char *pos, const char *end) {
233#else
234FORCEINLINE const char* next_non_delimiter(const char *pos, const char *end) {
235#endif
236 while (pos < end && is_delimiter(*pos))
237 pos++;
238 return pos;
239}
240#ifndef __REACTOS__
241__inline const char* prev_non_delimiter(const char *pos, const char *start) {
242#else
243FORCEINLINE const char* prev_non_delimiter(const char *pos, const char *start) {
244#endif
245 while (pos > start && is_delimiter(*pos))
246 pos--;
247 return pos;
248}
249
251 IN const char *path,
252 IN const char *path_end,
253 OUT nfs41_component *component);
254
256 IN const char *path,
257 IN const char *path_end,
258 OUT nfs41_component *component);
259
261 IN const char *path,
262 IN const char *path_end);
263
264void abs_path_copy(
266 IN const nfs41_abs_path *src);
267
268void path_fh_init(
271
272void fh_copy(
274 IN const nfs41_fh *src);
275
276void path_fh_copy(
278 IN const nfs41_path_fh *src);
279
280#ifndef __REACTOS__
282#else
284#endif
285 return handle != INVALID_HANDLE_VALUE && handle != 0;
286}
287
288#endif /* !__NFS41_DAEMON_UTIL_H__ */
__inline uint32_t align8(uint32_t offset)
Definition: util.h:191
void path_fh_init(OUT nfs41_path_fh *file, IN nfs41_abs_path *path)
Definition: util.c:346
bool_t is_last_component(IN const char *path, IN const char *path_end)
Definition: util.c:330
static __inline void bitmap_intersect(IN bitmap4 *dst, IN const bitmap4 *src)
Definition: util.h:85
__inline const char * prev_non_delimiter(const char *pos, const char *start)
Definition: util.h:241
uint32_t max_read_size(IN const struct __nfs41_session *session, IN const nfs41_fh *fh)
void nfs_to_standard_info(IN const nfs41_file_info *info, OUT PFILE_STANDARD_INFO std_out)
Definition: util.c:175
ULONG nfs_file_info_to_attributes(IN const nfs41_file_info *info)
Definition: util.c:137
__inline uint32_t align4(uint32_t offset)
Definition: util.h:198
bool_t last_component(IN const char *path, IN const char *path_end, OUT nfs41_component *component)
Definition: util.c:317
void get_nfs_time(OUT nfstime4 *nfs_time)
Definition: util.c:210
static __inline bool_t bitmap_isset(IN const bitmap4 *mask, IN uint32_t word, IN uint32_t flag)
Definition: util.h:55
static __inline void bitmap_unset(IN bitmap4 *mask, IN uint32_t word, IN uint32_t flag)
Definition: util.h:74
uint32_t max_write_size(IN const struct __nfs41_session *session, IN const nfs41_fh *fh)
int safe_write(unsigned char **pos, uint32_t *remaining, void *dest, uint32_t dest_len)
Definition: util.c:44
__inline int valid_handle(HANDLE handle)
Definition: util.h:281
void get_file_time(OUT PLARGE_INTEGER file_time)
Definition: util.c:204
static __inline void bitmap_set(IN bitmap4 *mask, IN uint32_t word, IN uint32_t flag)
Definition: util.h:62
static __inline void nfstime_diff(IN const nfstime4 *lhs, IN const nfstime4 *rhs, OUT nfstime4 *result)
Definition: util.h:148
static __inline void nfs_time_to_file_time(IN const nfstime4 *nfs_time, OUT PLARGE_INTEGER file_time)
Definition: util.h:125
void nfs_to_basic_info(IN const nfs41_file_info *info, OUT PFILE_BASIC_INFO basic_out)
Definition: util.c:163
#define FILETIME_EPOCH
Definition: util.h:114
static __inline void nfstime_abs(IN const nfstime4 *nt, OUT nfstime4 *result)
Definition: util.h:158
__inline int is_delimiter(char c)
Definition: util.h:207
const char * strip_path(IN const char *path, OUT uint32_t *len_out OPTIONAL)
__inline const char * next_non_delimiter(const char *pos, const char *end)
Definition: util.h:232
void fh_copy(OUT nfs41_fh *dst, IN const nfs41_fh *src)
Definition: util.c:354
__inline const char * next_delimiter(const char *pos, const char *end)
Definition: util.h:214
int map_symlink_errors(int status)
Definition: util.c:293
void abs_path_copy(OUT nfs41_abs_path *dst, IN const nfs41_abs_path *src)
Definition: util.c:338
void nfs_to_network_openinfo(IN const nfs41_file_info *info, OUT PFILE_NETWORK_OPEN_INFORMATION std_out)
Definition: util.c:189
int safe_read(unsigned char **pos, uint32_t *remaining, void *dest, uint32_t dest_len)
Definition: util.c:33
static __inline void file_time_to_nfs_time(IN const PLARGE_INTEGER file_time, OUT nfstime4 *nfs_time)
Definition: util.h:116
void path_fh_copy(OUT nfs41_path_fh *dst, IN const nfs41_path_fh *src)
Definition: util.c:364
int nfs_to_windows_error(int status, int default_error)
Definition: util.c:235
static __inline void nfstime_normalize(IN OUT nfstime4 *nfstime)
Definition: util.h:139
int get_name(unsigned char **pos, uint32_t *remaining, const char **out_name)
Definition: util.c:55
DWORD NFS41D_VERSION
Definition: nfs41_daemon.c:42
__inline const char * prev_delimiter(const char *pos, const char *start)
Definition: util.h:223
bool_t next_component(IN const char *path, IN const char *path_end, OUT nfs41_component *component)
Definition: util.c:305
bool_t verify_write(IN nfs41_write_verf *verf, IN OUT enum stable_how4 *stable)
Definition: util.c:100
bool_t verify_commit(IN nfs41_write_verf *verf)
Definition: util.c:126
int create_silly_rename(IN nfs41_abs_path *path, IN const nfs41_fh *fh, OUT nfs41_component *silly)
Definition: util.c:380
bool_t multi_addr_find(IN const multi_addr4 *addrs, IN const netaddr4 *addr, OUT OPTIONAL uint32_t *index_out)
Definition: util.c:218
int32_t bool_t
Definition: types.h:101
INT32 int32_t
Definition: types.h:71
UINT32 uint32_t
Definition: types.h:75
#define INVALID_HANDLE_VALUE
Definition: compat.h:731
unsigned long DWORD
Definition: ntddk_ex.h:95
GLuint start
Definition: gl.h:1545
GLuint GLuint end
Definition: gl.h:1545
GLuint GLuint GLsizei count
Definition: gl.h:1545
GLenum src
Definition: glext.h:6340
const GLubyte * c
Definition: glext.h:8905
GLenum GLint GLuint mask
Definition: glext.h:6028
GLenum GLenum dst
Definition: glext.h:6340
GLenum const GLvoid * addr
Definition: glext.h:9621
GLuint64EXT * result
Definition: glext.h:11304
GLintptr offset
Definition: glext.h:5920
GLsizei GLenum const GLvoid GLsizei GLenum GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLint GLint GLint GLshort GLshort GLshort GLubyte GLubyte GLubyte GLuint GLuint GLuint GLushort GLushort GLushort GLbyte GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLfloat GLint GLint GLint GLint GLshort GLshort GLshort GLshort GLubyte GLubyte GLubyte GLubyte GLuint GLuint GLuint GLuint GLushort GLushort GLushort GLushort GLboolean flag
Definition: glfuncs.h:52
GLsizei GLenum const GLvoid GLsizei GLenum GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLint GLint GLint GLshort GLshort GLshort GLubyte GLubyte GLubyte GLuint GLuint GLuint GLushort GLushort GLushort GLbyte GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLfloat GLint GLint GLint GLint GLshort GLshort GLshort GLshort GLubyte GLubyte GLubyte GLubyte GLuint GLuint GLuint GLuint GLushort GLushort GLushort GLushort GLboolean const GLdouble const GLfloat const GLint const GLshort const GLbyte const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLdouble const GLfloat const GLfloat const GLint const GLint const GLshort const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort GLenum GLenum GLenum GLfloat GLenum GLint GLenum GLenum GLenum GLfloat GLenum GLenum GLint GLenum GLfloat GLenum GLint GLint GLushort GLenum GLenum GLfloat GLenum GLenum GLint GLfloat const GLubyte GLenum GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLint GLint GLsizei GLsizei GLint GLenum GLenum const GLvoid GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLenum const GLdouble GLenum GLenum const GLfloat GLenum GLenum const GLint GLsizei GLuint GLfloat GLuint GLbitfield GLfloat GLint GLuint GLboolean GLenum GLfloat GLenum GLbitfield GLenum GLfloat GLfloat GLint GLint const GLfloat GLenum GLfloat GLfloat GLint GLint GLfloat GLfloat GLint GLint const GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat const GLdouble const GLfloat const GLdouble const GLfloat GLint i
Definition: glfuncs.h:248
const WCHAR * word
Definition: lex.c:36
#define memcpy(s1, s2, n)
Definition: mkisofs.h:878
IMAGE_NT_HEADERS nt
Definition: module.c:50
static char * dest
Definition: rtl.c:135
#define min(a, b)
Definition: monoChain.cc:55
stable_how4
Definition: nfs41_ops.h:835
#define uint32_t
Definition: nsiface.idl:61
int zero
Definition: sehframes.cpp:29
PULONG MinorVersion OPTIONAL
Definition: CrossNt.h:68
unsigned char verf[NFS4_VERIFIER_SIZE]
Definition: nfs41_types.h:76
Definition: fci.c:127
Definition: ps.c:97
int64_t LONGLONG
Definition: typedefs.h:68
#define IN
Definition: typedefs.h:39
uint32_t ULONG
Definition: typedefs.h:59
#define OUT
Definition: typedefs.h:40
#define FORCEINLINE
Definition: wdftypes.h:67