2010-06-08 02:14:10

by Jeffrey Merkey

[permalink] [raw]
Subject: Fwd: EXT3 File System Corruption 2.6.34

---------- Forwarded message ----------
From: Jeffrey Merkey <[email protected]>
Date: Mon, Jun 7, 2010 at 8:13 PM
Subject: Re: EXT3 File System Corruption 2.6.34
To: Eric Sandeen <[email protected]>


Well, I will set this as default from now on. ?Tell Evil Emperor Linus
to put the fucking thing back the way it was so default kernel builds
are not fucked up.

Jeff

here is the source to the xdump.c file. ?may be useful in the future
to someone who needs a tool to dump files to post to the list. ?Anyway
-- easier to use than that fucking hexedit program.

:-)

// Released under GPLv2 or whatever fucking version you like

#include <stdio.h>
#include <stdlib.h>
#include <fcntl.h>

unsigned char *dumpAsBytes(unsigned char *p, unsigned long size,
unsigned long base)
{
? register unsigned long i, r, total, count;
? register unsigned char *op = p;

? count = size / 16;

? printf(" ? ? ? ? ? 0 ?1 ?2 ?3 ?4 ?5 ?6 ?7 ?8 ?9 ?A ?B ?C ?D ?E ?F\n");

? for (r=0; r < count; r++)
? {
? ? ?printf("%08X ", (p - op) + base);
? ? ?for (total = 0, i=0; i < 16; i++, total++)
? ? ?{
? ? ? ? printf(" %02X", (unsigned char) p[i]);
? ? ?}
? ? ?printf(" ?");
? ? ?for (i=0; i < total; i++)
? ? ?{
? ? ? ? if (p[i] < 32 || p[i] > 126)
? ? ? ? ? ?printf(".");
? ? ? ? else printf("%c", p[i]);
? ? ?}
? ? ?printf("\n");

? ? ?p = (void *)((unsigned long) p + (unsigned long) total);
? }
? return p;

}

unsigned char *dumpAsLong(unsigned char *p, unsigned long size,
unsigned long base)
{
? register int i, r, count;
? register unsigned char *op = p;
? unsigned long *lp;

? count = size / 16;

? lp = (unsigned long *) p;

? for (r=0; r < count; r++)
? {
? ? ?printf("%08X ", (p - op) + base);
? ? ?for (i=0; i < (16 / 4); i++)
? ? ?{
? ? ? ? printf(" %08X", (unsigned long) lp[i]);
? ? ?}
? ? ?printf(" ?");
? ? ?for (i=0; i < 16; i++)
? ? ?{
? ? ? ? if (p[i] < 32 || p[i] > 126) printf(".");
? ? ? ? else printf("%c", p[i]);
? ? ?}
? ? ?printf("\n");

? ? ?p = (void *)((unsigned long) p + (unsigned long) 16);
? ? ?lp = (unsigned long *) p;
? }
? return p;

}

int getch(void)
{
? return getc(stdin);
}

unsigned long pause(void)
{
? extern int getch(void);
? register unsigned long key;

? printf(" --- More --- ");
? key = getch();
? printf("%c ? ? ? ? ? ? ?%c", '\r', '\r');
? if (key == 0x1B) // ESCAPE
? ? ?return 1;
? else
? ? ?return 0;

}
unsigned char buffer[512];


int main(int argc, char *argv[])
{
? ?unsigned long rc, total = 0, offset = 0;
? ?register int fp;

? ?if (argc < 2)
? ?{
? ? ? printf("USAGE: ?dump <filename.ext> <offset>\n");
? ? ? return 1;
? ?}

? ?if (argc == 3)
? ? ? offset = atol(argv[2]);


? ?fp = open(argv[1], O_RDWR);
? ?if (fp < 0)
? ?{
? ? ? printf("error opening file [%s]\n", argv[1]);
? ? ? return 1;
? ?}

? ?rc = lseek(fp, offset, SEEK_SET);
? ?if (rc == -1)
? ?{
? ? ? printf("error seeking file offset %d\n", offset);
? ? ? return 1;
? ?}

? ?total = offset;
? ?while (rc = read(fp, buffer, 256))
? ?{
? ? ? dumpAsBytes(buffer, rc, total);
? ? ? total += rc;

? ? ? if (pause())
? ? ? ? ?break;
? ?}

? ?close(fp);
? ?return 0;
}


