diff --git a/source/fatdir.c b/source/fatdir.c index 1a46c38..a0561c5 100644 --- a/source/fatdir.c +++ b/source/fatdir.c @@ -42,9 +42,10 @@ 2007-01-10 - Chishm * Updated directory iterator functions for DevkitPro r20 - - 2007-09-01 - Chishm + + 2007-10-25 - Chishm * Use CLUSTER_ERROR when an error occurs with the FAT, not CLUSTER_FREE + * Added statvfs functionality */ #include @@ -438,6 +439,46 @@ int _FAT_mkdir_r (struct _reent *r, const char *path, int mode) { return 0; } +int _FAT_statvfs_r (struct _reent *r, const char *path, struct statvfs *buf) +{ + PARTITION* partition = NULL; + u32 freeClusterCount; + + // Get the partition of the requested path + partition = _FAT_partition_getPartitionFromPath (path); + + if (partition == NULL) { + r->_errno = ENODEV; + return -1; + } + + freeClusterCount = _FAT_fat_freeClusterCount (partition); + + // FAT clusters = POSIX blocks + buf->f_bsize = partition->bytesPerCluster; // File system block size. + buf->f_frsize = partition->bytesPerCluster; // Fundamental file system block size. + + buf->f_blocks = partition->fat.lastCluster - CLUSTER_FIRST; // Total number of blocks on file system in units of f_frsize. + buf->f_bfree = freeClusterCount; // Total number of free blocks. + buf->f_bavail = freeClusterCount; // Number of free blocks available to non-privileged process. + + // Treat requests for info on inodes as clusters + buf->f_files = partition->fat.lastCluster - CLUSTER_FIRST; // Total number of file serial numbers. + buf->f_ffree = freeClusterCount; // Total number of free file serial numbers. + buf->f_favail = freeClusterCount; // Number of file serial numbers available to non-privileged process. + + // File system ID. 32bit ioType value + buf->f_fsid = _FAT_disc_hostType(partition->disc); + + // Bit mask of f_flag values. + buf->f_flag = ST_NOSUID /* No support for ST_ISUID and ST_ISGID file mode bits */ + | (partition->readOnly ? ST_RDONLY /* Read only file system */ : 0 ) ; + // Maximum filename length. + buf->f_namemax = MAX_FILENAME_LENGTH; + + return 0; +} + DIR_ITER* _FAT_diropen_r(struct _reent *r, DIR_ITER *dirState, const char *path) { DIR_ENTRY dirEntry; DIR_STATE_STRUCT* state = (DIR_STATE_STRUCT*) (dirState->dirStruct); diff --git a/source/fatdir.h b/source/fatdir.h index 5ad7b3b..55c8f9f 100644 --- a/source/fatdir.h +++ b/source/fatdir.h @@ -36,6 +36,9 @@ 2007-01-10 - Chishm * Updated directory iterator functions for DevkitPro r20 + + 2007-10-25 - Chishm + * Added statvfs functionality */ @@ -44,6 +47,7 @@ #include #include +#include #include #include "common.h" #include "directory.h" @@ -68,6 +72,8 @@ extern int _FAT_rename_r (struct _reent *r, const char *oldName, const char *new extern int _FAT_mkdir_r (struct _reent *r, const char *path, int mode); +extern int _FAT_statvfs_r (struct _reent *r, const char *path, struct statvfs *buf); + /* Directory iterator functions */ diff --git a/source/libfat.c b/source/libfat.c index f4321fc..4271a2f 100644 --- a/source/libfat.c +++ b/source/libfat.c @@ -39,6 +39,9 @@ 2007-01-11 - Chishm * Added missing #include + + 2007-10-25 - Chishm + * Added statvfs functionality */ #include @@ -72,7 +75,8 @@ const devoptab_t dotab_fat = { _FAT_diropen_r, _FAT_dirreset_r, _FAT_dirnext_r, - _FAT_dirclose_r + _FAT_dirclose_r, + _FAT_statvfs_r }; bool fatInit (u32 cacheSize, bool setAsDefaultDevice) {