Add $ and ` for escaping and reorder it according to the ascii values
[midnight-commander.git] / vfs / vfs.c
blob21b5404a37ee5dc0ade82109fbe3ae0047847c52
1 /* Virtual File System switch code
2 Copyright (C) 1995, 1998, 1999, 2000, 2001, 2002, 2003, 2004, 2005,
3 2007 Free Software Foundation, Inc.
5 Written by: 1995 Miguel de Icaza
6 1995 Jakub Jelinek
7 1998 Pavel Machek
9 This program is free software; you can redistribute it and/or
10 modify it under the terms of the GNU Library General Public License
11 as published by the Free Software Foundation; either version 2 of
12 the License, or (at your option) any later version.
14 This program is distributed in the hope that it will be useful,
15 but WITHOUT ANY WARRANTY; without even the implied warranty of
16 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 GNU Library General Public License for more details.
19 You should have received a copy of the GNU Library General Public
20 License along with this program; if not, write to the Free Software
21 Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */
23 /* Warning: funtions like extfs_lstat() have right to destroy any
24 * strings you pass to them. This is acutally ok as you g_strdup what
25 * you are passing to them, anyway; still, beware. */
27 /* Namespace: exports *many* functions with vfs_ prefix; exports
28 parse_ls_lga and friends which do not have that prefix. */
30 #include <config.h>
32 #include <stdio.h>
33 #include <stdlib.h> /* For atol() */
34 #include <stdarg.h>
35 #include <string.h>
36 #include <errno.h>
37 #include <sys/types.h>
38 #include <signal.h>
39 #include <ctype.h> /* is_digit() */
41 #include "../src/global.h"
42 #include "../src/tty.h" /* enable/disable interrupt key */
43 #include "../src/wtools.h" /* message() */
44 #include "../src/main.h" /* print_vfs_message */
45 #include "utilvfs.h"
46 #include "gc.h"
48 #include "vfs.h"
49 #ifdef USE_NETCODE
50 # include "tcputil.h"
51 #endif
52 #include "ftpfs.h"
53 #include "mcfs.h"
54 #include "smbfs.h"
55 #include "local.h"
57 /* They keep track of the current directory */
58 static struct vfs_class *current_vfs;
59 static char *current_dir;
61 struct vfs_openfile {
62 int handle;
63 struct vfs_class *vclass;
64 void *fsinfo;
67 static GSList *vfs_openfiles;
68 #define VFS_FIRST_HANDLE 100
70 static struct vfs_class *localfs_class;
72 /* Create new VFS handle and put it to the list */
73 static int
74 vfs_new_handle (struct vfs_class *vclass, void *fsinfo)
76 static int vfs_handle_counter = VFS_FIRST_HANDLE;
77 struct vfs_openfile *h;
79 h = g_new (struct vfs_openfile, 1);
80 h->handle = vfs_handle_counter++;
81 h->fsinfo = fsinfo;
82 h->vclass = vclass;
83 vfs_openfiles = g_slist_prepend (vfs_openfiles, h);
84 return h->handle;
87 /* Function to match handle, passed to g_slist_find_custom() */
88 static gint
89 vfs_cmp_handle (gconstpointer a, gconstpointer b)
91 if (!a)
92 return 1;
93 return ((struct vfs_openfile *) a)->handle != (long) b;
96 /* Find VFS class by file handle */
97 static inline struct vfs_class *
98 vfs_op (int handle)
100 GSList *l;
101 struct vfs_openfile *h;
103 l = g_slist_find_custom (vfs_openfiles, (void *) (long) handle,
104 vfs_cmp_handle);
105 if (!l)
106 return NULL;
107 h = (struct vfs_openfile *) l->data;
108 if (!h)
109 return NULL;
110 return h->vclass;
113 /* Find private file data by file handle */
114 static inline void *
115 vfs_info (int handle)
117 GSList *l;
118 struct vfs_openfile *h;
120 l = g_slist_find_custom (vfs_openfiles, (void *) (long) handle,
121 vfs_cmp_handle);
122 if (!l)
123 return NULL;
124 h = (struct vfs_openfile *) l->data;
125 if (!h)
126 return NULL;
127 return h->fsinfo;
130 /* Free open file data for given file handle */
131 static inline void
132 vfs_free_handle (int handle)
134 GSList *l;
136 l = g_slist_find_custom (vfs_openfiles, (void *) (long) handle,
137 vfs_cmp_handle);
138 vfs_openfiles = g_slist_delete_link (vfs_openfiles, l);
141 static struct vfs_class *vfs_list;
144 vfs_register_class (struct vfs_class *vfs)
146 if (vfs->init) /* vfs has own initialization function */
147 if (!(*vfs->init)(vfs)) /* but it failed */
148 return 0;
150 vfs->next = vfs_list;
151 vfs_list = vfs;
153 return 1;
156 /* Return VFS class for the given prefix */
157 static struct vfs_class *
158 vfs_prefix_to_class (char *prefix)
160 struct vfs_class *vfs;
162 /* Avoid last class (localfs) that would accept any prefix */
163 for (vfs = vfs_list; vfs->next; vfs = vfs->next) {
164 if (vfs->which) {
165 if ((*vfs->which) (vfs, prefix) == -1)
166 continue;
167 return vfs;
169 if (vfs->prefix
170 && !strncmp (prefix, vfs->prefix, strlen (vfs->prefix)))
171 return vfs;
173 return NULL;
176 /* Strip known vfs suffixes from a filename (possible improvement: strip
177 suffix from last path component).
178 Returns a malloced string which has to be freed. */
179 char *
180 vfs_strip_suffix_from_filename (const char *filename)
182 struct vfs_class *vfs;
183 char *semi;
184 char *p;
186 if (!filename)
187 vfs_die ("vfs_strip_suffix_from_path got NULL: impossible");
189 p = g_strdup (filename);
190 if (!(semi = strrchr (p, '#')))
191 return p;
193 /* Avoid last class (localfs) that would accept any prefix */
194 for (vfs = vfs_list; vfs->next; vfs = vfs->next) {
195 if (vfs->which) {
196 if ((*vfs->which) (vfs, semi + 1) == -1)
197 continue;
198 *semi = '\0'; /* Found valid suffix */
199 return p;
201 if (vfs->prefix
202 && !strncmp (semi + 1, vfs->prefix, strlen (vfs->prefix))) {
203 *semi = '\0'; /* Found valid suffix */
204 return p;
207 return p;
210 static inline int
211 path_magic (const char *path)
213 struct stat buf;
215 if (!stat(path, &buf))
216 return 0;
218 return 1;
222 * Splits path '/p1#op/inpath' into inpath,op; returns which vfs it is.
223 * What is left in path is p1. You still want to g_free(path), you DON'T
224 * want to free neither *inpath nor *op
226 struct vfs_class *
227 vfs_split (char *path, char **inpath, char **op)
229 char *semi;
230 char *slash;
231 struct vfs_class *ret;
233 if (!path)
234 vfs_die("Cannot split NULL");
236 semi = strrchr (path, '#');
237 if (!semi || !path_magic(path))
238 return NULL;
240 slash = strchr (semi, PATH_SEP);
241 *semi = 0;
243 if (op)
244 *op = NULL;
246 if (inpath)
247 *inpath = NULL;
249 if (slash)
250 *slash = 0;
252 if ((ret = vfs_prefix_to_class (semi+1))){
253 if (op)
254 *op = semi + 1;
255 if (inpath)
256 *inpath = slash ? slash + 1 : NULL;
257 return ret;
261 if (slash)
262 *slash = PATH_SEP;
263 ret = vfs_split (path, inpath, op);
264 *semi = '#';
265 return ret;
268 static struct vfs_class *
269 _vfs_get_class (char *path)
271 char *semi;
272 char *slash;
273 struct vfs_class *ret;
275 g_return_val_if_fail(path, NULL);
277 semi = strrchr (path, '#');
278 if (!semi || !path_magic (path))
279 return NULL;
281 slash = strchr (semi, PATH_SEP);
282 *semi = 0;
283 if (slash)
284 *slash = 0;
286 ret = vfs_prefix_to_class (semi+1);
288 if (slash)
289 *slash = PATH_SEP;
290 if (!ret)
291 ret = _vfs_get_class (path);
293 *semi = '#';
294 return ret;
297 struct vfs_class *
298 vfs_get_class (const char *pathname)
300 struct vfs_class *vfs;
301 char *path = g_strdup (pathname);
303 vfs = _vfs_get_class (path);
304 g_free (path);
306 if (!vfs)
307 vfs = localfs_class;
309 return vfs;
312 static int
313 ferrno (struct vfs_class *vfs)
315 return vfs->ferrno ? (*vfs->ferrno)(vfs) : E_UNKNOWN;
316 /* Hope that error message is obscure enough ;-) */
320 mc_open (const char *filename, int flags, ...)
322 int mode;
323 void *info;
324 va_list ap;
326 char *file = vfs_canon (filename);
327 struct vfs_class *vfs = vfs_get_class (file);
329 /* Get the mode flag */
330 if (flags & O_CREAT) {
331 va_start (ap, flags);
332 mode = va_arg (ap, int);
333 va_end (ap);
334 } else
335 mode = 0;
337 if (!vfs->open) {
338 g_free (file);
339 errno = -EOPNOTSUPP;
340 return -1;
343 info = (*vfs->open) (vfs, file, flags, mode); /* open must be supported */
344 g_free (file);
345 if (!info){
346 errno = ferrno (vfs);
347 return -1;
350 return vfs_new_handle (vfs, info);
354 #define MC_NAMEOP(name, inarg, callarg) \
355 int mc_##name inarg \
357 struct vfs_class *vfs; \
358 int result; \
359 char *mpath = vfs_canon (path); \
360 vfs = vfs_get_class (mpath); \
361 result = vfs->name ? (*vfs->name)callarg : -1; \
362 g_free (mpath); \
363 if (result == -1) \
364 errno = vfs->name ? ferrno (vfs) : E_NOTSUPP; \
365 return result; \
368 MC_NAMEOP (chmod, (const char *path, mode_t mode), (vfs, mpath, mode))
369 MC_NAMEOP (chown, (const char *path, uid_t owner, gid_t group), (vfs, mpath, owner, group))
370 MC_NAMEOP (utime, (const char *path, struct utimbuf *times), (vfs, mpath, times))
371 MC_NAMEOP (readlink, (const char *path, char *buf, int bufsiz), (vfs, mpath, buf, bufsiz))
372 MC_NAMEOP (unlink, (const char *path), (vfs, mpath))
373 MC_NAMEOP (symlink, (const char *name1, const char *path), (vfs, name1, mpath))
374 MC_NAMEOP (mkdir, (const char *path, mode_t mode), (vfs, mpath, mode))
375 MC_NAMEOP (rmdir, (const char *path), (vfs, mpath))
376 MC_NAMEOP (mknod, (const char *path, mode_t mode, dev_t dev), (vfs, mpath, mode, dev))
379 #define MC_HANDLEOP(name, inarg, callarg) \
380 int mc_##name inarg \
382 struct vfs_class *vfs; \
383 int result; \
384 if (handle == -1) \
385 return -1; \
386 vfs = vfs_op (handle); \
387 result = vfs->name ? (*vfs->name)callarg : -1; \
388 if (result == -1) \
389 errno = vfs->name ? ferrno (vfs) : E_NOTSUPP; \
390 return result; \
393 MC_HANDLEOP(read, (int handle, void *buffer, int count), (vfs_info (handle), buffer, count) )
394 MC_HANDLEOP (write, (int handle, const void *buf, int nbyte), (vfs_info (handle), buf, nbyte))
397 #define MC_RENAMEOP(name) \
398 int mc_##name (const char *fname1, const char *fname2) \
400 struct vfs_class *vfs; \
401 int result; \
402 char *name2, *name1 = vfs_canon (fname1); \
403 vfs = vfs_get_class (name1); \
404 name2 = vfs_canon (fname2); \
405 if (vfs != vfs_get_class (name2)){ \
406 errno = EXDEV; \
407 g_free (name1); \
408 g_free (name2); \
409 return -1; \
411 result = vfs->name ? (*vfs->name)(vfs, name1, name2) : -1; \
412 g_free (name1); \
413 g_free (name2); \
414 if (result == -1) \
415 errno = vfs->name ? ferrno (vfs) : E_NOTSUPP; \
416 return result; \
419 MC_RENAMEOP (link)
420 MC_RENAMEOP (rename)
424 mc_ctl (int handle, int ctlop, void *arg)
426 struct vfs_class *vfs = vfs_op (handle);
428 return vfs->ctl ? (*vfs->ctl)(vfs_info (handle), ctlop, arg) : 0;
432 mc_setctl (const char *path, int ctlop, void *arg)
434 struct vfs_class *vfs;
435 int result;
436 char *mpath;
438 if (!path)
439 vfs_die("You don't want to pass NULL to mc_setctl.");
441 mpath = vfs_canon (path);
442 vfs = vfs_get_class (mpath);
443 result = vfs->setctl ? (*vfs->setctl)(vfs, mpath, ctlop, arg) : 0;
444 g_free (mpath);
445 return result;
449 mc_close (int handle)
451 struct vfs_class *vfs;
452 int result;
454 if (handle == -1 || !vfs_info (handle))
455 return -1;
457 vfs = vfs_op (handle);
458 if (handle < 3)
459 return close (handle);
461 if (!vfs->close)
462 vfs_die ("VFS must support close.\n");
463 result = (*vfs->close)(vfs_info (handle));
464 vfs_free_handle (handle);
465 if (result == -1)
466 errno = ferrno (vfs);
468 return result;
471 DIR *
472 mc_opendir (const char *dirname)
474 int handle, *handlep;
475 void *info;
476 struct vfs_class *vfs;
477 char *dname;
479 dname = vfs_canon (dirname);
480 vfs = vfs_get_class (dname);
482 info = vfs->opendir ? (*vfs->opendir)(vfs, dname) : NULL;
483 g_free (dname);
484 if (!info){
485 errno = vfs->opendir ? ferrno (vfs) : E_NOTSUPP;
486 return NULL;
488 handle = vfs_new_handle (vfs, info);
490 handlep = g_new (int, 1);
491 *handlep = handle;
492 return (DIR *) handlep;
495 struct dirent *
496 mc_readdir (DIR *dirp)
498 int handle;
499 struct vfs_class *vfs;
500 struct dirent *result = NULL;
502 if (!dirp) {
503 errno = EFAULT;
504 return NULL;
506 handle = *(int *) dirp;
507 vfs = vfs_op (handle);
508 if (vfs->readdir)
509 result = (*vfs->readdir) (vfs_info (handle));
510 if (!result)
511 errno = vfs->readdir ? ferrno (vfs) : E_NOTSUPP;
512 return result;
516 mc_closedir (DIR *dirp)
518 int handle = *(int *) dirp;
519 struct vfs_class *vfs = vfs_op (handle);
520 int result;
522 result = vfs->closedir ? (*vfs->closedir)(vfs_info (handle)) : -1;
523 vfs_free_handle (handle);
524 g_free (dirp);
525 return result;
528 int mc_stat (const char *filename, struct stat *buf) {
529 struct vfs_class *vfs;
530 int result;
531 char *path;
532 path = vfs_canon (filename); vfs = vfs_get_class (path);
533 result = vfs->stat ? (*vfs->stat) (vfs, path, buf) : -1;
534 g_free (path);
535 if (result == -1)
536 errno = vfs->name ? ferrno (vfs) : E_NOTSUPP;
537 return result;
540 int mc_lstat (const char *filename, struct stat *buf) {
541 struct vfs_class *vfs;
542 int result;
543 char *path;
544 path = vfs_canon (filename); vfs = vfs_get_class (path);
545 result = vfs->lstat ? (*vfs->lstat) (vfs, path, buf) : -1;
546 g_free (path);
547 if (result == -1)
548 errno = vfs->name ? ferrno (vfs) : E_NOTSUPP;
549 return result;
552 int mc_fstat (int handle, struct stat *buf) {
553 struct vfs_class *vfs;
554 int result;
556 if (handle == -1)
557 return -1;
558 vfs = vfs_op (handle);
559 result = vfs->fstat ? (*vfs->fstat) (vfs_info (handle), buf) : -1;
560 if (result == -1)
561 errno = vfs->name ? ferrno (vfs) : E_NOTSUPP;
562 return result;
566 * Return current directory. If it's local, reread the current directory
567 * from the OS. You must g_strdup() whatever this function returns.
569 static const char *
570 _vfs_get_cwd (void)
572 char *p;
573 struct stat my_stat, my_stat2;
575 if (!_vfs_get_class (current_dir)) {
576 p = g_get_current_dir ();
577 if (!p) /* One of the directories in the path is not readable */
578 return current_dir;
580 /* Otherwise check if it is O.K. to use the current_dir */
581 if (!cd_symlinks || mc_stat (p, &my_stat)
582 || mc_stat (current_dir, &my_stat2)
583 || my_stat.st_ino != my_stat2.st_ino
584 || my_stat.st_dev != my_stat2.st_dev) {
585 g_free (current_dir);
586 current_dir = p;
587 return p;
588 } /* Otherwise we return current_dir below */
589 g_free (p);
591 return current_dir;
594 static void
595 vfs_setup_wd (void)
597 current_dir = g_strdup (PATH_SEP_STR);
598 _vfs_get_cwd ();
600 if (strlen (current_dir) > MC_MAXPATHLEN - 2)
601 vfs_die ("Current dir too long.\n");
603 current_vfs = vfs_get_class (current_dir);
607 * Return current directory. If it's local, reread the current directory
608 * from the OS. Put directory to the provided buffer.
610 char *
611 mc_get_current_wd (char *buffer, int size)
613 const char *cwd = _vfs_get_cwd ();
615 g_strlcpy (buffer, cwd, size);
616 return buffer;
620 * Return current directory without any OS calls.
622 char *
623 vfs_get_current_dir (void)
625 return current_dir;
628 off_t mc_lseek (int fd, off_t offset, int whence)
630 struct vfs_class *vfs;
631 int result;
633 if (fd == -1)
634 return -1;
636 vfs = vfs_op (fd);
637 result = vfs->lseek ? (*vfs->lseek)(vfs_info (fd), offset, whence) : -1;
638 if (result == -1)
639 errno = vfs->lseek ? ferrno (vfs) : E_NOTSUPP;
640 return result;
644 * remove //, /./ and /../
647 #define ISSLASH(a) (!a || (a == '/'))
649 char *
650 vfs_canon (const char *path)
652 if (!path)
653 vfs_die("Cannot canonicalize NULL");
655 /* Relative to current directory */
656 if (*path != PATH_SEP){
657 char *local, *result;
659 local = concat_dir_and_file (current_dir, path);
661 result = vfs_canon (local);
662 g_free (local);
663 return result;
667 * So we have path of following form:
668 * /p1/p2#op/.././././p3#op/p4. Good luck.
671 char *result = g_strdup (path);
672 canonicalize_pathname (result);
673 return result;
678 * VFS chdir.
679 * Return 0 on success, -1 on failure.
682 mc_chdir (const char *path)
684 char *new_dir;
685 struct vfs_class *old_vfs, *new_vfs;
686 vfsid old_vfsid;
687 int result;
689 new_dir = vfs_canon (path);
690 new_vfs = vfs_get_class (new_dir);
691 if (!new_vfs->chdir) {
692 g_free (new_dir);
693 return -1;
696 result = (*new_vfs->chdir) (new_vfs, new_dir);
698 if (result == -1) {
699 errno = ferrno (new_vfs);
700 g_free (new_dir);
701 return -1;
704 old_vfsid = vfs_getid (current_vfs, current_dir);
705 old_vfs = current_vfs;
707 /* Actually change directory */
708 g_free (current_dir);
709 current_dir = new_dir;
710 current_vfs = new_vfs;
712 /* This function uses the new current_dir implicitly */
713 vfs_stamp_create (old_vfs, old_vfsid);
715 /* Sometimes we assume no trailing slash on cwd */
716 if (*current_dir) {
717 char *p;
718 p = strchr (current_dir, 0) - 1;
719 if (*p == PATH_SEP && p > current_dir)
720 *p = 0;
723 return 0;
726 /* Return 1 is the current VFS class is local */
728 vfs_current_is_local (void)
730 return (current_vfs->flags & VFSF_LOCAL) != 0;
733 /* Return flags of the VFS class of the given filename */
735 vfs_file_class_flags (const char *filename)
737 struct vfs_class *vfs;
738 char *fname;
740 fname = vfs_canon (filename);
741 vfs = vfs_get_class (fname);
742 g_free (fname);
743 return vfs->flags;
746 static char *
747 mc_def_getlocalcopy (const char *filename)
749 char *tmp;
750 int fdin, fdout, i;
751 char buffer[8192];
752 struct stat mystat;
754 fdin = mc_open (filename, O_RDONLY | O_LINEAR);
755 if (fdin == -1)
756 return NULL;
758 fdout = vfs_mkstemps (&tmp, "vfs", filename);
760 if (fdout == -1)
761 goto fail;
762 while ((i = mc_read (fdin, buffer, sizeof (buffer))) > 0) {
763 if (write (fdout, buffer, i) != i)
764 goto fail;
766 if (i == -1)
767 goto fail;
768 i = mc_close (fdin);
769 fdin = -1;
770 if (i == -1)
771 goto fail;
772 if (close (fdout) == -1) {
773 fdout = -1;
774 goto fail;
777 if (mc_stat (filename, &mystat) != -1) {
778 chmod (tmp, mystat.st_mode);
780 return tmp;
782 fail:
783 if (fdout != -1)
784 close (fdout);
785 if (fdin != -1)
786 mc_close (fdin);
787 g_free (tmp);
788 return NULL;
791 char *
792 mc_getlocalcopy (const char *pathname)
794 char *result;
795 char *path = vfs_canon (pathname);
796 struct vfs_class *vfs = vfs_get_class (path);
798 result = vfs->getlocalcopy ? (*vfs->getlocalcopy)(vfs, path) :
799 mc_def_getlocalcopy (path);
800 g_free (path);
801 if (!result)
802 errno = ferrno (vfs);
803 return result;
806 static int
807 mc_def_ungetlocalcopy (struct vfs_class *vfs, const char *filename,
808 const char *local, int has_changed)
810 int fdin = -1, fdout = -1, i;
811 if (has_changed) {
812 char buffer[8192];
814 if (!vfs->write)
815 goto failed;
817 fdin = open (local, O_RDONLY);
818 if (fdin == -1)
819 goto failed;
820 fdout = mc_open (filename, O_WRONLY | O_TRUNC);
821 if (fdout == -1)
822 goto failed;
823 while ((i = read (fdin, buffer, sizeof (buffer))) > 0) {
824 if (mc_write (fdout, buffer, i) != i)
825 goto failed;
827 if (i == -1)
828 goto failed;
830 if (close (fdin) == -1) {
831 fdin = -1;
832 goto failed;
834 fdin = -1;
835 if (mc_close (fdout) == -1) {
836 fdout = -1;
837 goto failed;
840 unlink (local);
841 return 0;
843 failed:
844 message (1, _("Changes to file lost"), "%s", filename);
845 if (fdout != -1)
846 mc_close (fdout);
847 if (fdin != -1)
848 close (fdin);
849 unlink (local);
850 return -1;
854 mc_ungetlocalcopy (const char *pathname, const char *local, int has_changed)
856 int return_value = 0;
857 char *path = vfs_canon (pathname);
858 struct vfs_class *vfs = vfs_get_class (path);
860 return_value = vfs->ungetlocalcopy ?
861 (*vfs->ungetlocalcopy)(vfs, path, local, has_changed) :
862 mc_def_ungetlocalcopy (vfs, path, local, has_changed);
863 g_free (path);
864 return return_value;
868 void
869 vfs_init (void)
871 /* localfs needs to be the first one */
872 init_localfs();
873 /* fallback value for vfs_get_class() */
874 localfs_class = vfs_list;
876 init_extfs ();
877 init_sfs ();
878 init_tarfs ();
879 init_cpiofs ();
881 #ifdef USE_EXT2FSLIB
882 init_undelfs ();
883 #endif /* USE_EXT2FSLIB */
885 #ifdef USE_NETCODE
886 tcp_init();
887 init_ftpfs ();
888 init_fish ();
889 #ifdef WITH_SMBFS
890 init_smbfs ();
891 #endif /* WITH_SMBFS */
892 #ifdef WITH_MCFS
893 init_mcfs ();
894 #endif /* WITH_MCFS */
895 #endif /* USE_NETCODE */
897 vfs_setup_wd ();
900 void
901 vfs_shut (void)
903 struct vfs_class *vfs;
905 vfs_gc_done ();
907 g_free (current_dir);
909 for (vfs = vfs_list; vfs; vfs = vfs->next)
910 if (vfs->done)
911 (*vfs->done) (vfs);
913 g_slist_free (vfs_openfiles);
917 * These ones grab information from the VFS
918 * and handles them to an upper layer
920 void
921 vfs_fill_names (fill_names_f func)
923 struct vfs_class *vfs;
925 for (vfs=vfs_list; vfs; vfs=vfs->next)
926 if (vfs->fill_names)
927 (*vfs->fill_names) (vfs, func);
931 * Returns vfs path corresponding to given url. If passed string is
932 * not recognized as url, g_strdup(url) is returned.
935 static const struct {
936 const char *name;
937 size_t name_len;
938 const char *substitute;
939 } url_table[] = { {"ftp://", 6, "/#ftp:"},
940 {"mc://", 5, "/#mc:"},
941 {"smb://", 6, "/#smb:"},
942 {"sh://", 5, "/#sh:"},
943 {"ssh://", 6, "/#sh:"},
944 {"a:", 2, "/#a"}
947 char *
948 vfs_translate_url (const char *url)
950 size_t i;
952 for (i = 0; i < sizeof (url_table)/sizeof (url_table[0]); i++)
953 if (strncmp (url, url_table[i].name, url_table[i].name_len) == 0)
954 return g_strconcat (url_table[i].substitute, url + url_table[i].name_len, (char*) NULL);
956 return g_strdup (url);
959 int vfs_file_is_local (const char *filename)
961 return vfs_file_class_flags (filename) & VFSF_LOCAL;