diff options
author | Jeremy Allison <jra@samba.org> | 2009-04-22 08:04:53 -0700 |
---|---|---|
committer | Jeremy Allison <jra@samba.org> | 2009-04-22 08:04:53 -0700 |
commit | 455f2a4c65b679a996a8d6e7548dc2f4a6f28fae (patch) | |
tree | 95aab64d6f8927d5f7be56a363add62b0159c916 /source3/libsmb | |
parent | 740c2c4366badc62d017881c9484ee5153b62f94 (diff) | |
download | samba-455f2a4c65b679a996a8d6e7548dc2f4a6f28fae.tar.gz samba-455f2a4c65b679a996a8d6e7548dc2f4a6f28fae.tar.bz2 samba-455f2a4c65b679a996a8d6e7548dc2f4a6f28fae.zip |
Make dskattr async.
Jeremy.
Diffstat (limited to 'source3/libsmb')
-rw-r--r-- | source3/libsmb/clifile.c | 140 |
1 files changed, 102 insertions, 38 deletions
diff --git a/source3/libsmb/clifile.c b/source3/libsmb/clifile.c index c98346e3b3..3d1da5f412 100644 --- a/source3/libsmb/clifile.c +++ b/source3/libsmb/clifile.c @@ -2163,57 +2163,120 @@ NTSTATUS cli_chkpath(struct cli_state *cli, const char *path) return status; } -#if 0 -bool cli_chkpath(struct cli_state *cli, const char *path) +/**************************************************************************** + Query disk space. +****************************************************************************/ + +static void cli_dskattr_done(struct tevent_req *subreq); + +struct cli_dskattr_state { + int bsize; + int total; + int avail; +}; + +struct tevent_req *cli_dskattr_send(TALLOC_CTX *mem_ctx, + struct event_context *ev, + struct cli_state *cli) { - char *path2 = NULL; - char *p; - TALLOC_CTX *frame = talloc_stackframe(); + struct tevent_req *req = NULL, *subreq = NULL; + struct cli_dskattr_state *state = NULL; + uint8_t additional_flags = 0; - path2 = talloc_strdup(frame, path); - if (!path2) { - TALLOC_FREE(frame); - return false; + req = tevent_req_create(mem_ctx, &state, struct cli_dskattr_state); + if (req == NULL) { + return NULL; } - trim_char(path2,'\0','\\'); - if (!*path2) { - path2 = talloc_strdup(frame, "\\"); - if (!path2) { - TALLOC_FREE(frame); - return false; - } + + subreq = cli_smb_send(state, ev, cli, SMBdskattr, additional_flags, + 0, NULL, 0, NULL); + if (tevent_req_nomem(subreq, req)) { + return tevent_req_post(req, ev); } + tevent_req_set_callback(subreq, cli_dskattr_done, req); + return req; +} - memset(cli->outbuf,'\0',smb_size); - cli_set_message(cli->outbuf,0,0,True); - SCVAL(cli->outbuf,smb_com,SMBcheckpath); - SSVAL(cli->outbuf,smb_tid,cli->cnum); - cli_setup_packet(cli); - p = smb_buf(cli->outbuf); - *p++ = 4; - p += clistr_push(cli, p, path2, - cli->bufsize - PTR_DIFF(p,cli->outbuf), STR_TERMINATE); +static void cli_dskattr_done(struct tevent_req *subreq) +{ + struct tevent_req *req = tevent_req_callback_data( + subreq, struct tevent_req); + struct cli_dskattr_state *state = tevent_req_data( + req, struct cli_dskattr_state); + uint8_t wct; + uint16_t *vwv = NULL; + NTSTATUS status; - cli_setup_bcc(cli, p); + status = cli_smb_recv(subreq, 4, &wct, &vwv, NULL, NULL); + if (!NT_STATUS_IS_OK(status)) { + tevent_req_nterror(req, status); + return; + } + state->bsize = SVAL(vwv+1, 0)*SVAL(vwv+2,0); + state->total = SVAL(vwv+0, 0); + state->avail = SVAL(vwv+3, 0); + TALLOC_FREE(subreq); + tevent_req_done(req); +} - cli_send_smb(cli); - if (!cli_receive_smb(cli)) { - TALLOC_FREE(frame); - return False; +NTSTATUS cli_dskattr_recv(struct tevent_req *req, int *bsize, int *total, int *avail) +{ + struct cli_dskattr_state *state = tevent_req_data( + req, struct cli_dskattr_state); + NTSTATUS status; + + if (tevent_req_is_nterror(req, &status)) { + return status; } + *bsize = state->bsize; + *total = state->total; + *avail = state->avail; + return NT_STATUS_OK; +} - TALLOC_FREE(frame); +NTSTATUS cli_dskattr(struct cli_state *cli, int *bsize, int *total, int *avail) +{ + TALLOC_CTX *frame = talloc_stackframe(); + struct event_context *ev = NULL; + struct tevent_req *req = NULL; + NTSTATUS status = NT_STATUS_OK; - if (cli_is_error(cli)) return False; + if (cli_has_async_calls(cli)) { + /* + * Can't use sync call while an async call is in flight + */ + status = NT_STATUS_INVALID_PARAMETER; + goto fail; + } - return True; -} -#endif + ev = event_context_init(frame); + if (ev == NULL) { + status = NT_STATUS_NO_MEMORY; + goto fail; + } -/**************************************************************************** - Query disk space. -****************************************************************************/ + req = cli_dskattr_send(frame, ev, cli); + if (req == NULL) { + status = NT_STATUS_NO_MEMORY; + goto fail; + } + + if (!tevent_req_poll(req, ev)) { + status = map_nt_error_from_unix(errno); + goto fail; + } + status = cli_dskattr_recv(req, bsize, total, avail); + + fail: + TALLOC_FREE(frame); + if (!NT_STATUS_IS_OK(status)) { + cli_set_error(cli, status); + } + return status; +} + +#if 0 bool cli_dskattr(struct cli_state *cli, int *bsize, int *total, int *avail) { memset(cli->outbuf,'\0',smb_size); @@ -2233,6 +2296,7 @@ bool cli_dskattr(struct cli_state *cli, int *bsize, int *total, int *avail) return True; } +#endif /**************************************************************************** Create and open a temporary file. |