Ticket #2361: VFS URI reimplementation
[midnight-commander.git] / src / vfs / fish / fish.c
blob5666cbdbd054c1a32709af9a09ec550110176f0a
1 /* Virtual File System: FISH implementation for transfering files over
2 shell connections.
4 Copyright (C) 1998, 1999, 2000, 2001, 2002, 2003, 2004, 2005, 2006,
5 2007, 2008, 2009, 2010 Free Software Foundation, Inc.
7 Written by: 1998 Pavel Machek
8 Spaces fix: 2000 Michal Svec
9 2010 Andrew Borodin
10 2010 Slava Zanko
11 2010 Ilia Maslakov
13 Derived from ftpfs.c.
15 This program is free software; you can redistribute it and/or
16 modify it under the terms of the GNU Library General Public License
17 as published by the Free Software Foundation; either version 2 of
18 the License, or (at your option) any later version.
20 This program is distributed in the hope that it will be useful,
21 but WITHOUT ANY WARRANTY; without even the implied warranty of
22 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
23 GNU Library General Public License for more details.
25 You should have received a copy of the GNU Library General Public
26 License along with this program; if not, write to the Free Software
27 Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */
29 /**
30 * \file
31 * \brief Source: Virtual File System: FISH implementation for transfering files over
32 * shell connections
33 * \author Pavel Machek
34 * \author Michal Svec
35 * \date 1998, 2000
37 * Derived from ftpfs.c
38 * Read README.fish for protocol specification.
40 * Syntax of path is: \verbatim /#sh:user@host[:Cr]/path \endverbatim
41 * where C means you want compressed connection,
42 * and r means you want to use rsh
44 * Namespace: fish_vfs_ops exported.
47 /* Define this if your ssh can take -I option */
49 #include <config.h>
50 #include <errno.h>
51 #include <fcntl.h>
52 #include <pwd.h>
53 #include <grp.h>
54 #include <sys/time.h> /* gettimeofday() */
55 #include <stdlib.h>
56 #include <string.h>
57 #include <inttypes.h> /* uintmax_t */
59 #include "lib/global.h"
60 #include "lib/tty/tty.h" /* enable/disable interrupt key */
61 #include "lib/strescape.h"
62 #include "lib/unixcompat.h"
63 #include "lib/fileloc.h"
64 #include "lib/mcconfig.h"
66 #include "src/execute.h" /* pre_exec, post_exec */
68 #include "lib/vfs/vfs.h"
69 #include "lib/vfs/utilvfs.h"
70 #include "lib/vfs/netutil.h"
71 #include "lib/vfs/xdirentry.h"
72 #include "lib/vfs/gc.h" /* vfs_stamp_create */
74 #include "fish.h"
75 #include "fishdef.h"
77 /*** global variables ****************************************************************************/
79 int fish_directory_timeout = 900;
81 /*** file scope macro definitions ****************************************************************/
83 #define DO_RESOLVE_SYMLINK 1
84 #define DO_OPEN 2
85 #define DO_FREE_RESOURCE 4
87 #define FISH_FLAG_COMPRESSED 1
88 #define FISH_FLAG_RSH 2
90 #define OPT_FLUSH 1
91 #define OPT_IGNORE_ERROR 2
94 * Reply codes.
96 #define PRELIM 1 /* positive preliminary */
97 #define COMPLETE 2 /* positive completion */
98 #define CONTINUE 3 /* positive intermediate */
99 #define TRANSIENT 4 /* transient negative completion */
100 #define ERROR 5 /* permanent negative completion */
102 /* command wait_flag: */
103 #define NONE 0x00
104 #define WAIT_REPLY 0x01
105 #define WANT_STRING 0x02
107 /* environment flags */
108 #define FISH_HAVE_HEAD 1
109 #define FISH_HAVE_SED 2
110 #define FISH_HAVE_AWK 4
111 #define FISH_HAVE_PERL 8
112 #define FISH_HAVE_LSQ 16
113 #define FISH_HAVE_DATE_MDYT 32
114 #define FISH_HAVE_TAIL 64
116 #define SUP ((fish_super_data_t *) super->data)
118 /*** file scope type declarations ****************************************************************/
120 typedef struct
122 int sockr;
123 int sockw;
124 char *scr_ls;
125 char *scr_chmod;
126 char *scr_exists;
127 char *scr_mkdir;
128 char *scr_unlink;
129 char *scr_chown;
130 char *scr_rmdir;
131 char *scr_ln;
132 char *scr_mv;
133 char *scr_hardlink;
134 char *scr_get;
135 char *scr_send;
136 char *scr_append;
137 char *scr_info;
138 int host_flags;
139 char *scr_env;
140 } fish_super_data_t;
142 typedef struct
144 off_t got;
145 off_t total;
146 int append;
147 } fish_fh_data_t;
149 /*** file scope variables ************************************************************************/
151 static char reply_str[80];
153 static struct vfs_class vfs_fish_ops;
155 /*** file scope functions ************************************************************************/
156 /* --------------------------------------------------------------------------------------------- */
158 static char *
159 fish_load_script_from_file (const char *hostname, const char *script_name, const char *def_content)
161 char *scr_filename = NULL;
162 char *scr_content;
163 gsize scr_len = 0;
165 /* 1st: scan user directory */
166 scr_filename = g_build_path (PATH_SEP_STR, mc_config_get_data_path (), FISH_PREFIX, hostname,
167 script_name, (char *) NULL);
168 /* silent about user dir */
169 g_file_get_contents (scr_filename, &scr_content, &scr_len, NULL);
170 g_free (scr_filename);
171 /* 2nd: scan system dir */
172 if (scr_content == NULL)
174 scr_filename =
175 g_build_path (PATH_SEP_STR, LIBEXECDIR, FISH_PREFIX, script_name, (char *) NULL);
176 g_file_get_contents (scr_filename, &scr_content, &scr_len, NULL);
177 g_free (scr_filename);
180 if (scr_content != NULL)
181 return scr_content;
183 return g_strdup (def_content);
186 /* --------------------------------------------------------------------------------------------- */
188 static int
189 fish_decode_reply (char *s, int was_garbage)
191 int code;
192 if (!sscanf (s, "%d", &code))
194 code = 500;
195 return 5;
197 if (code < 100)
198 return was_garbage ? ERROR : (!code ? COMPLETE : PRELIM);
199 return code / 100;
202 /* --------------------------------------------------------------------------------------------- */
203 /* Returns a reply code, check /usr/include/arpa/ftp.h for possible values */
205 static int
206 fish_get_reply (struct vfs_class *me, int sock, char *string_buf, int string_len)
208 char answer[BUF_1K];
209 int was_garbage = 0;
211 for (;;)
213 if (!vfs_s_get_line (me, sock, answer, sizeof (answer), '\n'))
215 if (string_buf)
216 *string_buf = 0;
217 return 4;
220 if (strncmp (answer, "### ", 4))
222 was_garbage = 1;
223 if (string_buf)
224 g_strlcpy (string_buf, answer, string_len);
226 else
227 return fish_decode_reply (answer + 4, was_garbage);
231 /* --------------------------------------------------------------------------------------------- */
233 static int
234 fish_command (struct vfs_class *me, struct vfs_s_super *super, int wait_reply, const char *fmt, ...)
236 va_list ap;
237 char *str;
238 ssize_t status;
239 FILE *logfile = MEDATA->logfile;
241 va_start (ap, fmt);
243 str = g_strdup_vprintf (fmt, ap);
244 va_end (ap);
246 if (logfile)
248 size_t ret;
249 ret = fwrite (str, strlen (str), 1, logfile);
250 ret = fflush (logfile);
253 tty_enable_interrupt_key ();
255 status = write (SUP->sockw, str, strlen (str));
256 g_free (str);
258 tty_disable_interrupt_key ();
259 if (status < 0)
260 return TRANSIENT;
262 if (wait_reply)
263 return fish_get_reply (me, SUP->sockr,
264 (wait_reply & WANT_STRING) ? reply_str :
265 NULL, sizeof (reply_str) - 1);
266 return COMPLETE;
269 /* --------------------------------------------------------------------------------------------- */
271 static void
272 fish_free_archive (struct vfs_class *me, struct vfs_s_super *super)
274 if ((SUP->sockw != -1) || (SUP->sockr != -1))
276 vfs_print_message (_("fish: Disconnecting from %s"), super->name ? super->name : "???");
277 fish_command (me, super, NONE, "#BYE\nexit\n");
278 close (SUP->sockw);
279 close (SUP->sockr);
280 SUP->sockw = SUP->sockr = -1;
282 g_free (SUP->scr_ls);
283 g_free (SUP->scr_exists);
284 g_free (SUP->scr_mkdir);
285 g_free (SUP->scr_unlink);
286 g_free (SUP->scr_chown);
287 g_free (SUP->scr_chmod);
288 g_free (SUP->scr_rmdir);
289 g_free (SUP->scr_ln);
290 g_free (SUP->scr_mv);
291 g_free (SUP->scr_hardlink);
292 g_free (SUP->scr_get);
293 g_free (SUP->scr_send);
294 g_free (SUP->scr_append);
295 g_free (SUP->scr_info);
296 g_free (SUP->scr_env);
297 g_free (SUP);
298 super->data = NULL;
301 /* --------------------------------------------------------------------------------------------- */
303 static void
304 fish_pipeopen (struct vfs_s_super *super, const char *path, const char *argv[])
306 int fileset1[2], fileset2[2];
307 int res;
309 if ((pipe (fileset1) < 0) || (pipe (fileset2) < 0))
310 vfs_die ("Cannot pipe(): %m.");
312 res = fork ();
314 if (res != 0)
316 if (res < 0)
317 vfs_die ("Cannot fork(): %m.");
318 /* We are the parent */
319 close (fileset1[0]);
320 SUP->sockw = fileset1[1];
321 close (fileset2[1]);
322 SUP->sockr = fileset2[0];
324 else
326 res = dup2 (fileset1[0], 0);
327 close (fileset1[0]);
328 close (fileset1[1]);
329 res = dup2 (fileset2[1], 1);
330 close (2);
331 /* stderr to /dev/null */
332 res = open ("/dev/null", O_WRONLY);
333 close (fileset2[0]);
334 close (fileset2[1]);
335 execvp (path, const_cast (char **, argv));
336 _exit (3);
340 /* --------------------------------------------------------------------------------------------- */
342 static char *
343 fish_set_env (int flags)
345 GString *tmp;
347 tmp = g_string_sized_new (250);
348 g_string_assign (tmp, "");
350 if ((flags & FISH_HAVE_HEAD) != 0)
351 g_string_append (tmp, "FISH_HAVE_HEAD=1 export FISH_HAVE_HEAD; ");
353 if ((flags & FISH_HAVE_SED) != 0)
354 g_string_append (tmp, "FISH_HAVE_SED=1 export FISH_HAVE_SED; ");
356 if ((flags & FISH_HAVE_AWK) != 0)
357 g_string_append (tmp, "FISH_HAVE_AWK=1 export FISH_HAVE_AWK; ");
359 if ((flags & FISH_HAVE_PERL) != 0)
360 g_string_append (tmp, "FISH_HAVE_PERL=1 export FISH_HAVE_PERL; ");
362 if ((flags & FISH_HAVE_LSQ) != 0)
363 g_string_append (tmp, "FISH_HAVE_LSQ=1 export FISH_HAVE_LSQ; ");
365 if ((flags & FISH_HAVE_DATE_MDYT) != 0)
366 g_string_append (tmp, "FISH_HAVE_DATE_MDYT=1 export FISH_HAVE_DATE_MDYT; ");
368 if ((flags & FISH_HAVE_TAIL) != 0)
369 g_string_append (tmp, "FISH_HAVE_TAIL=1 export FISH_HAVE_TAIL; ");
371 return g_string_free (tmp, FALSE);
374 /* --------------------------------------------------------------------------------------------- */
376 static gboolean
377 fish_info (struct vfs_class *me, struct vfs_s_super *super)
379 char buffer[BUF_8K];
380 if (fish_command (me, super, NONE, SUP->scr_info) == COMPLETE)
382 while (TRUE)
384 int res;
386 res = vfs_s_get_line_interruptible (me, buffer, sizeof (buffer), SUP->sockr);
387 if ((res == 0) || (res == EINTR))
388 ERRNOR (ECONNRESET, FALSE);
389 if (strncmp (buffer, "### ", 4) == 0)
390 break;
391 SUP->host_flags = atol (buffer);
393 return TRUE;
395 ERRNOR (E_PROTO, FALSE);
399 /* --------------------------------------------------------------------------------------------- */
400 /* The returned directory should always contain a trailing slash */
402 static char *
403 fish_getcwd (struct vfs_class *me, struct vfs_s_super *super)
405 if (fish_command (me, super, WANT_STRING, "#PWD\npwd; echo '### 200'\n") == COMPLETE)
406 return g_strconcat (reply_str, "/", (char *) NULL);
407 ERRNOR (EIO, NULL);
411 /* --------------------------------------------------------------------------------------------- */
413 static void
414 fish_open_archive_pipeopen (struct vfs_s_super *super)
416 char gbuf[10];
417 const char *argv[10]; /* All of 10 is used now */
418 const char *xsh = (super->path_element->port == FISH_FLAG_RSH ? "rsh" : "ssh");
419 int i = 0;
421 argv[i++] = xsh;
422 if (super->path_element->port == FISH_FLAG_COMPRESSED)
423 argv[i++] = "-C";
425 if (super->path_element->port > FISH_FLAG_RSH)
427 argv[i++] = "-p";
428 g_snprintf (gbuf, sizeof (gbuf), "%d", super->path_element->port);
429 argv[i++] = gbuf;
433 * Add the user name to the ssh command line only if it was explicitly
434 * set in vfs URL. rsh/ssh will get current user by default
435 * plus we can set convenient overrides in ~/.ssh/config (explicit -l
436 * option breaks it for some)
439 if (super->path_element->user != NULL)
441 argv[i++] = "-l";
442 argv[i++] = super->path_element->user;
444 else
446 /* The rest of the code assumes it to be a valid username */
447 super->path_element->user = vfs_get_local_username ();
450 argv[i++] = super->path_element->host;
451 argv[i++] = "echo FISH:; /bin/sh";
452 argv[i++] = NULL;
454 fish_pipeopen (super, xsh, argv);
457 /* --------------------------------------------------------------------------------------------- */
459 static gboolean
460 fish_open_archive_talk (struct vfs_class *me, struct vfs_s_super *super)
462 char answer[2048];
464 printf ("\n%s\n", _("fish: Waiting for initial line..."));
466 if (!vfs_s_get_line (me, SUP->sockr, answer, sizeof (answer), ':'))
467 return FALSE;
469 if (strstr (answer, "assword") != NULL)
471 /* Currently, this does not work. ssh reads passwords from
472 /dev/tty, not from stdin :-(. */
474 printf ("\n%s\n", _("Sorry, we cannot do password authenticated connections for now."));
476 return FALSE;
477 #if 0
478 if (super->path_element->password == NULL)
480 char *p, *op;
481 p = g_strdup_printf (_("fish: Password is required for %s"), super->path_element->user);
482 op = vfs_get_password (p);
483 g_free (p);
484 if (op == NULL)
485 return FALSE;
486 super->path_element->password = op;
490 printf ("\n%s\n", _("fish: Sending password..."));
493 size_t str_len;
495 str_len = strlen (super->path_element->password);
496 if ((write (SUP.sockw, super->path_element->password, str_len) != (ssize_t) str_len)
497 || (write (SUP->sockw, "\n", 1) != 1))
498 return FALSE;
500 #endif
502 return TRUE;
505 /* --------------------------------------------------------------------------------------------- */
507 static int
508 fish_open_archive_int (struct vfs_class *me, struct vfs_s_super *super)
510 gboolean ftalk;
511 /* hide panels */
512 pre_exec ();
514 /* open pipe */
515 fish_open_archive_pipeopen (super);
517 /* Start talk with ssh-server (password prompt, etc ) */
518 ftalk = fish_open_archive_talk (me, super);
520 /* show panels */
521 post_exec ();
523 if (!ftalk)
524 ERRNOR (E_PROTO, -1);
526 vfs_print_message (_("fish: Sending initial line..."));
528 * Run `start_fish_server'. If it doesn't exist - no problem,
529 * we'll talk directly to the shell.
532 if (fish_command
533 (me, super, WAIT_REPLY,
534 "#FISH\necho; start_fish_server 2>&1; echo '### 200'\n") != COMPLETE)
535 ERRNOR (E_PROTO, -1);
537 vfs_print_message (_("fish: Handshaking version..."));
538 if (fish_command (me, super, WAIT_REPLY, "#VER 0.0.3\necho '### 000'\n") != COMPLETE)
539 ERRNOR (E_PROTO, -1);
541 /* Set up remote locale to C, otherwise dates cannot be recognized */
542 if (fish_command
543 (me, super, WAIT_REPLY,
544 "LANG=C LC_ALL=C LC_TIME=C; export LANG LC_ALL LC_TIME;\n" "echo '### 200'\n") != COMPLETE)
545 ERRNOR (E_PROTO, -1);
547 vfs_print_message (_("fish: Getting host info..."));
548 if (fish_info (me, super))
549 SUP->scr_env = fish_set_env (SUP->host_flags);
551 vfs_print_message (_("fish: Setting up current directory..."));
552 super->path_element->path = fish_getcwd (me, super);
553 vfs_print_message (_("fish: Connected, home %s."), super->path_element->path);
554 #if 0
555 super->name =
556 g_strconcat ("/#sh:", super->path_element->user, "@", super->path_element->host, "/",
557 (char *) NULL);
558 #else
559 super->name = g_strdup (PATH_SEP_STR);
560 #endif
562 super->root = vfs_s_new_inode (me, super, vfs_s_default_stat (me, S_IFDIR | 0755));
563 return 0;
566 /* --------------------------------------------------------------------------------------------- */
568 static int
569 fish_open_archive (struct vfs_s_super *super,
570 const vfs_path_t * vpath, const vfs_path_element_t * vpath_element)
572 (void) vpath;
574 super->data = g_new0 (fish_super_data_t, 1);
575 super->path_element = vfs_path_element_clone (vpath_element);
577 if (strncmp (vpath_element->vfs_prefix, "rsh", 3) == 0)
578 super->path_element->port = FISH_FLAG_RSH;
580 SUP->scr_ls =
581 fish_load_script_from_file (super->path_element->host, FISH_LS_FILE, FISH_LS_DEF_CONTENT);
582 SUP->scr_exists =
583 fish_load_script_from_file (super->path_element->host, FISH_EXISTS_FILE,
584 FISH_EXISTS_DEF_CONTENT);
585 SUP->scr_mkdir =
586 fish_load_script_from_file (super->path_element->host, FISH_MKDIR_FILE,
587 FISH_MKDIR_DEF_CONTENT);
588 SUP->scr_unlink =
589 fish_load_script_from_file (super->path_element->host, FISH_UNLINK_FILE,
590 FISH_UNLINK_DEF_CONTENT);
591 SUP->scr_chown =
592 fish_load_script_from_file (super->path_element->host, FISH_CHOWN_FILE,
593 FISH_CHOWN_DEF_CONTENT);
594 SUP->scr_chmod =
595 fish_load_script_from_file (super->path_element->host, FISH_CHMOD_FILE,
596 FISH_CHMOD_DEF_CONTENT);
597 SUP->scr_rmdir =
598 fish_load_script_from_file (super->path_element->host, FISH_RMDIR_FILE,
599 FISH_RMDIR_DEF_CONTENT);
600 SUP->scr_ln =
601 fish_load_script_from_file (super->path_element->host, FISH_LN_FILE, FISH_LN_DEF_CONTENT);
602 SUP->scr_mv =
603 fish_load_script_from_file (super->path_element->host, FISH_MV_FILE, FISH_MV_DEF_CONTENT);
604 SUP->scr_hardlink =
605 fish_load_script_from_file (super->path_element->host, FISH_HARDLINK_FILE,
606 FISH_HARDLINK_DEF_CONTENT);
607 SUP->scr_get =
608 fish_load_script_from_file (super->path_element->host, FISH_GET_FILE, FISH_GET_DEF_CONTENT);
609 SUP->scr_send =
610 fish_load_script_from_file (super->path_element->host, FISH_SEND_FILE,
611 FISH_SEND_DEF_CONTENT);
612 SUP->scr_append =
613 fish_load_script_from_file (super->path_element->host, FISH_APPEND_FILE,
614 FISH_APPEND_DEF_CONTENT);
615 SUP->scr_info =
616 fish_load_script_from_file (super->path_element->host, FISH_INFO_FILE,
617 FISH_INFO_DEF_CONTENT);
619 return fish_open_archive_int (vpath_element->class, super);
622 /* --------------------------------------------------------------------------------------------- */
624 static int
625 fish_archive_same (const vfs_path_element_t * vpath_element, struct vfs_s_super *super,
626 const vfs_path_t * vpath, void *cookie)
628 vfs_path_element_t *path_element;
629 int result;
631 (void) vpath;
632 (void) cookie;
634 path_element = vfs_path_element_clone (vpath_element);
636 if (path_element->user == NULL)
637 path_element->user = vfs_get_local_username ();
639 result = ((strcmp (path_element->host, super->path_element->host) == 0)
640 && (strcmp (path_element->user, super->path_element->user) == 0)
641 && (path_element->port == super->path_element->port)) ? 1 : 0;
643 vfs_path_element_free (path_element);
645 return result;
648 /* --------------------------------------------------------------------------------------------- */
650 static int
651 fish_dir_load (struct vfs_class *me, struct vfs_s_inode *dir, char *remote_path)
653 struct vfs_s_super *super = dir->super;
654 char buffer[8192];
655 struct vfs_s_entry *ent = NULL;
656 FILE *logfile;
657 char *quoted_path;
658 int reply_code;
659 gchar *shell_commands;
662 * Simple FISH debug interface :]
664 #if 0
665 if (!(MEDATA->logfile))
667 MEDATA->logfile = fopen ("/tmp/mc-FISH.sh", "w");
669 #endif
670 logfile = MEDATA->logfile;
672 vfs_print_message (_("fish: Reading directory %s..."), remote_path);
674 gettimeofday (&dir->timestamp, NULL);
675 dir->timestamp.tv_sec += fish_directory_timeout;
676 quoted_path = strutils_shell_escape (remote_path);
677 shell_commands = g_strconcat (SUP->scr_env, "FISH_FILENAME=%s;\n", SUP->scr_ls, (char *) NULL);
678 fish_command (me, super, NONE, shell_commands, quoted_path);
679 g_free (shell_commands);
680 g_free (quoted_path);
681 ent = vfs_s_generate_entry (me, NULL, dir, 0);
682 while (TRUE)
684 int res = vfs_s_get_line_interruptible (me, buffer, sizeof (buffer), SUP->sockr);
685 if ((!res) || (res == EINTR))
687 vfs_s_free_entry (me, ent);
688 me->verrno = ECONNRESET;
689 goto error;
691 if (logfile)
693 fputs (buffer, logfile);
694 fputs ("\n", logfile);
695 fflush (logfile);
697 if (!strncmp (buffer, "### ", 4))
698 break;
699 if ((!buffer[0]))
701 if (ent->name)
703 vfs_s_insert_entry (me, dir, ent);
704 ent = vfs_s_generate_entry (me, NULL, dir, 0);
706 continue;
709 #define ST ent->ino->st
711 switch (buffer[0])
713 case ':':
715 char *temp;
716 char *data_start = buffer + 1;
717 char *filename = data_start;
718 char *linkname = data_start;
719 char *filename_bound = filename + strlen (filename);
720 char *linkname_bound = filename_bound;
721 if (!strcmp (data_start, "\".\"") || !strcmp (data_start, "\"..\""))
722 break; /* We'll do "." and ".." ourselves */
724 if (S_ISLNK (ST.st_mode))
726 /* we expect: "escaped-name" -> "escaped-name"
727 // -> cannot occur in filenames,
728 // because it will be escaped to -\> */
730 if (*filename == '"')
731 ++filename;
733 linkname = strstr (filename, "\" -> \"");
734 if (!linkname)
736 /* broken client, or smth goes wrong */
737 linkname = filename_bound;
738 if (filename_bound > filename && *(filename_bound - 1) == '"')
739 --filename_bound; /* skip trailing " */
741 else
743 filename_bound = linkname;
744 linkname += 6; /* strlen ("\" -> \"") */
745 if (*(linkname_bound - 1) == '"')
746 --linkname_bound; /* skip trailing " */
749 ent->name = g_strndup (filename, filename_bound - filename);
750 temp = ent->name;
751 ent->name = strutils_shell_unescape (ent->name);
752 g_free (temp);
754 ent->ino->linkname = g_strndup (linkname, linkname_bound - linkname);
755 temp = ent->ino->linkname;
756 ent->ino->linkname = strutils_shell_unescape (ent->ino->linkname);
757 g_free (temp);
759 else
761 /* we expect: "escaped-name" */
762 if (filename_bound - filename > 2)
765 there is at least 2 "
766 and we skip them
768 if (*filename == '"')
769 ++filename;
770 if (*(filename_bound - 1) == '"')
771 --filename_bound;
773 ent->name = g_strndup (filename, filename_bound - filename);
774 temp = ent->name;
775 ent->name = strutils_shell_unescape (ent->name);
776 g_free (temp);
778 break;
780 case 'S':
781 #ifdef HAVE_ATOLL
782 ST.st_size = (off_t) atoll (buffer + 1);
783 #else
784 ST.st_size = (off_t) atof (buffer + 1);
785 #endif
786 break;
787 case 'P':
789 size_t skipped;
790 vfs_parse_filemode (buffer + 1, &skipped, &ST.st_mode);
791 break;
793 case 'R':
796 raw filemode:
797 we expect: Roctal-filemode octal-filetype uid.gid
799 size_t skipped;
800 vfs_parse_raw_filemode (buffer + 1, &skipped, &ST.st_mode);
801 break;
803 case 'd':
805 vfs_split_text (buffer + 1);
806 if (!vfs_parse_filedate (0, &ST.st_ctime))
807 break;
808 ST.st_atime = ST.st_mtime = ST.st_ctime;
810 break;
811 case 'D':
813 struct tm tim;
814 if (sscanf (buffer + 1, "%d %d %d %d %d %d", &tim.tm_year, &tim.tm_mon,
815 &tim.tm_mday, &tim.tm_hour, &tim.tm_min, &tim.tm_sec) != 6)
816 break;
817 ST.st_atime = ST.st_mtime = ST.st_ctime = mktime (&tim);
819 break;
820 case 'E':
822 int maj, min;
823 if (sscanf (buffer + 1, "%d,%d", &maj, &min) != 2)
824 break;
825 #ifdef HAVE_STRUCT_STAT_ST_RDEV
826 ST.st_rdev = makedev (maj, min);
827 #endif
832 vfs_s_free_entry (me, ent);
833 reply_code = fish_decode_reply (buffer + 4, 0);
834 if (reply_code == COMPLETE)
836 g_free (super->path_element->path);
837 super->path_element->path = g_strdup (remote_path);
838 vfs_print_message (_("%s: done."), me->name);
839 return 0;
842 me->verrno = reply_code == ERROR ? EACCES : E_REMOTE;
844 error:
845 vfs_print_message (_("%s: failure"), me->name);
846 return -1;
849 /* --------------------------------------------------------------------------------------------- */
851 static int
852 fish_file_store (struct vfs_class *me, vfs_file_handler_t * fh, char *name, char *localname)
854 fish_fh_data_t *fish = (fish_fh_data_t *) fh->data;
855 gchar *shell_commands = NULL;
856 struct vfs_s_super *super = FH_SUPER;
857 int n, total;
858 char buffer[8192];
859 struct stat s;
860 int was_error = 0;
861 int h;
862 char *quoted_name;
864 h = open (localname, O_RDONLY);
865 if (h == -1)
866 ERRNOR (EIO, -1);
867 if (fstat (h, &s) < 0)
869 close (h);
870 ERRNOR (EIO, -1);
873 /* First, try this as stor:
875 * ( head -c number ) | ( cat > file; cat >/dev/null )
877 * If `head' is not present on the remote system, `dd' will be used.
878 * Unfortunately, we cannot trust most non-GNU `head' implementations
879 * even if `-c' options is supported. Therefore, we separate GNU head
880 * (and other modern heads?) using `-q' and `-' . This causes another
881 * implementations to fail (because of "incorrect options").
883 * Fallback is:
885 * rest=<number>
886 * while [ $rest -gt 0 ]
887 * do
888 * cnt=`expr \( $rest + 255 \) / 256`
889 * n=`dd bs=256 count=$cnt | tee -a <target_file> | wc -c`
890 * rest=`expr $rest - $n`
891 * done
893 * `dd' was not designed for full filling of input buffers,
894 * and does not report exact number of bytes (not blocks).
895 * Therefore a more complex shell script is needed.
897 * On some systems non-GNU head writes "Usage:" error report to stdout
898 * instead of stderr. It makes impossible the use of "head || dd"
899 * algorithm for file appending case, therefore just "dd" is used for it.
902 quoted_name = strutils_shell_escape (name);
903 vfs_print_message (_("fish: store %s: sending command..."), quoted_name);
905 /* FIXME: File size is limited to ULONG_MAX */
906 if (!fish->append)
908 shell_commands =
909 g_strconcat (SUP->scr_env, "FISH_FILENAME=%s FISH_FILESIZE=%" PRIuMAX ";\n",
910 SUP->scr_append, (char *) NULL);
912 n = fish_command (me, super, WAIT_REPLY, shell_commands, quoted_name,
913 (uintmax_t) s.st_size);
914 g_free (shell_commands);
916 else
918 shell_commands =
919 g_strconcat (SUP->scr_env, "FISH_FILENAME=%s FISH_FILESIZE=%" PRIuMAX ";\n",
920 SUP->scr_send, (char *) NULL);
921 n = fish_command (me, super, WAIT_REPLY, shell_commands, quoted_name,
922 (uintmax_t) s.st_size);
923 g_free (shell_commands);
925 if (n != PRELIM)
927 close (h);
928 ERRNOR (E_REMOTE, -1);
931 total = 0;
933 while (TRUE)
935 int t;
936 while ((n = read (h, buffer, sizeof (buffer))) < 0)
938 if ((errno == EINTR) && tty_got_interrupt ())
939 continue;
940 vfs_print_message (_("fish: Local read failed, sending zeros"));
941 close (h);
942 h = open ("/dev/zero", O_RDONLY);
945 if (n == 0)
946 break;
948 t = write (SUP->sockw, buffer, n);
949 if (t != n)
951 if (t == -1)
952 me->verrno = errno;
953 else
954 me->verrno = EIO;
955 goto error_return;
957 tty_disable_interrupt_key ();
958 total += n;
959 vfs_print_message ("%s: %d/%" PRIuMAX,
960 was_error ? _("fish: storing zeros") : _("fish: storing file"),
961 total, (uintmax_t) s.st_size);
963 close (h);
964 g_free (quoted_name);
966 if ((fish_get_reply (me, SUP->sockr, NULL, 0) != COMPLETE) || was_error)
967 ERRNOR (E_REMOTE, -1);
968 return 0;
970 error_return:
971 close (h);
972 fish_get_reply (me, SUP->sockr, NULL, 0);
973 g_free (quoted_name);
974 return -1;
977 /* --------------------------------------------------------------------------------------------- */
979 static int
980 fish_linear_start (struct vfs_class *me, vfs_file_handler_t * fh, off_t offset)
982 fish_fh_data_t *fish;
983 gchar *shell_commands = NULL;
984 struct vfs_s_super *super = FH_SUPER;
985 char *name;
986 char *quoted_name;
988 if (fh->data == NULL)
989 fh->data = g_new0 (fish_fh_data_t, 1);
991 fish = (fish_fh_data_t *) fh->data;
993 name = vfs_s_fullpath (me, fh->ino);
994 if (name == NULL)
995 return 0;
996 quoted_name = strutils_shell_escape (name);
997 g_free (name);
998 fish->append = 0;
1001 * Check whether the remote file is readable by using `dd' to copy
1002 * a single byte from the remote file to /dev/null. If `dd' completes
1003 * with exit status of 0 use `cat' to send the file contents to the
1004 * standard output (i.e. over the network).
1007 shell_commands =
1008 g_strconcat (SUP->scr_env, "FISH_FILENAME=%s FISH_START_OFFSET=%" PRIuMAX ";\n",
1009 SUP->scr_get, (char *) NULL);
1010 offset = fish_command (me, super, WANT_STRING, shell_commands, quoted_name, (uintmax_t) offset);
1011 g_free (shell_commands);
1012 g_free (quoted_name);
1013 if (offset != PRELIM)
1014 ERRNOR (E_REMOTE, 0);
1015 fh->linear = LS_LINEAR_OPEN;
1016 fish->got = 0;
1017 errno = 0;
1018 #if SIZEOF_OFF_T == SIZEOF_LONG
1019 fish->total = (off_t) strtol (reply_str, NULL, 10);
1020 #else
1021 fish->total = (off_t) strtoll (reply_str, NULL, 10);
1022 #endif
1023 if (errno != 0)
1024 ERRNOR (E_REMOTE, 0);
1025 return 1;
1028 /* --------------------------------------------------------------------------------------------- */
1030 static void
1031 fish_linear_abort (struct vfs_class *me, vfs_file_handler_t * fh)
1033 fish_fh_data_t *fish = (fish_fh_data_t *) fh->data;
1034 struct vfs_s_super *super = FH_SUPER;
1035 char buffer[BUF_8K];
1036 int n;
1038 vfs_print_message (_("Aborting transfer..."));
1042 n = MIN (sizeof (buffer), (size_t) (fish->total - fish->got));
1043 if (n != 0)
1045 n = read (SUP->sockr, buffer, n);
1046 if (n < 0)
1047 return;
1048 fish->got += n;
1051 while (n != 0);
1053 if (fish_get_reply (me, SUP->sockr, NULL, 0) != COMPLETE)
1054 vfs_print_message (_("Error reported after abort."));
1055 else
1056 vfs_print_message (_("Aborted transfer would be successful."));
1059 /* --------------------------------------------------------------------------------------------- */
1061 static int
1062 fish_linear_read (struct vfs_class *me, vfs_file_handler_t * fh, void *buf, size_t len)
1064 fish_fh_data_t *fish = (fish_fh_data_t *) fh->data;
1065 struct vfs_s_super *super = FH_SUPER;
1066 ssize_t n = 0;
1069 len = MIN ((size_t) (fish->total - fish->got), len);
1070 tty_disable_interrupt_key ();
1071 while (len != 0 && ((n = read (SUP->sockr, buf, len)) < 0))
1073 if ((errno == EINTR) && !tty_got_interrupt ())
1074 continue;
1075 break;
1077 tty_enable_interrupt_key ();
1079 if (n > 0)
1080 fish->got += n;
1081 else if (n < 0)
1082 fish_linear_abort (me, fh);
1083 else if (fish_get_reply (me, SUP->sockr, NULL, 0) != COMPLETE)
1084 ERRNOR (E_REMOTE, -1);
1085 ERRNOR (errno, n);
1088 /* --------------------------------------------------------------------------------------------- */
1090 static void
1091 fish_linear_close (struct vfs_class *me, vfs_file_handler_t * fh)
1093 fish_fh_data_t *fish = (fish_fh_data_t *) fh->data;
1095 if (fish->total != fish->got)
1096 fish_linear_abort (me, fh);
1099 /* --------------------------------------------------------------------------------------------- */
1101 static int
1102 fish_ctl (void *fh, int ctlop, void *arg)
1104 (void) arg;
1105 (void) fh;
1106 (void) ctlop;
1107 return 0;
1108 #if 0
1109 switch (ctlop)
1111 case VFS_CTL_IS_NOTREADY:
1113 int v;
1115 if (!FH->linear)
1116 vfs_die ("You may not do this");
1117 if (FH->linear == LS_LINEAR_CLOSED || FH->linear == LS_LINEAR_PREOPEN)
1118 return 0;
1120 v = vfs_s_select_on_two (FH_SUPER->u.fish.sockr, 0);
1121 if (((v < 0) && (errno == EINTR)) || v == 0)
1122 return 1;
1123 return 0;
1125 default:
1126 return 0;
1128 #endif
1131 /* --------------------------------------------------------------------------------------------- */
1133 static int
1134 fish_send_command (struct vfs_class *me, struct vfs_s_super *super, const char *cmd, int flags)
1136 int r;
1138 r = fish_command (me, super, WAIT_REPLY, "%s", cmd);
1139 vfs_stamp_create (&vfs_fish_ops, super);
1140 if (r != COMPLETE)
1141 ERRNOR (E_REMOTE, -1);
1142 if (flags & OPT_FLUSH)
1143 vfs_s_invalidate (me, super);
1144 return 0;
1147 /* --------------------------------------------------------------------------------------------- */
1149 static int
1150 fish_rename (const vfs_path_t * vpath1, const vfs_path_t * vpath2)
1152 gchar *shell_commands = NULL;
1153 char buf[BUF_LARGE];
1154 const char *crpath1, *crpath2;
1155 char *rpath1, *rpath2;
1156 struct vfs_s_super *super, *super2;
1157 vfs_path_element_t *path_element = vfs_path_get_by_index (vpath1, -1);
1159 crpath1 = vfs_s_get_path (vpath1, &super, 0);
1160 if (crpath1 == NULL)
1161 return -1;
1163 crpath2 = vfs_s_get_path (vpath2, &super2, 0);
1164 if (crpath2 == NULL)
1165 return -1;
1167 rpath1 = strutils_shell_escape (crpath1);
1168 rpath2 = strutils_shell_escape (crpath2);
1169 shell_commands = g_strconcat (SUP->scr_env, "FISH_FILEFROM=%s FISH_FILETO=%s;\n",
1170 SUP->scr_mv, (char *) NULL);
1171 g_snprintf (buf, sizeof (buf), shell_commands, rpath1, rpath2);
1172 g_free (shell_commands);
1173 g_free (rpath1);
1174 g_free (rpath2);
1175 return fish_send_command (path_element->class, super2, buf, OPT_FLUSH);
1178 /* --------------------------------------------------------------------------------------------- */
1180 static int
1181 fish_link (const vfs_path_t * vpath1, const vfs_path_t * vpath2)
1183 gchar *shell_commands = NULL;
1184 char buf[BUF_LARGE];
1185 const char *crpath1, *crpath2;
1186 char *rpath1, *rpath2;
1187 struct vfs_s_super *super, *super2;
1188 vfs_path_element_t *path_element;
1191 path_element = vfs_path_get_by_index (vpath1, -1);
1193 crpath1 = vfs_s_get_path (vpath1, &super, 0);
1194 if (crpath1 == NULL)
1195 return -1;
1197 crpath2 = vfs_s_get_path (vpath2, &super2, 0);
1198 if (crpath2 == NULL)
1199 return -1;
1201 rpath1 = strutils_shell_escape (crpath1);
1202 rpath2 = strutils_shell_escape (crpath2);
1203 shell_commands = g_strconcat (SUP->scr_env, "FISH_FILEFROM=%s FISH_FILETO=%s;\n",
1204 SUP->scr_hardlink, (char *) NULL);
1205 g_snprintf (buf, sizeof (buf), shell_commands, rpath1, rpath2);
1206 g_free (shell_commands);
1207 g_free (rpath1);
1208 g_free (rpath2);
1209 return fish_send_command (path_element->class, super2, buf, OPT_FLUSH);
1213 /* --------------------------------------------------------------------------------------------- */
1215 static int
1216 fish_symlink (const vfs_path_t * vpath1, const vfs_path_t * vpath2)
1218 char *qsetto;
1219 gchar *shell_commands = NULL;
1220 char buf[BUF_LARGE];
1221 const char *crpath;
1222 char *rpath, *str_path;
1223 struct vfs_s_super *super;
1224 vfs_path_element_t *path_element = vfs_path_get_by_index (vpath1, -1);
1226 crpath = vfs_s_get_path (vpath2, &super, 0);
1227 if (crpath == NULL)
1228 return -1;
1229 rpath = strutils_shell_escape (crpath);
1231 str_path = vfs_path_to_str (vpath1);
1232 qsetto = strutils_shell_escape (str_path);
1233 g_free (str_path);
1235 shell_commands = g_strconcat (SUP->scr_env, "FISH_FILEFROM=%s FISH_FILETO=%s;\n",
1236 SUP->scr_ln, (char *) NULL);
1237 g_snprintf (buf, sizeof (buf), shell_commands, qsetto, rpath);
1238 g_free (shell_commands);
1239 g_free (qsetto);
1240 g_free (rpath);
1241 return fish_send_command (path_element->class, super, buf, OPT_FLUSH);
1244 /* --------------------------------------------------------------------------------------------- */
1246 static int
1247 fish_chmod (const vfs_path_t * vpath, mode_t mode)
1249 gchar *shell_commands = NULL;
1250 char buf[BUF_LARGE];
1251 const char *crpath;
1252 char *rpath;
1253 struct vfs_s_super *super;
1254 vfs_path_element_t *path_element;
1256 path_element = vfs_path_get_by_index (vpath, -1);
1258 crpath = vfs_s_get_path (vpath, &super, 0);
1259 if (crpath == NULL)
1260 return -1;
1261 rpath = strutils_shell_escape (crpath);
1263 shell_commands = g_strconcat (SUP->scr_env, "FISH_FILENAME=%s FISH_FILEMODE=%4.4o;\n",
1264 SUP->scr_chmod, (char *) NULL);
1265 g_snprintf (buf, sizeof (buf), shell_commands, rpath, (int) (mode & 07777));
1266 g_free (shell_commands);
1267 g_free (rpath);
1268 return fish_send_command (path_element->class, super, buf, OPT_FLUSH);
1271 /* --------------------------------------------------------------------------------------------- */
1273 static int
1274 fish_chown (const vfs_path_t * vpath, uid_t owner, gid_t group)
1276 char *sowner, *sgroup;
1277 struct passwd *pw;
1278 struct group *gr;
1280 pw = getpwuid (owner);
1281 if (pw == NULL)
1282 return 0;
1284 gr = getgrgid (group);
1285 if (gr == NULL)
1286 return 0;
1288 sowner = pw->pw_name;
1289 sgroup = gr->gr_name;
1292 gchar *shell_commands = NULL;
1293 char buf[BUF_LARGE];
1294 const char *crpath;
1295 char *rpath;
1296 struct vfs_s_super *super;
1297 vfs_path_element_t *path_element;
1299 path_element = vfs_path_get_by_index (vpath, -1);
1302 crpath = vfs_s_get_path (vpath, &super, 0);
1303 if (crpath == NULL)
1304 return -1;
1305 rpath = strutils_shell_escape (crpath);
1307 shell_commands = g_strconcat (SUP->scr_env,
1308 "FISH_FILENAME=%s FISH_FILEOWNER=%s FISH_FILEGROUP=%s;\n",
1309 SUP->scr_chown, (char *) NULL);
1310 g_snprintf (buf, sizeof (buf), shell_commands, rpath, sowner, sgroup);
1311 g_free (shell_commands);
1312 fish_send_command (path_element->class, super, buf, OPT_FLUSH);
1313 /* FIXME: what should we report if chgrp succeeds but chown fails? */
1314 /* fish_send_command(me, super, buf, OPT_FLUSH); */
1315 g_free (rpath);
1316 return fish_send_command (path_element->class, super, buf, OPT_FLUSH);
1320 /* --------------------------------------------------------------------------------------------- */
1322 static int
1323 fish_unlink (const vfs_path_t * vpath)
1325 gchar *shell_commands = NULL;
1327 char buf[BUF_LARGE];
1328 const char *crpath;
1329 char *rpath;
1330 struct vfs_s_super *super;
1331 vfs_path_element_t *path_element;
1333 path_element = vfs_path_get_by_index (vpath, -1);
1334 crpath = vfs_s_get_path (vpath, &super, 0);
1335 if (crpath == NULL)
1336 return -1;
1337 rpath = strutils_shell_escape (crpath);
1339 shell_commands =
1340 g_strconcat (SUP->scr_env, "FISH_FILENAME=%s;\n", SUP->scr_unlink, (char *) NULL);
1341 g_snprintf (buf, sizeof (buf), shell_commands, rpath);
1342 g_free (shell_commands);
1343 g_free (rpath);
1344 return fish_send_command (path_element->class, super, buf, OPT_FLUSH);
1347 /* --------------------------------------------------------------------------------------------- */
1349 static int
1350 fish_exists (const vfs_path_t * vpath)
1352 gchar *shell_commands = NULL;
1354 char buf[BUF_LARGE];
1355 const char *crpath;
1356 char *rpath;
1357 struct vfs_s_super *super;
1358 vfs_path_element_t *path_element;
1360 path_element = vfs_path_get_by_index (vpath, -1);
1361 crpath = vfs_s_get_path (vpath, &super, 0);
1362 if (crpath == NULL)
1363 return -1;
1364 rpath = strutils_shell_escape (crpath);
1366 shell_commands =
1367 g_strconcat (SUP->scr_env, "FISH_FILENAME=%s;\n", SUP->scr_exists, (char *) NULL);
1368 g_snprintf (buf, sizeof (buf), shell_commands, rpath);
1369 g_free (shell_commands);
1370 g_free (rpath);
1372 return (fish_send_command (path_element->class, super, buf, OPT_FLUSH) == 0) ? 1 : 0;
1375 /* --------------------------------------------------------------------------------------------- */
1377 static int
1378 fish_mkdir (const vfs_path_t * vpath, mode_t mode)
1380 gchar *shell_commands = NULL;
1381 int ret_code;
1382 char buf[BUF_LARGE];
1383 const char *crpath;
1384 char *rpath;
1385 struct vfs_s_super *super;
1386 vfs_path_element_t *path_element;
1388 (void) mode;
1390 path_element = vfs_path_get_by_index (vpath, -1);
1392 crpath = vfs_s_get_path (vpath, &super, 0);
1393 if (crpath == NULL)
1394 return -1;
1395 rpath = strutils_shell_escape (crpath);
1397 shell_commands =
1398 g_strconcat (SUP->scr_env, "FISH_FILENAME=%s;\n", SUP->scr_mkdir, (char *) NULL);
1399 g_snprintf (buf, sizeof (buf), shell_commands, rpath);
1400 g_free (shell_commands);
1402 g_free (rpath);
1403 ret_code = fish_send_command (path_element->class, super, buf, OPT_FLUSH);
1405 if (ret_code != 0)
1406 return ret_code;
1408 if (!fish_exists (vpath))
1410 path_element->class->verrno = EACCES;
1411 return -1;
1413 return 0;
1416 /* --------------------------------------------------------------------------------------------- */
1418 static int
1419 fish_rmdir (const vfs_path_t * vpath)
1421 gchar *shell_commands = NULL;
1422 char buf[BUF_LARGE];
1423 const char *crpath;
1424 char *rpath;
1425 struct vfs_s_super *super;
1426 vfs_path_element_t *path_element;
1428 path_element = vfs_path_get_by_index (vpath, -1);
1430 crpath = vfs_s_get_path (vpath, &super, 0);
1431 if (crpath == NULL)
1432 return -1;
1433 rpath = strutils_shell_escape (crpath);
1435 shell_commands =
1436 g_strconcat (SUP->scr_env, "FISH_FILENAME=%s;\n", SUP->scr_rmdir, (char *) NULL);
1437 g_snprintf (buf, sizeof (buf), shell_commands, rpath);
1438 g_free (shell_commands);
1439 g_free (rpath);
1440 return fish_send_command (path_element->class, super, buf, OPT_FLUSH);
1443 /* --------------------------------------------------------------------------------------------- */
1445 static int
1446 fish_fh_open (struct vfs_class *me, vfs_file_handler_t * fh, int flags, mode_t mode)
1448 fish_fh_data_t *fish;
1450 (void) mode;
1452 fh->data = g_new0 (fish_fh_data_t, 1);
1453 fish = (fish_fh_data_t *) fh->data;
1455 /* File will be written only, so no need to retrieve it */
1456 if (((flags & O_WRONLY) == O_WRONLY) && ((flags & (O_RDONLY | O_RDWR)) == 0))
1458 fish->append = flags & O_APPEND;
1459 if (!fh->ino->localname)
1461 int tmp_handle = vfs_mkstemps (&fh->ino->localname, me->name,
1462 fh->ino->ent->name);
1463 if (tmp_handle == -1)
1464 goto fail;
1465 close (tmp_handle);
1467 return 0;
1469 if (!fh->ino->localname && vfs_s_retrieve_file (me, fh->ino) == -1)
1470 goto fail;
1471 if (!fh->ino->localname)
1472 vfs_die ("retrieve_file failed to fill in localname");
1473 return 0;
1475 fail:
1476 g_free (fh->data);
1477 return -1;
1480 /* --------------------------------------------------------------------------------------------- */
1482 static int
1483 fish_fh_close (struct vfs_class *me, vfs_file_handler_t * fh)
1485 (void) me;
1487 g_free (fh->data);
1488 return 0;
1491 /* --------------------------------------------------------------------------------------------- */
1493 static void
1494 fish_fill_names (struct vfs_class *me, fill_names_f func)
1496 GList *iter;
1498 for (iter = MEDATA->supers; iter != NULL; iter = g_list_next (iter))
1500 const struct vfs_s_super *super = (const struct vfs_s_super *) iter->data;
1502 char *name;
1503 char gbuf[10];
1504 const char *flags = "";
1506 switch (super->path_element->port)
1508 case FISH_FLAG_RSH:
1509 flags = ":r";
1510 break;
1511 case FISH_FLAG_COMPRESSED:
1512 flags = ":C";
1513 break;
1514 default:
1515 if (super->path_element->port > FISH_FLAG_RSH)
1517 g_snprintf (gbuf, sizeof (gbuf), ":%d", super->path_element->port);
1518 flags = gbuf;
1520 break;
1523 name =
1524 g_strconcat (vfs_fish_ops.prefix, VFS_PATH_URL_DELIMITER,
1525 super->path_element->user, "@", super->path_element->host, flags, "/",
1526 super->path_element->path, (char *) NULL);
1527 func (name);
1528 g_free (name);
1532 /* --------------------------------------------------------------------------------------------- */
1534 static void *
1535 fish_open (const vfs_path_t * vpath, int flags, mode_t mode)
1538 sorry, i've places hack here
1539 cause fish don't able to open files with O_EXCL flag
1541 flags &= ~O_EXCL;
1542 return vfs_s_open (vpath, flags, mode);
1545 /* --------------------------------------------------------------------------------------------- */
1546 /*** public functions ****************************************************************************/
1547 /* --------------------------------------------------------------------------------------------- */
1549 void
1550 init_fish (void)
1552 static struct vfs_s_subclass fish_subclass;
1554 tcp_init ();
1556 fish_subclass.flags = VFS_S_REMOTE;
1557 fish_subclass.archive_same = fish_archive_same;
1558 fish_subclass.open_archive = fish_open_archive;
1559 fish_subclass.free_archive = fish_free_archive;
1560 fish_subclass.fh_open = fish_fh_open;
1561 fish_subclass.fh_close = fish_fh_close;
1562 fish_subclass.dir_load = fish_dir_load;
1563 fish_subclass.file_store = fish_file_store;
1564 fish_subclass.linear_start = fish_linear_start;
1565 fish_subclass.linear_read = fish_linear_read;
1566 fish_subclass.linear_close = fish_linear_close;
1568 vfs_s_init_class (&vfs_fish_ops, &fish_subclass);
1569 vfs_fish_ops.name = "fish";
1570 vfs_fish_ops.prefix = "sh";
1571 vfs_fish_ops.fill_names = fish_fill_names;
1572 vfs_fish_ops.chmod = fish_chmod;
1573 vfs_fish_ops.chown = fish_chown;
1574 vfs_fish_ops.open = fish_open;
1575 vfs_fish_ops.symlink = fish_symlink;
1576 vfs_fish_ops.link = fish_link;
1577 vfs_fish_ops.unlink = fish_unlink;
1578 vfs_fish_ops.rename = fish_rename;
1579 vfs_fish_ops.mkdir = fish_mkdir;
1580 vfs_fish_ops.rmdir = fish_rmdir;
1581 vfs_fish_ops.ctl = fish_ctl;
1582 vfs_register_class (&vfs_fish_ops);
1585 /* --------------------------------------------------------------------------------------------- */