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;
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 =
84 libssh2_sftp_open_ex (sftpfs_super->sftp_session, fixfname->str, fixfname->len, 0, 0,
85 LIBSSH2_SFTP_OPENDIR);
86 if (handle != NULL)
87 break;
88
89 libssh_errno = libssh2_session_last_errno (sftpfs_super->session);
90 if (!sftpfs_waitsocket (sftpfs_super, libssh_errno, mcerror))
91 return NULL;
92 }
93
94 sftpfs_dir = g_new0 (sftpfs_dir_data_t, 1);
95 sftpfs_dir->handle = handle;
96 sftpfs_dir->super = sftpfs_super;
97
98 return (void *) sftpfs_dir;
99 }
100
101
102
103
104
105
106
107
108
109
110 struct vfs_dirent *
111 sftpfs_readdir (void *data, GError **mcerror)
112 {
113 char mem[BUF_MEDIUM];
114 LIBSSH2_SFTP_ATTRIBUTES attrs;
115 sftpfs_dir_data_t *sftpfs_dir = (sftpfs_dir_data_t *) data;
116 int rc;
117
118 mc_return_val_if_error (mcerror, NULL);
119
120 do
121 {
122 rc = libssh2_sftp_readdir (sftpfs_dir->handle, mem, sizeof (mem), &attrs);
123 if (rc >= 0)
124 break;
125
126 if (!sftpfs_waitsocket (sftpfs_dir->super, rc, mcerror))
127 return NULL;
128 }
129 while (rc == LIBSSH2_ERROR_EAGAIN);
130
131 return (rc != 0 ? vfs_dirent_init (NULL, mem, 0) : NULL);
132 }
133
134
135
136
137
138
139
140
141
142
143 int
144 sftpfs_closedir (void *data, GError **mcerror)
145 {
146 int rc;
147 sftpfs_dir_data_t *sftpfs_dir = (sftpfs_dir_data_t *) data;
148
149 mc_return_val_if_error (mcerror, -1);
150
151 rc = libssh2_sftp_closedir (sftpfs_dir->handle);
152 g_free (sftpfs_dir);
153 return rc;
154 }
155
156
157
158
159
160
161
162
163
164
165
166 int
167 sftpfs_mkdir (const vfs_path_t *vpath, mode_t mode, GError **mcerror)
168 {
169 int res;
170 sftpfs_super_t *sftpfs_super;
171 const vfs_path_element_t *path_element;
172 const GString *fixfname;
173
174 if (!sftpfs_op_init (&sftpfs_super, &path_element, vpath, mcerror))
175 return -1;
176
177 fixfname = sftpfs_fix_filename (path_element->path);
178
179 do
180 {
181 res =
182 libssh2_sftp_mkdir_ex (sftpfs_super->sftp_session, fixfname->str, fixfname->len, mode);
183 if (res >= 0)
184 break;
185
186 if (!sftpfs_waitsocket (sftpfs_super, res, mcerror))
187 return -1;
188 }
189 while (res == LIBSSH2_ERROR_EAGAIN);
190
191 return res;
192 }
193
194
195
196
197
198
199
200
201
202
203 int
204 sftpfs_rmdir (const vfs_path_t *vpath, GError **mcerror)
205 {
206 int res;
207 sftpfs_super_t *sftpfs_super;
208 const vfs_path_element_t *path_element;
209 const GString *fixfname;
210
211 if (!sftpfs_op_init (&sftpfs_super, &path_element, vpath, mcerror))
212 return -1;
213
214 fixfname = sftpfs_fix_filename (path_element->path);
215
216 do
217 {
218 res = libssh2_sftp_rmdir_ex (sftpfs_super->sftp_session, fixfname->str, fixfname->len);
219 if (res >= 0)
220 break;
221
222 if (!sftpfs_waitsocket (sftpfs_super, res, mcerror))
223 return -1;
224 }
225 while (res == LIBSSH2_ERROR_EAGAIN);
226
227 return res;
228 }
229
230