Example #1
0
 internal IEnumerable <ComponentRecord> GetVolumeComponents(ulong volumeId)
 {
     foreach (var record in _records.Values)
     {
         if (record.RecordType == RecordType.Component)
         {
             ComponentRecord cmpntRecord = (ComponentRecord)record;
             if (cmpntRecord.VolumeId == volumeId)
             {
                 yield return(cmpntRecord);
             }
         }
     }
 }
Example #2
0
        private LogicalVolumeStatus GetComponentStatus(ComponentRecord cmpnt)
        {
            // NOTE: no support for RAID, so either valid or failed...
            LogicalVolumeStatus status = LogicalVolumeStatus.Healthy;

            foreach (var extent in _database.GetComponentExtents(cmpnt.Id))
            {
                DiskRecord disk = _database.GetDisk(extent.DiskId);
                if (!_disks.ContainsKey(new Guid(disk.DiskGuidString)))
                {
                    status = LogicalVolumeStatus.Failed;
                    break;
                }
            }

            return(status);
        }
Example #3
0
        private SparseStream OpenComponent(ComponentRecord component)
        {
            if (component.MergeType == ExtentMergeType.Concatenated)
            {
                List <ExtentRecord> extents = new List <ExtentRecord>(_database.GetComponentExtents(component.Id));
                extents.Sort(CompareExtentOffsets);

                // Sanity Check...
                long pos = 0;
                foreach (var extent in extents)
                {
                    if (extent.OffsetInVolumeLba != pos)
                    {
                        throw new IOException("Volume extents are non-contiguous");
                    }

                    pos += extent.SizeLba;
                }

                List <SparseStream> streams = new List <SparseStream>();
                foreach (var extent in extents)
                {
                    streams.Add(OpenExtent(extent));
                }

                return(new ConcatStream(Ownership.Dispose, streams.ToArray()));
            }
            else if (component.MergeType == ExtentMergeType.Interleaved)
            {
                List <ExtentRecord> extents = new List <ExtentRecord>(_database.GetComponentExtents(component.Id));
                extents.Sort(CompareExtentInterleaveOrder);

                List <SparseStream> streams = new List <SparseStream>();
                foreach (var extent in extents)
                {
                    streams.Add(OpenExtent(extent));
                }

                return(new StripedStream(component.StripeSizeSectors * Sizes.Sector, Ownership.Dispose, streams.ToArray()));
            }
            else
            {
                throw new NotImplementedException("Unknown component mode: " + component.MergeType);
            }
        }
Example #4
0
        public static DatabaseRecord ReadFrom(byte[] buffer, int offset)
        {
            DatabaseRecord result = null;

            if (Utilities.ToInt32BigEndian(buffer, offset + 0xC) != 0)
            {
                switch ((RecordType)(buffer[offset + 0x13] & 0xF))
                {
                case RecordType.Volume:
                    result = new VolumeRecord();
                    break;

                case RecordType.Component:
                    result = new ComponentRecord();
                    break;

                case RecordType.Extent:
                    result = new ExtentRecord();
                    break;

                case RecordType.Disk:
                    result = new DiskRecord();
                    break;

                case RecordType.DiskGroup:
                    result = new DiskGroupRecord();
                    break;

                default:
                    throw new NotImplementedException("Unrecognized record type: " + buffer[offset + 0x13]);
                }

                result.DoReadFrom(buffer, offset);
            }

            return(result);
        }