VxWorks Reference Manual : Libraries
memDrv - pseudo memory device driver
memDrv( ) - install a memory driver
memDevCreate( ) - create a memory device
memDevCreateDir( ) - create a memory device for multiple files
memDevDelete( ) - delete a memory device
This driver allows the I/O system to access memory directly as a pseudo-I/O device. Memory location and size are specified when the device is created. This feature is useful when data must be preserved between boots of VxWorks or when sharing data between CPUs.
Additionally, it can be used to build some files into a VxWorks binary image (having first converted them to data arrays in C source files, using a utility such as memdrvbuild), and then mount them in the filesystem; this is a simple way of delivering some non-changing files with VxWorks. For example, a system with an integrated web server may use this technique to build some HTML and associated content files into VxWorks.
memDrv can be used to simply provide a high-level method of reading and writing bytes in absolute memory locations through I/O calls. It can also be used to implement a simple, essentially read-only filesystem (exsisting files can be rewritten within their existing sizes); directory searches and a limited set of IOCTL calls (including stat( )) are supported.
Most of the routines in this driver are accessible only through the I/O system. Four routines, however, can be called directly: memDrv( ) to initialize the driver, memDevCreate( ) and memDevCreateDir( ) to create devices, and memDevDelete( ) to delete devices.
Before using the driver, it must be initialized by calling memDrv( ). This routine should be called only once, before any reads, writes, or memDevCreate( ) calls. It may be called from usrRoot( ) in usrConfig.c or at some later point.
The dosFs file system supports the following ioctl( ) functions. The functions listed are defined in the header ioLib.h. Unless stated otherwise, the file descriptor used for these functions may be any file descriptor which is opened to a file or directory on the volume or to the volume itself.
- FIOGETFL
- Copies to flags the open mode flags of the file (O_RDONLY, O_WRONLY, O_RDWR):
int flags; status = ioctl (fd, FIOGETFL, &flags);- FIOSEEK
- Sets the current byte offset in the file to the position specified by newOffset:
status = ioctl (fd, FIOSEEK, newOffset);The FIOSEEK offset is always relative to the beginning of the file. The offset, if any, given at open time by using pseudo-file name is overridden.
- FIOWHERE
- Returns the current byte position in the file. This is the byte offset of the next byte to be read or written. It takes no additional argument:
position = ioctl (fd, FIOWHERE, 0);- FIONREAD
- Copies to unreadCount the number of unread bytes in the file:
int unreadCount; status = ioctl (fd, FIONREAD, &unreadCount);- FIOREADDIR
- Reads the next directory entry. The argument dirStruct is a DIR directory descriptor. Normally, the readdir( ) routine is used to read a directory, rather than using the FIOREADDIR function directly. See dirLib.
DIR dirStruct; fd = open ("directory", O_RDONLY); status = ioctl (fd, FIOREADDIR, &dirStruct);- FIOFSTATGET
- Gets file status information (directory entry data). The argument statStruct is a pointer to a stat structure that is filled with data describing the specified file. File inode numbers, user and group IDs, and times are not supported (returned as 0).
Normally, the stat( ) or fstat( ) routine is used to obtain file information, rather than using the FIOFSTATGET function directly. See dirLib.
struct stat statStruct; fd = open ("file", O_RDONLY); status = ioctl (fd, FIOFSTATGET, &statStruct);Any other ioctl( ) function codes will return error status.
memDrv, VxWorks Programmer's Guide: I/O System
memDrv( ) - install a memory driver
STATUS memDrv (void)
This routine initializes the memory driver. It must be called first, before any other routine in the driver.
OK, or ERROR if the I/O system cannot install the driver.
memDevCreate( ) - create a memory device
STATUS memDevCreate ( char * name, /* device name */ char * base, /* where to start in memory */ int length /* number of bytes */ )
This routine creates a memory device containing a single file. Memory for the device is simply an absolute memory location beginning at base. The length parameter indicates the size of memory.
For example, to create the device "/mem/cpu0/", a device for accessing the entire memory of the local processor, the proper call would be:
memDevCreate ("/mem/cpu0/", 0, sysMemTop())The device is created with the specified name, start location, and size.To open a file descriptor to the memory, use open( ). Specify a pseudo-file name of the byte offset desired, or open the "raw" file at the beginning and specify a position to seek to. For example, the following call to open( ) allows memory to be read starting at decimal offset 1000.
-> fd = open ("/mem/cpu0/1000", O_RDONLY, 0)Pseudo-file name offsets are scanned with "%d".
The FIOSEEK operation overrides the offset given via the pseudo-file name at open time.
Consider a system configured with two CPUs in the backplane and a separate dual-ported memory board, each with 1 megabyte of memory. The first CPU is mapped at VMEbus address 0x00400000 (4 Meg.), the second at bus address 0x00800000 (8 Meg.), the dual-ported memory board at 0x00c00000 (12 Meg.). Three devices can be created on each CPU as follows. On processor 0:
-> memDevCreate ("/mem/local/", 0, sysMemTop()) ... -> memDevCreate ("/mem/cpu1/", 0x00800000, 0x00100000) ... -> memDevCreate ("/mem/share/", 0x00c00000, 0x00100000)On processor 1:-> memDevCreate ("/mem/local/", 0, sysMemTop()) ... -> memDevCreate ("/mem/cpu0/", 0x00400000, 0x00100000) ... -> memDevCreate ("/mem/share/", 0x00c00000, 0x00100000)Processor 0 has a local disk. Data or an object module needs to be passed from processor 0 to processor 1. To accomplish this, processor 0 first calls:-> copy </disk1/module.o >/mem/share/0Processor 1 can then be given the load command:-> ld </mem/share/0
OK, or ERROR if memory is insufficient or the I/O system cannot add
the device.
S_ioLib_NO_DRIVER
memDevCreateDir( ) - create a memory device for multiple files
STATUS memDevCreateDir ( char * name, /* device name */ MEM_DRV_DIRENTRY * files, /* array of dir. entries - not copied */ int numFiles /* number of entries */ )
This routine creates a memory device for a collection of files organised into directories. The given array of directory entry records describes a number of files, some of which may be directories, represented by their own directory entry arrays. The structure may be arbitrarily deep. This effectively allows a filesystem to be created and installed in VxWorks, for essentially read-only use. The filesystem structure can be created on the host using the memdrvbuild utility.
Note that the array supplied is not copied; a reference to it is kept. This array should not be modified after being passed to memDevCreateDir.
OK, or ERROR if memory is insufficient or the I/O system cannot
add the device.
S_ioLib_NO_DRIVER
memDevDelete( ) - delete a memory device
STATUS memDevDelete ( char * name /* device name */ )
This routine deletes a memory device containing a single file or a collection of files. The device is deleted with it own name.
For example, to delete the device created by memDevCreate ("/mem/cpu0/", 0, sysMemTop( )), the proper call would be:
memDevDelete ("/mem/cpu0/");
OK, or ERROR if the device doesn't exist.