ReactOS 0.4.15-dev-5666-gc548b97
util.h File Reference
#include "nfs41_types.h"
#include "from_kernel.h"
Include dependency graph for util.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Macros

#define FILETIME_EPOCH   116444736000000000LL
 

Functions

int safe_read (unsigned char **pos, uint32_t *remaining, void *dest, uint32_t dest_len)
 
int safe_write (unsigned char **pos, uint32_t *remaining, void *dest, uint32_t dest_len)
 
int get_name (unsigned char **pos, uint32_t *remaining, const char **out_name)
 
const charstrip_path (IN const char *path, OUT uint32_t *len_out OPTIONAL)
 
uint32_t max_read_size (IN const struct __nfs41_session *session, IN const nfs41_fh *fh)
 
uint32_t max_write_size (IN const struct __nfs41_session *session, IN const nfs41_fh *fh)
 
bool_t verify_write (IN nfs41_write_verf *verf, IN OUT enum stable_how4 *stable)
 
bool_t verify_commit (IN nfs41_write_verf *verf)
 
static __inline bool_t bitmap_isset (IN const bitmap4 *mask, IN uint32_t word, IN uint32_t flag)
 
static __inline void bitmap_set (IN bitmap4 *mask, IN uint32_t word, IN uint32_t flag)
 
static __inline void bitmap_unset (IN bitmap4 *mask, IN uint32_t word, IN uint32_t flag)
 
static __inline void bitmap_intersect (IN bitmap4 *dst, IN const bitmap4 *src)
 
ULONG nfs_file_info_to_attributes (IN const nfs41_file_info *info)
 
void nfs_to_basic_info (IN const nfs41_file_info *info, OUT PFILE_BASIC_INFO basic_out)
 
void nfs_to_standard_info (IN const nfs41_file_info *info, OUT PFILE_STANDARD_INFO std_out)
 
void nfs_to_network_openinfo (IN const nfs41_file_info *info, OUT PFILE_NETWORK_OPEN_INFORMATION std_out)
 
static __inline void file_time_to_nfs_time (IN const PLARGE_INTEGER file_time, OUT nfstime4 *nfs_time)
 
static __inline void nfs_time_to_file_time (IN const nfstime4 *nfs_time, OUT PLARGE_INTEGER file_time)
 
void get_file_time (OUT PLARGE_INTEGER file_time)
 
void get_nfs_time (OUT nfstime4 *nfs_time)
 
static __inline void nfstime_normalize (IN OUT nfstime4 *nfstime)
 
static __inline void nfstime_diff (IN const nfstime4 *lhs, IN const nfstime4 *rhs, OUT nfstime4 *result)
 
static __inline void nfstime_abs (IN const nfstime4 *nt, OUT nfstime4 *result)
 
int create_silly_rename (IN nfs41_abs_path *path, IN const nfs41_fh *fh, OUT nfs41_component *silly)
 
bool_t multi_addr_find (IN const multi_addr4 *addrs, IN const netaddr4 *addr, OUT OPTIONAL uint32_t *index_out)
 
int nfs_to_windows_error (int status, int default_error)
 
int map_symlink_errors (int status)
 
__inline uint32_t align8 (uint32_t offset)
 
__inline uint32_t align4 (uint32_t offset)
 
__inline int is_delimiter (char c)
 
__inline const charnext_delimiter (const char *pos, const char *end)
 
__inline const charprev_delimiter (const char *pos, const char *start)
 
__inline const charnext_non_delimiter (const char *pos, const char *end)
 
__inline const charprev_non_delimiter (const char *pos, const char *start)
 
bool_t next_component (IN const char *path, IN const char *path_end, OUT nfs41_component *component)
 
bool_t last_component (IN const char *path, IN const char *path_end, OUT nfs41_component *component)
 
bool_t is_last_component (IN const char *path, IN const char *path_end)
 
void abs_path_copy (OUT nfs41_abs_path *dst, IN const nfs41_abs_path *src)
 
void path_fh_init (OUT nfs41_path_fh *file, IN nfs41_abs_path *path)
 
void fh_copy (OUT nfs41_fh *dst, IN const nfs41_fh *src)
 
void path_fh_copy (OUT nfs41_path_fh *dst, IN const nfs41_path_fh *src)
 
__inline int valid_handle (HANDLE handle)
 

Variables

DWORD NFS41D_VERSION
 

Macro Definition Documentation

◆ FILETIME_EPOCH

#define FILETIME_EPOCH   116444736000000000LL

Definition at line 114 of file util.h.

Function Documentation

◆ abs_path_copy()

void abs_path_copy ( OUT nfs41_abs_path dst,
IN const nfs41_abs_path src 
)

Definition at line 338 of file util.c.

