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); }
/// <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)) { }
public Context(BtrfsFileSystemOptions options) { FsTrees = new Dictionary <ulong, NodeHeader>(); Options = options; }