This is the mail archive of the
ecos-patches@sourceware.org
mailing list for the eCos project.
Re: Bug in FAT32 filesystem
- From: Savin Zlobec <savinz at users dot sourceforge dot net>
- To: vlsi235 at yahoo dot com dot tw
- Cc: ecos-patches at sourceware dot org
- Date: Wed, 31 Jan 2007 16:57:37 +0100
- Subject: Re: Bug in FAT32 filesystem
Hi,All
I found a bug in FAT16/32 Filesystem. When I
delete file in FAT32, it seems not work correctly. In
the function called "fatfs_delete_file", the start
cluster for "free_cluster_chain" should not be the
"raw_dentry.cluster", it should be
"(raw_dentry.cluster | raw_dentry.cluster_HI << 16)"
for FAT32.
Your fix looks fine. A quick scan through the code
reveals at least one more place with the same type
of error. I've attached a patch - could you please
check 'directory move' throughout your fs tree -
especially that the parent directory link ('..')
was updated correctly.
--
savin
Index: fatfs_supp.c
===================================================================
RCS file: /cvs/ecos/ecos/packages/fs/fat/current/src/fatfs_supp.c,v
retrieving revision 1.6
diff -5 -u -r1.6 fatfs_supp.c
--- fatfs_supp.c 3 Aug 2005 20:40:48 -0000 1.6
+++ fatfs_supp.c 31 Jan 2007 15:11:57 -0000
@@ -1263,11 +1263,11 @@
diag_printf("FAT: FDE crt time: %u\n", dentry->crt_time);
diag_printf("FAT: FDE crt date: %u\n", dentry->crt_date);
diag_printf("FAT: FDE acc date: %u\n", dentry->acc_date);
diag_printf("FAT: FDE wrt time: %u\n", dentry->wrt_time);
diag_printf("FAT: FDE wrt date: %u\n", dentry->wrt_date);
- diag_printf("FAT: FDE cluster: %u\n", dentry->cluster);
+ diag_printf("FAT: FDE cluster: %u\n", (dentry->cluster_HI << 16) | dentry->cluster);
diag_printf("FAT: FDE size: %u\n", dentry->size);
}
#endif // TDE
// -------------------------------------------------------------------------
@@ -2164,11 +2164,11 @@
if (i > 2)
return EPERM;
}
// Free file clusters
- free_cluster_chain(disk, raw_dentry.cluster);
+ free_cluster_chain(disk, raw_dentry.cluster | (raw_dentry.cluster_HI << 16));
raw_dentry_set_deleted(disk, &raw_dentry);
err = write_raw_dentry(disk, &file->disk_pos, &raw_dentry);
return err;
}
@@ -2402,10 +2402,11 @@
// Deleate dentry at old location
raw_dentry_set_deleted(disk, &raw_dentry);
raw_dentry.size = 0;
raw_dentry.cluster = 0;
+ raw_dentry.cluster_HI = 0;
err = write_raw_dentry(disk, &target->disk_pos, &raw_dentry);
if (err != ENOERR)
return err;
// Set file new position and parent cluster
@@ -2434,11 +2435,12 @@
else if (err != ENOERR)
return err;
if (0 == strncmp("..", raw_cdentry.name, 2))
{
- raw_cdentry.cluster = dir2->cluster;
+ raw_cdentry.cluster = dir2->cluster & 0xFFFF;
+ raw_cdentry.cluster_HI = dir2->cluster >> 16;
err = write_raw_dentry(disk, &pos, &raw_cdentry);
if (err != ENOERR)
return err;
break;
}