2 * FreeRTOS Kernel V10.0.0
\r
3 * Copyright (C) 2017 Amazon.com, Inc. or its affiliates. All Rights Reserved.
\r
5 * Permission is hereby granted, free of charge, to any person obtaining a copy of
\r
6 * this software and associated documentation files (the "Software"), to deal in
\r
7 * the Software without restriction, including without limitation the rights to
\r
8 * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
\r
9 * the Software, and to permit persons to whom the Software is furnished to do so,
\r
10 * subject to the following conditions:
\r
12 * The above copyright notice and this permission notice shall be included in all
\r
13 * copies or substantial portions of the Software. If you wish to use our Amazon
\r
14 * FreeRTOS name, please do so in a fair use way that does not cause confusion.
\r
16 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
\r
17 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
\r
18 * FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
\r
19 * COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
\r
20 * IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
\r
21 * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
\r
23 * http://www.FreeRTOS.org
\r
24 * http://aws.amazon.com/freertos
\r
26 * 1 tab == 4 spaces!
\r
29 /* FreeRTOS includes. */
\r
30 #include "FreeRTOS.h"
\r
33 /* Standard includes. */
\r
38 /* FreeRTOS+CLI includes. */
\r
39 #include "FreeRTOS_CLI.h"
\r
41 /* File system includes. */
\r
42 #include <redposix.h>
\r
43 #include <redtests.h>
\r
46 #define snprintf _snprintf
\r
49 #define cliNEW_LINE "\r\n"
\r
51 /*******************************************************************************
\r
52 * See the URL in the comments within main.c for the location of the online
\r
54 ******************************************************************************/
\r
57 * Print out information on a single file.
\r
59 static void prvCreateFileInfoString( char *pcBuffer, REDDIRENT *pxDirent );
\r
62 * Copies an existing file into a newly created file.
\r
64 static BaseType_t prvPerformCopy( int32_t lSourceFildes,
\r
65 int32_t lDestinationFiledes,
\r
66 char *pxWriteBuffer,
\r
67 size_t xWriteBufferLen );
\r
70 * Implements the DIR command.
\r
72 static BaseType_t prvDIRCommand( char *pcWriteBuffer, size_t xWriteBufferLen, const char *pcCommandString );
\r
75 * Implements the DEL command.
\r
77 static BaseType_t prvDELCommand( char *pcWriteBuffer, size_t xWriteBufferLen, const char *pcCommandString );
\r
80 * Implements the TYPE command.
\r
82 static BaseType_t prvTYPECommand( char *pcWriteBuffer, size_t xWriteBufferLen, const char *pcCommandString );
\r
85 * Implements the APPEND command.
\r
87 static BaseType_t prvAPPENDCommand( char *pcWriteBuffer, size_t xWriteBufferLen, const char *pcCommandString );
\r
90 * Implements the COPY command.
\r
92 static BaseType_t prvCOPYCommand( char *pcWriteBuffer, size_t xWriteBufferLen, const char *pcCommandString );
\r
95 * Implements the CREATE command.
\r
97 static BaseType_t prvCREATECommand( char *pcWriteBuffer, size_t xWriteBufferLen, const char *pcCommandString );
\r
100 * Implements the MKDIR command.
\r
102 static BaseType_t prvMKDIRCommand( char *pcWriteBuffer, size_t xWriteBufferLen, const char *pcCommandString );
\r
105 * Implements the RENAME command.
\r
107 static BaseType_t prvRENAMECommand( char *pcWriteBuffer, size_t xWriteBufferLen, const char *pcCommandString );
\r
110 * Implements the LINK command.
\r
112 static BaseType_t prvLINKCommand( char *pcWriteBuffer, size_t xWriteBufferLen, const char *pcCommandString );
\r
115 * Implements the STAT command.
\r
117 static BaseType_t prvSTATCommand( char *pcWriteBuffer, size_t xWriteBufferLen, const char *pcCommandString );
\r
120 * Implements the STATFS command.
\r
122 static BaseType_t prvSTATFSCommand( char *pcWriteBuffer, size_t xWriteBufferLen, const char *pcCommandString );
\r
125 * Implements the FORMAT command.
\r
127 static BaseType_t prvFORMATCommand( char *pcWriteBuffer, size_t xWriteBufferLen, const char *pcCommandString );
\r
130 * Implements the TRANSACT command.
\r
132 static BaseType_t prvTRANSACTCommand( char *pcWriteBuffer, size_t xWriteBufferLen, const char *pcCommandString );
\r
135 * Implements the TRANSMASKGET command.
\r
137 static BaseType_t prvTRANSMASKGETCommand( char *pcWriteBuffer, size_t xWriteBufferLen, const char *pcCommandString );
\r
140 * Implements the TRANSMASKSET command.
\r
142 static BaseType_t prvTRANSMASKSETCommand( char *pcWriteBuffer, size_t xWriteBufferLen, const char *pcCommandString );
\r
145 * Implements the ABORT command.
\r
147 static BaseType_t prvABORTCommand( char *pcWriteBuffer, size_t xWriteBufferLen, const char *pcCommandString );
\r
150 * Implements the TEST command.
\r
152 static BaseType_t prvTESTFSCommand( char *pcWriteBuffer, size_t xWriteBufferLen, const char *pcCommandString );
\r
155 /* Structure that defines the DIR command line command, which lists all the
\r
156 files in the current directory. */
\r
157 static const CLI_Command_Definition_t xDIR =
\r
159 "dir", /* The command string to type. */
\r
160 "\r\ndir <filename>:\r\n Lists the files in the named directory\r\n",
\r
161 prvDIRCommand, /* The function to run. */
\r
162 1 /* One parameter is expected. */
\r
165 /* Structure that defines the TYPE command line command, which prints the
\r
166 contents of a file to the console. */
\r
167 static const CLI_Command_Definition_t xTYPE =
\r
169 "type", /* The command string to type. */
\r
170 "\r\ntype <filename>:\r\n Prints file contents to the terminal\r\n",
\r
171 prvTYPECommand, /* The function to run. */
\r
172 1 /* One parameter is expected. */
\r
175 /* Structure that defines the APPEND command line command, which appends data
\r
177 static const CLI_Command_Definition_t xAPPEND =
\r
179 "append", /* The command string to type. */
\r
180 "\r\nappend <filename> <character> <length>:\r\n Appends data to a file (created if it does not exist)\r\n",
\r
181 prvAPPENDCommand, /* The function to run. */
\r
182 3 /* Three parameters are expected. */
\r
185 /* Structure that defines the DEL command line command, which deletes a file. */
\r
186 static const CLI_Command_Definition_t xDEL =
\r
188 "del", /* The command string to type. */
\r
189 "\r\ndel <filename>:\r\n deletes a file or directory\r\n",
\r
190 prvDELCommand, /* The function to run. */
\r
191 1 /* One parameter is expected. */
\r
194 /* Structure that defines the COPY command line command, which copies a file. */
\r
195 static const CLI_Command_Definition_t xCOPY =
\r
197 "copy", /* The command string to type. */
\r
198 "\r\ncopy <source file> <dest file>:\r\n Copies <source file> to <dest file>\r\n",
\r
199 prvCOPYCommand, /* The function to run. */
\r
200 2 /* Two parameters are expected. */
\r
203 /* Structure that defines the CREATE command line command, which creates an
\r
205 static const CLI_Command_Definition_t xCREATE =
\r
207 "create", /* The command string to type. */
\r
208 "\r\ncreate <filename>:\r\n Creates an empty file\r\n",
\r
209 prvCREATECommand, /* The function to run. */
\r
210 1 /* One parameter is expected. */
\r
213 /* Structure that defines the MKDIR command line command, which creates an
\r
214 empty directory. */
\r
215 static const CLI_Command_Definition_t xMKDIR =
\r
217 "mkdir", /* The command string to type. */
\r
218 "\r\nmkdir <filename>:\r\n Creates an empty directory\r\n",
\r
219 prvMKDIRCommand, /* The function to run. */
\r
220 1 /* One parameter is expected. */
\r
223 /* Structure that defines the RENAME command line command, which renames a file. */
\r
224 static const CLI_Command_Definition_t xRENAME =
\r
226 "rename", /* The command string to type. */
\r
227 "\r\nrename <source file> <dest file>:\r\n Rename <source file> to <dest file>\r\n",
\r
228 prvRENAMECommand, /* The function to run. */
\r
229 2 /* Two parameters are expected. */
\r
232 /* Structure that defines the LINK command line command, which creates a hard
\r
234 static const CLI_Command_Definition_t xLINK =
\r
236 "link", /* The command string to type. */
\r
237 "\r\nlink <source file> <dest file>:\r\n Create hard link <dest file> pointing at <source file>\r\n",
\r
238 prvLINKCommand, /* The function to run. */
\r
239 2 /* Two parameters are expected. */
\r
242 /* Structure that defines the STAT command line command, which shows various
\r
243 information about a file. */
\r
244 static const CLI_Command_Definition_t xSTAT =
\r
246 "stat", /* The command string to type. */
\r
247 "\r\nstat <filename>:\r\n Show file information\r\n",
\r
248 prvSTATCommand, /* The function to run. */
\r
249 1 /* One parameter is expected. */
\r
252 /* Structure that defines the STATFS command line command, which shows various
\r
253 file system information. */
\r
254 static const CLI_Command_Definition_t xSTATFS =
\r
256 "statfs", /* The command string to type. */
\r
257 "\r\nstatfs:\r\n Show file system information.\r\n",
\r
258 prvSTATFSCommand, /* The function to run. */
\r
259 0 /* No parameters are expected. */
\r
262 /* Structure that defines the FORMAT command line command, which re-formats the
\r
264 static const CLI_Command_Definition_t xFORMAT =
\r
266 "format", /* The command string to type. */
\r
267 "\r\nformat:\r\n Re-formats the file system volume. ALL FILES WILL BE DELETED!\r\n",
\r
268 prvFORMATCommand, /* The function to run. */
\r
269 0 /* No parameters are expected. */
\r
272 /* Structure that defines the TRANSACT command line command, which commits a
\r
273 transaction point. */
\r
274 static const CLI_Command_Definition_t xTRANSACT =
\r
276 "transact", /* The command string to type. */
\r
277 "\r\ntransact:\r\n Commit a Reliance Edge transaction point\r\n",
\r
278 prvTRANSACTCommand, /* The function to run. */
\r
279 0 /* No parameters are expected. */
\r
282 /* Structure that defines the TRANSMASKGET command line command, which retrieves
\r
283 the current automatic transaction event mask. */
\r
284 static const CLI_Command_Definition_t xTRANSMASKGET =
\r
286 "transmaskget", /* The command string to type. */
\r
287 "\r\ntransmaskget:\r\n Retrieve the Reliance Edge automatic transaction mask\r\n",
\r
288 prvTRANSMASKGETCommand, /* The function to run. */
\r
289 0 /* No parameters are expected. */
\r
292 /* Structure that defines the TRANSMASKSET command line command, which sets the
\r
293 automatic transaction event mask. */
\r
294 static const CLI_Command_Definition_t xTRANSMASKSET =
\r
296 "transmaskset", /* The command string to type. */
\r
297 "\r\ntransmaskset <hex mask>:\r\n Set the Reliance Edge automatic transaction mask\r\n",
\r
298 prvTRANSMASKSETCommand, /* The function to run. */
\r
299 1 /* One parameter is expected. */
\r
302 /* Structure that defines the ABORT command line command, which rolls back
\r
303 changes which have not been transacted. */
\r
304 static const CLI_Command_Definition_t xABORT =
\r
306 "abort", /* The command string to type. */
\r
307 "\r\nabort:\r\n Roll back all changes not part of the last transaction point\r\n",
\r
308 prvABORTCommand, /* The function to run. */
\r
309 0 /* No parameters are expected. */
\r
312 /* Structure that defines the TEST-FS command line command, which executes some
\r
313 file system driver tests. */
\r
314 static const CLI_Command_Definition_t xTEST_FS =
\r
316 "test-fs", /* The command string to type. */
\r
317 "\r\ntest-fs:\r\n Executes file system tests. ALL FILES WILL BE DELETED!\r\n",
\r
318 prvTESTFSCommand, /* The function to run. */
\r
319 0 /* No parameters are expected. */
\r
322 /*-----------------------------------------------------------*/
\r
324 void vRegisterFileSystemCLICommands( void )
\r
326 /* Register all the command line commands defined immediately above. */
\r
327 FreeRTOS_CLIRegisterCommand( &xDIR );
\r
328 FreeRTOS_CLIRegisterCommand( &xTYPE );
\r
329 FreeRTOS_CLIRegisterCommand( &xAPPEND );
\r
330 FreeRTOS_CLIRegisterCommand( &xDEL );
\r
331 FreeRTOS_CLIRegisterCommand( &xCOPY );
\r
332 FreeRTOS_CLIRegisterCommand( &xCREATE );
\r
333 FreeRTOS_CLIRegisterCommand( &xMKDIR );
\r
334 FreeRTOS_CLIRegisterCommand( &xRENAME );
\r
335 FreeRTOS_CLIRegisterCommand( &xLINK );
\r
336 FreeRTOS_CLIRegisterCommand( &xSTAT );
\r
337 FreeRTOS_CLIRegisterCommand( &xSTATFS );
\r
338 FreeRTOS_CLIRegisterCommand( &xFORMAT );
\r
339 FreeRTOS_CLIRegisterCommand( &xTRANSACT );
\r
340 FreeRTOS_CLIRegisterCommand( &xTRANSMASKGET );
\r
341 FreeRTOS_CLIRegisterCommand( &xTRANSMASKSET );
\r
342 FreeRTOS_CLIRegisterCommand( &xABORT );
\r
343 FreeRTOS_CLIRegisterCommand( &xTEST_FS );
\r
345 /*-----------------------------------------------------------*/
\r
347 static BaseType_t prvDIRCommand( char *pcWriteBuffer, size_t xWriteBufferLen, const char *pcCommandString )
\r
349 static REDDIR *pxDir = NULL;
\r
350 REDDIRENT *pxDirent;
\r
351 const char *pcParameter;
\r
352 BaseType_t xParameterStringLength, xReturn = pdFALSE;
\r
354 /* This assumes pcWriteBuffer is long enough. */
\r
355 ( void ) pcCommandString;
\r
357 /* Ensure the buffer leaves space for the \r\n. */
\r
358 configASSERT( xWriteBufferLen > ( strlen( cliNEW_LINE ) * 2 ) );
\r
359 xWriteBufferLen -= strlen( cliNEW_LINE );
\r
361 if( pxDir == NULL )
\r
363 /* Retrieve the directory to DIR. */
\r
364 pcParameter = FreeRTOS_CLIGetParameter
\r
366 pcCommandString, /* The command string itself. */
\r
367 1, /* Return the first parameter. */
\r
368 &xParameterStringLength /* Store the parameter string length. */
\r
371 /* Sanity check something was returned. */
\r
372 configASSERT( pcParameter );
\r
374 /* This is the first time this function has been executed since the Dir
\r
375 command was run. Open the directory. */
\r
376 pxDir = red_opendir( pcParameter );
\r
381 /* red_readdir() returns NULL either on error or upon reaching the
\r
382 end of the directory. Clear errno so these conditions can be
\r
385 pxDirent = red_readdir( pxDir );
\r
389 prvCreateFileInfoString( pcWriteBuffer, pxDirent );
\r
392 else if( red_errno == 0 )
\r
394 /* There are no more files. Close the directory. */
\r
395 red_closedir( pxDir );
\r
398 /* No string to return. */
\r
399 pcWriteBuffer[ 0 ] = 0x00;
\r
403 snprintf( pcWriteBuffer, xWriteBufferLen, "Error %d reading directory.", ( int ) red_errno );
\r
408 /* User-friendly messages for common errors. */
\r
409 switch( red_errno )
\r
412 snprintf( pcWriteBuffer, xWriteBufferLen, "Directory not found." );
\r
416 snprintf( pcWriteBuffer, xWriteBufferLen, "Directory not found or not a directory." );
\r
420 snprintf( pcWriteBuffer, xWriteBufferLen, "Error %d opening directory.", ( int ) red_errno );
\r
425 strcat( pcWriteBuffer, cliNEW_LINE );
\r
429 /*-----------------------------------------------------------*/
\r
431 static BaseType_t prvTYPECommand( char *pcWriteBuffer, size_t xWriteBufferLen, const char *pcCommandString )
\r
433 const char *pcParameter;
\r
434 BaseType_t xParameterStringLength, xReturn = pdTRUE;
\r
435 static int32_t lFildes = -1;
\r
437 int32_t lStatus, lBytesRead;
\r
438 size_t xColumns = 50U;
\r
440 /* Ensure there is always a null terminator after each character written. */
\r
441 memset( pcWriteBuffer, 0x00, xWriteBufferLen );
\r
443 /* Ensure the buffer leaves space for the \r\n. */
\r
444 configASSERT( xWriteBufferLen > ( strlen( cliNEW_LINE ) * 2 ) );
\r
445 xWriteBufferLen -= strlen( cliNEW_LINE );
\r
447 if( xWriteBufferLen < xColumns )
\r
449 /* Ensure the loop that uses xColumns as an end condition does not
\r
450 write off the end of the buffer. */
\r
451 xColumns = xWriteBufferLen;
\r
454 if( lFildes == -1 )
\r
456 /* The file has not been opened yet. Find the file name. */
\r
457 pcParameter = FreeRTOS_CLIGetParameter
\r
459 pcCommandString, /* The command string itself. */
\r
460 1, /* Return the first parameter. */
\r
461 &xParameterStringLength /* Store the parameter string length. */
\r
464 /* Sanity check something was returned. */
\r
465 configASSERT( pcParameter );
\r
467 /* Attempt to open the requested file. */
\r
468 lFildes = red_open( pcParameter, RED_O_RDONLY );
\r
469 if( lFildes == -1 )
\r
471 /* User-friendly messages for common errors. */
\r
472 switch( red_errno )
\r
476 snprintf( pcWriteBuffer, xWriteBufferLen, "File not found." );
\r
480 snprintf( pcWriteBuffer, xWriteBufferLen, "Error %d opening file.", ( int ) red_errno );
\r
486 /* Make sure this is a file, not a directory. */
\r
487 lStatus = red_fstat( lFildes, &finfo );
\r
490 if( RED_S_ISDIR( finfo.st_mode ) )
\r
492 snprintf( pcWriteBuffer, xWriteBufferLen, "Cannot TYPE a directory." );
\r
493 red_close( lFildes );
\r
499 snprintf( pcWriteBuffer, xWriteBufferLen, "Error %d querying file.", ( int ) red_errno );
\r
500 red_close( lFildes );
\r
506 if( lFildes != -1 )
\r
508 /* Read the next chunk of data from the file. */
\r
509 lBytesRead = red_read( lFildes, pcWriteBuffer, xColumns );
\r
511 if( lBytesRead < ( int32_t ) xColumns )
\r
513 /* Error or no more characters to return. */
\r
514 red_close( lFildes );
\r
519 if( lFildes == -1 )
\r
521 /* Either the file was not opened, or all the data from the file has
\r
522 been returned and the file is now closed. */
\r
526 strcat( pcWriteBuffer, cliNEW_LINE );
\r
530 /*-----------------------------------------------------------*/
\r
532 static BaseType_t prvAPPENDCommand( char *pcWriteBuffer, size_t xWriteBufferLen, const char *pcCommandString )
\r
534 char *pcFileName = NULL;
\r
535 const char *pcCharacter = NULL, *pcLength;
\r
536 BaseType_t xParameterStringLength, xGoodParameters = pdTRUE;
\r
537 int32_t lFildes, lAppendLength = -1, lThisWrite, lTotalWritten, lBytesWritten;
\r
539 /* This function assumes xWriteBufferLen is large enough! */
\r
540 ( void ) xWriteBufferLen;
\r
542 /* Find the length to write. */
\r
543 pcLength = FreeRTOS_CLIGetParameter
\r
545 pcCommandString, /* The command string itself. */
\r
546 3, /* Return the third parameter. */
\r
547 &xParameterStringLength /* Store the parameter string length. */
\r
549 configASSERT( pcLength );
\r
551 /* Convert the string into a number. */
\r
552 lAppendLength = RedAtoI( pcLength );
\r
553 if( lAppendLength < 0 )
\r
555 strcpy( pcWriteBuffer, "Third parameter cannot be a negative number." );
\r
556 xGoodParameters = pdFALSE;
\r
559 if( xGoodParameters )
\r
561 /* Find the character to write. */
\r
562 pcCharacter = FreeRTOS_CLIGetParameter
\r
564 pcCommandString, /* The command string itself. */
\r
565 2, /* Return the second parameter. */
\r
566 &xParameterStringLength /* Store the parameter string length. */
\r
568 configASSERT( pcCharacter );
\r
570 if( xParameterStringLength != 1 )
\r
572 strcpy( pcWriteBuffer, "Second parameter must be a single character." );
\r
573 xGoodParameters = pdFALSE;
\r
577 if( xGoodParameters )
\r
579 /* Find the file name. */
\r
580 pcFileName = ( char * ) FreeRTOS_CLIGetParameter
\r
582 pcCommandString, /* The command string itself. */
\r
583 1, /* Return the first parameter. */
\r
584 &xParameterStringLength /* Store the parameter string length. */
\r
586 configASSERT( pcFileName );
\r
588 /* Terminate the string. */
\r
589 pcFileName[ xParameterStringLength ] = 0x00;
\r
592 if( xGoodParameters )
\r
594 /* Attempt to open the requested file. */
\r
595 lFildes = red_open( pcFileName, RED_O_WRONLY|RED_O_APPEND|RED_O_CREAT );
\r
597 if( lFildes == -1 )
\r
599 /* User-friendly messages for common errors. */
\r
600 switch( red_errno )
\r
604 strcpy( pcWriteBuffer, "Bad file path." );
\r
608 strcpy( pcWriteBuffer, "Cannot append to a directory." );
\r
612 sprintf( pcWriteBuffer, "Error %d opening file.", ( int ) red_errno );
\r
618 /* Put the requested character into the buffer. */
\r
619 memset( pcWriteBuffer, pcCharacter[0], xWriteBufferLen );
\r
621 /* Append the data. */
\r
622 for( lTotalWritten = 0; lTotalWritten < lAppendLength; lTotalWritten += lThisWrite )
\r
624 lThisWrite = lAppendLength - lTotalWritten;
\r
625 if( lThisWrite > ( int32_t ) xWriteBufferLen )
\r
627 lThisWrite = ( int32_t ) xWriteBufferLen;
\r
630 lBytesWritten = red_write( lFildes, pcWriteBuffer, lThisWrite );
\r
631 if( lBytesWritten == -1 )
\r
633 /* User-friendly messages for common errors. */
\r
634 switch( red_errno )
\r
637 strcpy( pcWriteBuffer, "Out of disk space." );
\r
641 sprintf( pcWriteBuffer, "Error %d writing to file.", ( int ) red_errno );
\r
647 else if( lBytesWritten != lThisWrite )
\r
649 /* Some data was written, but not all of it. This only
\r
650 happens when the disk is full or the file reached its
\r
651 maximum size. That latter is unlikely in this demo. */
\r
652 strcpy( pcWriteBuffer, "Out of disk space." );
\r
657 if( lTotalWritten == lAppendLength )
\r
659 strcpy( pcWriteBuffer, "Append successful." );
\r
662 red_close( lFildes );
\r
666 strcat( pcWriteBuffer, cliNEW_LINE );
\r
670 /*-----------------------------------------------------------*/
\r
672 static BaseType_t prvDELCommand( char *pcWriteBuffer, size_t xWriteBufferLen, const char *pcCommandString )
\r
674 const char *pcParameter;
\r
675 BaseType_t xParameterStringLength;
\r
678 /* This function assumes xWriteBufferLen is large enough! */
\r
679 ( void ) xWriteBufferLen;
\r
681 /* Obtain the parameter string. */
\r
682 pcParameter = FreeRTOS_CLIGetParameter
\r
684 pcCommandString, /* The command string itself. */
\r
685 1, /* Return the first parameter. */
\r
686 &xParameterStringLength /* Store the parameter string length. */
\r
689 /* Sanity check something was returned. */
\r
690 configASSERT( pcParameter );
\r
692 /* Attempt to delete the file or directory. */
\r
693 lStatus = red_unlink( pcParameter );
\r
697 sprintf( pcWriteBuffer, "%s was deleted", pcParameter );
\r
701 /* User-friendly messages for common errors. */
\r
702 switch( red_errno )
\r
706 sprintf( pcWriteBuffer, "File not found." );
\r
709 case RED_ENOTEMPTY :
\r
710 sprintf( pcWriteBuffer, "Cannot remove directory: not empty." );
\r
714 sprintf( pcWriteBuffer, "Error %d deleting file.", ( int ) red_errno );
\r
719 strcat( pcWriteBuffer, cliNEW_LINE );
\r
723 /*-----------------------------------------------------------*/
\r
725 static BaseType_t prvCOPYCommand( char *pcWriteBuffer, size_t xWriteBufferLen, const char *pcCommandString )
\r
727 char *pcSourceFile;
\r
728 const char *pcDestinationFile;
\r
729 BaseType_t xParameterStringLength;
\r
730 int32_t lSourceFildes, lDestinationFildes;
\r
732 /* Obtain the name of the destination file. */
\r
733 pcDestinationFile = FreeRTOS_CLIGetParameter
\r
735 pcCommandString, /* The command string itself. */
\r
736 2, /* Return the second parameter. */
\r
737 &xParameterStringLength /* Store the parameter string length. */
\r
740 /* Sanity check something was returned. */
\r
741 configASSERT( pcDestinationFile );
\r
743 /* Obtain the name of the source file. */
\r
744 pcSourceFile = ( char * ) FreeRTOS_CLIGetParameter
\r
746 pcCommandString, /* The command string itself. */
\r
747 1, /* Return the first parameter. */
\r
748 &xParameterStringLength /* Store the parameter string length. */
\r
751 /* Sanity check something was returned. */
\r
752 configASSERT( pcSourceFile );
\r
754 /* Terminate the string. */
\r
755 pcSourceFile[ xParameterStringLength ] = 0x00;
\r
757 /* See if the source file exists, openm it if it does. */
\r
758 lSourceFildes = red_open( pcSourceFile, RED_O_RDONLY );
\r
760 if( lSourceFildes == -1 )
\r
762 sprintf( pcWriteBuffer, "Source file does not exist" );
\r
766 /* Create the destination file, error if it already exists. */
\r
767 lDestinationFildes = red_open( pcDestinationFile, RED_O_CREAT|RED_O_EXCL|RED_O_WRONLY );
\r
769 if( lDestinationFildes == -1 )
\r
771 sprintf( pcWriteBuffer, "Error: Destination file already exists" );
\r
775 if( prvPerformCopy( lSourceFildes, lDestinationFildes, pcWriteBuffer, xWriteBufferLen ) == pdPASS )
\r
777 sprintf( pcWriteBuffer, "Copy made" );
\r
781 sprintf( pcWriteBuffer, "Error during copy" );
\r
784 red_close( lDestinationFildes );
\r
787 red_close( lSourceFildes );
\r
790 strcat( pcWriteBuffer, cliNEW_LINE );
\r
794 /*-----------------------------------------------------------*/
\r
796 static BaseType_t prvCREATECommand( char *pcWriteBuffer, size_t xWriteBufferLen, const char *pcCommandString )
\r
798 const char *pcParameter;
\r
799 BaseType_t xParameterStringLength;
\r
802 /* This function assumes xWriteBufferLen is large enough! */
\r
803 ( void ) xWriteBufferLen;
\r
805 /* Obtain the parameter string. */
\r
806 pcParameter = FreeRTOS_CLIGetParameter
\r
808 pcCommandString, /* The command string itself. */
\r
809 1, /* Return the first parameter. */
\r
810 &xParameterStringLength /* Store the parameter string length. */
\r
813 /* Sanity check something was returned. */
\r
814 configASSERT( pcParameter );
\r
816 /* Attempt to create the file. */
\r
817 lFildes = red_open( pcParameter, RED_O_CREAT|RED_O_EXCL|RED_O_RDWR );
\r
819 if( lFildes != -1 )
\r
821 sprintf( pcWriteBuffer, "%s was created", pcParameter );
\r
822 red_close( lFildes );
\r
826 /* User-friendly messages for common errors. */
\r
827 switch( red_errno )
\r
831 sprintf( pcWriteBuffer, "Bad file path." );
\r
835 sprintf( pcWriteBuffer, "File already exists." );
\r
839 sprintf( pcWriteBuffer, "Error %d creating file.", ( int ) red_errno );
\r
844 strcat( pcWriteBuffer, cliNEW_LINE );
\r
848 /*-----------------------------------------------------------*/
\r
850 static BaseType_t prvMKDIRCommand( char *pcWriteBuffer, size_t xWriteBufferLen, const char *pcCommandString )
\r
852 const char *pcParameter;
\r
853 BaseType_t xParameterStringLength;
\r
856 /* This function assumes xWriteBufferLen is large enough! */
\r
857 ( void ) xWriteBufferLen;
\r
859 /* Obtain the parameter string. */
\r
860 pcParameter = FreeRTOS_CLIGetParameter
\r
862 pcCommandString, /* The command string itself. */
\r
863 1, /* Return the first parameter. */
\r
864 &xParameterStringLength /* Store the parameter string length. */
\r
867 /* Sanity check something was returned. */
\r
868 configASSERT( pcParameter );
\r
870 /* Attempt to create the file. */
\r
871 lStatus = red_mkdir( pcParameter );
\r
875 sprintf( pcWriteBuffer, "%s was created", pcParameter );
\r
879 /* User-friendly messages for common errors. */
\r
880 switch( red_errno )
\r
884 sprintf( pcWriteBuffer, "Bad file path." );
\r
888 sprintf( pcWriteBuffer, "Directory already exists." );
\r
892 sprintf( pcWriteBuffer, "Error %d creating directory.", ( int ) red_errno );
\r
897 strcat( pcWriteBuffer, cliNEW_LINE );
\r
901 /*-----------------------------------------------------------*/
\r
903 static BaseType_t prvRENAMECommand( char *pcWriteBuffer, size_t xWriteBufferLen, const char *pcCommandString )
\r
905 const char *pcDestinationFile;
\r
906 char *pcSourceFile;
\r
907 BaseType_t xParameterStringLength;
\r
910 /* This function assumes xWriteBufferLen is large enough! */
\r
911 ( void ) xWriteBufferLen;
\r
913 /* Obtain the name of the destination file. */
\r
914 pcDestinationFile = FreeRTOS_CLIGetParameter
\r
916 pcCommandString, /* The command string itself. */
\r
917 2, /* Return the second parameter. */
\r
918 &xParameterStringLength /* Store the parameter string length. */
\r
921 /* Sanity check something was returned. */
\r
922 configASSERT( pcDestinationFile );
\r
924 /* Obtain the name of the source file. */
\r
925 pcSourceFile = ( char * ) FreeRTOS_CLIGetParameter
\r
927 pcCommandString, /* The command string itself. */
\r
928 1, /* Return the first parameter. */
\r
929 &xParameterStringLength /* Store the parameter string length. */
\r
932 /* Sanity check something was returned. */
\r
933 configASSERT( pcSourceFile );
\r
935 /* Terminate the string. */
\r
936 pcSourceFile[ xParameterStringLength ] = 0x00;
\r
938 /* Attempt to rename the file. */
\r
939 lStatus = red_rename( pcSourceFile, pcDestinationFile );
\r
943 sprintf( pcWriteBuffer, "%s was renamed to %s", pcSourceFile, pcDestinationFile );
\r
947 /* User-friendly messages for common errors. */
\r
948 switch( red_errno )
\r
953 sprintf( pcWriteBuffer, "Bad file path." );
\r
956 /* This will only be seen if POSIX rename is disabled. */
\r
958 sprintf( pcWriteBuffer, "Destination already exists." );
\r
962 sprintf( pcWriteBuffer, "Error %d renaming file.", ( int ) red_errno );
\r
967 strcat( pcWriteBuffer, cliNEW_LINE );
\r
971 /*-----------------------------------------------------------*/
\r
973 static BaseType_t prvLINKCommand( char *pcWriteBuffer, size_t xWriteBufferLen, const char *pcCommandString )
\r
975 const char *pcDestinationFile;
\r
976 char *pcSourceFile;
\r
977 BaseType_t xParameterStringLength;
\r
980 /* This function assumes xWriteBufferLen is large enough! */
\r
981 ( void ) xWriteBufferLen;
\r
983 /* Obtain the name of the destination file. */
\r
984 pcDestinationFile = FreeRTOS_CLIGetParameter
\r
986 pcCommandString, /* The command string itself. */
\r
987 2, /* Return the second parameter. */
\r
988 &xParameterStringLength /* Store the parameter string length. */
\r
991 /* Sanity check something was returned. */
\r
992 configASSERT( pcDestinationFile );
\r
994 /* Obtain the name of the source file. */
\r
995 pcSourceFile = ( char * ) FreeRTOS_CLIGetParameter
\r
997 pcCommandString, /* The command string itself. */
\r
998 1, /* Return the first parameter. */
\r
999 &xParameterStringLength /* Store the parameter string length. */
\r
1002 /* Sanity check something was returned. */
\r
1003 configASSERT( pcSourceFile );
\r
1005 /* Terminate the string. */
\r
1006 pcSourceFile[ xParameterStringLength ] = 0x00;
\r
1008 /* Attempt to create the hard link. */
\r
1009 lStatus = red_link( pcSourceFile, pcDestinationFile );
\r
1011 if( lStatus == 0 )
\r
1013 sprintf( pcWriteBuffer, "%s was linked to %s", pcDestinationFile, pcSourceFile );
\r
1017 /* User-friendly messages for common errors. */
\r
1018 switch( red_errno )
\r
1020 case RED_ENOTDIR :
\r
1022 sprintf( pcWriteBuffer, "Bad file path." );
\r
1026 sprintf( pcWriteBuffer, "Cannot link a directory." );
\r
1030 sprintf( pcWriteBuffer, "Too many hard links." );
\r
1034 sprintf( pcWriteBuffer, "Error %d linking file.", ( int ) red_errno );
\r
1039 strcat( pcWriteBuffer, cliNEW_LINE );
\r
1043 /*-----------------------------------------------------------*/
\r
1045 static BaseType_t prvSTATCommand( char *pcWriteBuffer, size_t xWriteBufferLen, const char *pcCommandString )
\r
1047 const char *pcParameter, *pcModeString;
\r
1048 BaseType_t xParameterStringLength;
\r
1050 int32_t lFildes, lStatus;
\r
1052 /* Ensure the buffer leaves space for the \r\n. */
\r
1053 configASSERT( xWriteBufferLen > ( strlen( cliNEW_LINE ) * 2 ) );
\r
1054 xWriteBufferLen -= strlen( cliNEW_LINE );
\r
1056 /* Find the file name. */
\r
1057 pcParameter = FreeRTOS_CLIGetParameter
\r
1059 pcCommandString, /* The command string itself. */
\r
1060 1, /* Return the first parameter. */
\r
1061 &xParameterStringLength /* Store the parameter string length. */
\r
1064 /* Sanity check something was returned. */
\r
1065 configASSERT( pcParameter );
\r
1067 /* Attempt to open the requested file. */
\r
1068 lFildes = red_open( pcParameter, RED_O_RDONLY );
\r
1069 if( lFildes == -1 )
\r
1071 /* User-friendly messages for common errors. */
\r
1072 switch( red_errno )
\r
1075 case RED_ENOTDIR :
\r
1076 snprintf( pcWriteBuffer, xWriteBufferLen, "File not found." );
\r
1080 snprintf( pcWriteBuffer, xWriteBufferLen, "Error %d opening file.", ( int ) red_errno );
\r
1086 lStatus = red_fstat( lFildes, &finfo );
\r
1087 if( lStatus == 0 )
\r
1089 if( RED_S_ISDIR( finfo.st_mode ) )
\r
1091 pcModeString = "dir";
\r
1095 pcModeString = "file";
\r
1098 snprintf( pcWriteBuffer, xWriteBufferLen, "ino=%lu mode=0x%04x(%s) nlink=%x size=%lu blocks=%lu",
\r
1099 ( unsigned long ) finfo.st_ino, ( unsigned ) finfo.st_mode, pcModeString,
\r
1100 ( unsigned ) finfo.st_nlink, (unsigned long) finfo.st_size, (unsigned long) finfo.st_blocks );
\r
1104 snprintf( pcWriteBuffer, xWriteBufferLen, "Error %d querying file.", ( int ) red_errno );
\r
1107 red_close( lFildes );
\r
1110 strcat( pcWriteBuffer, cliNEW_LINE );
\r
1114 /*-----------------------------------------------------------*/
\r
1116 static BaseType_t prvSTATFSCommand( char *pcWriteBuffer, size_t xWriteBufferLen, const char *pcCommandString )
\r
1121 /* Avoid compiler warnings. */
\r
1122 ( void ) pcCommandString;
\r
1124 /* Ensure the buffer leaves space for the \r\n. */
\r
1125 configASSERT( xWriteBufferLen > ( strlen( cliNEW_LINE ) * 2 ) );
\r
1126 xWriteBufferLen -= strlen( cliNEW_LINE );
\r
1128 lStatus = red_statvfs( "", &fsinfo );
\r
1130 if( lStatus == -1 )
\r
1132 snprintf( pcWriteBuffer, xWriteBufferLen, "Error %d querying file system.", ( int ) red_errno );
\r
1136 snprintf( pcWriteBuffer, xWriteBufferLen,
\r
1137 "Block size: %lu\r\n"
\r
1138 "Block count: %lu\r\n"
\r
1139 "Free blocks: %lu\r\n"
\r
1140 "Inode count: %lu\r\n"
\r
1141 "Free inodes: %lu\r\n",
\r
1142 ( unsigned long ) fsinfo.f_bsize, ( unsigned long ) fsinfo.f_blocks,
\r
1143 ( unsigned long ) fsinfo.f_bfree, ( unsigned long ) fsinfo.f_files,
\r
1144 ( unsigned long ) fsinfo.f_ffree );
\r
1147 strcat( pcWriteBuffer, cliNEW_LINE );
\r
1151 /*-----------------------------------------------------------*/
\r
1153 static BaseType_t prvFORMATCommand( char *pcWriteBuffer, size_t xWriteBufferLen, const char *pcCommandString )
\r
1157 /* Avoid compiler warnings. */
\r
1158 ( void ) pcCommandString;
\r
1160 /* This function assumes xWriteBufferLen is large enough! */
\r
1161 ( void ) xWriteBufferLen;
\r
1163 /* File system volumes cannot be formatted while mounted. */
\r
1164 lStatus = red_umount( "" );
\r
1165 if( lStatus == -1 )
\r
1167 sprintf( pcWriteBuffer, "Error %d during unmount.", ( int ) red_errno );
\r
1171 /* Re-format the file system volume. */
\r
1172 lStatus = red_format( "" );
\r
1174 if( lStatus == -1 )
\r
1176 sprintf( pcWriteBuffer, "Error %d during format.", ( int ) red_errno );
\r
1180 /* Mount again so that other commands will work properly. */
\r
1181 lStatus = red_mount( "" );
\r
1183 if( lStatus == -1 )
\r
1185 sprintf( pcWriteBuffer, "Error %d during mount.", ( int ) red_errno );
\r
1189 strcpy( pcWriteBuffer, "Format successful." );
\r
1194 strcat( pcWriteBuffer, cliNEW_LINE );
\r
1198 /*-----------------------------------------------------------*/
\r
1200 static BaseType_t prvTRANSACTCommand( char *pcWriteBuffer, size_t xWriteBufferLen, const char *pcCommandString )
\r
1204 /* Avoid compiler warnings. */
\r
1205 ( void ) pcCommandString;
\r
1207 /* This function assumes xWriteBufferLen is large enough! */
\r
1208 ( void ) xWriteBufferLen;
\r
1210 /* Save the original transaction mask settings. */
\r
1211 lStatus = red_transact( "" );
\r
1213 if( lStatus == -1 )
\r
1215 sprintf( pcWriteBuffer, "Error %d during transaction point.", ( int ) red_errno );
\r
1219 strcpy( pcWriteBuffer, "Transaction point successful." );
\r
1222 strcat( pcWriteBuffer, cliNEW_LINE );
\r
1226 /*-----------------------------------------------------------*/
\r
1228 static BaseType_t prvTRANSMASKGETCommand( char *pcWriteBuffer, size_t xWriteBufferLen, const char *pcCommandString )
\r
1230 uint32_t ulEventMask;
\r
1233 /* Avoid compiler warnings. */
\r
1234 ( void ) pcCommandString;
\r
1236 /* Ensure the buffer leaves space for the \r\n. */
\r
1237 configASSERT( xWriteBufferLen > ( strlen( cliNEW_LINE ) * 2 ) );
\r
1238 xWriteBufferLen -= strlen( cliNEW_LINE );
\r
1240 lStatus = red_gettransmask( "", &ulEventMask );
\r
1241 if( lStatus == -1 )
\r
1243 snprintf( pcWriteBuffer, xWriteBufferLen, "Error %d retrieving automatic transaction event mask.", ( int ) red_errno );
\r
1247 snprintf( pcWriteBuffer, xWriteBufferLen,
\r
1248 "Current automatic transaction event mask: 0x%04lx\r\n"
\r
1249 "RED_TRANSACT_UMOUNT (0x0001): %s\r\n"
\r
1250 "RED_TRANSACT_CREAT (0x0002): %s\r\n"
\r
1251 "RED_TRANSACT_UNLINK (0x0004): %s\r\n"
\r
1252 "RED_TRANSACT_MKDIR (0x0008): %s\r\n"
\r
1253 "RED_TRANSACT_RENAME (0x0010): %s\r\n"
\r
1254 "RED_TRANSACT_LINK (0x0020): %s\r\n"
\r
1255 "RED_TRANSACT_CLOSE (0x0040): %s\r\n"
\r
1256 "RED_TRANSACT_WRITE (0x0080): %s\r\n"
\r
1257 "RED_TRANSACT_FSYNC (0x0100): %s\r\n"
\r
1258 "RED_TRANSACT_TRUNCATE (0x0200): %s\r\n"
\r
1259 "RED_TRANSACT_VOLFULL (0x0400): %s\r\n",
\r
1260 ( unsigned long ) ulEventMask,
\r
1261 ( ulEventMask & RED_TRANSACT_UMOUNT ) ? "Enabled" : "Disabled",
\r
1262 ( ulEventMask & RED_TRANSACT_CREAT ) ? "Enabled" : "Disabled",
\r
1263 ( ulEventMask & RED_TRANSACT_UNLINK ) ? "Enabled" : "Disabled",
\r
1264 ( ulEventMask & RED_TRANSACT_MKDIR ) ? "Enabled" : "Disabled",
\r
1265 ( ulEventMask & RED_TRANSACT_RENAME ) ? "Enabled" : "Disabled",
\r
1266 ( ulEventMask & RED_TRANSACT_LINK ) ? "Enabled" : "Disabled",
\r
1267 ( ulEventMask & RED_TRANSACT_CLOSE ) ? "Enabled" : "Disabled",
\r
1268 ( ulEventMask & RED_TRANSACT_WRITE ) ? "Enabled" : "Disabled",
\r
1269 ( ulEventMask & RED_TRANSACT_FSYNC ) ? "Enabled" : "Disabled",
\r
1270 ( ulEventMask & RED_TRANSACT_TRUNCATE ) ? "Enabled" : "Disabled",
\r
1271 ( ulEventMask & RED_TRANSACT_VOLFULL ) ? "Enabled" : "Disabled" );
\r
1274 strcat( pcWriteBuffer, cliNEW_LINE );
\r
1278 /*-----------------------------------------------------------*/
\r
1280 static BaseType_t prvTRANSMASKSETCommand( char *pcWriteBuffer, size_t xWriteBufferLen, const char *pcCommandString )
\r
1282 const char *pcParameter;
\r
1283 BaseType_t xParameterStringLength;
\r
1284 uint32_t ulEventMask;
\r
1287 /* Ensure the buffer leaves space for the \r\n. */
\r
1288 configASSERT( xWriteBufferLen > ( strlen( cliNEW_LINE ) * 2 ) );
\r
1289 xWriteBufferLen -= strlen( cliNEW_LINE );
\r
1291 /* Obtain the parameter string. */
\r
1292 pcParameter = FreeRTOS_CLIGetParameter
\r
1294 pcCommandString, /* The command string itself. */
\r
1295 1, /* Return the first parameter. */
\r
1296 &xParameterStringLength /* Store the parameter string length. */
\r
1299 /* Sanity check something was returned. */
\r
1300 configASSERT( pcParameter );
\r
1302 if( ( pcParameter[0] == '0' ) && ( ( pcParameter[1] == 'x' ) || ( pcParameter[1] == 'X' ) ) )
\r
1307 /* Convert the argument into a value. */
\r
1308 RedHtoUL( pcParameter, &ulEventMask );
\r
1310 /* Set the new transaction mask. */
\r
1311 lStatus = red_settransmask( "", ulEventMask );
\r
1312 if( lStatus == -1 )
\r
1314 /* User-friendly messages for common errors. */
\r
1315 switch( red_errno )
\r
1318 snprintf( pcWriteBuffer, xWriteBufferLen, "Invalid bits in transaction mask." );
\r
1322 snprintf( pcWriteBuffer, xWriteBufferLen, "Error %d setting transaction mask.", ( int ) red_errno );
\r
1328 snprintf( pcWriteBuffer, xWriteBufferLen,
\r
1329 "Successfully set automatic transaction mask. Enabled events:\r\n"
\r
1330 "RED_TRANSACT_UMOUNT (0x0001): %s\r\n"
\r
1331 "RED_TRANSACT_CREAT (0x0002): %s\r\n"
\r
1332 "RED_TRANSACT_UNLINK (0x0004): %s\r\n"
\r
1333 "RED_TRANSACT_MKDIR (0x0008): %s\r\n"
\r
1334 "RED_TRANSACT_RENAME (0x0010): %s\r\n"
\r
1335 "RED_TRANSACT_LINK (0x0020): %s\r\n"
\r
1336 "RED_TRANSACT_CLOSE (0x0040): %s\r\n"
\r
1337 "RED_TRANSACT_WRITE (0x0080): %s\r\n"
\r
1338 "RED_TRANSACT_FSYNC (0x0100): %s\r\n"
\r
1339 "RED_TRANSACT_TRUNCATE (0x0200): %s\r\n"
\r
1340 "RED_TRANSACT_VOLFULL (0x0400): %s\r\n",
\r
1341 ( ulEventMask & RED_TRANSACT_UMOUNT ) ? "Enabled" : "Disabled",
\r
1342 ( ulEventMask & RED_TRANSACT_CREAT ) ? "Enabled" : "Disabled",
\r
1343 ( ulEventMask & RED_TRANSACT_UNLINK ) ? "Enabled" : "Disabled",
\r
1344 ( ulEventMask & RED_TRANSACT_MKDIR ) ? "Enabled" : "Disabled",
\r
1345 ( ulEventMask & RED_TRANSACT_RENAME ) ? "Enabled" : "Disabled",
\r
1346 ( ulEventMask & RED_TRANSACT_LINK ) ? "Enabled" : "Disabled",
\r
1347 ( ulEventMask & RED_TRANSACT_CLOSE ) ? "Enabled" : "Disabled",
\r
1348 ( ulEventMask & RED_TRANSACT_WRITE ) ? "Enabled" : "Disabled",
\r
1349 ( ulEventMask & RED_TRANSACT_FSYNC ) ? "Enabled" : "Disabled",
\r
1350 ( ulEventMask & RED_TRANSACT_TRUNCATE ) ? "Enabled" : "Disabled",
\r
1351 ( ulEventMask & RED_TRANSACT_VOLFULL ) ? "Enabled" : "Disabled" );
\r
1354 strcat( pcWriteBuffer, cliNEW_LINE );
\r
1358 /*-----------------------------------------------------------*/
\r
1360 static BaseType_t prvABORTCommand( char *pcWriteBuffer, size_t xWriteBufferLen, const char *pcCommandString )
\r
1362 uint32_t ulEventMask;
\r
1365 /* Avoid compiler warnings. */
\r
1366 ( void ) pcCommandString;
\r
1368 /* This function assumes xWriteBufferLen is large enough! */
\r
1369 ( void ) xWriteBufferLen;
\r
1371 /* Save the original transaction mask settings. */
\r
1372 lStatus = red_gettransmask( "", &ulEventMask );
\r
1374 if( lStatus == -1 )
\r
1376 sprintf( pcWriteBuffer, "Error %d querying transaction mask.", ( int ) red_errno );
\r
1380 /* Make it so that red_umount() will not automatically commit a new
\r
1381 transaction point. */
\r
1382 lStatus = red_settransmask( "", ulEventMask & ~( ( uint32_t ) RED_TRANSACT_UMOUNT ) );
\r
1384 if( lStatus == -1 )
\r
1386 sprintf( pcWriteBuffer, "Error %d setting transaction mask.", ( int ) red_errno );
\r
1390 /* Unmount. Since red_umount() will not transact, all changes which
\r
1391 were not already transacted are rolled back. */
\r
1392 lStatus = red_umount( "" );
\r
1394 if( lStatus == -1 )
\r
1396 sprintf( pcWriteBuffer, "Error %d during unmount.", ( int ) red_errno );
\r
1400 /* Mount. Mount always starts from the last transaction point. */
\r
1401 lStatus = red_mount( "" );
\r
1403 if( lStatus == -1 )
\r
1405 sprintf( pcWriteBuffer, "Error %d during mount.", ( int ) red_errno );
\r
1409 strcpy( pcWriteBuffer, "Working state changes succesfully aborted." );
\r
1413 /* Restore the original transaction mask settings. */
\r
1414 red_settransmask( "", ulEventMask );
\r
1418 strcat( pcWriteBuffer, cliNEW_LINE );
\r
1422 /*-----------------------------------------------------------*/
\r
1424 static BaseType_t prvTESTFSCommand( char *pcWriteBuffer, size_t xWriteBufferLen, const char *pcCommandString )
\r
1426 UBaseType_t uxOriginalPriority;
\r
1427 FSSTRESSPARAM param;
\r
1429 /* Avoid compiler warnings. */
\r
1430 ( void ) xWriteBufferLen;
\r
1431 ( void ) pcCommandString;
\r
1433 /* Limitations in the interaction with the Windows TCP/IP stack require
\r
1434 the command console to run at the idle priority. Raise the priority for
\r
1435 the duration of the tests to ensure there are not multiple switches to the
\r
1436 idle task as in the simulated environment the idle task hook function may
\r
1437 include a (relatively) long delay. */
\r
1438 uxOriginalPriority = uxTaskPriorityGet( NULL );
\r
1439 vTaskPrioritySet( NULL, configMAX_PRIORITIES - 1 );
\r
1441 /* Delete all files to avoid inteferring with the test. */
\r
1446 FsstressDefaultParams(¶m);
\r
1447 param.fVerbose = pdTRUE;
\r
1448 param.ulNops = 10000;
\r
1450 FsstressStart(¶m);
\r
1452 /* Clean up after the test. */
\r
1457 /* Reset back to the original priority. */
\r
1458 vTaskPrioritySet( NULL, uxOriginalPriority );
\r
1460 sprintf( pcWriteBuffer, "%s", "Test results were sent to Windows console" );
\r
1461 strcat( pcWriteBuffer, cliNEW_LINE );
\r
1465 /*-----------------------------------------------------------*/
\r
1467 static BaseType_t prvPerformCopy( int32_t lSourceFildes,
\r
1468 int32_t lDestinationFiledes,
\r
1469 char *pxWriteBuffer,
\r
1470 size_t xWriteBufferLen )
\r
1472 int32_t lBytesRead;
\r
1473 BaseType_t xReturn = pdPASS;
\r
1475 /* Assuming both files are at offset zero. */
\r
1479 /* Read the next block of data. */
\r
1480 lBytesRead = red_read( lSourceFildes, pxWriteBuffer, xWriteBufferLen );
\r
1481 if( lBytesRead <= 0 )
\r
1483 if( lBytesRead == -1)
\r
1485 /* Error reading from file. */
\r
1490 /* No error: reached end of file, time to stop. */
\r
1496 /* Write the block of data to the end of the file. */
\r
1497 if( red_write( lDestinationFiledes, pxWriteBuffer, lBytesRead ) != lBytesRead )
\r
1506 /*-----------------------------------------------------------*/
\r
1508 static void prvCreateFileInfoString( char *pcBuffer, REDDIRENT *pxDirent )
\r
1510 const char *pcFile = "file", *pcDirectory = "directory";
\r
1511 const char *pcAttrib;
\r
1513 /* Point pcAttrib to a string that describes the file. */
\r
1514 if( RED_S_ISDIR(pxDirent->d_stat.st_mode) )
\r
1516 pcAttrib = pcDirectory;
\r
1520 pcAttrib = pcFile;
\r
1523 /* Create a string that includes the file name, the file size and the
\r
1524 attributes string. */
\r
1525 sprintf( pcBuffer, "%s [%s] [size=%lld]", pxDirent->d_name, pcAttrib, pxDirent->d_stat.st_size );
\r