linux編程出錯: Value too large for defined data type

1. 背景

         有次在linux環境下,用交叉編譯器編譯一個簡單的helloworld(C語音寫的不超過10行代碼),結果提示如下所示的錯誤信息:

cc1: error: /home/yx/test.c: Value too large for defined data type

         而奇怪的是同一個test.c文件,放在不同位置下,有的能編譯通過,有的不行,對比結果如下:

#ls -lsi /root/test.c /home/test.c /home/yx/test.c

  16022526 4 -rw-r--r--. 1 root  root  149 7月  27 14:06 /home/test.c       # 編譯通過

4312840465 4 -rw-r--r--. 1 root  root  149 7月  27 14:07 /home/yx/test.c    # 編譯失敗

 202907598 4 -rw-r--r--. 1 root  root  149 7月  27 14:02 /root/test.c        # 編譯通過

         這個問題折騰我許久,最終發現跟掛載屬性inode64有關係,如下是我環境的掛載屬性。

#mount | grep -E '(home|root)'

/dev/mapper/centos-root on /     type xfs (rw,relatime,seclabel,attr2,inode64,noquota)

/dev/mapper/centos-home on /home type xfs (rw,relatime,seclabel,attr2,inode64,noquota)

        

2. 理論依據

         查看文件系統xfs格式的幫助手冊,裏面有詳細介紹inode32|inode64的注意要點。

man xfs

 

inode32|inode64

       When inode32 is specified, it indicates that XFS limits inode creation to locations which will not result in inode numbers with more than 32 bits of  signifi‐

       cance.

 

       When  inode64  is  specified,  it indicates that XFS is allowed to create inodes at any location in the filesystem, including those which will result in inode

       numbers occupying more than 32 bits of significance.

 

       inode32 is provided for backwards compatibility with older systems and applications, since 64 bits inode numbers might cause problems  for  some  applications

       that cannot handle large inode numbers.  If applications are in use which do not handle inode numbers bigger than 32 bits, the inode32 option should be speci‐

       fied.

 

       For kernel v3.7 and later, inode64 is the default.

 

3. 結合實際

         inode32最多能表達數字是4294967295,如果文件屬性中的inode超過這個上限,就說明是inode64的。

         比較老的交叉編譯器,只支持32位inode的文件訪問,當遇到超過4294967295的文件,就會編譯出錯並提示:Value too large for defined data type

4.   解決方案

         如https://gcc.gnu.org/bugzilla/show_bug.cgi?id=44116所說,在新版本的gcc中已經解決了該bug。那麼解決方案就有兩種:

Ø  升級交叉編譯器版本,讓其支持inode64的源文件。

Ø  交叉編譯器版本不變,將文件系統掛載屬性從inode64改爲inode32。

 

5. inode32與inode64的區別

         在http://xfs.org/index.php/XFS_FAQ#Q:_What_is_the_inode64_mount_option_for.3F裏面有這麼一段話能詮釋的5. inode32與inode64的區別:

 

By default, with 32bit inodes, XFS placesinodes only in the first 1TB of a disk. If you have a disk with 100TB, allinodes will be stuck in the first TB. This can lead to strange things like"disk full" when you still have plenty space free, but there's nomore place in the first TB to create a new inode. Also, performance sucks.

To come around this, use the inode64 mountoptions for filesystems >1TB. Inodes will then be placed in the locationwhere their data is, minimizing disk seeks.

Beware that some old programs might haveproblems reading 64bit inodes, especially over NFS. Your editor used inode64for over a year with recent (openSUSE 11.1 and higher) distributions using NFSand Samba without any corruptions, so that might be a recent enough distro.

 

         大意就是xfs文件系統會把inode存儲在磁盤最開始的這1T空間裏,如果這部分空間被完全填滿了,那麼就會出現磁盤空間不足的錯誤提示了。解決辦法就是在掛載時,指定 inode64 選項。

6. 其他

http://blog.fmeh.org/2013/05/11/does-the-world-need-32-bit-inodes/

 

上面看到的只使用 32 位 inode 的程序佔比結果 10% 還是比較令人滿意的,只支持 32 位 inode 的程序現在越來越少了。

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章