2 * Copyright (c) 2001-2002 Damien Miller. All rights reserved.
4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions
7 * 1. Redistributions of source code must retain the above copyright
8 * notice, this list of conditions and the following disclaimer.
9 * 2. Redistributions in binary form must reproduce the above copyright
10 * notice, this list of conditions and the following disclaimer in the
11 * documentation and/or other materials provided with the distribution.
13 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
14 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
15 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
16 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
17 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
18 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
19 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
20 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
21 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
22 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
26 /* XXX: signed vs unsigned */
27 /* XXX: we use fatal too much, error may be more appropriate in places */
28 /* XXX: copy between two remote sites */
31 RCSID("$OpenBSD: sftp-client.c,v 1.21 2002/02/12 12:32:27 djm Exp $");
33 #if defined(HAVE_SYS_QUEUE_H) && !defined(HAVE_BOGUS_SYS_QUEUE_H)
34 #include <sys/queue.h>
36 #include "openbsd-compat/fake-queue.h"
47 #include "sftp-common.h"
48 #include "sftp-client.h"
50 /* Minimum amount of data to read at at time */
51 #define MIN_READ_SIZE 512
54 static u_int msg_id = 1;
57 send_msg(int fd, Buffer *m)
59 int mlen = buffer_len(m);
64 buffer_put_int(&oqueue, mlen);
65 buffer_append(&oqueue, buffer_ptr(m), mlen);
66 buffer_consume(m, mlen);
68 len = atomicio(write, fd, buffer_ptr(&oqueue), buffer_len(&oqueue));
70 fatal("Couldn't send packet: %s", strerror(errno));
76 get_msg(int fd, Buffer *m)
79 unsigned char buf[4096];
81 len = atomicio(read, fd, buf, 4);
83 fatal("Connection closed");
85 fatal("Couldn't read packet: %s", strerror(errno));
87 msg_len = GET_32BIT(buf);
88 if (msg_len > 256 * 1024)
89 fatal("Received message too long %d", msg_len);
92 len = atomicio(read, fd, buf, MIN(msg_len, sizeof(buf)));
94 fatal("Connection closed");
96 fatal("Couldn't read packet: %s", strerror(errno));
99 buffer_append(m, buf, len);
104 send_string_request(int fd, u_int id, u_int code, char *s,
110 buffer_put_char(&msg, code);
111 buffer_put_int(&msg, id);
112 buffer_put_string(&msg, s, len);
114 debug3("Sent message fd %d T:%d I:%d", fd, code, id);
119 send_string_attrs_request(int fd, u_int id, u_int code, char *s,
120 u_int len, Attrib *a)
125 buffer_put_char(&msg, code);
126 buffer_put_int(&msg, id);
127 buffer_put_string(&msg, s, len);
128 encode_attrib(&msg, a);
130 debug3("Sent message fd %d T:%d I:%d", fd, code, id);
135 get_status(int fd, int expected_id)
138 u_int type, id, status;
142 type = buffer_get_char(&msg);
143 id = buffer_get_int(&msg);
145 if (id != expected_id)
146 fatal("ID mismatch (%d != %d)", id, expected_id);
147 if (type != SSH2_FXP_STATUS)
148 fatal("Expected SSH2_FXP_STATUS(%d) packet, got %d",
149 SSH2_FXP_STATUS, type);
151 status = buffer_get_int(&msg);
154 debug3("SSH2_FXP_STATUS %d", status);
160 get_handle(int fd, u_int expected_id, u_int *len)
168 type = buffer_get_char(&msg);
169 id = buffer_get_int(&msg);
171 if (id != expected_id)
172 fatal("ID mismatch (%d != %d)", id, expected_id);
173 if (type == SSH2_FXP_STATUS) {
174 int status = buffer_get_int(&msg);
176 error("Couldn't get handle: %s", fx2txt(status));
178 } else if (type != SSH2_FXP_HANDLE)
179 fatal("Expected SSH2_FXP_HANDLE(%d) packet, got %d",
180 SSH2_FXP_HANDLE, type);
182 handle = buffer_get_string(&msg, len);
189 get_decode_stat(int fd, u_int expected_id, int quiet)
198 type = buffer_get_char(&msg);
199 id = buffer_get_int(&msg);
201 debug3("Received stat reply T:%d I:%d", type, id);
202 if (id != expected_id)
203 fatal("ID mismatch (%d != %d)", id, expected_id);
204 if (type == SSH2_FXP_STATUS) {
205 int status = buffer_get_int(&msg);
208 debug("Couldn't stat remote file: %s", fx2txt(status));
210 error("Couldn't stat remote file: %s", fx2txt(status));
212 } else if (type != SSH2_FXP_ATTRS) {
213 fatal("Expected SSH2_FXP_ATTRS(%d) packet, got %d",
214 SSH2_FXP_ATTRS, type);
216 a = decode_attrib(&msg);
223 do_init(int fd_in, int fd_out)
229 buffer_put_char(&msg, SSH2_FXP_INIT);
230 buffer_put_int(&msg, SSH2_FILEXFER_VERSION);
231 send_msg(fd_out, &msg);
235 get_msg(fd_in, &msg);
237 /* Expecting a VERSION reply */
238 if ((type = buffer_get_char(&msg)) != SSH2_FXP_VERSION) {
239 error("Invalid packet back from SSH2_FXP_INIT (type %d)",
244 version = buffer_get_int(&msg);
246 debug2("Remote version: %d", version);
248 /* Check for extensions */
249 while (buffer_len(&msg) > 0) {
250 char *name = buffer_get_string(&msg, NULL);
251 char *value = buffer_get_string(&msg, NULL);
253 debug2("Init extension: \"%s\"", name);
264 do_close(int fd_in, int fd_out, char *handle, u_int handle_len)
272 buffer_put_char(&msg, SSH2_FXP_CLOSE);
273 buffer_put_int(&msg, id);
274 buffer_put_string(&msg, handle, handle_len);
275 send_msg(fd_out, &msg);
276 debug3("Sent message SSH2_FXP_CLOSE I:%d", id);
278 status = get_status(fd_in, id);
279 if (status != SSH2_FX_OK)
280 error("Couldn't close file: %s", fx2txt(status));
289 do_lsreaddir(int fd_in, int fd_out, char *path, int printflag,
293 u_int type, id, handle_len, i, expected_id, ents = 0;
299 buffer_put_char(&msg, SSH2_FXP_OPENDIR);
300 buffer_put_int(&msg, id);
301 buffer_put_cstring(&msg, path);
302 send_msg(fd_out, &msg);
306 handle = get_handle(fd_in, id, &handle_len);
312 *dir = xmalloc(sizeof(**dir));
319 id = expected_id = msg_id++;
321 debug3("Sending SSH2_FXP_READDIR I:%d", id);
324 buffer_put_char(&msg, SSH2_FXP_READDIR);
325 buffer_put_int(&msg, id);
326 buffer_put_string(&msg, handle, handle_len);
327 send_msg(fd_out, &msg);
331 get_msg(fd_in, &msg);
333 type = buffer_get_char(&msg);
334 id = buffer_get_int(&msg);
336 debug3("Received reply T:%d I:%d", type, id);
338 if (id != expected_id)
339 fatal("ID mismatch (%d != %d)", id, expected_id);
341 if (type == SSH2_FXP_STATUS) {
342 int status = buffer_get_int(&msg);
344 debug3("Received SSH2_FXP_STATUS %d", status);
346 if (status == SSH2_FX_EOF) {
349 error("Couldn't read directory: %s",
351 do_close(fd_in, fd_out, handle, handle_len);
354 } else if (type != SSH2_FXP_NAME)
355 fatal("Expected SSH2_FXP_NAME(%d) packet, got %d",
356 SSH2_FXP_NAME, type);
358 count = buffer_get_int(&msg);
361 debug3("Received %d SSH2_FXP_NAME responses", count);
362 for (i = 0; i < count; i++) {
363 char *filename, *longname;
366 filename = buffer_get_string(&msg, NULL);
367 longname = buffer_get_string(&msg, NULL);
368 a = decode_attrib(&msg);
371 printf("%s\n", longname);
374 *dir = xrealloc(*dir, sizeof(**dir) *
376 (*dir)[ents] = xmalloc(sizeof(***dir));
377 (*dir)[ents]->filename = xstrdup(filename);
378 (*dir)[ents]->longname = xstrdup(longname);
379 memcpy(&(*dir)[ents]->a, a, sizeof(*a));
380 (*dir)[++ents] = NULL;
389 do_close(fd_in, fd_out, handle, handle_len);
396 do_ls(int fd_in, int fd_out, char *path)
398 return(do_lsreaddir(fd_in, fd_out, path, 1, NULL));
402 do_readdir(int fd_in, int fd_out, char *path, SFTP_DIRENT ***dir)
404 return(do_lsreaddir(fd_in, fd_out, path, 0, dir));
407 void free_sftp_dirents(SFTP_DIRENT **s)
411 for (i = 0; s[i]; i++) {
412 xfree(s[i]->filename);
413 xfree(s[i]->longname);
420 do_rm(int fd_in, int fd_out, char *path)
424 debug2("Sending SSH2_FXP_REMOVE \"%s\"", path);
427 send_string_request(fd_out, id, SSH2_FXP_REMOVE, path, strlen(path));
428 status = get_status(fd_in, id);
429 if (status != SSH2_FX_OK)
430 error("Couldn't delete file: %s", fx2txt(status));
435 do_mkdir(int fd_in, int fd_out, char *path, Attrib *a)
440 send_string_attrs_request(fd_out, id, SSH2_FXP_MKDIR, path,
443 status = get_status(fd_in, id);
444 if (status != SSH2_FX_OK)
445 error("Couldn't create directory: %s", fx2txt(status));
451 do_rmdir(int fd_in, int fd_out, char *path)
456 send_string_request(fd_out, id, SSH2_FXP_RMDIR, path, strlen(path));
458 status = get_status(fd_in, id);
459 if (status != SSH2_FX_OK)
460 error("Couldn't remove directory: %s", fx2txt(status));
466 do_stat(int fd_in, int fd_out, char *path, int quiet)
471 send_string_request(fd_out, id, SSH2_FXP_STAT, path, strlen(path));
472 return(get_decode_stat(fd_in, id, quiet));
476 do_lstat(int fd_in, int fd_out, char *path, int quiet)
481 send_string_request(fd_out, id, SSH2_FXP_LSTAT, path, strlen(path));
482 return(get_decode_stat(fd_in, id, quiet));
486 do_fstat(int fd_in, int fd_out, char *handle, u_int handle_len, int quiet)
491 send_string_request(fd_out, id, SSH2_FXP_FSTAT, handle, handle_len);
492 return(get_decode_stat(fd_in, id, quiet));
496 do_setstat(int fd_in, int fd_out, char *path, Attrib *a)
501 send_string_attrs_request(fd_out, id, SSH2_FXP_SETSTAT, path,
504 status = get_status(fd_in, id);
505 if (status != SSH2_FX_OK)
506 error("Couldn't setstat on \"%s\": %s", path,
513 do_fsetstat(int fd_in, int fd_out, char *handle, u_int handle_len,
519 send_string_attrs_request(fd_out, id, SSH2_FXP_FSETSTAT, handle,
522 status = get_status(fd_in, id);
523 if (status != SSH2_FX_OK)
524 error("Couldn't fsetstat: %s", fx2txt(status));
530 do_realpath(int fd_in, int fd_out, char *path)
533 u_int type, expected_id, count, id;
534 char *filename, *longname;
537 expected_id = id = msg_id++;
538 send_string_request(fd_out, id, SSH2_FXP_REALPATH, path, strlen(path));
542 get_msg(fd_in, &msg);
543 type = buffer_get_char(&msg);
544 id = buffer_get_int(&msg);
546 if (id != expected_id)
547 fatal("ID mismatch (%d != %d)", id, expected_id);
549 if (type == SSH2_FXP_STATUS) {
550 u_int status = buffer_get_int(&msg);
552 error("Couldn't canonicalise: %s", fx2txt(status));
554 } else if (type != SSH2_FXP_NAME)
555 fatal("Expected SSH2_FXP_NAME(%d) packet, got %d",
556 SSH2_FXP_NAME, type);
558 count = buffer_get_int(&msg);
560 fatal("Got multiple names (%d) from SSH_FXP_REALPATH", count);
562 filename = buffer_get_string(&msg, NULL);
563 longname = buffer_get_string(&msg, NULL);
564 a = decode_attrib(&msg);
566 debug3("SSH_FXP_REALPATH %s -> %s", path, filename);
576 do_rename(int fd_in, int fd_out, char *oldpath, char *newpath)
583 /* Send rename request */
585 buffer_put_char(&msg, SSH2_FXP_RENAME);
586 buffer_put_int(&msg, id);
587 buffer_put_cstring(&msg, oldpath);
588 buffer_put_cstring(&msg, newpath);
589 send_msg(fd_out, &msg);
590 debug3("Sent message SSH2_FXP_RENAME \"%s\" -> \"%s\"", oldpath,
594 status = get_status(fd_in, id);
595 if (status != SSH2_FX_OK)
596 error("Couldn't rename file \"%s\" to \"%s\": %s", oldpath, newpath,
603 do_symlink(int fd_in, int fd_out, char *oldpath, char *newpath)
610 /* Send rename request */
612 buffer_put_char(&msg, SSH2_FXP_SYMLINK);
613 buffer_put_int(&msg, id);
614 buffer_put_cstring(&msg, oldpath);
615 buffer_put_cstring(&msg, newpath);
616 send_msg(fd_out, &msg);
617 debug3("Sent message SSH2_FXP_SYMLINK \"%s\" -> \"%s\"", oldpath,
621 status = get_status(fd_in, id);
622 if (status != SSH2_FX_OK)
623 error("Couldn't rename file \"%s\" to \"%s\": %s", oldpath, newpath,
630 do_readlink(int fd_in, int fd_out, char *path)
633 u_int type, expected_id, count, id;
634 char *filename, *longname;
637 expected_id = id = msg_id++;
638 send_string_request(fd_out, id, SSH2_FXP_READLINK, path, strlen(path));
642 get_msg(fd_in, &msg);
643 type = buffer_get_char(&msg);
644 id = buffer_get_int(&msg);
646 if (id != expected_id)
647 fatal("ID mismatch (%d != %d)", id, expected_id);
649 if (type == SSH2_FXP_STATUS) {
650 u_int status = buffer_get_int(&msg);
652 error("Couldn't readlink: %s", fx2txt(status));
654 } else if (type != SSH2_FXP_NAME)
655 fatal("Expected SSH2_FXP_NAME(%d) packet, got %d",
656 SSH2_FXP_NAME, type);
658 count = buffer_get_int(&msg);
660 fatal("Got multiple names (%d) from SSH_FXP_READLINK", count);
662 filename = buffer_get_string(&msg, NULL);
663 longname = buffer_get_string(&msg, NULL);
664 a = decode_attrib(&msg);
666 debug3("SSH_FXP_READLINK %s -> %s", path, filename);
676 send_read_request(int fd_out, u_int id, u_int64_t offset, u_int len,
677 char *handle, u_int handle_len)
683 buffer_put_char(&msg, SSH2_FXP_READ);
684 buffer_put_int(&msg, id);
685 buffer_put_string(&msg, handle, handle_len);
686 buffer_put_int64(&msg, offset);
687 buffer_put_int(&msg, len);
688 send_msg(fd_out, &msg);
693 do_download(int fd_in, int fd_out, char *remote_path, char *local_path,
694 int pflag, size_t buflen, int num_requests)
699 int local_fd, status, num_req, max_req, write_error;
700 int read_error, write_errno;
701 u_int64_t offset, size;
702 u_int handle_len, mode, type, id;
707 TAILQ_ENTRY(request) tq;
709 TAILQ_HEAD(reqhead, request) requests;
712 TAILQ_INIT(&requests);
714 a = do_stat(fd_in, fd_out, remote_path, 0);
718 /* XXX: should we preserve set[ug]id? */
719 if (a->flags & SSH2_FILEXFER_ATTR_PERMISSIONS)
720 mode = S_IWRITE | (a->perm & 0777);
724 if ((a->flags & SSH2_FILEXFER_ATTR_PERMISSIONS) &&
725 (a->perm & S_IFDIR)) {
726 error("Cannot download a directory: %s", remote_path);
730 if (a->flags & SSH2_FILEXFER_ATTR_SIZE)
735 local_fd = open(local_path, O_WRONLY | O_CREAT | O_TRUNC, mode);
736 if (local_fd == -1) {
737 error("Couldn't open local file \"%s\" for writing: %s",
738 local_path, strerror(errno));
744 /* Send open request */
746 buffer_put_char(&msg, SSH2_FXP_OPEN);
747 buffer_put_int(&msg, id);
748 buffer_put_cstring(&msg, remote_path);
749 buffer_put_int(&msg, SSH2_FXF_READ);
750 attrib_clear(&junk); /* Send empty attributes */
751 encode_attrib(&msg, &junk);
752 send_msg(fd_out, &msg);
753 debug3("Sent message SSH2_FXP_OPEN I:%d P:%s", id, remote_path);
755 handle = get_handle(fd_in, id, &handle_len);
756 if (handle == NULL) {
762 /* Read from remote and write to local */
763 write_error = read_error = write_errno = num_req = offset = 0;
765 while (num_req > 0 || max_req > 0) {
769 /* Send some more requests */
770 while (num_req < max_req) {
771 debug3("Request range %llu -> %llu (%d/%d)",
772 offset, offset + buflen - 1, num_req, max_req);
773 req = xmalloc(sizeof(*req));
776 req->offset = offset;
779 TAILQ_INSERT_TAIL(&requests, req, tq);
780 send_read_request(fd_out, req->id, req->offset,
781 req->len, handle, handle_len);
785 get_msg(fd_in, &msg);
786 type = buffer_get_char(&msg);
787 id = buffer_get_int(&msg);
788 debug3("Received reply T:%d I:%d R:%d", type, id, max_req);
790 /* Find the request in our queue */
791 for(req = TAILQ_FIRST(&requests);
792 req != NULL && req->id != id;
793 req = TAILQ_NEXT(req, tq))
796 fatal("Unexpected reply %u", id);
799 case SSH2_FXP_STATUS:
800 status = buffer_get_int(&msg);
801 if (status != SSH2_FX_EOF)
804 TAILQ_REMOVE(&requests, req, tq);
809 data = buffer_get_string(&msg, &len);
810 debug3("Received data %llu -> %llu", req->offset,
811 req->offset + len - 1);
813 fatal("Received more data than asked for "
814 "%d > %d", len, req->len);
815 if ((lseek(local_fd, req->offset, SEEK_SET) == -1 ||
816 atomicio(write, local_fd, data, len) != len) &&
824 if (len == req->len) {
825 TAILQ_REMOVE(&requests, req, tq);
829 /* Resend the request for the missing data */
830 debug3("Short data block, re-requesting "
831 "%llu -> %llu (%2d)", req->offset + len,
832 req->offset + req->len - 1, num_req);
836 send_read_request(fd_out, req->id,
837 req->offset, req->len, handle,
839 /* Reduce the request size */
841 buflen = MAX(MIN_READ_SIZE, len);
843 if (max_req > 0) { /* max_req = 0 iff EOF received */
844 if (size > 0 && offset > size) {
845 /* Only one request at a time
846 * after the expected EOF */
847 debug3("Finish at %llu (%2d)",
851 else if (max_req < num_requests + 1) {
857 fatal("Expected SSH2_FXP_DATA(%d) packet, got %d",
858 SSH2_FXP_DATA, type);
863 if (TAILQ_FIRST(&requests) != NULL)
864 fatal("Transfer complete, but requests still in queue");
867 error("Couldn't read from remote "
868 "file \"%s\" : %s", remote_path,
870 do_close(fd_in, fd_out, handle, handle_len);
871 } else if (write_error) {
872 error("Couldn't write to \"%s\": %s", local_path,
873 strerror(write_errno));
875 do_close(fd_in, fd_out, handle, handle_len);
877 status = do_close(fd_in, fd_out, handle, handle_len);
879 /* Override umask and utimes if asked */
881 if (pflag && fchmod(local_fd, mode) == -1)
883 if (pflag && chmod(local_path, mode) == -1)
884 #endif /* HAVE_FCHMOD */
885 error("Couldn't set mode on \"%s\": %s", local_path,
887 if (pflag && (a->flags & SSH2_FILEXFER_ATTR_ACMODTIME)) {
888 struct timeval tv[2];
889 tv[0].tv_sec = a->atime;
890 tv[1].tv_sec = a->mtime;
891 tv[0].tv_usec = tv[1].tv_usec = 0;
892 if (utimes(local_path, tv) == -1)
893 error("Can't set times on \"%s\": %s",
894 local_path, strerror(errno));
904 do_upload(int fd_in, int fd_out, char *local_path, char *remote_path,
905 int pflag, size_t buflen, int num_requests)
907 int local_fd, status;
908 u_int handle_len, id;
917 if ((local_fd = open(local_path, O_RDONLY, 0)) == -1) {
918 error("Couldn't open local file \"%s\" for reading: %s",
919 local_path, strerror(errno));
922 if (fstat(local_fd, &sb) == -1) {
923 error("Couldn't fstat local file \"%s\": %s",
924 local_path, strerror(errno));
928 stat_to_attrib(&sb, &a);
930 a.flags &= ~SSH2_FILEXFER_ATTR_SIZE;
931 a.flags &= ~SSH2_FILEXFER_ATTR_UIDGID;
934 a.flags &= ~SSH2_FILEXFER_ATTR_ACMODTIME;
938 /* Send open request */
940 buffer_put_char(&msg, SSH2_FXP_OPEN);
941 buffer_put_int(&msg, id);
942 buffer_put_cstring(&msg, remote_path);
943 buffer_put_int(&msg, SSH2_FXF_WRITE|SSH2_FXF_CREAT|SSH2_FXF_TRUNC);
944 encode_attrib(&msg, &a);
945 send_msg(fd_out, &msg);
946 debug3("Sent message SSH2_FXP_OPEN I:%d P:%s", id, remote_path);
950 handle = get_handle(fd_in, id, &handle_len);
951 if (handle == NULL) {
957 startid = ackid = id + 1;
958 data = xmalloc(buflen);
960 /* Read from local and write to remote */
966 * Can't use atomicio here because it returns 0 on EOF, thus losing
967 * the last block of the file
970 len = read(local_fd, data, buflen);
971 while ((len == -1) && (errno == EINTR || errno == EAGAIN));
974 fatal("Couldn't read from \"%s\": %s", local_path,
979 buffer_put_char(&msg, SSH2_FXP_WRITE);
980 buffer_put_int(&msg, ++id);
981 buffer_put_string(&msg, handle, handle_len);
982 buffer_put_int64(&msg, offset);
983 buffer_put_string(&msg, data, len);
984 send_msg(fd_out, &msg);
985 debug3("Sent message SSH2_FXP_WRITE I:%d O:%llu S:%u",
986 id, (u_int64_t)offset, len);
987 } else if ( id < ackid )
990 if (id == startid || len == 0 ||
991 id - ackid >= num_requests) {
992 status = get_status(fd_in, ackid);
993 if (status != SSH2_FX_OK) {
994 error("Couldn't write to remote file \"%s\": %s",
995 remote_path, fx2txt(status));
996 do_close(fd_in, fd_out, handle, handle_len);
1000 debug3("In write loop, got %d offset %llu", len,
1009 if (close(local_fd) == -1) {
1010 error("Couldn't close local file \"%s\": %s", local_path,
1012 do_close(fd_in, fd_out, handle, handle_len);
1017 /* Override umask and utimes if asked */
1019 do_fsetstat(fd_in, fd_out, handle, handle_len, &a);
1021 status = do_close(fd_in, fd_out, handle, handle_len);