Linux/Unix inode、vnode、dentry、file、プロセステーブル、ファイルテーブル(上)


従来のUnixにはvノード(vnode)もiノード(inode)もあり、vnodeのデータ構造にはinode情報が含まれている.ただしLinuxではvnodeは使用されず、汎用inodeが使用されている.「実現は違うが、概念的には同じだ」.
vnode(「virtual node」)はファイルが開いたときにのみ表示されます.一方inodeは、ファイルがディスクの位置にあり、その情報自体がディスクなどに格納され、ファイルを開くとディスクからメモリが読み込まれます.
inode情報はディスクのパーティションに格納されます.次の図は、inodeがデータブロック内のファイルの物理的な位置を示す拡張図です.したがって、inodeだけでは完全なファイルシステムを記述することはできません.例えば、ディレクトリとディレクトリのツリー構造はinodeでは反映されません.
延長:
複数のinodeが同じデータブロックを指している場合、おなじみのリンクを実現できるのではないでしょうか?!これがソフト接続の原理で、新しいファイル(シンボルリンクファイル、ファイルのプロパティにシンボルリンクファイルであることが明確に示されている)を作成し、リンクが必要なファイルに新しいinodeを割り当て、同じファイルを指します.
複数のファイルが1つのinodeを共有し、同じようにリンクを実現できますか?!これがハードリンクの原理で、inodeにはリンクカウンタがあり、ファイルがこのinodeを指す場合、カウンタは1増加します.特に、カウンタが0の場合、ファイルは本当にディスクから削除されます.すなわちls-lコマンドの第2欄ext3_inode上のデータ構造は、ファイルの長さ、ファイルが存在するデバイス、ファイルの物理的な場所、作成、変更、更新時間など、ファイルに関する多くの情報を記録しています.特に、ファイル名は含まれていません.ディレクトリの下にあるすべてのファイル名とディレクトリ名は、ディレクトリのデータブロック、すなわち上記のディレクトリブロックに格納されます.01 struct   ext3_inode { 02      __le16 i_mode; File mode 03      __le16 i_uid; Low 16 bits of Owner Uid 04      __le32 i_size; Size in bytes 05      __le32 i_atime; Access  time 06      __le32 i_ctime; Creation  time 07      __le32 i_mtime; Modification  time 08
  09      __le32 i_dtime; Deletion Time 10      __le16 i_gid; Low 16 bits of Group Id 11      __le16 i_links_count; Links count 12      ...... 13      __le32 i_block[EXT2_N_BLOCKS]; Pointers to blocks 14      ...... 15 };
vnodeの導入:初期バージョンのUnixではそうしていましたが、Linuxではありません.vnodeには、一般に、ファイルタイプと、このファイルに対してさまざまな操作を行う関数のポインタが含まれています.
 
Linuxにはdentryがあり、中国語ではディレクトリ項目を意味し、メモリ内のファイルとディスク内のファイルを接着し、よくアクセスするディレクトリ情報を保存します.
http://unix.stackexchange.com/questions/4402/what-is-a-superblock-inode-dentry-and-a-file
A dentry is the glue that holds inodes and files together by relating inode numbers to file names. Dentries also play a role in directory caching which, ideally, keeps the most frequently used files on-hand for faster access. File system traversal is another aspect of the dentry as it maintains a relationship between directories and their files.次は面白い写真です.
Interaction between processes and VFS objects
The common file model consists of the following object types:
<1>The superblock object Stores information concerning a mounted filesystem. For disk-based filesystems, this object usually corresponds to a filesystem control block stored on disk. <2>The inode object Stores general information about a specific file. For disk-based filesystems, this object usually corresponds to a file control block stored on disk. Each inode object is associated with an inode number, which uniquely identifies the file within the filesystem. <3>The file object Stores information about the interaction between an open file and a process. This information exists only in kernel memory during the period when a process has the file open. <4>The dentry object Stores information about the linking of a directory entry (that is, a particular name of the file) with the corresponding file. Each disk-based filesystem stores this information in its own particular way on disk. Figure 12-2 illustrates with a simple example how processes interact with files. Three different processes have opened the same file, two of them using the same hard link. In this case, each of the three processes uses its own file object, while only two dentry objects are requiredone for each hard link. Both dentry objects refer to the same inode object, which identifies the superblock object and, together with the latter, the common disk file.
 
次の点に注意してください.
1)プロセスはファイルを開くたびにfile構造に対応する.同じプロセスは、同じファイルを複数回開いて複数の異なるfile構造を得ることができ、file構造は、ファイルの現在のオフセットなどのファイルが開かれている属性を記述する.
2)2つの異なるfile構造は、同じdentry構造に対応することができる.プロセスが同じファイルを複数回開くと、対応するdentry構造は1つだけです.Dentry構造は、ディレクトリ項目と対応するファイル(inode)の情報を格納する.
3)記憶媒体では、各ファイルは一意のinodeノードに対応するが、各ファイルには複数のファイル名が存在してもよい.つまり、同じファイルに異なるファイル名でアクセスできます.ここで、複数のファイル名が1つのファイルに対応する関係は、データ構造ではdentryとinodeの関係であることを示す.
4)Inodeにはファイルの名前が格納されず、ノード番号のみが格納される.一方、dentryには名前と対応するノード番号が保存されているので、異なるdentryで同じinodeにアクセスできます.
5)異なるdentryは同じファイルリンク(lnコマンド)で実現される.01 struct   dentry { 02      atomic_t d_count; 03      unsigned  int   d_flags; 04      struct   inode * d_inode; 05      struct   dentry * d_parent; 06      struct   list_head d_hash; 07      struct   list_head d_lru; 08      struct   list_head d_child; 09      struct   list_head d_subdirs; , 10      struct   list_head d_alias; ( ) 11      int   d_mounted; , 12      struct   qstr d_name; 13      unsigned  long   d_time;  // used by d_revalidate 14      struct   dentry_operations *d_op; 15      struct   super_block * d_sb; 16      vunsigned  long   d_vfs_flags; 17      void   * d_fsdata; 18      unsigned  char   d_iname [DNAME_INLINE_LEN]; 19 };
ファイル名、親ディレクトリなど.dentryは、ディレクトリのツリー構造を記述することができる.
http://daoluan.net/blog/inode、vnode、dentry/