ReactOS  0.4.12-dev-102-g4b7f1e0
util.c File Reference
#include <windows.h>
#include <strsafe.h>
#include <stdio.h>
#include <stdlib.h>
#include <wincrypt.h>
#include "daemon_debug.h"
#include "util.h"
#include "nfs41_ops.h"
Include dependency graph for util.c:

Go to the source code of this file.

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 *src, uint32_t src_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)
 
uint32_t max_read_size (IN const nfs41_session *session, IN const nfs41_fh *fh)
 
uint32_t max_write_size (IN const 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)
 
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 net_out)
 
void get_file_time (OUT PLARGE_INTEGER file_time)
 
void get_nfs_time (OUT nfstime4 *nfs_time)
 
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)
 
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)
 
int create_silly_rename (IN nfs41_abs_path *path, IN const nfs41_fh *fh, OUT nfs41_component *silly)
 

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

◆ 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
unsigned char BYTE
Definition: mem.h:68
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
#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

◆ 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_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 nfs41_session session,
IN const nfs41_fh fh 
)

Definition at line 84 of file util.c.

Referenced by file_layout_read_thread(), and read_from_mds().

87 {
88  const uint32_t maxresponse = session->fore_chan_attrs.ca_maxresponsesize;
89  return (uint32_t)min(fh->superblock->maxread, maxresponse - READ_OVERHEAD);
90 }
#define READ_OVERHEAD
Definition: nfs41_const.h:68
#define min(a, b)
Definition: monoChain.cc:55
UINT32 uint32_t
Definition: types.h:75

◆ max_write_size()

uint32_t max_write_size ( IN const nfs41_session session,
IN const nfs41_fh fh 
)

Definition at line 92 of file util.c.

Referenced by file_layout_write_thread(), and write_to_mds().

95 {
96  const uint32_t maxrequest = session->fore_chan_attrs.ca_maxrequestsize;
97  return (uint32_t)min(fh->superblock->maxwrite, maxrequest - WRITE_OVERHEAD);
98 }
#define WRITE_OVERHEAD
Definition: nfs41_const.h:75
#define min(a, b)
Definition: monoChain.cc:55
UINT32 uint32_t
Definition: types.h:75

◆ 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

◆ 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_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  net_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

◆ 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

◆ 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 src,
uint32_t  src_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
#define CopyMemory
Definition: winbase.h:1633

◆ strip_path()

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

Definition at line 73 of file util.c.

76 {
77  const char *name = strrchr(path, '\\');
78  name = name ? name + 1 : path;
79  if (len_out)
80  *len_out = (uint32_t)strlen(name);
81  return name;
82 }
ACPI_SIZE strlen(const char *String)
Definition: utclib.c:269
GLsizei const GLchar ** path
Definition: glext.h:7234
_Check_return_ _CRTIMP _CONST_RETURN char *__cdecl strrchr(_In_z_ const char *_Str, _In_ int _Ch)
Definition: services.c:325
Definition: name.c:36
#define uint32_t
Definition: nsiface.idl:61
GLuint const GLchar * name
Definition: glext.h:6031

◆ 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