Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Network: update File System Interface #10

Merged
merged 1 commit into from
Jun 5, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions Components/Network/Interface/FTP_Client_FS.c
Original file line number Diff line number Diff line change
Expand Up @@ -10,21 +10,21 @@
#include "rl_net.h"

// Open local file for reading or writing in FTP client.
__WEAK void *netFTPc_fopen (const char *fname, const char *mode) {
void *netFTPc_fopen (const char *fname, const char *mode) {
return (fopen (fname, mode));
}

// Close local file previously open in FTP client.
__WEAK void netFTPc_fclose (void *file) {
void netFTPc_fclose (void *file) {
fclose (file);
}

// Read block of data from local file in FTP client.
__WEAK uint32_t netFTPc_fread (void *file, uint8_t *buf, uint32_t len) {
uint32_t netFTPc_fread (void *file, uint8_t *buf, uint32_t len) {
return (fread (buf, 1, len, file));
}

// Write block of data to local file in FTP client.
__WEAK uint32_t netFTPc_fwrite (void *file, const uint8_t *buf, uint32_t len) {
uint32_t netFTPc_fwrite (void *file, const uint8_t *buf, uint32_t len) {
return (fwrite (buf, 1, len, file));
}
29 changes: 13 additions & 16 deletions Components/Network/Interface/FTP_Server_FS.c
Original file line number Diff line number Diff line change
Expand Up @@ -9,18 +9,14 @@
#include <stdio.h>
#include <string.h>
#include "rl_net.h"

#ifdef RTE_FileSystem_Core
#include "rl_fs.h"

static fsFileInfo info;

#ifndef NET_FTP_SERVER_VBUF_SIZE
#define NET_FTP_SERVER_VBUF_SIZE 0
#endif

// Open a file for reading or writing on FTP server.
__WEAK void *netFTPs_fopen (const char *fname, const char *mode) {
void *netFTPs_fopen (const char *fname, const char *mode) {
FILE *f = fopen (fname, mode);
#if (NET_FTP_SERVER_VBUF_SIZE > 512)
if (f != NULL) {
Expand All @@ -31,63 +27,65 @@ __WEAK void *netFTPs_fopen (const char *fname, const char *mode) {
}

// Close a file previously open on FTP server.
__WEAK void netFTPs_fclose (void *file) {
void netFTPs_fclose (void *file) {
fclose (file);
}

// Read block of data from a file on FTP server.
__WEAK uint32_t netFTPs_fread (void *file, uint8_t *buf, uint32_t len) {
uint32_t netFTPs_fread (void *file, uint8_t *buf, uint32_t len) {
return (fread (buf, 1, len, file));
}

// Write block of data to a file on FTP server.
__WEAK uint32_t netFTPs_fwrite (void *file, const uint8_t *buf, uint32_t len) {
uint32_t netFTPs_fwrite (void *file, const uint8_t *buf, uint32_t len) {
return (fwrite (buf, 1, len, file));
}

// Delete a file on FTP server.
__WEAK bool netFTPs_fdelete (const char *fname) {
bool netFTPs_fdelete (const char *fname) {
if (fdelete (fname, NULL) == fsOK) {
return (true);
}
return (false);
}

// Rename a file or directory on FTP server.
__WEAK bool netFTPs_frename (const char *fname, const char *newname) {
bool netFTPs_frename (const char *fname, const char *newname) {
if (frename (fname, newname) == fsOK) {
return (true);
}
return (false);
}

// Make a new directory on FTP server.
__WEAK bool netFTPs_mkdir (const char *path) {
bool netFTPs_mkdir (const char *path) {
if (fmkdir (path) == fsOK) {
return (true);
}
return (false);
}

// Remove an empty directory on FTP server.
__WEAK bool netFTPs_rmdir (const char *path) {
bool netFTPs_rmdir (const char *path) {
if (frmdir (path, NULL) == fsOK) {
return (true);
}
return (false);
}

// Verify that the directory path exists on FTP server.
__WEAK bool netFTPs_chdir (const char *path) {
bool netFTPs_chdir (const char *path) {
if (fchdir (path) == fsOK) {
return (true);
}
return (false);
}

// Search the file system directory for matching files.
__WEAK int32_t netFTPs_ffind (const char *mask, char *fname,
uint32_t *fsize, NET_FS_TIME *ftime, bool first) {
int32_t netFTPs_ffind (const char *mask, char *fname,
uint32_t *fsize, NET_FS_TIME *ftime, bool first) {
static fsFileInfo info;

if (first) {
/* First call, initialize the info. */
info.fileID = 0;
Expand All @@ -114,4 +112,3 @@ __WEAK int32_t netFTPs_ffind (const char *mask, char *fname,
}
return (0);
}
#endif
28 changes: 11 additions & 17 deletions Components/Network/Interface/HTTP_Server_FS.c
Original file line number Diff line number Diff line change
Expand Up @@ -10,42 +10,36 @@
#include "../Source/net_lib.h"
#include "rl_fs.h"

#ifdef __clang__
#pragma clang diagnostic ignored "-Wcast-align"
#endif

// Open a file for reading on HTTP server.
__WEAK void *netHTTPs_fopen (const char *fname) {
void *netHTTPs_fopen (const char *fname) {
return (fopen (fname, "r"));
}

// Close a file previously open on HTTP server.
__WEAK void netHTTPs_fclose (void *file) {
void netHTTPs_fclose (void *file) {
fclose (file);
}

// Read block of data from a file on HTTP server.
__WEAK uint32_t netHTTPs_fread (void *file, uint8_t *buf, uint32_t len) {
uint32_t netHTTPs_fread (void *file, uint8_t *buf, uint32_t len) {
return (fread (buf, 1, len, file));
}

// Read a string from a file on HTTP server.
__WEAK char *netHTTPs_fgets (void *file, char *buf, uint32_t size) {
char *netHTTPs_fgets (void *file, char *buf, uint32_t size) {
return (fgets (buf, (int32_t)size, file));
}

// Retrieve size and last modification time of a file.
__WEAK void netHTTPs_fstat (const char *fname, uint32_t *fsize, uint32_t *ftime) {
fsFileInfo *info;
void netHTTPs_fstat (const char *fname, uint32_t *fsize, uint32_t *ftime) {
static fsFileInfo info;

info = (fsFileInfo *)net_mem_alloc (sizeof (fsFileInfo));
info->fileID = 0;
if (ffind (fname, info) == fsOK) {
info.fileID = 0;
if (ffind (fname, &info) == fsOK) {
// File found, return size
*fsize = info->size;
*fsize = info.size;
// Convert creation time to UTC format.
*ftime = net_http_time (info->time.hr, info->time.min, info->time.sec,
info->time.day, info->time.mon, info->time.year);
*ftime = net_http_time (info.time.hr, info.time.min, info.time.sec,
info.time.day, info.time.mon, info.time.year);
}
net_mem_free ((NET_FRAME *)info);
}
6 changes: 3 additions & 3 deletions Components/Network/Interface/SMTP_Client_FS.c
Original file line number Diff line number Diff line change
Expand Up @@ -10,16 +10,16 @@
#include "rl_net.h"

// Open a file for reading in SMTP client.
__WEAK void *netSMTPc_fopen (const char *fname) {
void *netSMTPc_fopen (const char *fname) {
return (fopen (fname, "r"));
}

// Close a file previously open in SMTP client.
__WEAK void netSMTPc_fclose (void *file) {
void netSMTPc_fclose (void *file) {
fclose (file);
}

// Read block of data from a file in SMTP client.
__WEAK uint32_t netSMTPc_fread (void *file, uint8_t *buf, uint32_t len) {
uint32_t netSMTPc_fread (void *file, uint8_t *buf, uint32_t len) {
return (fread (buf, 1, len, file));
}
8 changes: 4 additions & 4 deletions Components/Network/Interface/TFTP_Client_FS.c
Original file line number Diff line number Diff line change
Expand Up @@ -10,21 +10,21 @@
#include "rl_net.h"

// Open local file for reading or writing in TFTP client.
__WEAK void *netTFTPc_fopen (const char *fname, const char *mode) {
void *netTFTPc_fopen (const char *fname, const char *mode) {
return (fopen (fname, mode));
}

// Close local file previously open in TFTP client.
__WEAK void netTFTPc_fclose (void *file) {
void netTFTPc_fclose (void *file) {
fclose (file);
}

// Read block of data from local file in TFTP client.
__WEAK uint32_t netTFTPc_fread (void *file, uint8_t *buf, uint32_t len) {
uint32_t netTFTPc_fread (void *file, uint8_t *buf, uint32_t len) {
return (fread (buf, 1, len, file));
}

// Write block of data to local file in TFTP client.
__WEAK uint32_t netTFTPc_fwrite (void *file, const uint8_t *buf, uint32_t len) {
uint32_t netTFTPc_fwrite (void *file, const uint8_t *buf, uint32_t len) {
return (fwrite (buf, 1, len, file));
}
8 changes: 4 additions & 4 deletions Components/Network/Interface/TFTP_Server_FS.c
Original file line number Diff line number Diff line change
Expand Up @@ -10,21 +10,21 @@
#include "rl_net.h"

// Open a file for reading or writing on TFTP server.
__WEAK void *netTFTPs_fopen (const char *fname, const char *mode) {
void *netTFTPs_fopen (const char *fname, const char *mode) {
return (fopen (fname, mode));
}

// Close a file previously open on TFTP server.
__WEAK void netTFTPs_fclose (void *file) {
void netTFTPs_fclose (void *file) {
fclose (file);
}

// Read block of data from a file on TFTP server.
__WEAK uint32_t netTFTPs_fread (void *file, uint8_t *buf, uint32_t len) {
uint32_t netTFTPs_fread (void *file, uint8_t *buf, uint32_t len) {
return (fread (buf, 1, len, file));
}

// Write block of data to a file on TFTP server.
__WEAK uint32_t netTFTPs_fwrite (void *file, const uint8_t *buf, uint32_t len) {
uint32_t netTFTPs_fwrite (void *file, const uint8_t *buf, uint32_t len) {
return (fwrite (buf, 1, len, file));
}
6 changes: 0 additions & 6 deletions Components/Network/Source/net_rtos2.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,6 @@
#include "cmsis_os2.h"
#include "net_lib.h"

/* Avoid syntax-checker errors in editor */
#ifndef NET_THREAD_STACK_SIZE
#define NET_THREAD_STACK_SIZE 1024
#define NET_THREAD_PRIORITY osPriorityNormal
#endif

/* Network core resources */
#ifdef RTE_CMSIS_RTOS2_RTX5
#include "rtx_os.h"
Expand Down
46 changes: 24 additions & 22 deletions Documentation/Doxygen/Network/src/ref_net_services.txt
Original file line number Diff line number Diff line change
Expand Up @@ -759,10 +759,10 @@ enable a list of users, you need to adapt the following functions that are inclu
\ingroup netHTTP_Func
\brief HTTP server functions that work with a File System.
\details
All File System Interface functions are located in \b %HTTP_Server_FS.c, which will be automatically added to your project's
\b Network folder. The file is preconfigured for the \url{MW-FileSystem}, so no modifications are
required. If you wish to use another type of file system, you need to override these weak procedures with your required
functionality.
All functions of the File System Interface are located in \b HTTP_Server_FS.c, which is automatically added to the
\b Network folder of your project. The file is preconfigured for the \url{MW-FileSystem}, so no changes are required.
If you want to use a different type of file system, you must add a similar file to your project and implement
the interface functions yourself.

The following functions are implemented in this module:
- \ref netHTTPs_fopen - open a file for reading or writing.
Expand Down Expand Up @@ -1218,10 +1218,10 @@ The Network Component's FTP server supports only a subset of standard FTP comman
\brief FTP server functions that work with a File System.
\details

All File System Interface functions are located in \b %FTP_Server_FS.c, which will be automatically added to your project's
\b Network folder. The file is preconfigured for the \url{MW-FileSystem} component, so no modifications are
required. If you wish to use another type of file system, you need to override these weak procedures with your required
functionality.
All functions of the File System Interface are located in \b FTP_Server_FS.c, which is automatically added to the
\b Network folder of your project. The file is preconfigured for the \url{MW-FileSystem}, so no changes are required.
If you want to use a different type of file system, you must add a similar file to your project and implement
the interface functions yourself.

The following functions are implemented in this module:
- \ref netFTPs_fopen - open a file for reading or writing.
Expand Down Expand Up @@ -1338,9 +1338,10 @@ the file \b %FTP_Client_UIF.c module as well. You need to adapt the function to
\ingroup netFTPc_Func
\brief FTP client functions that work with a File System.
\details
All File System Interface functions are located in \b %FTP_Client_FS.c, which will be automatically added to your project's
\b Network folder. The file is preconfigured for the File System Component, so no modifications are required.
If you wish to use another type of file system, you need to add a similar file to your project.
All functions of the File System Interface are located in \b FTP_Client_FS.c, which is automatically added to the
\b Network folder of your project. The file is preconfigured for the \url{MW-FileSystem}, so no changes are required.
If you want to use a different type of file system, you must add a similar file to your project and implement
the interface functions yourself.

The following functions are implemented in this module:
- \ref netFTPc_fopen - open a file for reading or writing.
Expand Down Expand Up @@ -1444,10 +1445,10 @@ access.
\ingroup netTFTPs_Func
\brief TFTP server functions that work with a File System.
\details
All File System Interface functions are located in \b %TFTP_Server_FS.c, which will be automatically added to your project's
\b Network folder. The file is preconfigured for the \url{MW-FileSystem} component, so no modifications are
required. If you wish to use another type of file system, you need to override these weak procedures with your required
functionality.
All functions of the File System Interface are located in \b TFTP_Server_FS.c, which is automatically added to the
\b Network folder of your project. The file is preconfigured for the \url{MW-FileSystem}, so no changes are required.
If you want to use a different type of file system, you must add a similar file to your project and implement
the interface functions yourself.

The following functions are implemented in this module:
- \ref netTFTPs_fopen - open a file for reading or writing.
Expand Down Expand Up @@ -1532,10 +1533,10 @@ and scroll in the template files list until you find the <b>TFTP Client User Int
\ingroup netTFTPc_Func
\brief TFTP client functions that work with a File System.
\details
All File System Interface functions are located in \b %TFTP_Client_FS.c, which will be automatically added to your project's
\b Network folder. The file is preconfigured for the File System Component, so no modifications are required.
If you wish to use another type of file system or to use a different storage media such as a hard disk, you need to add a
similar file to your project.
All functions of the File System Interface are located in \b TFTP_Client_FS.c, which is automatically added to the
\b Network folder of your project. The file is preconfigured for the \url{MW-FileSystem}, so no changes are required.
If you want to use a different type of file system, you must add a similar file to your project and implement
the interface functions yourself.

The following functions are implemented in this module:
- \ref netTFTPc_fopen - open a file for reading or writing.
Expand Down Expand Up @@ -2409,9 +2410,10 @@ The following functions are available:
\ingroup netSMTPc_Func
\brief SMTP client functions that work with a File System.
\details
All File System Interface functions are located in \b %SMTP_Client_FS.c, which will be automatically added to your project's
\b Network folder. The file is preconfigured for the File System Component, so no modifications are required.
If you wish to use another type of file system, you need to add a similar file to your project.
All functions of the File System Interface are located in \b SMTP_Client_FS.c, which is automatically added to the
\b Network folder of your project. The file is preconfigured for the \url{MW-FileSystem}, so no changes are required.
If you want to use a different type of file system, you must add a similar file to your project and implement
the interface functions yourself.

The following functions are implemented in this module:
- \ref netSMTPc_fopen - open a file for reading.
Expand Down
Loading