/// <summary> /// Write record to transaction log /// </summary> /// <param name="id"></param> /// <param name="address"></param> /// <param name="_length"></param> /// <param name="_old"></param> /// <param name="_new"></param> public void WriteRecord(short id, long address, ref byte[] data) { IO.Write(-1, (short)id); IO.Write(-1, (long)address); IO.Write(-1, (int)data.Length); IO.Write(-1, ref data); int ln = (int)(data.Length + 14 + 4); IO.Write(-1, (int)ln); IO.Flush(); }
/// <summary> /// Dump storage /// Space name - 32 /// System area - 1024 /// Pool area - 4096 /// </summary> private void dump(VSIO IO, string name) { bool was_opened = false; uint e_code = IO.GetEncryption() ? e_code = DEFS.DATA_ENCRYPTED : e_code = DEFS.DATA_NOT_ENCRYPTED; if (state == DEFS.STATE_OPENED) { if (TA.Started) { throw new VSException(DEFS.E0025_STORAGE_UNABLE_TO_COMPLETE_CODE, "- Dump (transaction is in progress)"); } was_opened = true; } else { Open(null); } string[] spaces = this.GetSpaceList(); bool encr = IO.GetEncryption(); IO.SetEncryption(false); IO.Write(0, e_code); // + 0 (4)Encryption indicator IO.SetEncryption(encr); IO.Write(-1, DEFS.DUMP_SIGNATURE_INCOMPLETE); // + 4 (4) Signature 'incomplete' IO.Write(-1, (int)0); // + 8 (4) CRC placeholder IO.Write(-1, (long)0); // +12 (8)Total length for (int sp_index = 0; sp_index < spaces.Length; sp_index++) { VSpace sp = GetSpace(spaces[sp_index]); VSVirtualMemoryManager vm = GetVM(spaces[sp_index]); if ((name == "") | (VSLib.Compare(name, sp.Name))) { long sp_hdr_pos = IO.GetPosition(); // Position for header(number of bytes) IO.Write(-1, (long)0); // Save space header IO.Write(-1, (short)sp.Name.Length); // Space neme length (short) IO.Write(-1, sp.Name); // Space name IO.Write(-1, (short)sp.Owner.Length); // Space owner length (short) IO.Write(-1, sp.Owner); // Space owner ////////////////////////////////////////////////////////////// // Save keys ////////////////////////////////////////////////////////////// IO.Write(-1, DEFS.DUMP_KEYS_SIGNATURE); // Start keys VSKeyManager kh = sp.KeyManager; kh.Reset(); while (kh.Next()) { long k = kh.Current; IO.Write(-1, k); } IO.Write(-1, (long)-1); // End keys // Save pool ares (starting from 2) short[] pools = sp.GetPoolsForDump(); // Create list of pools for (int i = 0; i < pools.Length; i++) { long a_desc = sp.GetFirstAddress(pools[i]); while (a_desc > 0) { VSAllocation a = sp.GetAllocationByDescriptor(a_desc); //////////// Save ADSC fields /////////// IO.Write(-1, a.Id); IO.Write(-1, a.Pool); IO.Write(-1, (a.Chunk == 0) ? a.Length : a.Size); // Memory size IO.Write(-1, a.ChunkSize); // Chunk sizeMemory size IO.Write(-1, a.ALLOC); // Alloc version (object) IO.Write(-1, a.FIXED); // Fixed part (object) //////////// Save data ////////////////// byte[] b = vm.ReadBytes(a.Address, a.Length); IO.Write(-1, ref b); a_desc = a.NEXT; if (a.Chunk != 0) { while (a_desc != 0) { a = sp.GetAllocationByDescriptor(a_desc); if ((a.Chunk == 0) | (a.Chunk == 1)) { break; } b = vm.ReadBytes(a.Address, a.Length); IO.Write(-1, ref b); a_desc = a.NEXT; } } } } long sp_count = IO.GetPosition() - sp_hdr_pos; // Calculate count long current_pos = IO.GetPosition(); // Save current position IO.Write(sp_hdr_pos, sp_count); // Write count to the header (incl hdr) IO.SetPosition(current_pos); // Restore position } } IO.Write(-1, (long)-1); // Write eof indicator IO.Write(12, (long)IO.GetLength()); // + 8 (8) - Total length IO.Flush(); uint c = IO.GetCRC32(12, -1); // calculate CRC32 IO.Write(8, c); // + 4 (4) - CRC32 IO.Write(4, DEFS.DUMP_SIGNATURE); // Signature 'complete' IO.Flush(); if (!was_opened) { Close(); } }