int fsdevice_flush_write_byte(vdrive_t *vdrive, BYTE data) { unsigned int dnr; int rc; dnr = vdrive->unit - 8; rc = SERIAL_OK; /* FIXME: Consider the real size of the input buffer. */ if (fsdevice_dev[dnr].cptr < ioutil_maxpathlen() - 1) { fsdevice_dev[dnr].cmdbuf[(fsdevice_dev[dnr].cptr)++] = data; rc = SERIAL_OK; } else { fsdevice_error(vdrive, CBMDOS_IPE_LONG_LINE); rc = SERIAL_ERROR; } return rc; }
static int fsdevice_open_directory(vdrive_t *vdrive, unsigned int secondary, bufinfo_t *bufinfo, cbmdos_cmd_parse_t *cmd_parse, char *rname) { struct ioutil_dir_s *ioutil_dir; char *mask; BYTE *p; int i; if ((secondary != 0) || (bufinfo[secondary].mode != Read)) { fsdevice_error(vdrive, CBMDOS_IPE_NOT_WRITE); return FLOPPY_ERROR; } if (!(mask = strrchr(rname, '/'))) { mask = rname; } /* Test on wildcards. */ if (cbmdos_parse_wildcard_check(mask, (unsigned int)strlen(mask))) { if (*mask == '/') { strcpy(bufinfo[secondary].dirmask, mask + 1); *mask++ = 0; } else { strcpy(bufinfo[secondary].dirmask, mask); lib_free(cmd_parse->parsecmd); cmd_parse->parsecmd = lib_stralloc(fsdevice_get_path(vdrive->unit)); } } else { bufinfo[secondary].dirmask[0] = '\0'; if (!*(cmd_parse->parsecmd)) { lib_free(cmd_parse->parsecmd); cmd_parse->parsecmd = lib_stralloc(fsdevice_get_path(vdrive->unit)); } } /* trying to open */ ioutil_dir = ioutil_opendir((char *)(cmd_parse->parsecmd)); if (ioutil_dir == NULL) { for (p = (BYTE *)(cmd_parse->parsecmd); *p; p++) { if (isupper((int)*p)) { *p = tolower((int)*p); } } ioutil_dir = ioutil_opendir((char *)(cmd_parse->parsecmd)); if (ioutil_dir == NULL) { fsdevice_error(vdrive, CBMDOS_IPE_NOT_FOUND); return FLOPPY_ERROR; } } strcpy(bufinfo[secondary].dir, cmd_parse->parsecmd); /* * Start Address, Line Link and Line number 0 */ p = bufinfo[secondary].name; *p++ = 1; *p++ = 4; *p++ = 1; *p++ = 1; *p++ = 0; *p++ = 0; *p++ = (BYTE)0x12; /* Reverse on */ *p++ = '"'; strcpy((char *)p, bufinfo[secondary].dir); /* Dir name */ charset_petconvstring((BYTE *)p, 0); /* ASCII name to PETSCII */ i = 0; while (*p) { ++p; i++; } while (i < 16) { *p++ = ' '; i++; } *p++ = '"'; *p++ = ' '; *p++ = 'V'; *p++ = 'I'; *p++ = 'C'; *p++ = 'E'; *p++ = ' '; *p++ = 0; bufinfo[secondary].buflen = (int)(p - bufinfo[secondary].name); bufinfo[secondary].bufp = bufinfo[secondary].name; bufinfo[secondary].mode = Directory; bufinfo[secondary].ioutil_dir = ioutil_dir; bufinfo[secondary].eof = 0; return FLOPPY_COMMAND_OK; }
void fsdevice_flush(vdrive_t *vdrive, unsigned int secondary) { unsigned int dnr; char *cmd, *realarg, *arg; char *cbmcmd; int er = CBMDOS_IPE_SYNTAX; dnr = vdrive->unit - 8; if ((secondary != 15) || (!(fsdevice_dev[dnr].cptr))) { return; } cbmcmd = lib_malloc(ioutil_maxpathlen()); /* FIXME: Use `vdrive_command_parse()'! */ /* remove trailing cr */ while (fsdevice_dev[dnr].cptr && (fsdevice_dev[dnr].cmdbuf[fsdevice_dev[dnr].cptr - 1] == 13)) { (fsdevice_dev[dnr].cptr)--; } fsdevice_dev[dnr].cmdbuf[fsdevice_dev[dnr].cptr] = 0; strcpy(cbmcmd, (char *)(fsdevice_dev[dnr].cmdbuf)); charset_petconvstring((BYTE *)cbmcmd, 1); /* CBM name to FSname */ cmd = cbmcmd; while (*cmd == ' ') { cmd++; } arg = strchr(cbmcmd, ':'); if (arg != NULL) { *arg++ = '\0'; } realarg = strchr((char *)(fsdevice_dev[dnr].cmdbuf), ':'); if (realarg != NULL) { *realarg++ = '\0'; } /* i v n r s c b-r chn drv trk sec u1 chn drv trk sec b-w chn drv trk sec u2 chn drv trk sec b-p chn pos b-a drv trk sec b-f drv trk sec b-e chn drv trk sec m-r lo hi len m-w lo hi len <data> m-e lo hi u9/ui switch mode u:/uj reset cd cd_ / md rd */ if (!strncmp((char *)(fsdevice_dev[dnr].cmdbuf), "M-R", 3)) { er = fsdevice_flush_mr(vdrive, realarg); } else if (!strncmp((char *)(fsdevice_dev[dnr].cmdbuf), "M-W", 3)) { er = fsdevice_flush_mw(vdrive, realarg); } else if (!strncmp((char *)(fsdevice_dev[dnr].cmdbuf), "M-E", 3)) { er = fsdevice_flush_me(vdrive, realarg); } else if (!strcmp(cmd, "u1")) { er = fsdevice_flush_u1(vdrive, realarg); } else if (!strcmp(cmd, "u2")) { er = fsdevice_flush_u2(vdrive, realarg); } else if (!strncmp((char *)(fsdevice_dev[dnr].cmdbuf), "B-A", 3)) { er = fsdevice_flush_ba(vdrive, realarg); } else if (!strncmp((char *)(fsdevice_dev[dnr].cmdbuf), "B-F", 3)) { er = fsdevice_flush_bf(vdrive, realarg); } else if (!strncmp((char *)(fsdevice_dev[dnr].cmdbuf), "B-R", 3)) { er = fsdevice_flush_br(vdrive, realarg); } else if (!strncmp((char *)(fsdevice_dev[dnr].cmdbuf), "B-W", 3)) { er = fsdevice_flush_bw(vdrive, realarg); } else if (!strncmp((char *)(fsdevice_dev[dnr].cmdbuf), "B-P", 3)) { er = fsdevice_flush_bp(vdrive, realarg); } else if (!strncmp((char *)(fsdevice_dev[dnr].cmdbuf), "B-E", 3)) { er = fsdevice_flush_be(vdrive, realarg); } else if (!strcmp(cmd, "cd")) { er = fsdevice_flush_cd(vdrive, arg); } else if (!strcmp((char *)(fsdevice_dev[dnr].cmdbuf), "CD_")) { er = fsdevice_flush_cdup(vdrive); } else if (*cmd == '/') { er = fsdevice_flush_partition(vdrive, arg); } else if (!strcmp(cmd, "md")) { er = fsdevice_flush_mkdir(arg); } else if (!strcmp(cmd, "rd")) { er = fsdevice_flush_remove(arg); } else if ((!strcmp(cmd, "ui")) || (!strcmp(cmd, "u9"))) { er = fsdevice_flush_reset(); } else if ((!strcmp(cmd, "uj")) || (!strcmp(cmd, "u:"))) { er = fsdevice_flush_reset(); } else if (*cmd == 'i') { /* additional args for I are ignored */ er = fsdevice_flush_initialize(vdrive); } else if (*cmd == 'v') { /* additional args for V are ignored */ er = fsdevice_flush_validate(vdrive); } else if (*cmd == 'n' && arg != NULL) { er = fsdevice_flush_new(vdrive, realarg); } else if (*cmd == 'r' && arg != NULL) { er = fsdevice_flush_rename(vdrive, realarg); } else if (*cmd == 's' && arg != NULL) { er = fsdevice_flush_scratch(vdrive, realarg); } fsdevice_error(vdrive, er); fsdevice_dev[dnr].cptr = 0; lib_free(cbmcmd); }
static int fsdevice_open_file(vdrive_t *vdrive, unsigned int secondary, bufinfo_t *bufinfo, cbmdos_cmd_parse_t *cmd_parse, char *rname) { char *comma; tape_image_t *tape; unsigned int format = 0; fileio_info_t *finfo; if (fsdevice_convert_p00_enabled[(vdrive->unit) - 8]) { format |= FILEIO_FORMAT_P00; } if (!fsdevice_hide_cbm_files_enabled[vdrive->unit - 8]) { format |= FILEIO_FORMAT_RAW; } /* Remove comma. */ if ((cmd_parse->parsecmd)[0] == ',') { (cmd_parse->parsecmd)[1] = '\0'; } else { comma = strchr(cmd_parse->parsecmd, ','); if (comma != NULL) { *comma = '\0'; } } /* Test on wildcards. */ if (cbmdos_parse_wildcard_check(cmd_parse->parsecmd, (unsigned int)strlen(cmd_parse->parsecmd)) > 0) { if (bufinfo[secondary].mode == Write || bufinfo[secondary].mode == Append) { fsdevice_error(vdrive, CBMDOS_IPE_BAD_NAME); return FLOPPY_ERROR; } } /* Open file for write mode access. */ if (bufinfo[secondary].mode == Write) { if (fsdevice_save_p00_enabled[vdrive->unit - 8]) { format = FILEIO_FORMAT_P00; } else { format = FILEIO_FORMAT_RAW; } finfo = fileio_open(rname, fsdevice_get_path(vdrive->unit), format, FILEIO_COMMAND_WRITE, bufinfo[secondary].type); if (finfo != NULL) { bufinfo[secondary].fileio_info = finfo; fsdevice_error(vdrive, CBMDOS_IPE_OK); return FLOPPY_COMMAND_OK; } else { fsdevice_error(vdrive, CBMDOS_IPE_FILE_EXISTS); return FLOPPY_ERROR; } } if (bufinfo[secondary].mode == Append) { /* Open file for append mode access. */ finfo = fileio_open(rname, fsdevice_get_path(vdrive->unit), format, FILEIO_COMMAND_APPEND_READ, bufinfo[secondary].type); if (finfo != NULL) { bufinfo[secondary].fileio_info = finfo; fsdevice_error(vdrive, CBMDOS_IPE_OK); return FLOPPY_COMMAND_OK; } else { fsdevice_error(vdrive, CBMDOS_IPE_NOT_FOUND); return FLOPPY_ERROR; } } /* Open file for read mode access. */ tape = bufinfo[secondary].tape; tape->name = util_concat(fsdevice_get_path(vdrive->unit), FSDEV_DIR_SEP_STR, rname, NULL); charset_petconvstring((BYTE *)(tape->name) + strlen(fsdevice_get_path(vdrive->unit))+ strlen(FSDEV_DIR_SEP_STR), 1); tape->read_only = 1; /* Prepare for buffered reads */ bufinfo[secondary].isbuffered = 0; bufinfo[secondary].iseof = 0; if (tape_image_open(tape) < 0) { lib_free(tape->name); tape->name = NULL; } else { tape_file_record_t *r; static BYTE startaddr[2]; tape_seek_start(tape); tape_seek_to_file(tape, 0); r = tape_get_current_file_record(tape); if ( (r->type==1) || (r->type==3) ) { startaddr[0] = r->start_addr & 255; startaddr[1] = r->start_addr >> 8; bufinfo[secondary].bufp = startaddr; bufinfo[secondary].buflen = 2; } else {