未来のいつか/hyoshiokの日記

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

ルートディレクトリ

第28ブロックをダンプする。
# od -txz -Ad /dev/fd0
*
0028672 00000002 0201000c 0000002e 00000002  >................<
0028688 0202000c 00002e2e 0000000b 020a0014  >................<
0028704 74736f6c 756f662b 0000646e 0000000c  >lost+found......<
0028720 020803d4 736f7968 6b6f6968 00000000  >....hyoshiok....<
0028736 00000000 00000000 00000000 00000000  >................<

ディレクトリというのは特殊なファイルで、内容としてはファイル名とそのinodeの対を保存する。
下記はlinux/include/linux/ext2_fs.h

/*
 * The new version of the directory entry.  Since EXT2 structures are
 * stored in intel byte order, and the name_len field could never be
 * bigger than 255 chars, it's safe to reclaim the extra byte for the
 * file_type field.
 */
struct ext2_dir_entry_2 {
        __u32   inode;                  /* Inode number */
        __u16   rec_len;                /* Directory entry length */
        __u8    name_len;               /* Name length */
        __u8    file_type;
        char    name[EXT2_NAME_LEN];    /* File name */
};

ということなのでhyoshiokのinode=0000000c,file_type=02,name_len=08,rec_len=03d4でinodeが0000000c=12なので第12ブロックがinodeになる。inodeテーブルは5120バイト目から始まりinode一個で128バイト利用するのでhyoshiokのinodeは5120+128*(12-1)=6528からはじまる。ダンプしてみると

*
0006528 000041ed 00000400 411b8fe6 411b84e9  >.A.........A...A<
0006544 411b84e9 00000000 00020000 00000002  >...A............<
0006560 00000000 00000000 00000029 00000000  >........).......<
0006576 00000000 00000000 00000000 00000000  >................<
*

となるがこれだとよく分からないのでdebugfsでstat <12>をした。

debugfs:  stat <12>
Inode: 12   Type: directory    Mode:  0755   Flags: 0x0   Generation: 31940
User:     0   Group:     0   Size: 1024
File ACL: 0    Directory ACL: 0
Links: 2   Blockcount: 2
Fragment:  Address: 0    Number: 0    Size: 0
ctime: 0x411b84e9 -- Thu Aug 12 23:55:37 2004
atime: 0x411b8fe6 -- Fri Aug 13 00:42:30 2004
mtime: 0x411b84e9 -- Thu Aug 12 23:55:37 2004
BLOCKS:
(0):41 ←ここがデータブロック
TOTAL: 1

データブロックが41だ。