×

Discussion Board

Page 1 of 2 12 LastLast
Results 1 to 15 of 22
  1. #1
    Regular Contributor
    Join Date
    Jul 2006
    Location
    Italy
    Posts
    99

    RFile Read Write Asynchronous KErrCorrupt

    Hi all, I read another post about the problem but the problem it's bit different. I'm trying to Copy a file with read and write method of the RFile object. The files could be big (4-5MB) so I use the asynchronous method to read in a buffer and write in the other file. The problem is that the first read, or even the first write, always get me an KErrCorrupt in the RunL function. I open the files and create the buffer in the ConstructL of the class, after I start to read the source file...and I always got KErrCorrupt

  2. #2
    Super Contributor
    Join Date
    Oct 2005
    Location
    Hyderabad,India
    Posts
    1,156

    Re: RFile Read Write Asynchronous KErrCorrupt

    Could you post the code, and more over what priority have you set for the active object that reads the file?

    Priju

  3. #3
    Regular Contributor
    Join Date
    Jul 2006
    Location
    Italy
    Posts
    99

    Re: RFile Read Write Asynchronous KErrCorrupt

    I try with EPriorityStandard and EPriorityHigh but the problem it's the same. I try to change the source and destination directory from SD to internal memory.

    I have implemented a separate class, here is some code:

    void CCopyFileAsync::ConstructL()
    {
    CActiveScheduler::Add( this );
    m_iTotBytesRead=0;
    RFs& aFs=CCoeEnv::Static()->FsSession();
    m_fSource.Open(aFs,_L("c:\\data\\file1.jpg"),EFileRead);
    m_fDest.Replace(aFs,_L("c:\\data\\file2.jpg"),EFileWrite);
    TInt iSize;
    m_fSource.Size(iSize);
    m_pTmpBuffer = HBufC8::NewL(iSize);
    }

    void CCopyFileAsync::StartCopy()
    {
    TPtr8 puntBuffer(m_pTmpBuffer->Des());
    m_fSource.Read(m_iTotBytesRead, puntBuffer,iStatus);
    SetActive();
    }

    void CCopyFileAsync::RunL()
    {
    if (iStatus == KErrNone)
    {
    if (m_pTmpBuffer)
    {
    delete m_pTmpBuffer;
    m_pTmpBuffer=NULL;
    }
    m_fSource.Close();
    m_fDest.Close();
    iObserver->CopyFinish(iStatus.Int(),_L("OK"));
    }else{
    if (m_pTmpBuffer)
    {
    delete m_pTmpBuffer;
    m_pTmpBuffer=NULL;
    }
    m_fSource.Close();
    m_fDest.Close();
    iObserver->CopyFinish(iStatus.Int(),_L("KO"));
    }
    }

    When I enter in RunL I always got KErrCorrupt...
    If I use the synchronous method per read and write the file it's ok.
    ps. I have omitted the code for write the file because the problem it's on the first read

  4. #4
    Regular Contributor
    Join Date
    Jul 2006
    Location
    Italy
    Posts
    99

    Re: RFile Read Write Asynchronous KErrCorrupt

    But....the question is: What does it mean KErrCorrupt? I'm reading asynchronous a file...what is corrupting?

  5. #5
    Super Contributor
    Join Date
    Oct 2005
    Location
    Hyderabad,India
    Posts
    1,156

    Re: RFile Read Write Asynchronous KErrCorrupt

    Hi,
    Your code looks fine to me.Could you please replace the .jpg files with some small text files and test it out.Check whether that works fine, and moreover the path that you have mentioned looks a bit fishy, as i dont think there is a folder named as 'data' inside the 'c' folder? Did you happen to create that folder? Anyways, if the source path is invalid, the error code wouldnt be KErrCorrupt, probably -1 would be returned.

    Priju

  6. #6
    Regular Contributor
    Join Date
    Jul 2006
    Location
    Italy
    Posts
    99

    Re: RFile Read Write Asynchronous KErrCorrupt

    Yes c:\data is a path that I have created for some test. Now I'll try with some small file and I'll give you feedback

  7. #7
    Regular Contributor
    Join Date
    Jul 2006
    Location
    Italy
    Posts
    99

    Re: RFile Read Write Asynchronous KErrCorrupt

    I try with another smaller file...but I got always KErrCorrupt I can't understand...

  8. #8
    Super Contributor
    Join Date
    Oct 2005
    Location
    Hyderabad,India
    Posts
    1,156

    Re: RFile Read Write Asynchronous KErrCorrupt

    Quote Originally Posted by muntain View Post
    I try with another smaller file...but I got always KErrCorrupt I can't understand...
    Let me work it out here. Post you the results soon.

    Priju

  9. #9
    Regular Contributor
    Join Date
    Jul 2006
    Location
    Italy
    Posts
    99

    Re: RFile Read Write Asynchronous KErrCorrupt

    Ok, thank you for the support

  10. #10
    Super Contributor
    Join Date
    Oct 2005
    Location
    Hyderabad,India
    Posts
    1,156

    Re: RFile Read Write Asynchronous KErrCorrupt

    Quote Originally Posted by muntain View Post
    void CCopyFileAsync::StartCopy()
    {
    TPtr8 puntBuffer(m_pTmpBuffer->Des());
    m_fSource.Read(m_iTotBytesRead, puntBuffer,iStatus);
    SetActive();
    }
    Dude, it works fine for me here. Im able to make a replica of the image.
    Let me ask you. In the above code which you had posted. puntBuffer is a TPtr8, but Read doesnt accept a TPtr8 as an argument in the second position. it looks for a TInt Length value. Didnt you get compile time errors?

    Priju

  11. #11
    Regular Contributor
    Join Date
    Jul 2006
    Location
    Italy
    Posts
    99

    Re: RFile Read Write Asynchronous KErrCorrupt

    It depend from the method overload that you use. Ther's 6 overload of the method read: 3 synchronous and 3 asynchronous.
    sync:
    IMPORT_C TInt Read(TDes8 &aDes, TInt aLength) const;
    IMPORT_C TInt Read(TDes8 &aDes, TInt aLength) const;
    IMPORT_C TInt Read(TInt aPos, TDes8 &aDes, TInt aLength) const;

    async:
    IMPORT_C TInt Read(TDes8 &aDes, TInt aLength, TRequestStatus &aStatus) const;
    IMPORT_C TInt Read(TDes8 &aDes, TInt aLength, TRequestStatus &aStatus) const;
    IMPORT_C TInt Read(TInt aPos, TDes8 &aDes, TInt aLength, TRequestStatus &aStatus) const;

    I don't understand the problem...
    the strange error it's KErrCorrupt..what's corrupting?

  12. #12
    Super Contributor
    Join Date
    Oct 2005
    Location
    Hyderabad,India
    Posts
    1,156

    Re: RFile Read Write Asynchronous KErrCorrupt

    Well, this is my peice of code and it works for me.

    Code:
    void ActiveRead::ConstructL()
    {
        iFs.Connect();
        _LIT(KFile,"c:\\system\\apps\\MyXmlParser\\test.jpg");
        _LIT(KFile1,"c:\\system\\apps\\MyXmlParser\\test1.jpg");
        aFile.Replace(iFs,KFile1,EFileWrite);
        iFile.Open(iFs,KFile,EFileRead);   
        
        iFile.Size(iSizeRead);
        m_pTmpBuffer = HBufC8::NewL(iSizeRead);
        // mpuntBuffer is TPtr8 and i initialise it in the constructor.
        mpuntBuffer.Set(m_pTmpBuffer->Des());
        aFile.Size(iSizeWrite);        
        ReadFile();
    }
    Code:
    void ActiveRead::ReadFile()
    {  
        iFile.Read(mpuntBuffer, 100,iStatus);
        SetActive();
    }
    Code:
    void ActiveRead::RunL()
    {
       if (iStatus == KErrNone)
        {    
          if ( m_pTmpBuffer->Des().Length() == iSizeRead )
                {            
                 iFile.Close();
                 delete m_pTmpBuffer;
                 m_pTmpBuffer = 0;
                }
          else
             {
                // Read the next chunk of the file.            
                aFile.Write(mpuntBuffer);  
                aFile.Size(iSizeWrite);
                
                if(iSizeWrite!=iSizeRead)      
                  ReadFile();                           
             }            
        }
        else
        {
          TBuf<10>abuf;
          abuf.AppendNum(iStatus.Int());
          User::InfoPrint(abuf);
        }   
    
    }
    Regards,
    Priju

  13. #13
    Regular Contributor
    Join Date
    Jul 2006
    Location
    Italy
    Posts
    99

    Re: RFile Read Write Asynchronous KErrCorrupt

    Ok thank you, I'm going to try your code, I'll give you feedback

  14. #14
    Regular Contributor
    Join Date
    Jul 2006
    Location
    Italy
    Posts
    99

    Re: RFile Read Write Asynchronous KErrCorrupt

    No...the problem it's the same...I'm realy confused but probably it's my problem, thank you anyway for the support

  15. #15
    Nokia Developer Champion
    Join Date
    Jul 2004
    Posts
    2,015

    Re: RFile Read Write Asynchronous KErrCorrupt

    Quote Originally Posted by muntain View Post
    It depend from the method overload that you use. Ther's 6 overload of the method read: 3 synchronous and 3 asynchronous.
    sync:
    IMPORT_C TInt Read(TDes8 &aDes, TInt aLength) const;
    IMPORT_C TInt Read(TDes8 &aDes, TInt aLength) const;
    IMPORT_C TInt Read(TInt aPos, TDes8 &aDes, TInt aLength) const;

    async:
    IMPORT_C TInt Read(TDes8 &aDes, TInt aLength, TRequestStatus &aStatus) const;
    IMPORT_C TInt Read(TDes8 &aDes, TInt aLength, TRequestStatus &aStatus) const;
    IMPORT_C TInt Read(TInt aPos, TDes8 &aDes, TInt aLength, TRequestStatus &aStatus) const;

    I don't understand the problem...
    the strange error it's KErrCorrupt..what's corrupting?
    So which of these does this
    m_fSource.Read(m_iTotBytesRead, puntBuffer,iStatus);

    match to?

    If m_iTotBytesRead is a TInt, puntBuffer is a descriptor, iStatus is a TRequestStatus then I don't see the following signature in your list

    IMPORT_C TInt Read(TInt aPos, TDes8 &aDes, TRequestStatus &aStatus)

Similar Threads

  1. who can tell me how to Read and Write a 'Txt' file random.
    By wingfancy in forum Symbian User Interface
    Replies: 0
    Last Post: 2003-03-17, 00:38
  2. read and write operator logo, ring tones, phonebook, calendar and sms
    By pinodilucca in forum PC Suite API and PC Connectivity SDK
    Replies: 1
    Last Post: 2003-03-06, 11:59
  3. read / write INI file
    By Jeepy in forum Symbian
    Replies: 1
    Last Post: 2003-02-10, 15:39
  4. read write modify phonebook entries of Nokia 6310i
    By tixoman in forum PC Suite API and PC Connectivity SDK
    Replies: 0
    Last Post: 2002-12-13, 09:22
  5. read and write Chinese menu in J2ME
    By walterzcm in forum Mobile Java General
    Replies: 0
    Last Post: 2002-11-13, 06:22

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
×