Skip to contentSkip to conversation

statfs returns wrong values for 250Gb FAT fs

DISCUSSION Horms 4 participants 5 messages May 10, 2005 – May 12, 2005 1 message not in the archive

lore
Share & tools
lore

A message that is not in the archive (sent off-list or not yet received): [email protected]

Horms

author
#1 lore raw
Quoted 49 lines · Carlos Rodrigues

Package: kernel-image-2.6.8-2-386
Version: 2.6.8-13
Severity: important

I have a 250Gb external USB 2.0 hard-drive formatted with FAT32 and "df" always reports 64Kb of used space on it, although it contains a couple of gigabytes.

At first I thought the problem might be in "df" itself, but the following test code proves the statfs function is to blame. The values returned are incorrect.

However, it does report correct values for another FAT32 partition I have (70Gb).

----------- statfs.c -----------

#include <sys/vfs.h>

int main(int argc, char *argv[])

{
    struct statfs stats;
    long used;
    int kib;

    if (argc < 2) {
        printf("USAGE: %s <mountpoint>\n", argv[0]);
      
        return 1;
    }

    statfs(argv[1], &stats);
    used = stats.f_blocks - stats.f_bfree;
  
    printf("f_bsize = %ld blocks\nf_blocks = %ld blocks\nf_bfree = %ld blocks\nused = %ld blocks\n",
           stats.f_bsize, stats.f_blocks, stats.f_bfree, used);

    kib = stats.f_bsize / 1024;
    printf("total = %ld KiB\nfree = %ld KiB\nused = %ld KiB\n",
           kib * stats.f_blocks,
           kib * stats.f_bfree,
           kib * used);

    return 0;
}
Quoted 1 line

----------- eof - statfs.c -----------

Carlos,

this looks like it could be an issue with the fat file system handling a somewhat large filesystem. I have CCed the maintainer for comment. I have looked through most of the changes made to fat and vfat since 2.6.8.1 and I wasn't able to see anything there that looked like it would help your cause.

Signature · 1 line
Horms
#2 lore raw

Hi,

Quoted 8 lines · Horms
Quoted 8 lines

printf("f_bsize = %ld blocks\nf_blocks = %ld blocks\nf_bfree = %ld blocks\nused = %ld blocks\n",
stats.f_bsize, stats.f_blocks, stats.f_bfree, used);

kib = stats.f_bsize / 1024;
printf("total = %ld KiB\nfree = %ld KiB\nused = %ld KiB\n",
kib * stats.f_blocks,
kib * stats.f_bfree,
kib * used);

Filesystem may have the corrupted free-cluster value.

I couldn't reproduce the problem on 2.6.12-rc4.

Could you try a recently dosfsck (dosfstools-2.11 or later)? Also could you send the output of above program?

Thanks.

Signature · 1 line
OGAWA Hirofumi <[email protected]>
#3 lore raw
Quoted 8 lines · OGAWA Hirofumi

Filesystem may have the corrupted free-cluster value.

I couldn't reproduce the problem on 2.6.12-rc4.

Could you try a recently dosfsck (dosfstools-2.11 or later)? Also could you send the output of above program?

"dosfsck" did find a problem in the free-cluster value. And also said the backups FAT was different than the original FAT.

I didn't use "dosfsck" to fix the problems though (not that it couldn't, I just didn't try). As I had already copied everything to another disk, I just used "mkdosfs" to reformat the drive, and it works just fine now.

I still don't know what caused this, probably something related to some "kernel panics" I was seeing on shutdown (in a Fedora 3 installation, not Debian), after doing an umount+unplug.

I didn't though of using "dosfsck" because Windows' checkdisk was saying the filesystem was perfectly fine... It makes me feel really safe trusting MS tools... not.

Carlos Rodrigues

#4 lore raw

Hi,

Quoted 22 lines · Carlos Rodrigues
Quoted 9 lines · OGAWA Hirofumi

Filesystem may have the corrupted free-cluster value.

I couldn't reproduce the problem on 2.6.12-rc4.

Could you try a recently dosfsck (dosfstools-2.11 or later)? Also could you send the output of above program?

"dosfsck" did find a problem in the free-cluster value. And also said the backups FAT was different than the original FAT.

I didn't use "dosfsck" to fix the problems though (not that it couldn't, I just didn't try). As I had already copied everything to another disk, I just used "mkdosfs" to reformat the drive, and it works just fine now.

I still don't know what caused this, probably something related to some "kernel panics" I was seeing on shutdown (in a Fedora 3 installation, not Debian), after doing an umount+unplug.

Quoted 5 lines

I didn't though of using "dosfsck" because Windows' checkdisk was saying the filesystem was perfectly fine... It makes me feel really safe trusting MS tools... not.

Carlos Rodrigues

I had the same problem with an external 250 GB vfat USB 2.0 disk. The disk was formatted/used previously in windows, checkdisk said is OK, but mounted in linux readonly, game the same error (said only some little space was free, when in fact it was almost full).
However, I was able to see and copy all files from it.
As it was not my hard disk, I did not reformatted it, nor dosfsck-ed it. DOSFSCK reported errors with the FAT copy, and other errors, but as I said, I could access all data on it.

Best regards,
Paul

#5 lore raw
Quoted 8 lines · Paul Ionescu

I had the same problem with an external 250 GB vfat USB 2.0 disk. The disk was formatted/used previously in windows, checkdisk said is OK, but mounted in linux readonly, game the same error (said only some little space was free, when in fact it was almost full).
However, I was able to see and copy all files from it.
As it was not my hard disk, I did not reformatted it, nor dosfsck-ed it. DOSFSCK reported errors with the FAT copy, and other errors, but as I said, I could access all data on it.

If same problem happen, please report. And please let me investigate the details of the filesystem of this state.

Thanks.

Signature · 1 line
OGAWA Hirofumi <[email protected]>