ReactOS  0.4.11-dev-946-g431643b
setattr.c File Reference
#include <windows.h>
#include <stdio.h>
#include <strsafe.h>
#include "from_kernel.h"
#include "nfs41_ops.h"
#include "delegation.h"
#include "name_cache.h"
#include "upcall.h"
#include "util.h"
#include "daemon_debug.h"
Include dependency graph for setattr.c:

Go to the source code of this file.

Functions

static int parse_setattr (unsigned char *buffer, uint32_t length, nfs41_upcall *upcall)
 
static int handle_nfs41_setattr (setattr_upcall_args *args)
 
static int handle_nfs41_remove (setattr_upcall_args *args)
 
static void open_state_rename (OUT nfs41_open_state *state, IN const nfs41_abs_path *path)
 
static int nfs41_abs_path_compare (IN const struct list_entry *entry, IN const void *value)
 
static int is_dst_name_opened (nfs41_abs_path *dst_path, nfs41_session *dst_session)
 
static int handle_nfs41_rename (setattr_upcall_args *args)
 
static int handle_nfs41_set_size (setattr_upcall_args *args)
 
static int handle_nfs41_link (setattr_upcall_args *args)
 
static int handle_setattr (nfs41_upcall *upcall)
 
static int marshall_setattr (unsigned char *buffer, uint32_t *length, nfs41_upcall *upcall)
 

Variables

const nfs41_upcall_op nfs41_op_setattr
 

Function Documentation

◆ handle_nfs41_link()

static int handle_nfs41_link ( setattr_upcall_args args)
static

Definition at line 381 of file setattr.c.

Referenced by handle_setattr().

