コード例 #1
0
        private static RC readMasterJournal(VirtualFile pJrnl, byte[] zMaster, uint nMaster)
        {
            int  len   = 0;             // Length in bytes of master journal name
            long szJ   = 0;             // Total size in bytes of journal file pJrnl
            uint cksum = 0;             // MJ checksum value read from journal

            zMaster[0] = 0;
            var aMagic = new byte[8];   // A buffer to hold the magic header
            RC  rc;

            if (RC.OK != (rc = pJrnl.FileSize(ref szJ)) ||
                szJ < 16 ||
                RC.OK != (rc = pJrnl.ReadByte((int)(szJ - 16), ref len)) ||
                len >= nMaster ||
                RC.OK != (rc = pJrnl.ReadByte(szJ - 12, ref cksum)) ||
                RC.OK != (rc = pJrnl.Read(aMagic, 8, szJ - 8)) ||
                ArrayEx.Compare(aMagic, aJournalMagic, 8) != 0 ||
                RC.OK != (rc = pJrnl.Read(zMaster, len, (long)(szJ - 16 - len))))
            {
                return(rc);
            }
            // See if the checksum matches the master journal name
            for (var u = 0; u < len; u++)
            {
                cksum -= zMaster[u];
            }
            if (cksum != 0)
            {
                // If the checksum doesn't add up, then one or more of the disk sectors containing the master journal filename is corrupted. This means
                // definitely roll back, so just return SQLITE.OK and report a (nul) master-journal filename.
                len = 0;
            }
            if (len == 0)
            {
                zMaster[0] = 0;
            }
            return(RC.OK);
        }