⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 rawfslib.c

📁 vxworks操作系统的文件系统部分原代码
💻 C
📖 第 1 页 / 共 4 页
字号:
** This routine closes the specified raw volume file descriptor.  Any* buffered data for the descriptor is written to the physical device.** If the file descriptor has been marked as obsolete (meaning the* volume was unmounted while the descriptor was open), the descriptor* is freed, but an error is returned.** RETURNS: OK, or ERROR.*/LOCAL STATUS rawFsClose    (    FAST RAW_FILE_DESC  *pRawFd         /* file descriptor pointer */    )    {    FAST STATUS	      status;    FAST RAW_VOL_DESC *pVd = pRawFd->pRawFdVd;					/* pointer to volume descriptor */    /* Take control of file descriptor */    semTake (pRawFd->rawFdSemId, WAIT_FOREVER); /* get ownership of fd */    /* If file descriptor is obsolete, free it but return error */    if (pRawFd->rawFdStatus == RAWFD_OBSOLETE)	{    	rawFsFdFree (pRawFd);			/* put fd on free list */	semGive (pRawFd->rawFdSemId);		/* release fd */	errnoSet (S_rawFsLib_FD_OBSOLETE);	return (ERROR);				/* volume was remounted */	}    semTake (pVd->rawVdSemId, WAIT_FOREVER); /* get ownership of vol */    /* Write out file descriptor buffer, if necessary */    status = rawFsFdFlush (pRawFd);    semGive (pVd->rawVdSemId);		/* release volume */    rawFsFdFree (pRawFd);			/* put fd on free list */    semGive (pRawFd->rawFdSemId);		/* release fd */    return (status);    }/********************************************************************************* rawFsDevInit - associate a block device with raw volume functions** This routine takes a block device created by a device driver and* defines it as a raw file system volume.  As a result, when high-level * I/O operations, such as open() and write(), are performed on the* device, the calls will be routed through rawFsLib.** This routine associates <pVolName> with a device and installs it in* the VxWorks I/O System's device table.  The driver number used when* the device is added to the table is that which was assigned to the* raw library during rawFsInit().  (The driver number is kept in* the global variable `rawFsDrvNum'.)** The pDevice is a CBIO_DEV_ID or BLK_DEV ptr and contains configuration* data describing the device and the addresses of routines which* will be called to access device. These routines* will not be called until they are required by subsequent I/O * operations.** INTERNAL* The semaphore in the device is given, so the device is available for* use immediately.** RETURNS: A pointer to the volume descriptor (RAW_VOL_DESC),* or NULL if there is an error.*/RAW_VOL_DESC *rawFsDevInit    (    char      * pVolName,       /* volume name to be used with iosDevAdd */    BLK_DEV   * pDevice         /* a pointer to a BLK_DEV or a CBIO_DEV_ID */    )    {    FAST RAW_VOL_DESC	*pVd;		/* pointer to new volume descriptor */    CBIO_DEV_ID	cbio = NULL;    /* init RAW FS, if not yet */        if (rawFsInit (0) == ERROR)	return (NULL);        if (ERROR == cbioDevVerify( (CBIO_DEV_ID) pDevice ))        {        /* attempt to handle BLK_DEV subDev */        cbio = cbioWrapBlkDev ( pDevice );        if( NULL != cbio )            {            /* SPR#71633, clear the errno set in cbioDevVerify() */            errno = 0;            }        }    else	{	cbio = (CBIO_DEV_ID) pDevice;	}    if ( NULL == cbio )	{	return (NULL);	}    /* Allocate a raw volume descriptor for device */    pVd = (RAW_VOL_DESC *) KHEAP_ALLOC (sizeof (RAW_VOL_DESC));    if (NULL == pVd) 	{	return (NULL);			/* no memory */	}    else	{        bzero ((char *)pVd, sizeof (RAW_VOL_DESC));	}    /* Add device to system device table */    if (iosDevAdd ((DEV_HDR *) pVd, pVolName, rawFsDrvNum) != OK)	{	KHEAP_FREE ((char *) pVd);	return (NULL);				/* can't add device */	}    /* Initialize volume descriptor */    pVd->rawVdCbio 	= cbio;    pVd->rawVdStatus	= ERROR;	/* have not been mounted yet */    pVd->rawVdState	= RAW_VD_READY_CHANGED;    /* Create volume locking semaphore (initially available) */    pVd->rawVdSemId = semMCreate (rawFsVolMutexOptions);    if (pVd->rawVdSemId == NULL)	{	KHEAP_FREE ((char *) pVd);	return (NULL);		/* could not create semaphore */	}    return (pVd);    }/********************************************************************************* rawFsFdFlush - initiate CBIO buffers flushing.** RETURNS: CBIO ioctl return code.*/LOCAL STATUS rawFsFdFlush    (    FAST RAW_FILE_DESC  *pRawFd         /* pointer to file descriptor */    )    {    /* device flush returns with ERROR, if device is unavailable */        return (cbioIoctl (    		pRawFd->pRawFdVd->rawVdCbio, CBIO_CACHE_FLUSH,     		(void*)(-1) ));    }/********************************************************************************* rawFsFdFree - free a file descriptor** This routine removes a raw device file descriptor from the active* Fd list and places it on the free Fd list.**/LOCAL void rawFsFdFree    (    FAST RAW_FILE_DESC  *pRawFd      /* pointer to file descriptor to free */    )    {    semTake (rawFsFdListSemId, WAIT_FOREVER);	/* take control of Fd lists */    pRawFd->rawFdStatus = RAWFD_AVAILABLE;    lstDelete (&rawFsFdActiveList, &pRawFd->rawFdNode);					/* remove Fd from active list */    lstAdd (&rawFsFdFreeList, &pRawFd->rawFdNode);						/* add Fd to free list */    semGive (rawFsFdListSemId);			/* release Fd lists */    }/********************************************************************************* rawFsFdGet - get an available file descriptor** This routine obtains a free raw volume file descriptor.** RETURNS: Pointer to file descriptor, or NULL if none available.*/LOCAL RAW_FILE_DESC *rawFsFdGet (void)    {    FAST RAW_FILE_DESC	*pRawFd;	/* ptr to newly acquired file descr */    semTake (rawFsFdListSemId, WAIT_FOREVER);	/* take control of Fd lists */    pRawFd = (RAW_FILE_DESC *) lstGet (&rawFsFdFreeList);						/* get a free Fd */    if (pRawFd != NULL)	{	pRawFd->rawFdStatus = RAWFD_IN_USE;	/* mark Fd as in-use */	lstAdd (&rawFsFdActiveList, (NODE *) pRawFd);						/* add to active list */	}    else    	errnoSet (S_rawFsLib_NO_FREE_FILE_DESCRIPTORS);						/* max files already open */    semGive (rawFsFdListSemId);			/* release Fd lists */    return (pRawFd);    }/********************************************************************************* rawFsFlush - write all modified volume structures to disk** This routine will write all buffered data for a volume to the physical* device.  It is called by issuing an ioctl() call with the FIOFLUSH or* FIOSYNC function codes.  It may be used periodically to provide enhanced* data integrity, or to prepare a volume for removal from the device.** RETURNS: OK, or ERROR if volume could not be sync'd.**/LOCAL STATUS rawFsFlush    (    FAST RAW_VOL_DESC   *pVd          /* pointer to volume descriptor */    )    {    FAST STATUS		status;		/* return status */    /* Check that volume is available */    semTake (pVd->rawVdSemId, WAIT_FOREVER);	/* get ownership of volume */    if (pVd->rawVdState != RAW_VD_MOUNTED)        {        semGive (pVd->rawVdSemId);		/* release volume */        return (ERROR);				/* cannot access volume */        }    /* Flush volume to disk */    status = rawFsVolFlush (pVd);    semGive (pVd->rawVdSemId);		/* release volume */    return (status);    }/********************************************************************************* rawFsInit - prepare to use the raw volume library** This routine initializes the raw volume library.  It must be called exactly* once, before any other routine in the library.  The argument specifies the* number of file descriptors that may be open at once.  This routine allocates* and sets up the necessary memory structures and initializes semaphores.** This routine also installs raw volume library routines in the VxWorks I/O* system driver table.  The driver number assigned to rawFsLib is placed in* the global variable `rawFsDrvNum'.  This number will later be associated* with system file descriptors opened to rawFs devices.** To enable this initialization, define INCLUDE_RAWFS in configAll.h;* rawFsInit() will then be called from the root task, usrRoot(), in usrConfig.c.** RETURNS: OK or ERROR.*/STATUS rawFsInit    (    int  maxFiles  /* max no. of simultaneously open files */    )    {    FAST RAW_FILE_DESC	*pRawFd;/* pointer to created file descriptor */    FAST int		ix;		/* index var */    if (rawFsDrvNum != ERROR)    	return (OK);	/* initiation already done */        maxFiles = (maxFiles <= 0)? RAWFS_DEF_MAX_FILES : maxFiles;        /* Install rawFsLib routines in I/O system driver table     *   Note that there is no delete routine, and that the     *   rawFsOpen routine is also used as the create function.     */    rawFsDrvNum = iosDrvInstall ((FUNCPTR) rawFsOpen, (FUNCPTR) NULL,			         (FUNCPTR) rawFsOpen, rawFsClose,			         rawFsRead, rawFsWrite, rawFsIoctl);    if (rawFsDrvNum == ERROR)	return (ERROR);				/* can't install as driver */    /* Create semaphore for locking access to file descriptor list */    rawFsFdListSemId = semMCreate (rawFsFdListMutexOptions);    if (rawFsFdListSemId == NULL)	return (ERROR);				/* can't create semaphore */    semTake (rawFsFdListSemId, WAIT_FOREVER);	/* take control of fd list */    /* Allocate memory for required number of file descriptors */    pRawFd = (RAW_FILE_DESC *) 			KHEAP_ALLOC ((UINT) maxFiles * sizeof (RAW_FILE_DESC));    if (NULL == pRawFd)	{	return (ERROR);				/* no memory */	}    else	{	bzero ((char *)pRawFd, ((UINT) maxFiles * sizeof (RAW_FILE_DESC)));	}    /* Create list containing required number of file descriptors */    rawFsMaxFiles = maxFiles;    for (ix = 0; ix < rawFsMaxFiles; ix++)	{	pRawFd->rawFdStatus = RAWFD_AVAILABLE;	/* Create semaphore for this fd (initially available) */    	pRawFd->rawFdSemId = semMCreate (rawFsFdMutexOptions);    	if (pRawFd->rawFdSemId == NULL)	    return ((int) NULL);		/* could not create semaphore */	/* Add file descriptor to free list */	lstAdd (&rawFsFdFreeList, &pRawFd->rawFdNode);	pRawFd++;				/* next Fd */	}    semGive (rawFsFdListSemId);			/* release Fd lists */    return (OK);    }/********************************************************************************* rawFsIoctl - perform a device-specific control function** This routine performs the following ioctl() functions:** .CS*    FIODISKINIT:   Initialize the disk volume.  This routine does not*                   format the disk, that must be done by the driver.*    FIOSEEK:       Sets the file's current byte position to*                   the position specified by arg.*    FIOWHERE:      Returns the current byte position in the file.*    FIOSYNC:	    Write all modified file descriptor buffers to device.*    FIOFLUSH:      Same as FIOSYNC.*    FIONREAD:      Return in arg the number of unread bytes.*    FIODISKCHANGE: Indicate media change.  See rawFsReadyChange().*    FIOUNMOUNT:    Unmount disk volume.  See rawFsVolUnmount().*    FIOGETFL:      Return in arg the file's open mode.* .CE** If the ioctl (<function>) is not one of the above, the device driver* ioctl() routine is called to perform the function.** If an ioctl() call fails, the task status (see errnoGet()) indicates* the nature of the error.** RETURNS: OK, or ERROR if function failed or unknown function, or* current byte pointer for FIOWHERE.*/LOCAL STATUS rawFsIoctl    (

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -