/* unixDrv.c - UNIX-file disk driver (VxSim for Solaris) */ /* * Copyright (c) 1984-1995,1997,1999,2000,2001,2003,2004,2006,2007 * Wind River Systems, Inc. * * The right to copy, distribute, modify or otherwise make use of this * software may be licensed only pursuant to the terms of an applicable * Wind River license agreement. */ /* modification history -------------------- 01y,30jul07,elp added includes. 01x,18jun07,elp renamed field to coding convention. 01w,24may07,elp added SMP support. 01v,25oct06,elp include vxsimHostLibP.h rather than vxsimHostLib.h 01u,07apr06,dgp doc: fix formatting of routine name & examples in library 01t,31aug04,jmp modified to not build this library on SIMLINUX, it is only kept on SIMSPARCSOLARIS for backward compatibility. 01s,04feb04,dbt Fixed documentation. 01r,23jun03,jeg reworked to use virtual disk APIs and documented as obsolete. 01q,16jun03,dbt Fixed previous changes 01p,18mar03,jeg improve error management ralative to host routine 01o,05mar03,jeg updated access to unix file definitions 01n,03feb03,jeg updated access to host specific routines. Code cleanup. 01m,04apr01,pfl doc update (SPR #63976) 01l,05dec00,jmp added SIMLINUX support. 01k,31jul00,jkf removal of RT-11 (rt11) file system, SPR#32821/31223 01j,16mar99,elg mention unixDrv is for Solaris and HP simulators (SPR 7719). 01i,11jul97,dgp doc: ad (VxSim) to title line 01h,09jan97,pr added ARCHCVTFLAGS for simsolaris 01g,30oct95,ism added support for simsolaris 01f,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. */ /* DESCRIPTION This driver emulates a VxWorks disk driver by using a virtual disk. The VxWorks disk appears under UNIX as a single file. The UNIX file name, and the size of the disk, may be specified during the unixDiskDevCreate() call. USER-CALLABLE ROUTINES The routine unixDrv() must be called to initialize the driver and the unixDiskDevCreate() routine is used to create devices. CREATING UNIX DISKS Before a UNIX disk can be used, it must be created. This is done with 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 @/ ) \ce The UNIX file must be pre-allocated separately. This can be done using the UNIX mkfile(8) command. Note that you have to create an appropriately sized file. For example, to create a UNIX file system that is used as a common floppy dosFs file system, you would issue the comand: \cs mkfile 1440k /tmp/floppy.dos \ce This will create space for a 1.44 Meg DOS floppy (1474560 bytes, or 2880 512-byte blocks). The parameter specifies the size of each logical block on the disk. If is zero, 512 is the default. The parameter specifies the number of blocks on each logical track of the UNIX disk. If is zero, the count of blocks per track will be set to (i.e., the disk will be defined as having only one track). UNIX disk devices typically are specified with only one track. The parameter specifies the size of the disk, in blocks. If is zero the size of the UNIX file specified, divided by the number of bytes per block, is used. The formatting parameters (, , and ) are critical only if the UNIX disk already contains the contents of 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 or file system associated with it. This must be done by using the file system's device initialization routine (e.g., dosFsDevInit()). The dosFs file systems also provide make-file-system routines (dosFsMkfs()), which may be used to associate a name and file system with the block device and initialize that file system on the device using default configuration parameters. The unixDiskDevCreate() 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 UNIX disk driver. The BLK_DEV structure address must be passed to the desired file system (dosFs, 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); \ce This will attach the UNIX file /tmp/filesys1 as a block device. A convenience routine, unixDiskInit(), is provided to do the unixDiskDevCreate() 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 @/ ) \ce This call will create the UNIX disk if required. IMPORTANT NOTE This library is obsolete, but is kept for backward compatibility and is now replaced by virtual disk library. But note that the virtual disk library is not able to use unix disk created with unixDiskDevCreate() API. SEE ALSO: dosFsDevInit(), dosFsMkfs(), rawFsDevInit(), */ #include #include #include #include #include #include #include #include #include /* USED ONLY WITH SOLARIS SIMULATOR */ #if (CPU_FAMILY==SIMSPARCSOLARIS) #define BLOCKSIZE 8192 /* default block size */ /* host file permissions : User : RW / Group : Read / Other : Read */ #define FILE_PERM S_IRUSR| S_IWUSR | S_IRGRP | S_IROTH /******************************************************************************* * * unixDrv - install UNIX disk driver * * This routine is to cause the UNIX disk driver to be linked in * when building VxWorks when INCLUDE_DOS_DISK component is included in VxWorks * image. Otherwise, it is not necessary to call this routine before using * the UNIX disk driver. * * This routine is only applicable to VxSim for Solaris. * * IMPORTANT NOTE * This routine is obsolete, but is kept for backward compatibility. * * RETURNS: OK (always). */ STATUS unixDrv (void) { return (OK); } /******************************************************************************* * * unixDiskDevCreate - create a UNIX disk device * * This routine creates a UNIX disk device. * * The parameter specifies the name of the UNIX file to use * for the disk device. * * The parameter specifies the size of each logical block * on the disk. If is zero, 512 is the default. * * The parameter specifies the number of blocks on each * logical track of the disk. If is zero, the count of * blocks per track is set to (i.e., the disk is defined * as having only one track). * * The parameter specifies the size of the disk, in blocks. * If 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. * * IMPORTANT NOTE * This routine is obsolete, but is kept for backward compatibility with previous * version. * * 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 */ ) { struct stat fileStat; /* host file stat */ /* check if the host file aready exist, if not the unix disk is not * created and a NULL value is returned. */ if (vxsimHostStat (unixFile, &fileStat) == ERROR) { printErr ("unixDiskDevCreate: Could not open %s read/write\n", unixFile); return (NULL); } /* Set up defaults for any values not specified */ if (bytesPerBlk == 0) bytesPerBlk = DEFAULT_SIZE; if (nBlocks == 0) { /* *if nBlocks parameters is null, it is calculated regarding the * host file size and bytesPerBlk parameter. */ nBlocks = fileStat.st_size / bytesPerBlk; } if (blksPerTrack == 0) blksPerTrack = nBlocks; return ((BLK_DEV *) virtualDiskOldCreate (unixFile, bytesPerBlk, blksPerTrack, nBlocks)); } /******************************************************************************* * * 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. * * IMPORTANT NOTE * This routine is obsolete, but is kept for backward compatibility with previous * version. * * RETURNS: N/A */ void unixDiskInit ( char * unixFile, /* UNIX file name */ char * volName, /* dosFs name */ int diskSize /* number of bytes */ ) { int fd; /* Unix file descriptor */ BOOL create; /* TRUE if a new Unix file have been created */ int dosFsStatus; /* DosFS creation status */ BLK_DEV * pBlkDev; /* created block device */ char * fileName; /* duplicate name in kernel (for host call) */ create = FALSE; if ((fileName = strdup (unixFile)) == NULL) { printErr ("unixDiskInit: not enough memory\n"); return; } if ((fd = vxsimHostOpen (fileName, O_RDWR, FILE_PERM)) < 0) { /* Unix file not available, it must be created */ printErr ("unixDiskInit: %s not found. Creating...", unixFile); if ((fd = vxsimHostOpen (unixFile, O_RDWR | O_CREAT, FILE_PERM)) < 0) { printErr ("permission denied\n"); goto done; } if (diskSize == 0) diskSize = DEFAULT_DISK_SIZE; /* * filled the created file with empty characters to get the appropriated * file size. */ if (vxsimHostFtruncate (fd, diskSize) != 0) { printErr ("unixDiskInit: Disk Write failed (disk full?)\n"); goto done; } create = TRUE; } vxsimHostClose (fd); /* create the block device associated with the created file */ pBlkDev = unixDiskDevCreate (unixFile, DEFAULT_SIZE, 0, 0); if (pBlkDev != NULL) { if (create) dosFsStatus = (dosFsMkfs (volName, pBlkDev) == NULL) ? ERROR : OK; else dosFsStatus = (dosFsDevInit (volName, pBlkDev, 0) == NULL) ? ERROR : OK; if (dosFsStatus == ERROR) { 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"); done: free (fileName); } #endif /* (CPU_FAMILY==SIMSPARCSOLARIS) */