未来のいつか/hyoshiokの日記

hyoshiokの日々思うことをあれやこれや

ルートディレクトリを探検する

# ls -ail /mnt/floppy/
total 18
      2 drwxr-xr-x    4 root     root         1024 Aug 12 23:54 .
 832321 drwxr-xr-x    4 root     root         4096 Apr 30 09:22 ..
     12 drwxr-xr-x    2 root     root         1024 Aug 12 23:55 hyoshiok
     11 drwx------    2 root     root        12288 Aug 12 23:50 lost+found
# cd hyoshiok
# ls -ail
total 3
     12 drwxr-xr-x    2 root     root         1024 Aug 12 23:55 .
      2 drwxr-xr-x    4 root     root         1024 Aug 12 23:54 ..
     14 -rw-r--r--    1 root     root           10 Aug 12 23:55 test

ここでhyoshiokディレクトリのi-node番号が12(一番左端の数字)でtestというファイルのi-node番号が14だということがわかる。

そして . (root directory) の i-node 番号は2である。

# od -txz -Ad /dev/fd0

*
0005120 00000000 00000000 411b83ba 411b83ba  >...........A...A<
0005136 411b83ba 00000000 00000000 00000000  >...A............<
0005152 00000000 00000000 00000000 00000000  >................<
*
0005248 000041ed 00000400 411b8fd6 411b849a  >.A.........A...A<
0005264 411b849a 00000000 00040000 00000002  >...A............<
0005280 00000000 00000000 0000001c 00000000  >................<
0005296 00000000 00000000 00000000 00000000  >................<
*

i-nodeの大きさは128バイトで、i-nodeブロックは5120バイトから始まるので、5120+128*(i-node番号-1)=5120+128*1=5248が、root directoryのi-nodeである。

/* linux/include/linux/ext2_fs.h */
/*
 * Structure of an inode on the disk
 */
struct ext2_inode {
        __u16   i_mode;         /* File mode */
        __u16   i_uid;          /* Low 16 bits of Owner Uid */
        __u32   i_size;         /* Size in bytes */
        __u32   i_atime;        /* Access time */
        __u32   i_ctime;        /* Creation time */
        __u32   i_mtime;        /* Modification time */
        __u32   i_dtime;        /* Deletion Time */
        __u16   i_gid;          /* Low 16 bits of Group Id */
        __u16   i_links_count;  /* Links count */
        __u32   i_blocks;       /* Blocks count */
        __u32   i_flags;        /* File flags */
        union {
                struct {
                        __u32  l_i_reserved1;
                } linux1;
                struct {
                        __u32  h_i_translator;
                } hurd1;
                struct {
                        __u32  m_i_reserved1;
                } masix1;
        } osd1;                         /* OS dependent 1 */
        __u32   i_block[EXT2_N_BLOCKS];/* Pointers to blocks */
        __u32   i_generation;   /* File version (for NFS) */
        __u32   i_file_acl;     /* File ACL */
        __u32   i_dir_acl;      /* Directory ACL */
        __u32   i_faddr;        /* Fragment address */
        union {
                struct {
                        __u8    l_i_frag;       /* Fragment number */
                        __u8    l_i_fsize;      /* Fragment size */
                        __u16   i_pad1;
                        __u16   l_i_uid_high;   /* these 2 fields    */
                        __u16   l_i_gid_high;   /* were reserved2[0] */
                        __u32   l_i_reserved2;
                } linux2;
                struct {
                        __u8    h_i_frag;       /* Fragment number */
                        __u8    h_i_fsize;      /* Fragment size */
                        __u16   h_i_mode_high;
                        __u16   h_i_uid_high;
                        __u16   h_i_gid_high;
                        __u32   h_i_author;
                } hurd2;
                struct {
                        __u8    m_i_frag;       /* Fragment number */
                        __u8    m_i_fsize;      /* Fragment size */
                        __u16   m_pad1;
                        __u32   m_i_reserved2[2];
                } masix2;
        } osd2;                         /* OS dependent 2 */
};

ここで__u8,__u16,__u32はそれぞれ符号のない8ビット、16ビット、32ビットのデータ型である。

ダンプと見比べてみるとi_size=0x400,i_atime/i_ctime/i_mtime/i_dtime=411b8fd6 411b849a 411b849a 00000000, i_blocks=00000002, i_block=0x1cとなる。

debugfsでi-node番号2を表示するのは下記の通りである。上記のダンプと比較してみよう。

# debugfs /dev/fd0
debugfs 1.32 (09-Nov-2002)
debugfs:  stat <2>
Inode: 2   Type: directory    Mode:  0755   Flags: 0x0   Generation: 0
User:     0   Group:     0   Size: 1024
File ACL: 0    Directory ACL: 0
Links: 4   Blockcount: 2
Fragment:  Address: 0    Number: 0    Size: 0
ctime: 0x411b849a -- Thu Aug 12 23:54:18 2004
atime: 0x411b8fd6 -- Fri Aug 13 00:42:14 2004
mtime: 0x411b849a -- Thu Aug 12 23:54:18 2004
BLOCKS:
(0):28
TOTAL: 1

第28ブロックに . (root directory)の実体がある。