public inbox for ecos-discuss@sourceware.org
 help / color / mirror / Atom feed
* [ECOS] [eCos] a question about ROMFS
@ 2001-07-16  0:47 jjtsai
  2001-07-16 14:01 ` Jonathan Larmour
  0 siblings, 1 reply; 6+ messages in thread
From: jjtsai @ 2001-07-16  0:47 UTC (permalink / raw)
  To: ecos-discuss

[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #1: Type: text/plain, Size: 655 bytes --]

Hi, 
    I have a question about ROM files 
system.
 
[Question Description]
    A fseek(,,SEEK_CUR) after fread() will 
cause inconsistency between "(CYG_StdioStream) 
real_stream.position"
    and "fp->f_offset". See also 
stream.inl and rom_fs.c.
    
    Here is my test program. See 
attchment: fseek_test.c  .
 
[My modfication]
 
See attachment: stream_inl_patch.pat.
Instruction about how to apply it: cd 
$(ECOS_REPOSITORY)/packages/language/c/libc/stdio/current/include patch -p0 
< $(WHERE_THE_PATCH_IS)/stream_inl_patch.pat
regards,
Jang-Jer
fseek_test.c
stream_inl_patch.pat


[-- Attachment #2: fseek_test.c --]
[-- Type: text/x-c, Size: 1464 bytes --]

#include <unistd.h>
#include <fcntl.h>
#include <stdio.h>
#include <cyg/fileio/fileio.h>
#include <pkgconf/fs_rom.h>	// Address of ROMFS

//==========================================================================

MTAB_ENTRY( romfs_mte1,
                   "/",
                   "romfs",
                   "",
                   (CYG_ADDRWORD) CYGNUM_FS_ROM_BASE_ADDRESS );

//==========================================================================
// main

int main( int argc, char **argv )
{
    FILE *fd;
    int err;
    int i;
    int length;
    char s[1000];
    struct stat sbuf;
    
    stat("/HelloWorld.jar", &sbuf);

    printf("leng=%d\n",sbuf.st_size);  

    if( (fd=fopen("/HelloWorld.jar","rw")) == NULL)
	printf("fopen error\n");
    else {
	length=0;

	do{
	err=ftell(fd); printf("ftell=%d\n",err); //ftell should return 0;

	if( (err=fseek(fd, 195, SEEK_SET))<0)
		printf("fseek=%d\n",err);

	err=ftell(fd); printf("ftell=%d\n",err); //ftell should return 195

	if( (err=fread((s+length),sizeof(char), 30, fd))!=30) 
		printf("fread=%d\n",err);

	err=ftell(fd); printf("ftell=%d\n",err); //ftell should return 225

	if( (err=fseek(fd, 0, SEEK_CUR))<0)
		printf("fseek=%d\n",err);

	err=ftell(fd); printf("ftell=%d\n",err); //ftell should return 225

	if( (err=fseek(fd, 1, SEEK_CUR))<0)
		printf("fseek=%d\n",err);

	err=ftell(fd); printf("ftell=%d\n",err); //ftell should return 226

	}
	while(0);

	fclose(fd);
	}

    return 0;

}


[-- Attachment #3: stream_inl_patch.pat --]
[-- Type: text/x-diff, Size: 566 bytes --]

--- stream.inl	Sat Apr  7 01:20:40 2001
+++ stream.inl.my	Mon Jul 16 14:37:34 2001
@@ -406,7 +406,16 @@
     if (!lock_me())
         return EBADF; // assume file is now invalid
 
-    err = cyg_stdio_lseek( my_device, &newpos, whence );
+    //add jjt
+    if( whence == SEEK_CUR ){ 
+	newpos = position + pos;
+	err = cyg_stdio_lseek( my_device, &newpos, SEEK_SET);
+	}
+    else {
+    	err = cyg_stdio_lseek( my_device, &newpos, whence );
+	}
+    //end jjt
+    //err = cyg_stdio_lseek( my_device, &newpos, whence ); //del jjt
 
     if( err == ENOERR )
     {

^ permalink raw reply	[flat|nested] 6+ messages in thread

end of thread, other threads:[~2001-07-19 23:42 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2001-07-16  0:47 [ECOS] [eCos] a question about ROMFS jjtsai
2001-07-16 14:01 ` Jonathan Larmour
2001-07-17  0:11   ` jjtsai
2001-07-17 13:09     ` Jonathan Larmour
2001-07-18  0:07       ` jjtsai
2001-07-19 23:42         ` Jonathan Larmour

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).