■ 마스터 부트 레코드(Master Boot Record, MBR) 조회하기

------------------------------------------------------------------------------------------------------------------------


TestSolution.zip


Program.cs

 

 

using System;

using System.Collections.Generic;

 

using TestLibrary;

 

namespace TestProject

{

    /// <summary>

    /// 프로그램

    /// </summary>

    class Program

    {

        //////////////////////////////////////////////////////////////////////////////////////////////////// Method

        ////////////////////////////////////////////////////////////////////////////////////////// Static

        //////////////////////////////////////////////////////////////////////////////// Private

 

        #region 프로그램 시작하기 - Main()

 

        /// <summary>

        /// 프로그램 시작하기

        /// </summary>

        private static void Main()

        {

            Console.Title = "마스터 부트 레코드(Master Boot Record, MBR) 조회하기";

 

            List<PhysicalDiskInfo> physicalDiskInfoList = MBRHelper.Read();

            

            foreach(PhysicalDiskInfo physicalDiskInfo in physicalDiskInfoList)

            {

                Console.WriteLine

                (

                    "드라이브명 : {0} (섹터당 바이트 수 : {1})",

                    physicalDiskInfo.Name,

                    physicalDiskInfo.ByteCountPerSector

                );

            

                if(physicalDiskInfo.MBR != null)

                {

                    foreach(PartitionEntry entry in physicalDiskInfo.MBR.Value.PartitionEntryArray)

                    {

                        WritePartitionEntry(entry);

 

                        Console.WriteLine();

                    }

                }

            }

        }

 

        #endregion

 

        #region 파티션 엔트리 작성하기 - WritePartitionEntry(entry)

 

        /// <summary>

        /// 파티션 엔트리 작성하기

        /// </summary>

        /// <param name="entry">파티션 엔트리</param>

        private static void WritePartitionEntry(PartitionEntry entry)

        {

            if(entry.SectorSize == 0)

            {

                Console.WriteLine("    (미정의)");

 

                return;

            }

 

            Console.WriteLine("    BOOTABLE    : {0}"                    , entry.BootFlag == 0x80                          );

            Console.WriteLine("    TYPE        : {0}"                    , entry.GetPartitionTypeName(entry.Type)          );

            Console.WriteLine("    SECTOR SIZE : 0x{0,8:x8}"             , entry.SectorSize                                );

            Console.WriteLine("    CHS         : 0x{0,6:x6} ~ 0x{1,6:x6}", entry.StartingCHSAddress, entry.EndingCHSAddress);

            Console.WriteLine("    BEGIN LBA   : 0x{0,8:x8}"             , entry.StartingLBAAddress                        );

        }

 

        #endregion

    }

}

 

------------------------------------------------------------------------------------------------------------------------

※ 관리자 권한으로 실행한다.

Posted by 사용자 icodebroker
TAG