ReactOS  0.4.12-dev-43-g63b00d8
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.

Referenced by file_time_to_nfs_time(), and nfs_time_to_file_time().

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.

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

341 {
342  dst->len = src->len;
343  StringCchCopyNA(dst->path, NFS41_MAX_PATH_LEN, src->path, dst->len);
344 }
#define NFS41_MAX_PATH_LEN
Definition: nfs41_const.h:46
GLuint const GLubyte GLvoid * src
Definition: s_context.h:57
STRSAFEAPI StringCchCopyNA(STRSAFE_LPSTR pszDest, size_t cchDest, STRSAFE_LPCSTR pszSrc, size_t cchToCopy)
Definition: strsafe.h:230
GLuint const GLubyte GLvoid const GLvoid * dst
Definition: s_context.h:57

◆ 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 }
GLintptr offset
Definition: glext.h:5920
#define FORCEINLINE
Definition: ntbasedef.h:221
__inline uint32_t align4(uint32_t offset)
Definition: util.h:198
UINT32 uint32_t
Definition: types.h:75

◆ align8()

__inline uint32_t align8 ( uint32_t  offset)

Definition at line 191 of file util.h.

Referenced by readdir_copy_entry().

191  {
192 #else
194 #endif
195  return 8 + ((offset - 1) & ~7);
196 }
GLintptr offset
Definition: glext.h:5920
#define FORCEINLINE
Definition: ntbasedef.h:221
__inline uint32_t align8(uint32_t offset)
Definition: util.h:191
UINT32 uint32_t
Definition: types.h:75

◆ bitmap_intersect()

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

Definition at line 85 of file util.h.

Referenced by nfs41_superblock_supported_attrs(), and nfs41_superblock_supported_attrs_exclcreat().

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
GLuint const GLubyte GLvoid * src
Definition: s_context.h:57
GLenum GLclampf GLint i
Definition: glfuncs.h:14
#define min(a, b)
Definition: monoChain.cc:55
GLuint const GLubyte GLvoid const GLvoid * dst
Definition: s_context.h:57
UINT32 uint32_t
Definition: types.h:75

◆ 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.

Referenced by get_superblock_attrs(), and info_to_fattr4().

59 {
60  return mask->count > word && mask->arr[word] & flag;
61 }
GLenum GLint GLuint mask
Definition: glext.h:6028
GLenum GLclampf GLint GLenum GLuint GLenum GLenum GLsizei GLenum const GLvoid GLfloat GLfloat GLfloat GLfloat GLclampd GLint 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 GLboolean GLboolean GLboolean GLint GLenum GLsizei const GLvoid GLenum GLint GLenum GLint GLint GLsizei GLint GLenum GLint GLint GLint GLint GLsizei GLenum GLsizei const GLuint GLboolean flag
Definition: glfuncs.h:72
const WCHAR * word
Definition: lex.c:70

◆ 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.

Referenced by info_to_fattr4().

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 }
GLenum GLint GLuint mask
Definition: glext.h:6028
GLenum GLclampf GLint GLenum GLuint GLenum GLenum GLsizei GLenum const GLvoid GLfloat GLfloat GLfloat GLfloat GLclampd GLint 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 GLboolean GLboolean GLboolean GLint GLenum GLsizei const GLvoid GLenum GLint GLenum GLint GLint GLsizei GLint GLenum GLint GLint GLint GLint GLsizei GLenum GLsizei const GLuint GLboolean flag
Definition: glfuncs.h:72
const WCHAR * word
Definition: lex.c:70

◆ 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 }
GLenum GLint GLuint mask
Definition: glext.h:6028
GLenum GLclampf GLint GLenum GLuint GLenum GLenum GLsizei GLenum const GLvoid GLfloat GLfloat GLfloat GLfloat GLclampd GLint 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 GLboolean GLboolean GLboolean GLint GLenum GLsizei const GLvoid GLenum GLint GLenum GLint GLint GLsizei GLint GLenum GLint GLint GLint GLint GLsizei GLenum GLsizei const GLuint GLboolean flag
Definition: glfuncs.h:72
const WCHAR * word
Definition: lex.c:70

◆ 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.

Referenced by handle_close(), and nfstime_abs().

384 {
387  PBYTE buffer;
388  DWORD length;
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 */
402  if (!CryptAcquireContext(&context, NULL, NULL,
404  status = GetLastError();
405  eprintf("CryptAcquireContext() failed with %d\n", status);
406  goto out;
407  }
408  if (!CryptCreateHash(context, CALG_MD5, 0, 0, &hash)) {
409  status = GetLastError();
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)) {
415  status = GetLastError();
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;
423  if (!CryptGetHashParam(hash, HP_HASHVAL, buffer, &length, 0)) {
424  status = GetLastError();
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 
442 out_hash:
443  CryptDestroyHash(hash);
444 out_context:
445  CryptReleaseContext(context, 0);
446 out:
447  return status;
448 }
char * name
Definition: wpp.c:36
#define NFS41_MAX_COMPONENT_LEN
Definition: nfs41_const.h:45
Definition: http.c:6587
DWORD WINAPI GetLastError(VOID)
Definition: except.c:1059
void eprintf(LPCSTR format,...)
Definition: daemon_debug.c:86
GLuint buffer
Definition: glext.h:5915
#define CryptAcquireContext
Definition: wincrypt.h:4162
GLuint GLuint end
Definition: gl.h:1545
#define NO_ERROR
Definition: dderror.h:5
bool_t last_component(IN const char *path, IN const char *path_end, OUT nfs41_component *component)
Definition: util.c:317
#define NFS41_MAX_PATH_LEN
Definition: nfs41_const.h:46
GLenum GLclampf GLint i
Definition: glfuncs.h:14
STRSAFEAPI StringCchCopyNA(STRSAFE_LPSTR pszDest, size_t cchDest, STRSAFE_LPCSTR pszSrc, size_t cchToCopy)
Definition: strsafe.h:230
#define StringCchPrintf
Definition: strsafe.h:517
BOOL WINAPI CryptGetHashParam(HCRYPTHASH hHash, DWORD dwParam, BYTE *pbData, DWORD *pdwDataLen, DWORD dwFlags)
Definition: crypt.c:1615
int hash
Definition: main.c:58
smooth NULL
Definition: ftsmooth.c:416
GLenum GLuint GLenum GLsizei length
Definition: glext.h:5579
static FILE * out
Definition: regtests2xml.c:44
unsigned long DWORD
Definition: ntddk_ex.h:95
BOOL WINAPI CryptDestroyHash(HCRYPTHASH hHash)
Definition: crypt.c:895
BOOL WINAPI CryptCreateHash(HCRYPTPROV hProv, ALG_ID Algid, HCRYPTKEY hKey, DWORD dwFlags, HCRYPTHASH *phHash)
Definition: crypt.c:745
#define CALG_MD5
Definition: wincrypt.h:1805
unsigned char BYTE
Definition: ntddk_ex.h:96
#define CRYPT_VERIFYCONTEXT
Definition: wincrypt.h:2069
ULONG_PTR HCRYPTHASH
Definition: wincrypt.h:50
ULONG_PTR HCRYPTPROV
Definition: wincrypt.h:46
Definition: services.c:325
BOOL WINAPI CryptHashData(HCRYPTHASH hHash, const BYTE *pbData, DWORD dwDataLen, DWORD dwFlags)
Definition: crypt.c:1776
BOOL WINAPI CryptReleaseContext(HCRYPTPROV hProv, ULONG_PTR dwFlags)
Definition: crypt.c:651
Definition: name.c:36
#define HP_HASHVAL
Definition: wincrypt.h:2183
static SERVICE_STATUS status
Definition: service.c:31
BYTE * PBYTE
Definition: pedump.c:66
#define PROV_RSA_FULL
Definition: wincrypt.h:2039
#define ERROR_FILENAME_EXCED_RANGE
Definition: winerror.h:263
Definition: ps.c:97

◆ fh_copy()

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

Definition at line 354 of file util.c.

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().

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 }
GLuint const GLubyte GLvoid * src
Definition: s_context.h:57
#define memcpy(s1, s2, n)
Definition: mkisofs.h:878
GLuint const GLubyte GLvoid const GLvoid * dst
Definition: s_context.h:57

◆ 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
int64_t LONGLONG
Definition: typedefs.h:66
#define uint32_t
Definition: nsiface.idl:61

◆ get_file_time()

void get_file_time ( OUT PLARGE_INTEGER  file_time)

Definition at line 204 of file util.c.

Referenced by get_nfs_time(), and nfs_time_to_file_time().

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

◆ get_name()

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

Definition at line 55 of file util.c.

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().

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) {
63  status = ERROR_BUFFER_OVERFLOW;
64  goto out;
65  }
66  *out_name = (const char*)*pos;
67  *pos += len;
68  *remaining -= len;
69 out:
70  return status;
71 }
#define ERROR_BUFFER_OVERFLOW
Definition: winerror.h:185
static FILE * out
Definition: regtests2xml.c:44
GLenum GLsizei len
Definition: glext.h:6722
unsigned short USHORT
Definition: pedump.c:61
int safe_read(unsigned char **pos, uint32_t *remaining, void *dest, uint32_t dest_len)
Definition: util.c:33
static SERVICE_STATUS status
Definition: service.c:31

