?? unixdrv.c
字號:
/* Initialize BLK_DEV structure (in UNIXDISK_DEV) */ pBlkDev = &pUnixDiskDev->unixDiskBlkDev; pBlkDev->bd_nBlocks = nBlocks; /* number of blocks */ pBlkDev->bd_bytesPerBlk = bytesPerBlk; /* bytes per block */ pBlkDev->bd_blksPerTrack = blksPerTrack; /* blocks per track */ pBlkDev->bd_nHeads = 1; /* one "head" */ pBlkDev->bd_removable = FALSE; /* not removable */ pBlkDev->bd_retry = 1; /* retry count */ pBlkDev->bd_mode = UPDATE; /* initial mode for device */ pBlkDev->bd_readyChanged = TRUE; /* new ready status */ pBlkDev->bd_blkRd = unixDiskBlkRd; /* read block function */ pBlkDev->bd_blkWrt = unixDiskBlkWrt; /* write block function */ pBlkDev->bd_ioctl = unixDiskIoctl; /* ioctl function */ pBlkDev->bd_reset = NULL; /* no reset function */ pBlkDev->bd_statusChk = NULL; /* no check-status function */ /* Initialize remainder of device struct */ pUnixDiskDev->unixFd = fd; return (&pUnixDiskDev->unixDiskBlkDev); }/********************************************************************************* unixDiskIoctl - do device specific control function** This routine is called when the file system cannot handle an ioctl* function.** The FIODISKFORMAT function always returns OK, since a UNIX file does* not require formatting. All other requests return ERROR.** RETURNS: OK or ERROR.*/LOCAL STATUS unixDiskIoctl ( UNIXDISK_DEV *pUnixDiskDev, /* device structure pointer */ int function, /* function code */ int arg /* some argument */ ) { FAST int status; /* returned status value */ switch (function) { case FIODISKFORMAT: status = OK; break; default: status = ERROR; errno = S_ioLib_UNKNOWN_REQUEST; break; } return (status); }/********************************************************************************* unixDiskBlkRd - read one or more blocks from a unix file disk volume** This routine reads one or more blocks from the specified volume,* starting with the specified block number. The byte offset is* calculated and the UNIX disk data is copied to the specified buffer.** RETURNS: OK for success and ERROR for bad block.*/LOCAL STATUS unixDiskBlkRd ( UNIXDISK_DEV *pUnixDiskDev, /* pointer to device desriptor */ int startBlk, /* starting block number to read */ int numBlks, /* number of blocks to read */ char *pBuffer /* pointer to buffer to receive data */ ) { long offset; int numBytes, ret; FAST int bytesPerBlk; /* number of bytes per block */ bytesPerBlk = pUnixDiskDev->unixDiskBlkDev.bd_bytesPerBlk; /* Add in the block offset */ offset = startBlk*bytesPerBlk; if (u_lseek (pUnixDiskDev->unixFd, offset, 0) != offset) { printErr ("unixDiskBlkRd: lseek to offset %d failed\n", offset); return (ERROR); } numBytes = bytesPerBlk * numBlks; /* Read the block(s) */ if ((ret = u_read (pUnixDiskDev->unixFd, pBuffer, numBytes)) != numBytes) { printErr ("unixDiskBlkRd: failed to read %d bytes\n", numBytes); return (ERROR); } return (OK); }/********************************************************************************* unixDiskBlkWrt - write one or more blocks to a unix disk volume** This routine writes one or more blocks to the specified volume,* starting with the specified block number. The byte offset is* calculated and the buffer data is copied to the unix disk.** RETURNS: OK for success and ERROR for bad block.*/LOCAL STATUS unixDiskBlkWrt ( UNIXDISK_DEV *pUnixDiskDev, /* pointer to device desriptor */ int startBlk, /* starting block number to write */ int numBlks, /* number of blocks to write */ char *pBuffer /* pointer to buffer of data to write */ ) { long offset; int numBytes, ret; FAST int bytesPerBlk; /* number of bytes per block */ bytesPerBlk = pUnixDiskDev->unixDiskBlkDev.bd_bytesPerBlk; /* Add in the block offset */ offset = startBlk * bytesPerBlk; if (u_lseek (pUnixDiskDev->unixFd, offset, 0) != offset) { printErr ("unixDiskBlkWrt: lseek to offset %d failed\n", offset); return (ERROR); } numBytes = bytesPerBlk * numBlks; if ((ret = u_write (pUnixDiskDev->unixFd, pBuffer, numBytes)) != numBytes) { printErr ("unixDiskBlkWrt: failed to write %d bytes\n", numBytes); return (ERROR); } return (OK); }/********************************************************************************* unixDiskInit - initialize a dosFs disk on top of UNIX** This routine provides some convenience for a user wanting to create* a UNIX disk-based dosFs file system under VxWorks. The user only* specifes the UNIX file to use, the dosFs volume name, and the* size of the volume in bytes, if the UNIX file needs to be created.** This routine is only applicable to VxSim for Solaris and VxSim for HP.** RETURNS: N/A*/void unixDiskInit ( char *unixFile, /* UNIX file name */ char *volName, /* dosFs name */ int diskSize /* number of bytes */ ) { int ix; int fd; int numEightKBlocks; int numHalfKBlocks; int create = 0; int stat; struct unix_stat buf; char *emptySpace; BLK_DEV *pBlkDev; if (u_stat (unixFile, (char*)&buf) < 0) { printErr ("unixDiskInit: %s not found. Creating...", unixFile); if ((fd = u_open (unixFile, ARCHCVTFLAGS(unixCRFlag), unixCRMode)) < 0) { printErr ("permission denied\n"); return; } if (diskSize == 0) diskSize = DEFAULT_DISK_SIZE;#define BLOCKSIZE 8192 emptySpace = calloc (1, BLOCKSIZE); numEightKBlocks = diskSize / BLOCKSIZE; numHalfKBlocks = (diskSize % BLOCKSIZE) / DEFAULT_SEC_SIZE; for (ix = 0; ix < numEightKBlocks; ix++) if (u_write (fd, emptySpace, BLOCKSIZE) < 0) { printErr ("Disk Write failed (disk full?)\n"); free (emptySpace); return; } for (ix = 0; ix < numHalfKBlocks; ix++) if (u_write (fd, emptySpace, DEFAULT_SEC_SIZE) < 0) { printErr ("Disk Write failed (disk full?)\n"); free (emptySpace); return; } printErr ("done\n"); u_close (fd); free (emptySpace); create = 1; } pBlkDev = unixDiskDevCreate (unixFile, DEFAULT_SEC_SIZE, 0, 0); if (pBlkDev != NULL) { if (create) stat = (dosFsMkfs (volName, pBlkDev) == NULL) ? -1 : 0; else stat = (dosFsDevInit (volName, pBlkDev, 0) == NULL) ? -1 : 0; if (stat == -1) { printErr ("unixDiskInit: could not init dosFs file system on %s\n", unixFile); } else { printErr ("unixDiskInit: dosFs file system %s as device %s\n", create ? "init'd" : "attached", volName); } } else printErr ("unixDiskInit: failed\n"); }#endif /* (CPU_FAMILY==SIMSPARCSUNOS || CPU_FAMILY==SIMHPPA) || CPU_FAMILY==SIMSPARCSOLARIS */
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -