Ejemplo n.º 1
0
        /// <summary>
        /// Fetch all directory entries to build the internal index
        /// </summary>
        public void BuildIndex()
        {
            if (_indexBuilt)
            {
                return;
            }

            if (!_descriptorsRead)
            {
                throw new FrameworkException("Error : You must read the descriptors first");
            }

            try
            {
                long rootLba   = _primaryVolumeDescriptor.RootDirectoryEntry.ExtentLba;
                var  stream    = new CBinaryReader(ReadSector(rootLba, _defaultSectorMode));
                var  rootEntry = ReadDirectoryEntry(stream);

                _index = new DataTrackIndex(rootEntry);
                AddDirectoryToIndex(_index.Root);
                _indexBuilt = true;
            }
            catch (FrameworkException ex)
            {
                throw ex;
            }
            catch (Exception)
            {
                throw new FrameworkException("Error while building the index : unable to read data to build the internal index cache");
            }
        }
Ejemplo n.º 2
0
        // Methods

        /// <summary>
        /// Init the pvd and allocate some space for the path table and the root directory
        /// </summary>
        /// <param name="volumeId">The volume identifier</param>
        /// <param name="pathTableSize">Size of the path table in sector (default 1)</param>
        /// <param name="rootDirectorySize">Size of the root directory in sector (default 1)</param>
        public void Prepare(string volumeId, int pathTableSize = 1, int rootDirectorySize = 1)
        {
            try
            {
                if (_prepared)
                {
                    return;
                }

                SeekSector(16);
                WriteEmptySectors(2 + pathTableSize * 4);

                var root = new DirectoryEntry(_isXa);
                root.IsDirectory = true;
                root.ExtentSize  = (uint)(rootDirectorySize * GetSectorDataSize(_defaultSectorMode));
                root.ExtentLba   = (uint)SectorCount;

                _index = new DataTrackIndex(root);

                _primaryVolumeDescriptor               = new PrimaryVolumeDescriptor(1);
                _primaryVolumeDescriptor.VolumeId      = volumeId;
                _primaryVolumeDescriptor.PathTableSize = (uint)(pathTableSize * GetSectorDataSize(_defaultSectorMode));

                // The root directory included in the volume descriptor doesn't allow XA, so let's create a separated one
                _primaryVolumeDescriptor.RootDirectoryEntry             = new DirectoryEntry(false);
                _primaryVolumeDescriptor.RootDirectoryEntry.IsDirectory = true;
                _primaryVolumeDescriptor.RootDirectoryEntry.ExtentSize  = root.ExtentSize;
                _primaryVolumeDescriptor.RootDirectoryEntry.ExtentLba   = root.ExtentLba;

                WriteEmptySectors(rootDirectorySize);

                _prepared = true;
            }
            catch (FrameworkException ex)
            {
                throw ex;
            }
            catch (Exception)
            {
                throw new FrameworkException("Errow while preparing track : unable to prepare data track");
            }
        }