Beispiel #1
0
        public VfsXfsFileSystem(Stream stream, FileSystemParameters parameters)
            : base(new XfsFileSystemOptions(parameters))
        {
            stream.Position = 0;
            byte[] superblockData = Utilities.ReadFully(stream, 264);

            SuperBlock superblock = new SuperBlock();

            superblock.ReadFrom(superblockData, 0);

            if (superblock.Magic != SuperBlock.XfsMagic)
            {
                throw new IOException("Invalid superblock magic - probably not an xfs file system");
            }

            Context = new Context
            {
                RawStream  = stream,
                SuperBlock = superblock,
                Options    = (XfsFileSystemOptions)Options
            };

            var  allocationGroups = new AllocationGroup[superblock.AgCount];
            long offset           = 0;

            for (int i = 0; i < allocationGroups.Length; i++)
            {
                var ag = new AllocationGroup(Context, offset);
                allocationGroups[ag.InodeBtreeInfo.SequenceNumber] = ag;
                offset += ag.FreeBlockInfo.Length * superblock.Blocksize;
            }
            Context.AllocationGroups = allocationGroups;

            RootDirectory = new Directory(Context, Context.GetInode(superblock.RootInode));
        }
Beispiel #2
0
        internal static bool Detect(Stream stream)
        {
            if (stream.Length < 264)
            {
                return(false);
            }

            stream.Position = 0;
            byte[] superblockData = StreamUtilities.ReadFully(stream, 264);

            SuperBlock superblock = new SuperBlock();

            superblock.ReadFrom(superblockData, 0);

            return(superblock.Magic == SuperBlock.XfsMagic);
        }