Merge branch 'master' of ssh://git.samba.org/data/git/samba
[samba.git] / source3 / libsmb / clireadwrite.c
1 /*
2    Unix SMB/CIFS implementation.
3    client file read/write routines
4    Copyright (C) Andrew Tridgell 1994-1998
5
6    This program is free software; you can redistribute it and/or modify
7    it under the terms of the GNU General Public License as published by
8    the Free Software Foundation; either version 3 of the License, or
9    (at your option) any later version.
10
11    This program is distributed in the hope that it will be useful,
12    but WITHOUT ANY WARRANTY; without even the implied warranty of
13    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14    GNU General Public License for more details.
15
16    You should have received a copy of the GNU General Public License
17    along with this program.  If not, see <http://www.gnu.org/licenses/>.
18 */
19
20 #include "includes.h"
21
22 /****************************************************************************
23   Calculate the recommended read buffer size
24 ****************************************************************************/
25 static size_t cli_read_max_bufsize(struct cli_state *cli)
26 {
27         if (!client_is_signing_on(cli) && !cli_encryption_on(cli)
28             && (cli->posix_capabilities & CIFS_UNIX_LARGE_READ_CAP)) {
29                 return CLI_SAMBA_MAX_POSIX_LARGE_READX_SIZE;
30         }
31         if (cli->capabilities & CAP_LARGE_READX) {
32                 return cli->is_samba
33                         ? CLI_SAMBA_MAX_LARGE_READX_SIZE
34                         : CLI_WINDOWS_MAX_LARGE_READX_SIZE;
35         }
36         return (cli->max_xmit - (smb_size+32)) & ~1023;
37 }
38
39 /****************************************************************************
40   Calculate the recommended write buffer size
41 ****************************************************************************/
42 static size_t cli_write_max_bufsize(struct cli_state *cli, uint16_t write_mode)
43 {
44         if (write_mode == 0 &&
45             !client_is_signing_on(cli) &&
46             !cli_encryption_on(cli) &&
47             (cli->posix_capabilities & CIFS_UNIX_LARGE_WRITE_CAP) &&
48             (cli->capabilities & CAP_LARGE_FILES)) {
49                 /* Only do massive writes if we can do them direct
50                  * with no signing or encrypting - not on a pipe. */
51                 return CLI_SAMBA_MAX_POSIX_LARGE_WRITEX_SIZE;
52         }
53
54         if (cli->is_samba) {
55                 return CLI_SAMBA_MAX_LARGE_WRITEX_SIZE;
56         }
57
58         if (((cli->capabilities & CAP_LARGE_WRITEX) == 0)
59             || client_is_signing_on(cli)
60             || strequal(cli->dev, "LPT1:")) {
61
62                 /*
63                  * Printer devices are restricted to max_xmit writesize in
64                  * Vista and XPSP3 as are signing connections.
65                  */
66
67                 return (cli->max_xmit - (smb_size+32)) & ~1023;
68         }
69
70         return CLI_WINDOWS_MAX_LARGE_WRITEX_SIZE;
71 }
72
73
74 /*
75  * Send a read&x request
76  */
77
78 struct async_req *cli_read_andx_send(TALLOC_CTX *mem_ctx,
79                                      struct event_context *ev,
80                                      struct cli_state *cli, int fnum,
81                                      off_t offset, size_t size)
82 {
83         struct async_req *result;
84         struct cli_request *req;
85         bool bigoffset = False;
86
87         uint16_t vwv[12];
88         uint8_t wct = 10;
89
90         if (size > cli_read_max_bufsize(cli)) {
91                 DEBUG(0, ("cli_read_andx_send got size=%d, can only handle "
92                           "size=%d\n", (int)size,
93                           (int)cli_read_max_bufsize(cli)));
94                 return NULL;
95         }
96
97         SCVAL(vwv + 0, 0, 0xFF);
98         SCVAL(vwv + 0, 1, 0);
99         SSVAL(vwv + 1, 0, 0);
100         SSVAL(vwv + 2, 0, fnum);
101         SIVAL(vwv + 3, 0, offset);
102         SSVAL(vwv + 5, 0, size);
103         SSVAL(vwv + 6, 0, size);
104         SSVAL(vwv + 7, 0, (size >> 16));
105         SSVAL(vwv + 8, 0, 0);
106         SSVAL(vwv + 9, 0, 0);
107
108         if ((uint64_t)offset >> 32) {
109                 bigoffset = True;
110                 SIVAL(vwv + 10, 0,
111                       (((uint64_t)offset)>>32) & 0xffffffff);
112                 wct += 2;
113         }
114
115         result = cli_request_send(mem_ctx, ev, cli, SMBreadX, 0, wct, vwv, 0,
116                                   0, NULL);
117         if (result == NULL) {
118                 return NULL;
119         }
120
121         req = talloc_get_type_abort(result->private_data, struct cli_request);
122
123         req->data.read.ofs = offset;
124         req->data.read.size = size;
125         req->data.read.received = 0;
126         req->data.read.rcvbuf = NULL;
127
128         return result;
129 }
130
131 /*
132  * Pull the data out of a finished async read_and_x request. rcvbuf is
133  * talloced from the request, so better make sure that you copy it away before
134  * you talloc_free(req). "rcvbuf" is NOT a talloc_ctx of its own, so do not
135  * talloc_move it!
136  */
137
138 NTSTATUS cli_read_andx_recv(struct async_req *req, ssize_t *received,
139                             uint8_t **rcvbuf)
140 {
141         struct cli_request *cli_req = talloc_get_type_abort(
142                 req->private_data, struct cli_request);
143         uint8_t wct;
144         uint16_t *vwv;
145         uint16_t num_bytes;
146         uint8_t *bytes;
147         uint8_t *buf;
148         NTSTATUS status;
149         size_t size;
150
151         if (async_req_is_error(req, &status)) {
152                 return status;
153         }
154
155         status = cli_pull_reply(req, &wct, &vwv, &num_bytes, &bytes);
156
157         if (NT_STATUS_IS_ERR(status)) {
158                 return status;
159         }
160
161         if (wct < 12) {
162                 return NT_STATUS_INVALID_NETWORK_RESPONSE;
163         }
164
165         /* size is the number of bytes the server returned.
166          * Might be zero. */
167         size = SVAL(vwv + 5, 0);
168         size |= (((unsigned int)SVAL(vwv + 7, 0)) << 16);
169
170         if (size > cli_req->data.read.size) {
171                 DEBUG(5,("server returned more than we wanted!\n"));
172                 return NT_STATUS_UNEXPECTED_IO_ERROR;
173         }
174
175         /*
176          * bcc field must be valid for small reads, for large reads the 16-bit
177          * bcc field can't be correct.
178          */
179
180         if ((size < 0xffff) && (size > num_bytes)) {
181                 DEBUG(5, ("server announced more bytes than sent\n"));
182                 return NT_STATUS_INVALID_NETWORK_RESPONSE;
183         }
184
185         buf = (uint8_t *)smb_base(cli_req->inbuf) + SVAL(vwv+6, 0);
186
187         if (trans_oob(smb_len(cli_req->inbuf), SVAL(vwv+6, 0), size)
188             || (buf < bytes)) {
189                 DEBUG(5, ("server returned invalid read&x data offset\n"));
190                 return NT_STATUS_INVALID_NETWORK_RESPONSE;
191         }
192
193         *rcvbuf = (uint8_t *)(smb_base(cli_req->inbuf) + SVAL(vwv + 6, 0));
194         *received = size;
195         return NT_STATUS_OK;
196 }
197
198 /*
199  * Parallel read support.
200  *
201  * cli_pull sends as many read&x requests as the server would allow via
202  * max_mux at a time. When replies flow back in, the data is written into
203  * the callback function "sink" in the right order.
204  */
205
206 struct cli_pull_state {
207         struct async_req *req;
208
209         struct event_context *ev;
210         struct cli_state *cli;
211         uint16_t fnum;
212         off_t start_offset;
213         SMB_OFF_T size;
214
215         NTSTATUS (*sink)(char *buf, size_t n, void *priv);
216         void *priv;
217
218         size_t chunk_size;
219
220         /*
221          * Outstanding requests
222          */
223         int num_reqs;
224         struct async_req **reqs;
225
226         /*
227          * For how many bytes did we send requests already?
228          */
229         SMB_OFF_T requested;
230
231         /*
232          * Next request index to push into "sink". This walks around the "req"
233          * array, taking care that the requests are pushed to "sink" in the
234          * right order. If necessary (i.e. replies don't come in in the right
235          * order), replies are held back in "reqs".
236          */
237         int top_req;
238
239         /*
240          * How many bytes did we push into "sink"?
241          */
242
243         SMB_OFF_T pushed;
244 };
245
246 static char *cli_pull_print(TALLOC_CTX *mem_ctx, struct async_req *req)
247 {
248         struct cli_pull_state *state = talloc_get_type_abort(
249                 req->private_data, struct cli_pull_state);
250         char *result;
251
252         result = async_req_print(mem_ctx, req);
253         if (result == NULL) {
254                 return NULL;
255         }
256
257         return talloc_asprintf_append_buffer(
258                 result, "num_reqs=%d, top_req=%d",
259                 state->num_reqs, state->top_req);
260 }
261
262 static void cli_pull_read_done(struct async_req *read_req);
263
264 /*
265  * Prepare an async pull request
266  */
267
268 struct async_req *cli_pull_send(TALLOC_CTX *mem_ctx,
269                                 struct event_context *ev,
270                                 struct cli_state *cli,
271                                 uint16_t fnum, off_t start_offset,
272                                 SMB_OFF_T size, size_t window_size,
273                                 NTSTATUS (*sink)(char *buf, size_t n,
274                                                  void *priv),
275                                 void *priv)
276 {
277         struct async_req *result;
278         struct cli_pull_state *state;
279         int i;
280
281         result = async_req_new(mem_ctx, ev);
282         if (result == NULL) {
283                 goto failed;
284         }
285         state = talloc(result, struct cli_pull_state);
286         if (state == NULL) {
287                 goto failed;
288         }
289         result->private_data = state;
290         result->print = cli_pull_print;
291         state->req = result;
292
293         state->cli = cli;
294         state->ev = ev;
295         state->fnum = fnum;
296         state->start_offset = start_offset;
297         state->size = size;
298         state->sink = sink;
299         state->priv = priv;
300
301         state->pushed = 0;
302         state->top_req = 0;
303
304         if (size == 0) {
305                 if (!async_post_status(result, NT_STATUS_OK)) {
306                         goto failed;
307                 }
308                 return result;
309         }
310
311         state->chunk_size = cli_read_max_bufsize(cli);
312
313         state->num_reqs = MAX(window_size/state->chunk_size, 1);
314         state->num_reqs = MIN(state->num_reqs, cli->max_mux);
315
316         state->reqs = TALLOC_ZERO_ARRAY(state, struct async_req *,
317                                         state->num_reqs);
318         if (state->reqs == NULL) {
319                 goto failed;
320         }
321
322         state->requested = 0;
323
324         for (i=0; i<state->num_reqs; i++) {
325                 SMB_OFF_T size_left;
326                 size_t request_thistime;
327
328                 if (state->requested >= size) {
329                         state->num_reqs = i;
330                         break;
331                 }
332
333                 size_left = size - state->requested;
334                 request_thistime = MIN(size_left, state->chunk_size);
335
336                 state->reqs[i] = cli_read_andx_send(
337                         state->reqs, ev, cli, fnum,
338                         state->start_offset + state->requested,
339                         request_thistime);
340
341                 if (state->reqs[i] == NULL) {
342                         goto failed;
343                 }
344
345                 state->reqs[i]->async.fn = cli_pull_read_done;
346                 state->reqs[i]->async.priv = result;
347
348                 state->requested += request_thistime;
349         }
350         return result;
351
352 failed:
353         TALLOC_FREE(result);
354         return NULL;
355 }
356
357 /*
358  * Handle incoming read replies, push the data into sink and send out new
359  * requests if necessary.
360  */
361
362 static void cli_pull_read_done(struct async_req *read_req)
363 {
364         struct async_req *pull_req = talloc_get_type_abort(
365                 read_req->async.priv, struct async_req);
366         struct cli_pull_state *state = talloc_get_type_abort(
367                 pull_req->private_data, struct cli_pull_state);
368         struct cli_request *read_state = talloc_get_type_abort(
369                 read_req->private_data, struct cli_request);
370         NTSTATUS status;
371
372         status = cli_read_andx_recv(read_req, &read_state->data.read.received,
373                                     &read_state->data.read.rcvbuf);
374         if (!NT_STATUS_IS_OK(status)) {
375                 async_req_error(state->req, status);
376                 return;
377         }
378
379         /*
380          * This loop is the one to take care of out-of-order replies. All
381          * pending requests are in state->reqs, state->reqs[top_req] is the
382          * one that is to be pushed next. If however a request later than
383          * top_req is replied to, then we can't push yet. If top_req is
384          * replied to at a later point then, we need to push all the finished
385          * requests.
386          */
387
388         while (state->reqs[state->top_req] != NULL) {
389                 struct cli_request *top_read;
390
391                 DEBUG(11, ("cli_pull_read_done: top_req = %d\n",
392                            state->top_req));
393
394                 if (state->reqs[state->top_req]->state < ASYNC_REQ_DONE) {
395                         DEBUG(11, ("cli_pull_read_done: top request not yet "
396                                    "done\n"));
397                         return;
398                 }
399
400                 top_read = talloc_get_type_abort(
401                         state->reqs[state->top_req]->private_data,
402                         struct cli_request);
403
404                 DEBUG(10, ("cli_pull_read_done: Pushing %d bytes, %d already "
405                            "pushed\n", (int)top_read->data.read.received,
406                            (int)state->pushed));
407
408                 status = state->sink((char *)top_read->data.read.rcvbuf,
409                                      top_read->data.read.received,
410                                      state->priv);
411                 if (!NT_STATUS_IS_OK(status)) {
412                         async_req_error(state->req, status);
413                         return;
414                 }
415                 state->pushed += top_read->data.read.received;
416
417                 TALLOC_FREE(state->reqs[state->top_req]);
418
419                 if (state->requested < state->size) {
420                         struct async_req *new_req;
421                         SMB_OFF_T size_left;
422                         size_t request_thistime;
423
424                         size_left = state->size - state->requested;
425                         request_thistime = MIN(size_left, state->chunk_size);
426
427                         DEBUG(10, ("cli_pull_read_done: Requesting %d bytes "
428                                    "at %d, position %d\n",
429                                    (int)request_thistime,
430                                    (int)(state->start_offset
431                                          + state->requested),
432                                    state->top_req));
433
434                         new_req = cli_read_andx_send(
435                                 state->reqs, state->ev, state->cli,
436                                 state->fnum,
437                                 state->start_offset + state->requested,
438                                 request_thistime);
439
440                         if (async_req_nomem(new_req, state->req)) {
441                                 return;
442                         }
443
444                         new_req->async.fn = cli_pull_read_done;
445                         new_req->async.priv = pull_req;
446
447                         state->reqs[state->top_req] = new_req;
448                         state->requested += request_thistime;
449                 }
450
451                 state->top_req = (state->top_req+1) % state->num_reqs;
452         }
453
454         async_req_done(pull_req);
455 }
456
457 NTSTATUS cli_pull_recv(struct async_req *req, SMB_OFF_T *received)
458 {
459         struct cli_pull_state *state = talloc_get_type_abort(
460                 req->private_data, struct cli_pull_state);
461         NTSTATUS status;
462
463         if (async_req_is_error(req, &status)) {
464                 return status;
465         }
466         *received = state->pushed;
467         return NT_STATUS_OK;
468 }
469
470 NTSTATUS cli_pull(struct cli_state *cli, uint16_t fnum,
471                   off_t start_offset, SMB_OFF_T size, size_t window_size,
472                   NTSTATUS (*sink)(char *buf, size_t n, void *priv),
473                   void *priv, SMB_OFF_T *received)
474 {
475         TALLOC_CTX *frame = talloc_stackframe();
476         struct event_context *ev;
477         struct async_req *req;
478         NTSTATUS result = NT_STATUS_NO_MEMORY;
479
480         if (cli->fd_event != NULL) {
481                 /*
482                  * Can't use sync call while an async call is in flight
483                  */
484                 return NT_STATUS_INVALID_PARAMETER;
485         }
486
487         ev = event_context_init(frame);
488         if (ev == NULL) {
489                 goto nomem;
490         }
491
492         req = cli_pull_send(frame, ev, cli, fnum, start_offset, size,
493                             window_size, sink, priv);
494         if (req == NULL) {
495                 goto nomem;
496         }
497
498         while (req->state < ASYNC_REQ_DONE) {
499                 event_loop_once(ev);
500         }
501
502         result = cli_pull_recv(req, received);
503  nomem:
504         TALLOC_FREE(frame);
505         return result;
506 }
507
508 static NTSTATUS cli_read_sink(char *buf, size_t n, void *priv)
509 {
510         char **pbuf = (char **)priv;
511         memcpy(*pbuf, buf, n);
512         *pbuf += n;
513         return NT_STATUS_OK;
514 }
515
516 ssize_t cli_read(struct cli_state *cli, int fnum, char *buf,
517                  off_t offset, size_t size)
518 {
519         NTSTATUS status;
520         SMB_OFF_T ret;
521
522         status = cli_pull(cli, fnum, offset, size, size,
523                           cli_read_sink, &buf, &ret);
524         if (!NT_STATUS_IS_OK(status)) {
525                 cli_set_error(cli, status);
526                 return -1;
527         }
528         return ret;
529 }
530
531 /****************************************************************************
532  Issue a single SMBwrite and don't wait for a reply.
533 ****************************************************************************/
534
535 static bool cli_issue_write(struct cli_state *cli,
536                                 int fnum,
537                                 off_t offset,
538                                 uint16 mode,
539                                 const char *buf,
540                                 size_t size,
541                                 int i)
542 {
543         char *p;
544         bool large_writex = false;
545         /* We can only do direct writes if not signing and not encrypting. */
546         bool direct_writes = !client_is_signing_on(cli) && !cli_encryption_on(cli);
547
548         if (!direct_writes && size + 1 > cli->bufsize) {
549                 cli->outbuf = (char *)SMB_REALLOC(cli->outbuf, size + 1024);
550                 if (!cli->outbuf) {
551                         return False;
552                 }
553                 cli->inbuf = (char *)SMB_REALLOC(cli->inbuf, size + 1024);
554                 if (cli->inbuf == NULL) {
555                         SAFE_FREE(cli->outbuf);
556                         return False;
557                 }
558                 cli->bufsize = size + 1024;
559         }
560
561         memset(cli->outbuf,'\0',smb_size);
562         memset(cli->inbuf,'\0',smb_size);
563
564         if (cli->capabilities & CAP_LARGE_FILES) {
565                 large_writex = True;
566         }
567
568         if (large_writex) {
569                 cli_set_message(cli->outbuf,14,0,True);
570         } else {
571                 cli_set_message(cli->outbuf,12,0,True);
572         }
573
574         SCVAL(cli->outbuf,smb_com,SMBwriteX);
575         SSVAL(cli->outbuf,smb_tid,cli->cnum);
576         cli_setup_packet(cli);
577
578         SCVAL(cli->outbuf,smb_vwv0,0xFF);
579         SSVAL(cli->outbuf,smb_vwv2,fnum);
580
581         SIVAL(cli->outbuf,smb_vwv3,offset);
582         SIVAL(cli->outbuf,smb_vwv5,0);
583         SSVAL(cli->outbuf,smb_vwv7,mode);
584
585         SSVAL(cli->outbuf,smb_vwv8,(mode & 0x0008) ? size : 0);
586         /*
587          * According to CIFS-TR-1p00, this following field should only
588          * be set if CAP_LARGE_WRITEX is set. We should check this
589          * locally. However, this check might already have been
590          * done by our callers.
591          */
592         SSVAL(cli->outbuf,smb_vwv9,(size>>16));
593         SSVAL(cli->outbuf,smb_vwv10,size);
594         /* +1 is pad byte. */
595         SSVAL(cli->outbuf,smb_vwv11,
596               smb_buf(cli->outbuf) - smb_base(cli->outbuf) + 1);
597
598         if (large_writex) {
599                 SIVAL(cli->outbuf,smb_vwv12,(((uint64_t)offset)>>32) & 0xffffffff);
600         }
601
602         p = smb_base(cli->outbuf) + SVAL(cli->outbuf,smb_vwv11) -1;
603         *p++ = '\0'; /* pad byte. */
604         if (!direct_writes) {
605                 memcpy(p, buf, size);
606         }
607         if (size > 0x1FFFF) {
608                 /* This is a POSIX 14 word large write. */
609                 set_message_bcc(cli->outbuf, 0); /* Set bcc to zero. */
610                 _smb_setlen_large(cli->outbuf,smb_size + 28 + 1 /* pad */ + size - 4);
611         } else {
612                 cli_setup_bcc(cli, p+size);
613         }
614
615         SSVAL(cli->outbuf,smb_mid,cli->mid + i);
616
617         show_msg(cli->outbuf);
618         if (direct_writes) {
619                 /* For direct writes we now need to write the data
620                  * directly out of buf. */
621                 return cli_send_smb_direct_writeX(cli, buf, size);
622         } else {
623                 return cli_send_smb(cli);
624         }
625 }
626
627 /****************************************************************************
628   write to a file
629   write_mode: 0x0001 disallow write cacheing
630               0x0002 return bytes remaining
631               0x0004 use raw named pipe protocol
632               0x0008 start of message mode named pipe protocol
633 ****************************************************************************/
634
635 ssize_t cli_write(struct cli_state *cli,
636                  int fnum, uint16 write_mode,
637                  const char *buf, off_t offset, size_t size)
638 {
639         ssize_t bwritten = 0;
640         unsigned int issued = 0;
641         unsigned int received = 0;
642         int mpx = 1;
643         size_t writesize;
644         int blocks;
645
646         if(cli->max_mux > 1) {
647                 mpx = cli->max_mux-1;
648         } else {
649                 mpx = 1;
650         }
651
652         writesize = cli_write_max_bufsize(cli, write_mode);
653
654         blocks = (size + (writesize-1)) / writesize;
655
656         while (received < blocks) {
657
658                 while ((issued - received < mpx) && (issued < blocks)) {
659                         ssize_t bsent = issued * writesize;
660                         ssize_t size1 = MIN(writesize, size - bsent);
661
662                         if (!cli_issue_write(cli, fnum, offset + bsent,
663                                         write_mode,
664                                         buf + bsent,
665                                         size1, issued))
666                                 return -1;
667                         issued++;
668                 }
669
670                 if (!cli_receive_smb(cli)) {
671                         return bwritten;
672                 }
673
674                 received++;
675
676                 if (cli_is_error(cli))
677                         break;
678
679                 bwritten += SVAL(cli->inbuf, smb_vwv2);
680                 if (writesize > 0xFFFF) {
681                         bwritten += (((int)(SVAL(cli->inbuf, smb_vwv4)))<<16);
682                 }
683         }
684
685         while (received < issued && cli_receive_smb(cli)) {
686                 received++;
687         }
688
689         return bwritten;
690 }
691
692 /****************************************************************************
693   write to a file using a SMBwrite and not bypassing 0 byte writes
694 ****************************************************************************/
695
696 ssize_t cli_smbwrite(struct cli_state *cli,
697                      int fnum, char *buf, off_t offset, size_t size1)
698 {
699         char *p;
700         ssize_t total = 0;
701
702         do {
703                 size_t size = MIN(size1, cli->max_xmit - 48);
704
705                 memset(cli->outbuf,'\0',smb_size);
706                 memset(cli->inbuf,'\0',smb_size);
707
708                 cli_set_message(cli->outbuf,5, 0,True);
709
710                 SCVAL(cli->outbuf,smb_com,SMBwrite);
711                 SSVAL(cli->outbuf,smb_tid,cli->cnum);
712                 cli_setup_packet(cli);
713
714                 SSVAL(cli->outbuf,smb_vwv0,fnum);
715                 SSVAL(cli->outbuf,smb_vwv1,size);
716                 SIVAL(cli->outbuf,smb_vwv2,offset);
717                 SSVAL(cli->outbuf,smb_vwv4,0);
718
719                 p = smb_buf(cli->outbuf);
720                 *p++ = 1;
721                 SSVAL(p, 0, size); p += 2;
722                 memcpy(p, buf + total, size); p += size;
723
724                 cli_setup_bcc(cli, p);
725
726                 if (!cli_send_smb(cli))
727                         return -1;
728
729                 if (!cli_receive_smb(cli))
730                         return -1;
731
732                 if (cli_is_error(cli))
733                         return -1;
734
735                 size = SVAL(cli->inbuf,smb_vwv0);
736                 if (size == 0)
737                         break;
738
739                 size1 -= size;
740                 total += size;
741                 offset += size;
742
743         } while (size1);
744
745         return total;
746 }