バックナンバーはこちら。
https://www.simulationroom999.com/blog/In-vehicle-external-storage-backnumber/
はじめに
FatFsのファイル上シミュレーションの話。
ロングファイルネームなフォルダやファイルをディスクイメージ上で確認する場合の読み方。
フォルダの中のディレクトリエントリ達。
登場人物
博識フクロウのフクさん

イラスト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
フォルダの中のディレクトリエントリ

前回は「.」のカレントディレクトリ、「..」の親ディレクトリの話で終わっちゃったから、今回はフォルダ内のディレクトリエントリ全部見ておきたいね。

とりあえず、「long_file_name_folder」の中のディレクトリエントリの構造を書き出してみた。


考え方はlong_file_name_folderの時と一緒かな?

そうだね。

DIR_Attrが0x0FだったらLFN仕様ということで、LFN用のディレクトリエントリ構造体で参照。
unicodeでファイル名が埋まってるから、それを参照。
ただし、ファイル名の後方から埋まってる点に注意。
って感じか。

大正解!
ファイルの中身

ファイルの中身のデータ自体はSFNのディレクトリエントリでクラスタ指定してる感じかな?

そうだね。
そこら辺の考え方も一緒だね。

今回のSFNの中身は・・・。
![long_file_name_fileのディレクトリエントリ、struct DIR_ENTRY_t { BYTE DIR_Name[11]; BYTE DIR_Attr; BYTE DIR_NTRes; BYTE DIR_CrtTimeTenth; WORD DIR_CrtTime; WORD DIR_CrtDate; WORD DIR_LstAccDate; WORD DIR_FstClusHI; WORD DIR_WrtTime; WORD DIR_WrtDate; WORD DIR_FstClusLO; DWORD DIR_FileSize; };](https://www.simulationroom999.com/blog/wp-content/uploads/2021/04/03_long_file_name_fileのディレクトリエントリ-1024x364.png)

DIR_FstClusHIとDIR_FstClusLOからクラスタ8にファイルの中身のデータが配置されてるね。
ルートディレクトリエントリがクラスタ2で0x90000。
1クラスタが4096[byte]。
よって、
0x90000+(8-2)*4096=614400
614400[byte]目参照だ。

じゃ、ディクスイメージの614400[byte]目を見てみよう。


確か「0x63」こと’c’を16yte書き込んだはずだから、あってそうだね。

念のため、FAT領域のクラスタチェーンも確認してみよう。

FAT領域は128セクタ目で65536[byte]目だね。
たしか、ここの回で調べた。

そしてクラスタチェーンは・・・。


クラスタ8を見ると0x0fffffffになってるから、1個のクラスタで完結してるってことだ。

完璧だ!

まぁ見るところが分かってしまえば、それほど難しい構造じゃないよねー。
まとめ

まとめだよ。
- フォルダの中のディレクトリエントリの構成を図解。
- カレントディレクトリ、親ディレクトリ、LFN→SFNの構成。
- ファイルの実体が配置されてるクラスタ確認。
- ここの考え方は通常の「8.3形式」のファイルと同一。
- 該当クラスタのFAT領域に於けるクラスタチェーンを確認。
バックナンバーはこちら。
コメント