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

📄 usrfslib.c

📁 VXWORKS源代码
💻 C
📖 第 1 页 / 共 4 页
字号:
/* usrFsLib.c - file system user interface subroutine library *//* Copyright 1984-2002 Wind River Systems, Inc. */#include "copyright_wrs.h"/*modification history--------------------01r,16jan02,chn  SPR#24332, add check to avoid copy() to a directory name dest01q,12dec01,jkf  SPR#72133, add FIOMOVE to dosFsLib, use it in mv()01p,17oct01,jkf  SPR#74904, function cleanup.01o,20sep01,jkf  SPR#69031, common code for both AE & 5.x.01n,15mar01,jkf  SPR#33973, copy not preserving time/date.01m,15mar01,jkf  SPR#33557, ls returning error on first invocation01l,29aug00,jgn  add const to function signatures (SPR #30492) +		 clean up coding standard violations01k,17mar00,dgp  modify attrib and xattrib synopsis comments for syngen                 processing01j,16mar00,jkf  removed reference to dosFsVolFormat() from diskInit().01i,26dec99,jkf  T3 KHEAP_ALLOC01h,31jul99,jkf  T2 merge, tidiness & spelling.01g,07dec98,lrn  fixed netDrv spurious error message (SPR#22554)01f,23nov98,vld  print '/' after directory name in long output01e,13jul98,lrn  fixed diskInit() to call dosFsVolFormat() if open() fails01d,02jul98,lrn  corrected parameters for chkdsk()01c,28jun98,lrn  added recursive xcopy, xdelete, added wildcards to                 cp(), mv(), added attrib and xattrib(), added help01b,23jun98,lrn  rewrite ls, add more utils01a,19feb98,vld	 initial version, derived from usrLib.c*//*DESCRIPTIONThis library provides user-level utilities for managing file systems.These utilities may be used from Tornado Shell, the Target Shell or froman application.USAGE FROM TORNADOSome of the functions in this library have counterparts of the samenames built into the Tornado Shell (aka Windsh). The built-in functionsperform similar functions on the Tornado host computer's I/O systems.Hence if one of such functions needs to be executed in order to performany operation on the Target's I/O system, it must be preceded with an'@' sign, e.g.:.CE-> @ls "/sd0".CEwill list the directory of a disk named "/sd0" on the target, wile.CS-> ls "/tmp".CEwill list the contents of the "/tmp" directory on the host.The target I/O system and the Tornado Shell running on the host, eachhave their own notion of current directory, which are not related,hence.CS-> pwd.CEwill display the Tornado Shell current directory on the host filesystem, while.CS-> @pwd.CEwill display the target's current directory on the target's console.WILDCARDSSome of the functions herein support wildcard characters in argumentstrings where file or directory names are expected. The wildcards arelimited to "*" which matches zero or more characters and "?" whichmatches any single characters. Files or directories with names beginningwith a "." are not normally matched with the "*" wildcard.DIRECTORY LISTINGDirectory listing is implemented in one function dirList(), which can beaccessed using one of these four front-end functions:.iP ls()produces a short list of files.iP lsr()is like ls() but ascends into subdirectories.iP ll()produces a detailed list of files, with file size, modification dateattributes etc..iP llr()is like ll() but also ascends into subdirectoriesAll of the directory listing functions accept a name of a directory or asingle file to list, or a name which contain wildcards, which willresult in listing of all objects that match the wildcard stringprovided.SEE ALSOioLib, dosFsLib, netDrv, nfsLib,.pG "Target Shell".pG "Tornado Users's Guide"*//* includes */#include <vxWorks.h>#include <fioLib.h>#include "ctype.h"#include "stdio.h"#include "ioLib.h"#include "memLib.h"#include "string.h"#include "ftpLib.h"#include "usrLib.h"#include "dirent.h"#include "sys/stat.h"#include "errnoLib.h"#include "iosLib.h"#include "taskLib.h"#include "logLib.h"#include "netDrv.h"#include "time.h"#include "nfsLib.h"#include "pathLib.h"#include "private/dosFsVerP.h"#include "dosFsLib.h"#include "stat.h"#include "utime.h"/* types */LOCAL int mvFile (const char *oldname, const char *newname);/* defines *//******************************************************************************** usrPathCat - concatenate directory path to filename.** This routine constructs a valid filename from a directory path* and a filename.* The resultant path name is put into <result>.* No arcane rules are used to derive the concatenated result.** RETURNS: N/A.*/LOCAL void usrPathCat    (    const char *	dirName,    const char *	fileName,    char *		result    )    {    *result = EOS ;    if(dirName[0] != EOS && dirName != NULL && strcmp(dirName,".") != 0)	{	strcpy( result, dirName );	strcat( result,  "/" );	}    strcat( result, fileName );    } /* usrPathCat() *//********************************************************************************* cd - change the default directory** .iP NOTE* This is a target resident function, which manipulates the target I/O* system. It must be preceded with the* '@' letter if executed from the Tornado Shell (windsh), which has a* built-in command of the same name that operates on the Host's I/O* system.** This command sets the default directory to <name>.  The default directory* is a device name, optionally followed by a directory local to that* device.** To change to a different directory, specify one of the following:* .iP "" 4* an entire path name with a device name, possibly followed by a directory* name.  The entire path name will be changed.* .iP* a directory name starting with a `~' or `/' or `$'.  The directory part* of the path, immediately after the device name, will be replaced with the new* directory name.* .iP* a directory name to be appended to the current default directory.* The directory name will be appended to the current default directory.* .LP** An instance of ".." indicates one level up in the directory tree.** Note that when accessing a remote file system via RSH or FTP, the* VxWorks network device must already have been created using* netDevCreate().** WARNING* The cd() command does very little checking that <name> represents a valid* path.  If the path is invalid, cd() may return OK, but subsequent* calls that depend on the default path will fail.** EXAMPLES* The following example changes the directory to device `/fd0/':* .CS*     -> cd "/fd0/"* .CE* This example changes the directory to device `wrs:' with the local* directory `~leslie/target':* .CS*     -> cd "wrs:~leslie/target"* .CE* After the previous command, the following changes the directory to* `wrs:~leslie/target/config':* .CS*     -> cd "config"* .CE* After the previous command, the following changes the directory to* `wrs:~leslie/target/demo':* .CS*     -> cd "../demo"* .CE* After the previous command, the following changes the directory to* `wrs:/etc'.* .CS*     -> cd "/etc"* .CE* Note that `~' can be used only on network devices (RSH or FTP).** RETURNS: OK or ERROR.** SEE ALSO: pwd(),* .pG "Target Shell"*/STATUS cd    (    const char *	name		/* new directory name */    )    {    if (ioDefPathCat ((char *)name) != OK)	{	printf ("cd: error = %#x.\n", errno);	return (ERROR);	}    return (OK);    }/******************************************************************************** dirNameWildcard - check if file or dir name contains wildcards** RETURNS: TRUE if "*" or "?" are contained in the <name> string*/LOCAL BOOL dirNameWildcard    (    const char *	name    )    {    if (index(name, '*') != NULL ||	index(name, '?') != NULL)	return TRUE ;    else	return FALSE ;    }/******************************************************************************** nameIsDir - check if name is a directory** RETURNS: TRUE if the name is an existing directory*/LOCAL BOOL nameIsDir    (    const char *	name    )    {    struct stat fStat ;    if ((name == NULL) || (*name == EOS))	return FALSE ;    /* if it does not exist, it ain't a directory */    if (stat ((char *) name, &fStat) == ERROR)        {	errno = OK ;    	return FALSE;        }    if (S_ISDIR (fStat.st_mode))        {        return TRUE;        }    return FALSE ;    }/********************************************************************************* pwd - print the current default directory** This command displays the current working device/directory.** .iP NOTE* This is a target resident function, which manipulates the target I/O* system. It must be preceded with the* '@' letter if executed from the Tornado Shell (windsh), which has a* built-in command of the same name that operates on the Host's I/O* system.** RETURNS: N/A** SEE ALSO: cd(),* .pG "Target Shell,"* windsh,* .tG "Shell"*/void pwd (void)    {    char name [MAX_FILENAME_LENGTH];    ioDefPathGet (name);    printf ("%s\n", name);    }/********************************************************************************* mkdir - make a directory** This command creates a new directory in a hierarchical file system.* The <dirName> string specifies the name to be used for the* new directory, and can be either a full or relative pathname.** This call is supported by the VxWorks NFS and dosFs file systems.** RETURNS: OK, or ERROR if the directory cannot be created.** SEE ALSO: rmdir(),* .pG "Target Shell"*/STATUS mkdir    (    const char *	dirName		/* directory name */    )    {    int fd;    if ((fd = open (dirName, O_RDWR | O_CREAT, FSTAT_DIR | DEFAULT_DIR_PERM))	 == ERROR)	{	return (ERROR);	}    return (close (fd));    }/********************************************************************************* rmdir - remove a directory** This command removes an existing directory from a hierarchical file* system.  The <dirName> string specifies the name of the directory to* be removed, and may be either a full or relative pathname.** This call is supported by the VxWorks NFS and dosFs file systems.** RETURNS: OK, or ERROR if the directory cannot be removed.** SEE ALSO: mkdir(),* .pG "Target Shell"*/STATUS rmdir    (    const char *	dirName		/* name of directory to remove */    )    {    return (remove (dirName));    }/********************************************************************************* rm - remove a file** This command is provided for UNIX similarity.  It simply calls remove().** RETURNS: OK, or ERROR if the file cannot be removed.** SEE ALSO: remove(),* .pG "Target Shell"*/STATUS rm    (    const char *	fileName	/* name of file to remove */    )    {    return (remove (fileName));    }/********************************************************************************* copyStreams - copy from/to specified streams** This command copies from the stream identified by <inFd> to the stream* identified by <outFd> until an end of file is reached in <inFd>.* This command is used by copy().** INTERNAL* The size of an array buffer can have a dramatic impact on the throughput* achieved by the copyStreams() routine.  The default is 1 Kbyte, but this* can be increased as long as the calling task (usually the VxWorks shell)* has ample stack space.  Alternately, copyStreams() can be modified to use a* static buffer, as long as the routine is guaranteed not to be called in* the context of more than one task simultaneously.** RETURNS: OK, or ERROR if there is an error reading from <inFd> or writing* to <outFd>.** SEE ALSO: copy(),* .pG "Target Shell"** INTERNAL* Note use of printErr since printf's would probably go to the output stream* outFd!*/STATUS copyStreams    (    int inFd,		/* file descriptor of stream to copy from */    int outFd 		/* file descriptor of stream to copy to */    )    {    char * buffer;    int totalBytes = 0;    int nbytes;    size_t	dSize;    /* update file size */    if (ioctl( inFd, FIONREAD, (int)&dSize ) == ERROR)    	dSize = 1024;    /* transferring buffer */    dSize = min( 0x10000, dSize );    buffer = KHEAP_ALLOC( dSize );    if (buffer == NULL)    	return ERROR;    while ((nbytes = fioRead (inFd, buffer, dSize)) > 0)	{	if (write (outFd, buffer, nbytes) != nbytes)	    {	    printErr ("copy: error writing file. errno %p\n", (void *)errno);     	    KHEAP_FREE( buffer );	    return (ERROR);	    }	totalBytes += nbytes;    	}    KHEAP_FREE( buffer );    if (nbytes < 0)	{	printErr ("copy: error reading file after copying %d bytes.\n",		 totalBytes);	return (ERROR);	}    printf("Copy OK: %u bytes copied\n", totalBytes );    return (OK);    }/********************************************************************************* copy - copy <in> (or stdin) to <out> (or stdout)** This command copies from the input file to the output file, until an* end-of-file is reached.** EXAMPLES:* The following example displays the file `dog', found on the default file* device:* .CS*     -> copy <dog* .CE* This example copies from the console to the file `dog', on device `/ct0/',* until an EOF (default ^D) is typed:* .CS*     -> copy >/ct0/dog* .CE* This example copies the file `dog', found on the default file device, to* device `/ct0/':* .CS*     -> copy <dog >/ct0/dog* .CE* This example makes a conventional copy from the file named `file1' to the file* named `file2':* .CS*     -> copy "file1", "file2"* .CE* Remember that standard input and output are global; therefore, spawning* the first three constructs will not work as expected.** RETURNS:* OK, or* ERROR if <in> or <out> cannot be opened/created, or if there is an* error copying from <in> to <out>.** SEE ALSO: copyStreams(), tyEOFSet(), cp(), xcopy()* .pG "Target Shell"

⌨️ 快捷键说明

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