Esempio n. 1
0
        public VfsBtrfsFileSystem(Stream stream, BtrfsFileSystemOptions options)
            : base(options)
        {
            Context = new Context(options)
            {
                RawStream = stream,
            };
            foreach (var offset in BtrfsFileSystem.SuperblockOffsets)
            {
                if (offset + SuperBlock.Length > stream.Length)
                {
                    break;
                }

                stream.Position = offset;
                var superblockData = StreamUtilities.ReadExact(stream, SuperBlock.Length);
                var superblock     = new SuperBlock();
                superblock.ReadFrom(superblockData, 0);

                if (superblock.Magic != SuperBlock.BtrfsMagic)
                {
                    throw new IOException("Invalid Superblock Magic");
                }

                if (Context.SuperBlock == null)
                {
                    Context.SuperBlock = superblock;
                }
                else if (Context.SuperBlock.Generation < superblock.Generation)
                {
                    Context.SuperBlock = superblock;
                }

                Context.VerifyChecksum(superblock.Checksum, superblockData, 0x20, 0x1000 - 0x20);
            }
            if (Context.SuperBlock == null)
            {
                throw new IOException("No Superblock detected");
            }
            Context.ChunkTreeRoot = Context.ReadTree(Context.SuperBlock.ChunkRoot, Context.SuperBlock.ChunkRootLevel);
            Context.RootTreeRoot  = Context.ReadTree(Context.SuperBlock.Root, Context.SuperBlock.RootLevel);

            var      rootDir = (DirItem)Context.FindKey(Context.SuperBlock.RootDirObjectid, ItemType.DirItem);
            RootItem fsTreeLocation;

            if (!options.UseDefaultSubvolume)
            {
                fsTreeLocation = (RootItem)Context.FindKey(options.SubvolumeId, ItemType.RootItem);
            }
            else
            {
                fsTreeLocation = (RootItem)Context.FindKey(rootDir.ChildLocation.ObjectId, rootDir.ChildLocation.ItemType);
            }
            var rootDirObjectId = fsTreeLocation.RootDirId;

            Context.FsTrees.Add(rootDir.ChildLocation.ObjectId, Context.ReadTree(fsTreeLocation.ByteNr, fsTreeLocation.Level));

            var dirEntry = new DirEntry(rootDir.ChildLocation.ObjectId, rootDirObjectId);

            RootDirectory = new Directory(dirEntry, Context);
        }
Esempio n. 2
0
 /// <summary>
 /// Initializes a new instance of the BtrfsFileSystem class.
 /// </summary>
 /// <param name="stream">The stream containing the btrfs file system.</param>
 /// <param name="options">Options for opening the file system</param>
 public BtrfsFileSystem(Stream stream, BtrfsFileSystemOptions options)
     : base(new VfsBtrfsFileSystem(stream, options))
 {
 }
Esempio n. 3
0
 public Context(BtrfsFileSystemOptions options)
 {
     FsTrees = new Dictionary <ulong, NodeHeader>();
     Options = options;
 }