Ejemplo n.º 1
0
        public Directory(UdfContext context, LogicalPartition partition, FileEntry fileEntry)
            : base(context, partition, fileEntry, (uint)partition.LogicalBlockSize)
        {
            if (FileContent.Capacity > int.MaxValue)
            {
                throw new NotImplementedException("Very large directory");
            }

            _entries = new List <FileIdentifier>();

            byte[] contentBytes = StreamUtilities.ReadFully(FileContent, 0, (int)FileContent.Capacity);

            int pos = 0;

            while (pos < contentBytes.Length)
            {
                FileIdentifier id   = new FileIdentifier();
                int            size = id.ReadFrom(contentBytes, pos);

                if ((id.FileCharacteristics & (FileCharacteristic.Deleted | FileCharacteristic.Parent)) == 0)
                {
                    _entries.Add(id);
                }

                pos += size;
            }
        }
Ejemplo n.º 2
0
        public static File FromDescriptor(UdfContext context, LongAllocationDescriptor icb)
        {
            LogicalPartition partition = context.LogicalPartitions[icb.ExtentLocation.Partition];

            byte[]        rootDirData = UdfUtilities.ReadExtent(context, icb);
            DescriptorTag rootDirTag  = Utilities.ToStruct <DescriptorTag>(rootDirData, 0);

            if (rootDirTag.TagIdentifier == TagIdentifier.ExtendedFileEntry)
            {
                ExtendedFileEntry fileEntry = Utilities.ToStruct <ExtendedFileEntry>(rootDirData, 0);
                if (fileEntry.InformationControlBlock.FileType == FileType.Directory)
                {
                    return(new Directory(context, partition, fileEntry));
                }
                else
                {
                    return(new File(context, partition, fileEntry, (uint)partition.LogicalBlockSize));
                }
            }
            else if (rootDirTag.TagIdentifier == TagIdentifier.FileEntry)
            {
                FileEntry fileEntry = Utilities.ToStruct <FileEntry>(rootDirData, 0);
                if (fileEntry.InformationControlBlock.FileType == FileType.Directory)
                {
                    return(new Directory(context, partition, fileEntry));
                }
                else
                {
                    return(new File(context, partition, fileEntry, (uint)partition.LogicalBlockSize));
                }
            }
            else
            {
                throw new NotImplementedException("Only ExtendedFileEntries implemented");
            }
        }
Ejemplo n.º 3
0
            private void Initialize()
            {
                Context = new UdfContext
                {
                    PhysicalPartitions = new Dictionary <ushort, PhysicalPartition>(),
                    PhysicalSectorSize = (int)_sectorSize,
                    LogicalPartitions  = new List <LogicalPartition>()
                };

                IBuffer dataBuffer = new StreamBuffer(_data, Ownership.None);

                AnchorVolumeDescriptorPointer avdp = AnchorVolumeDescriptorPointer.FromStream(_data, 256, _sectorSize);

                uint sector          = avdp.MainDescriptorSequence.Location;
                bool terminatorFound = false;

                while (!terminatorFound)
                {
                    _data.Position = sector * (long)_sectorSize;

                    DescriptorTag dt;
                    if (!DescriptorTag.TryFromStream(_data, out dt))
                    {
                        break;
                    }

                    switch (dt.TagIdentifier)
                    {
                    case TagIdentifier.PrimaryVolumeDescriptor:
                        _pvd = PrimaryVolumeDescriptor.FromStream(_data, sector, _sectorSize);
                        break;

                    case TagIdentifier.ImplementationUseVolumeDescriptor:

                        // Not used
                        break;

                    case TagIdentifier.PartitionDescriptor:
                        PartitionDescriptor pd = PartitionDescriptor.FromStream(_data, sector, _sectorSize);
                        if (Context.PhysicalPartitions.ContainsKey(pd.PartitionNumber))
                        {
                            throw new IOException("Duplicate partition number reading UDF Partition Descriptor");
                        }

                        Context.PhysicalPartitions[pd.PartitionNumber] = new PhysicalPartition(pd, dataBuffer,
                                                                                               _sectorSize);
                        break;

                    case TagIdentifier.LogicalVolumeDescriptor:
                        _lvd = LogicalVolumeDescriptor.FromStream(_data, sector, _sectorSize);
                        break;

                    case TagIdentifier.UnallocatedSpaceDescriptor:

                        // Not used for reading
                        break;

                    case TagIdentifier.TerminatingDescriptor:
                        terminatorFound = true;
                        break;

                    default:
                        break;
                    }

                    sector++;
                }

                // Convert logical partition descriptors into actual partition objects
                for (int i = 0; i < _lvd.PartitionMaps.Length; ++i)
                {
                    Context.LogicalPartitions.Add(LogicalPartition.FromDescriptor(Context, _lvd, i));
                }

                byte[] fsdBuffer = UdfUtilities.ReadExtent(Context, _lvd.FileSetDescriptorLocation);
                if (DescriptorTag.IsValid(fsdBuffer, 0))
                {
                    FileSetDescriptor fsd = Utilities.ToStruct <FileSetDescriptor>(fsdBuffer, 0);
                    RootDirectory = (Directory)File.FromDescriptor(Context, fsd.RootDirectoryIcb);
                }
            }