internal Superblock(byte[] bytes)
        {
            Signature = BitConverter.ToUInt16(bytes, 0x38);

            if (Signature != EXT2_SUPER_MAGIC)
            {
                TotalInodeCount             = BitConverter.ToUInt32(bytes, 0x00);
                TotalBlockCount             = BitConverter.ToUInt32(bytes, 0x04);
                SuperUserReservedBlockCount = BitConverter.ToUInt32(bytes, 0x08);
                FreeBlockCount = BitConverter.ToUInt32(bytes, 0x0C);
                FreeInodeCount = BitConverter.ToUInt32(bytes, 0x10);
                FirstDataBlock = BitConverter.ToUInt32(bytes, 0x14);
                #region BlockSize

                uint s_log_block_size = BitConverter.ToUInt32(bytes, 0x18);
                BlockSize = (uint)1024 << (ushort)s_log_block_size;

                #endregion BlockSize
                #region ClusterSize

                uint s_log_frag_size = BitConverter.ToUInt32(bytes, 0x1C);
                ClusterSize = (uint)1024 << (ushort)s_log_frag_size;

                #endregion ClusterSize
                BlocksPerGroup              = BitConverter.ToUInt32(bytes, 0x20);
                ClustersPerGroup            = BitConverter.ToUInt32(bytes, 0x24);
                InodesPerGroup              = BitConverter.ToUInt32(bytes, 0x28);
                MountTime                   = NativeMethods.FromUnixTime(BitConverter.ToUInt32(bytes, 0x2C));
                WriteTime                   = NativeMethods.FromUnixTime(BitConverter.ToUInt32(bytes, 0x30));
                MountCount                  = BitConverter.ToUInt16(bytes, 0x34);
                MaxMountCount               = BitConverter.ToUInt16(bytes, 0x36);
                State                       = (S_STATE)BitConverter.ToUInt16(bytes, 0x3A);
                Errors                      = (S_ERRORS)BitConverter.ToUInt32(bytes, 0x3C);
                MinorRevisionLevel          = BitConverter.ToUInt16(bytes, 0x3E);
                LastCheckTime               = NativeMethods.FromUnixTime(BitConverter.ToUInt32(bytes, 0x40));
                CheckInterval               = BitConverter.ToUInt32(bytes, 0x44);
                CreatorOS                   = (S_CREATOR_OS)BitConverter.ToUInt32(bytes, 0x48);
                RevisionLevel               = BitConverter.ToUInt32(bytes, 0x4C);
                DefaultUID                  = BitConverter.ToUInt16(bytes, 0x50);
                DefaultGID                  = BitConverter.ToUInt16(bytes, 0x52);
                FirstNonReservedInode       = BitConverter.ToUInt32(bytes, 0x54);
                InodeSize                   = BitConverter.ToUInt16(bytes, 0x58);
                BlockGroupNumber            = BitConverter.ToUInt16(bytes, 0x5A);
                FeatureCompat               = (S_FEATURE_COMPAT)BitConverter.ToUInt32(bytes, 0x5C);
                FeatureIncompat             = (S_FEATURE_INCOMPAT)BitConverter.ToUInt32(bytes, 0x60);
                FeatureROCompat             = (S_FEATURE_RO_COMPAT)BitConverter.ToUInt32(bytes, 0x64);
                VolumeUUID                  = new Guid(NativeMethods.GetSubArray(bytes, 0x68, 0x10));
                VolumeName                  = Encoding.ASCII.GetString(bytes, 0x78, 0x10).TrimEnd('\0');
                LastMountedDirectory        = Encoding.ASCII.GetString(bytes, 0x88, 0x40).Split('\0')[0];
                AlgorithmBitmap             = (S_ALGO_BITMAP)BitConverter.ToUInt32(bytes, 0xC8);
                PreAllocatedBlocks          = bytes[0xCC];
                PreAllocatedDirectoryBlocks = bytes[0xCD];
                JournalSuperblockUUID       = new Guid(NativeMethods.GetSubArray(bytes, 0xD0, 0x10));
                JournalInode                = BitConverter.ToUInt32(bytes, 0xE0);
                JournalDeviceNumber         = BitConverter.ToUInt32(bytes, 0xE4);
                OrphanListOffset            = BitConverter.ToUInt32(bytes, 0xE8);
                HTREEHashSeed               = BitConverter.ToUInt32(bytes, 0xEC);
                HashVersion                 = (S_DEF_HASH_VERSION)bytes[0xFC];
                DefaultMountOptions         = (S_DEFAULT_MOUNT_OPTS)BitConverter.ToUInt32(bytes, 0x100);
                FirstMetablockBlockGroup    = BitConverter.ToUInt32(bytes, 0x104);
            }
            else
            {
                throw new Exception("Invalid Superblock Signature.");
            }
        }
