mirror of
https://github.com/samba-team/samba.git
synced 2025-01-11 05:18:09 +03:00
Make dskattr async.
Jeremy.
This commit is contained in:
parent
740c2c4366
commit
455f2a4c65
@ -307,7 +307,7 @@ static int do_dskattr(void)
|
||||
return 1;
|
||||
}
|
||||
|
||||
if (!cli_dskattr(targetcli, &bsize, &total, &avail)) {
|
||||
if (!NT_STATUS_IS_OK(cli_dskattr(targetcli, &bsize, &total, &avail))) {
|
||||
d_printf("Error in dskattr: %s\n",cli_errstr(targetcli));
|
||||
return 1;
|
||||
}
|
||||
|
@ -2417,7 +2417,7 @@ bool cli_setattrE(struct cli_state *cli, int fd,
|
||||
time_t write_time);
|
||||
bool cli_setatr(struct cli_state *cli, const char *fname, uint16 attr, time_t t);
|
||||
NTSTATUS cli_chkpath(struct cli_state *cli, const char *path);
|
||||
bool cli_dskattr(struct cli_state *cli, int *bsize, int *total, int *avail);
|
||||
NTSTATUS cli_dskattr(struct cli_state *cli, int *bsize, int *total, int *avail);
|
||||
int cli_ctemp(struct cli_state *cli, const char *path, char **tmp_path);
|
||||
NTSTATUS cli_raw_ioctl(struct cli_state *cli, int fnum, uint32 code, DATA_BLOB *blob);
|
||||
bool cli_set_ea_path(struct cli_state *cli, const char *path, const char *ea_name, const char *ea_val, size_t ea_len);
|
||||
|
@ -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)
|
||||
{
|
||||
char *path2 = NULL;
|
||||
char *p;
|
||||
TALLOC_CTX *frame = talloc_stackframe();
|
||||
|
||||
path2 = talloc_strdup(frame, path);
|
||||
if (!path2) {
|
||||
TALLOC_FREE(frame);
|
||||
return false;
|
||||
}
|
||||
trim_char(path2,'\0','\\');
|
||||
if (!*path2) {
|
||||
path2 = talloc_strdup(frame, "\\");
|
||||
if (!path2) {
|
||||
TALLOC_FREE(frame);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
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);
|
||||
|
||||
cli_setup_bcc(cli, p);
|
||||
|
||||
cli_send_smb(cli);
|
||||
if (!cli_receive_smb(cli)) {
|
||||
TALLOC_FREE(frame);
|
||||
return False;
|
||||
}
|
||||
|
||||
TALLOC_FREE(frame);
|
||||
|
||||
if (cli_is_error(cli)) return False;
|
||||
|
||||
return True;
|
||||
}
|
||||
#endif
|
||||
|
||||
/****************************************************************************
|
||||
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)
|
||||
{
|
||||
struct tevent_req *req = NULL, *subreq = NULL;
|
||||
struct cli_dskattr_state *state = NULL;
|
||||
uint8_t additional_flags = 0;
|
||||
|
||||
req = tevent_req_create(mem_ctx, &state, struct cli_dskattr_state);
|
||||
if (req == NULL) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
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;
|
||||
|
||||
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);
|
||||
}
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
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_has_async_calls(cli)) {
|
||||
/*
|
||||
* Can't use sync call while an async call is in flight
|
||||
*/
|
||||
status = NT_STATUS_INVALID_PARAMETER;
|
||||
goto fail;
|
||||
}
|
||||
|
||||
ev = event_context_init(frame);
|
||||
if (ev == NULL) {
|
||||
status = NT_STATUS_NO_MEMORY;
|
||||
goto fail;
|
||||
}
|
||||
|
||||
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.
|
||||
|
Loading…
Reference in New Issue
Block a user