◆ get_nfs_time()

void get_nfs_time ( OUT nfstime4 nfs_time)

Definition at line 210 of file util.c.

Referenced by delegation_truncate(), nfs_time_to_file_time(), and settime_how().

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
void file_time_to_nfs_time(IN const PLARGE_INTEGER file_time, OUT LONGLONG *nfs_time)

◆ is_delimiter()

__inline int is_delimiter ( char  c)

Definition at line 207 of file util.h.

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

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

◆ 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.

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

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
Definition: services.c:325

◆ 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.

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

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 }
unsigned short(__cdecl typeof(TIFFCurrentDirectory))(struct tiff *)
Definition: typeof.h:91
__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
__inline const char * next_non_delimiter(const char *pos, const char *end)
Definition: util.h:232
Definition: services.c:325

◆ map_symlink_errors()

int map_symlink_errors ( int  status)

Definition at line 293 of file util.c.

Referenced by handle_open(), handle_symlink(), and nfstime_abs().

294 {
295  switch (status) {
296  case NFS4ERR_BADCHAR:
299  case NFS4ERR_ACCESS: return ERROR_ACCESS_DENIED;
300  case NFS4ERR_NOTEMPTY: return ERROR_NOT_EMPTY;
302  }
303 }
#define ERROR_NOT_A_REPARSE_POINT
Definition: winerror.h:1288
int nfs_to_windows_error(int status, int default_error)
Definition: util.c:235
#define ERROR_BAD_NET_RESP
Definition: winerror.h:150
#define ERROR_ACCESS_DENIED
Definition: compat.h:87
#define ERROR_INVALID_REPARSE_DATA
Definition: winerror.h:1290
#define ERROR_NOT_EMPTY
Definition: winerror.h:1251
Definition: ps.c:97

◆ 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.

Referenced by cl_addr_compare(), nfstime_abs(), and server_addrs_add().

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 }
GLenum GLclampf GLint i
Definition: glfuncs.h:14
int strncmp(const char *String1, const char *String2, ACPI_SIZE Count)
Definition: utclib.c:534
#define NFS41_UNIVERSAL_ADDR_LEN
Definition: nfs41_const.h:53
GLenum const GLvoid * addr
Definition: glext.h:9621
char uaddr[NFS41_UNIVERSAL_ADDR_LEN+1]
Definition: nfs41_types.h:87
UINT32 uint32_t
Definition: types.h:75
#define NFS41_NETWORK_ID_LEN
Definition: nfs41_const.h:56
char netid[NFS41_NETWORK_ID_LEN+1]
Definition: nfs41_types.h:86

