Revert "VFS: make VFS-specific file handler class the derived one from vfs_file_handler_t."

This reverts commit 2d58e4d624.
This commit is contained in:
Andrew Borodin 2018-09-10 12:35:17 +03:00
parent 63a9750e5e
commit c91e3d5edb
9 changed files with 91 additions and 123 deletions

View File

@ -363,30 +363,6 @@ vfs_s_free_super (struct vfs_class *me, struct vfs_s_super *super)
g_free (super); g_free (super);
} }
/* --------------------------------------------------------------------------------------------- */
static vfs_file_handler_t *
vfs_s_new_fh (struct vfs_s_inode *ino, gboolean changed)
{
vfs_file_handler_t *fh;
fh = g_new0 (vfs_file_handler_t, 1);
vfs_s_init_fh (fh, ino, changed);
return fh;
}
/* --------------------------------------------------------------------------------------------- */
static void
vfs_s_free_fh (struct vfs_s_subclass *s, vfs_file_handler_t * fh)
{
if (s->fh_free != NULL)
s->fh_free (fh);
g_free (fh);
}
/* --------------------------------------------------------------------------------------------- */ /* --------------------------------------------------------------------------------------------- */
/* Support of archives */ /* Support of archives */
/* ------------------------ readdir & friends ----------------------------- */ /* ------------------------ readdir & friends ----------------------------- */
@ -687,8 +663,9 @@ vfs_s_close (void *fh)
close (FH->handle); close (FH->handle);
vfs_s_free_inode (me, FH->ino); vfs_s_free_inode (me, FH->ino);
vfs_s_free_fh (MEDATA, fh); if (MEDATA->fh_free_data != NULL)
MEDATA->fh_free_data (fh);
g_free (fh);
return res; return res;
} }
@ -1251,17 +1228,6 @@ vfs_s_fullpath (struct vfs_class *me, struct vfs_s_inode *ino)
return g_strconcat (ino->ent->dir->ent->name, PATH_SEP_STR, ino->ent->name, (char *) NULL); return g_strconcat (ino->ent->dir->ent->name, PATH_SEP_STR, ino->ent->name, (char *) NULL);
} }
/* --------------------------------------------------------------------------------------------- */
void
vfs_s_init_fh (vfs_file_handler_t * fh, struct vfs_s_inode *ino, gboolean changed)
{
fh->ino = ino;
fh->handle = -1;
fh->changed = changed;
fh->linear = LS_NOT_LINEAR;
}
/* --------------------------------------------------------------------------------------------- */ /* --------------------------------------------------------------------------------------------- */
/* --------------------------- stat and friends ---------------------------- */ /* --------------------------- stat and friends ---------------------------- */
@ -1341,7 +1307,13 @@ vfs_s_open (const vfs_path_t * vpath, int flags, mode_t mode)
return NULL; return NULL;
} }
fh = s->fh_new != NULL ? s->fh_new (ino, was_changed) : vfs_s_new_fh (ino, was_changed); fh = g_new (vfs_file_handler_t, 1);
fh->pos = 0;
fh->ino = ino;
fh->handle = -1;
fh->changed = was_changed;
fh->linear = LS_NOT_LINEAR;
fh->data = NULL;
if (IS_LINEAR (flags)) if (IS_LINEAR (flags))
{ {
@ -1355,7 +1327,9 @@ vfs_s_open (const vfs_path_t * vpath, int flags, mode_t mode)
{ {
if (s->fh_open != NULL && s->fh_open (path_element->class, fh, flags, mode) != 0) if (s->fh_open != NULL && s->fh_open (path_element->class, fh, flags, mode) != 0)
{ {
vfs_s_free_fh (s, fh); if (s->fh_free_data != NULL)
s->fh_free_data (fh);
g_free (fh);
return NULL; return NULL;
} }
} }
@ -1365,7 +1339,7 @@ vfs_s_open (const vfs_path_t * vpath, int flags, mode_t mode)
fh->handle = open (fh->ino->localname, NO_LINEAR (flags), mode); fh->handle = open (fh->ino->localname, NO_LINEAR (flags), mode);
if (fh->handle == -1) if (fh->handle == -1)
{ {
vfs_s_free_fh (s, fh); g_free (fh);
path_element->class->verrno = errno; path_element->class->verrno = errno;
return NULL; return NULL;
} }
@ -1414,13 +1388,17 @@ vfs_s_retrieve_file (struct vfs_class *me, struct vfs_s_inode *ino)
int handle; int handle;
ssize_t n; ssize_t n;
off_t stat_size = ino->st.st_size; off_t stat_size = ino->st.st_size;
vfs_file_handler_t *fh = NULL; vfs_file_handler_t fh;
vfs_path_t *tmp_vpath; vfs_path_t *tmp_vpath;
struct vfs_s_subclass *s = MEDATA;
if ((s->flags & VFS_S_USETMP) == 0) if ((MEDATA->flags & VFS_S_USETMP) == 0)
return (-1); return (-1);
memset (&fh, 0, sizeof (fh));
fh.ino = ino;
fh.handle = -1;
handle = vfs_mkstemps (&tmp_vpath, me->name, ino->ent->name); handle = vfs_mkstemps (&tmp_vpath, me->name, ino->ent->name);
ino->localname = g_strdup (vfs_path_as_str (tmp_vpath)); ino->localname = g_strdup (vfs_path_as_str (tmp_vpath));
vfs_path_free (tmp_vpath); vfs_path_free (tmp_vpath);
@ -1430,16 +1408,14 @@ vfs_s_retrieve_file (struct vfs_class *me, struct vfs_s_inode *ino)
goto error_4; goto error_4;
} }
fh = s->fh_new != NULL ? s->fh_new (ino, FALSE) : vfs_s_new_fh (ino, FALSE); if (MEDATA->linear_start (me, &fh, 0) == 0)
if (s->linear_start (me, fh, 0) == 0)
goto error_3; goto error_3;
/* Clear the interrupt status */ /* Clear the interrupt status */
tty_got_interrupt (); tty_got_interrupt ();
tty_enable_interrupt_key (); tty_enable_interrupt_key ();
while ((n = s->linear_read (me, fh, buffer, sizeof (buffer))) != 0) while ((n = MEDATA->linear_read (me, &fh, buffer, sizeof (buffer))) != 0)
{ {
int t; int t;
@ -1460,23 +1436,22 @@ vfs_s_retrieve_file (struct vfs_class *me, struct vfs_s_inode *ino)
goto error_1; goto error_1;
} }
} }
s->linear_close (me, fh); MEDATA->linear_close (me, &fh);
close (handle); close (handle);
tty_disable_interrupt_key (); tty_disable_interrupt_key ();
vfs_s_free_fh (s, fh); g_free (fh.data);
return 0; return 0;
error_1: error_1:
s->linear_close (me, fh); MEDATA->linear_close (me, &fh);
error_3: error_3:
tty_disable_interrupt_key (); tty_disable_interrupt_key ();
close (handle); close (handle);
unlink (ino->localname); unlink (ino->localname);
error_4: error_4:
MC_PTR_FREE (ino->localname); MC_PTR_FREE (ino->localname);
if (fh != NULL) g_free (fh.data);
vfs_s_free_fh (s, fh);
return (-1); return (-1);
} }

