Esempio n. 1
0
        public HfsPlusFileSystemImpl(Stream s)
            : base(new DiscFileSystemOptions())
        {
            s.Position = 1024;

            byte[]       headerBuf = Utilities.ReadFully(s, 512);
            VolumeHeader hdr       = new VolumeHeader();

            hdr.ReadFrom(headerBuf, 0);

            Context = new HfsPlus.Context();
            Context.VolumeStream = s;
            Context.VolumeHeader = hdr;

            FileBuffer catalogBuffer = new FileBuffer(Context, hdr.CatalogFile, CatalogNodeId.CatalogFileId);

            Context.Catalog = new BTree <CatalogKey>(catalogBuffer);

            FileBuffer extentsBuffer = new FileBuffer(Context, hdr.ExtentsFile, CatalogNodeId.ExtentsFileId);

            Context.ExtentsOverflow = new BTree <ExtentKey>(extentsBuffer);

            // Establish Root directory
            byte[]        rootThreadData = Context.Catalog.Find(new CatalogKey(CatalogNodeId.RootFolderId, string.Empty));
            CatalogThread rootThread     = new CatalogThread();

            rootThread.ReadFrom(rootThreadData, 0);
            byte[]   rootDirEntryData = Context.Catalog.Find(new CatalogKey(rootThread.ParentId, rootThread.Name));
            DirEntry rootDirEntry     = new DirEntry(rootThread.Name, rootDirEntryData);

            RootDirectory = (Directory)GetFile(rootDirEntry);
        }
Esempio n. 2
0
        /// <summary>
        /// Initializes a new instance of the <see cref="HfsPlusFileSystemImpl"/> class.
        /// </summary>
        /// <param name="stream">A stream containing the file system.</param>
        public HfsPlusFileSystemImpl(Stream stream)
            : base(new DiscFileSystemOptions())
        {
            if (stream == null)
            {
                throw new ArgumentNullException(nameof(stream));
            }

            if (stream.Length < 0x600)
            {
                throw new InvalidDataException("The stream does not represent a valid HFS+ file system");
            }

            stream.Position = 1024;

            byte[]       headerBuf = StreamUtilities.ReadExact(stream, 512);
            VolumeHeader hdr       = new VolumeHeader();

            hdr.ReadFrom(headerBuf, 0);

            if (!hdr.IsValid)
            {
                throw new InvalidDataException("The stream does not represent a valid HFS+ file system");
            }

            this.Context = new Context();
            this.Context.VolumeStream = stream;
            this.Context.VolumeHeader = hdr;

            FileBuffer catalogBuffer = new FileBuffer(this.Context, hdr.CatalogFile, CatalogNodeId.CatalogFileId);

            this.Context.Catalog = new BTree <CatalogKey>(catalogBuffer);

            FileBuffer extentsBuffer = new FileBuffer(this.Context, hdr.ExtentsFile, CatalogNodeId.ExtentsFileId);

            this.Context.ExtentsOverflow = new BTree <ExtentKey>(extentsBuffer);

            FileBuffer attributesBuffer = new FileBuffer(this.Context, hdr.AttributesFile, CatalogNodeId.AttributesFileId);

            this.Context.Attributes = new BTree <AttributeKey>(attributesBuffer);

            // Establish Root directory
            byte[]        rootThreadData = this.Context.Catalog.Find(new CatalogKey(CatalogNodeId.RootFolderId, string.Empty));
            CatalogThread rootThread     = new CatalogThread();

            rootThread.ReadFrom(rootThreadData, 0);
            byte[]   rootDirEntryData = this.Context.Catalog.Find(new CatalogKey(rootThread.ParentId, rootThread.Name));
            DirEntry rootDirEntry     = new DirEntry(rootThread.Name, rootDirEntryData);

            this.RootDirectory = (HfsPlusDirectory)this.GetFile(rootDirEntry);
        }