]> git.sur5r.net Git - freertos/blob - FreeRTOS-Plus/Demo/FreeRTOS_Plus_FAT_SL_and_CLI_Windows_Simulator/File-Releated-CLI-commands.c
Update version numbers.
[freertos] / FreeRTOS-Plus / Demo / FreeRTOS_Plus_FAT_SL_and_CLI_Windows_Simulator / File-Releated-CLI-commands.c
1 /*\r
2     FreeRTOS V7.5.2 - Copyright (C) 2013 Real Time Engineers Ltd.\r
3 \r
4     FEATURES AND PORTS ARE ADDED TO FREERTOS ALL THE TIME.  PLEASE VISIT\r
5     http://www.FreeRTOS.org TO ENSURE YOU ARE USING THE LATEST VERSION.\r
6 \r
7     ***************************************************************************\r
8      *                                                                       *\r
9      *    FreeRTOS tutorial books are available in pdf and paperback.        *\r
10      *    Complete, revised, and edited pdf reference manuals are also       *\r
11      *    available.                                                         *\r
12      *                                                                       *\r
13      *    Purchasing FreeRTOS documentation will not only help you, by       *\r
14      *    ensuring you get running as quickly as possible and with an        *\r
15      *    in-depth knowledge of how to use FreeRTOS, it will also help       *\r
16      *    the FreeRTOS project to continue with its mission of providing     *\r
17      *    professional grade, cross platform, de facto standard solutions    *\r
18      *    for microcontrollers - completely free of charge!                  *\r
19      *                                                                       *\r
20      *    >>> See http://www.FreeRTOS.org/Documentation for details. <<<     *\r
21      *                                                                       *\r
22      *    Thank you for using FreeRTOS, and thank you for your support!      *\r
23      *                                                                       *\r
24     ***************************************************************************\r
25 \r
26 \r
27     This file is part of the FreeRTOS distribution.\r
28 \r
29     FreeRTOS is free software; you can redistribute it and/or modify it under\r
30     the terms of the GNU General Public License (version 2) as published by the\r
31     Free Software Foundation AND MODIFIED BY the FreeRTOS exception.\r
32 \r
33     >>>>>>NOTE<<<<<< The modification to the GPL is included to allow you to\r
34     distribute a combined work that includes FreeRTOS without being obliged to\r
35     provide the source code for proprietary components outside of the FreeRTOS\r
36     kernel.\r
37 \r
38     FreeRTOS is distributed in the hope that it will be useful, but WITHOUT ANY\r
39     WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS\r
40     FOR A PARTICULAR PURPOSE.  See the GNU General Public License for more\r
41     details. You should have received a copy of the GNU General Public License\r
42     and the FreeRTOS license exception along with FreeRTOS; if not itcan be\r
43     viewed here: http://www.freertos.org/a00114.html and also obtained by\r
44     writing to Real Time Engineers Ltd., contact details for whom are available\r
45     on the FreeRTOS WEB site.\r
46 \r
47     1 tab == 4 spaces!\r
48 \r
49     ***************************************************************************\r
50      *                                                                       *\r
51      *    Having a problem?  Start by reading the FAQ "My application does   *\r
52      *    not run, what could be wrong?"                                     *\r
53      *                                                                       *\r
54      *    http://www.FreeRTOS.org/FAQHelp.html                               *\r
55      *                                                                       *\r
56     ***************************************************************************\r
57 \r
58 \r
59     http://www.FreeRTOS.org - Documentation, books, training, latest versions,\r
60     license and Real Time Engineers Ltd. contact details.\r
61 \r
62     http://www.FreeRTOS.org/plus - A selection of FreeRTOS ecosystem products,\r
63     including FreeRTOS+Trace - an indispensable productivity tool, and our new\r
64     fully thread aware and reentrant UDP/IP stack.\r
65 \r
66     http://www.OpenRTOS.com - Real Time Engineers ltd license FreeRTOS to High\r
67     Integrity Systems, who sell the code with commercial support,\r
68     indemnification and middleware, under the OpenRTOS brand.\r
69 \r
70     http://www.SafeRTOS.com - High Integrity Systems also provide a safety\r
71     engineered and independently SIL3 certified version for use in safety and\r
72     mission critical applications that require provable dependability.\r
73 */\r
74 \r
75 /* FreeRTOS includes. */\r
76 #include "FreeRTOS.h"\r
77 #include "task.h"\r
78 \r
79 /* Standard includes. */\r
80 #include <stdint.h>\r
81 #include <stdio.h>\r
82 #include <stdlib.h>\r
83 \r
84 /* FreeRTOS+CLI includes. */\r
85 #include "FreeRTOS_CLI.h"\r
86 \r
87 /* File system includes. */\r
88 #include "fat_sl.h"\r
89 #include "api_mdriver_ram.h"\r
90 #include "test.h"\r
91 \r
92 #ifdef _WINDOWS_\r
93         #define snprintf _snprintf\r
94 #endif\r
95 \r
96 #define cliNEW_LINE             "\r\n"\r
97 \r
98 /*******************************************************************************\r
99  * See the URL in the comments within main.c for the location of the online\r
100  * documentation.\r
101  ******************************************************************************/\r
102 \r
103 /*\r
104  * Print out information on a single file.\r
105  */\r
106 static void prvCreateFileInfoString( int8_t *pcBuffer, F_FIND *pxFindStruct );\r
107 \r
108 /*\r
109  * Copies an existing file into a newly created file.\r
110  */\r
111 static portBASE_TYPE prvPerformCopy( int8_t *pcSourceFile,\r
112                                                         int32_t lSourceFileLength,\r
113                                                         int8_t *pcDestinationFile,\r
114                                                         int8_t *pxWriteBuffer,\r
115                                                         size_t xWriteBufferLen );\r
116 \r
117 /*\r
118  * Implements the DIR command.\r
119  */\r
120 static portBASE_TYPE prvDIRCommand( int8_t *pcWriteBuffer, size_t xWriteBufferLen, const int8_t *pcCommandString );\r
121 \r
122 /*\r
123  * Implements the CD command.\r
124  */\r
125 static portBASE_TYPE prvCDCommand( int8_t *pcWriteBuffer, size_t xWriteBufferLen, const int8_t *pcCommandString );\r
126 \r
127 /*\r
128  * Implements the DEL command.\r
129  */\r
130 static portBASE_TYPE prvDELCommand( int8_t *pcWriteBuffer, size_t xWriteBufferLen, const int8_t *pcCommandString );\r
131 \r
132 /*\r
133  * Implements the TYPE command.\r
134  */\r
135 static portBASE_TYPE prvTYPECommand( int8_t *pcWriteBuffer, size_t xWriteBufferLen, const int8_t *pcCommandString );\r
136 \r
137 /*\r
138  * Implements the COPY command.\r
139  */\r
140 static portBASE_TYPE prvCOPYCommand( int8_t *pcWriteBuffer, size_t xWriteBufferLen, const int8_t *pcCommandString );\r
141 \r
142 /*\r
143  * Implements the TEST command.\r
144  */\r
145 static portBASE_TYPE prvTESTFSCommand( int8_t *pcWriteBuffer, size_t xWriteBufferLen, const int8_t *pcCommandString );\r
146 \r
147 /* Structure that defines the DIR command line command, which lists all the\r
148 files in the current directory. */\r
149 static const CLI_Command_Definition_t xDIR =\r
150 {\r
151         ( const int8_t * const ) "dir", /* The command string to type. */\r
152         ( const int8_t * const ) "\r\ndir:\r\n Lists the files in the current directory\r\n",\r
153         prvDIRCommand, /* The function to run. */\r
154         0 /* No parameters are expected. */\r
155 };\r
156 \r
157 /* Structure that defines the CD command line command, which changes the\r
158 working directory. */\r
159 static const CLI_Command_Definition_t xCD =\r
160 {\r
161         ( const int8_t * const ) "cd", /* The command string to type. */\r
162         ( const int8_t * const ) "\r\ncd <dir name>:\r\n Changes the working directory\r\n",\r
163         prvCDCommand, /* The function to run. */\r
164         1 /* One parameter is expected. */\r
165 };\r
166 \r
167 /* Structure that defines the TYPE command line command, which prints the\r
168 contents of a file to the console. */\r
169 static const CLI_Command_Definition_t xTYPE =\r
170 {\r
171         ( const int8_t * const ) "type", /* The command string to type. */\r
172         ( const int8_t * const ) "\r\ntype <filename>:\r\n Prints file contents to the terminal\r\n",\r
173         prvTYPECommand, /* The function to run. */\r
174         1 /* One parameter is expected. */\r
175 };\r
176 \r
177 /* Structure that defines the DEL command line command, which deletes a file. */\r
178 static const CLI_Command_Definition_t xDEL =\r
179 {\r
180         ( const int8_t * const ) "del", /* The command string to type. */\r
181         ( const int8_t * const ) "\r\ndel <filename>:\r\n deletes a file or directory\r\n",\r
182         prvDELCommand, /* The function to run. */\r
183         1 /* One parameter is expected. */\r
184 };\r
185 \r
186 /* Structure that defines the COPY command line command, which deletes a file. */\r
187 static const CLI_Command_Definition_t xCOPY =\r
188 {\r
189         ( const int8_t * const ) "copy", /* The command string to type. */\r
190         ( const int8_t * const ) "\r\ncopy <source file> <dest file>:\r\n Copies <source file> to <dest file>\r\n",\r
191         prvCOPYCommand, /* The function to run. */\r
192         2 /* Two parameters are expected. */\r
193 };\r
194 \r
195 /* Structure that defines the TEST command line command, which executes some\r
196 file system driver tests. */\r
197 static const CLI_Command_Definition_t xTEST_FS =\r
198 {\r
199         ( const int8_t * const ) "test-fs", /* The command string to type. */\r
200         ( const int8_t * const ) "\r\ntest-fs:\r\n Executes file system tests.  ALL FILES WILL BE DELETED!!!\r\n",\r
201         prvTESTFSCommand, /* The function to run. */\r
202         0 /* No parameters are expected. */\r
203 };\r
204 \r
205 /*-----------------------------------------------------------*/\r
206 \r
207 void vRegisterFileSystemCLICommands( void )\r
208 {\r
209         /* Register all the command line commands defined immediately above. */\r
210         FreeRTOS_CLIRegisterCommand( &xDIR );\r
211         FreeRTOS_CLIRegisterCommand( &xCD );\r
212         FreeRTOS_CLIRegisterCommand( &xTYPE );\r
213         FreeRTOS_CLIRegisterCommand( &xDEL );\r
214         FreeRTOS_CLIRegisterCommand( &xCOPY );\r
215         FreeRTOS_CLIRegisterCommand( &xTEST_FS );\r
216 }\r
217 /*-----------------------------------------------------------*/\r
218 \r
219 static portBASE_TYPE prvTYPECommand( int8_t *pcWriteBuffer, size_t xWriteBufferLen, const int8_t *pcCommandString )\r
220 {\r
221 int8_t *pcParameter;\r
222 portBASE_TYPE xParameterStringLength, xReturn = pdTRUE;\r
223 static F_FILE *pxFile = NULL;\r
224 int iChar;\r
225 size_t xByte;\r
226 size_t xColumns = 50U;\r
227 \r
228         /* Ensure there is always a null terminator after each character written. */\r
229         memset( pcWriteBuffer, 0x00, xWriteBufferLen );\r
230 \r
231         /* Ensure the buffer leaves space for the \r\n. */\r
232         configASSERT( xWriteBufferLen > ( strlen( cliNEW_LINE ) * 2 ) );\r
233         xWriteBufferLen -= strlen( cliNEW_LINE );\r
234 \r
235         if( xWriteBufferLen < xColumns )\r
236         {\r
237                 /* Ensure the loop that uses xColumns as an end condition does not\r
238                 write off the end of the buffer. */\r
239                 xColumns = xWriteBufferLen;\r
240         }\r
241 \r
242         if( pxFile == NULL )\r
243         {\r
244                 /* The file has not been opened yet.  Find the file name. */\r
245                 pcParameter = ( int8_t * ) FreeRTOS_CLIGetParameter\r
246                                                                         (\r
247                                                                                 pcCommandString,                /* The command string itself. */\r
248                                                                                 1,                                              /* Return the first parameter. */\r
249                                                                                 &xParameterStringLength /* Store the parameter string length. */\r
250                                                                         );\r
251 \r
252                 /* Sanity check something was returned. */\r
253                 configASSERT( pcParameter );\r
254 \r
255                 /* Attempt to open the requested file. */\r
256                 pxFile = f_open( ( const char * ) pcParameter, "r" );\r
257         }\r
258 \r
259         if( pxFile != NULL )\r
260         {\r
261                 /* Read the next chunk of data from the file. */\r
262                 for( xByte = 0; xByte < xColumns; xByte++ )\r
263                 {\r
264                         iChar = f_getc( pxFile );\r
265 \r
266                         if( iChar == -1 )\r
267                         {\r
268                                 /* No more characters to return. */\r
269                                 f_close( pxFile );\r
270                                 pxFile = NULL;\r
271                                 break;\r
272                         }\r
273                         else\r
274                         {\r
275                                 pcWriteBuffer[ xByte ] = ( int8_t ) iChar;\r
276                         }\r
277                 }\r
278         }\r
279 \r
280         if( pxFile == NULL )\r
281         {\r
282                 /* Either the file was not opened, or all the data from the file has\r
283                 been returned and the file is now closed. */\r
284                 xReturn = pdFALSE;\r
285         }\r
286 \r
287         strcat( ( char * ) pcWriteBuffer, cliNEW_LINE );\r
288 \r
289         return xReturn;\r
290 }\r
291 /*-----------------------------------------------------------*/\r
292 \r
293 static portBASE_TYPE prvCDCommand( int8_t *pcWriteBuffer, size_t xWriteBufferLen, const int8_t *pcCommandString )\r
294 {\r
295 int8_t *pcParameter;\r
296 portBASE_TYPE xParameterStringLength;\r
297 unsigned char ucReturned;\r
298 size_t xStringLength;\r
299 \r
300         /* Obtain the parameter string. */\r
301         pcParameter = ( int8_t * ) FreeRTOS_CLIGetParameter\r
302                                                                 (\r
303                                                                         pcCommandString,                /* The command string itself. */\r
304                                                                         1,                                              /* Return the first parameter. */\r
305                                                                         &xParameterStringLength /* Store the parameter string length. */\r
306                                                                 );\r
307 \r
308         /* Sanity check something was returned. */\r
309         configASSERT( pcParameter );\r
310 \r
311         /* Attempt to move to the requested directory. */\r
312         ucReturned = f_chdir( ( char * ) pcParameter );\r
313 \r
314         if( ucReturned == F_NO_ERROR )\r
315         {\r
316                 sprintf( ( char * ) pcWriteBuffer, "In: " );\r
317                 xStringLength = strlen( ( const char * ) pcWriteBuffer );\r
318                 f_getcwd( ( char * ) &( pcWriteBuffer[ xStringLength ] ), ( unsigned char ) ( xWriteBufferLen - xStringLength ) );\r
319         }\r
320         else\r
321         {\r
322                 sprintf( ( char * ) pcWriteBuffer, "Error" );\r
323         }\r
324 \r
325         strcat( ( char * ) pcWriteBuffer, cliNEW_LINE );\r
326 \r
327         return pdFALSE;\r
328 }\r
329 /*-----------------------------------------------------------*/\r
330 \r
331 static portBASE_TYPE prvDIRCommand( int8_t *pcWriteBuffer, size_t xWriteBufferLen, const int8_t *pcCommandString )\r
332 {\r
333 static F_FIND *pxFindStruct = NULL;\r
334 unsigned char ucReturned;\r
335 portBASE_TYPE xReturn = pdFALSE;\r
336 \r
337         /* This assumes pcWriteBuffer is long enough. */\r
338         ( void ) pcCommandString;\r
339 \r
340         /* Ensure the buffer leaves space for the \r\n. */\r
341         configASSERT( xWriteBufferLen > ( strlen( cliNEW_LINE ) * 2 ) );\r
342         xWriteBufferLen -= strlen( cliNEW_LINE );\r
343 \r
344         if( pxFindStruct == NULL )\r
345         {\r
346                 /* This is the first time this function has been executed since the Dir\r
347                 command was run.  Create the find structure. */\r
348                 pxFindStruct = ( F_FIND * ) pvPortMalloc( sizeof( F_FIND ) );\r
349 \r
350                 if( pxFindStruct != NULL )\r
351                 {\r
352                         ucReturned = f_findfirst( "*.*", pxFindStruct );\r
353 \r
354                         if( ucReturned == F_NO_ERROR )\r
355                         {\r
356                                 prvCreateFileInfoString( pcWriteBuffer, pxFindStruct );\r
357                                 xReturn = pdPASS;\r
358                         }\r
359                         else\r
360                         {\r
361                                 snprintf( ( char * ) pcWriteBuffer, xWriteBufferLen, "Error: f_findfirst() failed." );\r
362                         }\r
363                 }\r
364                 else\r
365                 {\r
366                         snprintf( ( char * ) pcWriteBuffer, xWriteBufferLen, "Failed to allocate RAM (using heap_4.c will prevent fragmentation)." );\r
367                 }\r
368         }\r
369         else\r
370         {\r
371                 /* The find struct has already been created.  Find the next file in\r
372                 the directory. */\r
373                 ucReturned = f_findnext( pxFindStruct );\r
374 \r
375                 if( ucReturned == F_NO_ERROR )\r
376                 {\r
377                         prvCreateFileInfoString( pcWriteBuffer, pxFindStruct );\r
378                         xReturn = pdPASS;\r
379                 }\r
380                 else\r
381                 {\r
382                         /* There are no more files.  Free the find structure. */\r
383                         vPortFree( pxFindStruct );\r
384                         pxFindStruct = NULL;\r
385 \r
386                         /* No string to return. */\r
387                         pcWriteBuffer[ 0 ] = 0x00;\r
388                 }\r
389         }\r
390 \r
391         strcat( ( char * ) pcWriteBuffer, cliNEW_LINE );\r
392 \r
393         return xReturn;\r
394 }\r
395 /*-----------------------------------------------------------*/\r
396 \r
397 static portBASE_TYPE prvDELCommand( int8_t *pcWriteBuffer, size_t xWriteBufferLen, const int8_t *pcCommandString )\r
398 {\r
399 int8_t *pcParameter;\r
400 portBASE_TYPE xParameterStringLength;\r
401 unsigned char ucReturned;\r
402 \r
403         /* This function assumes xWriteBufferLen is large enough! */\r
404         ( void ) xWriteBufferLen;\r
405 \r
406         /* Obtain the parameter string. */\r
407         pcParameter = ( int8_t * ) FreeRTOS_CLIGetParameter\r
408                                                                 (\r
409                                                                         pcCommandString,                /* The command string itself. */\r
410                                                                         1,                                              /* Return the first parameter. */\r
411                                                                         &xParameterStringLength /* Store the parameter string length. */\r
412                                                                 );\r
413 \r
414         /* Sanity check something was returned. */\r
415         configASSERT( pcParameter );\r
416 \r
417         /* Attempt to delete the file. */\r
418         ucReturned = f_delete( ( const char * ) pcParameter );\r
419 \r
420         if( ucReturned == F_NO_ERROR )\r
421         {\r
422                 sprintf( ( char * ) pcWriteBuffer, "%s was deleted", pcParameter );\r
423         }\r
424         else\r
425         {\r
426                 sprintf( ( char * ) pcWriteBuffer, "Error" );\r
427         }\r
428 \r
429         strcat( ( char * ) pcWriteBuffer, cliNEW_LINE );\r
430 \r
431         return pdFALSE;\r
432 }\r
433 /*-----------------------------------------------------------*/\r
434 \r
435 static portBASE_TYPE prvTESTFSCommand( int8_t *pcWriteBuffer, size_t xWriteBufferLen, const int8_t *pcCommandString )\r
436 {\r
437 unsigned portBASE_TYPE uxOriginalPriority;\r
438 \r
439         /* Avoid compiler warnings. */\r
440         ( void ) xWriteBufferLen;\r
441         ( void ) pcCommandString;\r
442 \r
443         /* Limitations in the interaction with the Windows TCP/IP stack require\r
444         the command console to run at the idle priority.  Raise the priority for\r
445         the duration of the tests to ensure there are not multiple switches to the\r
446         idle task as in the simulated environment the idle task hook function may\r
447         include a (relatively) long delay. */\r
448         uxOriginalPriority = uxTaskPriorityGet( NULL );\r
449         vTaskPrioritySet( NULL, configMAX_PRIORITIES - 1 );\r
450 \r
451         f_dotest( 0 );\r
452 \r
453         /* Reset back to the original priority. */\r
454         vTaskPrioritySet( NULL, uxOriginalPriority );\r
455 \r
456         sprintf( ( char * ) pcWriteBuffer, "%s", "Test results were sent to Windows console" );\r
457 \r
458         return pdFALSE;\r
459 }\r
460 /*-----------------------------------------------------------*/\r
461 \r
462 static portBASE_TYPE prvCOPYCommand( int8_t *pcWriteBuffer, size_t xWriteBufferLen, const int8_t *pcCommandString )\r
463 {\r
464 int8_t *pcSourceFile, *pcDestinationFile;\r
465 portBASE_TYPE xParameterStringLength;\r
466 long lSourceLength, lDestinationLength = 0;\r
467 \r
468         /* Obtain the name of the destination file. */\r
469         pcDestinationFile = ( int8_t * ) FreeRTOS_CLIGetParameter\r
470                                                                 (\r
471                                                                         pcCommandString,                /* The command string itself. */\r
472                                                                         2,                                              /* Return the second parameter. */\r
473                                                                         &xParameterStringLength /* Store the parameter string length. */\r
474                                                                 );\r
475 \r
476         /* Sanity check something was returned. */\r
477         configASSERT( pcDestinationFile );\r
478 \r
479         /* Obtain the name of the source file. */\r
480         pcSourceFile = ( int8_t * ) FreeRTOS_CLIGetParameter\r
481                                                                 (\r
482                                                                         pcCommandString,                /* The command string itself. */\r
483                                                                         1,                                              /* Return the first parameter. */\r
484                                                                         &xParameterStringLength /* Store the parameter string length. */\r
485                                                                 );\r
486 \r
487         /* Sanity check something was returned. */\r
488         configASSERT( pcSourceFile );\r
489 \r
490         /* Terminate the string. */\r
491         pcSourceFile[ xParameterStringLength ] = 0x00;\r
492 \r
493         /* See if the source file exists, obtain its length if it does. */\r
494         lSourceLength = f_filelength( ( const char * ) pcSourceFile );\r
495 \r
496         if( lSourceLength == 0 )\r
497         {\r
498                 sprintf( ( char * ) pcWriteBuffer, "Source file does not exist" );\r
499         }\r
500         else\r
501         {\r
502                 /* See if the destination file exists. */\r
503                 lDestinationLength = f_filelength( ( const char * ) pcDestinationFile );\r
504 \r
505                 if( lDestinationLength != 0 )\r
506                 {\r
507                         sprintf( ( char * ) pcWriteBuffer, "Error: Destination file already exists" );\r
508                 }\r
509         }\r
510 \r
511         /* Continue only if the source file exists and the destination file does\r
512         not exist. */\r
513         if( ( lSourceLength != 0 ) && ( lDestinationLength == 0 ) )\r
514         {\r
515                 if( prvPerformCopy( pcSourceFile, lSourceLength, pcDestinationFile, pcWriteBuffer, xWriteBufferLen ) == pdPASS )\r
516                 {\r
517                         sprintf( ( char * ) pcWriteBuffer, "Copy made" );\r
518                 }\r
519                 else\r
520                 {\r
521                         sprintf( ( char * ) pcWriteBuffer, "Error during copy" );\r
522                 }\r
523         }\r
524 \r
525         strcat( ( char * ) pcWriteBuffer, cliNEW_LINE );\r
526 \r
527         return pdFALSE;\r
528 }\r
529 /*-----------------------------------------------------------*/\r
530 \r
531 static portBASE_TYPE prvPerformCopy( int8_t *pcSourceFile,\r
532                                                         int32_t lSourceFileLength,\r
533                                                         int8_t *pcDestinationFile,\r
534                                                         int8_t *pxWriteBuffer,\r
535                                                         size_t xWriteBufferLen )\r
536 {\r
537 int32_t lBytesRead = 0, lBytesToRead, lBytesRemaining;\r
538 F_FILE *pxFile;\r
539 portBASE_TYPE xReturn = pdPASS;\r
540 \r
541         /* NOTE:  Error handling has been omitted for clarity. */\r
542 \r
543         while( lBytesRead < lSourceFileLength )\r
544         {\r
545                 /* How many bytes are left? */\r
546                 lBytesRemaining = lSourceFileLength - lBytesRead;\r
547 \r
548                 /* How many bytes should be read this time around the loop.  Can't\r
549                 read more bytes than will fit into the buffer. */\r
550                 if( lBytesRemaining > ( long ) xWriteBufferLen )\r
551                 {\r
552                         lBytesToRead = ( long ) xWriteBufferLen;\r
553                 }\r
554                 else\r
555                 {\r
556                         lBytesToRead = lBytesRemaining;\r
557                 }\r
558 \r
559                 /* Open the source file, seek past the data that has already been\r
560                 read from the file, read the next block of data, then close the\r
561                 file again so the destination file can be opened. */\r
562                 pxFile = f_open( ( const char * ) pcSourceFile, "r" );\r
563                 if( pxFile != NULL )\r
564                 {\r
565                         f_seek( pxFile, lBytesRead, F_SEEK_SET );\r
566                         f_read( pxWriteBuffer, lBytesToRead, 1, pxFile );\r
567                         f_close( pxFile );\r
568                 }\r
569                 else\r
570                 {\r
571                         xReturn = pdFAIL;\r
572                         break;\r
573                 }\r
574 \r
575                 /* Open the destination file and write the block of data to the end of\r
576                 the file. */\r
577                 pxFile = f_open( ( const char * ) pcDestinationFile, "a" );\r
578                 if( pxFile != NULL )\r
579                 {\r
580                         f_write( pxWriteBuffer, lBytesToRead, 1, pxFile );\r
581                         f_close( pxFile );\r
582                 }\r
583                 else\r
584                 {\r
585                         xReturn = pdFAIL;\r
586                         break;\r
587                 }\r
588 \r
589                 lBytesRead += lBytesToRead;\r
590         }\r
591 \r
592         return xReturn;\r
593 }\r
594 /*-----------------------------------------------------------*/\r
595 \r
596 static void prvCreateFileInfoString( int8_t *pcBuffer, F_FIND *pxFindStruct )\r
597 {\r
598 const char *pcWritableFile = "writable file", *pcReadOnlyFile = "read only file", *pcDirectory = "directory";\r
599 const char * pcAttrib;\r
600 \r
601         /* Point pcAttrib to a string that describes the file. */\r
602         if( ( pxFindStruct->attr & F_ATTR_DIR ) != 0 )\r
603         {\r
604                 pcAttrib = pcDirectory;\r
605         }\r
606         else if( pxFindStruct->attr & F_ATTR_READONLY )\r
607         {\r
608                 pcAttrib = pcReadOnlyFile;\r
609         }\r
610         else\r
611         {\r
612                 pcAttrib = pcWritableFile;\r
613         }\r
614 \r
615         /* Create a string that includes the file name, the file size and the\r
616         attributes string. */\r
617         sprintf( ( char * ) pcBuffer, "%s [%s] [size=%d]", pxFindStruct->filename, pcAttrib, pxFindStruct->filesize );\r
618 }\r