ReactOS  0.4.11-dev-946-g431643b
upcall.c File Reference
#include <windows.h>
#include <stdio.h>
#include <time.h>
#include "upcall.h"
#include "daemon_debug.h"
#include "util.h"
Include dependency graph for upcall.c:

Go to the source code of this file.

Functions

int upcall_parse (IN unsigned char *buffer, IN uint32_t length, OUT nfs41_upcall *upcall)
 
int upcall_handle (IN nfs41_upcall *upcall)
 
void upcall_marshall (IN nfs41_upcall *upcall, OUT unsigned char *buffer, IN uint32_t length, OUT uint32_t *length_out)
 
void upcall_cancel (IN nfs41_upcall *upcall)
 
void upcall_cleanup (IN nfs41_upcall *upcall)
 

Variables

const nfs41_upcall_op nfs41_op_mount
 
const nfs41_upcall_op nfs41_op_unmount
 
const nfs41_upcall_op nfs41_op_open
 
const nfs41_upcall_op nfs41_op_close
 
const nfs41_upcall_op nfs41_op_read
 
const nfs41_upcall_op nfs41_op_write
 
const nfs41_upcall_op nfs41_op_lock
 
const nfs41_upcall_op nfs41_op_unlock
 
const nfs41_upcall_op nfs41_op_readdir
 
const nfs41_upcall_op nfs41_op_getattr
 
const nfs41_upcall_op nfs41_op_setattr
 
const nfs41_upcall_op nfs41_op_getexattr
 
const nfs41_upcall_op nfs41_op_setexattr
 
const nfs41_upcall_op nfs41_op_symlink
 
const nfs41_upcall_op nfs41_op_volume
 
const nfs41_upcall_op nfs41_op_getacl
 
const nfs41_upcall_op nfs41_op_setacl
 
static const nfs41_upcall_opg_upcall_op_table []
 
static const uint32_t g_upcall_op_table_size = ARRAYSIZE(g_upcall_op_table)
 

Function Documentation

◆ upcall_cancel()

void upcall_cancel ( IN nfs41_upcall upcall)

Definition at line 189 of file upcall.c.

Referenced by thread_main().

191 {
192  const nfs41_upcall_op *op = g_upcall_op_table[upcall->opcode];
193  if (op && op->cancel)
194  op->cancel(upcall);
195 }
upcall_cancel_proc cancel
Definition: upcall.h:222
UINT op
Definition: effect.c:223
static const nfs41_upcall_op * g_upcall_op_table[]
Definition: upcall.c:48
nfs41_updowncall_list upcall
Definition: nfs41_driver.c:273

◆ upcall_cleanup()

void upcall_cleanup ( IN nfs41_upcall upcall)

Definition at line 197 of file upcall.c.

Referenced by thread_main().

199 {
200  const nfs41_upcall_op *op = g_upcall_op_table[upcall->opcode];
201  if (op && op->cleanup && upcall->status != NFSD_VERSION_MISMATCH)
202  op->cleanup(upcall);
203 
204  if (upcall->state_ref && upcall->state_ref != INVALID_HANDLE_VALUE) {
205  nfs41_open_state_deref(upcall->state_ref);
206  upcall->state_ref = NULL;
207  }
208  if (upcall->root_ref && upcall->root_ref != INVALID_HANDLE_VALUE) {
209  nfs41_root_deref(upcall->root_ref);
210  upcall->root_ref = NULL;
211  }
212 }
void nfs41_open_state_deref(IN nfs41_open_state *state)
Definition: open.c:104
#define INVALID_HANDLE_VALUE
Definition: compat.h:391
UINT op
Definition: effect.c:223
#define NFSD_VERSION_MISMATCH
Definition: upcall.h:28
smooth NULL
Definition: ftsmooth.c:416
static const nfs41_upcall_op * g_upcall_op_table[]
Definition: upcall.c:48
nfs41_updowncall_list upcall
Definition: nfs41_driver.c:273
void nfs41_root_deref(IN nfs41_root *root)
Definition: namespace.c:100
upcall_cleanup_proc cleanup
Definition: upcall.h:223

