Exemplo n.º 1
0
void CacheCD(BYTE Unit){
   DWORD     i,n, volSize;
   int       handle;
   union REGS      regs;
   struct SREGS    sregs;
   Window    wd;
   int       col=5, row=4, width=68, height=1;

   (void)ReadPVD(Unit);
   if(CD==CD_ISO)
      volSize = iso->volSize;
   else if (CD==CD_HSF)
      volSize = hsf->volSize;
   else{
      printf("Unkown CD Format.  Can't cache it.\n");
      return;
   }

   for (i=0;i<sizeof dta;i++){dta[i]=0;}

   wd = w_open(col, row, width, height);
   w_umessage(wd,"Creating Cache File ");
   w_lmessage(wd,"Control Break to interrupt");
   handle = open(CacheName, O_BINARY|O_CREAT|O_WRONLY,S_IWRITE);
   SigFlag = 0;
   signal(SIGINT, SetSigFlag);
   i = 0;
   while (i < volSize){
     n = volSize - i;
   w_printf(wd,"Writing block %ld of %ld to %s.\n",i,volSize,CacheName);
     if (n>=30){
        (void)CDReadLong(Unit,30,i);
        (void)write(handle,pdta, 61440);
        i += 30;
        }
     else {
        (void)CDReadLong(Unit,n,i);
        (void)write(handle,pdta, n*2048);
        i += n;
        }
     if (SigFlag != 0){
       if (PauseContinue() == -1) break;
       else{
          SigFlag=0;
          signal(SIGINT, SetSigFlag);
       }
     }
   }

   w_close(wd);
   close (handle);
}
Exemplo n.º 2
0
int ReadPVD(BYTE Unit){
   (void)CDReadLong(Unit,1,PriVolDescSector);
   if(strncmp(iso->cdID,ISO_ID,sizeof(iso->cdID))==0)
      CD=CD_ISO;
   else if (strncmp(hsf->cdID,HSF_ID,sizeof(hsf->cdID))==0)
      CD=CD_HSF;
   else
      CD=CD_Unknown;
}
Exemplo n.º 3
0
Arquivo: isobar.c Projeto: FDOS/shsucd
int main( int argc, char* argv[] )
{
  int	i;
  int	fdout = 0;
  char *outfile = NULL, *isofile = NULL, cdbuf[8];
  DWORD bootfound;
  int	drive = 0;
  int	type;
  DWORD n;
  UINT	len, w;

#ifndef _WIN32
  union REGS regs;

  _fmode = O_BINARY;
#endif

  if (argc > 1)
  {
    if (argv[1][0] == '?' || argv[1][1] == '?' || !strcmp( argv[1], "--help" ))
      usage();

    for (i = 1; i < argc; ++i)
    {
      if (*argv[i] == '-' || *argv[i] == '/')
      {
	switch (argv[i][1] | 0x20)
	{
	  case 'o':
	    if (argv[i][2] == '\0' && argv[i+1] == NULL)
	    {
	      fputs( "ERROR: -o requires filename.\n", stderr );
	      return E_OPT;
	    }
	    outfile = (argv[i][2] == '\0') ? argv[++i] : argv[i] + 2;
	  break;

	  case 'd':
	    drive = 1;
	  break;

	  default:
	    fprintf( stderr, "ERROR: unknown option: %s.\n", argv[i] );
	    return E_OPT;
	}
      }
      else
      {
	isofile = argv[i];
      }
    }
  }

#ifdef _WIN32
  if (!isofile)
  {
    char buf[32*4+1];
    len = GetLogicalDriveStrings( sizeof(buf)-1, buf );
    for (isofile = buf; len; isofile += 4, len -= 4)
    {
      if (GetDriveType( isofile ) == DRIVE_CDROM)
      {
	CD = *isofile - 'A';
	break;
      }
    }
    if (CD == -1)
    {
      fputs( "ERROR: No CD-ROM drives assigned.\n", stderr );
      return E_NOCD;
    }
  }
  else if (isofile[1] == '\0' || (isofile[1] == ':' && isofile[2] == '\0'))
  {
    CD = (*isofile | 0x20) - 'a';
    cdbuf[0] = CD + 'A';
    cdbuf[1] = ':';
    cdbuf[2] = '/';
    cdbuf[3] = '\0';
    if (GetDriveType( cdbuf ) != DRIVE_CDROM)
    {
      fprintf( stderr, "ERROR: %c: is not a CD-ROM drive.\n", cdbuf[0] );
      return E_NOCD;
    }
  }
  if (CD != -1)
  {
    sprintf( cdbuf, "//./%c:", CD + 'A' );
    isofile = cdbuf;
  }
  fdin = CreateFile( isofile, GENERIC_READ, FILE_SHARE_READ|FILE_SHARE_WRITE,
		     NULL, OPEN_EXISTING, FILE_FLAG_SEQUENTIAL_SCAN, NULL );
  if (fdin == INVALID_HANDLE_VALUE)
  {
    fprintf( stderr, "ERROR: Cannot open %s.\n", isofile );
    return E_NOCD;
  }
  if (CD != -1)
    isofile = cdbuf + 4;

#else
  if (!isofile)
  {
    regs.x.ax = 0x1500;
    regs.x.bx = 0;
    int86( 0x2f, &regs, &regs );
    CD = regs.x.cx;
  }
  else if (isofile[1] == '\0' || (isofile[1] == ':' && isofile[2] == '\0'))
  {
    CD = (*isofile | 0x20) - 'a';
    regs.x.ax = 0x150B;
    regs.x.cx = CD;
    int86( 0x2f, &regs, &regs );
    if (regs.x.bx != 0xADAD)
      regs.x.bx = 0;
    else if (regs.x.ax == 0)
    {
      fprintf( stderr, "ERROR: %c: is not a CD-ROM drive.\n", CD + 'A' );
      return E_NOCD;
    }
  }
  else
  {
    fdin = open( isofile, O_RDONLY );
    if (fdin < 0)
    {
      fprintf( stderr, "ERROR: Cannot open %s.\n", isofile );
      return E_NOCD;
    }
    regs.x.bx = 1;
  }
  if (regs.x.bx == 0)
  {
    fputs( "ERROR: No CD-ROM drives assigned.\n", stderr );
    return E_NOCD;
  }
  else if (CD != -1)
  {
    cdbuf[0] = CD + 'A';
    cdbuf[1] = ':';
    cdbuf[2] = '\0';
    isofile = cdbuf;
  }
#endif

  buf = farmalloc( MAX << 11 ); // transfer up to MAX blocks at a time
  if (buf == NULL)
  {
    fputs( "ERROR: Not enough memory.\n", stderr );
    return E_MEM;
  }

  if (!CDReadLong( 1, 0x11 ))
  {
    fputs( "Read error!\n", stderr );
    return E_ABORTED;
  }

  if (_fstrcmp( buf+1, "CD001\01EL TORITO SPECIFICATION" ))
  {
    fprintf( stderr, "ERROR: %s is not EL TORITO.\n", isofile );
    return E_NOCD;
  }
  bootfound = *(DWORD far*)(buf+0x47);
  printf( "Catalog Sector:\t%lx\n", bootfound );

  if (!CDReadLong( 1, bootfound ))
  {
    fputs( "Read error!\n", stderr );
    return E_ABORTED;
  }

  // Just check the key bytes, don't worry about the checksum.
  if (buf[0x1e] != (char)0x55 || buf[0x1f] != (char)0xAA)
  {
    fprintf( stderr, "ERROR: %s has an invalid boot catalog.\n", isofile );
    return E_NOCD;
  }
  type = (BYTE)buf[1];
  printf( "Platform:\t%s (%02x)\n", (type < 3) ? platform[type] : "unknown",
				    type );
  printf( "ID String:\t%.24"SFMT"\n", (buf[4]) ? buf+4 : "not recorded" );
  printf( "Bootable:\t%s (%02x)\n", (buf[0x20] == (char)0x88) ? "yes" : "no",
				    (BYTE)buf[0x20] );
  type = buf[0x21] & 15;
  printf( "Boot Type:\t%s (%02x)\n", (type < 5) ? boot_type[type] : "unknown",
				     (BYTE)buf[0x21] );
  i = *(WORD far*)(buf+0x22);
  printf( "Load Segment:\t%04x\n", (i == 0) ? 0x7c0 : i );
  printf( "System Type:\t%02x\n", (BYTE)buf[0x24] );
  imgsize = *(WORD far*)(buf+0x26);
  printf( "Sector Count:\t%02x (%d)\n", (UINT)imgsize, (UINT)imgsize );
  offset = *(DWORD far*)(buf+0x28);
  printf( "Image Sector:\t%lx\n", offset );

  if (type == 0)		// no emulation
  {
    blksize = 0x200;
  }
  else
  {
    CDReadLong( 1, offset );
    if (type == 4 && !drive)	// hard disk, keep MBR
    {
      blksize = 0x200;
      imgsize = *(DWORD far*)(buf+0x1ca);
    }
    else
    {
      if (type == 4)		// hard disk, skip MBR
      {
	offset += *(DWORD far*)(buf+0x1c6) >> 2;	// diff between HD & CD
	CDReadLong( 1, offset );
      }
      blksize = *(WORD far*)(buf+11);
      imgsize = *(WORD far*)(buf+19);
      if (imgsize == 0)
	imgsize = *(DWORD far*)(buf+32);
    }
  }