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

取消
显示结果 
显示  仅  | 搜索替代 
您的意思是: 
已解决

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

跳至解决方案
1,903 次查看
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).

标签 (1)
标记 (1)
0 项奖励
回复
1 解答
1,582 次查看
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;

在原帖中查看解决方案

0 项奖励
回复
3 回复数
1,583 次查看
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;

0 项奖励
回复
1,582 次查看
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 项奖励
回复
1,582 次查看
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 项奖励
回复