341{
342 dst->len = src->len;
343 StringCchCopyNA(dst->path, NFS41_MAX_PATH_LEN, src->path, dst->len);
344}
GLenum src
Definition: glext.h:6340
GLenum GLenum dst
Definition: glext.h:6340
#define NFS41_MAX_PATH_LEN
Definition: nfs41_const.h:46
STRSAFEAPI StringCchCopyNA(STRSAFE_LPSTR pszDest, size_t cchDest, STRSAFE_LPCSTR pszSrc, size_t cchToCopy)
Definition: strsafe.h:230

Referenced by delegation_create(), format_abs_path(), handle_open(), nfs41_lookup(), open_state_rename(), prev_non_delimiter(), and referral_resolve().

◆ align4()

__inline uint32_t align4 ( uint32_t  offset)

Definition at line 198 of file util.h.

198 {
199#else
201#endif
202 return 4 + ((offset - 1) & ~3);
203}
__inline uint32_t align4(uint32_t offset)
Definition: util.h:198
UINT32 uint32_t
Definition: types.h:75
GLintptr offset
Definition: glext.h:5920
#define FORCEINLINE
Definition: wdftypes.h:67

Referenced by align4().

◆ align8()

__inline uint32_t align8 ( uint32_t  offset)

Definition at line 191 of file util.h.

191 {
192#else
194#endif
195 return 8 + ((offset - 1) & ~7);
196}
__inline uint32_t align8(uint32_t offset)
Definition: util.h:191

Referenced by align8(), and readdir_copy_entry().

◆ bitmap_intersect()

static __inline void bitmap_intersect ( IN bitmap4 dst,
IN const bitmap4 src 
)
static

Definition at line 85 of file util.h.

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}
GLuint GLuint GLsizei count
Definition: gl.h:1545
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
#define min(a, b)
Definition: monoChain.cc:55

Referenced by nfs41_superblock_supported_attrs(), and nfs41_superblock_supported_attrs_exclcreat().

◆ bitmap_isset()

static __inline bool_t bitmap_isset ( IN const bitmap4 mask,
IN uint32_t  word,
IN uint32_t  flag 
)
static

Definition at line 55 of file util.h.

59{
60 return mask->count > word && mask->arr[word] & flag;
61}
GLenum GLint GLuint mask
Definition: glext.h:6028
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
const WCHAR * word
Definition: lex.c:36

Referenced by get_superblock_attrs(), and info_to_fattr4().

◆ bitmap_set()

static __inline void bitmap_set ( IN bitmap4 mask,
IN uint32_t  word,
IN uint32_t  flag 
)
static

Definition at line 62 of file util.h.

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}

Referenced by info_to_fattr4().

◆ bitmap_unset()

static __inline void bitmap_unset ( IN bitmap4 mask,
IN uint32_t  word,
IN uint32_t  flag 
)
static

Definition at line 74 of file util.h.

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}

◆ create_silly_rename()

int create_silly_rename ( IN nfs41_abs_path path,
IN const nfs41_fh fh,
OUT nfs41_component silly 
)

Definition at line 380 of file util.c.

