当前位置: 首页>>代码示例>>C#>>正文


C# BinaryFormat.GetUShort方法代码示例

本文整理汇总了C#中Mosa.ClassLib.BinaryFormat.GetUShort方法的典型用法代码示例。如果您正苦于以下问题:C# BinaryFormat.GetUShort方法的具体用法?C# BinaryFormat.GetUShort怎么用?C# BinaryFormat.GetUShort使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Mosa.ClassLib.BinaryFormat的用法示例。


在下文中一共展示了BinaryFormat.GetUShort方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: GetClusterEntry

        /// <summary>
        /// Gets the cluster entry.
        /// </summary>
        /// <param name="data">The data.</param>
        /// <param name="index">The index.</param>
        /// <param name="type">The type.</param>
        /// <returns></returns>
        public static uint GetClusterEntry(byte[] data, uint index, FatType type)
        {
            BinaryFormat entry = new BinaryFormat(data);

            uint cluster = entry.GetUShort(Entry.FirstCluster + (index * Entry.EntrySize));

            if (type == FatType.FAT32)
                cluster |= ((uint)entry.GetUShort(Entry.EAIndex + (index * Entry.EntrySize))) << 16;

            return cluster;
        }
开发者ID:pacificIT,项目名称:MOSA-Project,代码行数:18,代码来源:FatFileSystem.cs

示例2: SetClusterEntryValue

        /// <summary>
        /// Sets the cluster entry value.
        /// </summary>
        /// <param name="cluster">The cluster.</param>
        /// <param name="nextcluster">The nextcluster.</param>
        /// <returns></returns>
        protected bool SetClusterEntryValue(uint cluster, uint nextcluster)
        {
            uint fatOffset = 0;

            if (fatType == FatType.FAT12)
                fatOffset = (cluster + (cluster / 2));
            else if (fatType == FatType.FAT16)
                fatOffset = cluster * 2;
            else //if (type == FatType.FAT32)
                fatOffset = cluster * 4;

            uint sector = reservedSectors + (fatOffset / bytesPerSector);
            uint sectorOffset = fatOffset % bytesPerSector;
            uint nbrSectors = 1;

            if ((fatType == FatType.FAT12) && (sectorOffset == bytesPerSector - 1))
                nbrSectors = 2;

            BinaryFormat fat = new BinaryFormat(partition.ReadBlock(sector, nbrSectors));

            if (fatType == FatType.FAT12)
            {
                uint clustervalue = fat.GetUShort(sectorOffset);

                if (cluster % 2 == 1)
                    clustervalue = ((clustervalue & 0x000F) | (nextcluster << 4));
                else
                    clustervalue = ((clustervalue & 0xF000) | (nextcluster & 0x0FFF));

                fat.SetUShort(sectorOffset, (ushort)clustervalue);
            }
            else if (fatType == FatType.FAT16)
                fat.SetUShort(sectorOffset, (ushort)(nextcluster & 0xFFFF));
            else //if (type == FatType.FAT32)
                fat.SetUInt(sectorOffset, nextcluster);

            partition.WriteBlock(sector, nbrSectors, fat.Data);

            return true;
        }
开发者ID:pacificIT,项目名称:MOSA-Project,代码行数:46,代码来源:FatFileSystem.cs

