From owner-freebsd-stable@FreeBSD.ORG Sat Oct 1 18:16:09 2005 Return-Path: X-Original-To: freebsd-stable@freebsd.org Delivered-To: freebsd-stable@freebsd.org Received: from mx1.FreeBSD.org (mx1.freebsd.org [216.136.204.125]) by hub.freebsd.org (Postfix) with ESMTP id C813016A41F for ; Sat, 1 Oct 2005 18:16:09 +0000 (GMT) (envelope-from loox@e-shell.net) Received: from sophia3.e-shell.net (sophia3.e-shell.net [64.246.46.12]) by mx1.FreeBSD.org (Postfix) with ESMTP id 8ED8E43D46 for ; Sat, 1 Oct 2005 18:16:09 +0000 (GMT) (envelope-from loox@e-shell.net) Received: from dsl-201-154-37-23.prod-infinitum.com.mx (unknown [201.154.37.23]) by sophia3.e-shell.net (Postfix) with ESMTP id CBA33656826 for ; Sat, 1 Oct 2005 13:16:08 -0500 (CDT) From: Axel Gonzalez To: freebsd-stable@freebsd.org Date: Sat, 1 Oct 2005 13:16:06 -0500 User-Agent: KMail/1.8.2 MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Content-Disposition: inline Message-Id: <200510011316.07073.loox@e-shell.net> Subject: FAT32 corruption (related to kern/39043) X-BeenThere: freebsd-stable@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: Production branch of FreeBSD source code List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Sat, 01 Oct 2005 18:16:09 -0000 I had noticed some strange behaviour with some programs on FAT32 partitions, then I got into kern/39043 (moving files over samba), wich has been open for over 3 years. Then I decided to do some research. I made a simple program, that opens some files, write some data, and close the file (included at end). Inmediately after the program is done, the files are ok, all data is plain text, and they have what is expected. But after some time, or some disk access (unrelated to the files), the files are corrupted!, with lots of garbage. By looking at the uncorrupted text (specially formated for this), it seems that the corruption is in blocks of 4096 (the size of the partition's clusters). This leads me to belive there is a problem flushing cache entries to the directory structure (so directory entries get corrupted, by pointing to unrelated clusters). Sometimes files are ok, but its easy to get a corrupted one. This is what I did: $ uname -a FreeBSD moonlight.e-shell.net 5.4-STABLE FreeBSD 5.4-STABLE #1: Fri Sep 30 01:02:32 CDT 2005 loox@...:/usr/obj/usr/src/sys/LXAMD64 amd64 $ ./fat32 /mnt/wina5/tmp/test0 /mnt/wina5/tmp/test1 /mnt/wina5/tmp/test2 /mnt/wina5/tmp/test3 /mnt/wina5/tmp/test4 /mnt/wina5/tmp/test5 /mnt/wina5/tmp/test6 /mnt/wina5/tmp/test7 Files are created ok $ cat test0 | grep -v file00 $ file is ok.. no weird data do some disk access: $ find / > /dev/null $ test the file again: $ cat test0 | grep -v file00 (lots of binary garbage) $ The program I used to test: ************************************************** #include #include #include #define _PATH "/mnt/wina5/tmp" #define BLOCK 8192 #define NUM 1024 #define FN 8 int main() { int i, j, k; int fd[FN]; char file[128]; char name[128] = "test"; char str[BLOCK + 1]; for (j = 0; j < FN; j++) { sprintf(file, "%s/%s%d", _PATH, name, j); printf("%s\n", file); fd[j] = open(file, O_RDWR | O_TRUNC | O_CREAT); for (i = NUM; i >= 0; i--) { for (k = 0; k < BLOCK; k += 32) sprintf(str + k, "file%02d | Block: %06d [%06d]\n", j, i, k); lseek(fd[j], i * BLOCK, SEEK_SET); write(fd[j], str, BLOCK); } } for (j = 0; j < FN; j++) close(fd[j]); }