Example #1
0
int do_test()
{	
	DSK_GEOMETRY dg;
	DSK_PDRIVER dr;
	dsk_err_t e;
	char buf[512];

	e = dsk_open(&dr, "/dev/fd0", NULL, NULL);
	if (!e) e = dsk_getgeom(dr, &dg);
	if (!e) e = dsk_pread(dr, &dg, buf, 0, 1, 1);
	if (!e) e = dsk_close(&dr);
	if (e) 
	{
		fprintf(stderr, "%s\n", dsk_strerror(e));
		return 1;
	}
	else
	{
		int n;
		for (n = 0; n < 512; n++)
		{
			if (buf[n] >= ' ' && buf[n] <= '~') putchar(buf[n]);
			else putchar('.');
			if ((n % 32) == 31) putchar('\n');
		}
	}
	return 0;
}
Example #2
0
int do_swapboot(int argc, char *outfile, char *outtyp, char *outcomp, 
		int forcehead)
{
	DSK_PDRIVER outdr = NULL;
	dsk_err_t e;
	DSK_GEOMETRY dg;

	dsk_reportfunc_set(report, report_end);	
	e = dsk_open(&outdr, outfile, outtyp, outcomp);
	if (!e) e = dsk_set_retry(outdr, retries);
	if (forcehead >= 0 && !e) e = dsk_set_forcehead(outdr, forcehead);
	if (!e) 
	{
		if (format == -1) e = dsk_getgeom(outdr, &dg);
		else		  e = dg_stdformat(&dg, format, NULL, NULL);
	}
	if (!e)
	{
		if (dg.dg_secsize != 512)
		{
			fprintf(stderr, "%s: Sector size is not 512 bytes",
					outfile);
			dsk_close(&outdr);
			return 1;
		}
		e = dsk_pread(outdr, &dg, buffer, 0, 0, 1);
	}
	if (!e)
	{
		if (transform(md, buffer, outfile, 1))
		{
			dsk_close(&outdr);
			return 1;
		}
		e = dsk_pwrite(outdr, &dg, buffer, 0, 0, 1);
	}
	if (outdr) dsk_close(&outdr);
	if (e)
	{
		fprintf(stderr, "%s: %s\n", outfile, dsk_strerror(e));
		return 1;
	}
	return 0;
}
Example #3
0
STDMETHODIMP CLibrary::open(BSTR f, BSTR d, BSTR c, IDisk **ppDisk)
{
	DSK_PDRIVER pd;
	dsk_err_t err;
	char *filename;
	char *driver;
	char *compress;

	if (!f || !ppDisk)
	{
		return MapError(DSK_ERR_BADPTR);
	}
	filename = get_string(f);
	driver   = get_string(d);
	compress = get_string(c);

	if (driver[0] == 0)   
	{
		dsk_free(driver);
		driver   = NULL;
	}
	if (compress[0] == 0) 
	{
		dsk_free(compress);
		compress = NULL;
	}
	err = dsk_open(&pd, filename, driver, compress);
	if (filename) dsk_free(filename);
	if (driver)   dsk_free(driver);
	if (compress) dsk_free(compress);

	if (err)
	{
		return MapError(err);
	}
	HRESULT hr = CDisk::CreateInstance(ppDisk);
	if (FAILED(hr)) return hr;

	((CDisk *)ppDisk[0])->m_driver = pd;

	return hr;
}
Example #4
0
dsk_err_t DriveSelectPage::OpenDisc(DSK_PDRIVER *pdsk)
{
	wxString &filename = GetFilename();
	wxCharBuffer buf(filename.mb_str(wxConvUTF8));

	dsk_err_t err = dsk_open(pdsk, buf, GetType(), GetCompress());
	if (!err) 
	{
		long retries;
		if (!m_retries.ToLong(&retries)) retries = 1;

		dsk_set_retry(*pdsk, retries);
		if (GetForceHead() >= 0)
		{
			dsk_set_option(*pdsk, "HEAD", GetForceHead());
		}
		if (GetDoubleStep())
		{
			dsk_set_option(*pdsk, "DOUBLESTEP", 1);
		}
	}
	return err;
}
Example #5
0
libgdos_disk *
libgdos_openimage( const char *filename )
{
  libgdos_disk *d;
  int l;
  uint8_t sector[ 0x200 ];

  dsk_format_t fmt;
  dsk_err_t dsk_error;

  l = strlen( filename );
  if( l >= 5 ) {
    if( !strcasecmp( filename + ( l - 4 ), ".dsk" ) ||
	!strcasecmp( filename + ( l - 4 ), ".mgt" )    ) {
      fmt = FMT_800K;
    } else if( !strcasecmp( filename + ( l - 4 ), ".img" ) ) {
      fmt = FMT_MGT800;
    } else {
      return NULL;
    }
  } else {
    return NULL;
  }

  d = malloc( sizeof(*d) );
  if( !d ) return NULL;

  d->allocmap = NULL;

  /* First, try the "logical" driver. */
  dsk_error = dsk_open( &d->driver, filename, "logical", NULL );

  /* If it's not available, and we're using FMT_800K (an out-and-out format)
   * try the "raw" driver. */
  if( dsk_error != DSK_ERR_OK && fmt == FMT_800K ) {
    dsk_error = dsk_open( &d->driver, filename, "raw", NULL );
  }

  if( dsk_error != DSK_ERR_OK ) {
    free( d );
    return NULL;
  }

  dsk_error = dg_stdformat( &d->geom, fmt, NULL, NULL );
  if( dsk_error != DSK_ERR_OK ) {
    dsk_close( &d->driver );
    free( d );
    return NULL;
  }

  libgdos_readsector( d, sector, 0, 1 );
  if( sector[ 0xff ] <= 35 ) {
    d->extra_dir_tracks = sector[ 0xff ];
    if( sector[ 15 ] & 0x01 ) /* track 4, sector 1 is/was allocated */
      d->variant = libgdos_variant_masterdos;
    else
      d->variant = libgdos_variant_betados;
  } else {
    d->extra_dir_tracks = 0;
    d->variant = libgdos_variant_gdos;
  }

  return d;
}
Example #6
0
/* Decode an RPC packet and execute it.
 * If nRefCount is nonzero, it is increased each time a dsk_open or dsk_creat 
 * succeeds, and decreased when a dsk_close succeeds. This allows a server 
 * program to terminate automatically when the reference count reaches 0. 
 *
 * The only RPC codes that are currently obeyed are those sent by drvwin32.c
 * through rpccli.c
 */
