VxWorks Reference Manual : Libraries

ramDrv

NAME

ramDrv - RAM disk driver

ROUTINES

ramDrv( ) - prepare a RAM disk driver for use (optional)
ramDevCreate( ) - create a RAM disk device

DESCRIPTION

This driver emulates a disk driver, but actually keeps all data in memory. The memory location and size are specified when the "disk" is created. The RAM disk feature is useful when data must be preserved between boots of VxWorks or when sharing data between CPUs.

USER-CALLABLE ROUTINES

Most of the routines in this driver are accessible only through the I/O system. Two routines, however, can be called directly by the user. The first, ramDrv( ), provides no real function except to parallel the initialization function found in true disk device drivers. A call to ramDrv( ) is not required to use the RAM disk driver. However, the second routine, ramDevCreate( ), must be called directly to create RAM disk devices.

Once the device has been created, it must be associated with a name and file system (dosFs, rt11Fs, or rawFs). This is accomplished by passing the value returned by ramDevCreate( ), a pointer to a block device structure, to the file system's device initialization routine or make-file-system routine. See the manual entry ramDevCreate( ) for a more detailed discussion.

IOCTL FUNCTIONS

The RAM driver is called in response to ioctl( ) codes in the same manner as a normal disk driver. When the file system is unable to handle a specific ioctl( ) request, it is passed to the ramDrv driver. Although there is no physical device to be controlled, ramDrv does handle a FIODISKFORMAT request, which always returns OK. All other ioctl( ) requests return an error and set the task's errno to S_ioLib_UNKNOWN_REQUEST.

INCLUDE FILE

ramDrv.h

SEE ALSO

ramDrv, dosFsDevInit( ), dosFsMkfs( ), rt11FsDevInit( ), rt11FsMkfs( ), rawFsDevInit( ), VxWorks Programmer's Guide: I/O System, Local File Systems


Libraries : Routines

ramDrv( )

NAME

ramDrv( ) - prepare a RAM disk driver for use (optional)

SYNOPSIS


STATUS ramDrv (void)

DESCRIPTION

This routine performs no real function, except to provide compatibility with earlier versions of ramDrv and to parallel the initialization function found in true disk device drivers. It also is used in usrConfig.c to link in the RAM disk driver when building VxWorks. Otherwise, there is no need to call this routine before using the RAM disk driver.

RETURNS

OK, always.

SEE ALSO

ramDrv


Libraries : Routines

ramDevCreate( )

NAME

ramDevCreate( ) - create a RAM disk device

SYNOPSIS

BLK_DEV *ramDevCreate
    (
    char * ramAddr,      /* where it is in memory (0 = malloc) */
    int    bytesPerBlk,  /* number of bytes per block */
    int    blksPerTrack, /* number of blocks per track */
    int    nBlocks,      /* number of blocks on this device */
    int    blkOffset     /* no. of blks to skip at start of device */
    )

DESCRIPTION

This routine creates a RAM disk device.

Memory for the RAM disk can be pre-allocated separately; if so, the ramAddr parameter should be the address of the pre-allocated device memory. Or, memory can be automatically allocated with malloc( ) by setting ramAddr to zero.

The bytesPerBlk parameter specifies the size of each logical block on the RAM disk. If bytesPerBlk is zero, 512 is used.

The blksPerTrack parameter specifies the number of blocks on each logical track of the RAM disk. If blksPerTrack is zero, the count of blocks per track is set to nBlocks (i.e., the disk is defined as having only one track).

The nBlocks parameter specifies the size of the disk, in blocks. If nBlocks is zero, a default size is used. The default is calculated using a total disk size of either 51,200 bytes or one-half of the size of the largest memory area available, whichever is less. This default disk size is then divided by bytesPerBlk to determine the number of blocks.

The blkOffset parameter specifies an offset, in blocks, from the start of the device to be used when writing or reading the RAM disk. This offset is added to the block numbers passed by the file system during disk accesses. (VxWorks file systems always use block numbers beginning at zero for the start of a device.) This offset value is typically useful only if a specific address is given for ramAddr. Normally, blkOffset is 0.

FILE SYSTEMS

Once the device has been created, it must be associated with a name and a file system (dosFs, rt11Fs, or rawFs). This is accomplished using the file system's device initialization routine or make-file-system routine, e.g., dosFsDevInit( ) or dosFsMkfs( ). The ramDevCreate( ) call returns a pointer to a block device structure (BLK_DEV). This structure contains fields that describe the physical properties of a disk device and specify the addresses of routines within the ramDrv driver. The BLK_DEV structure address must be passed to the desired file system (dosFs, rt11Fs or rawFs) via the file system's device initialization or make-file-system routine. Only then is a name and file system associated with the device, making it available for use.

EXAMPLE

In the following example, a 200-Kbyte RAM disk is created with automatically allocated memory, 512-byte blocks, a single track, and no block offset. The device is then initialized for use with dosFs and assigned the name "DEV1:":

    BLK_DEV *pBlkDev;
    DOS_VOL_DESC *pVolDesc;

    pBlkDev = ramDevCreate (0,  512,  400,  400,  0);
    pVolDesc = dosFsMkfs ("DEV1:", pBlkDev);
The dosFsMkfs( ) routine calls dosFsDevInit( ) with default parameters and initializes the file system on the disk by calling ioctl( ) with the FIODISKINIT function.

If the RAM disk memory already contains a disk image created elsewhere, the first argument to ramDevCreate( ) should be the address in memory, and the formatting parameters -- bytesPerBlk, blksPerTrack, nBlocks, and blkOffset -- must be identical to those used when the image was created. For example:

    pBlkDev = ramDevCreate (0xc0000, 512, 400, 400, 0);
    pVolDesc = dosFsDevInit ("DEV1:", pBlkDev, NULL);
In this case, dosFsDevInit( ) must be used instead of dosFsMkfs( ), because the file system already exists on the disk and should not be re-initialized. This procedure is useful if a RAM disk is to be created at the same address used in a previous boot of VxWorks. The contents of the RAM disk will then be preserved.

These same procedures apply when creating a RAM disk with rt11Fs using rt11FsDevInit( ) and rt11FsMkfs( ), or creating a RAM disk with rawFs using rawFsDevInit( ).

RETURNS

A pointer to a block device structure (BLK_DEV) or NULL if memory cannot be allocated for the device structure or for the RAM disk.

SEE ALSO

ramDrv, dosFsMkfs( ), dosFsDevInit( ), rt11FsDevInit( ), rt11FsMkfs( ), rawFsDevInit( )