《reactosreactos操作系统实现(64).pdf》由会员分享,可在线阅读,更多相关《reactosreactos操作系统实现(64).pdf(13页珍藏版)》请在淘文阁 - 分享文档赚钱的网站上搜索。
1、reactos:reactos操作系统实现(64)疯狂代码 http:/CrazyC 在安装个操作系统时绝大多数都是把引导安装在硬盘里下面就来了解安装到硬盘里具体过程实现代码如下:#001PAGE_NUMBER#002BootLoaderHarddiskPage(PINPUT_RECORDIr)#003#004UCHARPartitionType;#005NTSTATUSStatus;#006 获取硬盘分区类型然后判断是否可以安装引导#007PartitionType=PartitionList-ActiveBootPartition-PartInfo0.PartitionType;#008(
2、PartitionTypePARTITION_FAT_12)|#009(PartitionTypePARTITION_FAT_16)|#010(PartitionTypePARTITION_HUGE)|#011(PartitionTypePARTITION_XINT13)|#012(PartitionTypePARTITION_FAT32)|#013(PartitionTypePARTITION_FAT32_XINT13)#014 可以安装引导InstallFatBootcodeToPartition实现#015Status=InstallFatBootcodeToPartition(&Roo
3、tPath,#016&SourceRootPath,#017&DestinationArcPath,#018PartitionType);#019(!NT_SUCCESS(Status)#020#021MUIDisplayError(ERROR_INSTALL_BOOTCODE,Ir,POPUP_WAIT_ENTER);#022QUIT_PAGE;#023#024#025SUCCESS_PAGE;#026#027#028 如果不能安装就提示出错#029MUIDisplayError(ERROR_WRITE_BOOT,Ir,POPUP_WAIT_ENTER);#030QUIT_PAGE;#031
4、#032#033BOOT_LOADER_HARDDISK_PAGE;#034 下面继续分析InstallFatBootcodeToPartition实现如下:#001NTSTATUS#002InstallFatBootcodeToPartition(PUNICODE_STRINGRootPath,#003PUNICODE_STRINGSourceRootPath,#004PUNICODE_STRINGDestinationArcPath,#005UCHARPartitionType)#006#007#def_REACTOS_#008WCHARSrcPathMAX_PATH;#009WCHARD
5、stPathMAX_PATH;#010NTSTATUSStatus;#011#012/*FATorFAT32partition*/#013DPRINT(path:%wZn,RootPath);#014 判断分区路径里是否存在ntldr和boot.ini文件#015(DoesFileExist(RootPath-Buffer,Lntldr)TRUE|#016DoesFileExist(RootPath-Buffer,Lboot.ini)TRUE)#017 如果发现NT、2000、XP引导就只需要设置选项让ntldr来加freeldr.sys就行了#018/*Searchrootdirectory
6、forntldrandboot.ini.*/#019DPRINT(FoundMicrosoftWindowsNT/2000/XPbootloadern);#020#021/*CopyFreeLoadertothebootpartition*/#022wcscpy(SrcPath,SourceRootPath-Buffer);#023wcscat(SrcPath,Lloaderfreeldr.sys);#024wcscpy(DstPath,RootPath-Buffer);#025wcscat(DstPath,Lfreeldr.sys);#026 这里开始拷贝文件#027DPRINT(Copy:
7、%S%Sn,SrcPath,DstPath);#028Status=SetupCopyFile(SrcPath,DstPath);#029(!NT_SUCCESS(Status)#030#031DPRINT1(SetupCopyFilefailed(Status%lx)n,Status);#032Status;#033#034 更新freeldr.ini文件#035/*Createorupdatefreeldr.ini*/#036(DoesFileExist(RootPath-Buffer,Lfreeldr.ini)FALSE)#037#038/*Createfreeldr.ini*/#039
8、DPRINT1(Createfreeldr.inin);#040wcscpy(DstPath,RootPath-Buffer);#041wcscat(DstPath,Lfreeldr.ini);#042#043Status=CreateFreeLoaderIniForReactos(DstPath,#044DestinationArcPath-Buffer);#045(!NT_SUCCESS(Status)#046#047DPRINT1(CreateFreeLoaderIniForReactosfailed(Status%lx)n,Status);#048Status;#049#050 安装新
9、引导代码到引导扇区#051/*Installbootcode*/#052(PartitionTypePARTITION_FAT32|#053PartitionTypePARTITION_FAT32_XINT13)#054#055/*InstallFAT32bootcode*/#056wcscpy(SrcPath,SourceRootPath-Buffer);#057wcscat(SrcPath,Lloaderfat32.bin);#058wcscpy(DstPath,RootPath-Buffer);#059wcscat(DstPath,Lbootsect.ros);#060#061DPRIN
10、T1(InstallFAT32bootcode:%S%Sn,SrcPath,DstPath);#062Status=InstallFat32BootCodeToFile(SrcPath,#063DstPath,#064RootPath-Buffer);#065(!NT_SUCCESS(Status)#066#067DPRINT1(InstallFat32BootCodeToFilefailed(Status%lx)n,Status);#068Status;#069#070#071#072#073/*InstallFAT16bootcode*/#074wcscpy(SrcPath,SourceR
11、ootPath-Buffer);#075wcscat(SrcPath,Lloaderfat.bin);#076wcscpy(DstPath,RootPath-Buffer);#077wcscat(DstPath,Lbootsect.ros);#078#079DPRINT1(InstallFATbootcode:%S%Sn,SrcPath,DstPath);#080Status=InstallFat16BootCodeToFile(SrcPath,#081DstPath,#082RootPath-Buffer);#083(!NT_SUCCESS(Status)#084#085DPRINT1(In
12、stallFat16BootCodeToFilefailed(Status%lx)n,Status);#086Status;#087#088#089#090#091#092/*Updateexistingfreeldr.ini*/#093DPRINT1(Updateexistingfreeldr.inin);#094wcscpy(DstPath,RootPath-Buffer);#095wcscat(DstPath,Lfreeldr.ini);#096#097Status=UpdateFreeLoaderIni(DstPath,#098DestinationArcPath-Buffer);#0
13、99(!NT_SUCCESS(Status)#100#101DPRINT1(UpdateFreeLoaderInifailed(Status%lx)n,Status);#102Status;#103#104#105#106/*Updateboot.ini*/#107wcscpy(DstPath,RootPath-Buffer);#108wcscat(DstPath,Lboot.ini);#109#110DPRINT1(Updateboot.ini:%Sn,DstPath);#111Status=UpdateBootIni(DstPath,#112LC:bootsect.ros,#113LRea
14、ctOS);#114(!NT_SUCCESS(Status)#115#116DPRINT1(UpdateBootInifailed(Status%lx)n,Status);#117Status;#118#119#120(DoesFileExist(RootPath-Buffer,Lio.sys)TRUE|#121DoesFileExist(RootPath-Buffer,Lmsdos.sys)TRUE)#122 查找分区里是否有DOS操作系统#123/*Searchforrootdirectoryforio.sysandmsdos.sys.*/#124DPRINT1(FoundMicrosof
15、tDOSorWindows9xbootloadern);#125#126/*CopyFreeLoadertothebootpartition*/#127wcscpy(SrcPath,SourceRootPath-Buffer);#128wcscat(SrcPath,Lloaderfreeldr.sys);#129wcscpy(DstPath,RootPath-Buffer);#130wcscat(DstPath,Lfreeldr.sys);#131 拷贝文件#132DPRINT(Copy:%S%Sn,SrcPath,DstPath);#133Status=SetupCopyFile(SrcPa
16、th,DstPath);#134(!NT_SUCCESS(Status)#135#136DPRINT1(SetupCopyFilefailed(Status%lx)n,Status);#137Status;#138#139 创建并更新freeldr.ini文件#140/*Createorupdatefreeldr.ini*/#141(DoesFileExist(RootPath-Buffer,Lfreeldr.ini)FALSE)#142#143/*Createfreeldr.ini*/#144DPRINT1(Createfreeldr.inin);#145wcscpy(DstPath,Roo
17、tPath-Buffer);#146wcscat(DstPath,Lfreeldr.ini);#147#148Status=CreateFreeLoaderIniForDos(DstPath,#149DestinationArcPath-Buffer);#150(!NT_SUCCESS(Status)#151#152DPRINT1(CreateFreeLoaderIniForDosfailed(Status%lx)n,Status);#153Status;#154#155#156/*SavecurrentbootsectorasBOOTSECT.DOS*/#157wcscpy(SrcPath,
18、RootPath-Buffer);#158wcscpy(DstPath,RootPath-Buffer);#159wcscat(DstPath,Lbootsect.dos);#160#161DPRINT1(Savebootsector:%S%Sn,SrcPath,DstPath);#162Status=SaveCurrentBootSector(SrcPath,#163DstPath);#164(!NT_SUCCESS(Status)#165#166DPRINT1(SaveCurrentBootSectorfailed(Status%lx)n,Status);#167Status;#168#1
19、69#170/*Installbootsector*/#171(PartitionTypePARTITION_FAT32|#172PartitionTypePARTITION_FAT32_XINT13)#173#174wcscpy(SrcPath,SourceRootPath-Buffer);#175wcscat(SrcPath,Lloaderfat32.bin);#176#177DPRINT1(InstallFAT32bootcode:%S%Sn,SrcPath,RootPath-Buffer);#178Status=InstallFat32BootCodeToDisk(SrcPath,#1
20、79RootPath-Buffer);#180(!NT_SUCCESS(Status)#181#182DPRINT1(InstallFat32BootCodeToDiskfailed(Status%lx)n,Status);#183Status;#184#185#186#187#188wcscpy(SrcPath,SourceRootPath-Buffer);#189wcscat(SrcPath,Lloaderfat.bin);#190#191DPRINT1(InstallFATbootcode:%S%Sn,SrcPath,RootPath-Buffer);#192Status=Install
21、Fat16BootCodeToDisk(SrcPath,#193RootPath-Buffer);#194(!NT_SUCCESS(Status)#195#196DPRINT1(InstallFat16BootCodeToDiskfailed(Status%lx)n,Status);#197Status;#198#199#200#201#202#203/*Updateexistingfreeldr.ini*/#204wcscpy(DstPath,RootPath-Buffer);#205wcscat(DstPath,Lfreeldr.ini);#206#207Status=UpdateFree
22、LoaderIni(DstPath,#208DestinationArcPath-Buffer);#209(!NT_SUCCESS(Status)#210#211DPRINT1(UpdateFreeLoaderInifailed(Status%lx)n,Status);#212Status;#213#214#215#216#217 这个硬盘分区没有任何已经安装系统#218/*Noorunknownbootloader*/#219DPRINT1(Noorunknownbootloaderfoundn);#220 拷贝Reactos引导和配置文件#221/*CopyFreeLoadertotheb
23、ootpartition*/#222wcscpy(SrcPath,SourceRootPath-Buffer);#223wcscat(SrcPath,Lloaderfreeldr.sys);#224wcscpy(DstPath,RootPath-Buffer);#225wcscat(DstPath,Lfreeldr.sys);#226#227DPRINT(Copy:%S%Sn,SrcPath,DstPath);#228Status=SetupCopyFile(SrcPath,DstPath);#229(!NT_SUCCESS(Status)#230#231DPRINT1(SetupCopyFi
24、lefailed(Status%lx)n,Status);#232Status;#233#234 创建和更新引导配置freeldr.ini文件#235/*Createorupdatefreeldr.ini*/#236(DoesFileExist(RootPath-Buffer,Lfreeldr.ini)FALSE)#237#238/*Createfreeldr.ini*/#239wcscpy(DstPath,RootPath-Buffer);#240wcscat(DstPath,Lfreeldr.ini);#241#242DPRINT(Copy:%S%Sn,SrcPath,DstPath);#
25、243Status=CreateFreeLoaderIniForReactos(DstPath,#244DestinationArcPath-Buffer);#245(!NT_SUCCESS(Status)#246#247DPRINT1(CreateFreeLoaderIniForReactosfailed(Status%lx)n,Status);#248Status;#249#250 保存当前引导扇区代码为BOOTSECT.OLD#251/*SavecurrentbootsectorasBOOTSECT.OLD*/#252wcscpy(SrcPath,RootPath-Buffer);#25
26、3wcscpy(DstPath,RootPath-Buffer);#254wcscat(DstPath,Lbootsect.old);#255#256DPRINT(Savebootsector:%S%Sn,SrcPath,DstPath);#257Status=SaveCurrentBootSector(SrcPath,#258DstPath);#259(!NT_SUCCESS(Status)#260#261DPRINT1(SaveCurrentBootSectorfailed(Status%lx)n,Status);#262Status;#263#264 安装新引导扇区代码硬盘分区#265/
27、*Installbootsector*/#266(PartitionTypePARTITION_FAT32|#267PartitionTypePARTITION_FAT32_XINT13)#268#269wcscpy(SrcPath,SourceRootPath-Buffer);#270wcscat(SrcPath,Lloaderfat32.bin);#271#272DPRINT(InstallFAT32bootcode:%S%Sn,SrcPath,RootPath-Buffer);#273Status=InstallFat32BootCodeToDisk(SrcPath,#274RootPa
28、th-Buffer);#275(!NT_SUCCESS(Status)#276#277DPRINT1(InstallFat32BootCodeToDiskfailed(Status%lx)n,Status);#278Status;#279#280#281#282#283wcscpy(SrcPath,SourceRootPath-Buffer);#284wcscat(SrcPath,Lloaderfat.bin);#285#286DPRINT(InstallFATbootcode:%S%Sn,SrcPath,RootPath-Buffer);#287Status=InstallFat16Boot
29、CodeToDisk(SrcPath,#288RootPath-Buffer);#289(!NT_SUCCESS(Status)#290#291DPRINT1(InstallFat16BootCodeToDiskfailed(Status%lx)n,Status);#292Status;#293#294#295#296#297#298/*Updateexistingfreeldr.ini*/#299wcscpy(DstPath,RootPath-Buffer);#300wcscat(DstPath,Lfreeldr.ini);#301#302Status=UpdateFreeLoaderIni(DstPath,#303DestinationArcPath-Buffer);#304(!NT_SUCCESS(Status)#305#306DPRINT1(UpdateFreeLoaderInifailed(Status%lx)n,Status);#307Status;#308#309#310#311#312STATUS_SUCCESS;#313#314STATUS_NOT_IMPLEMENTED;#315#end#316 2009-9-25 22:12:18 疯狂代码 http:/CrazyC
限制150内