How to get total size of an SD card with MFS?

cancel
Showing results for 
Search instead for 
Did you mean: 

How to get total size of an SD card with MFS?

Jump to solution
447 Views
dmitriyc
Contributor III

Hello,

I am using MQX with an SD card to log data. I need to be able to indicate to the user the size of the SD card inserted and the amount of space used.

I know there are IOCTL commands for getting the amount of free space, but I do not see anything in the documentation about getting the total space on the disk or the amount of space used (short of iterating through every file on the drive and taking the sum of the sizes).

Labels (1)
Tags (1)
0 Kudos
1 Solution
126 Views
dmitriyc
Contributor III

Found it: IO_IOCTL_LAST_CLUSTER returns the number of the last cluster. This (as far as I know) can be used as the total number of clusters in the file system. To obtain the total size of the filesystem, multiply that by the cluster size. (casting and error checking left out of code example).

  ioctl(fs_ptr, IO_IOCTL_FREE_SPACE, &free_b);

  ioctl(fs_ptr, IO_IOCTL_LAST_CLUSTER, &last_cluster);

  ioctl(fs_ptr, IO_IOCTL_GET_CLUSTER_SIZE, &cluster_b);

  total_kb = last_cluster*cluster_b/1024;

  free_kb = free_b/1024;

  used_kb = total_kb - free_kb;

View solution in original post

0 Kudos
3 Replies
127 Views
dmitriyc
Contributor III

Found it: IO_IOCTL_LAST_CLUSTER returns the number of the last cluster. This (as far as I know) can be used as the total number of clusters in the file system. To obtain the total size of the filesystem, multiply that by the cluster size. (casting and error checking left out of code example).

  ioctl(fs_ptr, IO_IOCTL_FREE_SPACE, &free_b);

  ioctl(fs_ptr, IO_IOCTL_LAST_CLUSTER, &last_cluster);

  ioctl(fs_ptr, IO_IOCTL_GET_CLUSTER_SIZE, &cluster_b);

  total_kb = last_cluster*cluster_b/1024;

  free_kb = free_b/1024;

  used_kb = total_kb - free_kb;

View solution in original post

0 Kudos
126 Views
danielchen
NXP TechSupport
NXP TechSupport

Hi dmitriyc:

Please refer to the example

C:\Freescale\Freescale_MQX_4_1\mfs\examples\sdcard

There is a shell command "df" can print out the disk information.

Regards

Daniel

0 Kudos
126 Views
dmitriyc
Contributor III

Hello Daniel,

I have already looked at that example. The implementation of the df command is in sh_df.c in the Shell project. It only lists free space, and the number of free clusters. It does not list the total space or total number of clusters in the filesystem, which is what I am looking for.

For example, I need a way to distinguish between an 8G SD card with 2G of free space and a 4G SD card with 2G of free space.

Thanks,

Dmitriy

0 Kudos