예제 #1
0
        internal static bool Detect(Stream stream)
        {
            if (stream.Length < 2048)
            {
                return false;
            }

            stream.Position = 1024;
            byte[] superblockData = Utilities.ReadFully(stream, 1024);

            SuperBlock superblock = new SuperBlock();
            superblock.ReadFrom(superblockData, 0);

            return superblock.Magic == SuperBlock.Ext2Magic;
        }
예제 #2
0
        public VfsExtFileSystem(Stream stream, FileSystemParameters parameters)
            : base(new ExtFileSystemOptions(parameters))
        {
            stream.Position = 1024;
            byte[] superblockData = Utilities.ReadFully(stream, 1024);

            SuperBlock superblock = new SuperBlock();

            superblock.ReadFrom(superblockData, 0);

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

            if (superblock.RevisionLevel == SuperBlock.OldRevision)
            {
                throw new IOException("Old ext revision - not supported");
            }

            if ((superblock.IncompatibleFeatures & ~SupportedIncompatibleFeatures) != 0)
            {
                throw new IOException("Incompatible ext features present: " + (superblock.IncompatibleFeatures & ~SupportedIncompatibleFeatures));
            }

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

            uint numGroups      = Utilities.Ceil(superblock.BlocksCount, superblock.BlocksPerGroup);
            long blockDescStart = (superblock.FirstDataBlock + 1) * (long)superblock.BlockSize;

            stream.Position = blockDescStart;
            byte[] blockDescData = Utilities.ReadFully(stream, (int)numGroups * BlockGroup.DescriptorSize);

            _blockGroups = new BlockGroup[numGroups];
            for (int i = 0; i < numGroups; ++i)
            {
                BlockGroup bg = new BlockGroup();
                bg.ReadFrom(blockDescData, i * BlockGroup.DescriptorSize);
                _blockGroups[i] = bg;
            }

            RootDirectory = new Directory(Context, 2, GetInode(2));
        }
예제 #3
0
        internal static bool Detect(Stream stream)
        {
            if (stream.Length < 2048)
            {
                return(false);
            }

            stream.Position = 1024;
            byte[] superblockData = Utilities.ReadFully(stream, 1024);

            SuperBlock superblock = new SuperBlock();

            superblock.ReadFrom(superblockData, 0);

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