VFAT rename bug

Michael Krause (rawstyle@ms.demo.org)
Wed, 7 Jan 1998 19:23:18 +0100 (CET)


Hi,

this bug has been discovered by me first in the late 2.1.60's (don't
know exactly which kernel introduced it or if it had been there
before) and still is in the 2.1.78 kernel -- renaming files on a VFAT
partition can destroy data. Here is a program which can reproduce that
bug:

/home/rawstyle> mount -t vfat /dev/fd0 /floppy
/home/rawstyle> ls -l /floppy
total 0
/home/rawstyle> cat >bug.c
#include <fcntl.h>

int main(void) {
int fd;
char buf[256];

for(fd=0; fd<256; fd++)
buf[fd] = fd;

fd = open("/floppy/a", O_WRONLY|O_CREAT|O_TRUNC);
write(fd, buf, 256);
close(fd);

rename("/floppy/a", "/floppy/b");
return 0;
}

/home/rawstyle> gcc bug.c
/home/rawstyle> ./a.out
/home/rawstyle> ls -l /floppy
total 1
-rw-r--r-- 1 rawstyle users 256 Jan 7 18:30 b
/home/rawstyle> hexdump /floppy/b
0000000 0100 0302 0504 0706 0908 0b0a 0d0c 0f0e
0000010 1110 1312 1514 1716 1918 1b1a 1d1c 1f1e
0000020 2120 2322 2524 2726 2928 2b2a 2d2c 2f2e
0000030 3130 3332 3534 3736 3938 3b3a 3d3c 3f3e
0000040 4140 4342 4544 4746 4948 4b4a 4d4c 4f4e
0000050 5150 5352 5554 5756 5958 5b5a 5d5c 5f5e
0000060 6160 6362 6564 6766 6968 6b6a 6d6c 6f6e
0000070 7170 7372 7574 7776 7978 7b7a 7d7c 7f7e
0000080 8180 8382 8584 8786 8988 8b8a 8d8c 8f8e
0000090 9190 9392 9594 9796 9998 9b9a 9d9c 9f9e
00000a0 a1a0 a3a2 a5a4 a7a6 a9a8 abaa adac afae
00000b0 b1b0 b3b2 b5b4 b7b6 b9b8 bbba bdbc bfbe
00000c0 c1c0 c3c2 c5c4 c7c6 c9c8 cbca cdcc cfce
00000d0 d1d0 d3d2 d5d4 d7d6 d9d8 dbda dddc dfde
00000e0 e1e0 e3e2 e5e4 e7e6 e9e8 ebea edec efee
00000f0 f1f0 f3f2 f5f4 f7f6 f9f8 fbfa fdfc fffe
0000100
/home/rawstyle> umount /floppy
/home/rawstyle> mount -t vfat /dev/fd0 /floppy
/home/rawstyle> ls -l /floppy
total 1
-rw-r--r-- 1 rawstyle users 256 Jan 7 18:30 b
/home/rawstyle> hexdump /floppy/b
0000000 0000 0000 0000 0000 0000 0000 0000 0000
*
0000100
/home/rawstyle>

I hope this helps!

bye,

michael krause aka raw style/lego^elke (amiga & linux)
http://ms.demo.org/rst/ --join mekka & symposium 1998!