Files
m241Neelima/components/ip_net2-6.9/ipssh/src/ipssh_sftp_file.c
T
2026-07-30 11:19:44 +05:30

378 lines
10 KiB
C

/*
******************************************************************************
* INTERPEAK SOURCE FILE
*
* Document no: @(#) $Name: VXWORKS_ITER40_2019102207 $ $RCSfile: ipssh_sftp_file.c,v $ $Revision: 1.8.10.1 $
* $Source: /home/interpeak/CVSRoot/ipssh/src/ipssh_sftp_file.c,v $
* $Author: jren $
* $State: Exp $ $Locker: $
*
* INTERPEAK_COPYRIGHT_STRING
* Design and implementation by Roger Boden <roger@interpeak.se>
******************************************************************************
*/
/*
****************************************************************************
* 1 DESCRIPTION
****************************************************************************
* This file implements sftp file operations against a standard file system.
* The implementation can be used as a reference when implementing sftp file
* operations against other sources/sinks, e.g. memory.
*/
/*
****************************************************************************
* 2 CONFIGURATION
****************************************************************************
*/
#include "ipssh_config.h"
#ifdef IPSSH_USE_SFTP
/*
****************************************************************************
* 3 INCLUDE FILES
****************************************************************************
*/
#include "ipssh_h.h"
#include "ipssh.h"
#include "ipssh_sftp.h"
#include "ipssh_buffer.h"
#include <ipcom_type.h>
#include <ipcom_cstyle.h>
#include <ipcom_clib.h>
#include <ipcom_err.h>
#include <ipcom_buffer.h>
#include <ipcom_syslog.h>
/*
****************************************************************************
* 4 DEFINES
****************************************************************************
*/
/*
****************************************************************************
* 5 TYPES
****************************************************************************
*/
/*
****************************************************************************
* 6 EXTERN PROTOTYPES
****************************************************************************
*/
/*
****************************************************************************
* 7 LOCAL PROTOTYPES
****************************************************************************
*/
IP_STATIC Ip_fd ipssh_sftp_file_open(const char *pathname, int omode, Ip_mode_t attrs);
IP_STATIC Ip_fd ipssh_sftp_file_close(Ip_fd fd);
IP_STATIC Ip_err ipssh_sftp_file_stat(const char* path, struct Ip_stat* buf);
IP_STATIC Ip_ssize_t ipssh_sftp_file_read(Ip_fd fd, char* data, Ip_size_t len);
IP_STATIC Ip_ssize_t ipssh_sftp_file_write(Ip_fd fd, const char* data, Ip_size_t len);
IP_STATIC Ip_off_t ipssh_sftp_file_lseek(Ip_fd fd, Ip_u64 offset, int whence);
IP_STATIC IP_DIR* ipssh_sftp_file_opendir(const char* path);
IP_STATIC int ipssh_sftp_file_closedir(IP_DIR* dirp);
IP_STATIC struct Ip_dirent* ipssh_sftp_file_readdir(IP_DIR* dirp);
IP_STATIC int ipssh_sftp_file_mkdir(const char* path, Ip_mode_t mode);
IP_STATIC int ipssh_sftp_file_rmdir(const char* path);
IP_STATIC int ipssh_sftp_file_unlink(const char* path);
IP_STATIC int ipssh_sftp_file_rename(const char* oldpath, const char* newpath);
/*
****************************************************************************
* 8 DATA
****************************************************************************
*/
IP_STATIC Ipssh_sftp_func_cb ipssh_sftp_file_funcs =
{
"File System",
ipssh_sftp_file_open,
ipssh_sftp_file_close,
ipssh_sftp_file_stat,
ipssh_sftp_file_read,
ipssh_sftp_file_write,
ipssh_sftp_file_lseek,
ipssh_sftp_file_opendir,
ipssh_sftp_file_closedir,
ipssh_sftp_file_readdir,
ipssh_sftp_file_mkdir,
ipssh_sftp_file_rmdir,
ipssh_sftp_file_unlink,
ipssh_sftp_file_rename
};
/*
****************************************************************************
* 9 STATIC FUNCTIONS
****************************************************************************
*/
/*
*===========================================================================
* ipssh_sftp_file_open
*===========================================================================
* Description:
* Parameters:
* Returns:
*
*/
IP_STATIC Ip_fd
ipssh_sftp_file_open(const char *path, int omode, Ip_mode_t attrs)
{
/* IPCOM doesn't handle IP_O_TRUNC well, so force an unlink */
if (omode & IP_O_TRUNC)
(void)ipcom_unlink(path);
return ipcom_fileopen(path, omode, attrs);
}
/*
*===========================================================================
* ipssh_sftp_file_close
*===========================================================================
* Description:
* Parameters:
* Returns:
*
*/
IP_STATIC Ip_fd
ipssh_sftp_file_close(Ip_fd fd)
{
return ipcom_fileclose(fd);
}
/*
*===========================================================================
* ipssh_sftp_file_stat
*===========================================================================
* Description:
* Parameters:
* Returns:
*
*/
IP_STATIC Ip_err
ipssh_sftp_file_stat(const char* path, struct Ip_stat* buf)
{
return ipcom_stat(path, buf);
}
/*
*===========================================================================
* ipssh_sftp_file_read
*===========================================================================
* Description:
* Parameters:
* Returns:
*
*/
IP_STATIC Ip_ssize_t
ipssh_sftp_file_read(Ip_fd fd, char* data, Ip_size_t len)
{
return ipcom_fileread(fd, data, len);
}
/*
*===========================================================================
* ipssh_sftp_file_write
*===========================================================================
* Description:
* Parameters:
* Returns:
*
*/
IP_STATIC Ip_ssize_t
ipssh_sftp_file_write(Ip_fd fd, const char* data, Ip_size_t len)
{
return ipcom_filewrite(fd, data, len);
}
/*
*===========================================================================
* ipssh_sftp_file_lseek
*===========================================================================
* Description:
* Parameters:
* Returns:
*
*/
IP_STATIC Ip_off_t
ipssh_sftp_file_lseek(Ip_fd fd, Ip_u64 offset, int whence)
{
Ip_off_t offset_lo;
Ip_off_t offset_hi;
offset_lo = (Ip_off_t)IP_U64_GETLO(offset);
offset_hi = (Ip_off_t)IP_U64_GETHI(offset);
ip_assert(offset_hi == 0);
return ipcom_lseek(fd, offset_lo, whence);
}
/*
*===========================================================================
* ipssh_sftp_file_opendir
*===========================================================================
* Description:
* Parameters:
* Returns:
*
*/
IP_STATIC IP_DIR*
ipssh_sftp_file_opendir(const char* path)
{
return ipcom_opendir(path);
}
/*
*===========================================================================
* ipssh_sftp_file_closedir
*===========================================================================
* Description:
* Parameters:
* Returns:
*
*/
IP_STATIC int
ipssh_sftp_file_closedir(IP_DIR* dirp)
{
return ipcom_closedir(dirp);
}
/*
*===========================================================================
* ipssh_sftp_file_readdir
*===========================================================================
* Description:
* Parameters:
* Returns:
*
*/
IP_STATIC struct Ip_dirent*
ipssh_sftp_file_readdir(IP_DIR* dirp)
{
return ipcom_readdir(dirp);
}
/*
*===========================================================================
* ipssh_sftp_file_mkdir
*===========================================================================
* Description:
* Parameters:
* Returns:
*
*/
IP_STATIC int
ipssh_sftp_file_mkdir(const char* path, Ip_mode_t mode)
{
return ipcom_mkdir(path, mode);
}
/*
*===========================================================================
* ipssh_sftp_file_rmdir
*===========================================================================
* Description:
* Parameters:
* Returns:
*
*/
IP_STATIC int
ipssh_sftp_file_rmdir(const char* path)
{
return ipcom_rmdir(path);
}
/*
*===========================================================================
* ipssh_sftp_file_unlink
*===========================================================================
* Description:
* Parameters:
* Returns:
*
*/
IP_STATIC int
ipssh_sftp_file_unlink(const char* path)
{
return ipcom_unlink(path);
}
/*
*===========================================================================
* ipssh_sftp_file_rename
*===========================================================================
* Description:
* Parameters:
* Returns:
*
*/
IP_STATIC int
ipssh_sftp_file_rename(const char* oldpath, const char* newpath)
{
return ipcom_rename(oldpath, newpath);
}
/*
****************************************************************************
* 10 GLOBAL FUNCTIONS
****************************************************************************
*/
/*
****************************************************************************
* 11 PUBLIC FUNCTIONS
****************************************************************************
*/
/*
*===========================================================================
* ipssh_get_sftp_file_func_cb
*===========================================================================
* Description:
* Parameters:
* Returns:
*
*/
IP_PUBLIC Ipssh_sftp_func_cb*
ipssh_get_sftp_file_func_cb(void)
{
return &ipssh_sftp_file_funcs;
}
#else
int ipssh_sftp_file_empty_file;
#endif /* IPSSH_USE_SFTP */
/*
****************************************************************************
* END OF FILE
****************************************************************************
*/