MMC msdos fs corrupt when files copied in shell
Gene Smith
gds at chartertn.net
Wed Jan 7 05:31:22 UTC 2009
Chris Johns wrote, On 01/06/2009 01:40 AM:
> Gene Smith wrote:
>> Starting with a cleanly formatted fat16 MMC containing some random
>> txt files, if I try to copy them to new files using the shell cp
>> command, they seem to work but when put on a pc (linux or windows)
>> the new files are always corrupted and there are additional files
>> present with random names that were never copied.
>>
>> Also, when I first mount the cleanly formatted fat16 MMC (or fat32)
>> and do ls in the shell I see a couple of random spurious files
>> listed. This is before I do any copies. If I try to ls those files,
>> the shell says they don't exist.
>
> These files may be the volume name or something similar. I suspect ls
> is listing them but you cannot open them.
I had labeled the volume MMC-KARD when doing the format fat16 under XP.
I see it listed as you say it might. I also see other files "Ac" which
don't seem to be part of the label. The other files are legit.
[/mnt] # ls
Ac CH-SHO.TXT GSD SHORT.TXT
Ac CHANGE.TXT MMC-KARD T.TXT
>
>> Also if I unmount and re-mount the MMC with the shell I see the
>> copied new files corrupted when cat'ing in the shell. I have varied
>> my MMC clock speed from 400Khz to 25Mhz with the same result (just
>> copies faster at higher clock rate). I intend to run at 12.5Mhz
>> (below the max 20Mhz MMC speed).
>>
>> I see no errors occurring with SYSLOG (DEBUG is defined in
>> spi-sd-card.c). So not sure what the problem is. Can others copy
>> files around on a SD/MMC with the shell and obtain good results?
Actually, I do see something that look a bit like errors but not sure,
lines with the word "token". This is an excerpt from doing an ls under /mnt:
:
[MMC]: sd_card_send_command: Ok: Write command and read response
[MMC]: sd_card_send_command: Token [07]: 0xff
[MMC]: sd_card_send_command: Token [08]: 0x00
[MMC]: sd_card_disk_block_read: Ok: Send: SD_CARD_CMD_READ_SINGLE_BLOCK
[MMC]: sd_card_read: Search from 9 to 17
[MMC]: sd_card_read: Token [09]: 0xff
[MMC]: sd_card_read: Token [10]: 0xff
[MMC]: sd_card_read: Token [11]: 0xff
[MMC]: sd_card_read: Token [12]: 0xff
[MMC]: sd_card_read: Token [13]: 0xff
[MMC]: sd_card_read: Token [14]: 0xff
[MMC]: sd_card_read: Token [15]: 0xff
[MMC]: sd_card_read: Token [16]: 0xff
[MMC]: sd_card_read: Token [17]: 0xff
[MMC]: sd_card_read: Ok: Query data start token
[MMC]: sd_card_read: Search from 0 to 1
[MMC]: sd_card_read: Token [00]: 0xff
[MMC]: sd_card_read: Token [01]: 0xff
[MMC]: sd_card_read: Ok: Query data start token
[MMC]: sd_card_read: Search from 0 to 17
[MMC]: sd_card_read: Token [00]: 0xfe
[MMC]: sd_card_read: Ok: Read data
[MMC]: sd_card_read: Ok: Read CRC 16
[MMC]: sd_card_disk_block_read: Ok: Read: SD_CARD_CMD_READ_SINGLE_BLOCK
[MMC]: sd_card_stop: Ok: Send stop
[MMC]: sd_card_disk_block_read: Ok: Stop
[MMC]: sd_card_disk_ioctl: dev = 8, req = 0, arg = 0x08c01c4201
[MMC]: sd_card_disk_block_read: start addr = 282112, bufnum = 1
:
>>
>
> What happens if you mount a disk with a tree of files ? Can you see
> the files ?
I reformatted the card to fat16 and put the RTEMS libi2c dir on it:
[/mnt] # ls
Al LIBI2C
[/mnt] # ls -l
Al: No such file or directory
total 4
drwxrwxrwx 0 root root 4096 Dec 9 1937 LIBI2C
[/mnt] # cd libi2c
[/mnt/LIBI2C] # ls
AM Al Ar LIBI2C.H MAKEFILE
AM Al LIBI2C.C MAKEFIL README.TXT
[/mnt/LIBI2C] #
The files beginning with A are spurious. I can cat the legit files OK.
(Some are shortened from long file names when I copied them to the card.)
>
> What happens if you unmount and remount the disk without making a
> change ?
Seems to be no problem:
[/mnt/LIBI2C] # cd
[/] # umount /mnt
umount: command not found
[/] # unmount /mnt
unmounted /mnt
[/] # mount -t msdos /dev/sd-card-a1 /mnt
mounted /dev/sd-card-a1 -> /mnt
[/] # cd /mnt
[/mnt] # ls -l
Al: No such file or directory
total 4
drwxrwxrwx 0 root root 4096 Dec 9 1937 LIBI2C
[/mnt] # cd libi2c
[/mnt/LIBI2C] # ls -l
AM: No such file or directory
AM: No such file or directory
Al: No such file or directory
Al: No such file or directory
Ar: No such file or directory
total 60
-rwxrwxrwx 0 root root 19065 Jan 29 1986 LIBI2C.C
-rwxrwxrwx 0 root root 15816 Jan 28 2017 LIBI2C.H
-rwxrwxrwx 0 root root 14134 May 29 1905 MAKEFIL
>
> Can you then make a directory then unmount then remount the disk ?
It seemed to work, but saw no SYSLOG activity (really wrote to card?):
[/mnt/LIBI2C] # mkdir testdir
[/mnt/LIBI2C] # ls
AM Al LIBI2C.H README.TXT
AM Ar MAKEFIL TESTDIR
Al LIBI2C.C MAKEFILE
[/mnt/LIBI2C] # cd
[/] # unmount /mnt
unmounted /mnt
[/] # mount -t msdos /dev/sd-card-a1 /mnt
mounted /dev/sd-card-a1 -> /mnt
[/] # cd /mnt/libi2c
[/mnt/LIBI2C] # ls
AM Al LIBI2C.H README.TXT
AM Ar MAKEFIL TESTDIR
Al LIBI2C.C MAKEFILE
>
> Finally what happens if you copy the tree using the cp command ?
[/mnt/LIBI2C/TESTDIR] # cd ..
[/mnt/LIBI2C] # cd ..
[/mnt] # ls
Al LIBI2C
[/mnt] # cp -r libi2c cpi2
[/mnt] # ls
Al CPI2C LIBI2C
[/mnt] # cd cpi2c
[/mnt/CPI2C] # ls
LIBI2C.C MAKEFIL README.TXT
LIBI2C.H MAKEFILE TESTDIR
File names look ok (spurious files not present). But when I cat them I
see corrupt data and contents from old files that were present in
previous formats.
I will now unmount and look at the "disk" on another system and see what
happened to it...
[/mnt/CPI2C] # cd
[/] # unmount /mnt
unmounted /mnt
[/] #
Now on my fc8 box it looks like this:
[gene at wally disk]$ ls
cpi2c libi2c
[gene at wally cpi2c]$ ll
total 76
-rwxr-xr-x 1 gene root 19065 1981-06-03 03:01 libi2c.c
-rwxr-xr-x 1 gene root 15816 1981-05-13 03:01 libi2c.h
-rwxr-xr-x 1 gene root 14134 1981-06-03 03:01 makefil
-rwxr-xr-x 1 gene root 215 1981-07-02 03:01 makefile
-rwxr-xr-x 1 gene root 13382 1981-06-09 03:01 readme.txt
drwxr-xr-x 2 gene root 4096 1981-05-21 03:01 testdir
The files that were copied with cp -r list OK. But internally they are
mixture of old files before the current re-format, some parts correct
and some just corrupt. No single copied file is correct however.
[gene at wally cpi2c]$ cd ../libi2c/
[gene at wally libi2c]$ ll
total 144
-rwxr-xr-x 1 gene root 19065 2009-01-01 01:33 libi2c.c
-rwxr-xr-x 1 gene root 19065 2009-01-01 01:33 libi2c.c
-rwxr-xr-x 1 gene root 15816 2008-09-01 10:17 libi2c.h
-rwxr-xr-x 1 gene root 15816 2008-09-01 10:17 libi2c.h
-rwxr-xr-x 1 gene root 14134 2008-12-01 15:23 makefil
-rwxr-xr-x 1 gene root 14134 2008-12-01 15:23 Makefil
-rwxr-xr-x 1 gene root 215 2006-01-05 23:19 Makefile
-rwxr-xr-x 1 gene root 13382 2008-01-11 10:20 readme.txt
-rwxr-xr-x 1 gene root 13382 2008-01-11 10:20 readme.txt
drwxr-xr-x 2 gene root 4096 1981-05-21 03:01 testdir
The original files look OK inside but somehow have the name repeated in
the listing (except for Makefile and testdir).
>
> What is the bdbuf configuration ?
Not sure were or what this is. So it must be still at default.
>
>> I still need to try the mount and copies with c library calls in
>> some test code independent of the shell.
>>
>
> The shell code should be fine. Most of these commands are taken from
> FreeBSD.
>
> Regards Chris
More information about the users
mailing list