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