Team Ai
Datasetpublic

hschumann2/TempleOS-Source-Code

sourceHugging Faceupdated 1y agoView on Hugging Face
0likes847downloads
DskAddDev.txt242 linesDownload Raw Back to BlkDev
1 2U0 BlkDevLockFwdingSet(CBlkDev *bd)3{  //If two blkdevs on same controller, use just one lock4  CBlkDev *bd1;5  I64 i;6  switch (bd->type) {7    case BDT_RAM:8      break;9    case BDT_ISO_FILE_READ:10    case BDT_ISO_FILE_WRITE:11      bd->lock_fwding=Let2BlkDev(*bd->file_dsk_name);12      break;13    case BDT_ATA:14    case BDT_ATAPI:15      for (i=0;i<BLKDEVS_NUM;i++) {16        bd1=&blkdev.blkdevs[i];17        if (bd1->bd_signature==BD_SIGNATURE_VAL && bd!=bd1 &&18              (bd1->type==BDT_ATAPI || bd1->type==BDT_ATA) &&19              bd1->base0==bd->base0) {20          bd->lock_fwding=bd1;21          break;22        }23      }24      break;25  }26}27 28I64 BlkDevAdd(CBlkDev *bd,I64 prt_num=I64_MIN,29        Bool whole_drv,Bool make_free)30{//It will mount just one partition of prt_num>=0.31//When repartitioing whole drive, whole_drv=TRUE.32  I64 i,j,ext_base,offset,res=0,num=0;33  CDrv *dv;34  CRedSeaBoot br;35  CMasterBoot mbr;36 37  bd->bd_signature=BD_SIGNATURE_VAL;38  if (make_free)39    dv=DrvMakeFreeSlot(bd->first_drv_let);40  else41    dv=DrvMakeFreeSlot(DrvNextFreeLet(bd->first_drv_let));42  dv->bd=bd;43  dv->drv_offset=bd->drv_offset;44  dv->size=bd->max_blk+1-bd->drv_offset;45  switch (bd->type) {46    case BDT_RAM:47    case BDT_ISO_FILE_READ:48    case BDT_ISO_FILE_WRITE:49      dv->dv_signature=DRV_SIGNATURE_VAL;50      dv->prt_num=num;51      dv->fs_type=FSt_REDSEA;52//This is to force creation of a RAM53      //drive during boot, so it is probably54      //MAlloced to the same addr and can55      //be assumed to be already formatted.56      //If this line is removed, RAM Drives57      //will be alloced on a just-in-time58      //basis.59      if (BlkDevInit(bd))60        res++;61      else62        dv->dv_signature=0;63      break;64    case BDT_ATA:65      dv->dv_signature=DRV_SIGNATURE_VAL; //Temporarily validate66      if (!BlkDevInit(bd))67        dv->dv_signature=0; //Revoke validation68      else {69        dv->dv_signature=0; //Revoke validation70        if (whole_drv) {71          dv->dv_signature=DRV_SIGNATURE_VAL;72          dv->prt_num=num;73          res++;74          dv->fs_type=FSt_REDSEA;75          dv->size=bd->max_blk+1-bd->drv_offset;76//The following read is a test read.77          //if it hangs, the drive is not supported.78          ATAReadBlks(bd,&mbr,0,1);79          break;80        }81        offset=0;82        ext_base=INVALID_CLUS;83        while (prt_num<0 || num<=prt_num) {84          ATAReadBlks(bd,&mbr,offset,1);85          if (mbr.signature!=0xAA55)86            break;87          j=-1;88          for (i=0;i<4 && (prt_num<0 || num<=prt_num);i++) {89            if (mbr.p[i].type) {90              if (make_free)91                dv=DrvMakeFreeSlot(bd->first_drv_let+res);92              else93                dv=DrvMakeFreeSlot(DrvNextFreeLet(bd->first_drv_let+res));94              dv->bd=bd;95              dv->drv_offset=mbr.p[i].offset+offset;96              dv->size  =mbr.p[i].size;97              switch (mbr.p[i].type) {98                case MBR_PT_REDSEA:99                  dv->dv_signature=DRV_SIGNATURE_VAL;100                  dv->prt_num=num;101                  res++;102                  dv->fs_type=FSt_REDSEA;103                  RedSeaInit(dv);104                  break;105                case MBR_PT_FAT32a:106                case MBR_PT_FAT32b:107                case MBR_PT_FAT32c:108                case MBR_PT_FAT32d:109                case MBR_PT_FAT32e:110                case MBR_PT_FAT32f:111                  ATAReadBlks(bd,&br,dv->drv_offset,1);112                  dv->dv_signature=DRV_SIGNATURE_VAL;113                  dv->prt_num=num;114                  res++;115                  if (br.signature==MBR_PT_REDSEA) {116                    dv->fs_type=FSt_REDSEA;117                    RedSeaInit(dv);118                  } else {119                    dv->fs_type=FSt_FAT32;120                    FAT32Init(dv);121                  }122                  break;123                case MBR_PT_NTFS:124                  dv->dv_signature=DRV_SIGNATURE_VAL;125                  dv->prt_num=num;126                  res++;127                  dv->fs_type=FSt_NTFS;128                  break;129                case 5:130                case 15:131                  j=i;132                  break;133                default:134                  dv->dv_signature=DRV_SIGNATURE_VAL;135                  dv->prt_num=num;136                  res++;137                  dv->fs_type=FSt_UNKNOWN;138              }139              num++;140            }141          }142          if (Let2BlkDevType(bd->first_drv_let+res)!=bd->type)143            break;144          if (j<0)145            break;146          if (!mbr.p[j].offset)147            break;148          if (ext_base==INVALID_CLUS) {149            offset=mbr.p[j].offset;150            ext_base=offset;151          } else152            offset=mbr.p[j].offset+ext_base;153        }154      }155      break;156    case BDT_ATAPI:157      dv->dv_signature=DRV_SIGNATURE_VAL;158      dv->prt_num=num;159      res++;160      dv->fs_type=FSt_ISO9660; //Start with this161      dv->size=0;162      break;163  }164  if (res)165    BlkDevLockFwdingSet(bd);166  else167    BlkDevDel(bd);168  return res;169}170 171Bool DrvEnable(U8 drv_let,Bool val)172{//Can unmount or remount, but not mount the first time.173  CDrv *dv;174  if (dv=Let2Drv(drv_let,FALSE))175    return !LBEqu(&dv->fs_type,FStf_DISABLE,!val);176  else177    return FALSE;178}179 180I64 SysGetI64()181{182  U8 st[STR_LEN];183  GetS(st,STR_LEN,FALSE);184  return Str2I64(st,16);185}186 187Bool GetBaseUnit(CBlkDev *bd)188{189  I64 ch;190  Bool probe;191  #exe {192    if (kernel_cfg->opts[CFG_DONT_PROBE])193      StreamPrint("probe=FALSE;");194    else195      StreamPrint("probe=TRUE;");196  };197  if (!probe || !BootDVDProbeAll(bd)) {198    "\nDon't worry.  This is not a product\n"199          "registration.        TempleOS just needs the\n"200          "I/O port numbers for the CD/DVD.\n"201          "\nRetry the ports above or check Windows\n"202          "system information under I/O ports for\n"203          "'IDE', 'ATA' or 'SATA'.\n"204          "In Linux, use 'lspci -v' for ports.\n"205          "\n\nEnter 4-digit hex I/O Port number.\n"206          "CD/DVD I/O Port Base0: 0x";207    bd->base0=SysGetI64;208    bd->base1=0;209    bd->unit =0;210    if (bd->base0) {211      "\nUnit (0 or 1): ";212      do ch=GetChar(,FALSE);213      while (!('0'<=ch<='1'));214      '' ch;215      bd->unit=ch-'0';216      blkdev.dvd_boot_is_good=BootDVDProbe(bd);217      return TRUE;218    } else {219      blkdev.dvd_boot_is_good=FALSE;220      return FALSE;221    }222  }223  return FALSE;224}225 226U0 BlkDevsInitAll()227{228  CBlkDev *bd;229  I64 i;230  blkdev.blkdevs=CAlloc(sizeof(CBlkDev)*BLKDEVS_NUM);231  blkdev.drvs=CAlloc(sizeof(CDrv)*DRVS_NUM);232  for (i=0;i<DRVS_NUM;i++)233    blkdev.let_to_drv[i]=&blkdev.drvs[i];234  #exe {235    if (kernel_cfg->opts[CFG_MOUNT_IDE_AUTO])236      StreamPrint("MountIDEAuto;");237    StreamPrint("#exe {Option(OPTf_WARN_PAREN,OFF);}");238    StreamDoc(kernel_cfg->add_dev);239    StreamPrint("#exe {Option(OPTf_WARN_PAREN,ON);}");240  };241}242