◆ 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.

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

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 }
unsigned short(__cdecl typeof(TIFFCurrentDirectory))(struct tiff *)
Definition: typeof.h:91
__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
Definition: services.c:325

◆ next_delimiter()

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

Definition at line 214 of file util.h.

Referenced by is_last_component(), and next_component().

214  {
215 #else
216 FORCEINLINE 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 }
GLuint GLuint end
Definition: gl.h:1545
#define FORCEINLINE
Definition: ntbasedef.h:221
__inline const char * next_delimiter(const char *pos, const char *end)
Definition: util.h:214
__inline int is_delimiter(char c)
Definition: util.h:207

◆ next_non_delimiter()

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

Definition at line 232 of file util.h.

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

232  {
233 #else
234 FORCEINLINE 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 }
GLuint GLuint end
Definition: gl.h:1545
#define FORCEINLINE
Definition: ntbasedef.h:221
__inline const char * next_non_delimiter(const char *pos, const char *end)
Definition: util.h:232
__inline int is_delimiter(char c)
Definition: util.h:207

◆ 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.

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

139 {
140  ULONG attrs = 0;
141  if (info->type == NF4DIR)
142  attrs |= FILE_ATTRIBUTE_DIRECTORY;
143  else if (info->type == NF4LNK) {
145  if (info->symlink_dir)
146  attrs |= FILE_ATTRIBUTE_DIRECTORY;
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 */
152  attrs |= FILE_ATTRIBUTE_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_SYSTEM
Definition: nt_native.h:704
#define dprintf
Definition: regdump.c:33
#define FILE_ATTRIBUTE_REPARSE_POINT
Definition: ntifs_ex.h:381
#define FILE_ATTRIBUTE_DIRECTORY
Definition: nt_native.h:705
#define FILE_ATTRIBUTE_READONLY
Definition: nt_native.h:702
#define FILE_ATTRIBUTE_ARCHIVE
Definition: nt_native.h:706
#define FILE_ATTRIBUTE_NORMAL
Definition: compat.h:126
#define FILE_ATTRIBUTE_HIDDEN
Definition: nt_native.h:703
unsigned int ULONG
Definition: retypes.h:1

◆ 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.

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

128 {
129  file_time->QuadPart = FILETIME_EPOCH +
130  nfs_time->seconds * 10000000 +
131  nfs_time->nseconds / 100;
132 }
#define FILETIME_EPOCH
Definition: util.h:114

◆ 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.

Referenced by bitmap_intersect(), handle_getattr(), and handle_open().

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 }
static __inline void nfs_time_to_file_time(IN const nfstime4 *nfs_time, OUT PLARGE_INTEGER file_time)
Definition: util.h:125
ULONG nfs_file_info_to_attributes(IN const nfs41_file_info *info)
Definition: util.c:137

◆ 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.

Referenced by bitmap_intersect(), and handle_getattr().

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 }
int64_t LONGLONG
Definition: typedefs.h:66
static __inline void nfs_time_to_file_time(IN const nfstime4 *nfs_time, OUT PLARGE_INTEGER file_time)
Definition: util.h:125
ULONG nfs_file_info_to_attributes(IN const nfs41_file_info *info)
Definition: util.c:137

◆ 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.

Referenced by bitmap_intersect(), handle_getattr(), and handle_open().

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
_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:1230
#define FILE_ATTRIBUTE_DIRECTORY
Definition: nt_native.h:705
int64_t LONGLONG
Definition: typedefs.h:66
ULONG nfs_file_info_to_attributes(IN const nfs41_file_info *info)
Definition: util.c:137
unsigned int ULONG
Definition: retypes.h:1

◆ nfs_to_windows_error()

