tarfs について (5)

ちょっと微妙な部分にフォーカスし杉な気もしますが、tarfs/src/super.c の tarfs_read_super() 手続きの最初の部分。

  kdev_t dev = sb->s_dev;
  
  set_blocksize(dev, TAR_BLOCKSIZE);

2.6 なカーネルでは set_blocksize() のプロトタイプは以下なカンジ。

int set_blocksize(struct block_device *bdev, int size)

kdev_t ではないのだよね。ちなみに 2.4 な set_blocksize() および sb_set_blocksize() な定義の一部が以下。まず、set_blocksize()

int set_blocksize(kdev_t dev, int size)
{       
        int oldsize;
        struct block_device *bdev;

        /* Size must be a power of two, and between 512 and PAGE_SIZE */
        if (size > PAGE_SIZE || size < 512 || (size & (size-1)))
                return -EINVAL;

        /* Size cannot be smaller than the size supported by the device */
        if (size < get_hardsect_size(dev))
                return -EINVAL;

あと、直下にて定義されている sb_set_blocksize() の定義の一部が以下

int sb_set_blocksize(struct super_block *sb, int size)
{       
        int bits;
        if (set_blocksize(sb->s_dev, size) < 0)
                return 0;

super_block なオブジェクトの s_dev 属性渡している。tarfs でヤッているナニとさほど変わりない。上記の引用以降では戻す値をナニしているだけなので、tarfs なソレとほぼ同一と言っても良いはず。

2.6 でどうする

ってコトなのですが、sb_set_blocksize() を眺めてみるに以下

int sb_set_blocksize(struct super_block *sb, int size)
{
	if (set_blocksize(sb->s_bdev, size))
		return 0;
	/* If we get here, we know size is power of two
	 * and it's value is between 512 and PAGE_SIZE */
	sb->s_blocksize = size;
	sb->s_blocksize_bits = blksize_bits(size);
	return sb->s_blocksize;
}

s_bdev 属性を渡しております。これは struct block_device 型です。戻り値が不要なのであれば、

  sb_set_blocksize(sb, TAR_BLOCKSIZE);

って書き換えても OK そげ。ちょっと気になるのが、2.6 な set_blocksize() の記述。

int set_blocksize(struct block_device *bdev, int size)
{
	/* Size must be a power of two, and between 512 and PAGE_SIZE */
	if (size > PAGE_SIZE || size < 512 || (size & (size-1)))
		return -EINVAL;

	/* Size cannot be smaller than the size supported by the device */
	if (size < bdev_hardsect_size(bdev))
		return -EINVAL;

2.4 では

        /* Size cannot be smaller than the size supported by the device */
        if (size < get_hardsect_size(dev))

って書き方。むむ。同じかと思ったら関数の名前が違うな。このあたりバージョンの違いを見つつ追い掛けてると時間がいくらあっても足らんな。
とは言え、2.4 と 2.6 でこのあたりのデータの持ち方が変更されたのも良く分かります。

次は

tarfs_read_super() なソレはなんとなくこれで良さげ。本当かどうかは動かしてみて分かるとして (を
次に確認すべきは

  sb->s_op = &tarfs_sops;
  sb->s_root = d_alloc_root(iget(sb, TARFS_ROOT_INO));
  if (!sb->s_root) {
    goto err_out;
  }

なあたりでしょうか。特に tarfs_sops な属性が指している関数ども。ちょっと時間を使って掘り進むのもありでしょうか。