382 {
383  nfs41_open_state *state = args->state;
385  nfs41_session *dst_session;
386  nfs41_abs_path dst_path = { 0 };
387  nfs41_path_fh dst_dir, dst;
388  nfs41_component dst_name;
389  uint32_t depth = 0;
390  nfs41_file_info info = { 0 };
391  int status;
392 
393  dst_path.len = (unsigned short)WideCharToMultiByte(CP_UTF8, 0,
394  link->FileName, link->FileNameLength/sizeof(WCHAR),
395  dst_path.path, NFS41_MAX_PATH_LEN, NULL, NULL);
396  if (dst_path.len == 0) {
397  eprintf("WideCharToMultiByte failed to convert destination "
398  "filename %S.\n", link->FileName);
400  goto out;
401  }
402  path_fh_init(&dst_dir, &dst_path);
403 
404  /* the destination path is absolute, so start from the root session */
406  &dst_path, &dst_dir, &dst, NULL, &dst_session);
407 
408  while (status == ERROR_REPARSE) {
409  if (++depth > NFS41_MAX_SYMLINK_DEPTH) {
411  goto out;
412  }
413 
414  /* replace the path with the symlink target's */
415  status = nfs41_symlink_target(dst_session, &dst_dir, &dst_path);
416  if (status) {
417  eprintf("nfs41_symlink_target() for %s failed with %d\n",
418  dst_dir.path->path, status);
419  goto out;
420  }
421 
422  /* redo the lookup until it doesn't return REPARSE */
423  status = nfs41_lookup(args->root, dst_session,
424  &dst_path, &dst_dir, &dst, NULL, &dst_session);
425  }
426 
427  /* get the components after lookup in case a referral changed its path */
428  last_component(dst_path.path, dst_path.path + dst_path.len, &dst_name);
429  last_component(dst_path.path, dst_name.name, &dst_dir.name);
430 
431  if (status == NO_ERROR) {
432  if (!link->ReplaceIfExists) {
434  goto out;
435  }
436  } else if (status != ERROR_FILE_NOT_FOUND) {
437  dprintf(1, "nfs41_lookup('%s') failed to find destination "
438  "directory with %d\n", dst_path.path, status);
439  goto out;
440  }
441 
442  /* http://tools.ietf.org/html/rfc5661#section-18.9.3
443  * "The existing file and the target directory must reside within
444  * the same file system on the server." */
445  if (state->file.fh.superblock != dst_dir.fh.superblock) {
447  goto out;
448  }
449 
450  if (status == NO_ERROR) {
451  /* break any delegations and truncate the destination file */
452  nfs41_delegation_return(dst_session, &dst,
454 
455  /* LINK will return NFS4ERR_EXIST if the target file exists,
456  * so we have to remove it ourselves */
457  status = nfs41_remove(state->session,
458  &dst_dir, &dst_name, dst.fh.fileid);
459  if (status) {
460  dprintf(1, "nfs41_remove() failed with error %s.\n",
463  goto out;
464  }
465  }
466 
467  /* break read delegations on the source file */
468  nfs41_delegation_return(state->session, &state->file,
470 
471  status = nfs41_link(state->session, &state->file, &dst_dir, &dst_name,
472  &info);
473  if (status) {
474  dprintf(1, "nfs41_link() failed with error %s.\n",
477  }
478  args->ctime = info.change;
479 out:
480  return status;
481 }
#define ERROR_INVALID_PARAMETER
Definition: compat.h:91
#define ERROR_FILE_EXISTS
Definition: winerror.h:165
int nfs_to_windows_error(int status, int default_error)
Definition: util.c:235
int nfs41_symlink_target(IN nfs41_session *session, IN nfs41_path_fh *file, OUT nfs41_abs_path *target)
Definition: symlink.c:92
int nfs41_remove(IN nfs41_session *session, IN nfs41_path_fh *parent, IN const nfs41_component *target, IN uint64_t fileid)
Definition: nfs41_ops.c:1180
#define TRUE
Definition: types.h:120
#define WideCharToMultiByte
Definition: compat.h:101
uint64_t fileid
Definition: nfs41_types.h:55
struct __nfs41_superblock * superblock
Definition: nfs41_types.h:56
unsigned char * buf
Definition: upcall.h:106
__wchar_t WCHAR
Definition: xmlstorage.h:180
int nfs41_lookup(IN nfs41_root *root, IN nfs41_session *session, IN OUT nfs41_abs_path *path_inout, OUT OPTIONAL nfs41_path_fh *parent_out, OUT OPTIONAL nfs41_path_fh *target_out, OUT OPTIONAL nfs41_file_info *info_out, OUT nfs41_session **session_out)
Definition: lookup.c:424
void eprintf(LPCSTR format,...)
Definition: daemon_debug.c:86
int nfs41_link(IN nfs41_session *session, IN nfs41_path_fh *src, IN nfs41_path_fh *dst_dir, IN const nfs41_component *target, OUT nfs41_file_info *cinfo)
Definition: nfs41_ops.c:1407
#define NO_ERROR
Definition: dderror.h:5
nfs41_root * root
Definition: upcall.h:104
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
unsigned short(__cdecl typeof(TIFFCurrentDirectory))(struct tiff *)
Definition: typeof.h:91
#define CP_UTF8
Definition: nls.h:20
#define dprintf
Definition: regdump.c:33
smooth NULL
Definition: ftsmooth.c:416
void path_fh_init(OUT nfs41_path_fh *file, IN nfs41_abs_path *path)
Definition: util.c:346
#define ERROR_FILE_NOT_FOUND
Definition: disk.h:79
nfs41_abs_path * path
Definition: nfs41_types.h:60
const char * name
Definition: nfs41_types.h:48
int nfs41_delegation_return(IN nfs41_session *session, IN nfs41_path_fh *file, IN enum open_delegation_type4 access, IN bool_t truncate)
Definition: delegation.c:629
static FILE * out
Definition: regtests2xml.c:44
const char * nfs_error_string(int status)
Definition: daemon_debug.c:370
static __inline nfs41_session * nfs41_root_session(IN nfs41_root *root)
Definition: nfs41.h:321
GLint GLint GLsizei GLsizei GLsizei depth
Definition: gl.h:1546
#define ERROR_TOO_MANY_LINKS
Definition: winerror.h:671
static int state
Definition: maze.c:121
#define ERROR_REPARSE
Definition: winerror.h:522
ULONGLONG ctime
Definition: upcall.h:109
nfs41_component name
Definition: nfs41_types.h:61
struct _FILE_LINK_INFORMATION * PFILE_LINK_INFORMATION
nfs41_open_state * state
Definition: upcall.h:105
GLuint const GLubyte GLvoid const GLvoid * dst
Definition: s_context.h:57
UINT32 uint32_t
Definition: types.h:75
#define NFS41_MAX_SYMLINK_DEPTH
Definition: nfs41_const.h:60
#define ERROR_NOT_SAME_DEVICE
Definition: winerror.h:120
const WCHAR * link
Definition: db.cpp:926
char path[NFS41_MAX_PATH_LEN]
Definition: nfs41_types.h:42
static SERVICE_STATUS status
Definition: service.c:31
Definition: ps.c:97

◆ handle_nfs41_remove()

static int handle_nfs41_remove ( setattr_upcall_args args)
static

Definition at line 152 of file setattr.c.

Referenced by handle_setattr().

153 {
154  nfs41_open_state *state = args->state;
155  int status;
156 
157  /* break any delegations and truncate before REMOVE */
158  nfs41_delegation_return(state->session, &state->file,
160 
161  status = nfs41_remove(state->session, &state->parent,
162  &state->file.name, state->file.fh.fileid);
163  if (status)
164  dprintf(1, "nfs41_remove() failed with error %s.\n",
165  nfs_error_string(status));
166 
168 }
int nfs_to_windows_error(int status, int default_error)
Definition: util.c:235
int nfs41_remove(IN nfs41_session *session, IN nfs41_path_fh *parent, IN const nfs41_component *target, IN uint64_t fileid)
Definition: nfs41_ops.c:1180
#define TRUE
Definition: types.h:120
uint64_t fileid
Definition: nfs41_types.h:55
struct __nfs41_session * session
Definition: nfs41.h:132
#define ERROR_ACCESS_DENIED
Definition: compat.h:87
#define dprintf
Definition: regdump.c:33
int nfs41_delegation_return(IN nfs41_session *session, IN nfs41_path_fh *file, IN enum open_delegation_type4 access, IN bool_t truncate)
Definition: delegation.c:629
const char * nfs_error_string(int status)
Definition: daemon_debug.c:370
static int state
Definition: maze.c:121
nfs41_path_fh parent
Definition: nfs41.h:129
nfs41_path_fh file
Definition: nfs41.h:130
nfs41_component name
Definition: nfs41_types.h:61
nfs41_open_state * state
Definition: upcall.h:105
static SERVICE_STATUS status
Definition: service.c:31

◆ handle_nfs41_rename()

static int handle_nfs41_rename ( setattr_upcall_args args)
static

Definition at line 211 of file setattr.c.

Referenced by handle_setattr().

212 {
213  nfs41_open_state *state = args->state;
214  nfs41_session *dst_session;
215  PFILE_RENAME_INFO rename = (PFILE_RENAME_INFO)args->buf;
216  nfs41_abs_path dst_path = { 0 };
217  nfs41_path_fh dst_dir, dst;
218  nfs41_component dst_name, *src_name;
219  uint32_t depth = 0;
220  int status;
221 
222  src_name = &state->file.name;
223 
224  if (rename->FileNameLength == 0) {
225  /* start from state->path instead of args->path, in case we got
226  * the file from a referred server */
227  AcquireSRWLockShared(&state->path.lock);
228  abs_path_copy(&dst_path, &state->path);
229  ReleaseSRWLockShared(&state->path.lock);
230 
231  path_fh_init(&dst_dir, &dst_path);
232  fh_copy(&dst_dir.fh, &state->parent.fh);
233 
234  create_silly_rename(&dst_path, &state->file.fh, &dst_name);
235  dprintf(1, "silly rename: %s -> %s\n", src_name->name, dst_name.name);
236 
237  /* break any delegations and truncate before silly rename */
238  nfs41_delegation_return(state->session, &state->file,
240 
241  status = nfs41_rename(state->session,
242  &state->parent, src_name,
243  &dst_dir, &dst_name);
244  if (status) {
245  dprintf(1, "nfs41_rename() failed with error %s.\n",
248  } else {
249  /* rename state->path on success */
250  open_state_rename(state, &dst_path);
251  }
252  goto out;
253  }
254 
255  dst_path.len = (unsigned short)WideCharToMultiByte(CP_UTF8, 0,
256  rename->FileName, rename->FileNameLength/sizeof(WCHAR),
257  dst_path.path, NFS41_MAX_PATH_LEN, NULL, NULL);
258  if (dst_path.len == 0) {
259  eprintf("WideCharToMultiByte failed to convert destination "
260  "filename %S.\n", rename->FileName);
262  goto out;
263  }
264  path_fh_init(&dst_dir, &dst_path);
265 
266  /* the destination path is absolute, so start from the root session */
268  &dst_path, &dst_dir, &dst, NULL, &dst_session);
269 
270  while (status == ERROR_REPARSE) {
271  if (++depth > NFS41_MAX_SYMLINK_DEPTH) {
273  goto out;
274  }
275 
276  /* replace the path with the symlink target's */
277  status = nfs41_symlink_target(dst_session, &dst_dir, &dst_path);
278  if (status) {
279  eprintf("nfs41_symlink_target() for %s failed with %d\n",
280  dst_dir.path->path, status);
281  goto out;
282  }
283 
284  /* redo the lookup until it doesn't return REPARSE */
285  status = nfs41_lookup(args->root, dst_session,
286  &dst_path, &dst_dir, NULL, NULL, &dst_session);
287  }
288 
289  /* get the components after lookup in case a referral changed its path */
290  last_component(dst_path.path, dst_path.path + dst_path.len, &dst_name);
291  last_component(dst_path.path, dst_name.name, &dst_dir.name);
292 
293  if (status == NO_ERROR) {
294  if (!rename->ReplaceIfExists) {
296  goto out;
297  }
298  /* break any delegations and truncate the destination file */
299  nfs41_delegation_return(dst_session, &dst,
301  } else if (status != ERROR_FILE_NOT_FOUND) {
302  dprintf(1, "nfs41_lookup('%s') failed to find destination "
303  "directory with %d\n", dst_path.path, status);
304  goto out;
305  }
306 
307  /* http://tools.ietf.org/html/rfc5661#section-18.26.3
308  * "Source and target directories MUST reside on the same
309  * file system on the server." */
310  if (state->parent.fh.superblock != dst_dir.fh.superblock) {
312  goto out;
313  }
314 
315  status = is_dst_name_opened(&dst_path, dst_session);
316  if (status) {
317  /* AGLO: 03/21/2011: we can't handle rename of a file with a filename
318  * that is currently opened by this client
319  */
320  eprintf("handle_nfs41_rename: %s is opened\n", dst_path.path);
322  goto out;
323  }
324 
325  /* break any delegations on the source file */
326  nfs41_delegation_return(state->session, &state->file,
328 
329  status = nfs41_rename(state->session,
330  &state->parent, src_name,
331  &dst_dir, &dst_name);
332  if (status) {
333  dprintf(1, "nfs41_rename() failed with error %s.\n",
336  } else {
337  /* rename state->path on success */
338  open_state_rename(state, &dst_path);
339  }
340 out:
341  return status;
342 }
#define ERROR_INVALID_PARAMETER
Definition: compat.h:91
#define ERROR_FILE_EXISTS
Definition: winerror.h:165
int nfs_to_windows_error(int status, int default_error)
Definition: util.c:235
int nfs41_symlink_target(IN nfs41_session *session, IN nfs41_path_fh *file, OUT nfs41_abs_path *target)
Definition: symlink.c:92
#define TRUE
Definition: types.h:120
#define WideCharToMultiByte
Definition: compat.h:101
struct __nfs41_superblock * superblock
Definition: nfs41_types.h:56
unsigned char * buf
Definition: upcall.h:106
__wchar_t WCHAR
Definition: xmlstorage.h:180
int nfs41_lookup(IN nfs41_root *root, IN nfs41_session *session, IN OUT nfs41_abs_path *path_inout, OUT OPTIONAL nfs41_path_fh *parent_out, OUT OPTIONAL nfs41_path_fh *target_out, OUT OPTIONAL nfs41_file_info *info_out, OUT nfs41_session **session_out)
Definition: lookup.c:424
void eprintf(LPCSTR format,...)
Definition: daemon_debug.c:86
#define NO_ERROR
Definition: dderror.h:5
int nfs41_rename(IN nfs41_session *session, IN nfs41_path_fh *src_dir, IN const nfs41_component *src_name, IN nfs41_path_fh *dst_dir, IN const nfs41_component *dst_name)
Definition: nfs41_ops.c:1247
nfs41_root * root
Definition: upcall.h:104
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
void abs_path_copy(OUT nfs41_abs_path *dst, IN const nfs41_abs_path *src)
Definition: util.c:338
unsigned short(__cdecl typeof(TIFFCurrentDirectory))(struct tiff *)
Definition: typeof.h:91
_Check_return_ int __cdecl rename(_In_z_ const char *_OldFilename, _In_z_ const char *_NewFilename)
#define CP_UTF8
Definition: nls.h:20
#define ERROR_ACCESS_DENIED
Definition: compat.h:87
static void open_state_rename(OUT nfs41_open_state *state, IN const nfs41_abs_path *path)
Definition: setattr.c:170
#define dprintf
Definition: regdump.c:33
smooth NULL
Definition: ftsmooth.c:416
void path_fh_init(OUT nfs41_path_fh *file, IN nfs41_abs_path *path)
Definition: util.c:346
#define ERROR_FILE_NOT_FOUND
Definition: disk.h:79
nfs41_abs_path * path
Definition: nfs41_types.h:60
const char * name
Definition: nfs41_types.h:48
int nfs41_delegation_return(IN nfs41_session *session, IN nfs41_path_fh *file, IN enum open_delegation_type4 access, IN bool_t truncate)
Definition: delegation.c:629
static FILE * out
Definition: regtests2xml.c:44
static int is_dst_name_opened(nfs41_abs_path *dst_path, nfs41_session *dst_session)
Definition: setattr.c:197
const char * nfs_error_string(int status)
Definition: daemon_debug.c:370
static __inline nfs41_session * nfs41_root_session(IN nfs41_root *root)
Definition: nfs41.h:321
int create_silly_rename(IN nfs41_abs_path *path, IN const nfs41_fh *fh, OUT nfs41_component *silly)
Definition: util.c:380
void fh_copy(OUT nfs41_fh *dst, IN const nfs41_fh *src)
Definition: util.c:354
GLint GLint GLsizei GLsizei GLsizei depth
Definition: gl.h:1546
#define ERROR_TOO_MANY_LINKS
Definition: winerror.h:671
static int state
Definition: maze.c:121
#define ERROR_REPARSE
Definition: winerror.h:522
nfs41_component name
Definition: nfs41_types.h:61
nfs41_open_state * state
Definition: upcall.h:105
GLuint const GLubyte GLvoid const GLvoid * dst
Definition: s_context.h:57
UINT32 uint32_t
Definition: types.h:75
#define NFS41_MAX_SYMLINK_DEPTH
Definition: nfs41_const.h:60
#define ERROR_NOT_SAME_DEVICE
Definition: winerror.h:120
char path[NFS41_MAX_PATH_LEN]
Definition: nfs41_types.h:42
static SERVICE_STATUS status
Definition: service.c:31
VOID WINAPI AcquireSRWLockShared(PSRWLOCK Lock)
Definition: sync.c:61
VOID WINAPI ReleaseSRWLockShared(PSRWLOCK Lock)
Definition: sync.c:89
Definition: ps.c:97

◆ handle_nfs41_set_size()

static int handle_nfs41_set_size ( setattr_upcall_args args)
static

Definition at line 344 of file setattr.c.

Referenced by handle_setattr().

345 {
346  nfs41_file_info info = { 0 };
347  stateid_arg stateid;
348  /* note: this is called with either FILE_END_OF_FILE_INFO or
349  * FILE_ALLOCATION_INFO, both of which contain a single LARGE_INTEGER */
351  nfs41_open_state *state = args->state;
352  int status;
353 
354  /* break read delegations before SETATTR */
355  nfs41_delegation_return(state->session, &state->file,
357 
358  nfs41_open_stateid_arg(state, &stateid);
359 
360  info.size = size->QuadPart;
361  info.attrmask.count = 1;
362  info.attrmask.arr[0] = FATTR4_WORD0_SIZE;
363 
364  dprintf(2, "calling setattr() with size=%lld\n", info.size);
365  status = nfs41_setattr(state->session, &state->file, &stateid, &info);
366  if (status) {
367  dprintf(1, "nfs41_setattr() failed with error %s.\n",
369  goto out;
370  }
371 
372  /* update the last offset for LAYOUTCOMMIT */
374  state->pnfs_last_offset = info.size ? info.size - 1 : 0;
376  args->ctime = info.change;
377 out:
379 }
VOID WINAPI AcquireSRWLockExclusive(PSRWLOCK Lock)
Definition: sync.c:54
int nfs_to_windows_error(int status, int default_error)
Definition: util.c:235
int nfs41_setattr(IN nfs41_session *session, IN nfs41_path_fh *file, IN stateid_arg *stateid, IN nfs41_file_info *info)
Definition: nfs41_ops.c:1351
unsigned char * buf
Definition: upcall.h:106
uint32_t arr[3]
Definition: nfs41_types.h:97
#define dprintf
Definition: regdump.c:33
uint32_t count
Definition: nfs41_types.h:96
void nfs41_open_stateid_arg(IN nfs41_open_state *state, OUT struct __stateid_arg *arg)
GLsizeiptr size
Definition: glext.h:5919
int nfs41_delegation_return(IN nfs41_session *session, IN nfs41_path_fh *file, IN enum open_delegation_type4 access, IN bool_t truncate)
Definition: delegation.c:629
static FILE * out
Definition: regtests2xml.c:44
const char * nfs_error_string(int status)
Definition: daemon_debug.c:370
static int state
Definition: maze.c:121
VOID WINAPI ReleaseSRWLockExclusive(PSRWLOCK Lock)
Definition: sync.c:82
ULONGLONG ctime
Definition: upcall.h:109
nfs41_open_state * state
Definition: upcall.h:105
#define ERROR_NOT_SUPPORTED
Definition: compat.h:90
union _LARGE_INTEGER * PLARGE_INTEGER
Definition: file.c:85
LONGLONG QuadPart
Definition: typedefs.h:112
Definition: ps.c:97

◆ handle_nfs41_setattr()

static int handle_nfs41_setattr ( setattr_upcall_args args)
static

Definition at line 58 of file setattr.c.

Referenced by handle_setattr().

59 {
60  PFILE_BASIC_INFO basic_info = (PFILE_BASIC_INFO)args->buf;
61  nfs41_open_state *state = args->state;
62  nfs41_superblock *superblock = state->file.fh.superblock;
63  stateid_arg stateid;
64  nfs41_file_info info = { 0 }, old_info = { 0 };
65  int status = NO_ERROR, getattr_status;
66 
67  if (basic_info->FileAttributes) {
68  info.hidden = basic_info->FileAttributes & FILE_ATTRIBUTE_HIDDEN ? 1 : 0;
69  info.system = basic_info->FileAttributes & FILE_ATTRIBUTE_SYSTEM ? 1 : 0;
70  info.archive = basic_info->FileAttributes & FILE_ATTRIBUTE_ARCHIVE ? 1 : 0;
71  getattr_status = nfs41_attr_cache_lookup(session_name_cache(state->session),
72  state->file.fh.fileid, &old_info);
73 
74  if (getattr_status || info.hidden != old_info.hidden) {
75  info.attrmask.arr[0] = FATTR4_WORD0_HIDDEN;
76  info.attrmask.count = 1;
77  }
78  if (getattr_status || info.archive != old_info.archive) {
79  info.attrmask.arr[0] |= FATTR4_WORD0_ARCHIVE;
80  info.attrmask.count = 1;
81  }
82  if (getattr_status || info.system != old_info.system) {
83  info.attrmask.arr[1] = FATTR4_WORD1_SYSTEM;
84  info.attrmask.count = 2;
85  }
86  }
87  if (old_info.mode == 0444 &&
88  ((basic_info->FileAttributes & FILE_ATTRIBUTE_READONLY) == 0)) {
89  info.mode = 0644;
90  info.attrmask.arr[1] |= FATTR4_WORD1_MODE;
91  info.attrmask.count = 2;
92  }
93 
94  if (superblock->cansettime) {
95  /* set the time_delta so xdr_settime4() can decide
96  * whether or not to use SET_TO_SERVER_TIME4 */
97  info.time_delta = &superblock->time_delta;
98 
99  /* time_create */
100  if (basic_info->CreationTime.QuadPart > 0) {
101  file_time_to_nfs_time(&basic_info->CreationTime,
102  &info.time_create);
103  info.attrmask.arr[1] |= FATTR4_WORD1_TIME_CREATE;
104  info.attrmask.count = 2;
105  }
106  /* time_access_set */
107  if (basic_info->LastAccessTime.QuadPart > 0) {
108  file_time_to_nfs_time(&basic_info->LastAccessTime,
109  &info.time_access);
110  info.attrmask.arr[1] |= FATTR4_WORD1_TIME_ACCESS_SET;
111  info.attrmask.count = 2;
112  }
113  /* time_modify_set */
114  if (basic_info->LastWriteTime.QuadPart > 0) {
115  file_time_to_nfs_time(&basic_info->LastWriteTime,
116  &info.time_modify);
117  info.attrmask.arr[1] |= FATTR4_WORD1_TIME_MODIFY_SET;
118  info.attrmask.count = 2;
119  }
120  }
121 
122  /* mode */
123  if (basic_info->FileAttributes & FILE_ATTRIBUTE_READONLY) {
124  info.mode = 0444;
125  info.attrmask.arr[1] |= FATTR4_WORD1_MODE;
126  info.attrmask.count = 2;
127  }
128 
129  /* mask out unsupported attributes */
131 
132  if (!info.attrmask.count)
133  goto out;
134 
135  /* break read delegations before SETATTR */
136  nfs41_delegation_return(state->session, &state->file,
138 
139  nfs41_open_stateid_arg(state, &stateid);
140 
141  status = nfs41_setattr(state->session, &state->file, &stateid, &info);
142  if (status) {
143  dprintf(1, "nfs41_setattr() failed with error %s.\n",
146  }
147  args->ctime = info.change;
148 out:
149  return status;
150 }
int nfs_to_windows_error(int status, int default_error)
Definition: util.c:235
int nfs41_setattr(IN nfs41_session *session, IN nfs41_path_fh *file, IN stateid_arg *stateid, IN nfs41_file_info *info)
Definition: nfs41_ops.c:1351
unsigned char * buf
Definition: upcall.h:106
#define FILE_ATTRIBUTE_SYSTEM
Definition: nt_native.h:704
#define NO_ERROR
Definition: dderror.h:5
unsigned int count
Definition: notification.c:64
static __inline struct nfs41_name_cache * session_name_cache(IN nfs41_session *session)
Definition: name_cache.h:34
#define dprintf
Definition: regdump.c:33
void nfs41_open_stateid_arg(IN nfs41_open_state *state, OUT struct __stateid_arg *arg)
static __inline void nfs41_superblock_supported_attrs(IN const nfs41_superblock *superblock, IN OUT bitmap4 *attrs)
Definition: nfs41.h:454
int nfs41_delegation_return(IN nfs41_session *session, IN nfs41_path_fh *file, IN enum open_delegation_type4 access, IN bool_t truncate)
Definition: delegation.c:629
#define FILE_ATTRIBUTE_READONLY
Definition: nt_native.h:702
static FILE * out
Definition: regtests2xml.c:44
const char * nfs_error_string(int status)
Definition: daemon_debug.c:370
#define FILE_ATTRIBUTE_ARCHIVE
Definition: nt_native.h:706
static int state
Definition: maze.c:121
ULONGLONG ctime
Definition: upcall.h:109
#define FILE_ATTRIBUTE_HIDDEN
Definition: nt_native.h:703
nfs41_open_state * state
Definition: upcall.h:105
#define ERROR_NOT_SUPPORTED
Definition: compat.h:90
void file_time_to_nfs_time(IN const PLARGE_INTEGER file_time, OUT LONGLONG *nfs_time)
int nfs41_attr_cache_lookup(IN struct nfs41_name_cache *cache, IN uint64_t fileid, OUT nfs41_file_info *info_out)
Definition: name_cache.c:859
static SERVICE_STATUS status
Definition: service.c:31
Definition: ps.c:97

◆ handle_setattr()

static int handle_setattr ( nfs41_upcall upcall)
static

Definition at line 483 of file setattr.c.

484 {
485  setattr_upcall_args *args = &upcall->args.setattr;
486  int status;
487 
488  switch (args->set_class) {
490  status = handle_nfs41_setattr(args);
491  break;
493  status = handle_nfs41_remove(args);
494  break;
496  status = handle_nfs41_rename(args);
497  break;
500  status = handle_nfs41_set_size(args);
501  break;
502  case FileLinkInformation:
503  status = handle_nfs41_link(args);
504  break;
505  default:
506  eprintf("unknown set_file information class %d\n",
507  args->set_class);
508  status = ERROR_NOT_SUPPORTED;
509  break;
510  }
511 
512  return status;
513 }
setattr_upcall_args setattr
Definition: upcall.h:184
void eprintf(LPCSTR format,...)
Definition: daemon_debug.c:86
Definition: match.c:390
static int handle_nfs41_link(setattr_upcall_args *args)
Definition: setattr.c:381
static int handle_nfs41_setattr(setattr_upcall_args *args)
Definition: setattr.c:58
upcall_args args
Definition: upcall.h:198
static int handle_nfs41_rename(setattr_upcall_args *args)
Definition: setattr.c:211
static int handle_nfs41_remove(setattr_upcall_args *args)
Definition: setattr.c:152
static int handle_nfs41_set_size(setattr_upcall_args *args)
Definition: setattr.c:344
#define ERROR_NOT_SUPPORTED
Definition: compat.h:90
static SERVICE_STATUS status
Definition: service.c:31

◆ is_dst_name_opened()

static int is_dst_name_opened ( nfs41_abs_path dst_path,
nfs41_session dst_session 
)
static

Definition at line 197 of file setattr.c.

198 {
199  int status;
200  nfs41_client *client = dst_session->client;
201 
202  EnterCriticalSection(&client->state.lock);
203  if (list_search(&client->state.opens, dst_path, nfs41_abs_path_compare))
204  status = TRUE;
205  else
206  status = FALSE;
207  LeaveCriticalSection(&client->state.lock);
208 
209  return status;
210 }
#define TRUE
Definition: types.h:120
void WINAPI EnterCriticalSection(LPCRITICAL_SECTION)
nfs41_client * client
Definition: nfs41.h:256
static int nfs41_abs_path_compare(IN const struct list_entry *entry, IN const void *value)
Definition: setattr.c:185
static FILE * client
Definition: client.c:41
struct client_state state
Definition: nfs41.h:215
static struct list_entry * list_search(const struct list_entry *head, const void *value, list_compare_fn compare)
Definition: list.h:102
void WINAPI LeaveCriticalSection(LPCRITICAL_SECTION)
static SERVICE_STATUS status
Definition: service.c:31

◆ marshall_setattr()

static int marshall_setattr ( unsigned char buffer,
uint32_t length,
nfs41_upcall upcall 
)
static

Definition at line 515 of file setattr.c.

516 {
517  setattr_upcall_args *args = &upcall->args.setattr;
518  return safe_write(&buffer, length, &args->ctime, sizeof(args->ctime));
519 }
setattr_upcall_args setattr
Definition: upcall.h:184
GLuint buffer
Definition: glext.h:5915
Definition: match.c:390
upcall_args args
Definition: upcall.h:198
GLenum GLuint GLenum GLsizei length
Definition: glext.h:5579
int safe_write(unsigned char **pos, uint32_t *remaining, void *src, uint32_t src_len)
Definition: util.c:44
ULONGLONG ctime
Definition: upcall.h:109

◆ nfs41_abs_path_compare()

static int nfs41_abs_path_compare ( IN const struct list_entry entry,
IN const void value 
)
static

Definition at line 185 of file setattr.c.

Referenced by is_dst_name_opened().

188 {
190  const nfs41_abs_path *name = (const nfs41_abs_path *)value;
191  if (client->path.len == name->len &&
192  !strncmp(client->path.path, name->path, client->path.len))
193  return NO_ERROR;
194  return ERROR_FILE_NOT_FOUND;
195 }
Definition: get.c:139
uint8_t entry
Definition: isohybrid.c:63
#define NO_ERROR
Definition: dderror.h:5
#define list_container(entry, type, field)
Definition: list.h:33
#define client_entry(pos)
Definition: namespace.c:33
#define ERROR_FILE_NOT_FOUND
Definition: disk.h:79
unsigned short len
Definition: nfs41_types.h:43
int strncmp(const char *String1, const char *String2, ACPI_SIZE Count)
Definition: utclib.c:534
static FILE * client
Definition: client.c:41
Definition: name.c:36
char path[NFS41_MAX_PATH_LEN]
Definition: nfs41_types.h:42
nfs41_abs_path path
Definition: nfs41.h:128

◆ open_state_rename()

static void open_state_rename ( OUT nfs41_open_state state,
IN const nfs41_abs_path path 
)
static

Definition at line 170 of file setattr.c.

173 {
174  AcquireSRWLockExclusive(&state->path.lock);
175 
176  abs_path_copy(&state->path, path);
177  last_component(state->path.path, state->path.path + state->path.len,
178  &state->file.name);
179  last_component(state->path.path, state->file.name.name,
180  &state->parent.name);
181 
182  ReleaseSRWLockExclusive(&state->path.lock);
183 }
VOID WINAPI AcquireSRWLockExclusive(PSRWLOCK Lock)
Definition: sync.c:54
bool_t last_component(IN const char *path, IN const char *path_end, OUT nfs41_component *component)
Definition: util.c:317
void abs_path_copy(OUT nfs41_abs_path *dst, IN const nfs41_abs_path *src)
Definition: util.c:338
static int state
Definition: maze.c:121
VOID WINAPI ReleaseSRWLockExclusive(PSRWLOCK Lock)
Definition: sync.c:82
Definition: services.c:325

◆ parse_setattr()

static int parse_setattr ( unsigned char buffer,
uint32_t  length,
nfs41_upcall upcall 
)
static

Definition at line 36 of file setattr.c.

37 {
38  int status;
40 
41  status = get_name(&buffer, &length, &args->path);
42  if (status) goto out;
43  status = safe_read(&buffer, &length, &args->set_class, sizeof(args->set_class));
44  if (status) goto out;
45  status = safe_read(&buffer, &length, &args->buf_len, sizeof(args->buf_len));
46  if (status) goto out;
47 
48  args->buf = buffer;
49  args->root = upcall->root_ref;
50  args->state = upcall->state_ref;
51 
52  dprintf(1, "parsing NFS41_FILE_SET: filename='%s' info_class=%d "
53  "buf_len=%d\n", args->path, args->set_class, args->buf_len);
54 out:
55  return status;
56 }
setattr_upcall_args setattr
Definition: upcall.h:184
unsigned char * buf
Definition: upcall.h:106
uint32_t buf_len
Definition: upcall.h:107
GLuint buffer
Definition: glext.h:5915
Definition: match.c:390
nfs41_root * root
Definition: upcall.h:104
nfs41_root * root_ref
Definition: upcall.h:206
nfs41_open_state * state_ref
Definition: upcall.h:207
#define dprintf
Definition: regdump.c:33
int get_name(unsigned char **pos, uint32_t *remaining, const char **out_name)
Definition: util.c:55
upcall_args args
Definition: upcall.h:198
GLenum GLuint GLenum GLsizei length
Definition: glext.h:5579
static FILE * out
Definition: regtests2xml.c:44
const char * path
Definition: upcall.h:103
nfs41_open_state * state
Definition: upcall.h:105
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

Variable Documentation

◆ nfs41_op_setattr

const nfs41_upcall_op nfs41_op_setattr
Initial value:
= {
}
static int handle_setattr(nfs41_upcall *upcall)
Definition: setattr.c:483
static int parse_setattr(unsigned char *buffer, uint32_t length, nfs41_upcall *upcall)
Definition: setattr.c:36
static int marshall_setattr(unsigned char *buffer, uint32_t *length, nfs41_upcall *upcall)
Definition: setattr.c:515

Definition at line 522 of file setattr.c.