Exemplo n.º 1
0
LDPUBLIC32 dsk_err_t LDPUBLIC16 dsk_close(DSK_DRIVER **self)
{
	dsk_err_t e, e2;
	COMPRESS_DATA *dc;
	DSK_OPTION *opt, *opt2;

	if (!self || (!(*self)) || (!(*self)->dr_class))    return DSK_ERR_BADPTR;

	e = ((*self)->dr_class->dc_close)(*self);

	dc = (*self)->dr_compress;
	if (dc)
	{
		if ((*self)->dr_dirty) e2 = comp_commit(&dc); 
		else		       e2 = comp_abort (&dc);

		if (!e) e = e2;
	}
	/* Free any option blocks the driver has accumulated */
	opt = (*self)->dr_options;
	while (opt)
	{
		opt2 = opt->do_next;
		dsk_free(opt);
		opt = opt2;
	}
	/* And any comments */
	dsk_set_comment(*self, NULL);
	dsk_free (*self);
	*self = NULL;
	return e;
}
Exemplo n.º 2
0
dsk_err_t ldbsdisk_attach(DSK_DRIVER *pdriver)
{
	LDBSDISK_DSK_DRIVER *self;
	char *comment;
	dsk_err_t err;

	DC_CHECK(pdriver)
	self = (LDBSDISK_DSK_DRIVER *)pdriver;

	err = ldbs_get_dpb(self->ld_store, &self->ld_dpb);
	if (err) return err;

	err = ldbs_get_comment(self->ld_store, &comment);
	if (err) return err;

	if (comment)
	{
		/* dsk_set_comment() sets the dirty flag, so preserve it */
		int dirty = pdriver->dr_dirty;
;
		dsk_set_comment(pdriver, comment);
		ldbs_free(comment);

		pdriver->dr_dirty = dirty;
	}
	self->ld_cur_cyl = -1;
	self->ld_cur_head = -1;
	self->ld_cur_track = NULL;

	return DSK_ERR_OK;
}
Exemplo n.º 3
0
STDMETHODIMP CDisk::put_comment(BSTR newVal)
{
	char *buf;
	dsk_err_t err;
	
	buf = get_string(newVal);
	if (!buf) return MapError(DSK_ERR_NOMEM);
	err = dsk_set_comment(m_driver, buf);
	dsk_free(buf);
	return MapError(err);
}
Exemplo n.º 4
0
dsk_err_t remote_creat(DSK_DRIVER *self, const char *filename)
{
	RPCFUNC function;
	char *outname, *outtype, *outcomp, *comment;

	dsk_err_t err = remote_lookup(self, filename, &outname, &outtype, &outcomp);

	if (err) return err;
	function = self->dr_remote->rd_class->rc_call;
	err = dsk_r_creat(self, function, &self->dr_remote->rd_handle, 
			 	outname, outtype, outcomp);
	dsk_free(outname);
	if (err) return err;
	err = dsk_r_properties(self, function, self->dr_remote->rd_handle);
	if (err) return err;
/*	if (implements(self, RPC_DSK_GETCOMMENT))
	{ */
		err = dsk_r_get_comment(self, function, 
				self->dr_remote->rd_handle, &comment);
		if (err) return err;
		if (comment != NULL) err = dsk_set_comment(self, comment);
/*	} */
	return err;
}
Exemplo n.º 5
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;
		}

	}
Exemplo n.º 6
0
dsk_err_t tele_open(DSK_DRIVER *s, const char *filename)
{
	unsigned char header[12];
	DC_CHECK(s);

	self->tele_fp = fopen(filename, "rb");
	if (!self->tele_fp) return DSK_ERR_NOTME;
	/* This does use fread not tele_fread, because it's not compressed
	 * by the Advanced compression */
	if (fread(header, 1, sizeof(header), self->tele_fp) < (int)sizeof(header) ||
	    (memcmp(header, "TD", 2) && memcmp(header, "td", 2)))
	{
		fclose(self->tele_fp);
		return DSK_ERR_NOTME;
	}
	memcpy(self->tele_head.magic, header, 2);
	self->tele_head.magic[2] = 0;
	self->tele_head.volume_seq  = header[2];
	self->tele_head.volume_id   = header[3];
	self->tele_head.ver         = header[4];
	self->tele_head.datarate    = header[5];
	self->tele_head.drivetype   = header[6];
	self->tele_head.doubletrack = header[7];
	self->tele_head.dosmode     = header[8];
	self->tele_head.sides       = header[9];
	self->tele_head.crc       = ((tele_word)header[11]) << 8 | header[10];
	/* XXX Advanced compression not supported */
	if (!strcmp((char *)header, "td"))
	{
#ifndef WIN16
		fprintf(stderr, "LibDsk TD0 driver: Advanced compression not supported\n");
#endif
		fclose(self->tele_fp);
		return DSK_ERR_NOTIMPL;
	}
	/* Read a comment if there is one */
	if (self->tele_head.doubletrack & 0x80)
	{
		int comment_len, n;
		if (tele_fread(self, header, 10))
		{
			fclose(self->tele_fp);
			return DSK_ERR_SYSERR;
		}
		comment_len = ((int)(header[3])) << 8 | header[2];
		self->tele_comment = dsk_malloc(comment_len + sizeof(TELE_COMMENT));
		if (!self->tele_comment)
		{
			fclose(self->tele_fp);
			return DSK_ERR_NOMEM;
		}
		self->tele_comment->year = header[4] + 1900;
		self->tele_comment->mon = header[5];
		self->tele_comment->day = header[6];
		self->tele_comment->hour = header[7];
		self->tele_comment->min = header[8];
		self->tele_comment->sec = header[9];
		if (tele_fread(self, self->tele_comment->text, comment_len))
		{
			fclose(self->tele_fp);
			return DSK_ERR_SYSERR;
		}
		self->tele_comment->text[comment_len] = 0;
		for (n = 0; n < comment_len; n++)
		{
			if (self->tele_comment->text[n] == 0 &&
			    self->tele_comment->text[n+1] == 0)
			{
				self->tele_comment->text[n] = '\r';
				self->tele_comment->text[n+1] = '\n';
			}
		}	
		dsk_set_comment(s, self->tele_comment->text);
	}
	self->tele_track_addr[0][0] = ftell(self->tele_fp);

	return DSK_ERR_OK;
}
Exemplo n.º 7
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;
}