A fork of the original SDFileSystem, added only stat() for getting file information.

Dependents:   FRDM_K64F_IOT

Added code to the original SDFileSystem to export the stat() command. It would now be possible to get the FILEINFO struct of a directory entry to get information such as file size, etc.

SDFileSystem2 usage

#include "SDFileSystem.h"
SDFileSystem sd(p5,p6,p7,p8,"sd"); // mosi, miso, sck, cs 

static void cmd_ls(Stream * chp, int argc, char * argv[])
{
   DIR * dp;
   struct dirent * dirp;
   FILINFO fileInfo;
   char dirroot[256];
   
   if (argc >= 1)
       sprintf(dirroot, "/sd/%s", argv[0]);
   else
       sprintf(dirroot, "/sd");
   
   chp->printf("Listing directory [%s]\r\n", dirroot);
   
   dp = opendir(dirroot);			
   while((dirp = readdir(dp)) != NULL)
   {
       if (sd.stat(dirp->d_name, &fileInfo) == 0)
       {
           if (fileInfo.fattrib & AM_DIR )
                   chp->printf("<DIR>\t\t");
           else
                   chp->printf("%ld\t\t", fileInfo.fsize);
       }
       chp->printf("%s\r\n", dirp->d_name);
   }
   closedir(dp);
}
Committer:
vpcola
Date:
Tue Apr 28 16:55:30 2015 +0000
Revision:
0:572d27f56fcd
Added stat() to get file information

Who changed what in which revision?

UserRevisionLine numberNew contents of line
vpcola 0:572d27f56fcd 1 /*-------------------------------------------*/
vpcola 0:572d27f56fcd 2 /* Integer type definitions for FatFs module */
vpcola 0:572d27f56fcd 3 /*-------------------------------------------*/
vpcola 0:572d27f56fcd 4
vpcola 0:572d27f56fcd 5 #ifndef _INTEGER
vpcola 0:572d27f56fcd 6 #define _INTEGER
vpcola 0:572d27f56fcd 7
vpcola 0:572d27f56fcd 8 #ifdef _WIN32 /* FatFs development platform */
vpcola 0:572d27f56fcd 9
vpcola 0:572d27f56fcd 10 #include <windows.h>
vpcola 0:572d27f56fcd 11 #include <tchar.h>
vpcola 0:572d27f56fcd 12
vpcola 0:572d27f56fcd 13 #else /* Embedded platform */
vpcola 0:572d27f56fcd 14
vpcola 0:572d27f56fcd 15 /* These types must be 16-bit, 32-bit or larger integer */
vpcola 0:572d27f56fcd 16 typedef int INT;
vpcola 0:572d27f56fcd 17 typedef unsigned int UINT;
vpcola 0:572d27f56fcd 18
vpcola 0:572d27f56fcd 19 /* These types must be 8-bit integer */
vpcola 0:572d27f56fcd 20 typedef char CHAR;
vpcola 0:572d27f56fcd 21 typedef unsigned char UCHAR;
vpcola 0:572d27f56fcd 22 typedef unsigned char BYTE;
vpcola 0:572d27f56fcd 23
vpcola 0:572d27f56fcd 24 /* These types must be 16-bit integer */
vpcola 0:572d27f56fcd 25 typedef short SHORT;
vpcola 0:572d27f56fcd 26 typedef unsigned short USHORT;
vpcola 0:572d27f56fcd 27 typedef unsigned short WORD;
vpcola 0:572d27f56fcd 28 typedef unsigned short WCHAR;
vpcola 0:572d27f56fcd 29
vpcola 0:572d27f56fcd 30 /* These types must be 32-bit integer */
vpcola 0:572d27f56fcd 31 typedef long LONG;
vpcola 0:572d27f56fcd 32 typedef unsigned long ULONG;
vpcola 0:572d27f56fcd 33 typedef unsigned long DWORD;
vpcola 0:572d27f56fcd 34
vpcola 0:572d27f56fcd 35 #endif
vpcola 0:572d27f56fcd 36
vpcola 0:572d27f56fcd 37 #endif