[En-Nut-Discussion] Seekable devices

Ralph Mason ralph.mason at telogis.com
Fri May 2 06:56:30 CEST 2003


I have implemented a Seekable device structure and would like to submit it
for consideration.

It changes the NUT device structure - removing the dev_size from it and
pushing into a seekable functions in to a structure that subblasses the
NUTDEVICE structure. This stops all the device structures getting larger.

It adds another device type IFTYP_SEEKABLE. I have implemented the fseek &
ftell functions, which I will supply if needed.

#define IFTYP_RAM       0	/*!< \brief RAM device */
#define IFTYP_ROM       1	/*!< \brief ROM device */
#define IFTYP_STREAM    2	/*!< \brief Stream device */
#define IFTYP_NET       3	/*!< \brief Net device */
#define IFTYP_TCPSOCK	4	/*!< \brief TCP socket */
#define IFTYP_SEEKABLE	5	/*!< \brief Seekable device */

/*!
 * \brief Device structure type.
 */
typedef struct _NUTDEVICE NUTDEVICE;

/*!
 * \struct _NUTDEVICE device.h sys/device.h
 * \brief Device structure.
 */
struct _NUTDEVICE {

    /*!
     * \brief Link to the next device structure.
     */
    NUTDEVICE *dev_next;

    /*!
     * \brief Unique device name.
     */
    u_char dev_name[9];

    /*!
     * \brief Type of interface.
     *
     * May be any of the following:
     * - IFTYP_RAM
     * - IFTYP_ROM
     * - IFTYP_STREAM
     * - IFTYP_NET
     * - IFTYP_SEEKABLE
     */
    u_char dev_type;

    /*!
     * \brief Hardware base address.
     *
     * Will be set by calling NutRegisterDevice(). On some device
     * drivers this address may be fixed.
     */
    u_char* dev_base;

    /*! \brief Interrupt registration number.
     *
     * Will be set by calling NutRegisterDevice(). On some device
     * drivers the interrupt may be fixed.
     */
    u_char dev_irq;

    /*! \brief Interface control block.
     *
     * With stream devices, this points to the IFSTREAM structure and
     * with network devices this is a pointer to the IFNET structure.
     */
    void *dev_icb;

    /*!
     * \brief Driver control block.
     *
     * Points to a device specific information block.
     */
    void *dev_dcb;

    /*!
     * \brief Driver initialization routine.
     *
     * With stream devices this is called during NutDeviceOpen(). For
     * network devices this routine is called within NutNetIfConfig().
     */
    int (*dev_init) (NUTDEVICE *);

    /*!
     * \brief Driver control function.
     *
     * Used to modify or query device specific settings.
     */
    int (*dev_ioctl) (NUTDEVICE *, int, void *);

    /*!
     * \brief Read from device.
     */
    int (*dev_read) (NUTFILE *, void *, int);

    /*!
     * \brief Write to device.
     */
    int (*dev_write) (NUTFILE *, CONST void *, int);

    /*!
     * \brief Write to device.
     */
    int (*dev_write_P) (NUTFILE *, PGM_P, int);

    /*!
     * \brief Open a device or file.
     */
    NUTFILE * (*dev_open) (NUTDEVICE *, CONST char *, int, int);

    /*!
     * \brief Close a device or file.
     */
    int (*dev_close) (NUTFILE *);

};
typedef struct _NUTSEEKABLEDEVICE NUTSEEKABLEDEVICE;

struct _NUTSEEKABLEDEVICE {

     struct _NUTDEVICE dev;

    /*!
     * \brief Request file size.
     */
    long (*dev_size) (NUTFILE *);

    /*!
     * \brief Seek to a given offset
     */
     long (*dev_seek) (NUTFILE*,long,int);

    /*!
     * \brief give current offset
     */
     long (*dev_tell) (NUTFILE*);
};

Regards
Ralph
---
Outgoing mail is certified Virus Free.
Checked by AVG anti-virus system (http://www.grisoft.com).
Version: 6.0.461 / Virus Database: 260 - Release Date: 10/03/2003




More information about the En-Nut-Discussion mailing list