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; }
IdentityForm::IdentityForm(wxWindow* parent, const wxString &title, DSK_PDRIVER dsk, DSK_GEOMETRY *dg) : wxDialog(parent, -1, title, wxDefaultPosition, wxSize(400, 375)) { const char *comp; char *comment; dsk_err_t err; unsigned char drv_status; memcpy(&m_dg, dg, sizeof(m_dg)); comp = dsk_compname(dsk); (void)new wxStaticText(this, -1, wxT("Driver:"), wxPoint(5, 5), wxSize(95, 25)); (void)new wxStaticText(this, -1, wxString(dsk_drvdesc(dsk), wxConvUTF8), wxPoint(105, 5), wxSize(300, 25)); (void)new wxStaticText(this, -1, wxT("Compression:"), wxPoint(5, 25), wxSize(95, 25)); (void)new wxStaticText(this, -1, comp ? wxString(comp, wxConvUTF8) : wxT("None"), wxPoint(105,25), wxSize(300, 25)); (void)new wxStaticText(this, -1, wxT("Sidedness:"), wxPoint(5, 45), wxSize(95, 25)); (void)new wxStaticText(this, -1, wxString::Format(wxT("%d"), m_dg.dg_sidedness), wxPoint(105,45), wxSize(300, 25)); (void)new wxStaticText(this, -1, wxT("Cylinders:"), wxPoint(5, 65), wxSize(95, 25)); (void)new wxStaticText(this, -1, wxString::Format(wxT("%d"), m_dg.dg_cylinders), wxPoint(105,65), wxSize(300, 25)); (void)new wxStaticText(this, -1, wxT("Heads:"), wxPoint(5, 85), wxSize(95, 25)); (void)new wxStaticText(this, -1, wxString::Format(wxT("%d"), m_dg.dg_heads), wxPoint(105,85), wxSize(300, 25)); (void)new wxStaticText(this, -1, wxT("Sectors:"), wxPoint(5, 105), wxSize(95, 25)); (void)new wxStaticText(this, -1, wxString::Format(wxT("%d"), m_dg.dg_sectors), wxPoint(105,105), wxSize(300, 25)); (void)new wxStaticText(this, -1, wxT("Sec. size:"), wxPoint(5, 125), wxSize(95, 25)); (void)new wxStaticText(this, -1, wxString::Format(wxT("%d"), m_dg.dg_secsize), wxPoint(105,125), wxSize(300, 25)); (void)new wxStaticText(this, -1, wxT("1st sector:"), wxPoint(5, 145), wxSize(95, 25)); (void)new wxStaticText(this, -1, wxString::Format(wxT("%d"), m_dg.dg_secbase), wxPoint(105,145), wxSize(300, 25)); (void)new wxStaticText(this, -1, wxT("Data rate:"), wxPoint(5, 165), wxSize(95, 25)); (void)new wxStaticText(this, -1, wxString::Format(wxT("%d"), m_dg.dg_datarate), wxPoint(105,165), wxSize(300, 25)); (void)new wxStaticText(this, -1, wxT("Record mode:"), wxPoint(5, 185), wxSize(95, 25)); (void)new wxStaticText(this, -1, m_dg.dg_fm ? wxT("FM") : wxT("MFM"), wxPoint(105,185), wxSize(300, 25)); (void)new wxStaticText(this, -1, wxT("R/W gap:"), wxPoint(5, 205), wxSize(95, 25)); (void)new wxStaticText(this, -1, wxString::Format(wxT("0x%02x"), m_dg.dg_rwgap), wxPoint(105,205), wxSize(300, 25)); (void)new wxStaticText(this, -1, wxT("Format gap:"), wxPoint(5, 225), wxSize(95, 25)); (void)new wxStaticText(this, -1, wxString::Format(wxT("0x%02x"), m_dg.dg_fmtgap), wxPoint(105,225), wxSize(300, 25)); err = dsk_drive_status(dsk, &m_dg, 0, &drv_status); (void)new wxStaticText(this, -1, wxT("Drive status:"), wxPoint(5, 245), wxSize(95, 25)); if (!err) { (void)new wxStaticText(this, -1, wxString::Format(wxT("0x%02x"), drv_status), wxPoint(105,245), wxSize(300, 25)); } else { (void)new wxStaticText(this, -1, wxString(dsk_strerror(err), wxConvUTF8), wxPoint(105,245), wxSize(300, 25)); } err = dsk_get_comment(dsk, &comment); if (err == DSK_ERR_OK && comment != NULL) { (void)new wxStaticText(this, -1, wxT("Comment:"), wxPoint(5, 265), wxSize(95, 25)); (void)new wxStaticText(this, -1, wxString(comment, wxConvUTF8), wxPoint(105,265), wxSize(300, 100)); } (void)new wxButton(this, wxID_OK, wxT("OK"), wxPoint(160, 305), wxSize(80, 30)); }
const char *p3fs_strerror(int err) { switch(err) { case P3FS_ERR_DISKFULL: return "Disk full."; case P3FS_ERR_DIRFULL: return "Directory full."; case P3FS_ERR_EXISTS: return "File exists."; case P3FS_ERR_MISALIGN: return "DOS clusters don't align with CP/M blocks."; } return dsk_strerror(err); }
HRESULT CDisk::MapError(int err) { char *desc = dsk_strerror(err); // These errors all map onto well-known HRESULTS: switch(err) { case DSK_ERR_OK: return S_OK; case DSK_ERR_BADPTR: return Error(desc, IID_IDisk, E_POINTER); case DSK_ERR_BADPARM: return Error(desc, IID_IDisk, E_INVALIDARG); case DSK_ERR_NOMEM: return Error(desc, IID_IDisk, E_OUTOFMEMORY); case DSK_ERR_NOTIMPL: return Error(desc, IID_IDisk, E_NOTIMPL); case DSK_ERR_ACCESS: return Error(desc, IID_IDisk, E_ACCESSDENIED); } return Error(desc, IID_IDisk, MAKE_HRESULT(1, FACILITY_ITF, -err)); }
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; }
int do_format(char *outfile, char *outtyp, char *outcomp, int forcehead, dsk_format_t format) { DSK_PDRIVER outdr = NULL; dsk_err_t e; dsk_pcyl_t cyl; dsk_phead_t head; DSK_GEOMETRY dg; dsk_cchar_t fdesc; dsk_reportfunc_set(report, report_end); e = dsk_creat(&outdr, outfile, outtyp, outcomp); if (!e) e = dsk_set_retry(outdr, retries); if (!e && forcehead >= 0) e = dsk_set_forcehead(outdr, forcehead); if (!e) e = dg_stdformat(&dg, format, NULL, &fdesc); if (!e) { printf("Formatting %s as %s\n", outfile, fdesc); for (cyl = 0; cyl < dg.dg_cylinders; cyl++) { for (head = 0; head < dg.dg_heads; head++) { printf("Cyl %02d/%02d Head %d/%d\r", cyl +1, dg.dg_cylinders, head+1, dg.dg_heads); fflush(stdout); if (!e) e = dsk_apform(outdr, &dg, cyl, head, 0xE5); if (e) break; } } } /* Create a disc spec on the first sector, if the format's recognised */ if (!e) { unsigned char bootsec[512]; unsigned int do_bootsec = 0; memset(bootsec, 0xE5, sizeof(bootsec)); switch(format) { case FMT_180K: memcpy(bootsec, spec180, 10); do_bootsec = 1; break; case FMT_CPCSYS: memcpy(bootsec, spec169, 10); do_bootsec = 1; break; case FMT_CPCDATA: break; case FMT_200K: memcpy(bootsec, spec200, 10); do_bootsec = 1; break; case FMT_720K: memcpy(bootsec, spec720, 10); do_bootsec = 1; break; case FMT_800K: memcpy(bootsec, spec800, 10); do_bootsec = 1; break; default: break; } if (do_bootsec) e = dsk_lwrite(outdr, &dg, bootsec, 0); } printf("\r \r"); if (outdr) dsk_close(&outdr); if (e) { fprintf(stderr, "%s\n", dsk_strerror(e)); return 1; } return 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; }