예제 #1
0
        private KeyValuePairList <int, IndexRecord> FindRemovalPath(byte[] key, out int indexOfEntryToRemove)
        {
            bool isParentNode         = true;
            List <IndexEntry> entries = m_rootRecord.IndexEntries;
            KeyValuePairList <int, IndexRecord> path = new KeyValuePairList <int, IndexRecord>();

            while (isParentNode)
            {
                int index = CollationHelper.FindIndexInParentNode(entries, key, m_rootRecord.CollationRule);
                if (!entries[index].IsLastEntry && CollationHelper.Compare(entries[index].Key, key, m_rootRecord.CollationRule) == 0)
                {
                    indexOfEntryToRemove = index;
                    return(path);
                }
                long        subnodeVBN  = entries[index].SubnodeVBN;
                IndexRecord indexRecord = ReadIndexRecord(subnodeVBN);
                isParentNode = indexRecord.IsParentNode;
                entries      = indexRecord.IndexEntries;
                path.Add(index, indexRecord);
            }

            indexOfEntryToRemove = CollationHelper.FindIndexInLeafNode(entries, key, m_rootRecord.CollationRule);
            if (indexOfEntryToRemove >= 0)
            {
                return(path);
            }
            else
            {
                return(null);
            }
        }
예제 #2
0
        public KeyValuePair <MftSegmentReference, byte[]>?FindEntry(byte[] key)
        {
            if (!m_rootRecord.IsParentNode)
            {
                int index = CollationHelper.FindIndexInLeafNode(m_rootRecord.IndexEntries, key, m_rootRecord.CollationRule);
                if (index >= 0)
                {
                    IndexEntry entry = m_rootRecord.IndexEntries[index];
                    return(new KeyValuePair <MftSegmentReference, byte[]>(entry.FileReference, entry.Key));
                }
                else
                {
                    return(null);
                }
            }
            else
            {
                bool isParentNode         = true;
                List <IndexEntry> entries = m_rootRecord.IndexEntries;
                int index;
                while (isParentNode)
                {
                    index = CollationHelper.FindIndexInParentNode(entries, key, m_rootRecord.CollationRule);
                    IndexEntry entry = entries[index];
                    if (!entry.IsLastEntry && CollationHelper.Compare(entry.Key, key, m_rootRecord.CollationRule) == 0)
                    {
                        return(new KeyValuePair <MftSegmentReference, byte[]>(entry.FileReference, entry.Key));
                    }
                    else
                    {
                        long        subnodeVBN  = entry.SubnodeVBN;
                        IndexRecord indexRecord = ReadIndexRecord(subnodeVBN);
                        isParentNode = indexRecord.IsParentNode;
                        entries      = indexRecord.IndexEntries;
                    }
                }

                index = CollationHelper.FindIndexInLeafNode(entries, key, m_rootRecord.CollationRule);
                if (index >= 0)
                {
                    IndexEntry entry = entries[index];
                    return(new KeyValuePair <MftSegmentReference, byte[]>(entry.FileReference, entry.Key));
                }
                else
                {
                    return(null);
                }
            }
        }
예제 #3
0
        public bool UpdateFileNameRecord(FileNameRecord fileNameRecord)
        {
            byte[] key = fileNameRecord.GetBytes();
            if (!m_rootRecord.IsParentNode)
            {
                int index = CollationHelper.FindIndexInLeafNode(m_rootRecord.IndexEntries, key, m_rootRecord.CollationRule);
                if (index >= 0)
                {
                    m_rootRecord.IndexEntries[index].Key = key;
                    m_volume.UpdateFileRecord(m_fileRecord);
                    return(true);
                }
            }
            else
            {
                IndexRecord       indexRecord  = null;
                bool              isParentNode = true;
                List <IndexEntry> entries      = m_rootRecord.IndexEntries;
                int index;
                while (isParentNode)
                {
                    index = CollationHelper.FindIndexInParentNode(entries, key, m_rootRecord.CollationRule);
                    IndexEntry entry = entries[index];
                    if (!entry.IsLastEntry && CollationHelper.Compare(entry.Key, key, m_rootRecord.CollationRule) == 0)
                    {
                        entries[index].Key = key;
                        if (indexRecord == null)
                        {
                            m_volume.UpdateFileRecord(m_fileRecord);
                        }
                        else
                        {
                            long recordIndex = ConvertToRecordIndex(indexRecord.RecordVBN);
                            WriteIndexRecord(recordIndex, indexRecord);
                        }
                        return(true);
                    }
                    else
                    {
                        long subnodeVBN = entry.SubnodeVBN;
                        indexRecord  = ReadIndexRecord(subnodeVBN);
                        isParentNode = indexRecord.IsParentNode;
                        entries      = indexRecord.IndexEntries;
                    }
                }

                index = CollationHelper.FindIndexInLeafNode(entries, key, m_rootRecord.CollationRule);
                if (index >= 0)
                {
                    entries[index].Key = key;
                    if (indexRecord == null)
                    {
                        m_volume.UpdateFileRecord(m_fileRecord);
                    }
                    else
                    {
                        long recordIndex = ConvertToRecordIndex(indexRecord.RecordVBN);
                        WriteIndexRecord(recordIndex, indexRecord);
                    }
                    return(true);
                }
            }

            return(false);
        }