384{
389 const char *end = path->path + NFS41_MAX_PATH_LEN;
390 const unsigned short extra_len = 2 + 16; //md5 is 16
392 unsigned char fhmd5[17] = { 0 };
393 char *tmp;
394 int status = NO_ERROR, i;
395
396 if (path->len + extra_len >= NFS41_MAX_PATH_LEN) {
398 goto out;
399 }
400
401 /* set up the md5 hash generator */
405 eprintf("CryptAcquireContext() failed with %d\n", status);
406 goto out;
407 }
408 if (!CryptCreateHash(context, CALG_MD5, 0, 0, &hash)) {
410 eprintf("CryptCreateHash() failed with %d\n", status);
411 goto out_context;
412 }
413
414 if (!CryptHashData(hash, (const BYTE*)fh->fh, (DWORD)fh->len, 0)) {
416 eprintf("CryptHashData() failed with %d\n", status);
417 goto out_hash;
418 }
419
420 /* extract the hash buffer */
421 buffer = (PBYTE)fhmd5;
422 length = 16;
425 eprintf("CryptGetHashParam(val) failed with %d\n", status);
426 goto out_hash;
427 }
428
429 last_component(path->path, path->path + path->len, silly);
430 StringCchCopyNA(name, NFS41_MAX_COMPONENT_LEN+1, silly->name, silly->len);
431
432 tmp = (char*)silly->name;
433 StringCchPrintf(tmp, end - tmp, ".%s.", name);
434 tmp += silly->len + 2;
435
436 for (i = 0; i < 16; i++, tmp++)
437 StringCchPrintf(tmp, end - tmp, "%x", fhmd5[i]);
438
439 path->len = path->len + extra_len;
440 silly->len = silly->len + extra_len;
441
442out_hash:
444out_context:
446out:
447 return status;
448}
bool_t last_component(IN const char *path, IN const char *path_end, OUT nfs41_component *component)
Definition: util.c:317
void eprintf(LPCSTR format,...)
Definition: daemon_debug.c:86
#define NO_ERROR
Definition: dderror.h:5
#define NULL
Definition: types.h:112
BOOL WINAPI CryptCreateHash(HCRYPTPROV hProv, ALG_ID Algid, HCRYPTKEY hKey, DWORD dwFlags, HCRYPTHASH *phHash)
Definition: crypt.c:740
BOOL WINAPI CryptGetHashParam(HCRYPTHASH hHash, DWORD dwParam, BYTE *pbData, DWORD *pdwDataLen, DWORD dwFlags)
Definition: crypt.c:1610
BOOL WINAPI CryptDestroyHash(HCRYPTHASH hHash)
Definition: crypt.c:890
BOOL WINAPI CryptReleaseContext(HCRYPTPROV hProv, DWORD dwFlags)
Definition: crypt.c:648
BOOL WINAPI CryptHashData(HCRYPTHASH hHash, const BYTE *pbData, DWORD dwDataLen, DWORD dwFlags)
Definition: crypt.c:1771
unsigned long DWORD
Definition: ntddk_ex.h:95
GLuint GLuint end
Definition: gl.h:1545
GLuint buffer
Definition: glext.h:5915
GLuint GLsizei GLsizei * length
Definition: glext.h:6040
#define NFS41_MAX_COMPONENT_LEN
Definition: nfs41_const.h:45
BYTE * PBYTE
Definition: pedump.c:66
static FILE * out
Definition: regtests2xml.c:44
#define StringCchPrintf
Definition: strsafe.h:517
Definition: http.c:7252
char * name
Definition: compiler.c:66
Definition: _hash_fun.h:40
Definition: name.c:39
Definition: ps.c:97
DWORD WINAPI GetLastError(void)
Definition: except.c:1040
#define PROV_RSA_FULL
Definition: wincrypt.h:2039
#define CRYPT_VERIFYCONTEXT
Definition: wincrypt.h:2069
ULONG_PTR HCRYPTPROV
Definition: wincrypt.h:46
#define CALG_MD5
Definition: wincrypt.h:1805
ULONG_PTR HCRYPTHASH
Definition: wincrypt.h:50
#define CryptAcquireContext
Definition: wincrypt.h:4164
#define HP_HASHVAL
Definition: wincrypt.h:2183
#define ERROR_FILENAME_EXCED_RANGE
Definition: winerror.h:263
unsigned char BYTE
Definition: xxhash.c:193

Referenced by handle_close().

◆ fh_copy()

void fh_copy ( OUT nfs41_fh dst,
IN const nfs41_fh src 
)

Definition at line 354 of file util.c.

357{
358 dst->fileid = src->fileid;
359 dst->superblock = src->superblock;
360 dst->len = src->len;
361 memcpy(dst->fh, src->fh, dst->len);
362}
#define memcpy(s1, s2, n)
Definition: mkisofs.h:878

Referenced by copy_fh(), delegation_create(), get_path_fhs(), layout_state_create(), name_cache_entry_update(), path_fh_copy(), prev_non_delimiter(), and server_lookup_loop().

◆ file_time_to_nfs_time()

static __inline void file_time_to_nfs_time ( IN const PLARGE_INTEGER  file_time,
OUT nfstime4 nfs_time 
)
static

Definition at line 116 of file util.h.

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}
#define FILETIME_EPOCH
Definition: util.h:114
#define uint32_t
Definition: nsiface.idl:61
int64_t LONGLONG
Definition: typedefs.h:68

Referenced by get_nfs_time().

◆ get_file_time()

void get_file_time ( OUT PLARGE_INTEGER  file_time)

Definition at line 204 of file util.c.

206{
208}
VOID WINAPI GetSystemTimeAsFileTime(OUT PFILETIME lpFileTime)
Definition: time.c:128

Referenced by get_nfs_time().

◆ get_name()

int get_name ( unsigned char **  pos,
uint32_t remaining,
const char **  out_name 
)

Definition at line 55 of file util.c.

56{
57 int status;
58 USHORT len;
59
60 status = safe_read(pos, remaining, &len, sizeof(USHORT));
61 if (status) goto out;
62 if (*remaining < len) {
64 goto out;
65 }
66 *out_name = (const char*)*pos;
67 *pos += len;
68 *remaining -= len;
69out:
70 return status;
71}
int safe_read(unsigned char **pos, uint32_t *remaining, void *dest, uint32_t dest_len)
Definition: util.c:33
GLenum GLsizei len
Definition: glext.h:6722
unsigned short USHORT
Definition: pedump.c:61
#define ERROR_BUFFER_OVERFLOW
Definition: winerror.h:185

Referenced by __release_category(), FT_DEFINE_SERVICE(), ft_property_do(), gen_proxy(), gen_stub(), gen_stub_thunk(), parse_close(), parse_getexattr(), parse_mount(), parse_open(), parse_readdir(), parse_setattr(), parse_setexattr(), parse_symlink(), pointer_tests(), write_client_func_decl(), write_dispatchtable(), write_function_stub(), write_proxy_methods(), write_proxy_procformatstring_offsets(), write_routinetable(), write_stub_methods(), and write_thunk_methods().