View File

@ -111,6 +111,7 @@ typedef struct
int handle; /* This is for module's use, but if != -1, will be mc_close()d */ int handle; /* This is for module's use, but if != -1, will be mc_close()d */
gboolean changed; /* Did this file change? */ gboolean changed; /* Did this file change? */
vfs_linear_state_t linear; /* Is that file open with O_LINEAR? */ vfs_linear_state_t linear; /* Is that file open with O_LINEAR? */
void *data; /* This is for filesystem-specific use */
} vfs_file_handler_t; } vfs_file_handler_t;
/* /*
@ -141,10 +142,9 @@ struct vfs_s_subclass
const vfs_path_t * vpath, const vfs_path_element_t * vpath_element); const vfs_path_t * vpath, const vfs_path_element_t * vpath_element);
void (*free_archive) (struct vfs_class * me, struct vfs_s_super * psup); void (*free_archive) (struct vfs_class * me, struct vfs_s_super * psup);
vfs_file_handler_t *(*fh_new) (struct vfs_s_inode * ino, gboolean changed);
int (*fh_open) (struct vfs_class * me, vfs_file_handler_t * fh, int flags, mode_t mode); int (*fh_open) (struct vfs_class * me, vfs_file_handler_t * fh, int flags, mode_t mode);
int (*fh_close) (struct vfs_class * me, vfs_file_handler_t * fh); int (*fh_close) (struct vfs_class * me, vfs_file_handler_t * fh);
void (*fh_free) (vfs_file_handler_t * fh); void (*fh_free_data) (vfs_file_handler_t * fh);
struct vfs_s_entry *(*find_entry) (struct vfs_class * me, struct vfs_s_entry *(*find_entry) (struct vfs_class * me,
struct vfs_s_inode * root, struct vfs_s_inode * root,
@ -189,8 +189,6 @@ struct vfs_s_super *vfs_get_super_by_vpath (const vfs_path_t * vpath);
void vfs_s_invalidate (struct vfs_class *me, struct vfs_s_super *super); void vfs_s_invalidate (struct vfs_class *me, struct vfs_s_super *super);
char *vfs_s_fullpath (struct vfs_class *me, struct vfs_s_inode *ino); char *vfs_s_fullpath (struct vfs_class *me, struct vfs_s_inode *ino);
void vfs_s_init_fh (vfs_file_handler_t * fh, struct vfs_s_inode *ino, gboolean changed);
/* network filesystems support */ /* network filesystems support */
int vfs_s_select_on_two (int fd1, int fd2); int vfs_s_select_on_two (int fd1, int fd2);
int vfs_s_get_line (struct vfs_class *me, int sock, char *buf, int buf_len, char term); int vfs_s_get_line (struct vfs_class *me, int sock, char *buf, int buf_len, char term);

