Skip to content

Commit b19ecb5

Browse files
authored
Merge pull request #805 from JacobBarthelmeh/port
move user filesystem override to the top of the ports check
2 parents 0e5d1fc + 65e3171 commit b19ecb5

File tree

5 files changed

+59
-62
lines changed

5 files changed

+59
-62
lines changed

ide/IAR-EWARM/Projects/lib/myFilesystem.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -144,12 +144,12 @@ static int SFTP_GetAttributes(void* fs, const char* fileName,
144144
}
145145

146146
static int SFTP_GetAttributes_Handle(void* ssh, byte* handle, int handleSz,
147-
void* atr) {
148-
(void)ssh; (void)handle; (void)handleSz;
147+
char* name, void* atr) {
148+
(void)ssh; (void)handle; (void)handleSz; (void)name;
149149

150150
return 0;
151151
}
152152

153153
#endif /* WOLFSSH_USER_FILESYSTEM */
154154

155-
#endif
155+
#endif

ide/STM32CUBE/myFilesystem.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -141,8 +141,8 @@ static inline int SFTP_GetAttributes(void* fs, const char* fileName,
141141
}
142142

143143
static inline int SFTP_GetAttributes_Handle(void* ssh, byte* handle, int handleSz,
144-
void* atr) {
145-
(void)ssh; (void)handle; (void)handleSz;
144+
char* name, void* atr) {
145+
(void)ssh; (void)handle; (void)handleSz; (void)name;
146146

147147
return 0;
148148
}