◆ get_nfs_time()

void get_nfs_time ( OUT nfstime4 nfs_time)

Definition at line 210 of file util.c.

212{
213 LARGE_INTEGER file_time;
214 get_file_time(&file_time);
215 file_time_to_nfs_time(&file_time, nfs_time);
216}
void get_file_time(OUT PLARGE_INTEGER file_time)
Definition: util.c:204
static __inline void file_time_to_nfs_time(IN const PLARGE_INTEGER file_time, OUT nfstime4 *nfs_time)
Definition: util.h:116

Referenced by delegation_truncate(), and settime_how().

◆ is_delimiter()

__inline int is_delimiter ( char  c)

Definition at line 207 of file util.h.

207 {
208#else
209FORCEINLINE int is_delimiter(char c) {
210#endif
211 return c == '\\' || c == '/' || c == '\0';
212}
__inline int is_delimiter(char c)
Definition: util.h:207
const GLubyte * c
Definition: glext.h:8905

Referenced by abs_path_link(), is_delimiter(), next_delimiter(), next_non_delimiter(), prev_delimiter(), and prev_non_delimiter().

◆ is_last_component()

bool_t is_last_component ( IN const char path,
IN const char path_end 
)

Definition at line 330 of file util.c.

333{
334 path = next_delimiter(path, path_end);
335 return next_non_delimiter(path, path_end) == path_end;
336}
__inline const char * next_non_delimiter(const char *pos, const char *end)
Definition: util.h:232
__inline const char * next_delimiter(const char *pos, const char *end)
Definition: util.h:214

Referenced by get_path_fhs(), name_cache_lookup(), prev_non_delimiter(), and server_lookup_loop().

◆ last_component()

bool_t last_component ( IN const char path,
IN const char path_end,
OUT nfs41_component component 
)

Definition at line 317 of file util.c.

321{
322 const char *component_end = prev_delimiter(path_end, path);
323 component->name = prev_non_delimiter(component_end, path);
324 component->name = prev_delimiter(component->name, path);
325 component->name = next_non_delimiter(component->name, component_end);
326 component->len = (unsigned short)(component_end - component->name);
327 return component->len > 0;
328}
__inline const char * prev_non_delimiter(const char *pos, const char *start)
Definition: util.h:241
__inline const char * prev_delimiter(const char *pos, const char *start)
Definition: util.h:223
unsigned short(__cdecl typeof(TIFFCurrentDirectory))(struct tiff *)
Definition: typeof.h:94

Referenced by abs_path_link(), create_open_state(), create_silly_rename(), delegation_create(), lookup_symlink(), map_lookup_error(), nfs41_lookup(), nfs41_symlink_follow(), open_state_rename(), path_fh_init(), prev_non_delimiter(), and server_lookup().

◆ map_symlink_errors()

int map_symlink_errors ( int  status)

Definition at line 293 of file util.c.

294{
295 switch (status) {
296 case NFS4ERR_BADCHAR:
302 }
303}
int nfs_to_windows_error(int status, int default_error)
Definition: util.c:235
#define ERROR_ACCESS_DENIED
Definition: compat.h:97
@ NFS4ERR_NOTEMPTY
Definition: nfs41_const.h:104
@ NFS4ERR_BADNAME
Definition: nfs41_const.h:148
@ NFS4ERR_ACCESS
Definition: nfs41_const.h:92
@ NFS4ERR_WRONG_TYPE
Definition: nfs41_const.h:192
@ NFS4ERR_BADCHAR
Definition: nfs41_const.h:147
#define ERROR_NOT_EMPTY
Definition: winerror.h:1251
#define ERROR_BAD_NET_RESP
Definition: winerror.h:150
#define ERROR_NOT_A_REPARSE_POINT
Definition: winerror.h:1288
#define ERROR_INVALID_REPARSE_DATA
Definition: winerror.h:1290

Referenced by handle_open(), and handle_symlink().

◆ max_read_size()

uint32_t max_read_size ( IN const struct __nfs41_session session,
IN const nfs41_fh fh 
)

◆ max_write_size()

uint32_t max_write_size ( IN const struct __nfs41_session session,
IN const nfs41_fh fh 
)

◆ multi_addr_find()

bool_t multi_addr_find ( IN const multi_addr4 addrs,
IN const netaddr4 addr,
OUT OPTIONAL uint32_t index_out 
)

Definition at line 218 of file util.c.

222{
223 uint32_t i;
224 for (i = 0; i < addrs->count; i++) {
225 const netaddr4 *saddr = &addrs->arr[i];
226 if (!strncmp(saddr->netid, addr->netid, NFS41_NETWORK_ID_LEN) &&
227 !strncmp(saddr->uaddr, addr->uaddr, NFS41_UNIVERSAL_ADDR_LEN)) {
228 if (index_out) *index_out = i;
229 return 1;
230 }
231 }
232 return 0;
233}
int strncmp(const char *String1, const char *String2, ACPI_SIZE Count)
Definition: utclib.c:534
GLenum const GLvoid * addr
Definition: glext.h:9621
#define NFS41_UNIVERSAL_ADDR_LEN
Definition: nfs41_const.h:53
#define NFS41_NETWORK_ID_LEN
Definition: nfs41_const.h:56
char netid[NFS41_NETWORK_ID_LEN+1]
Definition: nfs41_types.h:86
char uaddr[NFS41_UNIVERSAL_ADDR_LEN+1]
Definition: nfs41_types.h:87

Referenced by cl_addr_compare(), and server_addrs_add().

◆ next_component()

bool_t next_component ( IN const char path,
IN const char path_end,
OUT nfs41_component component 
)

Definition at line 305 of file util.c.

309{
310 const char *component_end;
311 component->name = next_non_delimiter(path, path_end);
312 component_end = next_delimiter(component->name, path_end);
313 component->len = (unsigned short)(component_end - component->name);
314 return component->len > 0;
315}

Referenced by abs_path_link(), get_component_array(), get_path_fhs(), name_cache_lookup(), and prev_non_delimiter().

◆ next_delimiter()

__inline const char * next_delimiter ( const char pos,
const char end 
)

Definition at line 214 of file util.h.

214 {
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}

Referenced by is_last_component(), next_component(), and next_delimiter().

◆ next_non_delimiter()

__inline const char * next_non_delimiter ( const char pos,
const char end 
)

Definition at line 232 of file util.h.

232 {
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}

Referenced by is_last_component(), last_component(), next_component(), and next_non_delimiter().

◆ nfs_file_info_to_attributes()

ULONG nfs_file_info_to_attributes ( IN const nfs41_file_info info)

Definition at line 137 of file util.c.

139{
140 ULONG attrs = 0;
141 if (info->type == NF4DIR)
143 else if (info->type == NF4LNK) {
145 if (info->symlink_dir)
147 } else if (info->type != NF4REG)
148 dprintf(1, "unhandled file type %d, defaulting to NF4REG\n",
149 info->type);
150
151 if (info->mode == 0444) /* XXX: 0444 for READONLY */
153
154 if (info->hidden) attrs |= FILE_ATTRIBUTE_HIDDEN;
155 if (info->system) attrs |= FILE_ATTRIBUTE_SYSTEM;
156 if (info->archive) attrs |= FILE_ATTRIBUTE_ARCHIVE;
157
158 // FILE_ATTRIBUTE_NORMAL attribute is only set if no other attributes are present.
159 // all other override this value.
160 return attrs ? attrs : FILE_ATTRIBUTE_NORMAL;
161}
#define FILE_ATTRIBUTE_NORMAL
Definition: compat.h:137
unsigned int ULONG
Definition: retypes.h:1
@ NF4REG
Definition: nfs41_const.h:294
@ NF4DIR
Definition: nfs41_const.h:295
@ NF4LNK
Definition: nfs41_const.h:298
#define FILE_ATTRIBUTE_READONLY
Definition: nt_native.h:702
#define FILE_ATTRIBUTE_HIDDEN
Definition: nt_native.h:703
#define FILE_ATTRIBUTE_SYSTEM
Definition: nt_native.h:704
#define FILE_ATTRIBUTE_ARCHIVE
Definition: nt_native.h:706
#define FILE_ATTRIBUTE_DIRECTORY
Definition: nt_native.h:705
#define FILE_ATTRIBUTE_REPARSE_POINT
Definition: ntifs_ex.h:381
#define dprintf
Definition: regdump.c:33

Referenced by handle_getattr(), nfs_to_basic_info(), nfs_to_network_openinfo(), nfs_to_standard_info(), and readdir_copy_dir_info().

◆ nfs_time_to_file_time()

static __inline void nfs_time_to_file_time ( IN const nfstime4 nfs_time,
OUT PLARGE_INTEGER  file_time 
)
static

Definition at line 125 of file util.h.

128{
129 file_time->QuadPart = FILETIME_EPOCH +
130 nfs_time->seconds * 10000000 +
131 nfs_time->nseconds / 100;
132}

Referenced by nfs_to_basic_info(), nfs_to_network_openinfo(), and readdir_copy_dir_info().

◆ nfs_to_basic_info()

void nfs_to_basic_info ( IN const nfs41_file_info info,
OUT PFILE_BASIC_INFO  basic_out 
)

Definition at line 163 of file util.c.

166{
167 nfs_time_to_file_time(&info->time_create, &basic_out->CreationTime);
168 nfs_time_to_file_time(&info->time_access, &basic_out->LastAccessTime);
169 nfs_time_to_file_time(&info->time_modify, &basic_out->LastWriteTime);
170 /* XXX: was using 'change' attr, but that wasn't giving a time */
171 nfs_time_to_file_time(&info->time_modify, &basic_out->ChangeTime);
172 basic_out->FileAttributes = nfs_file_info_to_attributes(info);
173}
ULONG nfs_file_info_to_attributes(IN const nfs41_file_info *info)
Definition: util.c:137
static __inline void nfs_time_to_file_time(IN const nfstime4 *nfs_time, OUT PLARGE_INTEGER file_time)
Definition: util.h:125

Referenced by handle_getattr(), and handle_open().

◆ nfs_to_network_openinfo()

void nfs_to_network_openinfo ( IN const nfs41_file_info info,
OUT PFILE_NETWORK_OPEN_INFORMATION  std_out 
)

Definition at line 189 of file util.c.

192{
193
194 nfs_time_to_file_time(&info->time_create, &net_out->CreationTime);
195 nfs_time_to_file_time(&info->time_access, &net_out->LastAccessTime);
196 nfs_time_to_file_time(&info->time_modify, &net_out->LastWriteTime);
197 /* XXX: was using 'change' attr, but that wasn't giving a time */
198 nfs_time_to_file_time(&info->time_modify, &net_out->ChangeTime);
199 net_out->AllocationSize.QuadPart =
200 net_out->EndOfFile.QuadPart = (LONGLONG)info->size;
201 net_out->FileAttributes = nfs_file_info_to_attributes(info);
202}

Referenced by handle_getattr().

◆ nfs_to_standard_info()

void nfs_to_standard_info ( IN const nfs41_file_info info,
OUT PFILE_STANDARD_INFO  std_out 
)

Definition at line 175 of file util.c.

178{
180
181 std_out->AllocationSize.QuadPart =
182 std_out->EndOfFile.QuadPart = (LONGLONG)info->size;
183 std_out->NumberOfLinks = info->numlinks;
184 std_out->DeletePending = FALSE;
185 std_out->Directory = FileAttributes & FILE_ATTRIBUTE_DIRECTORY ?
186 TRUE : FALSE;
187}
#define TRUE
Definition: types.h:120
#define FALSE
Definition: types.h:117
_Must_inspect_result_ _In_opt_ PFLT_INSTANCE _Out_ PHANDLE _In_ ACCESS_MASK _In_ POBJECT_ATTRIBUTES _Out_ PIO_STATUS_BLOCK _In_opt_ PLARGE_INTEGER _In_ ULONG FileAttributes
Definition: fltkernel.h:1236

Referenced by handle_getattr(), and handle_open().

◆ nfs_to_windows_error()

int nfs_to_windows_error ( int  status,
int  default_error 
)

Definition at line 235 of file util.c.

236{
237 /* make sure this is actually an nfs error */
238 if (status < 0 || (status > 70 && status < 10001) || status > 10087) {
239 eprintf("nfs_to_windows_error called with non-nfs "
240 "error code %d; returning the error as is\n", status);
241 return status;
242 }
243
244 switch (status) {
245 case NFS4_OK: return NO_ERROR;
250 case NFS4ERR_EXIST: return ERROR_FILE_EXISTS;
254 case NFS4ERR_NOSPC: return ERROR_DISK_FULL;
268
269 case NFS4ERR_BADCHAR:
271
272 case NFS4ERR_NOTDIR:
273 case NFS4ERR_ISDIR:
274 case NFS4ERR_SYMLINK:
276
277 case NFS4ERR_EXPIRED:
282
284
285 default:
286 dprintf(1, "nfs error %s not mapped to windows error; "
287 "returning default error %d\n",
288 nfs_error_string(status), default_error);
289 return default_error;
290 }
291}
const char * nfs_error_string(int status)
Definition: daemon_debug.c:370
#define ERROR_INVALID_PARAMETER
Definition: compat.h:101
#define ERROR_NOT_SUPPORTED
Definition: compat.h:100
#define ERROR_INVALID_NAME
Definition: compat.h:103
#define ERROR_FILE_NOT_FOUND
Definition: disk.h:79
@ NFS4ERR_OPENMODE
Definition: nfs41_const.h:145
@ NFS4ERR_BAD_STATEID
Definition: nfs41_const.h:132
@ NFS4ERR_ROFS
Definition: nfs41_const.h:101
@ NFS4ERR_SHARE_DENIED
Definition: nfs41_const.h:120
@ NFS4ERR_TOOSMALL
Definition: nfs41_const.h:110
@ NFS4ERR_NAMETOOLONG
Definition: nfs41_const.h:103
@ NFS4ERR_EXIST
Definition: nfs41_const.h:93
@ NFS4ERR_NOTDIR
Definition: nfs41_const.h:96
@ NFS4ERR_FBIG
Definition: nfs41_const.h:99
@ NFS4ERR_ADMIN_REVOKED
Definition: nfs41_const.h:154
@ NFS4ERR_NOSPC
Definition: nfs41_const.h:100
@ NFS4ERR_NOFILEHANDLE
Definition: nfs41_const.h:127
@ NFS4ERR_EXPIRED
Definition: nfs41_const.h:116
@ NFS4ERR_XDEV
Definition: nfs41_const.h:94
@ NFS4ERR_MLINK
Definition: nfs41_const.h:102
@ NFS4ERR_LOCK_NOTSUPP
Definition: nfs41_const.h:150
@ NFS4ERR_ISDIR
Definition: nfs41_const.h:97
@ NFS4ERR_WRONGSEC
Definition: nfs41_const.h:121
@ NFS4ERR_DENIED
Definition: nfs41_const.h:115
@ NFS4ERR_PERM
Definition: nfs41_const.h:88
@ NFS4ERR_LOCKED
Definition: nfs41_const.h:117
@ NFS4ERR_NOENT
Definition: nfs41_const.h:89
@ NFS4_OK
Definition: nfs41_const.h:87
@ NFS4ERR_LOCK_RANGE
Definition: nfs41_const.h:135
@ NFS4ERR_INVAL
Definition: nfs41_const.h:98
@ NFS4ERR_IO
Definition: nfs41_const.h:90
@ NFS4ERR_SYMLINK
Definition: nfs41_const.h:136
@ NFS4ERR_OLD_STATEID
Definition: nfs41_const.h:131
@ NFS4ERR_STALE
Definition: nfs41_const.h:106
@ NFS4ERR_ATTRNOTSUPP
Definition: nfs41_const.h:139
#define ERROR_NET_WRITE_FAULT
Definition: winerror.h:172
#define ERROR_SHARING_VIOLATION
Definition: winerror.h:135
#define ERROR_DISK_FULL
Definition: winerror.h:186
#define ERROR_NOT_LOCKED
Definition: winerror.h:230
#define ERROR_TOO_MANY_LINKS
Definition: winerror.h:671
#define ERROR_FILE_EXISTS
Definition: winerror.h:165
#define ERROR_FILE_TOO_LARGE
Definition: winerror.h:278
#define ERROR_LOCK_VIOLATION
Definition: winerror.h:136
#define ERROR_NOT_SAME_DEVICE
Definition: winerror.h:120
#define ERROR_FILE_INVALID
Definition: winerror.h:585
#define ERROR_LOCK_FAILED
Definition: winerror.h:236
#define ERROR_ATOMIC_LOCKS_NOT_SUPPORTED
Definition: winerror.h:240
#define ERROR_NETWORK_ACCESS_DENIED
Definition: winerror.h:157
#define ERROR_NETNAME_DELETED
Definition: winerror.h:156

Referenced by cancel_lock(), cancel_open(), do_nfs41_close(), get_volume_size_info(), handle_close(), handle_lock(), handle_nfs41_remove(), handle_nfs41_set_size(), handle_open(), handle_readdir(), handle_setacl(), handle_setexattr(), handle_unlock(), map_lookup_error(), map_symlink_errors(), nfs41_cached_getattr(), nfs41_name_cache_remove_stale(), read_from_mds(), referral_resolve(), session_get_lease(), and write_to_mds().

◆ nfstime_abs()

static __inline void nfstime_abs ( IN const nfstime4 nt,
OUT nfstime4 result 
)
static

Definition at line 158 of file util.h.

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}
static __inline void nfstime_diff(IN const nfstime4 *lhs, IN const nfstime4 *rhs, OUT nfstime4 *result)
Definition: util.h:148
GLuint64EXT * result
Definition: glext.h:11304
IMAGE_NT_HEADERS nt
Definition: module.c:50
int zero
Definition: sehframes.cpp:29

