91超碰碰碰碰久久久久久综合_超碰av人澡人澡人澡人澡人掠_国产黄大片在线观看画质优化_txt小说免费全本

溫馨提示×

溫馨提示×

您好,登錄后才能下訂單哦!

密碼登錄×
登錄注冊×
其他方式登錄
點擊 登錄注冊 即表示同意《億速云用戶服務條款》

SQL SERVER數據頁checksum校驗算法

發布時間:2020-07-11 08:05:47 來源:網絡 閱讀:963 作者:張宇 欄目:關系型數據庫

在SQL SERVER2005以上版本中,數據頁默認開啟checksum,標識為m_flagBits & 0x200 == True,其值m_tornBits位于頁頭0x3C,4字節。
其算法概述如下:

讀8KB 進BUF
將BUF頭部 CHECKSUM的4字節值清0
uint32 checksum = 0 //初始checksum
for i in range(0,15):
         //每扇區的初始checksum
         overall = 0;
        for ii in range(0,127):
                 //對當前扇區的每個4字節做累加異或
                overall = overall ^ BUF[i][ii];
                //對每扇區的checksum進行移位,方法為向左移位15-i位,
                //左邊移出的15-i位補到最低位。
                checksum = checksum ^ rol(overall, 15- i); 
return checksum; //Gets checksum

c源碼如下:

//***CODE***//
#include <stdio.h>
#include <stdlib.h>

#define seed 15 //Initial seed(for first sector)
#define CHAR_BIT 8 

//***PROTOTYPES***//
unsigned int page_checksum(int page_id, unsigned int *ondisk);
unsigned int rol(unsigned int value, unsigned int rotation);

int main(int argc, char *argv[]) {

    unsigned int computed_checksum; //Var to retrieve calculated checksum
    unsigned int ondisk_checksum; //Var to retrieve checksum on disk

        computed_checksum = page_checksum(152, &ondisk_checksum); //page_checksum call to retrieve stored and calculated checksum for page 152

        //***PRINTS***//
        printf("Calculated checksum: 0x%08x\n", computed_checksum);
        printf("On disk checksum: 0x%08x\n", ondisk_checksum);

}

unsigned int page_checksum(int page_id, unsigned int *ondisk)
{

    FILE *fileptr; 
    unsigned int i; 
    unsigned int j;
    unsigned int checksum;
    unsigned int overall;
    unsigned int *pagebuf[16][128]; //A pointer to describe 2d array [sector][element]

    fileptr = fopen("C:\\Users\\andre\\Desktop\\teste.mdf", "r+b"); //Open dummy data file for binary read

    fseek(fileptr, page_id * 8192, SEEK_SET); //Calculate page address on data file and points to it

    fread(pagebuf, 4, 2048, fileptr); //Read page buffer

    fclose(fileptr);

    checksum = 0;
    overall = 0;

    *ondisk = pagebuf[0][15]; //This means that torn bits is stored on first sector in 15th element, Internals researches understand this

    pagebuf[0][15] = 0x00000000; //Fill checksum field with zeroes (this field will be discarded in algorithm)

    for (i = 0; i < 16; i++) //Loop through sectors
    {

        overall = 0; //Reset overall sum for sectors

        for (j = 0; j < 128; j++) //Loop through elements in sector i
        {
            overall = overall ^ (unsigned int)pagebuf[i][j]; //XOR operation between sector i elements
        }

        checksum = checksum ^ rol(overall, seed - i); //Current checksum is overall for sector i circular shifted by seed (15 - i)
    }

    return checksum; //Gets checksum

}

unsigned int rol(unsigned int value, unsigned int rotation)
{
    return (value) << (rotation) | (value) >> (sizeof(int) * CHAR_BIT - rotation) & ( (1 << rotation) -1);
}
向AI問一下細節

免責聲明:本站發布的內容(圖片、視頻和文字)以原創、轉載和分享為主,文章觀點不代表本網站立場,如果涉及侵權請聯系站長郵箱:is@yisu.com進行舉報,并提供相關證據,一經查實,將立刻刪除涉嫌侵權內容。

AI

山西省| 讷河市| 彭泽县| 仁怀市| 石屏县| 鲁山县| 定州市| 凤山县| 常熟市| 沙湾县| 岱山县| 和田市| 曲阜市| 安国市| 齐齐哈尔市| 旺苍县| 额敏县| 扎鲁特旗| 阳春市| 庆阳市| 弋阳县| 琼海市| 大邑县| 辰溪县| 枝江市| 徐州市| 花莲市| 安西县| 衡阳市| 建平县| 达尔| 宣城市| 芷江| 平舆县| 阳泉市| 都匀市| 长葛市| 瑞丽市| 香河县| 措美县| 苗栗市|