Added statvfs functionality

This commit is contained in:
Michael Chisholm 2007-10-25 12:52:08 +00:00
parent 8cfa906c22
commit 8c319ec76a
3 changed files with 54 additions and 3 deletions

View File

@ -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 <string.h>
@ -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);

View File

@ -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 <sys/reent.h>
#include <sys/stat.h>
#include <sys/statvfs.h>
#include <sys/iosupport.h>
#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
*/

View File

@ -39,6 +39,9 @@
2007-01-11 - Chishm
* Added missing #include <unistd.h>
2007-10-25 - Chishm
* Added statvfs functionality
*/
#include <sys/iosupport.h>
@ -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) {