Beispiel #1
0
/* Initialise a DSK_GEOMETRY with a standard format */
LDPUBLIC32 dsk_err_t LDPUBLIC16 dg_stdformat(DSK_GEOMETRY *self, dsk_format_t formatid,
            dsk_cchar_t *fname, dsk_cchar_t *fdesc)
{
    int idx = (formatid - FMT_180K);

    dg_custom_init();

/* If index is out of range in the standard set, search the custom set */
    if ((unsigned)idx >= (sizeof(stdg)/sizeof(stdg[0]))  ) 
    {
        DSK_NAMEDGEOM *cg = customgeom;
        idx -= (sizeof(stdg) / sizeof(stdg[0]));

        while (idx)
        {
            if (!cg) return DSK_ERR_BADFMT;
            cg = cg->next;
            --idx;
        }
        if (!cg) return DSK_ERR_BADFMT;

        if (self) memcpy(self, &cg->dg, sizeof(*self));
        if (fname) *fname = cg->name;
        if (fdesc) *fdesc = cg->desc;
        return DSK_ERR_OK;
    }
/* Search the standard set */
    if (self) memcpy(self, &stdg[idx].dg, sizeof(*self));
    if (fname) *fname = stdg[idx].name;
    if (fdesc) *fdesc = stdg[idx].desc;
    return DSK_ERR_OK;
}
Beispiel #2
0
/* Create a disc file, of type "type" with name "filename". */
LDPUBLIC32 dsk_err_t LDPUBLIC16 dsk_creat(DSK_DRIVER **self, const char *filename, const char *type,
			const char *compress)
{
	int ndrv;
	dsk_err_t e;
	COMPRESS_DATA *cd = NULL;

	if (!self || !filename || !type) return DSK_ERR_BADPTR;

	dg_custom_init();
	if (compress)
	{	
		e = comp_creat(&cd, filename, compress);
		if (e) return e;
		if (cd) filename = cd->cd_ufilename;
	}

	for (ndrv = 0; classes[ndrv]; ndrv++)
	{
		if (!strcmp(type, classes[ndrv]->dc_drvname))
		{
			e = dsk_icreat(self, filename, ndrv, cd);
			if (e != DSK_ERR_OK && cd) comp_abort(&cd);
			return e;
		}
	}
	if (cd) comp_abort(&cd);
	return DSK_ERR_NODRVR;
}
Beispiel #3
0
/* Close a DSK file. Frees the pointer and sets it to null. */
LDPUBLIC32 dsk_err_t LDPUBLIC16 dsk_open(DSK_DRIVER **self, const char *filename, const char *type,
			const char *compress)
{
	int ndrv;
	dsk_err_t e;
	COMPRESS_DATA *cd;

	if (!self || !filename) return DSK_ERR_BADPTR;

	dg_custom_init();

	/* See if it's compressed */
	e = comp_open(&cd, filename, compress);
	if (e != DSK_ERR_OK && e != DSK_ERR_NOTME) return e;
	
	if (type)
	{
		for (ndrv = 0; classes[ndrv]; ndrv++)
		{
			if (!strcmp(type, classes[ndrv]->dc_drvname))
			{
				e = dsk_iopen(self, filename, ndrv, cd);
				if (e && cd) comp_abort(&cd);
				return e;
			}
		}
		if (cd) comp_abort(&cd);
		return DSK_ERR_NODRVR;
	}
	for (ndrv = 0; classes[ndrv]; ndrv++)
	{
		e = dsk_iopen(self, filename, ndrv, cd);
		if (e != DSK_ERR_NOTME) 
		{
			if (e != DSK_ERR_OK && cd) comp_abort(&cd);
			return e;
		}
	}	
	if (cd) comp_abort(&cd);
	return DSK_ERR_NOTME;
}