Example #1
0
        /// <summary>
        /// Gey index names by space prefix
        /// </summary>
        /// <param name="space_name"></param>
        /// <returns></returns>
        private string[] get_indexes_for_space(string space_name)
        {
            List <string> lx = new List <string>();
            string        nm = space_name.Trim().ToLower();

            for (int i = 0; i < index_list.Count; i++)
            {
                string[] parsed_name = new string[2];
                parsed_name[0] = DEFS.ParseIndexSpace(index_list[i].Name);
                parsed_name[1] = DEFS.ParseIndexName(index_list[i].Name);
                if (nm == "")
                {
                    if (parsed_name[0] == "")
                    {
                        lx.Add(parsed_name[1]);
                    }
                }
                else
                {
                    if (VSLib.Compare(nm, parsed_name[0]))
                    {
                        lx.Add(parsed_name[1]);
                    }
                }
            }

            return(lx.ToArray());
        }
Example #2
0
        /// <summary>
        /// Array of the field names by pattern
        /// </summary>
        public string[] GetFields(string pattern = "*")
        {
            sync_cache();
            if (FCache == null)
            {
                return(new string[0]);
            }

            List <string> ls = new List <string>();

            for (int i = 0; i < FCache.Count; i++)
            {
                if (VSLib.Compare(pattern, FCache[i].NAME))
                {
                    ls.Add(FCache[i].NAME);
                }
            }
            return(ls.ToArray());
        }
Example #3
0
        /// <summary>
        /// Display space/storage name
        /// </summary>
        /// <param name="name"></param>
        /// <returns></returns>
        public string[] List(string name = "*")
        {
            List <string> l = new List <string>();

            string[] sp_list = GetSpaceNameList();

            bool nf = false;
            long sz = GetStorageSize();

            if (name == "*")
            {
                l.Add("Storage size:   " + sz.ToString("#,#;(#,#)") + " bytes (" + (sz / 1048576).ToString("#,#;(#,#)") + " Mb)");
            }

            for (int i = 0; i < sp_list.Length; i++)
            {
                if (l.Count > 0)
                {
                    l.Add(" ");
                }
                if (VSLib.Compare(name.Trim().ToLower(), sp_list[i]))
                {
                    nf = true;
                    string[] info = GetSpaceHeaderInfo(sp_list[i]);
                    for (int j = 0; j < info.Length; j++)
                    {
                        l.Add(info[j]);
                    }
                }
            }

            if (!nf)
            {
                l.Add("No space found matching search criteria '" + name + "'");
            }

            return(l.ToArray());
        }
Example #4
0
        /// <summary>
        /// Remove space: name: space name
        /// </summary>
        /// <param name="name"></param>
        /// <returns></returns>
        public void Remove(string name)
        {
            if (state != DEFS.STATE_DEFINED)
            {
                throw new VSException(DEFS.E0025_STORAGE_UNABLE_TO_COMPLETE_CODE, "- 'Remove' (storage is opened or undefined)");
            }

            if (!this.Lock())
            {
                throw new VSException(DEFS.E0001_UNABLE_TO_LOCK_CODE, "(Remove space)");
            }

            for (int n = (CATALOG.Count - 1); n >= 0; n--)
            {
                if (VSLib.Compare(name, CATALOG[n].Name))
                {
                    if (!IMO)
                    {
                        for (int i = 0; i < CATALOG[n].Partitions; i++)
                        {
                            System.IO.File.Delete(GetSpaceFileName(CATALOG[n].Name, CATALOG[n].Path, i));
                        }

                        FileStream fp = new FileStream(TransactionFileName, FileMode.Create);
                        fp.Close();
                        CATALOG.Delete(CATALOG[n].Name);
                        CATALOG.Save();
                    }
                    else
                    {
                        CATALOG.Delete(CATALOG[n].Name);
                    }
                }
            }
            Release();
        }
Example #5
0
        /// <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();
            }
        }