20
20
You should have received a copy of the GNU Library General Public
21
21
License along with this program; if not, write to the Free Software
22
Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */
22
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */
153
157
static char *ftpfs_get_current_directory (struct vfs_class *me, struct vfs_s_super *super);
154
static int ftpfs_chdir_internal (struct vfs_class *me, struct vfs_s_super *super, char *remote_path);
158
static int ftpfs_chdir_internal (struct vfs_class *me, struct vfs_s_super *super, const char *remote_path);
155
159
static int ftpfs_command (struct vfs_class *me, struct vfs_s_super *super, int wait_reply, const char *fmt, ...)
156
160
__attribute__ ((format (printf, 4, 5)));
157
161
static int ftpfs_open_socket (struct vfs_class *me, struct vfs_s_super *super);
1295
ftpfs_file_store(struct vfs_class *me, struct vfs_s_fh *fh, char *name, char *localname)
1295
ftpfs_file_store (struct vfs_class *me, struct vfs_s_fh *fh, char *name,
1298
int h, sock, n_read, n_written;
1299
1300
#ifdef HAVE_STRUCT_LINGER_L_LINGER
1300
1301
struct linger li;
1304
1305
char buffer[8192];
1306
1308
struct vfs_s_super *super = FH_SUPER;
1308
h = open(localname, O_RDONLY);
1310
h = open (localname, O_RDONLY);
1312
sock = ftpfs_open_data_connection(me, super, fh->u.ftp.append ? "APPE" : "STOR", name, TYPE_BINARY, 0);
1314
ftpfs_open_data_connection (me, super,
1315
fh->u.ftp.append ? "APPE" : "STOR", name,
1317
if (sock < 0 || fstat (h, &s) == -1) {
1317
1321
#ifdef HAVE_STRUCT_LINGER_L_LINGER
1318
1322
li.l_onoff = 1;
1319
1323
li.l_linger = 120;
1320
setsockopt(sock, SOL_SOCKET, SO_LINGER, (char *) &li, sizeof(li));
1324
setsockopt (sock, SOL_SOCKET, SO_LINGER, (char *) &li, sizeof (li));
1322
setsockopt(sock, SOL_SOCKET, SO_LINGER, &flag_one, sizeof (flag_one));
1326
setsockopt (sock, SOL_SOCKET, SO_LINGER, &flag_one, sizeof (flag_one));
1326
enable_interrupt_key();
1330
enable_interrupt_key ();
1328
while ((n = read(h, buffer, sizeof(buffer))) < 0) {
1332
while ((n_read = read (h, buffer, sizeof (buffer))) == -1) {
1329
1333
if (errno == EINTR) {
1330
if (got_interrupt()) {
1334
if (got_interrupt ()) {
1331
1335
ftpfs_errno = EINTR;
1332
1336
goto error_return;
1337
1340
ftpfs_errno = errno;
1338
1341
goto error_return;
1342
while (write(sock, buffer, n) < 0) {
1343
if (errno == EINTR) {
1344
if (got_interrupt()) {
1345
ftpfs_errno = EINTR;
1347
while ((n_written = write (sock, w_buf, n_read)) != n_read) {
1348
if (n_written == -1) {
1349
if (errno == EINTR && !got_interrupt ()) {
1352
ftpfs_errno = errno;
1351
ftpfs_errno = errno;
1356
n_read -= n_written;
1355
print_vfs_message(_("ftpfs: storing file %lu (%lu)"),
1356
(unsigned long) total, (unsigned long) s.st_size);
1358
print_vfs_message (_("ftpfs: storing file %lu (%lu)"),
1359
(unsigned long) n_stored, (unsigned long) s.st_size);
1358
disable_interrupt_key();
1361
disable_interrupt_key ();
1361
1364
if (ftpfs_get_reply (me, SUP.sock, NULL, 0) != COMPLETE)
1365
disable_interrupt_key();
1368
ftpfs_get_reply(me, SUP.sock, NULL, 0);
1368
disable_interrupt_key ();
1371
ftpfs_get_reply (me, SUP.sock, NULL, 0);
1373
ftpfs_linear_start(struct vfs_class *me, struct vfs_s_fh *fh, int offset)
1376
ftpfs_linear_start (struct vfs_class *me, struct vfs_s_fh *fh, off_t offset)
1375
1378
char *name = vfs_s_fullpath (me, fh->ino);
1444
/* Warning: filename passed to this command is damaged */
1446
ftpfs_send_command(struct vfs_class *me, char *filename, char *cmd, int flags)
1448
ftpfs_send_command(struct vfs_class *me, const char *filename, const char *cmd, int flags)
1450
char *rpath, *p, *mpath = g_strdup(filename);
1449
1451
struct vfs_s_super *super;
1451
1453
int flush_directory_cache = (flags & OPT_FLUSH);
1453
if (!(rpath = vfs_s_get_path_mangle(me, filename, &super, 0)))
1455
if (!(rpath = vfs_s_get_path_mangle(me, mpath, &super, 0))) {
1455
1459
p = ftpfs_translate_path (me, super, rpath);
1456
1460
r = ftpfs_command (me, super, WAIT_REPLY, cmd, p);
1458
1462
vfs_stamp_create (&vfs_ftpfs_ops, super);
1459
1463
if (flags & OPT_IGNORE_ERROR)
1465
if (r != COMPLETE) {
1463
1470
if (flush_directory_cache)
1464
1471
vfs_s_invalidate(me, super);
1546
static int ftpfs_rename (struct vfs_class *me, char *path1, char *path2)
1554
static int ftpfs_rename (struct vfs_class *me, const char *path1, const char *path2)
1548
1556
ftpfs_send_command(me, path1, "RNFR /%s", OPT_FLUSH);
1549
1557
return ftpfs_send_command(me, path2, "RNTO /%s", OPT_FLUSH);
1552
static int ftpfs_mkdir (struct vfs_class *me, char *path, mode_t mode)
1560
static int ftpfs_mkdir (struct vfs_class *me, const char *path, mode_t mode)
1554
1562
return ftpfs_send_command(me, path, "MKD /%s", OPT_FLUSH);
1557
static int ftpfs_rmdir (struct vfs_class *me, char *path)
1565
static int ftpfs_rmdir (struct vfs_class *me, const char *path)
1559
1567
return ftpfs_send_command(me, path, "RMD /%s", OPT_FLUSH);
1656
ftpfs_fill_names (struct vfs_class *me, void (*func)(char *))
1664
ftpfs_fill_names (struct vfs_class *me, fill_names_f func)
1658
1666
struct vfs_s_super *super = MEDATA->supers;
1662
name = g_strconcat ("/#ftp:", SUP.user, "@", SUP.host, "/", SUP.cwdir, NULL);
1670
name = g_strconcat ("/#ftp:", SUP.user, "@", SUP.host, "/", SUP.cwdir, (char *) NULL);
1665
1673
super = super->next;