◆ upcall_handle()

int upcall_handle ( IN nfs41_upcall upcall)

Definition at line 138 of file upcall.c.

Referenced by thread_main().

140 {
141  int status = NO_ERROR;
142  const nfs41_upcall_op *op;
143 
144  op = g_upcall_op_table[upcall->opcode];
145  if (op == NULL || op->handle == NULL) {
146  status = ERROR_NOT_SUPPORTED;
147  eprintf("upcall '%s' missing handle function!\n",
148  opcode2string(upcall->opcode));
149  goto out;
150  }
151 
152  upcall->status = op->handle(upcall);
153 out:
154  return status;
155 }
void eprintf(LPCSTR format,...)
Definition: daemon_debug.c:86
#define NO_ERROR
Definition: dderror.h:5
UINT op
Definition: effect.c:223
smooth NULL
Definition: ftsmooth.c:416
static FILE * out
Definition: regtests2xml.c:44
upcall_handle_proc handle
Definition: upcall.h:220
static const nfs41_upcall_op * g_upcall_op_table[]
Definition: upcall.c:48
const char * opcode2string(DWORD opcode)
Definition: daemon_debug.c:280
nfs41_updowncall_list upcall
Definition: nfs41_driver.c:273
#define ERROR_NOT_SUPPORTED
Definition: compat.h:90
static SERVICE_STATUS status
Definition: service.c:31
Definition: ps.c:97

◆ upcall_marshall()

void upcall_marshall ( IN nfs41_upcall upcall,
OUT unsigned char buffer,
IN uint32_t  length,
OUT uint32_t length_out 
)

Definition at line 157 of file upcall.c.

Referenced by thread_main().

162 {
163  const nfs41_upcall_op *op;
164  unsigned char *orig_buf = buffer;
165  const uint32_t total = length, orig_len = length;
166 
167  /* marshall common elements */
168 write_downcall:
169  length = orig_len;
170  buffer = orig_buf;
171  safe_write(&buffer, &length, &upcall->xid, sizeof(upcall->xid));
172  safe_write(&buffer, &length, &upcall->opcode, sizeof(upcall->opcode));
173  safe_write(&buffer, &length, &upcall->status, sizeof(upcall->status));
174  safe_write(&buffer, &length, &upcall->last_error, sizeof(upcall->last_error));
175 
176  if (upcall->status)
177  goto out;
178 
179  /* marshall the operation's results */
180  op = g_upcall_op_table[upcall->opcode];
181  if (op && op->marshall) {
182  if ((upcall->status = op->marshall(buffer, &length, upcall)))
183  goto write_downcall;
184  }
185 out:
186  *length_out = total - length;
187 }
GLuint buffer
Definition: glext.h:5915
UINT op
Definition: effect.c:223
upcall_marshall_proc marshall
Definition: upcall.h:221
GLenum GLuint GLenum GLsizei length
Definition: glext.h:5579
static FILE * out
Definition: regtests2xml.c:44
int safe_write(unsigned char **pos, uint32_t *remaining, void *src, uint32_t src_len)
Definition: util.c:44
static const nfs41_upcall_op * g_upcall_op_table[]
Definition: upcall.c:48
UINT32 uint32_t
Definition: types.h:75
nfs41_updowncall_list upcall
Definition: nfs41_driver.c:273

◆ upcall_parse()

int upcall_parse ( IN unsigned char buffer,
IN uint32_t  length,
OUT nfs41_upcall upcall 
)

Definition at line 75 of file upcall.c.

Referenced by thread_main().

