/* 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; }
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; } dsk_free (*self); *self = NULL; return e; }
/* 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; }
LDPUBLIC32 dsk_err_t LDPUBLIC16 dsk_close(DSK_DRIVER **self) { dsk_err_t e, e2; COMPRESS_DATA *dc; 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; } dsk_free (*self); *self = NULL; return e; }