我正在嘗試編寫基於它的ELF頭文件來計算Linux核心轉儲文件大小的C代碼。這是需要的,因爲我將它傳遞給STDIN並需要傳遞它,首先指定它的大小,而不實際將它寫入文件。將整個文件讀入內存也不是一種選擇。從頭文件計算linux核心文件大小
首先,我尋找到核心轉儲頭:
ELF Header:
Magic: 7f 45 4c 46 02 02 01 00 00 00 00 00 00 00 00 00
Class: ELF64
Data: 2's complement, big endian
Version: 1 (current)
OS/ABI: UNIX - System V
ABI Version: 0
Type: CORE (Core file)
Machine: MIPS R3000
Version: 0x1
Entry point address: 0x0
Start of program headers: 64 (bytes into file)
Start of section headers: 0 (bytes into file)
Flags: 0x0
Size of this header: 64 (bytes)
Size of program headers: 56 (bytes)
Number of program headers: 257
Size of section headers: 0 (bytes)
Number of section headers: 0
Section header string table index: 0
There are no sections in this file.
There are no sections to group in this file.
接下來,我讀的程序頭在一個循環,並採取一切FileSiz領域的總和。 我的假設是(ELF頭大小)+(程序頭大小)*(程序頭數)+(所有大小的總和)將給我整個文件大小。然而,這種情況並非如此。在我的情況下,我得到的大小爲729088000字節的實際文件,而上面的數學給我729054616字節。我錯過了什麼?
此答案*完全*錯誤,並且該問題的前提是錯誤的。 –