added a rm to eLua shell

classic Classic list List threaded Threaded
4 messages Options
Marcelo Politzer Marcelo Politzer
Reply | Threaded
Open this post in threaded view
|

added a rm to eLua shell

Simple patch that adds rm to eLua shell and adds a "static" to the boot_order.
Best Marcelo.

--------------------------------------------------------------------------

diff --git a/src/main.c b/src/main.c
index 4ef1c1c..ccc3a3e 100644
--- a/src/main.c
+++ b/src/main.c
@@ -27,7 +27,7 @@
 
 // Define here your autorun/boot files, 
 // in the order you want eLua to search for them
-char *boot_order[] = {
+static char *boot_order[] = {
 #if defined(BUILD_MMCFS)
   "/mmc/autorun.lua",
   "/mmc/autorun.lc",
diff --git a/src/shell.c b/src/shell.c
index 8647dcf..32279fd 100644
--- a/src/shell.c
+++ b/src/shell.c
@@ -60,6 +60,7 @@ static void shell_help( char* args )
           "                there, otherwise run it.");
   printf( "  cp <src> <dst> - copy source file 'src' to 'dst'\n" );
   printf( "  ver         - print eLua version\n" );
+  printf( "  rm          - remove a file. (don't work for romfs)\n" );
 }
 
 // 'lua' handler
@@ -228,6 +229,14 @@ static void shell_ls( char* args )
   printf( "\n" );
 }
 
+static void shell_rm( char *args )
+{
+  if( remove( args ) != 0 )
+    perror( "Error deleting file" );
+  else
+    puts( "File successfully deleted" );
+}
+
 // 'cat' and 'type' handler
 static void shell_cat( char *args )
 {
@@ -338,6 +347,7 @@ static const SHELL_COMMAND shell_commands[] =
   { "cat", shell_cat },
   { "type", shell_cat },
   { "cp", shell_cp },
+  { "rm", shell_rm },
   { NULL, NULL }
 };

_______________________________________________
eLua-dev mailing list
[hidden email]
https://lists.berlios.de/mailman/listinfo/elua-dev
BogdanM BogdanM
Reply | Threaded
Open this post in threaded view
|

Re: added a rm to eLua shell

Hi,

On Tue, May 15, 2012 at 2:02 AM, Marcelo Politzer <[hidden email]> wrote:

> Simple patch that adds rm to eLua shell and adds a "static" to the
> boot_order.
> Best Marcelo.
>
>
> --------------------------------------------------------------------------
>
>
> diff --git a/src/main.c b/src/main.c
> index 4ef1c1c..ccc3a3e 100644
> --- a/src/main.c
> +++ b/src/main.c
> @@ -27,7 +27,7 @@
>
>  // Define here your autorun/boot files,
>  // in the order you want eLua to search for them
> -char *boot_order[] = {
> +static char *boot_order[] = {
>  #if defined(BUILD_MMCFS)
>    "/mmc/autorun.lua",
>    "/mmc/autorun.lc",
> diff --git a/src/shell.c b/src/shell.c
> index 8647dcf..32279fd 100644
> --- a/src/shell.c
> +++ b/src/shell.c
> @@ -60,6 +60,7 @@ static void shell_help( char* args )
>            "                there, otherwise run it.");
>    printf( "  cp <src> <dst> - copy source file 'src' to 'dst'\n" );
>    printf( "  ver         - print eLua version\n" );
> +  printf( "  rm          - remove a file. (don't work for romfs)\n" );
>  }
>
>  // 'lua' handler
> @@ -228,6 +229,14 @@ static void shell_ls( char* args )
>    printf( "\n" );
>  }
>
> +static void shell_rm( char *args )
> +{
> +  if( remove( args ) != 0 )
> +    perror( "Error deleting file" );
> +  else
> +    puts( "File successfully deleted" );
> +}
> +
>  // 'cat' and 'type' handler
>  static void shell_cat( char *args )
>  {
> @@ -338,6 +347,7 @@ static const SHELL_COMMAND shell_commands[] =
>    { "cat", shell_cat },
>    { "type", shell_cat },
>    { "cp", shell_cp },
> +  { "rm", shell_rm },
>    { NULL, NULL }
>  };
>
>

