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

キャンセル
次の結果を表示 
表示  限定  | 次の代わりに検索 
もしかして: 

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

ソリューションへジャンプ
1,538件の閲覧回数
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,217件の閲覧回数
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,218件の閲覧回数
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,217件の閲覧回数
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,217件の閲覧回数
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 件の賞賛
返信