Exemplo n.º 1
0
        /// <returns>In bytes</returns>
        public static long GetMaxNewExtentLength(DynamicDisk disk, long alignInSectors)
        {
            List <DiskExtent> unallocatedExtents = GetUnallocatedSpace(disk);

            if (unallocatedExtents == null)
            {
                return(-1);
            }

            long result = 0;

            for (int index = 0; index < unallocatedExtents.Count; index++)
            {
                DiskExtent extent = unallocatedExtents[index];
                if (alignInSectors > 1)
                {
                    extent = DiskExtentHelper.GetAlignedDiskExtent(extent, alignInSectors);
                }
                if (extent.Size > result)
                {
                    result = extent.Size;
                }
            }
            return(result);
        }
Exemplo n.º 2
0
        /// <param name="allocationLength">In bytes</param>
        /// <param name="alignInSectors">0 or 1 for no alignment</param>
        /// <returns>Allocated DiskExtent or null if there is not enough free disk space</returns>
        public static DiskExtent AllocateNewExtent(DynamicDisk disk, long allocationLength, long alignInSectors)
        {
            List <DiskExtent> unallocatedExtents = GetUnallocatedSpace(disk);

            if (unallocatedExtents == null)
            {
                return(null);
            }

            for (int index = 0; index < unallocatedExtents.Count; index++)
            {
                DiskExtent extent = unallocatedExtents[index];
                if (alignInSectors > 1)
                {
                    extent = DiskExtentHelper.GetAlignedDiskExtent(extent, alignInSectors);
                }
                if (extent.Size >= allocationLength)
                {
                    return(new DiskExtent(extent.Disk, extent.FirstSector, allocationLength));
                }
            }
            return(null);
        }