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

📄 usrfslib.c

📁 VXWORKS源代码
💻 C
📖 第 1 页 / 共 4 页
字号:
		status |= copy( fileName, destName );		}	    else if (strcmp(pDirEnt->d_name,"." ) &&		strcmp(pDirEnt->d_name,".." ))		{		printf("copying dir %s -> %s\n", fileName, destName );		mkdir(destName);		status |= xcopy( fileName, destName );		}	    }	} while (pDirEnt != NULL);		/* until end of dir */    status |= closedir (pDir);    return status ;    }/******************************************************************************** xdelete - delete a hierarchy of files with wildcards** <source> is a string containing a name of a directory, or a wildcard* or both which will cause this function to recursively remove all* files and subdirectories residing in that directory* and matching the wildcard pattern.* When a directory is encountered, all its contents are removed,* and then the directory itself is deleted.** CAVEAT* This function may call itself in accordance with the depth of the* source directory, and occupies approximately 520 bytes per stack* frame, meaning that to accommodate the maximum depth of subdirectories* which is 20, at least 10 Kbytes of stack space should be available to* avoid stack overflow.** RETURNS: OK or ERROR if any operation has failed.** SEE ALSO: checkStack(), cp(), copy(), xcopy(), tarLib*/STATUS xdelete    (    const char *source	/* source directory or wildcard name */    )    {    FAST DIR *pDir;		/* ptr to directory descriptor */    FAST struct dirent	*pDirEnt;	/* ptr to dirent */    STATUS status = OK ;    char * pattern = NULL ;    char * dirName = NULL ;    char  dir[MAX_FILENAME_LENGTH] ;    char  fileName[MAX_FILENAME_LENGTH] ;    strncpy( dir, source, MAX_FILENAME_LENGTH-1 );    pattern = rindex(dir, '/');    if ( pattern != NULL && pattern != dir && dirNameWildcard(pattern))	{	/* dir and pattern e.g. dir1/a*.c */	*pattern++ = EOS ;	dirName = dir ;	}    else if (dirNameWildcard( dir))	{	/* just pattern e.g. *.c or abc.? */	pattern = dir;	dirName = "." ;	}    else	{	pattern = NULL ;	dirName = dir ;	}    if (! nameIsDir( dirName ))	{	printf("deleting file %s\n", source);	return unlink((char *)source);	}    pDir = opendir (dirName) ;    if (pDir == NULL)	{	perror(dirName);	return ERROR;	}    errno = OK;    do	{    	pDirEnt = readdir (pDir);	if (pDirEnt != NULL)	    {	    if (pattern != NULL &&		dirListPattern( pattern, pDirEnt->d_name) == FALSE)		continue ;	    /* Construct path/filename for stat */	    usrPathCat( dirName, pDirEnt->d_name, fileName );	    if (!nameIsDir( fileName ))		{		printf("deleting file %s\n", fileName);		status |= unlink( fileName);		}	    else if (strcmp(pDirEnt->d_name,"." ) &&		strcmp(pDirEnt->d_name,".." ))		{		printf("deleting directory %s \n", fileName);		status |= xdelete( fileName);		status |= rmdir(fileName);		}	    }	} while (pDirEnt != NULL);		/* until end of dir */    status |= closedir (pDir);    return status ;    }/******************************************************************************** attrib - modify MS-DOS file attributes on a file or directory** This function provides means for the user to modify the attributes* of a single file or directory. There are four attribute flags which* may be modified: "Archive", "System", "Hidden" and "Read-only".* Among these flags, only "Read-only" has a meaning in VxWorks,* namely, read-only files can not be modified deleted or renamed.** The <attr> argument string may contain must start with either "+" or* "-", meaning the attribute flags which will follow should be either set* or cleared. After "+" or "-" any of these four letter will signify their* respective attribute flags - "A", "S", "H" and "R".** For example, to write-protect a particular file and flag that it is a* system file:** .CS* -> attrib( "bootrom.sys", "+RS")* .CE** RETURNS: OK, or ERROR if the file can not be opened.*/STATUS attrib    (    const char * fileName,	/* file or dir name on which to change flags */    const char * attr		/* flag settings to change */    )    {    BOOL set = TRUE ;    STATUS status ;    u_char bit = 0 ;    struct stat fileStat;    int fd ;    if (attr == NULL)	{	errno = EINVAL ;	return ERROR;	}    fd = open (fileName, O_RDONLY, 0);    if (fd == ERROR)	{	perror(fileName);	return ERROR ;	}    if (fstat (fd, &fileStat) == ERROR)          /* get file status    */	{	printErr("Can't get stat on %s\n", fileName );	return ERROR;	}    for ( ; *attr != EOS ; attr ++)	{	switch( *attr)	    {	    case '+' :		set = TRUE ;		break ;	    case '-' :		set = FALSE ;		break ;	    case 'A' : case 'a' :		bit = DOS_ATTR_ARCHIVE ;		break ;	    case 'S' : case 's' :		bit = DOS_ATTR_SYSTEM ;		break ;	    case 'H' : case 'h' :		bit = DOS_ATTR_HIDDEN ;		break ;	    case 'R' : case 'r' :		bit = DOS_ATTR_RDONLY ;		break ;	    default:		printErr("Illegal attribute flag \"%c\", ignored\n", *attr );	    } /* end of switch */	if (set)	    fileStat.st_attrib |= bit ;	else	    fileStat.st_attrib &= ~bit ;	}    status = ioctl (fd, FIOATTRIBSET, fileStat.st_attrib);    close(fd);    return status ;    }/******************************************************************************** xattrib - modify MS-DOS file attributes of many files** This function is essentially the same as attrib(), but it accepts* wildcards in <fileName>, and traverses subdirectories in order* to modify attributes of entire file hierarchies.** The <attr> argument string may contain must start with either "+" or* "-", meaning the attribute flags which will follow should be either set* or cleared. After "+" or "-" any of these four letter will signify their* respective attribute flags - "A", "S", "H" and "R".** EXAMPLE* .CS* -> xattrib( "/sd0/sysfiles", "+RS")	/@ write protect "sysfiles" @/* -> xattrib( "/sd0/logfiles", "-R")	/@ unprotect logfiles before deletion @/* -> xdelete( "/sd0/logfiles")* .CE** CAVEAT* This function may call itself in accordance with the depth of the* source directory, and occupies approximately 520 bytes per stack* frame, meaning that to accommodate the maximum depth of subdirectories* which is 20, at least 10 Kbytes of stack space should be available to* avoid stack overflow.** RETURNS: OK, or ERROR if the file can not be opened.*/STATUS xattrib    (    const char *source,	/* file or directory name on which to change flags */    const char *attr	/* flag settings to change */    )    {    FAST DIR *pDir;		/* ptr to directory descriptor */    FAST struct dirent	*pDirEnt;	/* ptr to dirent */    STATUS status = OK ;    char * pattern = NULL ;    char * dirName = NULL ;    char  dir[MAX_FILENAME_LENGTH] ;    char  fileName[MAX_FILENAME_LENGTH] ;    strncpy (dir, source, MAX_FILENAME_LENGTH-1 );    pattern = rindex(dir, '/');    if ( pattern != NULL && pattern != dir && dirNameWildcard(pattern))	{	/* dir and pattern e.g. dir1/a*.c */	*pattern++ = EOS ;	dirName = dir ;	}    else if (dirNameWildcard( dir))	{	/* just pattern e.g. *.c or abc.? */	pattern = dir;	dirName = "." ;	}    else	{	pattern = NULL ;	dirName = dir ;	}    if (!nameIsDir (dirName))	{	printf("changing attributes on %s\n", source);	return attrib(source, attr);	}    pDir = opendir (dirName);    if (pDir == NULL)	{	perror(dirName);	return ERROR;	}    errno = OK;    do	{    	pDirEnt = readdir (pDir);	if (pDirEnt != NULL)	    {	    if (pattern != NULL &&		dirListPattern( pattern, pDirEnt->d_name) == FALSE)		continue ;	    /* Construct path/filename for stat */	    usrPathCat( dirName, pDirEnt->d_name, fileName );	    if (!nameIsDir( fileName ))		{		printf("changing attributes on %s\n", fileName);		status |= attrib( fileName, attr);		}	    else if (strcmp(pDirEnt->d_name,"." ) &&		strcmp(pDirEnt->d_name,".." ))		{		printf("traversing directory %s to change attributes \n",			fileName);		status |= xattrib( fileName, attr);		status |= attrib( fileName, attr);		}	    }	} while (pDirEnt != NULL);		/* until end of dir */    status |= closedir (pDir);    return status ;    }/********************************************************************************* diskFormat - format a disk** This command formats a disk and creates a file system on it.  The* device must already have been created by the device driver and* initialized for use with a particular file system, via dosFsDevInit().** This command calls ioctl() to perform the FIODISKFORMAT function.** EXAMPLE* .CS*     -> diskFormat "/fd0/"* .CE** RETURNS:* OK, or ERROR if the device cannot be opened or formatted.** SEE ALSO: dosFsLib* .pG "Target Shell"*/STATUS diskFormat    (    const char *pDevName 	/* name of the device to initialize */    )    {    FAST int fd;    FAST const char *name;    /* If no directory name specified, use current working directory (".") */    name = (pDevName == NULL) ? "." : pDevName;    /* Open the device, format it, and initialize it. */    if ((fd = open (name, O_WRONLY, 0)) == ERROR)	{	printErr ("Couldn't open \"%s\".\n", name);	return (ERROR);	}    printf ("\"%s\" formatting... ", name);    if (ioctl (fd, FIODISKFORMAT, 0) != OK)	{	printErr ("Couldn't format \"%s\".\n", name);	close (fd);	return (ERROR);	}    printf ("\"%s\" formatted... ", name);    if (ioctl (fd, FIODISKINIT, 0) < OK)	{	printErr ("Couldn't initialize file system on \"%s\".\n", name);	close (fd);	return (ERROR);	}    close (fd);    printf ("\"%s\" initialized.\n", name);    return (OK);    }/********************************************************************************* diskInit - initialize a file system on a block device** This function is now obsolete, use of dosFsVolFormat() is recommended.** This command creates a new, blank file system on a block device.  The* device must already have been created by the device driver and* initialized for use with a particular file system, via dosFsDevCreate().** EXAMPLE* .CS*     -> diskInit "/fd0/"* .CE** Note that if the disk is unformatted, it can not be mounted,* thus open() will return error, in which case use the dosFsVolFormat* routine manually.** This routine performs the FIODISKINIT ioctl operation.** RETURNS:* OK, or* ERROR if the device cannot be opened or initialized.** SEE ALSO: dosFsLib* .pG "Target Shell"*/STATUS diskInit    (    const char *pDevName	/* name of the device to initialize */    )    {    FAST int fd;    char name[MAX_FILENAME_LENGTH+1];    /* If no directory name specified, use current working directory (".") */    if (pDevName == NULL)	ioDefPathGet (name);    else	strncpy (name, pDevName, MAX_FILENAME_LENGTH);    /* Open the device, format it, and initialize it. */    fd = open (name, O_WRONLY, 0) ;    if (ERROR == fd)	{	printErr ("Couldn't open file system on \"%s\".\n", name);	printErr ("Perhaps a dosFsVolFormat on the file system is needed.\n");	return (ERROR);	}    if (ioctl (fd, FIODISKINIT, 0) < OK)	{	printErr ("Couldn't initialize file system on \"%s\".\n", name);	close (fd);	return (ERROR);	}    printf ("\"%s\" initialized.\n", name);    close (fd);    return (OK);    }/********************************************************************************* ioHelp - print a synopsis of I/O utility functions** This function prints out synopsis for the I/O and File System* utility functions.** RETURNS: N/A** SEE ALSO:* .pG "Target Shell"*/void ioHelp (void)    {    static char *help_msg [] = {    "cd        \"path\"             Set current working path",    "pwd                            Print working path",    "ls        [\"wpat\"[,long]]    List contents of directory",    "ll        [\"wpat\"]           List contents of directory - long format",    "lsr       [\"wpat\"[,long]]    Recursive list of directory contents",    "llr       [\"wpat\"]           Recursive detailed list of directory",    "rename    \"old\",\"new\"      Change name of file",    "copy      [\"in\"][,\"out\"]   Copy in file to out file (0 = std in/out)",    "cp        \"wpat\",\"dst\"      Copy many files to another dir",    "xcopy     \"wpat\",\"dst\"      Recursively copy files",    "mv        \"wpat\",\"dst\"      Move files into another directory",    "xdelete   \"wpat\"             Delete a file, wildcard list or tree",    "attrib    \"path\",\"attr\"    Modify file attributes",    "xattrib   \"wpat\",\"attr\"    Recursively modify file attributes",    "chkdsk    \"device\", L, V     Consistency check of file system",    "diskInit  \"device\"           Initialize file system on disk",    "diskFormat \"device\"          Low level and file system disk format",    "",    "\"attr\" contains one or more of: \" + - A H S R\" characters",    "\"wpat\" may be name of a file, directory or wildcard pattern",    " in which case \"dst\" must be a directory name",    "chkdsk() params: L=0, check only, L=2, check and fix, V=0x200 verbose",    NULL    };    FAST int ix;    char ch;    printf ("\n");    for (ix = 0; help_msg [ix] != NULL; ix++)	{	if ((ix+1) % 20 == 0)	    {	    printf ("\nType <CR> to continue, Q<CR> to stop: ");	    fioRdString (STD_IN, &ch, 1);	    if (ch == 'q' || ch == 'Q')		break;	    else		printf ("\n");	    }	printf ("%s\n", help_msg [ix]);	}    printf ("\n");    }/* End of file */

⌨️ 快捷键说明

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