Exemple #1
0
        private int FindEmptyItem(int startIndex)
        {
            startIndex++;

            var emptyEntryIndex = default(int?);
            var maxCapacity     = index.SizeInBlocks * index.BlockSize;

            if (maxCapacity > startIndex)
            {
                var buffer = new DirectoryItem[maxCapacity - startIndex];
                blockStream.Read(startIndex, buffer);

                emptyEntryIndex = buffer
                                  .Where(x => x.Entry.Flags == DirectoryFlags.None || (x.Entry.Flags & DirectoryFlags.Deleted) != 0)
                                  .Select((x, entryIndex) => (int?)entryIndex)
                                  .FirstOrDefault();
            }

            if (emptyEntryIndex == null)
            {
                index.SetSizeInBlocks(index.SizeInBlocks + 1);
                return(startIndex);
            }

            return(startIndex + emptyEntryIndex.Value);
        }
Exemple #2
0
        public IDirectoryEntryInfo[] GetDirectoryEntries()
        {
            indexLock.EnterReadLock();
            try
            {
                var result = new List <IDirectoryEntryInfo>(itemsCount);
                if (itemsCount > 0)
                {
                    var buffer = new DirectoryItem[itemsCount];
                    blockStream.Read(1, buffer);

                    var names = new short[lastNameOffset];
                    nameIndexBlockStream.Read(0, names);

                    foreach (var item in buffer.Where(x => (x.Entry.Flags & DirectoryFlags.Deleted) == 0))
                    {
                        var entry = item.Entry;

                        var nameLength = names[entry.NameOffset];
                        var nameBuffer = new char[nameLength];
                        for (var i = 0; i < nameLength; i++)
                        {
                            nameBuffer[i] = (char)names[entry.NameOffset + 1 + i];
                        }

                        result.Add(new DirectoryEntryInfo(entry, new string(nameBuffer)));
                    }
                }

                return(result.ToArray());
            }
            finally
            {
                indexLock.ExitReadLock();
            }
        }