How about an implementation for "rm" for our various file systems? The
FS operations are described in inc/newlib/devman.h:

// A device structure with pointers to all the device functions
typedef struct
{
  char name[ DM_MAX_DEV_NAME + 1 ];
  int ( *p_open_r )( struct _reent *r, const char *path, int flags, int mode );
  int ( *p_close_r )( struct _reent *r, int fd );
  _ssize_t ( *p_write_r ) ( struct _reent *r, int fd, const void *ptr,
size_t len );
  _ssize_t ( *p_read_r )( struct _reent *r, int fd, void *ptr, size_t len );
  off_t ( *p_lseek_r )( struct _reent *r, int fd, off_t off, int whence );
  void* ( *p_opendir_r )( struct _reent *r, const char* name );
  struct dm_dirent* ( *p_readdir_r )( struct _reent *r, void *dir );
  int ( *p_closedir_r )( struct _reent *r, void* dir );
  const char* ( *p_getaddr_r )( struct _reent *r, int fd );
} DM_DEVICE;

You'd need to add a "rm" and implement it for each file system. The
ones that will support it will probably be MMCFS, RFS and SemiFS
(mBED).
Your patch is thus incomplete. I'm not even sure how it works in its
current form, since it seems to completely bypass devman.c and
probably just use the MMCFS code directly.

Best,
Bogdan

> _______________________________________________
> eLua-dev mailing list
> [hidden email]
> https://lists.berlios.de/mailman/listinfo/elua-dev
_______________________________________________
eLua-dev mailing list
[hidden email]
https://lists.berlios.de/mailman/listinfo/elua-dev
Marcelo Politzer Marcelo Politzer
Reply | Threaded
Open this post in threaded view
|

Re: added a rm to eLua shell

Sorry it took a long time to answer.

So the current implementation of eLua filesystems interaction with newlib is incomplete?

2012/5/17 Bogdan Marinescu <[hidden email]>
Hi,

On Tue, May 15, 2012 at 2:02 AM, Marcelo Politzer <[hidden email]> wrote:
> Simple patch that adds rm to eLua shell and adds a "static" to the
> boot_order.
> Best Marcelo.
>
>
> --------------------------------------------------------------------------
>
>
> diff --git a/src/main.c b/src/main.c
> index 4ef1c1c..ccc3a3e 100644
> --- a/src/main.c
> +++ b/src/main.c
> @@ -27,7 +27,7 @@
>
>  // Define here your autorun/boot files,
>  // in the order you want eLua to search for them
> -char *boot_order[] = {
> +static char *boot_order[] = {
>  #if defined(BUILD_MMCFS)
>    "/mmc/autorun.lua",
>    "/mmc/autorun.lc",
> diff --git a/src/shell.c b/src/shell.c
> index 8647dcf..32279fd 100644
> --- a/src/shell.c
> +++ b/src/shell.c
> @@ -60,6 +60,7 @@ static void shell_help( char* args )
>            "                there, otherwise run it.");
>    printf( "  cp <src> <dst> - copy source file 'src' to 'dst'\n" );
>    printf( "  ver         - print eLua version\n" );
> +  printf( "  rm          - remove a file. (don't work for romfs)\n" );
>  }
>
>  // 'lua' handler
> @@ -228,6 +229,14 @@ static void shell_ls( char* args )
>    printf( "\n" );
>  }
>
> +static void shell_rm( char *args )
> +{
> +  if( remove( args ) != 0 )
> +    perror( "Error deleting file" );
> +  else
> +    puts( "File successfully deleted" );
> +}
> +
>  // 'cat' and 'type' handler
>  static void shell_cat( char *args )
>  {
> @@ -338,6 +347,7 @@ static const SHELL_COMMAND shell_commands[] =
>    { "cat", shell_cat },
>    { "type", shell_cat },
>    { "cp", shell_cp },
> +  { "rm", shell_rm },
>    { NULL, NULL }
>  };
>
>

How about an implementation for "rm" for our various file systems? The
FS operations are described in inc/newlib/devman.h:

Yes that would be the correct thing to do.
and by the looks of the current implementation of the unlink there isn't much action going on...