LDPUBLIC32 dsk_err_t LDPUBLIC16 dsk_rpc_server(unsigned char *input,  int inp_len,
	   		unsigned char *output, int *out_len, int *nRefCount)
	{
	dsk_err_t err, err2;
	int16 function;
	DSK_DRIVER *pDriver;
	DSK_GEOMETRY geom;
	DSK_FORMAT fmt, *pfmt;
	int32 nd, int1, int2, int3, int4, int5, int6, int7;
	int16 filler;
	char  *str1, *str2, *str3;
	dsk_psect_t rcount;
	DSK_FORMAT *trkids;
	unsigned int nDriver, n;
	unsigned char secbuf[8192], *pbuf;
	unsigned char status;
	int deleted, value;
	int16 props[sizeof(DRV_CLASS)];

	err = dsk_unpack_i16(&input, &inp_len, &function); if (err) return err;
	switch(function)
		{
		case RPC_DSK_OPEN:
				err = dsk_unpack_string(&input, &inp_len, &str1); if (err) return err;
				err = dsk_unpack_string(&input, &inp_len, &str2); if (err) return err;
				err = dsk_unpack_string(&input, &inp_len, &str3); if (err) return err;
				err2= dsk_open(&pDriver, str1, str2, str3);
				err = dsk_map_dtoi(pDriver, &nDriver);            if (err) return err;
				err = dsk_pack_err  (&output, out_len, err2);    if (err) return err;
				err = dsk_pack_i32  (&output, out_len, nDriver); if (err) return err;
				if (nRefCount && err2 == DSK_ERR_OK) ++(*nRefCount);
				return DSK_ERR_OK;
		case RPC_DSK_CREAT:
				err = dsk_unpack_string(&input, &inp_len, &str1); if (err) return err;
				err = dsk_unpack_string(&input, &inp_len, &str2); if (err) return err;
				err = dsk_unpack_string(&input, &inp_len, &str3); if (err) return err;
				err2= dsk_creat(&pDriver, str1, str2, str3);
				err = dsk_map_dtoi(pDriver, &nDriver);            if (err) return err;
				err = dsk_pack_err  (&output, out_len, err2);    if (err) return err;
				err = dsk_pack_i32  (&output, out_len, nDriver); if (err) return err;
				if (nRefCount && err2 == DSK_ERR_OK) ++(*nRefCount);
				return DSK_ERR_OK;
		case RPC_DSK_CLOSE:
				err = dsk_unpack_i32(&input, &inp_len, &nd);	  if (err) return err;	nDriver = (unsigned int)nd;
				err = dsk_map_itod(nDriver, &pDriver);			  if (err) return err;
				err2= dsk_close(&pDriver);
				err = dsk_pack_err(&output,  out_len, err2);	  if (err) return err;
				if (nRefCount) --(*nRefCount);
				return DSK_ERR_OK;
		case RPC_DSK_PREAD:
				err = dsk_unpack_i32 (&input, &inp_len, &nd);	  if (err) return err;	nDriver = (unsigned int)nd;
				err = dsk_unpack_geom(&input, &inp_len, &geom);	  if (err) return err;
				err = dsk_unpack_i32 (&input, &inp_len, &int1);	  if (err) return err;
				err = dsk_unpack_i32 (&input, &inp_len, &int2);	  if (err) return err;
				err = dsk_unpack_i32 (&input, &inp_len, &int3);	  if (err) return err;
				err = dsk_map_itod(nDriver, &pDriver);			  if (err) return err;
				err2= dsk_pread(pDriver, &geom, secbuf, (dsk_pcyl_t)int1, (dsk_phead_t)int2, (dsk_psect_t)int3);
				err = dsk_pack_err(&output, out_len, err2);	  if (err) return err;
				err = dsk_pack_bytes(&output, out_len, secbuf, geom.dg_secsize); if (err) return err;
				return DSK_ERR_OK;
		case RPC_DSK_PWRITE:
				err = dsk_unpack_i32 (&input, &inp_len, &nd);	  if (err) return err;	nDriver = (unsigned int)nd;
				err = dsk_unpack_geom(&input, &inp_len, &geom);	  if (err) return err;
				err = dsk_unpack_bytes(&input, &inp_len, &pbuf);  if (err) return err;
				err = dsk_unpack_i32 (&input, &inp_len, &int1);	  if (err) return err;
				err = dsk_unpack_i32 (&input, &inp_len, &int2);	  if (err) return err;
				err = dsk_unpack_i32 (&input, &inp_len, &int3);	  if (err) return err;
				err = dsk_map_itod(nDriver, &pDriver);			  if (err) return err;
				err2= dsk_pwrite(pDriver, &geom, pbuf, (dsk_pcyl_t)int1, (dsk_phead_t)int2, (dsk_psect_t)int3);
				err = dsk_pack_err(&output, out_len, err2);	  if (err) return err;
				return DSK_ERR_OK;

		case RPC_DSK_PFORMAT:
				pfmt = (DSK_FORMAT *)secbuf;
				err = dsk_unpack_i32 (&input, &inp_len, &nd);	  if (err) return err;	nDriver = (unsigned int)nd;
				err = dsk_unpack_geom(&input, &inp_len, &geom);	  if (err) return err;
				err = dsk_unpack_i32 (&input, &inp_len, &int1);	  if (err) return err;
				err = dsk_unpack_i32 (&input, &inp_len, &int2);	  if (err) return err;
				for (n = 0; n < geom.dg_sectors; n++)
					{
					err = dsk_unpack_format(&input, &inp_len, &pfmt[n]); if (err) return err;
					}
				err = dsk_unpack_i16 (&input, &inp_len, &filler);  if (err) return err;
				err = dsk_map_itod(nDriver, &pDriver);			  if (err) return err;
				err2= dsk_pformat(pDriver, &geom, (dsk_pcyl_t)int1, (dsk_phead_t)int2, pfmt, (unsigned char)filler);
				err = dsk_pack_err(&output, out_len, err2);	  if (err) return err;
				err = dsk_pack_geom(&output, out_len, &geom); if (err) return err;
				return DSK_ERR_OK;

		case RPC_DSK_PSECID:
				err = dsk_unpack_i32 (&input, &inp_len, &nd);	  if (err) return err;	nDriver = (unsigned int)nd;
				err = dsk_unpack_geom(&input, &inp_len, &geom);	  if (err) return err;
				err = dsk_unpack_i32 (&input, &inp_len, &int1);	  if (err) return err;
				err = dsk_unpack_i32 (&input, &inp_len, &int2);	  if (err) return err;
				err = dsk_map_itod(nDriver, &pDriver);			  if (err) return err;
				err2= dsk_psecid(pDriver, &geom, (dsk_pcyl_t)int1, (dsk_phead_t)int2, &fmt);
				err = dsk_pack_err(&output, out_len, err2);	  if (err) return err;
				err = dsk_pack_format(&output, out_len, &fmt); if (err) return err;
				return DSK_ERR_OK;

		case RPC_DSK_DRIVE_STATUS:
				err = dsk_unpack_i32 (&input, &inp_len, &nd);	  if (err) return err;	nDriver = (unsigned int)nd;
				err = dsk_unpack_geom(&input, &inp_len, &geom);	  if (err) return err;
				err = dsk_unpack_i32 (&input, &inp_len, &int1);	  if (err) return err;
				err = dsk_map_itod(nDriver, &pDriver);			  if (err) return err;
				err2= dsk_drive_status(pDriver, &geom, (dsk_phead_t)int1, &status);
				err = dsk_pack_err(&output, out_len, err2);	  if (err) return err;
				err = dsk_pack_i16(&output, out_len, status); if (err) return err;
				return DSK_ERR_OK;

		case RPC_DSK_GETGEOM:
				err = dsk_unpack_i32 (&input, &inp_len, &nd);	  if (err) return err;	nDriver = (unsigned int)nd;
				err = dsk_map_itod(nDriver, &pDriver);		  if (err) return err;
				err2= dsk_getgeom(pDriver, &geom);
				err = dsk_pack_err(&output, out_len, err2);	  if (err) return err;
				err = dsk_pack_geom(&output, out_len, &geom);	  if (err) return err;
				return DSK_ERR_OK;

		case RPC_DSK_PSEEK:
				err = dsk_unpack_i32 (&input, &inp_len, &nd);	  if (err) return err;	nDriver = (unsigned int)nd;
				err = dsk_unpack_geom(&input, &inp_len, &geom);	  if (err) return err;
				err = dsk_unpack_i32 (&input, &inp_len, &int1);	  if (err) return err;
				err = dsk_unpack_i32 (&input, &inp_len, &int2);	  if (err) return err;
				err = dsk_map_itod(nDriver, &pDriver);		  if (err) return err;
				err2= dsk_pseek(pDriver, &geom, (dsk_pcyl_t)int1, (dsk_phead_t)int2);
				err = dsk_pack_err(&output, out_len, err2);	  if (err) return err;
				return DSK_ERR_OK;

		case RPC_DSK_XREAD:
				err = dsk_unpack_i32 (&input, &inp_len, &nd);	  if (err) return err;	nDriver = (unsigned int)nd;
				err = dsk_unpack_geom(&input, &inp_len, &geom);	  if (err) return err;
				err = dsk_unpack_i32 (&input, &inp_len, &int1);	  if (err) return err;
				err = dsk_unpack_i32 (&input, &inp_len, &int2);	  if (err) return err;
				err = dsk_unpack_i32 (&input, &inp_len, &int3);	  if (err) return err;
				err = dsk_unpack_i32 (&input, &inp_len, &int4);	  if (err) return err;
				err = dsk_unpack_i32 (&input, &inp_len, &int5);	  if (err) return err;
				err = dsk_unpack_i32 (&input, &inp_len, &int6);	  if (err) return err;
				err = dsk_unpack_i32 (&input, &inp_len, &int7);	  if (err) return err;
				err = dsk_map_itod(nDriver, &pDriver);			  if (err) return err;
				deleted = int7;
				err2= dsk_xread(pDriver, &geom, secbuf, 
						(dsk_pcyl_t)int1, 
						(dsk_phead_t)int2, 
						(dsk_pcyl_t)int3, 
						(dsk_phead_t)int4, 
						(dsk_psect_t)int5,
						(size_t)int6,
						&deleted);
				err = dsk_pack_err(&output, out_len, err2);	  if (err) return err;
				err = dsk_pack_bytes(&output, out_len, secbuf, int6); if (err) return err;
				err = dsk_pack_i32(&output, out_len, deleted);
				return DSK_ERR_OK;
		case RPC_DSK_XWRITE:
				err = dsk_unpack_i32 (&input, &inp_len, &nd);	  if (err) return err;	nDriver = (unsigned int)nd;
				err = dsk_unpack_geom(&input, &inp_len, &geom);	  if (err) return err;
				err = dsk_unpack_bytes(&input, &inp_len, &pbuf);  if (err) return err;
				err = dsk_unpack_i32 (&input, &inp_len, &int1);	  if (err) return err;
				err = dsk_unpack_i32 (&input, &inp_len, &int2);	  if (err) return err;
				err = dsk_unpack_i32 (&input, &inp_len, &int3);	  if (err) return err;
				err = dsk_unpack_i32 (&input, &inp_len, &int4);	  if (err) return err;
				err = dsk_unpack_i32 (&input, &inp_len, &int5);	  if (err) return err;
				err = dsk_unpack_i32 (&input, &inp_len, &int6);	  if (err) return err;
				err = dsk_unpack_i32 (&input, &inp_len, &int7);	  if (err) return err;
				err = dsk_map_itod(nDriver, &pDriver);			  if (err) return err;
				err2= dsk_xwrite(pDriver, &geom, pbuf, 
						(dsk_pcyl_t)int1, 
						(dsk_phead_t)int2, 
						(dsk_pcyl_t)int3, 
						(dsk_phead_t)int4, 
						(dsk_psect_t)int5,
						(size_t)int6,
						(int)int7);
				err = dsk_pack_err(&output, out_len, err2);	  if (err) return err;
				return DSK_ERR_OK;
		case RPC_DSK_TRACKIDS:
				err = dsk_unpack_i32 (&input, &inp_len, &nd);	  if (err) return err;	nDriver = (unsigned int)nd;
				err = dsk_unpack_geom(&input, &inp_len, &geom);	  if (err) return err;
				err = dsk_unpack_i32 (&input, &inp_len, &int1);	  if (err) return err;
				err = dsk_unpack_i32 (&input, &inp_len, &int2);	  if (err) return err;
				err = dsk_map_itod(nDriver, &pDriver);			  if (err) return err;
				err2 = dsk_ptrackids(pDriver, &geom, int1,
						int2, &rcount, &trkids);
				if (err2 || !trkids) rcount = 0;
				err = dsk_pack_err(&output, out_len, err2);	  if (err) return err;
				err = dsk_pack_i32(&output, out_len, rcount);	  if (err) return err;
				for (n = 0; n < rcount; n++)
				{
					err = dsk_pack_format(&output, out_len, &trkids[n]);
					if (err) return err;
				}
				if (trkids) dsk_free(trkids);
				return DSK_ERR_OK;	
		case RPC_DSK_PTREAD:
				err = dsk_unpack_i32 (&input, &inp_len, &nd);	  if (err) return err;	nDriver = (unsigned int)nd;
				err = dsk_unpack_geom(&input, &inp_len, &geom);	  if (err) return err;
				err = dsk_unpack_i32 (&input, &inp_len, &int1);	  if (err) return err;
				err = dsk_unpack_i32 (&input, &inp_len, &int2);	  if (err) return err;
				err = dsk_map_itod(nDriver, &pDriver);			  if (err) return err;
				err2= dsk_ptread(pDriver, &geom, secbuf, (dsk_pcyl_t)int1, (dsk_phead_t)int2);
				err = dsk_pack_err(&output, out_len, err2);	  if (err) return err;
				err = dsk_pack_bytes(&output, out_len, secbuf, geom.dg_secsize * geom.dg_sectors); if (err) return err;
				return DSK_ERR_OK;
		case RPC_DSK_XTREAD:
				err = dsk_unpack_i32 (&input, &inp_len, &nd);	  if (err) return err;	nDriver = (unsigned int)nd;
				err = dsk_unpack_geom(&input, &inp_len, &geom);	  if (err) return err;
				err = dsk_unpack_i32 (&input, &inp_len, &int1);	  if (err) return err;
				err = dsk_unpack_i32 (&input, &inp_len, &int2);	  if (err) return err;
				err = dsk_unpack_i32 (&input, &inp_len, &int3);	  if (err) return err;
				err = dsk_unpack_i32 (&input, &inp_len, &int4);	  if (err) return err;
				err = dsk_map_itod(nDriver, &pDriver);			  if (err) return err;
				err2= dsk_xtread(pDriver, &geom, secbuf, (dsk_pcyl_t)int1, (dsk_phead_t)int2, (dsk_pcyl_t)int3, (dsk_phead_t)int4);
				err = dsk_pack_err(&output, out_len, err2);	  if (err) return err;
				err = dsk_pack_bytes(&output, out_len, secbuf, geom.dg_secsize * geom.dg_sectors); if (err) return err;
				return DSK_ERR_OK;

		case RPC_DSK_OPTION_ENUM:
				err = dsk_unpack_i32 (&input, &inp_len, &nd);	  if (err) return err;	nDriver = (unsigned int)nd;
				err = dsk_unpack_i32 (&input, &inp_len, &int1);	  if (err) return err;
				err = dsk_map_itod(nDriver, &pDriver);			  if (err) return err;
				err2= dsk_option_enum(pDriver, int1, &str1);
				err = dsk_pack_err(&output, out_len, err2);	  if (err) return err;
				err = dsk_pack_string(&output, out_len, str1);	  if (err) return err;	
				return DSK_ERR_OK;
		case RPC_DSK_OPTION_SET:
				err = dsk_unpack_i32 (&input, &inp_len, &nd);	  if (err) return err;	nDriver = (unsigned int)nd;
				err = dsk_unpack_string(&input, &inp_len, &str1); if (err) return err;
				err = dsk_unpack_i32 (&input, &inp_len, &int1);	  if (err) return err;
				err = dsk_map_itod(nDriver, &pDriver);			  if (err) return err;
				err2= dsk_set_option(pDriver, str1, int1);
				err = dsk_pack_err(&output, out_len, err2);	  if (err) return err;
				return DSK_ERR_OK;
		case RPC_DSK_OPTION_GET:
				err = dsk_unpack_i32 (&input, &inp_len, &nd);	  if (err) return err;	nDriver = (unsigned int)nd;
				err = dsk_unpack_string(&input, &inp_len, &str1); if (err) return err;
				err = dsk_map_itod(nDriver, &pDriver);			  if (err) return err;
				err2= dsk_get_option(pDriver, str1, &value);
				err = dsk_pack_err(&output, out_len, err2);	  if (err) return err;
				err = dsk_pack_i32 (&output, out_len, value);	  if (err) return err;
				return DSK_ERR_OK;
		case RPC_DSK_GETCOMMENT:
				err = dsk_unpack_i32 (&input, &inp_len, &nd);	  if (err) return err;	nDriver = (unsigned int)nd;
				err = dsk_map_itod(nDriver, &pDriver);			  if (err) return err;
				err2= dsk_get_comment(pDriver, &str1);
				err = dsk_pack_err(&output, out_len, err2);	  if (err) return err;
				err = dsk_pack_string(&output, out_len, str1);	  if (err) return err;	
				return DSK_ERR_OK;
		case RPC_DSK_SETCOMMENT:
				err = dsk_unpack_i32 (&input, &inp_len, &nd);	  if (err) return err;	nDriver = (unsigned int)nd;
				err = dsk_map_itod(nDriver, &pDriver);			  if (err) return err;
				err = dsk_unpack_string(&input, &inp_len, &str1); if (err) return err;
				err2= dsk_set_comment(pDriver, str1);
				err = dsk_pack_err(&output, out_len, err2);	  if (err) return err;
				return DSK_ERR_OK;


		case RPC_DSK_RTREAD:
				err = dsk_unpack_i32 (&input, &inp_len, &nd);	  if (err) return err;	nDriver = (unsigned int)nd;
				err = dsk_unpack_geom(&input, &inp_len, &geom);	  if (err) return err;
				err = dsk_unpack_i32 (&input, &inp_len, &int1);	  if (err) return err;
				err = dsk_unpack_i32 (&input, &inp_len, &int2);	  if (err) return err;
				err = dsk_unpack_i32 (&input, &inp_len, &int3);	  if (err) return err;
				err = dsk_map_itod(nDriver, &pDriver);			  if (err) return err;
				err2= dsk_rtread(pDriver, &geom, secbuf, (dsk_pcyl_t)int1, (dsk_phead_t)int2, int3);
				err = dsk_pack_err(&output, out_len, err2);	  if (err) return err;
/* XXX This is a completely arbitrary buffer size */
				err = dsk_pack_i32(&output, out_len, geom.dg_secsize * geom.dg_sectors);  if (err) return err;
				err = dsk_pack_bytes(&output, out_len, secbuf, geom.dg_secsize * geom.dg_sectors); if (err) return err;
				return DSK_ERR_OK;


/* Return a list of implemented functions */
		case RPC_DSK_PROPERTIES:
				err = dsk_unpack_i32 (&input, &inp_len, &nd);	  if (err) return err;	nDriver = (unsigned int)nd;
				err = dsk_map_itod(nDriver, &pDriver);		  if (err) return err;
				int1 = 0;	/* Count of implemented functions */
#define PROPCHECK(func, rid) if (pDriver->dr_class->func) props[int1++] = rid;
				PROPCHECK(dc_open,    RPC_DSK_OPEN)
				PROPCHECK(dc_creat,   RPC_DSK_CREAT)
				PROPCHECK(dc_close,   RPC_DSK_CLOSE)
				PROPCHECK(dc_read,    RPC_DSK_PREAD)
				PROPCHECK(dc_write,   RPC_DSK_PWRITE)
				PROPCHECK(dc_format,  RPC_DSK_PFORMAT)
				PROPCHECK(dc_secid,   RPC_DSK_PSECID)
				PROPCHECK(dc_getgeom, RPC_DSK_GETGEOM)
				PROPCHECK(dc_xseek,   RPC_DSK_PSEEK)
				PROPCHECK(dc_status,  RPC_DSK_DRIVE_STATUS)
				PROPCHECK(dc_xread,   RPC_DSK_XREAD)
				PROPCHECK(dc_xwrite,  RPC_DSK_XWRITE)
				PROPCHECK(dc_tread,   RPC_DSK_PTREAD)
				PROPCHECK(dc_xtread,  RPC_DSK_XTREAD)
				PROPCHECK(dc_option_enum, RPC_DSK_OPTION_ENUM)
				PROPCHECK(dc_option_get, RPC_DSK_OPTION_GET)
				PROPCHECK(dc_option_set, RPC_DSK_OPTION_SET)
				PROPCHECK(dc_trackids, RPC_DSK_TRACKIDS)
				PROPCHECK(dc_rtread, RPC_DSK_RTREAD)
#undef PROPCHECK
				props[int1++] = RPC_DSK_PROPERTIES;
				err = dsk_pack_err(&output, out_len, DSK_ERR_OK);	  if (err) return err;
				err = dsk_pack_i16(&output, out_len, (unsigned short)int1); if (err) return err;
				for (int2 = 0; int2 < int1; int2++)
				{
					err = dsk_pack_i16(&output, out_len, props[int2]); if (err) return err;
				}
				err = dsk_pack_string(&output, out_len, pDriver->dr_class->dc_description); if (err) return err;
				return DSK_ERR_OK;

/* Unsupported function. Return DSK_ERR_UNKRPC */
		default: 
				err2 = dsk_pack_err(&output, out_len, 
						DSK_ERR_UNKRPC);
				return DSK_ERR_OK;
		}

	}
