Re: Possible bug in file truncation code
Andrew Lunn <[email protected]> Fri, 25 Feb 2005 18:43:32 +0100
| Newsgroups | gmane.linux.file-systems.jffs |
|---|---|
| Message-ID | <[email protected]> |
On Fri, Feb 25, 2005 at 05:21:41PM +0000, David Woodhouse wrote:
> On Fri, 2005-02-25 at 17:46 +0100, Andrew Lunn wrote:
> >ie if the node does not have any fragments left its marked as
> >obsolete. These appears to remove the node, but still leaves it
> >referenced in the directory. Hence the filesystem is corrupt.
>
> Directories don't refer to data nodes. They refer to inodes. This inode
> still exists and is zero-length because it has no valid data nodes. The
> directory still refers to it -- that's fine. What's the actual problem?
The test case does the open, followed by a close then umount and then
mounts. The mount then reports:
<5>Eep. Child "TestFile.txt" (ino #10) of dir ino #1 doesn't exist!
I've attached the test case if you want to try it.
Andrew
jffs2_4.c
(text/x-csrc, 1.2 KB)
#include <cyg/infra/diag.h>
#include <pkgconf/fs_jffs2.h>
#include <pkgconf/io_flash.h>
#include <stdio.h>
#include <cyg/fileio/fileio.h>
void do_file(void)
{
int err;
FILE *TestFile;
char Text[255];
// mount the filesystem
err = mount( CYGDAT_IO_FLASH_BLOCK_DEVICE_NAME_1, "/", "jffs2" );
if( err < 0 )
{
diag_printf("mount jffs2: %d %s\n", err, err<0?strerror(errno):"");
return;
}
// create a new file
TestFile = fopen("TestFile.txt","w");
if(TestFile == 0)
{
diag_printf("error: fopen\n");
return;
}
fputs("This is a test.", TestFile);
fclose(TestFile);
// read the file
TestFile = fopen("TestFile.txt","r");
if(TestFile == 0)
{
diag_printf("error: fopen\n");
return;
}
if( fgets( Text, sizeof(Text), TestFile ) == 0)
diag_printf("error: fgets\n");
else
diag_printf(Text);
fclose(TestFile);
// truncate the file
TestFile = fopen("TestFile.txt","w");
fclose(TestFile);
// unmount the filesystem
err = umount( "/" );
if( err < 0 )
{
diag_printf("umount jffs2: %d %s\n", err, err<0?strerror(errno):"");
return;
}
}
int main( int argc, char **argv )
{
// ok
do_file();
// not ok
do_file();
return 0;
}