src/port.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -660,7 +660,7 @@ int wPread(WFD fd, unsigned char* buf, unsigned int sz,
660660

661661
#endif
662662

663-
#ifndef NO_FILESYSTEM
663+
#if !defined(NO_FILESYSTEM) && !defined(WOLFSSH_USER_FILESYSTEM)
664664
#if defined(MICROCHIP_MPLAB_HARMONY)
665665
int wChmod(const char *path, int mode)
666666
{

src/wolfsftp.c

Lines changed: 42 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -994,11 +994,11 @@ static INLINE int SFTP_GetSz(byte* buf, word32* sz,
994994

995995
#ifndef NO_WOLFSSH_SERVER
996996

997-
#ifndef WOLFSSH_USER_FILESYSTEM
997+
#if !defined(WOLFSSH_USER_FILESYSTEM)
998998
static int SFTP_GetAttributes(void* fs, const char* fileName,
999999
WS_SFTP_FILEATRB* atr, byte noFollow, void* heap);
10001000
static int SFTP_GetAttributes_Handle(WOLFSSH* ssh, byte* handle, int handleSz,
1001-
WS_SFTP_FILEATRB* atr);
1001+
char* name, WS_SFTP_FILEATRB* atr);
10021002
#endif
10031003

10041004
/* unique from other packets because the request ID is not also sent.
@@ -3135,7 +3135,9 @@ static int wolfSSH_SFTPNAME_readdir(WOLFSSH* ssh, WDIR* dir, WS_SFTPNAME* out,
31353135
}
31363136

31373137
#elif defined(MICROCHIP_MPLAB_HARMONY)
3138+
#ifndef WOLFSSH_USER_FILESYSTEM
31383139
int SFTP_GetAttributesStat(WS_SFTP_FILEATRB* atr, WSTAT_T* stats);
3140+
#endif
31393141

31403142
/* helper function that gets file information from reading directory
31413143
*
@@ -4416,7 +4418,10 @@ int SFTP_RemoveHandleNode(WOLFSSH* ssh, byte* handle, word32 handleSz)
44164418
#endif /* WOLFSSH_STOREHANDLE */
44174419

44184420

4419-
#ifdef WOLFSSL_NUCLEUS
4421+
#if defined(WOLFSSH_USER_FILESYSTEM)
4422+
/* User-defined I/O support */
4423+
4424+
#elif defined(WOLFSSL_NUCLEUS)
44204425

44214426
#ifndef NO_WOLFSSH_MKTIME
44224427

@@ -4539,22 +4544,15 @@ int SFTP_GetAttributes(void* fs, const char* fileName, WS_SFTP_FILEATRB* atr,
45394544
* returns WS_SUCCESS on success
45404545
*/
45414546
int SFTP_GetAttributes_Handle(WOLFSSH* ssh, byte* handle, int handleSz,
4542-
WS_SFTP_FILEATRB* atr)
4547+
char* name, WS_SFTP_FILEATRB* atr)
45434548
{
45444549
DSTAT stats;
4545-
WS_HANDLE_LIST* cur;
45464550

45474551
if (handle == NULL || atr == NULL) {
45484552
return WS_FATAL_ERROR;
45494553
}
45504554

4551-
cur = SFTP_GetHandleNode(ssh, handle, handleSz);
4552-
if (cur == NULL) {
4553-
WLOG(WS_LOG_SFTP, "Unknown handle");
4554-
return WS_BAD_FILE_E;
4555-
}
4556-
4557-
if (WSTAT(ssh->fs, cur->name, &stats) != NU_SUCCESS) {
4555+
if (WSTAT(ssh->fs, name, &stats) != NU_SUCCESS) {
45584556
return WS_FATAL_ERROR;
45594557
}
45604558

@@ -4708,10 +4706,9 @@ int SFTP_GetAttributes(void* fs, const char* fileName, WS_SFTP_FILEATRB* atr,
47084706
* Fills out a WS_SFTP_FILEATRB structure
47094707
* returns WS_SUCCESS on success */
47104708
int SFTP_GetAttributes_Handle(WOLFSSH* ssh, byte* handle, int handleSz,
4711-
WS_SFTP_FILEATRB* atr)
4709+
char* name, WS_SFTP_FILEATRB* atr)
47124710
{
47134711
int err;
4714-
WS_HANDLE_LIST* cur;
47154712
MQX_FILE_PTR mfs_ptr;
47164713
MFS_SEARCH_DATA search_data;
47174714
MFS_SEARCH_PARAM search;
@@ -4721,14 +4718,8 @@ int SFTP_GetAttributes_Handle(WOLFSSH* ssh, byte* handle, int handleSz,
47214718
}
47224719
mfs_ptr = (MQX_FILE_PTR)ssh->fs;
47234720

4724-
cur = SFTP_GetHandleNode(ssh, handle, handleSz);
4725-
if (cur == NULL) {
4726-
WLOG(WS_LOG_SFTP, "Unknown handle");
4727-
return WS_BAD_FILE_E;
4728-
}
4729-
47304721
search.ATTRIBUTE = MFS_SEARCH_ANY;
4731-
search.WILDCARD = cur->name;
4722+
search.WILDCARD = name;
47324723
search.SEARCH_DATA_PTR = &search_data;
47334724

47344725
err = ioctl(mfs_ptr, IO_IOCTL_FIND_FIRST_FILE, (uint32_t*)&search);
@@ -4829,22 +4820,15 @@ static int SFTP_GetAttributes(void* fs, const char* fileName,
48294820
}
48304821

48314822
static int SFTP_GetAttributes_Handle(WOLFSSH* ssh, byte* handle, int handleSz,
4832-
WS_SFTP_FILEATRB* atr)
4823+
char* name, WS_SFTP_FILEATRB* atr)
48334824
{
48344825
FILINFO info;
4835-
WS_HANDLE_LIST *cur;
48364826

48374827
if (handle == NULL || atr == NULL) {
48384828
return WS_FATAL_ERROR;
48394829
}
48404830

4841-
cur = SFTP_GetHandleNode(ssh, handle, handleSz);
4842-
if (cur == NULL) {
4843-
WLOG(WS_LOG_SFTP, "Unknown handle");
4844-
return WS_BAD_FILE_E;
4845-
}
4846-
4847-
if (f_stat(cur->name, &info) != FR_OK) {
4831+
if (f_stat(name, &info) != FR_OK) {
48484832
return WS_FATAL_ERROR;
48494833
}
48504834

@@ -4877,6 +4861,9 @@ static int SFTP_GetAttributes_Handle(WOLFSSH* ssh, byte* handle, int handleSz,
48774861
atr->atime = info.ftime;
48784862
atr->mtime = info.ftime;
48794863
#endif /* NO_WOLFSSH_MKTIME */
4864+
4865+
WOLFSSH_UNUSED(ssh);
4866+
WOLFSSH_UNUSED(handleSz);
48804867
return WS_SUCCESS;
48814868
}
48824869

@@ -4919,21 +4906,18 @@ int SFTP_GetAttributes(void* fs, const char* fileName, WS_SFTP_FILEATRB* atr,
49194906
}
49204907

49214908
int SFTP_GetAttributes_Handle(WOLFSSH* ssh, byte* handle, int handleSz,
4922-
WS_SFTP_FILEATRB* atr)
4909+
char* name, WS_SFTP_FILEATRB* atr)
49234910
{
49244911
WOLFSSH_UNUSED(ssh);
49254912
WOLFSSH_UNUSED(handle);
49264913
WOLFSSH_UNUSED(handleSz);
49274914
WOLFSSH_UNUSED(atr);
4915+
WOLFSSH_UNUSED(name);
49284916

49294917
WLOG(WS_LOG_SFTP, "SFTP_GetAttributes_Handle() not implemented yet");
49304918
return WS_NOT_COMPILED;
49314919
}
49324920

4933-
4934-
#elif defined(WOLFSSH_USER_FILESYSTEM)
4935-
/* User-defined I/O support */
4936-
49374921
#elif defined(MICROCHIP_MPLAB_HARMONY)
49384922
int SFTP_GetAttributesStat(WS_SFTP_FILEATRB* atr, WSTAT_T* stats)
49394923
{
@@ -5021,20 +5005,8 @@ int SFTP_GetAttributes(void* fs, const char* fileName, WS_SFTP_FILEATRB* atr,
50215005
* returns WS_SUCCESS on success
50225006
*/
50235007
int SFTP_GetAttributes_Handle(WOLFSSH* ssh, byte* handle, int handleSz,
5024-
WS_SFTP_FILEATRB* atr)
5008+
char* name, WS_SFTP_FILEATRB* atr)
50255009
{
5026-
WS_HANDLE_LIST* cur;
5027-
5028-
if (handleSz != sizeof(word32)) {
5029-
WLOG(WS_LOG_SFTP, "Unexpected handle size SFTP_GetAttributes_Handle()");
5030-
}
5031-
5032-
cur = SFTP_GetHandleNode(ssh, handle, handleSz);
5033-
if (cur == NULL) {
5034-
WLOG(WS_LOG_SFTP, "Unknown handle");
5035-
return WS_BAD_FILE_E;
5036-
}
5037-
50385010
return SFTP_GetAttributesHelper(atr, cur->name);
50395011
}
50405012

@@ -5096,7 +5068,7 @@ int SFTP_GetAttributes(void* fs, const char* fileName, WS_SFTP_FILEATRB* atr,
50965068
* returns WS_SUCCESS on success
50975069
*/
50985070
int SFTP_GetAttributes_Handle(WOLFSSH* ssh, byte* handle, int handleSz,
5099-
WS_SFTP_FILEATRB* atr)
5071+
char* name, WS_SFTP_FILEATRB* atr)
51005072
{
51015073
struct stat stats;
51025074

@@ -5130,6 +5102,7 @@ int SFTP_GetAttributes_Handle(WOLFSSH* ssh, byte* handle, int handleSz,
51305102
/* @TODO handle attribute extensions */
51315103

51325104
WOLFSSH_UNUSED(ssh);
5105+
WOLFSSH_UNUSED(name);
51335106
return WS_SUCCESS;
51345107
}
51355108
#endif
@@ -5147,6 +5120,7 @@ int wolfSSH_SFTP_RecvFSTAT(WOLFSSH* ssh, int reqId, byte* data, word32 maxSz)
51475120
byte* handle;
51485121
word32 idx = 0;
51495122
int ret = WS_SUCCESS;
5123+
char* name = NULL;
51505124

51515125
byte* out = NULL;
51525126
word32 outSz = 0;
@@ -5168,9 +5142,27 @@ int wolfSSH_SFTP_RecvFSTAT(WOLFSSH* ssh, int reqId, byte* data, word32 maxSz)
51685142
}
51695143
handle = data + idx;
51705144

5145+
#ifdef WOLFSSH_STOREHANDLE
5146+
if (handleSz != sizeof(word32)) {
5147+
WLOG(WS_LOG_SFTP, "Unexpected handle size for stored handles");
5148+
}
5149+
else {
5150+
WS_HANDLE_LIST* cur;
5151+
5152+
cur = SFTP_GetHandleNode(ssh, handle, handleSz);
5153+
5154+
if (cur == NULL) {
5155+
WLOG(WS_LOG_SFTP, "Unknown handle");
5156+
return WS_BAD_FILE_E;
5157+
}
5158+
name = cur->name;
5159+
}
5160+
#endif
5161+
51715162
/* try to get file attributes and send back to client */
51725163
WMEMSET((byte*)&atr, 0, sizeof(WS_SFTP_FILEATRB));
5173-
if (SFTP_GetAttributes_Handle(ssh, handle, handleSz, &atr) != WS_SUCCESS) {
5164+
if (SFTP_GetAttributes_Handle(ssh, handle, handleSz, name, &atr)
5165+
!= WS_SUCCESS) {
51745166
WLOG(WS_LOG_SFTP, "Unable to get fstat of file/directory");
51755167
if (wolfSSH_SFTP_CreateStatus(ssh, WOLFSSH_FTP_FAILURE, reqId,
51765168
"STAT error", "English", NULL, &outSz) != WS_SIZE_ONLY) {

wolfssh/port.h

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -103,6 +103,11 @@ extern "C" {
103103

104104
#if defined(NO_FILESYSTEM) && !defined(WOLFSSH_FATFS)
105105
#define WS_DELIM '/'
106+
107+
#elif defined(WOLFSSH_USER_FILESYSTEM)
108+
/* User-defined I/O support, this should be at the top of the ports list
109+
* to override all */
110+
106111
#elif defined(WOLFSSL_NUCLEUS)
107112
#include "storage/nu_storage.h"
108113

@@ -427,8 +432,6 @@ extern "C" {
427432
#define WFSETTIME(fs,fd,a,m) (0)
428433
#define WCHDIR(fs,b) SYS_FS_DirectryChange((b))
429434

430-
#elif defined(WOLFSSH_USER_FILESYSTEM)
431-
/* User-defined I/O support */
432435
#else
433436
#include <stdlib.h>
434437
#if !defined(_WIN32_WCE) && !defined(FREESCALE_MQX)
@@ -636,7 +639,12 @@ extern "C" {
636639
#endif
637640
#endif
638641

639-
#ifdef WOLFSSL_NUCLEUS
642+
#if defined(WOLFSSH_USER_FILESYSTEM)
643+
/* User-defined I/O support, this should be at the top of the ports list
644+
* to override all */
645+
#include "myFilesystem.h"
646+
647+
#elif defined(WOLFSSL_NUCLEUS)
640648
#define WSTAT_T struct stat
641649
#define WRMDIR(fs,d) (NU_Remove_Dir((d)) == NU_SUCCESS)?0:1
642650
#define WMKDIR(fs,d,m) (NU_Make_Dir((d)) == NU_SUCCESS)?0:1
@@ -1433,9 +1441,6 @@ extern "C" {
14331441
#define WPWRITE(fs,fd,b,s,o) wPwrite((fd),(b),(s),(o))
14341442
#define WPREAD(fs,fd,b,s,o) wPread((fd),(b),(s),(o))
14351443

1436-
#elif defined(WOLFSSH_USER_FILESYSTEM)
1437-
/* User-defined I/O support */
1438-
#include "myFilesystem.h"
14391444
#else
14401445

14411446
#include <unistd.h> /* used for rmdir */

0 commit comments

Comments
 (0)