79 {
80  int status;
81  const nfs41_upcall_op *op;
82  DWORD version;
83 
84  ZeroMemory(upcall, sizeof(nfs41_upcall));
85  if (!length) {
86  eprintf("empty upcall\n");
87  upcall->status = status = 102;
88  goto out;
89  }
90 
91  dprintf(2, "received %d bytes upcall data: processing upcall\n", length);
92  print_hexbuf(4, (unsigned char *)"upcall buffer: ", buffer, length);
93 
94  /* parse common elements */
95  status = safe_read(&buffer, &length, &version, sizeof(uint32_t));
96  if (status) goto out;
97  status = safe_read(&buffer, &length, &upcall->xid, sizeof(uint64_t));
98  if (status) goto out;
99  status = safe_read(&buffer, &length, &upcall->opcode, sizeof(uint32_t));
100  if (status) goto out;
101  status = safe_read(&buffer, &length, &upcall->root_ref, sizeof(HANDLE));
102  if (status) goto out;
103  status = safe_read(&buffer, &length, &upcall->state_ref, sizeof(HANDLE));
104  if (status) goto out;
105 
106  dprintf(2, "time=%ld version=%d xid=%d opcode=%s session=0x%x open_state=0x%x\n",
107  time(NULL), version, upcall->xid, opcode2string(upcall->opcode), upcall->root_ref,
108  upcall->state_ref);
109  if (version != NFS41D_VERSION) {
110  eprintf("received version %d expecting version %d\n", version, NFS41D_VERSION);
111  upcall->status = status = NFSD_VERSION_MISMATCH;
112  goto out;
113  }
114  if (upcall->opcode >= g_upcall_op_table_size) {
115  status = ERROR_NOT_SUPPORTED;
116  eprintf("unrecognized upcall opcode %d!\n", upcall->opcode);
117  goto out;
118  }
119  if (upcall->root_ref != INVALID_HANDLE_VALUE)
120  nfs41_root_ref(upcall->root_ref);
121  if (upcall->state_ref != INVALID_HANDLE_VALUE)
122  nfs41_open_state_ref(upcall->state_ref);
123 
124  /* parse the operation's arguments */
125  op = g_upcall_op_table[upcall->opcode];
126  if (op && op->parse) {
127  status = op->parse(buffer, length, upcall);
128  if (status) {
129  eprintf("parsing of upcall '%s' failed with %d.\n",
130  opcode2string(upcall->opcode), status);
131  goto out;
132  }
133  }
134 out:
135  return status;
136 }
void nfs41_open_state_ref(IN nfs41_open_state *state)
Definition: open.c:96
#define INVALID_HANDLE_VALUE
Definition: compat.h:391
#define ZeroMemory
Definition: winbase.h:1635
GLuint buffer
Definition: glext.h:5915
void eprintf(LPCSTR format,...)
Definition: daemon_debug.c:86
__u16 time
Definition: mkdosfs.c:366
UINT op
Definition: effect.c:223
#define dprintf
Definition: regdump.c:33
#define NFSD_VERSION_MISMATCH
Definition: upcall.h:28
DWORD NFS41D_VERSION
Definition: nfs41_daemon.c:42
smooth NULL
Definition: ftsmooth.c:416
static const WCHAR version[]
Definition: asmname.c:64
void nfs41_root_ref(IN nfs41_root *root)
Definition: namespace.c:92
static const uint32_t g_upcall_op_table_size
Definition: upcall.c:72
GLenum GLuint GLenum GLsizei length
Definition: glext.h:5579
static FILE * out
Definition: regtests2xml.c:44
unsigned long DWORD
Definition: ntddk_ex.h:95
static const nfs41_upcall_op * g_upcall_op_table[]
Definition: upcall.c:48
UINT64 uint64_t
Definition: types.h:77
UINT32 uint32_t
Definition: types.h:75
const char * opcode2string(DWORD opcode)
Definition: daemon_debug.c:280
nfs41_updowncall_list upcall
Definition: nfs41_driver.c:273
#define ERROR_NOT_SUPPORTED
Definition: compat.h:90
int safe_read(unsigned char **pos, uint32_t *remaining, void *dest, uint32_t dest_len)
Definition: util.c:33
void print_hexbuf(int level, unsigned char *title, unsigned char *buf, int len)
Definition: daemon_debug.c:98
static SERVICE_STATUS status
Definition: service.c:31
upcall_parse_proc parse
Definition: upcall.h:219

Variable Documentation

