歡迎來到Linux教程網
Linux教程網
Linux教程網
Linux教程網
Linux教程網 >> Linux綜合 >> Linux資訊 >> Linux文化 >> linux中在big-endian機器下fat文件系統是否還是按spec.中所說的little-endian模式進行存儲?

linux中在big-endian機器下fat文件系統是否還是按spec.中所說的little-endian模式進行存儲?

日期:2017/2/27 12:12:37   编辑:Linux文化

看到ms的fat32的spec中有一段話說到fat的endian的問題

“All of the FAT file systems were originally developed for the IBM PC machine architecture. The importance of this is that FAT file system on disk data structure is all “little endian.” If we look at one 32-bit FAT entry stored on disk as a series of four 8-bit bytes—the first being byte[0] and the last being byte[4]—here is where the 32 bits numbered 00 through 31 are (00 being the least significant bit):

byte[3]3 3 2 2 2 2 2 2 1 0 9 8 7 6 5 4

byte[2]2 2 2 2 1 1 1 1 3 2 1 0 9 8 7 6

byte[1]1 1 1 1 1 1 0 0 5 4 3 2 1 0 9 8

byte[0]0 0 0 0 0 0 0 0 7 6 5 4 3 2 1 0

This is important if your machine is a “big endian” machine, because you will have to translate between big and little endian as you move data to and from the disk.”

按這樣的說法無論在big/little endian的機器中,fat管理的存儲器都是按照little endian的格式進行存儲的,這樣的話在big-endian機器中,在將數據寫到fat管理的存儲器或者從fat管理的存儲器中讀數據時就必須先對數據進行endian的轉換了,如此一來cpu的loading不是占用很厲害?!

很迷惑這點,想知道big endian下的fat文件系統相對於little endian下時是怎樣組織和工作的,MS或linux是如何處理的?那位朋友知道的懇請告知一二,實萬分感謝!謝謝!

>>> 此貼的回復 >> 並不關cpu的loading的事情,關鍵是你在內核中一些結構體的定義,如果全部都是按char類型進行操作,那麼就不需要字節序轉換,如果使用了大於1個字節的成員讀取數據,就需要對大小端進行處理,而最底層的存儲器操作,你完全可以基於一個字節進行讀取(假定存儲器是按一個字節一個字節進行操作的,在某些FLASH存儲中,一次只能對兩個字節進行操作),只是在讀取數據的後續操作中需要人為地進行字節序轉換,這就是內核與驅動中要做的事情了,比如你需要獲得第一個分區所在物理磁盤扇區號,假定這個號被存儲在存儲器的第一個扇區的最後四個字節中,而這個號是一個整型值,此時,你需要首先讀取這四個字節到一個char數組中,但是這個數組中的具體數值都是按little endian的格式進行存儲,而此時你的CPU卻按big-endian方式操作,那麼你在內核驅動中就需要顯示地完成將這個char數組轉換成int型,這時就需要明確處理大小端的情況,不能直接用C庫函數的方式來轉換,必須先進行存儲方式的轉換,再調用函數進行轉換,諸如此類的地方還有很多,所以在設計文件驅動時都要注意這個問題的


Copyright © Linux教程網 All Rights Reserved