summaryrefslogtreecommitdiff
path: root/nuttx/fs/fs_fat32.c
diff options
context:
space:
mode:
authorpatacongo <patacongo@42af7a65-404d-4744-a932-0658087f49c3>2007-05-29 00:31:17 +0000
committerpatacongo <patacongo@42af7a65-404d-4744-a932-0658087f49c3>2007-05-29 00:31:17 +0000
commit642245aa3c464b76fce9807ca63229770b313027 (patch)
tree39b1938584d32944b1032c47d8003cdf99664769 /nuttx/fs/fs_fat32.c
parenta72bee0b87f055095a1f9e84208dd2c4a363dde2 (diff)
downloadpx4-nuttx-642245aa3c464b76fce9807ca63229770b313027.tar.gz
px4-nuttx-642245aa3c464b76fce9807ca63229770b313027.tar.bz2
px4-nuttx-642245aa3c464b76fce9807ca63229770b313027.zip
Added statfs()
git-svn-id: svn://svn.code.sf.net/p/nuttx/code/trunk@261 42af7a65-404d-4744-a932-0658087f49c3
Diffstat (limited to 'nuttx/fs/fs_fat32.c')
-rw-r--r--nuttx/fs/fs_fat32.c58
1 files changed, 58 insertions, 0 deletions
diff --git a/nuttx/fs/fs_fat32.c b/nuttx/fs/fs_fat32.c
index 6aa58710f..93ea721a9 100644
--- a/nuttx/fs/fs_fat32.c
+++ b/nuttx/fs/fs_fat32.c
@@ -45,6 +45,7 @@
#include <nuttx/config.h>
#include <sys/types.h>
#include <sys/stat.h>
+#include <sys/statfs.h>
#include <stdlib.h>
#include <unistd.h>
#include <string.h>
@@ -93,6 +94,8 @@ static int fat_rewinddir(struct inode *mountpt, struct internal_dir_s *dir);
static int fat_bind(FAR struct inode *blkdriver, const void *data,
void **handle);
static int fat_unbind(void *handle, FAR struct inode **blkdriver);
+static int fat_statfs(struct inode *mountpt, struct statfs *buf);
+
static int fat_unlink(struct inode *mountpt, const char *relpath);
static int fat_mkdir(struct inode *mountpt, const char *relpath,
mode_t mode);
@@ -131,6 +134,8 @@ const struct mountpt_operations fat_operations =
fat_bind,
fat_unbind,
+ fat_statfs,
+
fat_unlink,
fat_mkdir,
fat_rmdir,
@@ -1579,6 +1584,59 @@ static int fat_unbind(void *handle, FAR struct inode **blkdriver)
}
/****************************************************************************
+ * Name: fat_statfs
+ *
+ * Description: Return filesystem statistics
+ *
+ ****************************************************************************/
+
+static int fat_statfs(struct inode *mountpt, struct statfs *buf)
+{
+ struct fat_mountpt_s *fs;
+ int ret;
+
+ /* Sanity checks */
+
+ DEBUGASSERT(mountpt && mountpt->i_private);
+
+ /* Get the mountpoint private data from the inode structure */
+
+ fs = mountpt->i_private;
+
+ /* Check if the mount is still healthy */
+
+ fat_semtake(fs);
+ ret = fat_checkmount(fs);
+ if (ret < 0)
+ {
+ goto errout_with_semaphore;
+ }
+
+ /* Fill in the statfs info */
+
+ memset(buf, 0, sizeof(struct statfs));
+ buf->f_type = MSDOS_SUPER_MAGIC;
+
+ /* We will claim that the optimal transfer size is the size of a cluster in bytes */
+
+ buf->f_bsize = fs->fs_fatsecperclus * fs->fs_hwsectorsize;
+
+ /* Everything else follows in units of clusters */
+
+ buf->f_blocks = fs->fs_nclusters; /* Total data blocks in the file system */
+ ret = fat_nfreeclusters(fs, &buf->f_bfree); /* Free blocks in the file system */
+ buf->f_bavail = buf->f_bfree; /* Free blocks avail to non-superuser */
+ buf->f_namelen = (8+1+3); /* Maximum length of filenames */
+
+ fat_semgive(fs);
+ return OK;
+
+errout_with_semaphore:
+ fat_semgive(fs);
+ return ret;
+}
+
+/****************************************************************************
* Name: fat_unlink
*
* Description: Remove a file