public inbox for ecos-discuss@sourceware.org
 help / color / mirror / Atom feed
From: "jjtsai" <jjtsai@itri.org.tw>
To: "Jonathan Larmour" <jlarmour@redhat.com>
Cc: <ecos-discuss@sources.redhat.com>
Subject: Re: [ECOS] [eCos] a question about ROMFS
Date: Wed, 18 Jul 2001 00:07:00 -0000	[thread overview]
Message-ID: <003401c10f58$b2853ea0$8c78608c@ccl.itri.org.tw> (raw)
In-Reply-To: <3B549B75.660C8B1D@redhat.com>

[-- Attachment #1: Type: text/plain, Size: 1138 bytes --]

----- Original Message -----
From: Jonathan Larmour <jlarmour@redhat.com>
To: jjtsai <jjtsai@itri.org.tw>
Cc: <ecos-discuss@sources.redhat.com>
Sent: Wednesday, July 18, 2001 4:09 AM
Subject: Re: [ECOS] [eCos] a question about ROMFS

> jjtsai wrote:
> > > I'll see if I can work on a better patch.
> > That would be great!
>
> Can you try the attached patch for me please? I haven't even tried
> compiling it yet nevermind testing it, but I was hoping you could do that
> instead :-). Let me know how it goes. Then I'll check it in.
 Your attached patch still has problems. Test program (fseek.c) is attached.

 I do a little modification on the stream.inl (based on your patch) and
romfs.c.
 It works well in my test program. Patch files are attached.

Have a try please. I am afraid if I make any mistakes.

Instruction about how to apply the patch files:

 cd $(ECOS_REPOSITORY)/packages/language/c/libc/stdio/current/include
patch -p0 < $(WHERE_THE_PATCH_IS)/stream_inl.pat
(This is the patch to the original file.)

 cd $(ECOS_REPOSITORY)/packages/fs/rom/current/src
patch -p0 < $(WHERE_THE_PATCH_IS)/romfs_c.pat

best regards,
JJ



[-- Attachment #2: fseek.c --]
[-- Type: text/x-c, Size: 1773 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, 1, SEEK_CUR))<0)
		printf("fseek=%d\n",err);

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

	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 256

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

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

	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 686
	}
	while(0);

	fclose(fd);
	}

    return 0;

}


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

--- romfs.c	Wed Jul 18 14:50:23 2001
+++ romfs.c.new	Wed Jul 18 14:28:15 2001
@@ -912,10 +912,16 @@
     {
     case SEEK_SET:
         // Pos is already where we want to be.
+	fp->f_offset= *apos; //add jjt
         break;
 
     case SEEK_CUR:
         // Add pos to current offset.
+	// comment jjt
+	// the following line should NEVER be executed
+	// because it will cause the inconsistency between
+	// fp->f_offset and real_stream.position. 
+	// end comment jjt
         pos += fp->f_offset;
         break;
 

[-- Attachment #4: stream_inl.pat --]
[-- Type: text/x-diff, Size: 2666 bytes --]

--- stream.inl	Wed Jul 18 14:45:00 2001
+++ stream.inl.new	Wed Jul 18 14:44:09 2001
@@ -363,6 +363,8 @@
 inline Cyg_ErrNo
 Cyg_StdioStream::set_position( fpos_t pos, int whence )
 {
+    CYG_ASSERTCLASS( this, "Stream object is not a valid stream!" );
+    
 #ifndef CYGPKG_LIBC_STDIO_FILEIO    
     // this is currently a workaround until we have real files
     // this will be corrected when we decide the true filesystem interface
@@ -370,8 +372,6 @@
     Cyg_ErrNo err;
     cyg_uint8 c;
 
-    CYG_ASSERTCLASS( this, "Stream object is not a valid stream!" );
-    
     if ((whence != SEEK_CUR) || pos < 0)
         return ENOSYS;
 
@@ -398,15 +398,54 @@
     
 #else
 
-    Cyg_ErrNo err;
-    off_t newpos = pos;
-
-    CYG_ASSERTCLASS( this, "Stream object is not a valid stream!" );
-    
     if (!lock_me())
         return EBADF; // assume file is now invalid
 
-    err = cyg_stdio_lseek( my_device, &newpos, whence );
+    if ( whence != SEEK_END ) {
+        cyg_ucount32 bytesavail = bytes_available_to_read();
+        off_t abspos = (whence == SEEK_CUR) ? position + pos : pos;
+        off_t posdiff = abspos - position;
+    
+        if ( bytesavail > posdiff ) {
+            // can just "seek" within the existing buffer
+#ifdef CYGFUN_LIBC_STDIO_ungetc
+            if (flags.unread_char_buf_in_use) {
+                flags.unread_char_buf_in_use = false;
+                posdiff--;
+            }
+#endif
+#ifdef CYGSEM_LIBC_STDIO_WANT_BUFFERED_IO
+            if (posdiff>0 && flags.buffering) {
+                io_buf.set_bytes_read(posdiff);
+                posdiff=0;
+            } else 
+#endif
+            if (posdiff>0 && flags.readbuf_char_in_use) {
+                flags.readbuf_char_in_use = false;
+                posdiff--;
+            }
+            CYG_ASSERT(posdiff==0, "Failed to seek within buffer correctly");
+
+            position = abspos;
+            unlock_me();
+            return ENOERR;
+        } // endif (bytesavail > posdiff)
+    } //endif (whence != SEEK_END)
+
+    Cyg_ErrNo err;
+    off_t newpos=pos;
+
+    //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 )
     {
@@ -422,10 +461,10 @@
 
         // Clear EOF indicator.
         flags.at_eof = false;
-    }
-    
-    if( err == ENOERR )
+        
+        // update stream pos
         position = newpos;
+    }
     
     unlock_me();
 

  reply	other threads:[~2001-07-18  0:07 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2001-07-16  0:47 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 [this message]
2001-07-19 23:42         ` Jonathan Larmour

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to='003401c10f58$b2853ea0$8c78608c@ccl.itri.org.tw' \
    --to=jjtsai@itri.org.tw \
    --cc=ecos-discuss@sources.redhat.com \
    --cc=jlarmour@redhat.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).