示例3: ReadBootSector

        /// <summary>
        /// Reads the boot sector.
        /// </summary>
        /// <returns></returns>
        protected bool ReadBootSector()
        {
            valid = false;

            if (blockSize != 512)   // only going to work with 512 sector sizes (for now)
                return false;

            BinaryFormat bootSector = new BinaryFormat(partition.ReadBlock(0, 1));

            if (bootSector.GetUShort(BootSector.BootSectorSignature) != 0xAA55)
                return false;

            byte extendedBootSignature = bootSector.GetByte(BootSector.ExtendedBootSignature);
            byte extendedBootSignature32 = bootSector.GetByte(BootSector.FAT32_ExtendedBootSignature);

            if ((extendedBootSignature != 0x29) && (extendedBootSignature != 0x28) && (extendedBootSignature32 != 0x29))
                return false;

            volumeLabel = bootSector.GetString(BootSector.VolumeLabel, 8).ToString().TrimEnd();
            bytesPerSector = bootSector.GetUShort(BootSector.BytesPerSector);
            sectorsPerCluster = bootSector.GetByte(BootSector.SectorsPerCluster);
            reservedSectors = bootSector.GetByte(BootSector.ReservedSectors);
            nbrFats = bootSector.GetByte(BootSector.FatAllocationTables);
            rootEntries = bootSector.GetUShort(BootSector.MaxRootDirEntries);
            rootCluster32 = bootSector.GetUInt(BootSector.FAT32_ClusterNumberOfRoot);

            uint sectorsPerFat16 = bootSector.GetUShort(BootSector.SectorsPerFAT);
            uint sectorsPerFat32 = bootSector.GetUInt(BootSector.FAT32_SectorPerFAT);
            uint totalSectors16 = bootSector.GetUShort(BootSector.TotalSectors16);
            uint totalSectors32 = bootSector.GetUInt(BootSector.TotalSectors32);
            uint sectorsPerFat = (sectorsPerFat16 != 0) ? sectorsPerFat16 : sectorsPerFat32;
            uint fatSectors = 0;

            try
            {
                fatSectors = nbrFats * sectorsPerFat;
                clusterSizeInBytes = sectorsPerCluster * blockSize;
                rootDirSectors = (((rootEntries * 32) + (bytesPerSector - 1)) / bytesPerSector);
                firstDataSector = reservedSectors + (nbrFats * sectorsPerFat) + rootDirSectors;
                totalSectors = (totalSectors16 != 0) ? totalSectors16 : totalSectors32;
                dataSectors = totalSectors - (reservedSectors + (nbrFats * sectorsPerFat) + rootDirSectors);
                totalClusters = dataSectors / sectorsPerCluster;
                entriesPerSector = (bytesPerSector / 32);
                firstRootDirectorySector = reservedSectors + fatSectors;
                dataAreaStart = firstRootDirectorySector + rootDirSectors;
            }
            catch
            {
                return false;
            }

            // Some basic checks
            if ((nbrFats == 0) || (nbrFats > 2) || (totalSectors == 0) || (sectorsPerFat == 0))
                return false;

            if (totalClusters < 4085)
                fatType = FatType.FAT12;
            else if (totalClusters < 65525)
                fatType = FatType.FAT16;
            else
                fatType = FatType.FAT32;

            if (fatType == FatType.FAT12)
            {
                reservedClusterMark = 0xFF0;
                endOfClusterMark = 0x0FF8;
                badClusterMark = 0x0FF7;
                fatMask = 0xFFFFFFFF;
                fatEntries = sectorsPerFat * 3 * blockSize / 2;
            }
            else if (fatType == FatType.FAT16)
            {
                reservedClusterMark = 0xFFF0;
                endOfClusterMark = 0xFFF8;
                badClusterMark = 0xFFF7;
                fatMask = 0xFFFFFFFF;
                fatEntries = sectorsPerFat * blockSize / 2;
            }
            else
            { //  if (type == FatType.FAT32) {
                reservedClusterMark = 0xFFF0;
                endOfClusterMark = 0x0FFFFFF8;
                badClusterMark = 0x0FFFFFF7;
                fatMask = 0x0FFFFFFF;
                fatEntries = sectorsPerFat * blockSize / 4;
            }

            // More basic checks
            if ((fatType == FatType.FAT32) && (rootCluster32 == 0))
                return false;

            valid = true;

            serialNbr = bootSector.GetBytes(fatType != FatType.FAT32 ? BootSector.IDSerialNumber : BootSector.FAT32_IDSerialNumber, 4);

            return true;
//.........这里部分代码省略.........
开发者ID:pacificIT,项目名称:MOSA-Project,代码行数:101,代码来源:FatFileSystem.cs

示例4: GetClusterEntryValue

        /// <summary>
        /// Gets the cluster entry value.
        /// </summary>
        /// <param name="cluster">The cluster.</param>
        /// <returns></returns>
        protected uint GetClusterEntryValue(uint cluster)
        {
            uint fatoffset = 0;

            if (fatType == FatType.FAT12)
                fatoffset = (cluster + (cluster / 2));
            else if (fatType == FatType.FAT16)
                fatoffset = cluster * 2;
            else //if (type == FatType.FAT32)
                fatoffset = cluster * 4;

            uint sector = reservedSectors + (fatoffset / bytesPerSector);
            uint sectorOffset = fatoffset % bytesPerSector;
            uint nbrSectors = 1;

            if ((fatType == FatType.FAT12) && (sectorOffset == bytesPerSector - 1))
                nbrSectors = 2;

            BinaryFormat fat = new BinaryFormat(partition.ReadBlock(sector, nbrSectors));

            uint clusterValue;

            if (fatType == FatType.FAT12)
            {
                clusterValue = fat.GetUShort(sectorOffset);
                if (cluster % 2 == 1)
                    clusterValue = clusterValue >> 4;
                else
                    clusterValue = clusterValue & 0x0FFF;
            }
            else if (fatType == FatType.FAT16)
                clusterValue = fat.GetUShort(sectorOffset);
            else //if (type == FatType.FAT32)
                clusterValue = fat.GetUInt(sectorOffset) & 0x0FFFFFFF;

            return clusterValue;
        }
开发者ID:pacificIT,项目名称:MOSA-Project,代码行数:42,代码来源:FatFileSystem.cs

示例5: ReadLBA48

        /// <summary>
        /// Reads the LBA48.
        /// </summary>
        /// <param name="operation">The operation.</param>
        /// <param name="drive">The drive.</param>
        /// <param name="lba">The lba.</param>
        /// <param name="data">The data.</param>
        /// <param name="offset">The offset.</param>
        /// <returns></returns>
        protected bool ReadLBA48(SectorOperation operation, uint drive, uint lba, byte[] data, uint offset)
        {
            if (drive > MaximunDriveCount)
                return false;

            FeaturePort.Write8(0);
            FeaturePort.Write8(0);

            SectorCountPort.Write8(0);
            SectorCountPort.Write8(1);

            LBALowPort.Write8((byte)((lba >> 24) & 0xFF));
            LBALowPort.Write8((byte)(lba & 0xFF));

            LBAMidPort.Write8((byte)((lba >> 32) & 0xFF));
            LBAMidPort.Write8((byte)((lba >> 8) & 0xFF));

            LBAHighPort.Write8((byte)((lba >> 40) & 0xFF));
            LBAHighPort.Write8((byte)((lba >> 16) & 0xFF));

            DeviceHeadPort.Write8((byte)(0x40 | (drive << 4)));

            if (operation == SectorOperation.Write)
                CommandPort.Write8(0x34);
            else
                CommandPort.Write8(0x24);

            if (!WaitForRegisterReady())
                return false;

            var sector = new BinaryFormat(data);

            //TODO: Don't use PIO
            if (operation == SectorOperation.Read)
            {
                for (uint index = 0; index < 256; index++)
                    sector.SetUShort(offset + (index * 2), DataPort.Read16());
            }
            else
            {
                for (uint index = 0; index < 256; index++)
                    DataPort.Write16(sector.GetUShort(offset + (index * 2)));
            }

            return true;
        }
开发者ID:Zahovay,项目名称:MOSA-Project,代码行数:55,代码来源:IDEController.cs

示例6: Read

        /// <summary>
        /// Reads the master boot block.
        /// </summary>
        /// <returns></returns>
        public bool Read()
        {
            valid = false;

            if (diskDevice.BlockSize != 512) return false;  // only going to work with 512 sector sizes
            if (diskDevice.TotalBlocks < 3) return false;

            BinaryFormat masterboot = new BinaryFormat(diskDevice.ReadBlock(0, 1));

            if (masterboot.GetUShort(MBR.MBRSignature) != MBRConstant.MBRSignature)
                return false;

            valid = true;

            diskSignature = masterboot.GetUInt(MBR.DiskSignature);

            for (uint index = 0; index < MaxMBRPartitions; index++) {
                uint offset = MBR.FirstPartition + (index * MBRConstant.PartitionSize);

                GenericPartition partition = new GenericPartition(index);

                partition.Bootable = masterboot.GetByte(offset + PartitionRecord.Status) == MBRConstant.Bootable;
                partition.PartitionType = masterboot.GetByte(offset + PartitionRecord.PartitionType);
                partition.StartLBA = masterboot.GetUInt(offset + PartitionRecord.LBA);
                partition.TotalBlocks = masterboot.GetUInt(offset + PartitionRecord.Sectors);

                Partitions[index] = partition;
            }

            //TODO: Extended Partitions

            code = new byte[MBRConstant.CodeAreaSize];
            for (uint index = 0; index < MBRConstant.CodeAreaSize; index++)
                code[index] = masterboot.GetByte(index);

            return valid;
        }
开发者ID:hj1980,项目名称:Mosa,代码行数:41,代码来源:MasterBootBlock.cs


注:本文中的Mosa.ClassLib.BinaryFormat.GetUShort方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。