You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@nuttx.apache.org by Jernej Turnsek <je...@gmail.com> on 2024/02/22 06:54:47 UTC
Deleting files with wildcard
Hi, I have accidentally written a lot of files on my sdcard and now I would
like to delete them. I have tried with rm * command and it doesn't work. Is
there a way to delete multiple files without formatting the card?
Regards,
Jernej
Re: Deleting files with wildcard
Posted by Jernej Turnsek <je...@gmail.com>.
Hi Alan,
in my case I also get an unlink error, but the files persist.
On Sat, Feb 24, 2024 at 12:59 AM Alan C. Assis <ac...@gmail.com> wrote:
> I did a quick test in the sim:nsh
>
> nsh> mount
> /bin type binfs
> /etc type romfs
> /proc type procfs
> /tmp type vfat
>
> nsh> cd /tmp
> nsh> ls
> /tmp:
>
> nsh> echo "T1" > test1
> nsh> echo "T2" > test2
> nsh> echo "T3" > test3
> nsh> ls
> /tmp:
> test1
> test2
> test3
> nsh> rm -r .
> nsh: rm: unlink failed: 1
> nsh> ls
> /tmp:
> nsh>
>
> It reported error "unlink failed: 1", but removed all the files.
>
> BR,
>
> Alan
>
> On Fri, Feb 23, 2024 at 8:47 PM Alan C. Assis <ac...@gmail.com> wrote:
>
> > Hi Jernej,
> >
> > Did you try enter inside the directory (i.e. /mnt) and run:
> >
> > nsh> rm -f .
> >
> > Maybe it helps.
> >
> > BR,
> >
> > Alan
> >
> > On Thu, Feb 22, 2024 at 3:55 AM Jernej Turnsek <jernej.turnsek@gmail.com
> >
> > wrote:
> >
> >> Hi, I have accidentally written a lot of files on my sdcard and now I
> >> would
> >> like to delete them. I have tried with rm * command and it doesn't work.
> >> Is
> >> there a way to delete multiple files without formatting the card?
> >> Regards,
> >> Jernej
> >>
> >
>
Re: Deleting files with wildcard
Posted by Gregory Nutt <sp...@gmail.com>.
> Makes sense since mount points should be "removed" with umount.
rm on a mount point should work. rm does not necessarily remove it. It
maps to unlink which removes the name from mount point, or file. Logic
in the VFS will detect detect the open count. The entity will exist
nameless until all references are closed, then it will finally delete
the mountpoint.
That is why on a POSIX system you can unlink (rm) a file open by another
task. The file will still persist (without a name) until that other
task closes it.
> About removing "." I think Linux is even more restrictive:
>
> $ mkdir /tmp/test
> $ cd /tmp/test
> $ echo "T1" > test1
> $ echo "T2" > test2
> $ echo "T3" > test3
>
> $ rm -r .
> rm: refusing to remove '.' or '..' directory: skipping '.'
Same behavior, just a better error message. Another difference is that
fat does not have "." or ".." but does have some lame logic to make fat
behave similarly when they are used.
The logic that implements rm -r * is part of apps/, not the NuttX vfs.
It is function unlink_recursive in nsh_fscmds.c. It doesn't look like
it handles the "*" expansion at all. May 'rm -r' would work
Does 'ls -r *' work? The logic is very similar.
Re: Deleting files with wildcard
Posted by "Alan C. Assis" <ac...@gmail.com>.
Also I noticed rm doesn't accept to remove a mount point:
$ ./nuttx
login: admin
password:
User Logged-in!
nsh> umount /tmp
nsh> mount -t vfat /dev/ram2 /tmp/disk
nsh> mount
/bin type binfs
/etc type romfs
/proc type procfs
/tmp/disk type vfat
nsh> cd /tmp/disk
nsh> ls
/tmp/disk:
nsh> echo "T1" > test1
nsh> echo "T2" > test2
nsh> echo "T3" > test3
nsh> ls
/tmp/disk:
test1
test2
test3
nsh> cd ..
nsh> ls
/tmp:
disk/
nsh> rm -r disk
nsh: rm: unlink failed: 1
nsh> ls /tmp/disk
/tmp/disk:
nsh>
My idea was to mount inside a subdir and remove only it, but it also didn't
work.
Makes sense since mount points should be "removed" with umount.
About removing "." I think Linux is even more restrictive:
$ mkdir /tmp/test
$ cd /tmp/test
$ echo "T1" > test1
$ echo "T2" > test2
$ echo "T3" > test3
$ rm -r .
rm: refusing to remove '.' or '..' directory: skipping '.'
$ ls
test1 test2 test3
$ rm -r *
$ ls
$
Linux thinks I want to remove the ".", not the files "here"! So it doesn't
even remove any file.
NuttX seems to be a little bit more smart! hehehe!
Best Regards,
Alan
On Fri, Feb 23, 2024 at 9:33 PM Gregory Nutt <sp...@gmail.com> wrote:
>
> On 2/23/2024 6:19 PM, Gregory Nutt wrote:
> >
> >
> > On 2/23/2024 5:57 PM, Alan C. Assis wrote:
> >> /tmp:
> >> test1
> >> test2
> >> test3
> >> nsh> rm -r .
> >> nsh: rm: unlink failed: 1
> >> nsh> ls
> >> /tmp:
> >> nsh>
> >>
> >> It reported error "unlink failed: 1", but removed all the files.
> >
> > 1 = EPERM, Operation not permitted
> >
> > I suspect that occurred when it tried to rm ".". Try putting a
> > subdirectory under /tmp. Does vfat even support the "." hardlink?
> >
> "." corresponds to the root directory of the mounted file system.
> Trying to delete "." will result in an EPERM error on VFAT. See
> fat/fs_fat32dirent.c, function fat_remove().
>
> It seems like there is some issue with unlink.
>
>
Re: Deleting files with wildcard
Posted by Gregory Nutt <sp...@gmail.com>.
On 2/23/2024 6:19 PM, Gregory Nutt wrote:
>
>
> On 2/23/2024 5:57 PM, Alan C. Assis wrote:
>> /tmp:
>> test1
>> test2
>> test3
>> nsh> rm -r .
>> nsh: rm: unlink failed: 1
>> nsh> ls
>> /tmp:
>> nsh>
>>
>> It reported error "unlink failed: 1", but removed all the files.
>
> 1 = EPERM, Operation not permitted
>
> I suspect that occurred when it tried to rm ".". Try putting a
> subdirectory under /tmp. Does vfat even support the "." hardlink?
>
"." corresponds to the root directory of the mounted file system.
Trying to delete "." will result in an EPERM error on VFAT. See
fat/fs_fat32dirent.c, function fat_remove().
It seems like there is some issue with unlink.
Re: Deleting files with wildcard
Posted by Gregory Nutt <sp...@gmail.com>.
On 2/23/2024 5:57 PM, Alan C. Assis wrote:
> /tmp:
> test1
> test2
> test3
> nsh> rm -r .
> nsh: rm: unlink failed: 1
> nsh> ls
> /tmp:
> nsh>
>
> It reported error "unlink failed: 1", but removed all the files.
1 = EPERM, Operation not permitted
I suspect that occurred when it tried to rm ".". Try putting a
subdirectory under /tmp. Does vfat even support the "." hardlink?
Re: Deleting files with wildcard
Posted by Gregory Nutt <sp...@gmail.com>.
On 2/24/2024 11:42 AM, Gregory Nutt wrote:
> On 2/24/2024 11:39 AM, Jernej Turnsek wrote:
>> @Tomek No, my SD card filesystem is notu mounted read-only, because I
>> can
>> delete single files. I believe that rm * is just not implemented.
> There is no logic in NSH that expands "*" to a list of all files in
> the current directory. It is passed on to unlink as the literal
> string "*" which is not the name of an element in the current directory.
I added this as a github issue for any future discussions.
https://github.com/apache/nuttx-apps/issues/2311
Re: Deleting files with wildcard
Posted by Gregory Nutt <sp...@gmail.com>.
On 2/24/2024 11:39 AM, Jernej Turnsek wrote:
> @Tomek No, my SD card filesystem is notu mounted read-only, because I can
> delete single files. I believe that rm * is just not implemented.
There is no logic in NSH that expands "*" to a list of all files in the
current directory. It is passed on to unlink as the literal string "*"
which is not the name of an element in the current directory.
Re: Deleting files with wildcard
Posted by Jernej Turnsek <je...@gmail.com>.
@Tomek No, my SD card filesystem is notu mounted read-only, because I can
delete single files. I believe that rm * is just not implemented.
On Sat, Feb 24, 2024 at 1:04 AM Tomek CEDRO <to...@cedro.info> wrote:
> Maybe the SD card filesystem is mounted read-only?
> For instance when filesystem is corrupted it may mount ready-only on
> some systems until fsck marks it clean?
>
> --
> CeDeROM, SQ7MHZ, http://www.tomek.cedro.info
>
Re: Deleting files with wildcard
Posted by "Alan C. Assis" <ac...@gmail.com>.
No, the issue he reported is correct: "rm *" and "rm -r *" are not
supported.
It is a missing feature.
Best Regards,
Alan
On Fri, Feb 23, 2024 at 9:04 PM Tomek CEDRO <to...@cedro.info> wrote:
> Maybe the SD card filesystem is mounted read-only?
> For instance when filesystem is corrupted it may mount ready-only on
> some systems until fsck marks it clean?
>
> --
> CeDeROM, SQ7MHZ, http://www.tomek.cedro.info
>
Re: Deleting files with wildcard
Posted by Tomek CEDRO <to...@cedro.info>.
Maybe the SD card filesystem is mounted read-only?
For instance when filesystem is corrupted it may mount ready-only on
some systems until fsck marks it clean?
--
CeDeROM, SQ7MHZ, http://www.tomek.cedro.info
Re: Deleting files with wildcard
Posted by "Alan C. Assis" <ac...@gmail.com>.
I did a quick test in the sim:nsh
nsh> mount
/bin type binfs
/etc type romfs
/proc type procfs
/tmp type vfat
nsh> cd /tmp
nsh> ls
/tmp:
nsh> echo "T1" > test1
nsh> echo "T2" > test2
nsh> echo "T3" > test3
nsh> ls
/tmp:
test1
test2
test3
nsh> rm -r .
nsh: rm: unlink failed: 1
nsh> ls
/tmp:
nsh>
It reported error "unlink failed: 1", but removed all the files.
BR,
Alan
On Fri, Feb 23, 2024 at 8:47 PM Alan C. Assis <ac...@gmail.com> wrote:
> Hi Jernej,
>
> Did you try enter inside the directory (i.e. /mnt) and run:
>
> nsh> rm -f .
>
> Maybe it helps.
>
> BR,
>
> Alan
>
> On Thu, Feb 22, 2024 at 3:55 AM Jernej Turnsek <je...@gmail.com>
> wrote:
>
>> Hi, I have accidentally written a lot of files on my sdcard and now I
>> would
>> like to delete them. I have tried with rm * command and it doesn't work.
>> Is
>> there a way to delete multiple files without formatting the card?
>> Regards,
>> Jernej
>>
>
Re: Deleting files with wildcard
Posted by "Alan C. Assis" <ac...@gmail.com>.
Hi Jernej,
Did you try enter inside the directory (i.e. /mnt) and run:
nsh> rm -f .
Maybe it helps.
BR,
Alan
On Thu, Feb 22, 2024 at 3:55 AM Jernej Turnsek <je...@gmail.com>
wrote:
> Hi, I have accidentally written a lot of files on my sdcard and now I would
> like to delete them. I have tried with rm * command and it doesn't work. Is
> there a way to delete multiple files without formatting the card?
> Regards,
> Jernej
>