示例#1
0
        internal static bool Detect(Stream stream)
        {
            if (stream.Length < 1536)
            {
                return(false);
            }

            stream.Position = 1024;

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

            hdr.ReadFrom(headerBuf, 0);

            return(hdr.IsValid);
        }
示例#2
0
        public HfsFileSystemImpl(Stream s)
            : base(new DiscFileSystemOptions())
        {
            s.Position = 1024;
            // Master block in HFS is 162 byes
            byte[] headerBuf         = StreamUtilities.ReadExact(s, 162);
            MasterDirectoryBlock hdr = new MasterDirectoryBlock();

            hdr.ReadFrom(headerBuf, 0);

            Context = new Context();
            Context.VolumeStream         = s;
            Context.MasterDirectoryBlock = hdr;

            //FileBuffer catalogBuffer = new FileBuffer(Context, hdr.CatalogFile, CatalogNodeId.CatalogFileId);
            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);

            //FileBuffer attributesBuffer = new FileBuffer(Context, hdr.AttributesFile, CatalogNodeId.AttributesFileId);
            //Context.Attributes = new BTree<AttributeKey>(attributesBuffer);

            // 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);
        }