mirror of https://github.com/minexew/Shrine.git
171 changed files with 5281 additions and 5192 deletions
Binary file not shown.
@ -1,7 +1,8 @@
|
||||
Cd(__DIR__);; |
||||
#include "ADskA" |
||||
#include "Mount" |
||||
#include "ADskB" |
||||
#include "PrtDsk" |
||||
#include "Mount" |
||||
#include "ChkDsk" |
||||
#include "FileMgr" |
||||
Cd("..");; |
||||
|
@ -1,102 +1,114 @@
|
||||
#help_index "Install;File/Cmd Line (Typically);Cmd Line (Typically);" |
||||
CDoc *BlkDevPmt(U8 boot_drv_let=0,Bool make_free=FALSE,Bool repartition=FALSE) |
||||
{ |
||||
I64 num_hints,drv_let,type,unit; |
||||
I64 Mount2(U8 boot_drv_let,CDoc *_doc,Bool repartition) |
||||
{//If _doc, called by $LK,"::/Kernel/KCfg.CPP"$ else called by $LK,"Mount",A="MN:Mount"$().
|
||||
I64 cnt,result=0,num_hints,drv_let,type,unit; |
||||
U8 blks_buf[STR_LEN],addr_buf[STR_LEN],base0_buf[STR_LEN],base1_buf[STR_LEN]; |
||||
CATARep *root=NULL,*tempha; |
||||
Bool one_drv,make_free; |
||||
CDoc *doc; |
||||
"\n****** Mount Drives ******\n" |
||||
"$$GREEN$$A$$FG$$-$$GREEN$$B$$FG$$ are RAM drives.\n" |
||||
"$$GREEN$$C$$FG$$-$$GREEN$$S$$FG$$ are hard drives.\n" |
||||
"$$GREEN$$T$$FG$$-$$GREEN$$Z$$FG$$ are CD/DVD drives.\n" |
||||
"\nDrive Letter ($$PURPLE$$<ENTER>$$FG$$ to exit):"; |
||||
drv_let=ToUpper(GetChar); |
||||
'\n'; |
||||
if ('A'<=drv_let<='Z') { |
||||
doc=DocNew; |
||||
unit=0; |
||||
if ('A'<=drv_let<='B') { |
||||
type=BDT_RAM; |
||||
"Addr of RAM disk ($$PURPLE$$<ENTER>$$FG$$ to MAlloc):"; |
||||
GetS(addr_buf,STR_LEN); |
||||
"Blks of 512 bytes:"; |
||||
GetS(blks_buf,STR_LEN); |
||||
} else { |
||||
num_hints=ATARep(,,&root); |
||||
if ('C'<=drv_let<='S') |
||||
type=BDT_ATA; |
||||
else |
||||
type=BDT_ATAPI; |
||||
if (type==BDT_ATAPI && boot_drv_let) |
||||
"<ENTER> to use booted CD/DVD\n"; |
||||
do { |
||||
if (num_hints) |
||||
"Enter dev number or\nport with $$PURPLE$$0x$$FG$$ prefix.\n" |
||||
"I/O Port Base0:\n"; |
||||
else |
||||
"Include $$PURPLE$$0x$$FG$$ prefix.\nI/O Port Base0:\n"; |
||||
GetS(base0_buf,STR_LEN); |
||||
} while (!Str2I64(base0_buf) && (type!=BDT_ATAPI || !boot_drv_let)); |
||||
if (1<=Str2I64(base0_buf)<=num_hints) { |
||||
tempha=ATARepFind(root,Str2I64(base0_buf)); |
||||
StrPrint(base0_buf,"0x%X",tempha->base0); |
||||
StrPrint(base1_buf,"0x%X",tempha->base1); |
||||
unit=tempha->unit; |
||||
} else if (type!=BDT_ATAPI || *base0_buf) { |
||||
if (type==BDT_ATAPI) |
||||
StrCpy(base1_buf,"0"); |
||||
else |
||||
boot_drv_let=ToUpper(boot_drv_let); |
||||
do { |
||||
cnt=0; |
||||
if (!_doc) |
||||
DrvRep; |
||||
"\n****** Mount Drives ******\n" |
||||
"$$GREEN$$A$$FG$$-$$GREEN$$B$$FG$$ are RAM drives.\n" |
||||
"$$GREEN$$C$$FG$$-$$GREEN$$S$$FG$$ are ATA hard drives.\n" |
||||
"$$GREEN$$T$$FG$$-$$GREEN$$Z$$FG$$ are ATAPI CD/DVD drives.\n" |
||||
"\nDrive Letter ($$PURPLE$$<ENTER>$$FG$$ to exit):"; |
||||
drv_let=ToUpper(GetChar); |
||||
'\n'; |
||||
if (type=Let2BlkDevType(drv_let)) { |
||||
one_drv=FALSE; |
||||
if (_doc) { //Called by $LK,"::/Kernel/KCfg.CPP"$
|
||||
doc=_doc; |
||||
make_free=FALSE; |
||||
} else { //Called by $LK,"Mount",A="MN:Mount"$()
|
||||
doc=DocNew; |
||||
DocPrint(doc,"CBlkDev *bd;\n"); |
||||
make_free=TRUE; |
||||
} |
||||
unit=0; |
||||
switch (type) { |
||||
case BDT_RAM: |
||||
type=BDT_RAM; |
||||
"Addr of RAM disk ($$PURPLE$$<ENTER>$$FG$$ to MAlloc):"; |
||||
GetS(addr_buf,STR_LEN); |
||||
"Blks of 512 bytes:"; |
||||
GetS(blks_buf,STR_LEN); |
||||
break; |
||||
case BDT_ATA: |
||||
case BDT_ATAPI: |
||||
num_hints=ATARep(,,&root); |
||||
if (type==BDT_ATAPI && boot_drv_let) |
||||
"<ENTER> to use booted CD/DVD\n"; //Only $LK,"::/Kernel/KCfg.CPP"$
|
||||
do { |
||||
"I/O Port Base1:\n"; |
||||
GetS(base1_buf,STR_LEN); |
||||
} while (!Str2I64(base1_buf)); |
||||
do { |
||||
"\t$$PURPLE$$0$$FG$$=Master\n\t$$PURPLE$$1$$FG$$=Slave\nUnit:"; |
||||
unit=GetChar-'0'; |
||||
} while (!(0<=unit<=1)); |
||||
'\n'; |
||||
if (num_hints) |
||||
"Enter dev number or\nport with $$PURPLE$$0x$$FG$$ prefix.\n" |
||||
"I/O Port Base0:\n"; |
||||
else |
||||
"Include $$PURPLE$$0x$$FG$$ prefix.\nI/O Port Base0:\n"; |
||||
GetS(base0_buf,STR_LEN); |
||||
} while (!Str2I64(base0_buf) && (type!=BDT_ATAPI || !boot_drv_let)); |
||||
if (1<=Str2I64(base0_buf)<=num_hints) { |
||||
tempha=ATARepFind(root,Str2I64(base0_buf)); |
||||
StrPrint(base0_buf,"0x%X",tempha->base0); |
||||
StrPrint(base1_buf,"0x%X",tempha->base1); |
||||
unit=tempha->unit; |
||||
} else if (type!=BDT_ATAPI || *base0_buf) { |
||||
if (type==BDT_ATAPI) |
||||
StrCpy(base1_buf,"0"); |
||||
else |
||||
do { |
||||
"I/O Port Base1:\n"; |
||||
GetS(base1_buf,STR_LEN); |
||||
} while (!Str2I64(base1_buf)); |
||||
do { |
||||
"\t$$PURPLE$$0$$FG$$=Master\n\t$$PURPLE$$1$$FG$$=Slave\nUnit:"; |
||||
unit=GetChar-'0'; |
||||
} while (!(0<=unit<=1)); |
||||
'\n'; |
||||
} |
||||
LinkedLstDel(root); |
||||
break; |
||||
} |
||||
LinkedLstDel(root); |
||||
} |
||||
DocPrint(doc,"bd=BlkDevNextFree(%d,%d);bd->unit=%d;\n",drv_let,type,unit); |
||||
if (type==BDT_RAM) { |
||||
if (!*addr_buf) StrCpy(addr_buf,"0"); |
||||
DocPrint(doc,"bd->RAM_dsk=%s;bd->max_blk=(%s)-1;\n",addr_buf,blks_buf); |
||||
} |
||||
if (type==BDT_ATA || type==BDT_ATAPI) { |
||||
if (type==BDT_ATAPI && !*base0_buf) { |
||||
DocPrint(doc,"GetBaseUnit(bd);\n"); |
||||
if (drv_let==boot_drv_let) |
||||
make_free=TRUE; |
||||
} else |
||||
DocPrint(doc,"bd->base0=%s;bd->base1=%s;\n", |
||||
base0_buf,base1_buf); |
||||
} |
||||
if (type==BDT_ATA && repartition) { |
||||
"\nReformat WHOLE drive!"; |
||||
if (YorN) { |
||||
DocPrint(doc,"if (!BlkDevAdd(bd,TRUE,TRUE))" |
||||
"\"\n\n$$BK,1$$$$RED$$Operation Failed$$BK,0$$$$FG$$\n\n\";" |
||||
"else PrtDsk(bd->first_drv_let);\n"); |
||||
return doc; |
||||
DocPrint(doc,"bd=BlkDevNextFree(\'%C\',%d);bd->unit=%d;\n", |
||||
drv_let,type,unit); |
||||
switch (type) { |
||||
case BDT_RAM: |
||||
if (!*addr_buf) StrCpy(addr_buf,"0"); |
||||
DocPrint(doc,"bd->RAM_dsk=%s;bd->max_blk=(%s)-1;\n", |
||||
addr_buf,blks_buf); |
||||
break; |
||||
case BDT_ATA: |
||||
case BDT_ATAPI: |
||||
if (type==BDT_ATAPI && !*base0_buf) { |
||||
DocPrint(doc,"GetBaseUnit(bd);\n"); //Only $LK,"::/Kernel/KCfg.CPP"$
|
||||
if (drv_let==boot_drv_let) |
||||
make_free=TRUE; |
||||
} else |
||||
DocPrint(doc,"bd->base0=%s;bd->base1=%s;\n",base0_buf,base1_buf); |
||||
if (type==BDT_ATA && repartition) { |
||||
"\nReformat WHOLE drive!"; |
||||
one_drv=YorN; |
||||
} |
||||
break; |
||||
} |
||||
DocPrint(doc,"BlkDevAdd(bd,%d,%d);\n",one_drv,make_free); |
||||
if (_doc) //Called by $LK,"::/Kernel/KCfg.CPP"$
|
||||
cnt++; |
||||
else { //Called by $LK,"Mount",A="MN:Mount"$()
|
||||
if ((cnt=ExeDoc(doc)) && one_drv) |
||||
PrtDsk(drv_let); |
||||
DocDel(doc); |
||||
} |
||||
} |
||||
DocPrint(doc,"if (!BlkDevAdd(bd,FALSE,%d))" |
||||
"\"\n\n$$BK,1$$$$RED$$Operation Failed$$BK,0$$$$FG$$\n\n\";\n",make_free); |
||||
return doc; |
||||
} else |
||||
return NULL; |
||||
result+=cnt; |
||||
} while (cnt || !result && _doc); //At least 1 if Called by $LK,"::/Kernel/KCfg.CPP"$
|
||||
return result; |
||||
} |
||||
|
||||
public U0 Mount(Bool repartition=FALSE) |
||||
{//Mount a drive.
|
||||
CDoc *doc; |
||||
ExePrint("CBlkDev *bd;"); //Leaks
|
||||
do { |
||||
DrvRep; |
||||
if (doc=BlkDevPmt(,TRUE,repartition)) { |
||||
ExeDoc(doc); |
||||
DocDel(doc); |
||||
} |
||||
} while (doc); |
||||
public I64 Mount(Bool repartition=FALSE) |
||||
{//Mount drives.
|
||||
return Mount2(0,NULL,repartition); |
||||
} |
||||
|
@ -0,0 +1,163 @@
|
||||
#help_index "Install;File/Cmd Line (Typically);Cmd Line (Typically)" |
||||
|
||||
#define ROUND_DRV_TO (63*255) |
||||
#define DRV_HEADER 63 |
||||
|
||||
class CPlannedDrv |
||||
{ |
||||
CPlannedDrv *next,*last; |
||||
I64 size; |
||||
Bool pri; |
||||
}; |
||||
|
||||
//Available to assist in writing scripts.
|
||||
I64 drv_dsk_dsk_size=0; |
||||
|
||||
public I64 PrtDsk(U8 drv_let=0) |
||||
{//Partition the disk containing partition drv_let.
|
||||
//drv_let=0 means add new drive that
|
||||
//is not already mounted.
|
||||
CBlkDev *bd; |
||||
CPlannedDrv root,*temppp; |
||||
CMasterBoot mbr; |
||||
Bool pri=TRUE; |
||||
I64 ext_base,drv_let2,pri_cnt=0, |
||||
i,start_offset,offset,remaining; |
||||
drv_dsk_dsk_size=0; |
||||
"This command does not play well\n" |
||||
"with other operating systems.\n" |
||||
"You really should use another\n" |
||||
"operating system's partitioner.\n" |
||||
"If you use this, it may, in fact,\n" |
||||
"make your hard drive impossible\n" |
||||
"to repartition with other operating\n" |
||||
"until you set block zero to zero\n" |
||||
"with $$LK,\"MasterBootZero\",\"MN:MasterBootZero\"$$()\n\n\n" |
||||
"Continue"; |
||||
if (!YorN) return 0; |
||||
if (drv_let && !Let2BlkDev(drv_let,FALSE)) |
||||
drv_let=0; |
||||
if (!drv_let) { |
||||
Mount(TRUE); |
||||
return 0; |
||||
} |
||||
if (!(bd=Let2BlkDev(drv_let,FALSE)) || bd->type!=BDT_ATA) |
||||
return 0; |
||||
|
||||
drv_dsk_dsk_size=bd->max_blk+1; |
||||
QueInit(&root); |
||||
drv_let2=bd->first_drv_let; |
||||
remaining=FloorU64(bd->max_blk+1,ROUND_DRV_TO); |
||||
while (FloorU64(remaining,ROUND_DRV_TO)>=ROUND_DRV_TO) { |
||||
temppp=MAlloc(sizeof(CPlannedDrv)); |
||||
do { |
||||
"$$RED$$Partition %C$$FG$$\n",drv_let2; |
||||
temppp->pri=FALSE; |
||||
if (pri) { |
||||
"Primary Partition"; |
||||
if (YorN) { |
||||
pri_cnt++; |
||||
temppp->pri=TRUE; |
||||
if (pri_cnt==3) |
||||
pri=FALSE; |
||||
} else |
||||
pri=FALSE; |
||||
} |
||||
"Blocks Remaining:%d (0x%X)\n", |
||||
remaining-DRV_HEADER,remaining-DRV_HEADER; |
||||
temppp->size=CeilU64(GetI64("Size in Blocks :", |
||||
remaining-DRV_HEADER)+DRV_HEADER,ROUND_DRV_TO); |
||||
} while (!(ROUND_DRV_TO<=temppp->size<=FloorU64(remaining,ROUND_DRV_TO))); |
||||
QueIns(temppp,root.last); |
||||
remaining-=temppp->size; |
||||
drv_let2++; |
||||
} |
||||
|
||||
"\n\n!!! Repartition Drive !!!\n\n"; |
||||
temppp=root.next; |
||||
drv_let2=bd->first_drv_let; |
||||
while (temppp!=&root) { |
||||
"Drive %C:%08X ",drv_let2,temppp->size; |
||||
if (temppp->pri) |
||||
"Primary\n"; |
||||
else |
||||
"Logical\n"; |
||||
temppp=temppp->next; |
||||
drv_let2++; |
||||
} |
||||
if (!AreYouSure) |
||||
goto pd_done; |
||||
|
||||
remaining=FloorU64(bd->max_blk+1,ROUND_DRV_TO)-ROUND_DRV_TO; |
||||
temppp=root.next; |
||||
MemSet(&mbr,0,BLK_SIZE); |
||||
mbr.signature=0xAA55; |
||||
offset=0; |
||||
for (i=0;i<pri_cnt;i++) { |
||||
mbr.p[i].active=0x80; |
||||
mbr.p[i].start_head=0; |
||||
mbr.p[i].start_cyl=0x101; |
||||
mbr.p[i].type=1; //Will get set different.
|
||||
mbr.p[i].end_head=0xFE; |
||||
mbr.p[i].end_cyl=0xFFFF; |
||||
mbr.p[i].offset=DRV_HEADER+offset; |
||||
mbr.p[i].size=temppp->size-DRV_HEADER; |
||||
offset+=temppp->size; |
||||
remaining-=temppp->size; |
||||
temppp=temppp->next; |
||||
} |
||||
if (!i) i++; |
||||
if (temppp!=&root) { |
||||
mbr.p[i].active=0x80; |
||||
mbr.p[i].start_head=0; |
||||
mbr.p[i].start_cyl=0x101; |
||||
mbr.p[i].type=0xF; |
||||
mbr.p[i].end_head=0xFE; |
||||
mbr.p[i].end_cyl=0xFFFF; |
||||
mbr.p[i].offset=offset; |
||||
mbr.p[i].size=remaining; |
||||
ext_base=offset; |
||||
} |
||||
ATAWriteBlks(bd,&mbr,0,1); |
||||
|
||||
while (temppp!=&root) { |
||||
start_offset=offset; |
||||
MemSet(&mbr,0,BLK_SIZE); |
||||
mbr.signature=0xAA55; |
||||
|
||||
mbr.p[0].active=0x80; |
||||
mbr.p[0].start_head=1; |
||||
mbr.p[0].start_cyl=0x101; |
||||
mbr.p[0].type=1; //Will get set different.
|
||||
mbr.p[0].end_head=0xFE; |
||||
mbr.p[0].end_cyl=0xFFFF; |
||||
mbr.p[0].offset=DRV_HEADER; |
||||
mbr.p[0].size=temppp->size-DRV_HEADER; |
||||
offset+=temppp->size; |
||||
temppp=temppp->next; |
||||
if (temppp!=&root) { |
||||
mbr.p[1].active=0x80; |
||||
mbr.p[1].start_head=0; |
||||
mbr.p[1].start_cyl=0x101; |
||||
mbr.p[1].type=5; |
||||
mbr.p[1].end_head=0xFE; |
||||
mbr.p[1].end_cyl=0xFFFF; |
||||
mbr.p[1].offset=offset-ext_base; |
||||
mbr.p[1].size=temppp->size; |
||||
} |
||||
ATAWriteBlks(bd,&mbr,start_offset,1); |
||||
} |
||||
|
||||
bd->flags&=~(BDF_INITIALIZED | BDF_INIT_IN_PROGRESS); |
||||
BlkDevAdd(bd,FALSE,TRUE); |
||||
for (i=bd->first_drv_let;i<drv_let2;i++) |
||||
Fmt(i,,FALSE); |
||||
|
||||
pd_done: |
||||
while (root.next!=&root) { |
||||
temppp=root.next; |
||||
QueRem(temppp); |
||||
Free(temppp); |
||||
} |
||||
return drv_dsk_dsk_size; |
||||
} |