int _unlink_r( struct _reent *r, const char *name )
{
  r->_errno = ENOSYS;
  return -1;
}

// A device structure with pointers to all the device functions
typedef struct
{
 char name[ DM_MAX_DEV_NAME + 1 ];
 int ( *p_open_r )( struct _reent *r, const char *path, int flags, int mode );
 int ( *p_close_r )( struct _reent *r, int fd );
 _ssize_t ( *p_write_r ) ( struct _reent *r, int fd, const void *ptr,
size_t len );
 _ssize_t ( *p_read_r )( struct _reent *r, int fd, void *ptr, size_t len );
 off_t ( *p_lseek_r )( struct _reent *r, int fd, off_t off, int whence );
 void* ( *p_opendir_r )( struct _reent *r, const char* name );
 struct dm_dirent* ( *p_readdir_r )( struct _reent *r, void *dir );
 int ( *p_closedir_r )( struct _reent *r, void* dir );
 const char* ( *p_getaddr_r )( struct _reent *r, int fd );
} DM_DEVICE;

You'd need to add a "rm" and implement it for each file system. The
ones that will support it will probably be MMCFS, RFS and SemiFS
(mBED).
Your patch is thus incomplete. I'm not even sure how it works in its
current form, since it seems to completely bypass devman.c and
probably just use the MMCFS code directly.


Not even that by the looks of it. 

I would still add this unrelated to 'rm' part of the patch to the code that cleans
a global symbol that is not being used anywhere else.

