From 8b3ea959f0d7032742645ceb5f211a80b0168012 Mon Sep 17 00:00:00 2001 From: Slava Zanko Date: Sat, 1 Jun 2013 01:19:38 +0300 Subject: [PATCH] smbfs: implmentation of file-related functions. Code refactoring Signed-off-by: Slava Zanko --- src/vfs/smbfs/Makefile.am | 2 + src/vfs/smbfs/attr.c | 76 +++++ src/vfs/smbfs/dir.c | 10 +- src/vfs/smbfs/file.c | 238 +++++++++++++++ src/vfs/smbfs/internal.c | 80 +++++ src/vfs/smbfs/internal.h | 29 +- src/vfs/smbfs/vfs_class.c | 282 ++++++++++++++++-- tests/src/vfs/smbfs/Makefile.am | 21 +- ...{dir__smbfs_opendir.c => smbfs_dir_open.c} | 6 +- ...{dir__smbfs_readdir.c => smbfs_dir_read.c} | 14 +- .../{stat__smbfs_lstat.c => smbfs_lstat.c} | 2 +- 11 files changed, 703 insertions(+), 57 deletions(-) create mode 100644 src/vfs/smbfs/attr.c create mode 100644 src/vfs/smbfs/file.c rename tests/src/vfs/smbfs/{dir__smbfs_opendir.c => smbfs_dir_open.c} (97%) rename tests/src/vfs/smbfs/{dir__smbfs_readdir.c => smbfs_dir_read.c} (93%) rename tests/src/vfs/smbfs/{stat__smbfs_lstat.c => smbfs_lstat.c} (99%) diff --git a/src/vfs/smbfs/Makefile.am b/src/vfs/smbfs/Makefile.am index b0bd05fa6..32095c7b2 100644 --- a/src/vfs/smbfs/Makefile.am +++ b/src/vfs/smbfs/Makefile.am @@ -3,8 +3,10 @@ AM_CPPFLAGS = $(GLIB_CFLAGS) -I$(top_srcdir) noinst_LTLIBRARIES = libvfs-smbfs.la libvfs_smbfs_la_SOURCES = \ + attr.c \ auth_dialog.c \ dir.c \ + file.c \ init.c init.h \ internal.c internal.h \ stat.c \ diff --git a/src/vfs/smbfs/attr.c b/src/vfs/smbfs/attr.c new file mode 100644 index 000000000..16ed8b351 --- /dev/null +++ b/src/vfs/smbfs/attr.c @@ -0,0 +1,76 @@ +/* Virtual File System: SFTP file system. + The internal functions: attributes + + Copyright (C) 2011 + The Free Software Foundation, Inc. + + Written by: + Ilia Maslakov , 2011 + Slava Zanko , 2011, 2012 + + This file is part of the Midnight Commander. + + The Midnight Commander is free software: you can redistribute it + and/or modify it under the terms of the GNU General Public License as + published by the Free Software Foundation, either version 3 of the License, + or (at your option) any later version. + + The Midnight Commander is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see . + */ + +#include +#include + +#include "lib/global.h" + +#include "internal.h" + +/*** global variables ****************************************************************************/ + +/*** file scope macro definitions ****************************************************************/ + +/*** file scope type declarations ****************************************************************/ + +/*** file scope variables ************************************************************************/ + +/*** file scope functions ************************************************************************/ +/* --------------------------------------------------------------------------------------------- */ + +/* --------------------------------------------------------------------------------------------- */ +/*** public functions ****************************************************************************/ +/* --------------------------------------------------------------------------------------------- */ +/** + * Changes the permissions of the file. + * + * @param vpath path to file or directory + * @param mode mode (see man 2 open) + * @param error pointer to error object + * @return 0 if sucess, negative value otherwise + */ + +int +smbfs_attr_chmod (const vfs_path_t * vpath, mode_t mode, GError ** error) +{ + int rc; + char *smb_url; + const vfs_path_element_t *path_element; + + path_element = vfs_path_get_by_index (vpath, -1); + smb_url = smbfs_make_url (path_element, TRUE); + errno = 0; + rc = smbc_chmod (smb_url, mode); + g_free (smb_url); + + if (rc < 0) + g_set_error (error, MC_ERROR, errno, "%s", smbfs_strerror (errno)); + + return rc; +} + +/* --------------------------------------------------------------------------------------------- */ diff --git a/src/vfs/smbfs/dir.c b/src/vfs/smbfs/dir.c index 3de888875..827b3f6b8 100644 --- a/src/vfs/smbfs/dir.c +++ b/src/vfs/smbfs/dir.c @@ -60,7 +60,7 @@ typedef struct */ void * -smbfs_opendir (const vfs_path_t * vpath, GError ** error) +smbfs_dir_open (const vfs_path_t * vpath, GError ** error) { smbfs_dir_data_t *smbfs_dir = NULL; struct vfs_s_super *super; @@ -104,7 +104,7 @@ smbfs_opendir (const vfs_path_t * vpath, GError ** error) */ void * -smbfs_readdir (void *data, GError ** error) +smbfs_dir_read (void *data, GError ** error) { struct smbc_dirent *smb_direntry; smbfs_dir_data_t *smbfs_dir = (smbfs_dir_data_t *) data; @@ -135,7 +135,7 @@ smbfs_readdir (void *data, GError ** error) */ int -smbfs_closedir (void *data, GError ** error) +smbfs_dir_close (void *data, GError ** error) { int return_code; smbfs_dir_data_t *smbfs_dir = (smbfs_dir_data_t *) data; @@ -161,7 +161,7 @@ smbfs_closedir (void *data, GError ** error) */ int -smbfs_mkdir (const vfs_path_t * vpath, mode_t mode, GError ** error) +smbfs_dir_make (const vfs_path_t * vpath, mode_t mode, GError ** error) { int return_code; char *smb_url; @@ -189,7 +189,7 @@ smbfs_mkdir (const vfs_path_t * vpath, mode_t mode, GError ** error) */ int -smbfs_rmdir (const vfs_path_t * vpath, GError ** error) +smbfs_dir_remove (const vfs_path_t * vpath, GError ** error) { int return_code; char *smb_url; diff --git a/src/vfs/smbfs/file.c b/src/vfs/smbfs/file.c new file mode 100644 index 000000000..a1aa8830b --- /dev/null +++ b/src/vfs/smbfs/file.c @@ -0,0 +1,238 @@ +/* Virtual File System: SFTP file system. + The internal functions: files + + Copyright (C) 2011 + The Free Software Foundation, Inc. + + Written by: + Ilia Maslakov , 2011 + Slava Zanko , 2011, 2012 + + This file is part of the Midnight Commander. + + The Midnight Commander is free software: you can redistribute it + and/or modify it under the terms of the GNU General Public License as + published by the Free Software Foundation, either version 3 of the License, + or (at your option) any later version. + + The Midnight Commander is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see . + */ + +#include +#include + +#include "lib/global.h" + +#include "internal.h" + +/*** global variables ****************************************************************************/ + +/*** file scope macro definitions ****************************************************************/ + +/*** file scope type declarations ****************************************************************/ + +/*** file scope variables ************************************************************************/ + +/*** file scope functions ************************************************************************/ +/* --------------------------------------------------------------------------------------------- */ + +/* --------------------------------------------------------------------------------------------- */ +/*** public functions ****************************************************************************/ +/* --------------------------------------------------------------------------------------------- */ +/** + * Open file. + * + * @param file_handler the file handler data + * @param flags flags (see man 2 open) + * @param mode mode (see man 2 open) + * @param error pointer to the error handler + * @return TRUE if connection was created successfully, FALSE otherwise + */ + +gboolean +smbfs_file_open (vfs_file_handler_t * file_handler, const vfs_path_t * vpath, int flags, + mode_t mode, GError ** error) +{ + const vfs_path_element_t *path_element; + char *smb_url; + + path_element = vfs_path_get_by_index (vpath, -1); + smb_url = smbfs_make_url (path_element, TRUE); + + errno = 0; + file_handler->handle = smbc_open (smb_url, flags, mode); + g_free (smb_url); + + if (file_handler->handle < 0) + g_set_error (error, MC_ERROR, errno, "%s", smbfs_strerror (errno)); + + return (file_handler->handle >= 0); +} + +/* --------------------------------------------------------------------------------------------- */ +/** + * Read up to 'count' bytes from the file descriptor 'file_handler' to the buffer starting at 'buffer'. + * + * @param file_handler file data handler + * @param buffer buffer for data + * @param count data size + * @param error pointer to the error handler + * + * @return 0 on sucess, negative value otherwise + */ + +ssize_t +smbfs_file_read (vfs_file_handler_t * file_handler, char *buffer, size_t count, GError ** error) +{ + ssize_t rc; + + if (file_handler == NULL) + { + g_set_error (error, MC_ERROR, -1, + _("smbfs: No file handler data present for reading file")); + return -1; + } + + errno = 0; + smbfs_file_lseek (file_handler, file_handler->pos, SEEK_SET, NULL); + rc = smbc_read (file_handler->handle, buffer, count); + if (rc < 0) + g_set_error (error, MC_ERROR, errno, "%s", smbfs_strerror (errno)); + else + file_handler->pos += rc; + + return rc; +} + +/* --------------------------------------------------------------------------------------------- */ + +/** + * Close a file descriptor. + * + * @param file_handler file data handler + * @param error pointer to the error handler + * + * @return 0 on sucess, negative value otherwise + */ + +int +smbfs_file_close (vfs_file_handler_t * file_handler, GError ** error) +{ + int rc; + + if (file_handler == NULL) + { + g_set_error (error, MC_ERROR, -1, + _("smbfs: No file handler data present for closing file")); + return -1; + } + + errno = 0; + rc = smbc_close (file_handler->handle); + if (rc < 0) + g_set_error (error, MC_ERROR, errno, "%s", smbfs_strerror (errno)); + + return rc; +} + +/* --------------------------------------------------------------------------------------------- */ + +/** + * Stats the file specified by the file descriptor. + * + * @param data file data handler + * @param buf buffer for store stat-info + * @param error pointer to the error handler + * @return 0 if sucess, negative value otherwise + */ + +int +smbfs_file_stat (vfs_file_handler_t * file_handler, struct stat *buf, GError ** error) +{ + int rc; + + if (file_handler == NULL) + { + g_set_error (error, MC_ERROR, -1, _("smbfs: No file handler data present for fstat file")); + return -1; + } + errno = 0; + rc = smbc_fstat (file_handler->handle, buf); + + if (rc < 0) + g_set_error (error, MC_ERROR, errno, "%s", smbfs_strerror (errno)); + + return rc; +} + +/* --------------------------------------------------------------------------------------------- */ +/** + * Write up to 'count' bytes from the buffer starting at 'buffer' to the descriptor 'file_handler'. + * + * @param file_handler file data handler + * @param buffer buffer for data + * @param count data size + * @param error pointer to the error handler + * + * @return 0 on sucess, negative value otherwise + */ + +ssize_t +smbfs_file_write (vfs_file_handler_t * file_handler, const char *buffer, size_t count, + GError ** error) +{ + ssize_t rc; + + if (file_handler == NULL) + { + g_set_error (error, MC_ERROR, -1, _("smbfs: No file handler data present for fstat file")); + return -1; + } + errno = 0; + rc = smbc_write (file_handler->handle, buffer, count); + + if (rc < 0) + g_set_error (error, MC_ERROR, errno, "%s", smbfs_strerror (errno)); + + return rc; +} + +/* --------------------------------------------------------------------------------------------- */ +/** + * Reposition the offset of the open file associated with the file descriptor. + * + * @param file_handler file data handler + * @param offset file offset + * @param whence method of seek (at begin, at current, at end) + * @param error pointer to the error handler + * + * @return 0 on sucess, negative value otherwise + */ +off_t +smbfs_file_lseek (vfs_file_handler_t * file_handler, off_t offset, int whence, GError ** error) +{ + off_t rc; + + if (file_handler == NULL) + { + g_set_error (error, MC_ERROR, -1, _("smbfs: No file handler data present for fstat file")); + return -1; + } + errno = 0; + rc = smbc_lseek (file_handler->handle, offset, whence); + + if (rc == -1) + g_set_error (error, MC_ERROR, errno, "%s", smbfs_strerror (errno)); + else + file_handler->pos = rc; + + return rc; +} + +/* --------------------------------------------------------------------------------------------- */ diff --git a/src/vfs/smbfs/internal.c b/src/vfs/smbfs/internal.c index 5d21b58bd..76c0c47fb 100644 --- a/src/vfs/smbfs/internal.c +++ b/src/vfs/smbfs/internal.c @@ -215,3 +215,83 @@ smbfs_assign_value_if_not_null (char *value, char **assignee) } /* --------------------------------------------------------------------------------------------- */ +/** + * Delete a name from the file system. + * + * @param vpath path to file or directory + * @param error pointer to error object + * @return 0 if sucess, negative value otherwise + */ + +int +smbfs_unlink (const vfs_path_t * vpath, GError ** error) +{ + int rc; + char *smb_url; + const vfs_path_element_t *path_element; + + path_element = vfs_path_get_by_index (vpath, -1); + smb_url = smbfs_make_url (path_element, TRUE); + errno = 0; + rc = smbc_unlink (smb_url); + g_free (smb_url); + + if (rc < 0) + g_set_error (error, MC_ERROR, errno, "%s", smbfs_strerror (errno)); + + return rc; +} + +/* --------------------------------------------------------------------------------------------- */ +/** + * Rename a file, moving it between directories if required. + * + * @param vpath1 path to source file or directory + * @param vpath2 path to destination file or directory + * @param error pointer to error object + * @return 0 if sucess, negative value otherwise + */ + +int +smbfs_rename (const vfs_path_t * vpath1, const vfs_path_t * vpath2, GError ** error) +{ + int rc; + char *smb_url1, *smb_url2; + const vfs_path_element_t *path_element1, *path_element2; + + path_element1 = vfs_path_get_by_index (vpath1, -1); + path_element2 = vfs_path_get_by_index (vpath2, -1); + smb_url1 = smbfs_make_url (path_element1, TRUE); + smb_url2 = smbfs_make_url (path_element2, TRUE); + errno = 0; + rc = smbc_rename (smb_url1, smb_url2); + g_free (smb_url1); + g_free (smb_url2); + + if (rc < 0) + g_set_error (error, MC_ERROR, errno, "%s", smbfs_strerror (errno)); + + return rc; +} + +/* --------------------------------------------------------------------------------------------- */ + +int +smbfs_file_change_modification_time (const vfs_path_t * vpath, struct utimbuf *tbuf, + GError ** error) +{ + int rc; + char *smb_url; + const vfs_path_element_t *path_element; + + path_element = vfs_path_get_by_index (vpath, -1); + smb_url = smbfs_make_url (path_element, TRUE); + errno = 0; + rc = smbc_utime (smb_url, tbuf); + g_free (smb_url); + + if (rc < 0) + g_set_error (error, MC_ERROR, errno, "%s", smbfs_strerror (errno)); + + return rc; +} diff --git a/src/vfs/smbfs/internal.h b/src/vfs/smbfs/internal.h index 591c3bf75..d28554172 100644 --- a/src/vfs/smbfs/internal.h +++ b/src/vfs/smbfs/internal.h @@ -48,16 +48,35 @@ const char *smbfs_strerror (int err_no); char *smbfs_make_url (const vfs_path_element_t * element, gboolean with_path); -void *smbfs_opendir (const vfs_path_t * vpath, GError ** error); -void *smbfs_readdir (void *data, GError ** error); -int smbfs_closedir (void *data, GError ** error); -int smbfs_mkdir (const vfs_path_t * vpath, mode_t mode, GError ** error); -int smbfs_rmdir (const vfs_path_t * vpath, GError ** error); +void *smbfs_dir_open (const vfs_path_t * vpath, GError ** error); +void *smbfs_dir_read (void *data, GError ** error); +int smbfs_dir_close (void *data, GError ** error); +int smbfs_dir_make (const vfs_path_t * vpath, mode_t mode, GError ** error); +int smbfs_dir_remove (const vfs_path_t * vpath, GError ** error); int smbfs_lstat (const vfs_path_t * vpath, struct stat *buf, GError ** error); int smbfs_stat (const vfs_path_t * vpath, struct stat *buf, GError ** error); + void smbfs_assign_value_if_not_null (char *value, char **assignee); +gboolean smbfs_file_open (vfs_file_handler_t * file_handler, const vfs_path_t * vpath, int flags, + mode_t mode, GError ** error); +int smbfs_file_stat (vfs_file_handler_t * data, struct stat *buf, GError ** error); +off_t smbfs_file_lseek (vfs_file_handler_t * file_handler, off_t offset, int whence, + GError ** error); +ssize_t smbfs_file_read (vfs_file_handler_t * file_handler, char *buffer, size_t count, + GError ** error); +ssize_t smbfs_file_write (vfs_file_handler_t * file_handler, const char *buffer, size_t count, + GError ** error); +int smbfs_file_close (vfs_file_handler_t * file_handler, GError ** error); + +int smbfs_attr_chmod (const vfs_path_t * vpath, mode_t mode, GError ** error); + +int smbfs_unlink (const vfs_path_t * vpath, GError ** error); +int smbfs_rename (const vfs_path_t * vpath1, const vfs_path_t * vpath2, GError ** error); + +int smbfs_file_change_modification_time (const vfs_path_t * vpath, struct utimbuf *tbuf, + GError ** error); /*** inline functions ****************************************************************************/ diff --git a/src/vfs/smbfs/vfs_class.c b/src/vfs/smbfs/vfs_class.c index e7129ae50..342ece503 100644 --- a/src/vfs/smbfs/vfs_class.c +++ b/src/vfs/smbfs/vfs_class.c @@ -27,6 +27,7 @@ #include #include "lib/global.h" +#include "lib/vfs/gc.h" #include "lib/vfs/utilvfs.h" #include "lib/tty/tty.h" /* tty_enable_interrupt_key () */ @@ -99,7 +100,7 @@ smbfs_cb_opendir (const vfs_path_t * vpath) /* reset interrupt flag */ tty_got_interrupt (); - ret_value = smbfs_opendir (vpath, &error); + ret_value = smbfs_dir_open (vpath, &error); vfs_show_gerror (&error); return ret_value; } @@ -124,7 +125,7 @@ smbfs_cb_readdir (void *data) return NULL; } - smbfs_dirent = smbfs_readdir (data, &error); + smbfs_dirent = smbfs_dir_read (data, &error); if (!vfs_show_gerror (&error)) { if (smbfs_dirent != NULL) @@ -150,7 +151,7 @@ smbfs_cb_closedir (void *data) int rc; GError *error = NULL; - rc = smbfs_closedir (data, &error); + rc = smbfs_dir_close (data, &error); vfs_show_gerror (&error); return rc; } @@ -199,7 +200,7 @@ smbfs_cb_mkdir (const vfs_path_t * vpath, mode_t mode) int rc; GError *error = NULL; - rc = smbfs_mkdir (vpath, mode, &error); + rc = smbfs_dir_make (vpath, mode, &error); vfs_show_gerror (&error); return rc; } @@ -219,7 +220,7 @@ smbfs_cb_rmdir (const vfs_path_t * vpath) int rc; GError *error = NULL; - rc = smbfs_rmdir (vpath, &error); + rc = smbfs_dir_remove (vpath, &error); vfs_show_gerror (&error); return rc; } @@ -264,6 +265,247 @@ smbfs_cb_stat (const vfs_path_t * vpath, struct stat *buf) return rc; } +/* --------------------------------------------------------------------------------------------- */ +/** + * Callback for fstat VFS-function. + * + * @param data file data handler + * @param buf buffer for store stat-info + * @return 0 if sucess, negative value otherwise + */ + +static int +smbfs_cb_fstat (void *data, struct stat *buf) +{ + int rc; + GError *error = NULL; + vfs_file_handler_t *file_handler = (vfs_file_handler_t *) data; + + rc = smbfs_file_stat (file_handler, buf, &error); + if (rc < 0) + vfs_show_gerror (&error); + + return rc; +} + +/* --------------------------------------------------------------------------------------------- */ +/** + * Callback for opening file. + * + * @param vpath path to file + * @param flags flags (see man 2 open) + * @param mode mode (see man 2 open) + * @return file data handler if success, NULL otherwise + */ + +static void * +smbfs_cb_open (const vfs_path_t * vpath, int flags, mode_t mode) +{ + vfs_file_handler_t *file_handler; + struct vfs_s_super *super; + GError *error = NULL; + + super = vfs_get_super_by_vpath (vpath, TRUE); + if (super == NULL) + return NULL; + + file_handler = vfs_s_create_file_handler (super, vpath, flags); + if (file_handler == NULL) + return NULL; + + if (!smbfs_file_open (file_handler, vpath, flags, mode, &error)) + { + vfs_show_gerror (&error); + g_free (file_handler); + return NULL; + } + vfs_s_open_file_post_action (vpath, super, file_handler); + + return file_handler; +} + +/* --------------------------------------------------------------------------------------------- */ +/** + * Callback for reading file content. + * + * @param data file data handler + * @param buffer buffer for data + * @param count data size + * @return 0 if sucess, negative value otherwise + */ + +static ssize_t +smbfs_cb_read (void *data, char *buffer, size_t count) +{ + int rc; + GError *error = NULL; + vfs_file_handler_t *fh = (vfs_file_handler_t *) data; + + if (tty_got_interrupt ()) + { + tty_disable_interrupt_key (); + return 0; + } + + rc = smbfs_file_read (fh, buffer, count, &error); + vfs_show_gerror (&error); + return rc; +} + +/* --------------------------------------------------------------------------------------------- */ +/** + * Callback for writing file content. + * + * @param data file data handler + * @param buf buffer for data + * @param count data size + * @return 0 if sucess, negative value otherwise + */ + +static ssize_t +smbfs_cb_write (void *data, const char *buf, size_t nbyte) +{ + int rc; + GError *error = NULL; + vfs_file_handler_t *fh = (vfs_file_handler_t *) data; + + rc = smbfs_file_write (fh, buf, nbyte, &error); + vfs_show_gerror (&error); + return rc; +} + +/* --------------------------------------------------------------------------------------------- */ +/** + * Callback for close file. + * + * @param data file data handler + * @return 0 if sucess, negative value otherwise + */ + +static int +smbfs_cb_close (void *data) +{ + int rc; + GError *error = NULL; + struct vfs_s_super *super; + vfs_file_handler_t *file_handler = (vfs_file_handler_t *) data; + + super = file_handler->ino->super; + + super->fd_usage--; + if (super->fd_usage == 0) + vfs_stamp_create (&smbfs_class, super); + + rc = smbfs_file_close (file_handler, &error); + vfs_show_gerror (&error); + vfs_s_free_inode (&smbfs_class, file_handler->ino); + g_free (file_handler); + + return rc; +} + +/* --------------------------------------------------------------------------------------------- */ +/** + * Callback for lseek VFS-function. + * + * @param data file data handler + * @param offset file offset + * @param whence method of seek (at begin, at current, at end) + * @return 0 if sucess, negative value otherwise + */ + +static off_t +smbfs_cb_lseek (void *data, off_t offset, int whence) +{ + off_t ret_offset; + vfs_file_handler_t *file_handler = (vfs_file_handler_t *) data; + GError *error = NULL; + + ret_offset = smbfs_file_lseek (file_handler, offset, whence, &error); + vfs_show_gerror (&error); + return ret_offset; +} + +/* --------------------------------------------------------------------------------------------- */ +/** + * Callback for chmod VFS-function. + * + * @param vpath path to file or directory + * @param mode mode (see man 2 open) + * @return 0 if sucess, negative value otherwise + */ + +static int +smbfs_cb_chmod (const vfs_path_t * vpath, mode_t mode) +{ + int rc; + GError *error = NULL; + + rc = smbfs_attr_chmod (vpath, mode, &error); + vfs_show_gerror (&error); + return rc; +} + +/* --------------------------------------------------------------------------------------------- */ +/** + * Callback for unlink VFS-function. + * + * @param vpath path to file or directory + * @return 0 if sucess, negative value otherwise + */ + +static int +smbfs_cb_unlink (const vfs_path_t * vpath) +{ + int rc; + GError *error = NULL; + + rc = smbfs_unlink (vpath, &error); + vfs_show_gerror (&error); + return rc; +} + +/* --------------------------------------------------------------------------------------------- */ +/** + * Callback for rename VFS-function. + * + * @param vpath1 path to source file or directory + * @param vpath2 path to destination file or directory + * @return 0 if sucess, negative value otherwise + */ + +static int +smbfs_cb_rename (const vfs_path_t * vpath1, const vfs_path_t * vpath2) +{ + int rc; + GError *error = NULL; + + rc = smbfs_rename (vpath1, vpath2, &error); + vfs_show_gerror (&error); + return rc; +} + +/* --------------------------------------------------------------------------------------------- */ +/** + * Callback for utime VFS-function. + * + * @param vpath unused + * @param times unused + * @return always 0 + */ + +static int +smbfs_cb_utime (const vfs_path_t * vpath, struct utimbuf *times) +{ + int rc; + GError *error = NULL; + + rc = smbfs_file_change_modification_time (vpath, times, &error); + + vfs_show_gerror (&error); + return rc; +} + /* --------------------------------------------------------------------------------------------- */ /*** public functions ****************************************************************************/ /* --------------------------------------------------------------------------------------------- */ @@ -294,33 +536,23 @@ smbfs_init_class_callbacks (void) smbfs_class.done = smbfs_cb_done; smbfs_class.fill_names = smbfs_cb_fill_names; - smbfs_class.opendir = smbfs_cb_opendir; smbfs_class.readdir = smbfs_cb_readdir; smbfs_class.closedir = smbfs_cb_closedir; smbfs_class.mkdir = smbfs_cb_mkdir; smbfs_class.rmdir = smbfs_cb_rmdir; - smbfs_class.stat = smbfs_cb_stat; smbfs_class.lstat = smbfs_cb_lstat; - /* - smbfs_class.fstat = smbfs_cb_fstat; - smbfs_class.symlink = smbfs_cb_symlink; - smbfs_class.link = smbfs_cb_link; - smbfs_class.utime = smbfs_cb_utime; - smbfs_class.mknod = smbfs_cb_mknod; - smbfs_class.chown = smbfs_cb_chown; - smbfs_class.chmod = smbfs_cb_chmod; - - smbfs_class.open = smbfs_cb_open; - smbfs_class.read = smbfs_cb_read; - smbfs_class.write = smbfs_cb_write; - smbfs_class.close = smbfs_cb_close; - smbfs_class.lseek = smbfs_cb_lseek; - smbfs_class.unlink = smbfs_cb_unlink; - smbfs_class.rename = smbfs_cb_rename; - smbfs_class.ferrno = smbfs_cb_errno; - */ + smbfs_class.fstat = smbfs_cb_fstat; + smbfs_class.utime = smbfs_cb_utime; + smbfs_class.chmod = smbfs_cb_chmod; + smbfs_class.open = smbfs_cb_open; + smbfs_class.read = smbfs_cb_read; + smbfs_class.write = smbfs_cb_write; + smbfs_class.close = smbfs_cb_close; + smbfs_class.lseek = smbfs_cb_lseek; + smbfs_class.unlink = smbfs_cb_unlink; + smbfs_class.rename = smbfs_cb_rename; } /* --------------------------------------------------------------------------------------------- */ diff --git a/tests/src/vfs/smbfs/Makefile.am b/tests/src/vfs/smbfs/Makefile.am index 00ed0d368..39e9894f4 100644 --- a/tests/src/vfs/smbfs/Makefile.am +++ b/tests/src/vfs/smbfs/Makefile.am @@ -15,26 +15,25 @@ LIBS=@CHECK_LIBS@ \ $(top_builddir)/lib/libmc.la TESTS = \ - dir__smbfs_opendir \ - dir__smbfs_readdir \ + smbfs_dir_open \ + smbfs_dir_read \ internal__smbfs_make_url \ internal__smbfs_strerror \ - stat__smbfs_lstat + smbfs_lstat check_PROGRAMS = $(TESTS) -dir__smbfs_opendir_SOURCES = \ - dir__smbfs_opendir.c +smbfs_dir_open_SOURCES = \ + smbfs_dir_open.c -dir__smbfs_readdir_SOURCES = \ - dir__smbfs_readdir.c +smbfs_dir_read_SOURCES = \ + smbfs_dir_read.c - -dir__smbfs_strerror_SOURCES = \ +internal__smbfs_strerror_SOURCES = \ internal__smbfs_strerror.c internal__smbfs_make_url_SOURCES = \ internal__smbfs_make_url.c -stat__smbfs_lstat_SOURCES = \ - stat__smbfs_lstat.c +smbfs_lstat_SOURCES = \ + smbfs_lstat.c diff --git a/tests/src/vfs/smbfs/dir__smbfs_opendir.c b/tests/src/vfs/smbfs/smbfs_dir_open.c similarity index 97% rename from tests/src/vfs/smbfs/dir__smbfs_opendir.c rename to tests/src/vfs/smbfs/smbfs_dir_open.c index 108c306a2..6fff6a842 100644 --- a/tests/src/vfs/smbfs/dir__smbfs_opendir.c +++ b/tests/src/vfs/smbfs/smbfs_dir_open.c @@ -150,7 +150,7 @@ START_TEST (test_smbfs_open_dir_fail) /* when */ - actual_result = smbfs_opendir (input_vpath, &error); + actual_result = smbfs_dir_open (input_vpath, &error); /* then */ @@ -196,7 +196,7 @@ START_TEST (test_smbfs_open_dir_success) /* when */ - actual_result = smbfs_opendir (input_vpath, &error); + actual_result = smbfs_dir_open (input_vpath, &error); /* then */ @@ -241,7 +241,7 @@ main (void) suite_add_tcase (s, tc_core); sr = srunner_create (s); - srunner_set_log (sr, "smbfs_opendir.log"); + srunner_set_log (sr, "smbfs_dir_open.log"); srunner_run_all (sr, CK_NORMAL); number_failed = srunner_ntests_failed (sr); srunner_free (sr); diff --git a/tests/src/vfs/smbfs/dir__smbfs_readdir.c b/tests/src/vfs/smbfs/smbfs_dir_read.c similarity index 93% rename from tests/src/vfs/smbfs/dir__smbfs_readdir.c rename to tests/src/vfs/smbfs/smbfs_dir_read.c index 3b448dcf8..08662db17 100644 --- a/tests/src/vfs/smbfs/dir__smbfs_readdir.c +++ b/tests/src/vfs/smbfs/smbfs_dir_read.c @@ -43,7 +43,7 @@ typedef struct /* --------------------------------------------------------------------------------------------- */ -static int smbfs_readdir__errno; +static int smbfs_dir_read__errno; /* @CapturedValue */ static int smbc_readdir__handle__captured; @@ -55,7 +55,7 @@ struct smbc_dirent * smbc_readdir (unsigned int handle) { smbc_readdir__handle__captured = handle; - errno = smbfs_readdir__errno; + errno = smbfs_dir_read__errno; return smbc_readdir__return_value; } @@ -103,8 +103,8 @@ START_TEST (test_smbfs_read_dir_fail) smbc_readdir__return_value = NULL; /* when */ - smbfs_readdir__errno = ENODEV; - actual_result = smbfs_readdir (&input_smbfs_dir_data, &error); + smbfs_dir_read__errno = ENODEV; + actual_result = smbfs_dir_read (&input_smbfs_dir_data, &error); /* then */ @@ -144,8 +144,8 @@ START_TEST (test_smbfs_read_dir_success) /* when */ - smbfs_readdir__errno = 0; - actual_result = smbfs_readdir (&input_smbfs_dir_data, &error); + smbfs_dir_read__errno = 0; + actual_result = smbfs_dir_read (&input_smbfs_dir_data, &error); /* then */ @@ -183,7 +183,7 @@ main (void) suite_add_tcase (s, tc_core); sr = srunner_create (s); - srunner_set_log (sr, "smbfs_readdir.log"); + srunner_set_log (sr, "smbfs_dir_read.log"); srunner_run_all (sr, CK_NORMAL); number_failed = srunner_ntests_failed (sr); srunner_free (sr); diff --git a/tests/src/vfs/smbfs/stat__smbfs_lstat.c b/tests/src/vfs/smbfs/smbfs_lstat.c similarity index 99% rename from tests/src/vfs/smbfs/stat__smbfs_lstat.c rename to tests/src/vfs/smbfs/smbfs_lstat.c index ba88b559e..b7ca9c650 100644 --- a/tests/src/vfs/smbfs/stat__smbfs_lstat.c +++ b/tests/src/vfs/smbfs/smbfs_lstat.c @@ -196,7 +196,7 @@ main (void) suite_add_tcase (s, tc_core); sr = srunner_create (s); - srunner_set_log (sr, "smbfs_opendir.log"); + srunner_set_log (sr, "smbfs_lstat.log"); srunner_run_all (sr, CK_NORMAL); number_failed = srunner_ntests_failed (sr); srunner_free (sr);