int nfs_to_windows_error ( int  status,
int  default_error 
)

Definition at line 235 of file util.c.

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(), nfstime_abs(), read_from_mds(), referral_resolve(), session_get_lease(), and write_to_mds().

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;
246  case NFS4ERR_PERM: return ERROR_ACCESS_DENIED;
247  case NFS4ERR_NOENT: return ERROR_FILE_NOT_FOUND;
248  case NFS4ERR_IO: return ERROR_NET_WRITE_FAULT;
249  case NFS4ERR_ACCESS: return ERROR_ACCESS_DENIED;
250  case NFS4ERR_EXIST: return ERROR_FILE_EXISTS;
251  case NFS4ERR_XDEV: return ERROR_NOT_SAME_DEVICE;
253  case NFS4ERR_FBIG: return ERROR_FILE_TOO_LARGE;
254  case NFS4ERR_NOSPC: return ERROR_DISK_FULL;
256  case NFS4ERR_MLINK: return ERROR_TOO_MANY_LINKS;
259  case NFS4ERR_NOTEMPTY: return ERROR_NOT_EMPTY;
260  case NFS4ERR_DENIED: return ERROR_LOCK_FAILED;
268 
269  case NFS4ERR_BADCHAR:
270  case NFS4ERR_BADNAME: return ERROR_INVALID_NAME;
271 
272  case NFS4ERR_NOTDIR:
273  case NFS4ERR_ISDIR:
274  case NFS4ERR_SYMLINK:
276 
277  case NFS4ERR_EXPIRED:
279  case NFS4ERR_OLD_STATEID:
280  case NFS4ERR_BAD_STATEID:
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 }
#define ERROR_NETNAME_DELETED
Definition: winerror.h:156
#define ERROR_INVALID_PARAMETER
Definition: compat.h:91
#define ERROR_FILE_EXISTS
Definition: winerror.h:165
#define ERROR_BUFFER_OVERFLOW
Definition: winerror.h:185
#define ERROR_DISK_FULL
Definition: winerror.h:186
void eprintf(LPCSTR format,...)
Definition: daemon_debug.c:86
#define ERROR_FILE_TOO_LARGE
Definition: winerror.h:278
#define NO_ERROR
Definition: dderror.h:5
#define ERROR_ACCESS_DENIED
Definition: compat.h:87
#define dprintf
Definition: regdump.c:33
#define ERROR_FILE_NOT_FOUND
Definition: disk.h:79
#define ERROR_LOCK_FAILED
Definition: winerror.h:236
#define ERROR_NOT_EMPTY
Definition: winerror.h:1251
const char * nfs_error_string(int status)
Definition: daemon_debug.c:370
#define ERROR_ATOMIC_LOCKS_NOT_SUPPORTED
Definition: winerror.h:240
#define ERROR_TOO_MANY_LINKS
Definition: winerror.h:671
#define ERROR_SHARING_VIOLATION
Definition: winerror.h:135
#define ERROR_NETWORK_ACCESS_DENIED
Definition: winerror.h:157
#define ERROR_FILE_INVALID
Definition: winerror.h:585
#define ERROR_NOT_SAME_DEVICE
Definition: winerror.h:120
#define ERROR_NOT_SUPPORTED
Definition: compat.h:90
#define ERROR_LOCK_VIOLATION
Definition: winerror.h:136
#define ERROR_NET_WRITE_FAULT
Definition: winerror.h:172
#define ERROR_INVALID_NAME
Definition: compat.h:93
#define ERROR_NOT_LOCKED
Definition: winerror.h:230
static SERVICE_STATUS status
Definition: service.c:31
#define ERROR_FILENAME_EXCED_RANGE
Definition: winerror.h:263
Definition: ps.c:97

◆ nfstime_abs()

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

Definition at line 158 of file util.h.

