在Reactos安装过程里,会出现下面的界面,如下:
上面的界面就是创建磁盘分区显示的内容,那么这个界面下面主要做了那些工作呢?磁盘又是怎么样分区的呢?分区后的数据怎么样保存到磁盘里的呢?接着下来,就分析创建磁盘分区的代码,才能知道整个实现过程,如下:
#001 static PAGE_NUMBER
#002 CreatePartitionPage (PINPUT_RECORD Ir)
#003 {
#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,
#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,
#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
#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
#135 CreateNewPartition (PartitionList,
#136 PartSize,
#137 FALSE);
#138
#139 return SELECT_PARTITION_PAGE;
#140 }
#141 }
#142
#143 return CREATE_PARTITION_PAGE;
#144}
原文地址:https://www.jb51.cc/react/308477.html
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。