Referenced by settime_how().

◆ nfstime_diff()

static __inline void nfstime_diff ( IN const nfstime4 lhs,
IN const nfstime4 rhs,
OUT nfstime4 result 
)
static

Definition at line 148 of file util.h.

152{
153 /* result = lhs - rhs */
154 result->seconds = lhs->seconds - rhs->seconds;
155 result->nseconds = lhs->nseconds - rhs->nseconds;
157}
static __inline void nfstime_normalize(IN OUT nfstime4 *nfstime)
Definition: util.h:139

Referenced by nfstime_abs(), and settime_how().

◆ nfstime_normalize()

static __inline void nfstime_normalize ( IN OUT nfstime4 nfstime)
static

Definition at line 139 of file util.h.

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}
INT32 int32_t
Definition: types.h:71

Referenced by nfstime_diff().

◆ path_fh_copy()

void path_fh_copy ( OUT nfs41_path_fh dst,
IN const nfs41_path_fh src 
)

Definition at line 364 of file util.c.

367{
368 dst->path = src->path;
369 if (dst->path) {
370 const size_t name_start = src->name.name - src->path->path;
371 dst->name.name = dst->path->path + name_start;
372 dst->name.len = src->name.len;
373 } else {
374 dst->name.name = NULL;
375 dst->name.len = 0;
376 }
377 fh_copy(&dst->fh, &src->fh);
378}
void fh_copy(OUT nfs41_fh *dst, IN const nfs41_fh *src)
Definition: util.c:354

