示例#1
0
        public override IEnumerable <StreamExtent> GetExtentsInRange(long start, long count)
        {
            CheckDisposed();

            return
                (StreamExtent.Intersect(
                     StreamExtent.Union(GetExtentsRaw(start, count), _parentStream.GetExtentsInRange(start, count)),
                     new StreamExtent(start, count)));
        }
        public void TestIntersect1()
        {
            StreamExtent[] s1 = new StreamExtent[] {
                new StreamExtent(0, 4)
            };
            StreamExtent[] s2 = new StreamExtent[] {
                new StreamExtent(4, 8)
            };
            StreamExtent[] r = new StreamExtent[] { };

            Compare(r, StreamExtent.Intersect(s1, s2));
        }
        public void TestIntersect5()
        {
            StreamExtent[] s1 = new StreamExtent[] {
                new StreamExtent(0, 10)
            };
            StreamExtent[] s2 = new StreamExtent[] {
                new StreamExtent(3, 5)
            };
            StreamExtent[] r = new StreamExtent[] {
                new StreamExtent(3, 5)
            };

            Compare(r, StreamExtent.Intersect(s1, s2));
        }
        public void TestIntersect4()
        {
            StreamExtent[] s1 = new StreamExtent[] {
                new StreamExtent(0, 4)
            };
            StreamExtent[] s2 = new StreamExtent[] {
                new StreamExtent(3, 8)
            };
            StreamExtent[] s3 = new StreamExtent[] {
                new StreamExtent(10, 10)
            };
            StreamExtent[] r = new StreamExtent[] {
            };

            Compare(r, StreamExtent.Intersect(s1, s2, s3));
        }
        public void TestIntersect3()
        {
            StreamExtent[] s1 = new StreamExtent[] {
                new StreamExtent(0, 4),
                new StreamExtent(10, 10)
            };
            StreamExtent[] s2 = new StreamExtent[] {
                new StreamExtent(3, 8)
            };
            StreamExtent[] r = new StreamExtent[] {
                new StreamExtent(3, 1),
                new StreamExtent(10, 1)
            };

            Compare(r, StreamExtent.Intersect(s1, s2));
        }
示例#6
0
        /// <summary>
        /// Indicates if a stream contains a valid partition table.
        /// </summary>
        /// <param name="disk">The stream to inspect</param>
        /// <returns><c>true</c> if the partition table is valid, else <c>false</c>.</returns>
        public static bool IsValid(Stream disk)
        {
            if (disk.Length < Utilities.SectorSize)
            {
                return(false);
            }

            disk.Position = 0;
            byte[] bootSector = Utilities.ReadFully(disk, Utilities.SectorSize);

            // Check for the 'bootable sector' marker
            if (bootSector[510] != 0x55 || bootSector[511] != 0xAA)
            {
                return(false);
            }

            bool foundPartition = false;

            List <StreamExtent> knownPartitions = new List <StreamExtent>();

            foreach (var record in ReadPrimaryRecords(bootSector))
            {
                // If the partition extends beyond the end of the disk, this is probably an invalid partition table
                if (record.LBALength != 0xFFFFFFFF && (record.LBAStart + (long)record.LBALength) * Sizes.Sector > disk.Length)
                {
                    return(false);
                }

                if (record.LBALength > 0)
                {
                    foundPartition = true;
                }

                StreamExtent[] thisPartitionExtents = new StreamExtent[] { new StreamExtent(record.LBAStart, record.LBALength) };

                // If the partition intersects another partition, this is probably an invalid partition table
                foreach (var overlap in StreamExtent.Intersect(knownPartitions, thisPartitionExtents))
                {
                    return(false);
                }

                knownPartitions = new List <StreamExtent>(StreamExtent.Union(knownPartitions, thisPartitionExtents));
            }

            return(foundPartition);
        }
示例#7
0
        public override IEnumerable <StreamExtent> GetExtentsInRange(long start, long count)
        {
            CheckDisposed();

            long maxCount = Math.Min(Length, start + count) - start;

            if (maxCount < 0)
            {
                return(new StreamExtent[0]);
            }

            IEnumerable <StreamExtent> parentExtents = _parentStream.GetExtentsInRange(start, maxCount);

            IEnumerable <StreamExtent> result = StreamExtent.Union(LayerExtents(start, maxCount), parentExtents);

            result = StreamExtent.Intersect(result, new[] { new StreamExtent(start, maxCount) });
            return(result);
        }
 public override IEnumerable <StreamExtent> GetExtentsInRange(long start, long count)
 {
     return(StreamExtent.Intersect(
                new[] { new StreamExtent(0, Capacity) },
                new StreamExtent(start, count)));
 }
 public override IEnumerable <StreamExtent> GetExtentsInRange(long start, long count)
 {
     return(StreamExtent.Intersect(_attribute.RawBuffer.GetExtentsInRange(start, count), new StreamExtent(0, Capacity)));
 }
示例#10
0
 public IEnumerable <StreamExtent> GetExtentsInRange(long start, long count)
 {
     return(StreamExtent.Intersect(Extents, new StreamExtent(start, count)));
 }