Skip to content

Commit 834df1b

Browse files
refactor internal handle list and set filesystem override priority
1 parent f18ce33 commit 834df1b

File tree

3 files changed

+42
-56
lines changed

3 files changed

+42
-56
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/wolfsftp.c

Lines changed: 37 additions & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -994,10 +994,7 @@ static INLINE int SFTP_GetSz(byte* buf, word32* sz,
994994

995995
#ifndef NO_WOLFSSH_SERVER
996996

997-
#if defined(MICROCHIP_MPLAB_HARMONY) || defined(WOLFSSH_ZEPHYR) || \
998-
defined(WOLFSSH_FATFS) || defined(FREESCALE_MQX) || \
999-
defined(USE_WINDOWS_API) || defined(WOLFSSL_NUCLEUS) || \
1000-
!defined(WOLFSSH_USER_FILESYSTEM)
997+
#if !defined(WOLFSSH_USER_FILESYSTEM)
1001998
static int SFTP_GetAttributes(void* fs, const char* fileName,
1002999
WS_SFTP_FILEATRB* atr, byte noFollow, void* heap);
10031000
static int SFTP_GetAttributes_Handle(WOLFSSH* ssh, byte* handle, int handleSz,
@@ -3138,7 +3135,9 @@ static int wolfSSH_SFTPNAME_readdir(WOLFSSH* ssh, WDIR* dir, WS_SFTPNAME* out,
31383135
}
31393136

31403137
#elif defined(MICROCHIP_MPLAB_HARMONY)
3138+
#ifndef WOLFSSH_USER_FILESYSTEM
31413139
int SFTP_GetAttributesStat(WS_SFTP_FILEATRB* atr, WSTAT_T* stats);
3140+
#endif
31423141

31433142
/* helper function that gets file information from reading directory
31443143
*
@@ -4413,7 +4412,10 @@ int SFTP_RemoveHandleNode(WOLFSSH* ssh, byte* handle, word32 handleSz)
44134412
#endif /* WOLFSSH_STOREHANDLE */
44144413

44154414

4416-
#ifdef WOLFSSL_NUCLEUS
4415+
#if defined(WOLFSSH_USER_FILESYSTEM)
4416+
/* User-defined I/O support */
4417+
4418+
#elif defined(WOLFSSL_NUCLEUS)
44174419

44184420
#ifndef NO_WOLFSSH_MKTIME
44194421

@@ -4536,22 +4538,15 @@ int SFTP_GetAttributes(void* fs, const char* fileName, WS_SFTP_FILEATRB* atr,
45364538
* returns WS_SUCCESS on success
45374539
*/
45384540
int SFTP_GetAttributes_Handle(WOLFSSH* ssh, byte* handle, int handleSz,
4539-
WS_SFTP_FILEATRB* atr)
4541+
char* name, WS_SFTP_FILEATRB* atr)
45404542
{
45414543
DSTAT stats;
4542-
WS_HANDLE_LIST* cur;
45434544

45444545
if (handle == NULL || atr == NULL) {
45454546
return WS_FATAL_ERROR;
45464547
}
45474548

4548-
cur = SFTP_GetHandleNode(ssh, handle, handleSz);
4549-
if (cur == NULL) {
4550-
WLOG(WS_LOG_SFTP, "Unknown handle");
4551-
return WS_BAD_FILE_E;
4552-
}
4553-
4554-
if (WSTAT(ssh->fs, cur->name, &stats) != NU_SUCCESS) {
4549+
if (WSTAT(ssh->fs, name, &stats) != NU_SUCCESS) {
45554550
return WS_FATAL_ERROR;
45564551
}
45574552

@@ -4705,10 +4700,9 @@ int SFTP_GetAttributes(void* fs, const char* fileName, WS_SFTP_FILEATRB* atr,
47054700
* Fills out a WS_SFTP_FILEATRB structure
47064701
* returns WS_SUCCESS on success */
47074702
int SFTP_GetAttributes_Handle(WOLFSSH* ssh, byte* handle, int handleSz,
4708-
WS_SFTP_FILEATRB* atr)
4703+
char* name, WS_SFTP_FILEATRB* atr)
47094704
{
47104705
int err;
4711-
WS_HANDLE_LIST* cur;
47124706
MQX_FILE_PTR mfs_ptr;
47134707
MFS_SEARCH_DATA search_data;
47144708
MFS_SEARCH_PARAM search;
@@ -4718,14 +4712,8 @@ int SFTP_GetAttributes_Handle(WOLFSSH* ssh, byte* handle, int handleSz,
47184712
}
47194713
mfs_ptr = (MQX_FILE_PTR)ssh->fs;
47204714

4721-
cur = SFTP_GetHandleNode(ssh, handle, handleSz);
4722-
if (cur == NULL) {
4723-
WLOG(WS_LOG_SFTP, "Unknown handle");
4724-
return WS_BAD_FILE_E;
4725-
}
4726-
47274715
search.ATTRIBUTE = MFS_SEARCH_ANY;
4728-
search.WILDCARD = cur->name;
4716+
search.WILDCARD = name;
47294717
search.SEARCH_DATA_PTR = &search_data;
47304718

47314719
err = ioctl(mfs_ptr, IO_IOCTL_FIND_FIRST_FILE, (uint32_t*)&search);
@@ -4826,22 +4814,15 @@ static int SFTP_GetAttributes(void* fs, const char* fileName,
48264814
}
48274815

48284816
static int SFTP_GetAttributes_Handle(WOLFSSH* ssh, byte* handle, int handleSz,
4829-
WS_SFTP_FILEATRB* atr)
4817+
char* name, WS_SFTP_FILEATRB* atr)
48304818
{
48314819
FILINFO info;
4832-
WS_HANDLE_LIST *cur;
48334820

48344821
if (handle == NULL || atr == NULL) {
48354822
return WS_FATAL_ERROR;
48364823
}
48374824

4838-
cur = SFTP_GetHandleNode(ssh, handle, handleSz);
4839-
if (cur == NULL) {
4840-
WLOG(WS_LOG_SFTP, "Unknown handle");
4841-
return WS_BAD_FILE_E;
4842-
}
4843-
4844-
if (f_stat(cur->name, &info) != FR_OK) {
4825+
if (f_stat(name, &info) != FR_OK) {
48454826
return WS_FATAL_ERROR;
48464827
}
48474828

@@ -4916,12 +4897,13 @@ int SFTP_GetAttributes(void* fs, const char* fileName, WS_SFTP_FILEATRB* atr,
49164897
}
49174898

49184899
int SFTP_GetAttributes_Handle(WOLFSSH* ssh, byte* handle, int handleSz,
4919-
WS_SFTP_FILEATRB* atr)
4900+
char* name, WS_SFTP_FILEATRB* atr)
49204901
{
49214902
WOLFSSH_UNUSED(ssh);
49224903
WOLFSSH_UNUSED(handle);
49234904
WOLFSSH_UNUSED(handleSz);
49244905
WOLFSSH_UNUSED(atr);
4906+
WOLFSSH_UNUSED(name);
49254907

49264908
WLOG(WS_LOG_SFTP, "SFTP_GetAttributes_Handle() not implemented yet");
49274909
return WS_NOT_COMPILED;
@@ -5002,7 +4984,7 @@ int SFTP_GetAttributes(void* fs, const char* fileName, WS_SFTP_FILEATRB* atr,
50024984
{
50034985
WOLFSSH_UNUSED(heap);
50044986
WOLFSSH_UNUSED(fs);
5005-
4987+
50064988
return SFTP_GetAttributesHelper(atr, fileName);
50074989
}
50084990

@@ -5014,26 +4996,11 @@ int SFTP_GetAttributes(void* fs, const char* fileName, WS_SFTP_FILEATRB* atr,
50144996
* returns WS_SUCCESS on success
50154997
*/
50164998
int SFTP_GetAttributes_Handle(WOLFSSH* ssh, byte* handle, int handleSz,
5017-
WS_SFTP_FILEATRB* atr)
4999+
char* name, WS_SFTP_FILEATRB* atr)
50185000
{
5019-
WS_HANDLE_LIST* cur;
5020-
5021-
if (handleSz != sizeof(word32)) {
5022-
WLOG(WS_LOG_SFTP, "Unexpected handle size SFTP_GetAttributes_Handle()");
5023-
}
5024-
5025-
cur = SFTP_GetHandleNode(ssh, handle, handleSz);
5026-
if (cur == NULL) {
5027-
WLOG(WS_LOG_SFTP, "Unknown handle");
5028-
return WS_BAD_FILE_E;
5029-
}
5030-
50315001
return SFTP_GetAttributesHelper(atr, cur->name);
50325002
}
50335003

5034-
#elif defined(WOLFSSH_USER_FILESYSTEM)
5035-
/* User-defined I/O support */
5036-
50375004
#else
50385005

50395006
/* NOTE: if atr->flags is set to a value of 0 then no attributes are set.
@@ -5143,6 +5110,7 @@ int wolfSSH_SFTP_RecvFSTAT(WOLFSSH* ssh, int reqId, byte* data, word32 maxSz)
51435110
byte* handle;
51445111
word32 idx = 0;
51455112
int ret = WS_SUCCESS;
5113+
char* name = NULL;
51465114

51475115
byte* out = NULL;
51485116
word32 outSz = 0;
@@ -5164,9 +5132,27 @@ int wolfSSH_SFTP_RecvFSTAT(WOLFSSH* ssh, int reqId, byte* data, word32 maxSz)
51645132
}
51655133
handle = data + idx;
51665134

5135+
#ifdef WOLFSSH_STOREHANDLE
5136+
if (handleSz != sizeof(word32)) {
5137+
WLOG(WS_LOG_SFTP, "Unexpected handle size for stored handles");
5138+
}
5139+
else {
5140+
WS_HANDLE_LIST* cur;
5141+
5142+
cur = SFTP_GetHandleNode(ssh, handle, handleSz);
5143+
5144+
if (cur == NULL) {
5145+
WLOG(WS_LOG_SFTP, "Unknown handle");
5146+
return WS_BAD_FILE_E;
5147+
}
5148+
name = cur->name;
5149+
}
5150+
#endif
5151+
51675152
/* try to get file attributes and send back to client */
51685153
WMEMSET((byte*)&atr, 0, sizeof(WS_SFTP_FILEATRB));
5169-
if (SFTP_GetAttributes_Handle(ssh, handle, handleSz, &atr) != WS_SUCCESS) {
5154+
if (SFTP_GetAttributes_Handle(ssh, handle, handleSz, name, &atr)
5155+
!= WS_SUCCESS) {
51705156
WLOG(WS_LOG_SFTP, "Unable to get fstat of file/directory");
51715157
if (wolfSSH_SFTP_CreateStatus(ssh, WOLFSSH_FTP_FAILURE, reqId,
51725158
"STAT error", "English", NULL, &outSz) != WS_SIZE_ONLY) {

0 commit comments

Comments
 (0)