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 / FatFs - FAT file system module configuration file R0.09a (C)ChaN, 2012
vpcola 0:572d27f56fcd 3 /----------------------------------------------------------------------------/
vpcola 0:572d27f56fcd 4 /
vpcola 0:572d27f56fcd 5 / CAUTION! Do not forget to make clean the project after any changes to
vpcola 0:572d27f56fcd 6 / the configuration options.
vpcola 0:572d27f56fcd 7 /
vpcola 0:572d27f56fcd 8 /----------------------------------------------------------------------------*/
vpcola 0:572d27f56fcd 9 #ifndef _FFCONF
vpcola 0:572d27f56fcd 10 #define _FFCONF 4004 /* Revision ID */
vpcola 0:572d27f56fcd 11
vpcola 0:572d27f56fcd 12 #define FFS_DBG 0
vpcola 0:572d27f56fcd 13
vpcola 0:572d27f56fcd 14 /*---------------------------------------------------------------------------/
vpcola 0:572d27f56fcd 15 / Functions and Buffer Configurations
vpcola 0:572d27f56fcd 16 /----------------------------------------------------------------------------*/
vpcola 0:572d27f56fcd 17
vpcola 0:572d27f56fcd 18 #define _FS_TINY 0 /* 0:Normal or 1:Tiny */
vpcola 0:572d27f56fcd 19 /* When _FS_TINY is set to 1, FatFs uses the sector buffer in the file system
vpcola 0:572d27f56fcd 20 / object instead of the sector buffer in the individual file object for file
vpcola 0:572d27f56fcd 21 / data transfer. This reduces memory consumption 512 bytes each file object. */
vpcola 0:572d27f56fcd 22
vpcola 0:572d27f56fcd 23
vpcola 0:572d27f56fcd 24 #define _FS_READONLY 0 /* 0:Read/Write or 1:Read only */
vpcola 0:572d27f56fcd 25 /* Setting _FS_READONLY to 1 defines read only configuration. This removes
vpcola 0:572d27f56fcd 26 / writing functions, f_write, f_sync, f_unlink, f_mkdir, f_chmod, f_rename,
vpcola 0:572d27f56fcd 27 / f_truncate and useless f_getfree. */
vpcola 0:572d27f56fcd 28
vpcola 0:572d27f56fcd 29
vpcola 0:572d27f56fcd 30 #define _FS_MINIMIZE 0 /* 0 to 3 */
vpcola 0:572d27f56fcd 31 /* The _FS_MINIMIZE option defines minimization level to remove some functions.
vpcola 0:572d27f56fcd 32 /
vpcola 0:572d27f56fcd 33 / 0: Full function.
vpcola 0:572d27f56fcd 34 / 1: f_stat, f_getfree, f_unlink, f_mkdir, f_chmod, f_truncate and f_rename
vpcola 0:572d27f56fcd 35 / are removed.
vpcola 0:572d27f56fcd 36 / 2: f_opendir and f_readdir are removed in addition to 1.
vpcola 0:572d27f56fcd 37 / 3: f_lseek is removed in addition to 2. */
vpcola 0:572d27f56fcd 38
vpcola 0:572d27f56fcd 39
vpcola 0:572d27f56fcd 40 #define _USE_STRFUNC 0 /* 0:Disable or 1-2:Enable */
vpcola 0:572d27f56fcd 41 /* To enable string functions, set _USE_STRFUNC to 1 or 2. */
vpcola 0:572d27f56fcd 42
vpcola 0:572d27f56fcd 43
vpcola 0:572d27f56fcd 44 #define _USE_MKFS 1 /* 0:Disable or 1:Enable */
vpcola 0:572d27f56fcd 45 /* To enable f_mkfs function, set _USE_MKFS to 1 and set _FS_READONLY to 0 */
vpcola 0:572d27f56fcd 46
vpcola 0:572d27f56fcd 47
vpcola 0:572d27f56fcd 48 #define _USE_FORWARD 0 /* 0:Disable or 1:Enable */
vpcola 0:572d27f56fcd 49 /* To enable f_forward function, set _USE_FORWARD to 1 and set _FS_TINY to 1. */
vpcola 0:572d27f56fcd 50
vpcola 0:572d27f56fcd 51
vpcola 0:572d27f56fcd 52 #define _USE_FASTSEEK 0 /* 0:Disable or 1:Enable */
vpcola 0:572d27f56fcd 53 /* To enable fast seek feature, set _USE_FASTSEEK to 1. */
vpcola 0:572d27f56fcd 54
vpcola 0:572d27f56fcd 55
vpcola 0:572d27f56fcd 56
vpcola 0:572d27f56fcd 57 /*---------------------------------------------------------------------------/
vpcola 0:572d27f56fcd 58 / Locale and Namespace Configurations
vpcola 0:572d27f56fcd 59 /----------------------------------------------------------------------------*/
vpcola 0:572d27f56fcd 60
vpcola 0:572d27f56fcd 61 #define _CODE_PAGE 858
vpcola 0:572d27f56fcd 62 /* The _CODE_PAGE specifies the OEM code page to be used on the target system.
vpcola 0:572d27f56fcd 63 / Incorrect setting of the code page can cause a file open failure.
vpcola 0:572d27f56fcd 64 /
vpcola 0:572d27f56fcd 65 / 932 - Japanese Shift-JIS (DBCS, OEM, Windows)
vpcola 0:572d27f56fcd 66 / 936 - Simplified Chinese GBK (DBCS, OEM, Windows)
vpcola 0:572d27f56fcd 67 / 949 - Korean (DBCS, OEM, Windows)
vpcola 0:572d27f56fcd 68 / 950 - Traditional Chinese Big5 (DBCS, OEM, Windows)
vpcola 0:572d27f56fcd 69 / 1250 - Central Europe (Windows)
vpcola 0:572d27f56fcd 70 / 1251 - Cyrillic (Windows)
vpcola 0:572d27f56fcd 71 / 1252 - Latin 1 (Windows)
vpcola 0:572d27f56fcd 72 / 1253 - Greek (Windows)
vpcola 0:572d27f56fcd 73 / 1254 - Turkish (Windows)
vpcola 0:572d27f56fcd 74 / 1255 - Hebrew (Windows)
vpcola 0:572d27f56fcd 75 / 1256 - Arabic (Windows)
vpcola 0:572d27f56fcd 76 / 1257 - Baltic (Windows)
vpcola 0:572d27f56fcd 77 / 1258 - Vietnam (OEM, Windows)
vpcola 0:572d27f56fcd 78 / 437 - U.S. (OEM)
vpcola 0:572d27f56fcd 79 / 720 - Arabic (OEM)
vpcola 0:572d27f56fcd 80 / 737 - Greek (OEM)
vpcola 0:572d27f56fcd 81 / 775 - Baltic (OEM)
vpcola 0:572d27f56fcd 82 / 850 - Multilingual Latin 1 (OEM)
vpcola 0:572d27f56fcd 83 / 858 - Multilingual Latin 1 + Euro (OEM)
vpcola 0:572d27f56fcd 84 / 852 - Latin 2 (OEM)
vpcola 0:572d27f56fcd 85 / 855 - Cyrillic (OEM)
vpcola 0:572d27f56fcd 86 / 866 - Russian (OEM)
vpcola 0:572d27f56fcd 87 / 857 - Turkish (OEM)
vpcola 0:572d27f56fcd 88 / 862 - Hebrew (OEM)
vpcola 0:572d27f56fcd 89 / 874 - Thai (OEM, Windows)
vpcola 0:572d27f56fcd 90 / 1 - ASCII only (Valid for non LFN cfg.)
vpcola 0:572d27f56fcd 91 */
vpcola 0:572d27f56fcd 92
vpcola 0:572d27f56fcd 93
vpcola 0:572d27f56fcd 94 #define _USE_LFN 1 /* 0 to 3 */
vpcola 0:572d27f56fcd 95 #define _MAX_LFN 255 /* Maximum LFN length to handle (12 to 255) */
vpcola 0:572d27f56fcd 96 /* The _USE_LFN option switches the LFN support.
vpcola 0:572d27f56fcd 97 /
vpcola 0:572d27f56fcd 98 / 0: Disable LFN feature. _MAX_LFN and _LFN_UNICODE have no effect.
vpcola 0:572d27f56fcd 99 / 1: Enable LFN with static working buffer on the BSS. Always NOT reentrant.
vpcola 0:572d27f56fcd 100 / 2: Enable LFN with dynamic working buffer on the STACK.
vpcola 0:572d27f56fcd 101 / 3: Enable LFN with dynamic working buffer on the HEAP.
vpcola 0:572d27f56fcd 102 /
vpcola 0:572d27f56fcd 103 / The LFN working buffer occupies (_MAX_LFN + 1) * 2 bytes. To enable LFN,
vpcola 0:572d27f56fcd 104 / Unicode handling functions ff_convert() and ff_wtoupper() must be added
vpcola 0:572d27f56fcd 105 / to the project. When enable to use heap, memory control functions
vpcola 0:572d27f56fcd 106 / ff_memalloc() and ff_memfree() must be added to the project. */
vpcola 0:572d27f56fcd 107
vpcola 0:572d27f56fcd 108
vpcola 0:572d27f56fcd 109 #define _LFN_UNICODE 0 /* 0:ANSI/OEM or 1:Unicode */
vpcola 0:572d27f56fcd 110 /* To switch the character code set on FatFs API to Unicode,
vpcola 0:572d27f56fcd 111 / enable LFN feature and set _LFN_UNICODE to 1. */
vpcola 0:572d27f56fcd 112
vpcola 0:572d27f56fcd 113
vpcola 0:572d27f56fcd 114 #define _FS_RPATH 0 /* 0 to 2 */
vpcola 0:572d27f56fcd 115 /* The _FS_RPATH option configures relative path feature.
vpcola 0:572d27f56fcd 116 /
vpcola 0:572d27f56fcd 117 / 0: Disable relative path feature and remove related functions.
vpcola 0:572d27f56fcd 118 / 1: Enable relative path. f_chdrive() and f_chdir() are available.
vpcola 0:572d27f56fcd 119 / 2: f_getcwd() is available in addition to 1.
vpcola 0:572d27f56fcd 120 /
vpcola 0:572d27f56fcd 121 / Note that output of the f_readdir fnction is affected by this option. */
vpcola 0:572d27f56fcd 122
vpcola 0:572d27f56fcd 123
vpcola 0:572d27f56fcd 124
vpcola 0:572d27f56fcd 125 /*---------------------------------------------------------------------------/
vpcola 0:572d27f56fcd 126 / Physical Drive Configurations
vpcola 0:572d27f56fcd 127 /----------------------------------------------------------------------------*/
vpcola 0:572d27f56fcd 128
vpcola 0:572d27f56fcd 129 #define _VOLUMES 1
vpcola 0:572d27f56fcd 130 /* Number of volumes (logical drives) to be used. */
vpcola 0:572d27f56fcd 131
vpcola 0:572d27f56fcd 132
vpcola 0:572d27f56fcd 133 #define _MAX_SS 512 /* 512, 1024, 2048 or 4096 */
vpcola 0:572d27f56fcd 134 /* Maximum sector size to be handled.
vpcola 0:572d27f56fcd 135 / Always set 512 for memory card and hard disk but a larger value may be
vpcola 0:572d27f56fcd 136 / required for on-board flash memory, floppy disk and optical disk.
vpcola 0:572d27f56fcd 137 / When _MAX_SS is larger than 512, it configures FatFs to variable sector size
vpcola 0:572d27f56fcd 138 / and GET_SECTOR_SIZE command must be implememted to the disk_ioctl function. */
vpcola 0:572d27f56fcd 139
vpcola 0:572d27f56fcd 140
vpcola 0:572d27f56fcd 141 #define _MULTI_PARTITION 0 /* 0:Single partition, 1/2:Enable multiple partition */
vpcola 0:572d27f56fcd 142 /* When set to 0, each volume is bound to the same physical drive number and
vpcola 0:572d27f56fcd 143 / it can mount only first primaly partition. When it is set to 1, each volume
vpcola 0:572d27f56fcd 144 / is tied to the partitions listed in VolToPart[]. */
vpcola 0:572d27f56fcd 145
vpcola 0:572d27f56fcd 146
vpcola 0:572d27f56fcd 147 #define _USE_ERASE 0 /* 0:Disable or 1:Enable */
vpcola 0:572d27f56fcd 148 /* To enable sector erase feature, set _USE_ERASE to 1. CTRL_ERASE_SECTOR command
vpcola 0:572d27f56fcd 149 / should be added to the disk_ioctl functio. */
vpcola 0:572d27f56fcd 150
vpcola 0:572d27f56fcd 151
vpcola 0:572d27f56fcd 152
vpcola 0:572d27f56fcd 153 /*---------------------------------------------------------------------------/
vpcola 0:572d27f56fcd 154 / System Configurations
vpcola 0:572d27f56fcd 155 /----------------------------------------------------------------------------*/
vpcola 0:572d27f56fcd 156
vpcola 0:572d27f56fcd 157 #define _WORD_ACCESS 0 /* 0 or 1 */
vpcola 0:572d27f56fcd 158 /* Set 0 first and it is always compatible with all platforms. The _WORD_ACCESS
vpcola 0:572d27f56fcd 159 / option defines which access method is used to the word data on the FAT volume.
vpcola 0:572d27f56fcd 160 /
vpcola 0:572d27f56fcd 161 / 0: Byte-by-byte access.
vpcola 0:572d27f56fcd 162 / 1: Word access. Do not choose this unless following condition is met.
vpcola 0:572d27f56fcd 163 /
vpcola 0:572d27f56fcd 164 / When the byte order on the memory is big-endian or address miss-aligned word
vpcola 0:572d27f56fcd 165 / access results incorrect behavior, the _WORD_ACCESS must be set to 0.
vpcola 0:572d27f56fcd 166 / If it is not the case, the value can also be set to 1 to improve the
vpcola 0:572d27f56fcd 167 / performance and code size.
vpcola 0:572d27f56fcd 168 */
vpcola 0:572d27f56fcd 169
vpcola 0:572d27f56fcd 170
vpcola 0:572d27f56fcd 171 /* A header file that defines sync object types on the O/S, such as
vpcola 0:572d27f56fcd 172 / windows.h, ucos_ii.h and semphr.h, must be included prior to ff.h. */
vpcola 0:572d27f56fcd 173
vpcola 0:572d27f56fcd 174 #define _FS_REENTRANT 0 /* 0:Disable or 1:Enable */
vpcola 0:572d27f56fcd 175 #define _FS_TIMEOUT 1000 /* Timeout period in unit of time ticks */
vpcola 0:572d27f56fcd 176 #define _SYNC_t HANDLE /* O/S dependent type of sync object. e.g. HANDLE, OS_EVENT*, ID and etc.. */
vpcola 0:572d27f56fcd 177
vpcola 0:572d27f56fcd 178 /* The _FS_REENTRANT option switches the reentrancy (thread safe) of the FatFs module.
vpcola 0:572d27f56fcd 179 /
vpcola 0:572d27f56fcd 180 / 0: Disable reentrancy. _SYNC_t and _FS_TIMEOUT have no effect.
vpcola 0:572d27f56fcd 181 / 1: Enable reentrancy. Also user provided synchronization handlers,
vpcola 0:572d27f56fcd 182 / ff_req_grant, ff_rel_grant, ff_del_syncobj and ff_cre_syncobj
vpcola 0:572d27f56fcd 183 / function must be added to the project. */
vpcola 0:572d27f56fcd 184
vpcola 0:572d27f56fcd 185
vpcola 0:572d27f56fcd 186 #define _FS_LOCK 0 /* 0:Disable or >=1:Enable */
vpcola 0:572d27f56fcd 187 /* To enable file lock control feature, set _FS_LOCK to 1 or greater.
vpcola 0:572d27f56fcd 188 The value defines how many files can be opened simultaneously. */
vpcola 0:572d27f56fcd 189
vpcola 0:572d27f56fcd 190
vpcola 0:572d27f56fcd 191 #endif /* _FFCONFIG */