private static void InitializeSusp(IsoContext context, DirectoryRecord rootSelfRecord)
        {
            // Stage 1 - SUSP present?
            List <SuspExtension> extensions = new List <SuspExtension>();

            if (!SuspRecords.DetectSharingProtocol(rootSelfRecord.SystemUseData, 0))
            {
                context.SuspExtensions = new List <SuspExtension>();
                context.SuspDetected   = false;
                return;
            }
            context.SuspDetected = true;

            SuspRecords suspRecords = new SuspRecords(context, rootSelfRecord.SystemUseData, 0);

            // Stage 2 - Init general SUSP params
            SharingProtocolSystemUseEntry spEntry =
                (SharingProtocolSystemUseEntry)suspRecords.GetEntries(null, "SP")[0];

            context.SuspSkipBytes = spEntry.SystemAreaSkip;

            // Stage 3 - Init extensions
            List <SystemUseEntry> extensionEntries = suspRecords.GetEntries(null, "ER");

            if (extensionEntries != null)
            {
                foreach (ExtensionSystemUseEntry extension in extensionEntries)
                {
                    switch (extension.ExtensionIdentifier)
                    {
                    case "RRIP_1991A":
                    case "IEEE_P1282":
                    case "IEEE_1282":
                        extensions.Add(new RockRidgeExtension(extension.ExtensionIdentifier));
                        context.RockRidgeIdentifier = extension.ExtensionIdentifier;
                        break;

                    default:
                        extensions.Add(new GenericSuspExtension(extension.ExtensionIdentifier));
                        break;
                    }
                }
            }
            else if (suspRecords.GetEntries(null, "RR") != null)
            {
                // Some ISO creators don't add the 'ER' record for RockRidge, but write the (legacy)
                // RR record anyway
                extensions.Add(new RockRidgeExtension("RRIP_1991A"));
                context.RockRidgeIdentifier = "RRIP_1991A";
            }

            context.SuspExtensions = extensions;
        }
Example #2
0
        public ReaderDirEntry(IsoContext context, DirectoryRecord dirRecord)
        {
            _context  = context;
            _record   = dirRecord;
            _fileName = _record.FileIdentifier;

            bool rockRidge = !string.IsNullOrEmpty(_context.RockRidgeIdentifier);

            if (context.SuspDetected && _record.SystemUseData != null)
            {
                SuspRecords = new SuspRecords(_context, _record.SystemUseData, 0);
            }

            if (rockRidge && SuspRecords != null)
            {
                // The full name is taken from this record, even if it's a child-link record
                List <SystemUseEntry> nameEntries = SuspRecords.GetEntries(_context.RockRidgeIdentifier, "NM");
                StringBuilder         rrName      = new StringBuilder();
                if (nameEntries != null && nameEntries.Count > 0)
                {
                    foreach (PosixNameSystemUseEntry nameEntry in nameEntries)
                    {
                        rrName.Append(nameEntry.NameData);
                    }

                    _fileName = rrName.ToString();
                }

                // If this is a Rock Ridge child link, replace the dir record with that from the 'self' record
                // in the child directory.
                ChildLinkSystemUseEntry clEntry =
                    SuspRecords.GetEntry <ChildLinkSystemUseEntry>(_context.RockRidgeIdentifier, "CL");
                if (clEntry != null)
                {
                    _context.DataStream.Position = clEntry.ChildDirLocation * _context.VolumeDescriptor.LogicalBlockSize;
                    byte[] firstSector = StreamUtilities.ReadExact(_context.DataStream,
                                                                   _context.VolumeDescriptor.LogicalBlockSize);

                    DirectoryRecord.ReadFrom(firstSector, 0, _context.VolumeDescriptor.CharacterEncoding, out _record);
                    if (_record.SystemUseData != null)
                    {
                        SuspRecords = new SuspRecords(_context, _record.SystemUseData, 0);
                    }
                }
            }

            LastAccessTimeUtc = _record.RecordingDateAndTime;
            LastWriteTimeUtc  = _record.RecordingDateAndTime;
            CreationTimeUtc   = _record.RecordingDateAndTime;

            if (rockRidge && SuspRecords != null)
            {
                FileTimeSystemUseEntry tfEntry =
                    SuspRecords.GetEntry <FileTimeSystemUseEntry>(_context.RockRidgeIdentifier, "TF");

                if (tfEntry != null)
                {
                    if ((tfEntry.TimestampsPresent & FileTimeSystemUseEntry.Timestamps.Access) != 0)
                    {
                        LastAccessTimeUtc = tfEntry.AccessTime;
                    }

                    if ((tfEntry.TimestampsPresent & FileTimeSystemUseEntry.Timestamps.Modify) != 0)
                    {
                        LastWriteTimeUtc = tfEntry.ModifyTime;
                    }

                    if ((tfEntry.TimestampsPresent & FileTimeSystemUseEntry.Timestamps.Creation) != 0)
                    {
                        CreationTimeUtc = tfEntry.CreationTime;
                    }
                }
            }
        }