バックナンバーはこちら。
https://www.simulationroom999.com/blog/In-vehicle-external-storage-backnumber/
はじめに
FatFsのファイル上シミュレーションの話。
今回はdiskio.cを改造した結果を確認。
登場人物
博識フクロウのフクさん

イラストACにて公開の「kino_k」さんのイラストを使用しています。
https://www.ac-illust.com/main/profile.php?id=iKciwKA9&area=1
エンジニア歴8年の太郎くん

イラストACにて公開の「しのみ」さんのイラストを使用しています。
https://www.ac-illust.com/main/profile.php?id=uCKphAW2&area=1
FatFs Win32 ファイル上シミュレーション起動

太郎くん
じゃ、早速ビルドして起動してみよう。

太郎くん
お!起動して・・・。

太郎くん
ん?
ちょっと様子が違うぞ?


太郎くん
あ!そういえば、物理ドライブを複数認識するように改造してたとか言ってたっけ?
これのことか?!

フクさん
正解。
動作確認

太郎くん
使い方は・・・RAM Diskの時と一緒なのかな?

フクさん
そうだね。
ざっと触ってみよう。

フクさん
ただ、物理ドライブ、論理ドライブは0ではなく、1なのでそこだけ注意かな。
動作ログ
FatFs module test monitor (LFN, CP932, UTF-8)
PD#0 <== RAM Disk (135MB, 512 bytes * 276480 sectors)
PD#1 <== PhysicalDrive1 (Not Ready)
PD#2 <== PhysicalDrive2 (Not Ready)
PD#3 <== PhysicalDrive3 (Not Ready)
PD#4 <== PhysicalDrive4 (Not Ready)
PD#5 <== PhysicalDrive5 (Not Ready)
PD#6 <== PhysicalDrive6 (Not Ready)
PD#7 <== PhysicalDrive7 (Not Ready)
PD#8 <== PhysicalDrive8 (Not Ready)
PD#9 <== PhysicalDrive9 (Not Ready)
Multiple partition is disabled.
Each logical drive is associated with the same physical drive number.
>di 1
rc=0
Sector size = 512
Number of sectors = 1048576
>fi 1
rc=0 FR_OK
>fm 1 2
The volume will be formatted. Are you sure? (Y/n)=Y
rc=0 FR_OK
>fj 1:
rc=0 FR_OK
>fs
FAT type = FAT32
Cluster size = 4096 bytes
Sectors/FAT = 1024
Number of FATs = 1
Number of clusters = 130928
Volume start sector = 63
FAT start sector = 128
Root DIR start cluster = 2
Data start sector = 1152
No volume label
Volume S/N is 5283-207B
0 files, 0 bytes.
0 folders.
4210120 KiB total disk space.
523708 KiB available.
>fl
0 File(s), 0 bytes total
0 Dir(s), 536276992 bytes free
>fo 6 test.txt
rc=0 FR_OK
>fw 7000 0x61
7000 bytes written.
>fc
rc=0 FR_OK
>fo 6 test2.txt
rc=0 FR_OK
>fw 8000 0x62
8000 bytes written.
>fc
rc=0 FR_OK
>fl
----A 2021/04/25 08:06 7000 test.txt
----A 2021/04/25 08:06 8000 test2.txt
2 File(s), 15000 bytes total
0 Dir(s), 536260608 bytes free
>fo 1 test.txt
rc=0 FR_OK
>fd 32
00000000: 61 61 61 61 61 61 61 61 61 61 61 61 61 61 61 61 aaaaaaaaaaaaaaaa
00000010: 61 61 61 61 61 61 61 61 61 61 61 61 61 61 61 61 aaaaaaaaaaaaaaaa
>fc
rc=0 FR_OK
>fo 1 test2.txt
rc=0 FR_OK
>fd 32
00000000: 62 62 62 62 62 62 62 62 62 62 62 62 62 62 62 62 bbbbbbbbbbbbbbbb
00000010: 62 62 62 62 62 62 62 62 62 62 62 62 62 62 62 62 bbbbbbbbbbbbbbbb
>fc
rc=0 FR_OK
>
動作ログ説明

フクさん
ざっと何をしたか列挙しよう。
- 物理ドライブ1にマウント
- FAT32でフォーマット
- カレントディレクトリは「1:」に変更
- volume status参照
- test.txtに’a’を7000byte書き込み
- tet2.txtに’b’を8000byte書き込み

太郎くん
うん。
ちゃんとファイルが2つ出来てて、
それぞれ読み出しもできるみたいだね。
fjコマンドでカレントディレクトリの変更ってのもできるのか。

太郎くん
でも、随分大きめのデータを書いたね?
なんで?

フクさん
まぁこの後、ファイルとして生成されたディスクイメージを見るときにある程度大きめのデータの方がいろいろ説明し易いんでね。

太郎くん
(ディスクイメージを見る???マジに言ってるのか???)

フクさん
というわけで、次回からディスクイメージの中を見てみる。
まとめ

フクさん
まとめだよ。
- FatFs Win32 ファイル上シミュレーション起動。
- マウント、フォーマットをして、ファイルを2つ作成。
- fjコマンドでカレントディレクトリ指定。
- flコマンドでファイルが作られていることを確認。
- ファイルの中身も確認。
- 次回からディスクイメージの中を見ていく。
バックナンバーはこちら。
コメント