?? unixdrv.c
字號:
/* unixDrv.c - UNIX-file disk driver (VxSim for Solaris and VxSim for HP) *//* Copyright 1984-1999 Wind River Systems, Inc. */#include "copyright_wrs.h"/* modification history--------------------01j,16mar99,elg mention unixDrv is for Solaris and HP simulators (SPR 7719).01i,11jul97,dgp doc: ad (VxSim) to title line01h,09jan97,pr added ARCHCVTFLAGS for simsolaris01g,30oct95,ism added support for simsolaris01f,31oct94,kdl made conditional for simulator only.01e,18aug93,gae modified unix_stat for hp.01d,30jul93,gae doc touchup.01c,23jan93,gae ANSIfied.01b,20jul92,gae minor revision.01a,01apr91,smeg derived from ramDrv.*//*DESCRIPTIONThis driver emulates a VxWorks disk driver, but actually uses the UNIXfile system to store the data. The VxWorks disk appears underUNIX as a single file.The UNIX file name, and the size of the disk, may be specified during the unixDiskDevCreate() call.USER-CALLABLE ROUTINESMost of the routines in this driver are accessible only through the I/Osystem. The routine unixDrv() must be called to initialize the driver andthe unixDiskDevCreate() routine is used to create devices.CREATING UNIX DISKSBefore a UNIX disk can be used, it must be created. This is donewith the unixDiskDevCreate() call. The format of this call is:.CS BLK_DEV *unixDiskDevCreate ( char *unixFile, /@ name of the UNIX file to use @/ int bytesPerBlk, /@ number of bytes per block @/ int blksPerTrack, /@ number of blocks per track @/ int nBlocks /@ number of blocks on this device @/ ).CEThe UNIX file must be pre-allocated separately. Thiscan be done using the UNIX mkfile(8) command. Note that you have tocreate an appropriately sized file. For example, to create a UNIXfile system that is used as a common floppy dosFs file system, youwould issue the comand:.CS mkfile 1440k /tmp/floppy.dos.CEThis will create space for a 1.44 Meg DOS floppy (1474560 bytes,or 2880 512-byte blocks).The <bytesPerBlk> parameter specifies the size of each logical blockon the disk. If <bytesPerBlk> is zero, 512 is the default.The <blksPerTrack> parameter specifies the number of blocks on eachlogical track of the UNIX disk. If <blksPerTrack> is zero, the count ofblocks per track will be set to <nBlocks> (i.e., the disk will be defined as having only one track). UNIX disk devices typically are specifiedwith only one track.The <nBlocks> parameter specifies the size of the disk, in blocks.If <nBlocks> is zero the size of the UNIX file specified, divided bythe number of bytes per block, is used.The formatting parameters (<bytesPerBlk>, <blksPerTrack>, and <nBlocks>)are critical only if the UNIX disk already contains the contentsof a disk created elsewhere. In that case, the formatting parameters must be identical to those used when the image was created. Otherwise, they may be any convenient number.Once the device has been created it still does not have a name orfile system associated with it. This must be done by using the file system's device initialization routine (e.g., dosFsDevInit()). ThedosFs and rt11Fs file systems also provide make-file-system routines(dosFsMkfs() and rt11FsMkfs()), which may be used to associate a nameand file system with the block device and initialize that file systemon the device using default configuration parameters.The unixDiskDevCreate() call returns a pointer to a block devicestructure (BLK_DEV). This structure contains fields that describe the physical properties of a disk device and specify the addresses of routines within the UNIX disk driver.The BLK_DEV structure address must be passed to the desired file system (dosFs, rt11Fs, or rawFs) during 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.As an example, to create a 200KB disk, 512-byte blocks, and only one track,the proper call would be:.CS BLK_DEV *pBlkDev; pBlkDev = unixDiskDevCreate ("/tmp/filesys1", 512, 400, 400, 0);.CEThis will attach the UNIX file /tmp/filesys1 as a block device.A convenience routine, unixDiskInit(), is provided to do theunixDiskDevCreate() followed by either a dosFsMkFs() or dosFsDevInit(),whichever is appropriate. The format of this call is:.CS BLK_DEV *unixDiskInit ( char * unixFile, /@ name of the UNIX file to use @/ char * volName, /@ name of the dosFs volume to use @/ int nBytes /@ number of bytes in dosFs volume @/ ).CEThis call will create the UNIX disk if required.IOCTLOnly the FIODISKFORMAT request is supported; all other ioctl requestsreturn an error, and set the task's errno to S_ioLib_UNKNOWN_REQUEST.SEE ALSO:dosFsDevInit(), dosFsMkfs(), rt11FsDevInit(), rt11FsMkfs(), rawFsDevInit(),.pG "I/O System, Local File Systems"LINTLIBRARY*/#include "vxWorks.h"#include "blkIo.h"#include "ioLib.h"#include "iosLib.h"#include "memLib.h"#include "errno.h"/* #include "stdio.h" */#include "dosFsLib.h"#include "stdlib.h"/* USED ONLY WITH SIMULATOR */#if (CPU_FAMILY==SIMSPARCSUNOS || CPU_FAMILY==SIMHPPA || CPU_FAMILY==SIMSPARCSOLARIS)#include "simLib.h"#include "u_Lib.h"extern int printErr ();int unixRWFlag = O_RDWR;int unixRWMode = 0;int unixCRFlag = O_RDWR | O_CREAT; /* 514 */int unixCRMode = 0644;#define DEFAULT_SEC_SIZE 512#define DEFAULT_DISK_SIZE (1024*1024)typedef struct /* UNIXDISK_DEV - UNIX disk device descriptor */ { BLK_DEV unixDiskBlkDev; /* generic block device structure */ int unixFd; /* UNIX file descriptor */ } UNIXDISK_DEV;/* forward declarations */LOCAL STATUS unixDiskIoctl ();LOCAL STATUS unixDiskBlkRd ();LOCAL STATUS unixDiskBlkWrt ();/********************************************************************************* unixDrv - install UNIX disk driver** Used in usrConfig.c to cause the UNIX disk driver to be linked in* when building VxWorks. Otherwise, it is not necessary to call this* routine before using the UNIX disk driver.** This routine is only applicable to VxSim for Solaris and VxSim for HP.** RETURNS: OK (always).*/STATUS unixDrv (void) { return (OK); }/********************************************************************************* unixDiskDevCreate - create a UNIX disk device** This routine creates a UNIX disk device.** The <unixFile> parameter specifies the name of the UNIX file to use* for the disk device.* * The <bytesPerBlk> parameter specifies the size of each logical block* on the disk. If <bytesPerBlk> is zero, 512 is the default.* * The <blksPerTrack> parameter specifies the number of blocks on each* logical track of the 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* as the size of the UNIX disk divided by the number of bytes per block.* * This routine is only applicable to VxSim for Solaris and VxSim for HP.** RETURNS: A pointer to block device (BLK_DEV) structure,* or NULL, if unable to open the UNIX disk.*/BLK_DEV *unixDiskDevCreate ( char *unixFile, /* name of the UNIX file */ int bytesPerBlk, /* number of bytes per block */ int blksPerTrack, /* number of blocks per track */ int nBlocks /* number of blocks on this device */ ) { FAST UNIXDISK_DEV *pUnixDiskDev; /* ptr to created UNIXDISK_DEV struct */ FAST BLK_DEV *pBlkDev; /* ptr to BLK_DEV struct in UNIXDISK_DEV */ int fd; /* Set up defaults for any values not specified */ if (bytesPerBlk == 0) bytesPerBlk = DEFAULT_SEC_SIZE; if ((fd = u_open (unixFile, ARCHCVTFLAGS(unixRWFlag), unixRWMode)) < 0) { printErr ("unixDiskDevCreate: Could not open %s read/write\n", unixFile); return (NULL); } if (nBlocks == 0) { struct unix_stat buf; if (u_fstat (fd, (char*)&buf) < 0) { printErr ("unixDiskDevCreate: Could not stat %s\n", unixFile); u_close (fd); return (NULL); } nBlocks = (int) buf.st_size / bytesPerBlk; } if (blksPerTrack == 0) blksPerTrack = nBlocks; /* Allocate a UNIXDISK_DEV structure for device */ pUnixDiskDev = (UNIXDISK_DEV *) calloc (1, sizeof (UNIXDISK_DEV)); if (pUnixDiskDev == NULL) { u_close (fd); return (NULL); /* no memory */ }
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -