This is the mail archive of the
ecos-discuss@sourceware.org
mailing list for the eCos project.
fseek on JFFS2
- From: "Paluch Sebastian" <the_sorcerer at op dot pl>
- To: ecos-discuss at ecos dot sourceware dot org
- Date: Fri, 22 Sep 2006 12:50:09 +0200
- Subject: [ECOS] fseek on JFFS2
hi, i have strange problem when i'm using fwrite after fseek. eg.
this is samo file:
0a a0 10 03 00 49 00 00 00 0a a0 01 40 e2 01 00
01 a1 00 00 d8 fd 0c 8c 00 00 00 00 01 00 00 00
01 00 d8 00 40 01 db 00 01 00 d8 00 40 01 f0 00
01 00 01 00 40 01 f0 00 01 00 d8 00 40 01 db 00
01 00 d8 00 40 01 db 00 08 69 08 8c 01 00 d8 00
40 01 db 00 a2'0a'a0 01 80 24 11 00 02 a1 00 00 <-
d8 fd 0c 8c 00 00 00 00 01 00 00 00 01 00 d8 00
40 01 db 00 01 00 d8 00 40 01 f0 00 01 00 01 00
40 01 f0 00 01 00 d8 00 40 01 db 00 01 00 d8 00
40 01 db 00 08 69 08 8c 01 00 d8 00 40 01 db 00
a2 0a a0 01 02 6d ab 00 02 a1 00 00 d8 fd 0c 8c
00 00 00 00 01 00 00 00 01 00 d8 00 40 01 db 00
01 00 d8 00 40 01 f0 00 01 00 01 00 40 01 f0 00
01 00 d8 00 40 01 db 00 01 00 d8 00 40 01 db 00
08 69 08 8c 01 00 d8 00 40 01 db 00 a2 ff
and this is some code operating on this file:
//seek to position marked in file
if( fseek(file,85,SEEK_SET) )
{
return ferror(file);
}
//sizeof(header) = 3
if( fread(&header,sizeof(header),1,file) != 1 )
{
return ferror(file);
}
//...
//some checks on header
//...
if( fseek(table->file,85+sizeof(header),SEEK_SET) )
{
return ferror(file);
}
//sizeof(buf) = 73
if( fwrite(buf,sizeof(buf),1,file) != 1 )
{
return ferror(file);
}
buf starts with values:
40 e2 01 00 02 a1
so after this code i should have file:
0a a0 10 03 00 49 00 00 00 0a a0 01 40 e2 01 00
01 a1 00 00 d8 fd 0c 8c 00 00 00 00 01 00 00 00
01 00 d8 00 40 01 db 00 01 00 d8 00 40 01 f0 00
01 00 01 00 40 01 f0 00 01 00 d8 00 40 01 db 00
01 00 d8 00 40 01 db 00 08 69 08 8c 01 00 d8 00
40 01 db 00 a2 0a a0 01'40 e2 01 00 02 a1'00 00 <-
d8 fd 0c 8c 00 00 00 00 01 00 00 00 01 00 d8 00
40 01 db 00 01 00 d8 00 40 01 f0 00 01 00 01 00
40 01 f0 00 01 00 d8 00 40 01 db 00 01 00 d8 00
40 01 db 00 08 69 08 8c 01 00 d8 00 40 01 db 00
a2 0a a0 01 02 6d ab 00 02 a1 00 00 d8 fd 0c 8c
00 00 00 00 01 00 00 00 01 00 d8 00 40 01 db 00
01 00 d8 00 40 01 f0 00 01 00 01 00 40 01 f0 00
01 00 d8 00 40 01 db 00 01 00 d8 00 40 01 db 00
08 69 08 8c 01 00 d8 00 40 01 db 00 a2 ff
i should... but i have:
0a a0 10 03 00 49 00 00 00 0a a0 01 40 e2 01 00
01 a1 00 00 78 fd 0c 8c 00 00 00 00 01 00 00 00
01 00 d8 00 40 01 db 00 01 00 d8 00 40 01 f0 00
01 00 01 00 40 01 f0 00 01 00 d8 00 40 01 db 00
01 00 d8 00 40 01 db 00 a8 68 08 8c 01 00 d8 00
40 01 db 00 a2 0a a0 01 80 24 11 00 02 a1 00 00 <- should be here
78 fd 0c 8c 00 00 00 00 01 00 00 00 01 00 d8 00
40 01 db 00 01 00 d8 00 40 01 f0 00 01 00 01 00
40 01 f0 00 01 00 d8 00 40 01 db 00 01 00 d8 00
40 01 db 00 a8 68 08 8c 01 00 d8 00 40 01 db 00
a2 0a a0 01 02 6d ab 00 02 a1 00 00 78 fd 0c 8c
00 00 00 00 01 00 00 00 01 00 d8 00 40 01 db 00
01 00 d8 00 40 01 f0 00 01 00 01 00 40 01 f0 00
01 00 d8 00 40 01 db 00 01 00 d8 00 40 01 db 00
a8 68 08 8c 01 00 d8 00 40 01 db 00 a2'40 e2 01 <- is here
00 02 a1'00 00 78 fd 0c 8c 00 00 00 00 01 00 00
00 01 00 d8 00 40 01 db 00 01 00 d8 00 40 01 f0
00 01 00 01 00 40 01 f0 00 01 00 d8 00 40 01 db
00 01 00 d8 00 40 01 db 00 a8 68 08 8c 01 00 d8
00 40 01 db 00 a2 ff
it go at the end of the file, why?
when i write back readed header and then buf it's OK, but it should work
in both way
//seek to position marked in file
if( fseek(file,85,SEEK_SET) )
{
return ferror(file);
}
//sizeof(header) = 3
if( fread(&header,sizeof(header),1,file) != 1 )
{
return ferror(file);
}
//...
//some checks on header
//...
if( fseek(table->file,85,SEEK_SET) )
{
return ferror(file);
}
//sizeof(header) = 3
if( fwrite(&header,sizeof(header),1,file) != 1 )
{
return ferror(file);
}
//sizeof(buf) = 73
if( fwrite(buf,sizeof(buf),1,file) != 1 )
{
return ferror(file);
}
can somebody explain? thnx
--
Sebastian Paluch
--
Before posting, please read the FAQ: http://ecos.sourceware.org/fom/ecos
and search the list archive: http://ecos.sourceware.org/ml/ecos-discuss