Referenced by nfs41_lookup(), prev_non_delimiter(), and server_lookup().

◆ path_fh_init()

void path_fh_init ( OUT nfs41_path_fh file,
IN nfs41_abs_path path 
)

Definition at line 346 of file util.c.

349{
350 file->path = path;
351 last_component(path->path, path->path + path->len, &file->name);
352}
Definition: fci.c:127
WCHAR * path
Definition: filesystem.c:122
char name[1]
Definition: fci.c:135

Referenced by create_open_state(), delegation_create(), and prev_non_delimiter().

◆ prev_delimiter()

__inline const char * prev_delimiter ( const char pos,
const char start 
)

Definition at line 223 of file util.h.

223 {
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}
GLuint start
Definition: gl.h:1545

Referenced by abs_path_link(), last_component(), and prev_delimiter().

◆ prev_non_delimiter()

__inline const char * prev_non_delimiter ( const char pos,
const char start 
)

Definition at line 241 of file util.h.

241 {
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}

Referenced by last_component(), and prev_non_delimiter().

◆ safe_read()

int safe_read ( unsigned char **  pos,
uint32_t remaining,
void dest,
uint32_t  dest_len 
)

Definition at line 33 of file util.c.

34{
35 if (*remaining < dest_len)
37
38 CopyMemory(dest, *pos, dest_len);
39 *pos += dest_len;
40 *remaining -= dest_len;
41 return 0;
42}
static char * dest
Definition: rtl.c:135
#define CopyMemory
Definition: winbase.h:1668

