reactos操作系统实现(56)

Reactos安装过程里,会出现下面的界面,如下:

上面的界面就是创建磁盘分区显示内容,那么这个界面下面主要做了那些工作呢?磁盘又是怎么样分区的呢?分区后的数据怎么样保存到磁盘里的呢?接着下来,就分析创建磁盘分区的代码,才能知道整个实现过程,如下:

#001 static PAGE_NUMBER

#002 CreatePartitionPage (PINPUT_RECORD Ir)

#003 {

当按下回车键时,就会调用这个函数执行创建分区的动作。

#004 PdisKENTRY diskEntry;

#005 PPARTENTRY PartEntry;

#006 BOOLEAN Quit;

#007 BOOLEAN Cancel;

#008 CHAR InputBuffer[50];

#009 ULONG MaxSize;

#010 ULONGLONG PartSize;

#011 ULONGLONG diskSize;

#012 PCHAR Unit;

#013

判断分区表是否为空。

#014 if (PartitionList == NULL ||

#015 PartitionList->Currentdisk == NULL ||

#016 PartitionList->CurrentPartition == NULL)

#017 {

#018 /* FIXME: show an error dialog */

#019 return QUIT_PAGE;

#020 }

#021

获取当前磁盘和当前分区。

#022 diskEntry = PartitionList->Currentdisk;

#023 PartEntry = PartitionList->CurrentPartition;

#024

#025 CONSOLE_SetStatusText(MUIGetString(STRING_PLEASEWAIT));

#026

#027 CONSOLE_SettextxY(6,8,MUIGetString(STRING_CHOOSENEWPARTITION));

#028

#029 #if 0

#030 if (diskEntry->diskSize >= 0x280000000ULL) /* 10 GB */

#031 {

#032 diskSize = (diskEntry->diskSize + (1 << 29)) >> 30;

#033 Unit = MUIGetString(STRING_GB);

#034 }

#035 else

#036 #endif

#037 {

获取磁盘的大小。

#038 diskSize = (diskEntry->diskSize + (1 << 19)) >> 20;

#039

#040 if (diskSize == 0)

#041 diskSize = 1;

#042

#043 Unit = MUIGetString(STRING_MB);

#044 }

#045

#046 if (diskEntry->DriverName.Length > 0)

#047 {

#048 CONSOLE_PrinttextxY(6,10,

#049 MUIGetString(STRING_HDINFOPARTCREATE),

#050 diskSize,

#051 Unit,

#052 diskEntry->diskNumber,

#053 diskEntry->Port,

#054 diskEntry->Bus,

#055 diskEntry->Id,

#056 &diskEntry->DriverName);

#057 }

#058 else

#059 {

#060 CONSOLE_PrinttextxY(6,

#061 MUIGetString(STRING_HDDINFOUNK1),

#062 diskSize,

#063 Unit,

#064 diskEntry->diskNumber,

#065 diskEntry->Port,

#066 diskEntry->Bus,

#067 diskEntry->Id);

#068 }

#069

#070 CONSOLE_SettextxY(6,12,MUIGetString(STRING_HDDSIZE));

#071

#072 #if 0

#073 CONSOLE_PrinttextxY(8,"Maximum size of the new partition is %I64u MB",

#074 PartitionList->CurrentPartition->UnpartitionedLength / (1024*1024));

#075 #endif

#076

#077 CONSOLE_SetStatusText(MUIGetString(STRING_CREATEPARTITION));

#078

循环地处理创建分区。

#079 PartEntry = PartitionList->CurrentPartition;

#080 while (TRUE)

#081 {

#082 MaxSize = (PartEntry->UnpartitionedLength + (1 << 19)) >> 20; /* in MBytes (rounded) */

#083

#084 if (MaxSize > PARTITION_MAXSIZE) MaxSize = PARTITION_MAXSIZE;

#085

获取用户输入分区的大小,比如输入多少M磁盘大小。

#086 ShowPartitionSizeInputBox (12,14,xScreen - 12,17,/* left,top,right,bottom */

#087 MaxSize,InputBuffer,&Quit,&Cancel);

#088

#089 if (Quit == TRUE)

#090 {

#091 if (ConfirmQuit (Ir) == TRUE)

#092 {

#093 return QUIT_PAGE;

#094 }

#095 }

#096 else if (Cancel == TRUE)

#097 {

#098 return SELECT_PARTITION_PAGE;

#099 }

#100 else

#101 {

根据输入的字符串来计算分区的大小。

#102 PartSize = atoi(InputBuffer);

#103

#104 if (PartSize < 1)

#105 {

#106 /* Too small */

#107 continue;

#108 }

#109

#110 if (PartSize > MaxSize)

#111 {

#112 /* Too large */

#113 continue;

#114 }

#115

下面把输入以MB为单位的大小转换为以字节为大小。

#116 /* Convert to bytes */

#117 if (PartSize == MaxSize)

#118 {

#119 /* Use all of the unpartitioned disk space */

#120 PartSize = PartEntry->UnpartitionedLength;

#121 }

#122 else

#123 {

#124 /* Round-up by cylinder size */

#125 PartSize = ROUND_UP (PartSize * 1024 * 1024,

#126 diskEntry->CylinderSize);

#127

#128 /* But never get larger than the unpartitioned disk space */

#129 if (PartSize > PartEntry->UnpartitionedLength)

#130 PartSize = PartEntry->UnpartitionedLength;

#131 }

#132

#133 DPRINT ("Partition size: %I64u bytes/n",PartSize);

#134

调用函数CreateNewPartition创建一个分区。

#135 CreateNewPartition (PartitionList,

#136 PartSize,

#137 FALSE);

#138

#139 return SELECT_PARTITION_PAGE;

#140 }

#141 }

#142

#143 return CREATE_PARTITION_PAGE;

#144}

相关文章

一、前言 在组件方面react和Vue一样的,核心思想玩的就是组件...
前言: 前段时间学习完react后,刚好就接到公司一个react项目...
前言: 最近收到组长通知我们项目组后面新开的项目准备统一技...
react 中的高阶组件主要是对于 hooks 之前的类组件来说的,如...
我们上一节了解了组件的更新机制,但是只是停留在表层上,例...
我们上一节了解了 react 的虚拟 dom 的格式,如何把虚拟 dom...