
- 新着としてマーク
- ブックマーク
- 購読
- ミュート
- RSS フィードを購読する
- ハイライト
- 印刷
- 不適切なコンテンツを報告
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).
解決済! 解決策の投稿を見る。

- 新着としてマーク
- ブックマーク
- 購読
- ミュート
- RSS フィードを購読する
- ハイライト
- 印刷
- 不適切なコンテンツを報告
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;

- 新着としてマーク
- ブックマーク
- 購読
- ミュート
- RSS フィードを購読する
- ハイライト
- 印刷
- 不適切なコンテンツを報告
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;


- 新着としてマーク
- ブックマーク
- 購読
- ミュート
- RSS フィードを購読する
- ハイライト
- 印刷
- 不適切なコンテンツを報告
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

- 新着としてマーク
- ブックマーク
- 購読
- ミュート
- RSS フィードを購読する
- ハイライト
- 印刷
- 不適切なコンテンツを報告
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
