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

📄 passfslib.c

📁 the vxworks system kernel souce packeg.there may be something you need .
💻 C
📖 第 1 页 / 共 2 页
字号:
/* passFsLib.c - pass-through (to UNIX) file system library (VxSim) *//* Copyright 1992-2001 Wind River Systems, Inc. */#include "copyright_wrs.h"/*modification history--------------------01r,06dec01,hbh  Fixed FIONREAD (SPR #22476 & #23615).01q,14mar99,jdi  doc: removed refs to config.h and/or configAll.h (SPR 25663).01p,17mar98,jmb  Merge my patch from HPSIM, 28oct97, fix bug in FIONREAD ioctl                 so that number of bytes remaining includes number of bytes                 in cache. (SPR 9628)01o,11jul97,dgp  doc: ad (VxSim) to title line01n,09jan97,pr   moved simsolaris macros and prototype in simLib.h 		 moved solarisCvtFlags function in simLib.c01n,23nov96,dvs  during merge fixed bug in ARCHCVTFLAGS for sunos,hppa 01m,12jul95,ism  added support for simsolaris01l,28mar95,kdl  changed to use POSIX date format during fstat().01k,31oct94,kdl  made conditional for SIMSPARCSUNOS and SIMHPPA.01j,24oct93,gae  documentation tweaks.01i,18aug93,gae  modified unix_stat for hp.01h,30jul93,gae  more doc touchups.01g,05jun93,gae  fixed doc about number of passFs's allowed.01f,23jan93,gae  removed u_printf; ANSIfied.01e,31aug92,gae  changed mkdir to use 755 per smeg.		 displayed unknown ioctl function code; ignored FIOSETOPTIONS.01d,10aug92,gae  set drvnum to usual 0 initially.01c,29jul92,gae  cleanup.01b,01jun92,gae  minor WRS revision.01a,04feb92,smeg written.*//*DESCRIPTIONThis module is only used with VxSim simulated versions of VxWorks.This library provides services for file-oriented device drivers to usethe UNIX file standard.  This module takes care of all the buffering,directory maintenance, and file system details that are necessary.In general, the routines in this library are not to be called directly by users, but rather by the VxWorks I/O System.INITIALIZING PASSFSLIBBefore any other routines in passFsLib can be used, the routine passFsInit()must be called to initialize this library.The passFsDevInit() routine associates a device name with the passFsLibfunctions.  The parameter expected by passFsDevInit() is a pointer toa name string, to be used to identify the volume/device.  This will be part ofthe pathname for I/O operations which operate on the device.  Thisname will appear in the I/O system device table, which may be displayedusing the iosDevShow() routine.As an example:.CS    passFsInit (1);    passFsDevInit ("host:");.CEAfter the passFsDevInit() call has been made, when passFsLib receives a request from the I/O system, it calls the UNIX I/O system to servicethe request.  Only one volume may be created.READING DIRECTORY ENTRIESDirectories on a passFs volume may be searched using the opendir(),readdir(), rewinddir(), and closedir() routines.  These calls allow thenames of files and sub-directories to be determined.To obtain more detailed information about a specific file, use the fstat()or stat() function.  Along with standard file information, the structureused by these routines also returns the file attribute byte from a passFsdirectory entry.FILE DATE AND TIMEUNIX file date and time are passed though to VxWorks.INCLUDE FILES: passFsLib.hSEE ALSOioLib, iosLib, dirLib, ramDrv*/#include "vxWorks.h"#include "ctype.h"#include "dirent.h"#include "iosLib.h"#include "lstLib.h"#include "semLib.h"#include "stat.h"#include "string.h"#include "stdlib.h"#include "passFsLib.h"/* ONLY USED FOR SIMULATOR */#if (CPU_FAMILY==SIMSPARCSUNOS || CPU_FAMILY==SIMHPPA || CPU_FAMILY==SIMSPARCSOLARIS)#include "simLib.h"#include "u_Lib.h"extern int printErr ();/* globals */int passFsUnixFilePerm = 0666;int passFsUnixDirPerm  = 0775;/* locals */LOCAL int passFsDrvNum;		/* driver number assigned to passFsLib */#define CACHE_SIZE 8192		/* size of read-ahead buffer *//* Volume descriptor */typedef struct          /* VOL_DESC */    {    DEV_HDR passDevHdr;	/* tracks the device: only one passFs device */    char passDevName [MAX_FILENAME_LENGTH];    } VOL_DESC;typedef struct    {    VOL_DESC *passVdptr;    UNIX_DIR *passDir;    char passName[MAX_FILENAME_LENGTH]; /* so we can do a UNIX stat() later */    int unixFd;    char *readCache;    int cacheOffset;    int cacheBytes;    } PASS_FILE_DESC;VOL_DESC *passVolume;	/* only 1 permitted */LOCAL PASS_FILE_DESC *passFsDirCreate ();LOCAL STATUS	     passFsDirMake ();LOCAL STATUS	     passFsIoctl ();LOCAL PASS_FILE_DESC *passFsOpen ();LOCAL int	     passFsRead ();LOCAL int	     passFsWrite ();/********************************************************************************* passFsClose - close a passFs file** This routine closes the specified passFs file.** The remainder of the file I/O buffer beyond the end of file is cleared out,* the buffer is flushed, and the directory is updated if necessary.** RETURNS: OK, or ERROR if directory couldn't be flushed or entry couldn't * be found.*/LOCAL STATUS passFsClose    (    PASS_FILE_DESC *pPassFd	/* passthough file descriptor */    )    {    int status = OK;    if ((int)pPassFd != -1)    	status = u_close (pPassFd->unixFd);    if (pPassFd->passDir != (UNIX_DIR *)0)    	status = u_closedir (pPassFd->passDir);    if (pPassFd->readCache != (char *)0)	free (pPassFd->readCache);    free (pPassFd);    return (status);    }/********************************************************************************* passFsCreate - create a UNIX file** RETURNS: passthrough file descriptor, or ERROR if error in create.*/LOCAL PASS_FILE_DESC *passFsCreate    (    VOL_DESC	*vdptr,		/* pointer to volume descriptor	*/    char	*fullName,	/* passFs path/filename string */    int		flags		/* file flags (READ/WRITE/UPDATE) */    )    {    PASS_FILE_DESC *pPassFd;    if ((pPassFd = (PASS_FILE_DESC *) calloc (1, sizeof (PASS_FILE_DESC)))						== (PASS_FILE_DESC *)0)	{	return ((PASS_FILE_DESC *)ERROR);	}		    pPassFd->unixFd = u_open (fullName, L_CREAT | ARCHCVTFLAGS(flags),	passFsUnixFilePerm);    if (pPassFd->unixFd == -1)	{	free (pPassFd);	return ((PASS_FILE_DESC *) ERROR);	}    strcpy (pPassFd->passName, fullName);    pPassFd->passDir     = (UNIX_DIR *)0;    pPassFd->readCache   = (char *)0;    pPassFd->cacheBytes  = 0;    pPassFd->cacheOffset = 0;    pPassFd->passVdptr   = vdptr;    return (pPassFd);    }/********************************************************************************* passFsDelete - delete a passFs file** This routine deletes the file <name> from the specified passFs volume.** RETURNS: OK, or ERROR if the file not found*/LOCAL STATUS passFsDelete    (    VOL_DESC	*vdptr,		/* pointer to volume descriptor	*/    char	*name		/* passFs path/filename */    )    {    /* XXX everything should relative to vdptr */    if (u_unlink (name) == -1)	{	/* try rmdir if unlink failed */	if (u_rmdir (name) == -1)	    return (ERROR);	}    return (OK);    }/********************************************************************************* passFsDevInit - associate a device with passFs file system functions** This routine associates the name <devName> with the file system and installs * it in the 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* passFs library during passFsInit().** RETURNS: A pointer to the volume descriptor, or NULL if there is an error.*/void *passFsDevInit    (    char *devName	/* device name */    )    {    /* Add device to system device table */    if (iosDevAdd (&passVolume->passDevHdr, devName, passFsDrvNum) != OK)	{	return (NULL);				/* can't add device */	}    strcpy (passVolume->passDevName, devName);    return ((void*)passVolume);    }/********************************************************************************* passFsDirCreate - create a passFs directory** This routine creates a new sub-directory on a passFs volume and* returns a open file descriptor for it.  It calls passFsDirMake to* actually create the directory; the remainder of this routine simply* sets up the file descriptor.** RETURNS: Pointer to passFs file descriptor (PASS_FILE_DESC),* or ERROR if error.*/LOCAL PASS_FILE_DESC *passFsDirCreate    (    VOL_DESC	*vdptr,	/* pointer to volume descriptor	*/    char *name          /* directory name */    )    {    PASS_FILE_DESC *pPassFd;    if (passFsDirMake (vdptr, name, TRUE) == ERROR)	return ((PASS_FILE_DESC *)ERROR);    if ((pPassFd = (PASS_FILE_DESC *) calloc (1, sizeof (PASS_FILE_DESC)))						== (PASS_FILE_DESC *)0)	{	return ((PASS_FILE_DESC *)ERROR);	}    strcpy (pPassFd->passName, name);    pPassFd->unixFd      = -1;    pPassFd->passDir     = (UNIX_DIR *)u_opendir (name);    pPassFd->readCache   = (char *)0;    pPassFd->cacheBytes  = 0;    pPassFd->cacheOffset = 0;    pPassFd->passVdptr   = vdptr;    if (pPassFd->passDir == (UNIX_DIR *)0)	{	free (pPassFd);	return ((PASS_FILE_DESC *)ERROR);	}    return (pPassFd);    }/********************************************************************************* passFsDirMake - make a passFs directory** This routine creates ("makes") a new passFs directory. ** Since this routine may be called as a result of either an open() call* or an ioctl() call, the level of filename expansion will vary.  A* boolean flag set by the calling routine (passFsOpen or passFsIoctl) indicates* whether the name has already been expanded (and the device name stripped).** RETURNS: status indicating success*/LOCAL STATUS passFsDirMake    (    VOL_DESC	*vdptr,		/* pointer to volume descriptor	*/    char	*name,		/* directory name */    BOOL	nameExpanded	/* TRUE if name was already expanded */    )    {    DEV_HDR		*pCurDev;	/* ptr to current dev hdr (ignored) */    char		fullName [MAX_FILENAME_LENGTH];	    /* Get full expanded dir name (no device name) unless already done */    if (nameExpanded == FALSE)	{    	if (ioFullFileNameGet (name, &pCurDev, fullName) != OK)	    return (ERROR);			/* cannot expand filename */	}    else	{	(void) strcpy (fullName, name);	}    if (u_mkdir (fullName, passFsUnixDirPerm) == -1)	return (ERROR);    return (OK);    }/********************************************************************************* passFsDirRead - read directory and return next filename** This routine is called via an ioctl() call with the FIOREADDIR function* code.  The "dirent" field in the passed directory descriptor (DIR) is* filled with the null-terminated name of the next file in the directory.** RETURNS: OK, or ERROR.*/LOCAL STATUS passFsDirRead    (    PASS_FILE_DESC  *pPassFd,	/* ptr to passFs file descriptor */    DIR		  *pDir		/* ptr to directory descriptor */    )    {    struct unix_dirent *dirent;    if (pPassFd->passDir == (UNIX_DIR *)0)    	pPassFd->passDir = (UNIX_DIR *)u_opendir (pPassFd->passName);    if (pPassFd->passDir == (UNIX_DIR *)0)	return (ERROR);    dirent = (struct unix_dirent *) u_readdir (pPassFd->passDir);    if (dirent == (struct unix_dirent *)0)	return (ERROR);    strcpy (pDir->dd_dirent.d_name, dirent->d_name);    return (OK);    }/********************************************************************************* passFsFileStatGet - get file status (directory entry data)** This routine is called via an ioctl() call, using the FIOFSTATGET* function code.  The passed stat structure is filled, using data* obtained from the directory entry which describes the file.** RETURNS: ERROR or OK*/LOCAL STATUS passFsFileStatGet    (    PASS_FILE_DESC	*pPassFd,	/* pointer to file descriptor */    struct stat	*pStat		/* structure to fill with data */    )    {    struct unix_stat unixbuf;    if (u_stat (pPassFd->passName, (char*)&unixbuf) == -1)	return (ERROR);    bzero ((char *) pStat, sizeof (struct stat)); /* zero out stat struct */    /* Fill stat structure */    pStat->st_dev     = (ULONG) passVolume;						/* device ID = DEV_HDR addr */    pStat->st_ino     = 0;			/* no file serial number */    pStat->st_nlink   = 1;			/* always only one link */    pStat->st_uid     = 0;			/* no user ID */    pStat->st_gid     = 0;			/* no group ID */    pStat->st_rdev    = 0;			/* no special device ID */    pStat->st_size    = unixbuf.st_size;	/* file size, in bytes */    pStat->st_atime   = 0;			/* no last-access time */    pStat->st_mtime   = 0;			/* no last-modified time */    pStat->st_ctime   = 0;			/* no last-change time */    pStat->st_attrib  = 0;			/* file attribute byte */    

⌨️ 快捷键说明

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