next up previous contents
Next: The cyclic_log class Up: Design Notes Previous: The cyclic log header   Contents

The cyclic log descriptor

The cyclic log descriptor is returned from CYC_open and is analogous to the FILE* returned by fopen. It contains a copy of the complete header since the header gets rewritten whenever data is added to the file (because the pointer values change).

The descriptor contains the start and end offsets and the size of the file in bytes. The read position is maintained, the write position is simply the end offset. Flags are also used to remember whether or not a read or write has wrapped. For the reader this is used to detect end of file. For the writer this is used to tell the write position to reset to just after the header. The descriptor also contains the integer file descriptor used in the file routines read, write, lseek and close.

typedef struct logfileDescriptor
{
    /**
     * Copy of the complete header which is rewritten at the start
     * whenever data is added to the file (because the pointer values
     * change).
     */
    CYC_LogfileHeader m_header;

    /**
     * The file descriptor on which the file is open.
     */
    int m_fd;

    /**
     * The file size in bytes, used to detect the wraparound condition.
     */
    off_t m_fileSize;

    /**
     * The file position at which the data starts.
     */
    off_t m_start;

    /**
     * The file position at which the data ends.
     * New data gets written here and the pointer advanced.
     */
    off_t m_end;

    /**
     * The file position from which to next the next bytes.
     */
    off_t m_readPosition;

    /**
     * True if the reader has wrapped during the read.
     */
    int m_wrapped;

    /**
     * True if the writer has wrapped during the write.
     */
    int m_writeWrapped;

} CYC_fd;



Andrew Marlow 2004-01-01