A quick and dirty FTP server port to mbed, for file i/o ops via LwIP stack.

Dependencies:   mbed

Revision:
0:c9ac16a7dfb4
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/NetFtp/vfs.c	Tue Nov 30 00:45:55 2010 +0000
@@ -0,0 +1,146 @@
+
+#include "mbed.h"                  // DRB
+#include "SDFileSystem.h"          // DRB
+#include "vfs.h"
+}
+
+extern void printit( char *p_buf );
+
+
+int  *vfs_openfs( void )
+{
+//    printit( "FTP vfs_openfs" );
+    return NULL;
+}
+
+
+vfs_file_t *vfs_open( int *fd, const char *fname, const char *mode )
+{
+#if 0
+    char what[ 40 ];
+    
+//    printit( "FTP vfs_open" );
+    printit( (char*)fname );
+    sprintf( what, "/sd/%s", fname );
+//    printit( what );
+    return (vfs_file_t *)fopen( what, mode );
+#else
+    return (vfs_file_t *)fopen( fname, mode );
+#endif
+}
+
+
+ssize_t vfs_read( void *buf,int what, int BufferSize, vfs_file_t *fp )
+{
+#if 0
+    char txt[ 40 ];
+    
+    sprintf( txt, "FTP vfs_read,%u", BufferSize );
+    printit( txt );
+    memset( buf, 0xAA, BufferSize );
+#endif
+    return fread( buf, 1, BufferSize, (FILE*)fp);
+}
+
+
+int vfs_write(  void *buf,int what, int BufferSize, vfs_file_t *fp  )
+{
+    return fwrite( buf, 1, BufferSize, (FILE*)fp);
+}
+
+
+int vfs_eof( vfs_file_t *fp )
+{
+    //printit( "vfs_eof" );
+    return feof( (FILE*)fp );
+//    return 0; // not eof
+}
+
+
+int vfs_close( vfs_file_t *fp  )
+{
+    //printit( "vfs_close" );
+    if( NULL != fp )
+    {
+        fclose( (FILE*)fp );
+    }
+    else
+    {
+        //printit( "vfs_close--opps!!!" );
+    }
+    return 0;
+}
+
+
+int vfs_stat( int *fd, const char *fname, vfs_stat_t *st )
+{
+    printit( "" );
+    printit( (char*)fname );
+    st->st_mode = 1; // ok
+    st->st_size = 123; // file size
+    return 1;
+}
+
+
+/*
+ * Find pathname of process's current directory.
+ *
+ * Use vfs vnode-to-name reverse cache; if that fails, fall back
+ * to reading directory contents.
+ */
+char *vfs_getcwd( int *fd, void *x, int y )
+{
+    printit( "vfs_getcwd" );
+    return (char*)malloc( 123 );
+}
+
+
+vfs_dir_t    *vfs_opendir( int *fd, char *cwd )
+{
+    printit( "FTP vfs_opendir" );
+    return 0;
+}
+
+
+vfs_dirent_t *vfs_readdir( vfs_dir_t *fd )
+{
+    printit( "FTP vfs_readdir" );
+    return 0;
+}
+
+
+int vfs_closedir( vfs_dir_t *fd )
+{
+    return 0;
+}
+
+
+int vfs_mkdir( int *fd, const char *arg, int mode )
+{
+    return 0;
+}
+
+
+int vfs_rmdir( int *fd, const char *arg )
+{
+    return 0;
+}
+
+
+int vfs_rename( int *fd, char *oldname, const char *newname )
+{
+    return rename( oldname, newname );
+}
+
+
+int vfs_remove( int *fd, const char *arg )
+{
+    return remove( arg );
+}
+
+
+int vfs_chdir( int *fd, const char *arg )
+{
+    return 0;
+}
+