Example #7
0
int do_login(int argc, char *outfile, char *outtyp, char *outcomp, int forcehead)
{
	DSK_PDRIVER outdr = NULL;
	dsk_err_t e;
	DSK_GEOMETRY dg;
	unsigned char drv_status;
	const char *comp;
	char *comment;
	int indent = 0;
	int opt, any;

	dsk_reportfunc_set(report, report_end);	
	e = dsk_open(&outdr, outfile, outtyp, outcomp);
	if (!e) e = dsk_set_retry(outdr, retries);
	if (forcehead >= 0 && !e) e = dsk_set_forcehead(outdr, forcehead);
	if (!e) e = dsk_getgeom(outdr, &dg);
	if (!e)
	{
		if (argc > 1)
		{
			printf("%s:\n", outfile);
			indent = 2;
		}
                printf(          "%-*.*sDriver:      %s\n", 
				indent, indent, "", dsk_drvdesc(outdr));
		comp = dsk_compname(outdr);
                if (comp) 
		{
			printf("%-*.*sCompression: %s\n", 
				indent, indent, "", dsk_compdesc(outdr));
		}

		if (forcehead >= 0) 
		{
			printf("%-*.*s[Forced to read from side %d]\n", 
					indent, indent, "", forcehead);
		}

		printf("%-*.*sSidedness:     %s\n"
                       "%-*.*sCylinders:     %2d\n"
		       "%-*.*sHeads:          %d\n"
                       "%-*.*sSectors:      %3d\n"
                       "%-*.*sFirst sector: %3d\n"
                       "%-*.*sSector size: %4ld\n"
		       "%-*.*sData rate:     %s\n"
		       "%-*.*sRecord mode:  %s\n"
		       "%-*.*sComplement:   %s\n"
		       "%-*.*sR/W gap:     0x%02x\n"
		       "%-*.*sFormat gap:  0x%02x\n",
			indent, indent, "", show_sidedness(dg.dg_sidedness), 
			indent, indent, "", dg.dg_cylinders,
			indent, indent, "", dg.dg_heads, 
			indent, indent, "", dg.dg_sectors, 
			indent, indent, "", dg.dg_secbase,
			indent, indent, "", (long)dg.dg_secsize, 
			indent, indent, "", show_rate(dg.dg_datarate),
			indent, indent, "", show_recmode(dg.dg_fm),
			indent, indent, "", (dg.dg_fm & RECMODE_COMPLEMENT) ? "Yes" : "No",
			indent, indent, "", dg.dg_rwgap,   
			indent, indent, "", dg.dg_fmtgap);
		e = dsk_drive_status(outdr, &dg, 0, &drv_status);
		if (!e)
		{	
			printf("\n%-*.*sDrive status:  0x%02x\n", 
				indent, indent, "", drv_status);
		}
		e = dsk_get_comment(outdr, &comment);
		if (!e && comment)  
		{
			char *c;
			printf("%-*.*sComment:       ", indent, indent, "");
			c = comment;
			while (*c)
			{
				putchar(*c);
				if (*c == '\n') printf("%-*.*s               ", 
					indent, indent, "");
				c++;
			}
		}	
		putchar('\n');
/* Dump filesystem options -- ie, any options beginning "FS." */
		opt = 0;
		any = 0;
		while (dsk_option_enum(outdr, opt, &comment) == DSK_ERR_OK &&
				comment != NULL)
		{
			int value;
			char buf[30];

			if (!strncmp(comment, "FS:", 3) &&
		            dsk_get_option(outdr, comment, &value) == DSK_ERR_OK)
			{
				if (!any) 
				{
					printf("%-*.*sFilesystem parameters:\n",
						indent, indent, "");
					any = 1;
				}
				sprintf(buf, "%s:", comment + 3);
				printf("%-*.*s%-15.15s0x%02x\n",
					indent, indent, "", buf, value);
			}			
			++opt;
		}
	}
	if (outdr) 
	{
		if (!e) e = dsk_close(&outdr); else dsk_close(&outdr);
	}
	if (e)
	{
		fprintf(stderr, "%s: %s\n", outfile, dsk_strerror(e));
		return 1;
	}
	return 0;
}
Example #8
0
int do_test(char *outfile, char *outtyp, char *outcomp, int forcehead)
{
	DSK_PDRIVER outdr = NULL;
	dsk_err_t e;
	DSK_GEOMETRY dg, dg2;
	static DSK_FORMAT fmt[9] =
		{
			{ 0, 0, 1, 512 },
			{ 0, 0, 3, 512 },
			{ 3, 1, 5, 512 },
			{ 0, 0, 7, 512 },
			{ 0, 0, 9, 512 },
			{ 0, 1, 2, 512 },
			{ 0, 0, 4, 512 },
			{ 2, 0, 6, 512 },
			{ 0, 0, 8, 512 },
		};
	static DSK_FORMAT fmt2[9] =
		{
			{ 4, 0, 1, 512 },
			{ 4, 0, 3, 512 },
			{ 4, 0, 5, 512 },
			{ 4, 0, 7, 512 },
			{ 4, 0, 9, 512 },
			{ 4, 0, 2, 512 },
			{ 4, 0, 4, 512 },
			{ 4, 0, 6, 512 },
			{ 4, 0, 8, 512 },
		};
	DSK_FORMAT secid, *pfmt;
	char *comment;
	unsigned char status;
	dsk_psect_t count, n;
	char *optname;
	int value;

	dsk_reportfunc_set(report, report_end);	
	dg_stdformat(&dg, FMT_180K, NULL, NULL);
	if (t80) dg.dg_cylinders = 80;

	printf("Checking dsk_creat\n");
	e = dsk_creat(&outdr, outfile, outtyp, outcomp);
	CHECKERR("dsk_creat")
	else
	{
		dsk_set_option(outdr, "REMOTE:TESTING", 1);
		printf("Checking set_comment\n");
		e = dsk_set_comment(outdr, "Example comment");
		CHECKERR3("dsk_set_comment");
		printf("Checking pformat\n");
		e = dsk_pformat(outdr, &dg, 0, 0, fmt, 0xE5);
		CHECKERR("dsk_pformat")
		printf("Checking apform\n");
		e = dsk_apform(outdr, &dg, 1, 0, 0xF6);
		CHECKERR("dsk_apform")
		printf("Checking lformat\n");
		e = dsk_lformat(outdr, &dg, 2, fmt2, 0xD4);
		CHECKERR("dsk_pformat")
		printf("Checking ptrackids\n");
		e = dsk_ptrackids(outdr, &dg, 0, 0, &count, &pfmt);
		CHECKERR("dsk_ptrackids")
		else
		{
			dsk_psect_t n;
			printf("Cyl Head Sec Size\n");
			printf("-----------------\n");
			for (n = 0; n < count; n++)
			{
				printf("%3d  %3d %3d %4d\n",
					pfmt[n].fmt_cylinder,
					pfmt[n].fmt_head,
					pfmt[n].fmt_sector,
					(int)pfmt[n].fmt_secsize);
			}
			printf("-----------------\n");
			dsk_free(pfmt);
		}
		memset(secbuf,       0, sizeof(secbuf));
		memcpy(secbuf, spec180, sizeof(spec180));
		printf("Checking dsk_lwrite\n");
		e = dsk_lwrite(outdr, &dg, secbuf, 0);
		CHECKERR("dsk_lwrite")
		strcpy((char *)secbuf, "Cyl=3 Head=1 Sec=5");
		printf("Checking dsk_xwrite\n");
		e = dsk_xwrite(outdr, &dg, secbuf, 0, 0, 3, 1, 5, 512, 0);
		CHECKERR("dsk_xwrite")
		printf("Checking dsk_psecid\n");
		e = dsk_psecid(outdr, &dg, 1, 0, &secid);
		CHECKERR("dsk_psecid")
		else
		{
			printf("%3d  %3d %3d %4d\n",
				secid.fmt_cylinder,
				secid.fmt_head,
				secid.fmt_sector,
				(int)secid.fmt_secsize);
			if (secid.fmt_cylinder != 1 || secid.fmt_head != 0 ||
			    secid.fmt_secsize != 512) 
			{
				++failures;
				printf("-- mismatch!\n");
			}
		}
	}	
	if (outdr) 
	{
		dsk_close(&outdr);
		CHECKERR("dsk_close")
	}
	printf("Checking dsk_open\n");
	e = dsk_open(&outdr, outfile, outtyp, outcomp);
	CHECKERR("dsk_open")
	else
	{
		dsk_set_option(outdr, "REMOTE:TESTING", 1);
		printf("Checking dsk_getgeom\n");
		e = dsk_getgeom(outdr, &dg2);
		if (t80 && dg2.dg_cylinders == 40) dg2.dg_cylinders = 80;
		CHECKERR("dsk_getgeom")
		else if (memcmp(&dg, &dg2, sizeof(dg)))
		{
			++failures;
			printf("-- mismatch!\n");
			printf("Cyls:  %3d %3d\n", dg.dg_cylinders, dg2.dg_cylinders);
			printf("Heads: %3d %3d\n", dg.dg_heads, dg2.dg_heads);
			printf("Secs:  %3d %3d\n", dg.dg_sectors, dg2.dg_sectors);
		}
		printf("Checking dsk_lread\n");
		e = dsk_lread(outdr, &dg, secbuf, 0);
		CHECKERR("dsk_lread")
		else if (memcmp(secbuf, spec180, sizeof(spec180)))
		{
			++failures;
			printf("-- mismatch!\n");
		}
		printf("Checking dsk_xread\n");
		e = dsk_xread(outdr, &dg, secbuf, 0, 0, 3, 1, 5, 512, NULL);
		CHECKERR("dsk_xread")
		else if (strcmp((char *)secbuf, "Cyl=3 Head=1 Sec=5"))
		{
			++failures;
			printf("-- mismatch!\n");
		}
		printf("Checking dsk_lseek\n");
		e = dsk_lseek(outdr, &dg, 1);
		CHECKERR("dsk_lseek")
		printf("Checking dsk_drive_status\n");
		e = dsk_drive_status(outdr, &dg, 0, &status);
		CHECKERR("dsk_drive_status")
		else printf("-- status=0x%02x\n", status);

		printf("Checking dsk_tread\n");
		e = dsk_ptread(outdr, &dg, trkbuf, 1, 0);
		CHECKERR("dsk_ptread")
		else
		{
			for (n = 0; n < 4608; n++) if (trkbuf[n] != 0xF6)
			{
				printf("-- mismatch!\n");
				++failures;
				break;
			}
	
		}
		printf("Checking dsk_xtread\n");
		e = dsk_xtread(outdr, &dg, trkbuf, 2, 0, 4, 0);
		CHECKERR("dsk_xtread")
		else
		{
			for (n = 0; n < 4608; n++) if (trkbuf[n] != 0xD4)
			{
				printf("-- mismatch!\n");
				++failures;
				break;
			}
		}
		printf("Checking dsk_option_enum\n");
		e = dsk_option_enum(outdr, 0, &optname);
		CHECKERR("dsk_option_enum")
		else
		{
			printf("-- first option is %s\n", optname);
		}
		if (!optname) optname = "dummy";
		printf("Checking dsk_get_option(%s)\n", optname);
		e = dsk_get_option(outdr, optname, &value);
		CHECKERR2("dsk_get_option")
		else
		{
			printf("-- value=%d\n", value);
		}
		printf("Checking dsk_set_option(example, 2)\n");
		e = dsk_set_option(outdr, "example", 2);
		CHECKERR2("dsk_set_option")
		printf("Checking dsk_rtread\n");
		e = dsk_rtread(outdr, &dg, trkbuf, 0, 0, 0);
		CHECKERR3("dsk_rtread")
		printf("Checking dsk_get_comment\n");
		e = dsk_get_comment(outdr, &comment);
		CHECKERR3("dsk_get_comment")
		else if (comment) printf("-- comment=%s\n", comment);
	}
	if (outdr) 
	{
		dsk_close(&outdr);
		CHECKERR("dsk_close")
	}
	printf("\n");
	printf("Failed calls (failure important):   %2d\n", failures);
	printf("Failed calls (failure unimportant): %2d\n", warnings);
	printf("Unimplemented functions:            %2d\n", unimpl);
	printf("Unimplemented functions over RPC:   %2d\n", rpcunimp);
	return failures;
}