Team Ai
Datasetpublic

hschumann2/TempleOS-Source-Code

sourceHugging Faceupdated 1y agoView on Hugging Face
0likes847downloads
DskFmt.txt97 linesDownload Raw Back to BlkDev
1 2Bool DrvTypeSet(U8 drv_let,I64 type=FSt_REDSEA)3{//Very dangerous4  I64 i,j,ext_base,drv_num,offset,cur_type;5  CMasterBoot mbr;6  CBlkDev *bd;7  drv_let=Let2Let(drv_let);8  bd=Let2BlkDev(drv_let);9  drv_num=bd->first_drv_let-'A';10  switch (bd->type) {11    case BDT_ATA:12      offset=0;13      ext_base=INVALID_CLUS;14      while (TRUE) {15        ATAReadBlks(bd,&mbr,offset,1);16        j=-1;17        for (i=0;i<4;i++) {18          cur_type=mbr.p[i].type;19          if (cur_type) {20            if (cur_type==5 || cur_type==15)21              j=i;22            else {23              if (drv_num+'A'==drv_let) {24                switch (type) {25                  case FSt_REDSEA:26                    mbr.p[i].type=MBR_PT_REDSEA;27                    break;28                  case FSt_FAT32:29                    mbr.p[i].type=MBR_PT_FAT32a;30                    break;31                  default:32                    throw('Drv');33                }34                mbr.p[i].active=0x80;35                ATAWriteBlks(bd,&mbr,offset,1);36                return TRUE;37              }38              drv_num++;39            }40          }41        }42        if (j<0)43          break;44        if (!mbr.p[j].offset)45          break;46        if (ext_base==INVALID_CLUS) {47          offset=mbr.p[j].offset;48          ext_base=offset;49        } else50          offset=mbr.p[j].offset+ext_base;51      }52      break;53  }54}55 56U0 Fmt(I64 drv_let,Bool quick=TRUE,Bool confirm=TRUE,I64 type=FSt_FAT32)57{//Format hard drive or RAM drive.58//Warning: Destroys all prev info.59  //quick=FALSE means fill entire drive with zeros.60  //Choose FSt_FAT32 or FSt_REDSEA.61  //You don't format a CD/DVD with this.62  CDrv *dv=Let2Drv(drv_let);63  Bool old_silent=IsSilent;64  if (confirm && !AreYouSure)65    return;66  if (!dv)  {67    PrintErr("Invalid Drive\n");68    return;69  }70  switch (type) {71    case FSt_FAT32:72      if (dv->bd->type==BDT_ATA) {73        Silent;74        Drv(drv_let);75        Silent(old_silent);76        FAT32Fmt(drv_let,quick);77        DskCacheInvalidate(Let2Drv(drv_let));78        Drv(drv_let);79        break;80      }81      "Using RedSea File System.\n";82    case FSt_REDSEA:83      Silent;84      Drv(drv_let);85      Silent(old_silent);86      RedSeaFmt(drv_let,quick);87      DskCacheInvalidate(Let2Drv(drv_let));88      Drv(drv_let);89      break;90    case FSt_ISO9660:91      PrintErr("Not Writable\n");92      break;93    default:94      PrintErr("File System Not Supported\n");95  }96}97