> +static char *boot_order[] = { 

Other than that it really does seem that a lot has to be done before a 'rm' comes to life.

Best,
Bogdan

> _______________________________________________
> eLua-dev mailing list
> [hidden email]
> https://lists.berlios.de/mailman/listinfo/elua-dev
_______________________________________________
eLua-dev mailing list
[hidden email]
https://lists.berlios.de/mailman/listinfo/elua-dev



--
Sorry about the noise.

Best,
Marcelo


_______________________________________________
eLua-dev mailing list
[hidden email]
https://lists.berlios.de/mailman/listinfo/elua-dev
jbsnyder jbsnyder
Reply | Threaded
Open this post in threaded view
|

Re: added a rm to eLua shell



--
James Snyder
Biomedical Engineering
Northwestern University
http://fanplastic.org/key.txt
ph: (847) 448-0386



On Saturday, May 19, 2012 at 5:46 PM, Marcelo Politzer wrote:

> Sorry it took a long time to answer.
>
> So the current implementation of eLua filesystems interaction with newlib is incomplete?
>
> 2012/5/17 Bogdan Marinescu <[hidden email] (mailto:[hidden email])>
> > Hi,
> >
> > On Tue, May 15, 2012 at 2:02 AM, Marcelo Politzer <[hidden email] (mailto:[hidden email])> wrote:
> > > Simple patch that adds rm to eLua shell and adds a "static" to the
> > > boot_order.
> > > Best Marcelo.
> > >
> > >
> > > --------------------------------------------------------------------------
> > >
> > >
> > > diff --git a/src/main.c b/src/main.c
> > > index 4ef1c1c..ccc3a3e 100644
> > > --- a/src/main.c
> > > +++ b/src/main.c
> > > @@ -27,7 +27,7 @@
> > >
> > > // Define here your autorun/boot files,
> > > // in the order you want eLua to search for them
> > > -char *boot_order[] = {
> > > +static char *boot_order[] = {
> > > #if defined(BUILD_MMCFS)
> > > "/mmc/autorun.lua",
> > > "/mmc/autorun.lc (http://autorun.lc)",
> > > diff --git a/src/shell.c b/src/shell.c
> > > index 8647dcf..32279fd 100644
> > > --- a/src/shell.c
> > > +++ b/src/shell.c
> > > @@ -60,6 +60,7 @@ static void shell_help( char* args )
> > > " there, otherwise run it.");
> > > printf( " cp <src> <dst> - copy source file 'src' to 'dst'\n" );
> > > printf( " ver - print eLua version\n" );
> > > + printf( " rm - remove a file. (don't work for romfs)\n" );
> > > }
> > >
> > > // 'lua' handler
> > > @@ -228,6 +229,14 @@ static void shell_ls( char* args )
> > > printf( "\n" );
> > > }
> > >
> > > +static void shell_rm( char *args )
> > > +{
> > > + if( remove( args ) != 0 )
> > > + perror( "Error deleting file" );
> > > + else
> > > + puts( "File successfully deleted" );
> > > +}
> > > +
> > > // 'cat' and 'type' handler
> > > static void shell_cat( char *args )
> > > {
> > > @@ -338,6 +347,7 @@ static const SHELL_COMMAND shell_commands[] =
> > > { "cat", shell_cat },
> > > { "type", shell_cat },
> > > { "cp", shell_cp },
> > > + { "rm", shell_rm },
> > > { NULL, NULL }
> > > };
> >
> >
> > How about an implementation for "rm" for our various file systems? The
> > FS operations are described in inc/newlib/devman.h:
>
> Yes that would be the correct thing to do.
> and by the looks of the current implementation of the unlink there isn't much action going on...
>
> int _unlink_r( struct _reent *r, const char *name )
> {
> r->_errno = ENOSYS;
> return -1;
> }
>
>
> > // A device structure with pointers to all the device functions
> > typedef struct
> > {
> > char name[ DM_MAX_DEV_NAME + 1 ];
> > int ( *p_open_r )( struct _reent *r, const char *path, int flags, int mode );
> > int ( *p_close_r )( struct _reent *r, int fd );
> > _ssize_t ( *p_write_r ) ( struct _reent *r, int fd, const void *ptr,
> > size_t len );
> > _ssize_t ( *p_read_r )( struct _reent *r, int fd, void *ptr, size_t len );
> > off_t ( *p_lseek_r )( struct _reent *r, int fd, off_t off, int whence );
> > void* ( *p_opendir_r )( struct _reent *r, const char* name );
> > struct dm_dirent* ( *p_readdir_r )( struct _reent *r, void *dir );
> > int ( *p_closedir_r )( struct _reent *r, void* dir );
> > const char* ( *p_getaddr_r )( struct _reent *r, int fd );
> > } DM_DEVICE;
> >
> > You'd need to add a "rm" and implement it for each file system. The
> > ones that will support it will probably be MMCFS, RFS and SemiFS
> > (mBED).
> > Your patch is thus incomplete. I'm not even sure how it works in its
> > current form, since it seems to completely bypass devman.c and
> > probably just use the MMCFS code directly.
>
>
> Not even that by the looks of it.
>
> I would still add this unrelated to 'rm' part of the patch to the code that cleans
> a global symbol that is not being used anywhere else.
>
> > +static char *boot_order[] = {
>
> Other than that it really does seem that a lot has to be done before a 'rm' comes to life.

I don't think it has to be too complicated.  Basically, you'd need to follow the template of the other _xxx_r functions in stubs  to do a check and then call a p_unlink_r function, which would need to be defined or null for each FS (and included in the DM_DEVICE struct), then the individual FSs that implement the function would need to call the requisite functionality to perform the actual operation.

I could be wrong though since I haven't ever added to the list of supported device functions.

The other longstanding unimplemented feature is handling subdirectories for things like mmcfs and others where possible.  I think that doesn't actually even require adding a new device function since we have opendir/readdir/closedir.

Best.

-jsnyder
 

>
> > Best,
> > Bogdan
> >
> > > _______________________________________________
> > > eLua-dev mailing list
> > > [hidden email] (mailto:[hidden email])
> > > https://lists.berlios.de/mailman/listinfo/elua-dev
> >
> > _______________________________________________
> > eLua-dev mailing list
> > [hidden email] (mailto:[hidden email])
> > https://lists.berlios.de/mailman/listinfo/elua-dev
>
>
>
>
> --
> Sorry about the noise.
>
> Best,
> Marcelo
>
> _______________________________________________
> eLua-dev mailing list
> [hidden email] (mailto:[hidden email])
> https://lists.berlios.de/mailman/listinfo/elua-dev



_______________________________________________
eLua-dev mailing list
[hidden email]
https://lists.berlios.de/mailman/listinfo/elua-dev