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

📄 k_vxdemo.c

📁 vxworks demo 有问题写信给我
💻 C
📖 第 1 页 / 共 2 页
字号:
			   (int *)&td.td_entry, &stype, 			   N_EXT | N_TEXT, N_EXT | N_TEXT);    taskEntryVars.taskMain->length     = strlen (tMain);    taskEntryVars.taskPriority     	= td.td_priority;    switch (td.td_status)	{	case WIND_READY:	    taskEntryVars.taskStatus   = D_taskStatus_task_ready;	    break;	    	case WIND_SUSPEND:	    taskEntryVars.taskStatus   = D_taskStatus_task_suspended;	    break;	case WIND_PEND:	case WIND_DELAY:	    taskEntryVars.taskStatus   = D_taskStatus_task_delay;	    break;	case WIND_DEAD:	    taskEntryVars.taskStatus   = D_taskStatus_task_deleted;	}    taskEntryVars.taskOptions      	 = td.td_options;    taskEntryVars.taskStackPtr     	 = (unsigned long) td.td_sp;    taskEntryVars.taskStackBase    	 = (unsigned long) td.td_pStackBase;    taskEntryVars.taskStackPos     	 = (unsigned long) td.td_sp;    taskEntryVars.taskStackEnd     	 = (unsigned long) td.td_pStackEnd;    taskEntryVars.taskStackSize    	 = td.td_stackSize;    taskEntryVars.taskStackSizeUsage     = td.td_stackCurrent;    taskEntryVars.taskStackMaxUsed 	 = td.td_stackHigh;    taskEntryVars.taskStackFree    	 = td.td_stackMargin;    taskEntryVars.taskErrorStatus  	 = td.td_errorStatus;    SET_ALL_VALID(taskEntryVars.valid);    return (&taskEntryVars);            /* Ptr to task entry information */    }/********************************************************************************* k_taskEntry_set -  Create or deletes a task, options & state can be changed.** This routine allows for manipulation of tasks.  Tasks can be created or* deleted.  Tasks state and options can also be changed.** RETURNS: NO_ERROR if successful otherwise GEN_ERROR* * SEE ALSO: symFindByName, taskSpawn, taskDelete, taskOptionsSet, taskResume,*	    taskIsSuspended, taskSuspend, and taskPrioritySet.*/int k_taskEntry_set     (    taskEntry_t * ptaskEntry,       /* Ptr to table Entry */    ContextInfo * contextInfo,    int           reqState          /*  Request to lower layer (INDEX) */    )    {    char 	* pentryRoutine;     SYM_TYPE      stype;    int           tOptions;    char   	  tString [DISPLAY_STR_SZ];   /* Temporary String Variable */    /*      *  Entries that have a taskId of Zero are used to spawn new tasks.  Non     *  zero ids are used to change a task status, options, or to delete it.     */    if (ptaskEntry->taskId == 0)	{	if (reqState != ADD_MODIFY)	    return (GEN_ERROR);	/* Verify that the entry point specified exists in the system. */	(void) strcpy (tString, "_");        (void) strncat (tString, (char *)ptaskEntry->taskMain->octet_ptr,                (int) ptaskEntry->taskMain->length);        tString [ptaskEntry->taskMain->length + 1] = '\0';	if (symFindByName (sysSymTbl, tString, &pentryRoutine, &stype) == ERROR)	    return (GEN_ERROR);	          (void) strncpy (tString, (char *)ptaskEntry->taskName->octet_ptr,                (int) ptaskEntry->taskName->length);        tString [ptaskEntry->taskName->length] = '\0';	if (taskSpawn (tString, ptaskEntry->taskPriority,		       ptaskEntry->taskOptions, ptaskEntry->taskStackSize,		       (FUNCPTR) pentryRoutine, 		       0, 0, 0, 0, 0, 0, 0, 0, 0, 0) == ERROR)	    return (GEN_ERROR);	}				/* TaskId == 0 */    else	{	if (reqState == ADD_MODIFY)	    {	    /* Check if the PRIORITY of the task is to be changed */	    if (VALID(I_taskPriority, ptaskEntry->valid)) 		{		if (taskPrioritySet (ptaskEntry->taskId, 				     ptaskEntry->taskPriority) == ERROR)		    return (GEN_ERROR);		}	    /* Check if the STATUS of the task is to be changed */	    if (VALID(I_taskStatus, ptaskEntry->valid)) 		{		/* Check if the task is to be suspended */		if (ptaskEntry->taskStatus == D_taskStatus_task_suspended)		   {		   if (taskSuspend (ptaskEntry->taskId) == ERROR)		       return (GEN_ERROR); /* Task Doesn't exits */		   }		else		   {		   /* Check if the task is to be made ready */		    if (ptaskEntry->taskStatus == D_taskStatus_task_ready)			{			if (taskResume (ptaskEntry->taskId) == ERROR)			    return (GEN_ERROR); /* Task Doesn't exits */			}		    else			return (GEN_ERROR);   /* Invalid State Change Request */		   }		}	    /* 	     * Check if the OPTIONS of the task are to be changed.  The only	     * option that can be changed is VX_UNBREAKABLE ON/OFF.	     */	    if (VALID(I_taskOptions, ptaskEntry->valid)) 		{		if (taskOptionsGet (ptaskEntry->taskId, &tOptions) == ERROR)		    return (GEN_ERROR); /* Task Doesn't exits */		if ((tOptions & VX_UNBREAKABLE) == 0)		    {		    if (taskOptionsSet (ptaskEntry->taskId, (~tOptions), 					(tOptions | VX_UNBREAKABLE)) == ERROR)			return (GEN_ERROR); /* Task Doesn't exits */		    }		else		    {		    tOptions &= ~VX_UNBREAKABLE;		    if (taskOptionsSet (ptaskEntry->taskId, VX_UNBREAKABLE,					tOptions) == ERROR)			return (GEN_ERROR); /* Task Doesn't exits */		    }		}	    }	else	    {  /* DELETE a Task Request */	    if (taskDelete (ptaskEntry->taskId) == ERROR)		return (GEN_ERROR);	    }	}    return (NO_ERROR);    }/********************************************************************************* k_sysmemory_get -  Reads the statistics from the System Memory Partition.** The vxWorks system memory partion is access and the statistics are returned.** RETURNS: Pointer to a sysmemory structure.** SEE ALSO: memPartInfoGet*/sysmemory_t * k_sysmemory_get     (    int           reqId,         /* SNMP PDU ID used for catching */    ContextInfo * contextInfo,    int           reqVar         /* Request for EXACT or NEXT */    )    {    MEM_PART_STATS  memStats;    memPartInfoGet (memSysPartId, &memStats);    memVars.numBytesFree       = memStats.numBytesFree;    memVars.numBlocksFree      = memStats.numBlocksFree;    if (memVars.numBlocksFree > 0)	memVars.avgBlockSizeFree = memVars.numBytesFree / memVars.numBlocksFree;    memVars.maxBlockSizeFree   = memStats.maxBlockSizeFree;    memVars.numBytesAlloc      = memStats.numBytesAlloc;    memVars.numBlocksAlloc     = memStats.numBlocksAlloc;    memVars.avgBlockSizeAlloc  = memVars.numBytesAlloc / memVars.numBlocksAlloc;    SET_ALL_VALID(memVars.valid);    return (&memVars);    }/********************************************************************************* k_sysnfs_get -  The NFS group and user IDs are read.** The vxWorks efective user and group IDs are accesse and returned.** RETURNS: Pointer to the NFS structure.** SEE ALSO: nfsAuthUnixGet*/sysnfs_t * k_sysnfs_get     (    int            reqId,         /* SNMP PDU ID used for catching */    ContextInfo  * contextInfo,    int            reqVar         /* Request for EXACT or NEXT */    )    {    char machname [AUTH_UNIX_FIELD_LEN];/* host name where client is */    int uid;                            /* client's UNIX effective uid */    int gid;                            /* client's current group ID */    int len;                            /* element length of aup_gids */    int aup_gids [MAX_GRPS];    nfsAuthUnixGet (machname, &uid, &gid, &len, aup_gids);	    nfsVars.nfsUserId  = uid;    nfsVars.nfsGroupId = gid;    SET_ALL_VALID(nfsVars.valid);    return (&nfsVars);    }/********************************************************************************* k_sysnfs_set -  Change the NFS user ID or the NFS group ID.** The NFS user ID or NFS group ID is changed. ** RETURNS: NO_ERROR, This is because nfsAuthUnixSet returns a void.** SEE ALSO: nfsAuthUnixSet.*/int k_sysnfs_set     (    sysnfs_t    * pnfsVars,         /* Ptr to nfs Variables */    ContextInfo * contextInfo,    int           reqState          /*  Request */    )    {    char machname [AUTH_UNIX_FIELD_LEN];/* host name where client is */    int uid;                            /* client's UNIX effective uid */    int gid;                            /* client's current group ID */    int len;                            /* element length of aup_gids */    int aup_gids [MAX_GRPS];    nfsAuthUnixGet (machname, &uid, &gid, &len, aup_gids);    if (VALID(I_nfsUserId, pnfsVars->valid))	uid = pnfsVars->nfsUserId;    if (VALID(I_nfsGroupId, pnfsVars->valid))	gid = pnfsVars->nfsGroupId;    nfsAuthUnixSet (machname, uid, gid, len, aup_gids);    return (NO_ERROR);    }/********************************************************************************* k_nfsEntry_get -  Read the information of an NFS Device in the system.** This routine allows for the NFS local file system name, remote file system* name etc, to be retrived from vxWorks.** RETURNS: A pointer to an nfsEntry structure or NULL if not found.* * SEE ALSO: nfsDevListGet, hostGetByName, */nfsEntry_t * k_nfsEntry_get     (    int            reqId,         /* SNMP PDU ID used for catching */    ContextInfo  * contextInfo,    int            reqVar,    int            searchType,    /* Request for EXACT or NEXT */    long  	   entryIndex    )    {    int          ix;		 /* Generic Index */    NFS_DEV_INFO nfsDev;    /*  Collect information of all the NFS devices currently mounted.  */    numMounted = nfsDevListGet (nfsHandles, MAXNFS);    if (numMounted <=  0)	return ((nfsEntry_t *)NULL);	/* No NFS devices Mounted */    /* Sort NFS Table Entries */    qsort ((void *) nfsHandles, numMounted, sizeof (long), intComp);    if (searchType == NEXT)	{	/* Find the NFS Index greater than the one passed */		for (ix = 0 ; ix < numMounted ; ix++)	    {		if ((nfsHandles [ix] > entryIndex) &&    		    (nfsDevInfoGet (nfsHandles [ix], &nfsDev) == OK))		    break;	    }	/* Check for END of table condition */	if (ix >= numMounted)	    return ((nfsEntry_t *)NULL);	entryIndex = nfsHandles [ix];	/* Entry Index Found */	}    else	{	/* Get Device information for the specified Index */	if (nfsDevInfoGet (entryIndex, &nfsDev) == ERROR)	    return ((nfsEntry_t *)NULL);	}    /* Fill the device information structure */    nfsEntryVars.nfsIndex 	= entryIndex; /* Fix Index for 1 - N */    						 /* File System Mounted */    nfsEntryVars.nfsState 	= D_nfsState_nfs_mounted;    strcpy (HostName, nfsDev.hostName);    nfsEntryVars.nfsHostName->length  	= strlen (HostName);    /* Get Host IP Address */    nfsEntryVars.nfsHostIpAddr = hostGetByName (HostName);     strcpy (HostFileSysName, nfsDev.hostName);    strcat (HostFileSysName, ":");    strcat (HostFileSysName, nfsDev.remFileSys);    nfsEntryVars.nfsHostFileSysName->length      = strlen (HostFileSysName);    strcpy (LocalFileSysName, nfsDev.locFileSys);    nfsEntryVars.nfsLocalFileSysName->length     = strlen (LocalFileSysName);    SET_ALL_VALID(nfsEntryVars.valid);    return (&nfsEntryVars);    }/********************************************************************************* k_nfsEntry_set -  Alter, create or delete an NFS device in the system.** This routine allows for a NFS device in the system to be changed or deleted.* NFS devices can also be created by this routine.  When devices are created* if the host does not exists in the host table it will be added.   For hosts* which require a route, the route must be added through the MIB-II.** RETURNS: NO_ERROR if successfull otherwise GEN_ERROR.* * SEE ALSO: nfsDevInfoGet, nfsUnmount, nfsMount, inet_ntoa_b, and hostAdd,*/int k_nfsEntry_set     (    nfsEntry_t  * pnfsEntry,        /* Ptr to table Entry */    ContextInfo * contextInfo,    int           reqState          /*  Request to lower layer (INDEX) */    )    {    char             thName      [80];    char             tlocalFile  [80];    char             thostFile   [80];    char             tIpString   [40];    struct in_addr   hostIpAd;    NFS_DEV_INFO     nfsDev;    if (reqState == DELETE)	{			    /* Unmount the NFS Device */	if (nfsDevInfoGet (pnfsEntry->nfsIndex, &nfsDev) == ERROR)	    return (GEN_ERROR);	if (nfsUnmount (nfsDev.locFileSys) == ERROR)	    return (GEN_ERROR);	return (NO_ERROR);	}    /*     *  The ADD_MODIFY state is used to add NFS mount entries.     */    if (reqState == ADD_MODIFY)	{			    /* ADD_MODIFY Request */	if (pnfsEntry->nfsIndex != 0) /* Can't mod an existing entry */	    return (GEN_ERROR);	/* If the host does not exist in the host table add it */	strncpy (thName, pnfsEntry->nfsHostName->octet_ptr,		 pnfsEntry->nfsHostName->length);	thName [pnfsEntry->nfsHostName->length] = '\0';    	hostIpAd.s_addr = hostGetByName (thName);	if (hostIpAd.s_addr == ERROR)	    {	    inet_ntoa_b (pnfsEntry->nfsHostIpAddr, tIpString);	    if (hostAdd (thName, tIpString) == ERROR)		return (GEN_ERROR);	    }	strncpy (thostFile, pnfsEntry->nfsHostFileSysName->octet_ptr,		 pnfsEntry->nfsHostFileSysName->length);	thostFile [pnfsEntry->nfsHostFileSysName->length] = '\0';	strncpy (tlocalFile, pnfsEntry->nfsLocalFileSysName->octet_ptr,		 pnfsEntry->nfsLocalFileSysName->length);	tlocalFile [pnfsEntry->nfsLocalFileSysName->length] = '\0';	if (nfsMount (thName, thostFile, tlocalFile) == OK)	    return (NO_ERROR);	}    return (GEN_ERROR);    }

⌨️ 快捷键说明

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