ext3のファイル最大長2


Rev.1を表示中。最新版はこちら

ext3のファイル最大長の実装をふまえて、実際の最大サイズを計算してみました。ブロックが1K=2^10、2K=2^1×2^10、4K=2^2×2^10で、ビットシフトは10、11、12となります。
#include <stdio.h>
#include <stdlib.h>

typedef unsigned long long u64;
typedef long long l64;

#define EXT3_NDIR_BLOCKS                12

void    get_size(int bits);
void    get_limit(int bits);

void    main()
{
   printf("limit size\n");
   get_limit(10);
   get_limit(11);
   get_limit(12);
   putchar('\n');

   printf("slot size\n");
   get_size(10);
   get_size(11);
   get_size(12);
}

void    get_size(int bits)
{
   u64 res = EXT3_NDIR_BLOCKS;

   res += 1LL << (bits-2);
   res += 1LL << (2*(bits-2));
   res += 1LL << (3*(bits-2));
   res <<= bits;
   printf("%llu\n", res);
}

void    get_limit(int bits)
{
   u64 meta_blocks;
   u64 upper_limit;

   meta_blocks = 1;
   meta_blocks += 1 + (1LL << (bits-2));
   meta_blocks += 1 + (1LL << (bits-2)) + (1LL << (2*(bits-2)));

   upper_limit = (1LL << 32) - 1;
   upper_limit >>= (bits - 9);

   upper_limit -= meta_blocks;
   upper_limit <<= bits;
   printf("%llu\n", upper_limit);
}

[root@localhost test]# ./a.out
limit size
2198955618304
2198484279296
2194719883264

slot size
17247252480
275415851008
4402345721856
最大サイズは、limit sizeを超えないslot sizeということで以下のようになります。
ブロックサイズが1Kの時、 17247252480(slot size)
ブロックサイズが2Kの時、 275415851008(slot size)
ブロックサイズが4Kの時、2194719883264(limit size)
[root@localhost test]# 10to2 17247252480
0000-0000000000-0000000000-0000010000-0001000000-0100001100-0000000000
                                   16G        64M       268K
[root@localhost test]# 10to2 275415851008
0000-0000000000-0000000000-0100000000-1000000001-0000011000-0000000000
                                  256G       513M        16K    
[root@localhost test]# 10to2 2194719883264
0000-0000000000-0000000001-1111111011-1111110111-1111110000-0000000000
                         1T      1019G     1015M       1008K
資料等には、16G/256G/2Tとされていますが、厳密にいうと上記サイズ正しいところです。


最終更新 2014/06/23 18:45:51 - north
(2014/06/23 18:45:51 作成)


検索

アクセス数
3594162
最近のコメント
コアダンプファイル - sakaia
list_head構造体 - yocto_no_yomikata
勧告ロックと強制ロック - wataash
LKMからのファイル出力 - 重松 宏昌
kprobe - ななし
ksetの実装 - スーパーコピー
カーネルスレッドとは - ノース
カーネルスレッドとは - nbyst
asmlinkageってなに? - ノース
asmlinkageってなに? - よろしく
Adsense
広告情報が設定されていません。