Referenced by settime_how().

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 }
IMAGE_NT_HEADERS nt
Definition: module.c:50
static double zero
Definition: j0_y0.c:96
#define memcpy(s1, s2, n)
Definition: mkisofs.h:878
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

◆ 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.

Referenced by nfstime_abs(), and settime_how().

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
GLuint64EXT * result
Definition: glext.h:11304

◆ nfstime_normalize()

static __inline void nfstime_normalize ( IN OUT nfstime4 nfstime)
static

Definition at line 139 of file util.h.

Referenced by nfstime_diff().

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

◆ 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.

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

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 }
GLuint const GLubyte GLvoid * src
Definition: s_context.h:57
smooth NULL
Definition: ftsmooth.c:416
void fh_copy(OUT nfs41_fh *dst, IN const nfs41_fh *src)
Definition: util.c:354
GLuint const GLubyte GLvoid const GLvoid * dst
Definition: s_context.h:57

◆ 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.

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

349 {
350  file->path = path;
351  last_component(path->path, path->path + path->len, &file->name);
352 }
GLsizei const GLchar ** path
Definition: glext.h:7234
bool_t last_component(IN const char *path, IN const char *path_end, OUT nfs41_component *component)
Definition: util.c:317
char name[1]
Definition: fci.c:135
Definition: services.c:325
WCHAR * path
Definition: filesystem.c:121
Definition: fci.c:126

◆ prev_delimiter()

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

Definition at line 223 of file util.h.

Referenced by abs_path_link(), and last_component().

223  {
224 #else
225 FORCEINLINE 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 }
__inline const char * prev_delimiter(const char *pos, const char *start)
Definition: util.h:223
#define FORCEINLINE
Definition: ntbasedef.h:221
GLuint start
Definition: gl.h:1545
__inline int is_delimiter(char c)
Definition: util.h:207

◆ prev_non_delimiter()

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

Definition at line 241 of file util.h.

Referenced by last_component().

241  {
242 #else
243 FORCEINLINE 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 }
__inline const char * prev_non_delimiter(const char *pos, const char *start)
Definition: util.h:241
#define FORCEINLINE
Definition: ntbasedef.h:221
GLuint start
Definition: gl.h:1545
__inline int is_delimiter(char c)
Definition: util.h:207

◆ 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.

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().

34 {
35  if (*remaining < dest_len)
36  return ERROR_BUFFER_OVERFLOW;
37 
38  CopyMemory(dest, *pos, dest_len);
39  *pos += dest_len;
40  *remaining -= dest_len;
41  return 0;
42 }
#define ERROR_BUFFER_OVERFLOW
Definition: winerror.h:185
#define CopyMemory
Definition: winbase.h:1633

◆ 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.

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().

45 {
46  if (*remaining < src_len)
47  return ERROR_BUFFER_OVERFLOW;
48 
49  CopyMemory(*pos, src, src_len);
50  *pos += src_len;
51  *remaining -= src_len;
52  return 0;
53 }
#define ERROR_BUFFER_OVERFLOW
Definition: winerror.h:185
GLuint const GLubyte GLvoid * src
Definition: s_context.h:57
#define CopyMemory
Definition: winbase.h:1633

◆ 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.

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

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

◆ verify_commit()

bool_t verify_commit ( IN nfs41_write_verf verf)

Definition at line 126 of file util.c.

Referenced by file_layout_write_thread(), and write_to_mds().

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
#define dprintf
Definition: regdump.c:33

◆ 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.

Referenced by file_layout_write_thread(), and write_to_mds().

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 }
int memcmp(void *Buffer1, void *Buffer2, ACPI_SIZE Count)
Definition: utclib.c:112
#define NFS4_VERIFIER_SIZE
Definition: nfs41_const.h:30
#define dprintf
Definition: regdump.c:33
#define memcpy(s1, s2, n)
Definition: mkisofs.h:878

Variable Documentation

◆ NFS41D_VERSION

DWORD NFS41D_VERSION

Definition at line 42 of file nfs41_daemon.c.

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