reactos操作系统实现(56)

前端之家收集整理的这篇文章主要介绍了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}

原文链接:https://www.f2er.com/react/308477.html

猜你在找的React相关文章