From ab033ad31896fe3773931a9b4ef7ade79fe36733 Mon Sep 17 00:00:00 2001 From: Andrew Borodin Date: Wed, 17 Aug 2016 13:54:08 +0300 Subject: [PATCH] VFS: make VFS-specific super class as derived one from vfs_s_super. Signed-off-by: Andrew Borodin --- lib/vfs/direntry.c | 8 +++-- lib/vfs/xdirentry.h | 5 +-- src/vfs/cpio/cpio.c | 64 +++++++++++++++++++--------------- src/vfs/fish/fish.c | 21 ++++++++--- src/vfs/ftpfs/ftpfs.c | 39 +++++++++++++-------- src/vfs/sftpfs/config_parser.c | 7 ++-- src/vfs/sftpfs/connection.c | 27 ++++---------- src/vfs/sftpfs/dir.c | 6 ++-- src/vfs/sftpfs/file.c | 8 ++--- src/vfs/sftpfs/internal.c | 2 +- src/vfs/sftpfs/internal.h | 4 +++ src/vfs/sftpfs/vfs_subclass.c | 33 +++++++++++------- src/vfs/tar/tar.c | 46 +++++++++++++++--------- 13 files changed, 156 insertions(+), 114 deletions(-) diff --git a/lib/vfs/direntry.c b/lib/vfs/direntry.c index 0cc0f4ee9..86af051b8 100644 --- a/lib/vfs/direntry.c +++ b/lib/vfs/direntry.c @@ -826,7 +826,7 @@ vfs_s_nothingisopen (vfsid id) static void vfs_s_free (vfsid id) { - vfs_s_free_super (((struct vfs_s_super *) id)->me, (struct vfs_s_super *) id); + vfs_s_free_super (VFS_SUPER (id)->me, VFS_SUPER (id)); } /* --------------------------------------------------------------------------------------------- */ @@ -1094,7 +1094,7 @@ vfs_get_super_by_vpath (const vfs_path_t * vpath) { int i; - super = (struct vfs_s_super *) iter->data; + super = VFS_SUPER (iter->data); /* 0 == other, 1 == same, return it, 2 == other but stop scanning */ i = subclass->archive_same (path_element, super, vpath_archive, cookie); @@ -1145,9 +1145,11 @@ vfs_s_get_path (const vfs_path_t * vpath, struct vfs_s_super **archive, int flag return NULL; } - super = vfs_s_new_super (path_element->class); subclass = VFS_SUBCLASS (path_element); + super = subclass->new_archive != NULL ? + subclass->new_archive (path_element->class) : vfs_s_new_super (path_element->class); + if (subclass->open_archive != NULL) { vfs_path_t *vpath_archive; diff --git a/lib/vfs/xdirentry.h b/lib/vfs/xdirentry.h index 6eca8526f..d3a17d30a 100644 --- a/lib/vfs/xdirentry.h +++ b/lib/vfs/xdirentry.h @@ -34,6 +34,8 @@ #define ERRNOR(a, b) do { me->verrno = a; return b; } while (0) +#define VFS_SUPER(a) ((struct vfs_s_super *) (a)) + #define MEDATA ((struct vfs_s_subclass *) me) #define VFS_SUBCLASS(a) ((struct vfs_s_subclass *) a->class) @@ -73,8 +75,6 @@ struct vfs_s_super #ifdef ENABLE_VFS_NET vfs_path_element_t *path_element; #endif /* ENABLE_VFS_NET */ - - void *data; /* This is for filesystem-specific use */ }; /* @@ -137,6 +137,7 @@ struct vfs_s_subclass void *(*archive_check) (const vfs_path_t * vpath); /* optional */ int (*archive_same) (const vfs_path_element_t * vpath_element, struct vfs_s_super * psup, const vfs_path_t * vpath, void *cookie); + struct vfs_s_super *(*new_archive) (struct vfs_class * me); int (*open_archive) (struct vfs_s_super * psup, const vfs_path_t * vpath, const vfs_path_element_t * vpath_element); void (*free_archive) (struct vfs_class * me, struct vfs_s_super * psup); diff --git a/src/vfs/cpio/cpio.c b/src/vfs/cpio/cpio.c index eb3f299f4..21fb5d1da 100644 --- a/src/vfs/cpio/cpio.c +++ b/src/vfs/cpio/cpio.c @@ -52,23 +52,19 @@ /*** file scope macro definitions ****************************************************************/ +#define SUP(super) ((cpio_super_data_t *) (super)) + #define CPIO_POS(super) cpio_position /* If some time reentrancy should be needed change it to */ /* #define CPIO_POS(super) (super)->u.arch.fd */ -#define CPIO_SEEK_SET(super, where) \ - mc_lseek (((cpio_super_data_t *)(super)->data)->fd, \ - CPIO_POS(super) = (where), SEEK_SET) -#define CPIO_SEEK_CUR(super, where) \ - mc_lseek (((cpio_super_data_t *)(super)->data)->fd, \ - CPIO_POS(super) += (where), SEEK_SET) +#define CPIO_SEEK_SET(super, where) mc_lseek (SUP(super)->fd, CPIO_POS(super) = (where), SEEK_SET) +#define CPIO_SEEK_CUR(super, where) mc_lseek (SUP(super)->fd, CPIO_POS(super) += (where), SEEK_SET) #define MAGIC_LENGTH (6) /* How many bytes we have to read ahead */ #define SEEKBACK CPIO_SEEK_CUR(super, ptr - top) -#define RETURN(x) return (((cpio_super_data_t *)super->data)->type = (x)) -#define TYPEIS(x) \ - ((((cpio_super_data_t *)super->data)->type == CPIO_UNKNOWN) || \ - (((cpio_super_data_t *)super->data)->type == (x))) +#define RETURN(x) return (SUP(super)->type = (x)) +#define TYPEIS(x) ((SUP(super)->type == CPIO_UNKNOWN) || (SUP(super)->type == (x))) #define HEAD_LENGTH (26) @@ -135,6 +131,8 @@ typedef struct typedef struct { + struct vfs_s_super base; /* base class */ + int fd; struct stat st; int type; /* Type of the archive */ @@ -148,6 +146,7 @@ static struct vfs_class *vfs_cpiofs_ops = (struct vfs_class *) &cpio_subclass; static off_t cpio_position; +/* --------------------------------------------------------------------------------------------- */ /*** file scope functions ************************************************************************/ /* --------------------------------------------------------------------------------------------- */ @@ -173,7 +172,7 @@ cpio_defer_find (const void *a, const void *b) static ssize_t cpio_skip_padding (struct vfs_s_super *super) { - switch (((cpio_super_data_t *) super->data)->type) + switch (SUP (super)->type) { case CPIO_BIN: case CPIO_BINRE: @@ -191,22 +190,33 @@ cpio_skip_padding (struct vfs_s_super *super) /* --------------------------------------------------------------------------------------------- */ +static struct vfs_s_super * +cpio_new_archive (struct vfs_class *me) +{ + cpio_super_data_t *arch; + + arch = g_new0 (cpio_super_data_t, 1); + arch->base.me = me; + arch->fd = -1; /* for now */ + arch->type = CPIO_UNKNOWN; + + return VFS_SUPER (arch); +} + +/* --------------------------------------------------------------------------------------------- */ + static void cpio_free_archive (struct vfs_class *me, struct vfs_s_super *super) { - cpio_super_data_t *arch = (cpio_super_data_t *) super->data; + cpio_super_data_t *arch = SUP (super); (void) me; - if (super->data == NULL) - return; - if (arch->fd != -1) mc_close (arch->fd); arch->fd = -1; g_slist_free_full (arch->deferred, g_free); arch->deferred = NULL; - MC_PTR_FREE (super->data); } /* --------------------------------------------------------------------------------------------- */ @@ -227,12 +237,8 @@ cpio_open_cpio_file (struct vfs_class *me, struct vfs_s_super *super, const vfs_ } super->name = g_strdup (vfs_path_as_str (vpath)); - super->data = g_new (cpio_super_data_t, 1); - arch = (cpio_super_data_t *) super->data; - arch->fd = -1; /* for now */ + arch = SUP (super); mc_stat (vpath, &arch->st); - arch->type = CPIO_UNKNOWN; - arch->deferred = NULL; type = get_compression_type (fd, super->name); if (type == COMPRESSION_NONE) @@ -303,7 +309,7 @@ cpio_read_head (struct vfs_class *me, struct vfs_s_super *super) static ssize_t cpio_find_head (struct vfs_class *me, struct vfs_s_super *super) { - cpio_super_data_t *arch = (cpio_super_data_t *) super->data; + cpio_super_data_t *arch = SUP (super); char buf[BUF_SMALL * 2]; ssize_t ptr = 0; ssize_t top; @@ -367,7 +373,7 @@ cpio_find_head (struct vfs_class *me, struct vfs_s_super *super) static int cpio_create_entry (struct vfs_class *me, struct vfs_s_super *super, struct stat *st, char *name) { - cpio_super_data_t *arch = (cpio_super_data_t *) super->data; + cpio_super_data_t *arch = SUP (super); struct vfs_s_inode *inode = NULL; struct vfs_s_inode *root = super->root; struct vfs_s_entry *entry = NULL; @@ -548,7 +554,7 @@ cpio_read_bin_head (struct vfs_class *me, struct vfs_s_super *super) short shorts[HEAD_LENGTH >> 1]; } u; - cpio_super_data_t *arch = (cpio_super_data_t *) super->data; + cpio_super_data_t *arch = SUP (super); ssize_t len; char *name; struct stat st; @@ -612,7 +618,7 @@ cpio_read_bin_head (struct vfs_class *me, struct vfs_s_super *super) static ssize_t cpio_read_oldc_head (struct vfs_class *me, struct vfs_s_super *super) { - cpio_super_data_t *arch = (cpio_super_data_t *) super->data; + cpio_super_data_t *arch = SUP (super); struct new_cpio_header hd; union { @@ -684,7 +690,7 @@ cpio_read_oldc_head (struct vfs_class *me, struct vfs_s_super *super) static ssize_t cpio_read_crc_head (struct vfs_class *me, struct vfs_s_super *super) { - cpio_super_data_t *arch = (cpio_super_data_t *) super->data; + cpio_super_data_t *arch = SUP (super); struct new_cpio_header hd; union { @@ -825,8 +831,7 @@ cpio_super_same (const vfs_path_element_t * vpath_element, struct vfs_s_super *p return 0; /* Has the cached archive been changed on the disk? */ - if (parc->data != NULL - && ((cpio_super_data_t *) parc->data)->st.st_mtime < archive_stat->st_mtime) + if (parc != NULL && SUP (parc)->st.st_mtime < archive_stat->st_mtime) { /* Yes, reload! */ vfs_cpiofs_ops->free ((vfsid) parc); @@ -844,7 +849,7 @@ static ssize_t cpio_read (void *fh, char *buffer, size_t count) { off_t begin = FH->ino->data_offset; - int fd = ((cpio_super_data_t *) FH_SUPER->data)->fd; + int fd = SUP (FH_SUPER)->fd; struct vfs_class *me = FH_SUPER->me; ssize_t res; @@ -885,6 +890,7 @@ init_cpiofs (void) 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; + cpio_subclass.new_archive = cpio_new_archive; cpio_subclass.open_archive = cpio_open_archive; cpio_subclass.free_archive = cpio_free_archive; cpio_subclass.fh_open = cpio_fh_open; diff --git a/src/vfs/fish/fish.c b/src/vfs/fish/fish.c index 353f67cc3..ae87c9110 100644 --- a/src/vfs/fish/fish.c +++ b/src/vfs/fish/fish.c @@ -117,12 +117,14 @@ int fish_directory_timeout = 900; #define FISH_HAVE_DATE_MDYT 32 #define FISH_HAVE_TAIL 64 -#define SUP ((fish_super_data_t *) super->data) +#define SUP ((fish_super_data_t *) super) /*** file scope type declarations ****************************************************************/ typedef struct { + struct vfs_s_super base; /* base class */ + int sockr; int sockw; char *scr_ls; @@ -356,6 +358,19 @@ fish_send_command (struct vfs_class *me, struct vfs_s_super *super, int flags, c /* --------------------------------------------------------------------------------------------- */ +static struct vfs_s_super * +fish_new_archive (struct vfs_class *me) +{ + fish_super_data_t *arch; + + arch = g_new0 (fish_super_data_t, 1); + arch->base.me = me; + + return VFS_SUPER (arch); +} + +/* --------------------------------------------------------------------------------------------- */ + static void fish_free_archive (struct vfs_class *me, struct vfs_s_super *super) { @@ -383,8 +398,6 @@ fish_free_archive (struct vfs_class *me, struct vfs_s_super *super) g_free (SUP->scr_append); g_free (SUP->scr_info); g_free (SUP->scr_env); - g_free (SUP); - super->data = NULL; } /* --------------------------------------------------------------------------------------------- */ @@ -647,7 +660,6 @@ fish_open_archive (struct vfs_s_super *super, { (void) vpath; - super->data = g_new0 (fish_super_data_t, 1); super->path_element = vfs_path_element_clone (vpath_element); if (strncmp (vpath_element->vfs_prefix, "rsh", 3) == 0) @@ -1733,6 +1745,7 @@ init_fish (void) fish_subclass.flags = VFS_S_REMOTE | VFS_S_USETMP; fish_subclass.archive_same = fish_archive_same; + fish_subclass.new_archive = fish_new_archive; fish_subclass.open_archive = fish_open_archive; fish_subclass.free_archive = fish_free_archive; fish_subclass.fh_open = fish_fh_open; diff --git a/src/vfs/ftpfs/ftpfs.c b/src/vfs/ftpfs/ftpfs.c index 2350cbb75..a1cb20cee 100644 --- a/src/vfs/ftpfs/ftpfs.c +++ b/src/vfs/ftpfs/ftpfs.c @@ -153,8 +153,8 @@ gboolean ftpfs_ignore_chattr_errors = TRUE; #define MAXHOSTNAMELEN 64 #endif -#define SUP ((ftp_super_data_t *) super->data) -#define FH_SOCK ((ftp_fh_data_t *) fh->data)->sock +#define SUP ((ftp_super_data_t *) super) +#define FH_SOCK ((ftp_fh_data_t *) fh)->sock #ifndef INADDR_NONE #define INADDR_NONE 0xffffffff @@ -203,6 +203,8 @@ typedef enum typedef struct { + struct vfs_s_super base; /* base class */ + int sock; char *proxy; /* proxy server, NULL if no proxy */ @@ -559,6 +561,24 @@ ftpfs_command (struct vfs_class *me, struct vfs_s_super *super, int wait_reply, /* --------------------------------------------------------------------------------------------- */ +static struct vfs_s_super * +ftpfs_new_archive (struct vfs_class *me) +{ + ftp_super_data_t *arch; + + arch = g_new0 (ftp_super_data_t, 1); + arch->base.me = me; + arch->base.name = g_strdup (PATH_SEP_STR); + arch->sock = -1; + arch->use_passive_connection = ftpfs_use_passive_connections; + arch->strict = ftpfs_use_unix_list_options ? RFC_AUTODETECT : RFC_STRICT; + arch->isbinary = TYPE_UNKNOWN; + + return VFS_SUPER (arch); +} + +/* --------------------------------------------------------------------------------------------- */ + static void ftpfs_free_archive (struct vfs_class *me, struct vfs_s_super *super) { @@ -569,7 +589,6 @@ ftpfs_free_archive (struct vfs_class *me, struct vfs_s_super *super) close (SUP->sock); } g_free (SUP->current_dir); - MC_PTR_FREE (super->data); } /* --------------------------------------------------------------------------------------------- */ @@ -999,18 +1018,9 @@ ftpfs_open_archive (struct vfs_s_super *super, { (void) vpath; - super->data = g_new0 (ftp_super_data_t, 1); - super->path_element = ftpfs_correct_url_parameters (vpath_element); - SUP->proxy = NULL; if (ftpfs_check_proxy (super->path_element->host)) SUP->proxy = ftpfs_proxy_host; - SUP->use_passive_connection = ftpfs_use_passive_connections; - SUP->strict = ftpfs_use_unix_list_options ? RFC_AUTODETECT : RFC_STRICT; - SUP->isbinary = TYPE_UNKNOWN; - SUP->remote_is_amiga = 0; - SUP->ctl_connection_busy = 0; - super->name = g_strdup (PATH_SEP_STR); super->root = vfs_s_new_inode (vpath_element->class, super, ftpfs_default_stat (vpath_element->class)); @@ -2219,7 +2229,7 @@ ftpfs_fh_open (struct vfs_class *me, vfs_file_handler_t * fh, int flags, mode_t * to local temporary file and stored to ftp server * by vfs_s_close later */ - if (((ftp_super_data_t *) (FH_SUPER->data))->ctl_connection_busy) + if (((ftp_super_data_t *) FH_SUPER)->ctl_connection_busy) { if (!fh->ino->localname) { @@ -2281,7 +2291,7 @@ ftpfs_fh_close (struct vfs_class *me, vfs_file_handler_t * fh) { if (fh->handle != -1 && !fh->ino->localname) { - ftp_super_data_t *ftp = (ftp_super_data_t *) fh->ino->super->data; + ftp_super_data_t *ftp = (ftp_super_data_t *) fh->ino->super; close (fh->handle); fh->handle = -1; @@ -2644,6 +2654,7 @@ init_ftpfs (void) ftpfs_subclass.flags = VFS_S_REMOTE | VFS_S_USETMP; ftpfs_subclass.archive_same = ftpfs_archive_same; + ftpfs_subclass.new_archive = ftpfs_new_archive; ftpfs_subclass.open_archive = ftpfs_open_archive; ftpfs_subclass.free_archive = ftpfs_free_archive; ftpfs_subclass.fh_open = ftpfs_fh_open; diff --git a/src/vfs/sftpfs/config_parser.c b/src/vfs/sftpfs/config_parser.c index ff2547165..638921ed5 100644 --- a/src/vfs/sftpfs/config_parser.c +++ b/src/vfs/sftpfs/config_parser.c @@ -354,19 +354,16 @@ sftpfs_get_config_entity (const vfs_path_element_t * vpath_element, GError ** mc void sftpfs_fill_connection_data_from_config (struct vfs_s_super *super, GError ** mcerror) { - sftpfs_super_data_t *super_data; + sftpfs_super_data_t *super_data = SUP; sftpfs_ssh_config_entity_t *config_entity; mc_return_if_error (mcerror); - super_data = (sftpfs_super_data_t *) super->data; - config_entity = sftpfs_get_config_entity (super->path_element, mcerror); if (config_entity == NULL) return; - super_data->config_auth_type = NONE; - super_data->config_auth_type |= (config_entity->pubkey_auth) ? PUBKEY : 0; + super_data->config_auth_type = (config_entity->pubkey_auth) ? PUBKEY : 0; super_data->config_auth_type |= (config_entity->identities_only) ? 0 : AGENT; super_data->config_auth_type |= (config_entity->password_auth) ? PASSWORD : 0; diff --git a/src/vfs/sftpfs/connection.c b/src/vfs/sftpfs/connection.c index 537159129..64210e578 100644 --- a/src/vfs/sftpfs/connection.c +++ b/src/vfs/sftpfs/connection.c @@ -167,11 +167,7 @@ static void sftpfs_recognize_auth_types (struct vfs_s_super *super) { char *userauthlist; - sftpfs_super_data_t *super_data; - - super_data = (sftpfs_super_data_t *) super->data; - - super_data->auth_type = NONE; + sftpfs_super_data_t *super_data = SUP; /* check what authentication methods are available */ /* userauthlist is internally managed by libssh2 and freed by libssh2_session_free() */ @@ -202,13 +198,12 @@ sftpfs_recognize_auth_types (struct vfs_s_super *super) static gboolean sftpfs_open_connection_ssh_agent (struct vfs_s_super *super, GError ** mcerror) { - sftpfs_super_data_t *super_data; + sftpfs_super_data_t *super_data = SUP; struct libssh2_agent_publickey *identity, *prev_identity = NULL; int rc; mc_return_val_if_error (mcerror, FALSE); - super_data = (sftpfs_super_data_t *) super->data; super_data->agent = NULL; if ((super_data->auth_type & AGENT) == 0) @@ -255,14 +250,12 @@ sftpfs_open_connection_ssh_agent (struct vfs_s_super *super, GError ** mcerror) static gboolean sftpfs_open_connection_ssh_key (struct vfs_s_super *super, GError ** mcerror) { - sftpfs_super_data_t *super_data; + sftpfs_super_data_t *super_data = SUP; char *p, *passwd; gboolean ret_value = FALSE; mc_return_val_if_error (mcerror, FALSE); - super_data = (sftpfs_super_data_t *) super->data; - if ((super_data->auth_type & PUBKEY) == 0) return FALSE; @@ -304,15 +297,13 @@ sftpfs_open_connection_ssh_key (struct vfs_s_super *super, GError ** mcerror) static gboolean sftpfs_open_connection_ssh_password (struct vfs_s_super *super, GError ** mcerror) { - sftpfs_super_data_t *super_data; + sftpfs_super_data_t *super_data = SUP; char *p, *passwd; gboolean ret_value = FALSE; int rc; mc_return_val_if_error (mcerror, FALSE); - super_data = (sftpfs_super_data_t *) super->data; - if ((super_data->auth_type & PASSWORD) == 0) return FALSE; @@ -365,12 +356,10 @@ int sftpfs_open_connection (struct vfs_s_super *super, GError ** mcerror) { int rc; - sftpfs_super_data_t *super_data; + sftpfs_super_data_t *super_data = SUP; mc_return_val_if_error (mcerror, -1); - super_data = (sftpfs_super_data_t *) super->data; - /* * The application code is responsible for creating the socket * and establishing the connection @@ -436,15 +425,11 @@ sftpfs_open_connection (struct vfs_s_super *super, GError ** mcerror) void sftpfs_close_connection (struct vfs_s_super *super, const char *shutdown_message, GError ** mcerror) { - sftpfs_super_data_t *super_data; + sftpfs_super_data_t *super_data = SUP; /* no mc_return_*_if_error() here because of abort open_connection handling too */ (void) mcerror; - super_data = (sftpfs_super_data_t *) super->data; - if (super_data == NULL) - return; - if (super_data->sftp_session != NULL) { libssh2_sftp_shutdown (super_data->sftp_session); diff --git a/src/vfs/sftpfs/dir.c b/src/vfs/sftpfs/dir.c index 367ab6725..50e57911f 100644 --- a/src/vfs/sftpfs/dir.c +++ b/src/vfs/sftpfs/dir.c @@ -78,7 +78,7 @@ sftpfs_opendir (const vfs_path_t * vpath, GError ** mcerror) if (vfs_s_get_path (vpath, &super, 0) == NULL) return NULL; - super_data = (sftpfs_super_data_t *) super->data; + super_data = SUP; while (TRUE) { @@ -194,7 +194,7 @@ sftpfs_mkdir (const vfs_path_t * vpath, mode_t mode, GError ** mcerror) if (super == NULL) return -1; - super_data = (sftpfs_super_data_t *) super->data; + super_data = SUP; if (super_data->sftp_session == NULL) return -1; @@ -244,7 +244,7 @@ sftpfs_rmdir (const vfs_path_t * vpath, GError ** mcerror) if (super == NULL) return -1; - super_data = (sftpfs_super_data_t *) super->data; + super_data = SUP; if (super_data->sftp_session == NULL) return -1; diff --git a/src/vfs/sftpfs/file.c b/src/vfs/sftpfs/file.c index ba96b7eb7..6001f3b37 100644 --- a/src/vfs/sftpfs/file.c +++ b/src/vfs/sftpfs/file.c @@ -123,7 +123,7 @@ sftpfs_open_file (vfs_file_handler_t * file_handler, int flags, mode_t mode, GEr if (name == NULL) return FALSE; - super_data = (sftpfs_super_data_t *) file_handler->ino->super->data; + super_data = (sftpfs_super_data_t *) file_handler->ino->super; file_handler_data = g_new0 (sftpfs_file_handler_data_t, 1); if ((flags & O_CREAT) != 0 || (flags & O_WRONLY) != 0) @@ -214,7 +214,7 @@ sftpfs_fstat (void *data, struct stat *buf, GError ** mcerror) vfs_file_handler_t *fh = (vfs_file_handler_t *) data; sftpfs_file_handler_data_t *sftpfs_fh = fh->data; struct vfs_s_super *super = fh->ino->super; - sftpfs_super_data_t *super_data = (sftpfs_super_data_t *) super->data; + sftpfs_super_data_t *super_data = SUP; mc_return_val_if_error (mcerror, -1); @@ -269,7 +269,7 @@ sftpfs_read_file (vfs_file_handler_t * file_handler, char *buffer, size_t count, } file_handler_data = file_handler->data; - super_data = (sftpfs_super_data_t *) file_handler->ino->super->data; + super_data = (sftpfs_super_data_t *) file_handler->ino->super; do { @@ -314,7 +314,7 @@ sftpfs_write_file (vfs_file_handler_t * file_handler, const char *buffer, size_t mc_return_val_if_error (mcerror, -1); file_handler_data = (sftpfs_file_handler_data_t *) file_handler->data; - super_data = (sftpfs_super_data_t *) file_handler->ino->super->data; + super_data = (sftpfs_super_data_t *) file_handler->ino->super; file_handler->pos = (off_t) libssh2_sftp_tell64 (file_handler_data->handle); diff --git a/src/vfs/sftpfs/internal.c b/src/vfs/sftpfs/internal.c index 0b03f1d51..2f95c13c8 100644 --- a/src/vfs/sftpfs/internal.c +++ b/src/vfs/sftpfs/internal.c @@ -117,7 +117,7 @@ sftpfs_op_init (sftpfs_super_data_t ** super_data, const vfs_path_element_t ** p if (super == NULL) return FALSE; - *super_data = (sftpfs_super_data_t *) super->data; + *super_data = SUP; if ((*super_data)->sftp_session == NULL) return FALSE; diff --git a/src/vfs/sftpfs/internal.h b/src/vfs/sftpfs/internal.h index 6fd350aeb..4846f5666 100644 --- a/src/vfs/sftpfs/internal.h +++ b/src/vfs/sftpfs/internal.h @@ -21,6 +21,8 @@ #define LIBSSH2_INVALID_SOCKET -1 #endif +#define SUP ((sftpfs_super_data_t *) super) + /*** enums ***************************************************************************************/ typedef enum @@ -35,6 +37,8 @@ typedef enum typedef struct { + struct vfs_s_super base; + sftpfs_auth_type_t auth_type; sftpfs_auth_type_t config_auth_type; diff --git a/src/vfs/sftpfs/vfs_subclass.c b/src/vfs/sftpfs/vfs_subclass.c index 8373e2ee5..3abddbcbe 100644 --- a/src/vfs/sftpfs/vfs_subclass.c +++ b/src/vfs/sftpfs/vfs_subclass.c @@ -65,7 +65,7 @@ sftpfs_cb_is_equal_connection (const vfs_path_element_t * vpath_element, struct (void) vpath; (void) cookie; - orig_connect_info = ((sftpfs_super_data_t *) super->data)->original_connection_info; + orig_connect_info = ((sftpfs_super_data_t *) super)->original_connection_info; result = ((g_strcmp0 (vpath_element->host, orig_connect_info->host) == 0) && (g_strcmp0 (vpath_element->user, orig_connect_info->user) == 0) @@ -74,6 +74,23 @@ sftpfs_cb_is_equal_connection (const vfs_path_element_t * vpath_element, struct return result; } +/* --------------------------------------------------------------------------------------------- */ + +static struct vfs_s_super * +sftpfs_cb_init_connection (struct vfs_class *me) +{ + sftpfs_super_data_t *arch; + + arch = g_new0 (sftpfs_super_data_t, 1); + arch->base.me = me; + arch->base.name = g_strdup (PATH_SEP_STR); + arch->auth_type = NONE; + arch->config_auth_type = NONE; + arch->socket_handle = LIBSSH2_INVALID_SOCKET; + + return VFS_SUPER (arch); +} + /* --------------------------------------------------------------------------------------------- */ /** * Callback for opening new connection. @@ -89,7 +106,7 @@ sftpfs_cb_open_connection (struct vfs_s_super *super, const vfs_path_t * vpath, const vfs_path_element_t * vpath_element) { GError *mcerror = NULL; - sftpfs_super_data_t *sftpfs_super_data; + sftpfs_super_data_t *sftpfs_super_data = SUP; int ret_value; (void) vpath; @@ -101,10 +118,7 @@ sftpfs_cb_open_connection (struct vfs_s_super *super, return -1; } - sftpfs_super_data = g_new0 (sftpfs_super_data_t, 1); - sftpfs_super_data->socket_handle = LIBSSH2_INVALID_SOCKET; sftpfs_super_data->original_connection_info = vfs_path_element_clone (vpath_element); - super->data = sftpfs_super_data; super->path_element = vfs_path_element_clone (vpath_element); sftpfs_fill_connection_data_from_config (super, &mcerror); @@ -114,7 +128,6 @@ sftpfs_cb_open_connection (struct vfs_s_super *super, return -1; } - super->name = g_strdup (PATH_SEP_STR); super->root = vfs_s_new_inode (vpath_element->class, super, vfs_s_default_stat (vpath_element->class, S_IFDIR | 0755)); @@ -136,18 +149,13 @@ static void sftpfs_cb_close_connection (struct vfs_class *me, struct vfs_s_super *super) { GError *mcerror = NULL; - sftpfs_super_data_t *sftpfs_super_data; (void) me; sftpfs_close_connection (super, "Normal Shutdown", &mcerror); - sftpfs_super_data = (sftpfs_super_data_t *) super->data; - if (sftpfs_super_data != NULL) - vfs_path_element_free (sftpfs_super_data->original_connection_info); + vfs_path_element_free (SUP->original_connection_info); mc_error_message (&mcerror, NULL); - - g_free (sftpfs_super_data); } /* --------------------------------------------------------------------------------------------- */ @@ -186,6 +194,7 @@ sftpfs_init_subclass (void) sftpfs_subclass.flags = VFS_S_REMOTE; sftpfs_subclass.archive_same = sftpfs_cb_is_equal_connection; + sftpfs_subclass.new_archive = sftpfs_cb_init_connection; sftpfs_subclass.open_archive = sftpfs_cb_open_connection; sftpfs_subclass.free_archive = sftpfs_cb_close_connection; sftpfs_subclass.dir_load = sftpfs_cb_dir_load; diff --git a/src/vfs/tar/tar.c b/src/vfs/tar/tar.c index 5811f0a9e..be7531053 100644 --- a/src/vfs/tar/tar.c +++ b/src/vfs/tar/tar.c @@ -61,6 +61,8 @@ /*** file scope macro definitions ****************************************************************/ +#define SUP(super) ((tar_super_data_t *) (super)) + /* * Header block on tape. * @@ -215,6 +217,8 @@ typedef enum typedef struct { + struct vfs_s_super base; /* base class */ + int fd; struct stat st; int type; /* Type of the archive */ @@ -230,6 +234,7 @@ static off_t current_tar_position = 0; static union record rec_buf; +/* --------------------------------------------------------------------------------------------- */ /*** file scope functions ************************************************************************/ /* --------------------------------------------------------------------------------------------- */ /** @@ -263,19 +268,30 @@ tar_from_oct (int digs, const char *where) /* --------------------------------------------------------------------------------------------- */ +static struct vfs_s_super * +tar_new_archive (struct vfs_class *me) +{ + tar_super_data_t *arch; + + arch = g_new0 (tar_super_data_t, 1); + arch->base.me = me; + arch->fd = -1; + arch->type = TAR_UNKNOWN; + + return VFS_SUPER (arch); +} + +/* --------------------------------------------------------------------------------------------- */ + static void tar_free_archive (struct vfs_class *me, struct vfs_s_super *archive) { + tar_super_data_t *arch = SUP (archive); + (void) me; - if (archive->data != NULL) - { - tar_super_data_t *arch = (tar_super_data_t *) archive->data; - - if (arch->fd != -1) - mc_close (arch->fd); - g_free (archive->data); - } + if (arch->fd != -1) + mc_close (arch->fd); } /* --------------------------------------------------------------------------------------------- */ @@ -297,11 +313,8 @@ tar_open_archive_int (struct vfs_class *me, const vfs_path_t * vpath, struct vfs } archive->name = g_strdup (vfs_path_as_str (vpath)); - archive->data = g_new (tar_super_data_t, 1); - arch = (tar_super_data_t *) archive->data; + arch = SUP (archive); mc_stat (vpath, &arch->st); - arch->fd = -1; - arch->type = TAR_UNKNOWN; /* Find out the method to handle this tar file */ type = get_compression_type (result, archive->name); @@ -426,7 +439,7 @@ tar_checksum (const union record *header) static void tar_fill_stat (struct vfs_s_super *archive, struct stat *st, union record *header, size_t h_size) { - tar_super_data_t *arch = (tar_super_data_t *) archive->data; + tar_super_data_t *arch = SUP (archive); st->st_mode = tar_from_oct (8, header->header.mode); @@ -516,7 +529,7 @@ tar_fill_stat (struct vfs_s_super *archive, struct stat *st, union record *heade static ReadStatus tar_read_header (struct vfs_class *me, struct vfs_s_super *archive, int tard, size_t * h_size) { - tar_super_data_t *arch = (tar_super_data_t *) archive->data; + tar_super_data_t *arch = SUP (archive); ReadStatus checksum_status; union record *header; static char *next_long_name = NULL, *next_long_link = NULL; @@ -876,7 +889,7 @@ tar_super_same (const vfs_path_element_t * vpath_element, struct vfs_s_super *pa return 0; /* Has the cached archive been changed on the disk? */ - if (((tar_super_data_t *) parc->data)->st.st_mtime < archive_stat->st_mtime) + if (parc != NULL && SUP (parc)->st.st_mtime < archive_stat->st_mtime) { /* Yes, reload! */ vfs_tarfs_ops->free ((vfsid) parc); @@ -894,7 +907,7 @@ static ssize_t tar_read (void *fh, char *buffer, size_t count) { off_t begin = FH->ino->data_offset; - int fd = ((tar_super_data_t *) FH_SUPER->data)->fd; + int fd = SUP (FH_SUPER)->fd; struct vfs_class *me = FH_SUPER->me; ssize_t res; @@ -934,6 +947,7 @@ init_tarfs (void) 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; + tarfs_subclass.new_archive = tar_new_archive; tarfs_subclass.open_archive = tar_open_archive; tarfs_subclass.free_archive = tar_free_archive; tarfs_subclass.fh_open = tar_fh_open;