◆ g_upcall_op_table

const nfs41_upcall_op* g_upcall_op_table[]
static
Initial value:
= {
NULL
}
const nfs41_upcall_op nfs41_op_lock
Definition: lock.c:360
const nfs41_upcall_op nfs41_op_getattr
Definition: getattr.c:180
const nfs41_upcall_op nfs41_op_volume
Definition: volume.c:172
const nfs41_upcall_op nfs41_op_getexattr
Definition: ea.c:689
const nfs41_upcall_op nfs41_op_open
Definition: open.c:936
const nfs41_upcall_op nfs41_op_getacl
Definition: acl.c:420
smooth NULL
Definition: ftsmooth.c:416
const nfs41_upcall_op nfs41_op_setexattr
Definition: ea.c:683
const nfs41_upcall_op nfs41_op_unmount
Definition: mount.c:173
const nfs41_upcall_op nfs41_op_close
Definition: open.c:942
const nfs41_upcall_op nfs41_op_readdir
Definition: readdir.c:645
const nfs41_upcall_op nfs41_op_mount
Definition: mount.c:151
const nfs41_upcall_op nfs41_op_symlink
Definition: symlink.c:295
const nfs41_upcall_op nfs41_op_read
Definition: readwrite.c:316
const nfs41_upcall_op nfs41_op_setattr
Definition: setattr.c:522
const nfs41_upcall_op nfs41_op_unlock
Definition: lock.c:366
const nfs41_upcall_op nfs41_op_setacl
Definition: acl.c:797
const nfs41_upcall_op nfs41_op_write
Definition: readwrite.c:321

Definition at line 48 of file upcall.c.

◆ g_upcall_op_table_size

const uint32_t g_upcall_op_table_size = ARRAYSIZE(g_upcall_op_table)
static

Definition at line 72 of file upcall.c.

Referenced by upcall_parse().

◆ nfs41_op_close

const nfs41_upcall_op nfs41_op_close

Definition at line 942 of file open.c.

◆ nfs41_op_getacl

const nfs41_upcall_op nfs41_op_getacl

Definition at line 420 of file acl.c.

◆ nfs41_op_getattr

const nfs41_upcall_op nfs41_op_getattr

Definition at line 180 of file getattr.c.

◆ nfs41_op_getexattr

const nfs41_upcall_op nfs41_op_getexattr

Definition at line 689 of file ea.c.

◆ nfs41_op_lock

const nfs41_upcall_op nfs41_op_lock

Definition at line 360 of file lock.c.

◆ nfs41_op_mount

const nfs41_upcall_op nfs41_op_mount

Definition at line 151 of file mount.c.

◆ nfs41_op_open

const nfs41_upcall_op nfs41_op_open

Definition at line 936 of file open.c.

◆ nfs41_op_read

const nfs41_upcall_op nfs41_op_read

Definition at line 316 of file readwrite.c.

◆ nfs41_op_readdir

const nfs41_upcall_op nfs41_op_readdir

Definition at line 645 of file readdir.c.

◆ nfs41_op_setacl

const nfs41_upcall_op nfs41_op_setacl

Definition at line 797 of file acl.c.

◆ nfs41_op_setattr

const nfs41_upcall_op nfs41_op_setattr

Definition at line 522 of file setattr.c.

◆ nfs41_op_setexattr

const nfs41_upcall_op nfs41_op_setexattr

Definition at line 683 of file ea.c.

◆ nfs41_op_symlink

const nfs41_upcall_op nfs41_op_symlink

Definition at line 295 of file symlink.c.

◆ nfs41_op_unlock

const nfs41_upcall_op nfs41_op_unlock

Definition at line 366 of file lock.c.

◆ nfs41_op_unmount

const nfs41_upcall_op nfs41_op_unmount

Definition at line 173 of file mount.c.

◆ nfs41_op_volume

const nfs41_upcall_op nfs41_op_volume

Definition at line 172 of file volume.c.

◆ nfs41_op_write

const nfs41_upcall_op nfs41_op_write

Definition at line 321 of file readwrite.c.