2 * FreeRTOS Kernel V10.2.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.
\r
15 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
\r
16 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
\r
17 * FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
\r
18 * COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
\r
19 * IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
\r
20 * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
\r
22 * http://www.FreeRTOS.org
\r
23 * http://aws.amazon.com/freertos
\r
25 * 1 tab == 4 spaces!
\r
28 /* FreeRTOS includes. */
\r
29 #include "FreeRTOS.h"
\r
32 /* Standard includes. */
\r
37 /* FreeRTOS+CLI includes. */
\r
38 #include "FreeRTOS_CLI.h"
\r
40 /* File system includes. */
\r
41 #include <redposix.h>
\r
42 #include <redtests.h>
\r
45 #define snprintf _snprintf
\r
48 #define cliNEW_LINE "\r\n"
\r
50 /*******************************************************************************
\r
51 * See the URL in the comments within main.c for the location of the online
\r
53 ******************************************************************************/
\r
56 * Print out information on a single file.
\r
58 static void prvCreateFileInfoString( char *pcBuffer, REDDIRENT *pxDirent );
\r
61 * Copies an existing file into a newly created file.
\r
63 static BaseType_t prvPerformCopy( int32_t lSourceFildes,
\r
64 int32_t lDestinationFiledes,
\r
65 char *pxWriteBuffer,
\r
66 size_t xWriteBufferLen );
\r
69 * Implements the DIR command.
\r
71 static BaseType_t prvDIRCommand( char *pcWriteBuffer, size_t xWriteBufferLen, const char *pcCommandString );
\r
74 * Implements the DEL command.
\r
76 static BaseType_t prvDELCommand( char *pcWriteBuffer, size_t xWriteBufferLen, const char *pcCommandString );
\r
79 * Implements the TYPE command.
\r
81 static BaseType_t prvTYPECommand( char *pcWriteBuffer, size_t xWriteBufferLen, const char *pcCommandString );
\r
84 * Implements the APPEND command.
\r
86 static BaseType_t prvAPPENDCommand( char *pcWriteBuffer, size_t xWriteBufferLen, const char *pcCommandString );
\r
89 * Implements the COPY command.
\r
91 static BaseType_t prvCOPYCommand( char *pcWriteBuffer, size_t xWriteBufferLen, const char *pcCommandString );
\r
94 * Implements the CREATE command.
\r
96 static BaseType_t prvCREATECommand( char *pcWriteBuffer, size_t xWriteBufferLen, const char *pcCommandString );
\r
99 * Implements the MKDIR command.
\r
101 static BaseType_t prvMKDIRCommand( char *pcWriteBuffer, size_t xWriteBufferLen, const char *pcCommandString );
\r
104 * Implements the RENAME command.
\r
106 static BaseType_t prvRENAMECommand( char *pcWriteBuffer, size_t xWriteBufferLen, const char *pcCommandString );
\r
109 * Implements the LINK command.
\r
111 static BaseType_t prvLINKCommand( char *pcWriteBuffer, size_t xWriteBufferLen, const char *pcCommandString );
\r
114 * Implements the STAT command.
\r
116 static BaseType_t prvSTATCommand( char *pcWriteBuffer, size_t xWriteBufferLen, const char *pcCommandString );
\r
119 * Implements the STATFS command.
\r
121 static BaseType_t prvSTATFSCommand( char *pcWriteBuffer, size_t xWriteBufferLen, const char *pcCommandString );
\r
124 * Implements the FORMAT command.
\r
126 static BaseType_t prvFORMATCommand( char *pcWriteBuffer, size_t xWriteBufferLen, const char *pcCommandString );
\r
129 * Implements the TRANSACT command.
\r
131 static BaseType_t prvTRANSACTCommand( char *pcWriteBuffer, size_t xWriteBufferLen, const char *pcCommandString );
\r
134 * Implements the TRANSMASKGET command.
\r
136 static BaseType_t prvTRANSMASKGETCommand( char *pcWriteBuffer, size_t xWriteBufferLen, const char *pcCommandString );
\r
139 * Implements the TRANSMASKSET command.
\r
141 static BaseType_t prvTRANSMASKSETCommand( char *pcWriteBuffer, size_t xWriteBufferLen, const char *pcCommandString );
\r
144 * Implements the ABORT command.
\r
146 static BaseType_t prvABORTCommand( char *pcWriteBuffer, size_t xWriteBufferLen, const char *pcCommandString );
\r
149 * Implements the TEST command.
\r
151 static BaseType_t prvTESTFSCommand( char *pcWriteBuffer, size_t xWriteBufferLen, const char *pcCommandString );
\r
154 /* Structure that defines the DIR command line command, which lists all the
\r
155 files in the current directory. */
\r
156 static const CLI_Command_Definition_t xDIR =
\r
158 "dir", /* The command string to type. */
\r
159 "\r\ndir <filename>:\r\n Lists the files in the named directory\r\n",
\r
160 prvDIRCommand, /* The function to run. */
\r
161 1 /* One parameter is expected. */
\r
164 /* Structure that defines the TYPE command line command, which prints the
\r
165 contents of a file to the console. */
\r
166 static const CLI_Command_Definition_t xTYPE =
\r
168 "type", /* The command string to type. */
\r
169 "\r\ntype <filename>:\r\n Prints file contents to the terminal\r\n",
\r
170 prvTYPECommand, /* The function to run. */
\r
171 1 /* One parameter is expected. */
\r
174 /* Structure that defines the APPEND command line command, which appends data
\r
176 static const CLI_Command_Definition_t xAPPEND =
\r
178 "append", /* The command string to type. */
\r
179 "\r\nappend <filename> <character> <length>:\r\n Appends data to a file (created if it does not exist)\r\n",
\r
180 prvAPPENDCommand, /* The function to run. */
\r
181 3 /* Three parameters are expected. */
\r
184 /* Structure that defines the DEL command line command, which deletes a file. */
\r
185 static const CLI_Command_Definition_t xDEL =
\r
187 "del", /* The command string to type. */
\r
188 "\r\ndel <filename>:\r\n deletes a file or directory\r\n",
\r
189 prvDELCommand, /* The function to run. */
\r
190 1 /* One parameter is expected. */
\r
193 /* Structure that defines the COPY command line command, which copies a file. */
\r
194 static const CLI_Command_Definition_t xCOPY =
\r
196 "copy", /* The command string to type. */
\r
197 "\r\ncopy <source file> <dest file>:\r\n Copies <source file> to <dest file>\r\n",
\r
198 prvCOPYCommand, /* The function to run. */
\r
199 2 /* Two parameters are expected. */
\r
202 /* Structure that defines the CREATE command line command, which creates an
\r
204 static const CLI_Command_Definition_t xCREATE =
\r
206 "create", /* The command string to type. */
\r
207 "\r\ncreate <filename>:\r\n Creates an empty file\r\n",
\r
208 prvCREATECommand, /* The function to run. */
\r
209 1 /* One parameter is expected. */
\r
212 /* Structure that defines the MKDIR command line command, which creates an
\r
213 empty directory. */
\r
214 static const CLI_Command_Definition_t xMKDIR =
\r
216 "mkdir", /* The command string to type. */
\r
217 "\r\nmkdir <filename>:\r\n Creates an empty directory\r\n",
\r
218 prvMKDIRCommand, /* The function to run. */
\r
219 1 /* One parameter is expected. */
\r
222 /* Structure that defines the RENAME command line command, which renames a file. */
\r
223 static const CLI_Command_Definition_t xRENAME =
\r
225 "rename", /* The command string to type. */
\r
226 "\r\nrename <source file> <dest file>:\r\n Rename <source file> to <dest file>\r\n",
\r
227 prvRENAMECommand, /* The function to run. */
\r
228 2 /* Two parameters are expected. */
\r
231 /* Structure that defines the LINK command line command, which creates a hard
\r
233 static const CLI_Command_Definition_t xLINK =
\r
235 "link", /* The command string to type. */
\r
236 "\r\nlink <source file> <dest file>:\r\n Create hard link <dest file> pointing at <source file>\r\n",
\r
237 prvLINKCommand, /* The function to run. */
\r
238 2 /* Two parameters are expected. */
\r
241 /* Structure that defines the STAT command line command, which shows various
\r
242 information about a file. */
\r
243 static const CLI_Command_Definition_t xSTAT =
\r
245 "stat", /* The command string to type. */
\r
246 "\r\nstat <filename>:\r\n Show file information\r\n",
\r
247 prvSTATCommand, /* The function to run. */
\r
248 1 /* One parameter is expected. */
\r
251 /* Structure that defines the STATFS command line command, which shows various
\r
252 file system information. */
\r
253 static const CLI_Command_Definition_t xSTATFS =
\r
255 "statfs", /* The command string to type. */
\r
256 "\r\nstatfs:\r\n Show file system information.\r\n",
\r
257 prvSTATFSCommand, /* The function to run. */
\r
258 0 /* No parameters are expected. */
\r
261 /* Structure that defines the FORMAT command line command, which re-formats the
\r
263 static const CLI_Command_Definition_t xFORMAT =
\r
265 "format", /* The command string to type. */
\r
266 "\r\nformat:\r\n Re-formats the file system volume. ALL FILES WILL BE DELETED!\r\n",
\r
267 prvFORMATCommand, /* The function to run. */
\r
268 0 /* No parameters are expected. */
\r
271 /* Structure that defines the TRANSACT command line command, which commits a
\r
272 transaction point. */
\r
273 static const CLI_Command_Definition_t xTRANSACT =
\r
275 "transact", /* The command string to type. */
\r
276 "\r\ntransact:\r\n Commit a Reliance Edge transaction point\r\n",
\r
277 prvTRANSACTCommand, /* The function to run. */
\r
278 0 /* No parameters are expected. */
\r
281 /* Structure that defines the TRANSMASKGET command line command, which retrieves
\r
282 the current automatic transaction event mask. */
\r
283 static const CLI_Command_Definition_t xTRANSMASKGET =
\r
285 "transmaskget", /* The command string to type. */
\r
286 "\r\ntransmaskget:\r\n Retrieve the Reliance Edge automatic transaction mask\r\n",
\r
287 prvTRANSMASKGETCommand, /* The function to run. */
\r
288 0 /* No parameters are expected. */
\r
291 /* Structure that defines the TRANSMASKSET command line command, which sets the
\r
292 automatic transaction event mask. */
\r
293 static const CLI_Command_Definition_t xTRANSMASKSET =
\r
295 "transmaskset", /* The command string to type. */
\r
296 "\r\ntransmaskset <hex mask>:\r\n Set the Reliance Edge automatic transaction mask\r\n",
\r
297 prvTRANSMASKSETCommand, /* The function to run. */
\r
298 1 /* One parameter is expected. */
\r
301 /* Structure that defines the ABORT command line command, which rolls back
\r
302 changes which have not been transacted. */
\r
303 static const CLI_Command_Definition_t xABORT =
\r
305 "abort", /* The command string to type. */
\r
306 "\r\nabort:\r\n Roll back all changes not part of the last transaction point\r\n",
\r
307 prvABORTCommand, /* The function to run. */
\r
308 0 /* No parameters are expected. */
\r
311 /* Structure that defines the TEST-FS command line command, which executes some
\r
312 file system driver tests. */
\r
313 static const CLI_Command_Definition_t xTEST_FS =
\r
315 "test-fs", /* The command string to type. */
\r
316 "\r\ntest-fs:\r\n Executes file system tests. ALL FILES WILL BE DELETED!\r\n",
\r
317 prvTESTFSCommand, /* The function to run. */
\r
318 0 /* No parameters are expected. */
\r
321 /*-----------------------------------------------------------*/
\r
323 void vRegisterFileSystemCLICommands( void )
\r
325 /* Register all the command line commands defined immediately above. */
\r
326 FreeRTOS_CLIRegisterCommand( &xDIR );
\r
327 FreeRTOS_CLIRegisterCommand( &xTYPE );
\r
328 FreeRTOS_CLIRegisterCommand( &xAPPEND );
\r
329 FreeRTOS_CLIRegisterCommand( &xDEL );
\r
330 FreeRTOS_CLIRegisterCommand( &xCOPY );
\r
331 FreeRTOS_CLIRegisterCommand( &xCREATE );
\r
332 FreeRTOS_CLIRegisterCommand( &xMKDIR );
\r
333 FreeRTOS_CLIRegisterCommand( &xRENAME );
\r
334 FreeRTOS_CLIRegisterCommand( &xLINK );
\r
335 FreeRTOS_CLIRegisterCommand( &xSTAT );
\r
336 FreeRTOS_CLIRegisterCommand( &xSTATFS );
\r
337 FreeRTOS_CLIRegisterCommand( &xFORMAT );
\r
338 FreeRTOS_CLIRegisterCommand( &xTRANSACT );
\r
339 FreeRTOS_CLIRegisterCommand( &xTRANSMASKGET );
\r
340 FreeRTOS_CLIRegisterCommand( &xTRANSMASKSET );
\r
341 FreeRTOS_CLIRegisterCommand( &xABORT );
\r
342 FreeRTOS_CLIRegisterCommand( &xTEST_FS );
\r
344 /*-----------------------------------------------------------*/
\r
346 static BaseType_t prvDIRCommand( char *pcWriteBuffer, size_t xWriteBufferLen, const char *pcCommandString )
\r
348 static REDDIR *pxDir = NULL;
\r
349 REDDIRENT *pxDirent;
\r
350 const char *pcParameter;
\r
351 BaseType_t xParameterStringLength, xReturn = pdFALSE;
\r
353 /* This assumes pcWriteBuffer is long enough. */
\r
354 ( void ) pcCommandString;
\r
356 /* Ensure the buffer leaves space for the \r\n. */
\r
357 configASSERT( xWriteBufferLen > ( strlen( cliNEW_LINE ) * 2 ) );
\r
358 xWriteBufferLen -= strlen( cliNEW_LINE );
\r
360 if( pxDir == NULL )
\r
362 /* Retrieve the directory to DIR. */
\r
363 pcParameter = FreeRTOS_CLIGetParameter
\r
365 pcCommandString, /* The command string itself. */
\r
366 1, /* Return the first parameter. */
\r
367 &xParameterStringLength /* Store the parameter string length. */
\r
370 /* Sanity check something was returned. */
\r
371 configASSERT( pcParameter );
\r
373 /* This is the first time this function has been executed since the Dir
\r
374 command was run. Open the directory. */
\r
375 pxDir = red_opendir( pcParameter );
\r
380 /* red_readdir() returns NULL either on error or upon reaching the
\r
381 end of the directory. Clear errno so these conditions can be
\r
384 pxDirent = red_readdir( pxDir );
\r
388 prvCreateFileInfoString( pcWriteBuffer, pxDirent );
\r
391 else if( red_errno == 0 )
\r
393 /* There are no more files. Close the directory. */
\r
394 red_closedir( pxDir );
\r
397 /* No string to return. */
\r
398 pcWriteBuffer[ 0 ] = 0x00;
\r
402 snprintf( pcWriteBuffer, xWriteBufferLen, "Error %d reading directory.", ( int ) red_errno );
\r
407 /* User-friendly messages for common errors. */
\r
408 switch( red_errno )
\r
411 snprintf( pcWriteBuffer, xWriteBufferLen, "Directory not found." );
\r
415 snprintf( pcWriteBuffer, xWriteBufferLen, "Directory not found or not a directory." );
\r
419 snprintf( pcWriteBuffer, xWriteBufferLen, "Error %d opening directory.", ( int ) red_errno );
\r
424 strcat( pcWriteBuffer, cliNEW_LINE );
\r
428 /*-----------------------------------------------------------*/
\r
430 static BaseType_t prvTYPECommand( char *pcWriteBuffer, size_t xWriteBufferLen, const char *pcCommandString )
\r
432 const char *pcParameter;
\r
433 BaseType_t xParameterStringLength, xReturn = pdTRUE;
\r
434 static int32_t lFildes = -1;
\r
436 int32_t lStatus, lBytesRead;
\r
437 size_t xColumns = 50U;
\r
439 /* Ensure there is always a null terminator after each character written. */
\r
440 memset( pcWriteBuffer, 0x00, xWriteBufferLen );
\r
442 /* Ensure the buffer leaves space for the \r\n. */
\r
443 configASSERT( xWriteBufferLen > ( strlen( cliNEW_LINE ) * 2 ) );
\r
444 xWriteBufferLen -= strlen( cliNEW_LINE );
\r
446 if( xWriteBufferLen < xColumns )
\r
448 /* Ensure the loop that uses xColumns as an end condition does not
\r
449 write off the end of the buffer. */
\r
450 xColumns = xWriteBufferLen;
\r
453 if( lFildes == -1 )
\r
455 /* The file has not been opened yet. Find the file name. */
\r
456 pcParameter = FreeRTOS_CLIGetParameter
\r
458 pcCommandString, /* The command string itself. */
\r
459 1, /* Return the first parameter. */
\r
460 &xParameterStringLength /* Store the parameter string length. */
\r
463 /* Sanity check something was returned. */
\r
464 configASSERT( pcParameter );
\r
466 /* Attempt to open the requested file. */
\r
467 lFildes = red_open( pcParameter, RED_O_RDONLY );
\r
468 if( lFildes == -1 )
\r
470 /* User-friendly messages for common errors. */
\r
471 switch( red_errno )
\r
475 snprintf( pcWriteBuffer, xWriteBufferLen, "File not found." );
\r
479 snprintf( pcWriteBuffer, xWriteBufferLen, "Error %d opening file.", ( int ) red_errno );
\r
485 /* Make sure this is a file, not a directory. */
\r
486 lStatus = red_fstat( lFildes, &finfo );
\r
489 if( RED_S_ISDIR( finfo.st_mode ) )
\r
491 snprintf( pcWriteBuffer, xWriteBufferLen, "Cannot TYPE a directory." );
\r
492 red_close( lFildes );
\r
498 snprintf( pcWriteBuffer, xWriteBufferLen, "Error %d querying file.", ( int ) red_errno );
\r
499 red_close( lFildes );
\r
505 if( lFildes != -1 )
\r
507 /* Read the next chunk of data from the file. */
\r
508 lBytesRead = red_read( lFildes, pcWriteBuffer, xColumns );
\r
510 if( lBytesRead < ( int32_t ) xColumns )
\r
512 /* Error or no more characters to return. */
\r
513 red_close( lFildes );
\r
518 if( lFildes == -1 )
\r
520 /* Either the file was not opened, or all the data from the file has
\r
521 been returned and the file is now closed. */
\r
525 strcat( pcWriteBuffer, cliNEW_LINE );
\r
529 /*-----------------------------------------------------------*/
\r
531 static BaseType_t prvAPPENDCommand( char *pcWriteBuffer, size_t xWriteBufferLen, const char *pcCommandString )
\r
533 char *pcFileName = NULL;
\r
534 const char *pcCharacter = NULL, *pcLength;
\r
535 BaseType_t xParameterStringLength, xGoodParameters = pdTRUE;
\r
536 int32_t lFildes, lAppendLength = -1, lThisWrite, lTotalWritten, lBytesWritten;
\r
538 /* This function assumes xWriteBufferLen is large enough! */
\r
539 ( void ) xWriteBufferLen;
\r
541 /* Find the length to write. */
\r
542 pcLength = FreeRTOS_CLIGetParameter
\r
544 pcCommandString, /* The command string itself. */
\r
545 3, /* Return the third parameter. */
\r
546 &xParameterStringLength /* Store the parameter string length. */
\r
548 configASSERT( pcLength );
\r
550 /* Convert the string into a number. */
\r
551 lAppendLength = RedAtoI( pcLength );
\r
552 if( lAppendLength < 0 )
\r
554 strcpy( pcWriteBuffer, "Third parameter cannot be a negative number." );
\r
555 xGoodParameters = pdFALSE;
\r
558 if( xGoodParameters )
\r
560 /* Find the character to write. */
\r
561 pcCharacter = FreeRTOS_CLIGetParameter
\r
563 pcCommandString, /* The command string itself. */
\r
564 2, /* Return the second parameter. */
\r
565 &xParameterStringLength /* Store the parameter string length. */
\r
567 configASSERT( pcCharacter );
\r
569 if( xParameterStringLength != 1 )
\r
571 strcpy( pcWriteBuffer, "Second parameter must be a single character." );
\r
572 xGoodParameters = pdFALSE;
\r
576 if( xGoodParameters )
\r
578 /* Find the file name. */
\r
579 pcFileName = ( char * ) FreeRTOS_CLIGetParameter
\r
581 pcCommandString, /* The command string itself. */
\r
582 1, /* Return the first parameter. */
\r
583 &xParameterStringLength /* Store the parameter string length. */
\r
585 configASSERT( pcFileName );
\r
587 /* Terminate the string. */
\r
588 pcFileName[ xParameterStringLength ] = 0x00;
\r
591 if( xGoodParameters )
\r
593 /* Attempt to open the requested file. */
\r
594 lFildes = red_open( pcFileName, RED_O_WRONLY|RED_O_APPEND|RED_O_CREAT );
\r
596 if( lFildes == -1 )
\r
598 /* User-friendly messages for common errors. */
\r
599 switch( red_errno )
\r
603 strcpy( pcWriteBuffer, "Bad file path." );
\r
607 strcpy( pcWriteBuffer, "Cannot append to a directory." );
\r
611 sprintf( pcWriteBuffer, "Error %d opening file.", ( int ) red_errno );
\r
617 /* Put the requested character into the buffer. */
\r
618 memset( pcWriteBuffer, pcCharacter[0], xWriteBufferLen );
\r
620 /* Append the data. */
\r
621 for( lTotalWritten = 0; lTotalWritten < lAppendLength; lTotalWritten += lThisWrite )
\r
623 lThisWrite = lAppendLength - lTotalWritten;
\r
624 if( lThisWrite > ( int32_t ) xWriteBufferLen )
\r
626 lThisWrite = ( int32_t ) xWriteBufferLen;
\r
629 lBytesWritten = red_write( lFildes, pcWriteBuffer, lThisWrite );
\r
630 if( lBytesWritten == -1 )
\r
632 /* User-friendly messages for common errors. */
\r
633 switch( red_errno )
\r
636 strcpy( pcWriteBuffer, "Out of disk space." );
\r
640 sprintf( pcWriteBuffer, "Error %d writing to file.", ( int ) red_errno );
\r
646 else if( lBytesWritten != lThisWrite )
\r
648 /* Some data was written, but not all of it. This only
\r
649 happens when the disk is full or the file reached its
\r
650 maximum size. That latter is unlikely in this demo. */
\r
651 strcpy( pcWriteBuffer, "Out of disk space." );
\r
656 if( lTotalWritten == lAppendLength )
\r
658 strcpy( pcWriteBuffer, "Append successful." );
\r
661 red_close( lFildes );
\r
665 strcat( pcWriteBuffer, cliNEW_LINE );
\r
669 /*-----------------------------------------------------------*/
\r
671 static BaseType_t prvDELCommand( char *pcWriteBuffer, size_t xWriteBufferLen, const char *pcCommandString )
\r
673 const char *pcParameter;
\r
674 BaseType_t xParameterStringLength;
\r
677 /* This function assumes xWriteBufferLen is large enough! */
\r
678 ( void ) xWriteBufferLen;
\r
680 /* Obtain the parameter string. */
\r
681 pcParameter = FreeRTOS_CLIGetParameter
\r
683 pcCommandString, /* The command string itself. */
\r
684 1, /* Return the first parameter. */
\r
685 &xParameterStringLength /* Store the parameter string length. */
\r
688 /* Sanity check something was returned. */
\r
689 configASSERT( pcParameter );
\r
691 /* Attempt to delete the file or directory. */
\r
692 lStatus = red_unlink( pcParameter );
\r
696 sprintf( pcWriteBuffer, "%s was deleted", pcParameter );
\r
700 /* User-friendly messages for common errors. */
\r
701 switch( red_errno )
\r
705 sprintf( pcWriteBuffer, "File not found." );
\r
708 case RED_ENOTEMPTY :
\r
709 sprintf( pcWriteBuffer, "Cannot remove directory: not empty." );
\r
713 sprintf( pcWriteBuffer, "Error %d deleting file.", ( int ) red_errno );
\r
718 strcat( pcWriteBuffer, cliNEW_LINE );
\r
722 /*-----------------------------------------------------------*/
\r
724 static BaseType_t prvCOPYCommand( char *pcWriteBuffer, size_t xWriteBufferLen, const char *pcCommandString )
\r
726 char *pcSourceFile;
\r
727 const char *pcDestinationFile;
\r
728 BaseType_t xParameterStringLength;
\r
729 int32_t lSourceFildes, lDestinationFildes;
\r
731 /* Obtain the name of the destination file. */
\r
732 pcDestinationFile = FreeRTOS_CLIGetParameter
\r
734 pcCommandString, /* The command string itself. */
\r
735 2, /* Return the second parameter. */
\r
736 &xParameterStringLength /* Store the parameter string length. */
\r
739 /* Sanity check something was returned. */
\r
740 configASSERT( pcDestinationFile );
\r
742 /* Obtain the name of the source file. */
\r
743 pcSourceFile = ( char * ) FreeRTOS_CLIGetParameter
\r
745 pcCommandString, /* The command string itself. */
\r
746 1, /* Return the first parameter. */
\r
747 &xParameterStringLength /* Store the parameter string length. */
\r
750 /* Sanity check something was returned. */
\r
751 configASSERT( pcSourceFile );
\r
753 /* Terminate the string. */
\r
754 pcSourceFile[ xParameterStringLength ] = 0x00;
\r
756 /* See if the source file exists, openm it if it does. */
\r
757 lSourceFildes = red_open( pcSourceFile, RED_O_RDONLY );
\r
759 if( lSourceFildes == -1 )
\r
761 sprintf( pcWriteBuffer, "Source file does not exist" );
\r
765 /* Create the destination file, error if it already exists. */
\r
766 lDestinationFildes = red_open( pcDestinationFile, RED_O_CREAT|RED_O_EXCL|RED_O_WRONLY );
\r
768 if( lDestinationFildes == -1 )
\r
770 sprintf( pcWriteBuffer, "Error: Destination file already exists" );
\r
774 if( prvPerformCopy( lSourceFildes, lDestinationFildes, pcWriteBuffer, xWriteBufferLen ) == pdPASS )
\r
776 sprintf( pcWriteBuffer, "Copy made" );
\r
780 sprintf( pcWriteBuffer, "Error during copy" );
\r
783 red_close( lDestinationFildes );
\r
786 red_close( lSourceFildes );
\r
789 strcat( pcWriteBuffer, cliNEW_LINE );
\r
793 /*-----------------------------------------------------------*/
\r
795 static BaseType_t prvCREATECommand( char *pcWriteBuffer, size_t xWriteBufferLen, const char *pcCommandString )
\r
797 const char *pcParameter;
\r
798 BaseType_t xParameterStringLength;
\r
801 /* This function assumes xWriteBufferLen is large enough! */
\r
802 ( void ) xWriteBufferLen;
\r
804 /* Obtain the parameter string. */
\r
805 pcParameter = FreeRTOS_CLIGetParameter
\r
807 pcCommandString, /* The command string itself. */
\r
808 1, /* Return the first parameter. */
\r
809 &xParameterStringLength /* Store the parameter string length. */
\r
812 /* Sanity check something was returned. */
\r
813 configASSERT( pcParameter );
\r
815 /* Attempt to create the file. */
\r
816 lFildes = red_open( pcParameter, RED_O_CREAT|RED_O_EXCL|RED_O_RDWR );
\r
818 if( lFildes != -1 )
\r
820 sprintf( pcWriteBuffer, "%s was created", pcParameter );
\r
821 red_close( lFildes );
\r
825 /* User-friendly messages for common errors. */
\r
826 switch( red_errno )
\r
830 sprintf( pcWriteBuffer, "Bad file path." );
\r
834 sprintf( pcWriteBuffer, "File already exists." );
\r
838 sprintf( pcWriteBuffer, "Error %d creating file.", ( int ) red_errno );
\r
843 strcat( pcWriteBuffer, cliNEW_LINE );
\r
847 /*-----------------------------------------------------------*/
\r
849 static BaseType_t prvMKDIRCommand( char *pcWriteBuffer, size_t xWriteBufferLen, const char *pcCommandString )
\r
851 const char *pcParameter;
\r
852 BaseType_t xParameterStringLength;
\r
855 /* This function assumes xWriteBufferLen is large enough! */
\r
856 ( void ) xWriteBufferLen;
\r
858 /* Obtain the parameter string. */
\r
859 pcParameter = FreeRTOS_CLIGetParameter
\r
861 pcCommandString, /* The command string itself. */
\r
862 1, /* Return the first parameter. */
\r
863 &xParameterStringLength /* Store the parameter string length. */
\r
866 /* Sanity check something was returned. */
\r
867 configASSERT( pcParameter );
\r
869 /* Attempt to create the file. */
\r
870 lStatus = red_mkdir( pcParameter );
\r
874 sprintf( pcWriteBuffer, "%s was created", pcParameter );
\r
878 /* User-friendly messages for common errors. */
\r
879 switch( red_errno )
\r
883 sprintf( pcWriteBuffer, "Bad file path." );
\r
887 sprintf( pcWriteBuffer, "Directory already exists." );
\r
891 sprintf( pcWriteBuffer, "Error %d creating directory.", ( int ) red_errno );
\r
896 strcat( pcWriteBuffer, cliNEW_LINE );
\r
900 /*-----------------------------------------------------------*/
\r
902 static BaseType_t prvRENAMECommand( char *pcWriteBuffer, size_t xWriteBufferLen, const char *pcCommandString )
\r
904 const char *pcDestinationFile;
\r
905 char *pcSourceFile;
\r
906 BaseType_t xParameterStringLength;
\r
909 /* This function assumes xWriteBufferLen is large enough! */
\r
910 ( void ) xWriteBufferLen;
\r
912 /* Obtain the name of the destination file. */
\r
913 pcDestinationFile = FreeRTOS_CLIGetParameter
\r
915 pcCommandString, /* The command string itself. */
\r
916 2, /* Return the second parameter. */
\r
917 &xParameterStringLength /* Store the parameter string length. */
\r
920 /* Sanity check something was returned. */
\r
921 configASSERT( pcDestinationFile );
\r
923 /* Obtain the name of the source file. */
\r
924 pcSourceFile = ( char * ) FreeRTOS_CLIGetParameter
\r
926 pcCommandString, /* The command string itself. */
\r
927 1, /* Return the first parameter. */
\r
928 &xParameterStringLength /* Store the parameter string length. */
\r
931 /* Sanity check something was returned. */
\r
932 configASSERT( pcSourceFile );
\r
934 /* Terminate the string. */
\r
935 pcSourceFile[ xParameterStringLength ] = 0x00;
\r
937 /* Attempt to rename the file. */
\r
938 lStatus = red_rename( pcSourceFile, pcDestinationFile );
\r
942 sprintf( pcWriteBuffer, "%s was renamed to %s", pcSourceFile, pcDestinationFile );
\r
946 /* User-friendly messages for common errors. */
\r
947 switch( red_errno )
\r
952 sprintf( pcWriteBuffer, "Bad file path." );
\r
955 /* This will only be seen if POSIX rename is disabled. */
\r
957 sprintf( pcWriteBuffer, "Destination already exists." );
\r
961 sprintf( pcWriteBuffer, "Error %d renaming file.", ( int ) red_errno );
\r
966 strcat( pcWriteBuffer, cliNEW_LINE );
\r
970 /*-----------------------------------------------------------*/
\r
972 static BaseType_t prvLINKCommand( char *pcWriteBuffer, size_t xWriteBufferLen, const char *pcCommandString )
\r
974 const char *pcDestinationFile;
\r
975 char *pcSourceFile;
\r
976 BaseType_t xParameterStringLength;
\r
979 /* This function assumes xWriteBufferLen is large enough! */
\r
980 ( void ) xWriteBufferLen;
\r
982 /* Obtain the name of the destination file. */
\r
983 pcDestinationFile = FreeRTOS_CLIGetParameter
\r
985 pcCommandString, /* The command string itself. */
\r
986 2, /* Return the second parameter. */
\r
987 &xParameterStringLength /* Store the parameter string length. */
\r
990 /* Sanity check something was returned. */
\r
991 configASSERT( pcDestinationFile );
\r
993 /* Obtain the name of the source file. */
\r
994 pcSourceFile = ( char * ) FreeRTOS_CLIGetParameter
\r
996 pcCommandString, /* The command string itself. */
\r
997 1, /* Return the first parameter. */
\r
998 &xParameterStringLength /* Store the parameter string length. */
\r
1001 /* Sanity check something was returned. */
\r
1002 configASSERT( pcSourceFile );
\r
1004 /* Terminate the string. */
\r
1005 pcSourceFile[ xParameterStringLength ] = 0x00;
\r
1007 /* Attempt to create the hard link. */
\r
1008 lStatus = red_link( pcSourceFile, pcDestinationFile );
\r
1010 if( lStatus == 0 )
\r
1012 sprintf( pcWriteBuffer, "%s was linked to %s", pcDestinationFile, pcSourceFile );
\r
1016 /* User-friendly messages for common errors. */
\r
1017 switch( red_errno )
\r
1019 case RED_ENOTDIR :
\r
1021 sprintf( pcWriteBuffer, "Bad file path." );
\r
1025 sprintf( pcWriteBuffer, "Cannot link a directory." );
\r
1029 sprintf( pcWriteBuffer, "Too many hard links." );
\r
1033 sprintf( pcWriteBuffer, "Error %d linking file.", ( int ) red_errno );
\r
1038 strcat( pcWriteBuffer, cliNEW_LINE );
\r
1042 /*-----------------------------------------------------------*/
\r
1044 static BaseType_t prvSTATCommand( char *pcWriteBuffer, size_t xWriteBufferLen, const char *pcCommandString )
\r
1046 const char *pcParameter, *pcModeString;
\r
1047 BaseType_t xParameterStringLength;
\r
1049 int32_t lFildes, lStatus;
\r
1051 /* Ensure the buffer leaves space for the \r\n. */
\r
1052 configASSERT( xWriteBufferLen > ( strlen( cliNEW_LINE ) * 2 ) );
\r
1053 xWriteBufferLen -= strlen( cliNEW_LINE );
\r
1055 /* Find the file name. */
\r
1056 pcParameter = FreeRTOS_CLIGetParameter
\r
1058 pcCommandString, /* The command string itself. */
\r
1059 1, /* Return the first parameter. */
\r
1060 &xParameterStringLength /* Store the parameter string length. */
\r
1063 /* Sanity check something was returned. */
\r
1064 configASSERT( pcParameter );
\r
1066 /* Attempt to open the requested file. */
\r
1067 lFildes = red_open( pcParameter, RED_O_RDONLY );
\r
1068 if( lFildes == -1 )
\r
1070 /* User-friendly messages for common errors. */
\r
1071 switch( red_errno )
\r
1074 case RED_ENOTDIR :
\r
1075 snprintf( pcWriteBuffer, xWriteBufferLen, "File not found." );
\r
1079 snprintf( pcWriteBuffer, xWriteBufferLen, "Error %d opening file.", ( int ) red_errno );
\r
1085 lStatus = red_fstat( lFildes, &finfo );
\r
1086 if( lStatus == 0 )
\r
1088 if( RED_S_ISDIR( finfo.st_mode ) )
\r
1090 pcModeString = "dir";
\r
1094 pcModeString = "file";
\r
1097 snprintf( pcWriteBuffer, xWriteBufferLen, "ino=%lu mode=0x%04x(%s) nlink=%x size=%lu blocks=%lu",
\r
1098 ( unsigned long ) finfo.st_ino, ( unsigned ) finfo.st_mode, pcModeString,
\r
1099 ( unsigned ) finfo.st_nlink, (unsigned long) finfo.st_size, (unsigned long) finfo.st_blocks );
\r
1103 snprintf( pcWriteBuffer, xWriteBufferLen, "Error %d querying file.", ( int ) red_errno );
\r
1106 red_close( lFildes );
\r
1109 strcat( pcWriteBuffer, cliNEW_LINE );
\r
1113 /*-----------------------------------------------------------*/
\r
1115 static BaseType_t prvSTATFSCommand( char *pcWriteBuffer, size_t xWriteBufferLen, const char *pcCommandString )
\r
1120 /* Avoid compiler warnings. */
\r
1121 ( void ) pcCommandString;
\r
1123 /* Ensure the buffer leaves space for the \r\n. */
\r
1124 configASSERT( xWriteBufferLen > ( strlen( cliNEW_LINE ) * 2 ) );
\r
1125 xWriteBufferLen -= strlen( cliNEW_LINE );
\r
1127 lStatus = red_statvfs( "", &fsinfo );
\r
1129 if( lStatus == -1 )
\r
1131 snprintf( pcWriteBuffer, xWriteBufferLen, "Error %d querying file system.", ( int ) red_errno );
\r
1135 snprintf( pcWriteBuffer, xWriteBufferLen,
\r
1136 "Block size: %lu\r\n"
\r
1137 "Block count: %lu\r\n"
\r
1138 "Free blocks: %lu\r\n"
\r
1139 "Inode count: %lu\r\n"
\r
1140 "Free inodes: %lu\r\n",
\r
1141 ( unsigned long ) fsinfo.f_bsize, ( unsigned long ) fsinfo.f_blocks,
\r
1142 ( unsigned long ) fsinfo.f_bfree, ( unsigned long ) fsinfo.f_files,
\r
1143 ( unsigned long ) fsinfo.f_ffree );
\r
1146 strcat( pcWriteBuffer, cliNEW_LINE );
\r
1150 /*-----------------------------------------------------------*/
\r
1152 static BaseType_t prvFORMATCommand( char *pcWriteBuffer, size_t xWriteBufferLen, const char *pcCommandString )
\r
1156 /* Avoid compiler warnings. */
\r
1157 ( void ) pcCommandString;
\r
1159 /* This function assumes xWriteBufferLen is large enough! */
\r
1160 ( void ) xWriteBufferLen;
\r
1162 /* File system volumes cannot be formatted while mounted. */
\r
1163 lStatus = red_umount( "" );
\r
1164 if( lStatus == -1 )
\r
1166 sprintf( pcWriteBuffer, "Error %d during unmount.", ( int ) red_errno );
\r
1170 /* Re-format the file system volume. */
\r
1171 lStatus = red_format( "" );
\r
1173 if( lStatus == -1 )
\r
1175 sprintf( pcWriteBuffer, "Error %d during format.", ( int ) red_errno );
\r
1179 /* Mount again so that other commands will work properly. */
\r
1180 lStatus = red_mount( "" );
\r
1182 if( lStatus == -1 )
\r
1184 sprintf( pcWriteBuffer, "Error %d during mount.", ( int ) red_errno );
\r
1188 strcpy( pcWriteBuffer, "Format successful." );
\r
1193 strcat( pcWriteBuffer, cliNEW_LINE );
\r
1197 /*-----------------------------------------------------------*/
\r
1199 static BaseType_t prvTRANSACTCommand( char *pcWriteBuffer, size_t xWriteBufferLen, const char *pcCommandString )
\r
1203 /* Avoid compiler warnings. */
\r
1204 ( void ) pcCommandString;
\r
1206 /* This function assumes xWriteBufferLen is large enough! */
\r
1207 ( void ) xWriteBufferLen;
\r
1209 /* Save the original transaction mask settings. */
\r
1210 lStatus = red_transact( "" );
\r
1212 if( lStatus == -1 )
\r
1214 sprintf( pcWriteBuffer, "Error %d during transaction point.", ( int ) red_errno );
\r
1218 strcpy( pcWriteBuffer, "Transaction point successful." );
\r
1221 strcat( pcWriteBuffer, cliNEW_LINE );
\r
1225 /*-----------------------------------------------------------*/
\r
1227 static BaseType_t prvTRANSMASKGETCommand( char *pcWriteBuffer, size_t xWriteBufferLen, const char *pcCommandString )
\r
1229 uint32_t ulEventMask;
\r
1232 /* Avoid compiler warnings. */
\r
1233 ( void ) pcCommandString;
\r
1235 /* Ensure the buffer leaves space for the \r\n. */
\r
1236 configASSERT( xWriteBufferLen > ( strlen( cliNEW_LINE ) * 2 ) );
\r
1237 xWriteBufferLen -= strlen( cliNEW_LINE );
\r
1239 lStatus = red_gettransmask( "", &ulEventMask );
\r
1240 if( lStatus == -1 )
\r
1242 snprintf( pcWriteBuffer, xWriteBufferLen, "Error %d retrieving automatic transaction event mask.", ( int ) red_errno );
\r
1246 snprintf( pcWriteBuffer, xWriteBufferLen,
\r
1247 "Current automatic transaction event mask: 0x%04lx\r\n"
\r
1248 "RED_TRANSACT_UMOUNT (0x0001): %s\r\n"
\r
1249 "RED_TRANSACT_CREAT (0x0002): %s\r\n"
\r
1250 "RED_TRANSACT_UNLINK (0x0004): %s\r\n"
\r
1251 "RED_TRANSACT_MKDIR (0x0008): %s\r\n"
\r
1252 "RED_TRANSACT_RENAME (0x0010): %s\r\n"
\r
1253 "RED_TRANSACT_LINK (0x0020): %s\r\n"
\r
1254 "RED_TRANSACT_CLOSE (0x0040): %s\r\n"
\r
1255 "RED_TRANSACT_WRITE (0x0080): %s\r\n"
\r
1256 "RED_TRANSACT_FSYNC (0x0100): %s\r\n"
\r
1257 "RED_TRANSACT_TRUNCATE (0x0200): %s\r\n"
\r
1258 "RED_TRANSACT_VOLFULL (0x0400): %s\r\n",
\r
1259 ( unsigned long ) ulEventMask,
\r
1260 ( ulEventMask & RED_TRANSACT_UMOUNT ) ? "Enabled" : "Disabled",
\r
1261 ( ulEventMask & RED_TRANSACT_CREAT ) ? "Enabled" : "Disabled",
\r
1262 ( ulEventMask & RED_TRANSACT_UNLINK ) ? "Enabled" : "Disabled",
\r
1263 ( ulEventMask & RED_TRANSACT_MKDIR ) ? "Enabled" : "Disabled",
\r
1264 ( ulEventMask & RED_TRANSACT_RENAME ) ? "Enabled" : "Disabled",
\r
1265 ( ulEventMask & RED_TRANSACT_LINK ) ? "Enabled" : "Disabled",
\r
1266 ( ulEventMask & RED_TRANSACT_CLOSE ) ? "Enabled" : "Disabled",
\r
1267 ( ulEventMask & RED_TRANSACT_WRITE ) ? "Enabled" : "Disabled",
\r
1268 ( ulEventMask & RED_TRANSACT_FSYNC ) ? "Enabled" : "Disabled",
\r
1269 ( ulEventMask & RED_TRANSACT_TRUNCATE ) ? "Enabled" : "Disabled",
\r
1270 ( ulEventMask & RED_TRANSACT_VOLFULL ) ? "Enabled" : "Disabled" );
\r
1273 strcat( pcWriteBuffer, cliNEW_LINE );
\r
1277 /*-----------------------------------------------------------*/
\r
1279 static BaseType_t prvTRANSMASKSETCommand( char *pcWriteBuffer, size_t xWriteBufferLen, const char *pcCommandString )
\r
1281 const char *pcParameter;
\r
1282 BaseType_t xParameterStringLength;
\r
1283 uint32_t ulEventMask;
\r
1286 /* Ensure the buffer leaves space for the \r\n. */
\r
1287 configASSERT( xWriteBufferLen > ( strlen( cliNEW_LINE ) * 2 ) );
\r
1288 xWriteBufferLen -= strlen( cliNEW_LINE );
\r
1290 /* Obtain the parameter string. */
\r
1291 pcParameter = FreeRTOS_CLIGetParameter
\r
1293 pcCommandString, /* The command string itself. */
\r
1294 1, /* Return the first parameter. */
\r
1295 &xParameterStringLength /* Store the parameter string length. */
\r
1298 /* Sanity check something was returned. */
\r
1299 configASSERT( pcParameter );
\r
1301 if( ( pcParameter[0] == '0' ) && ( ( pcParameter[1] == 'x' ) || ( pcParameter[1] == 'X' ) ) )
\r
1306 /* Convert the argument into a value. */
\r
1307 RedHtoUL( pcParameter, &ulEventMask );
\r
1309 /* Set the new transaction mask. */
\r
1310 lStatus = red_settransmask( "", ulEventMask );
\r
1311 if( lStatus == -1 )
\r
1313 /* User-friendly messages for common errors. */
\r
1314 switch( red_errno )
\r
1317 snprintf( pcWriteBuffer, xWriteBufferLen, "Invalid bits in transaction mask." );
\r
1321 snprintf( pcWriteBuffer, xWriteBufferLen, "Error %d setting transaction mask.", ( int ) red_errno );
\r
1327 snprintf( pcWriteBuffer, xWriteBufferLen,
\r
1328 "Successfully set automatic transaction mask. Enabled events:\r\n"
\r
1329 "RED_TRANSACT_UMOUNT (0x0001): %s\r\n"
\r
1330 "RED_TRANSACT_CREAT (0x0002): %s\r\n"
\r
1331 "RED_TRANSACT_UNLINK (0x0004): %s\r\n"
\r
1332 "RED_TRANSACT_MKDIR (0x0008): %s\r\n"
\r
1333 "RED_TRANSACT_RENAME (0x0010): %s\r\n"
\r
1334 "RED_TRANSACT_LINK (0x0020): %s\r\n"
\r
1335 "RED_TRANSACT_CLOSE (0x0040): %s\r\n"
\r
1336 "RED_TRANSACT_WRITE (0x0080): %s\r\n"
\r
1337 "RED_TRANSACT_FSYNC (0x0100): %s\r\n"
\r
1338 "RED_TRANSACT_TRUNCATE (0x0200): %s\r\n"
\r
1339 "RED_TRANSACT_VOLFULL (0x0400): %s\r\n",
\r
1340 ( ulEventMask & RED_TRANSACT_UMOUNT ) ? "Enabled" : "Disabled",
\r
1341 ( ulEventMask & RED_TRANSACT_CREAT ) ? "Enabled" : "Disabled",
\r
1342 ( ulEventMask & RED_TRANSACT_UNLINK ) ? "Enabled" : "Disabled",
\r
1343 ( ulEventMask & RED_TRANSACT_MKDIR ) ? "Enabled" : "Disabled",
\r
1344 ( ulEventMask & RED_TRANSACT_RENAME ) ? "Enabled" : "Disabled",
\r
1345 ( ulEventMask & RED_TRANSACT_LINK ) ? "Enabled" : "Disabled",
\r
1346 ( ulEventMask & RED_TRANSACT_CLOSE ) ? "Enabled" : "Disabled",
\r
1347 ( ulEventMask & RED_TRANSACT_WRITE ) ? "Enabled" : "Disabled",
\r
1348 ( ulEventMask & RED_TRANSACT_FSYNC ) ? "Enabled" : "Disabled",
\r
1349 ( ulEventMask & RED_TRANSACT_TRUNCATE ) ? "Enabled" : "Disabled",
\r
1350 ( ulEventMask & RED_TRANSACT_VOLFULL ) ? "Enabled" : "Disabled" );
\r
1353 strcat( pcWriteBuffer, cliNEW_LINE );
\r
1357 /*-----------------------------------------------------------*/
\r
1359 static BaseType_t prvABORTCommand( char *pcWriteBuffer, size_t xWriteBufferLen, const char *pcCommandString )
\r
1361 uint32_t ulEventMask;
\r
1364 /* Avoid compiler warnings. */
\r
1365 ( void ) pcCommandString;
\r
1367 /* This function assumes xWriteBufferLen is large enough! */
\r
1368 ( void ) xWriteBufferLen;
\r
1370 /* Save the original transaction mask settings. */
\r
1371 lStatus = red_gettransmask( "", &ulEventMask );
\r
1373 if( lStatus == -1 )
\r
1375 sprintf( pcWriteBuffer, "Error %d querying transaction mask.", ( int ) red_errno );
\r
1379 /* Make it so that red_umount() will not automatically commit a new
\r
1380 transaction point. */
\r
1381 lStatus = red_settransmask( "", ulEventMask & ~( ( uint32_t ) RED_TRANSACT_UMOUNT ) );
\r
1383 if( lStatus == -1 )
\r
1385 sprintf( pcWriteBuffer, "Error %d setting transaction mask.", ( int ) red_errno );
\r
1389 /* Unmount. Since red_umount() will not transact, all changes which
\r
1390 were not already transacted are rolled back. */
\r
1391 lStatus = red_umount( "" );
\r
1393 if( lStatus == -1 )
\r
1395 sprintf( pcWriteBuffer, "Error %d during unmount.", ( int ) red_errno );
\r
1399 /* Mount. Mount always starts from the last transaction point. */
\r
1400 lStatus = red_mount( "" );
\r
1402 if( lStatus == -1 )
\r
1404 sprintf( pcWriteBuffer, "Error %d during mount.", ( int ) red_errno );
\r
1408 strcpy( pcWriteBuffer, "Working state changes succesfully aborted." );
\r
1412 /* Restore the original transaction mask settings. */
\r
1413 red_settransmask( "", ulEventMask );
\r
1417 strcat( pcWriteBuffer, cliNEW_LINE );
\r
1421 /*-----------------------------------------------------------*/
\r
1423 static BaseType_t prvTESTFSCommand( char *pcWriteBuffer, size_t xWriteBufferLen, const char *pcCommandString )
\r
1425 UBaseType_t uxOriginalPriority;
\r
1426 FSSTRESSPARAM param;
\r
1428 /* Avoid compiler warnings. */
\r
1429 ( void ) xWriteBufferLen;
\r
1430 ( void ) pcCommandString;
\r
1432 /* Limitations in the interaction with the Windows TCP/IP stack require
\r
1433 the command console to run at the idle priority. Raise the priority for
\r
1434 the duration of the tests to ensure there are not multiple switches to the
\r
1435 idle task as in the simulated environment the idle task hook function may
\r
1436 include a (relatively) long delay. */
\r
1437 uxOriginalPriority = uxTaskPriorityGet( NULL );
\r
1438 vTaskPrioritySet( NULL, configMAX_PRIORITIES - 1 );
\r
1440 /* Delete all files to avoid inteferring with the test. */
\r
1445 FsstressDefaultParams(¶m);
\r
1446 param.fVerbose = pdTRUE;
\r
1447 param.ulNops = 10000;
\r
1449 FsstressStart(¶m);
\r
1451 /* Clean up after the test. */
\r
1456 /* Reset back to the original priority. */
\r
1457 vTaskPrioritySet( NULL, uxOriginalPriority );
\r
1459 sprintf( pcWriteBuffer, "%s", "Test results were sent to Windows console" );
\r
1460 strcat( pcWriteBuffer, cliNEW_LINE );
\r
1464 /*-----------------------------------------------------------*/
\r
1466 static BaseType_t prvPerformCopy( int32_t lSourceFildes,
\r
1467 int32_t lDestinationFiledes,
\r
1468 char *pxWriteBuffer,
\r
1469 size_t xWriteBufferLen )
\r
1471 int32_t lBytesRead;
\r
1472 BaseType_t xReturn = pdPASS;
\r
1474 /* Assuming both files are at offset zero. */
\r
1478 /* Read the next block of data. */
\r
1479 lBytesRead = red_read( lSourceFildes, pxWriteBuffer, xWriteBufferLen );
\r
1480 if( lBytesRead <= 0 )
\r
1482 if( lBytesRead == -1)
\r
1484 /* Error reading from file. */
\r
1489 /* No error: reached end of file, time to stop. */
\r
1495 /* Write the block of data to the end of the file. */
\r
1496 if( red_write( lDestinationFiledes, pxWriteBuffer, lBytesRead ) != lBytesRead )
\r
1505 /*-----------------------------------------------------------*/
\r
1507 static void prvCreateFileInfoString( char *pcBuffer, REDDIRENT *pxDirent )
\r
1509 const char *pcFile = "file", *pcDirectory = "directory";
\r
1510 const char *pcAttrib;
\r
1512 /* Point pcAttrib to a string that describes the file. */
\r
1513 if( RED_S_ISDIR(pxDirent->d_stat.st_mode) )
\r
1515 pcAttrib = pcDirectory;
\r
1519 pcAttrib = pcFile;
\r
1522 /* Create a string that includes the file name, the file size and the
\r
1523 attributes string. */
\r
1524 sprintf( pcBuffer, "%s [%s] [size=%lld]", pxDirent->d_name, pcAttrib, pxDirent->d_stat.st_size );
\r