View File

@ -871,9 +871,10 @@ cpio_read (void *fh, char *buffer, size_t count)
static int static int
cpio_fh_open (struct vfs_class *me, vfs_file_handler_t * fh, int flags, mode_t mode) cpio_fh_open (struct vfs_class *me, vfs_file_handler_t * fh, int flags, mode_t mode)
{ {
(void) fh;
(void) mode; (void) mode;
fh->data = NULL;
if ((flags & O_ACCMODE) != O_RDONLY) if ((flags & O_ACCMODE) != O_RDONLY)
ERRNOR (EROFS, -1); ERRNOR (EROFS, -1);
return 0; return 0;

View File

@ -118,7 +118,6 @@ int fish_directory_timeout = 900;
#define FISH_HAVE_TAIL 64 #define FISH_HAVE_TAIL 64
#define SUP ((fish_super_data_t *) super) #define SUP ((fish_super_data_t *) super)
#define FISH_FH ((fish_fh_data_t *) fh)
/*** file scope type declarations ****************************************************************/ /*** file scope type declarations ****************************************************************/
@ -149,8 +148,6 @@ typedef struct
typedef struct typedef struct
{ {
vfs_file_handler_t base; /* base class */
off_t got; off_t got;
off_t total; off_t total;
gboolean append; gboolean append;
@ -960,7 +957,7 @@ fish_dir_load (struct vfs_class *me, struct vfs_s_inode *dir, char *remote_path)
static int static int
fish_file_store (struct vfs_class *me, vfs_file_handler_t * fh, char *name, char *localname) fish_file_store (struct vfs_class *me, vfs_file_handler_t * fh, char *name, char *localname)
{ {
fish_fh_data_t *fish = FISH_FH; fish_fh_data_t *fish = (fish_fh_data_t *) fh->data;
struct vfs_s_super *super = FH_SUPER; struct vfs_s_super *super = FH_SUPER;
int code; int code;
off_t total = 0; off_t total = 0;
@ -1069,11 +1066,16 @@ fish_file_store (struct vfs_class *me, vfs_file_handler_t * fh, char *name, char
static int static int
fish_linear_start (struct vfs_class *me, vfs_file_handler_t * fh, off_t offset) fish_linear_start (struct vfs_class *me, vfs_file_handler_t * fh, off_t offset)
{ {
fish_fh_data_t *fish = FISH_FH; fish_fh_data_t *fish;
struct vfs_s_super *super = FH_SUPER; struct vfs_s_super *super = FH_SUPER;
char *name; char *name;
char *quoted_name; char *quoted_name;
if (fh->data == NULL)
fh->data = g_new0 (fish_fh_data_t, 1);
fish = (fish_fh_data_t *) fh->data;
name = vfs_s_fullpath (me, fh->ino); name = vfs_s_fullpath (me, fh->ino);
if (name == NULL) if (name == NULL)
return 0; return 0;
@ -1114,7 +1116,7 @@ fish_linear_start (struct vfs_class *me, vfs_file_handler_t * fh, off_t offset)
static void static void
fish_linear_abort (struct vfs_class *me, vfs_file_handler_t * fh) fish_linear_abort (struct vfs_class *me, vfs_file_handler_t * fh)
{ {
fish_fh_data_t *fish = FISH_FH; fish_fh_data_t *fish = (fish_fh_data_t *) fh->data;
struct vfs_s_super *super = FH_SUPER; struct vfs_s_super *super = FH_SUPER;
char buffer[BUF_8K]; char buffer[BUF_8K];
ssize_t n; ssize_t n;
@ -1145,7 +1147,7 @@ fish_linear_abort (struct vfs_class *me, vfs_file_handler_t * fh)
static ssize_t static ssize_t
fish_linear_read (struct vfs_class *me, vfs_file_handler_t * fh, void *buf, size_t len) fish_linear_read (struct vfs_class *me, vfs_file_handler_t * fh, void *buf, size_t len)
{ {
fish_fh_data_t *fish = FISH_FH; fish_fh_data_t *fish = (fish_fh_data_t *) fh->data;
struct vfs_s_super *super = FH_SUPER; struct vfs_s_super *super = FH_SUPER;
ssize_t n = 0; ssize_t n = 0;
@ -1173,7 +1175,7 @@ fish_linear_read (struct vfs_class *me, vfs_file_handler_t * fh, void *buf, size
static void static void
fish_linear_close (struct vfs_class *me, vfs_file_handler_t * fh) fish_linear_close (struct vfs_class *me, vfs_file_handler_t * fh)
{ {
fish_fh_data_t *fish = FISH_FH; fish_fh_data_t *fish = (fish_fh_data_t *) fh->data;
if (fish->total != fish->got) if (fish->total != fish->got)
fish_linear_abort (me, fh); fish_linear_abort (me, fh);
@ -1624,15 +1626,11 @@ fish_rmdir (const vfs_path_t * vpath)
/* --------------------------------------------------------------------------------------------- */ /* --------------------------------------------------------------------------------------------- */
static vfs_file_handler_t * static void
fish_fh_new (struct vfs_s_inode *ino, gboolean changed) fish_fh_free_data (vfs_file_handler_t * fh)
{ {
fish_fh_data_t *fh; if (fh != NULL)
MC_PTR_FREE (fh->data);
fh = g_new0 (fish_fh_data_t, 1);
vfs_s_init_fh ((vfs_file_handler_t *) fh, ino, changed);
return FH;
} }
/* --------------------------------------------------------------------------------------------- */ /* --------------------------------------------------------------------------------------------- */
@ -1640,10 +1638,13 @@ fish_fh_new (struct vfs_s_inode *ino, gboolean changed)
static int static int
fish_fh_open (struct vfs_class *me, vfs_file_handler_t * fh, int flags, mode_t mode) fish_fh_open (struct vfs_class *me, vfs_file_handler_t * fh, int flags, mode_t mode)
{ {
fish_fh_data_t *fish = FISH_FH; fish_fh_data_t *fish;
(void) mode; (void) mode;
fh->data = g_new0 (fish_fh_data_t, 1);
fish = (fish_fh_data_t *) fh->data;
/* File will be written only, so no need to retrieve it */ /* File will be written only, so no need to retrieve it */
if (((flags & O_WRONLY) == O_WRONLY) && ((flags & (O_RDONLY | O_RDWR)) == 0)) if (((flags & O_WRONLY) == O_WRONLY) && ((flags & (O_RDONLY | O_RDWR)) == 0))
{ {
@ -1675,6 +1676,7 @@ fish_fh_open (struct vfs_class *me, vfs_file_handler_t * fh, int flags, mode_t m
return 0; return 0;
fail: fail:
fish_fh_free_data (fh);
return -1; return -1;
} }
@ -1746,8 +1748,8 @@ init_fish (void)
fish_subclass.new_archive = fish_new_archive; fish_subclass.new_archive = fish_new_archive;
fish_subclass.open_archive = fish_open_archive; fish_subclass.open_archive = fish_open_archive;
fish_subclass.free_archive = fish_free_archive; fish_subclass.free_archive = fish_free_archive;
fish_subclass.fh_new = fish_fh_new;
fish_subclass.fh_open = fish_fh_open; fish_subclass.fh_open = fish_fh_open;
fish_subclass.fh_free_data = fish_fh_free_data;
fish_subclass.dir_load = fish_dir_load; fish_subclass.dir_load = fish_dir_load;
fish_subclass.file_store = fish_file_store; fish_subclass.file_store = fish_file_store;
fish_subclass.linear_start = fish_linear_start; fish_subclass.linear_start = fish_linear_start;

View File

@ -154,8 +154,7 @@ gboolean ftpfs_ignore_chattr_errors = TRUE;
#endif #endif
#define SUP ((ftp_super_data_t *) super) #define SUP ((ftp_super_data_t *) super)
#define FTP_FH ((ftp_fh_data_t *) fh) #define FH_SOCK ((ftp_fh_data_t *) fh)->sock
#define FH_SOCK FTP_FH->sock
#ifndef INADDR_NONE #ifndef INADDR_NONE
#define INADDR_NONE 0xffffffff #define INADDR_NONE 0xffffffff
@ -225,8 +224,6 @@ typedef struct
typedef struct typedef struct
{ {
vfs_file_handler_t base; /* base class */
int sock; int sock;
int append; int append;
} ftp_fh_data_t; } ftp_fh_data_t;
@ -1853,7 +1850,7 @@ ftpfs_file_store (struct vfs_class *me, vfs_file_handler_t * fh, char *name, cha
struct stat s; struct stat s;
char *w_buf; char *w_buf;
struct vfs_s_super *super = FH_SUPER; struct vfs_s_super *super = FH_SUPER;
ftp_fh_data_t *ftp = FTP_FH; ftp_fh_data_t *ftp = (ftp_fh_data_t *) fh->data;
h = open (localname, O_RDONLY); h = open (localname, O_RDONLY);
if (h == -1) if (h == -1)
@ -1937,6 +1934,9 @@ ftpfs_linear_start (struct vfs_class *me, vfs_file_handler_t * fh, off_t offset)
{ {
char *name; char *name;
if (fh->data == NULL)
fh->data = g_new0 (ftp_fh_data_t, 1);
name = vfs_s_fullpath (me, fh->ino); name = vfs_s_fullpath (me, fh->ino);
if (name == NULL) if (name == NULL)
return 0; return 0;
@ -1945,7 +1945,7 @@ ftpfs_linear_start (struct vfs_class *me, vfs_file_handler_t * fh, off_t offset)
if (FH_SOCK == -1) if (FH_SOCK == -1)
ERRNOR (EACCES, 0); ERRNOR (EACCES, 0);
fh->linear = LS_LINEAR_OPEN; fh->linear = LS_LINEAR_OPEN;
FTP_FH->append = 0; ((ftp_fh_data_t *) fh->data)->append = 0;
return 1; return 1;
} }
@ -2006,7 +2006,7 @@ ftpfs_ctl (void *fh, int ctlop, void *arg)
if (FH->linear == LS_LINEAR_CLOSED || FH->linear == LS_LINEAR_PREOPEN) if (FH->linear == LS_LINEAR_CLOSED || FH->linear == LS_LINEAR_PREOPEN)
return 0; return 0;
v = vfs_s_select_on_two (FH_SOCK, 0); v = vfs_s_select_on_two (((ftp_fh_data_t *) (FH->data))->sock, 0);
return (((v < 0) && (errno == EINTR)) || v == 0) ? 1 : 0; return (((v < 0) && (errno == EINTR)) || v == 0) ? 1 : 0;
} }
default: default:
@ -2197,16 +2197,11 @@ ftpfs_rmdir (const vfs_path_t * vpath)
/* --------------------------------------------------------------------------------------------- */ /* --------------------------------------------------------------------------------------------- */
static vfs_file_handler_t * static void
ftpfs_fh_new (struct vfs_s_inode *ino, gboolean changed) ftpfs_fh_free_data (vfs_file_handler_t * fh)
{ {
ftp_fh_data_t *fh; if (fh != NULL)
MC_PTR_FREE (fh->data);
fh = g_new0 (ftp_fh_data_t, 1);
vfs_s_init_fh ((vfs_file_handler_t *) fh, ino, changed);
fh->sock = -1;
return FH;
} }
/* --------------------------------------------------------------------------------------------- */ /* --------------------------------------------------------------------------------------------- */
@ -2214,10 +2209,12 @@ ftpfs_fh_new (struct vfs_s_inode *ino, gboolean changed)
static int static int
ftpfs_fh_open (struct vfs_class *me, vfs_file_handler_t * fh, int flags, mode_t mode) ftpfs_fh_open (struct vfs_class *me, vfs_file_handler_t * fh, int flags, mode_t mode)
{ {
ftp_fh_data_t *ftp = FTP_FH; ftp_fh_data_t *ftp;
(void) mode; (void) mode;
fh->data = g_new0 (ftp_fh_data_t, 1);
ftp = (ftp_fh_data_t *) fh->data;
/* File will be written only, so no need to retrieve it from ftp server */ /* File will be written only, so no need to retrieve it from ftp server */
if (((flags & O_WRONLY) == O_WRONLY) && ((flags & (O_RDONLY | O_RDWR)) == 0)) if (((flags & O_WRONLY) == O_WRONLY) && ((flags & (O_RDONLY | O_RDWR)) == 0))
{ {
@ -2283,6 +2280,7 @@ ftpfs_fh_open (struct vfs_class *me, vfs_file_handler_t * fh, int flags, mode_t
return 0; return 0;
fail: fail:
ftpfs_fh_free_data (fh);
return -1; return -1;
} }
@ -2659,9 +2657,9 @@ init_ftpfs (void)
ftpfs_subclass.new_archive = ftpfs_new_archive; ftpfs_subclass.new_archive = ftpfs_new_archive;
ftpfs_subclass.open_archive = ftpfs_open_archive; ftpfs_subclass.open_archive = ftpfs_open_archive;
ftpfs_subclass.free_archive = ftpfs_free_archive; ftpfs_subclass.free_archive = ftpfs_free_archive;
ftpfs_subclass.fh_new = ftpfs_fh_new;
ftpfs_subclass.fh_open = ftpfs_fh_open; ftpfs_subclass.fh_open = ftpfs_fh_open;
ftpfs_subclass.fh_close = ftpfs_fh_close; ftpfs_subclass.fh_close = ftpfs_fh_close;
ftpfs_subclass.fh_free_data = ftpfs_fh_free_data;
ftpfs_subclass.dir_load = ftpfs_dir_load; ftpfs_subclass.dir_load = ftpfs_dir_load;
ftpfs_subclass.file_store = ftpfs_file_store; ftpfs_subclass.file_store = ftpfs_file_store;
ftpfs_subclass.linear_start = ftpfs_linear_start; ftpfs_subclass.linear_start = ftpfs_linear_start;

View File

@ -39,14 +39,10 @@
/*** file scope macro definitions ****************************************************************/ /*** file scope macro definitions ****************************************************************/
#define SFTP_FH ((sftpfs_file_handler_data_t *) file_handler)
/*** file scope type declarations ****************************************************************/ /*** file scope type declarations ****************************************************************/
typedef struct typedef struct
{ {
vfs_file_handler_t base; /* base class */
LIBSSH2_SFTP_HANDLE *handle; LIBSSH2_SFTP_HANDLE *handle;
int flags; int flags;
mode_t mode; mode_t mode;
@ -66,12 +62,13 @@ typedef struct
static void static void
sftpfs_reopen (vfs_file_handler_t * file_handler, GError ** mcerror) sftpfs_reopen (vfs_file_handler_t * file_handler, GError ** mcerror)
{ {
sftpfs_file_handler_data_t *file_handler_data = SFTP_FH; sftpfs_file_handler_data_t *file_handler_data;
int flags; int flags;
mode_t mode; mode_t mode;
g_return_if_fail (mcerror == NULL || *mcerror == NULL); g_return_if_fail (mcerror == NULL || *mcerror == NULL);
file_handler_data = (sftpfs_file_handler_data_t *) file_handler->data;
flags = file_handler_data->flags; flags = file_handler_data->flags;
mode = file_handler_data->mode; mode = file_handler_data->mode;
@ -98,19 +95,6 @@ sftpfs_file__handle_error (sftpfs_super_data_t * super_data, int sftp_res, GErro
/* --------------------------------------------------------------------------------------------- */ /* --------------------------------------------------------------------------------------------- */
/*** public functions ****************************************************************************/ /*** public functions ****************************************************************************/
/* --------------------------------------------------------------------------------------------- */
vfs_file_handler_t *
sftpfs_fh_new (struct vfs_s_inode * ino, gboolean changed)
{
sftpfs_file_handler_data_t *fh;
fh = g_new0 (sftpfs_file_handler_data_t, 1);
vfs_s_init_fh ((vfs_file_handler_t *) fh, ino, changed);
return FH;
}
/* --------------------------------------------------------------------------------------------- */ /* --------------------------------------------------------------------------------------------- */
/** /**
* Open new SFTP file. * Open new SFTP file.
@ -128,7 +112,7 @@ sftpfs_open_file (vfs_file_handler_t * file_handler, int flags, mode_t mode, GEr
unsigned long sftp_open_flags = 0; unsigned long sftp_open_flags = 0;
int sftp_open_mode = 0; int sftp_open_mode = 0;
gboolean do_append = FALSE; gboolean do_append = FALSE;
sftpfs_file_handler_data_t *file_handler_data = SFTP_FH; sftpfs_file_handler_data_t *file_handler_data;
sftpfs_super_data_t *super_data; sftpfs_super_data_t *super_data;
char *name; char *name;
@ -140,6 +124,7 @@ sftpfs_open_file (vfs_file_handler_t * file_handler, int flags, mode_t mode, GEr
return FALSE; return FALSE;
super_data = (sftpfs_super_data_t *) file_handler->ino->super; 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) if ((flags & O_CREAT) != 0 || (flags & O_WRONLY) != 0)
{ {
@ -186,6 +171,7 @@ sftpfs_open_file (vfs_file_handler_t * file_handler, int flags, mode_t mode, GEr
file_handler_data->flags = flags; file_handler_data->flags = flags;
file_handler_data->mode = mode; file_handler_data->mode = mode;
file_handler->data = file_handler_data;
if (do_append) if (do_append)
{ {
@ -226,7 +212,7 @@ sftpfs_fstat (void *data, struct stat *buf, GError ** mcerror)
int res; int res;
LIBSSH2_SFTP_ATTRIBUTES attrs; LIBSSH2_SFTP_ATTRIBUTES attrs;
vfs_file_handler_t *fh = (vfs_file_handler_t *) data; vfs_file_handler_t *fh = (vfs_file_handler_t *) data;
sftpfs_file_handler_data_t *sftpfs_fh = (sftpfs_file_handler_data_t *) data; sftpfs_file_handler_data_t *sftpfs_fh = fh->data;
struct vfs_s_super *super = fh->ino->super; struct vfs_s_super *super = fh->ino->super;
sftpfs_super_data_t *super_data = SUP; sftpfs_super_data_t *super_data = SUP;
@ -270,18 +256,19 @@ ssize_t
sftpfs_read_file (vfs_file_handler_t * file_handler, char *buffer, size_t count, GError ** mcerror) sftpfs_read_file (vfs_file_handler_t * file_handler, char *buffer, size_t count, GError ** mcerror)
{ {
ssize_t rc; ssize_t rc;
sftpfs_file_handler_data_t *file_handler_data = SFTP_FH; sftpfs_file_handler_data_t *file_handler_data;
sftpfs_super_data_t *super_data; sftpfs_super_data_t *super_data;
mc_return_val_if_error (mcerror, -1); mc_return_val_if_error (mcerror, -1);
if (file_handler == NULL) if (file_handler == NULL || file_handler->data == NULL)
{ {
mc_propagate_error (mcerror, 0, "%s", mc_propagate_error (mcerror, 0, "%s",
_("sftp: No file handler data present for reading file")); _("sftp: No file handler data present for reading file"));
return -1; return -1;
} }
file_handler_data = file_handler->data;
super_data = (sftpfs_super_data_t *) file_handler->ino->super; super_data = (sftpfs_super_data_t *) file_handler->ino->super;
do do
@ -321,11 +308,12 @@ sftpfs_write_file (vfs_file_handler_t * file_handler, const char *buffer, size_t
GError ** mcerror) GError ** mcerror)
{ {
ssize_t rc; ssize_t rc;
sftpfs_file_handler_data_t *file_handler_data = SFTP_FH; sftpfs_file_handler_data_t *file_handler_data;
sftpfs_super_data_t *super_data; sftpfs_super_data_t *super_data;
mc_return_val_if_error (mcerror, -1); 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; super_data = (sftpfs_super_data_t *) file_handler->ino->super;
file_handler->pos = (off_t) libssh2_sftp_tell64 (file_handler_data->handle); file_handler->pos = (off_t) libssh2_sftp_tell64 (file_handler_data->handle);
@ -361,13 +349,19 @@ sftpfs_write_file (vfs_file_handler_t * file_handler, const char *buffer, size_t
int int
sftpfs_close_file (vfs_file_handler_t * file_handler, GError ** mcerror) sftpfs_close_file (vfs_file_handler_t * file_handler, GError ** mcerror)
{ {
int ret; sftpfs_file_handler_data_t *file_handler_data;
int ret = -1;
mc_return_val_if_error (mcerror, -1); mc_return_val_if_error (mcerror, -1);
ret = libssh2_sftp_close (SFTP_FH->handle); file_handler_data = (sftpfs_file_handler_data_t *) file_handler->data;
if (file_handler_data != NULL)
{
ret = libssh2_sftp_close (file_handler_data->handle);
g_free (file_handler_data);
}
return ret == 0 ? 0 : -1; return ret;
} }
/* --------------------------------------------------------------------------------------------- */ /* --------------------------------------------------------------------------------------------- */
@ -386,7 +380,7 @@ sftpfs_close_file (vfs_file_handler_t * file_handler, GError ** mcerror)
off_t off_t
sftpfs_lseek (vfs_file_handler_t * file_handler, off_t offset, int whence, GError ** mcerror) sftpfs_lseek (vfs_file_handler_t * file_handler, off_t offset, int whence, GError ** mcerror)
{ {
sftpfs_file_handler_data_t *file_handler_data = SFTP_FH; sftpfs_file_handler_data_t *file_handler_data;
mc_return_val_if_error (mcerror, 0); mc_return_val_if_error (mcerror, 0);
@ -419,6 +413,8 @@ sftpfs_lseek (vfs_file_handler_t * file_handler, off_t offset, int whence, GErro
break; break;
} }
file_handler_data = (sftpfs_file_handler_data_t *) file_handler->data;
libssh2_sftp_seek64 (file_handler_data->handle, file_handler->pos); libssh2_sftp_seek64 (file_handler_data->handle, file_handler->pos);
file_handler->pos = (off_t) libssh2_sftp_tell64 (file_handler_data->handle); file_handler->pos = (off_t) libssh2_sftp_tell64 (file_handler_data->handle);

View File

@ -89,8 +89,6 @@ int sftpfs_open_connection (struct vfs_s_super *super, GError ** mcerror);
void sftpfs_close_connection (struct vfs_s_super *super, const char *shutdown_message, void sftpfs_close_connection (struct vfs_s_super *super, const char *shutdown_message,
GError ** mcerror); GError ** mcerror);
vfs_file_handler_t *sftpfs_fh_new (struct vfs_s_inode *ino, gboolean changed);
void *sftpfs_opendir (const vfs_path_t * vpath, GError ** mcerror); void *sftpfs_opendir (const vfs_path_t * vpath, GError ** mcerror);
void *sftpfs_readdir (void *data, GError ** mcerror); void *sftpfs_readdir (void *data, GError ** mcerror);
int sftpfs_closedir (void *data, GError ** mcerror); int sftpfs_closedir (void *data, GError ** mcerror);

View File

@ -149,6 +149,7 @@ sftpfs_cb_open (const vfs_path_t * vpath, int flags, mode_t mode)
file_handler->handle = -1; file_handler->handle = -1;
file_handler->changed = is_changed; file_handler->changed = is_changed;
file_handler->linear = LS_NOT_LINEAR; file_handler->linear = LS_NOT_LINEAR;
file_handler->data = NULL;
if (!sftpfs_open_file (file_handler, flags, mode, &mcerror)) if (!sftpfs_open_file (file_handler, flags, mode, &mcerror))
{ {

View File

@ -197,7 +197,6 @@ sftpfs_init_subclass (void)
sftpfs_subclass.new_archive = sftpfs_cb_init_connection; sftpfs_subclass.new_archive = sftpfs_cb_init_connection;
sftpfs_subclass.open_archive = sftpfs_cb_open_connection; sftpfs_subclass.open_archive = sftpfs_cb_open_connection;
sftpfs_subclass.free_archive = sftpfs_cb_close_connection; sftpfs_subclass.free_archive = sftpfs_cb_close_connection;
sftpfs_subclass.fh_new = sftpfs_fh_new;
sftpfs_subclass.dir_load = sftpfs_cb_dir_load; sftpfs_subclass.dir_load = sftpfs_cb_dir_load;
} }