2010-06-08 11:14:06

by Theodore Ts'o

[permalink] [raw]
Subject: Re: EXT3 File System Corruption 2.6.34


On Jun 7, 2010, at 10:14 PM, Jeffrey Merkey wrote:

> From: Jeffrey Merkey <[email protected]>
> Date: Mon, Jun 7, 2010 at 8:13 PM
> Subject: Re: EXT3 File System Corruption 2.6.34
> To: Eric Sandeen <[email protected]>
>
>
> Well, I will set this as default from now on. Tell Evil Emperor Linus
> to put the fucking thing back the way it was so default kernel builds
> are not fucked up.

If you pull the plug without fsyncing the file, you will end up with a zero-length file -- or possibly no file at all, even with data=ordered. If you really want to preserve data after pulling the power cord immediately after a write were the application hasn't done an fsync() or a sync() call, you can mount the file system with the mount option -o sync --- but then the performance will be horrible.

It's all a tradeoff of what you think is important....

-- Ted

2010-06-08 13:33:24

by Török Edwin

[permalink] [raw]
Subject: Re: EXT3 File System Corruption 2.6.34

On 06/08/2010 02:14 PM, Theodore Tso wrote:
>
> If you pull the plug without fsyncing the file, you will end up with a zero-length file -- or possibly no file at all, even with data=ordered. If you really want to preserve data after pulling the power cord immediately after a write were the application hasn't done an fsync() or a sync() call, you can mount the file system with the mount option -o sync --- but then the performance will be horrible.
>
> It's all a tradeoff of what you think is important....
>

I think you should either get the old file, or the new file (if you
don't fsync), and not some random data from another file.
The manual entry for data=writeback only says that you may get old data
after a crash/recovery, not that you may get old/new data from *another*
file.

On the other hand I didn't specify any mount options, and I got
data=ordered. So is data=ordered the default or not?
Or does it depend whether you use ext3 or ext4 driver for ext3?

/etc/fstab has:
/dev/md3 / ext3 noatime,errors=remount-ro 0 1

and my ext* related config options:
# CONFIG_EXT2_FS is not set
# CONFIG_EXT3_FS is not set
CONFIG_EXT4_FS=y
CONFIG_EXT4_USE_FOR_EXT23=y
CONFIG_EXT4_FS_XATTR=y
# CONFIG_EXT4_FS_POSIX_ACL is not set
# CONFIG_EXT4_FS_SECURITY is not set
# CONFIG_EXT4_DEBUG is not set
# CONFIG_DEBUG_BLOCK_EXT_DEVT is not set

So I use the ext4 driver for the ext3 partition (I intended to convert
it to ext4 at some point, but didn't have time to do so yet).

This is with 2.6.34-00179-gdebb980 (drm-radeon-testing, which is
basically 2.6.34 + some radeon specific stuff).

Best regards,
--Edwin

2010-06-09 00:49:38

by David Lang

[permalink] [raw]
Subject: Re: EXT3 File System Corruption 2.6.34

On Tue, 8 Jun 2010, T?r?k Edwin wrote:

> On 06/08/2010 02:14 PM, Theodore Tso wrote:
>>
>> If you pull the plug without fsyncing the file, you will end up with a zero-length file -- or possibly no file at all, even with data=ordered. If you really want to preserve data after pulling the power cord immediately after a write were the application hasn't done an fsync() or a sync() call, you can mount the file system with the mount option -o sync --- but then the performance will be horrible.
>>
>> It's all a tradeoff of what you think is important....
>>
>
> I think you should either get the old file, or the new file (if you
> don't fsync), and not some random data from another file.

my understanding of the way to get what you want is to

write tempfile
sync
mv temptfile realfile

this also has the advantage that it will work on all filesystems.

David Lang