Forgot to remove some more .s strings and do a rename in order to prevent compiler...
[midnight-commander.git] / vfs / vfs.c
blobf13d217b20ea2ef4bd96ca9c07c984c24a788e64
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 <mhl/string.h>
43 #include "../src/global.h"
44 #include "../src/tty.h" /* enable/disable interrupt key */
45 #include "../src/wtools.h" /* message() */
46 #include "../src/main.h" /* print_vfs_message */
47 #include "utilvfs.h"
48 #include "gc.h"
50 #include "vfs.h"
51 #ifdef USE_NETCODE
52 # include "tcputil.h"
53 #endif
54 #include "ftpfs.h"
55 #include "mcfs.h"
56 #include "smbfs.h"
57 #include "local.h"
59 /* They keep track of the current directory */
60 static struct vfs_class *current_vfs;
61 static char *current_dir;
63 struct vfs_openfile {
64 int handle;
65 struct vfs_class *vclass;
66 void *fsinfo;
69 static GSList *vfs_openfiles;
70 #define VFS_FIRST_HANDLE 100
72 static struct vfs_class *localfs_class;
74 /* Create new VFS handle and put it to the list */
75 static int
76 vfs_new_handle (struct vfs_class *vclass, void *fsinfo)
78 static int vfs_handle_counter = VFS_FIRST_HANDLE;
79 struct vfs_openfile *h;
81 h = g_new (struct vfs_openfile, 1);
82 h->handle = vfs_handle_counter++;
83 h->fsinfo = fsinfo;
84 h->vclass = vclass;
85 vfs_openfiles = g_slist_prepend (vfs_openfiles, h);
86 return h->handle;
89 /* Function to match handle, passed to g_slist_find_custom() */
90 static gint
91 vfs_cmp_handle (gconstpointer a, gconstpointer b)
93 if (!a)
94 return 1;
95 return ((struct vfs_openfile *) a)->handle != (long) b;
98 /* Find VFS class by file handle */
99 static inline struct vfs_class *
100 vfs_op (int handle)
102 GSList *l;
103 struct vfs_openfile *h;
105 l = g_slist_find_custom (vfs_openfiles, (void *) (long) handle,
106 vfs_cmp_handle);
107 if (!l)
108 return NULL;
109 h = (struct vfs_openfile *) l->data;
110 if (!h)
111 return NULL;
112 return h->vclass;
115 /* Find private file data by file handle */
116 static inline void *
117 vfs_info (int handle)
119 GSList *l;
120 struct vfs_openfile *h;
122 l = g_slist_find_custom (vfs_openfiles, (void *) (long) handle,
123 vfs_cmp_handle);
124 if (!l)
125 return NULL;
126 h = (struct vfs_openfile *) l->data;
127 if (!h)
128 return NULL;
129 return h->fsinfo;
132 /* Free open file data for given file handle */
133 static inline void
134 vfs_free_handle (int handle)
136 GSList *l;
138 l = g_slist_find_custom (vfs_openfiles, (void *) (long) handle,
139 vfs_cmp_handle);
140 vfs_openfiles = g_slist_delete_link (vfs_openfiles, l);
143 static struct vfs_class *vfs_list;
146 vfs_register_class (struct vfs_class *vfs)
148 if (vfs->init) /* vfs has own initialization function */
149 if (!(*vfs->init)(vfs)) /* but it failed */
150 return 0;
152 vfs->next = vfs_list;
153 vfs_list = vfs;
155 return 1;
158 /* Return VFS class for the given prefix */
159 static struct vfs_class *
160 vfs_prefix_to_class (char *prefix)
162 struct vfs_class *vfs;
164 /* Avoid last class (localfs) that would accept any prefix */
165 for (vfs = vfs_list; vfs->next; vfs = vfs->next) {
166 if (vfs->which) {
167 if ((*vfs->which) (vfs, prefix) == -1)
168 continue;
169 return vfs;
171 if (vfs->prefix
172 && !strncmp (prefix, vfs->prefix, strlen (vfs->prefix)))
173 return vfs;
175 return NULL;
178 /* Strip known vfs suffixes from a filename (possible improvement: strip
179 suffix from last path component).
180 Returns a malloced string which has to be freed. */
181 char *
182 vfs_strip_suffix_from_filename (const char *filename)
184 struct vfs_class *vfs;
185 char *semi;
186 char *p;
188 if (!filename)
189 vfs_die ("vfs_strip_suffix_from_path got NULL: impossible");
191 p = g_strdup (filename);
192 if (!(semi = strrchr (p, '#')))
193 return p;
195 /* Avoid last class (localfs) that would accept any prefix */
196 for (vfs = vfs_list; vfs->next; vfs = vfs->next) {
197 if (vfs->which) {
198 if ((*vfs->which) (vfs, semi + 1) == -1)
199 continue;
200 *semi = '\0'; /* Found valid suffix */
201 return p;
203 if (vfs->prefix
204 && !strncmp (semi + 1, vfs->prefix, strlen (vfs->prefix))) {
205 *semi = '\0'; /* Found valid suffix */
206 return p;
209 return p;
212 static inline int
213 path_magic (const char *path)
215 struct stat buf;
217 if (!stat(path, &buf))
218 return 0;
220 return 1;
224 * Splits path '/p1#op/inpath' into inpath,op; returns which vfs it is.
225 * What is left in path is p1. You still want to g_free(path), you DON'T
226 * want to free neither *inpath nor *op
228 struct vfs_class *
229 vfs_split (char *path, char **inpath, char **op)
231 char *semi;
232 char *slash;
233 struct vfs_class *ret;
235 if (!path)
236 vfs_die("Cannot split NULL");
238 semi = strrchr (path, '#');
239 if (!semi || !path_magic(path))
240 return NULL;
242 slash = strchr (semi, PATH_SEP);
243 *semi = 0;
245 if (op)
246 *op = NULL;
248 if (inpath)
249 *inpath = NULL;
251 if (slash)
252 *slash = 0;
254 if ((ret = vfs_prefix_to_class (semi+1))){
255 if (op)
256 *op = semi + 1;
257 if (inpath)
258 *inpath = slash ? slash + 1 : NULL;
259 return ret;
263 if (slash)
264 *slash = PATH_SEP;
265 ret = vfs_split (path, inpath, op);
266 *semi = '#';
267 return ret;
270 static struct vfs_class *
271 _vfs_get_class (char *path)
273 char *semi;
274 char *slash;
275 struct vfs_class *ret;
277 g_return_val_if_fail(path, NULL);
279 semi = strrchr (path, '#');
280 if (!semi || !path_magic (path))
281 return NULL;
283 slash = strchr (semi, PATH_SEP);
284 *semi = 0;
285 if (slash)
286 *slash = 0;
288 ret = vfs_prefix_to_class (semi+1);
290 if (slash)
291 *slash = PATH_SEP;
292 if (!ret)
293 ret = _vfs_get_class (path);
295 *semi = '#';
296 return ret;
299 struct vfs_class *
300 vfs_get_class (const char *pathname)
302 struct vfs_class *vfs;
303 char *path = g_strdup (pathname);
305 vfs = _vfs_get_class (path);
306 g_free (path);
308 if (!vfs)
309 vfs = localfs_class;
311 return vfs;
314 static int
315 ferrno (struct vfs_class *vfs)
317 return vfs->ferrno ? (*vfs->ferrno)(vfs) : E_UNKNOWN;
318 /* Hope that error message is obscure enough ;-) */
322 mc_open (const char *filename, int flags, ...)
324 int mode;
325 void *info;
326 va_list ap;
328 char *file = vfs_canon (filename);
329 struct vfs_class *vfs = vfs_get_class (file);
331 /* Get the mode flag */
332 if (flags & O_CREAT) {
333 va_start (ap, flags);
334 mode = va_arg (ap, int);
335 va_end (ap);
336 } else
337 mode = 0;
339 if (!vfs->open) {
340 g_free (file);
341 errno = -EOPNOTSUPP;
342 return -1;
345 info = (*vfs->open) (vfs, file, flags, mode); /* open must be supported */
346 g_free (file);
347 if (!info){
348 errno = ferrno (vfs);
349 return -1;
352 return vfs_new_handle (vfs, info);
356 #define MC_NAMEOP(name, inarg, callarg) \
357 int mc_##name inarg \
359 struct vfs_class *vfs; \
360 int result; \
361 char *mpath = vfs_canon (path); \
362 vfs = vfs_get_class (mpath); \
363 result = vfs->name ? (*vfs->name)callarg : -1; \
364 g_free (mpath); \
365 if (result == -1) \
366 errno = vfs->name ? ferrno (vfs) : E_NOTSUPP; \
367 return result; \
370 MC_NAMEOP (chmod, (const char *path, mode_t mode), (vfs, mpath, mode))
371 MC_NAMEOP (chown, (const char *path, uid_t owner, gid_t group), (vfs, mpath, owner, group))
372 MC_NAMEOP (utime, (const char *path, struct utimbuf *times), (vfs, mpath, times))
373 MC_NAMEOP (readlink, (const char *path, char *buf, int bufsiz), (vfs, mpath, buf, bufsiz))
374 MC_NAMEOP (unlink, (const char *path), (vfs, mpath))
375 MC_NAMEOP (symlink, (const char *name1, const char *path), (vfs, name1, mpath))
376 MC_NAMEOP (mkdir, (const char *path, mode_t mode), (vfs, mpath, mode))
377 MC_NAMEOP (rmdir, (const char *path), (vfs, mpath))
378 MC_NAMEOP (mknod, (const char *path, mode_t mode, dev_t dev), (vfs, mpath, mode, dev))
381 #define MC_HANDLEOP(name, inarg, callarg) \
382 ssize_t mc_##name inarg \
384 struct vfs_class *vfs; \
385 int result; \
386 if (handle == -1) \
387 return -1; \
388 vfs = vfs_op (handle); \
389 result = vfs->name ? (*vfs->name)callarg : -1; \
390 if (result == -1) \
391 errno = vfs->name ? ferrno (vfs) : E_NOTSUPP; \
392 return result; \
395 MC_HANDLEOP(read, (int handle, void *buffer, int count), (vfs_info (handle), buffer, count))
396 MC_HANDLEOP(write, (int handle, const void *buf, int nbyte), (vfs_info (handle), buf, nbyte))
399 #define MC_RENAMEOP(name) \
400 int mc_##name (const char *fname1, const char *fname2) \
402 struct vfs_class *vfs; \
403 int result; \
404 char *name2, *name1 = vfs_canon (fname1); \
405 vfs = vfs_get_class (name1); \
406 name2 = vfs_canon (fname2); \
407 if (vfs != vfs_get_class (name2)){ \
408 errno = EXDEV; \
409 g_free (name1); \
410 g_free (name2); \
411 return -1; \
413 result = vfs->name ? (*vfs->name)(vfs, name1, name2) : -1; \
414 g_free (name1); \
415 g_free (name2); \
416 if (result == -1) \
417 errno = vfs->name ? ferrno (vfs) : E_NOTSUPP; \
418 return result; \
421 MC_RENAMEOP (link)
422 MC_RENAMEOP (rename)
426 mc_ctl (int handle, int ctlop, void *arg)
428 struct vfs_class *vfs = vfs_op (handle);
430 return vfs->ctl ? (*vfs->ctl)(vfs_info (handle), ctlop, arg) : 0;
434 mc_setctl (const char *path, int ctlop, void *arg)
436 struct vfs_class *vfs;
437 int result;
438 char *mpath;
440 if (!path)
441 vfs_die("You don't want to pass NULL to mc_setctl.");
443 mpath = vfs_canon (path);
444 vfs = vfs_get_class (mpath);
445 result = vfs->setctl ? (*vfs->setctl)(vfs, mpath, ctlop, arg) : 0;
446 g_free (mpath);
447 return result;
451 mc_close (int handle)
453 struct vfs_class *vfs;
454 int result;
456 if (handle == -1 || !vfs_info (handle))
457 return -1;
459 vfs = vfs_op (handle);
460 if (handle < 3)
461 return close (handle);
463 if (!vfs->close)
464 vfs_die ("VFS must support close.\n");
465 result = (*vfs->close)(vfs_info (handle));
466 vfs_free_handle (handle);
467 if (result == -1)
468 errno = ferrno (vfs);
470 return result;
473 DIR *
474 mc_opendir (const char *dirname)
476 int handle, *handlep;
477 void *info;
478 struct vfs_class *vfs;
479 char *dname;
481 dname = vfs_canon (dirname);
482 vfs = vfs_get_class (dname);
484 info = vfs->opendir ? (*vfs->opendir)(vfs, dname) : NULL;
485 g_free (dname);
486 if (!info){
487 errno = vfs->opendir ? ferrno (vfs) : E_NOTSUPP;
488 return NULL;
490 handle = vfs_new_handle (vfs, info);
492 handlep = g_new (int, 1);
493 *handlep = handle;
494 return (DIR *) handlep;
497 struct dirent *
498 mc_readdir (DIR *dirp)
500 int handle;
501 struct vfs_class *vfs;
502 struct dirent *result = NULL;
504 if (!dirp) {
505 errno = EFAULT;
506 return NULL;
508 handle = *(int *) dirp;
509 vfs = vfs_op (handle);
510 if (vfs->readdir)
511 result = (*vfs->readdir) (vfs_info (handle));
512 if (!result)
513 errno = vfs->readdir ? ferrno (vfs) : E_NOTSUPP;
514 return result;
518 mc_closedir (DIR *dirp)
520 int handle = *(int *) dirp;
521 struct vfs_class *vfs = vfs_op (handle);
522 int result;
524 result = vfs->closedir ? (*vfs->closedir)(vfs_info (handle)) : -1;
525 vfs_free_handle (handle);
526 g_free (dirp);
527 return result;
530 int mc_stat (const char *filename, struct stat *buf) {
531 struct vfs_class *vfs;
532 int result;
533 char *path;
534 path = vfs_canon (filename); vfs = vfs_get_class (path);
535 result = vfs->stat ? (*vfs->stat) (vfs, path, buf) : -1;
536 g_free (path);
537 if (result == -1)
538 errno = vfs->name ? ferrno (vfs) : E_NOTSUPP;
539 return result;
542 int mc_lstat (const char *filename, struct stat *buf) {
543 struct vfs_class *vfs;
544 int result;
545 char *path;
546 path = vfs_canon (filename); vfs = vfs_get_class (path);
547 result = vfs->lstat ? (*vfs->lstat) (vfs, path, buf) : -1;
548 g_free (path);
549 if (result == -1)
550 errno = vfs->name ? ferrno (vfs) : E_NOTSUPP;
551 return result;
554 int mc_fstat (int handle, struct stat *buf) {
555 struct vfs_class *vfs;
556 int result;
558 if (handle == -1)
559 return -1;
560 vfs = vfs_op (handle);
561 result = vfs->fstat ? (*vfs->fstat) (vfs_info (handle), buf) : -1;
562 if (result == -1)
563 errno = vfs->name ? ferrno (vfs) : E_NOTSUPP;
564 return result;
568 * Return current directory. If it's local, reread the current directory
569 * from the OS. You must g_strdup() whatever this function returns.
571 static const char *
572 _vfs_get_cwd (void)
574 char *p;
575 struct stat my_stat, my_stat2;
577 if (!_vfs_get_class (current_dir)) {
578 p = g_get_current_dir ();
579 if (!p) /* One of the directories in the path is not readable */
580 return current_dir;
582 /* Otherwise check if it is O.K. to use the current_dir */
583 if (!cd_symlinks || mc_stat (p, &my_stat)
584 || mc_stat (current_dir, &my_stat2)
585 || my_stat.st_ino != my_stat2.st_ino
586 || my_stat.st_dev != my_stat2.st_dev) {
587 g_free (current_dir);
588 current_dir = p;
589 return p;
590 } /* Otherwise we return current_dir below */
591 g_free (p);
593 return current_dir;
596 static void
597 vfs_setup_wd (void)
599 current_dir = g_strdup (PATH_SEP_STR);
600 _vfs_get_cwd ();
602 if (strlen (current_dir) > MC_MAXPATHLEN - 2)
603 vfs_die ("Current dir too long.\n");
605 current_vfs = vfs_get_class (current_dir);
609 * Return current directory. If it's local, reread the current directory
610 * from the OS. Put directory to the provided buffer.
612 char *
613 mc_get_current_wd (char *buffer, int size)
615 const char *cwd = _vfs_get_cwd ();
617 g_strlcpy (buffer, cwd, size);
618 return buffer;
622 * Return current directory without any OS calls.
624 char *
625 vfs_get_current_dir (void)
627 return current_dir;
630 off_t mc_lseek (int fd, off_t offset, int whence)
632 struct vfs_class *vfs;
633 int result;
635 if (fd == -1)
636 return -1;
638 vfs = vfs_op (fd);
639 result = vfs->lseek ? (*vfs->lseek)(vfs_info (fd), offset, whence) : -1;
640 if (result == -1)
641 errno = vfs->lseek ? ferrno (vfs) : E_NOTSUPP;
642 return result;
646 * remove //, /./ and /../
649 #define ISSLASH(a) (!a || (a == '/'))
651 char *
652 vfs_canon (const char *path)
654 if (!path)
655 vfs_die("Cannot canonicalize NULL");
657 /* Relative to current directory */
658 if (*path != PATH_SEP){
659 char *local, *result;
661 local = mhl_str_dir_plus_file (current_dir, path);
663 result = vfs_canon (local);
664 g_free (local);
665 return result;
669 * So we have path of following form:
670 * /p1/p2#op/.././././p3#op/p4. Good luck.
673 char *result = g_strdup (path);
674 canonicalize_pathname (result);
675 return result;
680 * VFS chdir.
681 * Return 0 on success, -1 on failure.
684 mc_chdir (const char *path)
686 char *new_dir;
687 struct vfs_class *old_vfs, *new_vfs;
688 vfsid old_vfsid;
689 int result;
691 new_dir = vfs_canon (path);
692 new_vfs = vfs_get_class (new_dir);
693 if (!new_vfs->chdir) {
694 g_free (new_dir);
695 return -1;
698 result = (*new_vfs->chdir) (new_vfs, new_dir);
700 if (result == -1) {
701 errno = ferrno (new_vfs);
702 g_free (new_dir);
703 return -1;
706 old_vfsid = vfs_getid (current_vfs, current_dir);
707 old_vfs = current_vfs;
709 /* Actually change directory */
710 g_free (current_dir);
711 current_dir = new_dir;
712 current_vfs = new_vfs;
714 /* This function uses the new current_dir implicitly */
715 vfs_stamp_create (old_vfs, old_vfsid);
717 /* Sometimes we assume no trailing slash on cwd */
718 if (*current_dir) {
719 char *p;
720 p = strchr (current_dir, 0) - 1;
721 if (*p == PATH_SEP && p > current_dir)
722 *p = 0;
725 return 0;
728 /* Return 1 is the current VFS class is local */
730 vfs_current_is_local (void)
732 return (current_vfs->flags & VFSF_LOCAL) != 0;
735 /* Return flags of the VFS class of the given filename */
737 vfs_file_class_flags (const char *filename)
739 struct vfs_class *vfs;
740 char *fname;
742 fname = vfs_canon (filename);
743 vfs = vfs_get_class (fname);
744 g_free (fname);
745 return vfs->flags;
748 static char *
749 mc_def_getlocalcopy (const char *filename)
751 char *tmp;
752 int fdin, fdout, i;
753 char buffer[8192];
754 struct stat mystat;
756 fdin = mc_open (filename, O_RDONLY | O_LINEAR);
757 if (fdin == -1)
758 return NULL;
760 fdout = vfs_mkstemps (&tmp, "vfs", filename);
762 if (fdout == -1)
763 goto fail;
764 while ((i = mc_read (fdin, buffer, sizeof (buffer))) > 0) {
765 if (write (fdout, buffer, i) != i)
766 goto fail;
768 if (i == -1)
769 goto fail;
770 i = mc_close (fdin);
771 fdin = -1;
772 if (i == -1)
773 goto fail;
774 if (close (fdout) == -1) {
775 fdout = -1;
776 goto fail;
779 if (mc_stat (filename, &mystat) != -1) {
780 chmod (tmp, mystat.st_mode);
782 return tmp;
784 fail:
785 if (fdout != -1)
786 close (fdout);
787 if (fdin != -1)
788 mc_close (fdin);
789 g_free (tmp);
790 return NULL;
793 char *
794 mc_getlocalcopy (const char *pathname)
796 char *result;
797 char *path = vfs_canon (pathname);
798 struct vfs_class *vfs = vfs_get_class (path);
800 result = vfs->getlocalcopy ? (*vfs->getlocalcopy)(vfs, path) :
801 mc_def_getlocalcopy (path);
802 g_free (path);
803 if (!result)
804 errno = ferrno (vfs);
805 return result;
808 static int
809 mc_def_ungetlocalcopy (struct vfs_class *vfs, const char *filename,
810 const char *local, int has_changed)
812 int fdin = -1, fdout = -1, i;
813 if (has_changed) {
814 char buffer[8192];
816 if (!vfs->write)
817 goto failed;
819 fdin = open (local, O_RDONLY);
820 if (fdin == -1)
821 goto failed;
822 fdout = mc_open (filename, O_WRONLY | O_TRUNC);
823 if (fdout == -1)
824 goto failed;
825 while ((i = read (fdin, buffer, sizeof (buffer))) > 0) {
826 if (mc_write (fdout, buffer, i) != i)
827 goto failed;
829 if (i == -1)
830 goto failed;
832 if (close (fdin) == -1) {
833 fdin = -1;
834 goto failed;
836 fdin = -1;
837 if (mc_close (fdout) == -1) {
838 fdout = -1;
839 goto failed;
842 unlink (local);
843 return 0;
845 failed:
846 message (D_ERROR, _("Changes to file lost"), "%s", filename);
847 if (fdout != -1)
848 mc_close (fdout);
849 if (fdin != -1)
850 close (fdin);
851 unlink (local);
852 return -1;
856 mc_ungetlocalcopy (const char *pathname, const char *local, int has_changed)
858 int return_value = 0;
859 char *path = vfs_canon (pathname);
860 struct vfs_class *vfs = vfs_get_class (path);
862 return_value = vfs->ungetlocalcopy ?
863 (*vfs->ungetlocalcopy)(vfs, path, local, has_changed) :
864 mc_def_ungetlocalcopy (vfs, path, local, has_changed);
865 g_free (path);
866 return return_value;
870 void
871 vfs_init (void)
873 /* localfs needs to be the first one */
874 init_localfs();
875 /* fallback value for vfs_get_class() */
876 localfs_class = vfs_list;
878 init_extfs ();
879 init_sfs ();
880 init_tarfs ();
881 init_cpiofs ();
883 #ifdef USE_EXT2FSLIB
884 init_undelfs ();
885 #endif /* USE_EXT2FSLIB */
887 #ifdef USE_NETCODE
888 tcp_init();
889 init_ftpfs ();
890 init_fish ();
891 #ifdef WITH_SMBFS
892 init_smbfs ();
893 #endif /* WITH_SMBFS */
894 #ifdef WITH_MCFS
895 init_mcfs ();
896 #endif /* WITH_MCFS */
897 #endif /* USE_NETCODE */
899 vfs_setup_wd ();
902 void
903 vfs_shut (void)
905 struct vfs_class *vfs;
907 vfs_gc_done ();
909 g_free (current_dir);
911 for (vfs = vfs_list; vfs; vfs = vfs->next)
912 if (vfs->done)
913 (*vfs->done) (vfs);
915 g_slist_free (vfs_openfiles);
919 * These ones grab information from the VFS
920 * and handles them to an upper layer
922 void
923 vfs_fill_names (fill_names_f func)
925 struct vfs_class *vfs;
927 for (vfs=vfs_list; vfs; vfs=vfs->next)
928 if (vfs->fill_names)
929 (*vfs->fill_names) (vfs, func);
933 * Returns vfs path corresponding to given url. If passed string is
934 * not recognized as url, g_strdup(url) is returned.
937 static const struct {
938 const char *name;
939 size_t name_len;
940 const char *substitute;
941 } url_table[] = { {"ftp://", 6, "/#ftp:"},
942 {"mc://", 5, "/#mc:"},
943 {"smb://", 6, "/#smb:"},
944 {"sh://", 5, "/#sh:"},
945 {"ssh://", 6, "/#sh:"},
946 {"a:", 2, "/#a"}
949 char *
950 vfs_translate_url (const char *url)
952 size_t i;
954 for (i = 0; i < sizeof (url_table)/sizeof (url_table[0]); i++)
955 if (strncmp (url, url_table[i].name, url_table[i].name_len) == 0)
956 return g_strconcat (url_table[i].substitute, url + url_table[i].name_len, (char*) NULL);
958 return g_strdup (url);
961 int vfs_file_is_local (const char *filename)
963 return vfs_file_class_flags (filename) & VFSF_LOCAL;