Ejemplo n.º 2
0
        internal Superblock(byte[] bytes)
        {
            Signature = BitConverter.ToUInt16(bytes, 0x38);

            if (Signature != EXT2_SUPER_MAGIC)
            {
                TotalInodeCount = BitConverter.ToUInt32(bytes, 0x00);
                TotalBlockCount = BitConverter.ToUInt32(bytes, 0x04);
                SuperUserReservedBlockCount = BitConverter.ToUInt32(bytes, 0x08);
                FreeBlockCount = BitConverter.ToUInt32(bytes, 0x0C);
                FreeInodeCount = BitConverter.ToUInt32(bytes, 0x10);
                FirstDataBlock = BitConverter.ToUInt32(bytes, 0x14);
                #region BlockSize

                uint s_log_block_size = BitConverter.ToUInt32(bytes, 0x18);
                BlockSize = (uint)1024 << (ushort)s_log_block_size;

                #endregion BlockSize
                #region ClusterSize

                uint s_log_frag_size = BitConverter.ToUInt32(bytes, 0x1C);
                ClusterSize = (uint)1024 << (ushort)s_log_frag_size;

                #endregion ClusterSize
                BlocksPerGroup = BitConverter.ToUInt32(bytes, 0x20);
                ClustersPerGroup = BitConverter.ToUInt32(bytes, 0x24);
                InodesPerGroup = BitConverter.ToUInt32(bytes, 0x28);
                MountTime = NativeMethods.FromUnixTime(BitConverter.ToUInt32(bytes, 0x2C));
                WriteTime = NativeMethods.FromUnixTime(BitConverter.ToUInt32(bytes, 0x30));
                MountCount = BitConverter.ToUInt16(bytes, 0x34);
                MaxMountCount = BitConverter.ToUInt16(bytes, 0x36);
                State = (S_STATE)BitConverter.ToUInt16(bytes, 0x3A);
                Errors = (S_ERRORS)BitConverter.ToUInt32(bytes, 0x3C);
                MinorRevisionLevel = BitConverter.ToUInt16(bytes, 0x3E);
                LastCheckTime = NativeMethods.FromUnixTime(BitConverter.ToUInt32(bytes, 0x40));
                CheckInterval = BitConverter.ToUInt32(bytes, 0x44);
                CreatorOS = (S_CREATOR_OS)BitConverter.ToUInt32(bytes, 0x48);
                RevisionLevel = BitConverter.ToUInt32(bytes, 0x4C);
                DefaultUID = BitConverter.ToUInt16(bytes, 0x50);
                DefaultGID = BitConverter.ToUInt16(bytes, 0x52);
                FirstNonReservedInode = BitConverter.ToUInt32(bytes, 0x54);
                InodeSize = BitConverter.ToUInt16(bytes, 0x58);
                BlockGroupNumber = BitConverter.ToUInt16(bytes, 0x5A);
                FeatureCompat = (S_FEATURE_COMPAT)BitConverter.ToUInt32(bytes, 0x5C);
                FeatureIncompat = (S_FEATURE_INCOMPAT)BitConverter.ToUInt32(bytes, 0x60);
                FeatureROCompat = (S_FEATURE_RO_COMPAT)BitConverter.ToUInt32(bytes, 0x64);
                VolumeUUID = new Guid(NativeMethods.GetSubArray(bytes, 0x68, 0x10));
                VolumeName = Encoding.ASCII.GetString(bytes, 0x78, 0x10).TrimEnd('\0');
                LastMountedDirectory = Encoding.ASCII.GetString(bytes, 0x88, 0x40).Split('\0')[0];
                AlgorithmBitmap = (S_ALGO_BITMAP)BitConverter.ToUInt32(bytes, 0xC8);
                PreAllocatedBlocks = bytes[0xCC];
                PreAllocatedDirectoryBlocks = bytes[0xCD];
                JournalSuperblockUUID = new Guid(NativeMethods.GetSubArray(bytes, 0xD0, 0x10));
                JournalInode = BitConverter.ToUInt32(bytes, 0xE0);
                JournalDeviceNumber = BitConverter.ToUInt32(bytes, 0xE4);
                OrphanListOffset = BitConverter.ToUInt32(bytes, 0xE8);
                HTREEHashSeed = BitConverter.ToUInt32(bytes, 0xEC);
                HashVersion = (S_DEF_HASH_VERSION)bytes[0xFC];
                DefaultMountOptions = (S_DEFAULT_MOUNT_OPTS)BitConverter.ToUInt32(bytes, 0x100);
                FirstMetablockBlockGroup = BitConverter.ToUInt32(bytes, 0x104);
            }
            else
            {
                throw new Exception("Invalid Superblock Signature.");
            }
        }