diff --git a/lib/utilunix.c b/lib/utilunix.c index 18459c241..92ddd4cf9 100644 --- a/lib/utilunix.c +++ b/lib/utilunix.c @@ -980,9 +980,8 @@ custom_canonicalize_pathname (char *path, CANON_PATH_FLAGS flags) if (vclass != NULL) { - struct vfs_s_subclass *sub = (struct vfs_s_subclass *) vclass; - - if ((sub->flags & VFS_S_REMOTE) != 0) + struct vfs_s_subclass *sub = (struct vfs_s_subclass *) vclass->data; + if (sub != NULL && sub->flags & VFS_S_REMOTE) { s = vfs_prefix; continue; diff --git a/lib/vfs/direntry.c b/lib/vfs/direntry.c index d6c817827..7df06f588 100644 --- a/lib/vfs/direntry.c +++ b/lib/vfs/direntry.c @@ -785,10 +785,10 @@ vfs_s_setctl (const vfs_path_t * vpath, int ctlop, void *arg) return 1; } case VFS_SETCTL_LOGFILE: - VFS_SUBCLASS (path_element)->logfile = fopen ((char *) arg, "w"); + ((struct vfs_s_subclass *) path_element->class->data)->logfile = fopen ((char *) arg, "w"); return 1; case VFS_SETCTL_FLUSH: - VFS_SUBCLASS (path_element)->flush = 1; + ((struct vfs_s_subclass *) path_element->class->data)->flush = 1; return 1; default: return 0; @@ -1075,7 +1075,9 @@ vfs_get_super_by_vpath (const vfs_path_t * vpath) vfs_path_t *vpath_archive; path_element = vfs_path_get_by_index (vpath, -1); - subclass = VFS_SUBCLASS (path_element); + subclass = (struct vfs_s_subclass *) path_element->class->data; + if (subclass == NULL) + return NULL; vpath_archive = vfs_path_clone (vpath); vfs_path_remove_element_by_index (vpath_archive, -1); @@ -1087,9 +1089,6 @@ vfs_get_super_by_vpath (const vfs_path_t * vpath) goto ret; } - if (subclass->archive_same == NULL) - goto ret; - for (iter = subclass->supers; iter != NULL; iter = g_list_next (iter)) { int i; @@ -1146,8 +1145,8 @@ vfs_s_get_path (const vfs_path_t * vpath, struct vfs_s_super **archive, int flag } super = vfs_s_new_super (path_element->class); - subclass = VFS_SUBCLASS (path_element); + subclass = (struct vfs_s_subclass *) path_element->class->data; if (subclass->open_archive != NULL) { vfs_path_t *vpath_archive; @@ -1238,7 +1237,6 @@ vfs_s_open (const vfs_path_t * vpath, int flags, mode_t mode) const char *q; struct vfs_s_inode *ino; const vfs_path_element_t *path_element; - struct vfs_s_subclass *s; path_element = vfs_path_get_by_index (vpath, -1); @@ -1252,8 +1250,6 @@ vfs_s_open (const vfs_path_t * vpath, int flags, mode_t mode) return NULL; } - s = VFS_SUBCLASS (path_element); - if (ino == NULL) { char *dirname, *name; @@ -1277,7 +1273,7 @@ vfs_s_open (const vfs_path_t * vpath, int flags, mode_t mode) ent = vfs_s_generate_entry (path_element->class, name, dir, 0755); ino = ent->ino; vfs_s_insert_entry (path_element->class, dir, ent); - if ((s->flags & VFS_S_USETMP) != 0) + if ((VFSDATA (path_element)->flags & VFS_S_USETMP) != 0) { int tmp_handle; vfs_path_t *tmp_vpath; @@ -1315,7 +1311,7 @@ vfs_s_open (const vfs_path_t * vpath, int flags, mode_t mode) if (IS_LINEAR (flags)) { - if (s->linear_start != NULL) + if (VFSDATA (path_element)->linear_start != NULL) { vfs_print_message ("%s", _("Starting linear transfer...")); fh->linear = LS_LINEAR_PREOPEN; @@ -1323,6 +1319,9 @@ vfs_s_open (const vfs_path_t * vpath, int flags, mode_t mode) } else { + struct vfs_s_subclass *s; + + s = VFSDATA (path_element); if (s->fh_open != NULL && s->fh_open (path_element->class, fh, flags, mode) != 0) { if (s->fh_free_data != NULL) @@ -1332,7 +1331,7 @@ vfs_s_open (const vfs_path_t * vpath, int flags, mode_t mode) } } - if ((s->flags & VFS_S_USETMP) != 0 && fh->ino->localname != NULL) + if ((VFSDATA (path_element)->flags & VFS_S_USETMP) != 0 && fh->ino->localname != NULL) { fh->handle = open (fh->ino->localname, NO_LINEAR (flags), mode); if (fh->handle == -1) @@ -1458,10 +1457,9 @@ vfs_s_retrieve_file (struct vfs_class *me, struct vfs_s_inode *ino) /* Initialize one of our subclasses - fill common functions */ void -vfs_s_init_class (struct vfs_s_subclass *sub) +vfs_s_init_class (struct vfs_class *vclass, struct vfs_s_subclass *sub) { - struct vfs_class *vclass = (struct vfs_class *) sub; - + vclass->data = sub; vclass->fill_names = vfs_s_fill_names; vclass->open = vfs_s_open; vclass->close = vfs_s_close; diff --git a/lib/vfs/path.c b/lib/vfs/path.c index e913b685e..a9b285b57 100644 --- a/lib/vfs/path.c +++ b/lib/vfs/path.c @@ -461,7 +461,7 @@ vfs_path_from_str_uri_parser (char *path) element->vfs_prefix = g_strdup (vfs_prefix_start); url_delimiter += strlen (VFS_PATH_URL_DELIMITER); - sub = VFS_SUBCLASS (element); + sub = VFSDATA (element); if (sub != NULL && (sub->flags & VFS_S_REMOTE) != 0) { char *slash_pointer; diff --git a/lib/vfs/vfs.h b/lib/vfs/vfs.h index 801011f88..58ba4b59d 100644 --- a/lib/vfs/vfs.h +++ b/lib/vfs/vfs.h @@ -141,6 +141,7 @@ typedef struct vfs_class const char *name; /* "FIles over SHell" */ vfs_class_flags_t flags; const char *prefix; /* "fish:" */ + void *data; /* this is for filesystem's own use */ int verrno; /* can't use errno because glibc2 might define errno as function */ /* *INDENT-OFF* */ diff --git a/lib/vfs/xdirentry.h b/lib/vfs/xdirentry.h index 2fe2d058c..df049c94b 100644 --- a/lib/vfs/xdirentry.h +++ b/lib/vfs/xdirentry.h @@ -34,9 +34,9 @@ #define ERRNOR(a, b) do { me->verrno = a; return b; } while (0) -#define MEDATA ((struct vfs_s_subclass *) me) +#define MEDATA ((struct vfs_s_subclass *) me->data) -#define VFS_SUBCLASS(a) ((struct vfs_s_subclass *) a->class) +#define VFSDATA(a) ((a->class != NULL) ? (struct vfs_s_subclass *) a->class->data : NULL) #define FH ((vfs_file_handler_t *) fh) #define FH_SUPER FH->ino->super @@ -116,12 +116,10 @@ typedef struct /* * One of our subclasses (tar, cpio, fish, ftpfs) with data and methods. - * Extends vfs_class. + * Extends vfs_class. Stored in the "data" field of vfs_class. */ struct vfs_s_subclass { - struct vfs_class base; /* base class */ - GList *supers; int inode_counter; vfs_subclass_flags_t flags; /* whether the subclass is remove, read-only etc */ @@ -181,7 +179,7 @@ struct vfs_s_inode *vfs_s_find_inode (struct vfs_class *me, struct vfs_s_inode *vfs_s_find_root (struct vfs_class *me, struct vfs_s_entry *entry); /* outside interface */ -void vfs_s_init_class (struct vfs_s_subclass *sub); +void vfs_s_init_class (struct vfs_class *vclass, struct vfs_s_subclass *sub); const char *vfs_s_get_path (const vfs_path_t * vpath, struct vfs_s_super **archive, int flags); struct vfs_s_super *vfs_get_super_by_vpath (const vfs_path_t * vpath); diff --git a/src/vfs/cpio/cpio.c b/src/vfs/cpio/cpio.c index eb3f299f4..de55806e7 100644 --- a/src/vfs/cpio/cpio.c +++ b/src/vfs/cpio/cpio.c @@ -143,8 +143,7 @@ typedef struct /*** file scope variables ************************************************************************/ -static struct vfs_s_subclass cpio_subclass; -static struct vfs_class *vfs_cpiofs_ops = (struct vfs_class *) &cpio_subclass; +static struct vfs_class vfs_cpiofs_ops; static off_t cpio_position; @@ -829,12 +828,12 @@ cpio_super_same (const vfs_path_element_t * vpath_element, struct vfs_s_super *p && ((cpio_super_data_t *) parc->data)->st.st_mtime < archive_stat->st_mtime) { /* Yes, reload! */ - vfs_cpiofs_ops->free ((vfsid) parc); - vfs_rmstamp (vfs_cpiofs_ops, (vfsid) parc); + (*vfs_cpiofs_ops.free) ((vfsid) parc); + vfs_rmstamp (&vfs_cpiofs_ops, (vfsid) parc); return 2; } /* Hasn't been modified, give it a new timeout */ - vfs_stamp (vfs_cpiofs_ops, (vfsid) parc); + vfs_stamp (&vfs_cpiofs_ops, (vfsid) parc); return 1; } @@ -882,6 +881,8 @@ cpio_fh_open (struct vfs_class *me, vfs_file_handler_t * fh, int flags, mode_t m void init_cpiofs (void) { + static struct vfs_s_subclass cpio_subclass; + cpio_subclass.flags = VFS_S_READONLY; /* FIXME: cpiofs used own temp files */ cpio_subclass.archive_check = cpio_super_check; cpio_subclass.archive_same = cpio_super_same; @@ -889,12 +890,12 @@ init_cpiofs (void) cpio_subclass.free_archive = cpio_free_archive; cpio_subclass.fh_open = cpio_fh_open; - vfs_s_init_class (&cpio_subclass); - vfs_cpiofs_ops->name = "cpiofs"; - vfs_cpiofs_ops->prefix = "ucpio"; - vfs_cpiofs_ops->read = cpio_read; - vfs_cpiofs_ops->setctl = NULL; - vfs_register_class (vfs_cpiofs_ops); + vfs_s_init_class (&vfs_cpiofs_ops, &cpio_subclass); + vfs_cpiofs_ops.name = "cpiofs"; + vfs_cpiofs_ops.prefix = "ucpio"; + vfs_cpiofs_ops.read = cpio_read; + vfs_cpiofs_ops.setctl = NULL; + vfs_register_class (&vfs_cpiofs_ops); } /* --------------------------------------------------------------------------------------------- */ diff --git a/src/vfs/extfs/extfs.c b/src/vfs/extfs/extfs.c index 861e86854..502e15702 100644 --- a/src/vfs/extfs/extfs.c +++ b/src/vfs/extfs/extfs.c @@ -141,9 +141,7 @@ static GArray *extfs_plugins = NULL; static gboolean errloop; static gboolean notadir; -static struct vfs_s_subclass extfs_subclass; -static struct vfs_class *vfs_extfs_ops = (struct vfs_class *) &extfs_subclass; - +static struct vfs_class vfs_extfs_ops; static GSList *first_archive = NULL; static int my_errno = 0; @@ -709,7 +707,7 @@ extfs_get_path (const vfs_path_t * vpath, extfs_super_t ** archive, int flags) if (parc != NULL) { a = EXTFS_SUPER (parc->data); - vfs_stamp (vfs_extfs_ops, (vfsid) a); + vfs_stamp (&vfs_extfs_ops, (vfsid) a); g_free (archive_name); goto return_success; } @@ -966,7 +964,7 @@ extfs_open (const vfs_path_t * vpath, int flags, mode_t mode) extfs_info->handle = local_handle; /* i.e. we had no open files and now we have one */ - vfs_rmstamp (vfs_extfs_ops, (vfsid) archive); + vfs_rmstamp (&vfs_extfs_ops, (vfsid) archive); archive->fd_usage++; return extfs_info; } @@ -1009,7 +1007,7 @@ extfs_close (void *data) } if (--file->archive->fd_usage == 0) - vfs_stamp_create (vfs_extfs_ops, file->archive); + vfs_stamp_create (&vfs_extfs_ops, file->archive); g_free (data); if (errno_code != 0) @@ -1696,40 +1694,37 @@ extfs_setctl (const vfs_path_t * vpath, int ctlop, void *arg) void init_extfs (void) { - memset (&extfs_subclass, 0, sizeof (extfs_subclass)); - vfs_s_init_class (&extfs_subclass); - - vfs_extfs_ops->name = "extfs"; - vfs_extfs_ops->init = extfs_init; - vfs_extfs_ops->done = extfs_done; - vfs_extfs_ops->fill_names = extfs_fill_names; - vfs_extfs_ops->which = extfs_which; - vfs_extfs_ops->open = extfs_open; - vfs_extfs_ops->close = extfs_close; - vfs_extfs_ops->read = extfs_read; - vfs_extfs_ops->write = extfs_write; - vfs_extfs_ops->opendir = extfs_opendir; - vfs_extfs_ops->readdir = extfs_readdir; - vfs_extfs_ops->closedir = extfs_closedir; - vfs_extfs_ops->stat = extfs_stat; - vfs_extfs_ops->lstat = extfs_lstat; - vfs_extfs_ops->fstat = extfs_fstat; - vfs_extfs_ops->chmod = extfs_chmod; - vfs_extfs_ops->chown = extfs_chown; - vfs_extfs_ops->readlink = extfs_readlink; - vfs_extfs_ops->unlink = extfs_unlink; - vfs_extfs_ops->chdir = extfs_chdir; - vfs_extfs_ops->ferrno = extfs_errno; - vfs_extfs_ops->lseek = extfs_lseek; - vfs_extfs_ops->getid = extfs_getid; - vfs_extfs_ops->nothingisopen = extfs_nothingisopen; - vfs_extfs_ops->free = extfs_free; - vfs_extfs_ops->getlocalcopy = extfs_getlocalcopy; - vfs_extfs_ops->ungetlocalcopy = extfs_ungetlocalcopy; - vfs_extfs_ops->mkdir = extfs_mkdir; - vfs_extfs_ops->rmdir = extfs_rmdir; - vfs_extfs_ops->setctl = extfs_setctl; - vfs_register_class (vfs_extfs_ops); + vfs_extfs_ops.name = "extfs"; + vfs_extfs_ops.init = extfs_init; + vfs_extfs_ops.done = extfs_done; + vfs_extfs_ops.fill_names = extfs_fill_names; + vfs_extfs_ops.which = extfs_which; + vfs_extfs_ops.open = extfs_open; + vfs_extfs_ops.close = extfs_close; + vfs_extfs_ops.read = extfs_read; + vfs_extfs_ops.write = extfs_write; + vfs_extfs_ops.opendir = extfs_opendir; + vfs_extfs_ops.readdir = extfs_readdir; + vfs_extfs_ops.closedir = extfs_closedir; + vfs_extfs_ops.stat = extfs_stat; + vfs_extfs_ops.lstat = extfs_lstat; + vfs_extfs_ops.fstat = extfs_fstat; + vfs_extfs_ops.chmod = extfs_chmod; + vfs_extfs_ops.chown = extfs_chown; + vfs_extfs_ops.readlink = extfs_readlink; + vfs_extfs_ops.unlink = extfs_unlink; + vfs_extfs_ops.chdir = extfs_chdir; + vfs_extfs_ops.ferrno = extfs_errno; + vfs_extfs_ops.lseek = extfs_lseek; + vfs_extfs_ops.getid = extfs_getid; + vfs_extfs_ops.nothingisopen = extfs_nothingisopen; + vfs_extfs_ops.free = extfs_free; + vfs_extfs_ops.getlocalcopy = extfs_getlocalcopy; + vfs_extfs_ops.ungetlocalcopy = extfs_ungetlocalcopy; + vfs_extfs_ops.mkdir = extfs_mkdir; + vfs_extfs_ops.rmdir = extfs_rmdir; + vfs_extfs_ops.setctl = extfs_setctl; + vfs_register_class (&vfs_extfs_ops); } /* --------------------------------------------------------------------------------------------- */ diff --git a/src/vfs/fish/fish.c b/src/vfs/fish/fish.c index 353f67cc3..b7f0f049d 100644 --- a/src/vfs/fish/fish.c +++ b/src/vfs/fish/fish.c @@ -155,8 +155,7 @@ typedef struct static char reply_str[80]; -static struct vfs_s_subclass fish_subclass; -static struct vfs_class *vfs_fish_ops = (struct vfs_class *) &fish_subclass; +static struct vfs_class vfs_fish_ops; /* --------------------------------------------------------------------------------------------- */ /*** file scope functions ************************************************************************/ @@ -344,7 +343,7 @@ fish_send_command (struct vfs_class *me, struct vfs_s_super *super, int flags, c va_start (ap, vars); r = fish_command_va (me, super, WAIT_REPLY, scr, vars, ap); va_end (ap); - vfs_stamp_create (vfs_fish_ops, super); + vfs_stamp_create (&vfs_fish_ops, super); if (r != COMPLETE) ERRNOR (E_REMOTE, -1); @@ -1701,7 +1700,7 @@ fish_fill_names (struct vfs_class *me, fill_names_f func) } name = - g_strconcat (vfs_fish_ops->prefix, VFS_PATH_URL_DELIMITER, + g_strconcat (vfs_fish_ops.prefix, VFS_PATH_URL_DELIMITER, super->path_element->user, "@", super->path_element->host, flags, PATH_SEP_STR, super->path_element->path, (char *) NULL); func (name); @@ -1729,6 +1728,8 @@ fish_open (const vfs_path_t * vpath, int flags, mode_t mode) void init_fish (void) { + static struct vfs_s_subclass fish_subclass; + tcp_init (); fish_subclass.flags = VFS_S_REMOTE | VFS_S_USETMP; @@ -1743,25 +1744,25 @@ init_fish (void) fish_subclass.linear_read = fish_linear_read; fish_subclass.linear_close = fish_linear_close; - vfs_s_init_class (&fish_subclass); - vfs_fish_ops->name = "fish"; - vfs_fish_ops->prefix = "sh"; - vfs_fish_ops->fill_names = fish_fill_names; - vfs_fish_ops->stat = fish_stat; - vfs_fish_ops->lstat = fish_lstat; - vfs_fish_ops->fstat = fish_fstat; - vfs_fish_ops->chmod = fish_chmod; - vfs_fish_ops->chown = fish_chown; - vfs_fish_ops->utime = fish_utime; - vfs_fish_ops->open = fish_open; - vfs_fish_ops->symlink = fish_symlink; - vfs_fish_ops->link = fish_link; - vfs_fish_ops->unlink = fish_unlink; - vfs_fish_ops->rename = fish_rename; - vfs_fish_ops->mkdir = fish_mkdir; - vfs_fish_ops->rmdir = fish_rmdir; - vfs_fish_ops->ctl = fish_ctl; - vfs_register_class (vfs_fish_ops); + vfs_s_init_class (&vfs_fish_ops, &fish_subclass); + vfs_fish_ops.name = "fish"; + vfs_fish_ops.prefix = "sh"; + vfs_fish_ops.fill_names = fish_fill_names; + vfs_fish_ops.stat = fish_stat; + vfs_fish_ops.lstat = fish_lstat; + vfs_fish_ops.fstat = fish_fstat; + vfs_fish_ops.chmod = fish_chmod; + vfs_fish_ops.chown = fish_chown; + vfs_fish_ops.utime = fish_utime; + vfs_fish_ops.open = fish_open; + vfs_fish_ops.symlink = fish_symlink; + vfs_fish_ops.link = fish_link; + vfs_fish_ops.unlink = fish_unlink; + vfs_fish_ops.rename = fish_rename; + vfs_fish_ops.mkdir = fish_mkdir; + vfs_fish_ops.rmdir = fish_rmdir; + vfs_fish_ops.ctl = fish_ctl; + vfs_register_class (&vfs_fish_ops); } /* --------------------------------------------------------------------------------------------- */ diff --git a/src/vfs/ftpfs/ftpfs.c b/src/vfs/ftpfs/ftpfs.c index 2350cbb75..7f5926471 100644 --- a/src/vfs/ftpfs/ftpfs.c +++ b/src/vfs/ftpfs/ftpfs.c @@ -237,8 +237,7 @@ static struct linklist *connections_list; static char reply_str[80]; -static struct vfs_s_subclass ftpfs_subclass; -static struct vfs_class *vfs_ftpfs_ops = (struct vfs_class *) &ftpfs_subclass; +static struct vfs_class vfs_ftpfs_ops; static GSList *no_proxy; @@ -2025,7 +2024,7 @@ ftpfs_send_command (const vfs_path_t * vpath, const char *cmd, int flags) p = ftpfs_translate_path (path_element->class, super, rpath); r = ftpfs_command (path_element->class, super, WAIT_REPLY, cmd, p); g_free (p); - vfs_stamp_create (vfs_ftpfs_ops, super); + vfs_stamp_create (&vfs_ftpfs_ops, super); if (flags & OPT_IGNORE_ERROR) r = COMPLETE; if (r != COMPLETE) @@ -2640,6 +2639,8 @@ ftpfs_init_passwd (void) void init_ftpfs (void) { + static struct vfs_s_subclass ftpfs_subclass; + tcp_init (); ftpfs_subclass.flags = VFS_S_REMOTE | VFS_S_USETMP; @@ -2655,23 +2656,23 @@ init_ftpfs (void) ftpfs_subclass.linear_read = ftpfs_linear_read; ftpfs_subclass.linear_close = ftpfs_linear_close; - vfs_s_init_class (&ftpfs_subclass); - vfs_ftpfs_ops->name = "ftpfs"; - vfs_ftpfs_ops->flags = VFSF_NOLINKS; - vfs_ftpfs_ops->prefix = "ftp"; - vfs_ftpfs_ops->done = &ftpfs_done; - vfs_ftpfs_ops->fill_names = ftpfs_fill_names; - vfs_ftpfs_ops->stat = ftpfs_stat; - vfs_ftpfs_ops->lstat = ftpfs_lstat; - vfs_ftpfs_ops->fstat = ftpfs_fstat; - vfs_ftpfs_ops->chmod = ftpfs_chmod; - vfs_ftpfs_ops->chown = ftpfs_chown; - vfs_ftpfs_ops->unlink = ftpfs_unlink; - vfs_ftpfs_ops->rename = ftpfs_rename; - vfs_ftpfs_ops->mkdir = ftpfs_mkdir; - vfs_ftpfs_ops->rmdir = ftpfs_rmdir; - vfs_ftpfs_ops->ctl = ftpfs_ctl; - vfs_register_class (vfs_ftpfs_ops); + vfs_s_init_class (&vfs_ftpfs_ops, &ftpfs_subclass); + vfs_ftpfs_ops.name = "ftpfs"; + vfs_ftpfs_ops.flags = VFSF_NOLINKS; + vfs_ftpfs_ops.prefix = "ftp"; + vfs_ftpfs_ops.done = &ftpfs_done; + vfs_ftpfs_ops.fill_names = ftpfs_fill_names; + vfs_ftpfs_ops.stat = ftpfs_stat; + vfs_ftpfs_ops.lstat = ftpfs_lstat; + vfs_ftpfs_ops.fstat = ftpfs_fstat; + vfs_ftpfs_ops.chmod = ftpfs_chmod; + vfs_ftpfs_ops.chown = ftpfs_chown; + vfs_ftpfs_ops.unlink = ftpfs_unlink; + vfs_ftpfs_ops.rename = ftpfs_rename; + vfs_ftpfs_ops.mkdir = ftpfs_mkdir; + vfs_ftpfs_ops.rmdir = ftpfs_rmdir; + vfs_ftpfs_ops.ctl = ftpfs_ctl; + vfs_register_class (&vfs_ftpfs_ops); } /* --------------------------------------------------------------------------------------------- */ diff --git a/src/vfs/sfs/sfs.c b/src/vfs/sfs/sfs.c index 73d1d2083..57d3ad52b 100644 --- a/src/vfs/sfs/sfs.c +++ b/src/vfs/sfs/sfs.c @@ -52,7 +52,6 @@ #include "lib/vfs/vfs.h" #include "lib/vfs/utilvfs.h" -#include "lib/vfs/xdirentry.h" #include "src/vfs/local/local.h" #include "lib/vfs/gc.h" /* vfs_stamp_create */ @@ -101,9 +100,7 @@ typedef struct cachedfile /*** file scope variables ************************************************************************/ static GSList *head; - -static struct vfs_s_subclass sfs_subclass; -static struct vfs_class *vfs_sfs_ops = (struct vfs_class *) &sfs_subclass; +static struct vfs_class vfs_sfs_ops; static int sfs_no = 0; static char *sfs_prefix[MAXFS]; @@ -236,7 +233,7 @@ sfs_redirect (const vfs_path_t * vpath) if (cur != NULL) { cf = (cachedfile *) cur->data; - vfs_stamp (vfs_sfs_ops, cf); + vfs_stamp (&vfs_sfs_ops, cf); return cf->cache; } @@ -255,7 +252,7 @@ sfs_redirect (const vfs_path_t * vpath) head = g_slist_prepend (head, cf); vfs_path_free (cache_vpath); - vfs_stamp_create (vfs_sfs_ops, (cachedfile *) head->data); + vfs_stamp_create (&vfs_sfs_ops, (cachedfile *) head->data); return cf->cache; } @@ -550,32 +547,29 @@ sfs_which (struct vfs_class *me, const char *path) void init_sfs (void) { - memset (&sfs_subclass, 0, sizeof (sfs_subclass)); - vfs_s_init_class (&sfs_subclass); - - vfs_sfs_ops->name = "sfs"; - vfs_sfs_ops->init = sfs_init; - vfs_sfs_ops->done = sfs_done; - vfs_sfs_ops->fill_names = sfs_fill_names; - vfs_sfs_ops->which = sfs_which; - vfs_sfs_ops->open = sfs_open; - vfs_sfs_ops->close = local_close; - vfs_sfs_ops->read = local_read; - vfs_sfs_ops->stat = sfs_stat; - vfs_sfs_ops->lstat = sfs_lstat; - vfs_sfs_ops->fstat = local_fstat; - vfs_sfs_ops->chmod = sfs_chmod; - vfs_sfs_ops->chown = sfs_chown; - vfs_sfs_ops->utime = sfs_utime; - vfs_sfs_ops->readlink = sfs_readlink; - vfs_sfs_ops->ferrno = local_errno; - vfs_sfs_ops->lseek = local_lseek; - vfs_sfs_ops->getid = sfs_getid; - vfs_sfs_ops->nothingisopen = sfs_nothingisopen; - vfs_sfs_ops->free = sfs_free; - vfs_sfs_ops->getlocalcopy = sfs_getlocalcopy; - vfs_sfs_ops->ungetlocalcopy = sfs_ungetlocalcopy; - vfs_register_class (vfs_sfs_ops); + vfs_sfs_ops.name = "sfs"; + vfs_sfs_ops.init = sfs_init; + vfs_sfs_ops.done = sfs_done; + vfs_sfs_ops.fill_names = sfs_fill_names; + vfs_sfs_ops.which = sfs_which; + vfs_sfs_ops.open = sfs_open; + vfs_sfs_ops.close = local_close; + vfs_sfs_ops.read = local_read; + vfs_sfs_ops.stat = sfs_stat; + vfs_sfs_ops.lstat = sfs_lstat; + vfs_sfs_ops.fstat = local_fstat; + vfs_sfs_ops.chmod = sfs_chmod; + vfs_sfs_ops.chown = sfs_chown; + vfs_sfs_ops.utime = sfs_utime; + vfs_sfs_ops.readlink = sfs_readlink; + vfs_sfs_ops.ferrno = local_errno; + vfs_sfs_ops.lseek = local_lseek; + vfs_sfs_ops.getid = sfs_getid; + vfs_sfs_ops.nothingisopen = sfs_nothingisopen; + vfs_sfs_ops.free = sfs_free; + vfs_sfs_ops.getlocalcopy = sfs_getlocalcopy; + vfs_sfs_ops.ungetlocalcopy = sfs_ungetlocalcopy; + vfs_register_class (&vfs_sfs_ops); } /* --------------------------------------------------------------------------------------------- */ diff --git a/src/vfs/sftpfs/file.c b/src/vfs/sftpfs/file.c index ba96b7eb7..76c64d077 100644 --- a/src/vfs/sftpfs/file.c +++ b/src/vfs/sftpfs/file.c @@ -119,7 +119,7 @@ sftpfs_open_file (vfs_file_handler_t * file_handler, int flags, mode_t mode, GEr (void) mode; mc_return_val_if_error (mcerror, FALSE); - name = vfs_s_fullpath (sftpfs_class, file_handler->ino); + name = vfs_s_fullpath (&sftpfs_class, file_handler->ino); if (name == NULL) return FALSE; diff --git a/src/vfs/sftpfs/init.c b/src/vfs/sftpfs/init.c index 50af6946f..af7d97f9d 100644 --- a/src/vfs/sftpfs/init.c +++ b/src/vfs/sftpfs/init.c @@ -34,9 +34,6 @@ /*** global variables ****************************************************************************/ -struct vfs_s_subclass sftpfs_subclass; -struct vfs_class *sftpfs_class = (struct vfs_class *) &sftpfs_subclass; - /*** file scope macro definitions ****************************************************************/ /*** file scope type declarations ****************************************************************/ @@ -58,10 +55,15 @@ init_sftpfs (void) { tcp_init (); - sftpfs_init_subclass (); - vfs_s_init_class (&sftpfs_subclass); sftpfs_init_class (); - vfs_register_class (sftpfs_class); + sftpfs_init_subclass (); + + vfs_s_init_class (&sftpfs_class, &sftpfs_subclass); + + sftpfs_init_class_callbacks (); + sftpfs_init_subclass_callbacks (); + + vfs_register_class (&sftpfs_class); } /* --------------------------------------------------------------------------------------------- */ diff --git a/src/vfs/sftpfs/internal.h b/src/vfs/sftpfs/internal.h index 6fd350aeb..2cce73772 100644 --- a/src/vfs/sftpfs/internal.h +++ b/src/vfs/sftpfs/internal.h @@ -54,13 +54,15 @@ typedef struct /*** global variables defined in .c file *********************************************************/ extern GString *sftpfs_filename_buffer; +extern struct vfs_class sftpfs_class; extern struct vfs_s_subclass sftpfs_subclass; -extern struct vfs_class *sftpfs_class; /*** declarations of public functions ************************************************************/ void sftpfs_init_class (void); void sftpfs_init_subclass (void); +void sftpfs_init_class_callbacks (void); +void sftpfs_init_subclass_callbacks (void); void sftpfs_init_config_variables_patterns (void); void sftpfs_deinit_config_variables_patterns (void); diff --git a/src/vfs/sftpfs/vfs_class.c b/src/vfs/sftpfs/vfs_class.c index 6a1a56547..a75d5b453 100644 --- a/src/vfs/sftpfs/vfs_class.c +++ b/src/vfs/sftpfs/vfs_class.c @@ -36,6 +36,8 @@ /*** global variables ****************************************************************************/ +struct vfs_class sftpfs_class; + /*** file scope macro definitions ****************************************************************/ /*** file scope type declarations ****************************************************************/ @@ -493,7 +495,7 @@ sftpfs_cb_close (void *data) super->fd_usage--; if (super->fd_usage == 0) - vfs_stamp_create (sftpfs_class, super); + vfs_stamp_create (&sftpfs_class, super); rc = sftpfs_close_file (file_handler, &mcerror); mc_error_message (&mcerror, NULL); @@ -501,7 +503,7 @@ sftpfs_cb_close (void *data) if (file_handler->handle != -1) close (file_handler->handle); - vfs_s_free_inode (sftpfs_class, file_handler->ino); + vfs_s_free_inode (&sftpfs_class, file_handler->ino); g_free (file_handler); return rc; @@ -682,40 +684,50 @@ sftpfs_cb_fill_names (struct vfs_class *me, fill_names_f func) void sftpfs_init_class (void) { - sftpfs_class->name = "sftpfs"; - sftpfs_class->prefix = "sftp"; - sftpfs_class->flags = VFSF_NOLINKS; - - sftpfs_class->init = sftpfs_cb_init; - sftpfs_class->done = sftpfs_cb_done; - - sftpfs_class->fill_names = sftpfs_cb_fill_names; - - sftpfs_class->opendir = sftpfs_cb_opendir; - sftpfs_class->readdir = sftpfs_cb_readdir; - sftpfs_class->closedir = sftpfs_cb_closedir; - sftpfs_class->mkdir = sftpfs_cb_mkdir; - sftpfs_class->rmdir = sftpfs_cb_rmdir; - - sftpfs_class->stat = sftpfs_cb_stat; - sftpfs_class->lstat = sftpfs_cb_lstat; - sftpfs_class->fstat = sftpfs_cb_fstat; - sftpfs_class->readlink = sftpfs_cb_readlink; - sftpfs_class->symlink = sftpfs_cb_symlink; - sftpfs_class->link = sftpfs_cb_link; - sftpfs_class->utime = sftpfs_cb_utime; - sftpfs_class->mknod = sftpfs_cb_mknod; - sftpfs_class->chown = sftpfs_cb_chown; - sftpfs_class->chmod = sftpfs_cb_chmod; - - sftpfs_class->open = sftpfs_cb_open; - sftpfs_class->read = sftpfs_cb_read; - sftpfs_class->write = sftpfs_cb_write; - sftpfs_class->close = sftpfs_cb_close; - sftpfs_class->lseek = sftpfs_cb_lseek; - sftpfs_class->unlink = sftpfs_cb_unlink; - sftpfs_class->rename = sftpfs_cb_rename; - sftpfs_class->ferrno = sftpfs_cb_errno; + memset (&sftpfs_class, 0, sizeof (sftpfs_class)); + sftpfs_class.name = "sftpfs"; + sftpfs_class.prefix = "sftp"; + sftpfs_class.flags = VFSF_NOLINKS; +} + +/* --------------------------------------------------------------------------------------------- */ +/** + * Initialization of VFS class callbacks. + */ + +void +sftpfs_init_class_callbacks (void) +{ + sftpfs_class.init = sftpfs_cb_init; + sftpfs_class.done = sftpfs_cb_done; + + sftpfs_class.fill_names = sftpfs_cb_fill_names; + + sftpfs_class.opendir = sftpfs_cb_opendir; + sftpfs_class.readdir = sftpfs_cb_readdir; + sftpfs_class.closedir = sftpfs_cb_closedir; + sftpfs_class.mkdir = sftpfs_cb_mkdir; + sftpfs_class.rmdir = sftpfs_cb_rmdir; + + sftpfs_class.stat = sftpfs_cb_stat; + sftpfs_class.lstat = sftpfs_cb_lstat; + sftpfs_class.fstat = sftpfs_cb_fstat; + sftpfs_class.readlink = sftpfs_cb_readlink; + sftpfs_class.symlink = sftpfs_cb_symlink; + sftpfs_class.link = sftpfs_cb_link; + sftpfs_class.utime = sftpfs_cb_utime; + sftpfs_class.mknod = sftpfs_cb_mknod; + sftpfs_class.chown = sftpfs_cb_chown; + sftpfs_class.chmod = sftpfs_cb_chmod; + + sftpfs_class.open = sftpfs_cb_open; + sftpfs_class.read = sftpfs_cb_read; + sftpfs_class.write = sftpfs_cb_write; + sftpfs_class.close = sftpfs_cb_close; + sftpfs_class.lseek = sftpfs_cb_lseek; + sftpfs_class.unlink = sftpfs_cb_unlink; + sftpfs_class.rename = sftpfs_cb_rename; + sftpfs_class.ferrno = sftpfs_cb_errno; } /* --------------------------------------------------------------------------------------------- */ diff --git a/src/vfs/sftpfs/vfs_subclass.c b/src/vfs/sftpfs/vfs_subclass.c index 8373e2ee5..5cc5bbcca 100644 --- a/src/vfs/sftpfs/vfs_subclass.c +++ b/src/vfs/sftpfs/vfs_subclass.c @@ -37,6 +37,8 @@ /*** global variables ****************************************************************************/ +struct vfs_s_subclass sftpfs_subclass; + /*** file scope macro definitions ****************************************************************/ /*** file scope type declarations ****************************************************************/ @@ -184,7 +186,16 @@ sftpfs_init_subclass (void) { memset (&sftpfs_subclass, 0, sizeof (sftpfs_subclass)); sftpfs_subclass.flags = VFS_S_REMOTE; +} +/* --------------------------------------------------------------------------------------------- */ +/** + * Initialization of VFS subclass callbacks. + */ + +void +sftpfs_init_subclass_callbacks (void) +{ sftpfs_subclass.archive_same = sftpfs_cb_is_equal_connection; sftpfs_subclass.open_archive = sftpfs_cb_open_connection; sftpfs_subclass.free_archive = sftpfs_cb_close_connection; diff --git a/src/vfs/tar/tar.c b/src/vfs/tar/tar.c index 7e0981eea..60e04be9a 100644 --- a/src/vfs/tar/tar.c +++ b/src/vfs/tar/tar.c @@ -222,8 +222,7 @@ typedef struct /*** file scope variables ************************************************************************/ -static struct vfs_s_subclass tarfs_subclass; -static struct vfs_class *vfs_tarfs_ops = (struct vfs_class *) &tarfs_subclass; +static struct vfs_class vfs_tarfs_ops; /* As we open one archive at a time, it is safe to have this static */ static off_t current_tar_position = 0; @@ -879,12 +878,12 @@ tar_super_same (const vfs_path_element_t * vpath_element, struct vfs_s_super *pa if (((tar_super_data_t *) parc->data)->st.st_mtime < archive_stat->st_mtime) { /* Yes, reload! */ - vfs_tarfs_ops->free ((vfsid) parc); - vfs_rmstamp (vfs_tarfs_ops, (vfsid) parc); + (*vfs_tarfs_ops.free) ((vfsid) parc); + vfs_rmstamp (&vfs_tarfs_ops, (vfsid) parc); return 2; } /* Hasn't been modified, give it a new timeout */ - vfs_stamp (vfs_tarfs_ops, (vfsid) parc); + vfs_stamp (&vfs_tarfs_ops, (vfsid) parc); return 1; } @@ -931,6 +930,8 @@ tar_fh_open (struct vfs_class *me, vfs_file_handler_t * fh, int flags, mode_t mo void init_tarfs (void) { + static struct vfs_s_subclass tarfs_subclass; + tarfs_subclass.flags = VFS_S_READONLY; /* FIXME: tarfs used own temp files */ tarfs_subclass.archive_check = tar_super_check; tarfs_subclass.archive_same = tar_super_same; @@ -938,12 +939,12 @@ init_tarfs (void) tarfs_subclass.free_archive = tar_free_archive; tarfs_subclass.fh_open = tar_fh_open; - vfs_s_init_class (&tarfs_subclass); - vfs_tarfs_ops->name = "tarfs"; - vfs_tarfs_ops->prefix = "utar"; - vfs_tarfs_ops->read = tar_read; - vfs_tarfs_ops->setctl = NULL; - vfs_register_class (vfs_tarfs_ops); + vfs_s_init_class (&vfs_tarfs_ops, &tarfs_subclass); + vfs_tarfs_ops.name = "tarfs"; + vfs_tarfs_ops.prefix = "utar"; + vfs_tarfs_ops.read = tar_read; + vfs_tarfs_ops.setctl = NULL; + vfs_register_class (&vfs_tarfs_ops); } /* --------------------------------------------------------------------------------------------- */ diff --git a/src/vfs/undelfs/undelfs.c b/src/vfs/undelfs/undelfs.c index 7ad9480bd..5b06009c1 100644 --- a/src/vfs/undelfs/undelfs.c +++ b/src/vfs/undelfs/undelfs.c @@ -64,7 +64,6 @@ #include "lib/util.h" #include "lib/widget.h" /* message() */ -#include "lib/vfs/xdirentry.h" #include "lib/vfs/utilvfs.h" #include "lib/vfs/vfs.h" @@ -130,11 +129,8 @@ static char *block_buf; static const char *undelfserr = N_("undelfs: error"); static int readdir_ptr; static int undelfs_usage; +static struct vfs_class vfs_undelfs_ops; -static struct vfs_s_subclass undelfs_subclass; -static struct vfs_class *vfs_undelfs_ops = (struct vfs_class *) &undelfs_subclass; - -/* --------------------------------------------------------------------------------------------- */ /*** file scope functions ************************************************************************/ /* --------------------------------------------------------------------------------------------- */ @@ -824,27 +820,24 @@ com_err (const char *whoami, long err_code, const char *fmt, ...) void init_undelfs (void) { - memset (&undelfs_subclass, 0, sizeof (undelfs_subclass)); - vfs_s_init_class (&undelfs_subclass); - - vfs_undelfs_ops->name = "undelfs"; - vfs_undelfs_ops->prefix = "undel"; - vfs_undelfs_ops->init = undelfs_init; - vfs_undelfs_ops->open = undelfs_open; - vfs_undelfs_ops->close = undelfs_close; - vfs_undelfs_ops->read = undelfs_read; - vfs_undelfs_ops->opendir = undelfs_opendir; - vfs_undelfs_ops->readdir = undelfs_readdir; - vfs_undelfs_ops->closedir = undelfs_closedir; - vfs_undelfs_ops->stat = undelfs_stat; - vfs_undelfs_ops->lstat = undelfs_lstat; - vfs_undelfs_ops->fstat = undelfs_fstat; - vfs_undelfs_ops->chdir = undelfs_chdir; - vfs_undelfs_ops->lseek = undelfs_lseek; - vfs_undelfs_ops->getid = undelfs_getid; - vfs_undelfs_ops->nothingisopen = undelfs_nothingisopen; - vfs_undelfs_ops->free = undelfs_free; - vfs_register_class (vfs_undelfs_ops); + vfs_undelfs_ops.name = "undelfs"; + vfs_undelfs_ops.prefix = "undel"; + vfs_undelfs_ops.init = undelfs_init; + vfs_undelfs_ops.open = undelfs_open; + vfs_undelfs_ops.close = undelfs_close; + vfs_undelfs_ops.read = undelfs_read; + vfs_undelfs_ops.opendir = undelfs_opendir; + vfs_undelfs_ops.readdir = undelfs_readdir; + vfs_undelfs_ops.closedir = undelfs_closedir; + vfs_undelfs_ops.stat = undelfs_stat; + vfs_undelfs_ops.lstat = undelfs_lstat; + vfs_undelfs_ops.fstat = undelfs_fstat; + vfs_undelfs_ops.chdir = undelfs_chdir; + vfs_undelfs_ops.lseek = undelfs_lseek; + vfs_undelfs_ops.getid = undelfs_getid; + vfs_undelfs_ops.nothingisopen = undelfs_nothingisopen; + vfs_undelfs_ops.free = undelfs_free; + vfs_register_class (&vfs_undelfs_ops); } /* --------------------------------------------------------------------------------------------- */