Beispiel #1
0
        /// <summary>
        /// Generates a "free list" of unused blocks in the existing parity data
        /// for this drive which we can then re-use for adds, so that we don't grow
        /// the parity data unnecessarily.
        /// </summary>
        public List <FreeNode> GetFreeList()
        {
            BitArray blockMask = BlockMask;

            List <FreeNode> freeList = new List <FreeNode>();
            UInt32          block    = 0;

            while (block < MaxBlock)
            {
                if (!blockMask.Get((int)block))
                {
                    FreeNode n = new FreeNode();
                    n.Start  = block++;
                    n.Length = 1;
                    while (block < MaxBlock && (!blockMask.Get((int)block)))
                    {
                        n.Length++;
                        block++;
                    }
                    freeList.Add(n);
                }
                else
                {
                    block++;
                }
            }

            return(freeList);
        }
Beispiel #2
0
        public static UInt32 FindBest(List <FreeNode> list, UInt32 blocks)
        {
            FreeNode best = null;

            foreach (FreeNode n in list)
            {
                if (n.Length == blocks)
                {
                    best = n;
                    break;
                }
                else if (n.Length > blocks)
                {
                    if ((best == null) || (n.Length < best.Length))
                    {
                        best = n;
                    }
                }
            }
            if (best == null)
            {
                return(INVALID_BLOCK);
            }
            UInt32 result = best.Start;

            if (best.Length == blocks)
            {
                list.Remove(best);
            }
            else
            {
                best.Start  += blocks;
                best.Length -= blocks;
            }
            return(result);
        }
Beispiel #3
0
        /// <summary>
        /// Generates a "free list" of unused blocks in the existing parity data 
        /// for this drive which we can then re-use for adds, so that we don't grow 
        /// the parity data unnecessarily.
        /// </summary>
        public List<FreeNode> GetFreeList()
        {
            BitArray blockMask = BlockMask;

              List<FreeNode> freeList = new List<FreeNode>();
              UInt32 block = 0;
              while (block < MaxBlock)
            if (!blockMask.Get((int)block)) {
              FreeNode n = new FreeNode();
              n.Start = block++;
              n.Length = 1;
              while (block < MaxBlock && (!blockMask.Get((int)block))) {
            n.Length++;
            block++;
              }
              freeList.Add(n);
            }
            else
              block++;

              return freeList;
        }