Referenced by get_name(), handle_unlock(), parse_abs_path(), parse_close(), parse_getacl(), parse_getattr(), parse_getexattr(), parse_lock(), parse_mount(), parse_open(), parse_readdir(), parse_rw(), parse_setacl(), parse_setattr(), parse_setexattr(), parse_symlink(), parse_unlock(), parse_volume(), and upcall_parse().

◆ safe_write()

int safe_write ( unsigned char **  pos,
uint32_t remaining,
void dest,
uint32_t  dest_len 
)

Definition at line 44 of file util.c.

45{
46 if (*remaining < src_len)
48
49 CopyMemory(*pos, src, src_len);
50 *pos += src_len;
51 *remaining -= src_len;
52 return 0;
53}

Referenced by delegation_return(), marshall_getacl(), marshall_getattr(), marshall_getexattr(), marshall_mount(), marshall_open(), marshall_readdir(), marshall_rw(), marshall_setacl(), marshall_setattr(), marshall_setexattr(), marshall_symlink(), marshall_volume(), and upcall_marshall().

◆ strip_path()

const char * strip_path ( IN const char path,
OUT uint32_t *len_out  OPTIONAL 
)

◆ valid_handle()

__inline int valid_handle ( HANDLE  handle)

Definition at line 281 of file util.h.

