File contains only zero's.

This is a discussion on File contains only zero's. within the C Programming forums, part of the General Programming Boards category; I've got a problem with an embedded PC which generates corrupted files during a shutdown-boot cycle. The corrupted files contain ...

  1. #1
    Registered User
    Join Date
    Jul 2006
    Posts
    1

    File contains only zero's.

    I've got a problem with an embedded PC which generates corrupted files during a shutdown-boot cycle. The corrupted files contain the correct (estimated) number of bytes, but all bytes have a zero value. To make the problem more interesting this occurs sometimes (after 1 cycle or after 30 cycles), and when it happens it can be possible that only the last number of bytes of the file contain zero's. Shutdown means that the power is shut down on the complete machine, thus stopping the PC immdiately. There's no way of forcing the OS to start a shutdown process.

    System used:
    Embedded PIV platform based on Intel 845GV chipset.
    Harddisk: Maxtor Fireball 3 or Diamonmax Plus 8 (40Gb). Microsoft XP embedded, EWF using RAM overlay on c: partition. Corrupted files are created on NTFS non-EWF d: partition.

    File handling code (c++):

    m_hFile = CreateFile( fname,
    GENERIC_WRITE | GENERIC_READ,
    0,
    &sa,
    OPEN_ALWAYS,
    FILE_ATTRIBUTE_NORMAL | FILE_FLAG_WRITE_THROUGH | FILE_FLAG_RANDOM_ACCESS ,
    NULL);

    if (m_hFile)
    {
    //doing stuff...

    FlushFileBuffers(m_hFile);
    CloseHandle(m_hFile);
    }

    And on the same file(s), not at the same time:

    fp = fopen(fname,"rt");

    if (fp)
    {
    //doing stuff...

    fflush(fp);
    fclose(fp);
    }

    I suspect that some kind of buffer failed to write (all) bytes to an already prepared file. This explains the number of bytes being zero. If this is an OS buffer, a filesystem buffer or a hardware buffer is unclear to me. Does one of you have experienced the same problem, or got any idea on how I can solve this problem? "

    ===
    Afsluiting :
    "
    Thanks in advance,

    Greetings from your big friend from The Netherlands,

  2. #2
    Gawking at stupidity
    Join Date
    Jul 2004
    Location
    Oregon, USA
    Posts
    3,171
    It sounds like an OS buffer. I know that *NIX has a sync() function:
    NAME
    sync - commit buffer cache to disk

    SYNOPSIS
    #include <unistd.h>

    void sync(void);

    DESCRIPTION
    sync first commits inodes to buffers, and then buffers to
    disk.

    ERRORS
    This function is always successful.

    CONFORMING TO
    SVr4, SVID, X/OPEN, BSD 4.3
    This forces the OS buffer to flush to the hardware. I'm not sure if the Windows API has something similar, but it would probably help.
    If you understand what you're doing, you're not learning anything.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Encryption program
    By zeiffelz in forum C Programming
    Replies: 1
    Last Post: 06-15-2005, 04:39 AM
  2. Unknown Memory Leak in Init() Function
    By CodeHacker in forum Windows Programming
    Replies: 3
    Last Post: 07-09-2004, 10:54 AM
  3. Making a LIB file from a DEF file for a DLL
    By JMPACS in forum C++ Programming
    Replies: 0
    Last Post: 08-02-2003, 09:19 PM
  4. Hmm....help me take a look at this: File Encryptor
    By heljy in forum C Programming
    Replies: 3
    Last Post: 03-23-2002, 10:57 AM
  5. Need a suggestion on a school project..
    By Screwz Luse in forum C Programming
    Replies: 5
    Last Post: 11-27-2001, 02:58 AM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21