1

より高い (より論理的な) レベルから FAT ファイル システムがどのように機能するかを理解しようとしています。FAT ファイル システムにはファイル アロケーション テーブルがあり、ディスク内の使用可能なアロケーション ユニット (クラスタ) ごとに 1 つのエントリがあります。このデータ構造は、ファイルがディスク上に表示される最初のクラスターのアドレスを使用してファイルをマップするために使用されます (ファイルはほぼ確実に複数のクラスターを占有し、これらのクラスターは連結リスト形式で接続されます)。ここまでは順調ですね。しかし、ファイル アロケーション テーブルのキーは何でしょうか? ファイル名はフルパスですか?

たとえば、ファイル C:\folder1\myFile.txt にアクセスする必要があるとします。I/O マネージャーは、エントリが見つかるまで、ファイル アロケーション テーブル内のファイル名 (パスを含む) を検索します。最初のクラスターのアドレスを返します。それがどのように機能するのですか?このトピックに関する多くのドキュメントをオンラインで読みましたが、どういうわけか、ファイル アロケーション テーブルへのアクセスはまだあいまいです。よろしくお願いいたします。

[編集]

オンラインで読めば読むほど、私は混乱します。この簡単な例で試してみます。うまくいけば、私の質問が明確になります。C ドライブに 2 つのファイルしかないとします。

C:\myFile.txt

C:\folder1\myFile.txt

ファイル アロケーション テーブルには (非常に抽象的な方法で) 3 つのエントリがあります。

  | Filename | Extension | First Cluster |
  |----------|-----------|---------------|
1 | MYFILE   | TXT       | 150           |
2 | FOLDER1  |           | 300           |
3 | MYFILE   | TXT       | 900           |

これまでのところ私が正しいと仮定して、C:\folder1 の myFile.txt にアクセスしたいとしましょう: 同じ名前のエントリが 2 つあるため、ファイル名 (MYFILE.TXT) 自体をキーとして使用することはできません (どのエントリを選択すればよいかわかりません)。

この時点で、フォルダから開始する必要があると思われるため、FAT をスキャンして FOLDER1 を見つけます。エントリ #2 (クラスタ 300) を取得します。次は何ですか?指定したクラスターのハード ドライブにアクセスできるように、テーブルをスキャンして "MYFILE.TXT" に必要なディレクトリ エントリを見つけるにはどうすればよいですか?

多分私はこれを間違った視点から見ているのかもしれませんが、わかりません。助けてくれてありがとう。

4

1 に答える 1

0

このコードを見てください。これは、ディスク D:\ からルート ディレクトリにあるすべてのディレクトリとファイルの名前を出力する何らかの dir コマンドです。

#include<dos.h>
#include<stdio.h>
#include<iostream.h>

struct Boot {
     char ignore1[11];
     int Byte_Per_Sector;
     char Serctors_Per_Cluster;
     int Number_Of_Reserved_sectors;
     char Number_of_FATS;
     int Maximum_Number_of_root_dir;
     int Total_Sector_count;
     char Ignore2;
     int Sectors_per_fat;
     int Sectors_per_trach;
     int Number_of_heads;
     char ignore3[4];
     char Total_sector_count_for_fat[4];
     int ignore4;
     char boot_signature;
     char Volume_id[4];
     char Volume_lable[11];
     char File_system_type[8];
     char Rest_of_boot_sector[450];
};
struct FCB {
      char file_name[8];
      char extension[3];
      char attribute;
      int reserved;
      int creation_time;
      int creation_date;
      int last_access_date;
      int ignore_in_fat;
      int last_write_time;
      int last_write_date;
      int first_logic_cluster;
      char file_size[4];
   };

  void main(){
       FCB root[16]; //to read all the Root directory 
       if(absread(3,1,217,&root) ==0) { // start read from disk number 3 , 1 sector and the first sector number is 217 (from the hard disk)
       cout<<"Read of Root Directory started:"<<endl;

       for(int j=1;j<15;j++){
        if(root[j].file_name[0]==0x00){//0x00 represents Unused file
                break;
        }
        if(root[j].attribute!=0x0F) //0x0f mean this directory entry is part of a long file name
        if(root[j].file_name[0]!='?')
        for(int i=0;i<7;i++){
            printf("%c",root[j].file_name[i]); // print the name of all files and directories

        }
        cout<<endl<<root[j].first_logic_cluster; to locate where is the first cluster contains the data on HD
        cout<<endl;
    } 
    cout<<"end of dirs in this cluster"<<endl;
    }
  else {
cout<<"error"<<endl;
}
 cout<<"===================="<<endl;
 char buffer[512];
 //here to read what a file contains after calculating the physical address of that file 
 if(absread(3,1,283,&buffer) ==0) {
    for(int i=0;i<512;i++ ){
        cout<<buffer[i];
    }
 }
}

注意事項

1-すべての情報がここに格納されるため、FAT では最初の構造体が最も重要です。

2- FCB には、ルート ディレクトリ内のファイルとディレクトリに関する情報が含まれています。

3- このコードは Windows 3.11 で実行でき、(Turbo c++) はコーディングおよびコンパイルするプログラムです。

4- コードは FAT12 を表し、整数は 2 バイトです

ご不明な点がございましたら、お役に立てれば幸いです

于 2015-03-22T16:24:38.607 に答える