281 {
282#else
284#endif
285 return handle != INVALID_HANDLE_VALUE && handle != 0;
286}
__inline int valid_handle(HANDLE handle)
Definition: util.h:281
#define INVALID_HANDLE_VALUE
Definition: compat.h:731

Referenced by get_handle_object(), nfs41_session_free(), nfs41_session_set_lease(), and valid_handle().

◆ verify_commit()

bool_t verify_commit ( IN nfs41_write_verf verf)

Definition at line 126 of file util.c.

128{
129 if (memcmp(verf->expected, verf->verf, NFS4_VERIFIER_SIZE) == 0) {
130 dprintf(3, "verify_commit: verifier matches expected\n");
131 return 1;
132 }
133 dprintf(2, "verify_commit: verifier changed; writes have been lost!\n");
134 return 0;
135}
int memcmp(void *Buffer1, void *Buffer2, ACPI_SIZE Count)
Definition: utclib.c:112
#define NFS4_VERIFIER_SIZE
Definition: nfs41_const.h:30

Referenced by file_layout_write_thread(), and write_to_mds().

◆ verify_write()

bool_t verify_write ( IN nfs41_write_verf verf,
IN OUT enum stable_how4 stable 
)

Definition at line 100 of file util.c.

103{
104 if (verf->committed != UNSTABLE4) {
105 *stable = verf->committed;
106 dprintf(3, "verify_write: committed to stable storage\n");
107 return 1;
108 }
109
110 if (*stable != UNSTABLE4) {
111 memcpy(verf->expected, verf->verf, NFS4_VERIFIER_SIZE);
112 *stable = UNSTABLE4;
113 dprintf(3, "verify_write: first unstable write, saving verifier\n");
114 return 1;
115 }
116
117 if (memcmp(verf->expected, verf->verf, NFS4_VERIFIER_SIZE) == 0) {
118 dprintf(3, "verify_write: verifier matches expected\n");
119 return 1;
120 }
121
122 dprintf(2, "verify_write: verifier changed; writes have been lost!\n");
123 return 0;
124}
@ UNSTABLE4
Definition: nfs41_ops.h:836

Referenced by file_layout_write_thread(), and write_to_mds().

Variable Documentation

◆ NFS41D_VERSION

DWORD NFS41D_VERSION
extern

Definition at line 42 of file nfs41_daemon.c.

Referenced by marshall_mount(), ServiceStart(), and upcall_parse().