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


C# BinaryFormat.SetBytes方法代码示例

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


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

示例1: Format

        /// <summary>
        /// Formats the partition with specified fat settings.
        /// </summary>
        /// <param name="fatSettings">The fat settings.</param>
        /// <returns></returns>
        public bool Format(FatSettings fatSettings)
        {
            if (!partition.CanWrite)
                return false;

            this.fatType = fatSettings.FATType;
            bytesPerSector = 512;
            nbrFats = 2;

            totalSectors = partition.BlockCount;
            sectorsPerCluster = GetSectorsPerClusterByTotalSectors(fatType, totalSectors);

            if (sectorsPerCluster == 0)
                return false;

            if (fatType == FatType.FAT32)
            {
                reservedSectors = 32;
                rootEntries = 0;
            }
            else
            {
                reservedSectors = 1;
                rootEntries = 512;
            }

            rootDirSectors = (((rootEntries * 32) + (bytesPerSector - 1)) / bytesPerSector);

            uint val1 = totalSectors - (reservedSectors + rootDirSectors);
            uint val2 = (uint)((sectorsPerCluster * 256) + nbrFats);

            if (fatType == FatType.FAT32)
                val2 = val2 / 2;

            uint sectorsPerFat = (val1 + (val2 - 1)) / val2;

            firstRootDirectorySector = reservedSectors + sectorsPerFat;

            BinaryFormat bootSector = new BinaryFormat(512);

            bootSector.SetUInt(BootSector.JumpInstruction, 0);
            bootSector.SetString(BootSector.EOMName, "MOSA    ");
            bootSector.SetUShort(BootSector.BytesPerSector, (ushort)bytesPerSector);
            bootSector.SetByte(BootSector.SectorsPerCluster, (byte)sectorsPerCluster);
            bootSector.SetUShort(BootSector.ReservedSectors, (ushort)reservedSectors);
            bootSector.SetByte(BootSector.FatAllocationTables, nbrFats);
            bootSector.SetUShort(BootSector.MaxRootDirEntries, (ushort)rootEntries);
            bootSector.SetUShort(BootSector.BootSectorSignature, 0xAA55);

            if (totalSectors > 0xFFFF)
            {
                bootSector.SetUShort(BootSector.TotalSectors16, 0);
                bootSector.SetUInt(BootSector.TotalSectors32, totalSectors);
            }
            else
            {
                bootSector.SetUShort(BootSector.TotalSectors16, (ushort)totalSectors);
                bootSector.SetUInt(BootSector.TotalSectors32, 0);
            }

            if (fatSettings.FloppyMedia)
            {
                // Default is 1.44
                bootSector.SetByte(BootSector.MediaDescriptor, 0xF0); // 0xF0 = 3.5" Double Sided, 80 tracks per side, 18 sectors per track (1.44MB).
            }
            else
                bootSector.SetByte(BootSector.MediaDescriptor, 0xF8); // 0xF8 = Hard disk

            bootSector.SetUShort(BootSector.SectorsPerTrack, fatSettings.SectorsPerTrack);
            bootSector.SetUShort(BootSector.NumberOfHeads, fatSettings.NumberOfHeads);
            bootSector.SetUInt(BootSector.HiddenSectors, fatSettings.HiddenSectors);

            if (fatType != FatType.FAT32)
            {
                bootSector.SetUShort(BootSector.SectorsPerFAT, (ushort)sectorsPerFat);
                if (fatSettings.FloppyMedia)
                    bootSector.SetByte(BootSector.PhysicalDriveNbr, 0x00);
                else
                    bootSector.SetByte(BootSector.PhysicalDriveNbr, 0x80);

                bootSector.SetByte(BootSector.ReservedCurrentHead, 0);
                bootSector.SetByte(BootSector.ExtendedBootSignature, 0x29);
                bootSector.SetBytes(BootSector.IDSerialNumber, fatSettings.SerialID, 0, (uint)Math.Min(4, fatSettings.SerialID.Length));

                if (string.IsNullOrEmpty(fatSettings.VolumeLabel))
                    bootSector.SetString(BootSector.VolumeLabel, "NO NAME    ");
                else
                {
                    bootSector.SetString(BootSector.VolumeLabel, "           ");  // 11 blank spaces
                    bootSector.SetString(BootSector.VolumeLabel, fatSettings.VolumeLabel, (uint)Math.Min(11, fatSettings.VolumeLabel.Length));
                }

                if (fatSettings.OSBootCode != null)
                {
                    if (fatSettings.OSBootCode.Length == 512)
//.........这里部分代码省略.........
开发者ID:pacificIT,项目名称:MOSA-Project,代码行数:101,代码来源:FatFileSystem.cs


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