changeset 2262:c393118a9636

* src/fats.c: Added functionality to the fatfs_getinfo() function to return disk usage information about the filesystem, making this information accessible through the cyg_fs_getinfo() interface. * tests/fatfs1.c: Added code to test the disk usage.
author asl
date Fri, 04 Aug 2006 09:22:04 +0000
parents 04c9eb8c07e9
children b79bf6f1fe6b
files packages/fs/fat/current/ChangeLog packages/fs/fat/current/src/fatfs.c packages/fs/fat/current/tests/fatfs1.c
diffstat 3 files changed, 46 insertions(+), 0 deletions(-) [+]
line wrap: on
line diff
--- a/packages/fs/fat/current/ChangeLog
+++ b/packages/fs/fat/current/ChangeLog
@@ -1,3 +1,11 @@
+2006-08-04  Paul Fine  <pfine@dtccom.com>
+            Andrew Lunn <andrew.lunn@ascom.ch>
+	
+	* src/fats.c: Added functionality to the fatfs_getinfo() function
+	to return disk usage information about the filesystem, making this
+	information accessible through the cyg_fs_getinfo() interface.
+	* tests/fatfs1.c: Added code to test the disk usage.
+	
 2005-07-30  Andrew Lunn  <andrew.lunn@ascom.ch>
 
 	* src/fatfs_supp.c: Correct types to remove compiler warnings.
--- a/packages/fs/fat/current/src/fatfs.c
+++ b/packages/fs/fat/current/src/fatfs.c
@@ -1109,6 +1109,22 @@ fatfs_getinfo(cyg_mtab_entry *mte,
             err = fatfs_get_attrib(mte, dir, name, (cyg_fs_attrib_t*)buf);
             break;
 #endif // CYGCFG_FS_FAT_USE_ATTRIBUTES
+#if defined(CYGSEM_FILEIO_BLOCK_USAGE)
+        case FS_INFO_BLOCK_USAGE: {
+	  cyg_uint32 total_clusters;
+	  cyg_uint32 free_clusters;
+	  struct cyg_fs_block_usage *usage = (struct cyg_fs_block_usage *) buf;
+	  fatfs_disk_t  *disk   = (fatfs_disk_t *) mte->data;
+
+	  err = fatfs_get_disk_usage(disk, &total_clusters, &free_clusters);
+	  if (err)
+	    return err;
+	  usage->total_blocks = total_clusters; 
+	  usage->free_blocks = free_clusters;
+	  usage->block_size = disk->cluster_size;
+	  break;
+	}
+#endif
         default:
             err = EINVAL;
             break;
--- a/packages/fs/fat/current/tests/fatfs1.c
+++ b/packages/fs/fat/current/tests/fatfs1.c
@@ -432,6 +432,9 @@ int main( int argc, char **argv )
 {
     int err;
     int existingdirents=-1;
+#if defined(CYGSEM_FILEIO_BLOCK_USAGE)
+    struct cyg_fs_block_usage usage;
+#endif
 
     CYG_TEST_INIT();
 
@@ -448,6 +451,16 @@ int main( int argc, char **argv )
     listdir( "/", true, -1, &existingdirents );
 
     // --------------------------------------------------------------
+#if defined(CYGSEM_FILEIO_BLOCK_USAGE)
+    err = cyg_fs_getinfo("/", FS_INFO_BLOCK_USAGE, &usage, sizeof(usage));
+    if( err < 0 ) SHOW_RESULT( cyg_fs_getinfo, err );
+    diag_printf("<INFO>: total size: %6lld blocks, %10lld bytes\n",
+		usage.total_blocks, usage.total_blocks * usage.block_size); 
+    diag_printf("<INFO>: free size:  %6lld blocks, %10lld bytes\n",
+		usage.free_blocks, usage.free_blocks * usage.block_size); 
+    diag_printf("<INFO>: block size: %6u bytes\n", usage.block_size);
+#endif
+    // --------------------------------------------------------------
 
     createfile( "/foo", 20257 );
     checkfile( "foo" );
@@ -480,6 +493,15 @@ int main( int argc, char **argv )
     checkfile( "/bar/bundy" );
     comparefiles("/fee", "bundy" );
 
+#if defined(CYGSEM_FILEIO_BLOCK_USAGE)
+    err = cyg_fs_getinfo("/", FS_INFO_BLOCK_USAGE, &usage, sizeof(usage));
+    if( err < 0 ) SHOW_RESULT( cyg_fs_getinfo, err );
+    diag_printf("<INFO>: total size: %6lld blocks, %10lld bytes\n",
+		usage.total_blocks, usage.total_blocks * usage.block_size); 
+    diag_printf("<INFO>: free size:  %6lld blocks, %10lld bytes\n",
+		usage.free_blocks, usage.free_blocks * usage.block_size); 
+    diag_printf("<INFO>: block size: %6u bytes\n", usage.block_size);
+#endif
     // --------------------------------------------------------------
 
     diag_printf("<INFO>: unlink fee\n");