Ticket #4560: extfs: fix segfault om enter to deleted archive.
[midnight-commander.git] / src / vfs / extfs / extfs.c
blob2e852279545887b0928cdfaf8cae79946d49f355
1 /*
2 Virtual File System: External file system.
4 Copyright (C) 1995-2024
5 Free Software Foundation, Inc.
7 Written by:
8 Jakub Jelinek, 1995
9 Pavel Machek, 1998
10 Andrew T. Veliath, 1999
11 Slava Zanko <slavazanko@gmail.com>, 2013
13 This file is part of the Midnight Commander.
15 The Midnight Commander is free software: you can redistribute it
16 and/or modify it under the terms of the GNU General Public License as
17 published by the Free Software Foundation, either version 3 of the License,
18 or (at your option) any later version.
20 The Midnight Commander 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 General Public License for more details.
25 You should have received a copy of the GNU General Public License
26 along with this program. If not, see <http://www.gnu.org/licenses/>.
29 /**
30 * \file
31 * \brief Source: Virtual File System: External file system
32 * \author Jakub Jelinek
33 * \author Pavel Machek
34 * \author Andrew T. Veliath
35 * \date 1995, 1998, 1999
38 /* Namespace: init_extfs */
40 #include <config.h>
42 #include <stdio.h>
43 #include <ctype.h>
44 #include <string.h>
45 #include <stdlib.h>
46 #include <sys/types.h>
47 #include <sys/stat.h>
48 #include <unistd.h>
49 #include <signal.h>
50 #include <errno.h>
51 #include <sys/wait.h>
53 #include "lib/global.h"
54 #include "lib/fileloc.h"
55 #include "lib/mcconfig.h"
56 #include "lib/util.h"
57 #include "lib/widget.h" /* message() */
59 #include "src/execute.h" /* For shell_execute */
61 #include "lib/vfs/vfs.h"
62 #include "lib/vfs/utilvfs.h"
63 #include "lib/vfs/xdirentry.h"
64 #include "lib/vfs/gc.h" /* vfs_rmstamp */
66 #include "extfs.h"
68 /*** global variables ****************************************************************************/
70 /*** file scope macro definitions ****************************************************************/
72 #undef ERRNOR
73 #define ERRNOR(x,y) do { my_errno = x; return y; } while(0)
75 #define RECORDSIZE 512
77 #define EXTFS_SUPER(a) ((struct extfs_super_t *) (a))
79 /*** file scope type declarations ****************************************************************/
81 struct extfs_super_t
83 struct vfs_s_super base; /* base class */
85 int fstype;
86 char *local_name;
87 struct stat local_stat;
88 dev_t rdev;
91 typedef struct
93 char *path;
94 char *prefix;
95 gboolean need_archive;
96 } extfs_plugin_info_t;
98 /*** forward declarations (file scope functions) *************************************************/
100 static struct vfs_s_entry *extfs_resolve_symlinks_int (struct vfs_s_entry *entry, GSList * list);
102 /*** file scope variables ************************************************************************/
104 static GArray *extfs_plugins = NULL;
106 static gboolean errloop;
107 static gboolean notadir;
109 static struct vfs_s_subclass extfs_subclass;
110 static struct vfs_class *vfs_extfs_ops = VFS_CLASS (&extfs_subclass);
112 static int my_errno = 0;
114 /* --------------------------------------------------------------------------------------------- */
115 /*** file scope functions ************************************************************************/
116 /* --------------------------------------------------------------------------------------------- */
118 static struct extfs_super_t *
119 extfs_super_new (struct vfs_class *me, const char *name, const vfs_path_t *local_name_vpath,
120 int fstype)
122 struct extfs_super_t *super;
123 struct vfs_s_super *vsuper;
125 super = g_new0 (struct extfs_super_t, 1);
126 vsuper = VFS_SUPER (super);
128 vsuper->me = me;
129 vsuper->name = g_strdup (name);
131 super->fstype = fstype;
133 if (local_name_vpath != NULL)
135 super->local_name = g_strdup (vfs_path_get_last_path_str (local_name_vpath));
136 mc_stat (local_name_vpath, &super->local_stat);
139 VFS_SUBCLASS (me)->supers = g_list_prepend (VFS_SUBCLASS (me)->supers, super);
141 return super;
144 /* --------------------------------------------------------------------------------------------- */
146 /* unlike vfs_s_new_entry(), inode->ent is kept */
147 static struct vfs_s_entry *
148 extfs_entry_new (struct vfs_class *me, const char *name, struct vfs_s_inode *inode)
150 struct vfs_s_entry *entry;
152 (void) me;
154 entry = g_new0 (struct vfs_s_entry, 1);
156 entry->name = g_strdup (name);
157 entry->ino = inode;
159 return entry;
162 /* --------------------------------------------------------------------------------------------- */
164 static void
165 extfs_fill_name (void *data, void *user_data)
167 struct vfs_s_super *a = VFS_SUPER (data);
168 fill_names_f func = (fill_names_f) user_data;
169 extfs_plugin_info_t *info;
170 char *name;
172 info = &g_array_index (extfs_plugins, extfs_plugin_info_t, EXTFS_SUPER (a)->fstype);
173 name =
174 g_strconcat (a->name != NULL ? a->name : "", PATH_SEP_STR, info->prefix,
175 VFS_PATH_URL_DELIMITER, (char *) NULL);
176 func (name);
177 g_free (name);
180 /* --------------------------------------------------------------------------------------------- */
182 static gint
183 extfs_cmp_archive (const void *a, const void *b)
185 const struct vfs_s_super *ar = (const struct vfs_s_super *) a;
186 const char *archive_name = (const char *) b;
188 return (ar->name != NULL && strcmp (ar->name, archive_name) == 0) ? 0 : 1;
191 /* --------------------------------------------------------------------------------------------- */
193 static struct vfs_s_entry *
194 extfs_generate_entry (struct extfs_super_t *archive, const char *name, struct vfs_s_inode *parent,
195 mode_t mode)
197 struct vfs_class *me = VFS_SUPER (archive)->me;
198 struct stat st;
199 mode_t myumask;
200 struct vfs_s_inode *inode;
201 struct vfs_s_entry *entry;
203 memset (&st, 0, sizeof (st));
204 st.st_ino = VFS_SUPER (archive)->ino_usage++;
205 st.st_dev = archive->rdev;
206 myumask = umask (022);
207 umask (myumask);
208 st.st_mode = mode & ~myumask;
209 st.st_uid = getuid ();
210 st.st_gid = getgid ();
211 st.st_mtime = time (NULL);
212 st.st_atime = st.st_mtime;
213 st.st_ctime = st.st_mtime;
214 st.st_nlink = 1;
216 inode = vfs_s_new_inode (me, VFS_SUPER (archive), &st);
217 entry = vfs_s_new_entry (me, name, inode);
218 if (parent != NULL)
219 vfs_s_insert_entry (me, parent, entry);
221 return entry;
224 /* --------------------------------------------------------------------------------------------- */
226 static struct vfs_s_entry *
227 extfs_find_entry_int (struct vfs_s_inode *dir, const char *name, GSList *list, int flags)
229 struct vfs_s_entry *pent, *pdir;
230 const char *p, *name_end;
231 char *q;
232 char c = PATH_SEP;
233 struct extfs_super_t *super;
235 if (g_path_is_absolute (name))
237 /* Handle absolute paths */
238 name = g_path_skip_root (name);
239 dir = dir->super->root;
242 super = EXTFS_SUPER (dir->super);
243 pent = dir->ent;
244 p = name;
245 name_end = name + strlen (name);
247 while ((pent != NULL) && (c != '\0') && (*p != '\0'))
249 q = strchr (p, PATH_SEP);
250 if (q == NULL)
251 q = (char *) name_end;
253 c = *q;
254 *q = '\0';
256 if (DIR_IS_DOTDOT (p))
257 pent = pent->dir != NULL ? pent->dir->ent : NULL;
258 else
260 GList *pl;
262 pent = extfs_resolve_symlinks_int (pent, list);
263 if (pent == NULL)
265 *q = c;
266 return NULL;
269 if (!S_ISDIR (pent->ino->st.st_mode))
271 *q = c;
272 notadir = TRUE;
273 return NULL;
276 pdir = pent;
277 pl = g_queue_find_custom (pent->ino->subdir, p, vfs_s_entry_compare);
278 pent = pl != NULL ? VFS_ENTRY (pl->data) : NULL;
279 if (pent != NULL && q + 1 > name_end)
281 /* Hack: I keep the original semanthic unless q+1 would break in the strchr */
282 *q = c;
283 notadir = !S_ISDIR (pent->ino->st.st_mode);
284 return pent;
287 /* When we load archive, we create automagically non-existent directories */
288 if (pent == NULL && (flags & FL_MKDIR) != 0)
289 pent = extfs_generate_entry (super, p, pdir->ino, S_IFDIR | 0777);
290 if (pent == NULL && (flags & FL_MKFILE) != 0)
291 pent = extfs_generate_entry (super, p, pdir->ino, S_IFREG | 0666);
294 /* Next iteration */
295 *q = c;
296 if (c != '\0')
297 p = q + 1;
299 if (pent == NULL)
300 my_errno = ENOENT;
301 return pent;
304 /* --------------------------------------------------------------------------------------------- */
306 static struct vfs_s_entry *
307 extfs_find_entry (struct vfs_s_inode *dir, const char *name, int flags)
309 struct vfs_s_entry *res;
311 errloop = FALSE;
312 notadir = FALSE;
314 res = extfs_find_entry_int (dir, name, NULL, flags);
315 if (res == NULL)
317 if (errloop)
318 my_errno = ELOOP;
319 else if (notadir)
320 my_errno = ENOTDIR;
322 return res;
325 /* --------------------------------------------------------------------------------------------- */
327 static void
328 extfs_fill_names (struct vfs_class *me, fill_names_f func)
330 g_list_foreach (VFS_SUBCLASS (me)->supers, extfs_fill_name, func);
333 /* --------------------------------------------------------------------------------------------- */
335 /* Create this function because VFSF_USETMP flag is not used in extfs */
336 static void
337 extfs_free_inode (struct vfs_class *me, struct vfs_s_inode *ino)
339 (void) me;
341 if (ino->localname != NULL)
343 unlink (ino->localname);
344 MC_PTR_FREE (ino->localname);
348 /* --------------------------------------------------------------------------------------------- */
350 static void
351 extfs_free_archive (struct vfs_class *me, struct vfs_s_super *psup)
353 struct extfs_super_t *archive = EXTFS_SUPER (psup);
355 (void) me;
357 if (archive->local_name != NULL)
359 struct stat my;
360 vfs_path_t *local_name_vpath, *name_vpath;
362 local_name_vpath = vfs_path_from_str (archive->local_name);
363 name_vpath = vfs_path_from_str (psup->name);
364 mc_stat (local_name_vpath, &my);
365 mc_ungetlocalcopy (name_vpath, local_name_vpath,
366 archive->local_stat.st_mtime != my.st_mtime);
367 vfs_path_free (local_name_vpath, TRUE);
368 vfs_path_free (name_vpath, TRUE);
369 g_free (archive->local_name);
373 /* --------------------------------------------------------------------------------------------- */
375 static inline char *
376 extfs_skip_leading_dotslash (char *s)
378 /* Skip leading "./" (if present).
379 * Some programs don't understand it:
381 * $ zip file.zip ./-file2.txt file1.txt
382 * adding: -file2.txt (stored 0%)
383 * adding: file1.txt (stored 0%)
384 * $ /usr/lib/mc/extfs.d/uzip copyout file.zip ./-file2.txt ./tmp-file2.txt
385 * caution: filename not matched: ./-file2.txt
387 if (s[0] == '.' && s[1] == PATH_SEP)
388 s += 2;
390 return s;
393 /* --------------------------------------------------------------------------------------------- */
395 static int
396 extfs_add_file (struct extfs_super_t *archive, const char *file_name)
398 struct vfs_s_super *super = VFS_SUPER (archive);
399 struct stat hstat;
400 char *current_file_name = NULL, *current_link_name = NULL;
401 int ret = 0;
403 if (vfs_parse_ls_lga (file_name, &hstat, &current_file_name, &current_link_name, NULL))
405 char *cfn = current_file_name;
407 if (*cfn != '\0')
409 struct vfs_s_entry *entry;
410 struct vfs_s_entry *pent = NULL;
411 struct vfs_s_inode *inode;
412 char *p, *q;
414 cfn = extfs_skip_leading_dotslash (cfn);
415 if (IS_PATH_SEP (*cfn))
416 cfn++;
417 p = strchr (cfn, '\0');
418 if (p != cfn && IS_PATH_SEP (p[-1]))
419 p[-1] = '\0';
420 p = strrchr (cfn, PATH_SEP);
421 if (p == NULL)
423 p = cfn;
424 q = strchr (cfn, '\0');
426 else
428 *(p++) = '\0';
429 q = cfn;
432 if (*q != '\0')
434 pent = extfs_find_entry (super->root, q, FL_MKDIR);
435 if (pent == NULL)
437 ret = -1;
438 goto done;
442 if (pent != NULL)
444 entry = extfs_entry_new (super->me, p, pent->ino);
445 entry->dir = pent->ino;
446 g_queue_push_tail (pent->ino->subdir, entry);
448 else
450 entry = extfs_entry_new (super->me, p, super->root);
451 entry->dir = super->root;
452 g_queue_push_tail (super->root->subdir, entry);
455 if (!S_ISLNK (hstat.st_mode) && (current_link_name != NULL))
457 pent = extfs_find_entry (super->root, current_link_name, FL_NONE);
458 if (pent == NULL)
460 ret = -1;
461 goto done;
464 pent->ino->st.st_nlink++;
465 entry->ino = pent->ino;
467 else
469 struct stat st;
471 memset (&st, 0, sizeof (st));
472 st.st_ino = super->ino_usage++;
473 st.st_nlink = 1;
474 st.st_dev = archive->rdev;
475 st.st_mode = hstat.st_mode;
476 #ifdef HAVE_STRUCT_STAT_ST_RDEV
477 st.st_rdev = hstat.st_rdev;
478 #endif
479 st.st_uid = hstat.st_uid;
480 st.st_gid = hstat.st_gid;
481 st.st_size = hstat.st_size;
482 st.st_mtime = hstat.st_mtime;
483 st.st_atime = hstat.st_atime;
484 st.st_ctime = hstat.st_ctime;
486 if (current_link_name == NULL && S_ISLNK (hstat.st_mode))
487 st.st_mode &= ~S_IFLNK; /* You *DON'T* want to do this always */
489 inode = vfs_s_new_inode (super->me, super, &st);
490 inode->ent = entry;
491 entry->ino = inode;
493 if (current_link_name != NULL && S_ISLNK (hstat.st_mode))
495 inode->linkname = current_link_name;
496 current_link_name = NULL;
501 done:
502 g_free (current_file_name);
503 g_free (current_link_name);
506 return ret;
509 /* --------------------------------------------------------------------------------------------- */
511 static mc_pipe_t *
512 extfs_open_archive (int fstype, const char *name, struct extfs_super_t **pparc, GError **error)
514 const extfs_plugin_info_t *info;
515 static dev_t archive_counter = 0;
516 mc_pipe_t *result = NULL;
517 mode_t mode;
518 char *cmd;
519 struct stat mystat;
520 struct extfs_super_t *current_archive;
521 struct vfs_s_entry *root_entry;
522 char *tmp = NULL;
523 vfs_path_t *local_name_vpath = NULL;
524 vfs_path_t *name_vpath;
526 memset (&mystat, 0, sizeof (mystat));
528 name_vpath = vfs_path_from_str (name);
529 info = &g_array_index (extfs_plugins, extfs_plugin_info_t, fstype);
531 if (info->need_archive)
533 if (mc_stat (name_vpath, &mystat) == -1)
535 mc_propagate_error (error, 0, "%s", unix_error_string (errno));
536 goto ret;
539 if (!vfs_file_is_local (name_vpath))
541 local_name_vpath = mc_getlocalcopy (name_vpath);
542 if (local_name_vpath == NULL)
543 goto ret;
546 tmp = name_quote (vfs_path_get_last_path_str (name_vpath), FALSE);
549 cmd = g_strconcat (info->path, info->prefix, " list ",
550 vfs_path_get_last_path_str (local_name_vpath) != NULL ?
551 vfs_path_get_last_path_str (local_name_vpath) : tmp, (char *) NULL);
552 g_free (tmp);
554 result = mc_popen (cmd, TRUE, TRUE, error);
555 g_free (cmd);
557 if (result == NULL)
559 if (local_name_vpath != NULL)
561 mc_ungetlocalcopy (name_vpath, local_name_vpath, FALSE);
562 vfs_path_free (local_name_vpath, TRUE);
564 goto ret;
567 current_archive = extfs_super_new (vfs_extfs_ops, name, local_name_vpath, fstype);
568 current_archive->rdev = archive_counter++;
569 vfs_path_free (local_name_vpath, TRUE);
571 mode = mystat.st_mode & 07777;
572 if (mode & 0400)
573 mode |= 0100;
574 if (mode & 0040)
575 mode |= 0010;
576 if (mode & 0004)
577 mode |= 0001;
578 mode |= S_IFDIR;
580 root_entry = extfs_generate_entry (current_archive, PATH_SEP_STR, NULL, mode);
581 root_entry->ino->st.st_uid = mystat.st_uid;
582 root_entry->ino->st.st_gid = mystat.st_gid;
583 root_entry->ino->st.st_atime = mystat.st_atime;
584 root_entry->ino->st.st_ctime = mystat.st_ctime;
585 root_entry->ino->st.st_mtime = mystat.st_mtime;
586 root_entry->ino->ent = root_entry;
587 VFS_SUPER (current_archive)->root = root_entry->ino;
589 *pparc = current_archive;
591 ret:
592 vfs_path_free (name_vpath, TRUE);
593 return result;
596 /* --------------------------------------------------------------------------------------------- */
598 * Main loop for reading an archive.
599 * Return 0 on success, -1 on error.
602 static int
603 extfs_read_archive (mc_pipe_t *pip, struct extfs_super_t *archive, GError **error)
605 int ret = 0;
606 GString *buffer;
607 GString *err_msg = NULL;
608 GString *remain_file_name = NULL;
610 while (ret != -1)
612 /* init buffers before call of mc_pread() */
613 pip->out.len = MC_PIPE_BUFSIZE;
614 pip->err.len = MC_PIPE_BUFSIZE;
616 mc_pread (pip, error);
618 if (*error != NULL)
619 return (-1);
621 if (pip->err.len > 0)
623 /* join errors/warnings */
624 if (err_msg == NULL)
625 err_msg = g_string_new_len (pip->err.buf, pip->err.len);
626 else
628 if (err_msg->str[err_msg->len - 1] != '\n')
629 g_string_append_c (err_msg, '\n');
630 g_string_append_len (err_msg, pip->err.buf, pip->err.len);
634 if (pip->out.len == MC_PIPE_STREAM_EOF)
635 break;
637 if (pip->out.len == 0)
638 continue;
640 if (pip->out.len == MC_PIPE_ERROR_READ)
641 return (-1);
643 while (ret != -1 && (buffer = mc_pstream_get_string (&pip->out)) != NULL)
645 /* handle a \n-separated file list */
647 if (buffer->str[buffer->len - 1] == '\n')
649 /* entire file name or last chunk */
651 g_string_truncate (buffer, buffer->len - 1);
653 /* join filename chunks */
654 if (remain_file_name != NULL)
656 g_string_append_len (remain_file_name, buffer->str, buffer->len);
657 g_string_free (buffer, TRUE);
658 buffer = remain_file_name;
659 remain_file_name = NULL;
662 else
664 /* first or middle chunk of file name */
666 if (remain_file_name == NULL)
667 remain_file_name = buffer;
668 else
670 g_string_append_len (remain_file_name, buffer->str, buffer->len);
671 g_string_free (buffer, TRUE);
674 continue;
677 ret = extfs_add_file (archive, buffer->str);
679 g_string_free (buffer, TRUE);
683 if (remain_file_name != NULL)
684 g_string_free (remain_file_name, TRUE);
686 if (err_msg != NULL)
688 if (*error == NULL)
689 mc_propagate_error (error, 0, "%s", err_msg->str);
691 g_string_free (err_msg, TRUE);
693 else if (ret == -1)
694 mc_propagate_error (error, 0, "%s", _("Inconsistent archive"));
696 return ret;
699 /* --------------------------------------------------------------------------------------------- */
701 static int
702 extfs_which (struct vfs_class *me, const char *path)
704 size_t path_len;
705 size_t i;
707 (void) me;
709 path_len = strlen (path);
711 for (i = 0; i < extfs_plugins->len; i++)
713 extfs_plugin_info_t *info;
715 info = &g_array_index (extfs_plugins, extfs_plugin_info_t, i);
717 if ((strncmp (path, info->prefix, path_len) == 0)
718 && ((info->prefix[path_len] == '\0') || (info->prefix[path_len] == '+')))
719 return i;
721 return -1;
724 /* --------------------------------------------------------------------------------------------- */
726 static int
727 extfs_open_and_read_archive (int fstype, const char *name, struct extfs_super_t **archive)
729 int result = -1;
730 struct extfs_super_t *a;
731 mc_pipe_t *pip;
732 GError *error = NULL;
734 pip = extfs_open_archive (fstype, name, archive, &error);
736 a = *archive;
738 if (pip == NULL)
740 const extfs_plugin_info_t *info;
742 info = &g_array_index (extfs_plugins, extfs_plugin_info_t, fstype);
743 if (error == NULL)
744 message (D_ERROR, MSG_ERROR, _("Cannot open %s archive\n%s"), info->prefix, name);
745 else
747 message (D_ERROR, MSG_ERROR, _("Cannot open %s archive\n%s:\n%s"), info->prefix, name,
748 error->message);
749 g_error_free (error);
752 else
754 result = extfs_read_archive (pip, a, &error);
756 if (result != 0)
757 VFS_SUPER (a)->me->free (VFS_SUPER (a));
759 if (error != NULL)
761 message (D_ERROR, MSG_ERROR, _("EXTFS virtual file system:\n%s"), error->message);
762 g_error_free (error);
765 mc_pclose (pip, NULL);
768 return result;
771 /* --------------------------------------------------------------------------------------------- */
773 * Dissect the path and create corresponding superblock.
775 static const char *
776 extfs_get_path (const vfs_path_t *vpath, struct extfs_super_t **archive, int flags)
778 char *archive_name;
779 int result = -1;
780 GList *parc;
781 int fstype;
782 const vfs_path_element_t *path_element;
783 struct extfs_super_t *a = NULL;
785 path_element = vfs_path_get_by_index (vpath, -1);
787 fstype = extfs_which (path_element->class, path_element->vfs_prefix);
788 if (fstype == -1)
789 return NULL;
791 archive_name = vfs_path_to_str_elements_count (vpath, -1);
793 /* All filesystems should have some local archive, at least it can be PATH_SEP ('/'). */
794 parc = g_list_find_custom (extfs_subclass.supers, archive_name, extfs_cmp_archive);
795 if (parc != NULL)
797 a = EXTFS_SUPER (parc->data);
798 vfs_stamp (vfs_extfs_ops, (vfsid) a);
799 g_free (archive_name);
801 else
803 if ((flags & FL_NO_OPEN) == 0)
804 result = extfs_open_and_read_archive (fstype, archive_name, &a);
806 g_free (archive_name);
808 if (result == -1)
810 path_element->class->verrno = EIO;
811 return NULL;
815 *archive = a;
816 return path_element->path;
819 /* --------------------------------------------------------------------------------------------- */
820 /* Return allocated path (without leading slash) inside the archive */
822 static char *
823 extfs_get_path_from_entry (const struct vfs_s_entry *entry)
825 const struct vfs_s_entry *e;
826 GString *localpath;
828 localpath = g_string_new ("");
830 for (e = entry; e->dir != NULL; e = e->dir->ent)
832 g_string_prepend (localpath, e->name);
833 if (e->dir->ent->dir != NULL)
834 g_string_prepend_c (localpath, PATH_SEP);
837 return g_string_free (localpath, FALSE);
840 /* --------------------------------------------------------------------------------------------- */
842 static struct vfs_s_entry *
843 extfs_resolve_symlinks_int (struct vfs_s_entry *entry, GSList *list)
845 struct vfs_s_entry *pent = NULL;
847 if (!S_ISLNK (entry->ino->st.st_mode))
848 return entry;
850 if (g_slist_find (list, entry) != NULL)
852 /* Here we protect us against symlink looping */
853 errloop = TRUE;
855 else
857 GSList *looping;
859 looping = g_slist_prepend (list, entry);
860 pent = extfs_find_entry_int (entry->dir, entry->ino->linkname, looping, FL_NONE);
861 looping = g_slist_delete_link (looping, looping);
863 if (pent == NULL)
864 my_errno = ENOENT;
867 return pent;
870 /* --------------------------------------------------------------------------------------------- */
872 static struct vfs_s_entry *
873 extfs_resolve_symlinks (struct vfs_s_entry *entry)
875 struct vfs_s_entry *res;
877 errloop = FALSE;
878 notadir = FALSE;
879 res = extfs_resolve_symlinks_int (entry, NULL);
880 if (res == NULL)
882 if (errloop)
883 my_errno = ELOOP;
884 else if (notadir)
885 my_errno = ENOTDIR;
887 return res;
890 /* --------------------------------------------------------------------------------------------- */
892 static char *
893 extfs_get_archive_name (const struct extfs_super_t *archive)
895 const char *archive_name;
897 if (archive->local_name != NULL)
898 archive_name = archive->local_name;
899 else
900 archive_name = CONST_VFS_SUPER (archive)->name;
902 if (archive_name == NULL || *archive_name == '\0')
903 return g_strdup ("no_archive_name");
904 else
906 char *ret_str;
907 vfs_path_t *vpath;
908 const char *path;
910 vpath = vfs_path_from_str (archive_name);
911 path = vfs_path_get_last_path_str (vpath);
912 ret_str = g_strdup (path);
913 vfs_path_free (vpath, TRUE);
914 return ret_str;
918 /* --------------------------------------------------------------------------------------------- */
919 /** Don't pass localname as NULL */
921 static int
922 extfs_cmd (const char *str_extfs_cmd, const struct extfs_super_t *archive,
923 const struct vfs_s_entry *entry, const char *localname)
925 char *file;
926 char *quoted_file;
927 char *archive_name, *quoted_archive_name;
928 const extfs_plugin_info_t *info;
929 char *cmd = NULL;
930 int retval = 0;
931 GError *error = NULL;
932 mc_pipe_t *pip;
934 file = extfs_get_path_from_entry (entry);
935 quoted_file = name_quote (file, FALSE);
936 g_free (file);
938 if (quoted_file == NULL)
940 message (D_ERROR, MSG_ERROR, _("EXTFS virtual file system:\nwrong file name"));
941 return (-1);
944 /* Skip leading "./" (if present) added in name_quote() */
945 file = extfs_skip_leading_dotslash (quoted_file);
947 archive_name = extfs_get_archive_name (archive);
948 quoted_archive_name = name_quote (archive_name, FALSE);
949 g_free (archive_name);
951 if (quoted_archive_name == NULL)
953 message (D_ERROR, MSG_ERROR, _("EXTFS virtual file system:\nwrong archive name"));
954 return (-1);
957 info = &g_array_index (extfs_plugins, extfs_plugin_info_t, archive->fstype);
959 if (localname == NULL || *localname == '\0')
960 cmd = g_strconcat (info->path, info->prefix, str_extfs_cmd, quoted_archive_name, " ",
961 file, (char *) NULL);
962 else
964 char *quoted_localname;
966 quoted_localname = name_quote (localname, FALSE);
967 cmd = g_strconcat (info->path, info->prefix, str_extfs_cmd, quoted_archive_name, " ",
968 file, " ", quoted_localname, (char *) NULL);
969 g_free (quoted_localname);
972 g_free (quoted_file);
973 g_free (quoted_archive_name);
975 if (cmd == NULL)
977 message (D_ERROR, MSG_ERROR, _("EXTFS virtual file system:\ncannot build command"));
978 return (-1);
981 /* don't read stdout */
982 pip = mc_popen (cmd, FALSE, TRUE, &error);
983 g_free (cmd);
985 if (pip == NULL)
987 message (D_ERROR, MSG_ERROR, _("EXTFS virtual file system:\n%s"), error->message);
988 g_error_free (error);
989 return (-1);
992 pip->err.null_term = TRUE;
994 mc_pread (pip, &error);
995 if (error != NULL)
997 message (D_ERROR, MSG_ERROR, _("EXTFS virtual file system:\n%s"), error->message);
998 g_error_free (error);
999 retval = -1;
1001 else if (pip->err.len > 0)
1002 message (D_ERROR, MSG_ERROR, _("EXTFS virtual file system:\n%s"), pip->err.buf);
1004 mc_pclose (pip, NULL);
1006 return retval;
1009 /* --------------------------------------------------------------------------------------------- */
1011 static void
1012 extfs_run (const vfs_path_t *vpath)
1014 struct extfs_super_t *archive = NULL;
1015 const char *p;
1016 char *q, *archive_name, *quoted_archive_name;
1017 char *cmd;
1018 const extfs_plugin_info_t *info;
1020 p = extfs_get_path (vpath, &archive, FL_NONE);
1021 if (p == NULL)
1022 return;
1023 q = name_quote (p, FALSE);
1025 archive_name = extfs_get_archive_name (archive);
1026 quoted_archive_name = name_quote (archive_name, FALSE);
1027 g_free (archive_name);
1028 info = &g_array_index (extfs_plugins, extfs_plugin_info_t, archive->fstype);
1029 cmd =
1030 g_strconcat (info->path, info->prefix, " run ", quoted_archive_name, " ", q, (char *) NULL);
1031 g_free (quoted_archive_name);
1032 g_free (q);
1033 shell_execute (cmd, 0);
1034 g_free (cmd);
1037 /* --------------------------------------------------------------------------------------------- */
1039 static void *
1040 extfs_open (const vfs_path_t *vpath, int flags, mode_t mode)
1042 vfs_file_handler_t *extfs_info;
1043 struct extfs_super_t *archive = NULL;
1044 const char *q;
1045 struct vfs_s_entry *entry;
1046 int local_handle;
1047 gboolean created = FALSE;
1049 q = extfs_get_path (vpath, &archive, FL_NONE);
1050 if (q == NULL)
1051 return NULL;
1052 entry = extfs_find_entry (VFS_SUPER (archive)->root, q, FL_NONE);
1053 if ((entry == NULL) && ((flags & O_CREAT) != 0))
1055 /* Create new entry */
1056 entry = extfs_find_entry (VFS_SUPER (archive)->root, q, FL_MKFILE);
1057 created = (entry != NULL);
1060 if (entry == NULL)
1061 return NULL;
1062 entry = extfs_resolve_symlinks (entry);
1063 if (entry == NULL)
1064 return NULL;
1066 if (S_ISDIR (entry->ino->st.st_mode))
1067 ERRNOR (EISDIR, NULL);
1069 if (entry->ino->localname == NULL)
1071 vfs_path_t *local_filename_vpath;
1072 const char *local_filename;
1074 local_handle = vfs_mkstemps (&local_filename_vpath, "extfs", entry->name);
1076 if (local_handle == -1)
1077 return NULL;
1078 close (local_handle);
1079 local_filename = vfs_path_get_last_path_str (local_filename_vpath);
1081 if (!created && ((flags & O_TRUNC) == 0)
1082 && extfs_cmd (" copyout ", archive, entry, local_filename))
1084 unlink (local_filename);
1085 vfs_path_free (local_filename_vpath, TRUE);
1086 my_errno = EIO;
1087 return NULL;
1089 entry->ino->localname = g_strdup (local_filename);
1090 vfs_path_free (local_filename_vpath, TRUE);
1093 local_handle = open (entry->ino->localname, NO_LINEAR (flags), mode);
1095 if (local_handle == -1)
1097 /* file exists(may be). Need to drop O_CREAT flag and truncate file content */
1098 flags = ~O_CREAT & (NO_LINEAR (flags) | O_TRUNC);
1099 local_handle = open (entry->ino->localname, flags, mode);
1102 if (local_handle == -1)
1103 ERRNOR (EIO, NULL);
1105 extfs_info = g_new (vfs_file_handler_t, 1);
1106 vfs_s_init_fh (extfs_info, entry->ino, created);
1107 extfs_info->handle = local_handle;
1109 /* i.e. we had no open files and now we have one */
1110 vfs_rmstamp (vfs_extfs_ops, (vfsid) archive);
1111 VFS_SUPER (archive)->fd_usage++;
1112 return extfs_info;
1115 /* --------------------------------------------------------------------------------------------- */
1117 static ssize_t
1118 extfs_read (void *fh, char *buffer, size_t count)
1120 vfs_file_handler_t *file = VFS_FILE_HANDLER (fh);
1122 return read (file->handle, buffer, count);
1125 /* --------------------------------------------------------------------------------------------- */
1127 static int
1128 extfs_close (void *fh)
1130 vfs_file_handler_t *file = VFS_FILE_HANDLER (fh);
1131 int errno_code = 0;
1133 close (file->handle);
1134 file->handle = -1;
1136 /* Commit the file if it has changed */
1137 if (file->changed)
1139 struct stat file_status;
1141 if (extfs_cmd
1142 (" copyin ", EXTFS_SUPER (VFS_FILE_HANDLER_SUPER (fh)), file->ino->ent,
1143 file->ino->localname))
1144 errno_code = EIO;
1146 if (stat (file->ino->localname, &file_status) != 0)
1147 errno_code = EIO;
1148 else
1149 file->ino->st.st_size = file_status.st_size;
1151 file->ino->st.st_mtime = time (NULL);
1154 if (--VFS_FILE_HANDLER_SUPER (fh)->fd_usage == 0)
1155 vfs_stamp_create (vfs_extfs_ops, VFS_FILE_HANDLER_SUPER (fh));
1157 g_free (fh);
1158 if (errno_code != 0)
1159 ERRNOR (EIO, -1);
1160 return 0;
1163 /* --------------------------------------------------------------------------------------------- */
1165 static int
1166 extfs_errno (struct vfs_class *me)
1168 (void) me;
1169 return my_errno;
1172 /* --------------------------------------------------------------------------------------------- */
1174 static void *
1175 extfs_opendir (const vfs_path_t *vpath)
1177 struct extfs_super_t *archive = NULL;
1178 const char *q;
1179 struct vfs_s_entry *entry;
1180 GList **info;
1182 q = extfs_get_path (vpath, &archive, FL_NONE);
1183 if (q == NULL)
1184 return NULL;
1185 entry = extfs_find_entry (VFS_SUPER (archive)->root, q, FL_NONE);
1186 if (entry == NULL)
1187 return NULL;
1188 entry = extfs_resolve_symlinks (entry);
1189 if (entry == NULL)
1190 return NULL;
1191 if (!S_ISDIR (entry->ino->st.st_mode))
1192 ERRNOR (ENOTDIR, NULL);
1194 info = g_new (GList *, 1);
1195 *info = g_queue_peek_head_link (entry->ino->subdir);
1197 return info;
1200 /* --------------------------------------------------------------------------------------------- */
1202 static struct vfs_dirent *
1203 extfs_readdir (void *data)
1205 struct vfs_dirent *dir;
1206 GList **info = (GList **) data;
1208 if (*info == NULL)
1209 return NULL;
1211 dir = vfs_dirent_init (NULL, VFS_ENTRY ((*info)->data)->name, 0); /* FIXME: inode */
1213 *info = g_list_next (*info);
1215 return dir;
1218 /* --------------------------------------------------------------------------------------------- */
1220 static int
1221 extfs_closedir (void *data)
1223 g_free (data);
1224 return 0;
1227 /* --------------------------------------------------------------------------------------------- */
1230 static void
1231 extfs_stat_move (struct stat *buf, const struct vfs_s_inode *inode)
1233 *buf = inode->st;
1235 #ifdef HAVE_STRUCT_STAT_ST_BLKSIZE
1236 buf->st_blksize = RECORDSIZE;
1237 #endif
1238 vfs_adjust_stat (buf);
1239 #ifdef HAVE_STRUCT_STAT_ST_MTIM
1240 buf->st_atim.tv_nsec = buf->st_mtim.tv_nsec = buf->st_ctim.tv_nsec = 0;
1241 #endif
1244 /* --------------------------------------------------------------------------------------------- */
1246 static int
1247 extfs_internal_stat (const vfs_path_t *vpath, struct stat *buf, gboolean resolve)
1249 struct extfs_super_t *archive;
1250 const char *q;
1251 struct vfs_s_entry *entry;
1252 int result = -1;
1254 q = extfs_get_path (vpath, &archive, FL_NONE);
1255 if (q == NULL)
1256 goto cleanup;
1257 entry = extfs_find_entry (VFS_SUPER (archive)->root, q, FL_NONE);
1258 if (entry == NULL)
1259 goto cleanup;
1260 if (resolve)
1262 entry = extfs_resolve_symlinks (entry);
1263 if (entry == NULL)
1264 goto cleanup;
1266 extfs_stat_move (buf, entry->ino);
1267 result = 0;
1268 cleanup:
1269 return result;
1272 /* --------------------------------------------------------------------------------------------- */
1274 static int
1275 extfs_stat (const vfs_path_t *vpath, struct stat *buf)
1277 return extfs_internal_stat (vpath, buf, TRUE);
1280 /* --------------------------------------------------------------------------------------------- */
1282 static int
1283 extfs_lstat (const vfs_path_t *vpath, struct stat *buf)
1285 return extfs_internal_stat (vpath, buf, FALSE);
1288 /* --------------------------------------------------------------------------------------------- */
1290 static int
1291 extfs_fstat (void *fh, struct stat *buf)
1293 vfs_file_handler_t *file = VFS_FILE_HANDLER (fh);
1295 extfs_stat_move (buf, file->ino);
1296 return 0;
1299 /* --------------------------------------------------------------------------------------------- */
1301 static int
1302 extfs_readlink (const vfs_path_t *vpath, char *buf, size_t size)
1304 struct extfs_super_t *archive;
1305 const char *q;
1306 size_t len;
1307 struct vfs_s_entry *entry;
1308 int result = -1;
1310 q = extfs_get_path (vpath, &archive, FL_NONE);
1311 if (q == NULL)
1312 goto cleanup;
1313 entry = extfs_find_entry (VFS_SUPER (archive)->root, q, FL_NONE);
1314 if (entry == NULL)
1315 goto cleanup;
1316 if (!S_ISLNK (entry->ino->st.st_mode))
1318 VFS_CLASS (vfs_path_get_last_path_vfs (vpath))->verrno = EINVAL;
1319 goto cleanup;
1321 len = strlen (entry->ino->linkname);
1322 if (size < len)
1323 len = size;
1324 /* readlink() does not append a NUL character to buf */
1325 result = len;
1326 memcpy (buf, entry->ino->linkname, result);
1327 cleanup:
1328 return result;
1331 /* --------------------------------------------------------------------------------------------- */
1333 static int
1334 extfs_chown (const vfs_path_t *vpath, uid_t owner, gid_t group)
1336 (void) vpath;
1337 (void) owner;
1338 (void) group;
1339 return 0;
1342 /* --------------------------------------------------------------------------------------------- */
1344 static int
1345 extfs_chmod (const vfs_path_t *vpath, mode_t mode)
1347 (void) vpath;
1348 (void) mode;
1349 return 0;
1352 /* --------------------------------------------------------------------------------------------- */
1354 static ssize_t
1355 extfs_write (void *fh, const char *buf, size_t nbyte)
1357 vfs_file_handler_t *file = VFS_FILE_HANDLER (fh);
1359 file->changed = TRUE;
1360 return write (file->handle, buf, nbyte);
1363 /* --------------------------------------------------------------------------------------------- */
1365 static int
1366 extfs_unlink (const vfs_path_t *vpath)
1368 struct extfs_super_t *archive;
1369 const char *q;
1370 struct vfs_s_entry *entry;
1371 int result = -1;
1373 q = extfs_get_path (vpath, &archive, FL_NONE);
1374 if (q == NULL)
1375 goto cleanup;
1376 entry = extfs_find_entry (VFS_SUPER (archive)->root, q, FL_NONE);
1377 if (entry == NULL)
1378 goto cleanup;
1379 entry = extfs_resolve_symlinks (entry);
1380 if (entry == NULL)
1381 goto cleanup;
1382 if (S_ISDIR (entry->ino->st.st_mode))
1384 VFS_CLASS (vfs_path_get_last_path_vfs (vpath))->verrno = EISDIR;
1385 goto cleanup;
1387 if (extfs_cmd (" rm ", archive, entry, ""))
1389 my_errno = EIO;
1390 goto cleanup;
1392 vfs_s_free_entry (VFS_SUPER (archive)->me, entry);
1393 result = 0;
1394 cleanup:
1395 return result;
1398 /* --------------------------------------------------------------------------------------------- */
1400 static int
1401 extfs_mkdir (const vfs_path_t *vpath, mode_t mode)
1403 struct extfs_super_t *archive;
1404 const char *q;
1405 struct vfs_s_entry *entry;
1406 int result = -1;
1407 struct vfs_class *me;
1409 (void) mode;
1411 me = VFS_CLASS (vfs_path_get_last_path_vfs (vpath));
1412 q = extfs_get_path (vpath, &archive, FL_NONE);
1413 if (q == NULL)
1414 goto cleanup;
1415 entry = extfs_find_entry (VFS_SUPER (archive)->root, q, FL_NONE);
1416 if (entry != NULL)
1418 me->verrno = EEXIST;
1419 goto cleanup;
1421 entry = extfs_find_entry (VFS_SUPER (archive)->root, q, FL_MKDIR);
1422 if (entry == NULL)
1423 goto cleanup;
1424 entry = extfs_resolve_symlinks (entry);
1425 if (entry == NULL)
1426 goto cleanup;
1427 if (!S_ISDIR (entry->ino->st.st_mode))
1429 me->verrno = ENOTDIR;
1430 goto cleanup;
1433 if (extfs_cmd (" mkdir ", archive, entry, ""))
1435 my_errno = EIO;
1436 vfs_s_free_entry (VFS_SUPER (archive)->me, entry);
1437 goto cleanup;
1439 result = 0;
1440 cleanup:
1441 return result;
1444 /* --------------------------------------------------------------------------------------------- */
1446 static int
1447 extfs_rmdir (const vfs_path_t *vpath)
1449 struct extfs_super_t *archive;
1450 const char *q;
1451 struct vfs_s_entry *entry;
1452 int result = -1;
1454 q = extfs_get_path (vpath, &archive, FL_NONE);
1455 if (q == NULL)
1456 goto cleanup;
1457 entry = extfs_find_entry (VFS_SUPER (archive)->root, q, FL_NONE);
1458 if (entry == NULL)
1459 goto cleanup;
1460 entry = extfs_resolve_symlinks (entry);
1461 if (entry == NULL)
1462 goto cleanup;
1463 if (!S_ISDIR (entry->ino->st.st_mode))
1465 VFS_CLASS (vfs_path_get_last_path_vfs (vpath))->verrno = ENOTDIR;
1466 goto cleanup;
1469 if (extfs_cmd (" rmdir ", archive, entry, ""))
1471 my_errno = EIO;
1472 goto cleanup;
1474 vfs_s_free_entry (VFS_SUPER (archive)->me, entry);
1475 result = 0;
1476 cleanup:
1477 return result;
1480 /* --------------------------------------------------------------------------------------------- */
1482 static int
1483 extfs_chdir (const vfs_path_t *vpath)
1485 void *data;
1487 my_errno = ENOTDIR;
1488 data = extfs_opendir (vpath);
1489 if (data == NULL)
1490 return (-1);
1491 extfs_closedir (data);
1492 my_errno = 0;
1493 return 0;
1496 /* --------------------------------------------------------------------------------------------- */
1498 static off_t
1499 extfs_lseek (void *fh, off_t offset, int whence)
1501 vfs_file_handler_t *file = VFS_FILE_HANDLER (fh);
1503 return lseek (file->handle, offset, whence);
1506 /* --------------------------------------------------------------------------------------------- */
1508 static vfsid
1509 extfs_getid (const vfs_path_t *vpath)
1511 struct extfs_super_t *archive = NULL;
1512 const char *p;
1514 p = extfs_get_path (vpath, &archive, FL_NO_OPEN);
1515 return (p == NULL ? NULL : (vfsid) archive);
1518 /* --------------------------------------------------------------------------------------------- */
1520 static vfs_path_t *
1521 extfs_getlocalcopy (const vfs_path_t *vpath)
1523 vfs_file_handler_t *fh;
1524 vfs_path_t *p;
1526 fh = VFS_FILE_HANDLER (extfs_open (vpath, O_RDONLY, 0));
1527 if (fh == NULL)
1528 return NULL;
1529 if (fh->ino->localname == NULL)
1531 extfs_close ((void *) fh);
1532 return NULL;
1534 p = vfs_path_from_str (fh->ino->localname);
1535 VFS_FILE_HANDLER_SUPER (fh)->fd_usage++;
1536 extfs_close ((void *) fh);
1537 return p;
1540 /* --------------------------------------------------------------------------------------------- */
1542 static int
1543 extfs_ungetlocalcopy (const vfs_path_t *vpath, const vfs_path_t *local, gboolean has_changed)
1545 vfs_file_handler_t *fh;
1547 fh = VFS_FILE_HANDLER (extfs_open (vpath, O_RDONLY, 0));
1548 if (fh == NULL)
1549 return 0;
1551 if (strcmp (fh->ino->localname, vfs_path_get_last_path_str (local)) == 0)
1553 VFS_FILE_HANDLER_SUPER (fh)->fd_usage--;
1554 if (has_changed)
1555 fh->changed = TRUE;
1556 extfs_close ((void *) fh);
1557 return 0;
1559 else
1561 /* Should not happen */
1562 extfs_close ((void *) fh);
1563 return 0;
1567 /* --------------------------------------------------------------------------------------------- */
1569 static gboolean
1570 extfs_get_plugins (const char *where, gboolean silent)
1572 char *dirname;
1573 GDir *dir;
1574 const char *filename;
1576 dirname = g_build_path (PATH_SEP_STR, where, MC_EXTFS_DIR, (char *) NULL);
1577 dir = g_dir_open (dirname, 0, NULL);
1579 /* We may not use vfs_die() message or message or similar,
1580 * UI is not initialized at this time and message would not
1581 * appear on screen. */
1582 if (dir == NULL)
1584 if (!silent)
1585 fprintf (stderr, _("Warning: cannot open %s directory\n"), dirname);
1586 g_free (dirname);
1587 return FALSE;
1590 if (extfs_plugins == NULL)
1591 extfs_plugins = g_array_sized_new (FALSE, TRUE, sizeof (extfs_plugin_info_t), 32);
1593 while ((filename = g_dir_read_name (dir)) != NULL)
1595 char fullname[MC_MAXPATHLEN];
1596 struct stat s;
1598 g_snprintf (fullname, sizeof (fullname), "%s" PATH_SEP_STR "%s", dirname, filename);
1600 if ((stat (fullname, &s) == 0) && S_ISREG (s.st_mode) && !S_ISDIR (s.st_mode)
1601 && is_exe (s.st_mode))
1603 int f;
1605 f = open (fullname, O_RDONLY);
1607 if (f >= 0)
1609 size_t len, i;
1610 extfs_plugin_info_t info;
1611 gboolean found = FALSE;
1613 close (f);
1615 /* Handle those with a trailing '+', those flag that the
1616 * file system does not require an archive to work
1618 len = strlen (filename);
1619 info.need_archive = (filename[len - 1] != '+');
1620 info.path = g_strconcat (dirname, PATH_SEP_STR, (char *) NULL);
1621 info.prefix = g_strndup (filename, len);
1623 /* prepare to compare file names without trailing '+' */
1624 if (!info.need_archive)
1625 info.prefix[len - 1] = '\0';
1627 /* don't overload already found plugin */
1628 for (i = 0; i < extfs_plugins->len && !found; i++)
1630 extfs_plugin_info_t *p;
1632 p = &g_array_index (extfs_plugins, extfs_plugin_info_t, i);
1634 /* 2 files with same names cannot be in a directory */
1635 found = strcmp (info.path, p->path) != 0
1636 && strcmp (info.prefix, p->prefix) == 0;
1639 if (found)
1641 g_free (info.path);
1642 g_free (info.prefix);
1644 else
1646 /* restore file name */
1647 if (!info.need_archive)
1648 info.prefix[len - 1] = '+';
1649 g_array_append_val (extfs_plugins, info);
1655 g_dir_close (dir);
1656 g_free (dirname);
1658 return TRUE;
1661 /* --------------------------------------------------------------------------------------------- */
1663 static int
1664 extfs_init (struct vfs_class *me)
1666 gboolean d1, d2;
1668 (void) me;
1670 /* 1st: scan user directory */
1671 d1 = extfs_get_plugins (mc_config_get_data_path (), TRUE); /* silent about user dir */
1672 /* 2nd: scan system dir */
1673 d2 = extfs_get_plugins (LIBEXECDIR, d1);
1675 return (d1 || d2 ? 1 : 0);
1678 /* --------------------------------------------------------------------------------------------- */
1680 static void
1681 extfs_done (struct vfs_class *me)
1683 size_t i;
1685 while (VFS_SUBCLASS (me)->supers != NULL)
1686 me->free ((vfsid) VFS_SUBCLASS (me)->supers->data);
1688 if (extfs_plugins == NULL)
1689 return;
1691 for (i = 0; i < extfs_plugins->len; i++)
1693 extfs_plugin_info_t *info;
1695 info = &g_array_index (extfs_plugins, extfs_plugin_info_t, i);
1696 g_free (info->path);
1697 g_free (info->prefix);
1700 g_array_free (extfs_plugins, TRUE);
1703 /* --------------------------------------------------------------------------------------------- */
1705 static int
1706 extfs_setctl (const vfs_path_t *vpath, int ctlop, void *arg)
1708 (void) arg;
1710 if (ctlop == VFS_SETCTL_RUN)
1712 extfs_run (vpath);
1713 return 1;
1715 return 0;
1718 /* --------------------------------------------------------------------------------------------- */
1719 /*** public functions ****************************************************************************/
1720 /* --------------------------------------------------------------------------------------------- */
1722 void
1723 vfs_init_extfs (void)
1725 vfs_init_subclass (&extfs_subclass, "extfs", VFSF_UNKNOWN, NULL);
1726 vfs_extfs_ops->init = extfs_init;
1727 vfs_extfs_ops->done = extfs_done;
1728 vfs_extfs_ops->fill_names = extfs_fill_names;
1729 vfs_extfs_ops->which = extfs_which;
1730 vfs_extfs_ops->open = extfs_open;
1731 vfs_extfs_ops->close = extfs_close;
1732 vfs_extfs_ops->read = extfs_read;
1733 vfs_extfs_ops->write = extfs_write;
1734 vfs_extfs_ops->opendir = extfs_opendir;
1735 vfs_extfs_ops->readdir = extfs_readdir;
1736 vfs_extfs_ops->closedir = extfs_closedir;
1737 vfs_extfs_ops->stat = extfs_stat;
1738 vfs_extfs_ops->lstat = extfs_lstat;
1739 vfs_extfs_ops->fstat = extfs_fstat;
1740 vfs_extfs_ops->chmod = extfs_chmod;
1741 vfs_extfs_ops->chown = extfs_chown;
1742 vfs_extfs_ops->readlink = extfs_readlink;
1743 vfs_extfs_ops->unlink = extfs_unlink;
1744 vfs_extfs_ops->chdir = extfs_chdir;
1745 vfs_extfs_ops->ferrno = extfs_errno;
1746 vfs_extfs_ops->lseek = extfs_lseek;
1747 vfs_extfs_ops->getid = extfs_getid;
1748 vfs_extfs_ops->getlocalcopy = extfs_getlocalcopy;
1749 vfs_extfs_ops->ungetlocalcopy = extfs_ungetlocalcopy;
1750 vfs_extfs_ops->mkdir = extfs_mkdir;
1751 vfs_extfs_ops->rmdir = extfs_rmdir;
1752 vfs_extfs_ops->setctl = extfs_setctl;
1753 extfs_subclass.free_inode = extfs_free_inode;
1754 extfs_subclass.free_archive = extfs_free_archive;
1755 vfs_register_class (vfs_extfs_ops);
1758 /* --------------------------------------------------------------------------------------------- */