This source file includes following definitions.
- sftpfs_opendir
- sftpfs_readdir
- sftpfs_closedir
- sftpfs_mkdir
- sftpfs_rmdir
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27 #include <config.h>
28
29 #include <libssh2.h>
30 #include <libssh2_sftp.h>
31
32 #include "lib/global.h"
33 #include "lib/util.h"
34
35 #include "internal.h"
36
37
38
39
40
41
42
43 typedef struct
44 {
45 LIBSSH2_SFTP_HANDLE *handle;
46 sftpfs_super_t *super;
47 } sftpfs_dir_data_t;
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65 void *
66 sftpfs_opendir (const vfs_path_t *vpath, GError **mcerror)
67 {
68 sftpfs_dir_data_t *sftpfs_dir;
69 sftpfs_super_t *sftpfs_super;
70 const vfs_path_element_t *path_element;
71 LIBSSH2_SFTP_HANDLE *handle = NULL;
72 const GString *fixfname;
73
74 if (!sftpfs_op_init (&sftpfs_super, &path_element, vpath, mcerror))
75 return NULL;
76
77 fixfname = sftpfs_fix_filename (path_element->path);
78
79 while (TRUE)
80 {
81 int libssh_errno;
82
83 handle = libssh2_sftp_open_ex (sftpfs_super->sftp_session, fixfname->str, fixfname->len, 0,
84 0, LIBSSH2_SFTP_OPENDIR);
85 if (handle != NULL)
86 break;
87
88 libssh_errno = libssh2_session_last_errno (sftpfs_super->session);
89 if (!sftpfs_waitsocket (sftpfs_super, libssh_errno, mcerror))
90 return NULL;
91 }
92
93 sftpfs_dir = g_new0 (sftpfs_dir_data_t, 1);
94 sftpfs_dir->handle = handle;
95 sftpfs_dir->super = sftpfs_super;
96
97 return (void *) sftpfs_dir;
98 }
99
100
101
102
103
104
105
106
107
108
109 struct vfs_dirent *
110 sftpfs_readdir (void *data, GError **mcerror)
111 {
112 char mem[BUF_MEDIUM];
113 LIBSSH2_SFTP_ATTRIBUTES attrs;
114 sftpfs_dir_data_t *sftpfs_dir = (sftpfs_dir_data_t *) data;
115 int rc;
116
117 mc_return_val_if_error (mcerror, NULL);
118
119 do
120 {
121 rc = libssh2_sftp_readdir (sftpfs_dir->handle, mem, sizeof (mem), &attrs);
122 if (rc >= 0)
123 break;
124
125 if (!sftpfs_waitsocket (sftpfs_dir->super, rc, mcerror))
126 return NULL;
127 }
128 while (rc == LIBSSH2_ERROR_EAGAIN);
129
130 return (rc != 0 ? vfs_dirent_init (NULL, mem, 0) : NULL);
131 }
132
133
134
135
136
137
138
139
140
141
142 int
143 sftpfs_closedir (void *data, GError **mcerror)
144 {
145 int rc;
146 sftpfs_dir_data_t *sftpfs_dir = (sftpfs_dir_data_t *) data;
147
148 mc_return_val_if_error (mcerror, -1);
149
150 rc = libssh2_sftp_closedir (sftpfs_dir->handle);
151 g_free (sftpfs_dir);
152 return rc;
153 }
154
155
156
157
158
159
160
161
162
163
164
165 int
166 sftpfs_mkdir (const vfs_path_t *vpath, mode_t mode, GError **mcerror)
167 {
168 int res;
169 sftpfs_super_t *sftpfs_super;
170 const vfs_path_element_t *path_element;
171 const GString *fixfname;
172
173 if (!sftpfs_op_init (&sftpfs_super, &path_element, vpath, mcerror))
174 return -1;
175
176 fixfname = sftpfs_fix_filename (path_element->path);
177
178 do
179 {
180 res =
181 libssh2_sftp_mkdir_ex (sftpfs_super->sftp_session, fixfname->str, fixfname->len, mode);
182 if (res >= 0)
183 break;
184
185 if (!sftpfs_waitsocket (sftpfs_super, res, mcerror))
186 return -1;
187 }
188 while (res == LIBSSH2_ERROR_EAGAIN);
189
190 return res;
191 }
192
193
194
195
196
197
198
199
200
201
202 int
203 sftpfs_rmdir (const vfs_path_t *vpath, GError **mcerror)
204 {
205 int res;
206 sftpfs_super_t *sftpfs_super;
207 const vfs_path_element_t *path_element;
208 const GString *fixfname;
209
210 if (!sftpfs_op_init (&sftpfs_super, &path_element, vpath, mcerror))
211 return -1;
212
213 fixfname = sftpfs_fix_filename (path_element->path);
214
215 do
216 {
217 res = libssh2_sftp_rmdir_ex (sftpfs_super->sftp_session, fixfname->str, fixfname->len);
218 if (res >= 0)
219 break;
220
221 if (!sftpfs_waitsocket (sftpfs_super, res, mcerror))
222 return -1;
223 }
224 while (res == LIBSSH2_ERROR_EAGAIN);
225
226 return res;
227 }
228
229