Exemplo n.º 1
0
        /// <summary>
        /// Validates that the volume has a valid partition.
        /// </summary>
        /// <param name="volume">The volume to validate.</param>
        /// <returns>Returns true if the volume is valid.</returns>
        private bool ValidateVolumePartition(LogicalVolume volume)
        {
            for (int i = 0; i < volume.PartitionMaps.Count; i++)
            {
                PartitionMap map = volume.PartitionMaps[0];

                bool found = false;
                foreach (var partition in this.Partitions)
                {
                    if (partition.Number == map.PartitionNumber)
                    {
                        // partition can only be member of one volume
                        if (partition.VolumeIndex >= 0)
                        {
                            return(false);
                        }

                        // Add cross references between partitions and volumes.
                        map.PartitionNumber   = this.Partitions.IndexOf(partition);
                        partition.VolumeIndex = this.LogicalVolumes.IndexOf(volume);
                        found = true;
                    }
                }

                if (!found)
                {
                    return(false);
                }
            }

            return(true);
        }
Exemplo n.º 2
0
        /// <summary>
        /// Reads a logical volume descriptor from the buffer.
        /// </summary>
        /// <param name="buffer">The buffer to read the data from.</param>
        /// <returns>Returns true if the descriptor is valid.</returns>
        private bool ReadLogicalDescriptor(byte[] buffer)
        {
            LogicalVolume volume = new LogicalVolume();

            volume.Id.Parse(84, buffer);
            volume.BlockSize = UdfHelper.Get32(212, buffer);
            if (volume.BlockSize < VirtualSectorSize || volume.BlockSize > MaxExtents)
            {
                return(false);
            }

            volume.FileSetLocation.Parse(248, buffer);

            int numPartitionMaps = UdfHelper.Get32(268, buffer);

            if (numPartitionMaps > MaxPartitions)
            {
                return(false);
            }

            int position = 440;

            for (int index = 0; index < numPartitionMaps; index++)
            {
                if (position + 2 > SectorSize)
                {
                    return(false);
                }

                PartitionMap pm = new PartitionMap();
                pm.Type = buffer[position];
                byte length = buffer[position + 1];
                if (position + length > SectorSize)
                {
                    return(false);
                }

                if (pm.Type == 1)
                {
                    if (position + 6 > SectorSize)
                    {
                        return(false);
                    }

                    pm.PartitionNumber = UdfHelper.Get16(position + 4, buffer);
                }
                else
                {
                    return(false);
                }

                position         += length;
                pm.PartitionIndex = volume.PartitionMaps.Count;
                volume.PartitionMaps.Add(pm);
            }

            this.LogicalVolumes.Add(volume);
            return(true);
        }