A fork of the original SDFileSystem, added only stat() for getting file information.
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); }
Diff: FATFileSystem/ChaN/integer.h
- Revision:
- 0:572d27f56fcd
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/FATFileSystem/ChaN/integer.h Tue Apr 28 16:55:30 2015 +0000 @@ -0,0 +1,37 @@ +/*-------------------------------------------*/ +/* Integer type definitions for FatFs module */ +/*-------------------------------------------*/ + +#ifndef _INTEGER +#define _INTEGER + +#ifdef _WIN32 /* FatFs development platform */ + +#include <windows.h> +#include <tchar.h> + +#else /* Embedded platform */ + +/* These types must be 16-bit, 32-bit or larger integer */ +typedef int INT; +typedef unsigned int UINT; + +/* These types must be 8-bit integer */ +typedef char CHAR; +typedef unsigned char UCHAR; +typedef unsigned char BYTE; + +/* These types must be 16-bit integer */ +typedef short SHORT; +typedef unsigned short USHORT; +typedef unsigned short WORD; +typedef unsigned short WCHAR; + +/* These types must be 32-bit integer */ +typedef long LONG; +typedef unsigned long ULONG; +typedef unsigned long DWORD; + +#endif + +#endif